Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Select box in MFC

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
drakkarnoir
Asked:
drakkarnoir
  • 14
  • 13
1 Solution
 
mrwad99Commented:
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
 
mrwad99Commented:
CEdit* pEdit = (CEdit*)m_wndDlgBar.GetDlgItem(IDC_COMBO);

should be

 CComboBox* pCombo  (CComboBox*)m_wndDlgBar.GetDlgItem(IDC_COMBO);
0
 
drakkarnoirAuthor Commented:
I don't understand Step 2.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
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
 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
I will try :)
0
 
mrwad99Commented:
drakkarnoir: how are you getting on, and did you add the code I posted ?
0
 
drakkarnoirAuthor Commented:
I tried, and it did not work :(
0
 
mrwad99Commented:
Download the zip file again.  Changes are made.
0
 
drakkarnoirAuthor Commented:
Got it, how do I define a URL for each of the select options?
0
 
mrwad99Commented:
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
 
mrwad99Commented:
drakkarnoir: or "drakkar noir" - a fragrance, right ?

:)
0
 
drakkarnoirAuthor Commented:
Yep :)

Thanks again :)
0
 
drakkarnoirAuthor Commented:
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
 
mrwad99Commented:
No problem - glad to help; if I can assist you on any other of your questions I will be glad to :)
0
 
drakkarnoirAuthor Commented:
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
 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
Nope, still the same, wierd...maybe it's because I'm converting the project from 6 to .NET?
0
 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
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
 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
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
 
mrwad99Commented:
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
 
drakkarnoirAuthor Commented:
Oh yeah, we'll do another question for sure :)
0
 
mrwad99Commented:
DO you want me to do this now, or are you going to post another question in the C++ TA ?
0
 
drakkarnoirAuthor Commented:
Posted question already :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 14
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now