代码如下,具体意思不再赘述,很简单. #include<windows.h>#include<stdlib.h>#include<string.h> LRESULT CALLBACK WndProc(HWND hWnd,UINT message,UINT wParam,LONG lParam);BOOL InitWindowsClass(HINSTANCE hInstance);BOOL InitWindow(HINSTANCE hInstance,int nCmdShow); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lPCmdLine,int nCmdShow){ MSG Msg; if(!InitWindowsClass(hInstance)) { return FALSE; } if(! InitWindow(hInstance,nCmdShow)) { return FALSE; } while(GetMessage(&Msg,0,0,0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam;} //define the windowclassnameBOOL InitWindowsClass(HINSTANCE hInstance){ WNDCLASS windowclass; windowclass.cbClsExtra=0; windowclass.cbWndExtra=0; windowclass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH)); windowclass.hCursor=LoadCursor(NULL,IDC_ARROW); windowclass.hIcon=LoadIcon(NULL,"END"); windowclass.hInstance=hInstance; windowclass.lpfnWndProc=WndProc; windowclass.lpszClassName="WINTEXT"; windowclass.lpszMenuName=NULL; windowclass.style=CS_HREDRAW|CS_VREDRAW; return RegisterClass(&windowclass);} // define windowclass BOOL InitWindow(HINSTANCE hInstance,int nCmdShow){ HWND hWnd; hWnd=CreateWindow( "WINTEXT", "文字显示实例", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL ); if(!hWnd) { return FALSE; } ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); return TRUE;} LRESULT CALLBACK WndProc(HWND hWnd,UINT message,UINT wParam,LONG lParam)//Input your code{ HDC hdc; PAINTSTRUCT ps; int x=800,y=0; static int xpos=0; static count=0;// TEXTMETRIC tm; HFONT hF; SIZE size; char text[]="白日依山尽,黄河入海流"; char *textfont[]= { "宋体", "楷体", "仿宋" }; switch(message) { case WM_CREATE: SetTimer(hWnd,1,500,NULL); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd,message,wParam,lParam); case WM_PAINT: hdc=BeginPaint(hWnd,&ps); hF=CreateFont( 20, 0, 0, 0, FW_HEAVY, 0, 0, 0, GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, textfont[count] ); SetTextColor(hdc,RGB((count+1)*50,0,0)); SelectObject(hdc,hF); TextOut(hdc,x-xpos,y,text,lstrlen(text)); GetTextExtentPoint32(hdc,text,strlen(text),&size); xpos=xpos+size.cx; break; case WM_TIMER: xpos=xpos+15; if(x<xpos) { xpos=0; count=count+1; if(count>=3) { count=0; } } InvalidateRect(hWnd,NULL,1); break; } return 0;}

评论