启动vc++6.0,新建win32 application,新建 c++ source file ,写入以下程序,你就可以看到舞动的文字.
#include <windows.h>
LRESULT CALLBACK WindowProc(
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, // command line
int nCmdShow // show state
)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_EXCLAMATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName="abc";
wndclass.style=0;
wndclass.lpszMenuName=NULL;
RegisterClass(&wndclass);
hwnd=CreateWindow("abc","TYC1920",WS_OVERLAPPEDWINDOW,200,300,400,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
static char str[]=" hello,vc++!";
static POINT point[12];
int i;
switch(uMsg)
{
case WM_CREATE:
SetTimer(hwnd,1,100,NULL);
break;
case WM_TIMER:
GetCursorPos(&point[0]);
ScreenToClient(hwnd,&point[0]);
for(i=12;i>0;i--)
{
point[i].x=point[i-1].x+10;
point[i].y=point[i-1].y;
}
InvalidateRect(hwnd,NULL,TRUE);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
for(i=0;i<12;i++)
TextOut(hdc,point[i].x,point[i].y,&str[i],1);
break;
case WM_CLOSE:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}