Hi,
In RichEdit5, open an RTF file. There are tables in this file. How can I access the cells of these tables ?
Hi,
In RichEdit5, open an RTF file. There are tables in this file. How can I access the cells of these tables ?
// Assuming you have a handle to the Rich Edit control
// in the variable `hRichEdit`.
// Get the number of tables in the document.
int tableCount = SendMessage(hRichEdit, EM_GETTABLECOUNT, 0, 0);
// Iterate through the tables.
for (int i = 0; i < tableCount; i++) {
  // Select the current table.
  SendMessage(hRichEdit, EM_SETSEL, 0, MAKELONG(i, i));
  // Get the table properties.
  TABLESELINFO tsi;
  SendMessage(hRichEdit, EM_GETTABLESEL, 0, (LPARAM)&tsi);
  // Extract the table structure information.
  int numRows = tsi.cRows;
  int numCols = tsi.cCols;
  // Iterate through the rows and columns of the table.
  for (int row = 0; row < numRows; row++) {
    for (int col = 0; col < numCols; col++) {
      // Access the cell at the current row and column.
      CELLINFO ci;
      ci.cbSize = sizeof(ci);
      ci.row = row;
      ci.col = col;
      SendMessage(hRichEdit, EM_GETCELLINFO, 0, (LPARAM)&ci);
      // Process the cell's information as needed.
      // The ci contains information such as cell's text, formatting, etc.
      // For example:
      wchar_t cellText[256];
      SendMessage(hRichEdit, EM_GETTEXTRANGE, ci.cpStart, ci.cpEnd, (LPARAM)cellText);
      // Process the cell text...
      // You can also modify the cell content if desired:
      // SendMessage(hRichEdit, EM_SETSEL, ci.cpStart, ci.cpEnd);
      // SendMessage(hRichEdit, EM_REPLACESEL, TRUE, (LPARAM)L"New Text");
    }
  }
}Antonio, thanks for the example!
What is a hRichedit handle, because we are working with a TRichEdit5 object ?
Is there any guide for working with RichEdit5 ?
I understood.