WEB开发网
开发学院手机开发Windows Mobile 开发 Windows Mobile SP/PPC 中 Menu Bar 使用完美方案... 阅读

Windows Mobile SP/PPC 中 Menu Bar 使用完美方案

 2010-08-22 12:53:00 来源:WEB开发网   
核心提示:&tb);}// 设置按钮文字BOOL SetButtonText(PCTSTR ptzStr, BOOL bRight = TRUE){TBBUTTONINFO tb;tb.cbSize = sizeof(TBBUTTONINFO);tb.dwMask = _MBIF(TBIF_TEXT);tb.pszText =
&tb);

}

// 设置按钮文字

BOOL SetButtonText(PCTSTR ptzStr, BOOL bRight = TRUE)

{

TBBUTTONINFO tb;

tb.cbSize = sizeof(TBBUTTONINFO);

tb.dwMask = _MBIF(TBIF_TEXT);

tb.pszText = (PTSTR) ptzStr;

return SendMessage(m_hMenuBar, TB_SETBUTTONINFO, _MBID(bRight), (LPARAM) &tb);

}

// 获取按钮状态

BYTE GetButtonState(BOOL bRight = TRUE)

{

TBBUTTONINFO tb;

tb.cbSize = sizeof(TBBUTTONINFO);

tb.dwMask = _MBIF(TBIF_STATE);

SendMessage(m_hMenuBar, TB_GETBUTTONINFO, _MBID(bRight), (LPARAM) &tb);

return tb.fsState;

}

// 设置按钮状态

BOOL SetButtonState(BYTE bState = TBSTATE_ENABLED, BOOL bRight = TRUE)

{

TBBUTTONINFO tb;

tb.cbSize = sizeof(TBBUTTONINFO);

tb.dwMask = _MBIF(TBIF_STATE);

tb.fsState = bState;

return SendMessage(m_hMenuBar, TB_SETBUTTONINFO, _MBID(bRight), (LPARAM) &tb);

}

// 启用或禁用按钮

BOOL EnableButton(BOOL bEnable = TRUE, BOOL bRight = TRUE)

{

return SetButtonState(bEnable ? TBSTATE_ENABLED : 0, bRight);

}

// 显示或隐藏按钮

BOOL HideButton(BOOL bHide = TRUE, BOOL bRight = TRUE)

{

return SetButtonState(bHide ? TBSTATE_HIDDEN : 0, bRight);

}

// 弹出菜单,用于需要动态切换弹出菜单的情况

BOOL PopupMenu(HMENU hMenu, BOOL bRight = TRUE)

{

BYTE bState = GetButtonState(bRight);

if (bState & TBSTATE_PRESSED)

{

keybd_event(VK_ESCAPE, 0, KEYEVENTF_SILENT, 0);

keybd_event(VK_ESCAPE, 0, KEYEVENTF_SILENT | KEYEVENTF_KEYUP, 0);

}

else

{

RECT rt;

GetWindowRect(m_hMenuBar, &rt);

SetButtonState(bState | TBSTATE_PRESSED, bRight);

TrackPopupMenuEx(hMenu, bRight ? (TPM_RIGHTALIGN | TPM_BOTTOMALIGN) : (TPM_LEFTALIGN | TPM_BOTTOMALIGN),

bRight ? rt.right : rt.left, rt.top, GetParent(m_hMenuBar), NULL);

}

return SetButtonState(bState & ~TBSTATE_PRESSED, bRight);

}

};

上一页  1 2 3 

Tags:Windows Mobile SP

编辑录入:coldstar [复制链接] [打 印]
赞助商链接