Shoutbox

Button_SetCheckState - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Button_SetCheckState (/showthread.php?tid=97675)

Button_SetCheckState by enoid on 05-26-2011 at 11:28 PM

I'm having a problem with the rewriting of my script. I'm trying to implement as much as possible into my DLL and so far everything works without a problem. There's only one thing that doesn't seem to work, period. I'm talking about Button_SetCheckState.

The Checkbox we're talking about...

XML code:
<Control xsi:type="CheckBoxControl" Id="ChkTest">
    <Position Top="90" Width="300" Left="20"/>
    <Caption>Try to enable me...</Caption>
</Control>

...and how we set it @ enabled in JScript:
JScript code:
var Wnd = MsgPlus.CreateWnd("Preferences.xml","FormConfig");
 
Wnd.SetControlText("LblTestString", "It worked!");      // It works!
 
Wnd.Button_SetCheckState("ChkTest", true);          // It works too!


Everythings works. Now try to implement it in C++:
C++ code:
IDispatchPtr dispPlusWnd = pMsgPlus->CreateWnd("Preferences.xml", "FormConfig");
_IMPPlusWndPtr pPlusWnd;
acquireInterfacePtr(dispPlusWnd, pPlusWnd);
 
pPlusWnd->SetControlText("LblTestString", "It worked!");        // It works!
 
pPlusWnd->Button_SetCheckState("ChkTest", true);            // It does NOT work :(

It does NOT work :(
The strange thing is, SetControlText works (just a simple StaticControl for testing purposes), so one would asume that Button_SetCheckState should work aswell (and yes, I've tried switching them around). I've been trying loads of things, using the VARIANT_BOOLs instead of the normal true/false, trying to use the 'raw' version, trying to get the value with Button_IsChecked too see if it was changed but not visible, checking if the WindowId is correct, and too much other things too write down here...

Anyone got an idea what it could be, because it has been driving me insane for the last two days :@
RE: Button_SetCheckState by matty on 05-27-2011 at 01:38 AM

Try passing 1 or 0 instead of true/false.


RE: RE: Button_SetCheckState by enoid on 05-27-2011 at 07:50 AM

quote:
Originally posted by matty
Try passing 1 or 0 instead of true/false.
Same thing.

To be sure I'm not screwing it up elsewhere in my code, I just took the example code from Mnjul and only added the code it's all about. See the attachment.

See 'PlusScriptDLLExample.cpp' for the code and (if needed) change the import to build.
RE: Button_SetCheckState by Eljay on 05-27-2011 at 08:06 AM

Changing it to use VARIANT_BOOL seems to work fine for me.

C++ code:
pPlusWnd->Button_SetCheckState("ChkTest", VARIANT_TRUE);


RE: RE: Button_SetCheckState by enoid on 05-27-2011 at 08:33 AM

quote:
Originally posted by Eljay
Changing it to use VARIANT_BOOL seems to work fine for me.

C++ code:
pPlusWnd->Button_SetCheckState("ChkTest", VARIANT_TRUE);


Yes it does,.. Thanks! I could have sworn I tried that in my original code too (I even mention it in my opening post...)
Now I feel like an idiot :(
RE: Button_SetCheckState by Mnjul on 05-27-2011 at 08:47 AM

Good to know you got it solved :p 'cos I am pretty sure it should work...at least when I wrote the tutorial it worked. (It was Plus! 4 when I wrote the tutorial, and I didn't check if Plus! 5 broke things...so I was a little bit worried when I saw your post earlier today).

Anyway, to keep things a little bit more "geeky": while VARIANT_FALSE is usually defined 0, VARIANT_TRUE is usually defined as -1 (and it's a short -1, which is 0xffff), not 1. "true" in C++ usually translates into a positive 1 with common compiler implementation (of course, anything could work), FYI.


RE: RE: Button_SetCheckState by enoid on 05-27-2011 at 11:31 AM

quote:
Originally posted by Mnjul
Anyway, to keep things a little bit more "geeky": while VARIANT_FALSE is usually defined 0, VARIANT_TRUE is usually defined as -1 (and it's a short -1, which is 0xffff), not 1. "true" in C++ usually translates into a positive 1 with common compiler implementation (of course, anything could work), FYI.
Thanks for clearing that up. I just looked at some of my revisions and I saw that I never tried VARIANT_TRUE itself. I tried to cast a bool or int to a VARIANT_BOOL, assuming it would work. After your explanation now trying it with -1 it magically works. Ahh well, ternary operations to the resque.

Also, thanks for your tutorial, it motivated and helped me to get started on the project I'm currently working on and it sure helped me a lot!