How do you set this up?

This is a discussion on How do you set this up? within the Windows Programming forums, part of the Platform Specific Boards category; I have a console program I’m trying to put into an dialog MFC api… I’ve implemented the class… fixed syntax ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    31

    How do you set this up?

    I have a console program I’m trying to put into an dialog MFC api… I’ve implemented the class… fixed syntax and linking errors and so on but now that I’m trying to actually use it I’m having some problems.

    In the example program they connect to the server as such:
    Code:
    int _tmain(int, _TCHAR*)
    {
    	Trade tc;
    	
    	if ( tc.Startup() )
    	{
    I was thinking just throwing this into the constructor:
    Code:
    CBasic_Order_WindowDlg::CBasic_Order_WindowDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CBasic_Order_WindowDlg::IDD, pParent)
    	, m_equity_option(-1)
    	, m_operation(-1)
    	, m_quantity(_T(""))
    	, m_option_symbol(_T(""))
    	, bconnected(false)
    {
    	Trade tc;
    	
    	if(tc.Startup()){
    		AfxMessageBox("You connected to the server.");
    	}
    
    	else {
    		AfxMessageBox("You couldn't connect to the server.\nPlease set the UserConfig.ini file.");
    	}
    
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    But, this I couldn’t axcess any of the Trade class functions from event handlers attached the buttons in the dialog. I figured it might calling maybe calling the constructor over and over causing problems… I’m not experaince in Windows Programming. So I created a connect button (that way I could make sure it would only be called once. But, when I click connect now I get the

    Code:
    AfxMessageBox("You connected to the server.");
    Dialog but then the program just hangs. So I guess my question is how do you referance and create an object of another class which I can repeatly referance from a dialog box, this dialog box loops until the user hits an exit button.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Have you got an instance of the Trade class as a member of the dialog?

    Then the Trade member object will have scope while the dialog runs.
    Set the Trade member up in the dialogs constructor or in the dialogs OnInit() (or OnCreate()) handler.

    If you put the Trade class as a local in the Dialogs constructor it will lose scope when the constructor ends.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    31
    I tried creating an object in both the constructor and in
    Code:
    BOOL CBasic_Order_WindowDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    
    	// TODO: Add extra initialization here
    	Trade tc;
    
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }

    But, I still get errors in my member functions when I try to referance that object.
    Code:
    void CBasic_Order_WindowDlg::OnBnClickedButtonDisconnect()  //disconnect from RedSky
    {
    	//Trade tc;
    
    	if(bconnected == true){
    		tc.Shutdown();
    		bconnected = false;
    		AfxMessageBox("Logged Off.");
    	}
    
    	else{
    		AfxMessageBox("You're not connected to the RedSky server.");
    	}
    C2065: 'tc' undeclared identifier

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Put the Trade class as a member in the Dialogs class declaration (the Dialogs header).

    ie where m_equity_option is declared.
    Last edited by novacain; 01-23-2006 at 06:54 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 01-18-2008, 03:06 AM
  2. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Set default directory with GetTempDir?
    By Bajanine in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2003, 11:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21