1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/utilsgui.cpp
3 // Purpose: Various utility functions only available in wxMSW GUI
4 // Author: Vadim Zeitlin
6 // Created: 21.06.2003 (extracted from msw/utils.cpp)
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/cursor.h"
28 #include "wx/window.h"
32 #include "wx/dynlib.h"
34 #include "wx/msw/private.h" // includes <windows.h>
36 // ============================================================================
38 // ============================================================================
43 ::MessageBeep((UINT
)-1); // default sound
46 // ---------------------------------------------------------------------------
47 // helper functions for showing a "busy" cursor
48 // ---------------------------------------------------------------------------
50 static HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
51 static HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
52 static int gs_wxBusyCursorCount
= 0;
54 extern HCURSOR
wxGetCurrentBusyCursor()
56 return gs_wxBusyCursor
;
59 // Set the cursor to the busy cursor for all windows
60 void wxBeginBusyCursor(const wxCursor
*cursor
)
62 if ( gs_wxBusyCursorCount
++ == 0 )
64 gs_wxBusyCursor
= (HCURSOR
)cursor
->GetHCURSOR();
65 #ifndef __WXMICROWIN__
66 gs_wxBusyCursorOld
= ::SetCursor(gs_wxBusyCursor
);
69 //else: nothing to do, already set
72 // Restore cursor to normal
73 void wxEndBusyCursor()
75 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
76 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
78 if ( --gs_wxBusyCursorCount
== 0 )
80 #ifndef __WXMICROWIN__
81 ::SetCursor(gs_wxBusyCursorOld
);
83 gs_wxBusyCursorOld
= 0;
87 // true if we're between the above two calls
90 return gs_wxBusyCursorCount
> 0;
93 // Check whether this window wants to process messages, e.g. Stop button
94 // in long calculations.
95 bool wxCheckForInterrupt(wxWindow
*wnd
)
97 wxCHECK( wnd
, false );
100 while ( ::PeekMessage(&msg
, GetHwndOf(wnd
), 0, 0, PM_REMOVE
) )
102 ::TranslateMessage(&msg
);
103 ::DispatchMessage(&msg
);
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 // See also the wxGetMousePosition in window.cpp
114 // Deprecated: use wxPoint wxGetMousePosition() instead
115 void wxGetMousePosition( int* x
, int* y
)
118 wxGetCursorPosMSW( & pt
);
123 // Return true if we have a colour display
124 bool wxColourDisplay()
126 #ifdef __WXMICROWIN__
130 // this function is called from wxDC ctor so it is called a *lot* of times
131 // hence we optimize it a bit but doing the check only once
133 // this should be MT safe as only the GUI thread (holding the GUI mutex)
135 static int s_isColour
= -1;
137 if ( s_isColour
== -1 )
140 int noCols
= ::GetDeviceCaps(dc
, NUMCOLORS
);
142 s_isColour
= (noCols
== -1) || (noCols
> 2);
145 return s_isColour
!= 0;
149 // Returns depth of screen
153 return GetDeviceCaps(dc
, PLANES
) * GetDeviceCaps(dc
, BITSPIXEL
);
156 // Get size of display
157 void wxDisplaySize(int *width
, int *height
)
159 #ifdef __WXMICROWIN__
161 HWND hWnd
= GetDesktopWindow();
162 ::GetWindowRect(hWnd
, & rect
);
165 *width
= rect
.right
- rect
.left
;
167 *height
= rect
.bottom
- rect
.top
;
168 #else // !__WXMICROWIN__
172 *width
= ::GetDeviceCaps(dc
, HORZRES
);
174 *height
= ::GetDeviceCaps(dc
, VERTRES
);
175 #endif // __WXMICROWIN__/!__WXMICROWIN__
178 void wxDisplaySizeMM(int *width
, int *height
)
180 #ifdef __WXMICROWIN__
190 *width
= ::GetDeviceCaps(dc
, HORZSIZE
);
192 *height
= ::GetDeviceCaps(dc
, VERTSIZE
);
196 // ---------------------------------------------------------------------------
197 // window information functions
198 // ---------------------------------------------------------------------------
200 wxString WXDLLEXPORT
wxGetWindowText(WXHWND hWnd
)
206 int len
= GetWindowTextLength((HWND
)hWnd
) + 1;
207 ::GetWindowText((HWND
)hWnd
, wxStringBuffer(str
, len
), len
);
213 wxString WXDLLEXPORT
wxGetWindowClass(WXHWND hWnd
)
218 #ifndef __WXMICROWIN__
221 int len
= 256; // some starting value
225 int count
= ::GetClassName((HWND
)hWnd
, wxStringBuffer(str
, len
), len
);
229 // the class name might have been truncated, retry with larger
239 #endif // !__WXMICROWIN__
244 int WXDLLEXPORT
wxGetWindowId(WXHWND hWnd
)
246 return ::GetWindowLong((HWND
)hWnd
, GWL_ID
);
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
)
255 int iWidthMM
= GetDeviceCaps(hdcRef
, HORZSIZE
),
256 iHeightMM
= GetDeviceCaps(hdcRef
, VERTSIZE
),
257 iWidthPels
= GetDeviceCaps(hdcRef
, HORZRES
),
258 iHeightPels
= GetDeviceCaps(hdcRef
, VERTRES
);
260 *x
*= (iWidthMM
* 100);
262 *y
*= (iHeightMM
* 100);
266 void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
)
268 int iWidthMM
= GetDeviceCaps(hdcRef
, HORZSIZE
),
269 iHeightMM
= GetDeviceCaps(hdcRef
, VERTSIZE
),
270 iWidthPels
= GetDeviceCaps(hdcRef
, HORZRES
),
271 iHeightPels
= GetDeviceCaps(hdcRef
, VERTRES
);
274 *x
/= (iWidthMM
* 100);
276 *y
/= (iHeightMM
* 100);
279 void HIMETRICToPixel(LONG
*x
, LONG
*y
)
281 HIMETRICToPixel(x
, y
, ScreenHDC());
284 void PixelToHIMETRIC(LONG
*x
, LONG
*y
)
286 PixelToHIMETRIC(x
, y
, ScreenHDC());
289 void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
)
297 Polyline(hdc
, points
, 2);
299 MoveToEx(hdc
, x1
, y1
, NULL
); LineTo((HDC
) hdc
, x2
, y2
);
304 // ----------------------------------------------------------------------------
305 // Shell API wrappers
306 // ----------------------------------------------------------------------------
308 extern bool wxEnableFileNameAutoComplete(HWND hwnd
)
310 #if wxUSE_DYNLIB_CLASS
311 typedef HRESULT (WINAPI
*SHAutoComplete_t
)(HWND
, DWORD
);
313 static SHAutoComplete_t s_pfnSHAutoComplete
= NULL
;
314 static bool s_initialized
= false;
316 if ( !s_initialized
)
318 s_initialized
= true;
321 wxDynamicLibrary
dll(wxT("shlwapi.dll"));
322 if ( dll
.IsLoaded() )
324 s_pfnSHAutoComplete
=
325 (SHAutoComplete_t
)dll
.GetSymbol(wxT("SHAutoComplete"));
326 if ( s_pfnSHAutoComplete
)
328 // won't be unloaded until the process termination, no big deal
334 if ( !s_pfnSHAutoComplete
)
337 HRESULT hr
= s_pfnSHAutoComplete(hwnd
, 0x10 /* SHACF_FILESYS_ONLY */);
340 wxLogApiError(wxT("SHAutoComplete"), hr
);
348 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS