Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Window Position (Word 97SR2)

    I think we've been here before, but maybe not.

    I use the SHBrowseForFolder API function to display a "pick a folder" dialog. The problem is the dialog opens at a screen position relative to OPUSApp (the classname for Word) instead of relative to the userform with focus when the SHBrowseForFolder function is called. That's my best guess anyway.

    In other words, I want the dialog centered on the screen not positioned in the upper left corner. How can I do this?

    My approach has been to get the handle for the userform, set the focus to that then call the SHBrowseForFolder function. Nothing's coming together...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Window Position (Word 97SR2)

    Hi Kevin,
    Something like:
    <pre>Private Type BrowseInfo
    hWndOwner As Long
    pIDLRoot As Long
    pszDisplayName As Long
    lpszTitle As Long
    ulFlags As Long
    lpfnCallback As Long
    lParam As Long
    iImage As Long
    End Type
    Const BIF_RETURNONLYFSDIRS = 1
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
    (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Dim lpIDList As Long, udtBI As BrowseInfo

    With udtBI
    .hWndOwner = GetForegroundWindow()
    .lpszTitle = lstrcat("C:", "")
    .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    lpIDList = SHBrowseForFolder(udtBI)
    </pre>

    should help - it's still not exactly centred but better! I guess you could also do something with SetWindowPos?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Window Position (Word 97SR2)

    Rory,

    (Happy Birthday, Mr. Elvis)

    I finally got around to trying this code. It works! And the Browse window opens exactly centered!

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>
    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>


    As Gary would say "You're a gem"

    I wasn't setting the .hWndOwner flag of the BrowseInfo structure, which works with GetActiveWindow as well.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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