⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgdemo.cpp

📁 wince 6 dilag example based on vs2005
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            // Print property page, control ID, and message.
            wsprintf (szOut, TEXT ("%s \tid:%3d \t%s"),
                      szPages[HIWORD (wParam) - ID_BTNPAGE],
                      LOWORD (wParam), (LPTSTR)lParam);
    }
    i = SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_ADDSTRING, 0,
                            (LPARAM)(LPCTSTR)szOut);
    if (i != LB_ERR)
        SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_SETTOPINDEX, i,
                            (LPARAM)(LPCTSTR)szOut);
    return 0;
}
//----------------------------------------------------------------------
// DoDestroyMain - Process WM_DESTROY message for window.
//
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {
    PostQuitMessage (0);
    return 0;
}
//======================================================================
// Command handler routines
//----------------------------------------------------------------------
// DoMainCommandOpen - Process File Open command
//
LPARAM DoMainCommandOpen (HWND hWnd, WORD idItem, HWND hwndCtl,
                          WORD wNotifyCode) {
    OPENFILENAME of;
    TCHAR szFileName [MAX_PATH] = {0};
    const LPTSTR pszOpenFilter = TEXT ("All Documents (*.*)\0*.*\0\0");
    TCHAR szOut[128];
    INT rc;

    szFileName[0] = '\0';           // Initialize filename.
    memset (&of, 0, sizeof (of));   // Initialize File Open structure.

    of.lStructSize = sizeof (of);
    of.hwndOwner = hWnd;
    of.lpstrFile = szFileName;
    of.nMaxFile = dim(szFileName);
    of.lpstrFilter = pszOpenFilter;
    of.Flags = 0;

    rc = GetOpenFileName (&of);
    wsprintf (szOut,
              TEXT ("GetOpenFileName returned: %x, filename: %s"),
              rc, szFileName);
    SendMessage (hWnd, MYMSG_ADDLINE, -1, (LPARAM)szOut);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandSave - Process File Save command.
//
LPARAM DoMainCommandSave (HWND hWnd, WORD idItem, HWND hwndCtl,
                          WORD wNotifyCode) {
    OPENFILENAME of;
    TCHAR szFileName [MAX_PATH] = {0};
    const LPTSTR pszOpenFilter = TEXT ("All Documents (*.*)\0*.*\0\0");
    TCHAR szOut[128];
    INT rc;

    szFileName[0] = '\0';           // Initialize filename.
    memset (&of, 0, sizeof (of));   // Initialize File Open structure.
    of.lStructSize = sizeof (of);
    of.hwndOwner = hWnd;
    of.lpstrFile = szFileName;
    of.nMaxFile = dim(szFileName);
    of.lpstrFilter = pszOpenFilter;
    of.Flags = 0;
    rc = GetSaveFileName (&of);

    wsprintf (szOut,
              TEXT ("GetSaveFileName returned: %x, filename: %s"),
              rc, szFileName);
    SendMessage (hWnd, MYMSG_ADDLINE, -1, (LPARAM)szOut);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandColor - Process File Color command.
//
LPARAM DoMainCommandColor (HWND hWnd, WORD idItem, HWND hwndCtl,
                           WORD wNotifyCode) {
    CHOOSECOLOR cc;
    static COLORREF cr[16];
    TCHAR szOut[128];
    INT rc;

    // Initialize color structure.
    memset (&cc, 0, sizeof (cc));
    memset (&cr, 0, sizeof (cr));

    cc.lStructSize = sizeof (cc);
    cc.hwndOwner = hWnd;
    cc.hInstance = hInst;
    cc.rgbResult = RGB (0, 0, 0);
    cc.lpCustColors = cr;
    cc.Flags = CC_ANYCOLOR;

    rc = (lpfnChooseColor) (&cc);
    wsprintf (szOut, TEXT ("Choose Color returned: %x, color: %x"),
              rc, cc.rgbResult);
    SendMessage (hWnd, MYMSG_ADDLINE, -1, (LPARAM)szOut);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandPrint - Process File Print command.
//
LPARAM DoMainCommandPrint (HWND hWnd, WORD idItem, HWND hwndCtl,
                           WORD wNotifyCode) {
    TCHAR szOut[128];
    INT rc;
#ifndef WIN32_PLATFORM_PSPC
    PAGESETUPDLG psd;

    // Initialize print structure.
    memset (&psd, 0, sizeof (psd));
    psd.lStructSize = sizeof (psd);
    psd.hwndOwner = hWnd;

    rc = (lpfnPrintDlg) (&psd);
#else
    PRINTDLG pd;
    // Initialize print structure.
    memset (&pd, 0, sizeof (pd));

    pd.cbStruct = sizeof (pd);
    pd.hwndOwner = hWnd;
    pd.dwFlags = PD_SELECTALLPAGES;

    rc = (lpfnPrintDlg) (&pd);
#endif // ifndef WIN32_PLATFORM_PSPC
    wsprintf (szOut, TEXT ("PrintDlg returned: %x, : %x"),
              rc, GetLastError());
    SendMessage (hWnd, MYMSG_ADDLINE, -1, (LPARAM)szOut);
    return 0;
}
//----------------------------------------------------------------------
// PropSheetProc - Function called when Property sheet created
//
#if defined(WIN32_PLATFORM_PSPC) && (_WIN32_WCE >= 300)
int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam) {

    if (uMsg == PSCB_INITIALIZED) {
        // Get tab control.
        HWND hwndTabs = GetDlgItem (hwndDlg, 0x3020);
        DWORD dwStyle = GetWindowLong (hwndTabs, GWL_STYLE);
        SetWindowLong (hwndTabs, GWL_STYLE, dwStyle | TCS_BOTTOM);

    } else if (uMsg ==  PSCB_GETVERSION)
        return COMCTL32_VERSION;

   // Add a hyperlink line below the tabs.
   else if (uMsg ==  PSCB_GETLINKTEXT) {
       lstrcpy ((LPTSTR)lParam, TEXT ("Launch the calculator by ")
                TEXT("tapping <file:\\windows\\calc.exe{here}>."));
       return 0;
   }
    return 1;
}
#endif //defined(WIN32_PLATFORM_PSPC) && (_WIN32_WCE >= 300)
//----------------------------------------------------------------------
// DoMainCommandShowProp - Process show property sheet command.
//
LPARAM DoMainCommandShowProp(HWND hWnd, WORD idItem, HWND hwndCtl,
                             WORD wNotifyCode) {
    PROPSHEETPAGE psp[5];
    PROPSHEETHEADER psh;
    INT i;
    // Zero all the property page structures.
    memset (&psp, 0, sizeof (psp));
    // Fill in default values in property page structures.
    for (i = 0; i < dim(psp); i++) {
        psp[i].dwSize = sizeof (PROPSHEETPAGE);
        psp[i].dwFlags = PSP_DEFAULT;
        psp[i].hInstance = hInst;
        psp[i].lParam = (LPARAM)hWnd;
    }
    // Set the dialog box templates for each page.
    psp[0].pszTemplate = MAKEINTRESOURCE (ID_BTNPAGE);
    psp[1].pszTemplate = MAKEINTRESOURCE (ID_EDITPAGE);
    psp[2].pszTemplate = MAKEINTRESOURCE (ID_LISTPAGE);
    psp[3].pszTemplate = MAKEINTRESOURCE (ID_STATPAGE);
    psp[4].pszTemplate = MAKEINTRESOURCE (ID_SCROLLPAGE);

    // Set the dialog box procedures for each page.
    psp[0].pfnDlgProc = BtnDlgProc;
    psp[1].pfnDlgProc = EditDlgProc;
    psp[2].pfnDlgProc = ListDlgProc;
    psp[3].pfnDlgProc = StaticDlgProc;
    psp[4].pfnDlgProc = ScrollDlgProc;

    // Initialize property sheet structure.
    psh.dwSize = sizeof (PROPSHEETHEADER);
    psh.dwFlags = PSH_PROPSHEETPAGE;
    psh.hwndParent = hWnd;
    psh.hInstance = hInst;
    psh.pszCaption = TEXT ("Property Sheet Demo");
    psh.nPages = dim(psp);
    psh.nStartPage = 0;
    psh.ppsp = psp;
    // On Pocket PC, make property sheets full screen.
#if defined(WIN32_PLATFORM_PSPC) && (_WIN32_WCE >= 300)
    psh.pfnCallback = PropSheetProc;
    psh.dwFlags |= PSH_USECALLBACK | PSH_MAXIMIZE;
#else
    psh.pfnCallback = 0;
#endif //defined(WIN32_PLATFORM_PSPC) && (_WIN32_WCE >= 300)
    // Create and display property sheet.
    PropertySheet (&psh);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandModelessDlg - Process the File Modeless menu command.
//
LPARAM DoMainCommandModeless(HWND hWnd, WORD idItem, HWND hwndCtl,
                             WORD wNotifyCode) {

    // Create dialog box only if not already created.
    if (g_hwndMlDlg == 0)
        // Use CreateDialog to create modeless dialog box.
        g_hwndMlDlg = CreateDialog (hInst, TEXT ("Clearbox"), hWnd,
                                    ModelessDlgProc);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl,
                          WORD wNotifyCode) {
    SendMessage (hWnd, WM_CLOSE, 0, 0);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAbout - Process the Help About menu command.
//
LPARAM DoMainCommandAbout(HWND hWnd, WORD idItem, HWND hwndCtl,
                          WORD wNotifyCode) {
    // Use DialogBox to create modal dialog box.
    DialogBox (hInst, TEXT ("aboutbox"), hWnd, AboutDlgProc);
    return 0;
}
//======================================================================
// Modeless ClearList dialog box procedure
//
BOOL CALLBACK ModelessDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
                               LPARAM lParam) {
    switch (wMsg) {
        case WM_COMMAND:
            switch (LOWORD (wParam)) {
                case IDD_CLEAR:
                    // Send message to list box to clear it.
                    SendDlgItemMessage (GetWindow (hWnd, GW_OWNER),
                                        IDC_RPTLIST,
                                        LB_RESETCONTENT, 0, 0);
                    return TRUE;

                case IDOK:
                case IDCANCEL:
                    // Modeless dialog boxes can't use EndDialog.
                    DestroyWindow (hWnd);
                    g_hwndMlDlg = 0;  // 0 means dlg destroyed.
                    return TRUE;
            }
        break;
    }
    return FALSE;
}
//======================================================================
// About dialog box procedure
//
BOOL CALLBACK AboutDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam,
                            LPARAM lParam) {
    switch (wMsg) {
        case WM_COMMAND:
            switch (LOWORD (wParam)) {
                case IDOK:
                case IDCANCEL:
                    EndDialog (hWnd, 0);
                    return TRUE;
            }
        break;
    }
    return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -