Answer the question
In order to leave comments, you need to log in
LoadPicture to Console?
#define _WIN32_WINNT 0x0500
#include "stdafx.h"
#include <windows.h>
#include <conio.h>
#include <iostream>
void DrawBitmap(HDC hdc, int x, int y, HBITMAP hBitmap)
{
HBITMAP hbm, hOldbm;
HDC hMemDC;
BITMAP bm;
POINT ptSize, ptOrg;
hMemDC = CreateCompatibleDC(hdc);
hOldbm = (HBITMAP)SelectObject(hMemDC, hBitmap);
if (hOldbm)
{
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
DPtoLP(hdc, &ptSize, 1);
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP(hMemDC, &ptOrg, 1);
BitBlt(hdc, x, y, ptSize.x, ptSize.y,
hMemDC, ptOrg.x, ptOrg.y, SRCCOPY);
SelectObject(hMemDC, hOldbm);
}
DeleteDC(hMemDC);
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
static HBITMAP hBitmap;
PAINTSTRUCT ps;
static char MyName[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, MyName, sizeof(MyName));
wchar_t wtext[300];
mbstowcs(wtext, MyName, strlen(MyName) + 1);
LPWSTR ptr = wtext;
HWND hwnd = FindWindow(NULL, wtext);
HDC hdc;
hdc = GetWindowDC(hwnd);
hBitmap = (HBITMAP)LoadImage(NULL, L"C:\\picture.png", IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
std::cout << "Hello world !!!" << "\n";
InvalidateRect(hwnd, NULL, TRUE);
hdc = BeginPaint(hwnd, &ps);
DrawBitmap(hdc, 0, 20, hBitmap);
EndPaint(hwnd, &ps);
getch();
return EXIT_SUCCESS;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question