【转载】windows mobile 上隐藏和关闭X以及OK的处理
生活随笔
收集整理的這篇文章主要介紹了
【转载】windows mobile 上隐藏和关闭X以及OK的处理
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
【轉(zhuǎn)自】http://blog.csdn.net/czbever
1、隱藏X:
?在WM_CREATE里?SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
3、如果想將X按鈕改為退出程序而不是最小化,可以在初始化window時用:?SHDoneButton(hWnd,SHDB_SHOWCANCEL);?然后在OnCommand中的IDCANCEL中向窗口發(fā)送WM_CLOSE消息就可以關(guān)閉程序了
這樣子程序一開始就是ok按鈕。
4、對話框中將屏幕右上角ok隱藏:
在win32中需要在WM_INITDIALOG消息加入以下:SHDoneButton(hWnd,SHDB_HIDE);?SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
在MFC中,需要按以下方法處理:
BOOL CtestmfcDlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM?
lParam, LRESULT* pResult){?if(message == WM_INITDIALOG)?{?? ? ? ? ? ? ? ?// 創(chuàng)建一個“完成”按鈕并調(diào)整其大小。?? ? ? ? ? ? ? ?SHINITDLGINFO shidi;?? ? ? ? ? ? ? ?shidi.dwMask = SHIDIM_FLAGS;?? ? ? ? ? ? ? ?shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN?
| SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;?? ? ? ? ? ? ? ?shidi.hDlg = m_hWnd;?? ?::SHInitDialog(&shidi);
?? ?::SHDoneButton(m_hWnd,SHDB_HIDE);??? ?::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
?? ? ? ? ? ? ? return (INT_PTR)TRUE;?}?return CDialog::OnWndMsg(message,wParam,lParam,pResult);}
或者在直接在OnInitDialog里替換掉CDialog::OnInitDialog.
BOOL CtestmfcDlg::OnInitDialog(){?? SHINITDLGINFO shidi;?? ? ? ? ? ? ? ?shidi.dwMask = SHIDIM_FLAGS;?? ? ? ? ? ? ? ?shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN?
| SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;?? ? ? ? ? ? ? ?shidi.hDlg = m_hWnd;?? ?::SHInitDialog(&shidi);
?? ?::SHDoneButton(m_hWnd,SHDB_HIDE);??? ?::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
?// 設(shè)置此對話框的圖標(biāo)。當(dāng)應(yīng)用程序主窗口不是對話框時,框架將自動?// ?執(zhí)行此操作?SetIcon(m_hIcon, TRUE); ? // 設(shè)置大圖標(biāo)?SetIcon(m_hIcon, FALSE); ?// 設(shè)置小圖標(biāo)
?// TODO: 在此添加額外的初始化代碼?return TRUE; ?// 除非將焦點設(shè)置到控件,否則返回TRUE}
The button at the right of the Task Bar (the bar at the top of your?
Pocket PC) is called the "Smart Minimize Button".
5、另外一種把X處理為退出程序的方法為子類化TaskBar:
But how do we manage to have the "Smart Minimize Button" close the?
application for us?
We have to hook it. Here's how it works: First, subclass the task?
bar window. The new window procedure must be looking for?
WM_LBUTTONUP messages in the rectangle of the button. When you?
intercept the message, post a WM_CLOSE message to your main frame.?
You will have to be careful when subclassing the task bar window?
procedure: you have to make sure that you will un-subclass it when?
your application loses the focus (deactivated) or when it is closed?
(essentially the same thing).
The Recipe for MFCAll the work you need to do is restricted to the CMainFrame class.?
First, let's look at the definitions you need to add to the header?
file:
extern HWND g_hWndMain, g_hWndTask;extern WNDPROC g_fnProcTask;static LRESULT CALLBACK TaskWndProc(HWND hWnd, UINT msg, WPARAM?
wParam, LPARAM lParam);
The static variables will store the task bar and main frame's?
window handles. The WNDPROC will store the task bar's original?
window proc. Now, go to the implementation file (CPP) and add these?
declarations:
//// Static variables for task bar subclassing//static HWND g_hWndMain = NULL;static HWND g_hWndTask = NULL;static WNDPROC g_fnProcTask = NULL;
Now, add the following protected methods to CMainFrame:
// CMainFrame::HookTaskBar//// Hook into the task bar//BOOL CMainFrame::HookTaskBar(){?//?// Already hooked??//?if(g_fnProcTask)??return FALSE;
?g_hWndTask = ::FindWindow(_T("HHTaskBar"), NULL);?if(g_hWndTask)?{??g_hWndMain = GetSafeHwnd();
??g_fnProcTask = (WNDPROC)::GetWindowLong(g_hWndTask, GWL_WNDPROC);
??::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)TaskWndProc);?}?return g_hWndTask != NULL;}
// CMainFrame::FreeTaskBar//// Free the task bar//BOOL CMainFrame::FreeTaskBar(){?//?// Already freed??//?if(!g_fnProcTask)??return FALSE;?::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)g_fnProcTask);?g_fnProcTask = NULL;?return TRUE;}
Add an OnActivate handler to the class (WM_ACTIVATE message):
// CMainFrame::OnActivate//// The frame is being activated / deactivated//void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL?
bMinimized)?{?CFrameWnd::OnActivate(nState, pWndOther, bMinimized);?if(nState == WA_INACTIVE)??FreeTaskBar();?else??HookTaskBar();}
Finally, here is the new task bar window proc.
// TaskWndProc//// ?Handles the WM_LBUTTONUP message//LRESULT TaskWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM?
lParam){?if(msg == WM_LBUTTONUP)?{??RECT rc;??POINT pt;
??rc.left ?= 240 - 26;??rc.top ?= 0;??rc.bottom = 26;??rc.right = 240;
??pt.x ?= LOWORD(lParam);??pt.y ?= HIWORD(lParam);
??if(::PtInRect(&rc, pt))??{?? ::PostMessage(g_hWndMain, WM_CLOSE, 0, 0);?? return ::CallWindowProc(?? ?g_fnProcTask,??? ?hWnd,??? ?WM_MOUSEMOVE,??? ?0,??? ?MAKELPARAM(200, 0));??}?}?return ::CallWindowProc(g_fnProcTask, hWnd, msg, wParam, lParam);}
Why the WM_MOUSEMOVE? It simulates the user dragging the stylus out?
of the button, and thereby restoring it to the normal state.
4、另外在win32中還有另外一種去掉 (OK) 和 [x] 的辦法:在對話框的風(fēng)格上加 WS_NONAVDONEBUTTON 屬性#define WS_NONAVDONEBUTTON WS_MINIMIZEBOX注意這個 WS_MINIMIZEBOX 和 PC 上的意義不一樣
5、隱藏輸入法按鈕:在 SHCreateMenuBar 時使用 SHCMBF_HIDESIPBUTTON 標(biāo)志,最好還要調(diào)用?
SipShowIM( SIPF_OFF );因為可能程序的調(diào)用者打開著輸入法(調(diào)用者打開著輸入法有時候會導(dǎo)致被調(diào)用者也
打開輸入法)
1、隱藏X:
?在WM_CREATE里?SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
3、如果想將X按鈕改為退出程序而不是最小化,可以在初始化window時用:?SHDoneButton(hWnd,SHDB_SHOWCANCEL);?然后在OnCommand中的IDCANCEL中向窗口發(fā)送WM_CLOSE消息就可以關(guān)閉程序了
這樣子程序一開始就是ok按鈕。
4、對話框中將屏幕右上角ok隱藏:
在win32中需要在WM_INITDIALOG消息加入以下:SHDoneButton(hWnd,SHDB_HIDE);?SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
在MFC中,需要按以下方法處理:
BOOL CtestmfcDlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM?
lParam, LRESULT* pResult){?if(message == WM_INITDIALOG)?{?? ? ? ? ? ? ? ?// 創(chuàng)建一個“完成”按鈕并調(diào)整其大小。?? ? ? ? ? ? ? ?SHINITDLGINFO shidi;?? ? ? ? ? ? ? ?shidi.dwMask = SHIDIM_FLAGS;?? ? ? ? ? ? ? ?shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN?
| SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;?? ? ? ? ? ? ? ?shidi.hDlg = m_hWnd;?? ?::SHInitDialog(&shidi);
?? ?::SHDoneButton(m_hWnd,SHDB_HIDE);??? ?::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
?? ? ? ? ? ? ? return (INT_PTR)TRUE;?}?return CDialog::OnWndMsg(message,wParam,lParam,pResult);}
或者在直接在OnInitDialog里替換掉CDialog::OnInitDialog.
BOOL CtestmfcDlg::OnInitDialog(){?? SHINITDLGINFO shidi;?? ? ? ? ? ? ? ?shidi.dwMask = SHIDIM_FLAGS;?? ? ? ? ? ? ? ?shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN?
| SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;?? ? ? ? ? ? ? ?shidi.hDlg = m_hWnd;?? ?::SHInitDialog(&shidi);
?? ?::SHDoneButton(m_hWnd,SHDB_HIDE);??? ?::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );
?// 設(shè)置此對話框的圖標(biāo)。當(dāng)應(yīng)用程序主窗口不是對話框時,框架將自動?// ?執(zhí)行此操作?SetIcon(m_hIcon, TRUE); ? // 設(shè)置大圖標(biāo)?SetIcon(m_hIcon, FALSE); ?// 設(shè)置小圖標(biāo)
?// TODO: 在此添加額外的初始化代碼?return TRUE; ?// 除非將焦點設(shè)置到控件,否則返回TRUE}
The button at the right of the Task Bar (the bar at the top of your?
Pocket PC) is called the "Smart Minimize Button".
5、另外一種把X處理為退出程序的方法為子類化TaskBar:
But how do we manage to have the "Smart Minimize Button" close the?
application for us?
We have to hook it. Here's how it works: First, subclass the task?
bar window. The new window procedure must be looking for?
WM_LBUTTONUP messages in the rectangle of the button. When you?
intercept the message, post a WM_CLOSE message to your main frame.?
You will have to be careful when subclassing the task bar window?
procedure: you have to make sure that you will un-subclass it when?
your application loses the focus (deactivated) or when it is closed?
(essentially the same thing).
The Recipe for MFCAll the work you need to do is restricted to the CMainFrame class.?
First, let's look at the definitions you need to add to the header?
file:
extern HWND g_hWndMain, g_hWndTask;extern WNDPROC g_fnProcTask;static LRESULT CALLBACK TaskWndProc(HWND hWnd, UINT msg, WPARAM?
wParam, LPARAM lParam);
The static variables will store the task bar and main frame's?
window handles. The WNDPROC will store the task bar's original?
window proc. Now, go to the implementation file (CPP) and add these?
declarations:
//// Static variables for task bar subclassing//static HWND g_hWndMain = NULL;static HWND g_hWndTask = NULL;static WNDPROC g_fnProcTask = NULL;
Now, add the following protected methods to CMainFrame:
// CMainFrame::HookTaskBar//// Hook into the task bar//BOOL CMainFrame::HookTaskBar(){?//?// Already hooked??//?if(g_fnProcTask)??return FALSE;
?g_hWndTask = ::FindWindow(_T("HHTaskBar"), NULL);?if(g_hWndTask)?{??g_hWndMain = GetSafeHwnd();
??g_fnProcTask = (WNDPROC)::GetWindowLong(g_hWndTask, GWL_WNDPROC);
??::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)TaskWndProc);?}?return g_hWndTask != NULL;}
// CMainFrame::FreeTaskBar//// Free the task bar//BOOL CMainFrame::FreeTaskBar(){?//?// Already freed??//?if(!g_fnProcTask)??return FALSE;?::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)g_fnProcTask);?g_fnProcTask = NULL;?return TRUE;}
Add an OnActivate handler to the class (WM_ACTIVATE message):
// CMainFrame::OnActivate//// The frame is being activated / deactivated//void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL?
bMinimized)?{?CFrameWnd::OnActivate(nState, pWndOther, bMinimized);?if(nState == WA_INACTIVE)??FreeTaskBar();?else??HookTaskBar();}
Finally, here is the new task bar window proc.
// TaskWndProc//// ?Handles the WM_LBUTTONUP message//LRESULT TaskWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM?
lParam){?if(msg == WM_LBUTTONUP)?{??RECT rc;??POINT pt;
??rc.left ?= 240 - 26;??rc.top ?= 0;??rc.bottom = 26;??rc.right = 240;
??pt.x ?= LOWORD(lParam);??pt.y ?= HIWORD(lParam);
??if(::PtInRect(&rc, pt))??{?? ::PostMessage(g_hWndMain, WM_CLOSE, 0, 0);?? return ::CallWindowProc(?? ?g_fnProcTask,??? ?hWnd,??? ?WM_MOUSEMOVE,??? ?0,??? ?MAKELPARAM(200, 0));??}?}?return ::CallWindowProc(g_fnProcTask, hWnd, msg, wParam, lParam);}
Why the WM_MOUSEMOVE? It simulates the user dragging the stylus out?
of the button, and thereby restoring it to the normal state.
4、另外在win32中還有另外一種去掉 (OK) 和 [x] 的辦法:在對話框的風(fēng)格上加 WS_NONAVDONEBUTTON 屬性#define WS_NONAVDONEBUTTON WS_MINIMIZEBOX注意這個 WS_MINIMIZEBOX 和 PC 上的意義不一樣
5、隱藏輸入法按鈕:在 SHCreateMenuBar 時使用 SHCMBF_HIDESIPBUTTON 標(biāo)志,最好還要調(diào)用?
SipShowIM( SIPF_OFF );因為可能程序的調(diào)用者打開著輸入法(調(diào)用者打開著輸入法有時候會導(dǎo)致被調(diào)用者也
打開輸入法)
轉(zhuǎn)載于:https://www.cnblogs.com/IamEasy_Man/archive/2009/11/05/1596570.html
總結(jié)
以上是生活随笔為你收集整理的【转载】windows mobile 上隐藏和关闭X以及OK的处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows服务ServicesDep
- 下一篇: 导出到Excel的操作