Thread: GUI for beginners

  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715

    GUI for beginners

    Hi, I want to write program that will display graph f(x)=a*x^2+b*x+c
    user will enter a parameters a,b,c.
    I only wrote programs for console.
    I can solve this in console by plotting '*' at some small step, but this is not what I want.
    Now, I don't know how to print
    continuous curve, and should I use MFC? I really don't have experince and don't know from where to start. What I should learn first. I found some code on net that uses MFC and stuff seems pretty cool, but code and functions I don't understand fully, and there are a lot of .h and source code files that are hard to read.
    Do you have any advices? From where to start? What tutorial to use? I already spent a lot of time surfing. I assume that probably most of you had similar problem.
    Thanks in advance!

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Quote Originally Posted by Micko
    ...I can solve this in console by plotting '*' at some small step, but this is not what I want...
    I believe that is exactly what you want. You can increase the steps and draw lines in between the points to speed it up a bit but essentially, you make your own graphing calculator.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Actually, I want windows aplication and that graph would be plotted to it's own window. This problem is just part of bigger program, so If I use console window, I would have to type all in the same window and that wouldn't look nice.
    By the way how to draw line between two points in the console window?

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    ok, didn't realize you were talking about getting it into a window.

    You're going to have to learn a ton of Windows API stuff first. Once you figure out how to make a window come up (try Petzold), come back and ask the same question. My answer of course is the same. You'll need to draw lines from point to point using the MoveToEx() and LineTo() Windows API functions operating on a device context. the windows GDI makes graphics a little easier but it still comes down to you plotting points.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Get somthing like Borland C++ Builder 5/6 or Microsoft Visual C++, both are good. I prefer Borland, but lots of people here swear by Visual C++.

    This'll help you out creating the forms, and take a lot of grunt work out of creating the window. After that, its all about drawing to the scree n (Form1->Canvas->Draw(x1,y1,x2,y2,line type) in BCB) so if you ran a counted loop, x=1;x< whatever then put X^3 + 2 = Y, get that coord, then draw, loop, and wash. THis is the method I would take, not sure if its the best! but its worth a shot. Thats the way you do graphing by hand....

    DW

  6. #6
    Registered User gandalf_bar's Avatar
    Join Date
    Oct 2003
    Posts
    92
    What about qt or gtkmm.......... or wxwidgets
    www.trolltech.com
    www.gtkmm.org
    www.wxwidgets.org

    Oh yeah don't forget about C++BuilderX
    A man asked, "Who are you?"
    Buddha answered, "I am awaked."

  7. #7
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    This part of code:
    Code:
    void CDrawMag::OnPaint() 
    {
    	CPaintDC dc(this); // device context for painting
    	
    	CRect rect;
    	
    	dc.SetPolyFillMode(WINDING);
    
    	CBrush brushBlack(m_BrushBlack.lbColor);
    //	CBrush brushCross(HS_CROSS, RGB(0, 0, 0));
    	GetClientRect(rect);
    
    	dc.FillRect(&rect, &brushBlack);
    	
    //	dc.SelectObject(&brushCross);
    //	dc.Rectangle(rect);
    
    	//------------------------------
    	// draw grid in green color
    	//------------------------------
    	int x, y, xstep, ystep;
    	int H = rect.Height();
    	int W = rect.Width();
    	CPen GreenPen(PS_DOT, 1, RGB(0, 255, 0));
    	dc.SelectObject(&GreenPen);
    	
    	xstep = W / 10;
    	for (x=0; x<W; x+=xstep) 
    	{
    		dc.MoveTo(x, 0);
    		dc.LineTo(x, H);
    	}
    
    	ystep = H / 10;
    	for (y=0; y<H; y+=ystep) 
    	{
    		dc.MoveTo(0, y);
    		dc.LineTo(W, y);
    	}
    and similar I found!
    Because of the names I concluded that these functions exists somwhere in the library.
    The books you recommended start from scratch and I don't have time to learn all that.
    Consider this:
    Code:
    class CAboutDlg : public CDialog
    {
    public:
    	CAboutDlg();
    
    // Dialog Data
    	//{{AFX_DATA(CAboutDlg)
    	enum { IDD = IDD_ABOUTBOX };
    	//}}AFX_DATA
    
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CAboutDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    	//}}AFX_VIRTUAL
    
    // Implementation
    protected:
    	//{{AFX_MSG(CAboutDlg)
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    
    CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    	//{{AFX_DATA_INIT(CAboutDlg)
    	//}}AFX_DATA_INIT
    }
    
    void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CAboutDlg)
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    	//{{AFX_MSG_MAP(CAboutDlg)
    		// No message handlers
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CFIRDsgnDlg dialog
    
    CFIRDsgnDlg::CFIRDsgnDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CFIRDsgnDlg::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CFIRDsgnDlg)
    	m_Order = 511;
    	m_SRate = 8000;
    	//}}AFX_DATA_INIT
    	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    
    
    	Coef  = NULL;
    	Order = 0;
    
    }
    If you recognize this may help me with some link on how to use what already exists not to learn how to make this.
    I really have no knowledge about this issuse and if someone this seems silly or something like that I apologize in advance!
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Programming...
    By ShadeS_07 in forum C++ Programming
    Replies: 12
    Last Post: 12-28-2008, 04:58 PM
  2. Convert Windows GUI to Linux GUI
    By BobS0327 in forum Linux Programming
    Replies: 21
    Last Post: 11-27-2005, 04:39 AM
  3. .NET And GUI Programming :: C++
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 01-27-2002, 04:22 PM
  4. GUI Programming :: C++ Exclusive
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2002, 03:22 PM
  5. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 08:03 PM