Create a simple ATL dialog program without using the ATL wizard.

zhaozj2021-02-08  227

This example creates a dialog program using the CWINDOWIMPL class. Step 1: Create a new Win32 Application Engineering.

Step 2: In the stdafx.h, the following three rows are included.

#include extern ccommodule _module; #include

Step 3: Write the WinMain function, as follows:

Int apientry Winmain (Hinstance Hinstance, Hinstance, LPSTR, INT) {_ module.init (null, hinstance);

// Create an instance of cmcbwindowcmcbwindow atlwnd; atlwnd.create (null, cwindow :: rcdefault, _t ("mahesh's atl window", ws_overlappedwindow | ws_visible);

Msg Msg; While (GetMessage (& MSG, NULL, 0, 0)) {TranslateMessage (& MSG); DispatchMessage (& MSG);

_Module.Term (); return msg.wparam;} Step 4: Inheriting the CMCBWindow class from CWindowImpl:

// NOTE: See the template parameter Its CMcbWindowclass CMcbWindow:. Public CWindowImpl {// START MESSAGE_MAPBEGIN_MSG_MAP (CMcbWindow) MESSAGE_HANDLER (WM_PAINT, OnPaint) MESSAGE_HANDLER (WM_DESTROY, OnDestroy) END_MSG_MAP () // END MESSAGE_MAP

// this function will Paint A Hello Mindcracker String Lresult Onpaint (Uint, WPARAM, LPARAM, BOOL &) {PAINTSTRUCT PS; HDC HDC = Getdc (); BeginPaint (& PS); Textout (HDC, 0, 0, _t ("Hello Mindcracker "), 17); Endpaint (& PS); Return 0;}

LResult, WParam, LParam, Bool &) {PostquitMessage (0); return 0;}}; fifth step: Define ccommodule _Module:

// atlwnd.cpp: Defines the entry point for the application. # Include "stdafx.h" ccommodule _module; Final: Compiling execution.

转载请注明原文地址:https://www.9cbs.com/read-2835.html

New Post(0)