From: Giovanni Dicanio on
Eddards ha scritto:
> Thanks, I missed that.
> The code still worked, go figgure.

'nIDEvent = 200' is an expression that is evaluated to 200.
In fact, '=' is an operator, and its return value is the RHS (i.e. 200)
in your case.

So the expression in the else-if:

else if (nIDEvent = 200)
...

is evaluated as:

else if (200)
...

200 is different from 0, so it is evaluated as boolean value "true" (0
-> "false", non-0 -> "true").

So, your code is equivalent to:

...
else if (true) {
nIDEvent = 200;
...

}

or just (considering that 'else if (true)' is simply an 'else'):

...
else {
nIDEvent = 200;
...
}

So, the global 'if' becomes:

<code>

if (nIDEvent == 100)
{
KillTimer(100);
//start the button pressing timer
SetTimer(200,200,NULL); // 200=ID 1000=msdelay
}
else // was: else if (nIDEvent = 200)
{
nIDEvent = 200;

CWnd *Parent = GetParent();
if (Parent)
{
//send the BN_CLICK Message to the parent

Parent->SendMessage(WM_COMMAND,MAKEWPARAM(GetDlgCtrlID(),BN_CLICKED),(LPARAM)m_hWnd);
}
}

</code>

Probably you only have two timers (the '100' and the '200'), so if the
event ID is not 100 it is 200, so your code works.

But of course it is not good programming style, and the proper thing to
do is to use the clear form of operator== (equality operator) and use
const int to identify timer IDs, as David and Joe suggested.

Giovanni