Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select box in MFC

Posted on 2004-05-02
27
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

670 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