ZBLOG

duilib设置窗口边框

在DuiLib中,可以通过设置窗口的样式来实现自定义窗口边框。以下是一个示例:

  1. #include "DuiLib/UIlib.h"
  2. using namespace DuiLib;
  3. class MyWindow : public CWindowWnd, public INotifyUI
  4. {
  5. public:
  6. virtual LPCTSTR GetWindowClassName() const { return _T("MyWindow"); }
  7. virtual UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; }
  8. virtual void Notify(TNotifyUI& msg)
  9. {
  10. if (msg.sType == _T("click"))
  11. {
  12. if (msg.pSender->GetName() == _T("btnClose"))
  13. Close();
  14. else if (msg.pSender->GetName() == _T("btnMin"))
  15. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  16. }
  17. }
  18. virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  19. {
  20. LRESULT lRes = 0;
  21. BOOL bHandled = TRUE;
  22. switch (uMsg)
  23. {
  24. case WM_CREATE:
  25. OnCreate(uMsg, wParam, lParam);
  26. break;
  27. case WM_NCACTIVATE:
  28. if (!::IsIconic(*this))
  29. return (wParam == 0) ? TRUE : FALSE;
  30. break;
  31. case WM_NCCALCSIZE:
  32. if (!::IsIconic(*this))
  33. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  34. break;
  35. default:
  36. bHandled = FALSE;
  37. break;
  38. }
  39. if (bHandled)
  40. return lRes;
  41. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  42. }
  43. private:
  44. void OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam)
  45. {
  46. m_PaintManager.Init(m_hWnd);
  47. CDialogBuilder builder;
  48. CContainerUI* pRoot = static_cast<CContainerUI*>(builder.Create(_T("window.xml"), (UINT)0, NULL, &m_PaintManager));
  49. if (pRoot != NULL)
  50. {
  51. m_PaintManager.AttachDialog(pRoot);
  52. m_PaintManager.AddNotifier(this);
  53. CButtonUI* btnClose = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnClose")));
  54. if (btnClose != NULL)
  55. btnClose->SetVisible(true);
  56. CButtonUI* btnMin = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnMin")));
  57. if (btnMin != NULL)
  58. btnMin->SetVisible(true);
  59. }
  60. }
  61. private:
  62. CPaintManagerUI m_PaintManager;
  63. };
  64. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int nCmdShow)
  65. {
  66. CPaintManagerUI::SetInstance(hInstance);
  67. CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("\\resources"));
  68. MyWindow wnd;
  69. // 设置窗口样式,去掉默认边框
  70. DWORD dwStyle = WS_POPUP | WS_VISIBLE;
  71. ::CreateWindowEx(WS_EX_APPWINDOW, wnd.GetWindowClassName(), _T("DuiLib Custom Window Border"), dwStyle,
  72. 0, 0, 800, 600, NULL, NULL, hInstance, &wnd);
  73. CPaintManagerUI::MessageLoop();
  74. return 0;
  75. }

在上述示例中,我们创建了一个自定义窗口边框的窗口。通过设置 WS_POPUP 样式来实现去掉默认边框。然后,通过调用 CreateWindowEx 函数创建窗口并设置其样式。

你可以根据自己的需求修改窗口的布局和样式,以实现更加个性化的窗口边框效果。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=16767

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?