Author Topic: question  (Read 519 times)

0 Members and 1 Guest are viewing this topic.

[TKC]Solid Snake

  • Klass Klown
  • ***
  • Posts: 395
    • View Profile
question
« on: September 26, 2006, 11:29:30 am »
how can i get a button in visual studio c++ mfc to lead to a diffrent window/dialog? is there a specific code?

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: question
« Reply #1 on: September 26, 2006, 12:07:45 pm »
In MFC, you often derive your custom class from the base MFC class- so, for example assume you wish to create a dialog.  In this case- the default class for a dialog in MFC is CDialog.

You'd create a class like:

CMainDialog::public CDialog {

public:

//Message Handler functions
afx_msg void OnBtnNewDialogClick();

DECLARE_MESSAGE_MAP()  //VS Macro that adds a message pump to this class

private:
...

};

//This defines all the windows messages we want to respond to.

BEGIN_MESSAGE_MAP(CMainDialog, CDialog)
    ON_COMMAND(IDD_BTNNEWDIALOGCLICK, OnBtnNewDialogClick)
END_MESSAGE_MAP()

In MFC, there are two types of dialogs- modal ones (upon which you can not access any other windows until it is closed) vs modeless ones (run besides others- eg does not appear to 'freeze' the rest of the program like modal ones).

how can i get a button in visual studio c++ mfc to lead to a diffrent window/dialog? is there a specific code?

In this case; to create and display a new dialog from the original one- you'd do something like:

afx_msg void CMainDialog::OnBtnNewDialogClick()
{
    CDifferentDialog CDiffDlg;
    CDiffDlg.DoModal();  //for a modal dialog
}

This will create a model dialog box- provided you've derived CDiffDialog from CDialog like like CMainDialog.

You really need to feel confident with C++ before you can use MFC effeciently.  If you can understand all that syntax I've just written; keep reading articles on the internet about MFC; or buy a book on MFC (MFC from ground up is truely a great, fast-track book that I learnt the basics from).  Otherwise- try to practice writing/understanding C++ classes before you attempt to tackle MFC.

Subsky


[TKC]Solid Snake

  • Klass Klown
  • ***
  • Posts: 395
    • View Profile
Re: question
« Reply #2 on: September 26, 2006, 12:21:03 pm »
aha, thanks subsky, it worked.

dont worry, im not a complete idiot when it comes to developing, i used visual basic for a year, and i am new to mfc, but i know alot about how the script in c++ language works.

ps. but thanks for the advice, ill keep studying c++.
« Last Edit: September 26, 2006, 12:37:17 pm by [TKC]Solid Snake »

Subsky

  • Insane Joker
  • ****
  • Posts: 504
  • Subskii
    • View Profile
Re: question
« Reply #3 on: September 26, 2006, 12:36:46 pm »
Ah thats really good to hear then :).

When you've made something; send a link- always good to show off to others your progress :).

Subsky

[TKC]Solid Snake

  • Klass Klown
  • ***
  • Posts: 395
    • View Profile
Re: question
« Reply #4 on: September 26, 2006, 12:38:38 pm »
im making a very cool trainer, although it may be some time before its done.
« Last Edit: September 26, 2006, 05:40:02 pm by [TKC]Solid Snake »