INTRODUCTION AND RELEVANT INFORMATION:
I am making a GUI widget application in WPF that will be rendered on top of a game. I am trying to add a ComboBox that will be rendered in front of widget’s background. Moving the ComboBox below the image in XAML simply fixes that but the popup from the ComboBox gets rendered behind the image no matter what I did. I tried setting the z-index of the ComboBox, z-index of ComboBox’s items, I tried moving the ComboBox to a different grid but none worked. After a bunch of tries I figured what causes this, it was the code I use to foremost/bottommost my widget:
IntPtr windowHandle = new System.Windows.Interop.WindowInteropHelper(overlayWindow).Handle;
if (foregroundWindowHandle == targetGameProcessHandle) {
SetWindowPos(windowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
} else {
SetWindowPos(windowHandle, false ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
Replacing that codeblock with this fixes the issue:
overlayWindow.Topmost = true;
if (foregroundWindowHandle == targetGameProcessHandle) {
overlayWindow.Visibility = Visibility.Visible;
} else {
overlayWindow.Visibility = Visibility.Hidden;
}
QUESTION:
As I said, this fixed my issue so I’m not looking for a better code that will fix it (tho it would be appreciated). I just wanna know why or what makes it break when SetWindowPos is used.
Thank you for your time and efforts to help.
Halil Efe Çeteci is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.