Share via


How to Call a System-defined Dialog Box

4/19/2010

The following code sample shows how to call the common dialog boxes on Windows Mobile Professional and Windows Mobile Classic.

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
    LRESULT   lResult = TRUE;
    TCHAR   szFile[MAX_PATH] = TEXT("\0");
    OPENFILENAME   ofn;
    
    memset( &(ofn), 0, sizeof(ofn));
    ofn.lStructSize   = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFile;
    ofn.nMaxFile = MAX_PATH;

    switch(msg)
    {
    case WM_COMMAND:
    switch (GET_WM_COMMAND_ID(wp, lp))
    {
    case IDM_OPENPRJ:
        ofn.lpstrTitle = TEXT("Open Folder");
        // Open project dialog for Windows Mobile.
        ofn.Flags = OFN_PROJECT;
        if (GetOpenFileName(&ofn)) {
           MessageBox(NULL, ofn.lpstrFile, TEXT("Info"), MB_OK);
        }
        // Add the opening project code here.
        break;

    case IDM_OPENFILE:
        ofn.lpstrFilter = TEXT("All (*.*)\0*.*\0");   
        ofn.lpstrTitle = TEXT("Open File");
        ofn.Flags = OFN_EXPLORER;
        if (GetOpenFileName(&ofn))
            MessageBox(NULL, ofn.lpstrFile, TEXT("Info"), MB_OK);
        // Add the opening file code here.
        break;

    case IDM_SAVEFILE:
        ofn.lpstrFilter = TEXT("Text (*.txt)\0*.txt\0");   
        ofn.lpstrTitle = TEXT("Save File As");
        ofn.Flags = OFN_HIDEREADONLY; 
        ofn.lpstrDefExt = TEXT("txt");
        if (GetSaveFileName(&ofn))   
            MessageBox(NULL, ofn.lpstrFile, TEXT("Info"), MB_OK);
        // Add saving file code here.
        break;

    case IDM_PROPERTY:
        // Use GetOpenFileName to choose a file, and then use 
        // GetSaveFileName to display its properties.
        ofn.lpstrFilter = TEXT("All (*.*)\0*.*\0");
        ofn.lpstrTitle = TEXT("File Property");
        ofn.Flags = OFN_EXPLORER;
        if (GetOpenFileName(&ofn)) {
            ofn.lpstrTitle = TEXT("Property");
            // Open property dialog for Windows Mobile
            ofn.Flags = OFN_PROPERTY;
            GetSaveFileName(&ofn);
        }
        break;

    default:
        return DefWindowProc(hwnd, msg, wp, lp);
    }
    break; 

See Also

Tasks

How to Enable System-defined File Dialog Boxes
How to Prevent Display of Smart Minimize and OK Buttons in Dialog Boxes

Other Resources

Designing Full-Screen Dialog Boxes