Dialog Window Property Question?
Hi,
I'm new to Visual Studio and have been tasked with taking over someone else's C++ code. The Win32 application in question has several complicated dialogs open simultaneously. What is the best way to determine which dialog window is on top, i.e. the window that has been clicked on (anywhere in the window) most recently? Example code would be very helpful. Thanks in advance, cheers!
Tim
Re: Dialog Window Property Question?
GetForegroundWindow - ?
From what tool/application are you going to determine which dialog window is on top?
Re: Dialog Window Property Question?
Hi Victor,
Thanks for helping.
I am using Visual Studio 2008.
Re: Dialog Window Property Question?
Ok, I looked into GetForegroundWindow. It returns a type CWnd*. How do I get a CWnd* type handle for each of my 3 open windows in order to compare and find out which one is the one on top? I found GetSafeHwnd but it returns HWND type so cannot use. Do you have an example of how to get the handles do a comparison?
Re: Dialog Window Property Question?
Re: Dialog Window Property Question?
Thanks, yes, I looked into GetForegroundWindow. It works. It gives me a handle of type CWnd*. So now my question is how do I use it? I need to know the CWnd* type handles of my open windows so I can compare to know which one is on top but I can't find a way to do that. Can you provide an example?
Re: Dialog Window Property Question?
Quote:
Originally Posted by
tboygee
Thanks, yes, I looked into GetForegroundWindow. It works. It gives me a handle of type CWnd*.
No. It gives you the HWND . :cool:
Re: Dialog Window Property Question?
This compiles successfully for me:
CWnd *CWnd_hdl;
CWnd_hdl= GetForegroundWindow();
This gives "error C2440: '=' : cannot convert from 'CWnd *' to 'HWND *'"
HWND *HWND_hdl;
HWND_hdl = GetForegroundWindow();
I guess we have different libraries?
In any case, how do I get handles of my other open windows? Can you provide an example?
Re: Dialog Window Property Question?
Quote:
to know which one is on top
There is only one foreground window. The HWND handle returned from GetForegroundWindow() is the handle to the current foreground window.
Quote:
I looked into GetForegroundWindow. It works. It gives me a handle of type CWnd*
This is the MFC version from https://msdn.microsoft.com/en-us/library/b52w40kc.aspx This is not the WIN32 version referenced in post #5.
You stated in post #1 that this is a WIN32 application - but does it use the WIN32 APIs or does the application use the MFC framework?
Re: Dialog Window Property Question?
Please, read the documentation carefully!
The GetForegroundWindow() Win32 API function returns HWND.
Note: HWND. Neither HWND*, nor CWnd *.
PS: if your application is an MFC one then either use
Code:
HWND HWND_hdl = ::GetForegroundWindow();
or
Code:
CWnd* pWnd = GetForegroundWindow();
HWND HWND_hdl = pWnd->GetSafeHwnd();
Re: Dialog Window Property Question?
Code:
HWND HWND_hdl = GetForegroundWindow();
GetForegroundWindow() for WIN32 doesn't return a pointer like the MFC version - it returns a value.
Re: Dialog Window Property Question?
Quote:
Originally Posted by
tboygee
The Win32 application in question has several complicated dialogs open simultaneously. What is the best way to determine which dialog window is on top, i.e. the window that has been clicked on (anywhere in the window) most recently?
I don't mean to sound flip, but why would you care?
I say this because unless you are trying to automate the app, having to determine which window is on top could be an indication of a design flaw.
Re: Dialog Window Property Question?
Sorry for the confusion. Like I said earlier, I'm new to Visual Studio. My background is as a C programmer using LabWindows/CVI. I didn't write this code, I was given the assignment to modify it. Since only the CWnd version of GetForegroundWindow() compiles for me, I guess that means I have an MFC app.
That being the case, my earlier question stands. How do I use the obtained handle? I need to know the CWnd* type handles of my open windows so I can somehow compare to know which one is on top but I can't find a way to do that. Can you provide an example?
Re: Dialog Window Property Question?
Have you done any WIN32/MFC windows programming before?
Re: Dialog Window Property Question?
Wow.
Please, is there anyone willing to help me without judging my programming skills or motivation for daring to ask a question in the first place?
You've help a bunch Victor, I just need the rest of the puzzle - how do I use the newly obtained handle? I can't find a way to obtain handles of my other windows do a comparison. Can you give a quick example?