CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1

    opposite to GotoDlgCtrl?

    how to get from dialog (or property page) it's focused control?
    (asking for GetFocus asks whole system, not concrete dialog)
    thanks

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: opposite to GotoDlgCtrl?

    Why would you like to know that ?

  3. #3

    Re: opposite to GotoDlgCtrl?

    i just want to save it and than return back - so is there is standard way to get actual state?

    (i have not standard problem with loosing alt-letter hotkeys functionality and seems gotodlgctrl (maybe setfocus) helps, seems to me stupid call gotonext and than previous)

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: opposite to GotoDlgCtrl?

    Can you be more specific?
    Do you need something inverse of NextDlgCtrl? Well, it is PrevDlgCtrl.

    Furthermore, what if your dialog loses focus when user press ALT comination (or use any other method to set focus on other windows)? It is responsibily of Windows (OS) to save the state of last active control within some Frame/Dialog window.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5

    Re: opposite to GotoDlgCtrl?

    more specific:
    function will return me focused control in dialog also when dialog is not "on top"
    (when click on button in dialog1 opens another dialog2 i want function asking for hDialog1 will return me id or hwnd of that button (because it was focused before d2 open and will be focused after d2 close))

  6. #6
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: opposite to GotoDlgCtrl?

    do u want like this.
    Code:
    CEdit* pBoxOne;
    pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT1);
    GotoDlgCtrl(pBoxOne);

  7. #7

    Re: opposite to GotoDlgCtrl?

    no

    if gotodlgctrl is set-function
    i'm searching get-function, it's parameter should be dialog handler

  8. #8

    Re: opposite to GotoDlgCtrl?

    maybe is unclear i'm searching get-only function?
    i want just find actual state, that will not change by this get-function call

    i do not want DM_GETDEFID, i want focused control (it is that you can set by gotodlgctrl)

  9. #9
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: opposite to GotoDlgCtrl?

    Quote Originally Posted by real name
    if gotodlgctrl is set-function
    i'm searching get-function
    Well - GotoDlgCtrl() is a way of setting the focus to a specific window (control in this case). The opposite is GetFocus(), it retrieves the window which currently has the focus.

    Quote Originally Posted by real name
    it's parameter should be dialog handler
    Handler? You probably mean handle. Anyway, since only one window on your system can have the focus at any given time, there's no need to pass a parameter.

  10. #10

    Re: opposite to GotoDlgCtrl?

    one case i afraid getfocus is not safe enough (f.e. should happen any unexpected messagebox will appear)
    next case (already bit out of my problem) how to ask dialog is not actualy "on top" what control will get focus (when child dialogs will close)

  11. #11
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: opposite to GotoDlgCtrl?

    Quote Originally Posted by real name
    one case i afraid getfocus is not safe enough (f.e. should happen any unexpected messagebox will appear)
    Not sure what you mean... How would you want an "unexpected message box" to appear? If it occurs in your own thread, your code wouldn't be in control anyway at that moment, so the GetFocus() call would never be made while the messagebox is displayed. And if it's from another thread or process it's not a problem anyway, since GetFocus() always gives you the focussed window of the calling thread.

    Besides that, you can always check via GetParent() whether the control having the focus belongs to your dialog or not.

  12. #12

    Re: opposite to GotoDlgCtrl?

    maybe we speaking the same?
    "Besides that, you can always check via GetParent() whether the control having the focus belongs to your dialog or not."
    what to do in case i will receive NULL? i understand getfocus will return != NULL just for one process and thread in system

    seems dialog must somehow remember what will make focused again

  13. #13
    Join Date
    Apr 2003
    Posts
    1,755

    Smile Re: opposite to GotoDlgCtrl?

    Try to capture the WM_ACTIVATE message and save the control id when when the dialog is deactivated
    Code:
    void CTESTDLGDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
    {
       //m_ActiveId is a class variable
       if (WA_INACTIVE != nState && m_ActiveId) {
          CString str;
          str.Format("ACTIVATE APP: Control id %d", m_ActiveId);
          SetWindowText(str);
       }
       else {
          CWnd *pWnd = GetFocus();
          if (pWnd && this == pWnd->GetParent()) {
             m_ActiveId = pWnd->GetDlgCtrlID();
             CString str;
             str.Format("DEACTIVATEAPP: Control id %d", m_ActiveId);
             SetWindowText(str);
          }
       }
    }
    Hope it will help you

  14. #14

    Re: opposite to GotoDlgCtrl?

    thanks for tips, seems i made no mistake and get-focus-dlg-ctrl(hdialog) does not exist

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured