注册 登录
编程论坛 C++教室

求<windows.h>画图的完整函数并附解析

hedaacm 发布于 2012-11-17 22:16, 2939 次点击
求<windows.h>画图的完整函数并附解析。注:不能用tuboc的graphics.h  也不能用VC的MFC。就是在VC环境下的windows
能画出下面的二叉树(其实这棵树为哈夫曼树,叶子结点存有权值)
大家会的,赶快画哈,送分给你

只有本站会员才能查看附件,请 登录



[ 本帖最后由 hedaacm 于 2012-11-17 22:21 编辑 ]
19 回复
#2
hedaacm2012-11-17 22:18
这次的9、9不是178分    竟然是146    哈  大BUG
#3
hedaacm2012-11-17 23:01
我知道为啥只有146分了     因为我就剩146分了   
#4
TonyDeng2012-11-17 23:04
恭喜恭喜,赶快结了。
#5
青春无限2012-11-17 23:06
你老是创造论坛奇迹!!!佩服!!
#6
hedaacm2012-11-17 23:21
回复 4楼 TonyDeng
结个啥子嘛      你这么厉害的人   也不帮帮小生      你把代码放出来我就结     然后。。。。。然后把我所有的分。。。分都给你
#7
hedaacm2012-11-17 23:27
回复 4楼 TonyDeng
给答案吧     
我知道你windows很好     俺现在还不想学windows     明年再学       如果你不给答案    我会睡不着的   
#8
TonyDeng2012-11-17 23:30
我哪里有答案给你呀。用API画这个很麻烦的啦,没事折磨自己才弄。
#9
hedaacm2012-11-17 23:39
回复 8楼 TonyDeng
折磨。。。。。。好吧  以后我再折磨我自己吧 。。。。不麻烦您了
#10
寒风中的细雨2012-11-17 23:54
Ding~
#11
lz10919149992012-11-17 23:58
我还画不出来呢,坐等高手!
#12
wp2319572012-11-18 00:47
用画笔画啊
#13
hedaacm2012-11-18 22:31
回复 12楼 wp231957
画笔?  你把代码放出来啊
#14
hedaacm2012-11-18 23:03
回复 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


只有本站会员才能查看附件,请 登录



#15
hedaacm2012-11-18 23:05
不过是用C写的     不知能否用C++    求围观   求指导
#16
zxd5432012-11-18 23:45
这个。。。。看着就真头疼
#17
mmmmmmmmmmmm2012-11-19 09:21
恭喜恭喜,赶快结了。
#18
hedaacm2012-11-19 12:29
回复 17楼 mmmmmmmmmmmm
真郁闷   自己的问题   最终自己解决了   
#19
寒风中的细雨2012-11-19 16:13
回复 18楼 hedaacm
受惊呀!!!  怎么把分都压我这儿了, 请不要告诉我是误操作
#20
hedaacm2012-11-19 21:29
回复 19楼 寒风中的细雨
string   s;
s="正确操作";
if(s==正确操作)
  cout<<" 某人会,就是不帮我。觉的你比他好,so.......";   
1