Home > Software engineering >  The main thread wait loop, because DispatchMessage () block missed synchronization events, how to so
The main thread wait loop, because DispatchMessage () block missed synchronization events, how to so

Time:09-26

This is part of the code in the main thread;
The main thread of the need to create a modal dialog box, when the mouse hold the dialog title bar, wait for a while the following (TRUE) card below DispatchMessage (& amp; MSG); Function, because the DispatchMessage function to wait for message processing function returns; Because it is the main thread requires the response message, interface control input, so must the response message, is there any function can replace DispatchMessage function, can not need to wait for returns? Using PostMessage messaging doesn't work,
When the main thread interface CListCtrl controls have a scroll bar, the mouse point when staying in a scroll bar is also may clog, should be DispatchMessage function waiting for return,
The great god, is there any solution can make main interface normal response message, without blocking the While loop, not missed synchronization events????????
 
HPrsEvents=CreateEvent (NULL, FALSE, FALSE, NULL);
HPrsDEvents=CreateEvent (NULL, FALSE, FALSE, NULL);
HDAQThread=AfxBeginThread (CDaqUsb1616HS: : DaqScanT, & amp; M_daq);//data acquisition thread
HPrcThread=AfxBeginThread (CDataPreAnalyse: : DaqRundataPrc, & amp; M_dpa);//data processing threads
HAllEvents [0]=hPrsEvents;
HAllEvents [1]=hPrsDEvents;

While (TRUE)
{
DwRet=MsgWaitForMultipleObjects (2, hAllEvents, FALSE, INFINITE, QS_ALLINPUT);//wait for
The switch (dwRet)
{
Case WAIT_OBJECT_0://stop
STR. The Format (" the end of the data collection! Acquisition=% ld, display storage quantity=% ld;" , m_daq. DaqP. SampleNum, I);
StrInfo=STR;

break;//break the loop
Case WAIT_OBJECT_0 + 1://data update
i++;
STR. The Format (" I=% ld, display the data number data processing=% d;" And I, m_dpa. DataP. IPrsTimes);
StrInfo=STR;
SetStatusInfo (strInfo, 1);
UpdateShow ();
continue;
Case WAIT_OBJECT_0 + 2:
While (PeekMessage (& amp; MSG, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);////when the mouse hold the dialog title bar
}
continue;
Default:
break;//unexpected failure
}
break;
}

CodePudding user response:

Note that the application is responsible for retrieving and dispatching input messages to the dialog box, Most applications use the main message loop for this. Or, to permit the user to move to and select controls by using the the rid_device_info_keyboard, the application must call IsDialogMessage. For more information, see dialog box the rid_device_info_keyboard Interface. See if the effect of the ~

CodePudding user response:

IsDialogMessage
Itself is synchronous, the same will be blocked! I tried, the result is the same

CodePudding user response:

MsgWaitForMultipleObjects do you want to use this

CodePudding user response:

"Windows core programming"

CodePudding user response:

4th floor, "Windows core programming" a good thick, about my problem in the message processing in where? To help locate it,,,

CodePudding user response:

While (PeekMessage (& amp; Is modified to the if (PeekMessage (& amp; Give it a try

CodePudding user response:


While (PeekMessage (& amp; Is modified to the if (PeekMessage (& amp; Try

There will be other issues, a take a message, it is easy to die, I'm using if before, use while a take out all the news is the best, otherwise efficiency is too low!!
Problem is on the dispatchmessage, he is a synchronous function, so let's wait for message processing after return; Because drag the title bar to wait for release the mouse, and a dragging action is finished, I used to intercept the mouse drag the title bar of the message, can realize the function of drag a window to overcome the problems by themselves; I want to use the same method to eliminate, the mouse to click minimum, maximum button, and the mouse point to live the inside of the CListCtrl scroll bar not to put, the issues that led to the interface can't update found that I was unable to determine what parts of the concrete click of the mouse scroll bar, so the left and right sides of the scroll bar arrows, the scroll bar slider or scrollbar margin; This information is can not function and parameters. Because the inside of the CListCtrl scroll bar is not CScrollBar object, is a custom painting scroll bar, so GetScrollBarCtrl function get a null pointer; I also know how to get the mouse is clicked on the minimize maximize button; A great god can work it out, please?

CodePudding user response:

Don't wait for events in the main thread, start a timer to detect acquisition and processing, waiting for the timeout parameter is set to 0, waiting for the return immediately

CodePudding user response:

I know with the settimer can overcome the problem of drag CListCtrl scrollbar stuck inside, drag the title bar but for the smallest maximize button or click the title bar, is also a problem; So I wonder is there a way to completely solve these problems, these problems are due to dispatchmessage sends out the news to wait for returns, drag and drop. Don't simple method can overcome the above disadvantages??????

CodePudding user response:

reference 5 floor lfxiansheng reply: ,
4 floor "Windows core programming" a good thick, about my problem in the message processing in where? To help locate it,,,

Problems with his watch "Windows core programming" in the section,

CodePudding user response:

references to the tenth floor zhao4zhong1 response:
Quote: refer to the fifth floor lfxiansheng reply:

4th floor, "Windows core programming" a good thick, about my problem in the message processing in where? To help locate it,,,

Problems with his watch in the "Windows core programming" related chapters,

I have read the book from the first page of chapter 9: with a kernel thread synchronization, couldn't find a solution;
Don't I see the bifurcation? Didn't find the solution,,,

CodePudding user response:

11 references lfxiansheng response:
Quote: reference to the tenth floor zhao4zhong1 response:

Quote: refer to the fifth floor lfxiansheng reply:

4th floor, "Windows core programming" a good thick, about my problem in the message processing in where? To help locate it,,,

Problems with his watch in the "Windows core programming" related chapters,

I have read the book from the first page of chapter 9: with a kernel thread synchronization, couldn't find a solution;
Don't I see the bifurcation? Didn't find the solution,,,

Then in a simple MFC ""

CodePudding user response:

refer to 12 floor zhao4zhong1 reply:
Quote: reference 11 floor lfxiansheng response:

The
Quote: reference to the tenth floor zhao4zhong1 response:

Quote: refer to the fifth floor lfxiansheng reply:

4th floor, "Windows core programming" a good thick, about my problem in the message processing in where? To help locate it,,,

Problems with his watch in the "Windows core programming" related chapters,

I have read the book from the first page of chapter 9: with a kernel thread synchronization, couldn't find a solution; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related