'전체 글'에 해당되는 글 533건

  1. 2018.11.22 Console 어플리케이션에 이미지 디스플레이 하기
반응형

Console에 이미지를 디스플레이 하는 간단한 코드.

윈도우 어플리케이션처럼 이미지가 지워졌을때 다시 그려주는 코드가 없기 때문에 커서 이동, 마우스 클릭등으로 이미지가 지워져도 다시 그려주지는 않는다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<stdio.h>
#include<Windows.h>
 
int main(void)
{
    printf("Image loading...\n");
    Sleep(100); // 콘솔이 나타날때까지 잠시 멈추지 않으면 이미지가 표시되지 않는 경우가 생긴다.
 
    HWND hWnd = GetConsoleWindow();
    // Retrieves the window handle used by the console associated with the calling process.
 
    HBITMAP hImage, hOldBitmap;
 
    HDC hDC = GetDC(hWnd);
    HDC hMemDC = CreateCompatibleDC(hDC);
 
    hImage = (HBITMAP)LoadImage(NULL, TEXT("cat.bmp"), IMAGE_BITMAP, 00, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
    // Loads an icon, cursor, animated cursor, or bitmap.
 
    hOldBitmap = (HBITMAP)SelectObject(hMemDC, hImage);
    BitBlt(hDC, 505050 + 61250 + 409, hMemDC, 00, SRCCOPY); // Image(612, 409) at (50, 50)
    // The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels
    // from the specified source device context into a destination device context.
 
    SelectObject(hMemDC, hOldBitmap);
    DeleteObject(hImage);
    DeleteDC(hMemDC);
    ReleaseDC(hWnd, hDC);
 
    return 0;
}
cs


결과:






반응형

'C, C++' 카테고리의 다른 글

Qt 스프라이트 애니매이션  (0) 2019.02.21
Qt 설치 및 간단한 사용 예  (4) 2019.01.16
How to install and use JsonCpp - JsonCpp 설치 및 사용  (2) 2019.01.08
Python C API  (0) 2018.11.21
MySQL C API  (0) 2018.11.20
Posted by J-sean
: