Discussion:
[Foxgui-users] Hot Key in Main Window
Julia Dudascik (Contractor)
2017-01-11 19:25:20 UTC
Permalink
Hi,

I would like to add a HotKey in my Main Window. When the user presses the
button Ctl+Q (Control Q), I would like the application to exit. In the
constructor where I create my window, I did the following:

FXHotKey test = parseHotKey("Ctl-Q")
this->addHotKey(test)
this->accelTable->addAccel(test, this, ID_TEST_HOTKEY)

Then in FXMAPFUNC, I define:
FXMAPFUNC(SeL_KEYPRESS, MyClass::ID_TEST_HOTKEY, MyClass::test_hot_keyFunc),

When I pres Control Q, the application never gets to my function
test_hot_keyFunc.

Did I define the hotkey correctly for Control q?
How do you set-up a hot key for a window, so that the user can quit the
application
with the command Ctl-Q in the main window?

This is just one instance on shortcuts I would like my "Main Window" to
have. For instance, I would also like to save the database with the command
Ctl+S. I am first trying to figure out how to add a hot key to a window
before proceeding, Any assistance would be greatly appreciated.

Thank you
Julia
JVZ
2017-01-12 01:57:51 UTC
Permalink
On Wed, 11 Jan 2017 14:25:20 -0500
Post by Julia Dudascik (Contractor)
Hi,
I would like to add a HotKey in my Main Window. When the user presses the
button Ctl+Q (Control Q), I would like the application to exit. In the
FXHotKey test = parseHotKey("Ctl-Q")
this->addHotKey(test)
this->accelTable->addAccel(test, this, ID_TEST_HOTKEY)
FXMAPFUNC(SeL_KEYPRESS, MyClass::ID_TEST_HOTKEY, MyClass::test_hot_keyFunc),
When I pres Control Q, the application never gets to my function
test_hot_keyFunc.
Did I define the hotkey correctly for Control q?
How do you set-up a hot key for a window, so that the user can quit the
application
with the command Ctl-Q in the main window?
This is just one instance on shortcuts I would like my "Main Window" to
have. For instance, I would also like to save the database with the command
Ctl+S. I am first trying to figure out how to add a hot key to a window
before proceeding, Any assistance would be greatly appreciated.
Thank you
Julia
You should want to use parseAccell() instead of parseHotKey(). parseAccel()
is for strings like "Ctl-Q" and "Shift-Alt-F3". The parseHotKey()( is for
strings that are part of a menu or label, such as "&Open File" (which
would add a hotkey Alt-O, active only when the label or menu is presented.

Now, since you're supplying the text directly, you might as well just skip
the step and call acceltable->addAccel() directly, like:

getAccelTable()->addAccel(MKUINT(KEY_Q,CONTROLMASK),mytarget,FXSEL(SEL_COMMAND,MyWidget::ID_THEMESSAGE));

This would be a lot simpler.

Of course, if your program has pulldown menus, you can make your life even easier
by just passing a special string to the Quit option:

menubar=new FXMenuBar(...);
filemenu=new FXMenuPane(...);
new FXMenuTitle(menubar,"&File",NULL,filemenu);

new FXMenuCommand(filemenu,"&Open...",...);
...
...
...
new FXMenuCommand(filemenu,"&Quit\tCtl-Q",...);

In FXMenuTitle, the string "&File" would automatically add a hot-key Alt-F to
bring up the menu, while the string "&Quit\tCtl-Q" would not only add a hot-key
Alt-Q but also an accelerator Ctl-Q.

Since most applications would have a menubar, this is by-far the easiest way to
add hotkeys and accelerators.

But every once in a while, you may have an accelerator that does not have a corresponding
menu, or maybe have an app that has no menus; in such a case, directly adding the key-combo
to the accelerator table may be the way to go....


Hope this helps,


-- JVZ
Julia Dudascik (Contractor)
2017-01-13 21:11:05 UTC
Permalink
Thank you. I tried to upgrade to the new version of FOX toolkit (version
1.6.53). When I build my application, which dynamically links with the FOX
libraries (FOX-1.6.lib and FOXDLL-1.6.lib). I built the FOX libraries as
64-bit in Visual Studio 2013, I get the following warning message when it
builds the FOX header file FXList.h:

"warning C4251: FX::FXList::items : class
FX::FXObjectListOf<FX::FXListItem> needs to have dll-interface to be used
by clients of class FX::FXList"

I did not get this warning message with version 1.6.51. Should I be
concerned? Do you know what would cause it?

Thanks
Julia
Post by JVZ
On Wed, 11 Jan 2017 14:25:20 -0500
Post by Julia Dudascik (Contractor)
Hi,
I would like to add a HotKey in my Main Window. When the user presses the
button Ctl+Q (Control Q), I would like the application to exit. In the
FXHotKey test = parseHotKey("Ctl-Q")
this->addHotKey(test)
this->accelTable->addAccel(test, this, ID_TEST_HOTKEY)
FXMAPFUNC(SeL_KEYPRESS, MyClass::ID_TEST_HOTKEY,
MyClass::test_hot_keyFunc),
Post by Julia Dudascik (Contractor)
When I pres Control Q, the application never gets to my function
test_hot_keyFunc.
Did I define the hotkey correctly for Control q?
How do you set-up a hot key for a window, so that the user can quit the
application
with the command Ctl-Q in the main window?
This is just one instance on shortcuts I would like my "Main Window" to
have. For instance, I would also like to save the database with the
command
Post by Julia Dudascik (Contractor)
Ctl+S. I am first trying to figure out how to add a hot key to a window
before proceeding, Any assistance would be greatly appreciated.
Thank you
Julia
You should want to use parseAccell() instead of parseHotKey().
parseAccel()
is for strings like "Ctl-Q" and "Shift-Alt-F3". The parseHotKey()( is for
strings that are part of a menu or label, such as "&Open File" (which
would add a hotkey Alt-O, active only when the label or menu is presented.
Now, since you're supplying the text directly, you might as well just skip
getAccelTable()->addAccel(MKUINT(KEY_Q,CONTROLMASK),
mytarget,FXSEL(SEL_COMMAND,MyWidget::ID_THEMESSAGE));
This would be a lot simpler.
Of course, if your program has pulldown menus, you can make your life even easier
menubar=new FXMenuBar(...);
filemenu=new FXMenuPane(...);
new FXMenuTitle(menubar,"&File",NULL,filemenu);
new FXMenuCommand(filemenu,"&Open...",...);
...
...
...
new FXMenuCommand(filemenu,"&Quit\tCtl-Q",...);
In FXMenuTitle, the string "&File" would automatically add a hot-key Alt-F to
bring up the menu, while the string "&Quit\tCtl-Q" would not only add a hot-key
Alt-Q but also an accelerator Ctl-Q.
Since most applications would have a menubar, this is by-far the easiest way to
add hotkeys and accelerators.
But every once in a while, you may have an accelerator that does not have a corresponding
menu, or maybe have an app that has no menus; in such a case, directly adding the key-combo
to the accelerator table may be the way to go....
Hope this helps,
-- JVZ
JVZ
2017-01-13 22:23:06 UTC
Permalink
On Fri, 13 Jan 2017 16:11:05 -0500
Post by Julia Dudascik (Contractor)
Thank you. I tried to upgrade to the new version of FOX toolkit (version
1.6.53). When I build my application, which dynamically links with the FOX
libraries (FOX-1.6.lib and FOXDLL-1.6.lib). I built the FOX libraries as
64-bit in Visual Studio 2013, I get the following warning message when it
"warning C4251: FX::FXList::items : class
FX::FXObjectListOf<FX::FXListItem> needs to have dll-interface to be used
by clients of class FX::FXList"
I did not get this warning message with version 1.6.51. Should I be
concerned? Do you know what would cause it?
See:


http://stackoverflow.com/questions/4145605/stdvector-needs-to-have-dll-interface-to-be-used-by-clients-of-class-xt-war

https://msdn.microsoft.com/en-us/library/esew7y1w.aspx


The way I understand it, when you specialize a templated class (in this case,
FXObjectListOf<>), some of generated functions would have no DLL linkage.

In this case, the class is accessed only from FXList's API's which have DLL
linkage by virtue of FXAPI declaration in the header file.

But the concrete template instantiation produced by FX::FXObjectListOf<FX::FXListItem>
does not (generated inside FXList.cpp).

So, if it were possible for you to access API's of this class directly, those would
not have DLL linkage as expected.

Of course, FXList.cpp functions access the functions of FXObjectListOf<> without
such linkage; this is not a problem as the implementation of the specialized
FXObjectListOf<> lives in the same DLL as FXList.


It *could* be a problem if you would be able to access non-inlined API's via
FXObjectListOf<> API's (because the compiler would have to access the DLL's
import library for those functions, which don't exist due to not having
DLL spec on them.

I hope I'm explaining this properly.


Basically, this is due to the way the Microsoft world does DLL's; a DLL is a blob
of code that has entry-points for functions marked in some way.

When the DLL is loaded, those entry points become available to the hosting executable.

On Linux, the references to the entry points are resolved "lazyly" on as-needed basis
[unless you pass the magic linker flags (-Wl,-z -Wl,now).
On Windows, the executable is linked to a so-called "import" library, which is conceptually
simply an array of jump-instructions, where the target addess is not yet filled in.

When loading the DLL, those jumps will get filled in. A problem exists if the caller
would reference an object from the template that lives inside the DLL.

Most cases, this is not a big problem.


Hope this helps,


-- JVZ




+----------------------------------------------------------------------------+
| Copyright (C) 15:30 01/13/2017 Jeroen van der Zijp. All Rights Reserved. |
+----------------------------------------------------------------------------+
Loading...