怎样在标题栏上放控件?

windywater119 2017-11-08 11:00:21
我想在原生标题栏上放置按钮等控件,而不是做个无边框窗口自绘标题栏,尝试了一下DwmExtendFrameIntoClientArea,没有达到预期效果,像IE、Chrome这些是如何做到的?请赐教~~
...全文
398 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2017-11-10
  • 打赏
  • 举报
回复
好啊,不过 WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED); 这句 GetDlgCtrlID(), 是多余的 直接 写 0.
耳边呢喃 2017-11-10
  • 打赏
  • 举报
回复
标题栏好像是无法加入控件的
zgl7903 2017-11-09
  • 打赏
  • 举报
回复
引用 10 楼 schlafenhamster 的回复:
m_TestButton.CreateEx(0,_T("BUTTON"),_T("Test"),WS_POPUP|WS_VISIBLE, CRect(0,0,0,0), this,0); m_TestButton.SetDlgCtrlID(1000); // 这句 failed ! 这个 按钮 的 ID =0 ; (这样产生的 按钮 ID 都=0, 区分这种按钮 得用 hwnd) 见 UINT uID = LOWORD(wParam); // ==0 if(uNotify == BN_CLICKED && uID == (UINT)m_TestButton.GetDlgCtrlID() /* == 0 */ )
之前测试只用了一个按钮 所以没留意这个问题, 多谢提醒!! 可以改造一下
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point) 
{
  // TODO: Add your message handler code here and/or call default
  CWnd *pParent = GetParent();
  if((GetStyle() & WS_POPUP) && pParent)
  {
    WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED);
    pParent->PostMessage(WM_COMMAND, wParam, (LPARAM)m_hWnd);
  }   
  CButton::OnLButtonDown(nFlags, point);
}
 
BOOL CDlg5Dlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{
  // TODO: Add your specialized code here and/or call the base class
  UINT uNotify = HIWORD(wParam);
  UINT uID = LOWORD(wParam);
  if(uNotify == BN_CLICKED && (HWND)lParam == m_TestButton.m_hWnd)
  {
    AfxMessageBox(_T("Button clicked!"));
  }
   
  return CDialog::OnCommand(wParam, lParam);
}

schlafenhamster 2017-11-09
  • 打赏
  • 举报
回复
m_TestButton.CreateEx(0,_T("BUTTON"),_T("Test"),WS_POPUP|WS_VISIBLE, CRect(0,0,0,0), this,0); m_TestButton.SetDlgCtrlID(1000); // 这句 failed ! 这个 按钮 的 ID =0 ; (这样产生的 按钮 ID 都=0, 区分这种按钮 得用 hwnd) 见 UINT uID = LOWORD(wParam); // ==0 if(uNotify == BN_CLICKED && uID == (UINT)m_TestButton.GetDlgCtrlID() /* == 0 */ )
sevancheng 2017-11-09
  • 打赏
  • 举报
回复
不是有菜单栏,工具栏么
smwhotjay 2017-11-09
  • 打赏
  • 举报
回复
这什么奇怪需求,标题就是干标题的活,
oyljerry 2017-11-09
  • 打赏
  • 举报
回复
浏览器等应该都是自绘的,只有这样才能灵活,好自己处理
向立天 2017-11-09
  • 打赏
  • 举报
回复
标题栏是放不了通用控件的,可以通过自绘非客户区的方式绘制自定义的控件在上面
schlafenhamster 2017-11-08
  • 打赏
  • 举报
回复
DwmExtendFrameIntoClientArea 是 Extends the window frame into the client area.
赵4老师 2017-11-08
  • 打赏
  • 举报
回复
百度搜相关关键字。
零隐 2017-11-08
  • 打赏
  • 举报
回复
引用 楼主 dowithsmiles 的回复:
我想在原生标题栏上放置按钮等控件,而不是做个无边框窗口自绘标题栏,尝试了一下DwmExtendFrameIntoClientArea,没有达到预期效果,像IE、Chrome这些是如何做到的?请赐教~~
会不会是无边框对话框。
zgl7903 2017-11-08
  • 打赏
  • 举报
回复
以WS_POPUP风格创建就有可能 在标题栏放一个按钮的测试代码

//从CButton派生新类 处理 WM_LBUTTONDOWN 消息, 发送按下消息
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point) 
{
  // TODO: Add your message handler code here and/or call default
  CWnd *pParent = GetParent();
  if((GetStyle() & WS_POPUP) && pParent)
  {
    WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED);
    pParent->PostMessage(WM_COMMAND, wParam);
  }
  
  CButton::OnLButtonDown(nFlags, point);
}
//在对话框上测试 //Dlg5Dlg.h

class CDlg5Dlg : public CDialog
{
CMyButton m_TestButton;

BOOL CDlg5Dlg::OnInitDialog()
{
  CDialog::OnInitDialog();

  // Set the icon for this dialog.  The framework does this automatically
  //  when the application's main window is not a dialog
  SetIcon(m_hIcon, TRUE);      // Set big icon
  SetIcon(m_hIcon, FALSE);    // Set small icon

  // TODO: Add extra initialization here
  m_TestButton.CreateEx(0, _T("BUTTON"),
    _T("Test"), WS_POPUP|WS_VISIBLE,  CRect(0, 0, 200, 40), this, 0);
  m_TestButton.SetDlgCtrlID(1000);

  return TRUE;  // return TRUE  unless you set the focus to a control
}

BOOL CDlg5Dlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{
  // TODO: Add your specialized code here and/or call the base class
  UINT uNotify = HIWORD(wParam);
  UINT uID = LOWORD(wParam);
  if(uNotify == BN_CLICKED && uID == m_TestButton.GetDlgCtrlID())
  {
    AfxMessageBox(_T("Button clicked!"));
  }
  
  return CDialog::OnCommand(wParam, lParam);
}

//处理 WM_WINDOWPOSCHANGED 消息
void CDlg5Dlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) 
{
  CDialog::OnWindowPosChanged(lpwndpos);
	
  // TODO: Add your message handler code here
  if(m_TestButton.m_hWnd)
  {
    CRect rcRect;
    GetWindowRect(&rcRect);  
    m_TestButton.MoveWindow(rcRect.left+20, rcRect.top, 100, 40);
  }	
}

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