一. bmp静态框控件
static HBITMAP g_bg_bmp;
//获取窗口大小
GetWindowRect(hWnd,&rect);
nWinX = rect.right - rect.left;
nWinY = rect.bottom - rect.top;
g_bg_bmp = LoadBitmap(hInst, (LPCTSTR)IDB_BITMAP1);
//图片静态框
CreateWindowEx(0, "static", "静态框bmp", WS_CHILD|WS_VISIBLE|SS_SUNKEN, 0, 0, nWinX, nWinY,
hWnd, (HMENU)ID_USR_BMP, hInst, NULL);
//设置SS_BITMAP风格
HWND hWndBmp = GetDlgItem(hWnd, ID_USR_BMP);
LONG nStyle = GetWindowLong(hWndBmp, GWL_STYLE);
SetWindowLong(hWndBmp, GWL_STYLE, nStyle|SS_BITMAP);
//设置图片
SendDlgItemMessage(hWnd, ID_USR_BMP, STM_SETIMAGE, IMAGE_BITMAP, (long)g_bg_bmp);
二. 在WM_PAINT消息中填充图片背景
HDC hdc;
PAINTSTRUCT ps;
BITMAP bminfo;
hdc = BeginPaint(hWnd, &ps);
HDC memdc = CreateCompatibleDC(hdc); //内存DC
GetObject(g_bg_bmp, sizeof(bminfo), &bminfo); //获取图片大小信息
SelectObject(memdc, g_bg_bmp); //将g_bg_bmp选入内存DC
BitBlt(hdc,0,0,bminfo.bmWidth,bminfo.bmHeight,memdc,0,0,SRCCOPY); //贴图到目标DC
DeleteDC(memdc);
EndPaint(hWnd, &ps);
来源:https://blog.csdn.net/fengruoying93/article/details/99071958