none
How to get window handle of FileDialog RRS feed

  • Question

  • Hi,

    May I know is there a way to get the Window Handle of OpenFileDialog or SaveFileDialog.

    Looks like FileDialog stores window handle in a private member "dialogHwd".. But seems no public member or property to get the window handle.

    Thanks

    Suneel

    Wednesday, November 16, 2016 1:14 PM

Answers

  • For explorer style file dialogs you can provide a dialog function to OpenFileName or SaveFileName, then call GetParent when u get WM_INITDIALOG (the dialog procedure is actually used for a child dialog), or for a Vista style dialog, query for IOleWindow.



    Visual C++ MVP

    • Proposed as answer by Kristin Xie Monday, November 21, 2016 8:02 AM
    • Marked as answer by thisissuneel Wednesday, December 7, 2016 7:13 PM
    Wednesday, November 16, 2016 1:52 PM

All replies

  • For explorer style file dialogs you can provide a dialog function to OpenFileName or SaveFileName, then call GetParent when u get WM_INITDIALOG (the dialog procedure is actually used for a child dialog), or for a Vista style dialog, query for IOleWindow.



    Visual C++ MVP

    • Proposed as answer by Kristin Xie Monday, November 21, 2016 8:02 AM
    • Marked as answer by thisissuneel Wednesday, December 7, 2016 7:13 PM
    Wednesday, November 16, 2016 1:52 PM
  • Hi Suneel,

    Actually,  OpenFileDialog Class has no these properties to help you get Window handle in .Net Framework. You may use some Win32 API from C++.

    Here is a detailed description from Seva Alekseyev 

    If the dialog is in your application, you typically don't need FindWindow() to know its HWND. First off, the window procedure of the dialog receives the HWND on every callback. If the dialog is non-modal, the CreateDialog() function returns the HWND. If the dialog is modal, then all activity outside of its window procedure is frozen out anyway (save for other threads), so the HWND may only be needed down the call stack from the window proc. If you have to, you may cache the HWND in a global/static variable in the WM_INITDIALOG handler. But make sure to clear (reset to 0) the variable in the WM_DESTROY handler, since the HWND won't be valid anymore.

    Here are some references that I referred from.

    how to get a window handle (HWND)?

    How to get handler(HWND) for dialog box 

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Kristin Xie Monday, November 21, 2016 8:02 AM
    Thursday, November 17, 2016 8:09 AM
  • Hi Suneel,

    What's the problem now? Do you have any updates? If yes, please post here. If no, please remember to close this thread by marking helpful reply as an answer, It also could be beneficial to other community members who meet the same issue. Thanks for your understanding and cooperation.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 25, 2016 7:46 AM