1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/////////////////////////////////////////////////////////////////////////////
// Name: samples/dll/my_exe.cpp
// Purpose: Sample showing how to use wx DLL from a Win32 application
// Author: Vadim Zeitlin
// Created: 2009-12-07
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/*
This program is intentionally as simple as possible and shouldn't be seen
as an example of how to write a proper Win32 application (why should you
want to do this anyhow when you have wxWidgets). It's just a test bed for
the wx DLL which it uses.
*/
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <tchar.h>
#include "my_dll.h"
namespace
{
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
const TCHAR *MAIN_WIN_CLASS_NAME = _TEXT("my_exe_main_win_class");
const int IDB_RUN_GUI_FROM_DLL = 100;
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
HINSTANCE g_hInstance;
HWND g_hwndMain;
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// callbacks
// ----------------------------------------------------------------------------
void
OnCommand(HWND /* hwnd */, int id, HWND /* hwndCtl */, UINT /* codeNotify */)
{
if ( id == IDB_RUN_GUI_FROM_DLL )
{
run_wx_gui_from_dll("child instance");
}
}
void OnDestroy(HWND hwnd)
{
wx_dll_cleanup();
PostQuitMessage(0);
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch ( msg )
{
HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
// ----------------------------------------------------------------------------
// initialization functions
// ----------------------------------------------------------------------------
bool RegisterMainClass()
{
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.hInstance = g_hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszClassName = MAIN_WIN_CLASS_NAME;
return RegisterClass(&wc) != 0;
}
bool CreateMainWindow()
{
g_hwndMain = CreateWindow
(
MAIN_WIN_CLASS_NAME,
_TEXT("Main Win32 app"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
400, 300,
NULL, NULL, g_hInstance, NULL
);
if ( !g_hwndMain )
return false;
CreateWindow
(
_TEXT("static"),
_TEXT("Main Win32 application"),
WS_CHILD | WS_VISIBLE,
10, 10, 200, 30,
g_hwndMain, (HMENU)-1, g_hInstance, NULL
);
CreateWindow
(
_TEXT("button"),
_TEXT("Run GUI from DLL"),
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
200, 200, 150, 35,
g_hwndMain, (HMENU)IDB_RUN_GUI_FROM_DLL, g_hInstance, NULL
);
return true;
}
} // anonymous namespace
// ----------------------------------------------------------------------------
// entry point
// ----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
g_hInstance = hInstance;
if ( !RegisterMainClass() )
return 1;
if ( !CreateMainWindow() )
return 2;
ShowWindow(g_hwndMain, nCmdShow);
MSG msg;
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
|