Solved

Select box in MFC

Posted on 2004-05-02
27
405 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
ID: 10972748
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
ID: 10972751
CEdit* pEdit = (CEdit*)m_wndDlgBar.GetDlgItem(IDC_COMBO);

should be

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

Author Comment

by:drakkarnoir
ID: 10972759
I don't understand Step 2.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 19

Expert Comment

by:mrwad99
ID: 10972791
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
ID: 10972853
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
ID: 10972874
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
ID: 10973079
I will try :)
0
 
LVL 19

Expert Comment

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

Author Comment

by:drakkarnoir
ID: 10978879
I tried, and it did not work :(
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10979571
Download the zip file again.  Changes are made.
0
 

Author Comment

by:drakkarnoir
ID: 10981296
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
ID: 10989421
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
ID: 10989432
drakkarnoir: or "drakkar noir" - a fragrance, right ?

:)
0
 

Author Comment

by:drakkarnoir
ID: 10990348
Yep :)

Thanks again :)
0
 

Author Comment

by:drakkarnoir
ID: 10991932
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
ID: 10994477
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
ID: 11025773
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
ID: 11025816
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
ID: 11026001
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
ID: 11026010
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
ID: 11026172
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
ID: 11026270
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
ID: 11026314
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
ID: 11026375
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
ID: 11026380
Oh yeah, we'll do another question for sure :)
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 11026387
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
ID: 11026388
Posted question already :)
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

810 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