ATL GUI programming (2)

Source: Internet
Author: User
Tags win32

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 (&AMP;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 (&AMP;MSG);
DispatchMessage (&AMP;MSG);
}
return msg.wparam;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.