C++ GUI in MFC - Pagination widget

306 Views Asked by At

I'm writing C++ code, targeting WinCE 6.0 device and I'm having hard time finalizing GUI for my app. VS 2005 window builder which I have to be using does not seem to simplify this task and I cant find documentation which will throw some light on API, hopefully somebody here can.

I need to be dynamically writing on widget page user is on / total number of pages. I expect CTEXT is correct widget to use

CTEXT           IDC_PG, 168,183,63,63

However I dont seem to find correct way how to print on CTEXT (or any other suitable widget) Thanks in advance for any good advices.

1

There are 1 best solutions below

1
Adrian McCarthy On

If I'm understanding the question correctly, you want to display a bit of text on your UI of the form "Page x of n". A static text control (like CTEXT) is appropriate for this.

To set the text programmatically, you can call SetWindowText, but since this is on a dialog, it's probably easier to call SetDlgItemText.

From your example, the identifier is IDC_PG, and it should correspond to a numeric constant that is unique among all the controls on the dialog. Assuming you have an MFC object for the dialog (which I'll assume is myDialog) and a pointer to the zero-terminated text you want it to display (which I'll assume is szPageText), your call would look like:

myDialog.SetDlgItemText(IDC_PG, szPageText);

If you just have a handle to the dialog, your call would look like this:

SetDlgItemText(hDlg, IDC_PG, szPageText);

Since this is older code, it might be compiled for MBCS (often called ANSI in Windows documentation) or UTF-16 (often called Unicode or "wide" strings in MSDN), so you probably want to use the TCHAR and related macros to make sure it works either way.

TCHAR szPageText[64] = TEXT("");
wsprintf(szPageText, TEXT("Page %d of %d"), currentPage, totalPages);
myDialog.SetDlgItemText(IDC_PG, szPageText);

In more modern code, you'd probably explicitly use the wide versions of the APIs:

WCHAR szPageText[64] = L"";
::wsprintfW(szPageText, L"Page %d of %d", currentPage, totalPages);
myDialog.SetDlgItemTextW(IDC_PG, szPageText);