C语言有什么用,如何C用写窗口程序

C语言有什么用,如何C用写窗口程序 如何用C画图形, 为什么C写的程序都在黑框框里运行…
学习MFC前我应该学些什么呢

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) ;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-07-10
楼主您好~~
您看看这个 呵呵
其实 我在一年前也和您一样想过这个问题 后来学了MFC才明白 其实黑框程序是在console application工程里运行的那种控制台程序程序。如果需要编写界面,您应该学MFC啦 装一个VC6.0对照孙鑫老师的视频教程慢慢学就会拉 ~~~画图啊 编写界面啊都很方便的 您试试本回答被提问者采纳
第2个回答  2011-07-09
写窗口程序?你还是用VC吧。C语言想做出窗口来,很难啊。
第3个回答  2011-07-09
黑框框是控制台程序
c不能做窗口程序或者很难做,
第4个回答  2011-07-09
学MFC...

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网