]>
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
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 This program is intentionally as simple as possible and shouldn't be seen
13 as an example of how to write a proper Win32 application (why should you
14 want to do this anyhow when you have wxWidgets). It's just a test bed for
15 the wx DLL which it uses.
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 const TCHAR
*MAIN_WIN_CLASS_NAME
= _TEXT("my_exe_main_win_class");
43 const int IDB_RUN_GUI_FROM_DLL
= 100;
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 HINSTANCE g_hInstance
;
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
61 OnCommand(HWND
/* hwnd */, int id
, HWND
/* hwndCtl */, UINT
/* codeNotify */)
63 if ( id
== IDB_RUN_GUI_FROM_DLL
)
65 run_wx_gui_from_dll("child instance");
69 void OnDestroy(HWND hwnd
)
76 LRESULT CALLBACK
MainWndProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
80 HANDLE_MSG(hwnd
, WM_COMMAND
, OnCommand
);
81 HANDLE_MSG(hwnd
, WM_DESTROY
, OnDestroy
);
84 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
90 // ----------------------------------------------------------------------------
91 // initialization functions
92 // ----------------------------------------------------------------------------
94 bool RegisterMainClass()
97 ZeroMemory(&wc
, sizeof(wc
));
98 wc
.style
= CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
;
99 wc
.lpfnWndProc
= MainWndProc
;
100 wc
.hInstance
= g_hInstance
;
101 wc
.hIcon
= LoadIcon(NULL
, IDI_APPLICATION
);
102 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
103 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
104 wc
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
106 return RegisterClass(&wc
) != 0;
109 bool CreateMainWindow()
111 g_hwndMain
= CreateWindow
114 _TEXT("Main Win32 app"),
116 CW_USEDEFAULT
, CW_USEDEFAULT
,
118 NULL
, NULL
, g_hInstance
, NULL
126 _TEXT("Main Win32 application"),
127 WS_CHILD
| WS_VISIBLE
,
129 g_hwndMain
, (HMENU
)-1, g_hInstance
, NULL
135 _TEXT("Run GUI from DLL"),
136 WS_CHILD
| WS_VISIBLE
| BS_DEFPUSHBUTTON
,
138 g_hwndMain
, (HMENU
)IDB_RUN_GUI_FROM_DLL
, g_hInstance
, NULL
144 } // anonymous namespace
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
150 int APIENTRY
WinMain(HINSTANCE hInstance
, HINSTANCE
, LPSTR
, int nCmdShow
)
152 g_hInstance
= hInstance
;
154 if ( !RegisterMainClass() )
157 if ( !CreateMainWindow() )
160 ShowWindow(g_hwndMain
, nCmdShow
);
163 while ( GetMessage(&msg
, NULL
, 0, 0) )
165 TranslateMessage(&msg
);
166 DispatchMessage(&msg
);