Thread: Windows CE & Bitmap & ( DCscroll or scrollWindow ? )

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    2

    Windows CE & Bitmap & ( DCscroll or scrollWindow ? )

    Hello,

    In my Research project, i'm trying to draw a bitmap and scrolling it with the mouse.

    I don't have problem to print a bitmap on a screen.

    But my problem is to scroll it, I tried the ScrollDC function and ScrollWindow, but nothing happen !


    I would like to know how to scroll a bitmap that are printed on the screen ? ( I'm trying to avoid the function "BitBlt" because I can see the refresh )


    My first test was :

    detecting the new position of the mouse with "onMouseMove" and calling invalidate function.

    And in the function OnPaint() I added the scrollDC function, but I found that the screen is erased by calling the function invalidate. So my first test failed.


    My second test was :
    on the function "onMouseMove", I called the function ScrollWindow(2,2,NULL,NULL);

    but nothing happen


    My third test was :
    on the function "onMouseMove", I called the function :
    dc.ScrollDC(5,5,clientRectScroll,clientRectclip,NU LL,NULL);

    ( clientrectscroll and clientrectclip are at the screen size )


    but nothing happen!

    I really don't understand why!


    Last informations : I'm printing the bitmap in the derived class of CWnd.


    I don't know if someone can help me, but i'm lost :'(

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    if you have issues with flicker or shearing with BitBlt() it may be that you ned to double buffer (I have never done this without double buffering, which I have posted code here for many times).

    read this MSDN link, it shows the basics and post again (with actual code) if you have problems;

    How to Scroll a Bitmap (Windows)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    2
    hello thx for the help!

    Finally I chosse to use a buffer as you said.

    But now I got sometime this exception :

    Unhandled exception at 0x0004bf14 in BITMAPLOADER.exe: 0xC0000005: Violation d'accès lors de la lecture de l'emplacement 0x00000004 :
    Code:
     
    BOOL CGdiObject::DeleteObject()
    {
    	if (m_hObject == NULL)             <========= HERE
    		return FALSE;
    	return ::DeleteObject(Detach());
    }
    Do you know where does it come from ?


    My blitter function :
    Code:
     
    void Blitter::BlitTo (CDC& pDC){
    	//
    	CDC dcMemory;
    	//
    	CBitmap   *spBitMap= CBitmap::FromHandle(_bmp->_hBitmap);
    
    	// create a new dc :
    	dcMemory.CreateCompatibleDC(&pDC);
    	// add the bitmap :
    	dcMemory.SelectObject(spBitMap);
    	//
    	// update the screen with this :
    	pDC.BitBlt(_xDst, _yDst, _width-_xSrc, _height-_ySrc,&dcMemory,_xSrc, _ySrc, _mode);
    
    	spBitMap->DeleteObject();
    	dcMemory.DeleteDC();
    
    
    	//delete spBitMap;
    
    
    
    }

    The creation of my buffer :
    Code:
     
    int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) {
    	CDC *dc = GetDC();   // this is the screen DC
    	m_MemDC.CreateCompatibleDC(dc);
    	m_Bitmap.CreateCompatibleBitmap(dc,WINDOW_W,WINDOW_H);
    	m_MemDC.SelectObject(m_Bitmap);
    	ReleaseDC(dc);
    
    	return 0;
    }
    my paint function called with RedrawWindow() :

    Code:
     
    void CChildView::OnPaint() {
    	CPaintDC dc(this); 
    	dc.BitBlt(0,0,WINDOW_W,WINDOW_H,&m_MemDC,0,0,SRCCOPY);
    	DeleteDC(dc);
    
    }

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    When you use SelectObject() you 'push' a GDI object into the DC, pushing out the current GDI object.

    So when you SelectObject() your bitmap the current bitmap is pushed out (as you just created the DC it is a default 1x1 monochrome bitmap).

    Some GDI objects can not be deleted while the DC they are selected into has scope (is valid) as this would leave the DC without a pen, brush or bitmap (to do 'standard' drawing with).

    So you have to put the Dc back to the original state (push the original GDI back in) before you can delete the DC or any GDI objects.

    You have to 'catch' the current GDI object when you use SelectObject() and SelectObject() these original/default objects back in before you clean up your GDIs.

    Code:
    //something like...
    CBitmap *pOrigBMP = (CBitmap*)dcMemory.SelectObject(spBitMap);
    //do drawing
    //put DC back to default state
    dcMemory.SelectObject(pOrigBMP);
    //clean up
    spBitMap->DeleteObject();
    dcMemory.DeleteDC();
    NOTE: 'Delete' any DCs you 'create', 'Release' and DCs you 'Get' (you are Releasing in one method)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is ScrollWindow() ?
    By Newbeee in forum Windows Programming
    Replies: 1
    Last Post: 07-04-2006, 06:47 PM
  2. Bitmap...Please Help!?
    By oneevilchicken in forum C Programming
    Replies: 3
    Last Post: 10-01-2003, 12:21 AM
  3. ScrollWindow()
    By Ariod in forum Windows Programming
    Replies: 7
    Last Post: 08-25-2003, 10:08 AM
  4. bitmap in windows
    By samudrala_99 in forum Windows Programming
    Replies: 2
    Last Post: 10-03-2002, 12:54 PM
  5. How I can dispaly the windows bitmap files in 800*600 256 color mode?
    By hadizadeh in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-15-2001, 05:31 AM