Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » How to use buttons in a Dialog Collapse All
Subject Author Date
Peter Roth Mar 2, 2004 - 6:35 AM

I’m very new in c++ programming, but perhaps anybody can help me witdh my questions about dialogs and Prof-UIS:
I’ve got a SingleDocTemplate-project width CMainDoc,CMainFrame and CMainView, now I want to use Prof-UIS to output a dockable Dialog.
First I’ve created a Dialog (IDD_RESIZABLE1) width the Ressource-Editor and inserted some buttons (e.g.: IDC_BUTTON_FROM).
Then I wrote the Create-Part in MainFrm.cpp, but now I want to change e.g. a picture in the Dialog after someone pushed the button.
So my question: how do I link the button e.g. width "void CMainView::OnButtonFromPushed()"?
If the button is part of a toolbar, everything is ok and something happens, but if the button is part of a dialog nothing happens!


here’s the code for the project:


in MainFrm.h:


protected:


 CExtControlBar   m_wndResizableBar1;
 CExtResizableDialog  m_dlgForResizable;
 CExtButton   m_ButtonCombiFrom;



in MainFrm.cpp:


// to create the dialog from ressource:


 if( !m_wndResizableBar1.Create(
   NULL, // _T("Optional control bar caption"),
   this,
   IDD_RESIZABLE1
   )
  )
 {
  TRACE0("Failed to create m_wndResizableBar1\n");
  return -1;  // fail to create
 }
 if( !m_dlgForResizable.Create(
   IDD_RESIZABLE1,
   &m_wndResizableBar1
   )
  )
 {
  TRACE0("Failed to create m_dlgForResizable\n");
  return -1;  // fail to create
 }



// and for the new button-style:


 VERIFY(
  m_ButtonCombiFrom.SubclassDlgItem(
   IDC_BUTTON_FROM,
   &m_dlgForResizable
   )



now my problem: how can I use this button in MainView.cpp ?
I tried it there width:


BEGIN_MESSAGE_MAP(CMainView, CView)
 //{{AFX_MSG_MAP(CMainView)
 ON_COMMAND(IDC_BUTTON_FROM, OnButtonFrom)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()
 
but only if the IDC_... is part of a Toolbar something happens.



Perhaps it’s the wrong way to read the IDD_RESZIABLE1 in MainFrm and it’s better to use something like a view.
I found a code in StatusPanes, maybe there’s a way to use that for the problem:


m_pWndView = new CChildFormView;
 if (!m_pWndView->Create(
  NULL,
  NULL,
  AFX_WS_DEFAULT_VIEW,
  CRect(0, 0, 0, 0),
  this,
  AFX_IDW_PANE_FIRST,
  NULL)
  )
 {
  TRACE0("Failed to create view window\n");
  return -1;
 }


 

Sergiy Lavrynenko Mar 3, 2004 - 6:03 AM

Hi Peter,


You are absolutely right. The WM_COMMAND messages from the dialog’s buttons can be caught in this dialog only. If you want some CMainFrame methods to be invoked when clicking buttons in a dockable dialog, you may handle the corresponding commands in dialog’s methods and invoke methods of CMainFrame in these methods of the dockable dialog. This is a very simple and not convenient solution. In fact, it is possible to catch these dialog’s commands in the main frame window, but you should use your own dialog class derived from the CExtResizableDialog class and override the following virtual methods:

BOOL CYourDlg::OnCmdMsg(
            UINT nID,
            int nCode,
            void* pExtra,
            AFX_CMDHANDLERINFO* pHandlerInfo
            ) 
{
            return
                        CWnd::OnCmdMsg(
                                    nID,
                                    nCode,
                                    pExtra,
                                    pHandlerInfo
                                    );
}
 
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg) 
{
            if( CExtControlBar::
                    DoCustomModePreTranslateMessage(
                                this,
                                pMsg
                                )
                 )
                 return TRUE;
            if(          WM_KEYFIRST <= pMsg->message
                        && pMsg->message <= WM_KEYLAST
                        )
                        return FALSE;
            if( PreTranslateInput(pMsg) )
                        return TRUE;
            return FALSE;
}

Best regards, Sergiy.