Click here to Skip to main content
15,914,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Connecting to FTP site Pin
Mark Salsbery17-Jun-07 9:05
Mark Salsbery17-Jun-07 9:05 
QuestionHow to do transparent color in the CBitmapButton? [modified] Pin
Romiks17-Jun-07 7:21
Romiks17-Jun-07 7:21 
AnswerRe: How to do transparent color in the CBitmapButton? Pin
Mark Salsbery17-Jun-07 9:15
Mark Salsbery17-Jun-07 9:15 
QuestionSome video effects on directshow Pin
Akin Ocal17-Jun-07 3:08
Akin Ocal17-Jun-07 3:08 
QuestionEditing/Changing Default Command Handlers Pin
Abhijeet Pathak17-Jun-07 1:57
Abhijeet Pathak17-Jun-07 1:57 
Questiondouble buffering issue... Pin
eli1502197917-Jun-07 1:32
eli1502197917-Jun-07 1:32 
GeneralRe: double buffering issue... Pin
Matthew Faithfull17-Jun-07 2:38
Matthew Faithfull17-Jun-07 2:38 
AnswerRe: double buffering issue... [modified] Pin
Mark Salsbery17-Jun-07 15:43
Mark Salsbery17-Jun-07 15:43 
Here's an example of a double-buffered bitmap static control class...
//------------------------------
// DblBufferedStatic.h
 
#pragma once
 
// CDblBufferedStatic
 
class CDblBufferedStatic : public CStatic
{
   DECLARE_DYNAMIC(CDblBufferedStatic)
 
protected:
   HBITMAP hStaticBitmap;
   CSize BackBufferSize;
   CDC BackBufferDC;
   CBitmap BackBufferBitmap;
 
   void InitBackBuffer();
 
public:
   void RedrawBackBuffer();
 
public:
   CDblBufferedStatic();
   virtual ~CDblBufferedStatic();
 
protected:
   DECLARE_MESSAGE_MAP()
public:
   afx_msg void OnPaint();
   afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
 
 
//------------------------------
// DblBufferedStatic.cpp
 
// DblBufferedStatic.cpp : implementation file
//
 
#include "stdafx.h"
#include "MyApp.h"
#include "DblBufferedStatic.h"
#include ".\dblbufferedstatic.h"
 
// CDblBufferedStatic
 
IMPLEMENT_DYNAMIC(CDblBufferedStatic, CStatic)
 
CDblBufferedStatic::CDblBufferedStatic()
{
   hStaticBitmap = 0;
}
 
CDblBufferedStatic::~CDblBufferedStatic()
{
}
 
BEGIN_MESSAGE_MAP(CDblBufferedStatic, CStatic)
   ON_WM_PAINT()
   ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
 
void CDblBufferedStatic::InitBackBuffer()
{
   // Get a handle to the bitmap associated with this control
   hStaticBitmap = GetBitmap();
 
   if (hStaticBitmap)
   {
      // Get the bitmap's dimensions
      BITMAP bitmapstruct;
      ::GetObject(hStaticBitmap, sizeof(BITMAP), &bitmapstruct);
      BackBufferSize.cx = bitmapstruct.bmWidth;
      BackBufferSize.cy = bitmapstruct.bmHeight;
 
      // Create the background buffer (DC and bitmap)
      CWindowDC WindowDC(this);
      BackBufferDC.CreateCompatibleDC(&WindowDC);
      BackBufferBitmap.CreateCompatibleBitmap(&WindowDC, BackBufferSize.cx, BackBufferSize.cy);
      <code>//*edit* removed BackBufferBitmap.GetObject(sizeof(BITMAP), &bitmapstruct);</code>
      BackBufferDC.SelectObject(&BackBufferBitmap);
   }
}
 
void CDblBufferedStatic::RedrawBackBuffer()
{
   // Refresh (redraw) contents of background buffer
 
   if (hStaticBitmap)
   {
      // Draw original bitmap to offscreen buffer
      CDC TempDC;
      TempDC.CreateCompatibleDC(&BackBufferDC);
      CBitmap SrcBitmap;
      SrcBitmap.Attach(hStaticBitmap);
      CBitmap *pOldBitmap = TempDC.SelectObject(&SrcBitmap);
      BackBufferDC.BitBlt(0, 0, BackBufferSize.cx, BackBufferSize.cy, &TempDC, 0, 0, SRCCOPY);
      TempDC.SelectObject(pOldBitmap);
      SrcBitmap.Detach();
 
<code>
      //**
      //** Do your drawing on top of the bitmap here
      //**  (Draw on BackBufferDC) 
      //**
 
      CRect CorridorRect;
      static int x = 0;
      // Set attributes of the DC
      BackBufferDC.SetTextColor(RED_COLOR);
      BackBufferDC.SetBkMode(TRANSPARENT);
      GetClientRect(&CorridorRect);
      szCaption.Format(_T("Test %d") , x++);
      BackBufferDC.ExtTextOut(CorridorRect.left, CorridorRect.top + 30 , ETO_OPAQUE , NULL , szCaption , NULL);
      DrawIcon(BackBufferDC.m_hDC, CorridorRect.left , CorridorRect.top  , m_hUavInsideAtolCorridorIcon);</code>   
   }
}
 
// CDblBufferedStatic message handlers
 
void CDblBufferedStatic::OnPaint()
{
   if (hStaticBitmap == 0)
      InitBackBuffer();
 
   if (hStaticBitmap)
   {
      // Refresh the background buffer
      RedrawBackBuffer();
 
      // Blt the background buffer to the screen
      CPaintDC dc(this);
      dc.BitBlt(0, 0, BackBufferSize.cx, BackBufferSize.cy, &BackBufferDC, 0, 0, SRCCOPY);
   }
   else
   {
      CStatic::OnPaint();
   }
}
 
BOOL CDblBufferedStatic::OnEraseBkgnd(CDC* pDC)
{
   return TRUE;//CStatic::OnEraseBkgnd(pDC);
}

If you make your m_AtolCorridorBitmap a CDblBufferedStatic object, then you can do this in
response to the timer message:
void Frm_WkAtol::OnTimer(UINT_PTR nIDEvent)
{
   // cause the bitmap to redraw itself
   m_AtolCorridorBitmap.Invalidate();
   m_AtolCorridorBitmap.UpdateWindow();
 
   CDialog::OnTimer(nIDEvent);
}

This should be flicker free Smile | :)

