Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
86 lines (71 loc) · 2.02 KB

testnativew32.c

File metadata and controls

86 lines (71 loc) · 2.02 KB
 
Apr 8, 2011
Apr 8, 2011
1
2
3
4
5
6
7
8
9
10
11
/*
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
12
13
14
#include "testnative.h"
Jan 21, 2011
Jan 21, 2011
15
#ifdef TEST_NATIVE_WINDOWS
Jan 21, 2011
Jan 21, 2011
17
18
static void *CreateWindowNative(int w, int h);
static void DestroyWindowNative(void *window);
Jan 21, 2011
Jan 21, 2011
20
21
22
23
NativeWindowFactory WindowsWindowFactory = {
"windows",
CreateWindowNative,
DestroyWindowNative
Feb 17, 2009
Feb 17, 2009
26
27
LRESULT CALLBACK
WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Feb 9, 2009
Feb 9, 2009
28
{
Feb 17, 2009
Feb 17, 2009
29
30
31
switch (msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
Feb 9, 2009
Feb 9, 2009
32
break;
Feb 17, 2009
Feb 17, 2009
33
34
case WM_DESTROY:
PostQuitMessage(0);
Feb 9, 2009
Feb 9, 2009
35
break;
Feb 17, 2009
Feb 17, 2009
36
37
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
Feb 9, 2009
Feb 9, 2009
38
39
40
}
return 0;
}
41
42
static void *
Jan 21, 2011
Jan 21, 2011
43
CreateWindowNative(int w, int h)
Feb 9, 2009
Feb 9, 2009
45
46
47
HWND hwnd;
WNDCLASS wc;
Feb 17, 2009
Feb 17, 2009
48
49
50
51
52
53
54
55
56
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
Feb 9, 2009
Feb 9, 2009
57
58
wc.lpszClassName = "SDL Test";
Feb 17, 2009
Feb 17, 2009
59
if (!RegisterClass(&wc)) {
Feb 9, 2009
Feb 9, 2009
60
MessageBox(NULL, "Window Registration Failed!", "Error!",
Feb 17, 2009
Feb 17, 2009
61
MB_ICONEXCLAMATION | MB_OK);
Feb 9, 2009
Feb 9, 2009
62
63
64
return 0;
}
Feb 17, 2009
Feb 17, 2009
65
66
67
68
69
hwnd =
CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
NULL);
if (hwnd == NULL) {
Feb 9, 2009
Feb 9, 2009
70
MessageBox(NULL, "Window Creation Failed!", "Error!",
Feb 17, 2009
Feb 17, 2009
71
MB_ICONEXCLAMATION | MB_OK);
Feb 9, 2009
Feb 9, 2009
72
73
74
75
76
77
return 0;
}
ShowWindow(hwnd, SW_SHOW);
return hwnd;
78
79
80
}
static void
Jan 21, 2011
Jan 21, 2011
81
DestroyWindowNative(void *window)
Feb 17, 2009
Feb 17, 2009
83
DestroyWindow((HWND) window);
84
85
86
}
#endif