天天看點

在Windows Mobile 中最小化,顯示圖示再工作列上

最近寫了一個小程式,當使用者點選最小化按鈕的時候,在工作列上顯示一個小圖示。類似MSN Mobile。開始的時候看了好多實作。最終還是看了MSN,找到了結果。 下面是我的實作代碼,其實很簡單的。在MFC中實際上隻需響應一個函數,然後把下面的代碼拷貝過去就可以了。 SHNOTIFICATIONDATA sn = {0}; sn.cbStruct = sizeof(sn); sn.dwID = 1; //SHNP_ICONIC sn.npPriority = SHNP_ICONIC; sn.csDuration = 5; sn.hicon = LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_MESSAGE)); sn.clsid = CLSID_SHNAPI_ICON; sn.grfFlags = 0; sn.pszTitle = TEXT("LearnerAgent"); sn.pszHTML = TEXT(""); sn.rgskn[0].pszTitle = TEXT("Dismiss"); sn.rgskn[0].skc.wpCmd = 100; sn.pszTodaySK = TEXT("!BC"); sn.pszHTML = TEXT("

The main window was minilized. minilized .

"); sn.npPriority = SHNP_INFORM; SHNotificationUpdate(SHNUM_PRIORITY, &sn); SHNotificationUpdate(SHNUM_HTML,&sn); SHNotificationAdd(&sn);

上一篇文章中提到了如何在Windows mobile中顯示一個Notification。但是,由一個問題,就是如何處理在Notification中按鈕的響應事件問題。

我想再使用者點選按鈕的時候做相應的操作:這樣的話就需要再設定SHNOTIFICATIONDATA 的hwndSink屬性。

sn.hwndSink = this->m_hWnd;

然後再MFC類中的OnCommand方法中根據HTML button cmd值進行消息處理。

<html><body><form method=/"POST/" action=><p>The main window was minilized.Click <font color=/"#0000FF/"><b>Show Window</b></font> to display the main window. </p><p align=right><input type=button name='cmd:20 ' value='Show Window'></p></body></html>

BOOL SampleDlg::OnCommand(WPARAM wParam, LPARAM lParam)

{

    UINT nID = LOWORD( wParam );

    switch(nID)

    {

        case 20:

            {

                this->ShowWindow(SW_SHOW);

                return true;

            }

            break;

    }

    return CWnd::OnCommand(wParam,lParam);

}

當然如果是再Windows程式中也可以用如下的方式寫:

在WinMain函數中設定回調函數。

int WINAPI WinMain(

    HINSTANCE hInstance,

    HINSTANCE hPrevInstance,

    LPTSTR lpCmdLine,   

    int nCmdShow

    )

{

    g_hInst = hInstance;

    SHInitExtraControls();

    // just call a dialog box, system will handle messaging, painting, etc...

    DialogBox(hInstance,(LPCTSTR)IDD_NOTIFYMAIN, NULL,(DLGPROC)NotifyMain );

    return 0;

}

在回調函數中處理:

LRESULT CALLBACK NotifyMain(

    HWND hDlg,

    UINT message,

    WPARAM wParam,

    LPARAM lParam

    )

{

      switch(message)

    {

          case WM_COMMAND:

            {

                 switch(LOWORD(wParam))

                 {

                      case 10:

                       {Your operation}

                       Break;

                 }

            }

     }

}

繼續閱讀