<2017年12月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

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); //返回消息的默认处理
}

 

posted @ 2018-07-04 10:26  史D芬周  阅读(2083)  评论(0编辑  收藏  举报