图形用户界面2010中的gui绘图 [英] gui drawing in c usin visual stdio 2010

查看:65
本文介绍了图形用户界面2010中的gui绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以的话,我有2个问题?..
1)我尝试将GetWindowText与&至变量一起使用,但在初始化它们时它们仍然为0时没有任何反应..我通过使用WGPrintf(hDC,600,670,%f", F);但它打印了0.00000,所以它没有变化
2)我需要使用绘制曲线按钮来绘制曲线,然后单击它,所以我认为我必须在情况wm_command时使用绘制fn ...但是当我这样放置时

i have 2 questions if i may?..
1)i tried to use GetWindowText with the variables from &to but nothing happened they still 0 as i initialize them..i made a test to know if tey change or not by using WGPrintf(hDC,600,670,"%f",f); but it printed 0.00000 so it means it didn''t change
2)i need the draw curve button to draw the curve win i click it so i think i must use the draw fn at case wm_command...but when i put it like that

case 1:
					{   
				       if(controlEvent==BN_CLICKED)
					   drawing(hWnd,from,to);
					   InvalidateRect(hWnd,NULL,FALSE);
					   break;
					}  


什么都没出现,所以我该怎么办?
预先谢谢你...


nothing appears so what shal i do???
thank you in advance...

#include "wingui.h"
#include "math.h"
#define PI 3.14
float m,l,f,t,c;
static float from =0 ,to =0 ;
int h,k, r=0,z=10,a=-25;

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
void drawing(HWND hWnd,float f,float t)
 {
   HDC hDC=GetDC(hWnd);
   HPEN holdPen, hPen1;
   hPen1   = WGCreatePen   (RGB(0,255,0),5,PS_SOLID);
   holdPen = (HPEN)SelectObject(hDC,hPen1);
   MoveToEx(hDC,74,235,NULL); 
   if (z<18)
     { 
       do
         { 
           float y = sin(((f-74)*PI/100)*10/z);
           LineTo(hDC,f,235-(y*100)*z/10);
           f+=1;
         } while(f<t);>
     }
   else 
     {
       do
         {
		   float y = sin(((f-74)*PI/100)*10/17);
           LineTo(hDC,f,235-(y*100)*17/10);
           f+=1;
         } while(f<t);>
     }
  ReleaseDC(hWnd,hDC);
 }

