C 和 Windows GDI 中的雙緩衝 *framework* (Double-buffering *framework* in C and Windows GDI)


問題描述

C 和 Windows GDI 中的雙緩衝 framework (Double‑buffering framework in C and Windows GDI)

Background: My client has a very extensive proprietary forms library which is effectively implemented in C (actually, it's a proprietary object‑oriented language that basically wraps Windows controls and interacts with them with SendMessage()SetStyle(), etc.)

Problem I want to solve: Whenever I drag/resize a top‑level window (or drag a splitter) in an app implemented in the above framework, there is massive flicker. The top‑level window is repainted, and any controls it contains repaint themselves.

Question 1: Is there a way to surgically introduce double‑buffering into the forms library. In particular, I want to know if I can implement double‑buffering using standard Windows GDI functions.

For example, if I could cause the top‑level windows to be double‑buffered such that all child windows of the top‑level window are automatically drawn double‑buffered as well. An even better alternative would be to be able to introduce double‑buffering on any arbitrary window and have all its children inherit this.

The best solution would somehow cause the BeginPaint() function for child controls to return a handle to the DC of the offscreen back buffer so that I don't have to write special code for each individual control class.

Question 2: Is there a way (such as a set of flags) to cause generic Windows controls (EDIT, BUTTON, and so on) to draw themselves double‑buffered? This would be a worse solution than a more generic approach that would just seamlessly give them the back buffer to draw on, but it might also be acceptable.

All help greatly appreciated. Please let me know if I can clarify anything for you.


參考解法

方法 1:

Look into WS_EX_COMPOSITED, which is an extended window style that turns on double‑buffering for the window.  It may be enough to set this style on the parent of the controls.

方法 2:

You actually might be able to wrap all your window drawing code with C that executes C#, and that way there is already a double‑buffered implementation for you.  

How to eliminate flicker in Windows.Forms custom control when scrolling?

(by 0xbe5077edAdrian McCarthyMagn3s1um)

參考文件

  1. Double‑buffering framework in C and Windows GDI (CC BY‑SA 3.0/4.0)

#gdi #winapi #gdi+ #C #Windows






相關問題

繪製鼠標光標 (Draw mouse cursor)

C 和 Windows GDI 中的雙緩衝 *framework* (Double-buffering *framework* in C and Windows GDI)

一個進程的 GDI 洩漏會影響其他進程嗎? (Can GDI leaks from one process affect other processes?)

BeginPath Textout EndPath 繪製反轉文本 (BeginPath Textout EndPath draws inverted text)

監控GDI通話 (Monitoring GDI calls)

如何捕獲(並希望修復)GDI 資源洩漏 (How to catch (and hopefully fix) a GDI resource leak)

如何使用 GDI(+) 在內存中渲染漸變 (How to render a gradient in memory using GDI(+))

使用 BITMAP::bmBits 與 GetDIBits 有什麼區別? (What is the difference between using BITMAP::bmBits vs GetDIBits?)

獲取背景窗口的縮略圖 (Get Thumbnail of background window)

AlphaBlend 返回“假”的原因可能是什麼 (What could be the reason for AlphaBlend to return 'false')

在 C++ 中查找像素 RGB 數據的最快方法是什麼? (What is the fastest method to lookup pixel RGB data in C++?)

逐行讀取文本框並將其視為單獨的文本 (Read a textbox line by line and treat it as a separate text)







留言討論