VC screen operations

Source: Internet
Author: User

The current screen resolution method obtained by vc is as follows:
1. Windows API call
Int width = GetSystemMetrics (SM_CXSCREEN );
Int height = GetSystemMetrics (SM_CYSCREEN );
To dynamically adapt to resolution changes, process the WM_DISPLAYCHANGE message.
2. Get resolution
BOOL EnumDisplaySettings (
LPCTSTR lpszDeviceName, // display device
DWORD iModeNum, // graphics mode
LPDEVMODE lpDevMode // graphics mode settings
);

Change resolution
LONG ChangeDisplaySettings (
LPDEVMODE lpDevMode, // graphics mode
DWORD dwflags // graphics mode options
);
3. Use GetDeviceCaps

Int GetDeviceCaps (
HDC hdc, // handle to the device context
Int nIndex // index of capability to query
);

4. Use GetDeviceCaps
HDC hdcScreen = GetDC (NULL );
Int cx = GetDeviceCaps (hdcScreen, HORZRES );
Int cy = GetDeviceCaps (hdcScreen, VERTRES );
DeleteObject (hdcScreen );
The nIndex can be used as follows:
Horzres vertres or
Respectively:
HORZRES: Width, in pixels, of the screen.
VERTRES: Height, in raster lines, of the screen.

That is, the device resolution.
5. Get the size of the desktop customer zone
(1) The simplest way to use APIs
RECT rc;
SystemParametersInfo (SPI_GETWORKAREA, 0, (PVOID) & rc, 0 );
Str. Format ("% d * % d", rc. Right-rc.left, rc. Bottom-rc.top );
(2) indirect calculation: first use the above three methods to get the screen size, and then subtract the taskbar size (note: Check whether the taskbar is hidden)
Int cx = GetSystemMetrics (SM_CXSCREEN );
Int cy = GetSystemMetrics (SM_CYSCREEN );
Or
HDC hdcScreen = GetDC (NULL );
Int cx = GetDeviceCaps (hdcScreen, HORZRES );
Int cy = GetDeviceCaps (hdcScreen, VERTRES );
DeleteObject (hdcScreen );

Taskbar:
CWnd * pTaskWnd = FindWindow (_ T ("Shell_TrayWnd"), NULL );
If (pTaskWnd) pTaskWnd-> ShowWindow (FALSE );
Hide the taskbar:
LONG lStyle = GetWindowLong (pTaskWnd-> GetSafeHwnd (), GWL_STYLE );
If (lStyle & WS_VISIBLE)

// Visible

Else

// Hide
}

/////////////////////////////////
VC obtains the screen size
Int with = GetSystemMetrics (SM_CXFULLSCREEN );

Int heigh = GetSystemMetrics (SM_CYFULLSCREEN );

The two functions above show the screen size and do not include the taskbar and other areas.


Int cx = GetSystemMetrics (SM_CXSCREEN );
Int cy = GetSystemMetrics (SM_CYSCREEN );

The two functions obtain the real screen size.

The size obtained using the first two functions may be 1024*687, and the size obtained using the following two functions is 1024*768.
Description
Returns information related to windows.
Return value
Long depends on the constant index.
Parameter table
Parameter type and description
NIndex Long, constant, specifies the information to be obtained; as shown in the following table.
NIndex constant settings
Constant definition to obtain information
SM_ARRANGE sets how windows arranges a flag of the minimized window. Reference ARW constant in api32.txt
SM_CLEANBOOT specifies the startup mode. 0 = normal mode; 1 = security mode with network support
Number of available system environments of SM_CMETRICS
The number of SM_CMOUSEBUTTON buttons. Zero if there is no mouse
SM_CXBORDER, SM_CYBORDER size unchangeable border size
SM_CXCURSOR, SM_CYCURSOR standard pointer size
Size of the border in the SM_CXDLGFRAME and SM_CYDLGFRAME dialog boxes
SM_CXDOUBLECLK, SM_CYDOUBLECLK double-click the area size (refer to the annotation)
SM_CXFRAME, SM_CYFRAME variable border size (use SM_C? In win95 and nt 4.0? FIXEDFRAME)
SM_CXFULLSCREEN and SM_CYFULLSCREEN maximize the size of the window client area
Size of arrows on the SM_CXHSCROLL horizontal scroll bar
Size of SM_CXHTHUMB and SM_CYHTHUMB on the horizontal scroll bar
Size of SM_CXICON and SM_CYICON standard icons
The gap between SM_CXICONSPACING and SM_CYICONSPACING desktop icons. In win95 and nt 4.0, it refers to the distance between the big picture subject.
SM_CXMAXIMIZED and SM_CYMAXIMIZED maximize the default window size
SM_CXMAXTRACK, SM_CYMAXTRACK change window size, maximum track width
SM_CXMENUCHECK, SM_CYMENUCHECK
SM_CXMENUSIZE, the button size on the SM_CYMENUSIZE menu bar
Minimum size of SM_CXMIN and SM_CYMIN windows
SM_CXMINIMIZED: the SM_CYMINIMIZED minimized window must be filled with a rectangle smaller than or equal to SM_C? ICONSPACING
Minimum track width of the SM_CXMINTRACK and SM_CYMINTRACK windows
SM_CXSCREEN, SM_CYSCREEN screen size
SM_CXSIZE, SM_CYSIZE the size of the title bar bitmap
SM_CXSIZEFRAME, SM_CYSIZEFRAME has the size of the window in the WS_THICKFRAME style
Size of SM_CXSMICON and SM_CYSMICON icons
SM_CXSMSIZE, SM_CYSMSIZE the size of the title button
SM_CXVSCROLL, the size of the arrow button in the SM_CYVSCROLL vertical scroll bar
Height of SM_CYCAPTION window title
Size of the SM_CYKANJIWINDOW Kanji window (Height of Kanji window)
SM_CYMENU menu height
Height of SM_CYSMCAPTION subtitles
Height of the scroll block on the SM_CYVTHUMB vertical scroll bar
SM_DBCSENABLED: TRUE if dual bytes are supported
If the debug version of windows is running, the value of SM_DEBUG is TRUE.
SM_MENUDropALIGNMENT. If the pop-up menu is aligned to the left of the menu bar item, the value is zero.
SM_MIDEASTENABLED allows Hebrew and Arabic
SM_MOUSEPRESENT: TRUE if the mouse is installed
SM_MOUSEWHEELPRESENT: TRUE if the mouse with a wheel is installed; applicable only to nt 4.0
If SM_NETWORK is installed with a network, set the bit to 0. Other places are retained
SM_PENWINDOWS indicates the handle of the pen window if the DLL supporting the Pen Window is loaded.
SM_SECURE is TRUE if the secure (confidential) mechanism is installed.
SM_SHOWSOUNDS forces visual display of sound
The SM_SLOWMACHINE System is too slow but is still running (System is too slow for failed use but is being run anyway)
SM_SWAPBUTTON. If the left and right mouse buttons have been switched, the value is TRUE.
Annotation
Double-click an area to specify a specific display area on the screen. It can be processed as a double-click event only when two consecutive mouse clicks are made in this area.
Others
Constant SM_ARRANGE, SM_CLEANBOOT, SM_CMETRICS, SM_C? MAXIMIZED, SM_C? MAXTRACK, SM_C? SIZEFRAME, SM_C? SMICON, SM_C? SMSIZE, SM_CYSMCAPTION,
SM_SECURE, SM_SHOWSOUNDS, and SM_SLOWMACHINE are not supported by NT 3.51 or earlier versions.


This article is from the blog "I know what I don't have". I don't want to repost it!

VC screen operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.