2 swiftmgw swiftmgw 于 2015.05.28 09:42 提问

我是菜鸟,在window编程出现错误,求大神指导!!

//头文件
#include

#include
#pragma comment(lib,"Winmm.lib")

//宏定义
#define WINDOW_WIDTH 800//窗口宽度定义的宏,方便修改
#define WINDOW_HEIGHT 600//高度
#define WINDOW_TITLE L"[致我们永不熄灭的游戏开发梦想]GDI程序核心框架"//标题
//全局函数声明
HDC g_hdc=NULL;//全局设备环境句柄
HPEN g_hPen[7]={0};
HBRUSH g_hBrush[7]={0};
int g_iPenStyle[7]={PS_SOLID,PS_DASH,PS_DOT,PS_DASHDOT,PS_DASHDOTDOT,PS_NULL,PS_INSIDEFRAME};
int g_iBrushStyle[6]={HS_VERTICAL,HS_HORIZONTAL,HS_CROSS,HS_DIAGCROSS,HS_FDIAGONAL,HS_BDIAGONAL};

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL Game_Init(HWND hwnd);//资源的初始化函数
VOID Game_Paint(HWND hwnd);//绘图代码书写函数
BOOL Game_CleanUp(HWND hwnd);//资源清理函数
// [WinMain()函数]
//程序入口
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
//1、设计完整的窗口类
{
WNDCLASSEX wndClass={0};//定义窗口类
wndClass.cbSize=sizeof(WNDCLASSEX);//结构体的字节数大小
wndClass.style=CS_HREDRAW | CS_VREDRAW;//窗口样式
wndClass.lpfnWndProc=WndProc;//指向窗口过程函数的指针
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hInstance=hInstance;//句柄
wndClass.hIcon=(HICON)::LoadImage(NULL,L"icon.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
wndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndClass.lpszMenuName=NULL;
wndClass.lpszClassName=L"ForTheDreamOfGameDevelop";
//2、注册窗口类
if(!RegisterClassEx(&wndClass))
return -1;
//3、创建窗口
HWND hwnd=CreateWindow(L"ForTheDreamOfGameDevelop",WINDOW_TITLE,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,WINDOW_WIDTH,WINDOW_HEIGHT,NULL,NULL,hInstance,NULL);
//4、窗口的移动、更新
MoveWindow(hwnd,250,80,WINDOW_WIDTH,WINDOW_HEIGHT,true);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
//游戏资源的初始化。若失败,返回FALSE
if(!Game_Init(hwnd))
{
MessageBox(hwnd,L"资源初始化失败",L"消息窗口",0);
return FALSE;
}
//5、消息循环
MSG msg={0};
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//6、窗口注销
UnregisterClass(L"ForTheDreamOfGameDevelop",wndClass.hInstance);
return 0;
}
//窗口过程函数WndProc,对窗口消息处理
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT paintStruct;//定义该结构体记录绘制信息

switch(message)
{
case WM_PAINT://客户区重绘消息
    g_hdc=BeginPaint(hwnd,&paintStruct);
    Game_Paint(hwnd);
    EndPaint(hwnd,&paintStruct);
    ValidateRect(hwnd,NULL);//更新客户区的显示
    break;

case WM_KEYDOWN://键盘按下消息
    if(wParam==VK_ESCAPE)//如果ESC按下
        DestroyWindow(hwnd);//销毁窗口,并发送一条WM_DESTROY消息
    break;

case WM_DESTROY://若是窗口销毁消息
    Game_CleanUp(hwnd);
    PostQuitMessage(0);//响应WM_DESTROY消息
    break;

default:
    return DefWindowProc(hwnd,message,wParam,lParam);//调用默认的窗口消息
}
return 0;

}
// [Gmane_Init()函数]
BOOL Gmane_Init(HWND hwnd)
{
g_hdc=GetDC(hwnd);
srand(timeGetTime());//初始化时间种子
//随机初始化画笔、画刷颜色值
for(int i=0;i<=6;i++)
{
g_hPen[i]=CreatePen(g_iPenStyle[i],1,RGB(rand()%256,rand()%256,rand()%256));
if(i=6)
g_hBrush[i]=CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));
else
g_hBrush[i]=CreateHatchBrush(g_iPenStyle[i],RGB(rand()%256,rand()%256,rand()%256));

}

Game_Paint(hwnd);
ReleaseDC(hwnd,g_hdc);
return TRUE;

}
// [Gmane_Pnit()函数]
VOID Gmane_Pnit(HWND hwnd)
{
int y=0;
for(int i=0;i<=6;i++)
{
y=(i+1)*70;
SelectObject(g_hdc,g_hPen[i]);
MoveToEx(g_hdc,30,y,NULL);
LineTo(g_hdc,100,y);
}
int x1=120;
int x2=190;
for(int i=0;i<=6;i++)
{
SelectObject(g_hdc,g_hBrush[i]);
Rectangle(g_hdc,x1,70,x2,y);
x1+=90;
x2+=90;
}
}
//【Gmane_CleanUp()函数】
BOOL Gmane_CleanUp(HWND hwnd )
{
for(int i=0;i<=6;i++)
{
DeleteObject(g_hPen[i]);
DeleteObject(g_hBrush[i]);

}
return TRUE;

}

main.obj : error LNK2019: 无法解析的外部符号 "int cdecl Game_Init(struct HWND *)" (?Game_Init@@YAHPAUHWND__@@@Z),该符号在函数 WinMain@16 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "int __cdecl Game_CleanUp(struct HWND
_ *)" (?Game_CleanUp@@YAHPAUHWND__@@@Z),该符号在函数 "long stdcall WndProc(struct HWND *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用
1>main.obj : error LNK2019: 无法解析的外部符号 "void cdecl Game_Paint(struct HWND *)" (?Game_Paint@@YAXPAUHWND__@@@Z),该符号在函数 "long stdcall WndProc(struct HWND *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) 中被引用

3个回答

oyljerry
oyljerry   Ds   Rxr 2015.05.28 10:14

Game_Init 这些函数实现的cpp有没有一起编译

a1193561652
a1193561652   Rxr 2015.05.28 11:19

大致就是没有找到那些函数的实现,你找找那些函数在哪。

qq2888804
qq2888804   2015.05.28 20:26

好东西,谢谢分享~~~~~~~~~~~~~~

Csdn user default icon
上传中...
上传图片
插入图片