当前位置: 代码迷 >> C语言 >> 不知道哪里错了,一个简单的程序
  详细解决方案

不知道哪里错了,一个简单的程序

热度:190   发布时间:2007-04-23 18:31:34.0
不知道哪里错了,一个简单的程序

#include<windows.h>


LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WINMIAN
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hbrBackground =(HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.hCursor =LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon =LoadIcon(NULL,IDI_WINLOGO);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc =WindowProc;
wndclass.lpszClassName ="firstwindow";
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW|CS_VREDRAW|CS_NOCLOSE;

RegisterClass(&wndclass);

HWND hwnd;
hwnd=CreateWindow("firstwindow","an easy window",WS_OVERLAPPED,CW_USEDEFAULT ,
CW_USEDEFAULT ,CW_USEDEFAULT ,CW_USEDEFAULT ,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);

MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
break;
case WM_LBUTTONDOWN:
break;
case WM_PAINT:
break;
case WM_CLOSE:
/*if(MessageBox(hwnd,"是否要关闭窗口?","提示",0)==IDYES)
{
DestroyWindow(hwnd);
}*/
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;

}




Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/窗口代码.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

窗口代码.exe - 2 error(s), 0 warning(s)


----------------解决方案--------------------------------------------------------
以下是引用zh286091487在2007-4-23 18:31:34的发言:

#include<windows.h>


LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);

int WINAPI WINMIAN //WinMain WinMain名字写错了
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndclass;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hbrBackground =(HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.hCursor =LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon =LoadIcon(NULL,IDI_WINLOGO);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc =WindowProc;
wndclass.lpszClassName ="firstwindow";
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW|CS_VREDRAW|CS_NOCLOSE;

RegisterClass(&wndclass);

HWND hwnd;
hwnd=CreateWindow("firstwindow","an easy window",WS_OVERLAPPED,CW_USEDEFAULT ,
CW_USEDEFAULT ,CW_USEDEFAULT ,CW_USEDEFAULT ,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);

MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
break;
case WM_LBUTTONDOWN:
break;
case WM_PAINT:
break;
case WM_CLOSE:
/*if(MessageBox(hwnd,"是否要关闭窗口?","提示",0)==IDYES)
{
DestroyWindow(hwnd);
}*/
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;

}




Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/窗口代码.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

窗口代码.exe - 2 error(s), 0 warning(s)


----------------解决方案--------------------------------------------------------
这也叫小程序啊 我都不想看了
----------------解决方案--------------------------------------------------------
是你没接触过而已,这是最简单的WINDOWS API 程序!!
----------------解决方案--------------------------------------------------------

  相关解决方案