Home > Software engineering >  In the [WCE7] PreTranslateMessage doModal after open the window, PostMessage won't receive it o
In the [WCE7] PreTranslateMessage doModal after open the window, PostMessage won't receive it o

Time:09-22

RT:
Program has a background thread, matrix keyboard scanning, and according to the CWnd * dlgCurrent, keystroke messages sent
: : PostMessage (dlgCurrent - & gt; M_hwnd,... )

In the main window and the child window (in the Menu window) defines PreTranslateMessage news,
Main form initialization time dlgCurrent=this,

After running the program, main form can receive the corresponding key information,
In one of the key message is open the child form
Case MYKEY_MENU:
CMYMenu * dlgMenu=new CMYMenu ();
DlgCurrent=dlgMenu;
DlgMenu. DoModal ();
DlgCurrent=this;
.

Just open the Menu window, keyboard keys all news,

Don't do any operation, about 5 minutes later, the Menu window will not receive any news of the PostMessage anymore,,,,

Through the alignment:
Normal background keyboard scanning thread send PostMessage dlgCurrent data (window pointer what of, is pointing at the Menu window, before and after contrast).
The Menu window display properly;
Menu window destructor added a piece of code and breakpoints, no interruption occurred;
Main form in case PreTranslateMessage MYKEY_MENU branch to open the menu window is added before and after the breakpoint, no abnormal exit,



Why?
The message the breakdown?
How to troubleshoot the problem?

CodePudding user response:

Search "GDI leak detection"?

CodePudding user response:

See if PostMessage success?
The PostMessage parameters TRACE out to observe the changes of news

CodePudding user response:

Handle to the window and also a print, see there are any changes window handle

CodePudding user response:

"Program have a background thread, matrix keyboard scanning"
Upload code?

CodePudding user response:

reference 1st floor zhao4zhong1 response:
search "GDI leak detection"?


Isn't the problem the GDI

1 all GDI associated within a custom class, GetXX createXX have ReleaseXX DeleteXX corresponding,

2 in the main program timing refresh interface display data, after the login is not refresh (or even commented out), open the Menu after the child window, what all don't operation, a few minutes later, the same result,


CodePudding user response:

refer to the second floor zgl7903 response:
see if PostMessage success?
The PostMessage message TRACE out observation parameters change


The keyboard scanning, if there is no key, I returned to the 0 x00, have key when the returned values (according to the ranks of the two-dimensional table), the button is released

If ((byteKey==0 x00) & amp; & (bytePriorKey & gt; 0))//up, just think to complete a button
{
//according to the current window directional buttons messages sent
: : PostMessage (dlgCurrent - & gt; M_hWnd, MYMSG_KEYDOWN bytePriorKey, 0);
}
BytePriorKey=byteKey;

So use the debug and breakpoints, send messages, related dlgCurrent data are normal,
PostMessage itself was successful, can see,

CodePudding user response:

reference oyljerry reply: 3/f
the print, too, such as a handle to the window to see there are any changes window handle


Handle the normal, does not change,

CodePudding user response:

One way to check whether resource leaks:
In the process of the task manager to see inside the column selection: memory, virtual memory size, handle number, number of threads, the USER object, GDI objects
Make your program (process) don't quit, cycle through main process many times, the more the better, like 1000000 times or even an infinite loop, record the above numerical, it through at least one hour, as long as possible, such as a month, to record more than the value, if the above two groups of numerical differential is bigger or increasing over time, will certainly have a corresponding resources resource leaks!

CodePudding user response:

The hardware keyboard to consider jitter,

CodePudding user response:

1. Suggest don't use multithreading program sends a message window pointer, then the inside of the window handle, because this dlgCurrent auxiliary thread when window switch may not know, so you at least do a critical region incompatible
2. May your program somewhere modified the pointer, or pointer is invalid, so this time may be bad to debug the abnormal errors, suggest you every time PostMessage (... ) handle to the target window and saved to a Log file, then also put CMYMenu popup Windows also do a record, best time to record to milliseconds

CodePudding user response:

refer to the eighth floor zhao4zhong1 response:
check whether resource leaks one way:
In the process of the task manager to see inside the column selection: memory, virtual memory size, handle number, number of threads, the USER object, GDI objects
Make your program (process) don't quit, cycle through main process many times, the more the better, like 1000000 times or even an infinite loop, record the above numerical, it through at least one hour, as long as possible, such as a month, to record more than the value, if the above two groups of numerical differential is bigger or increasing over time, will certainly have a corresponding resources resource leaks!


Buy board with Windows Embedded Compact 7 without these inside,,,

CodePudding user response:

references to the tenth floor WWWFFFHHH response:
1. Suggest don't use multithreading program sends a message window pointer, then the inside of the window handle, because this dlgCurrent auxiliary thread when window switch may not know, so you at least do a critical region incompatible

Now open a new window is a new, new, assignment dlgCurrent immediately, then domodal domodal exit, restore dlgCurrent values,
Carefully checked the assignment of the no middle other situation,
The place to do critical section? Make each window to scan the keyboard, instead of scanning a thread the message?

2. May your program somewhere modified the pointer, or pointer is invalid, so this time may be bad to debug the abnormal errors, suggest you every time PostMessage (... ) handle to the target window and saved to a Log file, then also put CMYMenu popup Windows also do a record, best able to record to the millisecond time


Try to write a log to see, tomorrow,

CodePudding user response:

references 9 f schlafenhamster response:
hardware keyboard to consider jitter,


Stabilization is considered the use of delay,

CodePudding user response:

Why PostMessage, not SendMessage, further, window after receiving the Message to reply to a Message, said received,
You like loose hair disorderly, do not lose things?
  • Related