Pelles C forum

C language => Beginner questions => Topic started by: Franzki on January 12, 2009, 09:45:38 AM

Title: enabling and disabling buttons
Post by: Franzki 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:

        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?
Title: Re: enabling and disabling buttons
Post by: Pelle 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:

#define SetDlgItemFocus(hwnd,idCtl)  FORWARD_WM_NEXTDLGCTL((hwnd), GetDlgItem((hwnd),(idCtl)), TRUE, PostMessage)
Title: Re: enabling and disabling buttons
Post by: Franzki on January 16, 2009, 02:18:33 PM
Thank you Pelle,

The SetDlgItemFocus() macro made it work!