473,383 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

VB6 + VC++ : how to avoid flicker?

Hi,

I am trying to avoid flicker in this situation:

1) I create a simple VB6 Window application (a void form) and I define
this code for the form (that has the autoredraw property set to false):

'NOTE: this declaration is in another file
Declare Sub InstallMsgHandler Lib _
"E:\TestMsgHandler\Debug\TestMsgHandler.dll" (ByVal lpPC As Long)

Private Sub Form_Load()
InstallMsgHandler (Me.hWnd)
End Sub

Private Sub Form_Paint()
Dim lRet As Long
Dim rectClient As RECT
lRet = GetClientRect(Me.hWnd, rectClient)

Dim hTempDC As Long
hTempDC = GetDC(Me.hWnd)
Dim hbr, hbrOld As Long
hbr = CreateSolidBrush(RGB(255, 0, 0)) 'red
lRet = FillRect(hTempDC, rectClient, hbr)
lRet = DeleteObject(hbr)
lRet = ReleaseDC(Me.hWnd, hTempDC)
End Sub

2) I create a MFC dll and I add a CWnd derived class that subclass the
VB form window:

//memdc.h - //header/implementation for double buffer drawing : see
CODEGURU or CODEPROJECT

#ifndef _MEMDC_H_
#define _MEMDC_H_

//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: ke****@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// This class implements a memory Device Context

class CMemDC : public CDC {
private:
CBitmap* m_bitmap;
CBitmap* m_oldBitmap;
CDC* m_pDC;
CRect m_rcBounds;
public:
CMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
{
CreateCompatibleDC(pDC);
m_bitmap = new CBitmap;
m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(),
rcBounds.Height());
m_oldBitmap = SelectObject(m_bitmap);
m_pDC = pDC;
m_rcBounds = rcBounds;
}
~CMemDC()
{
m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(),
m_rcBounds.Height(),
this, m_rcBounds.left, m_rcBounds.top, SRCCOPY);
SelectObject(m_oldBitmap);
if (m_bitmap != NULL) delete m_bitmap;
}
CMemDC* operator->() {
return this;
}
};

#endif

// CMyCWnd.h

class CMyCWnd : public CWnd
{
DECLARE_DYNAMIC(CMyCWnd)

public:
CMyCWnd();
virtual ~CMyCWnd();

bool init(HWND hwnd);

protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};

// MyCWnd.cpp : implementation file
//

#include "stdafx.h"
#include "TestMsgHandler.h"
#include "MyCWnd.h"

#include "memdc.h"

extern "C" void WINAPI InstallMsgHandler(HWND hwnd)
{
static bool bAlreadyInit = false;
if (!bAlreadyInit)
{
static CMyCWnd wnd;
bAlreadyInit = wnd.init(hwnd);
}
}

// CMyCWnd

IMPLEMENT_DYNAMIC(CMyCWnd, CWnd)
CMyCWnd::CMyCWnd()
{
}

CMyCWnd::~CMyCWnd()
{
}

bool CMyCWnd::init(HWND hwnd)
{
return SubclassWindow(hwnd) != 0;
}

BEGIN_MESSAGE_MAP(CMyCWnd, CWnd)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

void CMyCWnd::OnPaint()
{
CRect rectClient;
GetClientRect(&rectClient);

CPaintDC dc(this); // device context for painting
CMemDC memdc(&dc, rectClient);

Default(); // this call the visual basic application redraw.

rectClient.DeflateRect(rectClient.Width()/4, rectClient.Height()/4);
CBrush Brush(RGB(0x80,0x80,0x80));
memdc.FillRect(&rectClient, &Brush);
}

BOOL CMyCWnd::OnEraseBkgnd(CDC* /*pDC*/)
{
return FALSE;
}

Running this example I have that VC++ draws on the memory buffer while
VB6 draws on the screen. How may I force VB6 to draw on the replaced
in-memory bitmap ?

Thanks for help.
Marco.

--
For direct reply change underscore to dot

Nov 17 '05 #1
4 6317
Marco Segurini wrote:

Running this example I have that VC++ draws on the memory buffer while
VB6 draws on the screen. How may I force VB6 to draw on the replaced
in-memory bitmap ?


And why are you asking in the managed C++ group !?

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
Nov 17 '05 #2
Jochen Kalmbach wrote:
Marco Segurini wrote:
Running this example I have that VC++ draws on the memory buffer while
VB6 draws on the screen. How may I force VB6 to draw on the replaced
in-memory bitmap ?

And why are you asking in the managed C++ group !?


Is this group only for managed c++ questions?

Marco.
--
For direct reply change underscore to dot

Nov 17 '05 #3
Marco Segurini wrote:
And why are you asking in the managed C++ group !?


Is this group only for managed c++ questions?


"microsoft.public.dotnet.languages.vc" is for managaed C++
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
Nov 17 '05 #4
Hi,

You can use Win32 API in VB and VC.

LockWindowUpdate()

Regards, Amit

Marco Segurini <ma************@jumpy.it> wrote in message news:<u3**************@TK2MSFTNGP12.phx.gbl>...
Hi,

I am trying to avoid flicker in this situation:

1) I create a simple VB6 Window application (a void form) and I define
this code for the form (that has the autoredraw property set to false):

'NOTE: this declaration is in another file
Declare Sub InstallMsgHandler Lib _
"E:\TestMsgHandler\Debug\TestMsgHandler.dll" (ByVal lpPC As Long)

