help intercepting win32 messages and delaying the message being processed

Hi guys,

I hope you can help here. I created a program which 'hooks' into an external programs window win32 messages and adds a couple of buttons.

To do this i detect and intercept the programs WM_WINPOSCHANGED message. When i intercept this message i check if the window being opened is the one i want to add the buttons to (using the window title) and i add my button to the screen. However this has caused a couple of problems.

I have found out that there are a couple of windows with the same window title (i.e. "customers") that do totally different things, and so to distinguish between the different windows  i decided to look for a field on the screen which was unique to that screen, i.e. a field with the text "contacts".

So when i intercept the WM_WINPOSCHANGED from the window with the title "customers" i set up an EnumChildProc of its windows and iterate through the windows to see if a window with the text "contacts" is present. if so than i will want to add the button.

however the is when the WM_WINPOSCHANGED message is sent for the window "customers" all of the child windows have not been added to the screen. so when i  iterate through using the EmunChildProc i don't iterate through all the windows, and so cannot check the text in the field.

(this also adds the problem of the buttons not being added to the top the screen, but this can be solved using BringWindoToTop()).

Now, would it be possible to detect the WM_WINPOSCHANGED message and somehow put a hold (using a timer or something) executing my check and add button code until all the windows have been added?

(Could i perhaps intercept the WM_WINPOSCHANGED message wait and then post my own user message which would add the buttons? how would i do this?)

many thanks,

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.

flynnyAuthor Commented:
sorry guys the message i was intecepting was the WM_WINPOSCHANGED not WM_WINDOWCHANGED
flynnyAuthor Commented:
would it be worth trying WaitForInputIdle() for this?
if so, would this be possible to execute inside a callback function? i.e. the method waits until there is not message left to process in the thread, but if i'm processing the thread then is this possible?
>>Now, would it be possible to detect the WM_WINPOSCHANGED message and
>>somehow put a hold (using a timer or something) executing my check and add
>>button code until all the windows have been added?

You should be able to do that in a WH_GETMESSAGE hook. Just store the message and remove it via

MSG msg;

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
flynnyAuthor Commented:
As i'm still having problems in my other thread and as my questions are interlinked now i'll join this to my other question here.

flynnyAuthor Commented:
great thanks for all your help jkr
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
Microsoft Development

From novice to tech pro — start learning today.