C++中如何创建窗口并在窗口中加载图片哪位能给个步骤同,就是从开始创建到结束
2011-07-12
展开全部
#include<windows.h>
LRESULT CALLBACK MsgProc(HWND hWnd,UINT msg,WPARAM wParam ,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
return 0;
break;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
WNDCLASSEX wc;
ZeroMemory(&wc,sizeof(wc));
wc.cbSize = sizeof(wc);
wc.hInstance = hInst;
wc.lpfnWndProc = MsgProc;
wc.lpszClassName = "VS";
wc.style = CS_CLASSDC;
RegisterClassEx(&wc);
HWND hWnd = CreateWindowEx(NULL,"VS","LOAD",
WS_OVERLAPPEDWINDOW,
0,0,800,600,NULL,NULL,hInst,NULL);
MSG msg;
memset(&msg,0,sizeof(msg));
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while(msg.message != WM_QUIT)
{
if(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
UnregisterClass("VS",hInst);
return 0;
}
加载图片用BitBlt函数,注意工程类型为win32 application
LRESULT CALLBACK MsgProc(HWND hWnd,UINT msg,WPARAM wParam ,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
case WM_CLOSE:
PostQuitMessage(0);
return 0;
break;
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
WNDCLASSEX wc;
ZeroMemory(&wc,sizeof(wc));
wc.cbSize = sizeof(wc);
wc.hInstance = hInst;
wc.lpfnWndProc = MsgProc;
wc.lpszClassName = "VS";
wc.style = CS_CLASSDC;
RegisterClassEx(&wc);
HWND hWnd = CreateWindowEx(NULL,"VS","LOAD",
WS_OVERLAPPEDWINDOW,
0,0,800,600,NULL,NULL,hInst,NULL);
MSG msg;
memset(&msg,0,sizeof(msg));
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while(msg.message != WM_QUIT)
{
if(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
UnregisterClass("VS",hInst);
return 0;
}
加载图片用BitBlt函数,注意工程类型为win32 application
更多追问追答
追问
f:\制作\c专用\11111111111111\11111111111111\11.cpp(22): error C2440: “=”: 无法从“const char [3]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
追答
恩。。,将“..."改为L("...")或_T("........")试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询