paint a DC
-
Hello, a have a big problem ... I tried to paint a dc with BitBlt (win32 api NOT MFC) and it did not work, my code is : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(b,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,b,0,0,SRCCOPY); the problem is that all functions return OK values and the screen is empty if I change : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(hdc,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,hdc,0,0,SRCCOPY); is OK, so I jump to one conclusion that only "hdc" can be painted .... all is done in the WM_PAINT message So my question is how can I create a buffer in memory and paint there and in the end paint my app with it ! thank you !
-
Hello, a have a big problem ... I tried to paint a dc with BitBlt (win32 api NOT MFC) and it did not work, my code is : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(b,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,b,0,0,SRCCOPY); the problem is that all functions return OK values and the screen is empty if I change : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(hdc,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,hdc,0,0,SRCCOPY); is OK, so I jump to one conclusion that only "hdc" can be painted .... all is done in the WM_PAINT message So my question is how can I create a buffer in memory and paint there and in the end paint my app with it ! thank you !
u need to find a sample in MSDN (many there) and test it to get right idea. includeh10
-
Hello, a have a big problem ... I tried to paint a dc with BitBlt (win32 api NOT MFC) and it did not work, my code is : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(b,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,b,0,0,SRCCOPY); the problem is that all functions return OK values and the screen is empty if I change : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(hdc,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,hdc,0,0,SRCCOPY); is OK, so I jump to one conclusion that only "hdc" can be painted .... all is done in the WM_PAINT message So my question is how can I create a buffer in memory and paint there and in the end paint my app with it ! thank you !
remember, a dc is not a surface, but the means of accessing one. If you create a memory dc, it is created with a default 1x1 monochrome surface. (If I recall) What you need to do is create a bitmap (the surface) and select it into the memory dc. Then you can paint on that surface using the memory dc and finally blit from the bitmap (using the memory dc) to the display surface (using the window dc)
-
Hello, a have a big problem ... I tried to paint a dc with BitBlt (win32 api NOT MFC) and it did not work, my code is : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(b,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,b,0,0,SRCCOPY); the problem is that all functions return OK values and the screen is empty if I change : HDC a,b; a = GetDC(GetDesktopWindow()); b = CreateCompatibleDC(NULL); BOOL ahr; ahr = BitBlt(hdc,0,0,100,100,a,0,0,SRCCOPY); ahr = BitBlt(hdc,0,0,400,400,hdc,0,0,SRCCOPY); is OK, so I jump to one conclusion that only "hdc" can be painted .... all is done in the WM_PAINT message So my question is how can I create a buffer in memory and paint there and in the end paint my app with it ! thank you !
First of all, it's best to use BeginPaint and EndPaint when painting from the WM_PAINT message: PAINTSTRUCT ps; BeginPaint(hwnd,&ps); //you can use ps.hdc now for drawing EndPaint(hwnd,&ps); Otherwise use GetDC() when painting. The HDC object you have using the above methods can be used for drawing. A HDC object is 'connected' to a certain surface like a bitmap. The 'b' HDC object you use in your code points to nothing so to say, so you need to create a HBITMAP object if you want the code to work: HBITMAP bmp=CreateCompatibleBitmap(hdc,width,height); Then use SelectObject(b,bmp); to let 'b' point to the new bitmap. After that you can draw to it/copy to it etc. Also, I advice you use b=CreateCompatibleDC(hdc); instead of NULL as argument.
-
remember, a dc is not a surface, but the means of accessing one. If you create a memory dc, it is created with a default 1x1 monochrome surface. (If I recall) What you need to do is create a bitmap (the surface) and select it into the memory dc. Then you can paint on that surface using the memory dc and finally blit from the bitmap (using the memory dc) to the display surface (using the window dc)