Updated documentation to reflect renamed header.
[wine] / libtest / hello3.c
1 #include <windows.h>
2 #include <commdlg.h>
3
4 typedef struct
5 {
6   HANDLE  hInstance;
7   HWND    hMainWnd;
8   HMENU   hMainMenu;
9 } GLOBALS;
10
11 GLOBALS Globals;
12
13 BOOL FileOpen(HWND hWnd)
14 {
15   char filename[80] = "test.c";
16   OPENFILENAME ofn = { sizeof(OPENFILENAME),
17                        hWnd, NULL, "C code\0*.c\0", NULL, 0, 0, filename, 80,
18                        NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
19                        OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
20   return GetOpenFileName(&ofn);
21 }
22
23 LRESULT CALLBACK DlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
24 {
25     switch(msg)
26     {
27         case WM_INITDIALOG:
28             break;
29         case WM_COMMAND:
30             switch (wParam)
31             {
32                 case 100:
33                     EndDialog(hWnd, 100);
34                     return TRUE;
35             }
36     }
37     return FALSE;
38 }
39
40 LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
41 {
42     switch (msg){
43
44         case WM_COMMAND:
45         switch(w){
46                 case 100:
47                         DialogBox(Globals.hInstance,
48                                 "DIADEMO", wnd,
49                                 (DLGPROC)DlgProc);
50                         return 0;
51                 case 101:
52                 {
53                         HDC hdc, hMemDC;
54                         HBITMAP hBitmap, hPrevBitmap;
55                         BITMAP bmp;
56
57                         hBitmap = LoadBitmapA (Globals.hInstance, "BITDEMO");
58                         hdc = GetDC (wnd);
59                         hMemDC = CreateCompatibleDC (hdc);
60                         hPrevBitmap = SelectObject (hMemDC, hBitmap);
61                         GetObjectA (hBitmap, sizeof(BITMAP), &bmp);
62                         BitBlt (hdc, 0, 0, bmp.bmWidth, bmp.bmHeight,
63                                 hMemDC, 0, 0, SRCCOPY);
64                         SelectObject (hMemDC, hPrevBitmap);
65                         DeleteDC (hMemDC);
66                         ReleaseDC (wnd, hdc);
67                         return 0;
68                 }
69                 case 102:
70                         FileOpen(wnd);
71                         return 0;
72                 default:
73                         return DefWindowProc (wnd, msg, w, l);
74         }
75     case WM_DESTROY:
76         PostQuitMessage (0);
77         break;
78
79     default:
80         return DefWindowProc (wnd, msg, w, l);
81     }
82     return 0l;
83 }
84
85 int PASCAL WinMain (HANDLE inst, HANDLE prev, LPSTR cmdline, int show)
86 {
87     MSG      msg;
88     WNDCLASS class;
89     char className[] = "class";  /* To make sure className >= 0x10000 */
90     char winName[] = "Test app";
91
92     Globals.hInstance = inst;
93     if (!prev){
94         class.style = CS_HREDRAW | CS_VREDRAW;
95         class.lpfnWndProc = WndProc;
96         class.cbClsExtra = 0;
97         class.cbWndExtra = 0;
98         class.hInstance  = inst;
99         class.hIcon      = LoadIcon (0, IDI_APPLICATION);
100         class.hCursor    = LoadCursor (0, IDC_ARROW);
101         class.hbrBackground = GetStockObject (WHITE_BRUSH);
102         class.lpszMenuName = 0;
103         class.lpszClassName = className;
104     }
105     if (!RegisterClass (&class))
106         return FALSE;
107
108     Globals.hMainWnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW,
109                         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 
110                         LoadMenu(inst,"MAIN"), inst, 0);
111     ShowWindow (Globals.hMainWnd, show);
112     UpdateWindow (Globals.hMainWnd);
113
114     while (GetMessage (&msg, 0, 0, 0)){
115         TranslateMessage (&msg);
116         DispatchMessage (&msg);
117     }
118     return 0;
119 }