duilib小计
m_pm.AddPostPaint(pButton);
DC获取方法
m_hWndPaint = hWnd; m_hDcPaint = ::GetDC(句柄);
在析构函数中去release: ::ReleaseDC(m_hWndPaint, m_hDcPaint);
duilib中方法
DC 绘画内容 绘画区域 风格
DT_NOPREFIX | 关闭前缀字符的处理。 通常DrawText解释助记前缀字符,&为给其后的字符加下划线,解释&&为显示单个&。指定DT_NOPREFIX,这种处理被关闭。 |
void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle)
{
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
if( pstrText == NULL || pManager == NULL ) return;
::SetBkMode(hDC, TRANSPARENT);
::SetTextColor(hDC, RGB(GetBValue(dwTextColor), GetGValue(dwTextColor), GetRValue(dwTextColor)));
HFONT hOldFont = (HFONT)::SelectObject(hDC, pManager->GetFont(iFont));
::DrawText(hDC, pstrText, -1, &rc, uStyle | DT_NOPREFIX);
::SelectObject(hDC, hOldFont);
}
void CPaintManagerUI::Init(HWND hWnd)
{
ASSERT(::IsWindow(hWnd));
// Remember the window context we came from
m_hWndPaint = hWnd; //得到句柄
m_hDcPaint = ::GetDC(hWnd); 得到DC
// We'll want to filter messages globally too
m_aPreMessages.Add(this);
}
paintManager维持着当前的句柄和DC 窗口中保存着一份实例, 所有的绘画操作都交给它去处理了
bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
{
CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
const CDuiString& sName = pThis->GetName();
if( sName.IsEmpty() ) return NULL;
// Add this control to the hash list
pManager->m_mNameHash.Set(sName, pThis);
return NULL; // Attempt to add all controls
}
把当前控件加到表里
::SelectObject(hDC, pFontInfo->hFont);
CDuiRect rcWnd;
GetWindowRect(m_hWnd, &rcWnd);
::ClientToScreen(*this, &pt); //这句话加上后 位置就能根据窗口移动的位置而变化了
bkcolor="#FF97C0DA" bkcolor2="#FFB8DFF2" />
bordercolor = "#FF026cb8" bordersize="1">
itemalign="center" 修改list中的body项居中显示
caption="0,0,0,38" 修改为可以鼠标拖动窗体
非客户区自绘:
WM_NC开头的
WM_NCPaint 非客户区自绘的时候会发送这些消息我们只要去重载OnNcPaint方法即可
非客户区里面获取DC用 GetWindowDC()获取画家hDC
beginPaint只有在OnPaint中使用
绘制图片:
CImage成熟的类
CImage m_imgCaption;
CImage m_imgBorder;
CImage m_imgCloseBtn;
CImage m_imgMaxBtn; <atlimage.h>
GetModuleHandle函数得到其中某一模块的句柄
m_imgCaption.LoadFromResource((HINSTANCE)::GetModuleHandle(NULL), IDB_CAPTION); 加载资源
//判断最小化
if(::IsIconic()) 最小化
GetWindowRect
非激活状态即鼠标不再NcActivate
OnNcPaint(0,0);
绘制关闭按钮 禁用状态
CRect rcClosebtn;
rcClosebtn.left = rcWnd.Width()-15-4;
rcClosebtn.right=rcCloseBtn.left+15;
NcMouseMove() WM_NCHITTEST
CPoint pt;
pt.x = LOWORD(lParam);
判断像素点在哪里?
rcCloseBtn.PtInRect(pt)
30
防止系统的
OnNcLButtonDown()
{
WM_NCHITTEST
HTBORDER
}
::SendMEssage(m_hWNd,WM_SYSCOMMAND,SC_CLOSE, 0);
IsZoomed9)
子窗口
comCtrl
子窗口的特有窗口消息
自定义窗口
duilib中:SendNotify 方法
m_pOwner->GetManager()->SendNotify(m_pOwner, _T("menu_Delete"), 0, 0, true);
得到owner的PaintManager 调用其方法发送响应
对于当前的窗口来说:利用自己持有的PaintManager给自己发送Message
m_pm.AddNotifier(this); 消息相应
设置圆角: m_pm.SetRoundCorner(3, 3);
关于duilib中的notify(通知) 处理,一开始我以为也是发送WM_NOTIFY消息去相应Notify()函数后来与同事yangdong交流后发现不是
TNotifyUI Msg;
static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg); 他是直接调用那个函数 |
他是直接去调用那个函数,
The InvalidateRect function adds a rectangle to the specified window's update region.
The update region represents the portion of the window's client area that must be redrawn.
Invalidate()函数的作用是使整个窗口客户区无效,窗口客户无效即需要重绘,这时Window系统会发送一WM_PAINT消息放在应用程序的消息队列中,WM_PAINT消息的优先级很低,所以不会立即重绘
<HorizontalLayout height="20" bkimage="file='2.0_trade_panel_bg_2.png' source='0,0,840,20' ">
<HorizontalLayout bordersize="1" bordercolor="#FFFFFF00">
<Container width="22" height="22" bkimage="file='icon.png' source='0,0,16,16' dest='5,4,21,20' " />
<Text text="2013.12.02持仓:0平均成本:0.00 盈亏:0.00%" font="2" width="178" height="19" textpadding="2,0,2,0" textcolor="#FF447AA1" disabledtextcolor="#FFA7A6AA" align="wrap" />
</HorizontalLayout>
<HorizontalLayout width="100">
<Button tooltip="最小" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='btn_system.png' source='0,0,27,21' " hotimage=" file='btn_system.png' source='27,0,54,21' " pushedimage=" file='btn_system.png' source='54,0,81,21' " focusedtextcolor="#FF000000" pushedtextcolor="#FF000000" hottextcolor="#FF000000"/>
<Button tooltip="最大化" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='btn_system.png' source='0,21,27,42' " hotimage=" file='btn_system.png' source='27,21,54,42' " pushedimage=" file='btn_system.png' source='54,21,81,42' " focusedtextcolor="#FF000000" pushedtextcolor="#FF000000" hottextcolor="#FF000000"/>
<Button name="restorebtn" visible="false" float="true" pos="547,0,0,0" width="27" height="21" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='btn_system.png' source='0,42,27,63' " hotimage="file='btn_system.png' source='27,42,54,63'" pushedimage="file='btn_system.png' source='54,42,81,63' " focusedtextcolor="#FF000000" pushedtextcolor="#FF000000" hottextcolor="#FF000000"/>
<Button tooltip="关闭" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage=" file='btn_system.png' source='0,63,47,84' " hotimage=" file='btn_system.png' source='47,63,94,84' " pushedimage=" file='btn_system.png' source='94,63,141,84' " focusedtextcolor="#FF000000" pushedtextcolor="#FF000000" hottextcolor="#FF000000"/>
</HorizontalLayout>
</HorizontalLayout>
CPaintManagerUI 这个类最重要 所有的绘制都在里面 包括:字体 绘制, 滚动条绘制 所有xml中配置的东西 都在里面 ,他是duilib自绘的关机 , DC 去paint