1、C语言的应用很广的,比如 单片机,嵌入式,都需要C语言,而C语言也是非常合适类似开发的,这个是和硬件电路密切相关的,虽然很少用C语言开发可视化界面
(目前我没有用过),但可以控制各种硬件的运行动作。此外.C语言可以开发可视化的程序界面,但这是高级的C语言编程,需要继续学习才能了解的。更重要的
一点,学习C语言个人一种编程开发的思想,计算机的各种语言很多,但都有类似的地方,学过C语言在学习其他语言如java等就简单了.
2、下面是一个在windows窗体上显示树形图的程序。在vc6中新建win32工程(注意不是控制台)。然后新建c++源文件,粘贴代码进去,编译运行即可。
#include <windows.h>
#include <math.h>
#define AD 3.14159265*45/180//相邻树枝的旋转角度
#define Gold 0.618//相邻树枝的长度比例 范围0-1
#define Len 100 //树根的长度
HDC hdc;
struct Node
{
double x;//节点坐标x
double y;//节点坐标y
double AM;//节点的左右分支的中线方向
double Length;//节点的原支长度
struct Node *LeftNode;//左分支
struct Node *RightNode;//右分支
};
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void DL(double x1,double y1,double x2,double y2);
void DrawNode(struct Node *ThisNode);
void DrawTree (void);
//画一条直线
void DL(double x1,double y1,double x2,double y2)
{
MoveToEx (hdc, x1, y1, NULL) ;
LineTo (hdc, x2, y2) ;
}
void DrawNode(struct Node *ThisNode)
{
//左分支的地址、角度、长度、坐标
ThisNode->LeftNode=(struct Node *)malloc(sizeof(struct Node));
ThisNode->LeftNode->AM =ThisNode->AM +AD;
ThisNode->LeftNode->Length =ThisNode->Length *Gold;
ThisNode->LeftNode->x=ThisNode->x+cos(ThisNode->LeftNode->AM)*ThisNode->LeftNode->Length;
ThisNode->LeftNode->y=ThisNode->y+sin(ThisNode->LeftNode->AM)*ThisNode->LeftNode->Length;
//右分支的地址、角度、长度、坐标
ThisNode->RightNode=(struct Node *)malloc(sizeof(struct Node));
ThisNode->RightNode->AM =ThisNode->AM -AD;
ThisNode->RightNode->Length =ThisNode->Length *Gold;
ThisNode->RightNode->x=ThisNode->x+cos(ThisNode->RightNode->AM)*ThisNode->RightNode->Length;
ThisNode->RightNode->y=ThisNode->y+sin(ThisNode->RightNode->AM)*ThisNode->RightNode->Length;
//画图
DL(ThisNode->x,ThisNode->y,ThisNode->LeftNode->x,ThisNode->LeftNode->y);
DL(ThisNode->x,ThisNode->y,ThisNode->RightNode->x,ThisNode->RightNode->y);
//递归终点
if(ThisNode->Length>5 )
{
DrawNode(ThisNode->LeftNode);
DrawNode(ThisNode->RightNode);//
}
}
void DrawTree (void)
{
struct Node TreeRoot;
TreeRoot.x =500;//树根的横坐标
TreeRoot.y =Len;
TreeRoot.AM =3.14159265/2;
TreeRoot.Length =Len;
DrawNode(&TreeRoot);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc= WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("Sine Wave Using Polyline"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps ;
switch (message)
{
case WM_SIZE:
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
DrawTree();
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}