Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Drawing on transparent window

Reply
Thread Tools

Drawing on transparent window

 
 
ShurikAg@gmail.com
Guest
Posts: n/a
 
      09-15-2006
Hi,

I have this kind of class:

// SplashWnd.cpp : implementation of the CSplashWnd class

//

/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "CapturePrevWnd.h"

#include "Resource.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CSplashWnd class

CCapturePrevWnd* CCapturePrevWnd::m_pSplashWnd = NULL;

CCapturePrevWnd::CCapturePrevWnd()

{

start.SetPoint(0,0);

end.SetPoint(0,0);

}

CCapturePrevWnd::~CCapturePrevWnd()

{

// Clear the static window pointer.

ASSERT(m_pSplashWnd == this);

m_pSplashWnd = NULL;

}

BEGIN_MESSAGE_MAP(CCapturePrevWnd, CWnd)

//{{AFX_MSG_MAP(CSplashWnd)

ON_WM_CREATE()

ON_WM_PAINT()

ON_WM_LBUTTONDOWN()

ON_WM_LBUTTONUP()

ON_WM_MOUSEMOVE()

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

void CCapturePrevWnd::ShowCaptureScreen(CWnd* pParentWnd /*= NULL*/)

{

if (m_pSplashWnd != NULL)

return;

// Allocate a new splash screen, and create the window.

m_pSplashWnd = new CCapturePrevWnd;

if (!m_pSplashWnd->Create(pParentWnd))

delete m_pSplashWnd;

else m_pSplashWnd->UpdateWindow();

}

BOOL CCapturePrevWnd::Create(CWnd* pParentWnd /*= NULL*/)

{

return CreateEx(0,

AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS,
AfxGetApp()->LoadStandardCursor(IDC_CROSS)),

NULL, WS_POPUP | WS_VISIBLE | WS_EX_TRANSPARENT | WS_BORDER |
WS_MAXIMIZE,
0, 0, 0, 0,

pParentWnd->GetSafeHwnd(), NULL);

}

void CCapturePrevWnd::HideCaptureScreen()

{

// Destroy the window, and update the mainframe.

DestroyWindow();

AfxGetMainWnd()->UpdateWindow();

}

void CCapturePrevWnd:ostNcDestroy()

{

// Free the C++ class.

delete this;

}

int CCapturePrevWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

if (CWnd::OnCreate(lpCreateStruct) == -1)

return -1;

// Center the window.

//CenterWindow();

return 0;

}

void CCapturePrevWnd::OnPaint()

{

CRect selRect = GetSelRect();

if(!selRect.IsRectEmpty())

{

CClientDC dc(this);

//dc.SetROP2(R2_NOTXORPEN);

dc.DrawFocusRect(&selRect);

}

}

void CCapturePrevWnd::OnLButtonDown(UINT nFlags, CPoint point)

{

start = end = point;

Invalidate();

UpdateWindow();

}

void CCapturePrevWnd::OnMouseMove(UINT nFlags, CPoint point)

{

switch(nFlags)

{

case MK_LBUTTON:

end = point;

Invalidate();

UpdateWindow();

break;

}

}

void CCapturePrevWnd::OnLButtonUp(UINT nFlags, CPoint point)

{

end = point;

CRect rect = GetSelRect();

if(!rect.IsRectEmpty())

{

CBitmap bitmap;

CClientDC dc(NULL);

CDC memDC;

CBitmap* pOldBitmap;

memDC.CreateCompatibleDC(&dc);

bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() );

pOldBitmap = memDC.SelectObject(&bitmap);

memDC.BitBlt(0, 0, rect.Width()-2,rect.Height()-2, &dc, rect.left+1,
rect.top+1, SRCCOPY);




OpenClipboard() ;

EmptyClipboard() ;

SetClipboardData (CF_BITMAP, bitmap.GetSafeHandle() ) ;

CloseClipboard () ;

memDC.SelectObject(pOldBitmap);

bitmap.Detach();

}

HideCaptureScreen();

}

CRect CCapturePrevWnd::GetSelRect()

{

return CRect(min(start.x,end.x), min(start.y,end.y),

max(start.x,end.x), max(start.y,end.y));

}



this class is suppose to give an ability to draw rectangle on the
desktop
(on top of everything).

All works well except: when I'm drawing the rectangle with mouse the
transparent window doesn't remove the old, already drawn, rectangles in
order
to draw a new one with right dimensions.

All rectangles from every redraw are staing on the window.

How do I solve this problem?

 
Reply With Quote
 
 
 
 
BigBrian
Guest
Posts: n/a
 
      09-15-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have this kind of class:
>
> implementation of the CSplashWnd class


What is CSplashWnd? It's not part of the standard.

> /////////////////////////////////////////////////////////////////////////////
> #include "stdafx.h"


Oh, must be some sort of Windows header.

> this class is suppose to give an ability to draw rectangle on the
> desktop
> (on top of everything).
>
> All works well except: when I'm drawing the rectangle with mouse the
> transparent window doesn't remove the old, already drawn, rectangles in
> order
> to draw a new one with right dimensions.
>
> All rectangles from every redraw are staing on the window.
>
> How do I solve this problem?


By asking in a windows group. This is off topic here.

-Brian

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Guide to the standard library? Library for drawing in GUIs?drawing inbrowsers? defn noob Java 1 06-28-2008 02:50 AM
System.Drawing.Image.Save() on Transparent GIF =?Utf-8?B?RGFsZQ==?= ASP .Net 4 10-23-2006 05:11 AM
funny drawing software:ScreenPen,drawing directly on screen! yyzzbb@sina.com Digital Photography 0 02-04-2006 12:31 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com ASP .Net 1 01-09-2006 09:55 PM
problem system.drawing transparent web images eruess ASP .Net 0 08-08-2003 05:58 PM



Advertisments