Hi,
I am trying to write a class which creates a window and then assigns a
method of the class as the wndproc function for the window so that
each instance of the class can handle the messages for its repective
form.
I am trying to do the following:
class myWinClass {
.....
private: LRESULT CALLBACK _wndProc(HWND, UINT, WPARAM, LPARAM);
.....
}
.....
WNDCLASS wc;
.....
wc.lpfnWndProc = (WNDPROC)&_wndProc;
.....
But this raises the following compile error under Borland C++ 5.5
Compiler:
"Cannot cast from 'long (__stdcall * (_closure )(HWND__ *,unsigned
int,unsigned int,long))(HWND__ *,unsigned int,unsigned int,long)'
to
'long (__stdcall *)(HWND__ *,unsigned int,unsigned int,long)'"
I should imagine this is a general c++ syntax problem and would happen
on any c++ compiler not just Borland's.
I can see that a method is not the same as a normal function (it has
the implicit this pointer for example) but would like to know if there
is a way to get this to work.
Thanks for your help
Gareth Williams 6 3583
Window procedure must be static when is inside a class.
If you don't want to make it static declare WndProc outside the class
and pass it's pointer to the class for exapmle in class constructor.
--
SirMike
the code is my strength http://www.sirmike.grudziadz.com
"Turbo_King" <gj*************@yahoo.co.uk>, haber iletisinde sunlari
yazdi:c3**************************@posting.google. com... Hi,
I am trying to write a class which creates a window and then assigns a method of the class as the wndproc function for the window so that each instance of the class can handle the messages for its repective form.
I am trying to do the following:
class myWinClass { .... private: LRESULT CALLBACK _wndProc(HWND, UINT, WPARAM, LPARAM); .... } .... WNDCLASS wc; .... wc.lpfnWndProc = (WNDPROC)&_wndProc; ....
But this raises the following compile error under Borland C++ 5.5 Compiler:
"Cannot cast from 'long (__stdcall * (_closure )(HWND__ *,unsigned int,unsigned int,long))(HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(HWND__ *,unsigned int,unsigned int,long)'"
I should imagine this is a general c++ syntax problem and would happen on any c++ compiler not just Borland's.
I can see that a method is not the same as a normal function (it has the implicit this pointer for example) but would like to know if there is a way to get this to work.
Thanks for your help
Gareth Williams
Have you checked the ATL source code? It has a nice technique for
generating some thunk code for a WndProc that changes the first
parameter from a HWND to this. So your WndProc member function is directly
called. No static function at all.
SirMike <sirmike@FUCK_SPAMMERS.poczta.onet.pl> wrote in message news:<d0**********@korweta.task.gda.pl>... Window procedure must be static when is inside a class. If you don't want to make it static declare WndProc outside the class and pass it's pointer to the class for exapmle in class constructor.
Thanks for the reply.
Correct me if I'm wrong...
If I make the method static then it won't be able to access its member
variables, because there is only one instance of the wndproc method
but multiple instances of the class that owns it.
If I declare the wnd proc outside the class and hand it a pointer then
how do I get the wndproc to reference the member variables of the
owning class instance?
Thanks again
Gareth Williams
"Turbo_King" <gj*************@yahoo.co.uk> wrote in message
news:c3**************************@posting.google.c om... SirMike <sirmike@FUCK_SPAMMERS.poczta.onet.pl> wrote in message news:<d0**********@korweta.task.gda.pl>... Window procedure must be static when is inside a class. If you don't want to make it static declare WndProc outside the class and pass it's pointer to the class for exapmle in class constructor.
Thanks for the reply.
Correct me if I'm wrong...
If I make the method static then it won't be able to access its member variables, because there is only one instance of the wndproc method but multiple instances of the class that owns it.
If I declare the wnd proc outside the class and hand it a pointer then how do I get the wndproc to reference the member variables of the owning class instance?
Thanks again
Gareth Williams
Most such callbacks have a void* parameter which you can use to pass
whatever data you please. What I do is pass "this" as that pointer, so that
the callback can be a simple one-liner, like such:
{
((MyClass*)userData)->HandleCallback(wParam,hParam);
}
-Howard
Thanks for everyone's reply! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Beach Potato |
last post by:
Hi:
I've searched newsgroups and various archives, including MSDN & MFC sources,
but at this point failed to locate an accurate and simple implementation of
WndProc function for MSWindows window...
|
by: sshuangw |
last post by:
Hello:
I am encountering a very weird issue with MDI child, Overriden WndProc
function and hidden form.
Basically, the application has two forms, Form1(parent form),
Form2(Child form),...
|
by: Ed Sutton |
last post by:
How can a WndProc be created inside a component?
Currently I have a WndProc in my frmMain. It looks for WM_DEVICECHANGE
messages for connection and removal events for a USB/Serial device. My...
|
by: cyrille |
last post by:
Hello
from example from web i did a little code to avoiding columnHeader resize.
this code seems to work well,
but when I put a 'normal' ListView on the same Form than my overrided ListView
it...
|
by: dworthem |
last post by:
if I have the compiler option /clr:oldSyntax in a Windows Forms application
protected:
void WndProc(System::Windows::Forms::Message* m)
is called
If I remove oldSyntax
protected:
|
by: Lenster |
last post by:
When using PostMessage to post myself a message, the msg and wparam
parameters somehow get swapped over. They are in the correct order when
calling PostMessage but by the time wndproc handles the...
|
by: Phuff |
last post by:
I have an application that should run in the system tray while open.
It is supposed to be open at all times and I need it to dissapear when
the "X" button is pushed on the form...but without...
|
by: Matt Brown - identify |
last post by:
Hello,
I'm very new to this level of programming and .net in general. My
background is VB.
I am attempting to use the WebBrowser control to load a flash movie,
and it is a known issue...
|
by: Newbie Coder |
last post by:
I am trying to override WndProc like I would in this VB.NET sub. How do I do
it?
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissi
ons.SecurityAction.Demand,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |