#include<windows.h>
#include<tchar.h>
#include<math.h>
#define PI 3.1415926
BOOLEAN InitWindowClass(HINSTANCE hinstance,int nCmdShow);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HFONT CreateMyFont(TCHAR *fontName,int height,int lean);//創建自定義字體
//三個引數分別是字體名稱,字體大小,字體傾斜度,傾斜度以/10為一個邏輯單位
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowClass(hInstance,nCmdShow))
{
MessageBox(NULL,_T("創建視窗失敗!"),_T("創建視窗"),NULL);
return 1;
}
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam )
{
HDC hDC;
PAINTSTRUCT ps;
HFONT font;
HPEN hPen;
LPWSTR title=L"登高 唐.杜甫",poem[8]={L"風急天高猿嘯哀",L"渚清沙白鳥飛回",L"無邊落木蕭蕭下",L"不盡長江滾滾來",L"萬里悲秋常作客",L"百年多病獨登臺",L"艱難苦恨繁霜鬢",L"潦倒新停濁酒杯"};
int r,r0,i,j=-1,fontSize,fontSize0,color;
RECT clientDimension;
POINT begin,end,org;
double sita;
switch(message)
{
case WM_SIZE:
InvalidateRect(hWnd,NULL,true);
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
hPen=CreatePen(PS_DASH,1,RGB(127,127,127));
SelectObject(hDC,hPen);
GetClientRect(hWnd,&clientDimension);
if((clientDimension.right -clientDimension.left)<400||(clientDimension.bottom -clientDimension.top)<300)
{
MessageBox(hWnd,_T("螢屏尺寸太小,無法繪圖!"),_T("錯誤資訊"),0);
break;
}
r=(clientDimension.bottom -clientDimension.top)*8/10;
org.x=(clientDimension.right -clientDimension.left)/2;
org.y=(clientDimension.bottom -clientDimension.top)*9/10;
Arc(hDC,org.x-r,org.y-r,org.x+r,org.y+r,org.x+(int)(r*sin(PI/31)),org.y+(int)(r*cos(PI/3)),org.x-(int)(r*sin(2*PI/3)),org.y+(int)(r*cos(2*PI/3))); //畫外為圓弧
for(sita=PI/6;sita<=PI*5/6;sita+=PI*2/27)
{
begin.x=org.x-(int)(r*sin(sita));
begin.y=org.y-(int)(r*cos(sita));
MoveToEx(hDC,begin.x,begin.y,NULL);
end.x=org.x;
end.y=org.y;
LineTo(hDC,end.x,end.y);
}//畫折線
r0=r*2/5;
Arc(hDC,org.x-r0,org.y-r0,org.x+r0,org.y+r0,org.x+(int)(r0*sin(PI/31)),org.y+(int)(r0*cos(PI/3)),org.x-(int)(r0*sin(2*PI/3)),org.y+(int)(r0*cos(2*PI/3)));
sita=PI/6+PI*4/15/5;
fontSize0=fontSize=(r-r0)/7;
r0=r-20;
for(i=0;i<7;i++)
{
LPCWSTR outInfo=(LPCWSTR)&title[i];
fontSize-=3;
font=CreateMyFont(_T("楷體_GB2312"),fontSize-5,-(int)((sita+PI/15)*1800/PI));
SelectObject(hDC,font);
begin.x=org.x+(int)(r*sin(sita));
begin.y=org.y-(int)(r*cos(sita));
TextOut(hDC,begin.x,begin.y,outInfo,1);
r0-=fontSize;
DeleteObject(font);
}
for(sita=PI/6+PI*4/27-PI/40;sita<=PI*5/6;sita+=PI*2/27)
{
fontSize=fontSize0;
r0=r-20;
j++;
color=0;
for(i=0;i<7;i++)
{
color+=255/7;
SetTextColor(hDC,RGB(255-color,0,color));
LPCWSTR outInfo=&poem[j][i];
fontSize-=3;
font=CreateMyFont(_T("華文行楷"),fontSize,(int)(((sita-PI/2)*1800/PI))%3600);
SelectObject(hDC,font);
begin.x=org.x+(int)(r0*sin(sita));
begin.y=org.y-(int)(r0*cos(sita));
TextOut(hDC,begin.x,begin.y,outInfo,1);
r0-=fontSize;
DeleteObject(font);
Sleep(10);
}
}
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
break;
}
return 0;
}
HFONT CreatMyFont(TCHAR *fontName,int height,int lean)
{
return CreateFont(height,
0,
lean,
0,
FW_HEAVY,
0,
0,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
fontName
);
}
BOOLEAN InitWindowClass(HINSTANCE hInstance,int nCmdShow)
{
WNDCLASSEX wcex;
HWND hWnd;
TCHAR szWindowClass[]=_T("視窗示例");
TCHAR szTitle[]=_T("字體及位置示例");
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.style=0;
wcex.lpfnWndProc=WndProc;
wcex.cbClsExtra=0;
wcex.cbWndExtra=0;
wcex.hInstance=hInstance;
wcex.hIcon=LoadCursor(hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wcex.lpszClassName=szWindowClass;
wcex.lpszMenuName=NULL;
wcex.hIconSm=LoadIcon(wcex.hInstance ,MAKEINTRESOURCE(IDI_APPLICATION));
if(!RegisterClassEx(&wcex))
return FALSE;
hWnd=CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
uj5u.com熱心網友回復:
求大神指點菜鳥吧uj5u.com熱心網友回復:
你使用的API版本和作為引數代入的字串型別不匹配。把
TextOut(hDC,begin.x,begin.y,outInfo,1);
改成
TextOutW(hDC,begin.x,begin.y,outInfo,1);
即可,注意細微差別。
uj5u.com熱心網友回復:
另外,我得補充一下,你這個代碼有太多太多的改進空間了。在成功編譯之前,你需要改掉兩處TextOut為TextOutW,注意是兩處!!!然后還需要把函式CreateMyFont的定義部分的函式名拼寫對(定義的地方少寫了一個e字,注意是定義的部分,不是宣告的部分)uj5u.com熱心網友回復:
我明白了,謝謝你了,以后會注意!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/103023.html
下一篇:資料結構C語言尾插法問題
