// // 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; Parameter handleParam = new Parameter(this, handle); Parameter itemParam = new Parameter(this, (int)item); m_PtrMessageStore->NumberOfMessages++; m_DoneFind = true; m_DoneQuery = true; m_DoneGet = true; }
// // 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; }
private unsafe void GetTitleBarItemRectangle(Message *ptrMessage, int messageNumber) { //must be first message if (messageNumber != 1) { throw new Exception("GetTitleBarItemRectangle must be first message"); } // p1 = handle IntPtr handle = GetParameterIntPtr(ptrMessage, 0); // p2 = TitleBarStateElement NM.TitleBarStateElement item = (NM.TitleBarStateElement)GetParameterInt32(ptrMessage, 1); // p3 = scalingfactor float screenScalingFactor = GetParameterSingle(ptrMessage, 2); CleanUpMessage(ptrMessage); NM.TITLEBARINFOEX tbi = new NM.TITLEBARINFOEX(); tbi.cbSize = Marshal.SizeOf(typeof(NM.TITLEBARINFOEX)); // Send the WM_GETTITLEBARINFOEX message IntPtr result; IntPtr smtReturn; smtReturn = NM.SendMessageTimeout(handle, NM.WM_GETTITLEBARINFOEX, IntPtr.Zero, ref tbi, NM.SendMessageTimeoutFlags.SMTO_NORMAL, TimeOut, out result); uint state; int left; int top; int right; int bottom; switch (item) { case NM.TitleBarStateElement.TitleBar: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.TitleBar]; top = tbi.rcTitleBar.top; left = tbi.rcTitleBar.left; bottom = tbi.rcTitleBar.bottom; right = tbi.rcTitleBar.right; break; case NM.TitleBarStateElement.Minimize: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Minimize]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].right; break; case NM.TitleBarStateElement.Maximize: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Maximize]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].right; break; case NM.TitleBarStateElement.Help: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Help]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Help].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Help].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Help].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Help].right; break; case NM.TitleBarStateElement.Close: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Close]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Close].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Close].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Close].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Close].right; break; default: throw new Exception("Unknown titlebar element: " + item.ToString()); } //HACK - Windows 10 1809 has a bug where by when the window is maximised and you have a docked app bar above it then the top value is wrong if (top < tbi.rcTitleBar.top) { top = tbi.rcTitleBar.top; } left = (int)(Math.Round((float)(left) / screenScalingFactor)); top = (int)(Math.Round((float)(top) / screenScalingFactor)); right = (int)(Math.Round((float)(right) / screenScalingFactor)); bottom = (int)(Math.Round((float)(bottom) / screenScalingFactor)); AddReturnValue(new Parameter(this, state)); AddReturnValue(new Parameter(this, top)); AddReturnValue(new Parameter(this, left)); AddReturnValue(new Parameter(this, bottom)); AddReturnValue(new Parameter(this, right)); }
private unsafe void GetTitleBarItemRectangle(Message *ptrMessage, int messageNumber) { //must be first message if (messageNumber != 1) { throw new Exception("GetTitleBarItemRectangle must be first message"); } // p1 = handle IntPtr handle = GetParameterIntPtr(ptrMessage, 0); // p2 = TitleBarStateElement NM.TitleBarStateElement item = (NM.TitleBarStateElement)GetParameterInt32(ptrMessage, 1); CleanUpMessage(ptrMessage); NM.TITLEBARINFOEX tbi = new NM.TITLEBARINFOEX(); tbi.cbSize = Marshal.SizeOf(typeof(NM.TITLEBARINFOEX)); // Send the WM_GETTITLEBARINFOEX message IntPtr result; IntPtr smtReturn; smtReturn = NM.SendMessageTimeout(handle, NM.WM_GETTITLEBARINFOEX, IntPtr.Zero, ref tbi, NM.SendMessageTimeoutFlags.SMTO_NORMAL, TimeOut, out result); uint state; int left; int top; int right; int bottom; switch (item) { case NM.TitleBarStateElement.TitleBar: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.TitleBar]; top = tbi.rcTitleBar.top; left = tbi.rcTitleBar.left; bottom = tbi.rcTitleBar.bottom; right = tbi.rcTitleBar.right; break; case NM.TitleBarStateElement.Minimize: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Minimize]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].right; break; case NM.TitleBarStateElement.Maximize: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Maximize]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].right; break; case NM.TitleBarStateElement.Help: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Help]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Help].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Help].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Help].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Help].right; break; case NM.TitleBarStateElement.Close: state = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Close]; top = tbi.rgrect[(int)NM.TitleBarStateElement.Close].top; left = tbi.rgrect[(int)NM.TitleBarStateElement.Close].left; bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Close].bottom; right = tbi.rgrect[(int)NM.TitleBarStateElement.Close].right; break; default: throw new Exception("Unknown titlebar element: " + item.ToString()); } AddReturnValue(new Parameter(this, state)); AddReturnValue(new Parameter(this, top)); AddReturnValue(new Parameter(this, left)); AddReturnValue(new Parameter(this, bottom)); AddReturnValue(new Parameter(this, right)); }