]> git.saurik.com Git - wxWidgets.git/blob - src/msw/utils.cpp
For efficiency reasons, text controls no longer set the string for each text updated...
[wxWidgets.git] / src / msw / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/utils.cpp
3 // Purpose: Various utilities
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/utils.h"
29 #include "wx/app.h"
30 #include "wx/intl.h"
31 #include "wx/log.h"
32 #endif //WX_PRECOMP
33
34 #include "wx/apptrait.h"
35 #include "wx/dynlib.h"
36 #include "wx/dynload.h"
37
38 #include "wx/confbase.h" // for wxExpandEnvVars()
39
40 #include "wx/msw/private.h" // includes <windows.h>
41 #include "wx/msw/missing.h" // CHARSET_HANGUL
42
43 #if defined(__GNUWIN32_OLD__) || defined(__WXWINCE__) \
44 || defined(__CYGWIN32__)
45 // apparently we need to include winsock.h to get WSADATA and other stuff
46 // used in wxGetFullHostName() with the old mingw32 versions
47 #include <winsock.h>
48 #endif
49
50 #include "wx/timer.h"
51
52 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
53 #include <direct.h>
54
55 #ifndef __MWERKS__
56 #include <dos.h>
57 #endif
58 #endif //GNUWIN32
59
60 #if defined(__CYGWIN__)
61 #include <sys/unistd.h>
62 #include <sys/stat.h>
63 #include <sys/cygwin.h> // for cygwin_conv_to_full_win32_path()
64 #endif //GNUWIN32
65
66 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
67 // this (3.1 I believe) and how to test for it.
68 // If this works for Borland 4.0 as well, then no worries.
69 #include <dir.h>
70 #endif
71
72 // VZ: there is some code using NetXXX() functions to get the full user name:
73 // I don't think it's a good idea because they don't work under Win95 and
74 // seem to return the same as wxGetUserId() under NT. If you really want
75 // to use them, just #define USE_NET_API
76 #undef USE_NET_API
77
78 #ifdef USE_NET_API
79 #include <lm.h>
80 #endif // USE_NET_API
81
82 #if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
83 #ifndef __UNIX__
84 #include <io.h>
85 #endif
86
87 #ifndef __GNUWIN32__
88 #include <shellapi.h>
89 #endif
90 #endif
91
92 #ifndef __WATCOMC__
93 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
94 #include <errno.h>
95 #endif
96 #endif
97
98 // For wxKillAllChildren
99 #include <tlhelp32.h>
100
101 // ----------------------------------------------------------------------------
102 // constants
103 // ----------------------------------------------------------------------------
104
105 // In the WIN.INI file
106 static const wxChar WX_SECTION[] = wxT("wxWindows");
107 static const wxChar eUSERNAME[] = wxT("UserName");
108
109 // ============================================================================
110 // implementation
111 // ============================================================================
112
113 // ----------------------------------------------------------------------------
114 // get host name and related
115 // ----------------------------------------------------------------------------
116
117 // Get hostname only (without domain name)
118 bool wxGetHostName(wxChar *buf, int maxSize)
119 {
120 #if defined(__WXWINCE__)
121 return false;
122 #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
123 DWORD nSize = maxSize;
124 if ( !::GetComputerName(buf, &nSize) )
125 {
126 wxLogLastError(wxT("GetComputerName"));
127
128 return false;
129 }
130
131 return true;
132 #else
133 wxChar *sysname;
134 const wxChar *default_host = wxT("noname");
135
136 if ((sysname = wxGetenv(wxT("SYSTEM_NAME"))) == NULL) {
137 GetProfileString(WX_SECTION, eHOSTNAME, default_host, buf, maxSize - 1);
138 } else
139 wxStrncpy(buf, sysname, maxSize - 1);
140 buf[maxSize] = wxT('\0');
141 return *buf ? true : false;
142 #endif
143 }
144
145 // get full hostname (with domain name if possible)
146 bool wxGetFullHostName(wxChar *buf, int maxSize)
147 {
148 #if !defined( __WXMICROWIN__) && wxUSE_DYNAMIC_LOADER
149 // TODO should use GetComputerNameEx() when available
150
151 // we don't want to always link with Winsock DLL as we might not use it at
152 // all, so load it dynamically here if needed (and don't complain if it is
153 // missing, we handle this)
154 wxLogNull noLog;
155
156 wxDynamicLibrary dllWinsock(_T("ws2_32.dll"), wxDL_VERBATIM);
157 if ( dllWinsock.IsLoaded() )
158 {
159 typedef int (PASCAL *WSAStartup_t)(WORD, WSADATA *);
160 typedef int (PASCAL *gethostname_t)(char *, int);
161 typedef hostent* (PASCAL *gethostbyname_t)(const char *);
162 typedef hostent* (PASCAL *gethostbyaddr_t)(const char *, int , int);
163 typedef int (PASCAL *WSACleanup_t)(void);
164
165 #define LOAD_WINSOCK_FUNC(func) \
166 func ## _t \
167 pfn ## func = (func ## _t)dllWinsock.GetSymbol(_T(#func))
168
169 LOAD_WINSOCK_FUNC(WSAStartup);
170
171 WSADATA wsa;
172 if ( pfnWSAStartup && pfnWSAStartup(MAKEWORD(1, 1), &wsa) == 0 )
173 {
174 LOAD_WINSOCK_FUNC(gethostname);
175
176 wxString host;
177 if ( pfngethostname )
178 {
179 char bufA[256];
180 if ( pfngethostname(bufA, WXSIZEOF(bufA)) == 0 )
181 {
182 // gethostname() won't usually include the DNS domain name,
183 // for this we need to work a bit more
184 if ( !strchr(bufA, '.') )
185 {
186 LOAD_WINSOCK_FUNC(gethostbyname);
187
188 struct hostent *pHostEnt = pfngethostbyname
189 ? pfngethostbyname(bufA)
190 : NULL;
191
192 if ( pHostEnt )
193 {
194 // Windows will use DNS internally now
195 LOAD_WINSOCK_FUNC(gethostbyaddr);
196
197 pHostEnt = pfngethostbyaddr
198 ? pfngethostbyaddr(pHostEnt->h_addr,
199 4, AF_INET)
200 : NULL;
201 }
202
203 if ( pHostEnt )
204 {
205 host = wxString::FromAscii(pHostEnt->h_name);
206 }
207 }
208 }
209 }
210
211 LOAD_WINSOCK_FUNC(WSACleanup);
212 if ( pfnWSACleanup )
213 pfnWSACleanup();
214
215
216 if ( !host.empty() )
217 {
218 wxStrncpy(buf, host, maxSize);
219
220 return true;
221 }
222 }
223 }
224 #endif // !__WXMICROWIN__
225
226 return wxGetHostName(buf, maxSize);
227 }
228
229 // Get user ID e.g. jacs
230 bool wxGetUserId(wxChar *buf, int maxSize)
231 {
232 #if defined(__WXWINCE__)
233 return false;
234 #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
235 DWORD nSize = maxSize;
236 if ( ::GetUserName(buf, &nSize) == 0 )
237 {
238 // actually, it does happen on Win9x if the user didn't log on
239 DWORD res = ::GetEnvironmentVariable(wxT("username"), buf, maxSize);
240 if ( res == 0 )
241 {
242 // not found
243 return false;
244 }
245 }
246
247 return true;
248 #else // __WXMICROWIN__
249 wxChar *user;
250 const wxChar *default_id = wxT("anonymous");
251
252 // Can't assume we have NIS (PC-NFS) or some other ID daemon
253 // So we ...
254 if ( (user = wxGetenv(wxT("USER"))) == NULL &&
255 (user = wxGetenv(wxT("LOGNAME"))) == NULL )
256 {
257 // Use wxWidgets configuration data (comming soon)
258 GetProfileString(WX_SECTION, eUSERID, default_id, buf, maxSize - 1);
259 }
260 else
261 {
262 wxStrncpy(buf, user, maxSize - 1);
263 }
264
265 return *buf ? true : false;
266 #endif
267 }
268
269 // Get user name e.g. Julian Smart
270 bool wxGetUserName(wxChar *buf, int maxSize)
271 {
272 #if defined(__WXWINCE__)
273 return false;
274 #elif defined(USE_NET_API)
275 CHAR szUserName[256];
276 if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) )
277 return false;
278
279 // TODO how to get the domain name?
280 CHAR *szDomain = "";
281
282 // the code is based on the MSDN example (also see KB article Q119670)
283 WCHAR wszUserName[256]; // Unicode user name
284 WCHAR wszDomain[256];
285 LPBYTE ComputerName;
286
287 USER_INFO_2 *ui2; // User structure
288
289 // Convert ANSI user name and domain to Unicode
290 MultiByteToWideChar( CP_ACP, 0, szUserName, strlen(szUserName)+1,
291 wszUserName, WXSIZEOF(wszUserName) );
292 MultiByteToWideChar( CP_ACP, 0, szDomain, strlen(szDomain)+1,
293 wszDomain, WXSIZEOF(wszDomain) );
294
295 // Get the computer name of a DC for the domain.
296 if ( NetGetDCName( NULL, wszDomain, &ComputerName ) != NERR_Success )
297 {
298 wxLogError(wxT("Can not find domain controller"));
299
300 goto error;
301 }
302
303 // Look up the user on the DC
304 NET_API_STATUS status = NetUserGetInfo( (LPWSTR)ComputerName,
305 (LPWSTR)&wszUserName,
306 2, // level - we want USER_INFO_2
307 (LPBYTE *) &ui2 );
308 switch ( status )
309 {
310 case NERR_Success:
311 // ok
312 break;
313
314 case NERR_InvalidComputer:
315 wxLogError(wxT("Invalid domain controller name."));
316
317 goto error;
318
319 case NERR_UserNotFound:
320 wxLogError(wxT("Invalid user name '%s'."), szUserName);
321
322 goto error;
323
324 default:
325 wxLogSysError(wxT("Can't get information about user"));
326
327 goto error;
328 }
329
330 // Convert the Unicode full name to ANSI
331 WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1,
332 buf, maxSize, NULL, NULL );
333
334 return true;
335
336 error:
337 wxLogError(wxT("Couldn't look up full user name."));
338
339 return false;
340 #else // !USE_NET_API
341 // Could use NIS, MS-Mail or other site specific programs
342 // Use wxWidgets configuration data
343 bool ok = GetProfileString(WX_SECTION, eUSERNAME, wxEmptyString, buf, maxSize - 1) != 0;
344 if ( !ok )
345 {
346 ok = wxGetUserId(buf, maxSize);
347 }
348
349 if ( !ok )
350 {
351 wxStrncpy(buf, wxT("Unknown User"), maxSize);
352 }
353 #endif // Win32/16
354
355 return true;
356 }
357
358 const wxChar* wxGetHomeDir(wxString *pstr)
359 {
360 wxString& strDir = *pstr;
361
362 // first branch is for Cygwin
363 #if defined(__UNIX__)
364 const wxChar *szHome = wxGetenv("HOME");
365 if ( szHome == NULL ) {
366 // we're homeless...
367 wxLogWarning(_("can't find user's HOME, using current directory."));
368 strDir = wxT(".");
369 }
370 else
371 strDir = szHome;
372
373 // add a trailing slash if needed
374 if ( strDir.Last() != wxT('/') )
375 strDir << wxT('/');
376
377 #ifdef __CYGWIN__
378 // Cygwin returns unix type path but that does not work well
379 static wxChar windowsPath[MAX_PATH];
380 cygwin_conv_to_full_win32_path(strDir, windowsPath);
381 strDir = windowsPath;
382 #endif
383 #elif defined(__WXWINCE__)
384 // Nothing
385 #else
386 strDir.clear();
387
388 // If we have a valid HOME directory, as is used on many machines that
389 // have unix utilities on them, we should use that.
390 const wxChar *szHome = wxGetenv(wxT("HOME"));
391
392 if ( szHome != NULL )
393 {
394 strDir = szHome;
395 }
396 else // no HOME, try HOMEDRIVE/PATH
397 {
398 szHome = wxGetenv(wxT("HOMEDRIVE"));
399 if ( szHome != NULL )
400 strDir << szHome;
401 szHome = wxGetenv(wxT("HOMEPATH"));
402
403 if ( szHome != NULL )
404 {
405 strDir << szHome;
406
407 // the idea is that under NT these variables have default values
408 // of "%systemdrive%:" and "\\". As we don't want to create our
409 // config files in the root directory of the system drive, we will
410 // create it in our program's dir. However, if the user took care
411 // to set HOMEPATH to something other than "\\", we suppose that he
412 // knows what he is doing and use the supplied value.
413 if ( wxStrcmp(szHome, wxT("\\")) == 0 )
414 strDir.clear();
415 }
416 }
417
418 if ( strDir.empty() )
419 {
420 // If we have a valid USERPROFILE directory, as is the case in
421 // Windows NT, 2000 and XP, we should use that as our home directory.
422 szHome = wxGetenv(wxT("USERPROFILE"));
423
424 if ( szHome != NULL )
425 strDir = szHome;
426 }
427
428 if ( !strDir.empty() )
429 {
430 // sometimes the value of HOME may be "%USERPROFILE%", so reexpand the
431 // value once again, it shouldn't hurt anyhow
432 strDir = wxExpandEnvVars(strDir);
433 }
434 else // fall back to the program directory
435 {
436 // extract the directory component of the program file name
437 wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL);
438 }
439 #endif // UNIX/Win
440
441 return strDir.c_str();
442 }
443
444 wxChar *wxGetUserHome(const wxString& WXUNUSED(user))
445 {
446 // VZ: the old code here never worked for user != "" anyhow! Moreover, it
447 // returned sometimes a malloc()'d pointer, sometimes a pointer to a
448 // static buffer and sometimes I don't even know what.
449 static wxString s_home;
450
451 return (wxChar *)wxGetHomeDir(&s_home);
452 }
453
454 bool wxDirExists(const wxString& dir)
455 {
456 #ifdef __WXMICROWIN__
457 return wxPathExist(dir);
458 #elif defined(__WIN32__)
459 DWORD attribs = GetFileAttributes(dir);
460 return ((attribs != (DWORD)-1) && (attribs & FILE_ATTRIBUTE_DIRECTORY));
461 #endif // Win32/__WXMICROWIN__
462 }
463
464 bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
465 {
466 #ifdef __WXWINCE__
467 return false;
468 #else
469 if ( path.empty() )
470 return false;
471
472 // old w32api don't have ULARGE_INTEGER
473 #if defined(__WIN32__) && \
474 (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION( 0, 3 ))
475 // GetDiskFreeSpaceEx() is not available under original Win95, check for
476 // it
477 typedef BOOL (WINAPI *GetDiskFreeSpaceEx_t)(LPCTSTR,
478 PULARGE_INTEGER,
479 PULARGE_INTEGER,
480 PULARGE_INTEGER);
481
482 GetDiskFreeSpaceEx_t
483 pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress
484 (
485 ::GetModuleHandle(_T("kernel32.dll")),
486 #if wxUSE_UNICODE
487 "GetDiskFreeSpaceExW"
488 #else
489 "GetDiskFreeSpaceExA"
490 #endif
491 );
492
493 if ( pGetDiskFreeSpaceEx )
494 {
495 ULARGE_INTEGER bytesFree, bytesTotal;
496
497 // may pass the path as is, GetDiskFreeSpaceEx() is smart enough
498 if ( !pGetDiskFreeSpaceEx(path,
499 &bytesFree,
500 &bytesTotal,
501 NULL) )
502 {
503 wxLogLastError(_T("GetDiskFreeSpaceEx"));
504
505 return false;
506 }
507
508 // ULARGE_INTEGER is a union of a 64 bit value and a struct containing
509 // two 32 bit fields which may be or may be not named - try to make it
510 // compile in all cases
511 #if defined(__BORLANDC__) && !defined(_ANONYMOUS_STRUCT)
512 #define UL(ul) ul.u
513 #else // anon union
514 #define UL(ul) ul
515 #endif
516 if ( pTotal )
517 {
518 *pTotal = wxLongLong(UL(bytesTotal).HighPart, UL(bytesTotal).LowPart);
519 }
520
521 if ( pFree )
522 {
523 *pFree = wxLongLong(UL(bytesFree).HighPart, UL(bytesFree).LowPart);
524 }
525 }
526 else
527 #endif // Win32
528 {
529 // there's a problem with drives larger than 2GB, GetDiskFreeSpaceEx()
530 // should be used instead - but if it's not available, fall back on
531 // GetDiskFreeSpace() nevertheless...
532
533 DWORD lSectorsPerCluster,
534 lBytesPerSector,
535 lNumberOfFreeClusters,
536 lTotalNumberOfClusters;
537
538 // FIXME: this is wrong, we should extract the root drive from path
539 // instead, but this is the job for wxFileName...
540 if ( !::GetDiskFreeSpace(path,
541 &lSectorsPerCluster,
542 &lBytesPerSector,
543 &lNumberOfFreeClusters,
544 &lTotalNumberOfClusters) )
545 {
546 wxLogLastError(_T("GetDiskFreeSpace"));
547
548 return false;
549 }
550
551 wxLongLong lBytesPerCluster = lSectorsPerCluster;
552 lBytesPerCluster *= lBytesPerSector;
553
554 if ( pTotal )
555 {
556 *pTotal = lBytesPerCluster;
557 *pTotal *= lTotalNumberOfClusters;
558 }
559
560 if ( pFree )
561 {
562 *pFree = lBytesPerCluster;
563 *pFree *= lNumberOfFreeClusters;
564 }
565 }
566
567 return true;
568 #endif
569 // __WXWINCE__
570 }
571
572 // ----------------------------------------------------------------------------
573 // env vars
574 // ----------------------------------------------------------------------------
575
576 bool wxGetEnv(const wxString& var, wxString *value)
577 {
578 #ifdef __WXWINCE__
579 return false;
580 #else // Win32
581 // first get the size of the buffer
582 DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0);
583 if ( !dwRet )
584 {
585 // this means that there is no such variable
586 return false;
587 }
588
589 if ( value )
590 {
591 (void)::GetEnvironmentVariable(var, wxStringBuffer(*value, dwRet),
592 dwRet);
593 }
594
595 return true;
596 #endif // WinCE/32
597 }
598
599 bool wxSetEnv(const wxString& var, const wxChar *value)
600 {
601 // some compilers have putenv() or _putenv() or _wputenv() but it's better
602 // to always use Win32 function directly instead of dealing with them
603 #if defined(__WIN32__) && !defined(__WXWINCE__)
604 if ( !::SetEnvironmentVariable(var, value) )
605 {
606 wxLogLastError(_T("SetEnvironmentVariable"));
607
608 return false;
609 }
610
611 return true;
612 #else // no way to set env vars
613 return false;
614 #endif
615 }
616
617 // ----------------------------------------------------------------------------
618 // process management
619 // ----------------------------------------------------------------------------
620
621 // structure used to pass parameters from wxKill() to wxEnumFindByPidProc()
622 struct wxFindByPidParams
623 {
624 wxFindByPidParams() { hwnd = 0; pid = 0; }
625
626 // the HWND used to return the result
627 HWND hwnd;
628
629 // the PID we're looking from
630 DWORD pid;
631
632 DECLARE_NO_COPY_CLASS(wxFindByPidParams)
633 };
634
635 // wxKill helper: EnumWindows() callback which is used to find the first (top
636 // level) window belonging to the given process
637 BOOL CALLBACK wxEnumFindByPidProc(HWND hwnd, LPARAM lParam)
638 {
639 DWORD pid;
640 (void)::GetWindowThreadProcessId(hwnd, &pid);
641
642 wxFindByPidParams *params = (wxFindByPidParams *)lParam;
643 if ( pid == params->pid )
644 {
645 // remember the window we found
646 params->hwnd = hwnd;
647
648 // return FALSE to stop the enumeration
649 return FALSE;
650 }
651
652 // continue enumeration
653 return TRUE;
654 }
655
656 int wxKillAllChildren(long pid, wxSignal sig, wxKillError *krc);
657
658 int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
659 {
660 if (flags & wxKILL_CHILDREN)
661 wxKillAllChildren(pid, sig, krc);
662
663 // get the process handle to operate on
664 HANDLE hProcess = ::OpenProcess(SYNCHRONIZE |
665 PROCESS_TERMINATE |
666 PROCESS_QUERY_INFORMATION,
667 FALSE, // not inheritable
668 (DWORD)pid);
669 if ( hProcess == NULL )
670 {
671 if ( krc )
672 {
673 if ( ::GetLastError() == ERROR_ACCESS_DENIED )
674 {
675 *krc = wxKILL_ACCESS_DENIED;
676 }
677 else
678 {
679 *krc = wxKILL_NO_PROCESS;
680 }
681 }
682
683 return -1;
684 }
685
686 bool ok = true;
687 switch ( sig )
688 {
689 case wxSIGKILL:
690 // kill the process forcefully returning -1 as error code
691 if ( !::TerminateProcess(hProcess, (UINT)-1) )
692 {
693 wxLogSysError(_("Failed to kill process %d"), pid);
694
695 if ( krc )
696 {
697 // this is not supposed to happen if we could open the
698 // process
699 *krc = wxKILL_ERROR;
700 }
701
702 ok = false;
703 }
704 break;
705
706 case wxSIGNONE:
707 // do nothing, we just want to test for process existence
708 break;
709
710 default:
711 // any other signal means "terminate"
712 {
713 wxFindByPidParams params;
714 params.pid = (DWORD)pid;
715
716 // EnumWindows() has nice semantics: it returns 0 if it found
717 // something or if an error occured and non zero if it
718 // enumerated all the window
719 if ( !::EnumWindows(wxEnumFindByPidProc, (LPARAM)&params) )
720 {
721 // did we find any window?
722 if ( params.hwnd )
723 {
724 // tell the app to close
725 //
726 // NB: this is the harshest way, the app won't have
727 // opportunity to save any files, for example, but
728 // this is probably what we want here. If not we
729 // can also use SendMesageTimeout(WM_CLOSE)
730 if ( !::PostMessage(params.hwnd, WM_QUIT, 0, 0) )
731 {
732 wxLogLastError(_T("PostMessage(WM_QUIT)"));
733 }
734 }
735 else // it was an error then
736 {
737 wxLogLastError(_T("EnumWindows"));
738
739 ok = false;
740 }
741 }
742 else // no windows for this PID
743 {
744 if ( krc )
745 {
746 *krc = wxKILL_ERROR;
747 }
748
749 ok = false;
750 }
751 }
752 }
753
754 // the return code
755 DWORD rc;
756
757 if ( ok )
758 {
759 // as we wait for a short time, we can use just WaitForSingleObject()
760 // and not MsgWaitForMultipleObjects()
761 switch ( ::WaitForSingleObject(hProcess, 500 /* msec */) )
762 {
763 case WAIT_OBJECT_0:
764 // process terminated
765 if ( !::GetExitCodeProcess(hProcess, &rc) )
766 {
767 wxLogLastError(_T("GetExitCodeProcess"));
768 }
769 break;
770
771 default:
772 wxFAIL_MSG( _T("unexpected WaitForSingleObject() return") );
773 // fall through
774
775 case WAIT_FAILED:
776 wxLogLastError(_T("WaitForSingleObject"));
777 // fall through
778
779 case WAIT_TIMEOUT:
780 if ( krc )
781 {
782 *krc = wxKILL_ERROR;
783 }
784
785 rc = STILL_ACTIVE;
786 break;
787 }
788 }
789 else // !ok
790 {
791 // just to suppress the warnings about uninitialized variable
792 rc = 0;
793 }
794
795 ::CloseHandle(hProcess);
796
797 // the return code is the same as from Unix kill(): 0 if killed
798 // successfully or -1 on error
799 //
800 // be careful to interpret rc correctly: for wxSIGNONE we return success if
801 // the process exists, for all the other sig values -- if it doesn't
802 if ( ok &&
803 ((sig == wxSIGNONE) == (rc == STILL_ACTIVE)) )
804 {
805 if ( krc )
806 {
807 *krc = wxKILL_OK;
808 }
809
810 return 0;
811 }
812
813 // error
814 return -1;
815 }
816
817 HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
818 BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ;
819 BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ;
820
821 static void InitToolHelp32()
822 {
823 static bool s_initToolHelpDone = false;
824
825 if (s_initToolHelpDone)
826 return;
827
828 s_initToolHelpDone = true;
829
830 lpfCreateToolhelp32Snapshot = NULL;
831 lpfProcess32First = NULL;
832 lpfProcess32Next = NULL;
833
834 HINSTANCE hInstLib = LoadLibrary( wxT("Kernel32.DLL") ) ;
835 if( hInstLib == NULL )
836 return ;
837
838 // Get procedure addresses.
839 // We are linking to these functions of Kernel32
840 // explicitly, because otherwise a module using
841 // this code would fail to load under Windows NT,
842 // which does not have the Toolhelp32
843 // functions in the Kernel 32.
844 lpfCreateToolhelp32Snapshot=
845 (HANDLE(WINAPI *)(DWORD,DWORD))
846 GetProcAddress( hInstLib,
847 #ifdef __WXWINCE__
848 wxT("CreateToolhelp32Snapshot")
849 #else
850 "CreateToolhelp32Snapshot"
851 #endif
852 ) ;
853
854 lpfProcess32First=
855 (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
856 GetProcAddress( hInstLib,
857 #ifdef __WXWINCE__
858 wxT("Process32First")
859 #else
860 "Process32First"
861 #endif
862 ) ;
863
864 lpfProcess32Next=
865 (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
866 GetProcAddress( hInstLib,
867 #ifdef __WXWINCE__
868 wxT("Process32Next")
869 #else
870 "Process32Next"
871 #endif
872 ) ;
873
874 FreeLibrary( hInstLib ) ;
875 }
876
877 // By John Skiff
878 int wxKillAllChildren(long pid, wxSignal sig, wxKillError *krc)
879 {
880 InitToolHelp32();
881
882 if (krc)
883 *krc = wxKILL_OK;
884
885 // If not implemented for this platform (e.g. NT 4.0), silently ignore
886 if (!lpfCreateToolhelp32Snapshot || !lpfProcess32First || !lpfProcess32Next)
887 return 0;
888
889 // Take a snapshot of all processes in the system.
890 HANDLE hProcessSnap = lpfCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
891 if (hProcessSnap == INVALID_HANDLE_VALUE) {
892 if (krc)
893 *krc = wxKILL_ERROR;
894 return -1;
895 }
896
897 //Fill in the size of the structure before using it.
898 PROCESSENTRY32 pe = {0};
899 pe.dwSize = sizeof(PROCESSENTRY32);
900
901 // Walk the snapshot of the processes, and for each process,
902 // kill it if its parent is pid.
903 if (!lpfProcess32First(hProcessSnap, &pe)) {
904 // Can't get first process.
905 if (krc)
906 *krc = wxKILL_ERROR;
907 CloseHandle (hProcessSnap);
908 return -1;
909 }
910
911 do {
912 if (pe.th32ParentProcessID == (DWORD) pid) {
913 if (wxKill(pe.th32ProcessID, sig, krc))
914 return -1;
915 }
916 } while (lpfProcess32Next (hProcessSnap, &pe));
917
918
919 return 0;
920 }
921
922 // Execute a program in an Interactive Shell
923 bool wxShell(const wxString& command)
924 {
925 wxString cmd;
926
927 #ifdef __WXWINCE__
928 cmd = command;
929 #else
930 wxChar *shell = wxGetenv(wxT("COMSPEC"));
931 if ( !shell )
932 shell = (wxChar*) wxT("\\COMMAND.COM");
933
934 if ( !command )
935 {
936 // just the shell
937 cmd = shell;
938 }
939 else
940 {
941 // pass the command to execute to the command processor
942 cmd.Printf(wxT("%s /c %s"), shell, command.c_str());
943 }
944 #endif
945
946 return wxExecute(cmd, wxEXEC_SYNC) == 0;
947 }
948
949 // Shutdown or reboot the PC
950 bool wxShutdown(wxShutdownFlags wFlags)
951 {
952 #ifdef __WXWINCE__
953 return false;
954 #elif defined(__WIN32__)
955 bool bOK = true;
956
957 if ( wxGetOsVersion(NULL, NULL) == wxWINDOWS_NT ) // if is NT or 2K
958 {
959 // Get a token for this process.
960 HANDLE hToken;
961 bOK = ::OpenProcessToken(GetCurrentProcess(),
962 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
963 &hToken) != 0;
964 if ( bOK )
965 {
966 TOKEN_PRIVILEGES tkp;
967
968 // Get the LUID for the shutdown privilege.
969 ::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
970 &tkp.Privileges[0].Luid);
971
972 tkp.PrivilegeCount = 1; // one privilege to set
973 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
974
975 // Get the shutdown privilege for this process.
976 ::AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
977 (PTOKEN_PRIVILEGES)NULL, 0);
978
979 // Cannot test the return value of AdjustTokenPrivileges.
980 bOK = ::GetLastError() == ERROR_SUCCESS;
981 }
982 }
983
984 if ( bOK )
985 {
986 UINT flags = EWX_SHUTDOWN | EWX_FORCE;
987 switch ( wFlags )
988 {
989 case wxSHUTDOWN_POWEROFF:
990 flags |= EWX_POWEROFF;
991 break;
992
993 case wxSHUTDOWN_REBOOT:
994 flags |= EWX_REBOOT;
995 break;
996
997 default:
998 wxFAIL_MSG( _T("unknown wxShutdown() flag") );
999 return false;
1000 }
1001
1002 bOK = ::ExitWindowsEx(flags, 0) != 0;
1003 }
1004
1005 return bOK;
1006 #endif // Win32/16
1007 }
1008
1009 // ----------------------------------------------------------------------------
1010 // misc
1011 // ----------------------------------------------------------------------------
1012
1013 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
1014 wxMemorySize wxGetFreeMemory()
1015 {
1016 #if defined(__WIN64__)
1017 MEMORYSTATUSEX memStatex;
1018 statex.dwLength = sizeof (statex);
1019 ::GlobalMemoryStatusEx (&statex);
1020 return (wxMemorySize)memStatus.ullAvailPhys;
1021 #else /* if defined(__WIN32__) */
1022 MEMORYSTATUS memStatus;
1023 memStatus.dwLength = sizeof(MEMORYSTATUS);
1024 ::GlobalMemoryStatus(&memStatus);
1025 return (wxMemorySize)memStatus.dwAvailPhys;
1026 #endif
1027 }
1028
1029 unsigned long wxGetProcessId()
1030 {
1031 return ::GetCurrentProcessId();
1032 }
1033
1034 // Emit a beeeeeep
1035 void wxBell()
1036 {
1037 ::MessageBeep((UINT)-1); // default sound
1038 }
1039
1040 bool wxIsDebuggerRunning()
1041 {
1042 // IsDebuggerPresent() is not available under Win95, so load it dynamically
1043 wxDynamicLibrary dll(_T("kernel32.dll"), wxDL_VERBATIM);
1044
1045 typedef BOOL (WINAPI *IsDebuggerPresent_t)();
1046 if ( !dll.HasSymbol(_T("IsDebuggerPresent")) )
1047 {
1048 // no way to know, assume no
1049 return false;
1050 }
1051
1052 return (*(IsDebuggerPresent_t)dll.GetSymbol(_T("IsDebuggerPresent")))() != 0;
1053 }
1054
1055 // ----------------------------------------------------------------------------
1056 // OS version
1057 // ----------------------------------------------------------------------------
1058
1059 wxString wxGetOsDescription()
1060 {
1061 wxString str;
1062
1063 OSVERSIONINFO info;
1064 wxZeroMemory(info);
1065
1066 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1067 if ( ::GetVersionEx(&info) )
1068 {
1069 switch ( info.dwPlatformId )
1070 {
1071 case VER_PLATFORM_WIN32s:
1072 str = _("Win32s on Windows 3.1");
1073 break;
1074
1075 case VER_PLATFORM_WIN32_WINDOWS:
1076 switch (info.dwMinorVersion)
1077 {
1078 case 0:
1079 if ( info.szCSDVersion[1] == 'B' ||
1080 info.szCSDVersion[1] == 'C' )
1081 {
1082 str = _("Windows 95 OSR2");
1083 }
1084 else
1085 {
1086 str = _("Windows 95");
1087 }
1088 break;
1089 case 10:
1090 if ( info.szCSDVersion[1] == 'B' ||
1091 info.szCSDVersion[1] == 'C' )
1092 {
1093 str = _("Windows 98 SE");
1094 }
1095 else
1096 {
1097 str = _("Windows 98");
1098 }
1099 break;
1100 case 90:
1101 str = _("Windows ME");
1102 break;
1103 default:
1104 str.Printf(_("Windows 9x (%d.%d)"),
1105 info.dwMajorVersion,
1106 info.dwMinorVersion);
1107 break;
1108 }
1109 if ( !wxIsEmpty(info.szCSDVersion) )
1110 {
1111 str << _T(" (") << info.szCSDVersion << _T(')');
1112 }
1113 break;
1114
1115 case VER_PLATFORM_WIN32_NT:
1116 if ( info.dwMajorVersion == 5 )
1117 {
1118 switch ( info.dwMinorVersion )
1119 {
1120 case 0:
1121 str.Printf(_("Windows 2000 (build %lu"),
1122 info.dwBuildNumber);
1123 break;
1124 case 1:
1125 str.Printf(_("Windows XP (build %lu"),
1126 info.dwBuildNumber);
1127 break;
1128 case 2:
1129 str.Printf(_("Windows Server 2003 (build %lu"),
1130 info.dwBuildNumber);
1131 break;
1132 }
1133 }
1134 if ( wxIsEmpty(str) )
1135 {
1136 str.Printf(_("Windows NT %lu.%lu (build %lu"),
1137 info.dwMajorVersion,
1138 info.dwMinorVersion,
1139 info.dwBuildNumber);
1140 }
1141 if ( !wxIsEmpty(info.szCSDVersion) )
1142 {
1143 str << _T(", ") << info.szCSDVersion;
1144 }
1145 str << _T(')');
1146 break;
1147 }
1148 }
1149 else
1150 {
1151 wxFAIL_MSG( _T("GetVersionEx() failed") ); // should never happen
1152 }
1153
1154 return str;
1155 }
1156
1157 wxToolkitInfo& wxAppTraits::GetToolkitInfo()
1158 {
1159 // cache the version info, it's not going to change
1160 //
1161 // NB: this is MT-safe, we may use these static vars from different threads
1162 // but as they always have the same value it doesn't matter
1163 static int s_ver = -1,
1164 s_major = -1,
1165 s_minor = -1;
1166
1167 if ( s_ver == -1 )
1168 {
1169 OSVERSIONINFO info;
1170 wxZeroMemory(info);
1171
1172 s_ver = wxWINDOWS;
1173 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1174 if ( ::GetVersionEx(&info) )
1175 {
1176 s_major = info.dwMajorVersion;
1177 s_minor = info.dwMinorVersion;
1178
1179 switch ( info.dwPlatformId )
1180 {
1181 case VER_PLATFORM_WIN32s:
1182 s_ver = wxWIN32S;
1183 break;
1184
1185 case VER_PLATFORM_WIN32_WINDOWS:
1186 s_ver = wxWIN95;
1187 break;
1188
1189 case VER_PLATFORM_WIN32_NT:
1190 s_ver = wxWINDOWS_NT;
1191 break;
1192 #ifdef __WXWINCE__
1193 case VER_PLATFORM_WIN32_CE:
1194 s_ver = wxWINDOWS_CE;
1195 break;
1196 #endif
1197 }
1198 }
1199 }
1200
1201 static wxToolkitInfo info;
1202 info.versionMajor = s_major;
1203 info.versionMinor = s_minor;
1204 info.os = s_ver;
1205 info.name = _T("wxBase");
1206 return info;
1207 }
1208
1209 // ----------------------------------------------------------------------------
1210 // sleep functions
1211 // ----------------------------------------------------------------------------
1212
1213 void wxMilliSleep(unsigned long milliseconds)
1214 {
1215 ::Sleep(milliseconds);
1216 }
1217
1218 void wxMicroSleep(unsigned long microseconds)
1219 {
1220 wxMilliSleep(microseconds/1000);
1221 }
1222
1223 void wxSleep(int nSecs)
1224 {
1225 wxMilliSleep(1000*nSecs);
1226 }
1227
1228 // ----------------------------------------------------------------------------
1229 // font encoding <-> Win32 codepage conversion functions
1230 // ----------------------------------------------------------------------------
1231
1232 extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding)
1233 {
1234 switch ( encoding )
1235 {
1236 // although this function is supposed to return an exact match, do do
1237 // some mappings here for the most common case of "standard" encoding
1238 case wxFONTENCODING_SYSTEM:
1239 return DEFAULT_CHARSET;
1240
1241 case wxFONTENCODING_ISO8859_1:
1242 case wxFONTENCODING_ISO8859_15:
1243 case wxFONTENCODING_CP1252:
1244 return ANSI_CHARSET;
1245
1246 #if !defined(__WXMICROWIN__)
1247 // The following four fonts are multi-byte charsets
1248 case wxFONTENCODING_CP932:
1249 return SHIFTJIS_CHARSET;
1250
1251 case wxFONTENCODING_CP936:
1252 return GB2312_CHARSET;
1253
1254 case wxFONTENCODING_CP949:
1255 return HANGUL_CHARSET;
1256
1257 case wxFONTENCODING_CP950:
1258 return CHINESEBIG5_CHARSET;
1259
1260 // The rest are single byte encodings
1261 case wxFONTENCODING_CP1250:
1262 return EASTEUROPE_CHARSET;
1263
1264 case wxFONTENCODING_CP1251:
1265 return RUSSIAN_CHARSET;
1266
1267 case wxFONTENCODING_CP1253:
1268 return GREEK_CHARSET;
1269
1270 case wxFONTENCODING_CP1254:
1271 return TURKISH_CHARSET;
1272
1273 case wxFONTENCODING_CP1255:
1274 return HEBREW_CHARSET;
1275
1276 case wxFONTENCODING_CP1256:
1277 return ARABIC_CHARSET;
1278
1279 case wxFONTENCODING_CP1257:
1280 return BALTIC_CHARSET;
1281
1282 case wxFONTENCODING_CP874:
1283 return THAI_CHARSET;
1284 #endif // !__WXMICROWIN__
1285
1286 case wxFONTENCODING_CP437:
1287 return OEM_CHARSET;
1288
1289 default:
1290 // no way to translate this encoding into a Windows charset
1291 return -1;
1292 }
1293 }
1294
1295 // we have 2 versions of wxCharsetToCodepage(): the old one which directly
1296 // looks up the vlaues in the registry and the new one which is more
1297 // politically correct and has more chances to work on other Windows versions
1298 // as well but the old version is still needed for !wxUSE_FONTMAP case
1299 #if wxUSE_FONTMAP
1300
1301 #include "wx/fontmap.h"
1302
1303 extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding)
1304 {
1305 // There don't seem to be symbolic names for
1306 // these under Windows so I just copied the
1307 // values from MSDN.
1308
1309 unsigned int ret;
1310
1311 switch (encoding)
1312 {
1313 case wxFONTENCODING_ISO8859_1: ret = 28591; break;
1314 case wxFONTENCODING_ISO8859_2: ret = 28592; break;
1315 case wxFONTENCODING_ISO8859_3: ret = 28593; break;
1316 case wxFONTENCODING_ISO8859_4: ret = 28594; break;
1317 case wxFONTENCODING_ISO8859_5: ret = 28595; break;
1318 case wxFONTENCODING_ISO8859_6: ret = 28596; break;
1319 case wxFONTENCODING_ISO8859_7: ret = 28597; break;
1320 case wxFONTENCODING_ISO8859_8: ret = 28598; break;
1321 case wxFONTENCODING_ISO8859_9: ret = 28599; break;
1322 case wxFONTENCODING_ISO8859_10: ret = 28600; break;
1323 case wxFONTENCODING_ISO8859_11: ret = 28601; break;
1324 // case wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
1325 case wxFONTENCODING_ISO8859_13: ret = 28603; break;
1326 case wxFONTENCODING_ISO8859_14: ret = 28604; break;
1327 case wxFONTENCODING_ISO8859_15: ret = 28605; break;
1328 case wxFONTENCODING_KOI8: ret = 20866; break;
1329 case wxFONTENCODING_KOI8_U: ret = 21866; break;
1330 case wxFONTENCODING_CP437: ret = 437; break;
1331 case wxFONTENCODING_CP850: ret = 850; break;
1332 case wxFONTENCODING_CP852: ret = 852; break;
1333 case wxFONTENCODING_CP855: ret = 855; break;
1334 case wxFONTENCODING_CP866: ret = 866; break;
1335 case wxFONTENCODING_CP874: ret = 874; break;
1336 case wxFONTENCODING_CP932: ret = 932; break;
1337 case wxFONTENCODING_CP936: ret = 936; break;
1338 case wxFONTENCODING_CP949: ret = 949; break;
1339 case wxFONTENCODING_CP950: ret = 950; break;
1340 case wxFONTENCODING_CP1250: ret = 1250; break;
1341 case wxFONTENCODING_CP1251: ret = 1251; break;
1342 case wxFONTENCODING_CP1252: ret = 1252; break;
1343 case wxFONTENCODING_CP1253: ret = 1253; break;
1344 case wxFONTENCODING_CP1254: ret = 1254; break;
1345 case wxFONTENCODING_CP1255: ret = 1255; break;
1346 case wxFONTENCODING_CP1256: ret = 1256; break;
1347 case wxFONTENCODING_CP1257: ret = 1257; break;
1348 case wxFONTENCODING_EUC_JP: ret = 51932; break;
1349 case wxFONTENCODING_MACROMAN: ret = 10000; break;
1350 case wxFONTENCODING_MACJAPANESE: ret = 10001; break;
1351 case wxFONTENCODING_MACCHINESETRAD: ret = 10002; break;
1352 case wxFONTENCODING_MACKOREAN: ret = 10003; break;
1353 case wxFONTENCODING_MACARABIC: ret = 10004; break;
1354 case wxFONTENCODING_MACHEBREW: ret = 10005; break;
1355 case wxFONTENCODING_MACGREEK: ret = 10006; break;
1356 case wxFONTENCODING_MACCYRILLIC: ret = 10007; break;
1357 case wxFONTENCODING_MACTHAI: ret = 10021; break;
1358 case wxFONTENCODING_MACCHINESESIMP: ret = 10008; break;
1359 case wxFONTENCODING_MACCENTRALEUR: ret = 10029; break;
1360 case wxFONTENCODING_MACCROATIAN: ret = 10082; break;
1361 case wxFONTENCODING_MACICELANDIC: ret = 10079; break;
1362 case wxFONTENCODING_MACROMANIAN: ret = 10009; break;
1363 case wxFONTENCODING_UTF7: ret = 65000; break;
1364 case wxFONTENCODING_UTF8: ret = 65001; break;
1365 default: return -1;
1366 }
1367
1368 if (::IsValidCodePage(ret) == 0)
1369 return -1;
1370
1371 CPINFO info;
1372 if (::GetCPInfo(ret, &info) == 0)
1373 return -1;
1374
1375 return (long) ret;
1376 }
1377
1378 extern long wxCharsetToCodepage(const wxChar *name)
1379 {
1380 // first get the font encoding for this charset
1381 if ( !name )
1382 return -1;
1383
1384 wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(name, false);
1385 if ( enc == wxFONTENCODING_SYSTEM )
1386 return -1;
1387
1388 // the use the helper function
1389 return wxEncodingToCodepage(enc);
1390 }
1391
1392 #else // !wxUSE_FONTMAP
1393
1394 #include "wx/msw/registry.h"
1395
1396 // this should work if Internet Exploiter is installed
1397 extern long wxCharsetToCodepage(const wxChar *name)
1398 {
1399 if (!name)
1400 return GetACP();
1401
1402 long CP = -1;
1403
1404 wxString path(wxT("MIME\\Database\\Charset\\"));
1405 wxString cn(name);
1406
1407 // follow the alias loop
1408 for ( ;; )
1409 {
1410 wxRegKey key(wxRegKey::HKCR, path + cn);
1411
1412 if (!key.Exists())
1413 break;
1414
1415 // two cases: either there's an AliasForCharset string,
1416 // or there are Codepage and InternetEncoding dwords.
1417 // The InternetEncoding gives us the actual encoding,
1418 // the Codepage just says which Windows character set to
1419 // use when displaying the data.
1420 if (key.HasValue(wxT("InternetEncoding")) &&
1421 key.QueryValue(wxT("InternetEncoding"), &CP))
1422 break;
1423
1424 // no encoding, see if it's an alias
1425 if (!key.HasValue(wxT("AliasForCharset")) ||
1426 !key.QueryValue(wxT("AliasForCharset"), cn))
1427 break;
1428 }
1429
1430 return CP;
1431 }
1432
1433 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
1434
1435 /*
1436 Creates a hidden window with supplied window proc registering the class for
1437 it if necesssary (i.e. the first time only). Caller is responsible for
1438 destroying the window and unregistering the class (note that this must be
1439 done because wxWidgets may be used as a DLL and so may be loaded/unloaded
1440 multiple times into/from the same process so we cna't rely on automatic
1441 Windows class unregistration).
1442
1443 pclassname is a pointer to a caller stored classname, which must initially be
1444 NULL. classname is the desired wndclass classname. If function succesfully
1445 registers the class, pclassname will be set to classname.
1446 */
1447 extern "C" WXDLLIMPEXP_BASE HWND
1448 wxCreateHiddenWindow(LPCTSTR *pclassname, LPCTSTR classname, WNDPROC wndproc)
1449 {
1450 wxCHECK_MSG( classname && pclassname && wndproc, NULL,
1451 _T("NULL parameter in wxCreateHiddenWindow") );
1452
1453 // register the class fi we need to first
1454 if ( *pclassname == NULL )
1455 {
1456 WNDCLASS wndclass;
1457 wxZeroMemory(wndclass);
1458
1459 wndclass.lpfnWndProc = wndproc;
1460 wndclass.hInstance = wxGetInstance();
1461 wndclass.lpszClassName = classname;
1462
1463 if ( !::RegisterClass(&wndclass) )
1464 {
1465 wxLogLastError(wxT("RegisterClass() in wxCreateHiddenWindow"));
1466
1467 return NULL;
1468 }
1469
1470 *pclassname = classname;
1471 }
1472
1473 // next create the window
1474 HWND hwnd = ::CreateWindow
1475 (
1476 *pclassname,
1477 NULL,
1478 0, 0, 0, 0,
1479 0,
1480 (HWND) NULL,
1481 (HMENU)NULL,
1482 wxGetInstance(),
1483 (LPVOID) NULL
1484 );
1485
1486 if ( !hwnd )
1487 {
1488 wxLogLastError(wxT("CreateWindow() in wxCreateHiddenWindow"));
1489 }
1490
1491 return hwnd;
1492 }
1493