Hope you can extract something useful from this!
MArk



-- modified at 11:10 Monday 18th June, 2007
*edit* removed line that was there for testing Roll eyes | :rolleyes:

"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

GeneralRe: double buffering issue... Pin
eli1502197917-Jun-07 23:11
eli1502197917-Jun-07 23:11 
GeneralRe: double buffering issue... Pin
eli1502197918-Jun-07 23:09
eli1502197918-Jun-07 23:09 
GeneralRe: double buffering issue... Pin
Mark Salsbery19-Jun-07 6:21
Mark Salsbery19-Jun-07 6:21 
GeneralRe: double buffering issue... Pin
eli1502197919-Jun-07 19:07
eli1502197919-Jun-07 19:07 
GeneralRe: double buffering issue... Pin
Mark Salsbery19-Jun-07 20:11
Mark Salsbery19-Jun-07 20:11 
GeneralRe: double buffering issue... Pin
eli1502197920-Jun-07 1:05
eli1502197920-Jun-07 1:05 
QuestionHow to change display properties of a computer through code? Pin
Sameer_Thakur17-Jun-07 0:18
Sameer_Thakur17-Jun-07 0:18 
AnswerRe: How to change display properties of a computer through code? Pin
Hans Ruck17-Jun-07 20:22
Hans Ruck17-Jun-07 20:22 
GeneralRe: How to change display properties of a computer through code? Pin
Sameer_Thakur18-Jun-07 1:09
Sameer_Thakur18-Jun-07 1:09 
Questionsend number to speaker Pin
SYS-MAN16-Jun-07 22:17
SYS-MAN16-Jun-07 22:17 
AnswerRe: send number to speaker Pin
azonenberg17-Jun-07 7:54
azonenberg17-Jun-07 7:54 
QuestionThreads and mutexes Pin
Cyrilix16-Jun-07 21:43
Cyrilix16-Jun-07 21:43 
AnswerRe: Threads and mutexes Pin
Matthew Faithfull17-Jun-07 0:45
Matthew Faithfull17-Jun-07 0:45 
GeneralRe: Threads and mutexes Pin
Cyrilix17-Jun-07 7:02
Cyrilix17-Jun-07 7:02 
GeneralRe: Threads and mutexes Pin
Matthew Faithfull17-Jun-07 10:11
Matthew Faithfull17-Jun-07 10:11 
GeneralRe: Threads and mutexes [modified] Pin
Cyrilix17-Jun-07 11:25
Cyrilix17-Jun-07 11:25 
GeneralRe: Threads and mutexes Pin
Bram van Kampen17-Jun-07 15:00
Bram van Kampen17-Jun-07 15:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.