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