msi: Fix possible free of uninitialized pointer.
[wine] / dlls / ddraw / surface_wndproc.c
1 /*      User-based primary surface driver
2  *
3  * Copyright 2000 TransGaming Technologies Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "config.h"
21
22 #include <assert.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "winerror.h"
27
28 #include "ddraw_private.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
33
34 static LRESULT WINAPI DirectDrawSurface_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
35
36 void DirectDrawSurface_RegisterClass(void)
37 {
38     WNDCLASSA wc;
39     memset(&wc, 0, sizeof(wc));
40     wc.lpfnWndProc = DirectDrawSurface_WndProc;
41     wc.cbWndExtra  = sizeof(IDirectDrawSurfaceImpl*);
42     wc.hCursor     = (HCURSOR)IDC_ARROW;
43     wc.lpszClassName = "WINE_DDRAW";
44     RegisterClassA(&wc);
45 }
46
47 void DirectDrawSurface_UnregisterClass(void)
48 {
49     UnregisterClassA("WINE_DDRAW", 0);
50 }
51
52 static LRESULT WINAPI DirectDrawSurface_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
53 {
54     IDirectDrawSurfaceImpl *This;
55     LRESULT ret;
56
57     This = (IDirectDrawSurfaceImpl *)GetWindowLongPtrA(hwnd, 0);
58     if (This) {
59         HWND window = This->ddraw_owner->window;
60
61         switch (msg) {
62         case WM_DESTROY:
63         case WM_NCDESTROY:
64         case WM_SHOWWINDOW:
65         case WM_WINDOWPOSCHANGING:
66         case WM_WINDOWPOSCHANGED:
67         case WM_SIZE:
68         case WM_MOVE:
69         case WM_ERASEBKGND:
70         case WM_SYNCPAINT:
71             /* since we're pretending fullscreen,
72              * let's not pass these on to the app */
73             ret = DefWindowProcA(hwnd, msg, wParam, lParam);
74             break;
75         case WM_NCHITTEST:
76             ret = HTCLIENT;
77             break;
78         case WM_MOUSEACTIVATE:
79             ret = MA_NOACTIVATE;
80             break;
81         case WM_PAINT:
82             {
83                 PAINTSTRUCT ps;
84                 HDC dc;
85                 dc = BeginPaint(hwnd, &ps);
86                 /* call User_copy_to_screen? */
87                 EndPaint(hwnd, &ps);
88                 ret = 0;
89             }
90             break;
91         default:
92             ret = window ? SendMessageA(window, msg, wParam, lParam)
93                          : DefWindowProcA(hwnd, msg, wParam, lParam);
94         }
95     } else {
96         if (msg == WM_CREATE) {
97             CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
98             This = (IDirectDrawSurfaceImpl *)cs->lpCreateParams;
99             SetWindowLongPtrA(hwnd, 0, (LONG_PTR)This);
100         }
101         ret = DefWindowProcA(hwnd, msg, wParam, lParam);
102     }
103     return ret;
104 }