Need help with SendMessage
-
I'm trying to programmatically "click" a tab on a CTabCtrl. My understanding is that I can use SendMessage to do that by using TCN_SELCHANGE. But I am also assuming that I need *something* in the lParam and/or wParam values. It seems to me that the index of the tab "clicked" has to be included in there somewhere and somehow. My question is how (or where)? And where do I find things like this? For example, I happened to find here at CodeProject some info on sending a MOUSEMOVE message to a window with the coordinates of the mouse position:
SendMessage(hWndTarget, WM_MOUSEMOVE, fFlags, MAKELPARAM(x,y));
Where do I find things like the fact that the lParam is for flags and the wParam is for the coordinates? Any info is greatly appreciated. Thanks. -
I'm trying to programmatically "click" a tab on a CTabCtrl. My understanding is that I can use SendMessage to do that by using TCN_SELCHANGE. But I am also assuming that I need *something* in the lParam and/or wParam values. It seems to me that the index of the tab "clicked" has to be included in there somewhere and somehow. My question is how (or where)? And where do I find things like this? For example, I happened to find here at CodeProject some info on sending a MOUSEMOVE message to a window with the coordinates of the mouse position:
SendMessage(hWndTarget, WM_MOUSEMOVE, fFlags, MAKELPARAM(x,y));
Where do I find things like the fact that the lParam is for flags and the wParam is for the coordinates? Any info is greatly appreciated. Thanks.If you're using MFC, most of the classes abstract away the idea of having to send messages. Check out the documentation for CTabCtrl::SetCurSel(int nItem)? Or do you actually need to move the mouse?
If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling
-
I'm trying to programmatically "click" a tab on a CTabCtrl. My understanding is that I can use SendMessage to do that by using TCN_SELCHANGE. But I am also assuming that I need *something* in the lParam and/or wParam values. It seems to me that the index of the tab "clicked" has to be included in there somewhere and somehow. My question is how (or where)? And where do I find things like this? For example, I happened to find here at CodeProject some info on sending a MOUSEMOVE message to a window with the coordinates of the mouse position:
SendMessage(hWndTarget, WM_MOUSEMOVE, fFlags, MAKELPARAM(x,y));
Where do I find things like the fact that the lParam is for flags and the wParam is for the coordinates? Any info is greatly appreciated. Thanks.http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/tab/notifications/tcn\_selchange.asp MSDN is the answer to all your SendMessage-Questions ;)
-
If you're using MFC, most of the classes abstract away the idea of having to send messages. Check out the documentation for CTabCtrl::SetCurSel(int nItem)? Or do you actually need to move the mouse?
If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling
Sure, that selects the tab, but unfortunately it does NOT call the OnSelchange code. Therefore, simply calling SetCurSel won't activate the code that goes along with clicking on a tab. That's why I need to actually do a SendMessage -- to call the OnSelchange routine as though a tab was actually clicked.
-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/tab/notifications/tcn\_selchange.asp MSDN is the answer to all your SendMessage-Questions ;)
Yeah, I've been there. Personally I find it decidedly NOT helpful.
TCN_SELCHANGE Notification
Notifies a tab control's parent window that the currently selected tab has changed. This message is sent in the form of a WM_NOTIFY message.
Syntax
TCN_SELCHANGE
lpnmhdr = (LPNMHDR) lParam;
Parameters
lpnmhdr
Pointer to an NMHDR structure. The hwndFrom member is the handle to the tab control. The idFrom member is the child window identifier of the tab control. The code member is TCN_SELCHANGE.
Return ValueNo return value.
Remarks
To determine the currently selected tab, use the TabCtrl_GetCurSel macro.
Notification Requirements
Minimum DLL Version None
Header commctrl.h
Minimum operating systems Windows NT 3.51, Windows 95See Also
TCN_SELCHANGING
Then if I go to SendMessage itself, I get:
SendMessage Function
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
Syntax
LRESULT SendMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
ParametershWnd
[in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
Return ValueThe return value specifies the result of the message processing; it depends on the message sent.
And that doesn't tell me anything about what I need in lParam or wParam, nor does it tell me where I might go about finding such information. *That's* actually the info I'm hoping to get my hands on - and an actual code example would be swell.
-
Yeah, I've been there. Personally I find it decidedly NOT helpful.
TCN_SELCHANGE Notification
Notifies a tab control's parent window that the currently selected tab has changed. This message is sent in the form of a WM_NOTIFY message.
Syntax
TCN_SELCHANGE
lpnmhdr = (LPNMHDR) lParam;
Parameters
lpnmhdr
Pointer to an NMHDR structure. The hwndFrom member is the handle to the tab control. The idFrom member is the child window identifier of the tab control. The code member is TCN_SELCHANGE.
Return ValueNo return value.
Remarks
To determine the currently selected tab, use the TabCtrl_GetCurSel macro.
Notification Requirements
Minimum DLL Version None
Header commctrl.h
Minimum operating systems Windows NT 3.51, Windows 95See Also
TCN_SELCHANGING
Then if I go to SendMessage itself, I get:
SendMessage Function
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
To send a message and return immediately, use the SendMessageCallback or SendNotifyMessage function. To post a message to a thread's message queue and return immediately, use the PostMessage or PostThreadMessage function.
Syntax
LRESULT SendMessage( HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
ParametershWnd
[in] Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
Msg
[in] Specifies the message to be sent.
wParam
[in] Specifies additional message-specific information.
lParam
[in] Specifies additional message-specific information.
Return ValueThe return value specifies the result of the message processing; it depends on the message sent.
And that doesn't tell me anything about what I need in lParam or wParam, nor does it tell me where I might go about finding such information. *That's* actually the info I'm hoping to get my hands on - and an actual code example would be swell.
Post a TCM_SETCURFOCUS message, assuming that your Tab control is NOT using TCM_BUTTONS style. This message's default handler causes TCM_SELCHANGING and TCM_SELCHANGE messages to be generated & sent to the tab control. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
-
Post a TCM_SETCURFOCUS message, assuming that your Tab control is NOT using TCM_BUTTONS style. This message's default handler causes TCM_SELCHANGING and TCM_SELCHANGE messages to be generated & sent to the tab control. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
Fantastic! It works perfectly. Thanks a bunch.