I
Ikke
Hi everybody,
I have a problem with the callback WndProc. Based on a setting, I'm
trying to start one of two windows. Basically, what I'm trying to do is
the following:
- main.cpp is my main source file, and is the one which contains int
WINAPI WinMain.
- inside WinMain, I decide which class to instantiate (A or B)
- both classes should create a window, handle the messages for the
window, and call further/other stuff
The problem is that I cannot add WindowProcedure as a function inside
class A (nor B). If I do so, I get the following messages:
error C3867: 'A::WindowProcedure': function call missing argument list;
use '&A::WindowProcedure' to create a pointer to member
error C2440: '=' : cannot convert from 'LRESULT (__stdcall A::* )
(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'
On the internet, I've found a few solutions to solve this - the first one
was to make the function static. This works perfectly, the code compiles,
but of course I cannot call any class functions from within a static
function, so this is a bit useless for me.
The second solution was to define the function call as before, but
change:
winClass.lpfnWndProc = WindowProcedure;
to
winClass.lpfnWndProc = (WNDPROC) WindowProcedure;
However, this doesn't compile at all: the message I'm getting now is:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to
'WNDPROC'
My question now is, of course, how can I make this WindowProcedure
function part of a class?
There's another solution (I guess), that is to keep the classes as they
are, and keep the WindowProcedure in main.cpp, and pass a pointer to the
function to the class. However, I've only just begun learning C++, and I
have no idea how to do this.
Can anybody please help me out here?
Thanks in advance!
Ikke
I have a problem with the callback WndProc. Based on a setting, I'm
trying to start one of two windows. Basically, what I'm trying to do is
the following:
- main.cpp is my main source file, and is the one which contains int
WINAPI WinMain.
- inside WinMain, I decide which class to instantiate (A or B)
- both classes should create a window, handle the messages for the
window, and call further/other stuff
The problem is that I cannot add WindowProcedure as a function inside
class A (nor B). If I do so, I get the following messages:
error C3867: 'A::WindowProcedure': function call missing argument list;
use '&A::WindowProcedure' to create a pointer to member
error C2440: '=' : cannot convert from 'LRESULT (__stdcall A::* )
(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'
On the internet, I've found a few solutions to solve this - the first one
was to make the function static. This works perfectly, the code compiles,
but of course I cannot call any class functions from within a static
function, so this is a bit useless for me.
The second solution was to define the function call as before, but
change:
winClass.lpfnWndProc = WindowProcedure;
to
winClass.lpfnWndProc = (WNDPROC) WindowProcedure;
However, this doesn't compile at all: the message I'm getting now is:
error C2440: 'type cast' : cannot convert from 'overloaded-function' to
'WNDPROC'
My question now is, of course, how can I make this WindowProcedure
function part of a class?
There's another solution (I guess), that is to keep the classes as they
are, and keep the WindowProcedure in main.cpp, and pass a pointer to the
function to the class. However, I've only just begun learning C++, and I
have no idea how to do this.
Can anybody please help me out here?
Thanks in advance!
Ikke