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

📄 notedemo.cpp

📁 《Windows CE 6.0开发者参考》(《Programming Windows Embedded CE 6.0 Developer Reference》)第四版书中的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//======================================================================
// NoteDemo - Demonstrates the Windows CE Notification API
//
// Written for the book Programming Windows CE
// Copyright (C) 2007 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include <notify.h>                  // For notification defines
#include "NoteDemo.h"                // Program-specific stuff

//----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("NoteDemo");
HINSTANCE hInst;                     // Program instance handle
HWND g_hMain;

CE_USER_NOTIFICATION g_ceun;         // User notification structure
TCHAR szDlgTitle[] = TEXT ("Notification Demo");
TCHAR szDlgText[] = TEXT ("Times Up!");
TCHAR szSound[MAX_PATH] = TEXT ("alarm1.wav");

// Used for timer event notification
TCHAR szEventName[] = TEXT ("Bob");
                       
HANDLE g_hNoteEvent = 0; 
BOOL g_fContinue = TRUE;

// Message dispatch table for MainWindowProc
const struct decodeUINT MainMessages[] = {
    WM_INITDIALOG, DoInitDialogMain,
    WM_COMMAND, DoCommandMain,
    MYMSG_TELLNOTIFY, DoTellNotifyMain,
};
// Command Message dispatch for MainWindowProc
const struct decodeCMD MainCommandItems[] = {
    IDOK, DoMainCommandExit,
    IDCANCEL, DoMainCommandExit,
    IDD_ADDUSERNOT, DoMainCommandAddUserNotification,
    IDD_CFGUSERNOT, DoMainCommandConfigUserNotification,
    IDD_ADDSYSNOT, DoMainCommandAddSysNotification, 
    IDD_ADDTIMENOT, DoMainCommandAddTimerNotification, 
    IDD_CLEARNOT, DoMainCommandClearNotifications, 
};
// Used by Set System Notification dialog
const struct decodeBtn SysTypeBtns[] = {
    IDC_SYNC_END	 , NOTIFICATION_EVENT_SYNC_END,
    IDC_DEVICE_CHANGE, NOTIFICATION_EVENT_DEVICE_CHANGE,
    IDC_SERIAL_DETECT, NOTIFICATION_EVENT_RS232_DETECTED,
    IDC_TIME_CHANGE  , NOTIFICATION_EVENT_TIME_CHANGE,
    IDC_RESTORE_END  , NOTIFICATION_EVENT_RESTORE_END,
    IDC_POWER_UP     , NOTIFICATION_EVENT_WAKEUP,
    IDC_TZ_CHANGE    , NOTIFICATION_EVENT_TZ_CHANGE,
    IDC_NAME_CHANGE  , NOTIFICATION_EVENT_MACHINE_NAME_CHANGE,
    IDC_RNDIS_CHANGE , NOTIFICATION_EVENT_RNDIS_FN_DETECTED,
    IDC_PROXY_CHANGE , NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE,
};

