正文

vc实现字体的移动和变色2009-09-27 17:10:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bigpig/48206.html

分享到:

代码如下,具体意思不再赘述,很简单. #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;}

阅读(1909) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册