C語言視覺化村村通實現Windows程式設計

2021-09-25 04:26:27 字數 4864 閱讀 5667

使用codeblocks整合平台,c語言程式語言,windows程式設計實現介面,prim演算法實現。

工程結構如下:其中example.c檔案是介面實現檔案,prim1.c是演算法實現檔案

prim.c檔案:

#include #include #include "prim1.h"

#define maxv 100

#define inf 32767

double edges[1000][1000];

int n=6;

int root[100][1000][3];

void prim(int v)

msgwithproc;

point pt[7] = ,,,,,,}; //結點位置

hwnd edit1 ;

hdc g_hdc = null;

hinstance g_hinstance = null;

lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam);

lresult __stdcall wmcreate(hwnd hwnd, uint message, wparam wparam, lparam lparam);

lresult __stdcall wmpaint(hwnd hwnd, uint message, wparam wparam, lparam lparam);

lresult __stdcall wmcommand(hwnd hwnd, uint message, wparam wparam, lparam lparam);

lresult __stdcall wmkeydown(hwnd hwnd, uint message, wparam wparam, lparam lparam);

lresult __stdcall wmdestory(hwnd hwnd, uint message, wparam wparam, lparam lparam);

int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd);

wndclass.cbsize = sizeof(wndclas***);

wndclass.style = cs_hredraw | cs_vredraw;

wndclass.lpfnwndproc = wndproc;

wndclass.cbcl***tra = 0;

wndclass.cbwndextra = 0;

wndclass.hinstance = hinstance;

wndclass.hicon = null;

wndclass.hcursor = loadcursor(null, idc_arrow);

wndclass.hbrbackground = (hbrush)getstockobject(ltgray_brush);

wndclass.lpszmenuname = null;

wndclass.lpszclassname = l"page36";

if(!registerclas***(&wndclass))

//為了讓視窗居中

int cxscreen = getsystemmetrics(sm_cxscreen);

int cyscreen = getsystemmetrics(sm_cyscreen);

rect rect = {};

rect.left = cxscreen / 4;

rect.right = cxscreen * 3 / 4;

rect.top = cyscreen / 4;

rect.bottom = cyscreen * 3 / 4;

hwnd hwnd = createwindowex(

null,

l"page36",

window_title,

ws_popup | ws_sysmenu ,

rect.left, rect.top,rect.right-rect.left, rect.bottom-rect.top,

null, null, hinstance, null

); showwindow(hwnd, nshowcmd);

updatewindow(hwnd);

msg msg = ;

while(msg.message != wm_quit)

} unregisterclass(l"page36", hinstance);

return 0;

}//繪製指定屬性的直線

static void drawline(hdc hdc, int x0, int y0, int x1, int y1, int style, int width, colorref color)

//繪製實心圓

static void drawcircle(hdc hdc, int x, int y, int len, colorref color)

//繪製填充矩形

static void drawrect(hdc hdc, int left, int top, int width, int height, int style, colorref color)

//繪製位圖填充矩形

static void drawbmprect(hdc hdc, int left, int top, int width, int height, lpctstr file)

lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam),

, ,

, }; for(int i=0 ;i < 4; i++)

} return defwindowproc(hwnd, message, wparam, lparam);

}lresult __stdcall wmcreate(hwnd hwnd, uint message, wparam wparam, lparam lparam)

lresult __stdcall wmpaint(hwnd hwnd, uint message, wparam wparam, lparam lparam)

//繪製不同模式的直線

drawline(hdc, 105, 50, 425, 50, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 70, 400, 425, 400, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 425, 50, 425, 400, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 70, 50, 70, 400, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 500, 50, 650, 50, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 500, 400, 650,400, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 500, 50, 500, 400, ps_join_bevel, 2, rgb(0,0,0));

drawline(hdc, 650, 50, 650, 400, ps_join_bevel, 2, rgb(0,0,0));

//繪製圓

for(int i=1;i<=6;i++);

itoa(i,string,16);

textout(hdc, pt[i].x-6, pt[i].y-6, text(string), 1);

}//繪製文字*/

setbkcolor(hdc,rgb(192,192,192));

textout(hdc, 30, 40, text("show graph"), 10);

textout(hdc, 480, 40, text("control"), 7);

textout(hdc, 520, 190, text("start"),5 );

endpaint(hwnd, &ps);

return 0;

}lresult __stdcall wmcommand(hwnd hwnd, uint message, wparam wparam, lparam lparam)}}

endpaint(hwnd, & ptstr); // 結束繪圖

return 0;

} return 0;

}lresult __stdcall wmkeydown(hwnd hwnd, uint message, wparam wparam, lparam lparam)

case vk_escape:

postquitmessage(0);

break;

} return 0;

}lresult __stdcall wmdestory(hwnd hwnd, uint message, wparam wparam, lparam lparam)

example.**件:

#ifndef unicode

#define unicode

#define unicode_was_undefined

#endif

#ifdef unicode_was_undefined

#undef unicode

#endif

7 10 公路村村通 C語言

現有村落間道路的統計資料表中,列出了有可能建設成標準公路的若干條道路的成本,求使每個村落都有公路連通所需要的最低成本。輸入資料報括城鎮數目正整數n 1000 和候選道路數目m 3n 隨後的m行對應m條道路,每行給出3個正整數,分別是該條道路直接連通的兩個城鎮的編號以及該道路改建的預算成本。為簡單起見...

資料視覺化 R語言實現網路視覺化

最近在學習貝葉斯網路,當用k2演算法建立了貝葉斯網路結構之後,用r語言工具可以很清楚地實現網路視覺化。例如,在鐵達尼號資料集中,最後生成的貝葉斯網路結構如下 age,portembarked,numparentschildren,age numparentschildren,passengercla...

C語言實現flappy bird(視覺化程式設計)

定義圖形變數陣列 initgraph 288 624 構建乙個寬288,高624的視窗 loadimage bj 0 名稱 將賦給圖形變數,就相當於給起乙個名字 loadimage bj 1 名稱 putimage 0 0,bg 0 在0,0的位置貼上 putimage 0 512 bg 1 因為我...