今天做的项目中需要根据系统的分辨率控制窗体的位置,所以用到这些,拿出来分享一下。
这里需要引用到wxWidgets的一个库文件:#include <wx/settings.h>
我们用到的是它里面的wxSystemSettings这个类,在这里摘录一下官方帮助文档:
Members
wxSystemSettings::wxSystemSettings
wxSystemSettings::GetColour
wxSystemSettings::GetFont
wxSystemSettings::GetMetric
wxSystemSettings::GetScreenType
wxSystemSettings::GetMetric
static int GetMetric(wxSystemMetric index, wxWindow* win = NULL)
Returns the value of a system metric, or -1 if the metric is not supported on the current system. The value of win determines if the metric returned is a global value or a wxWindow based value, in which case it might determine the widget, the display the window is on, or something similar. The window given should be as close to the metric as possible (e.g a wxTopLevelWindow in case of the wxSYS_CAPTION_Y metric).
index can be one of:
wxSYS_MOUSE_BUTTONS Number of buttons on mouse, or zero if no mouse was installed. wxSYS_BORDER_X Width of single border. wxSYS_BORDER_Y Height of single border. wxSYS_CURSOR_X Width of cursor. wxSYS_CURSOR_Y Height of cursor. wxSYS_DCLICK_X Width in pixels of rectangle within which two successive mouse clicks must fall to generate a double-click. wxSYS_DCLICK_Y Height in pixels of rectangle within which two successive mouse clicks must fall to generate a double-click. wxSYS_DRAG_X Width in pixels of a rectangle centered on a drag point to allow for limited movement of the mouse pointer before a drag operation begins. wxSYS_DRAG_Y Height in pixels of a rectangle centered on a drag point to allow for limited movement of the mouse pointer before a drag operation begins. wxSYS_EDGE_X Width of a 3D border, in pixels. wxSYS_EDGE_Y Height of a 3D border, in pixels. wxSYS_HSCROLL_ARROW_X Width of arrow bitmap on horizontal scrollbar. wxSYS_HSCROLL_ARROW_Y Height of arrow bitmap on horizontal scrollbar. wxSYS_HTHUMB_X Width of horizontal scrollbar thumb. wxSYS_ICON_X The default width of an icon. wxSYS_ICON_Y The default height of an icon. wxSYS_ICONSPACING_X Width of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of this size when arranged. wxSYS_ICONSPACING_Y Height of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of this size when arranged. wxSYS_WINDOWMIN_X Minimum width of a window. wxSYS_WINDOWMIN_Y Minimum height of a window. wxSYS_SCREEN_X Width of the screen in pixels. wxSYS_SCREEN_Y Height of the screen in pixels. wxSYS_FRAMESIZE_X Width of the window frame for a wxTHICK_FRAME window. wxSYS_FRAMESIZE_Y Height of the window frame for a wxTHICK_FRAME window. wxSYS_SMALLICON_X Recommended width of a small icon (in window captions, and small icon view). wxSYS_SMALLICON_Y Recommended height of a small icon (in window captions, and small icon view). wxSYS_HSCROLL_Y Height of horizontal scrollbar in pixels. wxSYS_VSCROLL_X Width of vertical scrollbar in pixels. wxSYS_VSCROLL_ARROW_X Width of arrow bitmap on a vertical scrollbar. wxSYS_VSCROLL_ARROW_Y Height of arrow bitmap on a vertical scrollbar. wxSYS_VTHUMB_Y Height of vertical scrollbar thumb. wxSYS_CAPTION_Y Height of normal caption area. wxSYS_MENU_Y Height of single-line menu bar. wxSYS_NETWORK_PRESENT 1 if there is a network present, 0 otherwise. wxSYS_PENWINDOWS_PRESENT 1 if PenWindows is installed, 0 otherwise. wxSYS_SHOW_SOUNDS Non-zero if the user requires an application to present information visually in situations where it would otherwise present the information only in audible form; zero otherwise. wxSYS_SWAP_BUTTONS Non-zero if the meanings of the left and right mouse buttons are swapped; zero otherwise. win is a pointer to the window for which the metric is requested. Specifying the win parameter is encouraged, because some metrics on some ports are not supported without one, or they might be capable of reporting better values if given one. If a window does not make sense for a metric, one should still be given, as for example it might determine which displays cursor width is requested with wxSYS_CURSOR_X.
根据文档里的以上介绍,我们如果要获取屏幕分辨率,只要用下面的方法就可以了:
int nWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X, NULL);
int nHeight= wxSystemSettings::GetMetric(wxSYS_SCREEN_Y, NULL);
除特别声明为转载内容外,本站所有内容均为作者原创,谢绝任何单位和个人不经许可的复制和转播!
对于确有转载需要的,请先与作者联系,在获得允许后烦请在转载时保留文章出处。
本文出自Lupin's Blog:http://www.cnzui.com/archives/336