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

📄 usernotify.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */


#include <aygshell.h>
#include "resource.h"
#include "usernotify.h"
#include "startsync.h"
#include "HwndFunctions.h"
#include "pim/maincpp.h"
#include "customization.h"

#include "base/Log.h"
#include "processUtils.h"

#define IDS_DEFAULTTITLE      TEXT("Synchronization in progress...")
#define IDS_DEFAULTHTMLMESSAGE   TEXT("<html><body>Do you really want to interrupt the synchronization? <br/></br><input type=button name='cmd:10' value='  Yes  '>&nbsp;&nbsp;&nbsp;<input type=button name='cmd:2' value='  No  '></body</html>")
// {CA777AF7-3CDE-4c15-A7CD-81F629ABA6B8}
static const GUID guidPPCAlertsApp = { 0xca777af7, 0x3cde, 0x4c15, { 0xa7, 0xcd, 0x81, 0xf6, 0x29, 0xab, 0xa6, 0xb8 } };

#if defined WIN32_PLATFORM_PSPC
    static SHNOTIFICATIONDATA pCurrentNotification = {0};
#else

	// NOTIFYICONDATA* pnid = NULL
    static NOTIFYICONDATA pnid = {0};
#endif

long CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

//extern "C" DWORD WINAPI createBubble(LPVOID lpv) {return 0;}
//void removeNotif() {}
//long CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {}

extern "C" DWORD WINAPI createBubble(LPVOID lpv) {

    HANDLE moduleHandle = 0;

    WNDCLASS wc;

    // Just to be safe, remove a lost icon.. (works on ppc only)
    removeNotif();

    LPCWSTR lpszClassName= L"funambolstartsync";
    moduleHandle = GetModuleHandle(0);
    MSG msg;

    // Init Wnd class
    wc.style=CS_HREDRAW | CS_VREDRAW ;
    wc.lpfnWndProc=WndProc;
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hInstance=(HINSTANCE)moduleHandle;
    wc.hIcon=0;
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName=NULL;
    wc.lpszClassName=lpszClassName;

    if(!RegisterClass(&wc)) return false;

    HWND hMainWindow = CreateWindow(
                                TEXT("funambolstartsync"),
                                NULL,
                                WS_BORDER,
                                0,0,
                                0,0,
                                NULL,
                                NULL,
                                (HINSTANCE)moduleHandle,
                                NULL);

    if(!hMainWindow)
        return FALSE;

    HICON   icon = NULL;
    icon = (HICON)LoadImage(
                      (HINSTANCE)moduleHandle,
                      MAKEINTRESOURCE(IDI_FUNAMBOLSTART_ICON),
                      IMAGE_ICON,
                      GetSystemMetrics(SM_CXSMICON),
                      GetSystemMetrics(SM_CYSMICON),
                      0
    );

#if defined WIN32_PLATFORM_PSPC

    pCurrentNotification.cbStruct = sizeof(pCurrentNotification);
    pCurrentNotification.dwID = 100;
    pCurrentNotification.npPriority = SHNP_INFORM;
    pCurrentNotification.hicon = icon; //LoadIcon((HINSTANCE)moduleHandle, MAKEINTRESOURCE(IDI_FUNAMBOLSTART_ICON));
    pCurrentNotification.clsid = guidPPCAlertsApp;
    pCurrentNotification.csDuration = 15;
    pCurrentNotification.hwndSink = hMainWindow;
    pCurrentNotification.pszHTML = IDS_DEFAULTHTMLMESSAGE;
    pCurrentNotification.pszTitle = IDS_DEFAULTTITLE;
    pCurrentNotification.grfFlags = SHNF_STRAIGHTTOTRAY | SHNF_SILENT;

#else

    pnid.cbSize = sizeof(pnid);
    pnid.uID = 100;      // Per WinCE SDK docs, values from 0 to 12 are reserved and should not be used.
    pnid.uFlags = NIF_ICON;
    pnid.hIcon = icon;
    pnid.hWnd = hMainWindow;

#endif


#if defined WIN32_PLATFORM_PSPC
	LRESULT res = 0;
    // ERROR_INVALID_PARAMETER = code 87
    res = SHNotificationAdd(&pCurrentNotification);

#else

	//Add the notification to the tray
	Shell_NotifyIcon(NIM_ADD, &pnid);
	//Shell_NotifyIcon(NIM_MODIFY, &pnid);
#endif

    while(GetMessage(&msg,NULL,NULL,NULL))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;

}


void removeNotif() {

#if defined WIN32_PLATFORM_PSPC
	SHNotificationRemove(&guidPPCAlertsApp, 100);
    // FIXME On some PocketPC, the icon is not removed at the first call
	SHNotificationRemove(&guidPPCAlertsApp, 100);
#else


    //remove the notification from the tray
    // if the removing action returns 0 it means it becomes from another process
    // try to remove looking at its handle

    if (pnid.uID != 100) {
        HWND wnd = NULL;
        wnd = ::FindWindow(TEXT("funambolstartsync"), NULL);
        if (wnd) {
            pnid.cbSize = sizeof(pnid);
            pnid.uID = 100;      // Per WinCE SDK docs, values from 0 to 12 are reserved and should not be used.
            pnid.uFlags = NIF_ICON;
            pnid.hWnd = wnd;
        }
    }

    Shell_NotifyIcon(NIM_DELETE, &pnid);

#endif
}

//
// It listens to the message event and processes the action to do
// return -6 if the user terminates the application
//
long CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    int ret = 0;
    switch(msg) {

        case WM_DESTROY:
        case WM_CLOSE:
        case WM_QUIT:
            //PostQuitMessage(0);
            return 0;

        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case 10:
                LOG.info("Sync stopped by the user");
                quit(-6);
                break;

                case 11:
                PostQuitMessage(0);
                break;
            }
        break;

        case WM_NOTIFY:
            if((int) wParam == 100 && ((NMHDR)((NMSHN*)lParam)->hdr).code == SHNN_SHOW)
            {
                // search for UI window handle, if it is not found then we start the UI
                HWND wnd = NULL;
                wnd = HwndFunctions::getWindowHandle();
                if(wnd == NULL){
                    startProgram(PROVIDER_W _T(".exe"),_T(""));
                };

                for(int i=0;i<3;i++){
                    wnd =HwndFunctions::getWindowHandle();
                    if(wnd != NULL)
                        break;
                };

                if(wnd != NULL)
                    SetForegroundWindow(wnd);
                return -1;
            } ;
           break;

        case WM_TIMER:

            break;
    }
    return DefWindowProc(hWnd,msg,wParam,lParam);
}


⌨️ 快捷键说明

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