Chapter II Transformation of one of the simplest window programs
I know, there may be a lot of friends on the last chapter of "Hello, world!" The ATL version disagrees because it's not an ATL program-after all, it's just a ccommodule. But anyway, I would say that it almost still has all the components of an ATL GUI program: Portal, initialization, program body, uninstall ...
Wait "Maybe you'll interrupt me suddenly,"--and the Registration window class, the message loop? ”
Of course, this is necessary for a complete GUI program.
Looks like crap.
It's not clear if you're ready for the content of this chapter, because we're going to do the real work here. However, considering that there may be a considerable number of readers in this book that understand MFC but not very familiar with the fundamentals and processes of the Win32 GUI, Li Ma specially prepared this section for you. Fans of the SDK can skip this section if you feel that Li Ma is a bit of a long, drawn-out conversation.
So, I'm going to start with a standard WIN32 SDK program:
//////////////////////////////////////////////////////////////////////////
ATL GUI programming supporting source code
Chapter II Transformation of one of the simplest window programs
Project Name: HELLOSDK
Author: Li Ma
http://www.titilima.cn
//////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK Hellowndproc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM)
{
Switch (umsg)
{
Case Wm_destroy:
{
PostQuitMessage (0);
}
Break
Case WM_PAINT:
{
HDC HDC;
Paintstruct PS;
HDC = BeginPaint (hWnd, &ps);
DrawText (HDC, _t ("Hello, sdk!"),-1, &ps.rcpaint, Dt_center | Dt_vcenter | Dt_singleline);
EndPaint (HWnd, &ps);
}
Break
Default
Return DefWindowProc (HWnd, umsg, WParam, LParam);
}
return 0;
}
BOOL initapplication (hinstance hinstance)
{
WNDCLASS WC;
Wc.cbclsextra = 0;
Wc.cbwndextra = 0;
Wc.hbrbackground = (hbrush) getstockobject (White_brush);
Wc.hcursor = LoadCursor (NULL, Idc_arrow);
Wc.hicon = LoadIcon (NULL, idi_application);
Wc.hinstance = hinstance;
Wc.lpfnwndproc = Hellowndproc;
Wc.lpszclassname = _t ("Hellosdk");
Wc.lpszmenuname = NULL;
Wc.style = Cs_hredraw | Cs_vredraw;
Return registerclass (&WC);
}
int WINAPI _tWinMain (hinstance hinstance, hinstance hprevinstance, LPTSTR lpcmdline, int nshowcmd)
{
Register window class
InitApplication (HINSTANCE);
Create a window
HWND hwnd = CreateWindow (_t ("Hellosdk"), _t ("Hello SDK"), Ws_overlappedwindow, Cw_usedefault, Cw_usedefault,
Cw_usedefault, cw_usedefault, NULL, NULL, HINSTANCE, NULL);
ShowWindow (HWnd, nShowCmd);
UpdateWindow (HWND);
Message loops
MSG msg;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
return msg.wparam;
}