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. How to draw bitmaps without access to HDC or HWND

How to draw bitmaps without access to HDC or HWND

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicshelptutorialquestion
7 Posts 2 Posters 0 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.
  • H Offline
    H Offline
    hvanzyll
    wrote on last edited by
    #1

    I need to draw on bitmaps buried deep in a DLL and have no access to HDC or HWND any attempt to GetDC(NULL) returns a valid pointer but all attempts to draw the bitmap fails. I'm not using MFC, straight SDK. Has anyone done this before or know how to implement this? any help would be appreciated.

    M 1 Reply Last reply
    0
    • H hvanzyll

      I need to draw on bitmaps buried deep in a DLL and have no access to HDC or HWND any attempt to GetDC(NULL) returns a valid pointer but all attempts to draw the bitmap fails. I'm not using MFC, straight SDK. Has anyone done this before or know how to implement this? any help would be appreciated.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      What is a bitmap "buried deep in a DLL"? You only need an HWND if you're doing something window related. GetDC() is for obtaining a device context for a window (or the screen). If you're not drawing there, then that's useless as well. What are you trying to do? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      H 1 Reply Last reply
      0
      • M Mark Salsbery

        What is a bitmap "buried deep in a DLL"? You only need an HWND if you're doing something window related. GetDC() is for obtaining a device context for a window (or the screen). If you're not drawing there, then that's useless as well. What are you trying to do? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        H Offline
        H Offline
        hvanzyll
        wrote on last edited by
        #3

        I'm trying to do on screen display inside a DirectShow filter. To show buffering messages. I figured it would be easy to just create a bitmap the size of the output image, then just draw buffering messages and send it off to the render.

        M 1 Reply Last reply
        0
        • H hvanzyll

          I'm trying to do on screen display inside a DirectShow filter. To show buffering messages. I figured it would be easy to just create a bitmap the size of the output image, then just draw buffering messages and send it off to the render.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Assuming you want to use GDI to draw on the video frames... If you have access to the uncompressed frames before they are rendered, I would use a DIBSection (see CreateDIBSection). Create a memory DC (CreateCompatibleDC()), select the DIBSection into it. For each frame, copy the frame pixel bits into the DIBSection's pixel bits. Then use GDI to draw to the memory DC. Copy the pixel bits from the DIBSection back to the frame buffer. Depending on the renderer you are using, there may be features already there for overlays. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          H 1 Reply Last reply
          0
          • M Mark Salsbery

            Assuming you want to use GDI to draw on the video frames... If you have access to the uncompressed frames before they are rendered, I would use a DIBSection (see CreateDIBSection). Create a memory DC (CreateCompatibleDC()), select the DIBSection into it. For each frame, copy the frame pixel bits into the DIBSection's pixel bits. Then use GDI to draw to the memory DC. Copy the pixel bits from the DIBSection back to the frame buffer. Depending on the renderer you are using, there may be features already there for overlays. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            H Offline
            H Offline
            hvanzyll
            wrote on last edited by
            #5

            I'll try that... only difrence is i'll have to create the buffer first, take the previous frame and color convert it to rgb24 then pass it into the CreateDIBSection draw the message I want, then color convert it to YUY2 or what ever output format is beeing used. HBITMAP CreateDIBSection( HDC hdc, // handle to DC CONST BITMAPINFO *pbmi, // bitmap data UINT iUsage, // data type indicator VOID **ppvBits, // bit values HANDLE hSection, // handle to file mapping object DWORD dwOffset // offset to bitmap bit values ); it needs a HDC, I dont' have one... How do i get one, or do i need a valid value? (pass in NULL?) edit: just looked into CreateCompatibleDC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen. would that be dependent if someone is running their display in 16,24, or 32bit? -- modified at 12:35 Thursday 4th October, 2007

            M 1 Reply Last reply
            0
            • H hvanzyll

              I'll try that... only difrence is i'll have to create the buffer first, take the previous frame and color convert it to rgb24 then pass it into the CreateDIBSection draw the message I want, then color convert it to YUY2 or what ever output format is beeing used. HBITMAP CreateDIBSection( HDC hdc, // handle to DC CONST BITMAPINFO *pbmi, // bitmap data UINT iUsage, // data type indicator VOID **ppvBits, // bit values HANDLE hSection, // handle to file mapping object DWORD dwOffset // offset to bitmap bit values ); it needs a HDC, I dont' have one... How do i get one, or do i need a valid value? (pass in NULL?) edit: just looked into CreateCompatibleDC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen. would that be dependent if someone is running their display in 16,24, or 32bit? -- modified at 12:35 Thursday 4th October, 2007

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              hvanzyll wrote:

              t needs a HDC, I dont' have one...

              You can pass NULL for the DC when calling CreateDIBSection. The DC is only used for DIBs requiring a color table, not RGB DIBs.

              hvanzyll wrote:

              If this handle is NULL, the function creates a memory DC compatible with the application's current screen. would that be dependent if someone is running their display in 16,24, or 32bit?

              The DIBSection will determine the bitmap format so a screen compatible DC will be fine.  Note this is NOT the case with regular DDBs (HBITMAP), which cannot be selected into an incompatible DC.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              H 1 Reply Last reply
              0
              • M Mark Salsbery

                hvanzyll wrote:

                t needs a HDC, I dont' have one...

                You can pass NULL for the DC when calling CreateDIBSection. The DC is only used for DIBs requiring a color table, not RGB DIBs.

                hvanzyll wrote:

                If this handle is NULL, the function creates a memory DC compatible with the application's current screen. would that be dependent if someone is running their display in 16,24, or 32bit?

                The DIBSection will determine the bitmap format so a screen compatible DC will be fine.  Note this is NOT the case with regular DDBs (HBITMAP), which cannot be selected into an incompatible DC.

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                H Offline
                H Offline
                hvanzyll
                wrote on last edited by
                #7

                Thank you for your help on this. hopefully my schedule will clear up in the next few days and I will get a chance to implement this.

                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