Secrets under the ATL Drapes (5)

Source: Internet
Author: User

Introduced

Many people think that ATL is just for writing COM components, but you can also use window classes in ATL to create windows-based applications. Although you can convert MFC based programs to ATL, there is too little support in ATL for UI components. So, this requires you to write a lot of code yourself. For example, there is no document/view in ATL, so you need to implement it yourself when you want to use it. In this article, we'll explore some of the secrets of window classes and the secrets of ATL technology implementations. WTL (Windows Template Library, window Template gallery), although this article was published on October 27, 2002 in CodeProject, is not supported by Microsoft, but it is a big step in making graphics applications. WTL is the ATL-based window class.

Before we start talking about ATL based programs, let's start with a classic Hello World program. This program is written entirely in the SDK, and almost everyone of us is already familiar with it.

Program 66.

#include <windows.h>
LRESULT CALLBACK WndProc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM);
int WINAPI WinMain (hinstance hinstance, HInstance hprevinstance,
LPSTR lpcmdline, int ncmdshow)
{
Char szappname[] = "Hello World";
HWND hwnd;
MSG msg;
Wndclass Wnd;

Wnd.cbclsextra = NULL;
Wnd.cbwndextra = NULL;
Wnd.hbrbackground = (hbrush) getstockobject (White_brush);
Wnd.hcursor = LoadCursor (NULL, Idc_arrow);
Wnd.hicon = LoadIcon (NULL, idi_application);
Wnd.hinstance = hinstance;
Wnd.lpfnwndproc = WndProc;
Wnd.lpszclassname = Szappname;
Wnd.lpszmenuname = NULL;
Wnd.style = Cs_hredraw | Cs_vredraw;

if (! RegisterClass (&wnd))
{
MessageBox (NULL, "Can not register window class", "Error",
MB_OK | Mb_iconinformation);
return-1;
}

HWnd = CreateWindow (Szappname, "Hello World", Ws_overlappedwindow, Cw_usedefault,
Cw_usedefault, Cw_usedefault, cw_usedefault, NULL, NULL, HINSTANCE, NULL);

ShowWindow (HWnd, ncmdshow);
UpdateWindow (HWND);

while (GetMessage (&msg, NULL, 0, 0))
{
DispatchMessage (&AMP;MSG);
}

return msg.wparam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM)
{
HDC HDC;
Paintstruct PS;
RECT RECT;
Switch (umsg)
{
Case WM_PAINT:
HDC = BeginPaint (hWnd, &ps);
GetClientRect (HWnd, &rect);
DrawText (HDC, "Hello World",-1, &rect, Dt_singleline | Dt_center | Dt_vcenter);
EndPaint (HWnd, &ps);
Break
Case Wm_destroy:
PostQuitMessage (0);
Break
}

Return DefWindowProc (HWnd, umsg, WParam, LParam);
}

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.