Bawss
Bawss

Reputation: 38

VC++ (.Net) 2010 Draw Graphic To A Window

How can I draw a .png file to a certain window like for an example notepad?

HWND hWnd = FindWindow(0, "Untitled - Notepad");

void DrawTohWnd()
{
     Image^ newImage = Image::FromFile("smile.png");
     //Draw newImage to Window (Notepad)...
     //...
}

Upvotes: 0

Views: 348

Answers (1)

Cody Gray
Cody Gray

Reputation: 244971

The easiest way is to use the Graphics::DrawImage method and pass in your Image object (along with any other desired parameters specifying drawing options).

But that requires you to have an instance of the Graphics class corresponding to your window (HWND). You can get one by calling the Graphics::FromHwnd method.

Do be careful with the code you have written, though. Searching for windows by their caption is an inherently fragile method—windows change titles often.

Upvotes: 2

Related Questions