]> git.saurik.com Git - wxWidgets.git/blame - src/os2/utils.cpp
Committing in .
[wxWidgets.git] / src / os2 / utils.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose: Various utilities
45fcbf3b 4// Author: David Webster
0e320a79 5// Modified by:
45fcbf3b 6// Created: 09/17/99
0e320a79 7// RCS-ID: $Id$
45fcbf3b
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows license
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
45fcbf3b
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
16 #include "wx/setup.h"
17 #include "wx/utils.h"
18 #include "wx/app.h"
19 #include "wx/cursor.h"
20#endif //WX_PRECOMP
21
22#include "wx/os2/private.h"
23#include "wx/timer.h"
24#include "wx/intl.h"
25
0e320a79 26#include <ctype.h>
45fcbf3b
DW
27#include <direct.h>
28
29#include "wx/log.h"
30
31#include <io.h>
0e320a79
DW
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
45fcbf3b 36#include <errno.h>
0e320a79
DW
37#include <stdarg.h>
38
d90895ac 39#define INCL_DOS
86de7616 40#define INCL_PM
d90895ac 41#define INCL_GPI
86de7616 42#include <os2.h>
d90895ac 43#define PURE_32
7cdc2f1e
DW
44#include <upm.h>
45#include <netcons.h>
46#include <netbios.h>
45fcbf3b 47
86de7616
DW
48static const wxChar WX_SECTION[] = _T("wxWindows");
49static const wxChar eHOSTNAME[] = _T("HostName");
50static const wxChar eUSERID[] = _T("UserId");
51static const wxChar eUSERNAME[] = _T("UserName");
45fcbf3b
DW
52
53// For the following functions we SHOULD fill in support
54// for Windows-NT (which I don't know) as I assume it begin
55// a POSIX Unix (so claims MS) that it has some special
56// functions beyond those provided by WinSock
57
0e320a79 58// Get full hostname (eg. DoDo.BSn-Germany.crg.de)
10e5b930
DW
59bool wxGetHostName(
60 wxChar* zBuf
61, int nMaxSize
62)
0e320a79 63{
d90895ac 64#if wxUSE_NET_API
10e5b930
DW
65 char zServer[256];
66 char zComputer[256];
909b4f08 67 unsigned long ulLevel = 0;
10e5b930 68 unsigned char* zBuffer;
909b4f08
DW
69 unsigned long ulBuffer;
70 unsigned long* pulTotalAvail;
10e5b930 71
dde11e60
DW
72 NetBios32GetInfo( (const unsigned char*)zServer
73 ,(const unsigned char*)zComputer
909b4f08 74 ,ulLevel
dde11e60 75 ,zBuffer
909b4f08
DW
76 ,ulBuffer
77 ,pulTotalAvail
dde11e60 78 );
10e5b930 79 strcpy(zBuf, zServer);
45fcbf3b 80#else
10e5b930
DW
81 wxChar* zSysname;
82 const wxChar* zDefaultHost = _T("noname");
45fcbf3b 83
10e5b930
DW
84 if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL)
85 {
86 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
87 ,(PSZ)WX_SECTION
88 ,(PSZ)eHOSTNAME
89 ,(PSZ)zDefaultHost
90 ,(void*)zBuf
91 ,(ULONG)nMaxSize - 1
92 );
93 }
94 else
95 wxStrncpy(zBuf, zSysname, nMaxSize - 1);
96 zBuf[nMaxSize] = _T('\0');
45fcbf3b 97#endif
10e5b930 98 return *zBuf ? TRUE : FALSE;
0e320a79
DW
99}
100
101// Get user ID e.g. jacs
10e5b930
DW
102bool wxGetUserId(
103 wxChar* zBuf
2bd5bbc9 104, int nType
10e5b930 105)
0e320a79 106{
2bd5bbc9
DW
107 long lrc;
108 // UPM procs return 0 on success
109 lrc = U32ELOCU((unsigned char*)zBuf, (unsigned long *)&nType);
110 if (lrc == 0) return TRUE;
111 return FALSE;
0e320a79
DW
112}
113
10e5b930
DW
114bool wxGetUserName(
115 wxChar* zBuf
116, int nMaxSize
117)
0e320a79 118{
45fcbf3b 119#ifdef USE_NET_API
10e5b930
DW
120 wxGetUserId( zBuf
121 ,nMaxSize
122 );
45fcbf3b 123#else
10e5b930 124 wxStrncpy(zBuf, _T("Unknown User"), nMaxSize);
45fcbf3b 125#endif
10e5b930 126 return TRUE;
0e320a79
DW
127}
128
10e5b930
DW
129int wxKill(
130 long lPid
131, int nSig
132)
0e320a79 133{
10e5b930 134 return((int)::DosKillProcess(0, (PID)lPid));
0e320a79
DW
135}
136
137//
138// Execute a program in an Interactive Shell
139//
10e5b930
DW
140bool wxShell(
141 const wxString& rCommand
142)
0e320a79 143{
c5fb56c0
DW
144 wxChar* zShell = _T("CMD.EXE");
145 wxString sInputs;
10e5b930 146 wxChar zTmp[255];
c5fb56c0
DW
147 STARTDATA SData = {0};
148 PSZ PgmTitle = "Command Shell";
149 APIRET rc;
150 PID vPid = 0;
151 ULONG ulSessID = 0;
152 UCHAR achObjBuf[256] = {0}; //error data if DosStart fails
153 RESULTCODES vResult;
154
155 SData.Length = sizeof(STARTDATA);
156 SData.Related = SSF_RELATED_INDEPENDENT;
157 SData.FgBg = SSF_FGBG_FORE;
158 SData.TraceOpt = SSF_TRACEOPT_NONE;
159 SData.PgmTitle = PgmTitle;
160 SData.PgmName = zShell;
161
909b4f08 162 sInputs = "/C " + rCommand;
9ac6ff7b 163 SData.PgmInputs = (BYTE*)sInputs.c_str();
c5fb56c0
DW
164 SData.TermQ = 0;
165 SData.Environment = 0;
166 SData.InheritOpt = SSF_INHERTOPT_SHELL;
167 SData.SessionType = SSF_TYPE_WINDOWABLEVIO;
168 SData.IconFile = 0;
169 SData.PgmHandle = 0;
170 SData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
171 SData.InitXPos = 30;
172 SData.InitYPos = 40;
173 SData.InitXSize = 200;
174 SData.InitYSize = 140;
175 SData.Reserved = 0;
176 SData.ObjectBuffer = (char*)achObjBuf;
177 SData.ObjectBuffLen = (ULONG)sizeof(achObjBuf);
178
179 rc = ::DosStartSession(&SData, &ulSessID, &vPid);
9ac6ff7b 180 if (rc == 0 || rc == 457) // NO_ERROR or SMG_START_IN_BACKGROUND
c5fb56c0
DW
181 {
182 PTIB ptib;
183 PPIB ppib;
10e5b930 184
c5fb56c0 185 ::DosGetInfoBlocks(&ptib, &ppib);
10e5b930 186
c5fb56c0
DW
187 ::DosWaitChild( DCWA_PROCESS
188 ,DCWW_WAIT
189 ,&vResult
190 ,&ppib->pib_ulpid
191 ,vPid
192 );
193 }
194 return (rc != 0);
0e320a79
DW
195}
196
197// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
5d4b632b 198long wxGetFreeMemory()
0e320a79 199{
5d4b632b 200 void* pMemptr;
78d50441
DW
201 ULONG lSize;
202 ULONG lMemFlags;
203 APIRET rc;
204
205 lMemFlags = PAG_FREE;
10e5b930 206 rc = ::DosQueryMem(pMemptr, &lSize, &lMemFlags);
78d50441
DW
207 if (rc != 0)
208 return -1L;
209 return (long)lSize;
45fcbf3b
DW
210}
211
212// Sleep for nSecs seconds. Attempt a Windows implementation using timers.
213static bool inTimer = FALSE;
214
215class wxSleepTimer: public wxTimer
216{
10e5b930
DW
217public:
218 inline void Notify()
219 {
220 inTimer = FALSE;
221 Stop();
222 }
45fcbf3b
DW
223};
224
10e5b930 225static wxTimer* wxTheSleepTimer = NULL;
45fcbf3b 226
10e5b930
DW
227void wxUsleep(
228 unsigned long ulMilliseconds
229)
45fcbf3b 230{
10e5b930 231 ::DosSleep(ulMilliseconds);
0e320a79
DW
232}
233
10e5b930
DW
234void wxSleep(
235 int nSecs
236)
0e320a79 237{
10e5b930 238 ::DosSleep(1000 * nSecs);
0e320a79
DW
239}
240
241// Consume all events until no more left
242void wxFlushEvents()
243{
45fcbf3b 244// wxYield();
0e320a79
DW
245}
246
45fcbf3b 247// Output a debug mess., in a system dependent fashion.
10e5b930
DW
248void wxDebugMsg(
249 const wxChar* zFmt ...
250)
251{
252 va_list vAp;
253 static wxChar zBuffer[512];
254
255 if (!wxTheApp->GetWantDebugOutput())
256 return ;
257 va_start(vAp, zFmt);
258 sprintf(zBuffer, zFmt, vAp) ;
259 va_end(vAp);
0e320a79
DW
260}
261
262// Non-fatal error: pop up message box and (possibly) continue
10e5b930
DW
263void wxError(
264 const wxString& rMsg
265, const wxString& rTitle
266)
267{
13a4ea8d 268 wxBuffer = new wxChar[256];
10e5b930
DW
269 wxSprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST rMsg);
270 if (::WinMessageBox( HWND_DESKTOP
271 ,NULL
272 ,(PSZ)wxBuffer
273 ,(PSZ)WXSTRINGCAST rTitle
274 ,0
275 ,MB_ICONEXCLAMATION | MB_YESNO
276 ) == MBID_YES)
13a4ea8d 277 delete[] wxBuffer;
0e320a79
DW
278 wxExit();
279}
280
281// Fatal error: pop up message box and abort
10e5b930
DW
282void wxFatalError(
283 const wxString& rMsg
284, const wxString& rTitle
285)
286{
287 unsigned long ulRc;
288
289 ulRc = ::WinMessageBox( HWND_DESKTOP
290 ,NULL
291 ,WXSTRINGCAST rMsg
292 ,WXSTRINGCAST rTitle
293 ,0
294 ,MB_NOICON | MB_OK
295 );
296 DosExit(EXIT_PROCESS, ulRc);
0e320a79
DW
297}
298
299// Emit a beeeeeep
300void wxBell()
301{
45fcbf3b 302 DosBeep(1000,1000); // 1kHz during 1 sec.
0e320a79
DW
303}
304
45fcbf3b
DW
305// Chris Breeze 27/5/98: revised WIN32 code to
306// detect WindowsNT correctly
10e5b930
DW
307int wxGetOsVersion(
308 int* pMajorVsn
309, int* pMinorVsn
310)
311{
312 ULONG ulSysInfo[QSV_MAX] = {0};
5d4b632b
DW
313 APIRET ulrc;
314
315 ulrc = ::DosQuerySysInfo( 1L
316 ,QSV_MAX
317 ,(PVOID)ulSysInfo
318 ,sizeof(ULONG) * QSV_MAX
319 );
320 if (ulrc == 0L)
10e5b930
DW
321 {
322 *pMajorVsn = ulSysInfo[QSV_VERSION_MAJOR];
5d4b632b 323 *pMajorVsn = *pMajorVsn/10;
10e5b930
DW
324 *pMinorVsn = ulSysInfo[QSV_VERSION_MINOR];
325 return wxWINDOWS_OS2;
326 }
327 return wxWINDOWS; // error if we get here, return generic value
0e320a79
DW
328}
329
330// Reading and writing resources (eg WIN.INI, .Xdefaults)
331#if wxUSE_RESOURCES
10e5b930
DW
332bool wxWriteResource(
333 const wxString& rSection
334, const wxString& rEntry
335, const wxString& rValue
336, const wxString& rFile
337)
0e320a79 338{
78d50441
DW
339 HAB hab;
340 HINI hIni;
341
10e5b930 342 if (rFile != "")
78d50441 343 {
10e5b930 344 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
78d50441
DW
345 if (hIni != 0L)
346 {
347 return (::PrfWriteProfileString( hIni
10e5b930
DW
348 ,(PSZ)WXSTRINGCAST rSection
349 ,(PSZ)WXSTRINGCAST rEntry
350 ,(PSZ)WXSTRINGCAST rValue
78d50441
DW
351 ));
352 }
353 }
354 else
355 return (::PrfWriteProfileString( HINI_PROFILE
10e5b930
DW
356 ,(PSZ)WXSTRINGCAST rSection
357 ,(PSZ)WXSTRINGCAST rEntry
358 ,(PSZ)WXSTRINGCAST rValue
78d50441 359 ));
d90895ac 360 return FALSE;
0e320a79
DW
361}
362
10e5b930
DW
363bool wxWriteResource(
364 const wxString& rSection
365, const wxString& rEntry
366, float fValue
367, const wxString& rFile
368)
369{
370 wxChar zBuf[50];
371
372 wxSprintf(zBuf, "%.4f", fValue);
373 return wxWriteResource( rSection
374 ,rEntry
375 ,zBuf
376 ,rFile
377 );
0e320a79
DW
378}
379
1be7f92a
DW
380bool wxWriteResource(
381 const wxString& rSection
382, const wxString& rEntry
383, long lValue
384, const wxString& rFile
385)
0e320a79 386{
1be7f92a
DW
387 wxChar zBuf[50];
388
389 wxSprintf(zBuf, "%ld", lValue);
390 return wxWriteResource( rSection
391 ,rEntry
392 ,zBuf
393 ,rFile
394 );
0e320a79
DW
395}
396
1be7f92a
DW
397bool wxWriteResource(
398 const wxString& rSection
399, const wxString& rEntry
400, int lValue
401, const wxString& rFile
402)
0e320a79 403{
1be7f92a
DW
404 wxChar zBuf[50];
405
406 wxSprintf(zBuf, "%d", lValue);
407 return wxWriteResource( rSection
408 ,rEntry
409 ,zBuf
410 ,rFile
411 );
0e320a79
DW
412}
413
1be7f92a
DW
414bool wxGetResource(
415 const wxString& rSection
416, const wxString& rEntry
417, wxChar** ppValue
418, const wxString& rFile
419)
0e320a79 420{
78d50441
DW
421 HAB hab;
422 HINI hIni;
e8fd750b
DW
423 wxChar zDefunkt[] = _T("$$default");
424 char zBuf[1000];
78d50441 425
1be7f92a 426 if (rFile != "")
78d50441 427 {
1be7f92a 428 hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile);
78d50441
DW
429 if (hIni != 0L)
430 {
431 ULONG n = ::PrfQueryProfileString( hIni
1be7f92a
DW
432 ,(PSZ)WXSTRINGCAST rSection
433 ,(PSZ)WXSTRINGCAST rEntry
434 ,(PSZ)zDefunkt
e8fd750b 435 ,(PVOID)zBuf
78d50441
DW
436 ,1000
437 );
e8fd750b 438 if (zBuf == NULL)
78d50441 439 return FALSE;
e8fd750b
DW
440 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
441 return FALSE;
442 zBuf[n-1] = '\0';
78d50441
DW
443 }
444 else
445 return FALSE;
446 }
447 else
448 {
449 ULONG n = ::PrfQueryProfileString( HINI_PROFILE
1be7f92a
DW
450 ,(PSZ)WXSTRINGCAST rSection
451 ,(PSZ)WXSTRINGCAST rEntry
452 ,(PSZ)zDefunkt
e8fd750b 453 ,(PVOID)zBuf
78d50441
DW
454 ,1000
455 );
e8fd750b
DW
456 if (zBuf == NULL)
457 return FALSE;
458 if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0)
78d50441 459 return FALSE;
e8fd750b 460 zBuf[n-1] = '\0';
78d50441 461 }
e8fd750b 462 strcpy((char*)*ppValue, zBuf);
78d50441 463 return TRUE;
d90895ac 464}
0e320a79 465
1be7f92a
DW
466bool wxGetResource(
467 const wxString& rSection
468, const wxString& rEntry
469, float* pValue
470, const wxString& rFile
471)
0e320a79 472{
1be7f92a 473 wxChar* zStr = NULL;
13a4ea8d
DW
474
475 zStr = new wxChar[1000];
1be7f92a
DW
476 bool bSucc = wxGetResource( rSection
477 ,rEntry
478 ,(wxChar **)&zStr
479 ,rFile
480 );
481
482 if (bSucc)
483 {
484 *pValue = (float)wxStrtod(zStr, NULL);
485 delete[] zStr;
486 return TRUE;
487 }
13a4ea8d
DW
488 else
489 {
490 delete[] zStr;
491 return FALSE;
492 }
0e320a79
DW
493}
494
1be7f92a
DW
495bool wxGetResource(
496 const wxString& rSection
497, const wxString& rEntry
498, long* pValue
499, const wxString& rFile
500)
0e320a79 501{
1be7f92a 502 wxChar* zStr = NULL;
13a4ea8d
DW
503
504 zStr = new wxChar[1000];
1be7f92a
DW
505 bool bSucc = wxGetResource( rSection
506 ,rEntry
507 ,(wxChar **)&zStr
508 ,rFile
509 );
510
511 if (bSucc)
512 {
513 *pValue = wxStrtol(zStr, NULL, 10);
514 delete[] zStr;
515 return TRUE;
516 }
13a4ea8d
DW
517 else
518 {
519 delete[] zStr;
520 return FALSE;
521 }
0e320a79
DW
522}
523
1be7f92a
DW
524bool wxGetResource(
525 const wxString& rSection
526, const wxString& rEntry
527, int* pValue
528, const wxString& rFile
529)
0e320a79 530{
1be7f92a 531 wxChar* zStr = NULL;
13a4ea8d
DW
532
533 zStr = new wxChar[1000];
1be7f92a
DW
534 bool bSucc = wxGetResource( rSection
535 ,rEntry
536 ,(wxChar **)&zStr
537 ,rFile
538 );
539
540 if (bSucc)
541 {
542 *pValue = (int)wxStrtol(zStr, NULL, 10);
543 delete[] zStr;
544 return TRUE;
545 }
13a4ea8d
DW
546 else
547 {
548 delete[] zStr;
549 return FALSE;
550 }
0e320a79
DW
551}
552#endif // wxUSE_RESOURCES
553
45fcbf3b
DW
554// ---------------------------------------------------------------------------
555// helper functions for showing a "busy" cursor
556// ---------------------------------------------------------------------------
557
558HCURSOR gs_wxBusyCursor = 0; // new, busy cursor
559HCURSOR gs_wxBusyCursorOld = 0; // old cursor
560static int gs_wxBusyCursorCount = 0;
0e320a79
DW
561
562// Set the cursor to the busy cursor for all windows
1be7f92a
DW
563void wxBeginBusyCursor(
564 wxCursor* pCursor
565)
0e320a79 566{
45fcbf3b
DW
567 if ( gs_wxBusyCursorCount++ == 0 )
568 {
1be7f92a 569 gs_wxBusyCursor = (HCURSOR)pCursor->GetHCURSOR();
45fcbf3b
DW
570 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursor);
571 }
572 //else: nothing to do, already set
0e320a79
DW
573}
574
575// Restore cursor to normal
576void wxEndBusyCursor()
577{
1be7f92a
DW
578 wxCHECK_RET( gs_wxBusyCursorCount > 0
579 ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()")
580 );
45fcbf3b 581
1be7f92a 582 if (--gs_wxBusyCursorCount == 0)
45fcbf3b
DW
583 {
584 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)gs_wxBusyCursorOld);
585 gs_wxBusyCursorOld = 0;
586 }
0e320a79
DW
587}
588
589// TRUE if we're between the above two calls
590bool wxIsBusy()
591{
1be7f92a 592 return (gs_wxBusyCursorCount > 0);
45fcbf3b
DW
593}
594
595// ---------------------------------------------------------------------------
1be7f92a
DW
596const wxChar* wxGetHomeDir(
597 wxString* pStr
598)
45fcbf3b 599{
1be7f92a 600 wxString& rStrDir = *pStr;
0e320a79 601
1be7f92a
DW
602 // OS/2 has no idea about home,
603 // so use the working directory instead?
45fcbf3b 604
1be7f92a 605 // 256 was taken from os2def.h
45fcbf3b
DW
606#ifndef MAX_PATH
607# define MAX_PATH 256
608#endif
609
1be7f92a
DW
610 char zDirName[256];
611 ULONG ulDirLen;
45fcbf3b 612
1be7f92a
DW
613 ::DosQueryCurrentDir(0, zDirName, &ulDirLen);
614 rStrDir = zDirName;
615 return rStrDir.c_str();
45fcbf3b
DW
616}
617
10e5b930 618// Hack for OS/2
1be7f92a
DW
619wxChar* wxGetUserHome (
620 const wxString& rUser
621)
622{
623 wxChar* zHome;
624 wxString sUser1(rUser);
625
13a4ea8d 626 wxBuffer = new wxChar[256];
1be7f92a 627 if (sUser1 != _T(""))
45fcbf3b 628 {
1be7f92a
DW
629 wxChar zTmp[64];
630
631 if (wxGetUserId( zTmp
632 ,sizeof(zTmp)/sizeof(char)
633 ))
634 {
635 // Guests belong in the temp dir
636 if (wxStricmp(zTmp, _T("annonymous")) == 0)
637 {
638 if ((zHome = wxGetenv(_T("TMP"))) != NULL ||
639 (zHome = wxGetenv(_T("TMPDIR"))) != NULL ||
640 (zHome = wxGetenv(_T("TEMP"))) != NULL)
13a4ea8d 641 delete[] wxBuffer;
1be7f92a
DW
642 return *zHome ? zHome : (wxChar*)_T("\\");
643 }
644 if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0)
645 sUser1 = _T("");
646 }
45fcbf3b 647 }
1be7f92a 648 if (sUser1 == _T(""))
13a4ea8d 649 {
1be7f92a
DW
650 if ((zHome = wxGetenv(_T("HOME"))) != NULL)
651 {
652 wxStrcpy(wxBuffer, zHome);
653 Unix2DosFilename(wxBuffer);
13a4ea8d
DW
654 wxStrcpy(zHome, wxBuffer);
655 delete[] wxBuffer;
656 return zHome;
1be7f92a 657 }
13a4ea8d
DW
658 }
659 delete[] wxBuffer;
660 return NULL; // No home known!
0e320a79
DW
661}
662
663// Check whether this window wants to process messages, e.g. Stop button
664// in long calculations.
1be7f92a
DW
665bool wxCheckForInterrupt(
666 wxWindow* pWnd
667)
0e320a79 668{
1be7f92a
DW
669 if(pWnd)
670 {
671 QMSG vMsg;
672 HAB hab;
673 HWND hwndFilter;
674 HWND hwndWin= (HWND) pWnd->GetHWND();
45fcbf3b 675
1be7f92a
DW
676 while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE))
677 {
678 ::WinDispatchMsg(hab, &vMsg);
679 }
680 return TRUE;//*** temporary?
681 }
682 else
45fcbf3b 683 {
1be7f92a
DW
684 wxFAIL_MSG(_T("pWnd==NULL !!!"));
685 return FALSE;//*** temporary?
45fcbf3b 686 }
45fcbf3b
DW
687}
688
1be7f92a
DW
689void wxGetMousePosition(
690 int* pX
691, int* pY
692)
0e320a79 693{
1be7f92a
DW
694 POINTL vPt;
695
696 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
697 *pX = vPt.x;
698 *pY = vPt.y;
0e320a79
DW
699};
700
701// Return TRUE if we have a colour display
702bool wxColourDisplay()
703{
1be7f92a
DW
704 HPS hpsScreen;
705 HDC hdcScreen;
706 LONG lColors;
707
708 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
709 hdcScreen = ::GpiQueryDevice(hpsScreen);
710 ::DevQueryCaps(hdcScreen, CAPS_COLORS, 1L, &lColors);
711 return(lColors > 1L);
0e320a79
DW
712}
713
714// Returns depth of screen
715int wxDisplayDepth()
716{
1be7f92a
DW
717 HPS hpsScreen;
718 HDC hdcScreen;
719 LONG lPlanes;
720 LONG lBitsPerPixel;
721 LONG nDepth;
722
723 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
724 hdcScreen = ::GpiQueryDevice(hpsScreen);
725 ::DevQueryCaps(hdcScreen, CAPS_COLOR_PLANES, 1L, &lPlanes);
726 ::DevQueryCaps(hdcScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitsPerPixel);
727
728 nDepth = (int)(lPlanes * lBitsPerPixel);
729 DevCloseDC(hdcScreen);
d90895ac 730 return (nDepth);
0e320a79
DW
731}
732
733// Get size of display
1be7f92a
DW
734void wxDisplaySize(
735 int* pWidth
736, int* pHeight
737)
0e320a79 738{
1be7f92a
DW
739 HPS hpsScreen;
740 HDC hdcScreen;
45fcbf3b 741
1be7f92a
DW
742 hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
743 hdcScreen = ::GpiQueryDevice(hpsScreen);
744 ::DevQueryCaps(hdcScreen, CAPS_WIDTH, 1L, (PLONG)pWidth);
745 ::DevQueryCaps(hdcScreen, CAPS_HEIGHT, 1L, (PLONG)pHeight);
746 DevCloseDC(hdcScreen);
45fcbf3b
DW
747}
748
1be7f92a
DW
749bool wxDirExists(
750 const wxString& rDir
751)
45fcbf3b 752{
1be7f92a 753 return (::DosSetCurrentDir(WXSTRINGCAST rDir));
45fcbf3b
DW
754}
755
756// ---------------------------------------------------------------------------
757// window information functions
758// ---------------------------------------------------------------------------
759
1be7f92a
DW
760wxString WXDLLEXPORT wxGetWindowText(
761 WXHWND hWnd
762)
45fcbf3b 763{
1be7f92a
DW
764 wxString vStr;
765 long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
766
767 ::WinQueryWindowText((HWND)hWnd, lLen, vStr.GetWriteBuf((int)lLen));
768 vStr.UngetWriteBuf();
45fcbf3b 769
1be7f92a 770 return vStr;
45fcbf3b
DW
771}
772
1be7f92a
DW
773wxString WXDLLEXPORT wxGetWindowClass(
774 WXHWND hWnd
775)
45fcbf3b 776{
1be7f92a
DW
777 wxString vStr;
778 int nLen = 256; // some starting value
45fcbf3b
DW
779
780 for ( ;; )
781 {
1be7f92a 782 int nCount = ::WinQueryClassName((HWND)hWnd, nLen, vStr.GetWriteBuf(nLen));
45fcbf3b 783
1be7f92a
DW
784 vStr.UngetWriteBuf();
785 if (nCount == nLen )
45fcbf3b
DW
786 {
787 // the class name might have been truncated, retry with larger
788 // buffer
1be7f92a 789 nLen *= 2;
45fcbf3b
DW
790 }
791 else
792 {
793 break;
794 }
795 }
1be7f92a 796 return vStr;
45fcbf3b
DW
797}
798
1be7f92a
DW
799WXWORD WXDLLEXPORT wxGetWindowId(
800 WXHWND hWnd
801)
45fcbf3b
DW
802{
803 return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
0e320a79
DW
804}
805