Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. paint a DC

paint a DC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++jsonperformancehelp
5 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _crs_
    wrote on last edited by
    #1

    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 !

    I S _ 3 Replies Last reply
    0
    • _ _crs_

      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 !

      I Offline
      I Offline
      includeh10
      wrote on last edited by
      #2

      u need to find a sample in MSDN (many there) and test it to get right idea. includeh10

      1 Reply Last reply
      0
      • _ _crs_

        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 !

        S Offline
        S Offline
        Scott H Settlemier
        wrote on last edited by
        #3

        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)

        _ 1 Reply Last reply
        0
        • _ _crs_

          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 !

          _ Offline
          _ Offline
          _Theo_
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Scott H Settlemier

            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)

            _ Offline
            _ Offline
            _crs_
            wrote on last edited by
            #5

            thanks, you were right, it worked !!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups