#include<windows.h> //函数声明int InitWindow( HINSTANCE hInstance, int nCmdShow );LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );//*******************************************************************//函数:WinMain()//功能:Win32应用程序入口函数。创建主窗口,处理消息循环//*******************************************************************int WINAPI WinMain( HINSTANCE hInstance, //当前实例句柄HINSTANCE hPrevInstance, //前一个实例句柄PSTR lpCmdLine, //命令行字符int nCmdShow) //窗口显示方式{MSG msg;//创建主窗口if (!InitWindow(hInstance,nCmdShow))
{
return 0;
}
else MessageBox(NULL,TEXT("OK"),TEXT("Because Error"),MB_OK);
//进入消息循环://从该应用程序的消息队列中检取消息,送到消息处理过程,//当检取到WM_QUIT消息时,退出消息循环。while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}//程序结束return msg.wParam;}//******************************************************************//函数:InitWindow()//功能:创建窗口。//******************************************************************int InitWindow( HINSTANCE hInstance, int nCmdShow )
{HWND hwnd; //窗口句柄WNDCLASS wc; //窗口类结构static TCHAR szA[]=TEXT("GaoHE");//填充窗口类结构wc.style = CS_VREDRAW | CS_HREDRAW;wc.lpfnWndProc = WinProc;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hInstance = hInstance;wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION );wc.hCursor = LoadCursor( NULL, IDC_ARROW );wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.lpszMenuName = NULL;wc.lpszClassName = szA;//注册窗口类if(!RegisterClass(&wc))
{
   MessageBox(NULL,TEXT("NO"),TEXT("Error"),MB_OK);
   return 0;
}//创建主窗口hwnd = CreateWindow(szA, //窗口类名称TEXT("一个基本的Win32程序"), //窗口标题WS_OVERLAPPEDWINDOW, //窗口风格,定义为普通型100, //窗口位置的x坐标100, //窗口位置的y坐标400, //窗口的宽度300, //窗口的高度NULL, //父窗口句柄NULL, //菜单句柄hInstance, //应用程序实例句柄NULL); //窗口创建数据指针if( !hwnd ) return 0;//显示并更新窗口ShowWindow( hwnd, nCmdShow );UpdateWindow( hwnd );return 1;}//******************************************************************//函数:WinProc()//功能:处理主窗口消息//******************************************************************LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ){switch( message ){case WM_KEYDOWN://击键消息switch( wParam ){case VK_ESCAPE:MessageBox(hWnd,"ESC键按下了!","Keyboard",MB_OK);break;}break;case WM_RBUTTONDOWN://鼠标消息{MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);break;}case WM_PAINT://窗口重画消息{char hello[]="你好,我是EasyWin !";HDC hdc;PAINTSTRUCT ps;hdc=BeginPaint( hWnd,&ps ); //取得设备环境句柄SetTextColor(hdc, RGB(0,0,255)); //设置文字颜色TextOut( hdc, 20, 10, hello, strlen(hello) );//输出文字EndPaint( hWnd, &ps ); //释放资源break;}case WM_DESTROY://退出消息PostQuitMessage( 0 );//调用退出函数break;}//调用缺省消息处理过程return DefWindowProc(hWnd, message, wParam, lParam);}
编译错误!!!Linking...
Text2.obj : error LNK2001: unresolved external symbol __imp__DispatchMessageA@4
Text2.obj : error LNK2001: unresolved external symbol __imp__TranslateMessage@4
Text2.obj : error LNK2001: unresolved external symbol __imp__GetMessageA@16
Text2.obj : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
Text2.obj : error LNK2001: unresolved external symbol __imp__UpdateWindow@4
Text2.obj : error LNK2001: unresolved external symbol __imp__ShowWindow@8
Text2.obj : error LNK2001: unresolved external symbol __imp__CreateWindowExA@48
Text2.obj : error LNK2001: unresolved external symbol __imp__RegisterClassA@4
Text2.obj : error LNK2001: unresolved external symbol __imp__GetStockObject@4
Text2.obj : error LNK2001: unresolved external symbol __imp__LoadCursorA@8
Text2.obj : error LNK2001: unresolved external symbol __imp__LoadIconA@8
Text2.obj : error LNK2001: unresolved external symbol __imp__DefWindowProcA@16
Text2.obj : error LNK2001: unresolved external symbol __imp__PostQuitMessage@4
Text2.obj : error LNK2001: unresolved external symbol __imp__EndPaint@8
Text2.obj : error LNK2001: unresolved external symbol __imp__TextOutA@20
Text2.obj : error LNK2001: unresolved external symbol __imp__SetTextColor@8
Text2.obj : error LNK2001: unresolved external symbol __imp__BeginPaint@8
LIBCMTD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Text2.exe : fatal error LNK1120: 18 unresolved externals
Error executing link.exe.Text2.exe - 19 error(s), 0 warning(s)

解决方案 »

  1.   

    建立一个win32 application 的工程 后面的选择选一个empty project 
    然后再workspace的file里面添加一个cpp文件 
    把你的代码复制进去就可以了
      

  2.   

    你包含了user32.lib没有?
    设置连接选项为:
    /nologo /subsystem:windows /incremental:yes /pdb:"Debug/Fun.pdb" /debug /machine:I386 /out:"Debug/Fun.exe" /pdbtype:sept
      

  3.   

    谢谢大家,持别是:: kingofvc(其实恶狼2000也不错) 问题解决了!!!