Window event callback if I have a window's m_hwnd ...

Hi,

In my own application, how do I recieve a minimisation event (WM_MINIMIZE) from a window (eg. Command Prompt) when it minimises and unminimises?

Thanks
erictankokAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cookreCommented:
SetWindowsHookEx():
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp?frame=true

with the WH_CALLWNDPROC option.

The specified CallWndProc() (in an wxternal DLL), looks in the returned lParam for a pointer to a CWPSTRUCT whose member hwnd is compared against the target hwnd.  When they match, look for whichever message(s) you're interested in.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
erictankokAuthor Commented:
Thanks.

is there a way to use SetWindowsHookEx() without having to put the CallWndProc() in another DLL? This is because my application is just a EXE file.

For example,

SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, NULL, 0)

Can the above work with my CallWndProc located in my main program?

cookreCommented:
With the callback for a global hook in an external dll, the callback code will still be in RAM for the OS to call even if your code exits without releasing the hook.  The OS thus need not check for the presence of the callback before each call to it.
phobiasCommented:
And specifically to answer your question, no you can't do it without putting it in a DLL. Windows requires any global hook callbacks reside in a dll code space so that it is present in the virtual address space of all processes.

In this case it is clear that the hook will need to be called from the context of a separate process, so a function that was from your own process and not in a DLL would not be present at the time the hook was triggered.

However, even for global hooks besides CALLWNDPROC, it is necessary for the function to reside in a dll because global hooks by definition can be called from an arbitrary process/thread context and not just the context of your own process (otherwise it wouldn't be global).

Hope that helps clear up the reason for the inconvenience of having to place the function in a dll.
erictankokAuthor Commented:
Oh well. I can't have a separate DLL due to certain project requirements. So I guess I will have to use a timer to poll for window minimisation.

Thanks everyone for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.