-
June 21st, 2010, 03:28 AM
#1
[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.
-
June 21st, 2010, 04:20 AM
#2
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.
-
June 21st, 2010, 07:29 AM
#3
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.
-
June 21st, 2010, 03:47 PM
#4
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.
-
June 21st, 2010, 03:51 PM
#5
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
-
June 21st, 2010, 04:33 PM
#6
Re: [gdi] Erasing Window
I need to save the image, am a bmp for example. I dont want to use GetPixel.
-
June 22nd, 2010, 07:28 AM
#7
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.
-
June 22nd, 2010, 09:28 AM
#8
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.
-
June 22nd, 2010, 10:12 AM
#9
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.
-
June 22nd, 2010, 01:27 PM
#10
Re: [gdi] Erasing Window
Without any other library like gdi+. The aplication is designed for windows mobile
-
June 22nd, 2010, 01:42 PM
#11
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:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 22nd, 2010, 02:07 PM
#12
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|