private void AppbarQueryPos(ref NM.tagRect appRect) { float ScreenScalingFactor; using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { IntPtr desktop = g.GetHdc(); int LogicalScreenHeight = NM.GetDeviceCaps(desktop, NM.DeviceCap.VERTRES); int PhysicalScreenHeight = NM.GetDeviceCaps(desktop, NM.DeviceCap.DESKTOPVERTRES); g.ReleaseHdc(); ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight; } // prepare data structure of message NM.APPBARDATA msgData = new NM.APPBARDATA(); msgData.cbSize = (UInt32)Marshal.SizeOf(msgData); msgData.hWnd = Handle; msgData.uEdge = (UInt32)m_Edge; msgData.rc = appRect; // query postion for the appbar msgData.rc.left = (int)(Math.Round((float)msgData.rc.left * ScreenScalingFactor)); msgData.rc.right = (int)(Math.Round((float)msgData.rc.right * ScreenScalingFactor)); msgData.rc.top = (int)(Math.Round((float)msgData.rc.top * ScreenScalingFactor)); msgData.rc.bottom = (int)(Math.Round((float)msgData.rc.bottom * ScreenScalingFactor)); NM.SHAppBarMessage(NM.AppBarMessages.QueryPos, ref msgData); msgData.rc.left = (int)(Math.Round((float)msgData.rc.left / ScreenScalingFactor)); msgData.rc.right = (int)(Math.Round((float)msgData.rc.right / ScreenScalingFactor)); msgData.rc.top = (int)(Math.Round((float)msgData.rc.top / ScreenScalingFactor)); msgData.rc.bottom = (int)(Math.Round((float)msgData.rc.bottom / ScreenScalingFactor)); appRect = msgData.rc; }
internal int TwipsToPixels(int twips, Direction direction) { int pixelsPerInch; IntPtr deviceContext = NM.GetDC(this.Handle); switch (direction) { case Direction.Horizontal: pixelsPerInch = NM.GetDeviceCaps(deviceContext, NM.DeviceCap.LOGPIXELSX); break; case Direction.Vertical: pixelsPerInch = NM.GetDeviceCaps(deviceContext, NM.DeviceCap.LOGPIXELSY); break; default: throw GUI.ApeException("Unknown direction: " + direction.ToString()); } NM.ReleaseDC(this.Handle, deviceContext); int pixels = (int)Math.Round((float)twips / (float)1440 * (float)pixelsPerInch); return(pixels); }
// // GetTitleBarItemRectangle // unsafe public void AddFirstMessageGetTitleBarItemRectangle(IntPtr handle, NM.TitleBarStateElement item) { // Window messages 0x0400 (WM_USER) or higher are not marshalled by windows so make the call in the AUT FirstMessageInitialise(); Message *ptrMessage = GetPointerToNextMessage(); ptrMessage->Action = MessageAction.GetTitleBarItemRectangle; float screenScalingFactor; if (NV.IsWindows10OrHigher) { screenScalingFactor = 1; } else { using (Graphics desktopGraphics = Graphics.FromHwnd(handle)) { IntPtr desktopDeviceContext = desktopGraphics.GetHdc(); int logicalScreenHeight = NM.GetDeviceCaps(desktopDeviceContext, NM.DeviceCap.VERTRES); int physicalScreenHeight = NM.GetDeviceCaps(desktopDeviceContext, NM.DeviceCap.DESKTOPVERTRES); desktopGraphics.ReleaseHdc(); screenScalingFactor = (float)physicalScreenHeight / (float)logicalScreenHeight; } } Parameter handleParam = new Parameter(this, handle); Parameter itemParam = new Parameter(this, (int)item); Parameter screenScalingFactorParam = new Parameter(this, screenScalingFactor); m_PtrMessageStore->NumberOfMessages++; m_DoneFind = true; m_DoneQuery = true; m_DoneGet = true; }