TKC-Community

Hacking and Art => Vietcong 1 & 2 => Topic started by: [TKC]Solid Snake on September 26, 2006, 11:29:30 am

Title: question
Post by: [TKC]Solid Snake 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?
Title: Re: question
Post by: Subsky 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

Title: Re: question
Post by: [TKC]Solid Snake 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++.
Title: Re: question
Post by: Subsky 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
Title: Re: question
Post by: [TKC]Solid Snake on September 26, 2006, 12:38:38 pm
im making a very cool trainer, although it may be some time before its done.