Changed the GDI driver interface to pass an opaque PHYSDEV pointer
[wine] / libtest / hello3.c
1 /*
2  * Copyright 1995 Martin von Loewis
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <windows.h>
20 #include <commdlg.h>
21
22 typedef struct
23 {
24   HANDLE  hInstance;
25   HWND    hMainWnd;
26   HMENU   hMainMenu;
27 } GLOBALS;
28
29 GLOBALS Globals;
30
31 BOOL FileOpen(HWND hWnd)
32 {
33   char filename[80] = "test.c";
34   OPENFILENAME ofn = { sizeof(OPENFILENAME),
35                        hWnd, NULL, "C code\0*.c\0", NULL, 0, 0, filename, 80,
36                        NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
37                        OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
38   return GetOpenFileName(&ofn);
39 }
40
41 LRESULT CALLBACK DlgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
42 {
43     switch(msg)
44     {
45         case WM_INITDIALOG:
46             break;
47         case WM_COMMAND:
48             switch (wParam)
49             {
50                 case 100:
51                     EndDialog(hWnd, 100);
52                     return TRUE;
53             }
54     }
55     return FALSE;
56 }
57
58 LRESULT CALLBACK WndProc (HWND wnd, UINT msg, WPARAM w, LPARAM l)
59 {
60     switch (msg){
61
62         case WM_COMMAND:
63         switch(w){
64                 case 100:
65                         DialogBox(Globals.hInstance,
66                                 "DIADEMO", wnd,
67                                 (DLGPROC)DlgProc);
68                         return 0;
69                 case 101:
70                 {
71                         HDC hdc, hMemDC;
72                         HBITMAP hBitmap, hPrevBitmap;
73                         BITMAP bmp;
74
75                         hBitmap = LoadBitmapA (Globals.hInstance, "BITDEMO");
76                         hdc = GetDC (wnd);
77                         hMemDC = CreateCompatibleDC (hdc);
78                         hPrevBitmap = SelectObject (hMemDC, hBitmap);
79                         GetObjectA (hBitmap, sizeof(BITMAP), &bmp);
80                         BitBlt (hdc, 0, 0, bmp.bmWidth, bmp.bmHeight,
81                                 hMemDC, 0, 0, SRCCOPY);
82                         SelectObject (hMemDC, hPrevBitmap);
83                         DeleteDC (hMemDC);
84                         ReleaseDC (wnd, hdc);
85                         return 0;
86                 }
87                 case 102:
88                         FileOpen(wnd);
89                         return 0;
90                 default:
91                         return DefWindowProc (wnd, msg, w, l);
92         }
93     case WM_DESTROY:
94         PostQuitMessage (0);
95         break;
96
97     default:
98         return DefWindowProc (wnd, msg, w, l);
99     }
100     return 0l;
101 }
102
103 int PASCAL WinMain (HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
104 {
105     MSG      msg;
106     WNDCLASS class;
107     char className[] = "class";  /* To make sure className >= 0x10000 */
108     char winName[] = "Test app";
109
110     Globals.hInstance = inst;
111     if (!prev){
112         class.style = CS_HREDRAW | CS_VREDRAW;
113         class.lpfnWndProc = WndProc;
114         class.cbClsExtra = 0;
115         class.cbWndExtra = 0;
116         class.hInstance  = inst;
117         class.hIcon      = LoadIcon (0, IDI_APPLICATION);
118         class.hCursor    = LoadCursor (0, IDC_ARROW);
119         class.hbrBackground = GetStockObject (WHITE_BRUSH);
120         class.lpszMenuName = 0;
121         class.lpszClassName = className;
122     }
123     if (!RegisterClass (&class))
124         return FALSE;
125
126     Globals.hMainWnd = CreateWindow (className, winName, WS_OVERLAPPEDWINDOW,
127                         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 
128                         LoadMenu(inst,"MAIN"), inst, 0);
129     ShowWindow (Globals.hMainWnd, show);
130     UpdateWindow (Globals.hMainWnd);
131
132     while (GetMessage (&msg, 0, 0, 0)){
133         TranslateMessage (&msg);
134         DispatchMessage (&msg);
135     }
136     return 0;
137 }