使用的是VC++2008
;想要用gdi+将"I:\123\测试图片.png"绘制到form1上,方法?
长期学习、长期在线,可远程操作指导.....最大程度加分
542209396@qq.com
vc++2008 gdi+ 绘图
答案:3 悬赏:50 手机版
解决时间 2021-01-23 18:43
- 提问者网友:回忆在搜索
- 2021-01-23 09:49
最佳答案
- 五星知识达人网友:神的生死簿
- 2021-01-23 09:54
给你贴个小例子
#include
#include
#include
#pragma comment(lib,"GdiPlus.lib")
using namespace Gdiplus;
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
void drawbitmap(HDC hdc)
{
Graphics grap(hdc);
Image img(L"E:\\宽屏壁纸\\图片\\jiani.jpg");
grap.DrawImage(&img,0,0);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
TCHAR szname[]=TEXT("classname");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
wndclass. CS_VREDRAW;
wndclass.lpfnWndProc=WinProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpszClassName=szname;
wndclass.lpszMenuName=NULL;
RegisterClass(&wndclass);
hwnd=CreateWindow(szname,TEXT("windowsnametest"),WS_OVERLAPPEDWINDOW,100,100,300,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass(szname,hInstance);
GdiplusShutdown(gdiplusToken);
return 1;
}
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
HDC hdc;
case WM_PAINT:
hdc = GetDC(hwnd);
drawbitmap(hdc);
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
PostQuitMessage(1);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
#include
#include
#include
#pragma comment(lib,"GdiPlus.lib")
using namespace Gdiplus;
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
void drawbitmap(HDC hdc)
{
Graphics grap(hdc);
Image img(L"E:\\宽屏壁纸\\图片\\jiani.jpg");
grap.DrawImage(&img,0,0);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
TCHAR szname[]=TEXT("classname");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
// Initialize GDI+.
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
wndclass. CS_VREDRAW;
wndclass.lpfnWndProc=WinProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpszClassName=szname;
wndclass.lpszMenuName=NULL;
RegisterClass(&wndclass);
hwnd=CreateWindow(szname,TEXT("windowsnametest"),WS_OVERLAPPEDWINDOW,100,100,300,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass(szname,hInstance);
GdiplusShutdown(gdiplusToken);
return 1;
}
LRESULT CALLBACK WinProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
HDC hdc;
case WM_PAINT:
hdc = GetDC(hwnd);
drawbitmap(hdc);
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
PostQuitMessage(1);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
全部回答
- 1楼网友:渊鱼
- 2021-01-23 11:25
背景图片
加载位图dc中绘制
- 2楼网友:一把行者刀
- 2021-01-23 10:19
你好!
问题给你转问一下。嘿嘿
我的回答你还满意吗~~
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