![]() |
CXTPDialogBar Messages |
Post Reply ![]() |
Author | |
Ocrana ![]() Groupie ![]() Joined: 20 November 2007 Status: Offline Points: 32 |
![]() ![]() ![]() ![]() ![]() Posted: 11 August 2010 at 8:57pm |
Hi,
is there a sample available where I can see how to receive messages from a CXTPDialogBar. I use a CXTPDialogBar with some buttons as a special ToolBar. But I have now Idea how to receive the Messages (Button click) in the main form. So I want to see or get help how to communicate with the CXTPDialogBar. Thanks, Ocrana |
|
![]() |
|
CyberSky ![]() Groupie ![]() Joined: 15 February 2010 Status: Offline Points: 15 |
![]() ![]() ![]() ![]() ![]() |
My program's view used to get messages from the MFC dialog bar without any extra work. Then I switched to CXTPDialogBar and that broke. The way I dealt with this is to add handlers for the controls in my dialog bar class and to send the messages to my view:
void CControlDlg::OnBnClickedFoo()
{ CMyProgramView::View()->SendMessage(WM_COMMAND, IDC_FOO, NULL); } I don't know if this is the best way, but it works.
You should also be aware that if the CodeJock dialog has the focus you can't press Alt+F to access the File menu, etc. You need to override PreTranslateMessage() in your CXTPDialogBar-derived class and add the code from the MFC dialog bar class.
|
|
![]() |
|
znakeeye ![]() Senior Member ![]() ![]() Joined: 26 July 2006 Status: Offline Points: 1672 |
![]() ![]() ![]() ![]() ![]() |
Microsoft didn't document this well. Due to that, you find a lot of bad hacks out there. Like the one proposed. If a WM_COMMAND message does not arrive to its destination, it is due to an erroneous message handler: CWnd::OnCmdMsg. If the main-window does not route messages to the CXTPDialogBar, then you cannot expect it to receive them. WM_COMMAND is propagated from top to bottom, so you should NEVER send it to a window's parent window! Doing so might hang your application if some other programmer, later on, implements command routing logic the right way:
BOOL CMainWnd::OnCmdMsg(...)
{
if (m_wndDialogBar.OnCmdMsg(...))
return TRUE;
return CFrameWnd::OnCmdMsg(...);
}
This is of course a very simple example. Usually you have to consider focus, active pane/view and stuff. The reason why CDialog worked out of the box, is that MFC does a lot of nasty things behind your back :)
Note: If you must send a WM_COMMAND message, then always send it to the top-level parent, usually AfxGetMainWnd().
|
|
PokerMemento - http://www.pokermemento.com/
|
|
![]() |
|
CyberSky ![]() Groupie ![]() Joined: 15 February 2010 Status: Offline Points: 15 |
![]() ![]() ![]() ![]() ![]() |
Thank you for your comments, znakeeye! I'm sorry it's taken so long to get back to you.
To be clear: I had message handlers in my view class for menu commands and toolbar buttons. When I used the MFC dialog bar, I found that if I gave a control (a button) the same resource ID as a menu command or toolbar button, I could click the menu command, the tollbar button, or the button in the dialog bar and have the same code (the message handler in my view) do whatever needed to be done.
When I switched to the CodeJock CXTPDialogBar, this stopped working. I wanted to quickly find a way to get things working again, and they do. I'd like to do things in a better way, if possible. However, I tried your code an nothing happens. I click the button in the dialog bar and the handler in my view class doesn't get the message. I'm not sure how it would...
I'm obviously not an expert in command routing. Any more pointers on what I can try? Do you know if one of the CodeJock examples shows the correct way to do this?
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |