首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

一个windows窗口的创建,大家帮忙找上异常啊

2013-03-06 
一个windows窗口的创建,大家帮忙找下错误啊~~~急~~~#includewindows.h/*窗口函数说明*/LRESULT CALLBACK

一个windows窗口的创建,大家帮忙找下错误啊~~~急~~~
#include<windows.h>

/*窗口函数说明*/
LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);
/*初始化窗口类*/
/*WinMain 函数说明*/
int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
 HWND hWnd;

 MSG msg;
 WNDCLASS wndclass;
 char lpszClassName[]="窗口";
         char lpszTitle[]= "迷宫游戏";

wndclass.style= 0;        //窗口类型为缺省类型
wndclass.lpfnWndProc        = WndProc;  //窗口处理函数为WndProc
wndclass.cbClsExtra= 0;        //窗口类无扩展
wndclass.cbWndExtra= 0;        //窗口实例无扩展
wndclass.hInstance= hInstance; //当前实例句柄
wndclass.hIcon= LoadIcon(NULL, IDI_APPLICATION); 
                                                    //窗口最小化图标为缺省图标
wndclass.hCursor= LoadCursor(NULL, IDC_ARROW);
                                                    //窗口采用箭头图标
wndclass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
                                                   //窗口背景为白色
wndclass.lpszMenuName= NULL;            //窗口中无菜单
wndclass.lpszClassName= lpszClassName;   //窗口类名为窗口示例

        //窗口类注册
if(!RegisterClass(&wndclass))              //如果注册失败则发出警告声
{
MessageBeep(0);
return FALSE;
}
   //创建窗口
   hWnd = CreateWindow(lpszClassName,            //窗口类名
                  lpszTitle,            //窗口实例的标题名
    WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,//窗口风格
    CW_USEDEFAULT, 
       CW_USEDEFAULT,                      //窗口左上角坐标为缺省值
            CW_USEDEFAULT,
            CW_USEDEFAULT,                      //窗口的高和宽为缺省值


    NULL,                               //此窗口无父窗口
    NULL,                               //此窗口无主菜单
    hInstance,                          //创建此窗口的应用程序的当前句柄
    NULL);                              //不使用该值
   //显示窗口   
   ShowWindow(hWnd, nCmdShow);
   //绘制用户区
   UpdateWindow(hWnd);

   //消息循环
while (GetMessage(&msg, NULL, 0, 0)) 
{

TranslateMessage(&msg);
DispatchMessage(&msg);

}

return msg.wParam;                     //消息循环结束即程序终止时将信息返回系统
}

//窗口函数
LRESULT CALLBACK WndProc(HWND hWnd, 
UINT message, 
WPARAM wParam,
LPARAM lParam)
{

unsigned short key = 0;

switch (message) 
{

case WM_DESTROY:               //调用PostQuitMessage()函数 发出WM_QUIT消息
PostQuitMessage(0);

default:                        //缺省时采用系统消息缺省处理函数
return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

/*这是我编译时的错误

--------------------Configuration: maze - Win32 Release--------------------
Linking...
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/maze.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

maze.exe - 1 error(s), 0 warning(s)
*/

[解决办法]
你创建的是Console工程,要换成WIN32应用程序才行。

热点排行