Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean messages in Windows Message Pump

  1. I don't know much about Windows Message Pump but I guess events are triggered using Message Pump.

When my Web browser control navigates to some websites it fires various events of Document Completion. Once I have what I need in WebBrowser_Document_Completed() I want to ignore all further Document Completion.

  1. How can I it?

If I show a MessageBox() in Document_Completed(...), It shows multiple message boxes, looks like it is running in parallel threads, but when I debug it I find that it runs always on main thread.

  1. When are the other two threads created?

Also, when I press Close it closes the window but the process is still running in the background. I am not using any other thread yet I still see two other threads when I debug.

like image 912
Charlie Avatar asked Nov 27 '14 09:11

Charlie


People also ask

What is the difference between GetMessage and PeekMessage?

The main difference between the two functions is that GetMessage does not return until a message matching the filter criteria is placed in the queue, whereas PeekMessage returns immediately regardless of whether a message is in the queue.

What is message loop in windows programming?

The message loop is an obligatory section of code in every program that uses a graphical user interface under Microsoft Windows. Windows programs that have a GUI are event-driven. Windows maintains an individual message queue for each thread that has created a window. Usually only the first thread creates windows.

What are queued and non queued messages?

Message queues is used to route mouse and keyboard input to the appropriate window. Nonqueued messages are sent immediately to the destination window procedure, bypassing the system message queue and thread message queue.

What is message in visual programming?

The MsgBox is a dialog box in the excel VBA that can be used to inform the users of your program. It displays a pop-up style message box and waits for the user to click a button, and then an action is performed based on the clicked button by the user.


1 Answers

The most direct way to do this will be to intercept and evaluate messages being propagated to your control by overriding it's WndProc() method. With a little bit of debugger observation you can identify the wm_message constant that corresponds to your target event and then alter execution flow accordingly. There is a pretty good example of this on the MSDN site: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

To get an idea of the message(s) you are seeing/looking for, reference: http://www.pinvoke.net/default.aspx/Constants/WM.html

like image 95
Serialize Avatar answered Nov 09 '22 01:11

Serialize