Article View: borland.public.cppbuilder.nativeapi
Article #12585Re: Subclassing an edit control
From: Gary Setter
Date: Fri, 28 Nov 2003 14:32
Date: Fri, 28 Nov 2003 14:32
68 lines
3818 bytes
3818 bytes
"Martin Golm" <golm@gmx.de> wrote in message
news:3FC72C07.F8402E63@gmx.de...
> Gary Setter wrote:
> > I see that your main window which is the frame for your edit window
reserves
> > memory for a pointer to a tWindow in
> > wndclass.cbWndExtra = sizeof(tWindow*);
>
> Yes, I do that to forward the messages from the global window procedure
> to the appropriate window's window procedure.
> Interestingly enough this isn't working for the edit control. First I
> didn't use SetWindowLong() with the GWL_WNDPROC parameter. It simply
> didn't exist. Whenever my application received a message for the edit
> control it crashed, and the call stack was non-exisiting (just a lot of
> ???'s). This was because the pointer I cast to tWindow* didn't represent
> a tWindow descendant. Don't know why...
>
I don't understand. Why don't you think that GWL_WNDPROC existis?
I was able to get you app running. I posted some of your code below.
> > But if you can't why not use Get/SetWindowLong(hWnd,GWL_USERDATA) ?
> > That would let you use the same technique to tie that tEdit/tWindow
object
> > to the window handle in the static WndProc function.
>
> Sorry, I don't quite get the point?
>
That's because I'm a native gibberish speaker ;-) Sorry :-(
Here is some of the code that I changed. The key is using the GWL_USERDATA
offset, which is available for all windows including EDIT.
static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
LPARAM
lParam) {
tWindow* pWindow = reinterpret_cast<tWindow*>(GetWindowLong(hWnd,
GWL_USERDATA));
if (!pWindow) {
if (iMessage == WM_CREATE) {
LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
pWindow = reinterpret_cast<tWindow*>(lpcs->lpCreateParams);
SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<long>(pWindow));
return pWindow->WndProc(hWnd, iMessage, wParam, lParam);
}
return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
return pWindow->WndProc(hWnd, iMessage, wParam, lParam);
}
void tEdit :: Create() {
attr.style |= ES_AUTOHSCROLL | ES_LEFT | WS_TABSTOP;
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", attr.style,
attr.left, attr.top, attr.width, attr.height,
parent ? parent->GetHandle() : 0, 0,
tApp::hInst, reinterpret_cast<void*>(this));
if (!hWnd)
throw tXWindow();
orgWndProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC,
(LONG)::WndProc);
SetWindowLong(hWnd,GWL_USERDATA,(long)this);
if (!orgWndProc)
throw tXWindow();
if (parent)
parent->AddChild(this);
}
Technical Details
Message-ID:
<3fc75c8b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3FC37DC6.8A69A621@gmx.de> <3fc39946@newsgroups.borland.com> <3FC4C880.15E477D2@gmx.de> <3fc61f76@newsgroups.borland.com> <3fc62d43@newsgroups.borland.com> <3FC72C07.F8402E63@gmx.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,7f8523ddb948f0d0 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-28 06:39:06 PST From: "Gary Setter" <setterg@worldnet.att.net> Newsgroups: borland.public.cppbuilder.nativeapi References: <3FC37DC6.8A69A621@gmx.de> <3fc39946@newsgroups.borland.com> <3FC4C880.15E477D2@gmx.de> <3fc61f76@newsgroups.borland.com> <3fc62d43@newsgroups.borland.com> <3FC72C07.F8402E63@gmx.de> Subject: Re: Subclassing an edit control Date: Fri, 28 Nov 2003 08:32:27 -0600 Lines: 69 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 12.74.20.20 Message-ID: <3fc75c8b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1070029963 12.74.20.20 (28 Nov 2003 06:32:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail