|
-
November 11th, 2010, 04:51 AM
#1
[RESOLVED] Another Logic Question: Button Control Only To Fire Once.
Well I have a Dialog with all kinds of things going on but for this question it regards a single Button Control. I would like the user to be able to use this button only once. It is pretty basic, but using a simple BOOL does not seem to do the trick - or at least how I have tried it.
My version:
Code:
//Reset Button
case IDC_BTN_RSTR:
{
BOOL var = TRUE;
if(var == FALSE) return TRUE;
SetDlgItemInt(hwndDlg, IDC_STR, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR__, 0, FALSE);
var = FALSE;
return TRUE;
}
Last edited by Morbane; November 11th, 2010 at 04:54 AM.
-
November 11th, 2010, 06:45 AM
#2
Re: Another Logic Question: Button Control Only To Fire Once.
 Originally Posted by Morbane
My version:
Code:
//Reset Button
case IDC_BTN_RSTR:
{
BOOL var = TRUE;
if(var == FALSE) return TRUE;
...
}
Well, the line with if(var == FALSE) doesn't make any sense because above your set If you set it to TRUE, then it is TRUE, so why check whether it is FALSE???? 
Why don't you want instead just to disable button after its first use?
Victor Nijegorodov
-
November 11th, 2010, 10:18 AM
#3
Re: Another Logic Question: Button Control Only To Fire Once.
HRRRRrrmmmmmmmmmhhhhhhhhhhhhhh??? Whatever that code is supposed to do, rightnow it just returns TRUE and nothing else! Maybe you meant:
Code:
//Reset Button
case IDC_BTN_RSTR:
{
static BOOL var = FALSE;
if(var == FALSE)
{
SetDlgItemInt(hwndDlg, IDC_STR, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR__, 0, FALSE);
var = TRUE;
return TRUE;
}
else
{
return FALSE;
}
}
However this will run once, there's no way to reset the oneshot button. Unles "var" becomes a publicly available variable may that be by declaring it public or some function to reset it again.
????????
-
November 11th, 2010, 04:17 PM
#4
Re: Another Logic Question: Button Control Only To Fire Once.
...So returning FALSE will make the button not reuseable? I imagined that was possible but was unsure about how doing so would effect the operation of the dialog.
I will see what that does.
Thanks for the help.
Edit: Great - a simple solution. I think I enjoy posting here too much - I will try to be more diligent before asking such simple questions.
Last edited by Morbane; November 11th, 2010 at 04:21 PM.
-
November 12th, 2010, 05:44 PM
#5
Re: Another Logic Question: Button Control Only To Fire Once.
Great - a simple solution.
Simple, but not great. The button still looks active, but pressing it produces no effect: very, very bad solution. A button intended to be non-functional should be either disabled or hidden:
Code:
case IDC_BTN_RSTR:
{
SetDlgItemInt(hwndDlg, IDC_STR, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR__, 0, FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_BTN_RSTR), FALSE); // disable it
//ShowWindow(GetDlgItem(hDlg, IDC_BTN_RSTR), SW_HIDE); // or hide
return TRUE;
}
Best regards,
Igor
-
November 12th, 2010, 06:11 PM
#6
Re: [RESOLVED] Another Logic Question: Button Control Only To Fire Once.
Thanks again Igor!
[RE-RESOLVED]
-
November 15th, 2010, 08:34 AM
#7
Re: [RESOLVED] Another Logic Question: Button Control Only To Fire Once.
Except that it wasn't intended as a solution but as a possible explanation on the behaviour he / she was looking for.
^^
--edit:
...So returning FALSE will make the button not reuseable? I imagined that was possible but was unsure about how doing so would effect the operation of the dialog.
No. Turning it false simply means that YOU will handle the the message and not the default handler:
Code:
return DefWindowProc( hwnd, message, wparam, lparam );
.
Any message that you do not whish to handle should be defaulted back in that case. It's not realy a matter of enabling nor disabling funcionality.
In fact it would be better to return FALSE / NULL / 0 in both cases as you handle both cases.
Last edited by CrashPilot; November 15th, 2010 at 08:43 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|