C++将一个图片显示到窗口里面

// Test2.cpp : 定义控制台应用程序的入口点。
//
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")


#include "stdafx.h"


#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <atlimage.h>


HWND WINAPI GetConsoleWindow();
void HideTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = FALSE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
void ShowTheCursor() {
    CONSOLE_CURSOR_INFO cciCursor;
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {
        cciCursor.bVisible = TRUE;
        SetConsoleCursorInfo(hStdOut, &cciCursor);
    }
}
int main() {
    HWND  hwnd;
    HDC   hdc;
    HFONT hfont;
    HBITMAP hbm;
    HDC hdcBits;
    BITMAP bm;
CImage Image;


    system("color F0");
    system("cls");
    HideTheCursor();
    hwnd  = GetConsoleWindow();
    hdc   = GetDC(hwnd);


Image.Load(L"1.jpg");
hbm=Image.Detach();


//hbm=LoadImage(0,"C:\\Windows\\1.jpg",IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
    if (hbm) {
        hdcBits = CreateCompatibleDC(hdc);
        GetObject (hbm, sizeof(BITMAP), &bm);
        SelectObject(hdcBits,hbm);
        BitBlt(hdc,20,10,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
BitBlt(hdc,20,10,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
        DeleteDC(hdcBits);
        DeleteObject(hbm);
    }
    hfont = CreateFont(24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"华文楷体");
    SelectObject(hdc,hfont);
    SetTextColor(hdc,RGB(255,255,255));
    SetBkMode(hdc,TRANSPARENT);
    TextOut(hdc,210,30,L"这个背景是泡泡",14);
    DeleteObject(hfont);
    ReleaseDC(hwnd,hdc);
    getch();
    system("color 07");
    system("cls");
    ShowTheCursor();
    return 0;
}
  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值