Article View: borland.public.cppbuilder.nativeapi
Article #8923Re: SetClassLong problems
From: Remy Lebeau (TeamB)
Date: Fri, 03 Sep 2004 20:57
Date: Fri, 03 Sep 2004 20:57
85 lines
3553 bytes
3553 bytes
"Lynn Morrison" <Cranky@__whisp.com> wrote in message
news:4138cc6a@newsgroups.borland.com...
> a member function used as a WindProc has to be static
You can use the VCL's MakeObjectInstance() function to get around that. It
was specifically designed to allow a non-static member to be used as a
window procedure. For example:
class MSocket
{
private:
void* FWndProc;
LONG FOldWndProc;
void __fastcall MWndProc(TMessage &Message);
//...
};
MSocket::MSocket()
{
FWndProc = MakeObjectInstance(MWndProc);
//...
FOldWndProc = SetWindowLong(FWindowHandle, GWL_WNDPROC, (LONG)
FWndProc);
//...
}
MSocket::~MSocket()
{
SetWindowLong(FWindowHandle, GWL_WNDPROC, FOldWndProc);
DestroyWindow(FWindowHandle);
//...
FreeObjectInstance(FWndProc);
//...
}
void __fastcall MSocket::MWndProc(TMessage &Message)
{
// use Message as needed...
}
> I wish to set the classes memory pointer to the cbClsExtra
> member in my WNDCLASSEX struct using SetClassLong...
You should use SetWindowLong() with the GWL_USERDATA flag instead.
> problem is that I keep getting errors when compiling it...
> "Cannot cast from MSocket to long"...
You need to get rid of the asterik when passing the 'this' pointer:
SetClassLong(FWindowHandle, GCL_CBCLSEXTRA, (LONG) this);
Or, using SetWindowLong():
SetWindowLong(FWindowHandle, GWL_USERDATA, (LONG) this);
> I am doing all of this so that when I get messages(which can
> be for any of the MSocket classes) I want to know if the message
> is for "THIS" object and not another, because of the static
> WindProc.
You should not be handling the situation like that. The specified HWND will
be the specific FWindowHandle window that the message belongs to. You don't
need to do any comparisons, you will already know exactly which MSocket
instance the message is intended for. Just extract the MSocket* pointer
from the HWND and pass the message data to it as needed for processing.
LRESULT CALLBACK MSocket::MWindProc(HWND Wnd, UINT Msg, WPARAM WParam,
LPARAM LParam)
{
MSocket* pThis = (MSocket*) GetWindowLong(Wnd, GWL_USERDATA);
// handle message as needed...
// use pThis as needed...
}
> if((long) TempMSocketClassPointer != (long)&FWindowHandle)
That is not the correct comparison to make. You are trying to compare an
MSocket* pointer to an HWND pointer, which will always fail.
Gambit
Technical Details
Message-ID:
<4138da54$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4138cc6a@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ce81aceba334526c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4138cc6a@newsgroups.borland.com> Subject: Re: SetClassLong problems Date: Fri, 3 Sep 2004 13:57:19 -0700 Lines: 87 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4138da54$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1094244948 68.69.17.41 (3 Sep 2004 13:55:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsgate.cistron.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.icl.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail