LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Easter eggs in Labwindows/CVI

Hi all!

I have a quite tricky question...

I would like to insert an "easter egg" in my Labwindows program.. something like a popup message or a panel that appear only if the user press a given key combination..

Any suggestion on how to implement such a feature?

Thank you for the help.. I know that it is not a vital thing..

 

Francesco

0 Kudos
Message 1 of 14
(4,655 Views)

Well, I can think at at least two ways of doing that.

1. You can install a callback on the main panel trapping EVENT_KEYPRESS event: on the event callback, discriminate which key has been pressed and operate on the correct key combination

2. Create a button, place it outside the visible region of your mainpanel and associate it the desired key combination: in the button callback show your popup panel



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 14
(4,638 Views)

Hi Roberto!

thank you for your hints..

regarding solution #1, how can I install a callback without a control?? 

However, I also tried to place a button, configure it as "non visible" and the associate to it a shortkey configuration.. but it did not work 😞

 

Ciao

Francesco

 

0 Kudos
Message 3 of 14
(4,625 Views)

Besides control callbacks, you install a callback on a panel either in the UIR editor or programmatically by calling InstallPanelCallback. The panel callback responds to a subset of the user events among which EVENT_KEYPRESS can be found.

Regarding the second solution, if a control is not visible is not operable at all, neither with the mouse nor with the keyboard. I suggested you to move it outside the visible region of the panel exactly to "hide" it to the user while keeping it still "visible" (and so fully operable).

 

Ciao!

 

BTW It seems you are italian like me: are you aware of the italian forum board?

Message Edited by Roberto Bozzolo on 11-16-2008 08:29 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 14
(4,619 Views)

Hi Francesco,

 

For your application, I feel that it is not a must to use InstallPanelCallback.

As mentioned in the function help, it is actually identical to specifying a panel callback within the UIR (by double-clicking the panel and filling in the callback field).

 

But as an advantage, by using InstallPanelCallback you can change which function will be serving the panel events while the application is running.

To do this, you should first uninstall the current callback by calling InstallPanelCallback with the function parameter set to NULL and then call it again with the new callback function name.

 

You can even add multiple callbacks to a panel using ChainPanelCallback function. So for any event on the panel multiple function blocks "get activated".

So, you have lots of flexibility 🙂 

Message Edited by ebalci on 11-17-2008 09:11 AM
S. Eren BALCI
IMESTEK
0 Kudos
Message 5 of 14
(4,607 Views)
Reminds me of a story... I did that years ago in a CVI program. The 'egg'
would trigger on april 1st and on one of the plots it sent daily to the
printer it would add large white chars with some joke (don't remember what
it was).

I wrote it a day I was bored, and obfuscated the code so it would be hard to
find. Then I forgot all about it.

Years later my former boss calls me all worried: "the program has been
hacked! You have to help us!". It took me several hours to find the problem,
and more to remember who the author was... Non billable, of course.
--
Guillaume Dargaud
http://www.gdargaud.net/


0 Kudos
Message 6 of 14
(4,593 Views)

Hi All!

I would like to use the InstallPanelCallback but it is not clear to me how to use this command.

Could someone provide a simple example of it usage? 

I would like only that a MEssagePopUp appear when someone strikes a combination of keys, let's say shift+A or ABC.

Thanks for any help...

 

Francesco

0 Kudos
Message 7 of 14
(4,537 Views)

This is a sample callback that prompts a message on Ctrl + A key combination:

 

/****************************************************************************/
int CVICALLBACK mainCbk (int panel, int event, void *callbackData,
        int eventData1, int eventData2)

// Callback installed on main panel
{
    int        virtualKey, modifierKey, asciiKey, tmpH, error = 0;
    char    msg[256];

    switch (event) {
        case EVENT_KEYPRESS:
        // eventData1: a 4-byte integer consisting of 3 fields: 0x00MMVVAA
        // MM = the modifier key, VV = the virtual key, AA = the ASCII key
        // key masks are defined in "userint.h"
            virtualKey = eventData1 & VAL_VKEY_MASK;
            modifierKey = eventData1 & VAL_MODIFIER_KEY_MASK;
            asciiKey = eventData1 & VAL_ASCII_KEY_MASK;

            // Ctrl + A: Prompt a message

           if (modifierKey == VAL_MENUKEY_MODIFIER && asciiKey == 'A') {
                MessagePopup ("Key Press", "Message.");
            }
            break;
    }

Error:
    if (error < 0) {
        sprintf (msg, "Error %d received in mainCbk.", error);
        MessagePopup ("Severe error", msg);
    }
    return 0;
}

 

Here the line to install this callback on the main panel:

    InstallPanelCallback (panelHandle, mainCbk, 0);
 

Remember that the panel callback can be set in the UIR editor without need to use InstallPanelCallback.

Message Edited by Roberto Bozzolo on 11-19-2008 10:14 PM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 8 of 14
(4,530 Views)

Thank you very much Roberto..

you really know a lot 😉

 

Ciao

 

Francesco

0 Kudos
Message 9 of 14
(4,510 Views)

Hi Roberto,

as far as I understand, I cannot use a combination like SHIFT+CTRL+A since both SHIFT and CTRL are defined as "key modifiers".

Am I right?

 

Francesco

0 Kudos
Message 10 of 14
(4,492 Views)