动态菜单的问题 我动态添加一个菜单,怎么在鼠标划过菜单的时候在状态栏里显示提示信息? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.codeguru.com/Cpp/controls/statusbar/article.php/c5935/ 如果想浮动工具条中加控件,可以通过继承CToolBar,然后在创建工具条的时候,在Toolbar上创建控件,就像在一般窗口的操作,不过需要调整位置BOOL CComboxToolBar::InsertCombox(){ const int nDropHeight = 800; // test CToolBarCtrl &pCtrl = GetToolBarCtrl(); TBBUTTON tb ={0}; tb.idCommand = IDW_COMBO;// tb.fsState = TBSTATE_ENABLED; // Insert it in existing toolbar control pCtrl.InsertButton(3, &tb); SetButtonInfo(3, IDW_COMBO, TBBS_SEPARATOR, 100); CRect rect; GetItemRect(3, &rect); rect.top = 0; rect.bottom = rect.top + nDropHeight; rect.left -= 3; rect.right -= 3; if (!m_comboBox.Create( CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP, rect, this, IDW_COMBO)) { TRACE0("Failed to create combo-box\n"); return FALSE; } // Fill the combo box CString szStyle; for (INT i=0; i<4; i++) { szStyle.Format("%d%%", 25*(i+1)); m_comboBox.AddString((LPCTSTR)szStyle); } szStyle.Format("%d%%", 150); m_comboBox.AddString((LPCTSTR)szStyle); szStyle.Format("%d%%", 200); m_comboBox.AddString((LPCTSTR)szStyle); szStyle.Format("%d%%", 500); m_comboBox.AddString((LPCTSTR)szStyle); m_comboBox.SetCurSel(0); return TRUE;} http://www.codeguru.com/Cpp/controls/void CChangeMenu::OnClear() { AfxGetMainWnd()->SetMenu(NULL); AfxGetMainWnd()->DrawMenuBar(); } void CChangeMenu::OnGoone() { if(!menu1){ menu1.LoadMenu(IDR_MENU1); AfxGetMainWnd()->SetMenu(&menu1); AfxGetMainWnd()->DrawMenuBar(); menu1.Detach(); } } void CChangeMenu::OnGotwo() { if(!menu2){ menu2.LoadMenu(IDR_MAINFRAME); AfxGetMainWnd()->SetMenu(&menu2); AfxGetMainWnd()->DrawMenuBar(); menu2.Detach(); } } void CChangeMenu::OnAdd() { static int x=400; AfxGetMainWnd()->GetMenu()->AppendMenu(MF_STRING,x,"mynew"); AfxGetMainWnd()->DrawMenuBar(); x++; } void CChangeMenu::OnAdditem() { static int y=500; AfxGetMainWnd()->GetMenu()->GetSubMenu(0)->InsertMenu(1,MF_BYPOSITION,y,"mynewitem"); AfxGetMainWnd()->DrawMenuBar(); y++; } void CChangeMenu::OnEdit() { AfxGetMainWnd()->GetMenu()->ModifyMenu(0,MF_BYPOSITION,402,"dfd"); AfxGetMainWnd()->DrawMenuBar(); } 这个消息好像是在String Table里面直接写就可以的。 在资源里的item properties里的prompt里加入提示的时候,须加入\n如Open an existing document\nOpen,前一段是在状态栏显示,后一个是鼠标移动的tip 如果要实现动态菜单提示,必须重载CFrameWnd::OnMenuSelect和 用提示串发送WM_SETMESSAGESTRIN消息。void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags,HMENU hSysMenu) { if (/* nItemID has a dynamic prompt */) {CString sPrompt = // whatever you want SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)sPrompt); m_nIDTracking = nItemID; } else { CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu); } } vs2010,最简单的MFC编译出错 关于VC绘图问题 如何重绘在CScrollView中的ScrollBar 散分,散分...... --------->>如何设置VC6的编译器优化选项? 请指教!ADO访问ODBC时,获得字段值的长度不对! 我的电脑不能启动,我用98启动盘对其sys c:之后,c:\盘的资料就看不到了,如何修复啊? 静态切分与动态切分的有啥区别呢? 一个关于在MFC下调用API函数的问题 给基于对话框的应用程序添加菜单? 有没有TCPselect模型的现成类? 请教自绘窗体和EDIT的问题!
BOOL CComboxToolBar::InsertCombox()
{
const int nDropHeight = 800;
// test
CToolBarCtrl &pCtrl = GetToolBarCtrl();
TBBUTTON tb ={0}; tb.idCommand = IDW_COMBO;
// tb.fsState = TBSTATE_ENABLED;
// Insert it in existing toolbar control
pCtrl.InsertButton(3, &tb);
SetButtonInfo(3, IDW_COMBO, TBBS_SEPARATOR, 100);
CRect rect;
GetItemRect(3, &rect);
rect.top = 0;
rect.bottom = rect.top + nDropHeight;
rect.left -= 3;
rect.right -= 3;
if (!m_comboBox.Create(
CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP,
rect, this, IDW_COMBO))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
// Fill the combo box
CString szStyle;
for (INT i=0; i<4; i++)
{
szStyle.Format("%d%%", 25*(i+1));
m_comboBox.AddString((LPCTSTR)szStyle);
} szStyle.Format("%d%%", 150);
m_comboBox.AddString((LPCTSTR)szStyle);
szStyle.Format("%d%%", 200);
m_comboBox.AddString((LPCTSTR)szStyle);
szStyle.Format("%d%%", 500);
m_comboBox.AddString((LPCTSTR)szStyle); m_comboBox.SetCurSel(0);
return TRUE;
}
void CChangeMenu::OnClear()
{
AfxGetMainWnd()->SetMenu(NULL);
AfxGetMainWnd()->DrawMenuBar();
} void CChangeMenu::OnGoone()
{
if(!menu1){
menu1.LoadMenu(IDR_MENU1);
AfxGetMainWnd()->SetMenu(&menu1);
AfxGetMainWnd()->DrawMenuBar();
menu1.Detach();
}
} void CChangeMenu::OnGotwo()
{
if(!menu2){
menu2.LoadMenu(IDR_MAINFRAME);
AfxGetMainWnd()->SetMenu(&menu2);
AfxGetMainWnd()->DrawMenuBar();
menu2.Detach();
}
} void CChangeMenu::OnAdd()
{
static int x=400;
AfxGetMainWnd()->GetMenu()->AppendMenu(MF_STRING,x,"mynew");
AfxGetMainWnd()->DrawMenuBar();
x++;
} void CChangeMenu::OnAdditem()
{
static int y=500;
AfxGetMainWnd()->GetMenu()->GetSubMenu(0)->InsertMenu(1,MF_BYPOSITION,y,"mynewitem");
AfxGetMainWnd()->DrawMenuBar();
y++;
} void CChangeMenu::OnEdit()
{
AfxGetMainWnd()->GetMenu()->ModifyMenu(0,MF_BYPOSITION,402,"dfd");
AfxGetMainWnd()->DrawMenuBar();
}
HMENU hSysMenu)
{
if (/* nItemID has a dynamic prompt */)
{
CString sPrompt = // whatever you want
SendMessage(WM_SETMESSAGESTRING, 0, (LPARAM)(LPCTSTR)sPrompt);
m_nIDTracking = nItemID;
} else {
CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
}
}