Able and Disable a button

Hello guys, I'm new to windows programming and i'd like to know if this code is a good practice for able and disable a button in a Windows Program.
Thanks




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 if (title[0]=='\\')						//DISABLE
{
CreateWindow(TEXT("button"), TEXT("C++"),
WS_VISIBLE | WS_CHILD | WS_DISABLED,
350,60,100,25,
hwnd, (HMENU) 111, NULL, NULL
);
}
if (title[0]=='/')		//ENABLE
{	
CreateWindow(TEXT("button"), TEXT("C++"),
WS_VISIBLE | WS_CHILD,
350,60,100,25,
hwnd, (HMENU) 111, NULL, NULL
);
}
Why don't you create a button once and then use ShowWindow using either SW_SHOW or SW_HIDE ?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx
I want the button to be shown everytime, but if i input \ it closes and if i input / it opens like a password or something
i'd like to know if this code is a good practice for able and disable a button in a Windows Program.

No it isn't.

If you want enable or disable a button, use EnableWindow

EnableWindow function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646291%28v=vs.85%29.aspx

(This sets or clears the WS_DISABLED flag.)

ShowWindow is for when you want to show or hide a window.

Andy

PS You code is esp bad as you keep creating windows but you never destroy them; so you have a memory leak.
Last edited on
Topic archived. No new replies allowed.