| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2939 人关注过本帖
标题:求<windows.h>画图的完整函数并附解析
只看楼主 加入收藏
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:0 
我还画不出来呢,坐等高手!

My life is brilliant
2012-11-17 23:58
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
用画笔画啊

DO IT YOURSELF !
2012-11-18 00:47
hedaacm
Rank: 6Rank: 6
来 自:河北保定
等 级:侠之大者
威 望:2
帖 子:400
专家分:418
注 册:2012-1-26
收藏
得分:0 
回复 12楼 wp231957
画笔?  你把代码放出来啊
2012-11-18 22:31
hedaacm
Rank: 6Rank: 6
来 自:河北保定
等 级:侠之大者
威 望:2
帖 子:400
专家分:418
注 册:2012-1-26
收藏
得分:0 
回复 11楼 lz1091914999
你就是高手啊    你们应该都学过windows吧    应该能画出吧   我在网上看过能画出的代码:
程序代码:
#include <stdio.h>

#include <string.h>

#include <windows.h>

struct BTree {


 int data;


 struct BTree * left;


 struct BTree * right;

};//end struct BTree

BTree * CreateLeaf(int number)

{


 BTree * l = new BTree;


 l->data = number;


 l->left = 0;


 l->right = 0;


 return l;

}//end CreateLeaf

void append(BTree ** root, int number)

{


 if (!root) return ;


 BTree * t = *root;


 if (!t) {

  *root = CreateLeaf(number);

  return ;


 }//end if


 while(t) {

  if(number == t->data ) return ; //ignore duplicated elements.

  if(number < t->data ) {

   if(!t->left ) {

    t->left = CreateLeaf(number);

    return ;

   }//end if

   t = t->left ;

  }else{

   if(!t->right ) {

    t->right = CreateLeaf(number);

    return ;

   }//end if

   t = t->right ;

  }//end if


 }//end while

}//end append

void PrintLeaf(const BTree * root)

{


 if (!root) return ;


 if (root->left ) PrintLeaf(root->left );


 printf("%d\t", root->data);


 if (root->right ) PrintLeaf(root->right );

}//end printLeaf

void PrintTree (const BTree * root)

{


 printf("[\t");


 PrintLeaf(root);


 printf("]\n");

}//end printTree

BTree * global_root = 0;

int Offsets[32];

int LevelHeight = 50;

void GDIShowTree(HDC h, BTree * root, int level, int center)

{


 if (!root || !h) return ;


 char number[32] = ""; sprintf(number, "%d", root->data );


 int x0 = center; int off = Offsets[level + 1]; int x1 = 0;


 int y0 = level * LevelHeight; int y1 = y0 + LevelHeight;


 if (root->left ) {

  x1 = x0 - off;

  GDIShowTree(h, root->left , level + 1, x1);

  MoveToEx(h, x0, y0, 0);

  LineTo(h, x1, y1);


 }//end if


 if (root->right) {

  x1 = x0 + off;

  GDIShowTree(h, root->right, level + 1, x1);

  MoveToEx(h, x0, y0, 0);

  LineTo(h, x1, y1);


 }//end if


 TextOut(h, x0, y0, number, strlen(number));

}//end GDIShowTree

LRESULT CALLBACK MsgProc(

  HWND hwnd,      // handle to window

  UINT uMsg,      // message identifier

  WPARAM wParam,  // first message parameter

  LPARAM lParam)   // second message parameter

{


 HDC hDC = 0; int i = 0; RECT r = {0, 0, 0, 0}; int width = 0;


 PAINTSTRUCT ps;


 switch(uMsg){


 case WM_PAINT:

  hDC=BeginPaint(hwnd,&ps);

  GetClientRect(hwnd, &r);

  width = r.right ;

  for(i = 0; i < 32; i++) {

   width /= 2;

   Offsets[i] = width;

  }//next i

  GDIShowTree(hDC, global_root, 0, r.right / 2);

  EndPaint(hwnd,&ps);


 break;


 case WM_CLOSE:

  exit(0);


 default:

  return DefWindowProc(hwnd,uMsg,wParam,lParam);


 }//end case


 return 0;

}//end MsgProc

int main(void)

{


 int x = 0; 


 printf("Enter some numbers ended with 0:");


 do {

  scanf("%d", &x);

  append(&global_root, x);


 }while(x);


 PrintTree(global_root);


 WNDCLASS wc;


 wc.cbClsExtra=0;


 wc.cbWndExtra=0;


 wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);


 wc.hCursor=LoadCursor(NULL,IDC_CROSS);


 wc.hIcon=LoadIcon(NULL,IDI_ERROR);


 wc.hInstance=0;


 wc.lpfnWndProc=MsgProc;


 wc.lpszClassName="Binary Tree Demo";


 wc.lpszMenuName=NULL;


 wc.style=CS_HREDRAW | CS_VREDRAW;


 RegisterClass(&wc);


 HWND hwnd;


 hwnd=CreateWindow("Binary Tree Demo","Enoch WILLS 2010",WS_OVERLAPPEDWINDOW,


 0,0,640,480,0,0,0,0);


 ShowWindow(hwnd,SW_MAXIMIZE);


 UpdateWindow(hwnd);


 MSG msg;


 while(GetMessage(&msg,NULL,0,0))


 {

  TranslateMessage(&msg);

  DispatchMessage(&msg);


 }//end while


 return 0;

}//end main


图片附件: 游客没有浏览图片的权限,请 登录注册



2012-11-18 23:03
hedaacm
Rank: 6Rank: 6
来 自:河北保定
等 级:侠之大者
威 望:2
帖 子:400
专家分:418
注 册:2012-1-26
收藏
得分:0 
不过是用C写的     不知能否用C++    求围观   求指导
2012-11-18 23:05
zxd543
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:内蒙古
等 级:贵宾
威 望:17
帖 子:453
专家分:2351
注 册:2012-4-12
收藏
得分:0 
这个。。。。看着就真头疼

马马虎虎 不吝赐教 我是路过蹭分滴
2012-11-18 23:45
mmmmmmmmmmmm
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:8
帖 子:388
专家分:1809
注 册:2012-11-2
收藏
得分:0 
恭喜恭喜,赶快结了。

我们的目标只有一个:消灭0回复!
while(1)
++money;
2012-11-19 09:21
hedaacm
Rank: 6Rank: 6
来 自:河北保定
等 级:侠之大者
威 望:2
帖 子:400
专家分:418
注 册:2012-1-26
收藏
得分:0 
回复 17楼 mmmmmmmmmmmm
真郁闷   自己的问题   最终自己解决了   
2012-11-19 12:29
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
回复 18楼 hedaacm
受惊呀!!!  怎么把分都压我这儿了, 请不要告诉我是误操作
2012-11-19 16:13
hedaacm
Rank: 6Rank: 6
来 自:河北保定
等 级:侠之大者
威 望:2
帖 子:400
专家分:418
注 册:2012-1-26
收藏
得分:0 
回复 19楼 寒风中的细雨
string   s;
s="正确操作";
if(s==正确操作)
  cout<<" 某人会,就是不帮我。觉的你比他好,so.......";   
收到的鲜花
  • 寒风中的细雨2012-11-22 09:10 送鲜花  10朵   附言:看来我还是沾某人会的光了......
2012-11-19 21:29
快速回复:求<windows.h>画图的完整函数并附解析
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018688 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved