]> git.saurik.com Git - wxWidgets.git/blob - docs/html/faqmsw.htm
clean up of memory debugging macros and chanegs to compile with CW7 (patch 548408)
[wxWidgets.git] / docs / html / faqmsw.htm
1
2 <HTML>
3
4 <HEAD>
5 <TITLE>wxWindows 2 for Windows FAQ</TITLE>
6 </HEAD>
7
8 <BODY BGCOLOR=#FFFFFF TEXT=#000000 VLINK="#00376A" LINK="#00529C" ALINK="#313063">
9
10 <font face="Arial, Lucida Sans, Helvetica">
11
12 <table width=100% border=0 cellpadding=3 cellspacing=0>
13 <tr>
14 <td bgcolor="#004080" align=left height=24 background="images/bluetitlegradient.gif">
15 <font size=+1 face="Arial, Lucida Sans, Helvetica" color="#FFFFFF">
16 <b>wxWindows 2 for Windows FAQ</b>
17 </font>
18 </td>
19 </tr>
20 </table>
21
22 <P>
23
24 See also <a href="faq.htm">top-level FAQ page</a>.
25 <hr>
26 <h3>List of questions in this category</h3>
27 <ul>
28 <li><a href="#platforms">Which Windows platforms are supported?</a></li>
29 <li><a href="#wince">What about Windows CE?</a></li>
30 <li><a href="#winxp">What do I need to do for Windows XP?</a></li>
31 <li><a href="#compilers">What compilers are supported?</a></li>
32 <li><a href="#bestcompiler">Which is the best compiler to use with wxWindows 2?</a></li>
33 <li><a href="#unicode">Is Unicode supported?</a></li>
34 <li><a href="#doublebyte">Does wxWindows support double byte fonts (Chinese/Japanese/Korean etc.)?</a></li>
35 <li><a href="#dll">Can you compile wxWindows 2 as a DLL?</a></li>
36 <li><a href="#exesize">How can I reduce executable size?</a></li>
37 <li><a href="#mfc">Is wxWindows compatible with MFC?</a></li>
38 <li><a href="#newerrors">Why my code fails to compile with strange errors about new operator?</a></li>
39 <li><a href="#mfcport">How do I port MFC applications to wxWindows?</a></li>
40 <li><a href="#crash">Why do I sometimes get bizarre crash problems using VC++ 5/6?</a></li>
41 <li><a href="#makefiles">How are the wxWindows makefiles edited under Windows?</a></li>
42 <li><a href="#vcdebug">How do you use VC++&#39;s memory leak checking instead of that in wxWindows?</a></li>
43 <li><a href="#shortcutproblem">Why are menu hotkeys or shortcuts not working in my application?</a></li>
44 <li><a href="#regconfig">Why can I not write to the HKLM part of the registry with wxRegConfig?</a></li>
45 </ul>
46 <hr>
47
48 <h3><a name="platforms">Which Windows platforms are supported?</a></h3>
49
50 wxWindows 2 can be used to develop and deliver applications on Windows 3.1, Win32s,
51 Windows 95, Windows 98, Windows NT, Windows 2000, and Windows XP. A Windows CE
52 version is being looked into (see below).<P>
53
54 wxWindows 2 is designed to make use of WIN32 features and controls. However, unlike Microsoft,
55 we have not forgotten users of 16-bit Windows. Most features
56 work under Windows 3.1, including wxTreeCtrl and wxListCtrl using the generic implementation.
57 However, don&#39;t expect very Windows-95-specific classes to work, such as wxTaskBarIcon. The wxRegConfig
58 class doesn&#39;t work either because the Windows 3.1 registry is very simplistic. Check out the 16-bit
59 makefiles to see what other files have been left out.
60 <P>
61 16-bit compilation is supported under Visual C++ 1.5, and Borland BC++ 4 to 5.
62 <P>
63
64 wxWindows 2 for Windows will also compile on Unix with gcc using TWIN32 from <a href="http://www.willows.com" target=_top>Willows</a>,
65 although TWIN32 is still in a preliminary state. The resulting executables are
66 Unix binaries that work with the TWIN32 Windows API emulator.<P>
67
68 You can also compile wxWindows 2 for Windows on Unix with Cygwin or Mingw32, resulting
69 in executables that will run on Windows. So in theory you could write your applications
70 using wxGTK or wxMotif, then check/debug your wxWindows for Windows
71 programs with TWIN32, and finally produce an ix86 Windows executable using Cygwin/Mingw32,
72 without ever needing a copy of Microsoft Windows. See the Technical Note on the Web site detailing cross-compilation.<P>
73
74 <h3><a name="wince">What about Windows CE?</a></h3>
75
76 This is under consideration, though we need to get wxWindows Unicode-aware first.
77 There are other interesting issues, such as how to combine the menubar and toolbar APIs
78 as Windows CE requires. But there&#39;s no doubt that it will be possible, albeit
79 by mostly cutting down wxWindows 2 API functionality, and adding a few classes here
80 and there. Since wxWindows for 2 produces small binaries (less than 300K for
81 the statically-linked &#39;minimal&#39; sample), shoehorning wxWindows 2 into a Windows CE device&#39;s limited
82 storage should not be a problem.<P>
83
84 <h3><a name="winxp">What do I need to do for Windows XP?</a></h3>
85
86 In the same directory as you have your executable (e.g. foo.exe) you
87 put a file called foo.exe.manifest in which you have something like
88 the following:
89
90 <pre>
91 &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
92 &lt;assembly
93 xmlns="urn:schemas-microsoft-com:asm.v1"
94 manifestVersion="1.0"&gt;
95 &lt;assemblyIdentity
96 processorArchitecture="x86"
97 version="5.1.0.0"
98 type="win32"
99 name="foo.exe"/&gt;
100 &lt;description&gt;Foo program&lt;/description&gt;
101 &lt;dependency&gt;
102 &lt;dependentAssembly&gt;
103 &lt;assemblyIdentity
104 type="win32"
105 name="Microsoft.Windows.Common-Controls"
106 version="6.0.0.0"
107 publicKeyToken="6595b64144ccf1df"
108 language="*"
109 processorArchitecture="x86"/&gt;
110 &lt;/dependentAssembly&gt;
111 &lt;/dependency&gt;
112 &lt;/assembly&gt;
113 </pre>
114
115 <h3><a name="compilers">What compilers are supported?</a></h3>
116
117 Please see the wxWindows 2 for Windows install.txt file for up-to-date information, but
118 currently the following are known to work:<P>
119
120 <ul>
121 <li>Visual C++ 1.5, 4.0, 5.0, 6.0
122 <li>Borland C++ 4.5, 5.0
123 <li>Borland C++Builder 1.0, 3.0
124 <li>Watcom C++ 10.6 (WIN32)
125 <li>Cygwin b20
126 <li>Mingw32
127 <li>MetroWerks CodeWarrior 4
128 </ul>
129 <P>
130
131 There is a linking problem with Symantec C++ which I hope someone can help solve.
132 <P>
133
134 <h3><a name="bestcompiler">Which is the best compiler to use with wxWindows 2?</a></h3>
135
136 It&#39;s partly a matter of taste, but I (JACS) prefer Visual C++ since the debugger is very
137 good, it&#39;s very stable, the documentation is extensive, and it generates small executables.
138 Since project files are plain text, it&#39;s easy for me to generate appropriate project files
139 for wxWindows samples.<P>
140
141 Borland C++ is fine - and very fast - but it&#39;s hard (impossible?) to use the debugger without using project files, and
142 the debugger is nowhere near up to VC++&#39;s quality. The IDE isn&#39;t great.<P>
143
144 C++Builder&#39;s power isn&#39;t really used with wxWindows since it needs integration with its
145 own class library (VCL). For wxWindows, I&#39;ve only used it with makefiles, in which case
146 it&#39;s almost identical to BC++ 5.0 (the same makefiles can be used).<P>
147
148 You can&#39;t beat Cygwin&#39;s price (free), and you can debug adequately using gdb. However, it&#39;s
149 quite slow to compile since it does not use precompiled headers.<P>
150
151 CodeWarrior is cross-platform - you can debug and generate Windows executables from a Mac, but not
152 the other way around I think - but the IDE is, to my mind, a bit primitive.<P>
153
154 Watcom C++ is a little slow and the debugger is not really up to today&#39;s standards.<P>
155
156 Among the free compilers the best choice seem to be Borland C++ command line
157 tools and mingw32 (port of gcc to Win32). Both of them are supported by
158 wxWindows.
159
160 <h3><a name="unicode">Is Unicode supported?</a></h3>
161
162 Yes, Unicode is fully supported under Windows NT/2000 (Windows 9x don&#39;t
163 have Unicode support anyhow).
164
165 <h3><a name="doublebyte">Does wxWindows support double byte fonts (Chinese/Japanese/Korean etc.)?</a></h3>
166
167 An answer from <a href="mailto:goedde@logosoft.de">Klaus Goedde</a>:<p>
168
169 "For Japanese under Win2000, it seems that wxWindows has no problems to work with double byte char sets
170 (I mean DBCS, that&#39;s not Unicode). First you have to install Japanese support on your Win2K system
171 and choose for ANSI translation
172 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage=932 (default is 1252 for Western).
173 Then you can see all the funny Japanese letters under wxWindows too.<P>
174
175 In a wxTextCtrl control you have to set the window style "wxTE_RICH", otherwise this control shows the wrong
176 letters.
177
178 I don&#39;t now whether it works on non W2K systems, because I&#39;m just starting using wxWindows."
179 <P>
180
181 <h3><a name="dll">Can you compile wxWindows 2 as a DLL?</a></h3>
182
183 Yes (using the Visual C++ or Borland C++ makefile), but be aware that distributing DLLs is a thorny issue
184 and you may be better off compiling statically-linked applications, unless you&#39;re
185 delivering a suite of separate programs, or you&#39;re compiling a lot of wxWindows applications
186 and have limited hard disk space.<P>
187
188 With a DLL approach, and with different versions and configurations of wxWindows
189 needing to be catered for, the end user may end up with a host of large DLLs in his or her Windows system directory,
190 negating the point of using DLLs. Of course, this is not a problem just associated with
191 wxWindows!
192 <P>
193
194 <h3><a name="exesize">How can I reduce executable size?</a></h3>
195
196 You can compile wxWindows as a DLL (see above, VC++/BC++ only at present). You should also
197 compile your programs for release using non-debugging and space-optimisation options, but
198 take with VC++ 5/6 space optimisation: it can sometimes cause problems.<P>
199
200 Statically-linked wxWindows 2 programs are smaller than wxWindows 1.xx programs, because of the way
201 wxWindows 2 has been designed to reduce dependencies between classes, and other
202 techniques. The linker will not include code from the library that is not (directly or
203 indirectly) referenced
204 by your application. So for example, the &#39;minimal&#39; sample is less than 300KB using VC++ 6.<P>
205
206 If you want to distribute really small executables, you can
207 use <a href="http://www.un4seen.com/petite/" target=_top>Petite</a>
208 by Ian Luck. This nifty utility compresses Windows executables by around 50%, so your 500KB executable
209 will shrink to a mere 250KB. With this sort of size, there is reduced incentive to
210 use DLLs. Another good compression tool is <a href="http://upx.sourceforge.net/" target=_top>UPX</a>.
211 <P>
212
213 <H3><a name="mfc">Is wxWindows compatible with MFC?</a></H3>
214
215 There is a sample which demonstrates MFC and wxWindows code co-existing in the same
216 application. However, don&#39;t expect to be able to enable wxWindows windows with OLE-2
217 functionality using MFC.<P>
218
219 <H3><a name="newerrors">Why my code fails to compile with strange errors about new operator?</a></H3>
220
221 The most common cause of this problem is the memory debugging settings in
222 <tt>wx/msw/setup.h</tt>. You have several choices:
223
224 <ul>
225 <li> Either disable overloading the global operator new completely by
226 setting <tt>wxUSE_GLOBAL_MEMORY_OPERATORS</tt> and
227 <tt>wxUSE_DEBUG_NEW_ALWAYS</tt> to 0 in this file
228 <li> Or leave them on but do <tt>#undef new</tt> after including any
229 wxWindows headers, like this the memory debugging will be still on
230 for wxWindows sources but off for your own code
231 </ul>
232
233 Notice that IMHO the first solution is preferable for VC++ users who can use
234 the <a href="#vcdebug">VC++ CRT memory debugging features</a> instead.
235
236 <H3><a name="mfcport">How do I port MFC applications to wxWindows?</a></H3>
237
238 Set up your interface from scratch using wxWindows (especially wxDesigner --
239 it&#39;ll save you a <i>lot</i> of time) and when you have a shell prepared, you can start
240 &#39;pouring in&#39; code from the MFC app, with appropriate
241 modifications. This is the approach I have used, and I found
242 it very satisfactory. A two-step process then - reproduce the bare
243 interface first, then wire it up afterwards. That way you deal
244 with each area of complexity separately. Don&#39;t try to think MFC
245 and wxWindows simultaneously from the beginning - it is easier to
246 reproduce the initial UI by looking at the behaviour of the MFC
247 app, not its code.
248
249 <H3><a name="crash">Why do I sometimes get bizarre crash problems using VC++ 5/6?</a></H3>
250
251 Some crash problems can be due to inconsistent compiler
252 options (and of course this isn&#39;t limited to wxWindows).
253 If strange/weird/impossible things start to happen please
254 check (dumping IDE project file as makefile and doing text comparison
255 if necessary) that the project settings, especially the list of defined
256 symbols, struct packing, etc. are exactly the same for all items in
257 the project. After this, delete everything (including PCH) and recompile.<P>
258
259 VC++ 5&#39;s optimization code seems to be broken and can
260 cause problems: this can be seen when deleting an object Dialog
261 Editor, in Release mode with optimizations on. If in doubt,
262 switch off optimisations, although this will result in much
263 larger executables. It seems possible that the library can be created with
264 strong optimization, so long as the application is not strongly
265 optimized. For example, in wxWindows project, set to &#39;Minimum
266 Size&#39;. In Dialog Editor project, set to &#39;Customize: Favor Small
267 Code&#39; (and no others). This will then work.<P>
268
269 <H3><a name="makefiles">How are the wxWindows makefiles edited under Windows?</a></H3>
270
271 As of wxWindows 2.1, there is a new system written by Vadim Zeitlin, that
272 generates the makefiles from templates using tmake.<P>
273
274 Here are Vadim&#39;s notes:<P>
275
276 <blockquote>
277 To use these new makefiles, you don&#39;t need anything (but see below).
278 However, you should NOT modify them because these files will be
279 rewritten when I regenerate them using tmake the next time. So, if
280 you find a problem with any of these makefiles (say, makefile.b32)
281 you&#39;ll need to modify the corresponding template (b32.t in this
282 example) and regenerate the makefile using tmake.<P>
283
284 tmake can be found at
285 <a href="http://www.troll.no/freebies/tmake.html" target=_new>www.troll.no/freebies/tmake.html</a>.
286 It&#39;s a Perl5 program and so it needs Perl (doh). There is a binary for
287 Windows (available from the same page), but I haven&#39;t used it, so
288 I don&#39;t know if it works as flawlessly as "perl tmake" does (note
289 for people knowing Perl: don&#39;t try to run tmake with -w, it won&#39;t
290 do you any good). Using it extremely simple: to regenerate makefile.b32
291 just go to distrib/msw/tmake and type<P>
292
293 <pre>tmake -t b32 wxwin.pro -o ../../src/msw/makefile.b32</pre><P>
294
295 The makefiles are untested - I don&#39;t have any of Borland, Watcom or
296 Symantec and I don&#39;t have enough diskspace to recompile even with
297 VC6 using makefiles. The new makefiles are as close as possible to the
298 old ones, but not closer: in fact, there has been many strange things
299 (should I say bugs?) in some of makefiles, some files were not compiled
300 without any reason etc. Please test them and notify me about any problems.
301 Better yet, modify the template files to generate the correct makefiles
302 and check them in.<P>
303
304 The templates are described in tmake ref manual (1-2 pages of text)
305 and are quite simple. They do contain some Perl code, but my Perl is
306 primitive (very C like) so it should be possible for anybody to make
307 trivial modifications to it (I hope that only trivial modifications
308 will be needed). I&#39;ve tagged the ol makefiles as MAKEFILES_WITHOUT_TMAKE
309 in the cvs, so you can always retrieve them and compare the new ones,
310 this will make it easier to solve the problems you might have.<P>
311
312 Another important file is filelist.txt: it contains the list of all
313 files to be compiled. Some of them are only compiled in 16/32 bit mode.
314 Some other are only compiled with some compilers (others can&#39;t compile
315 them) - all this info is contained in this file.<P>
316
317 So now adding a new file to wxWindows is as easy as modifying filelist.txt
318 (and Makefile.ams for Unix ports) and regenerating the makefiles - no
319 need to modify all files manually any more.<P>
320
321 Finally, there is also a file vc6.t which I use myself: this one
322 generates a project file for VC++ 6.0 (I didn&#39;t create vc5.t because
323 I don&#39;t need it and can&#39;t test it, but it should be trivial to create
324 one from vc6.t - probably the only things to change would be the
325 version number in the very beginning and the /Z option - VC5 doesn&#39;t
326 support edit-and=continue). This is not an officially supported way
327 of building wxWindows (that is, nobody guarantees that it will work),
328 but it has been very useful to me and I hope it will be also for
329 others. To generate wxWindows.dsp run<P>
330
331 <pre>tmake -t vc6 wxwin.pro -o ../../wxWindows.dsp</pre><P>
332
333 Then just include this project in any workspace or open it from VC IDE
334 and it will create a new workspace for you.<P>
335
336 If all goes well, I&#39;m planning to create a template file for Makefile.ams
337 under src/gtk and src/motif and also replace all makefiles in the samples
338 subdirectories with the project files from which all the others will be
339 generated. At least it will divide the number of files in samples
340 directory by 10 (and the number of files to be maintained too).
341 </blockquote>
342
343 <P>
344
345 <H3><a name="vcdebug">How do you use VC++&#39;s memory leak checking instead of that in wxWindows?</a></H3>
346
347 Vadim Zeitlin:
348
349 <pre>
350 On the VC++ level, it&#39;s just the matter of calling _CrtSetDbgFlag() in the very
351 beginning of the program. In wxWindows, this is done automatically when
352 compiling with VC++ in debug mode unless wxUSE_GLOBAL_MEMORY_OPERATORS or
353 __NO_VC_CRTDBG__ are defined - this check is done in wx/msw/msvcrt.h which
354 is included from app.cpp which then calls wxCrtSetDbgFlag() without any
355 ifdefs.
356
357 This works quite well: at the end of the program, all leaked blocks with their
358 malloc count are shown. This number (malloc count) can be used to determine
359 where exactly the object was allocated: for this it&#39;s enough to set the variable
360 _crtBreakAlloc (look in VC98\crt\srs\dbgheap.c line 326) to this number and
361 a breakpoint will be triggered when the block with this number is allocated.
362
363 For simple situations it works like a charm. For something more complicated
364 like reading uninitialized memory a specialized tool is probably better...
365
366 Regards,
367 VZ
368 </pre>
369
370 <P>
371
372 <H3><a name="shortcutproblem">Why are menu hotkeys or shortcuts not working in my application?</a></H3>
373
374 This can happen if you have a child window intercepting EVT_CHAR events and swallowing
375 all keyboard input. You should ensure that event.Skip() is called for all input that
376 isn&#39;used by the event handler.
377
378 <H3><a name="#regconfig">Why can I not write to the HKLM part of the registry with wxRegConfig?</a></H3>
379
380 Currently this is not possible because the wxConfig family of classes is
381 supposed to deal with per-user application configuration data, and HKLM is
382 only supposed to be writeable by a user with Administrator privileges. In theory,
383 only installers should write to HKLM. This is still a point debated by the
384 wxWindows developers. There are at least two ways to work around it if you really
385 need to write to HKLM.<P>
386
387 First, you can use wxRegKey directly, for example:
388
389 <pre>
390 wxRegKey regKey;
391
392 wxString idName(wxT("HKEY_LOCAL_MACHINE\\SOFTWARE\\My Company\\My Product\\Stuff\\"));
393 idName += packid;
394
395 regKey.SetName(idName);
396
397 {
398 wxLogNull dummy;
399 if (!regKey.Create())
400 {
401 idName = wxT("HKEY_CURRENT_USER\\SOFTWARE\\My Company\\My Product\\Stuff\\");
402 idName += packid;
403 regKey.SetName(idName);
404 if (!regKey.Create())
405 return FALSE;
406 }
407 }
408
409 if (!regKey.SetValue(wxT("THING"), (long) thing)) err += 1;
410
411 regKey.Close();
412
413 </pre>
414
415 Or, you can employ this trick suggested by Istvan Kovacs:
416
417 <pre>
418 class myGlobalConfig : public wxConfig
419 {
420 myGlobalConfig() :
421 wxConfig ("myApp", "myCompany", "", "", wxCONFIG_USE_GLOBAL_FILE)
422 {};
423 bool Write(const wxString& key, const wxString& value);
424 }
425
426 bool myGlobalConfig::Write (const wxString& key, const wxString& value)
427 {
428 wxString path = wxString ("SOFTWARE\\myCompany\\myApp\\") + wxPathOnly(key);
429 wxString new_path = path.Replace ("/", "\\", true);
430 wxString new_key = wxFileNameFromPath (key);
431 LocalKey().SetName (wxRegKey::HKLM, path);
432 return wxConfig::Write (new_key, value);
433 }
434 </pre>
435
436 </font>
437
438 </BODY>
439
440 </HTML>