Set the ChildDialog Window Focus when i go to another application and come here
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: Set the ChildDialog Window Focus when i go to another application and come here

  1. #1
    Join Date
    Jun 2017
    Posts
    7

    Post Set the ChildDialog Window Focus when i go to another application and come here

    Hi Team,

    please help me on how to set the focus for the Child Dialog Window
    I have CDialog. In this i have couple of Tool bar [ File, Edit, Options, Tool,help]

    Out of all these option,I clicked on Tool->Display panel.

    Now Display Panel small Dialog pops-up.In this window there are static controls are available.

    (Reset,Draw buttons). when I hover the cursor on the Reset button "Tool-tip" should display.It's happening.

    In the "Display panel" dialog i have written the code SetActiveWindow function to activate the dialog. Now if i minimize and maximize the window,

    the main Dialog is visible.But the "Display Panel" is hidden. This is where i am facing the problem. In this case, SetActiveWindow function is applied to the parent window.But i need to set child window as active window.



    Regards,

    Senthil

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,957

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    ...
    Out of all these option,I clicked on Tool->Display panel.

    Now Display Panel small Dialog pops-up.
    ...
    In the "Display panel" dialog i have written the code SetActiveWindow function to activate the dialog.
    Does it mean that "Display panel" dialog is a modless one?
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2017
    Posts
    7

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Thank you for your reply Victor . I am not sure what is model and modeless Dialog.Anyway by referring this site http://www.codersource.net/2010/01/3...-boxes-in-mfc/ I got to know that "The difference between a modal and modeless dialog box is that, modal dialogs once invoked will not allow the users to access the parent window, where as modeless dialogs will allow the user to work with the parent window. "

    My Application is Model Dialog since Parent window(Display panel) will not be able to access when child window is open.

    I found out the example code in this site [http://www.codersource.net/2010/01/3...-boxes-in-mfc/] which is exactly I am looking to explain you.
    In this application , in the children lets assume I have included the tooltip for the button(Cancel). It is working.
    But when i click on another application and come this application Focus is not on the child window of the application. I need to set the focus on the child window and when i move the cursor over the button, Tooltip should display. I tried to set the focus to child window.But it is focusing the parent window.

    Regards,
    Senthil

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,957

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    Thank you for your reply Victor . I am not sure what is model and modeless Dialog.Anyway by referring this site http://www.codersource.net/2010/01/3...-boxes-in-mfc/ I got to know that "The difference between a modal and modeless dialog box is that, modal dialogs once invoked will not allow the users to access the parent window, where as modeless dialogs will allow the user to work with the parent window. " ...
    OK, let's try it from the "other side": please, show us the code you are using to spawn this "Display Panel" dialog.
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2017
    Posts
    7

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by VictorN View Post
    OK, let's try it from the "other side": please, show us the code you are using to spawn this "Display Panel" dialog.
    I guess i could not share the code of "Display Panel" dialog with you. But you can get the application from the following link.In this Link you can download the application and try to set the focus on the child window. [For instance Cancel button]
    https://cboard.cprogramming.com/cplu...-come-mfc.html

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,957

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    I guess i could not share the code of "Display Panel" dialog with you. ...
    But I didn't ask you to "share the code of "Display Panel" dialog", just only the code used to spawn this dialog!
    Hint: are you using CDialog::DoModal or CDialog::Create?
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2017
    Posts
    7

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by VictorN View Post
    But I didn't ask you to "share the code of "Display Panel" dialog", just only the code used to spawn this dialog!
    Hint: are you using CDialog::DoModal or CDialog::Create?

    Neither we are using CDialog:oModal nor CDialog::Create.
    If I am not wrong , "Code of Display Panel to spawn this dialog" may be in OnInitDialog

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,957

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    Neither we are using CDialog:oModal nor CDialog::Create.
    If I am not wrong , "Code of Display Panel to spawn this dialog" may be in OnInitDialog
    Victor Nijegorodov

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,559

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    I guess i could not share the code of "Display Panel" dialog with you. But you can get the application from the following link.In this Link you can download the application and try to set the focus on the child window. [For instance Cancel button]
    https://cboard.cprogramming.com/cplu...-come-mfc.html
    If you want to have someone look at the code, please zip it up and attach it directly. We're willing to help, but most folks here are not willing take the risk of going to an unknown site for a download.

    At any rate, Victor has asked you for the specific code that creates the dialog.

    Can you take the time to post that bit of code here?
    Last edited by Arjay; July 4th, 2017 at 04:05 AM.

  10. #10
    Join Date
    Jun 2017
    Posts
    7

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by Arjay View Post
    If you want to have someone look at the code, please zip it up and attach it directly. We're willing to help, but most folks here are willing take the risk of going to an unknown site for a download.

    At any rate, Victor has asked you for the specific code that creates the dialog.

    Can't you take the time to post that bit of code here?
    Thank you for your time Victor /Arjay/Everyone
    I Understand everyone is trying to help me here and I am not sure which part of code i need to share.
    I am sorry that i could not able to provide the information.

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,559

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    Thank you for your time Victor /Arjay/Everyone
    I Understand everyone is trying to help me here and I am not sure which part of code i need to share.
    I am sorry that i could not able to provide the information.
    We are asking for the code snippet that displays the dialog. If you have written the code, this should be very easy to provide

  12. #12
    Join Date
    Jun 2017
    Posts
    7

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    I understand your concern and try to give the code.

    I have tried the below things. But not able to set the Focus on the Dialog
    Written this code in the Child Window(Display panel) as per the above conversation. Its get notified whenever the Dialog is activate/Inactivated/WA_CLICKACTIVE.
    Here,I am not sure how to set the focus on my Dialog(Display panel) when the user goes to another app and come to this application.

    one more point is in the Parent window , the below notification code is written



    void parentApp::OnActiveApp(Bool bActive, DWORD hTask) {
    if(bActive)
    if(GetLastActivePopUp !=this)
    {
    BringWindowTop();
    }
    } // This function is getting callled whenver I go to another app and come to the application


    void XYZ::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
    {
    case WA_INACTIVE:
    pWndOther = GetDlgItem(IDC_DISPLAY_UNIT);
    pWndOther->SetFocus();
    case WA_INACTIVE:

    case WA_CLICKACTIVE:
    SetWindowText("This window has been activated using the mouse!!!");


    }
    void XYZ::OnSetFocus(CWnd* pOldWnd) {
    if (pOldWnd != NULL)
    {
    GetDlgItem(IDC_DISPLAY_UNIT)->SetFocus();
    }
    }
    Included the Notifications in the message maps
    ON_WM_ACTIVATE()
    ON_WM_SETFOCUS()
    ON_WM_KILLFOCUS()

    As I am new to MFC, please forgive if anything i have written mistakenly


    Thank you,
    Senthil
    Last edited by SAP_7; July 6th, 2017 at 09:35 AM. Reason: Included the Content

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,957

    Re: Set the ChildDialog Window Focus when i go to another application and come here

    Quote Originally Posted by SAP_7 View Post
    Code:
    
      void parentApp::OnActiveApp(Bool bActive, DWORD hTask)  {
         if(bActive)
          if(GetLastActivePopUp !=this)
          {
                BringWindowTop(); 
          }
    }   // This function is getting callled whenver I go to another app and come to the application
    
    What is BringWindowTop function?

    Quote Originally Posted by SAP_7 View Post
    Code:
    void XYZ::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
    {
                case WA_INACTIVE:
    					pWndOther = GetDlgItem(IDC_DISPLAY_UNIT);
    					pWndOther->SetFocus();
                case WA_INACTIVE:
    						
    			case WA_CLICKACTIVE:
    					SetWindowText("This window has been activated using the mouse!!!");
    
    			
     }
    Does this code compile?

    Quote Originally Posted by SAP_7 View Post
    Code:
    void XYZ::OnSetFocus(CWnd* pOldWnd) {
    	if (pOldWnd != NULL)
    	{
    		GetDlgItem(IDC_DISPLAY_UNIT)->SetFocus();
    	}
    }
    if your code does compile - then did you try to debug it?

    Besides, you didn't show the line of your code to spawn this "Display panel" dialog window yet. Why????
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)