windows mobile 上隐藏和关闭X以及OK的处理

1、隐藏X:

 在WM_CREATE里
 SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );

3、如果想将X按钮改为退出程序而不是最小化,可以在初始化window时用:
SHDoneButton(hWnd,SHDB_SHOWCANCEL);
然后在OnCommand中的IDCANCEL中向窗口发送WM_CLOSE消息就可以关闭程序了

这样子程序一开始就是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)
 {
  
      
                // 创建一个“完成”按钮并调整其大小。
                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 );

 

 // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
 //  执行此操作
 SetIcon(m_hIcon, TRUE);   // 设置大图标
 SetIcon(m_hIcon, FALSE);  // 设置小图标

 // TODO: 在此添加额外的初始化代码
 
 return TRUE;  // 除非将焦点设置到控件,否则返回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 MFC
All 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] 的办法:
 
在对话框的风格上加 WS_NONAVDONEBUTTON 属性
 
#define WS_NONAVDONEBUTTON WS_MINIMIZEBOX
 
注意这个 WS_MINIMIZEBOX 和 PC 上的意义不一样

5、隐藏输入法按钮:
 
在 SHCreateMenuBar 时使用 SHCMBF_HIDESIPBUTTON 标志,最好还要调用 SipShowIM( SIPF_OFF );
因为可能程序的调用者打开着输入法(调用者打开着输入法有时候会导致被调用者也打开输入法)

 

你可能感兴趣的:(windows mobile 上隐藏和关闭X以及OK的处理)