NO

Author Topic: Use Windows Vista Double Buffer in WM_PAINT. (Usar Doble Buffer d Windows Vista)  (Read 5117 times)

lucindom

  • Guest
1) From PEllesC,  Create a Windows Project (Desde Pelles, crear un Proyecto Windows).
2) after the last #include directive, add the next (Despues de la ultima directiva #include, agregar)
     #include <uxtheme.h>
     #pragma comment(lib, "uxtheme.lib")
3) Declare the bIsbufered Variable:  static BOOL IsBufered = FALSE;
4) To this Option dont crash in Windows Xp, follow this steps ().
     3.1.- Open the Menu:  Project -> Project Options (Abrir en el Menu estas opciones).
     3.2.- In the Tab <Linker>, add the uxtheme.dll in the "Dll Files with delayed loading".
5) Add the Next Prototypes:
       static LRESULT Main_OnCreate(HWND, LPCREATESTRUCT);
       void MiPaint( HDC , RECT,  BOOL );
6) Add the Next Message Cracker: HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
7) Change the Main_OnDestroy: static void Main_OnDestroy(HWND hwnd){
    if (IsBufered) BufferedPaintUnInit(); PostQuitMessage(0); }
8) Put the Main_OnCreate: static LRESULT Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpstr) {
    IsBufered = (S_OK == BufferedPaintInit() );
    return 1;}
9) Change the Main_OnPaint:  static void Main_OnPaint(HWND hwnd){
      PAINTSTRUCT ps; RECT rc;GetClientRect(hwnd, &rc);
      HDC hdc = BeginPaint(hwnd, &ps);
         if (IsBufered){
            HDC hNewDC;         
            HPAINTBUFFER hBufferedPaint =  BeginBufferedPaint(hdc, &rc, BPBF_COMPATIBLEBITMAP, NULL, &hNewDC);
            if (hBufferedPaint) {
               MiPaint(hNewDC, rc, TRUE);
               EndBufferedPaint(hBufferedPaint, TRUE);
            } else{
               MiPaint(hdc, rc, FALSE);
            }
         } else {
            MiPaint(hdc, rc, FALSE);
         }
      EndPaint(hwnd, &ps); }
9) Add your Paint Function:
     void MiPaint( HDC thdc, RECT trc,  BOOL bBuffered ) {
           int iMonX = GetDeviceCaps(thdc, HORZRES);
           int iMonY = GetDeviceCaps(thdc, VERTRES);
           PatBlt(memoriDC, 0, 0, iMonX ,iMonY , WHITENESS);
           TextOut.....................
            ..... some code to show in the window.................
     }