在DuiLib中,可以通过设置窗口的样式来实现自定义窗口边框。以下是一个示例:
#include "DuiLib/UIlib.h"
using namespace DuiLib;
class MyWindow : public CWindowWnd, public INotifyUI
{
public:
virtual LPCTSTR GetWindowClassName() const { return _T("MyWindow"); }
virtual UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; }
virtual void Notify(TNotifyUI& msg)
{
if (msg.sType == _T("click"))
{
if (msg.pSender->GetName() == _T("btnClose"))
Close();
else if (msg.pSender->GetName() == _T("btnMin"))
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
}
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;
BOOL bHandled = TRUE;
switch (uMsg)
{
case WM_CREATE:
OnCreate(uMsg, wParam, lParam);
break;
case WM_NCACTIVATE:
if (!::IsIconic(*this))
return (wParam == 0) ? TRUE : FALSE;
break;
case WM_NCCALCSIZE:
if (!::IsIconic(*this))
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
break;
default:
bHandled = FALSE;
break;
}
if (bHandled)
return lRes;
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
}
private:
void OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
m_PaintManager.Init(m_hWnd);
CDialogBuilder builder;
CContainerUI* pRoot = static_cast<CContainerUI*>(builder.Create(_T("window.xml"), (UINT)0, NULL, &m_PaintManager));
if (pRoot != NULL)
{
m_PaintManager.AttachDialog(pRoot);
m_PaintManager.AddNotifier(this);
CButtonUI* btnClose = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnClose")));
if (btnClose != NULL)
btnClose->SetVisible(true);
CButtonUI* btnMin = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("btnMin")));
if (btnMin != NULL)
btnMin->SetVisible(true);
}
}
private:
CPaintManagerUI m_PaintManager;
};
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int nCmdShow)
{
CPaintManagerUI::SetInstance(hInstance);
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("\\resources"));
MyWindow wnd;
// 设置窗口样式,去掉默认边框
DWORD dwStyle = WS_POPUP | WS_VISIBLE;
::CreateWindowEx(WS_EX_APPWINDOW, wnd.GetWindowClassName(), _T("DuiLib Custom Window Border"), dwStyle,
0, 0, 800, 600, NULL, NULL, hInstance, &wnd);
CPaintManagerUI::MessageLoop();
return 0;
}
在上述示例中,我们创建了一个自定义窗口边框的窗口。通过设置 WS_POPUP
样式来实现去掉默认边框。然后,通过调用 CreateWindowEx
函数创建窗口并设置其样式。
你可以根据自己的需求修改窗口的布局和样式,以实现更加个性化的窗口边框效果。
内容由零声教学AI助手提供,问题来源于学员提问