Private Sub Form_Load()
InstallMsgHandler (Me.hWnd)
End Sub

Private Sub Form_Paint()
Dim lRet As Long
Dim rectClient As RECT
lRet = GetClientRect(Me.hWnd, rectClient)

Dim hTempDC As Long
hTempDC = GetDC(Me.hWnd)
Dim hbr, hbrOld As Long
hbr = CreateSolidBrush(RGB(255, 0, 0)) 'red
lRet = FillRect(hTempDC, rectClient, hbr)
lRet = DeleteObject(hbr)
lRet = ReleaseDC(Me.hWnd, hTempDC)
End Sub

2) I create a MFC dll and I add a CWnd derived class that subclass the
VB form window:

//memdc.h - //header/implementation for double buffer drawing : see
CODEGURU or CODEPROJECT

#ifndef _MEMDC_H_
#define _MEMDC_H_

//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email: ke****@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// This class implements a memory Device Context

class CMemDC : public CDC {
private:
CBitmap* m_bitmap;
CBitmap* m_oldBitmap;
CDC* m_pDC;
CRect m_rcBounds;
public:
CMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
{
CreateCompatibleDC(pDC);
m_bitmap = new CBitmap;
m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(),
rcBounds.Height());
m_oldBitmap = SelectObject(m_bitmap);
m_pDC = pDC;
m_rcBounds = rcBounds;
}
~CMemDC()
{
m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(),
m_rcBounds.Height(),
this, m_rcBounds.left, m_rcBounds.top, SRCCOPY);
SelectObject(m_oldBitmap);
if (m_bitmap != NULL) delete m_bitmap;
}
CMemDC* operator->() {
return this;
}
};

#endif

// CMyCWnd.h

class CMyCWnd : public CWnd
{
DECLARE_DYNAMIC(CMyCWnd)

public:
CMyCWnd();
virtual ~CMyCWnd();

bool init(HWND hwnd);

protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};

// MyCWnd.cpp : implementation file
//

#include "stdafx.h"
#include "TestMsgHandler.h"
#include "MyCWnd.h"

#include "memdc.h"

extern "C" void WINAPI InstallMsgHandler(HWND hwnd)
{
static bool bAlreadyInit = false;
if (!bAlreadyInit)
{
static CMyCWnd wnd;
bAlreadyInit = wnd.init(hwnd);
}
}

// CMyCWnd

IMPLEMENT_DYNAMIC(CMyCWnd, CWnd)
CMyCWnd::CMyCWnd()
{
}

CMyCWnd::~CMyCWnd()
{
}

bool CMyCWnd::init(HWND hwnd)
{
return SubclassWindow(hwnd) != 0;
}

BEGIN_MESSAGE_MAP(CMyCWnd, CWnd)
ON_WM_PAINT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

void CMyCWnd::OnPaint()
{
CRect rectClient;
GetClientRect(&rectClient);

CPaintDC dc(this); // device context for painting
CMemDC memdc(&dc, rectClient);

Default(); // this call the visual basic application redraw.

rectClient.DeflateRect(rectClient.Width()/4, rectClient.Height()/4);
CBrush Brush(RGB(0x80,0x80,0x80));
memdc.FillRect(&rectClient, &Brush);
}

BOOL CMyCWnd::OnEraseBkgnd(CDC* /*pDC*/)
{
return FALSE;
}

Running this example I have that VC++ draws on the memory buffer while
VB6 draws on the screen. How may I force VB6 to draw on the replaced
in-memory bitmap ?

Thanks for help.
Marco.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mp3boss | last post by:
I am updating a string in the format MM:SS every second using the On_Timer event in Access97 by changing the caption of a label. Even though I'm using 8point text, the box sometimes flickers...
2
by: mhansemann | last post by:
I'm a C# (but not programming in general) novice, but I couldn't find any answer to this elsewhere. I'm trying to make a text scroll on the form. I thought this was a good example to get started...
1
by: Alessandro Fragnani | last post by:
Hi, I would like to know how to avoid flicker while adding controls to a panel. I couldn´t find any kind of "BeginUpdate/EndUpdate" on it. Thanks in advance Alessandro
3
by: Per Dunberg | last post by:
Hi all, I have to develop a "skinned" application and I have a problem with the graphics. When a form is loaded and displayed there's aways a flicker where all the controls are located on the...
7
by: Frederico Pissarra | last post by:
Recently I tried to use -G5 option on CL compiler (from Visual Studio 2005)... To my surprise, there is no processor specific optimizations anymore! Is that correct? Is so, why? s Fred
3
by: seamlyne | last post by:
The first method I ever used for multiple state buttons was to create a graphic for each button for each state: AboutUs_on, AbooutUs_over, AboutUs_out, etc. That works great when there are just a...
1
by: Wayne | last post by:
I've noticed some screen flicker when using Access 2003 under Vista and I'm curious as to whether this is a bug or peculiar to my machine. In design view, if I make changes to a form and then...
4
by: Frank Rizzo | last post by:
Hello, I inherited a large Winforms project that is suffering from excessive flicker when switching between portions of the application. I've noticed that most parts of the application (user...
0
by: crankeboy | last post by:
Hi Folks, My setup: Visual Studio Express 2008, VC++, .NET, BitBlt Here is a summary of the problem: - I am trying to copy a bitmap of my main form into a picture box. - To do this, I bitblt...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.