NO

Author Topic: enabling and disabling buttons  (Read 2751 times)

Franzki

  • Guest
enabling and disabling buttons
« on: January 12, 2009, 09:45:38 AM »
I'm new to Windows programming... I started with the sample dialog based program from the Pelles project Wizzard.

What I'm trying to do is disabling a button when it's clicked and enabling (and activating) an other one.

I modified the sample code as follows:

Code: [Select]
        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
             case IDOK:
             EnableWindow(GetDlgItem (hwndDlg, 4001),1);
             EnableWindow(GetDlgItem (hwndDlg, IDOK),0);
             SetFocus(GetDlgItem (hwndDlg, 4001));
             return TRUE;

             case 4001:
             EnableWindow(GetDlgItem (hwndDlg, 4001),0);
             EnableWindow(GetDlgItem (hwndDlg, IDOK),1);
             SetFocus(GetDlgItem (hwndDlg, IDOK));
             return TRUE;

            }
            break;

The problem is that the border around the button isn't updated... so a disabled button can still have a black border... this makes it confusing as the button is disabled.

How can I fix this? Do I need to redraw something and how can I implement this in my program?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: enabling and disabling buttons
« Reply #1 on: January 15, 2009, 07:51:50 PM »
I don't have time to test your code right now, but check if changing SetFocus(...) to SetDlgItemFocus(...), in the following macro, makes any difference:

Code: [Select]
#define SetDlgItemFocus(hwnd,idCtl)  FORWARD_WM_NEXTDLGCTL((hwnd), GetDlgItem((hwnd),(idCtl)), TRUE, PostMessage)
/Pelle

Franzki

  • Guest
Re: enabling and disabling buttons
« Reply #2 on: January 16, 2009, 02:18:33 PM »
Thank you Pelle,

The SetDlgItemFocus() macro made it work!