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. closing of a dialog box on button click problem!

closing of a dialog box on button click problem!

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
19 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.
  • _ _AnsHUMAN_

    Handle the WM_KILLFOCUS event and send a WM_CLOSE (also OnOK, OnCancel would solve ur problem) message to the dialog at the very end of this function.

    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

    D Offline
    D Offline
    Dhiraj kumar Saini
    wrote on last edited by
    #5

    Please tell me how to handle WM_KILLFOCUS message

    _ S 2 Replies Last reply
    0
    • D Dhiraj kumar Saini

      Please tell me how to handle WM_KILLFOCUS message

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #6

      In the same manner in which you handle other messages like WM_PAINT etc.... Write a OnKillFocus handler function for WM_KILLFOCUS and a corresponding entry should be added in the message map. Also do not forget to declare the function in the header file and then implement in the cpp file for your dialog that pops up

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      1 Reply Last reply
      0
      • D Dhiraj kumar Saini

        Please tell me how to handle WM_KILLFOCUS message

        S Offline
        S Offline
        SandipG
        wrote on last edited by
        #7

        Add this to message map.

        ON_WM_KILLFOCUS()

        and add handler funciton

        void CTrialMFCDlg::OnKillFocus(CWnd* pNewWnd)
        {
        CDialog::OnKillFocus(pNewWnd);

        // TODO: Add your message handler code here
        

        }

        Also dont forget to add the handler declaration of the handler in class. I hope it helps. BTW: You can use class wizard to add the handler :)

        Regards, Sandip.

        D 1 Reply Last reply
        0
        • S SandipG

          Add this to message map.

          ON_WM_KILLFOCUS()

          and add handler funciton

          void CTrialMFCDlg::OnKillFocus(CWnd* pNewWnd)
          {
          CDialog::OnKillFocus(pNewWnd);

          // TODO: Add your message handler code here
          

          }

          Also dont forget to add the handler declaration of the handler in class. I hope it helps. BTW: You can use class wizard to add the handler :)

          Regards, Sandip.

          D Offline
          D Offline
          Dhiraj kumar Saini
          wrote on last edited by
          #8

          Sorry to bother you again but i want to ask you one thing. In my application there is a chat dialog box whose name is CChatDlg. In this box there is a button with text as emoticons. On click of this button I am opening a new dialog CEmoticonsDlg without any title bar just on top of the emoticons button. This new dialog box is having 16 emoticons placed as bmp images on a button as is in the case of messanger . Now in the case when no emoticons is selected and the user clicks any arear outside the CEmoticons dialog I want the Dialog CEmoticons to be closed. Right now what i am able to do is that i need to select a emoticon and and on click event of it i am closing the dialog box as a result of which i need to select a smiley. So please help me as to in whcih class I have to use the above cod ewhich you have provided.

          enhzflepE 1 Reply Last reply
          0
          • D Dhiraj kumar Saini

            Sorry to bother you again but i want to ask you one thing. In my application there is a chat dialog box whose name is CChatDlg. In this box there is a button with text as emoticons. On click of this button I am opening a new dialog CEmoticonsDlg without any title bar just on top of the emoticons button. This new dialog box is having 16 emoticons placed as bmp images on a button as is in the case of messanger . Now in the case when no emoticons is selected and the user clicks any arear outside the CEmoticons dialog I want the Dialog CEmoticons to be closed. Right now what i am able to do is that i need to select a emoticon and and on click event of it i am closing the dialog box as a result of which i need to select a smiley. So please help me as to in whcih class I have to use the above cod ewhich you have provided.

            enhzflepE Offline
            enhzflepE Offline
            enhzflep
            wrote on last edited by
            #9

            Dhiraj kumar Saini wrote:

            So please help me as to in whcih class I have to use the above cod ewhich you have provided.

            CEmoticonsDlg, since this is the dialog you want to be able to close by clicking on the background. (as in, not on any of the 16 buttons)

            D 1 Reply Last reply
            0
            • enhzflepE enhzflep

              Dhiraj kumar Saini wrote:

              So please help me as to in whcih class I have to use the above cod ewhich you have provided.

              CEmoticonsDlg, since this is the dialog you want to be able to close by clicking on the background. (as in, not on any of the 16 buttons)

              D Offline
              D Offline
              Dhiraj kumar Saini
              wrote on last edited by
              #10

              what code should i write in the messege handler ON_WM_KILLFOCUS

              enhzflepE 1 Reply Last reply
              0
              • D Dhiraj kumar Saini

                what code should i write in the messege handler ON_WM_KILLFOCUS

                enhzflepE Offline
                enhzflepE Offline
                enhzflep
                wrote on last edited by
                #11

                Dhiraj kumar Saini wrote:

                what code should i write in the messege handler ON_WM_KILLFOCUS

                The already supplied one?[^]

                D 1 Reply Last reply
                0
                • enhzflepE enhzflep

                  Dhiraj kumar Saini wrote:

                  what code should i write in the messege handler ON_WM_KILLFOCUS

                  The already supplied one?[^]

                  D Offline
                  D Offline
                  Dhiraj kumar Saini
                  wrote on last edited by
                  #12

                  I have used the following message handler but now on clicking the emoticon button the dialogbox CEmoticonDlg is not being opened. Please tell me whats the problem. Its urgent

                  void CEmotionsDlg::OnKillFocus(CWnd* pNewWnd)
                  {
                  CDialog::OnKillFocus(pNewWnd);
                  // TODO: Add your message handler code here
                  SendMessage(WM_CLOSE,0,0);
                  }

                  This is how I am opening the CEmoticonDlg Dialog box

                  void CChatDlg::OnEmotions()
                  {
                  CEmotionsDlg m_EmotionsDlg(this);
                  m_EmotionsDlg.DoModal();
                  }

                  Thanks In Advance

                  I 1 Reply Last reply
                  0
                  • D Dhiraj kumar Saini

                    I have used the following message handler but now on clicking the emoticon button the dialogbox CEmoticonDlg is not being opened. Please tell me whats the problem. Its urgent

                    void CEmotionsDlg::OnKillFocus(CWnd* pNewWnd)
                    {
                    CDialog::OnKillFocus(pNewWnd);
                    // TODO: Add your message handler code here
                    SendMessage(WM_CLOSE,0,0);
                    }

                    This is how I am opening the CEmoticonDlg Dialog box

                    void CChatDlg::OnEmotions()
                    {
                    CEmotionsDlg m_EmotionsDlg(this);
                    m_EmotionsDlg.DoModal();
                    }

                    Thanks In Advance

                    I Offline
                    I Offline
                    Iain Clarke Warrior Programmer
                    wrote on last edited by
                    #13

                    Your getting beyond anyone's ability to help you here. You need to put breakpoints in your code, and see what error codes are. My suspicion is your CEmotionsDlg is starting, and stopping almost straight away. Put a breakpoint in the OnKillFocus handler, and see if I'm right. Put a breakpoint in the OnInitDialog handler, see if it gets called. Put a breakpoint on the m_EmotionsDlg.DoModal(); line and follow the code inside. Do you get errors? If in doubt, put breakpoints everywhere! Maybe you have a breakpoint somewhere, and the act of swapping to the debugger is losing focus on your dialog, and... Iain.

                    D 1 Reply Last reply
                    0
                    • I Iain Clarke Warrior Programmer

                      Your getting beyond anyone's ability to help you here. You need to put breakpoints in your code, and see what error codes are. My suspicion is your CEmotionsDlg is starting, and stopping almost straight away. Put a breakpoint in the OnKillFocus handler, and see if I'm right. Put a breakpoint in the OnInitDialog handler, see if it gets called. Put a breakpoint on the m_EmotionsDlg.DoModal(); line and follow the code inside. Do you get errors? If in doubt, put breakpoints everywhere! Maybe you have a breakpoint somewhere, and the act of swapping to the debugger is losing focus on your dialog, and... Iain.

                      D Offline
                      D Offline
                      Dhiraj kumar Saini
                      wrote on last edited by
                      #14

                      I have used the break points after domodal the control is going in InitDialog but not in the KillFocus Message Handler

                      I 1 Reply Last reply
                      0
                      • D Dhiraj kumar Saini

                        I have used the break points after domodal the control is going in InitDialog but not in the KillFocus Message Handler

                        I Offline
                        I Offline
                        Iain Clarke Warrior Programmer
                        wrote on last edited by
                        #15

                        Well, your dialog is starting (which is good news), but it is also finishing too early. You need to find out why it's finishing early then. Ask yourself what you know about stopping dialog. Maybe the OnInitDialog is not working correctly. Maybe something in your code is stopping the dialog? Try a breakpoint in CDialog::EndDialog - it could tell you which bit of your code is killing the dialog. Same with OnClose... If you still can't find it, comment out 99% of the dialog code until it stays up. Then start putting code back again until it breaks. This is going to be a pain to track down, but none of it is rocket science. Just plod through your code until you find the offending line or two. Iain.

                        D 1 Reply Last reply
                        0
                        • I Iain Clarke Warrior Programmer

                          Well, your dialog is starting (which is good news), but it is also finishing too early. You need to find out why it's finishing early then. Ask yourself what you know about stopping dialog. Maybe the OnInitDialog is not working correctly. Maybe something in your code is stopping the dialog? Try a breakpoint in CDialog::EndDialog - it could tell you which bit of your code is killing the dialog. Same with OnClose... If you still can't find it, comment out 99% of the dialog code until it stays up. Then start putting code back again until it breaks. This is going to be a pain to track down, but none of it is rocket science. Just plod through your code until you find the offending line or two. Iain.

                          D Offline
                          D Offline
                          Dhiraj kumar Saini
                          wrote on last edited by
                          #16

                          Ok I will try it.

                          1 Reply Last reply
                          0
                          • D Dhiraj kumar Saini

                            Hi, I am working on an mfc application in which I am opening a dialog box containing smileys on button click. Now what I want is to close the dialog dialog box with smileys when mouse click event is fired anywhere on the screen. Thanks Dhiraj Kumar Saini

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

                            Dhiraj kumar Saini wrote:

                            ...when mouse click event is fired anywhere on the screen.

                            See SetCapture().

                            "Love people and use things, not love things and use people." - Unknown

                            "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                            D 1 Reply Last reply
                            0
                            • D David Crow

                              Dhiraj kumar Saini wrote:

                              ...when mouse click event is fired anywhere on the screen.

                              See SetCapture().

                              "Love people and use things, not love things and use people." - Unknown

                              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                              D Offline
                              D Offline
                              Dhiraj kumar Saini
                              wrote on last edited by
                              #18

                              Can you help me out with some tutorial for how to use SetCapture

                              D 1 Reply Last reply
                              0
                              • D Dhiraj kumar Saini

                                Can you help me out with some tutorial for how to use SetCapture

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

                                Dhiraj kumar Saini wrote:

                                Can you help me out with some tutorial for how to use SetCapture

                                Other than what is provided here?

                                "Love people and use things, not love things and use people." - Unknown

                                "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                                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