Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - CXTPDialogBar Messages
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPDialogBar Messages

 Post Reply Post Reply
Author
Message
Ocrana View Drop Down
Groupie
Groupie


Joined: 20 November 2007
Status: Offline
Points: 32
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ocrana Quote  Post ReplyReply Direct Link To This Post Topic: CXTPDialogBar Messages
    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
Back to Top
CyberSky View Drop Down
Groupie
Groupie


Joined: 15 February 2010
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote CyberSky Quote  Post ReplyReply Direct Link To This Post Posted: 21 August 2010 at 1:23pm
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.
 
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 22 August 2010 at 8:49am

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/
Back to Top
CyberSky View Drop Down
Groupie
Groupie


Joined: 15 February 2010
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote CyberSky Quote  Post ReplyReply Direct Link To This Post Posted: 01 September 2010 at 12:51am
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?
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.