]> git.saurik.com Git - wxWidgets.git/blame - src/msw/main.cpp
Printing improvements: GetPageInfo() gets called after the DC has
[wxWidgets.git] / src / msw / main.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
b568d04f 2// Name: msw/main.cpp
e2478fde 3// Purpose: WinMain/DllMain
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
b568d04f
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
a3b46648 20#ifdef __GNUG__
b568d04f 21 #pragma implementation
a3b46648
UU
22#endif
23
2bda0e17
KB
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
b568d04f 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
2432b92d 31#include "wx/event.h"
2bda0e17 32#include "wx/app.h"
94826170 33#include "wx/cmdline.h"
b568d04f
VZ
34
35#include "wx/msw/private.h"
36
e2478fde 37// Don't implement WinMain if we're building an MFC/wxWindows hybrid app.
4cd513ab 38#if wxUSE_MFC && !defined(NOMAIN)
e2478fde 39 #define NOMAIN 1
4cd513ab
JS
40#endif
41
e2478fde
VZ
42#ifdef __BORLANDC__
43 // BC++ has to be special: its run-time expects the DLL entry point to be
44 // named DllEntryPoint instead of the (more) standard DllMain
45 #define DllMain DllEntryPoint
46#endif
47
48#if defined(__WXMICROWIN__)
49 #define HINSTANCE HANDLE
50#endif
beed393c 51
94826170
VZ
52#if wxUSE_GUI
53
b568d04f 54// ----------------------------------------------------------------------------
e2478fde 55// function prototypes
b568d04f
VZ
56// ----------------------------------------------------------------------------
57
94826170
VZ
58static wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc);
59
b568d04f 60// ============================================================================
e2478fde 61// implementation: various entry points
b568d04f
VZ
62// ============================================================================
63
94826170
VZ
64// ----------------------------------------------------------------------------
65// Windows-specific wxEntry
66// ----------------------------------------------------------------------------
67
b5fe6924
VS
68WXDLLEXPORT int wxEntry(HINSTANCE hInstance,
69 HINSTANCE WXUNUSED(hPrevInstance),
70 char *pCmdLine,
71 int nCmdShow)
94826170
VZ
72{
73 // remember the parameters Windows gave us
13bdd545 74 wxSetInstance(hInstance);
94826170
VZ
75 wxApp::m_nCmdShow = nCmdShow;
76
77 // parse the command line
78 int argc;
79 wxChar **argv = ConvertToStandardCommandArgs(wxConvertMB2WX(pCmdLine), argc);
80
81 return wxEntry(argc, argv);
82}
83
2bda0e17 84// May wish not to have a DllMain or WinMain, e.g. if we're programming
b568d04f 85// a Netscape plugin or if we're writing a console application
94826170 86#if !defined(NOMAIN)
2bda0e17 87
e2478fde
VZ
88extern "C"
89{
2bda0e17 90
e2478fde 91// ----------------------------------------------------------------------------
2bda0e17 92// WinMain
e2478fde
VZ
93// ----------------------------------------------------------------------------
94
2bda0e17
KB
95// Note that WinMain is also defined in dummy.obj, which is linked to
96// an application that is using the DLL version of wxWindows.
97
98#if !defined(_WINDLL)
99
4676948b
JS
100#ifdef __WXWINCE__
101int WINAPI WinMain(HINSTANCE hInstance,
102 HINSTANCE hPrevInstance,
103 LPWSTR lpCmdLine,
104 int nCmdShow)
105{
106 return wxEntry(hInstance, hPrevInstance, (char*) lpCmdLine, nCmdShow);
107}
108#else
8f177c8e
VZ
109int PASCAL WinMain(HINSTANCE hInstance,
110 HINSTANCE hPrevInstance,
111 LPSTR lpCmdLine,
112 int nCmdShow)
2bda0e17 113{
13bdd545 114 return wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
2bda0e17 115}
4676948b 116#endif
8f177c8e 117
e2478fde 118#else // _WINDLL
2bda0e17
KB
119
120// DLL entry point
121
e2478fde
VZ
122BOOL WINAPI
123DllMain(HANDLE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpReserved))
2bda0e17 124{
e2478fde
VZ
125 // Only call wxEntry if the application itself is part of the DLL.
126 // If only the wxWindows library is in the DLL, then the
127 // initialisation will be called when the application implicitly
128 // calls WinMain.
beed393c 129#ifndef WXMAKINGDLL
2bda0e17 130 switch (fdwReason)
b568d04f
VZ
131 {
132 case DLL_PROCESS_ATTACH:
13bdd545 133 return wxEntry(hModule);
2bda0e17 134
b568d04f 135 case DLL_PROCESS_DETACH:
94826170
VZ
136 wxEntryCleanup();
137 break;
b568d04f 138 }
33ac7e6f
KB
139#else
140 (void)hModule;
141 (void)fdwReason;
beed393c 142#endif // !WXMAKINGDLL
e2478fde 143
b568d04f 144 return TRUE;
2bda0e17
KB
145}
146
e2478fde
VZ
147#endif // _WINDLL/!_WINDLL
148
149} // extern "C"
2bda0e17 150
b568d04f
VZ
151#endif // !NOMAIN
152
94826170
VZ
153// ---------------------------------------------------------------------------
154// Convert Windows to argc, argv style
155// ---------------------------------------------------------------------------
156
157wxChar **ConvertToStandardCommandArgs(const wxChar *p, int& argc)
158{
159 // break the command line in words
160 wxArrayString args;
161 if ( p )
162 {
163 args = wxCmdLineParser::ConvertStringToArgs(p);
164 }
165
166 // +1 here for the program name
167 argc = args.GetCount() + 1;
168
169 // and +1 here for the terminating NULL
170 wxChar **argv = new wxChar *[argc + 1];
171
f252f8c3
VZ
172 // as we use wxStrdup below we must allocate the first argument using
173 // malloc(), not new[], as well
174 argv[0] = (wxChar *)malloc(MAX_PATH * sizeof(wxChar));
94826170
VZ
175 ::GetModuleFileName(wxhInstance, argv[0], MAX_PATH);
176
177 // copy all the other arguments to wxApp::argv[]
178 for ( int i = 1; i < argc; i++ )
179 {
180 argv[i] = wxStrdup(args[i - 1]);
181 }
182
183 // argv[] must be NULL-terminated
184 argv[argc] = NULL;
185
186 return argv;
187}
188
189#endif // wxUSE_GUI
190
b568d04f 191// ----------------------------------------------------------------------------
e2478fde 192// global HINSTANCE
b568d04f
VZ
193// ----------------------------------------------------------------------------
194
ec67cff1 195#if wxUSE_BASE
e2478fde
VZ
196
197HINSTANCE wxhInstance = 0;
198
b568d04f
VZ
199HINSTANCE wxGetInstance()
200{
201 return wxhInstance;
202}
203
204void wxSetInstance(HINSTANCE hInst)
205{
206 wxhInstance = hInst;
207}
2bda0e17 208
ec67cff1 209#endif // wxUSE_BASE
e2478fde 210