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 (&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);
}