[gdi] Erasing Window
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: [gdi] Erasing Window

  1. #1
    Join Date
    May 2009
    Posts
    14

    [gdi] Erasing Window

    Hello everyone!
    My problem is this:
    Code:
    case WM_PAINT:
    		{
    			PAINTSTRUCT ps;
    			HDC hdc = BeginPaint(imagine_aux, &ps);
    
    			
    				
    			        RestoreDC(hdc,-1);//reinitializez fereastra, cum era inainte de desenat
    				
    				HDC hdcMem = CreateCompatibleDC(hdc);
    				SelectObject(hdcMem, imagine_bmp);
    
    				GetObject(imagine_bmp, sizeof(bm), &bm);
    
    				BitBlt(hdc, image_x, image_y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);//redesenez imaginea
    
    				//SelectObject(hdcMem, hbmOld);
    				DeleteDC(hdcMem);
    		
    			EndPaint(hwnd, &ps);
    			break;
    		}
    I am sending InvalidateRect from another function. What i want to do is this:
    Erase the current window (imagine_aux), then send RestoreDc to get the initial image.
    So after a HBITMAP was loaded, i save the dc, when it was moved, i simply want to delete everything and redraw the bitmap in the new position.
    The bitmap loads, the image is moved, but the window isnt't reinitialised , so i get the trail.
    Last edited by zorro59; June 21st, 2010 at 06:01 AM.

  2. #2
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    Edit now the window is erased, but i lose all the drawing =))
    The problem is with savedc / restoredc. Save dc returns 0.
    Last edited by zorro59; June 21st, 2010 at 06:00 AM.

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    Re: [gdi] Erasing Window

    Just looking at your code, everything looks OK except the RestoreDC. That should only be called when a corresponding SaveDC has been called first, but both calls should be within the BeginPaint and EndPaint block. In your example above, neither one is really needed.

  4. #4
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    Code:
    case WM_PAINT:
    		{
    			PAINTSTRUCT ps;
    			HDC hdc = BeginPaint(hwnd, &ps);
    
    			if (current_sel == 1) {
    			
    				if (saved == false)
    				{
    					reg = SaveDC(hdc);//salvez status, inainte de desenarea imaginii
    					saved = true;
    				}
    				else
    					RestoreDC(hdc,reg);//reinitializez fereastra, cum era inainte de desenat
    
    				BITMAP bm;				
    				HDC hdcMem = CreateCompatibleDC(hdc);
    				SelectObject(hdcMem, imagine_bmp);
    
    				GetObject(imagine_bmp, sizeof(bm), &bm);
    
    				BitBlt(hdc, image_x+70, image_y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);//redesenez imaginea
    				
    
    				DeleteDC(hdcMem);
    			}
    			//SetBkMode((HDC)hwnd,TRANSPARENT);
    			EndPaint(hwnd, &ps);
    			break;
    		}
    Still not beying able to restore the window initial state, then repaint the image. However saveDc now woks ok.

  5. #5
    Join Date
    Feb 2005
    Posts
    2,160

    Re: [gdi] Erasing Window

    What are you trying to do with SaveDC/RestoreDC? I don't think they do what you think they do:

    http://msdn.microsoft.com/en-us/libr...45(VS.85).aspx

  6. #6
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    I need to save the image, am a bmp for example. I dont want to use GetPixel.

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: [gdi] Erasing Window

    Get Pixel()? I'm not sure how that relates at all. I'm not sure, but I believe you want to sort-of cache a DC's contents (an already rendered screen) between paint cycles which is not what SaveDC() and RestoreDC() are for.

    If you're trying to save a bitmap somehow, you'll need to go about that very differently.

  8. #8
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    Yes,that is what i am trying. MSDN was very confuse, and i tought that the function saveDC it saves the capture of the window. An example of that different thing?
    Last edited by zorro59; June 22nd, 2010 at 09:31 AM.

  9. #9
    Join Date
    Feb 2005
    Posts
    2,160

    Re: [gdi] Erasing Window

    Do you want to save a screen image to a file? There are tons of examples of that on the web.

  10. #10
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    Without any other library like gdi+. The aplication is designed for windows mobile

  11. #11
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,523

    Re: [gdi] Erasing Window

    Judging by the attempt to use SaveDC / RestoreDC, I guess saving to a file is not needed.
    To cache content of your window, create compatible DC, select a properly sized bitmap into it and BitBlt the content of your DC into it.
    When needed, you can BitBlt it back.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  12. #12
    Join Date
    May 2009
    Posts
    14

    Re: [gdi] Erasing Window

    Go it thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center