Drawing on transparent window

Discussion in 'C++' started by ShurikAg@gmail.com, Sep 15, 2006.

  1. Guest

    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::postNcDestroy()

    {

    // 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?
    , Sep 15, 2006
    #1
    1. Advertising

  2. BigBrian Guest

    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
    BigBrian, Sep 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eruess
    Replies:
    0
    Views:
    456
    eruess
    Aug 8, 2003
  2. Replies:
    1
    Views:
    618
    Kevin Spencer
    Jan 9, 2006
  3. kishkin
    Replies:
    2
    Views:
    370
    Diez B. Roggisch
    Jan 30, 2006
  4. =?Utf-8?B?RGFsZQ==?=

    System.Drawing.Image.Save() on Transparent GIF

    =?Utf-8?B?RGFsZQ==?=, Oct 20, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    2,321
    Steven Cheng[MSFT]
    Oct 23, 2006
  5. defn noob
    Replies:
    1
    Views:
    364
    Mark Space
    Jun 28, 2008
Loading...

Share This Page