当前位置: 首页>>代码示例>>C++>>正文


C++ MonitorFromPoint函数代码示例

本文整理汇总了C++中MonitorFromPoint函数的典型用法代码示例。如果您正苦于以下问题:C++ MonitorFromPoint函数的具体用法?C++ MonitorFromPoint怎么用?C++ MonitorFromPoint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MonitorFromPoint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetStartupMonitor

// If possible, open our windows on the monitor where user
// have clicked our icon (shortcut on the desktop or TaskBar)
HMONITOR GetStartupMonitor()
{
	STARTUPINFO si = {sizeof(si)};
	MONITORINFO mi = {sizeof(mi)};
	POINT ptCur = {}, ptOut = {-32000,-32000};
	HMONITOR hStartupMonitor = NULL, hMouseMonitor, hPrimaryMonitor;

	GetStartupInfo(&si);
	GetCursorPos(&ptCur);

	// Get primary monitor, it's expected to be started at 0x0, but we can't be sure
	hPrimaryMonitor = MonitorFromPoint(ptOut, MONITOR_DEFAULTTOPRIMARY);

	// Get the monitor where mouse cursor is located
	hMouseMonitor = MonitorFromPoint(ptCur, MONITOR_DEFAULTTONEAREST);

	// si.hStdOutput may have a handle of monitor with shortcut or used taskbar
	if (si.hStdOutput && GetMonitorInfo((HMONITOR)si.hStdOutput, &mi))
	{
		hStartupMonitor = (HMONITOR)si.hStdOutput;
	}

	// Now, due to MS Windows bugs or just an inconsistence,
	// hStartupMonitor has hPrimaryMonitor, if program was started
	// from shortcut, even if it is located on secondary monitor,
	// if it was started by keyboard.
	// So we can trust hStartupMonitor value only when it contains
	// non-primary monitor value (when user clicks shortcut with mouse)
	if (hStartupMonitor && ((hStartupMonitor != hPrimaryMonitor) || (hStartupMonitor == hMouseMonitor)))
		return hStartupMonitor;

	// Otherwise - return monitor where mouse cursor is located
	return hMouseMonitor ? hMouseMonitor : hPrimaryMonitor;
}
开发者ID:akrisiun,项目名称:ConEmu,代码行数:36,代码来源:Monitors.cpp

示例2: MonitorFromPoint

Monitor DisplayManager::Primary() {
    /* The Primary or 'Main' monitor is at (0, 0). */
    const POINT p = { 0, 0 };
    HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTOPRIMARY);
    MONITORINFO mInfo = Info(monitor);
    return Monitor(monitor, L"Primary", mInfo.rcMonitor);
}
开发者ID:malensek,项目名称:3RVX,代码行数:7,代码来源:DisplayManager.cpp

示例3: GetCursorPos

void SliderWnd::PositionWindow() {
    POINT p;
    GetCursorPos(&p);

    HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
    MONITORINFO mInfo = {};
    mInfo.cbSize = sizeof(mInfo);
    GetMonitorInfo(monitor, &mInfo);
    RECT mRect = mInfo.rcWork;

    /* Default location is the bottom of the window centered above cursor. */
    POINT loc;
    loc.x = p.x - _size.cx / 2;
    loc.y = p.y - _size.cy;

    /* Reposition the window if it's falling off the monitor somewhere. */
    if (loc.y < mRect.top) {
        loc.y = mRect.top;
    }

    if (loc.x < mRect.left) {
        loc.x = mRect.left;
    }

    if (p.y > mRect.bottom) {
        loc.y = mRect.bottom - _size.cy;
    }

    if (p.x > mRect.right - _size.cx) {
        loc.x = mRect.right - _size.cx;
    }

    Position(loc.x, loc.y);
}
开发者ID:malensek,项目名称:3RVX,代码行数:34,代码来源:SliderWnd.cpp

示例4: MonitorFromPoint

