主题:???问一个win窗口编译的问题
小弟我刚学windows编程,模仿书上写了一个,用DEV-C++编译运行的时候不知为什么win窗口后面还有一个DOS窗口,关闭它的话win窗口也会同时关闭
还有我用visual c++时,编译通过了,没有错误,但是点ctrl+f5执行是会出现两个错误
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/window.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
window.exe - 2 error(s), 0 warning(s)
请高手指点下,不胜感激
代码如下:
#include <windows.h>
LRESULT CALLBACK guocheng(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS window;
window.cbClsExtra=0;
window.cbWndExtra=0;
window.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
window.hCursor=LoadCursor(NULL,IDC_APPSTARTING);
window.hIcon=LoadIcon(NULL,IDI_APPLICATION);
window.hInstance=hInstance;
window.lpfnWndProc=guocheng;
window.lpszClassName="天才";
window.lpszMenuName=NULL;
window.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&window);
HWND hwnd;
hwnd=CreateWindow("天才","垃圾",WS_OVERLAPPEDWINDOW,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 guocheng(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"别后悔哦!","退出",MB_YESNO))
{DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
还有我用visual c++时,编译通过了,没有错误,但是点ctrl+f5执行是会出现两个错误
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/window.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
window.exe - 2 error(s), 0 warning(s)
请高手指点下,不胜感激
代码如下:
#include <windows.h>
LRESULT CALLBACK guocheng(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS window;
window.cbClsExtra=0;
window.cbWndExtra=0;
window.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
window.hCursor=LoadCursor(NULL,IDC_APPSTARTING);
window.hIcon=LoadIcon(NULL,IDI_APPLICATION);
window.hInstance=hInstance;
window.lpfnWndProc=guocheng;
window.lpszClassName="天才";
window.lpszMenuName=NULL;
window.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&window);
HWND hwnd;
hwnd=CreateWindow("天才","垃圾",WS_OVERLAPPEDWINDOW,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 guocheng(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"别后悔哦!","退出",MB_YESNO))
{DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}