windows程序怎样加一个背景图片?求助
求助 怎样给窗体加一个背景?改变颜色的话只需要在注册信息里修改背景信息
如果是弄上一张图片那就是贴图了 这些涉及到GDI绘图技术,小甲鱼往后会将的 #include "stdafx.h"
#include "resource.h"
HINSTANCE g_hInst;
void OnPaint(HWND hWnd)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
//HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,"./Picture.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP hBitmap = LoadBitmap(g_hInst,(LPCTSTR)IDB_BITMAP1);
BITMAP bm;
//获取图片信息
GetObject(hBitmap,sizeof(bm),&bm);
HDC dc = CreateCompatibleDC(hdc);
SelectObject(dc,hBitmap);
MoveWindow(hWnd,0,0,bm.bmWidth,bm.bmHeight,FALSE);
BitBlt(hdc,0,0,bm.bmWidth,bm.bmHeight,dc,0,0,SRCCOPY);
//
RECT rect;
GetClientRect(hWnd,&rect);
Rectangle(hdc,100,100,300,500);
LineTo(hdc,100,100);
MoveToEx(hdc,300,500,NULL);
EndPaint(hWnd,&ps);
}
void OnInitDialog(HWND hwnd)
{
//HICON hIcon = (HICON)LoadImage(NULL,"./1.ico",IMAGE_ICON,0,0,LR_LOADFROMFILE);
HICON hIcon = LoadIcon(g_hInst,(LPCTSTR)IDI_ICON1);
::SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)hIcon);
SetWindowText(hwnd,"绘图测试");
}
void OnMouseMove(HWND hwnd)
{
HCURSOR hCursor = LoadCursor(g_hInst,(LPCTSTR)IDC_CURSOR1);
SetCursor(hCursor);
}
BOOL CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg) {
case WM_PAINT:
OnPaint(hwndDlg);
return TRUE;
case WM_INITDIALOG:
OnInitDialog(hwndDlg);
return TRUE;
case WM_MOUSEMOVE:
OnMouseMove(hwndDlg);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hwndDlg,IDCANCEL);
return TRUE;
case IDOK:
return TRUE;
} 学习 学习下 网上是有win32贴图代码的。
页:
[1]