//源程序,示例代碼:

10年積累的網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有韶山免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
//?Instance_3_1_.cpp?:?Defines?the?entry?point?for?the?application.
//
/*************************************************************************
在窗口中畫一個(gè)旋轉(zhuǎn)的風(fēng)車,風(fēng)車中有三個(gè)葉片,顏色分別為紅黃和藍(lán),
葉片外側(cè)有一個(gè)外接圓。
*************************************************************************/
#include?windows.h
#include?math.h
//?回調(diào)函數(shù)聲明
LRESULT?CALLBACK?WndProc(HWND?hwnd,?UINT?message,?WPARAM?wParam,?LPARAM?lParam);
//?初始化窗口類聲明
BOOL?InitWindowsClass(HINSTANCE?hInstance,?char?*lpszClassName);
//?初始化窗口聲明
BOOL?InitWindows(HINSTANCE?hInstance,?int?nCmdShow,?char?*lpszClassName,?char?*lpTitle);
WNDCLASS?wndclass;?//?定義一個(gè)窗口類
HWND?hwnd;?????????//?定義一個(gè)窗口句柄
const?double?Pi?=?3.1415926;
int?nMaxNumber?=?20;?//?葉片循環(huán)一周中繪圖的次數(shù)
int?nNum?=?0;?//?記錄當(dāng)前的順序
int?WINAPI?WinMain(HINSTANCE?hInstance,
HINSTANCE?hPrevInstance,
LPSTR?????lpCmdLine,
int???????nCmdShow)
{
MSG?Msg;??????????????????????//?定義消息
char?lpszClassName[]?=?"風(fēng)車";?//?窗口的類名
char?lpTitle[]?=?"基本繪圖-旋轉(zhuǎn)的風(fēng)車";???//?窗口標(biāo)題名
//?初始化窗口類
if?(!InitWindowsClass(hInstance,?lpszClassName))
{
return?FALSE;
}
//?初始化窗口
if?(!InitWindows(hInstance,?nCmdShow,?lpszClassName,?lpTitle))
{
return?FALSE;
}
//消息循環(huán)
while(GetMessage(Msg,?NULL,?0,?0))
{
TranslateMessage(Msg);
DispatchMessage(Msg);
}
return?Msg.wParam;?//?程序終止時(shí)將信息返回系統(tǒng)
}
//?初始化窗口類定義
BOOL?InitWindowsClass(HINSTANCE?hInstance,?char?*lpszClassName)
{
//1、窗口類定義
wndclass.style?=?0;?????????????//?窗口類型為默認(rèn)類型
wndclass.lpfnWndProc?=?WndProc;?//?窗口處理函數(shù)為?WNDPROC
wndclass.cbClsExtra?=?0;????????//?窗口類無擴(kuò)展
wndclass.cbWndExtra?=?0;????????//?窗口實(shí)例無擴(kuò)展
wndclass.hInstance?=?hInstance;?//?當(dāng)前實(shí)例句柄
wndclass.hIcon?=?LoadIcon(NULL,?IDI_APPLICATION);?//?窗口的最小化圖標(biāo)為默認(rèn)圖標(biāo)
wndclass.hCursor?=?LoadCursor(NULL,?IDC_ARROW);???//?窗口采用箭頭光標(biāo)
wndclass.hbrBackground?=?(HBRUSH)GetStockObject(WHITE_BRUSH);?//?窗口采用白色背景
wndclass.lpszMenuName?=?NULL;?//?窗口中無菜單
wndclass.lpszClassName?=?lpszClassName;?//類名為?lpClassName
//2、注冊(cè)窗口類
if?(!RegisterClass(wndclass))
{?//?如果注冊(cè)失敗則發(fā)出警告聲音
MessageBeep(0);
return?FALSE;
}
return?TRUE;
}
//?初始化窗口聲明
BOOL?InitWindows(HINSTANCE?hInstance,?int?nCmdShow,?char?*lpszClassName,?char?*lpTitle)
{
//3、創(chuàng)建窗口
hwnd?=?CreateWindow(
lpszClassName,?
lpTitle,?
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,?
0,?
600,?
450,?
NULL,?
NULL,?
hInstance,?
NULL
);
//4、顯示窗口
ShowWindow(hwnd,?nCmdShow);
UpdateWindow(hwnd);
return?TRUE;
}
//?回調(diào)函數(shù)定義
LRESULT?CALLBACK?WndProc(HWND?hwnd,?UINT?message,?WPARAM?wParam,?LPARAM?lParam)
{
HDC?????????hDC;??????????//?定義設(shè)備環(huán)境句柄
HPEN????????hPen;?????????//?定義畫筆句柄
HBRUSH??????hBrush;???????//?定義畫刷句柄
PAINTSTRUCT?PtStr;????????//?定義包含繪制信息的結(jié)構(gòu)體變量
POINT???????pCenterPoint;?//?定義一個(gè)圓盡心點(diǎn)的坐標(biāo)
int?????????nRadious?=?50;//?定義圓的半徑
double??????fAngle;???????//?葉片的直邊與水平軸的夾角
switch(message)
{
case?WM_PAINT:
{?//?處理繪圖消息
hDC?=?BeginPaint(hwnd,?PtStr);????????//?得到設(shè)備句柄
SetMapMode(hDC,?MM_ANISOTROPIC);???????//?設(shè)置映像模式
SetWindowExtEx(hDC,?400,?300,?NULL);???//?設(shè)置窗口區(qū)域(邏輯單位)
SetViewportExtEx(hDC,?600,?450,?NULL);?//?設(shè)置視口區(qū)域(物理單位)
SetViewportOrgEx(hDC,?300,?200,?NULL);?//?設(shè)置視口原點(diǎn)坐標(biāo)為(300,?200)
//?繪制外圓
hPen?=?(HPEN)GetStockObject(BLACK_PEN);
SelectObject(hDC,?hPen);
Ellipse(hDC,?-100,?-100,?100,?100);
//?繪制風(fēng)車的葉片
//?1、畫紅色葉片
hBrush?=?CreateSolidBrush(RGB(255,?0,?0));?
SelectObject(hDC,?hBrush);
fAngle?=?2?*?Pi?/?nMaxNumber?*?nNum;
pCenterPoint.x?=?(int)(nRadious?*?cos(fAngle));
pCenterPoint.y?=?(int)(nRadious?*?sin(fAngle));
Pie(
hDC,?
pCenterPoint.x?-?nRadious,?pCenterPoint.y?-?nRadious,?
pCenterPoint.x?+?nRadious,?pCenterPoint.y?+?nRadious,?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle)),
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle)),?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle?+?Pi)),?
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle?+?Pi))
);
//?2、畫天藍(lán)色葉片
hBrush?=?CreateSolidBrush(RGB(255,?255,?0));?
SelectObject(hDC,?hBrush);
pCenterPoint.x?=?(int)(nRadious?*?cos(fAngle?+?2?*?Pi?/?3));
pCenterPoint.y?=?(int)(nRadious?*?sin(fAngle?+?2?*?Pi?/?3));
Pie(
hDC,?
pCenterPoint.x?-?nRadious,?pCenterPoint.y?-?nRadious,?
pCenterPoint.x?+?nRadious,?pCenterPoint.y?+?nRadious,?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle?+?2?*?Pi?/?3)),?
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle?+?2?*?Pi?/?3)),?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle?+?Pi?+?2?*?Pi?/?3)),
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle?+?Pi?+?2?*?Pi?/?3))
);
//?2、畫黃色葉片
hBrush?=?CreateSolidBrush(RGB(0,?255,?255));?
SelectObject(hDC,?hBrush);
pCenterPoint.x?=?(int)(nRadious?*?cos(fAngle?+?4?*?Pi?/?3));
pCenterPoint.y?=?(int)(nRadious?*?sin(fAngle?+?4?*?Pi?/?3));
Pie(
hDC,?
pCenterPoint.x?-?nRadious,?pCenterPoint.y?-?nRadious,?
pCenterPoint.x?+?nRadious,?pCenterPoint.y?+?nRadious,?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle?+?4?*?Pi?/?3)),?
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle?+?4?*?Pi?/?3)),?
(int)(pCenterPoint.x?+?nRadious?*?cos(fAngle?+?Pi?+?4?*?Pi?/?3)),
(int)(pCenterPoint.y?+?nRadious?*?sin(fAngle?+?Pi?+?4?*?Pi?/?3))
);
nNum++;?//?當(dāng)前充數(shù)增加1
Sleep(50);?//等待0.1秒
InvalidateRect(hwnd,?NULL,?1);?//?重繪窗口區(qū)域
DeleteObject(hPen);
DeleteObject(hBrush);
EndPaint(hwnd,?PtStr);
break;
}
case?WM_DESTROY:
{
//?調(diào)用?PostQuitMessage?發(fā)出?WM_QUIT?消息
PostQuitMessage(0);
}
default:
{
return?DefWindowProc(hwnd,?message,?wParam,?lParam);
}
}
return?0;
}
1、首先要打開瀏覽器。
2、其次在瀏覽器上方搜索欄輸入直線風(fēng)車組成的代碼。
3、最后點(diǎn)擊搜索即可。
你可以拖一個(gè)pictureBox1到你的窗體上,設(shè)置一個(gè)gif圖片的路徑即可
this.pictureBox1.ImageLocation = @"F:\Download\未命名.gif";
所以你需要找的就是一個(gè)籃球gif的圖片,就這么簡單
分享標(biāo)題:java能動(dòng)的風(fēng)車代碼 java編寫旋轉(zhuǎn)風(fēng)車程序
網(wǎng)頁鏈接:http://www.jbt999.com/article28/hjjdjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網(wǎng)站設(shè)計(jì)公司、建站公司、網(wǎng)站制作、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)