Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PreTranslateMessage problem? :(

PreTranslateMessage problem? :(

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bosfan
    wrote on last edited by
    #1

    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

    J U L J 4 Replies Last reply
    0
    • B 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 bosfan

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • J Jochen Arndt

        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.

        B Offline
        B Offline
        bosfan
        wrote on last edited by
        #3

        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

        D J 2 Replies Last reply
        0
        • B bosfan

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          B 1 Reply Last reply
          0
          • D David Crow

            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

            B Offline
            B Offline
            bosfan
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • B 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 bosfan

              U Offline
              U Offline
              User 8402662
              wrote on last edited by
              #6

              if(uMsg == WM_MOUSEWHEEL)
              {
              // do something
              //you must return here
              return ;
              }
              return CDialog::PreTranslateMessage(pMsg);
              }

              B 1 Reply Last reply
              0
              • B bosfan

                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

                J Offline
                J Offline
                Jochen Arndt
                wrote on last edited by
                #7

                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 some Sleep(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 using Sleep(). 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?

                B 1 Reply Last reply
                0
                • U User 8402662

                  if(uMsg == WM_MOUSEWHEEL)
                  {
                  // do something
                  //you must return here
                  return ;
                  }
                  return CDialog::PreTranslateMessage(pMsg);
                  }

                  B Offline
                  B Offline
                  bosfan
                  wrote on last edited by
                  #8

                  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 return

                  bosfan

                  1 Reply Last reply
                  0
                  • J Jochen Arndt

                    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 some Sleep(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 using Sleep(). 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?

                    B Offline
                    B Offline
                    bosfan
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • B 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 bosfan

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Hi, 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

                      1 Reply Last reply
                      0
                      • B 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 bosfan

                        J Offline
                        J Offline
                        JackDingler
                        wrote on last edited by
                        #11

                        You'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.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups