No announcement yet.

OpenFileDialog Modal to application

  • Filter
  • Time
  • Show
Clear All
new posts

  • Semen Matusovski
    > I think my TOP_MOST will have to go bye bye ???
    If you want only.

    It's very easy to receive hWnd of OFN window (using local CBT_HOOK or OFN callback function) and to make it TOPMOST also
    This is a part of sample posted in Source code' forum
       #Compile Exe
       #Dim All
       #Register None
       #Include ""
       #Include ""
       Global ofn As OPENFILENAME
       Function GetFileNameProc (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
          Local rc1 As Rect, rc2 As Rect, hWnd1 As Long, hWnd2 As Long
          Select Case wMsg
             Case %WM_SIZE
                hWnd1 = GetParent(hWnd)
                ' Center
                hWnd2 = ofn.hWndOwner: If hWnd2 = 0 Then hWnd2 = GetDesktopWindow
                GetWindowRect hWnd1, rc1: GetWindowRect hWnd2, rc2
                SetWindowPos hWnd1, %HWND_TOPMOST, _
                   rc2.nLeft + ((rc2.nRight - rc2.nLeft) - (rc1.nRight - rc1.nLeft)) / 2, _
                   rc2.nTop + ((rc2.nBottom - rc2.nTop) - (rc1.nBottom - rc1.nTop)) / 2, _
                   0, 0, %SWP_NOSIZE
          End Select
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
       Function GetFileName(hWnd As Long) As String
          Static szCurDir1 As Asciiz * %MAX_PATH, szCurDir2 As Asciiz * %MAX_PATH
          Static szTitleName As Asciiz * %MAX_PATH, _
          szFilter As Asciiz * %MAX_PATH
          If ofn.lStructSize = 0 Then
             ofn.lStructSize = SizeOf(ofn)
             ofn.hWndOwner = hWnd
             szFilter = "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0) + _
                "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0)
             ofn.lpstrFilter = VarPtr(szFilter)
             ofn.lpstrFileTitle = VarPtr(szTitleName)
             ofn.nMaxFileTitle = SizeOf(szTitleName)
             ofn.lpfnHook = CodePtr(GetFileNameProc)
          End If
          GetCurrentDirectory SizeOf(szCurDir1), szCurDir1
          GetOpenFileName ofn
          GetCurrentDirectory SizeOf(szCurDir2), szCurDir2
          If Right$(szCurDir2, 1) <> "\" Then szCurDir2 = szCurDir2 + "\"
          If szTitleName = "" Then Function = "" Else Function = szCurDir2 + szTitleName
          SetCurrentDirectory szCurDir1
       End Function
       CallBack Function OkProc
          SetWindowText CbHndl, "Selected: " + GetFileName(GetDlgItem(CbHndl, 101))
       End Function
       Function PbMain
          Local hDlg As Long
          Dialog New %HWND_DESKTOP, "OFN", , , 400, 200, %WS_CAPTION Or %WS_SYSMENU, %WS_EX_TOPMOST To hDlg
          Control Add TextBox, hDlg, 101, "", 5, 10, 300, 180
          Control Add Button, hDlg, 102, "Open", 320, 10, 70, 15 Call OkProc
          Dialog Show Modal hDlg
       End Function
    E-MAIL: [email protected]

    [This message has been edited by Semen Matusovski (edited November 05, 2000).]

    Leave a comment:

  • Scott Turchin
    started a topic OpenFileDialog Modal to application

    OpenFileDialog Modal to application

    If I am using the TOP_MOST on my dialog box:

    SetWindowPos hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE

    And I want to do an OpenFileDialog from there...
    How do I tell the OpenFileDialog to be Modal to MY app...

    Ie it needs to be in the foreground but it ends up behind the topmost window...

    Didn't we have this discussion a while back?
    I think my TOP_MOST will have to go bye bye ???


    mailto:[email protected][email protected]</A>