changing control's state from outside dialog 
Author Message
 changing control's state from outside dialog

Hi
I want to change the state of a control- lets say from enabled to disabled
but not from inside its dialog class but from my own class (mine is general
class not dialog). i have tried to do
 GetDlgItem(handle of the window, control ID) but its not working well.
rather its returns an invalid handle to the control. and gives an exseption
if i try to call enable () with that pointer. what am i doing wrong.
TIA
Usman


Fri, 18 Feb 2005 14:44:50 GMT  
 changing control's state from outside dialog

Quote:

> Hi
> I want to change the state of a control- lets say from enabled to disabled
> but not from inside its dialog class but from my own class (mine is general
> class not dialog). i have tried to do
>  GetDlgItem(handle of the window, control ID) but its not working well.
> rather its returns an invalid handle to the control. and gives an exseption
> if i try to call enable () with that pointer. what am i doing wrong.
> TIA
> Usman

If the function returns NULL it probably means you are calling it before
the control exists.  The dialog handle and the controls do not exist
until after DoModal is called.  You also seem to be confusing handles
and pointers.  A handle is not a pointer.

Try adding a member function to the dialog, and call that function from
your class.  The function can save the desired state in a member
variable.  Then it should use the state in OnInitDialog to
enable/disable the control.

--
Scott McPhillips [VC++ MVP]



Fri, 18 Feb 2005 16:45:38 GMT  
 changing control's state from outside dialog
This is probably a mistake. No matter want you want to do, manipulating a control from
outside the dialog usually results in an unmaintainable mess. Send a user-defined message
to the dialog to request it to change the control. You have not actually said how you are
using GetDlgItem, so it is hard to say what went wrong (there are many different errors
you could make in this fashion), but I'd suggest a cleaner approach is what is required.
Use a user-defined message and let the dialog manipulate its own controls.
                                joe

Quote:

>Hi
>I want to change the state of a control- lets say from enabled to disabled
>but not from inside its dialog class but from my own class (mine is general
>class not dialog). i have tried to do
> GetDlgItem(handle of the window, control ID) but its not working well.
>rather its returns an invalid handle to the control. and gives an exseption
>if i try to call enable () with that pointer. what am i doing wrong.
>TIA
>Usman

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sat, 19 Feb 2005 18:39:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Changing Dialog Controls' Tab Order at Runtime

2. Can't change cursor state

3. Seems no way can change IE's fullscreen size/position or state

4. why my Control methods can't be seen by outside

5. problems capturing state change event from a List Control: OnOdstatechangedFunction

6. Changing control state

7. Using OCX controls outside dialogs

8. Accessing Session State outside of ASP.NET

9. Accessing a parent dialog's controls from a child modeless dialog

10. Child window of ActiveX control doesn't draw when control is moved in dialog

11. IEEE Computer Society's Texas State Programming Contest '93

12. How to implement 'State Engine'?

 

 
Powered by phpBB® Forum Software