views:

18

answers:

1

I'm trying to use a template with GetOpenFileName without success. I've found very little on this topic in the MSDN or on the web. I've based my attempt on what I saw here

http://visual-c.itags.org/visual-c-c++/77687/

My code follows. The TEMPLATE comments show where I made changes to code b4 the template attempt; mainly to remove certain lines. The normal Windows explorer type open windows is displayed but without the additions I wish to make with the template. I'm not at all sure what should be in the hook function but I know it does not get called since I set a break point there.

// Global variable

OPENFILENAME    IFN;

// In WndProc

    case WM_CREATE:
        IFN.hInstance = ((LPCREATESTRUCT)lParam)->hInstance;    // TEMPLATE
        IFN.hwndOwner = hWnd;               // TEMPLATE
        break;

// In WndProc menu processing

    case IDM_INPUT_FILE:
    {
//      OPENFILENAME    IFN;                        // TEMPLATE
        strcpy (szFile,"NEWEXPORT.GED");
        IFN.lStructSize     = sizeof(IFN);
//      IFN.hwndOwner       = hWnd;                 // TEMPLATE
//      IFN.hInstance       = NULL;                 // TEMPLATE
        IFN.lpstrFilter     = "All\0*.*\0GEDCOM\0*.GED\0";
        IFN.nFilterIndex    = 2;
        IFN.lpstrCustomFilter   = NULL;
        IFN.lpstrFile       = szFile;
        IFN.nMaxFile        = 510;
        IFN.lpstrFileTitle  = NULL;
        IFN.lpstrInitialDir = NULL;
        IFN.lpstrTitle      = NULL;
        IFN.Flags       = OFN_FILEMUSTEXIST || OFN_PATHMUSTEXIST || OFN_EXPLORER || OFN_ENABLETEMPLATE || OFN_ENABLEHOOK ; // TEMPLATE
        IFN.lpstrDefExt     = NULL;
        IFN.lpfnHook        = FileAddOn;                // TEMPLATE NULL;
        IFN.lpTemplateName  = MAKEINTRESOURCE(IDD_FILEADDON);   // TEMPLATE

        if (!GetOpenFileName(&IFN))
        {
            Beep (1000,500);
            break;
        }

// **************** Hook function

UINT_PTR CALLBACK FileAddOn (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
                return TRUE;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
            {
                EndDialog(hDlg, LOWORD(wParam));
                return TRUE;
            }
            break;
    }
    return TRUE;
}

// IDD_FILEADDON was made with the visual C dialog editor and has the following properties
// Style=Child, Border=none,clip siblings,3D look
A: 

You must OR the OPENFILENAME flags with |, not ||

Anders
OMG! At least now there's an example here. Thanks.
Mike D
Any idea why the desktop, network, etc. buttons don't appear?
Mike D
#define _WIN32_WINNT 0x0500 before you include the windows headers (And it is called the places bar)
Anders
@anders: no joy on that. maybe it's because I'm using and old sdk or have an old visual c but this article implies you can't have the places bar and a hook procedure. http://msdn.microsoft.com/en-us/magazine/cc301399.aspx
Mike D
@anders: Ok, got it! moving the define immediately b4 windows.h did the trick. This adds some more fields to the openfilename structure including the FlagsEx.
Mike D