Reputation: 678
I have a trivial question hopefully. I create a button with CreateWindowEx where I specify a button name. Later in the application I need to change the button caption so I use a WM_SETTEXT message:
SendMessage(hStartBtn, WM_SETTEXT, 0, (LPARAM) _T("NewText"));
This works fine, it changes a button caption to "NewText". However it also have one drawback - it changes the button name specified during CreateWindowEx call. This messes few things in my app since I use FindWindowEx to find a handle of this button (Im trying to avoid using global variables thus I don't store handle returned by CreateWindowEx).
Is this really how buttons work or Im missing some other message/function that changes the caption but doesn't affect the control name?
Thanks,
Kra
Upvotes: 2
Views: 6192
Reputation: 36016
Buttons are not identified by "name". The string passed to the button control is the text it displays.
Windows uses control IDs to identify controls. GetDlgItem is used to retrieve a window handle, given its parent window. All that is required is that windows are created with the correct control id (passed in via the HMENU parameter of CreateWindow) and the parent window does not have to be a dialog.
Upvotes: 1
Reputation: 78573
This MSDN article on WM_SETTEXT suggests that "For a button, the text is the button name".
Upvotes: 0