Solved

Hiding Controls at runtime

Posted on 2004-09-09
14
281 Views
Last Modified: 2013-11-20
I am using VC++ 6 and am trying to hide controls at runtime given various conditions, but have been unsuccessful to this point figuring out how to do this.  It is very easy in VB, so I am not sure what the problem is.  I have edit controls and comboboxes that I would like to hide/show given certain criteria.  Disabling might be a better option as well.
0
Comment
Question by:neverrealm
[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
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 4

Expert Comment

by:r2far
ID: 12017314
Are you using a dialog box?  If so have you used class-wizard to setup a CONTROL variable for each edit box and/or combobox you want to control?

If you do not have control variables setup, you can still use GetDlgItem() to get a handle to the control.

Once you have a control handle (either setup by class-wizard, or done in code using GetDlgItem() ), you can simply call ShowWindow() with either 'TRUE' or 'FALSE' and this should allow you to show or hide the window.


// using a DDC control variable
m_ctlEdit1->ShowWindow(FALSE);

// using GetDlgItem()
GetDlgItem(IDC_EDIT1)->ShowWindow(FALSE);
0
 

Author Comment

by:neverrealm
ID: 12017771
I didn't use the class wizard.  It looks like that will work.  Do you know what the other finctions would be such as Disabling the control.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12017894
For disabling you can use CWnd method EnableWindow(FALSE)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:neverrealm
ID: 12018095
How would I use that on an individual control within a regular dialog box.
0
 
LVL 16

Accepted Solution

by:
nonubik earned 125 total points
ID: 12018242
// using a DDC control variable
m_ctlEdit1->EnableWindow(FALSE);

// using GetDlgItem()
GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE);
0
 

Author Comment

by:neverrealm
ID: 12018273
I'm not using a CWND, I'm using an HWND
0
 

Author Comment

by:neverrealm
ID: 12018328
I get the message:  EnableWindow is not a member of HWND
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12018361
ok, then
EnableWindow(hEditWnd, FALSE);
0
 

Author Comment

by:neverrealm
ID: 12018849
Great.  One last thing.  I'll increase the points.

How do you edit the text of a label at runtime.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12018887
SetWindowText(hWndEdit, "new text");
0
 

Author Comment

by:neverrealm
ID: 12019158
Once I finish the code, I will assign points
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12037322
These are windows API functions, not MFC.  MFC specifically hides HWNDs whenever possible, because they're not object oriented.  take a look at the api, it has all sorts of nifty functions like DestroyWindow, GetWindowText, ResizeWindow, etc.  They're all exposed in CWnd's functions, if you can get a CWnd, but they're origionally API calls.

In fact, its rather nifty.  A ton of MFC functions look like this
void CSomething::WindowsAPIName()
{
  Assert(Valid CSomething Object);
  HandleAfxJunk
  WindowsAPIName(this->m_hWnd);
  Assert(No error);
  HandleMoreAfxJunk
}
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12042444
>I'm not using a CWND, I'm using an HWND

I think the asker does not use MFC...
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12045034
You are problaby right.  I just make the comment because the question was posted in the MFC area.  Not looking for points for it, just trying to help people along where I can, so that when i need help, people will do the same for me =)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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