Changing control styles...

This is a discussion on Changing control styles... within the Windows Programming forums, part of the Platform Specific Boards category; How do I disable an EDITTEXT? Scenario: I have an EDITTEXT control and a PUSHBUTTON control. I want to click ...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Unhappy Changing control styles...

    How do I disable an EDITTEXT?
    Scenario:
    I have an EDITTEXT control and a PUSHBUTTON control.
    I want to click the push button, and it will then set the EDITTEXT style to WS_DISABLED.

    Is there a simple function I have overlooked, or what?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Look up EnableWindow() and GetDlgItem() in your Windows documentation.
    Last edited by CommonTater; 04-16-2011 at 04:51 PM.

  3. #3
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    I am not so sure you understand what I want.
    Here is the example source...
    resource.rc
    Code:
    #include "resource.h"
    DLG_MAIN DIALOGEX 6, 5, 194, 106
    STYLE 0x10CE0804
    BEGIN
        CONTROL "&Disable", IDC_BTN_DISABLE, "Button", 0x10010000, 138,  5, 46, 15
        CONTROL "&Quit", IDC_BTN_QUIT, "Button", 0x10010000, 138, 29, 46, 15
        EDITTEXT  3, 10, 10, 100, 10
    END
    main.cpp
    Code:
         ...
    case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDC_BTN_QUIT:
                        EndDialog(hwndDlg, 0);
                        return TRUE;
    
                    case IDC_BTN_DISABLE:
                        //Disable the EDITTEXT control: what should be here?
                        return TRUE;
                }
           ...
    Or am I misunderstanding you?
    Last edited by Benji Wiebe; 04-16-2011 at 05:12 PM. Reason: clarity

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    I am not so sure you understand what I want.
    You want to selectively enable and disable windows controls...

    Part of your problem may be that your EDITTEST in your resources is poorly formed as it does not return an identifier.

    Code:
         ...
    case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDC_BTN_QUIT:
                        EndDialog(hwndDlg, 0);
                        return TRUE;
    
                    case IDC_BTN_DISABLE:
                       EnableWindow(GetDlgItem(hDialog,IDC_EDIT),0);
                        return TRUE;
                }
           ...
    Or am I misunderstanding you?
    EnableWindow needs the window handle of the control (which is wehre GetDlgItem() is used) and either a 1 to enable the window or a 0 to disable it. For a button, it's greyed and you can't click it. For an edit box, it's greyed and you can't type into it (but it still shows content). etc.

    EnableWindow Function (Windows)
    Last edited by CommonTater; 04-16-2011 at 09:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing the window frame styles causes the window to disappear
    By sethjackson in forum Windows Programming
    Replies: 2
    Last Post: 08-12-2010, 05:43 PM
  2. Control-specific styles can't be applied in a resource???
    By Viper187 in forum Windows Programming
    Replies: 2
    Last Post: 10-04-2008, 09:03 PM
  3. Changing windows Styles on the Fly.
    By Mastadex in forum Windows Programming
    Replies: 9
    Last Post: 07-31-2007, 02:51 PM
  4. Few Questions (Styles, Static Control)
    By Zeusbwr in forum Windows Programming
    Replies: 11
    Last Post: 04-15-2005, 05:13 AM
  5. How to change control styles
    By lvk in forum Windows Programming
    Replies: 3
    Last Post: 03-03-2003, 09:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21