Solved

Select box in MFC

Posted on 2004-05-02
27
403 Views
Last Modified: 2013-11-25
How would I make a drop-down select box for a MFC project and have each option "jump" to a URL inside the application? For example:

Please select your destination: Home
                                            (drop down)
                                            Search
                                            Advance Search
                                            etc...

And once a user clicks on a specific option, to shoot them to it. Using the base class CHtmlview in MFC.
0
Comment
Question by:drakkarnoir
  • 14
  • 13
27 Comments
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
1) Add a combo box to your dialog resource for your dialog bar.
2) Handle the ON_CBN_SELENDOK message:

// Message map in View class
ON_CBN_SELENDOK(IDC_URL_COMBO, OnAddressSelected)


void YourView::OnAddressSelected()
{
      CString strNewURL;

      CEdit* pEdit = (CEdit*)m_wndDlgBar.GetDlgItem(IDC_COMBO);
      
      pCombo->GetLBText(pCombo->GetCurSel(), strNewURL);
      Navigate2(strNewURL,NULL,NULL);

}

Assume m_wndDlgBar is your dialog bar.
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
CEdit* pEdit = (CEdit*)m_wndDlgBar.GetDlgItem(IDC_COMBO);

should be

 CComboBox* pCombo  (CComboBox*)m_wndDlgBar.GetDlgItem(IDC_COMBO);
0
 

Author Comment

by:drakkarnoir
Comment Utility
I don't understand Step 2.
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
OK.  If you have added the combo box to your dialog resource and given it the ID IDC_URL_COMBO (right click, properties, IE), like the other controls in your other question, you need to go to your view class and add the following code:

At the top of the view class you will see the message map

BEGIN_MESSAGE_MAP(...,...)
      //{{AFX_MSG_MAP(CMainFrame)
      //}}AFX_MSG_MAP
<------
END_MESSAGE_MAP()

Insert the following line as indicated at <----

ON_CBN_SELENDOK(IDC_URL_COMBO, OnAddressSelected)

Now right click the view class and select Add Member Function.

Type: afx_msg void

Declaration: OnAddressSelected

Edit the body of the function, and add the code

  CString strNewURL;
  CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();

  CComboBox* pCombo = (CComboBox*)pMainFrame->m_wndDlgBar.GetDlgItem(IDC_COMBO);
     
  pCombo->GetLBText(pCombo->GetCurSel(), strNewURL);
  Navigate2(strNewURL,NULL,NULL);

This assumes that you have a dialog bar in CMainFrame called m_wndDlgBar that is public.
0
 

Author Comment

by:drakkarnoir
Comment Utility
I keep losing you there, perhaps because I'm using VS .NET 2003 and the options are different? Time for EE_Test.zip again :( ?
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
I have given you all the code you need above; you just need to add it in the right places.  Go to VC++ and have a read of the last comment.  You can do it !

This is me out for the night; I will hand you over to other comments.

Good luck !
0
 

Author Comment

by:drakkarnoir
Comment Utility
I will try :)
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
drakkarnoir: how are you getting on, and did you add the code I posted ?
0
 

Author Comment

by:drakkarnoir
Comment Utility
I tried, and it did not work :(
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
Download the zip file again.  Changes are made.
0
 

Author Comment

by:drakkarnoir
Comment Utility
Got it, how do I define a URL for each of the select options?
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 500 total points
Comment Utility
The way I have coded the drop down box, each time a URL is navigated to that URL is added to the drop down list.  If you want default values in there, you can add them from the resource editor.  Do as follows:

1) Open up the resource that contains the drop down list.  If you are using the dialogue bar as before, this will be the dialog resource called IDR_MAINFRAME.
2) Right click the drop down list, select properties and then select the Data tab.  Type your default URLs into the text box, pressing ctrl-enter to add another one.  If you press just enter, the properties dialogue will be dismissed.
3) When finished, close the properties dialogue and rebuild your project.

Hope that helps :)
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
drakkarnoir: or "drakkar noir" - a fragrance, right ?

:)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:drakkarnoir
Comment Utility
Yep :)

Thanks again :)
0
 

Author Comment

by:drakkarnoir
Comment Utility
mrwad99, I might be throwing another question along this question your way soon, to do with creating an autorun program in MFC, or in InstallShield. I have both, so we'll decide then :)
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
No problem - glad to help; if I can assist you on any other of your questions I will be glad to :)
0
 

Author Comment

by:drakkarnoir
Comment Utility
mrwad99, I hate to bother you again, but the http://mr_wad_99.europe.webmatrixhosting.net/EE_Test.zip still has the previous, not updated code.
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
Hmm; I could have swore that I FTPd the latest zip file over, mind you there have been some problem with the server so I have re-uploaded it to a new location under a new filename.  Try

http://mr_wad_99.europe.webmatrixhosting.net/New/EE_TestNEW.zip

Let me know if that is OK.
0
 

Author Comment

by:drakkarnoir
Comment Utility
Nope, still the same, wierd...maybe it's because I'm converting the project from 6 to .NET?
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
I am thinking that you mean "new code" as the code you asked for in this question, i.e. a drop down list that allows the user to select a URL.  That URL is then navigated to when selected ?

And from your comment above,

>> Got it, how do I define a URL for each of the select options?

I figured that you had already got a hold of the code that does so ?
0
 

Author Comment

by:drakkarnoir
Comment Utility
Ah, I see where the problem is...

I wanted to be able to define the drop down boxes with URL's, could you put like a test URL in there for me so I get the idea?
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
I stated how to do that in my comment of  05/04/2004 07:20PM BST (the accepted answer).  Follow that; it is simple enough :)
0
 

Author Comment

by:drakkarnoir
Comment Utility
I did folllow those, but here's the problem:

If I type in www.yahoo.com, for the data, it will take me to www.yahoo.com, that's fine. But I want to make the select name as "Yahoo!" and have it go to www.yahoo.com.
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
Right well that is a whole different kettle of fish and worthy of a different question.  

To start with, if you want to pre-define some values in the drop down combo box, you are going to have to link a normal string to a URL.  Now you could do this using a container of structures, but how you would get the title for a link that the user types in is tougher.  Say I type in www.google.com; this should be stored in the list as Google - but how are you going to get the string google ?

You could do this by handling specific messages from the browser control, but it is gonna be around a hundred more lines of code.  I could do this, but it will cost you in points...:)
0
 

Author Comment

by:drakkarnoir
Comment Utility
Oh yeah, we'll do another question for sure :)
0
 
LVL 19

Expert Comment

by:mrwad99
Comment Utility
DO you want me to do this now, or are you going to post another question in the C++ TA ?
0
 

Author Comment

by:drakkarnoir
Comment Utility
Posted question already :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now