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. Draw Using Graphics object from Window Handle

Draw Using Graphics object from Window Handle

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
3 Posts 3 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.
  • 0 Offline
    0 Offline
    002comp
    wrote on last edited by
    #1

    Hello Friends I want to draw on a image and for that m using FindWindow for its handle and then crating DC and then Graphics Object but after that when I am drawing using drawImage then its drawing above all the windows not on that specific window whose handle m finding. Here is the code below:

    Bitmap gbmp(fileName);
    HWND hwnd = FindWindow(...,..);
    HDC hdc;
    hdc = GetDC(hwnd);
    Graphics g(hdc);
    g.DrawImage(&gbmp, 500,500, gbmp.GetWidth(), gbmp.GetHeight());

    Any Ideas? Regards Yogesh

    _ P 2 Replies Last reply
    0
    • 0 002comp

      Hello Friends I want to draw on a image and for that m using FindWindow for its handle and then crating DC and then Graphics Object but after that when I am drawing using drawImage then its drawing above all the windows not on that specific window whose handle m finding. Here is the code below:

      Bitmap gbmp(fileName);
      HWND hwnd = FindWindow(...,..);
      HDC hdc;
      hdc = GetDC(hwnd);
      Graphics g(hdc);
      g.DrawImage(&gbmp, 500,500, gbmp.GetWidth(), gbmp.GetHeight());

      Any Ideas? Regards Yogesh

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You will need to convert the coordinates from screen coordinates to window coordinates. The APIs ClientToScreen and ScreenToClient do this. Not sure which class/method in GDI+ does this.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • 0 002comp

        Hello Friends I want to draw on a image and for that m using FindWindow for its handle and then crating DC and then Graphics Object but after that when I am drawing using drawImage then its drawing above all the windows not on that specific window whose handle m finding. Here is the code below:

        Bitmap gbmp(fileName);
        HWND hwnd = FindWindow(...,..);
        HDC hdc;
        hdc = GetDC(hwnd);
        Graphics g(hdc);
        g.DrawImage(&gbmp, 500,500, gbmp.GetWidth(), gbmp.GetHeight());

        Any Ideas? Regards Yogesh

        P Offline
        P Offline
        Parthi_Appu
        wrote on last edited by
        #3

        I hope the window you are finding is not the foreground window? Is that correct? Here is the reason, even though we get separate DC for each window, keep it in mind that the screen space is shared by all the windows. So if you try to get the DC of window which is not in foreground and when we paint it other than in WM_PAINT cycle then it'll be painted on the shared screen space. This is why you are seeing the bitmap image at top of all the windows and not in the found window.


        Do your Duty and Don't expect the Result

        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