[Windows Mobile Development and Hacking General] Peter Bruderlin:
Ok, here's the code as it exists now:

case WM_INITDIALOG:
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
//
// Code to check setting text
//
//LRESULT result = SendDlgItemMessage(hDlg, IDC_STATIC_2, WM_SETTEXT, 0, L"Example");
// Get the text from the control
wchar_t buffer[100];
HWND hCtl = GetDlgItem(hDlg, IDC_STATIC_2);
LRESULT result = SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Text from control...", MB_OK | MB_ICONINFORMATION);
// Modify the extracted text
buffer[0] = L'A';
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Set text by SendMessage to...", MB_OK | MB_ICONINFORMATION);
SetLastError(0);
//BOOL textResult = SetWindowText(hCtl, (LPCWSTR)buffer);
result = SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (result == 0)
{
wchar_t errorTitle[] = L"Last Error...";
LPVOID lpMsgBuf;
DWORD error = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
result = SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Text from control...", MB_OK | MB_ICONINFORMATION);
// Modify the extracted text
buffer[0] = L'A';
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Set text by SetWindowText to...", MB_OK | MB_ICONINFORMATION);
SetLastError(0);
BOOL textResult = SetWindowText(hCtl, (LPCWSTR)buffer);
//result = SendMessage(hCtl, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer);
if (textResult == 0)
{
wchar_t errorTitle[] = L"Last Error...";
LPVOID lpMsgBuf;
DWORD error = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, (LPCWSTR)errorTitle, MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
}
result = SendMessage(hCtl, WM_GETTEXT, (WPARAM)80, (LPARAM)buffer);
MessageBox(NULL, (LPCTSTR)buffer, (LPCWSTR)L"Text from control...", MB_OK | MB_ICONINFORMATION);
//
// End of changes
//
}
return (INT_PTR)TRUE;

It's the WM_INITDIALOG section of the main window's WndProc function.

This is the only part of the default application I have modified after the project wizard created it.

In the code above I find that by return value, SendMessage fails while SetWindowText succeeds.

By looking at GetLastError (after having set it to zero first), both functions succeed.

One interesting thing I noticed is that after I set the control's text, I can retreive it and it is the text that I have just set. So in that sense, both functions (SetMessage and SetWindowText) succeed.

However when I see the about dialog, on both the WM5 emulator and my Atom, the text has not changed from "TestSetText Version".

It seems that the static's text is actually being set properly. I think it has become an issue of why isn't it rendering the new text when the control is displayed?