How To Implement an Independent Floating Modeless Dialog Box in MFC for Pocket PC (298685)



The information in this article applies to:

  • Microsoft Windows CE for the Pocket PC

This article was previously published under Q298685

SUMMARY

When you implement a modeless dialog box for Pocket PC in Microsoft Foundation Classes (MFC), MFC may resize the dialog box and hook some default processing to it. Sometimes it is desirable to have a fixed size for the dialog box and enable the user to move it around, such as a floating toolbox.

MORE INFORMATION

Follow these steps to create a floating dialog box of fixed size:
  1. Define your CDialog class (for example, CMyDialog) as usual.
  2. Implement WM_INITDIALOG in a static dialog procedure, which will be used in that next step, that:

    1. Sets the dialog box's m_bFullScreen member to FALSE.
    2. Attaches the newly created dialog box to your dialog class.
    3. Calls OnInitDialog.
    This following code demonstrates this:
    // This proc is declared as static in the class declaration
    BOOL CALLBACK CMyDialog::MyDlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	CDialog *pDlg;
    
    	switch (msg)
    	{
    		case WM_INITDIALOG:
    			pDlg = (CDialog*)lParam;
    			pDlg->m_bFullScreen = FALSE;
    			pDlg->Attach(hWnd);
    			return pDlg->OnInitDialog();
    
    		default:
    			return FALSE;
    	}
    
    }
    					
  3. Override CMyDialog::Create to call ::CreateDialogParam and pass the this pointer as the dwInitParam parameter. This will be passed in the lParam of the WM_INITDIALOG message:
    BOOL CMyDialog::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
    {
    	::CreateDialogParam(AfxGetInstanceHandle(),
    		MAKEINTRESOURCE(IDD_DIALOG1),
    		pParentWnd->GetSafeHwnd(),
    		CMyDialog::MyDlgProc,
    		(LPARAM)this);
    
    	return TRUE;
    }
    
    					
  4. Implement CMyDialog::OnSettingChange to return CWnd::OnSettingChange:
    void CMyDialog::OnSettingChange(UINT uFlags,LPCTSTR lpszSection)
    {
    	CWnd::OnSettingChange(uFlags,lpszSection);
    }
    					
Now you should have a dialog box that assumes the size of the dialog resource it was created from and that can be moved around.

Modification Type:MinorLast Reviewed:10/11/2004
Keywords:kbhowto KB298685