Microsoft KB Archive/252413

= BUG: CDialogBar Does Not Forward Child Control Messages to Main Window for Windows CE =

Article ID: 252413

Article Last Modified on 3/6/2000

-

APPLIES TO


 * Microsoft Windows CE Toolkit for Visual C++ 6.0

-



This article was previously published under Q252413



SYMPTOMS
In Windows CE, when using the CDialogBar MFC class with standard Windows controls on it, the main window (CMainFrame) does not get notification messages from the controls on the dialog bar. For example, if you place a button control on the dialog bar, the BN_CLICKED message handler in CMainFrame is not called.



RESOLUTION
To work around this problem subclass CDialogBar with your own class to handle the messages from its child controls and forward them to the main window.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new project named "sample" using the Windows CE MFC AppWizard (exe) and select Win32 (WCE MIPS) and Win32 (WCE x86em) as platforms. At step 2 of 4, select Internet Explorer ReBars for the Control bar type. The rest of the wizard steps can be the default steps. Once the wizard is complete then switch to the ResourceView tab and open the IDR_MAINFRAME dialog resource. Delete the static text control and add a button control called (IDC_BUTTON1). Start ClassWizard and switch to the Message Maps tab. Under the CMainFrame class for the IDC_BUTTON1 object, add a BN_CLICKED message handler function, and call it OnButton1.  In the handler for CMainFrame::OnButton1 add code similar to the following:

MessageBox(L"Button 1", L"Test"); </li> Compile the application for the Palm-size PC 1.2 emulator and for the actual target device. Run the sample in the emulator or on the target device and click or tap the dialog bar button (IDC_BUTTON1).</li></ol>

Notice that CMainFrame::OnButton1 is not called and the message box does not pop up.

Steps to Work Around this Problem:
<ul>  In the Visual C++ workspace switch to the FileView tab and add two new files to the project: MyDialogBar.h and MyDialogBar.cpp with the code listed below:

Contents of MyDialogBar.h:
 * 1) if !defined(MYDIALOGBAR_H_INCLUDED)
 * 2) define MYDIALOGBAR_H_INCLUDED


 * 1) if _MSC_VER > 1000
 * 2) pragma once
 * 3) endif // _MSC_VER > 1000


 * 1) include "resource.h"

class CMyDialogBar : public CDialogBar { public: CMyDialogBar;  // standard constructor

protected: virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); };


 * 1) endif // !defined(MYDIALOGBAR_H_INCLUDED)

Contents of MyDialogBar.cpp:
 * 1) include "stdafx.h"
 * 2) include "sample.h"
 * 3) include "MyDialogBar.h"

static char THIS_FILE[] = __FILE__;
 * 1) ifdef _DEBUG
 * 2) define new DEBUG_NEW
 * 3) undef THIS_FILE
 * 1) endif

CMyDialogBar::CMyDialogBar : CDialogBar { }

LRESULT CMyDialogBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {   if (message == WM_COMMAND) { AfxGetMainWnd->SendMessage(message, wParam, lParam); }   return CDialogBar::WindowProc(message, wParam, lParam); }                       </li>  Open the MainFrm.h file and at the top of the file MainFrm.h, insert the following line:

 In the CMainFrame class definition alter the line CDialogBar m_wndDlgBar; to CMyDialogBar m_wndDlgBar; </li> Recompile the application for the Palm-size PC 1.2 emulator and for the actual target device. Run the sample in the emulator or on the target device and hit or tap the dialog bar button (IDC_BUTTON1).</li></ul>
 * 1) include "MyDialogBar.h" </li>

Now CMainFrame::OnButton1 is called and the message box pops up.

Additional query words: wince CDialogBar message handler

Keywords: kbbug kbarchitecture kbmfcctrlbar kbpending KB252413

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.