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)
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/cursor.h"
29 #include "wx/window.h"
33 #include "wx/dynlib.h"
35 #include "wx/msw/private.h" // includes <windows.h>
37 // ============================================================================
39 // ============================================================================
44 ::MessageBeep((UINT
)-1); // default sound
47 // ---------------------------------------------------------------------------
48 // helper functions for showing a "busy" cursor
49 // ---------------------------------------------------------------------------
51 static HCURSOR gs_wxBusyCursor
= 0; // new, busy cursor
52 static HCURSOR gs_wxBusyCursorOld
= 0; // old cursor
53 static int gs_wxBusyCursorCount
= 0;
55 extern HCURSOR
wxGetCurrentBusyCursor()
57 return gs_wxBusyCursor
;
60 // Set the cursor to the busy cursor for all windows
61 void wxBeginBusyCursor(const wxCursor
*cursor
)
63 if ( gs_wxBusyCursorCount
++ == 0 )
65 gs_wxBusyCursor
= (HCURSOR
)cursor
->GetHCURSOR();
66 #ifndef __WXMICROWIN__
67 gs_wxBusyCursorOld
= ::SetCursor(gs_wxBusyCursor
);
70 //else: nothing to do, already set
73 // Restore cursor to normal
74 void wxEndBusyCursor()
76 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
77 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
79 if ( --gs_wxBusyCursorCount
== 0 )
81 #ifndef __WXMICROWIN__
82 ::SetCursor(gs_wxBusyCursorOld
);
84 gs_wxBusyCursorOld
= 0;
88 // true if we're between the above two calls
91 return gs_wxBusyCursorCount
> 0;
94 // Check whether this window wants to process messages, e.g. Stop button
95 // in long calculations.
96 bool wxCheckForInterrupt(wxWindow
*wnd
)
98 wxCHECK( wnd
, false );
101 while ( ::PeekMessage(&msg
, GetHwndOf(wnd
), 0, 0, PM_REMOVE
) )
103 ::TranslateMessage(&msg
);
104 ::DispatchMessage(&msg
);
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 // See also the wxGetMousePosition in window.cpp
115 // Deprecated: use wxPoint wxGetMousePosition() instead
116 void wxGetMousePosition( int* x
, int* y
)
119 wxGetCursorPosMSW( & pt
);
124 // Return true if we have a colour display
125 bool wxColourDisplay()
127 #ifdef __WXMICROWIN__
131 // this function is called from wxDC ctor so it is called a *lot* of times
132 // hence we optimize it a bit but doing the check only once
134 // this should be MT safe as only the GUI thread (holding the GUI mutex)
136 static int s_isColour
= -1;
138 if ( s_isColour
== -1 )
141 int noCols
= ::GetDeviceCaps(dc
, NUMCOLORS
);
143 s_isColour
= (noCols
== -1) || (noCols
> 2);
146 return s_isColour
!= 0;
150 // Returns depth of screen
154 return GetDeviceCaps(dc
, PLANES
) * GetDeviceCaps(dc
, BITSPIXEL
);
157 // Get size of display
158 void wxDisplaySize(int *width
, int *height
)
160 #ifdef __WXMICROWIN__
162 HWND hWnd
= GetDesktopWindow();
163 ::GetWindowRect(hWnd
, & rect
);
166 *width
= rect
.right
- rect
.left
;
168 *height
= rect
.bottom
- rect
.top
;
169 #else // !__WXMICROWIN__
173 *width
= ::GetDeviceCaps(dc
, HORZRES
);
175 *height
= ::GetDeviceCaps(dc
, VERTRES
);
176 #endif // __WXMICROWIN__/!__WXMICROWIN__
179 void wxDisplaySizeMM(int *width
, int *height
)
181 #ifdef __WXMICROWIN__
191 *width
= ::GetDeviceCaps(dc
, HORZSIZE
);
193 *height
= ::GetDeviceCaps(dc
, VERTSIZE
);
197 // ---------------------------------------------------------------------------
198 // window information functions
199 // ---------------------------------------------------------------------------
201 wxString WXDLLEXPORT
wxGetWindowText(WXHWND hWnd
)
207 int len
= GetWindowTextLength((HWND
)hWnd
) + 1;
208 ::GetWindowText((HWND
)hWnd
, wxStringBuffer(str
, len
), len
);
214 wxString WXDLLEXPORT
wxGetWindowClass(WXHWND hWnd
)
219 #ifndef __WXMICROWIN__
222 int len
= 256; // some starting value
226 int count
= ::GetClassName((HWND
)hWnd
, wxStringBuffer(str
, len
), len
);
230 // the class name might have been truncated, retry with larger
240 #endif // !__WXMICROWIN__
245 int WXDLLEXPORT
wxGetWindowId(WXHWND hWnd
)
247 return ::GetWindowLong((HWND
)hWnd
, GWL_ID
);
250 // ----------------------------------------------------------------------------
252 // ----------------------------------------------------------------------------
254 void PixelToHIMETRIC(LONG
*x
, LONG
*y
, HDC hdcRef
)
256 int iWidthMM
= GetDeviceCaps(hdcRef
, HORZSIZE
),
257 iHeightMM
= GetDeviceCaps(hdcRef
, VERTSIZE
),
258 iWidthPels
= GetDeviceCaps(hdcRef
, HORZRES
),
259 iHeightPels
= GetDeviceCaps(hdcRef
, VERTRES
);
261 *x
*= (iWidthMM
* 100);
263 *y
*= (iHeightMM
* 100);
267 void HIMETRICToPixel(LONG
*x
, LONG
*y
, HDC hdcRef
)
269 int iWidthMM
= GetDeviceCaps(hdcRef
, HORZSIZE
),
270 iHeightMM
= GetDeviceCaps(hdcRef
, VERTSIZE
),
271 iWidthPels
= GetDeviceCaps(hdcRef
, HORZRES
),
272 iHeightPels
= GetDeviceCaps(hdcRef
, VERTRES
);
275 *x
/= (iWidthMM
* 100);
277 *y
/= (iHeightMM
* 100);
280 void HIMETRICToPixel(LONG
*x
, LONG
*y
)
282 HIMETRICToPixel(x
, y
, ScreenHDC());
285 void PixelToHIMETRIC(LONG
*x
, LONG
*y
)
287 PixelToHIMETRIC(x
, y
, ScreenHDC());
290 void wxDrawLine(HDC hdc
, int x1
, int y1
, int x2
, int y2
)
298 Polyline(hdc
, points
, 2);
300 MoveToEx(hdc
, x1
, y1
, NULL
); LineTo((HDC
) hdc
, x2
, y2
);
305 // ----------------------------------------------------------------------------
306 // Shell API wrappers
307 // ----------------------------------------------------------------------------
309 extern bool wxEnableFileNameAutoComplete(HWND hwnd
)
311 #if wxUSE_DYNLIB_CLASS
312 typedef HRESULT (WINAPI
*SHAutoComplete_t
)(HWND
, DWORD
);
314 static SHAutoComplete_t s_pfnSHAutoComplete
= NULL
;
315 static bool s_initialized
= false;
317 if ( !s_initialized
)
319 s_initialized
= true;
322 wxDynamicLibrary
dll(wxT("shlwapi.dll"));
323 if ( dll
.IsLoaded() )
325 s_pfnSHAutoComplete
=
326 (SHAutoComplete_t
)dll
.GetSymbol(wxT("SHAutoComplete"));
327 if ( s_pfnSHAutoComplete
)
329 // won't be unloaded until the process termination, no big deal
335 if ( !s_pfnSHAutoComplete
)
338 HRESULT hr
= s_pfnSHAutoComplete(hwnd
, 0x10 /* SHACF_FILESYS_ONLY */);
341 wxLogApiError(wxT("SHAutoComplete"), hr
);
349 #endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS