By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,723 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,723 IT Pros & Developers. It's quick & easy.

VC++ hot keys

P: n/a
Ed
I've been away from C++ programming for awhile. Maybe this is a simple
problem. I get the error message "illegal call of non-static member
function" when I insert
DWORD hotkey;
hotkey=CHotKeyCtrl::GetHotKey();
into a Wizard-generated function that is NOT static --
void CCubesView::OnLButtonUp(UINT nFlags, CPoint point)
I am using MFC provided by the Wizard. I #include "stdafx.h" (it's
actually in afxcmn.h).

I seem to remember this error message from when I was a hotter
programmer, and it was due to something other than what it says at
face value.

Any suggestions? Or do you need more info? (Visual C++ 6.0)

-Ed P.
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Ed" <pr*****@my-deja.com> wrote in message
news:39**************************@posting.google.c om...
I've been away from C++ programming for awhile. Maybe this is a simple
problem. I get the error message "illegal call of non-static member
function" when I insert
DWORD hotkey;
hotkey=CHotKeyCtrl::GetHotKey();
into a Wizard-generated function that is NOT static --
void CCubesView::OnLButtonUp(UINT nFlags, CPoint point)
I am using MFC provided by the Wizard. I #include "stdafx.h" (it's
actually in afxcmn.h).

I seem to remember this error message from when I was a hotter
programmer, and it was due to something other than what it says at
face value.


No, the 'face value' meaning of the message is germane.

You have a nonstatic member function, and you're using
the syntax to call a static member function. In order
to invoke a nonstatic member function, you need to create
an object of the type which defines that function, and
call the function for that object.

e.g.

class X
{
public:
void func() const {} /* nonstatic member function */
};

int main()
{
// X::func(); /* invalid, 'func()' is nonstatic */
X obj;
obj.func(); /* OK */
// or:

obj().func(); /* OK */
return 0;
}

-Mike
Jul 19 '05 #2

P: n/a
"Ed" <pr*****@my-deja.com> wrote...
I've been away from C++ programming for awhile. Maybe this is a simple
problem. I get the error message "illegal call of non-static member
function" when I insert
DWORD hotkey;
hotkey=CHotKeyCtrl::GetHotKey();
If 'GetHotKey' function is non-static, and this code is not in
any member of 'CHotKeyCtrl' function, you need an object (or
a pointer to an object) of the type 'CHotKeyCtrl' and then use
operator dot (or the operator arrow) to access the function:

CHotKeyCtrl *ctrl = ??? ; // get it somehow somewhere
DWORD hotkey = ctrl->GetHotKey();
into a Wizard-generated function that is NOT static --
void CCubesView::OnLButtonUp(UINT nFlags, CPoint point)
Is CCubesView a descendant of CHotKeyCtrl? It is likely that
it's not. At this point there is not enough information about
your classes to recommend anything more.
I am using MFC provided by the Wizard. I #include "stdafx.h" (it's
actually in afxcmn.h).

I seem to remember this error message from when I was a hotter
programmer, and it was due to something other than what it says at
face value.
You seem to remember incorrectly. The face falue is just fine.
You can only call static member functions using the :: notation.
Any suggestions? Or do you need more info? (Visual C++ 6.0)


It would probalby be better if you try an MFC newsgroup and
supply them with the necessary info. I stronly recommend
'microsoft.public.vc.mfc' as your next stop.

Victor
Jul 19 '05 #3

P: n/a
Ed wrote:
I've been away from C++ programming for awhile. Maybe this is a simple
problem. I get the error message "illegal call of non-static member
function" when I insert
DWORD hotkey;
hotkey=CHotKeyCtrl::GetHotKey();
into a Wizard-generated function that is NOT static --
void CCubesView::OnLButtonUp(UINT nFlags, CPoint point)


Read the message again:

"illegal call"

So it's talking about calling a function, not defining one.

"of non-static member function"

So you're actually calling a member function "that is NOT static".
This means that the error message must be about the call to
CHotKeyCtrl::GetHotKey(). The problem is that you're calling it as if
it were a static member function, but it doesn't seem to be one. You
need to get an object of class CHotKeyCtrl and call your function on
that object.

Jul 19 '05 #4

P: n/a
Ed
Thanks all for the input. I knew it was something simple. By creating
an object of the class CHotKeyCtrl and then the "." to call the
function, I got it to compile.

But now it is giving a run-time assert failure related to my use of
the function, so I may be stuck giving up that idea. I just wanted to
detect when the Shift or Control keys were pressed.

I might have to go to an MFC newsgroup.

-Ed P.
Jul 19 '05 #5

P: n/a
"Ed" <pr*****@my-deja.com> wrote...
Thanks all for the input. I knew it was something simple. By creating
an object of the class CHotKeyCtrl and then the "." to call the
function, I got it to compile.

But now it is giving a run-time assert failure related to my use of
the function, so I may be stuck giving up that idea. I just wanted to
detect when the Shift or Control keys were pressed.
Look at GetKeyboardState function.

I might have to go to an MFC newsgroup.


May not be a bad idea.
Jul 19 '05 #6

P: n/a
Ed
Thanks for the tip. I got GetKeyboardState to work - it's just what I
need.

I hadn't realized the left and right shift and control keys were
distinct (160 and 161, 162 and 163).

-Ed P.

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<G7Wtb.170611$275.533354@attbi_s53>...
"Ed" <pr*****@my-deja.com> wrote...
Thanks all for the input. I knew it was something simple. By creating
an object of the class CHotKeyCtrl and then the "." to call the
function, I got it to compile.

But now it is giving a run-time assert failure related to my use of
the function, so I may be stuck giving up that idea. I just wanted to
detect when the Shift or Control keys were pressed.


Look at GetKeyboardState function.

I might have to go to an MFC newsgroup.


May not be a bad idea.

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.