Thread: center the GetOpenFileName

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310

    Lightbulb center the GetOpenFileName

    I'm in XP machine and I'm trying to center, by hook, the Open file dialog....
    Ok... It's suppose to be like this one:
    http://msdn.microsoft.com/library/en...opendialog.gif
    but, the result is the one that comes with Win98
    Here's my short version of my code:
    Code:
    UINT APIENTRY OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg)
        {
            case WM_INITDIALOG:
                {
                    RECT r;
                    int w, h, x, y;
                    GetWindowRect(GetParent(hWnd), &r);
                    w = r.right - r.left;
                    h = r.bottom - r.top;
                    GetWindowRect(GetDesktopWindow(), &r); 
                    MoveWindow(GetParent(hWnd), (r.right-w)/2,(r.bottom-h)/2, w, h, TRUE);
                    return TRUE;
                }
            default:
                {
                    break;
                }
        }
        return FALSE;
    }
    
    // loading the struct
    OPENFILENAME ofn;
    
    ZeroMemory(&ofn, sizeof(OPENFILENAME)); 
    
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = hWndParent;
    ofn.nFilterIndex = iIndex;
    ofn.lpstrFile = lpbuffer;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrFilter = "(*.*)\0*.*\0\0";
    ofn.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_ENABLEHOOK|OFN_EXPLORER|OFN_ENABLEHOOK;
    ofn.lpfnHook = OFNHookProc;
    GetOpenFileName(&ofn);
    Any ideas?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by MSDN
    For compatibility reasons, the Places Bar is hidden if Flags is set to OFN_ENABLEHOOK and lStructSize is OPENFILENAME_SIZE_VERSION_400.
    You could try adding this line above your #includes:
    Code:
    #define _WIN32_WINNT 0x0500
    This tells the compiler to use the newer structure size but will also make your program break on platforms earlier than Windows 2000.

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    @anonytmouse: Good spot :up: Although, still doesn't work

  4. #4
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    Originally Posted by MSDN
    For compatibility reasons, the Places Bar is hidden if Flags is set to OFN_ENABLEHOOK and lStructSize is OPENFILENAME_SIZE_VERSION_400.
    it seems that if you are wanting to hook the dialog (by setting the OFN_ENABLEHOOK flag). Then it's not possible for that 'places bar' to show up. I've made many attempts to try and overcome this but it seems it's not that easy to do.

    There are a couple of ways which I can think of which would make it possible to center the dialog without hooking it, but they are very 'hackerish' and not advised. One would be to create a tiny dialog with the popup style, center that, then set that window as the parent... The other would be to create a thread which would use FindWindowEx() to retrieve the dialog's HWND, then use SetWindowPos(). As you can see, these are awfull suggestions..


    -r1ck0r

  5. #5
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Yeah, I though that also but... no luck at the moment
    Anyway... I stuck on this, now :/
    I'm poping the Folder dialog:
    Code:
    int CALLBACK BrowseCallbackProc(HWND hwnd, UINT msg, LPARAM lParam, LPARAM lpData)
    {
    	switch (msg)
    	{
    	case BFFM_INITIALIZED:
    		{
    			break;
    		}
    	case BFFM_SELCHANGED:
            {
                break;
            }
    	default:
            {
                break;
            }
    	}
    	return 0;
    }
    
    bi.lpfn = BrowseCallbackProc;
    bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT|BIF_EDITBOX;
    Is it possible:
    1.- Put the absolute path of the chosen folder in the edit box?
    2.- If the user put another folder on the edit box, return that folder?

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetOpenFileName not working...
    By manugarciac in forum Windows Programming
    Replies: 6
    Last Post: 04-24-2007, 10:50 PM
  2. GetOpenFileName function for dir's?
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 04-15-2006, 12:54 AM
  3. Stopwatch program (need help!)
    By modnar in forum C Programming
    Replies: 9
    Last Post: 03-22-2004, 12:42 AM
  4. Troubles with GetOpenFileName()
    By lyx in forum Windows Programming
    Replies: 13
    Last Post: 10-28-2003, 09:47 PM
  5. GetOpenFileName() won't show
    By harryP in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2003, 04:47 PM