6.10.2010

Simple Dialog Program with WTL

一個簡單的 Dialog 程式:
main.cpp:
#pragma once
#define WINVER 0x0420

#include <atlbase.h>
#include <atlapp.h>
#include <atlwin.h>

#include "resource.h"

class CMainDialog : public CDialogImpl<CMainDialog>
{
public:
enum { IDD = IDD_MAINDLG };

BEGIN_MSG_MAP(CMainDialog)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()

LRESULT OnCancel(WORD,WORD wID,HWND,BOOL&)
{
::PostQuitMessage(wID);
return 0;
}
};

CAppModule _Module;

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE,LPTSTR lpstrCmdLine, int nCmdShow)
{
HRESULT hRes = ::CoInitialize(NULL);

::DefWindowProc(NULL,0,0,0L);

AtlInitCommonControls(NULL);

hRes = _Module.Init(NULL,hInstance);

CMainDialog dlgMain;
hRes = dlgMain.DoModal();

_Module.Term();
::CoUninitialize();

return hRes;
}

resource.h
#define IDD_MAINDLG 101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

resource.rc 就是一個 dialog,沒有 button。


奇怪,現在我自己照著作,反而要改這樣:
.c
#pragma once
#define WINVER 0x0600

#include <atlbase.h>
#include <atlapp.h>
#include <atlwin.h>

#include "resource.h"

class CMainDialog : public CDialogImpl<CMainDialog>
{
public:
enum { IDD = IDD_DIALOG1 };

BEGIN_MSG_MAP(CMainDialog)
COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()

LRESULT OnCancel(WORD,WORD wID,HWND, BOOL&)
{
::PostQuitMessage(wID);
return 0;
}
};

CAppModule _Module;

int WINAPI _tWinMain(HINSTANCE hInstance,HINSTANCE,LPTSTR lpstrCmdLine,int nCmdShow)
{
HRESULT hRes = ::CoInitializeEx(NULL,COINIT_MULTITHREADED);
::DefWindowProc(NULL,0,0,0L);
AtlInitCommonControls(NULL);
hRes = _Module.Init(NULL,hInstance);

CMainDialog dlgMain;
hRes = dlgMain.DoModal();
::CoUninitialize();

return hRes;
}


.h 大概就跟上面一樣。

沒有留言: