LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HBITMAP hBitmap, hSysBitmap[5];
    BITMAP bmp;
    HDC memDC = NULL;
    long w;
    long y;
    switch (message)
    {
    case WM_CREATE:
        hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
        if (!hBitmap)
        {
            MessageBox(hWnd,_T("位图加载失败"),NULL,MB_OK);

        }
        for (size_t i = 0; i < sizeof(hSysBitmap)/sizeof(HBITMAP); i++)
        {
            hSysBitmap[i] = LoadBitmap(NULL, (TCHAR*)(OBM_REDUCE + i));
        }
        break;
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // 分析菜单选择:
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            // TODO: 在此处添加使用 hdc 的任何绘图代码...
            if (hBitmap)
            {
                memDC = CreateCompatibleDC(hdc);
                SelectObject(memDC, hBitmap);
                GetObject(hBitmap, sizeof(bmp), &bmp);
                BitBlt(hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, memDC, 0, 0, SRCCOPY);
                w = bmp.bmWidth;
                y = 0;
                for (size_t i = 0; i < sizeof(hSysBitmap)/sizeof(HBITMAP); i++)
                {
                    SelectObject(memDC,hSysBitmap[i]);
                    GetObject(hSysBitmap[i], sizeof(bmp), &bmp);
                    BitBlt(hdc, 5+w, y, bmp.bmWidth, bmp.bmHeight, memDC, 0, 0, SRCCOPY);
                    y += bmp.bmHeight + 5;
                }

            }
            DeleteDC(memDC);

            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        DeleteObject(hBitmap);
        for (size_t i = 0; i < sizeof(hSysBitmap)/sizeof(HBITMAP); i++)
        {
            DeleteObject(hSysBitmap[i]);
        }
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