SwapChain::SwapChain()
{
    refreshRate.Numerator = 60;
    refreshRate.Denominator = 1;

    // Try to figure out if we should default to 1280x720 or 1920x1080
    POINT point;
    point.x = 0;
    point.y = 0;
    HMONITOR monitor = MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY);
    if(monitor != 0)
    {
        MONITORINFOEX info;
        ZeroMemory(&info, sizeof(info));
        info.cbSize = sizeof(MONITORINFOEX);
        if(GetMonitorInfo(monitor, &info) != 0)
        {
            int32 monitorWidth = info.rcWork.right - info.rcWork.left;
            int32 monitorHeight = info.rcWork.bottom - info.rcWork.top;
            if(monitorWidth > 1920 && monitorHeight > 1080)
            {
                width = 1920;
                height = 1080;
            }
        }
    }
}
开发者ID:TheRealMJP,项目名称:DeferredTexturing,代码行数:27,代码来源:SwapChain.cpp

示例5: GetMonitorLeftmost

int GetMonitorLeftmost(int PosX, int PosY)
{
	OSVERSIONINFO osvi;

	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&osvi);
	if ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) ||
	     (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && osvi.dwMinorVersion < 10) ) {
		// // NT4.0, 95 はマルチモニタAPIに非対応
		return 0;
	}
	else {
		HMONITOR hm;
		POINT pt;
		MONITORINFO mi;

		pt.x = PosX;
		pt.y = PosY;
		hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

		mi.cbSize = sizeof(MONITORINFO);
		GetMonitorInfo(hm, &mi);
		return mi.rcWork.left;
	}
}
开发者ID:lifangbo,项目名称:teraterm,代码行数:25,代码来源:ttmlib.c

示例6: SetSplashImage

// Calls UpdateLayeredWindow to set a bitmap (with alpha) as the content of the splash window.
static void SetSplashImage(HWND hwndSplash, HBITMAP hbmpSplash)

{
	// get the size of the bitmap
	BITMAP bm;
	GetObject(hbmpSplash, sizeof(bm), &bm);
	SIZE sizeSplash = { bm.bmWidth, bm.bmHeight };

	// get the primary monitor's info
	POINT ptZero = { 0 };
	HMONITOR hmonPrimary = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
	MONITORINFO monitorinfo = { 0 };
	monitorinfo.cbSize = sizeof(monitorinfo);
	GetMonitorInfo(hmonPrimary, &monitorinfo);

	// center the splash screen in the middle of the primary work area
	const RECT & rcWork = monitorinfo.rcWork;
	POINT ptOrigin;
	ptOrigin.x = rcWork.left + (rcWork.right - rcWork.left - sizeSplash.cx) / 2;
	ptOrigin.y = rcWork.top + (rcWork.bottom - rcWork.top - sizeSplash.cy) / 2;

	// create a memory DC holding the splash bitmap
	HDC hdcScreen = GetDC(NULL);
	HDC hdcMem = CreateCompatibleDC(hdcScreen);
	HBITMAP hbmpOld = (HBITMAP) SelectObject(hdcMem, hbmpSplash);

	// paint the window (in the right location) with the alpha-blended bitmap
	UpdateLayeredWindow(hwndSplash, hdcScreen, &ptOrigin, &sizeSplash,
		hdcMem, &ptZero, RGB(0, 0, 0), NULL, ULW_OPAQUE);

	// delete temporary objects
	SelectObject(hdcMem, hbmpOld);
	DeleteDC(hdcMem);
	ReleaseDC(NULL, hdcScreen);
}
开发者ID:adhistac,项目名称:ee-client-2-0,代码行数:36,代码来源:win32SplashScreen.cpp

示例7: sizeof

