• GDI+ 加载PNG图片


    #include <GdiPlus.h>
    #pragma comment(lib, "GdiPlus.lib")
    using namespace Gdiplus;

    class mygdiplus
    {
      GdiplusStartupInput gdiplusStartupInput;
      ULONG_PTR gdiplusToken;
    public:
      mygdiplus()
      {
        GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
      }
      ~mygdiplus()
      {
        GdiplusShutdown(gdiplusToken);
      }
    };


    Rect rect(20, 20, 326, 326);
    Graphics grpx(hdc);
    Image* pImage = new Image(TEXT("a1.png"));
    //Image* pImage = Gdiplus::Image::FromFile(TEXT("a1.png"));
    grpx.DrawImage(pImage,rect);
    case WM_PAINT:
        {
            hdc = BeginPaint(hWnd, &ps);
    
            /*Image image(L"a1.png");
            Graphics graphics(hdc);
            graphics.DrawImage(&image, 0, 0);*/
    
            //GdiplusStartupInput gdiplusStartupInput;
            //ULONG_PTR gdiplusToken;
            //GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
            Rect rect(20, 20, 326, 326);
            Graphics grpx(hdc);
            Image* pImage = new Image(TEXT("a1.png"));
            //Image* pImage = Gdiplus::Image::FromFile(TEXT("a1.png"));
            grpx.DrawImage(pImage,rect);
    
            delete pImage;
            
            // shut down - only once per process
            //GdiplusShutdown(gdiplusToken);
    
    
            EndPaint(hWnd, &ps);
            return 0;


    #include <windows.h>
    #include <GdiPlus.h>
    #pragma comment(lib, "GdiPlus.lib")
    using namespace Gdiplus;
    
    
    
    
    
    
    class mygdiplus
    {
        GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR   gdiplusToken;
    public:
        mygdiplus()
        {
            GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
        }
        ~mygdiplus()
        {
            GdiplusShutdown(gdiplusToken);
        }
    };
    
    
    
    
    
    
    
    
    LRESULT CALLBACK MyWinMain(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);//回调函数(消息的)
    
    
    
    class cWNDCLASSEX
    {
    public:
        cWNDCLASSEX(HINSTANCE h, int n) :hInstance(h), nCmdShow(n) {};
        //WNDCLASSEX wndclass;
        void cj();
    private:
        int nCmdShow;
        HINSTANCE hInstance;
        //WNDCLASSEX wndclass;
    
    };
    
    void cWNDCLASSEX::cj()
    {
        WNDCLASSEX wndclass;
        HBRUSH hBrush = ::CreateSolidBrush(RGB(236, 236, 236));
        HWND hWnd;
        wndclass.cbClsExtra = 0;
        wndclass.cbSize = sizeof(wndclass);
        wndclass.cbWndExtra = 0;
        wndclass.hbrBackground = hBrush;
        wndclass.hCursor = 0;
        wndclass.hIcon = 0;
        wndclass.hIconSm = 0;
        wndclass.lpfnWndProc = MyWinMain;
        wndclass.lpszClassName = TEXT("Leo");   //注册窗口时候要的名字,作为参数
        wndclass.lpszMenuName = 0;        //菜单名字
        wndclass.style = CS_HREDRAW | CS_VREDRAW ;
        wndclass.hInstance = hInstance;
    
        if (RegisterClassEx(&wndclass) == false)
        {
            //MessageBox(NULL, "注册失败", "提示", MB_OK);
            //return 0;
        }
    
        hWnd = CreateWindow(
            TEXT("Leo"), 
            TEXT("Small Test"), 
            WS_OVERLAPPEDWINDOW|WS_VSCROLL,
            0, 
            200, 
            500, 
            500, 
            NULL, 
            NULL,
            hInstance, 
            NULL);
    
        ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);
        MSG msg;
        while (::GetMessage(&msg, 0, 0, 0))
        {
    
            ::TranslateMessage(&msg);   //将得到的消息翻译
            ::DispatchMessage(&msg);    //翻译来的消息发送
    
        }
    
    }
    
    
    int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        cWNDCLASSEX a1(hInstance, nCmdShow);
        a1.cj();
        return 0;
    }
    
    
    LRESULT CALLBACK MyWinMain(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)//回调函数(消息的)
    {
        //HBRUSH m_hbr = CreateSolidBrush(RGB(255, 0, 0));
        HDC hdc;    //设备描述表句柄
        PAINTSTRUCT ps;//绘制窗口
        //RECT rect;
        mygdiplus mygdiplusS;
        switch(uMsg)
        {
    
        case WM_PAINT:
        {
            hdc = BeginPaint(hWnd, &ps);
    
            /*Image image(L"a1.png");
            Graphics graphics(hdc);
            graphics.DrawImage(&image, 0, 0);*/
    
            //GdiplusStartupInput gdiplusStartupInput;
            //ULONG_PTR gdiplusToken;
            //GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
            Rect rect(20, 20, 326, 326);
            Graphics grpx(hdc);
            Image* pImage = new Image(TEXT("a1.png"));
            //Image* pImage = Gdiplus::Image::FromFile(TEXT("a1.png"));
            grpx.DrawImage(pImage,rect);
    
            delete pImage;
            
            // shut down - only once per process
            //GdiplusShutdown(gdiplusToken);
    
    
            EndPaint(hWnd, &ps);
            return 0;
    
        }
        case WM_CLOSE:          //自动退出
    
            ::PostQuitMessage(0);
            break;
    
        }
    
        return  DefWindowProc(hWnd, uMsg, wParam, lParam); //返回消息的默认处理
    }
  • 相关阅读:
    英文网站优化之十个非常不错的Zen Cart插件
    kindeditor4.0.4个性化修改
    C#线程从陌生到熟悉(1)
    c# 关于LISTBOX的添加项的问题 以及不重复插入
    CSS设置字体为楷体
    SqlServer2005安装成功后补加Sa用户
    c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值
    实例讲解如何把表格变量传递到存储过程中
    StringBuilder
    初学基于.net三层架构的ERP系统(1)
  • 原文地址:https://www.cnblogs.com/weekbo/p/9262047.html
Copyright © 2020-2023  润新知