多语言展示
当前在线:1293今日阅读:84今日分享:32

怎么获得扩展屏HWND

小编今天教大家怎么获得扩展屏HWND ,帮助大家解决在生活中遇到的一些小问题。让大家开心每一天。
方法/步骤
1

创建窗口 - 以 WS_POPUP 样式创建窗口 m_hMain = CreateWindow (WNDCLASS_NAME, g_title, WS_POPUP, 0, 0, 0, 0, NULL, NULL, m_hInst, NULL); //窗口化 - x/y:窗口位于主屏的位置,w/h:窗口的宽高 MoveWindow (m_hMain, m_wmode.x, m_wmode.y, m_wmode.w, m_wmode.h, TRUE);

2

//全屏化 - cx/cy:主屏的大小 int cx = GetSystemMetrics (SM_CXSCREEN); int cy = GetSystemMetrics (SM_CYSCREEN); MoveWindow (m_hMain, 0, 0, cx, cy, TRUE);

3

枚举显示屏 - 获得扩展屏(第二屏)的坐标,left/top/right/bottom static BOOL CALLBACK Callback_enumMonitors (HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { RECT* pRect = (RECT*) dwData; MONITORINFO mi = {0};         mi.cbSize = sizeof (MONITORINFO); GetMonitorInfo (hMonitor, &mi); if (mi.dwFlags != MONITORINFOF_PRIMARY) { *pRect = mi.rcMonitor; return FALSE; } return TRUE; }

4

//显示主窗口到扩展屏 void Tapp::show_expanscrn () { RECT rc = {0}; EnumDisplayMonitors (NULL, NULL, Callback_enumMonitors, (LPARAM) &rc); if (rc.left == 0 && rc.top == 0 && rc.right == 0 && rc.bottom == 0) MessageBox (m_hMain, L'无扩展屏', g_title, MB_OK | MB_ICONWARNING); else MoveWindow (m_hMain, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);

5

//对话框默认是位于主屏的中央的,如果想位于扩展屏中央,就要在对话框的 WM_INITDIALOG 消息中,执行下列函数 Tfuns::center_box (hDlg); void Tfuns::center_box (HWND hDlg) { RECT rc; HWND hDesktop = GetDesktopWindow (); GetWindowRect (hDesktop, &rc); int desk_h = rc.bottom - rc.top; int desk_w = rc.right - rc.left;

6

GetWindowRect (hDlg, &rc); int wnd_w = rc.right - rc.left; int wnd_h = rc.bottom - rc.top; int x = (desk_w - wnd_w) / 2; if (x < 0) x = 0; int y = (desk_h - wnd_h) / 2; if (y < 0) y = 0; SetWindowPos (hDlg, NULL, x, y, 0, 0, SWP_NOSIZE);

推荐信息