////////////////////////////////////////////////////////////////////////////////////////////////////
// Fills specified SHELLEXECUTEINFO structure with the information read from registry
VOID CConfigReader::PopulateExecuteInformation ( SHELLEXECUTEINFO* pExecInfo )
{
    pExecInfo->cbSize = sizeof ( SHELLEXECUTEINFO ) ;
    pExecInfo->fMask = 
        SEE_MASK_FLAG_DDEWAIT | SEE_MASK_HMONITOR | SEE_MASK_NOASYNC | SEE_MASK_UNICODE ;
    pExecInfo->hwnd = NULL ;
    pExecInfo->lpVerb = g_szShellExecuteVerb ;
    pExecInfo->lpFile = m_lpszPath ;
    pExecInfo->lpParameters = m_lpszParams ;
    pExecInfo->lpDirectory = NULL ;
    pExecInfo->nShow = m_dwWindowState ;

    // Set monitor handle. 0 means primary monitor, if index is greater then zero we will enumerate
    // through all monitors and find the required one using index. 
    if ( 0 < m_dwMonitorIndex )
    {
        FINDMONITOR FindMonitor ;
        FindMonitor.dwCurrentIndex = 0 ;
        FindMonitor.dwRequiredIndex = m_dwMonitorIndex ;
        FindMonitor.hMonitor = NULL ;
        EnumDisplayMonitors ( NULL , NULL , EnumMonitorsCallBack , ( LPARAM ) &FindMonitor ) ;
        if ( NULL != FindMonitor.hMonitor )
        {
            pExecInfo->hMonitor = FindMonitor.hMonitor ;
            return ;
        }
    } // If index is invalid or is 0 we will default to primary monitor
    else
    {
        POINT ptZero = { 0 } ;
        pExecInfo->hMonitor = MonitorFromPoint ( ptZero , MONITOR_DEFAULTTOPRIMARY ) ;
    }
}
开发者ID:sergey-rybalkin,项目名称:QLaunch,代码行数:35,代码来源:ConfigReader.cpp

示例8: ValidatePosition

void ValidatePosition(HWND hwndDlg)
{
	RECT r;
	SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);

	POINT pt = { 0, 0 };
	HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); // always 

	MONITORINFO monitorInfo;
	monitorInfo.cbSize = sizeof(MONITORINFO);
	if (GetMonitorInfo(hMonitor, &monitorInfo))
		memcpy(&r, &monitorInfo.rcMonitor, sizeof(RECT));

	// /window going off right of screen*
	if (Xposition + WindowWidth >= r.right)
		Xposition = r.right - WindowWidth;

	// window going off bottom of screen
	if (Yposition + WindowHeight >= r.bottom)
		Yposition = r.bottom - WindowHeight;

	// window going off left of screen
	if (Xposition >= r.right)
		Xposition = 0;
}
开发者ID:kmdtukl,项目名称:miranda-ng,代码行数:25,代码来源:webview_datawnd.cpp

示例9: Clock_PositionWindow

