Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

VB6 + VC++ : how to avoid flicker?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marco Segurini - 03 May 2004 16:22 GMT
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:  keithr@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.

Signature

For direct reply change underscore to dot

Jochen Kalmbach - 03 May 2004 17:05 GMT
> 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 !?

Signature

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/

Marco Segurini - 04 May 2004 07:50 GMT
>>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.

Signature

For direct reply change underscore to dot

Jochen Kalmbach - 04 May 2004 08:48 GMT
>> 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++

Signature

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/

AMIT - 04 May 2004 13:20 GMT
Hi,

You can use Win32 API in VB and VC.

LockWindowUpdate()

Regards, Amit

> Hi,
>
[quoted text clipped - 163 lines]
> Thanks for help.
> Marco.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.