Draw Using Graphics object from Window Handle
-
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
-
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
You will need to convert the coordinates from screen coordinates to window coordinates. The APIs
ClientToScreen
andScreenToClient
do this. Not sure which class/method in GDI+ does this.«_Superman_» _I love work. It gives me something to do between weekends.
-
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
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