Thursday, May 22, 2008

WTL - Create a dialog without resource

Hi,
yesterday i explained how create a menu by code without use resource, today i'll explain how to create a dialog without use resource using WTL in 2 mins and with 20 lines :)

WTL framework comes with two classes:
CMemDlgTemplate (which define our dialog template)
CIndirectDialogImpl (which define our dialog class)

In the code below i'll show how create an empty dialog with just few lines:


#pragma once
#include <atldlgs.h> //don't forget it :)

typedef
CWinTraits<WS_VISIBLEWS_POPUPDS_CENTER> MyDlgTraits;
class
CAboutDlg : public CIndirectDialogImpl<CAboutDlg, CMemDlgTemplate,
CStdDialogImpl<CAboutDlg>>
{
public:
//ovverride the DoInitTemplate and set the correct values for template
void
DoInitTemplate()
{
m_Template.Create(false, L"OUR DIALOG CAPTION", 0, 0, 0, 0,
MyDlgTraits::GetWndStyle(0),
MyDlgTraits::GetWndExStyle(0));
}

BEGIN_MSG_MAP(CAboutDlg)
MESSAGE_HANDLER(WM_INITDIALOG,
OnInitDialog)
CHAIN_MSG_MAP(CStdDialogImpl)
END_MSG_MAP()

LRESULT
OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL&
bHandled)
{
#ifdef
WIN32_PLATFORM_PSPC
AtlCreateEmptyMenuBar(m_hWnd);
#endif
return
bHandled = FALSE;
}
};


I used CStdDialogImpl as base class which is the specific base dialog for devices.

Bye

No comments: