rev |
line source |
nuclear@60
|
1 #include <string.h>
|
nuclear@60
|
2 #include <windows.h>
|
nuclear@60
|
3 #include "minwin.h"
|
nuclear@60
|
4
|
nuclear@60
|
5 #define GOATSCE_WCLASS "goatsce-window"
|
nuclear@60
|
6
|
nuclear@60
|
7 struct MinWidget {
|
nuclear@60
|
8 HWND win;
|
nuclear@60
|
9
|
nuclear@60
|
10 MWCallback cbfunc;
|
nuclear@60
|
11 void *cbcls;
|
nuclear@60
|
12
|
nuclear@60
|
13 MinWidget() { win = 0; cbfunc = 0; cbcls = 0; }
|
nuclear@60
|
14 };
|
nuclear@60
|
15
|
nuclear@60
|
16 static void init();
|
nuclear@60
|
17 static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam);
|
nuclear@60
|
18
|
nuclear@60
|
19 void mw_set_callback(MinWidget *w, MWCallback func, void *cls)
|
nuclear@60
|
20 {
|
nuclear@60
|
21 w->cbfunc = func;
|
nuclear@60
|
22 w->cbcls = cls;
|
nuclear@60
|
23 }
|
nuclear@60
|
24
|
nuclear@60
|
25 MinWidget *mw_create_window(MinWidget *parent, const char *name)
|
nuclear@60
|
26 {
|
nuclear@60
|
27 MinWidget *w = new MinWidget;
|
nuclear@60
|
28 HINSTANCE inst = GetModuleHandle(0);
|
nuclear@60
|
29
|
nuclear@60
|
30 w->win = CreateWindowA(GOATSCE_WCLASS, "Goat3D Scene export options ...", WS_OVERLAPPED,
|
nuclear@60
|
31 CW_USEDEFAULT, CW_USEDEFAULT, 512, 400, parent ? parent->win : 0, 0, inst, 0);
|
nuclear@60
|
32 ShowWindow(w->win, 1);
|
nuclear@60
|
33
|
nuclear@60
|
34 return w;
|
nuclear@60
|
35 }
|
nuclear@60
|
36
|
nuclear@60
|
37 MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz)
|
nuclear@60
|
38 {
|
nuclear@60
|
39 MinWidget *bn = new MinWidget;
|
nuclear@60
|
40 HINSTANCE inst = GetModuleHandle(0);
|
nuclear@60
|
41
|
nuclear@60
|
42 bn->win = CreateWindowA("BUTTON", text, BS_PUSHBUTTON | BS_TEXT,
|
nuclear@60
|
43 x, y, xsz, ysz, parent ? parent->win : 0, 0, inst, 0);
|
nuclear@60
|
44 ShowWindow(bn->win, 1);
|
nuclear@60
|
45
|
nuclear@60
|
46 return bn;
|
nuclear@60
|
47 }
|
nuclear@60
|
48
|
nuclear@60
|
49 MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int w, int h, bool checked)
|
nuclear@60
|
50 {
|
nuclear@60
|
51 return 0;
|
nuclear@60
|
52 }
|
nuclear@60
|
53
|
nuclear@60
|
54
|
nuclear@60
|
55 void mw_test()
|
nuclear@60
|
56 {
|
nuclear@60
|
57 MinWidget *win = mw_create_window(0, "test window!");
|
nuclear@60
|
58 MinWidget *bn = mw_create_button(win, "button!", 100, 100, 300, 80);
|
nuclear@60
|
59 }
|
nuclear@60
|
60
|
nuclear@60
|
61 static void init()
|
nuclear@60
|
62 {
|
nuclear@60
|
63 static bool done_init;
|
nuclear@60
|
64 if(done_init) {
|
nuclear@60
|
65 return;
|
nuclear@60
|
66 }
|
nuclear@60
|
67 done_init = true;
|
nuclear@60
|
68
|
nuclear@60
|
69 HINSTANCE hinst = GetModuleHandle(0);
|
nuclear@60
|
70
|
nuclear@60
|
71 WNDCLASSA wc;
|
nuclear@60
|
72 memset(&wc, 0, sizeof wc);
|
nuclear@60
|
73 wc.lpszClassName = GOATSCE_WCLASS;
|
nuclear@60
|
74 wc.hInstance = hinst;
|
nuclear@60
|
75 wc.lpfnWndProc = handle_msg;
|
nuclear@60
|
76 wc.style = CS_HREDRAW | CS_VREDRAW;
|
nuclear@60
|
77
|
nuclear@60
|
78 RegisterClassA(&wc);
|
nuclear@60
|
79 }
|
nuclear@60
|
80
|
nuclear@60
|
81 static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam)
|
nuclear@60
|
82 {
|
nuclear@60
|
83 switch(msg) {
|
nuclear@60
|
84 case WM_CLOSE:
|
nuclear@60
|
85 DestroyWindow(win);
|
nuclear@60
|
86 break;
|
nuclear@60
|
87
|
nuclear@60
|
88 default:
|
nuclear@60
|
89 return DefWindowProc(win, msg, wparam, lparam);
|
nuclear@60
|
90 }
|
nuclear@60
|
91
|
nuclear@60
|
92 return 0;
|
nuclear@60
|
93 } |