一个具有GDI功能的简单win32程序出错···
include<windows.h>staticcharszAppName[]="skyblud_CLASS";LRESULTCALLBACKWndProc(HWNDhw...
include <windows.h>
static char szAppName[] = "skyblud_CLASS";
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM Lparam);
BOOL Def_RegClass(HINSTANCE hInst);
HWND Create_ShowWnd(HINSTANCE hInst, int nCmdShow);
//主函数
int WINAPI Winmain(HINSTANCE hInst,HINSTANCE hprevInstance,LPSTR IpszCmdparam, int nCmdShow)
{
MSG Msg;
//定义并注册窗体类
if(! Def_RegClass(hInst))
return FALSE;
//创建并显示窗体
if(! Create_ShowWnd(hInst, nCmdShow))
return FALSE;
//启动消息循环
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);//翻译
DispatchMessage(&Msg);//派发消息
}
return Msg.wParam;
}
//定义并注册窗户体类
BOOL def_RegClass(HINSTANCE hInst)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW|CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0 ;
WndClass.cbWndExtra = 0 ;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
return (RegisterClass(&WndClass) != 0);
}
//创建并显示窗体
HWND Create_ShowWnd(HINSTANCE hInst,int nCmdShow)
{
HWND hwnd = CreateWindow (szAppName,szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInst,NULL);
if(hwnd = NULL)
return FALSE;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
//窗口回调函数
LRESULT CALLBACK WndProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch(Message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,Message,wParam,lParam);
}
}
ompiling...
main.cpp
D:\C游戏\C++\snake\main.cpp(85) : warning C4715: 'WndProc' : not all control paths return a value
Linking...
main.obj : error LNK2001: unresolved external symbol "int __cdecl Def_RegClass(struct HINSTANCE__ *)" (?Def_RegClass@@YAHPAUHINSTANCE__@@@Z)
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/snake.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.
snake.exe - 1 error(s), 0 warning(s)
好答案有追加
改过程序后发现无法生成窗口。。。大牛们···帮帮忙~~ 展开
static char szAppName[] = "skyblud_CLASS";
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM Lparam);
BOOL Def_RegClass(HINSTANCE hInst);
HWND Create_ShowWnd(HINSTANCE hInst, int nCmdShow);
//主函数
int WINAPI Winmain(HINSTANCE hInst,HINSTANCE hprevInstance,LPSTR IpszCmdparam, int nCmdShow)
{
MSG Msg;
//定义并注册窗体类
if(! Def_RegClass(hInst))
return FALSE;
//创建并显示窗体
if(! Create_ShowWnd(hInst, nCmdShow))
return FALSE;
//启动消息循环
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);//翻译
DispatchMessage(&Msg);//派发消息
}
return Msg.wParam;
}
//定义并注册窗户体类
BOOL def_RegClass(HINSTANCE hInst)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW|CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0 ;
WndClass.cbWndExtra = 0 ;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
return (RegisterClass(&WndClass) != 0);
}
//创建并显示窗体
HWND Create_ShowWnd(HINSTANCE hInst,int nCmdShow)
{
HWND hwnd = CreateWindow (szAppName,szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInst,NULL);
if(hwnd = NULL)
return FALSE;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
//窗口回调函数
LRESULT CALLBACK WndProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch(Message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,Message,wParam,lParam);
}
}
ompiling...
main.cpp
D:\C游戏\C++\snake\main.cpp(85) : warning C4715: 'WndProc' : not all control paths return a value
Linking...
main.obj : error LNK2001: unresolved external symbol "int __cdecl Def_RegClass(struct HINSTANCE__ *)" (?Def_RegClass@@YAHPAUHINSTANCE__@@@Z)
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/snake.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.
snake.exe - 1 error(s), 0 warning(s)
好答案有追加
改过程序后发现无法生成窗口。。。大牛们···帮帮忙~~ 展开
2个回答
展开全部
HWND hwnd = CreateWindow (szAppName,szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInst,NULL);
if(!hwnd) <-亲,这里改下就ok啦
return FALSE;
if(!hwnd) <-亲,这里改下就ok啦
return FALSE;
更多追问追答
追问
额,这个地方被我注释了。。。还是没有用。。。
追答
我的是vs2010,需要的话可以把工程发给你看看。QQ:1377九584
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询