[英]Why does DrawImageUnscaled cause flickering when used from WM_NCPAINT?
[英]Should I receive WM_NCPAINT when there is no client area?
我想在自定義控件中了解一些內容。 我處理WM_NCCALCSIZE將客戶區設置為整個窗口,換句話說,沒有非客戶區。 我期望不會收到WM_NCPAINT,但是每次窗口大小更改時我仍然會收到它。 這是我的WndProc代碼:
if (m.Msg == Win32Calls.WM_NCPAINT)
{
// I don't know why WM_NCPAINT is sent when WM_NCCALCSIZE has stated that there is no client area, so here is my workaround to stop processing here
if (Bounds.Size == ClientSize)
return;
// Draw borders if any
if (handled)
return;
}
else if (m.Msg == Win32Calls.WM_NCCALCSIZE)
{
if (m.WParam != IntPtr.Zero)
{
Win32Calls.NCCALCSIZE_PARAMS csp;
csp = (Win32Calls.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(Win32Calls.NCCALCSIZE_PARAMS));
Rectangle rect = new Rectangle(csp.rgrc0.Left, csp.rgrc0.Top,
csp.rgrc0.Right - csp.rgrc0.Left, csp.rgrc0.Bottom - csp.rgrc0.Top);
_drawManager.NcCalcSize(ref rect);
csp.rgrc0.Left = rect.X;
csp.rgrc0.Right = rect.X + rect.Width;
csp.rgrc0.Top = rect.Y;
csp.rgrc0.Bottom = rect.Y + rect.Height;
Marshal.StructureToPtr(csp, m.LParam, false);
}
}
因此,當發生調整大小時,我檢查並正確接收到WM_NCCALCSIZE,_drawManager.NcCalcSize不修改“ rect”,然后接收到WM_NCPAINT,我不得不比較邊界和客戶端rect以檢查是否應進行任何非客戶端繪畫。 這正常嗎?
我的猜測是
1)Windows更容易以這種方式執行此操作(缺少邊框的特殊情況),不發送它的好處僅是微不足道的性能提升。
2)由於某些程序在處理程序中做得太多,因此某些程序需要發送消息,因此現在無法更改。 而且,如果您閱讀Raymond Chen的博客,您將知道這對Windows api團隊非常重要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.