HWND hSecondEdit,hThirdEdit;
LRESULT WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{    HDC hDC = GetDC(hWnd);
	RECT R;
    GetClientRect(hWnd, &R);
    int width = GetSystemMetrics(SM_CXSCREEN);
	int height = GetSystemMetrics(SM_CYSCREEN);
	switch(message)
	{
	case WM_CREATE:
		{
			SetWindowText(hWnd, "Equation Analyzer");
			MoveWindow(hWnd,10,10,1330,720,FALSE);
			HWND hButton1,hButton2,hButton3,hButton4, hFirstEdit,hSecondEdit,hThirdEdit,hFourthEdit,hFifthEdit;
	hButton1= CreateWindow("Button", "" , WS_CHILD|WS_VISIBLE, 16*width/20, 1*height/12 , 200, 50, hWnd ,(HMENU)(UINT_PTR)1,NULL,NULL);
	  SetWindowText(hButton1, "Draw Curve");
    hButton2 = CreateWindow("Button", "" , WS_CHILD|WS_VISIBLE, 16*width/20 , 2*height/12 , 200, 50, hWnd ,(HMENU)(UINT_PTR)2,NULL,NULL);
	  SetWindowText(hButton2, "Draw Equation");
    hButton3 = CreateWindow("Button", "" , WS_CHILD|WS_VISIBLE, 16*width/20, 3*height/12, 200, 50, hWnd ,(HMENU)(UINT_PTR)3,NULL,NULL);
	  SetWindowText(hButton3, "Zoom In");
	 hButton4 = CreateWindow("Button", "" , WS_CHILD|WS_VISIBLE, 16*width/20, 4*height/12, 200, 50, hWnd ,(HMENU)(UINT_PTR)4,NULL,NULL);
	  SetWindowText(hButton4, "Zoom Out");
    hFirstEdit =CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,90,625 ,620,35,hWnd,(HMENU)(UINT_PTR)5,NULL,NULL);
      SetWindowText(hFirstEdit,"");   //f(x)
    hSecondEdit =CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,95,670 ,60,25,hWnd,(HMENU)(UINT_PTR)6,NULL,NULL);
      SetWindowText(hSecondEdit,"");   //from
    hThirdEdit =CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,190,670 ,80,25,hWnd,(HMENU)(UINT_PTR)7,NULL,NULL);
      SetWindowText(hThirdEdit,"");   //to
    hFourthEdit =CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,375,670 ,80,25,hWnd,(HMENU)(UINT_PTR)8,NULL,NULL);
      SetWindowText(hFourthEdit,"");   //resolution
    hFifthEdit =CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE|ES_WANTRETURN,490,670 ,80,25,hWnd,(HMENU)(UINT_PTR)9,NULL,NULL);
      SetWindowText(hFifthEdit,"");   //x
	 
		}
		break;
		case WM_COMMAND:
		{   
			HDC hDC=GetDC(hWnd);
            WORD controlEvent = HIWORD(wParam);
			WORD controlID = LOWORD(wParam);
			HWND hControl = (HWND)lParam;
			 switch(controlID)
			   {
				
                 case 1:
					 { 
					  if(controlEvent==BN_CLICKED)  
				     
					  InvalidateRect(hWnd,NULL,FALSE);
					   break;
					 }   
				 case 3:              
					 {
				       if(controlEvent==BN_CLICKED)
					   z++;
					   InvalidateRect(hWnd,NULL,FALSE);
					   
				       break;
				     }
                case 4:              
				     {
				      if(controlEvent==BN_CLICKED) 
					  z--;
					  InvalidateRect(hWnd,NULL,FALSE);
			           break;
					 }
					
					  case 6:              
				       {
                        if(controlEvent==EN_CHANGE)
					      {
				            char text1[128];
						    GetWindowText(hSecondEdit,text1,128);
				            from = atof(text1);
					        f=from;
						WGPrintf(hDC,600,670,"%f",f);
							break;
				          }
					   }
					     
			     case 7:              
				     {
				       if(controlEvent==EN_CHANGE)
					  {
						  char text2[128];
				          GetWindowText(hSecondEdit,text2,128);
				          to = atof(text2);
						  t=to;
						  break;
					  }
					 }
				     }
				
			ReleaseDC(hWnd,hDC);
			return 0;
	}
		
          case WM_PAINT :
		   {
		     HDC hDC=GetDC(hWnd);
            HBRUSH holdbrush, hbrush1,hbrush2,hbrush3,hbrush4,hbrush5,hbrush6;
			HPEN holdPen, hPen1,hPen2,hPen3,hPen4;
			HFONT holdfont, hfont1,hfont2,hfont3,hfont4;
            hbrush1 = WGCreateBrush (RGB(0,0,0),HS_SOLID);
			hbrush2 = WGCreateBrush (RGB(255,255,255),HS_SOLID);
			hbrush3 = WGCreateBrush (RGB(245,194,194),HS_SOLID);
			hbrush4 = WGCreateBrush (RGB(255,255,255),HS_NULL);
			hbrush5 = WGCreateBrush (RGB(150,150,200),HS_SOLID);
			hbrush6 = WGCreateBrush (RGB(0,204,153),HS_SOLID);
			hPen1   = WGCreatePen   (RGB(0,255,0),5,PS_SOLID);
			hPen2   = WGCreatePen   (RGB(150,150,150),1,PS_SOLID);
			hPen3   = WGCreatePen   (RGB(150,150,150),3,PS_SOLID);
			hPen4   = WGCreatePen   (RGB(200,200,200),3,PS_SOLID);
			hfont1  =WGCreateFont ("Calibri",15,FS_BOLD,-600);
			hfont2  =WGCreateFont ("Calibri",15,FS_BOLD,0);
            hfont3  =WGCreateFont ("New Times Roman",16,FS_ITALIC|FS_UNDERLINE,0);
			hfont4  =WGCreateFont ("New Times Roman",20,FS_ITALIC|FS_BOLD,0);
			
		    holdbrush = (HBRUSH)SelectObject(hDC,hbrush3);
			Rectangle(hDC,0,0,10000,4500);
			SelectObject(hDC,hbrush1);
			Rectangle(hDC,30,30,1010,455);
			
			SelectObject(hDC,hbrush5);
            Rectangle(hDC,90,470,710,615);
	
			SelectObject(hDC,hbrush1);
			SetBkMode(hDC, TRANSPARENT);
			WGPrintf(hDC,10,525,"Equation");
			WGPrintf(hDC,40,625,"F(X)");
            WGPrintf(hDC,40,670,"From");
            WGPrintf(hDC,160,670,"To");
            WGPrintf(hDC,275,670,"Resolution");
            WGPrintf(hDC,460,670,"x=");
			
           holdPen = (HPEN)SelectObject(hDC,hPen2);
           for(int i =70;i<width-400;i>            {
              for( int h =60;h<400;h=h+30)
               {
                 Rectangle(hDC,i,h,i+35,h+30);
               }
            }
		    SelectObject(hDC,hPen3);  
			MoveToEx(hDC,70,60,NULL);
			LineTo(hDC,980,60);
			MoveToEx(hDC,70,420,NULL);
			LineTo(hDC,980,420);
		    MoveToEx(hDC,70,60,NULL);
			LineTo(hDC,70,420);
			MoveToEx(hDC,980,60,NULL);
			LineTo(hDC,980,420);
			
			
		
		       k=0;
                for(int i=80;i<=1015;i=i+35)
              {
               SetBkMode(hDC, TRANSPARENT);
               SetTextColor(hDC,RGB(225,200,0));
               SelectObject(hDC,hfont1);
               WGPrintf(hDC,i,420,"%d",10*k/z);
               k+=5;
		      }                              
		
			 
			m=0.24;
            for(int i=50;i<=410;i=i+30)
            {
              SetTextColor(hDC,RGB(225,200,0));
              SelectObject(hDC,hfont2);
              WGPrintf(hDC,40,i,"%.2f",10*m/z);
              m-=0.02;
            }
			 drawing(hWnd,f,t);
			
			DeleteObject(hbrush1);
			DeleteObject(hbrush2);
			DeleteObject(hbrush3);
			DeleteObject(hbrush4);
			DeleteObject(hbrush5);
			DeleteObject(hbrush6);
            DeleteObject(hPen1);
		    DeleteObject(hPen2);
		    DeleteObject(hPen3);
		    DeleteObject(hPen4);
		    DeleteObject(hfont1);
		    DeleteObject(hfont2);
		    DeleteObject(hfont3);
			ReleaseDC(hWnd,hDC);
			break;
		   }
	}
	return WGDefaultWindowProc(hWnd, message, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	return WGCreateMainWindow(hInstance, nCmdShow, WndProc);
}