void Clock_PositionWindow(HWND hwnd, int padding) {
	POINT cursor_pos;
	MONITORINFO moni = {sizeof(moni)};
	int wProp, hProp;
	HWND hwnd_clock;
	
	GetWindowRect(hwnd, &moni.rcWork); // Options dialog dimensions
	wProp = moni.rcWork.right-moni.rcWork.left;  //----------+++--> Width
	hProp = moni.rcWork.bottom-moni.rcWork.top; //----------+++--> Height
	
	GetCursorPos(&cursor_pos);
	GetMonitorInfo(MonitorFromPoint(cursor_pos,MONITOR_DEFAULTTONEAREST),&moni);
	
	if(moni.rcWork.top!=moni.rcMonitor.top || moni.rcWork.bottom!=moni.rcMonitor.bottom) { // taskbar is horizontal
		moni.rcMonitor.left=moni.rcWork.right-wProp-padding;
		if(moni.rcWork.top!=moni.rcMonitor.top) // top
			moni.rcMonitor.top=moni.rcWork.top+padding;
		else // bottom
			moni.rcMonitor.top=moni.rcWork.bottom-hProp-padding;
		// center small windows within clock dimension when possible
		hwnd_clock = gs_hwndClock;
		if(!hwnd_clock)
			hwnd_clock = FindClock();
		if(hwnd_clock) {
			GetClientRect(hwnd_clock, &moni.rcWork);
			if(wProp < moni.rcWork.right)
				moni.rcMonitor.left -= ((moni.rcWork.right - wProp)>>1) + api.desktop_button_size;
		}
	}else if(moni.rcWork.left!=moni.rcMonitor.left || moni.rcWork.right!=moni.rcMonitor.right){ // vertical
开发者ID:heicks,项目名称:T-Clock,代码行数:29,代码来源:clock_utils.c

示例10: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
    const POINT ptZero = { 0, 0 };
    HMONITOR hMon = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);

    MONITORINFO monInfo;
    monInfo.cbSize = sizeof monInfo;

    if (GetMonitorInfo(hMon, &monInfo) == TRUE)
    {
        LONG width = monInfo.rcMonitor.right - monInfo.rcMonitor.left;
        LONG height = monInfo.rcMonitor.bottom - monInfo.rcMonitor.top;

        if (SetCursorPos(width / 2, height / 2) != TRUE)
        {
            std::cout << "SetCursorPos() failed, error : " << GetLastError() << "\n";
            return 1;
        }
    }
    else
    {
        std::cout << "GetMonitorInfo() failed, error : " << GetLastError() << "\n";
        return 2;
    }

	return 0;
}
开发者ID:jossgray,项目名称:center_cursor,代码行数:27,代码来源:center_cursor.cpp

示例11: MonitorFromPoint

 // FIXME: There is no guarantee that descMap contains the info required
 // Because of threading issue. Must implement mutex
 DisplayDeviceDescriptor winDisplayDeviceManager::uriFromPoint(int x, int y)
 {
   POINT p;
   p.x = x;
   p.y = y;
   HMONITOR hMon = MonitorFromPoint(p, MONITOR_DEFAULTTOPRIMARY);
   return descMap[hMon];
 }
开发者ID:Rylith,项目名称:TouchpadTestV2,代码行数:10,代码来源:winDisplayDeviceManager.cpp

示例12: CSize

CSize CBCGPPopupDlg::GetOptimalTextSize (CString str)
{
	if (str.IsEmpty ())
	{
		return CSize (0, 0);
	}

	CRect rectScreen;

	CRect rectDlg;
	GetWindowRect (rectDlg);

	MONITORINFO mi;
	mi.cbSize = sizeof (MONITORINFO);
	if (GetMonitorInfo (MonitorFromPoint (rectDlg.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi))
	{
		rectScreen = mi.rcWork;
	}
	else
	{
		::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
	}

	CClientDC dc (this);

	CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
	ASSERT_VALID (pOldFont);

	int nStepY = globalData.GetTextHeight ();
	int nStepX = nStepY * 3;

	CRect rectText (0, 0, nStepX, nStepY);

	for (;;)
	{
		CRect rectTextSaved = rectText;

		int nHeight = dc.DrawText (str, rectText, DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX);
		int nWidth = rectText.Width ();

		rectText = rectTextSaved;

		if (nHeight <= rectText.Height () ||
			rectText.Width () > rectScreen.Width () ||
			rectText.Height () > rectScreen.Height ())
		{
			rectText.bottom = rectText.top + nHeight + 5;
			rectText.right = rectText.left + nWidth + 5;
			break;
		}

		rectText.right += nStepX;
		rectText.bottom += nStepY;
	}

	dc.SelectObject (pOldFont);
	return rectText.Size ();
}
开发者ID:cugxiangzhenwei,项目名称:WorkPlatForm,代码行数:58,代码来源:BCGPPopupDlg.cpp

示例13: CreateWnd

// CreateWnd: creates a full screen window to span the projectors
void CreateWnd(HINSTANCE &hinst, int width, int height, int depth)
{
	// Find the middle projector
	POINT pt;
	pt.x = -SCRWIDTH;
	pt.y = 100;

	HMONITOR hmon; // monitor handles
	hmon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);

	MONITORINFO mi;
	mi.cbSize = sizeof(MONITORINFO);
	GetMonitorInfo(hmon, &mi);

	// Set the window position based on the projector locations
	int posx1 = mi.rcMonitor.left;
	int posy1 = mi.rcMonitor.top;

	// Constants for fullscreen mode
	long wndStyle = WS_POPUP | WS_VISIBLE;

	// create the window
	hwnd1 = CreateWindowEx(NULL,
		WNDCLASSNAME,
		WNDNAME,
		wndStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
		posx1, posy1,
		width, height,
		NULL,
		NULL,
		hinst,
		NULL);

	hdc1 = GetDC(hwnd1);

	PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		SCRDEPTH,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		32,
		0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
	};
	indexPixelFormat = ChoosePixelFormat(hdc1, &pfd);
	SetPixelFormat(hdc1, indexPixelFormat, &pfd);

	// Setup OpenGL
	hglrc = wglCreateContext(hdc1);
	wglMakeCurrent(hdc1, hglrc);
	glewExperimental = GL_TRUE;
	glewInit();
	InitOpenGL();
	ShowWindow(hwnd1, SW_SHOW);		// everything went OK, show the window
	UpdateWindow(hwnd1);
}
开发者ID:dteinferno,项目名称:OpenGL,代码行数:59,代码来源:winmain.cpp

