C
C
continue2016-01-27 02:05:17
C++ / C#
continue, 2016-01-27 02:05:17

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;
}

And in general, is it possible to load a picture into the console (for example, this one):
cec0be9de00646f8b74b2abd8f7b4df1.jpg
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AtomKrieg, 2016-01-27
@AtomKrieg

It is forbidden. Can only hack cmd.exe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question