Sign in to follow this  
Chaucer

SendMessage breaks, causes crash

Recommended Posts

I have an application that I am sending messages to from my program using SendMessage. One of those messages is to close a specific window within the application. If I open and close this window quickly( once every 500 milliseconds ), I find that after a few iterations, the window opens but the message to close the window does not actually close the window. I'm using SendMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 ). Any ideas on why it would stay open after the SendMessage call?

Share this post


Link to post
Share on other sites
I heard somewhere (I forget where) that you should use PostMessage() to send messages to other applications. Does the problem still happen with PostMessage()?

Also, why do you need to create and destroy the window every 500ms? Wouldn't something like ShowWindow(hWnd,SW_HIDE) be better?

Share this post


Link to post
Share on other sites
I need to use SendMessage because I don't want to continue until the window is closed. I would like to be able to leave it open and show/hide it except that it is a dialog with an OK button that I sometimes need to press. When I press the OK button, the dialog will disappear and I'll have to open again.

I believe the reason might be that there's another dialog with the same title that I'm finding and closing... the wrong one. I'm not sure how else to distinguish 2 windows with the same title. Or how to know which is the one I just opened and which is the one that has been open but hidden the entire time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
SendMessage(hwnd,WM_CLOSE,NULL,NULL); //the nice guy approach

SendMessage(hwnd,WM_DESTROY,NULL,NULL); //the more abrupt approach


I suppose either of these two should work, give them a try.


-Nervo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this