//======================================================================
// Program entry point
// 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPWSTR lpCmdLine, int nCmdShow) {
    INT i;
    TCHAR szText[MAX_PATH];
    WCHAR *pPtr;
    HANDLE hNotify;
    HWND hWnd;
    HANDLE hThread;

    hInst = hInstance;

    if (*lpCmdLine) {
        pPtr = lpCmdLine;
        // Parse the first word of the command line.
        for (i = 0; (i < dim(szText)-1) && (*pPtr > TEXT (' ')); i++)
            szText[i] = *pPtr++;
        szText[i] = TEXT ('\0');

        // Check to see if app started due to notification.
        if (lstrcmp (szText, APP_RUN_TO_HANDLE_NOTIFICATION) == 0) {
            // Acknowledge the notification.
            GetModuleFileName (hInst, szText, sizeof (szText));
            CeHandleAppNotifications (szText);

            // Get handle of command line.
            hNotify = (HANDLE)_wtol (pPtr);

            // Look to see if another instance of the app is running.
            hWnd = FindWindow (NULL, szAppName);
            if (hWnd) {
                SendMessage (hWnd, MYMSG_TELLNOTIFY, 0, 
                             (LPARAM)hNotify);
                // I should terminate this app here, but I don抰 so you
                // can see what happens.
                return 0;
            }
        } 
    }
    // Do a little initialization of CE_USER_NOTIFICATION.
    memset (&g_ceun, 0, sizeof (g_ceun));
    g_ceun.ActionFlags = PUN_DIALOG;
    g_ceun.pwszDialogTitle = szDlgTitle;
    g_ceun.pwszDialogText = szDlgText;
    g_ceun.pwszSound = szSound;
    g_ceun.nMaxSound = sizeof (szSound);

    // Create secondary thread for timer event notification.
    g_hNoteEvent = CreateEvent (NULL, FALSE, FALSE, szEventName);
    hThread = CreateThread (NULL, 0, MonitorThread, hWnd, 0, (DWORD *)&i);
    if (hThread == 0)
        return -1;

    // Display dialog box as main window.
    DialogBoxParam (hInstance, szAppName, NULL, MainDlgProc, 
                    (LPARAM)lpCmdLine);
    // Signal notification thread to terminate
    g_fContinue = FALSE;
    SetEvent (g_hNoteEvent);
    WaitForSingleObject (hThread, 1000);
    CloseHandle (hThread);
    CloseHandle (g_hNoteEvent);
    return 0;

}
//======================================================================
// Message handling procedures for main window
//----------------------------------------------------------------------
// MainDlgProc - Callback function for application window
//
BOOL CALLBACK MainDlgProc (HWND hWnd, UINT wMsg, WPARAM wParam, 
                           LPARAM lParam) {
    INT i;
    //
    // Search message list to see if we need to handle this
    // message. If in list, call procedure.
    //
    for (i = 0; i < dim(MainMessages); i++) {
        if (wMsg == MainMessages[i].Code)
            return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
    }
    return FALSE;
}
//----------------------------------------------------------------------
// DoInitDialogMain - Process WM_INITDIALOG message for window.
//
BOOL DoInitDialogMain (HWND hWnd, UINT wMsg, WPARAM wParam,
                       LPARAM lParam) {

    g_hMain = hWnd;
    if (*(LPTSTR)lParam)
        Add2List (hWnd, (LPTSTR)lParam);
    return FALSE;
}
//----------------------------------------------------------------------
// DoCommandMain - Process WM_COMMAND message for window.
//
BOOL DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam){
    WORD idItem, wNotifyCode;
    HWND hwndCtl;
    INT  i;

    // Parse the parameters.
    idItem = (WORD) LOWORD (wParam);
    wNotifyCode = (WORD) HIWORD (wParam);
    hwndCtl = (HWND) lParam;

    // Call routine to handle control message.
    for (i = 0; i < dim(MainCommandItems); i++) {
        if (idItem == MainCommandItems[i].Code) {
            (*MainCommandItems[i].Fxn)(hWnd, idItem, hwndCtl, 
                                       wNotifyCode);
            return TRUE;
        }
    }
    return FALSE;
}
//----------------------------------------------------------------------
// DoTellNotifyMain - Process MYMSG_TELLNOTIFY message for window.
//
BOOL DoTellNotifyMain (HWND hWnd, UINT wMsg, WPARAM wParam, 
                       LPARAM lParam) {
    Add2List (hWnd, TEXT ("Notification %x reported"), lParam);
    SetForegroundWindow ((HWND)((DWORD)hWnd | 0x01));
    return 0;
}
//======================================================================
// Command handler routines
//----------------------------------------------------------------------
// DoMainCommandExit - Process Program Exit command.
//
LPARAM DoMainCommandExit (HWND hWnd, WORD idItem, HWND hwndCtl, 
                          WORD wNotifyCode) {
    EndDialog (hWnd, 0);
    return 0;
}
//----------------------------------------------------------------------
// DoMainCommandAddUserNotification - Process Add User Notify button.
//
LPARAM DoMainCommandAddUserNotification (HWND hWnd, WORD idItem, 
                                         HWND hwndCtl, WORD wNotifyCode) {
    SYSTEMTIME st, ste;
    TCHAR szExeName[MAX_PATH], szText[128];
    TCHAR szArgs[128] = TEXT("This is my user notification string.");
    CE_NOTIFICATION_TRIGGER nt;
    HANDLE hNotify;

    // Initialize time structure with local time.
    GetLocalTime (&st);
    // Do a trivial amount of error checking.
    st.wMinute++;
    if (st.wMinute > 59) {
        st.wHour++;
        st.wMinute -= 60;
    }

    // Set end time 10 minutes past start.
    ste = st;
    // Do a trivial amount of error checking.
    ste.wMinute += 10;
    if (ste.wMinute > 59) {
        ste.wHour++;
        ste.wMinute -= 60;

⌨️ 快捷键说明

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