示例14: PhpUpdateTooltip

static VOID PhpUpdateTooltip(
    __in PPHP_GRAPH_CONTEXT Context
    )
{
    POINT point;
    RECT windowRect;
    HWND hwnd;
    TOOLINFO toolInfo = { sizeof(toolInfo) };
    HMONITOR monitor;

    GetCursorPos(&point);
    GetWindowRect(Context->Handle, &windowRect);

    if (
        point.x < windowRect.left || point.x >= windowRect.right ||
        point.y < windowRect.top || point.y >= windowRect.bottom
        )
        return;

    hwnd = WindowFromPoint(point);

    if (hwnd != Context->Handle)
        return;

    toolInfo.hwnd = Context->Handle;
    toolInfo.uId = 1;

    if (!Context->TooltipVisible)
    {
        TRACKMOUSEEVENT trackMouseEvent = { sizeof(trackMouseEvent) };

        SendMessage(Context->TooltipHandle, TTM_TRACKACTIVATE, TRUE, (LPARAM)&toolInfo);

        trackMouseEvent.dwFlags = TME_LEAVE;
        trackMouseEvent.hwndTrack = Context->Handle;
        TrackMouseEvent(&trackMouseEvent);

        Context->ValidMonitor = NULL; // force a refresh of monitor info
    }

    // Update monitor information only if the tooltip has moved onto another monitor.

    monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);

    if (Context->ValidMonitor != monitor)
    {
        GetMonitorInfo(monitor, &Context->MonitorInfo);
        Context->ValidMonitor = monitor;
    }

    // Add an offset to fix the case where the user moves the mouse to the bottom-right.
    point.x += 12;
    point.y += 12;

    SendMessage(Context->TooltipHandle, TTM_TRACKPOSITION, 0, MAKELONG(point.x, point.y));
}
开发者ID:john-peterson,项目名称:processhacker,代码行数:56,代码来源:graph.c

示例15: n2e_ScintillaDPIInit

void n2e_ScintillaDPIInit(const HWND hwnd)
{
  if (!IsWindowsVistaOrGreater())
  {
    return;
  }
  RECT rc = { 0 };
  GetWindowRect(hwnd, &rc);
  const POINT pt = { rc.left, rc.top };
  SciCall_SetDPI(GetDPIFromMonitor(MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY), hwnd));
}
开发者ID:ProgerXP,项目名称:Notepad2e,代码行数:11,代码来源:DPIHelperScintilla.c


注:本文中的MonitorFromPoint函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。