1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:         ReactOS Tests
3*c2c66affSColin Finck  * LICENSE:         GPL - See COPYING in the top level directory
4*c2c66affSColin Finck  * FILE:            rostests/win32/user32/paintdesktop/PaintDesktop.c
5*c2c66affSColin Finck  *
6*c2c66affSColin Finck  * PURPOSE:         Demonstrates how the user32!PaintDesktop() API visually works.
7*c2c66affSColin Finck  *                  This API paints the desktop inside the given HDC with its
8*c2c66affSColin Finck  *                  origin always fixed to the origin of the monitor on which
9*c2c66affSColin Finck  *                  the window is present.
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * PROGRAMMER:      Hermes Belusca-Maito
12*c2c66affSColin Finck  */
13*c2c66affSColin Finck 
14*c2c66affSColin Finck #define WIN32_LEAN_AND_MEAN
15*c2c66affSColin Finck #include <windows.h>
16*c2c66affSColin Finck 
17*c2c66affSColin Finck static HINSTANCE hInst;
18*c2c66affSColin Finck static PWSTR szTitle       = L"PaintDesktop";
19*c2c66affSColin Finck static PWSTR szWindowClass = L"PAINTDESKTOP";
20*c2c66affSColin Finck 
21*c2c66affSColin Finck ATOM                MyRegisterClass(HINSTANCE hInstance);
22*c2c66affSColin Finck BOOL                InitInstance(HINSTANCE, int);
23*c2c66affSColin Finck LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
24*c2c66affSColin Finck 
wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)25*c2c66affSColin Finck int APIENTRY wWinMain(HINSTANCE hInstance,
26*c2c66affSColin Finck                       HINSTANCE hPrevInstance,
27*c2c66affSColin Finck                       LPWSTR    lpCmdLine,
28*c2c66affSColin Finck                       int       nCmdShow)
29*c2c66affSColin Finck {
30*c2c66affSColin Finck     MSG msg;
31*c2c66affSColin Finck 
32*c2c66affSColin Finck     UNREFERENCED_PARAMETER(hPrevInstance);
33*c2c66affSColin Finck     UNREFERENCED_PARAMETER(lpCmdLine);
34*c2c66affSColin Finck 
35*c2c66affSColin Finck     MyRegisterClass(hInstance);
36*c2c66affSColin Finck 
37*c2c66affSColin Finck     if (!InitInstance (hInstance, nCmdShow))
38*c2c66affSColin Finck         return FALSE;
39*c2c66affSColin Finck 
40*c2c66affSColin Finck     while (GetMessage(&msg, NULL, 0, 0))
41*c2c66affSColin Finck     {
42*c2c66affSColin Finck         TranslateMessage(&msg);
43*c2c66affSColin Finck         DispatchMessage(&msg);
44*c2c66affSColin Finck     }
45*c2c66affSColin Finck 
46*c2c66affSColin Finck     return (int) msg.wParam;
47*c2c66affSColin Finck }
48*c2c66affSColin Finck 
MyRegisterClass(HINSTANCE hInstance)49*c2c66affSColin Finck ATOM MyRegisterClass(HINSTANCE hInstance)
50*c2c66affSColin Finck {
51*c2c66affSColin Finck     WNDCLASS wc;
52*c2c66affSColin Finck 
53*c2c66affSColin Finck     wc.style          = 0;
54*c2c66affSColin Finck     wc.lpfnWndProc    = WndProc;
55*c2c66affSColin Finck     wc.cbClsExtra     = 0;
56*c2c66affSColin Finck     wc.cbWndExtra     = 0;
57*c2c66affSColin Finck     wc.hInstance      = hInstance;
58*c2c66affSColin Finck     wc.hIcon          = LoadIconW(NULL, IDI_WINLOGO);
59*c2c66affSColin Finck     wc.hCursor        = LoadCursorW(NULL, IDC_ARROW);
60*c2c66affSColin Finck     wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
61*c2c66affSColin Finck     wc.lpszMenuName   = NULL;
62*c2c66affSColin Finck     wc.lpszClassName  = szWindowClass;
63*c2c66affSColin Finck 
64*c2c66affSColin Finck     return RegisterClass(&wc);
65*c2c66affSColin Finck }
66*c2c66affSColin Finck 
InitInstance(HINSTANCE hInstance,int nCmdShow)67*c2c66affSColin Finck BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
68*c2c66affSColin Finck {
69*c2c66affSColin Finck     HWND hWnd;
70*c2c66affSColin Finck 
71*c2c66affSColin Finck     hInst = hInstance;
72*c2c66affSColin Finck 
73*c2c66affSColin Finck     hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
74*c2c66affSColin Finck                         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
75*c2c66affSColin Finck     if (!hWnd)
76*c2c66affSColin Finck         return FALSE;
77*c2c66affSColin Finck 
78*c2c66affSColin Finck     ShowWindow(hWnd, nCmdShow);
79*c2c66affSColin Finck     UpdateWindow(hWnd);
80*c2c66affSColin Finck 
81*c2c66affSColin Finck     return TRUE;
82*c2c66affSColin Finck }
83*c2c66affSColin Finck 
WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)84*c2c66affSColin Finck LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
85*c2c66affSColin Finck {
86*c2c66affSColin Finck     switch (message)
87*c2c66affSColin Finck     {
88*c2c66affSColin Finck         case WM_MOVE:
89*c2c66affSColin Finck             InvalidateRect(hWnd, NULL, TRUE);
90*c2c66affSColin Finck             UpdateWindow(hWnd);
91*c2c66affSColin Finck             break;
92*c2c66affSColin Finck 
93*c2c66affSColin Finck         case WM_ERASEBKGND:
94*c2c66affSColin Finck             return (LRESULT)PaintDesktop((HDC)wParam);
95*c2c66affSColin Finck 
96*c2c66affSColin Finck         case WM_DESTROY:
97*c2c66affSColin Finck             PostQuitMessage(0);
98*c2c66affSColin Finck             break;
99*c2c66affSColin Finck 
100*c2c66affSColin Finck         default:
101*c2c66affSColin Finck             return DefWindowProc(hWnd, message, wParam, lParam);
102*c2c66affSColin Finck     }
103*c2c66affSColin Finck 
104*c2c66affSColin Finck     return 0;
105*c2c66affSColin Finck }
106