CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2004
    Location
    muahaha
    Posts
    84

    Question Enable/Disable button

    I had create button called IDC_PLAY on the design view in a dialog box call IDD_CONTROL. How can i disable it.

    I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
    Have anyone got some clue....

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Enable/Disable button

    Quote Originally Posted by whaTHell
    I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
    Have anyone got some clue....
    Yes - you can call GetDlgItem() to get the control's window handle.

  3. #3
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Enable/Disable button

    Quote Originally Posted by whaTHell
    I had create button called IDC_PLAY on the design view in a dialog box call IDD_CONTROL. How can i disable it.

    I had heard about EnableWindow(); but i don't know how to associate HWND for that button because i don't create the button on run-time. It's already in the dialog box.
    Have anyone got some clue....
    You also can use SendDlgItemMessage() with the ID of your button defined in resource.h:

    Code:
    // enable button IDC_BUTTON1 in dialog hDialog
    SendDlgItemMessage(hDialog, IDC_BUTTON1, WM_ENABLE, (WPARAM)TRUE, 0);
    // disable button:
    SendDlgItemMessage(hDialog, IDC_BUTTON1, WM_ENABLE, (WPARAM)FALSE, 0);
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  4. #4
    Join Date
    Oct 2004
    Location
    muahaha
    Posts
    84

    Wink Re: Enable/Disable button

    Thanx all..
    It's work. I use GetDlgItem() to get the button handle and enable/disable it with EnableWindow().

    But if I use:

    SendDlgItemMessage(hDialog, IDC_PLAY, WM_ENABLE, (WPARAM) FALSE, 0);

    it didn't work. Am I missing something there? Actually I had try this method before I post this thread and it didn't work also..
    Anyway, thanx again..

  5. #5
    Join Date
    Oct 2004
    Posts
    38

    Re: Enable/Disable button

    SendDlgItemMessage(hDialog, IDC_PLAY, WM_ENABLE, (WPARAM) FALSE, 0);

    I have the same problem...if anyone knows why it does not work...???

    by now I solve this with the folllowing:

    EnableWindow(GetDlgItem(hDialog, IDC_PLAY), TRUE);
    Last edited by rafraf; May 5th, 2005 at 07:04 AM.

  6. #6
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Enable/Disable button

    WM_ENABLE is a notification message. It is sent to your parent window in response to the enabling/disabling of a child window. It cannot be used to alter it.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  7. #7
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Enable/Disable button

    Quote Originally Posted by Bond
    WM_ENABLE is a notification message. It is sent to your parent window in response to the enabling/disabling of a child window. It cannot be used to alter it.
    I always mix those two up... ...
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  8. #8
    Join Date
    Aug 2003
    Posts
    938

    Re: Enable/Disable button

    Ws_disabled

  9. #9
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Enable/Disable button

    Quote Originally Posted by Quell
    Ws_disabled
    WS_DISABLED is a window style, not a message, and would have to be used in conjunction with SetWindowLong() to change the window's current style. I'm not even sure if it affects the window other than when it is initially created but one could test it.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  10. #10
    Join Date
    Aug 2003
    Posts
    938

    Re: Enable/Disable button

    WS_DISABLED worlks after the application has been created//or can be made to work in a few cases....adn windows style is as good as a message is..

  11. #11
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: Enable/Disable button

    Quote Originally Posted by Quell
    adn windows style is as good as a message is..
    It may be as effective, but I would think:
    Code:
    EnableWindow(hwnd, FALSE);
    would be much more readable than:
    Code:
    LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
    SetWindowLong(hwnd, GWL_STYLE, lStyle & WS_DISABLED);
    I would only use WS_DISABLED if I wanted a window/control to be initially disabled during creation.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured