主题:基础中的基础问题
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc= WinSunProc;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hInstance = hInstance;
wndcls.hIcon=LoadIcon(NULL, IDC_CROSS);
wndcls.hCursor = LoadCursor( NULL, IDI_ERROR );
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.lpszMenuName = NULL;
LPCTSTR lpszClassName = "wuyufei";
HWND hwnd;
hwnd = CreateWindow("wuyufei","生命在于学习", WS_OVERLAPPEDWINDOW, 0, 0,
600, 400, 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 WinSunProc( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch( uMsg )
{
case WM_CHAR:
char szChar[ 20 ];
sprintf(szChar,"char is %d", wParam );
MessageBox(hwnd, szChar, "woaini", 0 );
break;
case WM_LBUTTONDOWN:
MessageBox( hwnd, "mouse clicked", "woaini", 0 );
HDC hdc;
hdc = GetDC(hwnd );
TextOut(hdc, 0, 50, "生命在于学习", strlen("生命在于学习"));
ReleaseDC(hwnd, hdc );
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint( hwnd, &ps );
TextOut( hDC, 0, 0, "学编程", strlen("学编程"));
EndPaint( hwnd, &ps );
break;
case WM_CLOSE:
if(IDYES == MessageBox( hwnd, "是否真的结束? ", "woaini", MB_YESNO))
{
DestroyWindow( hwnd );
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
return 0;
}
小弟刚接触这个不久,模仿着做一个窗口,在vc++ 6.0上能正常编译,但连接时出现如下错误:请指正!!
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/winmain.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
winmain.exe - 2 error(s), 0 warning(s)
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc= WinSunProc;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hInstance = hInstance;
wndcls.hIcon=LoadIcon(NULL, IDC_CROSS);
wndcls.hCursor = LoadCursor( NULL, IDI_ERROR );
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.lpszMenuName = NULL;
LPCTSTR lpszClassName = "wuyufei";
HWND hwnd;
hwnd = CreateWindow("wuyufei","生命在于学习", WS_OVERLAPPEDWINDOW, 0, 0,
600, 400, 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 WinSunProc( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch( uMsg )
{
case WM_CHAR:
char szChar[ 20 ];
sprintf(szChar,"char is %d", wParam );
MessageBox(hwnd, szChar, "woaini", 0 );
break;
case WM_LBUTTONDOWN:
MessageBox( hwnd, "mouse clicked", "woaini", 0 );
HDC hdc;
hdc = GetDC(hwnd );
TextOut(hdc, 0, 50, "生命在于学习", strlen("生命在于学习"));
ReleaseDC(hwnd, hdc );
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint( hwnd, &ps );
TextOut( hDC, 0, 0, "学编程", strlen("学编程"));
EndPaint( hwnd, &ps );
break;
case WM_CLOSE:
if(IDYES == MessageBox( hwnd, "是否真的结束? ", "woaini", MB_YESNO))
{
DestroyWindow( hwnd );
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, uMsg, wParam, lParam );
}
return 0;
}
小弟刚接触这个不久,模仿着做一个窗口,在vc++ 6.0上能正常编译,但连接时出现如下错误:请指正!!
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/winmain.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
winmain.exe - 2 error(s), 0 warning(s)