]>
git.saurik.com Git - wxWidgets.git/blob - samples/dll/sdk_exe.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/dll/my_exe.cpp
3 // Purpose: Sample showing how to use wx DLL from a Win32 application
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 This program is intentionally as simple as possible and shouldn't be seen
12 as an example of how to write a proper Win32 application (why should you
13 want to do this anyhow when you have wxWidgets). It's just a test bed for
14 the wx DLL which it uses.
17 // ============================================================================
19 // ============================================================================
21 // ----------------------------------------------------------------------------
23 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 const TCHAR
*MAIN_WIN_CLASS_NAME
= _TEXT("my_exe_main_win_class");
42 const int IDB_RUN_GUI_FROM_DLL
= 100;
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 HINSTANCE g_hInstance
;
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
60 OnCommand(HWND
/* hwnd */, int id
, HWND
/* hwndCtl */, UINT
/* codeNotify */)
62 if ( id
== IDB_RUN_GUI_FROM_DLL
)
64 run_wx_gui_from_dll("child instance");
68 void OnDestroy(HWND hwnd
)
75 LRESULT CALLBACK
MainWndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
79 HANDLE_MSG(hwnd
, WM_COMMAND
, OnCommand
);
80 HANDLE_MSG(hwnd
, WM_DESTROY
, OnDestroy
);
83 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
89 // ----------------------------------------------------------------------------
90 // initialization functions
91 // ----------------------------------------------------------------------------
93 bool RegisterMainClass()
96 ZeroMemory(&wc
, sizeof(wc
));
97 wc
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
;
98 wc
.lpfnWndProc
= MainWndProc
;
99 wc
.hInstance
= g_hInstance
;
100 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
101 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
102 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
103 wc
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
105 return RegisterClass(&wc
) != 0;
108 bool CreateMainWindow()
110 g_hwndMain
= CreateWindow
113 _TEXT("Main Win32 app"),
115 CW_USEDEFAULT
, CW_USEDEFAULT
,
117 NULL
, NULL
, g_hInstance
, NULL
125 _TEXT("Main Win32 application"),
126 WS_CHILD
| WS_VISIBLE
,
128 g_hwndMain
, (HMENU
)-1, g_hInstance
, NULL
134 _TEXT("Run GUI from DLL"),
135 WS_CHILD
| WS_VISIBLE
| BS_DEFPUSHBUTTON
,
137 g_hwndMain
, (HMENU
)IDB_RUN_GUI_FROM_DLL
, g_hInstance
, NULL
143 } // anonymous namespace
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 int APIENTRY
WinMain(HINSTANCE hInstance
, HINSTANCE
, LPSTR
, int nCmdShow
)
151 g_hInstance
= hInstance
;
153 if ( !RegisterMainClass() )
156 if ( !CreateMainWindow() )
159 ShowWindow(g_hwndMain
, nCmdShow
);
162 while ( GetMessage(&msg
, NULL
, 0, 0) )
164 TranslateMessage(&msg
);
165 DispatchMessage(&msg
);