#include <windows.h>
#include <stdio.h>
#define ID_TIMER 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
TCHAR szAppName[] = TEXT ("sample") ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = 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 = szAppName ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Menu Demonstration"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
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)
{
HDC hdc;
char str[40];
TEXTMETRIC tm;
PAINTSTRUCT ps;
static int i=0;
static int cxlong,cylong,cxchar,cychar;
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
cxlong=cylong=10;
GetTextMetrics(hdc,&tm);
cxchar=tm.tmAveCharWidth;
cychar=tm.tmHeight;
ReleaseDC(hwnd,hdc);
return 0;
case WM_CHAR:
hdc=GetWindowDC(hwnd);
cxlong++;
if(cxlong==20)
{
cylong++;
cxlong=10;
}
if(i==40)
{
MessageBox(hwnd,"is not enough",szAppName,MB_OK);
i=0;
}
str[i]=(TCHAR)wParam;
TextOut(hdc,cxlong*cxchar,cylong*cychar,(str+i),1);
++i;
ReleaseDC(hwnd,hdc);
return 0;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click",szAppName,MB_OK);
hdc=GetWindowDC(hwnd);
//TextOut(hdc,20,100,
return 0;
case WM_CLOSE:
if(IDOK==MessageBox(NULL,"you really will go?","hi hi",MB_OKCANCEL))
{
DestroyWindow(hwnd);
}
return 0;
case WM_PAINT:
ps.fErase=0;
hdc=BeginPaint(hwnd,&ps);
//TextOut(hdc,20,20,"知识就使力量",strlen("知识就使力量"));
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
错误提示为:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Cpp1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Cpp1.exe - 2 error(s), 0 warning(s)