推荐答案

多年来,我没有在WinForms中完成任何C ++的工作,所以我可能还差一些,但是我使用了很多自定义绘图功能C#.
为什么要先调用drawing()函数然后执行InvalidateRect?
您正在绘制,然后调用InvalidateRect,它将强制发送WM_PAINT消息.
发送WM_PAINT消息时,所有图形都需要集中并完成.

希望这对您有所帮助,并祝您好运.
I haven''t done any C++ in WinForms in many years so I may be a little off base but I do a lot of custom drawing with C#.
Why are you calling the drawing() function then doing a InvalidateRect?
You are drawing then calling InvalidateRect which forces the WM_PAINT message to be sent.
All drawing needs to be centralized and done when the WM_PAINT message is sent.

Hope this helps and good luck.


1.您尝试调用GetWindowText(hSecondEdit,text1,128);,但是在使用SetWindowText(hSecondEdit,"");在WM_CREATE上将文本设置为空白之前,这就是您返回空白的原因.
2.您似乎正在尝试绘制到主窗口,但是在调用InvalidateRect()之后,您将其覆盖.您可能应该定义要在哪里进行更好的绘制(例如在单独的窗口或主窗口中的控件中).
1. You try calling GetWindowText(hSecondEdit,text1,128); but you''ve set the text to blank before on WM_CREATE with SetWindowText(hSecondEdit,"");, that''s the reason you get blanks back.

2. You seem to be attempting to draw to the main window, but then you overwrite that after you call InvalidateRect(). You should probably define where you''re going to be drawing to better (as in a separate window or a control on the main window).


这篇关于图形用户界面2010中的gui绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