1a4a59ad4SBaruch Rutman /*
2a4a59ad4SBaruch Rutman  * PROJECT:         ReactOS Tests
3a4a59ad4SBaruch Rutman  * FILE:            rostests/win32/user32/biditext/biditext.c
4a4a59ad4SBaruch Rutman  * PURPOSE:         Demonstrates how ExtTextOut and GetCharacterPlacement
5a4a59ad4SBaruch Rutman  *                  handle bidirectional text strings via certain selection
6a4a59ad4SBaruch Rutman  *                  of flags provided to them.
7a4a59ad4SBaruch Rutman  *
8a4a59ad4SBaruch Rutman  * PROGRAMMER:      Program skeleton: https://github.com/TransmissionZero/MinGW-Win32-Application
9a4a59ad4SBaruch Rutman  *                  Test code by Baruch Rutman
10a4a59ad4SBaruch Rutman  */
11a4a59ad4SBaruch Rutman 
12a4a59ad4SBaruch Rutman #include "biditext.h"
13a4a59ad4SBaruch Rutman 
14a4a59ad4SBaruch Rutman /* Prototypes */
15a4a59ad4SBaruch Rutman DWORD WINAPI LpkGetCharacterPlacement(HDC hdc, LPCWSTR lpString, INT uCount, INT nMaxExtent,
16a4a59ad4SBaruch Rutman                                       GCP_RESULTSW *lpResults, DWORD dwFlags, DWORD dwUnused);
17a4a59ad4SBaruch Rutman 
18a4a59ad4SBaruch Rutman BOOL WINAPI LpkExtTextOut(HDC hdc, int x, int y,
19a4a59ad4SBaruch Rutman                           UINT fuOptions, const RECT *lprc, LPCWSTR lpString,
20a4a59ad4SBaruch Rutman                           UINT uCount , const INT *lpDx, INT unknown);
21a4a59ad4SBaruch Rutman 
22a4a59ad4SBaruch Rutman /* Global instance handle */
23a4a59ad4SBaruch Rutman HINSTANCE g_hInstance = NULL;
24a4a59ad4SBaruch Rutman 
25a4a59ad4SBaruch Rutman /* Our application entry point */
26a4a59ad4SBaruch Rutman int WINAPI
wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpszCmdLine,int nCmdShow)27a4a59ad4SBaruch Rutman wWinMain(HINSTANCE hInstance,
28a4a59ad4SBaruch Rutman           HINSTANCE hPrevInstance,
29a4a59ad4SBaruch Rutman           LPTSTR lpszCmdLine,
30a4a59ad4SBaruch Rutman           int nCmdShow)
31a4a59ad4SBaruch Rutman {
32a4a59ad4SBaruch Rutman   INITCOMMONCONTROLSEX icc;
33a4a59ad4SBaruch Rutman   HWND hWnd;
34a4a59ad4SBaruch Rutman   HACCEL hAccelerators;
35a4a59ad4SBaruch Rutman   MSG msg;
36a4a59ad4SBaruch Rutman 
37a4a59ad4SBaruch Rutman   /* Assign global HINSTANCE */
38a4a59ad4SBaruch Rutman   g_hInstance = hInstance;
39a4a59ad4SBaruch Rutman 
40a4a59ad4SBaruch Rutman   /* Initialise common controls */
41a4a59ad4SBaruch Rutman   icc.dwSize = sizeof(icc);
42a4a59ad4SBaruch Rutman   icc.dwICC = ICC_WIN95_CLASSES;
43a4a59ad4SBaruch Rutman   InitCommonControlsEx(&icc);
44a4a59ad4SBaruch Rutman 
45a4a59ad4SBaruch Rutman   /* Register our main window class, or error */
46a4a59ad4SBaruch Rutman   if (!RegisterMainWindowClass())
47a4a59ad4SBaruch Rutman   {
48a4a59ad4SBaruch Rutman     MessageBox(NULL, TEXT("Error registering main window class."), TEXT("Error"), MB_ICONERROR | MB_OK);
49a4a59ad4SBaruch Rutman     return 0;
50a4a59ad4SBaruch Rutman   }
51a4a59ad4SBaruch Rutman 
52a4a59ad4SBaruch Rutman   /* Create our main window, or error */
53a4a59ad4SBaruch Rutman   if (!(hWnd = CreateMainWindow()))
54a4a59ad4SBaruch Rutman   {
55a4a59ad4SBaruch Rutman     MessageBox(NULL, TEXT("Error creating main window."), TEXT("Error"), MB_ICONERROR | MB_OK);
56a4a59ad4SBaruch Rutman     return 0;
57a4a59ad4SBaruch Rutman   }
58a4a59ad4SBaruch Rutman 
59a4a59ad4SBaruch Rutman   /* Load accelerators */
60a4a59ad4SBaruch Rutman   hAccelerators = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));
61a4a59ad4SBaruch Rutman 
62a4a59ad4SBaruch Rutman   /* Show main window and force a paint */
631fc041c9SBaruch Rutman   ShowWindow(hWnd, nCmdShow | SW_MAXIMIZE);
64a4a59ad4SBaruch Rutman   UpdateWindow(hWnd);
65a4a59ad4SBaruch Rutman 
66a4a59ad4SBaruch Rutman   /* Main message loop */
67a4a59ad4SBaruch Rutman   while (GetMessage(&msg, NULL, 0, 0) > 0)
68a4a59ad4SBaruch Rutman   {
69a4a59ad4SBaruch Rutman     if (!TranslateAccelerator(hWnd, hAccelerators, &msg))
70a4a59ad4SBaruch Rutman     {
71a4a59ad4SBaruch Rutman       TranslateMessage(&msg);
72a4a59ad4SBaruch Rutman       DispatchMessage(&msg);
73a4a59ad4SBaruch Rutman     }
74a4a59ad4SBaruch Rutman   }
75a4a59ad4SBaruch Rutman 
76a4a59ad4SBaruch Rutman   return (int)msg.wParam;
77a4a59ad4SBaruch Rutman }
78a4a59ad4SBaruch Rutman 
79a4a59ad4SBaruch Rutman /* Dialog procedure for our "about" dialog */
AboutDialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)80a4a59ad4SBaruch Rutman INT_PTR CALLBACK AboutDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
81a4a59ad4SBaruch Rutman {
82a4a59ad4SBaruch Rutman   switch (uMsg)
83a4a59ad4SBaruch Rutman   {
84a4a59ad4SBaruch Rutman     case WM_COMMAND:
85a4a59ad4SBaruch Rutman     {
86a4a59ad4SBaruch Rutman       WORD id = LOWORD(wParam);
87a4a59ad4SBaruch Rutman 
88a4a59ad4SBaruch Rutman       switch (id)
89a4a59ad4SBaruch Rutman       {
90a4a59ad4SBaruch Rutman         case IDOK:
91a4a59ad4SBaruch Rutman         case IDCANCEL:
92a4a59ad4SBaruch Rutman         {
93a4a59ad4SBaruch Rutman           EndDialog(hwndDlg, (INT_PTR)id);
94a4a59ad4SBaruch Rutman           return (INT_PTR)TRUE;
95a4a59ad4SBaruch Rutman         }
96a4a59ad4SBaruch Rutman       }
97a4a59ad4SBaruch Rutman       break;
98a4a59ad4SBaruch Rutman     }
99a4a59ad4SBaruch Rutman 
100a4a59ad4SBaruch Rutman     case WM_INITDIALOG:
101a4a59ad4SBaruch Rutman     {
102a4a59ad4SBaruch Rutman       return (INT_PTR)TRUE;
103a4a59ad4SBaruch Rutman     }
104a4a59ad4SBaruch Rutman   }
105a4a59ad4SBaruch Rutman 
106a4a59ad4SBaruch Rutman   return (INT_PTR)FALSE;
107a4a59ad4SBaruch Rutman }
108a4a59ad4SBaruch Rutman 
109a4a59ad4SBaruch Rutman /* Show our "about" dialog */
ShowAboutDialog(HWND owner)110a4a59ad4SBaruch Rutman void ShowAboutDialog(HWND owner)
111a4a59ad4SBaruch Rutman {
112a4a59ad4SBaruch Rutman   DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), owner, &AboutDialogProc);
113a4a59ad4SBaruch Rutman }
114a4a59ad4SBaruch Rutman 
115a4a59ad4SBaruch Rutman /* Main window class and title */
116a4a59ad4SBaruch Rutman static LPCTSTR MainWndClass = TEXT("BiDi Test");
117a4a59ad4SBaruch Rutman 
118a4a59ad4SBaruch Rutman /* Window procedure for our main window */
MainWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)119a4a59ad4SBaruch Rutman LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
120a4a59ad4SBaruch Rutman {
121a4a59ad4SBaruch Rutman   switch (msg)
122a4a59ad4SBaruch Rutman   {
123a4a59ad4SBaruch Rutman     case WM_COMMAND:
124a4a59ad4SBaruch Rutman     {
125a4a59ad4SBaruch Rutman       WORD id = LOWORD(wParam);
126a4a59ad4SBaruch Rutman 
127a4a59ad4SBaruch Rutman       switch (id)
128a4a59ad4SBaruch Rutman       {
129a4a59ad4SBaruch Rutman         case ID_HELP_ABOUT:
130a4a59ad4SBaruch Rutman         {
131a4a59ad4SBaruch Rutman           ShowAboutDialog(hWnd);
132a4a59ad4SBaruch Rutman           return 0;
133a4a59ad4SBaruch Rutman         }
134a4a59ad4SBaruch Rutman 
135a4a59ad4SBaruch Rutman         case ID_FILE_EXIT:
136a4a59ad4SBaruch Rutman         {
137a4a59ad4SBaruch Rutman           DestroyWindow(hWnd);
138a4a59ad4SBaruch Rutman           return 0;
139a4a59ad4SBaruch Rutman         }
140a4a59ad4SBaruch Rutman       }
141a4a59ad4SBaruch Rutman       break;
142a4a59ad4SBaruch Rutman     }
143a4a59ad4SBaruch Rutman 
144a4a59ad4SBaruch Rutman     case WM_GETMINMAXINFO:
145a4a59ad4SBaruch Rutman     {
146a4a59ad4SBaruch Rutman       /* Prevent our window from being sized too small */
147a4a59ad4SBaruch Rutman       MINMAXINFO *minMax = (MINMAXINFO*)lParam;
148a4a59ad4SBaruch Rutman       minMax->ptMinTrackSize.x = 220;
149a4a59ad4SBaruch Rutman       minMax->ptMinTrackSize.y = 110;
150a4a59ad4SBaruch Rutman 
151a4a59ad4SBaruch Rutman       return 0;
152a4a59ad4SBaruch Rutman     }
153a4a59ad4SBaruch Rutman 
154a4a59ad4SBaruch Rutman     /* Item from system menu has been invoked */
155a4a59ad4SBaruch Rutman     case WM_SYSCOMMAND:
156a4a59ad4SBaruch Rutman     {
157a4a59ad4SBaruch Rutman       WORD id = LOWORD(wParam);
158a4a59ad4SBaruch Rutman 
159a4a59ad4SBaruch Rutman       switch (id)
160a4a59ad4SBaruch Rutman       {
161a4a59ad4SBaruch Rutman         /* Show "about" dialog on about system menu item */
162a4a59ad4SBaruch Rutman         case ID_HELP_ABOUT:
163a4a59ad4SBaruch Rutman         {
164a4a59ad4SBaruch Rutman           ShowAboutDialog(hWnd);
165a4a59ad4SBaruch Rutman           return 0;
166a4a59ad4SBaruch Rutman         }
167a4a59ad4SBaruch Rutman       }
168a4a59ad4SBaruch Rutman       break;
169a4a59ad4SBaruch Rutman     }
170a4a59ad4SBaruch Rutman 
171a4a59ad4SBaruch Rutman     case WM_PAINT:
172a4a59ad4SBaruch Rutman         {
173a4a59ad4SBaruch Rutman             PAINTSTRUCT ps;
174a4a59ad4SBaruch Rutman 
175a4a59ad4SBaruch Rutman             HDC hdc = BeginPaint(hWnd, &ps);
176a4a59ad4SBaruch Rutman 
1771fc041c9SBaruch Rutman             enum
1781fc041c9SBaruch Rutman             {
1791fc041c9SBaruch Rutman                 ALEF = 0x5D0,
1801fc041c9SBaruch Rutman                 BET,
1811fc041c9SBaruch Rutman                 GIMEL,
1821fc041c9SBaruch Rutman                 DALET,
1831fc041c9SBaruch Rutman                 HEY,
1841fc041c9SBaruch Rutman                 VAV,
1851fc041c9SBaruch Rutman                 ZAYIN,
1861fc041c9SBaruch Rutman                 HET,
1871fc041c9SBaruch Rutman                 TET,
1881fc041c9SBaruch Rutman                 YUD
1891fc041c9SBaruch Rutman             };
190a4a59ad4SBaruch Rutman 
1911fc041c9SBaruch Rutman             const WCHAR szString[] = {ALEF, BET, GIMEL, DALET, HEY, 'A', 'B', 'C', 'D', VAV, ZAYIN, HET, TET, YUD, 0};
1921fc041c9SBaruch Rutman             const WCHAR szReversedString[] = {HEY, DALET, GIMEL, BET, ALEF, 'A', 'B', 'C', 'D', YUD, TET, HET, ZAYIN, VAV, 0};
193*42d2d5ecSTimo Kreuzer             int Len = lstrlenW(szString);
1941fc041c9SBaruch Rutman             int i, xpos, tempLength;
1951fc041c9SBaruch Rutman             WCHAR tempString[20] = { 0 };
196a4a59ad4SBaruch Rutman             WCHAR Glyphs[100] = { 0 };
197a4a59ad4SBaruch Rutman             WCHAR OutString[100] = { 0 };
1981fc041c9SBaruch Rutman             INT lpCaretPos[100] = { 0 };
1991fc041c9SBaruch Rutman             UINT lpOrder[100] = { 0 };
200a4a59ad4SBaruch Rutman             GCP_RESULTSW Results = { 0 };
2011fc041c9SBaruch Rutman 
202a4a59ad4SBaruch Rutman             Results.lStructSize = sizeof(Results);
203a4a59ad4SBaruch Rutman             Results.lpOutString = OutString;
204a4a59ad4SBaruch Rutman             Results.lpGlyphs = Glyphs;
205a4a59ad4SBaruch Rutman             Results.nGlyphs = 100;
2061fc041c9SBaruch Rutman             Results.lpCaretPos = lpCaretPos;
2071fc041c9SBaruch Rutman             Results.lpOrder = lpOrder;
2081fc041c9SBaruch Rutman 
2091fc041c9SBaruch Rutman             SetBkMode(hdc, TRANSPARENT);
210a4a59ad4SBaruch Rutman 
211a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 10, L"Proper (string being used):", 27);
212a4a59ad4SBaruch Rutman             TextOutW(hdc, 200, 10, szString, 14);
213a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 30, L"Reversed (example):", 19);
2141fc041c9SBaruch Rutman             TextOutW(hdc, 200, 30, szReversedString, 14);
215a4a59ad4SBaruch Rutman 
216a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 50, L"String with NULL LpkETO call (not reversed):", 44);
217a4a59ad4SBaruch Rutman             LpkExtTextOut(hdc, 10, 70, 0, NULL, szString, Len, NULL, 0);
218a4a59ad4SBaruch Rutman 
219a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 90, L"String with ETO_IGNORELANGUAGE LpkETO call (not reversed):", 58);
220a4a59ad4SBaruch Rutman             LpkExtTextOut(hdc, 10, 110, ETO_IGNORELANGUAGE, NULL, szString, Len, NULL, 0);
221a4a59ad4SBaruch Rutman 
222a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 130, L"String with GCP_REORDER and ETO_GLYPH_INDEX LpkGCP call (not reversed):", 71);
223a4a59ad4SBaruch Rutman             LpkGetCharacterPlacement(hdc, szString, Len, 0, &Results, GCP_REORDER, 0);
224a4a59ad4SBaruch Rutman             LpkExtTextOut(hdc, 10, 150, ETO_GLYPH_INDEX, NULL, Glyphs, Results.nGlyphs, NULL, 0);
225a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 170, L"String with GCP_REORDER and ETO_IGNORELANGUAGE LpkGCP call (not reversed, lpOutString):", 87);
226a4a59ad4SBaruch Rutman             ExtTextOutW(hdc, 10, 190, ETO_IGNORELANGUAGE, NULL, OutString, Results.nGlyphs, NULL);
227a4a59ad4SBaruch Rutman 
228a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 210, L"String without GCP_REORDER and ETO_GLYPH_INDEX LpkGCP call (reversed):", 70);
229a4a59ad4SBaruch Rutman             LpkGetCharacterPlacement(hdc, szString, Len, 0, &Results, 0, 0);
230a4a59ad4SBaruch Rutman             LpkExtTextOut(hdc, 10, 230, ETO_GLYPH_INDEX, NULL, Glyphs, Results.nGlyphs, NULL, 0);
231a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 250, L"String without GCP_REORDER and ETO_IGNORELANGUAGE LpkGCP call (reversed, lpOutString):", 86);
232a4a59ad4SBaruch Rutman             ExtTextOutW(hdc, 10, 270, ETO_IGNORELANGUAGE, NULL, OutString, Len, NULL);
233a4a59ad4SBaruch Rutman 
234a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 290, L"String with ETO_IGNORELANGUAGE ETO call (reversed, not Lpk direct call!):", 73);
235a4a59ad4SBaruch Rutman             ExtTextOutW(hdc, 10, 310, ETO_IGNORELANGUAGE, NULL, szString, Len, NULL);
236a4a59ad4SBaruch Rutman 
237a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 330, L"String with ETO_RTLREADING LpkETO call (slight order change)", 60);
238a4a59ad4SBaruch Rutman             LpkExtTextOut(hdc, 10, 350, ETO_RTLREADING, NULL, szString, Len, NULL, 0);
239a4a59ad4SBaruch Rutman 
240a4a59ad4SBaruch Rutman             TextOutW(hdc, 10, 370, L"String with ETO_RTLREADING ETO call (slight order change)", 57);
241a4a59ad4SBaruch Rutman             ExtTextOutW(hdc, 10, 390, ETO_RTLREADING, NULL, szString, Len, NULL);
242a4a59ad4SBaruch Rutman 
2431fc041c9SBaruch Rutman             GetCharacterPlacementW(hdc, szString, Len, 0, &Results, GCP_REORDER);
2441fc041c9SBaruch Rutman             TextOutW(hdc, 10, 410, L"Glyph positions with GCP_REORDER flag", 37);
2451fc041c9SBaruch Rutman 
2461fc041c9SBaruch Rutman             /* Prints per column the location of the character in the string, reordered location, its position and the character itself */
2471fc041c9SBaruch Rutman             for (i = 0, xpos = 10; i < Len; i++, xpos += 30)
2481fc041c9SBaruch Rutman             {
2491fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", i);
250*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2511fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 430, tempString, tempLength);
2521fc041c9SBaruch Rutman 
2531fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", lpOrder[i]);
254*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2551fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 450, tempString, tempLength);
2561fc041c9SBaruch Rutman 
2571fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", lpCaretPos[i]);
258*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2591fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 470, tempString, tempLength);
2601fc041c9SBaruch Rutman 
2611fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 490, &szString[i], 1);
2621fc041c9SBaruch Rutman             }
2631fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 430, L"Character location", 18);
2641fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 450, L"lpOrder[i]", 10);
2651fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 470, L"lpCaretPos[i]", 13);
2661fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 490, L"String[i]", 9);
2671fc041c9SBaruch Rutman 
2681fc041c9SBaruch Rutman             GetCharacterPlacementW(hdc, szString, Len, 0, &Results, 0);
2691fc041c9SBaruch Rutman             TextOutW(hdc, 10, 510, L"Glyph positions without GCP_REORDER flag", 40);
2701fc041c9SBaruch Rutman 
2711fc041c9SBaruch Rutman             for (i = 0, xpos = 10; i < Len; i++, xpos += 30)
2721fc041c9SBaruch Rutman             {
2731fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", i);
274*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2751fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 530, tempString, tempLength);
2761fc041c9SBaruch Rutman 
2771fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", lpOrder[i]);
278*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2791fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 550, tempString, tempLength);
2801fc041c9SBaruch Rutman 
2811fc041c9SBaruch Rutman                 StringCchPrintfW(tempString, 20, L"%d", lpCaretPos[i]);
282*42d2d5ecSTimo Kreuzer                 tempLength = lstrlenW(tempString);
2831fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 570, tempString, tempLength);
2841fc041c9SBaruch Rutman 
2851fc041c9SBaruch Rutman                 TextOutW(hdc, xpos, 590, &szString[i], 1);
2861fc041c9SBaruch Rutman             }
2871fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 530, L"Character location", 18);
2881fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 550, L"lpOrder[i]", 10);
2891fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 570, L"lpCaretPos[i]", 13);
2901fc041c9SBaruch Rutman             TextOutW(hdc, xpos, 590, L"String[i]", 9);
2911fc041c9SBaruch Rutman 
292a4a59ad4SBaruch Rutman             EndPaint(hWnd, &ps);
293a4a59ad4SBaruch Rutman             break;
294a4a59ad4SBaruch Rutman         }
295a4a59ad4SBaruch Rutman 
296a4a59ad4SBaruch Rutman     case WM_DESTROY:
297a4a59ad4SBaruch Rutman     {
298a4a59ad4SBaruch Rutman       PostQuitMessage(0);
299a4a59ad4SBaruch Rutman       return 0;
300a4a59ad4SBaruch Rutman     }
301a4a59ad4SBaruch Rutman   }
302a4a59ad4SBaruch Rutman 
303a4a59ad4SBaruch Rutman   return DefWindowProc(hWnd, msg, wParam, lParam);
304a4a59ad4SBaruch Rutman }
305a4a59ad4SBaruch Rutman 
306a4a59ad4SBaruch Rutman /* Register a class for our main window */
RegisterMainWindowClass()307a4a59ad4SBaruch Rutman BOOL RegisterMainWindowClass()
308a4a59ad4SBaruch Rutman {
309a4a59ad4SBaruch Rutman   WNDCLASSEX wc;
310a4a59ad4SBaruch Rutman 
311a4a59ad4SBaruch Rutman   /* Class for our main window */
312a4a59ad4SBaruch Rutman   wc.cbSize        = sizeof(wc);
313a4a59ad4SBaruch Rutman   wc.style         = 0;
314a4a59ad4SBaruch Rutman   wc.lpfnWndProc   = &MainWndProc;
315a4a59ad4SBaruch Rutman   wc.cbClsExtra    = 0;
316a4a59ad4SBaruch Rutman   wc.cbWndExtra    = 0;
317a4a59ad4SBaruch Rutman   wc.hInstance     = g_hInstance;
318a4a59ad4SBaruch Rutman   wc.hIcon         = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_APPICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE |
319a4a59ad4SBaruch Rutman                                       LR_DEFAULTCOLOR | LR_SHARED);
320a4a59ad4SBaruch Rutman   wc.hCursor       = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
321a4a59ad4SBaruch Rutman   wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
322a4a59ad4SBaruch Rutman   wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MAINMENU);
323a4a59ad4SBaruch Rutman   wc.lpszClassName = MainWndClass;
324a4a59ad4SBaruch Rutman   wc.hIconSm       = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_APPICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
325a4a59ad4SBaruch Rutman 
326a4a59ad4SBaruch Rutman   return (RegisterClassEx(&wc)) ? TRUE : FALSE;
327a4a59ad4SBaruch Rutman }
328a4a59ad4SBaruch Rutman 
329a4a59ad4SBaruch Rutman /* Create an instance of our main window */
CreateMainWindow()330a4a59ad4SBaruch Rutman HWND CreateMainWindow()
331a4a59ad4SBaruch Rutman {
332a4a59ad4SBaruch Rutman   /* Create instance of main window */
333a4a59ad4SBaruch Rutman   HWND hWnd = CreateWindowEx(0, MainWndClass, MainWndClass, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
334a4a59ad4SBaruch Rutman                              NULL, NULL, g_hInstance, NULL);
335a4a59ad4SBaruch Rutman 
336a4a59ad4SBaruch Rutman   if (hWnd)
337a4a59ad4SBaruch Rutman   {
338a4a59ad4SBaruch Rutman     /* Add "about" to the system menu */
339a4a59ad4SBaruch Rutman     HMENU hSysMenu = GetSystemMenu(hWnd, FALSE);
340a4a59ad4SBaruch Rutman     InsertMenu(hSysMenu, 5, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
341a4a59ad4SBaruch Rutman     InsertMenu(hSysMenu, 6, MF_BYPOSITION, ID_HELP_ABOUT, TEXT("About"));
342a4a59ad4SBaruch Rutman   }
343a4a59ad4SBaruch Rutman 
344a4a59ad4SBaruch Rutman   return hWnd;
345a4a59ad4SBaruch Rutman }
346