Did SendMessage has sent custom message? - winapi

I'm using code below to send message to main thread dialog window:
SendMessage(AuthMsgHWND,WM_AUTHORISE_MESSAGE, (WPARAM)&params,0);
Because of unknown reason sometimes main window didn't get message and SendMessage imediatly returns. Is it possible somehow to know was SendMessage successful?

Related

WM_PAINT while waiting for server response

It seems to me, WM_PAINT messages are send to a window while a thread with this window is waiting for a synchronous response of the COM server. The message appears after a while, or when other actions of user appear. I would like to change background color of the window in this case, but how can I find out, if WM_PAINT is sent as a result of blocking COM server, and not just send in other cases?
I tried to expect a flag while painting, maybe in PAINTSTRUCT, but there I found anything. I need another API call to check this condition.

A question about windows api DestroyWindow

I want to konw if there is a message pump in DestroyWindow,and if the message WM_DESTROY will be processed before DestroyWindow return.
This is my test code:
And the message posted before DestroyWindow still remains in the message queue when the WM_DESTROY is processed:
enter image description here
but when DestroyWindow return,the message posted before DestroyWindow will be removed:
enter image description here
There is no message pump in DestroyWindow. I submit that it is pretty obvious that any messages destined to a window that's being destroyed are dropped from the queue when the window is destroyed. Even in Windows 3.1, the alternative would be unthinkable because you can't know if another program's window is about to be destroyed. How much more so now when we have pre-emptive threading now.

Determine the origin of a WM_CLOSE message

I have an app that prompts the user for confirmation on exit, which is (indirectly) done by opening a confirmation dialog when the WM_CLOSE message is received. However the message is also sent by the task manager when the user uses end task on the process.
Because I prevent the window from closing with the confirmation dialog, task manager sees it as the process hanging and forcefully terminates it preventing the app from doing a graceful exit when it's possible.
Is there any way to determine if it's the user closing the window from the message (e.g. clicking the close button, or Alt+F4), and not the task manager? As the message's parameters are unused the only way I could think of is checking for mouse events or WM_SYSCOMMAND that were received some time before the WM_CLOSE is received, but I'm unsure if this would handle all cases.
I assume the task manager calls EndTask. Perhaps in the old days it only sent WM_CLOSE but it seems to send WM_SYSCOMMAND when I tested now so there are no clues in the messages you can use, it just looks like a normal Alt+F4.
If your app is asking about unsaved changes in a document, I would say, put up the dialog regardless and just accept the hard termination if that is what the user wants.
If you are just trying to prevent an accidental close, call GetForegroundWindow in WM_CLOSE. If you are not foreground, it was not an accidental close.

Close Find/Replace Dialog programmatically

How do I close the Windows Find and Replace dialog boxes programmatically ensuring the FINDMSGSTRING message is sent so I can get the settings to save them? DestroyWindow does not send the message.
FindText() and ReplaceText() both return an HWND for the dialog. If you want to close that HWND yourself programmably, send it a WM_CLOSE message. That is the same message the dialog receives if the user dismisses the dialog. It will destroy itself after closing, but this gives it the opportunity to send the final FINDMSGSTRING message to you.

Why does my SendMessage call fail when the target application executes in the background?

I'm trying to send text to 2 different textboxes in a 3rd party application.
And my code works. Although it doesn't work if my application executes in the background. Only if the program I send the text to is behind mine.
Does anyone know what causes this?
Use PostMessage not SendMessage - SendMessage waits for the message to be processed by the called winproc before it returns where PostMessage places the message on the application queue and returns immediately.

Resources