PreTranslateMessage problem? :(
-
Hi i need some help in my work with PreTranslateMessage. PreTranslateMessage dont work if my worker thread is runnin? I kant catch keyevents if i want to copy and paste from my CListCtrl with ctrl + c :
// sample with mousewheel: BOOL CMyDialog::PreTranslateMessage(MSG* pMsg ) { UINT uMsg = pMsg->message; if(uMsg == WM_MOUSEWHEEL) { // do something } return CDialog::PreTranslateMessage(pMsg); }
When the workerthread ist stoped PreTranslateMessage works fine and i can cach keyboard input. What is wrong with my code?? Best regards bosfan -
Hi i need some help in my work with PreTranslateMessage. PreTranslateMessage dont work if my worker thread is runnin? I kant catch keyevents if i want to copy and paste from my CListCtrl with ctrl + c :
// sample with mousewheel: BOOL CMyDialog::PreTranslateMessage(MSG* pMsg ) { UINT uMsg = pMsg->message; if(uMsg == WM_MOUSEWHEEL) { // do something } return CDialog::PreTranslateMessage(pMsg); }
When the workerthread ist stoped PreTranslateMessage works fine and i can cach keyboard input. What is wrong with my code?? Best regards bosfanThe code shown is OK. But we don't know what your worker thread is doing. If it is performing long operations without using wait calls, it may block other threads.
-
The code shown is OK. But we don't know what your worker thread is doing. If it is performing long operations without using wait calls, it may block other threads.
-
Hello, worker thread fill a large CListCtrl with data etc. I look into workerthread and try to find what causes this! Thanks for answer. Regards bosfan
bosfan wrote:
worker thread fill a large CListCtrl with data etc.
Your secondary thread should not be interacting directly with a UI control it does not own. It should be posting a message to the owning (primary) thread instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
bosfan wrote:
worker thread fill a large CListCtrl with data etc.
Your secondary thread should not be interacting directly with a UI control it does not own. It should be posting a message to the owning (primary) thread instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
Hi, thanks for answer,sorry my mistake, the worker thread don't fill a list control directly, they just fill a stl::map with data, and a owner thread(primary thread) take the items from map and show them, is "Owner Data" of CListCtrl. This way is ok? best regards bosfan
-
Hi i need some help in my work with PreTranslateMessage. PreTranslateMessage dont work if my worker thread is runnin? I kant catch keyevents if i want to copy and paste from my CListCtrl with ctrl + c :
// sample with mousewheel: BOOL CMyDialog::PreTranslateMessage(MSG* pMsg ) { UINT uMsg = pMsg->message; if(uMsg == WM_MOUSEWHEEL) { // do something } return CDialog::PreTranslateMessage(pMsg); }
When the workerthread ist stoped PreTranslateMessage works fine and i can cach keyboard input. What is wrong with my code?? Best regards bosfanif(uMsg == WM_MOUSEWHEEL)
{
// do something
//you must return here
return ;
}
return CDialog::PreTranslateMessage(pMsg);
} -
Hello, worker thread fill a large CListCtrl with data etc. I look into workerthread and try to find what causes this! Thanks for answer. Regards bosfan
When the worker threads runs for a significant time (above 100 ms), there should be some function calls allowing other threads to run (
WaitForSingleObjectm
,WaitForMultipleObjects
,Sleep
). If the worker thread runs with the same priority as the main thread, you may insert someSleep(0)
calls inside the loop to check if this allows your main thread to handle its messages. If so, you should change the worker thread in some way without usingSleep()
. You may also check the communication between worker and main thread. There may be problems even when not directly accessing UI elements. How did you send messages from the worker thread to your dialog or list control? -
if(uMsg == WM_MOUSEWHEEL)
{
// do something
//you must return here
return ;
}
return CDialog::PreTranslateMessage(pMsg);
}Hi, there is an return, that what i mean is i cant set a breakpoint in this function when worker thread is running, there is an code for [strg + c] and [strg + v], i mean for copy and paste :), and this don't work and i dont know why? :( Like i said before this works only if i stop a worker thread not when he is active. So i think i do something wrong :( Here is little more code:
if(WM_KEYDOWN == uMsg)
{
if(GetKeyState(VK_CONTROL) < 0)
{
if('C' == pMsg->wParam )
{
// kopieren!
theApp.CopyToClipboard();
}
else if('V' == pMsg->wParam || 'v' == pMsg->wParam)
{
// rest of code
}
}
}
// some other code
// at end is returnbosfan
-
When the worker threads runs for a significant time (above 100 ms), there should be some function calls allowing other threads to run (
WaitForSingleObjectm
,WaitForMultipleObjects
,Sleep
). If the worker thread runs with the same priority as the main thread, you may insert someSleep(0)
calls inside the loop to check if this allows your main thread to handle its messages. If so, you should change the worker thread in some way without usingSleep()
. You may also check the communication between worker and main thread. There may be problems even when not directly accessing UI elements. How did you send messages from the worker thread to your dialog or list control?I don't use ::SendMessage(..) for this, i set a timer to set the size for this list control with CListCtrl::SetSize(newsize) and new size is stl::map size, number of items in map. Like you said i check first communication between worker and main thread. I start this thread (worker) with a lowest priority.
-
Hi i need some help in my work with PreTranslateMessage. PreTranslateMessage dont work if my worker thread is runnin? I kant catch keyevents if i want to copy and paste from my CListCtrl with ctrl + c :
// sample with mousewheel: BOOL CMyDialog::PreTranslateMessage(MSG* pMsg ) { UINT uMsg = pMsg->message; if(uMsg == WM_MOUSEWHEEL) { // do something } return CDialog::PreTranslateMessage(pMsg); }
When the workerthread ist stoped PreTranslateMessage works fine and i can cach keyboard input. What is wrong with my code?? Best regards bosfanHi, There is probably nothing syntactically wrong with your code. Your architecture is wrong. When worker thread B interacts with a window belonging to thread A... the windows subsystem (win32k.sys) associates thread B with the window and thread B will potentially recieve messages from the input queue... it actually depends on which thread is the 'foreground thread'. This effectively causes worker thread B to eat your input message for lunch. Best Wishes, -David Delaune P.S. I assert that the documentation on MSDN is incomplete: About Keyboard Input[^] The graph and description there is a simplification of what is actually happening and does not address thread groups. Best Wishes, -David Delaune
-
Hi i need some help in my work with PreTranslateMessage. PreTranslateMessage dont work if my worker thread is runnin? I kant catch keyevents if i want to copy and paste from my CListCtrl with ctrl + c :
// sample with mousewheel: BOOL CMyDialog::PreTranslateMessage(MSG* pMsg ) { UINT uMsg = pMsg->message; if(uMsg == WM_MOUSEWHEEL) { // do something } return CDialog::PreTranslateMessage(pMsg); }
When the workerthread ist stoped PreTranslateMessage works fine and i can cach keyboard input. What is wrong with my code?? Best regards bosfanYou're not trying to update the control inside of PreTranslateMessage are you? The controls get updated from messages sent through the message pump. If you're blocking from inside of PreTranslateMessage, then your code could hang.