Secondary Loop vs Separate Thread Thread

I'm talking about a Windows desktop app. I want to write a function like SelectObject

(for example) that blocks the caller until the user clicks on an object in the client area of โ€‹โ€‹the application. After the user has selected an object, the function returns a pointer to it.

One way to do this is to run a small message loop and filter WM_MOUSE*

as other messages are passed to the outer message loop. ( CRectTracker

does it I guess.)

This can also be tweaked to start the caller on a separate thread. SelectObject

will be used CreateEvent/SetEvent/ResetEvent

to synchronize with the main thread that processes mouse messages and returns after the conditions that match the object selection are met.

What are the pros and cons of each approach? Where can I find more information about such projects? What are the formal terms for such things?

Programmers who have closely watched or worked with AutoCAD may understand what I conveyed so poorly here.

+1


source to share


2 answers


I don't know the term for it, but the type of function you are describing I would call a modal function in the same vein as a modal window. It sounds like you want something like TrackPopupMenu

. I expect it to work as you described, with a message loop that handles mouse and keyboard messages for the popup menu.

I think your flow idea will just get complicated for a little benefit. Messages for the base window will still go to this window thread, not your separate thread, and any picture you make in that window should happen on that window thread as well.



Do you know SetCapture

? I think it would be helpful to get where you are trying to go. This allows you to drag all mouse events into one window even if the mouse is not over that window.

+1


source


Modal doesn't make sense in Win32. SelectObject completely off topic (GDI)



-1


source







All Articles