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. Problem in subclassing of Combobox

Problem in subclassing of Combobox

Scheduled Pinned Locked Moved C / C++ / MFC
delphihelp
17 Posts 2 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.
  • A ashtwin

    Hi, from the function below i am sending the message. BOOL MyBaseClass::PreTranslateMessage(MSG *pMsg) { HWND hParent, hChild; if(::FindWindow(NULL, _T("My Dialog"))) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_TAB) { hChild = ::GetFocus(); hParent = ::GetParent(hChild); ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); } } } return MyBaseClass::PreTranslateMessage(pMsg); } I am doing this because due to some reasons the keyboard messages are going to the above function. MyBaseclass is the class from the child class of whom i am creating the modeless dialog.

    modified on Monday, January 07, 2008 8:31:43 AM

    N Offline
    N Offline
    Nishad S
    wrote on last edited by
    #8

    ashtwin wrote:

    return MyBaseClass::PreTranslateMessage(pMsg);

    OK...

    ashtwin wrote:

    ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0);

    I think this WM_MYMESSAGE is WM_USER + nonzero message, right? If so what is the exact value? Or it a registered message? Also did you tried by excluding the subclassing done in the InitDialog, but keeping this MyBaseClass::PreTranslateMessage function as now?

    - NS - [ODBaseBtn]

    A 1 Reply Last reply
    0
    • N Nishad S

      ashtwin wrote:

      return MyBaseClass::PreTranslateMessage(pMsg);

      OK...

      ashtwin wrote:

      ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0);

      I think this WM_MYMESSAGE is WM_USER + nonzero message, right? If so what is the exact value? Or it a registered message? Also did you tried by excluding the subclassing done in the InitDialog, but keeping this MyBaseClass::PreTranslateMessage function as now?

      - NS - [ODBaseBtn]

      A Offline
      A Offline
      ashtwin
      wrote on last edited by
      #9

      The value of MyMessage is WM_USER+1 and it is working fine for other controls. Without subclassing also io have tried but the message is getting lost somewhere because the focus is on the editbox of combobox and not on combobox. Thanks

      1 Reply Last reply
      0
      • A ashtwin

        Hi, from the function below i am sending the message. BOOL MyBaseClass::PreTranslateMessage(MSG *pMsg) { HWND hParent, hChild; if(::FindWindow(NULL, _T("My Dialog"))) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_TAB) { hChild = ::GetFocus(); hParent = ::GetParent(hChild); ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); } } } return MyBaseClass::PreTranslateMessage(pMsg); } I am doing this because due to some reasons the keyboard messages are going to the above function. MyBaseclass is the class from the child class of whom i am creating the modeless dialog.

        modified on Monday, January 07, 2008 8:31:43 AM

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #10

        One thing I noticed just now... :( <blockquote class="FQ"><div class="FQA">ashtwin wrote:</div>hChild = ::GetFocus(); hParent = ::GetParent(hChild); ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); </blockquote> So the parent is the combobox itself, and the message is posted to it. So this message is going to be received by combobox, not the parent of the combobox. Is it expected? What is happening exactly with the subclassing?

        - NS - [ODBaseBtn]

        A 1 Reply Last reply
        0
        • N Nishad S

          One thing I noticed just now... :( <blockquote class="FQ"><div class="FQA">ashtwin wrote:</div>hChild = ::GetFocus(); hParent = ::GetParent(hChild); ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); </blockquote> So the parent is the combobox itself, and the message is posted to it. So this message is going to be received by combobox, not the parent of the combobox. Is it expected? What is happening exactly with the subclassing?

          - NS - [ODBaseBtn]

          A Offline
          A Offline
          ashtwin
          wrote on last edited by
          #11

          No it is not expected, i want to send the message to the parent dialog and not to the combobox. Because in dialog class i am setting the focus to the next control after receiving the message i.e why i have done subclassing for combobox. But after doing subclassing mouse clicks and other things are not working for combobox and even it is effecting other comboboxes also(eg they are appearing as disabled untill i am cliking the mouse on them). Thanks

          N 1 Reply Last reply
          0
          • A ashtwin

            No it is not expected, i want to send the message to the parent dialog and not to the combobox. Because in dialog class i am setting the focus to the next control after receiving the message i.e why i have done subclassing for combobox. But after doing subclassing mouse clicks and other things are not working for combobox and even it is effecting other comboboxes also(eg they are appearing as disabled untill i am cliking the mouse on them). Thanks

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #12

            So you should check whether it is the correct control or not. You can check control ID since you have to do it in only one control. Calling ::GetMenu( hWndCombo ) will give you the ID, provided hWndCombo is the handle to the combobox obtained by calling GetParent( hWndEdit ). You should only change the focus if the control ID is of the specified combo.

            - NS - [ODBaseBtn]

            A 1 Reply Last reply
            0
            • N Nishad S

              So you should check whether it is the correct control or not. You can check control ID since you have to do it in only one control. Calling ::GetMenu( hWndCombo ) will give you the ID, provided hWndCombo is the handle to the combobox obtained by calling GetParent( hWndEdit ). You should only change the focus if the control ID is of the specified combo.

              - NS - [ODBaseBtn]

              A Offline
              A Offline
              ashtwin
              wrote on last edited by
              #13

              Hi, now after doing the following changes the application is working fine but still i don't know about the problem with subclassing. BOOL MyBaseClass::PreTranslateMessage(MSG *pMsg) { if(::FindWindow(NULL, _T("Temporary Catheter Connections"))) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_TAB) { COMBOBOXINFO cbi; hChild = ::GetFocus(); hParent = ::GetParent(hChild); cbi.cbSize = sizeof(COMBOBOXINFO); if(GetComboBoxInfo(hParent, &cbi)) { hParent = ::GetParent(hParent);//Get dialog handle for combobox } ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); } } } return BaseClass::PreTranslateMessage(pMsg); } Thanks

              N 1 Reply Last reply
              0
              • A ashtwin

                Hi, now after doing the following changes the application is working fine but still i don't know about the problem with subclassing. BOOL MyBaseClass::PreTranslateMessage(MSG *pMsg) { if(::FindWindow(NULL, _T("Temporary Catheter Connections"))) { if(pMsg->message == WM_KEYDOWN) { if(pMsg->wParam == VK_TAB) { COMBOBOXINFO cbi; hChild = ::GetFocus(); hParent = ::GetParent(hChild); cbi.cbSize = sizeof(COMBOBOXINFO); if(GetComboBoxInfo(hParent, &cbi)) { hParent = ::GetParent(hParent);//Get dialog handle for combobox } ::PostMessage(hParent, WM_MYMESSAGE, /*pMsg->wParam*/0, /*pMsg->lParam*/0); } } } return BaseClass::PreTranslateMessage(pMsg); } Thanks

                N Offline
                N Offline
                Nishad S
                wrote on last edited by
                #14

                OK... :) Please confirm my understanding. You need to change the focus to the next control when the focus is set to combo using Tab key. Am I right?

                - NS - [ODBaseBtn]

                A 1 Reply Last reply
                0
                • N Nishad S

                  OK... :) Please confirm my understanding. You need to change the focus to the next control when the focus is set to combo using Tab key. Am I right?

                  - NS - [ODBaseBtn]

                  A Offline
                  A Offline
                  ashtwin
                  wrote on last edited by
                  #15

                  Yes, u r right. Thanks :)

                  N 1 Reply Last reply
                  0
                  • A ashtwin

                    Yes, u r right. Thanks :)

                    N Offline
                    N Offline
                    Nishad S
                    wrote on last edited by
                    #16

                    Then removing the WS_TABSTOP property wasn't enough?

                    - NS - [ODBaseBtn]

                    A 1 Reply Last reply
                    0
                    • N Nishad S

                      Then removing the WS_TABSTOP property wasn't enough?

                      - NS - [ODBaseBtn]

                      A Offline
                      A Offline
                      ashtwin
                      wrote on last edited by
                      #17

                      I want the focus on combobox also, when user presses the tab key on the control previous to the ComboBox. So, problem was that if the focus is on Combobox and user presses the tab key, then it should move to the next control. Thanks

                      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