Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++6: register card with dialog boxes?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
How can i program a register card that consists of 6 or more already existing dialog (s) (boxes)? The dialogs i already have programmed, but how can i link them together? One dialog box should be one index card, together they should form a register where in can select the dialog i want; like a box with register cards in it where i can flip trough them by selecting the tabs. Please help! Thanks very much in advance...!!! :)
 
You can change the Base class of these 6 Dialogs to CPropertyPage (easy replace in *.cpp and *.h - Files all CDialog with CPropertyPage). If Your Dialogs (PropertyPages) classes are CPpg1, CPpg2 etc., You can start it all so:
CPropertySheet psheet("Register");
psheet.m_psh.dwFlags |= PSH_NOAPPLYNOW; //Do not show Apply - Button
CPpg1 ppg1;
CPpg2 ppg2;
//And so on with ppg3...
psheet.AddPage(&ppg1);
psheet.AddPage(&ppg2);
//And so on with ppg3...
psheet.DoModal( );
 
Wow, thank you very much for your quick reply! My dialogs are all single dialog-based programs with different functions, which are already running independently. Is CPropertySheet an own class or do i have to implement it somewhere? Do i have to write all this in OnInitDialog or in the dialog classes? Please excuse my basic questions, but i'm just working with Visual C++ for 2 months. :)

 
It should be noted that simply changing the base class to CPropertySheet is not all that is required. IMHO You are better to delete the .cpp and .h files for the pages. Call Calsswizard and select the old classes 1 at a time. Class Wizard will complain about not finding them and then give you the opportunity to delete the references. Do this for each class you have, the close ClassWizard.

Once you have done that load your DLGs in the resource editor and call ClassWizard (Ctrl+W). When you do this you will then see the New Class Dialog make sure you select the CPropertyPage for your base class when you create the new ones.

It may seem a long way for a short cut but I've been there and found this approach much easier in the long run.

Once you have done that go to the insert menu and insert a new class for example CRegistration and set it's base class to CPropertySheet. In the H file generated by the wizard #include the .h files from your property pages and declare Member variables for them.

private:
CPage1 m_Page1 ;
CPage2 m_Page2 ;
etc.

Then in the .CPP file add in to the Constructor the following:

AddPage(&m_Page1) ;
AddPage(&m_Page2) ;
etc.

When creating an instance of your PropertySheet Dialog before you call DoModal() you can the PropertySheet to Wizard Mode.

MyPropertySheet.SetWizardMode() ;

This will display the sheets one at a time (in the order you added them). When you get to the last sheet and all is well you can change the button to "Finish" to complete the porcess and then save your data.


HTH


William
Software Engineer
 
Hi William.
My already existing dialogs are single independent programs. Why delete/replace all their the *.cpp and *.h files? All their functions and features get lost, or not? I'm still a rookie in programming with Visual C++, so please don't worry about my questions.
 
Hey no fair comment but I've tried to do the same and you have to change other references that relate to the CDialog Box class, it's not as simple as changing the base class.

However, in your case you may well benefit from this approach. The other alternative it to rename your .cpp and .h files to classxyz.cpp.txt classxyz.h.txt instead of deleting them. You could then load the txt files into notepad and copy and paste your code into the new CPropertyPages and get the best of both worlds.


William
Software Engineer
ICQ No. 56047340
 
What about the OK an Cancel buttons? Every dialog box has its own 2. Does every button work in the end? Or do i have to create something new?
 
CPropertySheet is a MFC - class and You do not need to implement it. It is a child of CDialog and has all it's functions. It is of course better to implement all classes new as williamu says, but my way is more quicklier.
Of course You have a problem with old OK - Buttons. I do normally so: rename all OK - Buttons in Dialogs to SET or APPLY buttons and rewrite OnOK() - Functions of Dialogs (remove CDialog::OnOK() from they; if they are on begin Your's OnOK(), You should replace they with UpdateData() ). Then You should think about OK Button of CPropertySheet - normally, You should call in it all OnOK() - Functions of Your Dialogs (as sayed, rewrited without CDialog::OnOK() in them). Cancel - Buttons of dialogs You can remove at all.
You should check in Resource.h File, if some Controls of Dialogs (Property Pages) have the same hexadecimal ID's - if it is so, renumber it!
 
No in a proper PropertyPage there are no Ok and Cancel button, since these are replaced by the Next, Back, Finish, Cancel and Apply button combinations on the Property Sheet.

If you want these to be dialogs to operate as standalone PropertyPages you will have to remove these button. Either that or you hide them when in Property Page mode. It would be a fair bit of work to have the best of both worlds here I think.



William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top