Home > Articles > Home & Office Computing > Microsoft Windows Desktop

  • Print
  • + Share This
This chapter is from the book

Can you give an example where this makes a difference?

CONSIDER THIS CONTROL:

SampleWndProc(...)
{
    case WM_GETTEXT:
        lstrcpyn((LPTSTR)lParam, TEXT("Booga!"), (int)wParam);
        return lstrlen((LPTSTR)lParam);
    case WM_GETTEXTLENGTH: return 7; // lstrlen("Booga!") + null
    ...
}

And application A, which does this:

hwnd = CreateWindow("Sample", "Frappy", ...);

Now consider process B, which gets the handle to the window created by application A (by whatever means):

TCHAR szBuf[80];
GetWindowText(hwnd, szBuf, 80);

This will return szBuf = "Frappy" because it is getting the window text from the special place. However

SendMessage(hwnd, WM_GETTEXT, 80, (LPARAM)szBuf);

will return szBuf = "Booga!"

  • + Share This
  • 🔖 Save To Your Account