Move tests from rosapps to rostests
[reactos.git] / rostests / tests / guithreadinfo / guithreadinfo.c
1 #include <windows.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 static GUITHREADINFO gti;
6 //HFONT tf;
7 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
8
9 int WINAPI
10 WinMain(HINSTANCE hInstance,
11 HINSTANCE hPrevInstance,
12 LPSTR lpszCmdLine,
13 int nCmdShow)
14 {
15 WNDCLASS wc;
16 MSG msg;
17 HWND hWnd;
18
19 wc.lpszClassName = "GuiThreadInfoClass";
20 wc.lpfnWndProc = MainWndProc;
21 wc.style = CS_VREDRAW | CS_HREDRAW;
22 wc.hInstance = hInstance;
23 wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
24 wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
25 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
26 wc.lpszMenuName = NULL;
27 wc.cbClsExtra = 0;
28 wc.cbWndExtra = 0;
29 if (RegisterClass(&wc) == 0)
30 {
31 fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
32 GetLastError());
33 return(1);
34 }
35
36 hWnd = CreateWindow("GuiThreadInfoClass",
37 "GetGUIThreadInfo",
38 WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
39 0,
40 0,
41 CW_USEDEFAULT,
42 CW_USEDEFAULT,
43 NULL,
44 NULL,
45 hInstance,
46 NULL);
47 if (hWnd == NULL)
48 {
49 fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
50 GetLastError());
51 return(1);
52 }
53
54 //tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
55 // ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
56 // DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
57
58 gti.cbSize = sizeof(GUITHREADINFO);
59 GetGUIThreadInfo(0, &gti);
60
61 SetTimer(hWnd, 1, 1000, NULL);
62 ShowWindow(hWnd, nCmdShow);
63
64 while(GetMessage(&msg, NULL, 0, 0))
65 {
66 TranslateMessage(&msg);
67 DispatchMessage(&msg);
68 }
69
70 //DeleteObject(tf);
71
72 return msg.wParam;
73 }
74
75 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
76 {
77 PAINTSTRUCT ps;
78 HDC hDC;
79 char str[255];
80
81 switch(msg)
82 {
83
84 case WM_PAINT:
85 hDC = BeginPaint(hWnd, &ps);
86 wsprintf(str, "flags: ");
87 if(gti.flags & GUI_16BITTASK) lstrcat(str, "GUI_16BITTASK ");
88 if(gti.flags & GUI_CARETBLINKING) lstrcat(str, "GUI_CARETBLINKING ");
89 if(gti.flags & GUI_INMENUMODE) lstrcat(str, "GUI_INMENUMODE ");
90 if(gti.flags & GUI_INMOVESIZE) lstrcat(str, "GUI_INMOVESIZE ");
91 if(gti.flags & GUI_POPUPMENUMODE) lstrcat(str, "GUI_POPUPMENUMODE ");
92 if(gti.flags & GUI_SYSTEMMENUMODE) lstrcat(str, "GUI_SYSTEMMENUMODE ");
93 TextOut(hDC, 10, 10, str, strlen(str));
94
95 wsprintf(str, "hwndActive == %08X", gti.hwndActive);
96 TextOut(hDC, 10, 30, str, strlen(str));
97 wsprintf(str, "hwndFocus == %08X", gti.hwndFocus);
98 TextOut(hDC, 10, 50, str, strlen(str));
99 wsprintf(str, "hwndCapture == %08X", gti.hwndCapture);
100 TextOut(hDC, 10, 70, str, strlen(str));
101 wsprintf(str, "hwndMenuOwner == %08X", gti.hwndMenuOwner);
102 TextOut(hDC, 10, 90, str, strlen(str));
103 wsprintf(str, "hwndMoveSize == %08X", gti.hwndMoveSize);
104 TextOut(hDC, 10, 110, str, strlen(str));
105 wsprintf(str, "hwndCaret == %08X", gti.hwndCaret);
106 TextOut(hDC, 10, 130, str, strlen(str));
107 wsprintf(str, "rcCaret == (%lu, %lu, %lu, %lu)", gti.rcCaret.left, gti.rcCaret.top, gti.rcCaret.right, gti.rcCaret.bottom);
108 TextOut(hDC, 10, 150, str, strlen(str));
109
110 wsprintf(str, "GetGuiResources for the current process: %08X", GetCurrentProcess());
111 TextOut(hDC, 10, 180, str, strlen(str));
112 wsprintf(str, "GetGuiResources: GR_GDIOBJECTS == %04X", GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS));
113 TextOut(hDC, 10, 200, str, strlen(str));
114 wsprintf(str, "GetGuiResources: GR_USEROBJECTS == %04x", GetGuiResources(GetCurrentProcess(), GR_USEROBJECTS));
115 TextOut(hDC, 10, 220, str, strlen(str));
116 EndPaint(hWnd, &ps);
117 break;
118
119 case WM_TIMER:
120 GetGUIThreadInfo(0, &gti);
121 InvalidateRect(hWnd, NULL, TRUE);
122 break;
123
124 case WM_DESTROY:
125 PostQuitMessage(0);
126 break;
127
128 default:
129 return DefWindowProc(hWnd, msg, wParam, lParam);
130 }
131 return 0;
132 }