Article View: borland.public.cppbuilder.nativeapi
Article #12546Re: Subclassing an edit control
From: Martin Golm
Date: Tue, 02 Dec 2003 15:02
Date: Tue, 02 Dec 2003 15:02
63 lines
3189 bytes
3189 bytes
Gary Setter wrote:
> I don't understand. Why don't you think that GWL_WNDPROC existis?
I'm just now checking that for a window control that was not created
with my window class (like tEdit) my code cannot work as intended.
> I was able to get you app running. I posted some of your code below.
The code as posted works just fine.
> 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.
Moving from GWL_WNDPROC to GWL_USERDATA helped. Now I can work with a
non-static tEdit::WndProc, that means the code from EditWindowProc can
be moved to tEdit::WndProc. The resulting functions after changings look
as following:
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam,
LPARAM lParam) {
tWindow* pWindow = reinterpret_cast<tWindow*>
(GetWindowLong(hWnd, GWL_USERDATA));
if (!pWindow)
return DefWindowProc(hWnd, iMessage, wParam, lParam);
return pWindow->WndProc(iMessage, wParam, lParam);
}
void tWindow :: Create() {
hWnd = CreateWindow(szWndClsName, title.c_str(), attr.style,
attr.left, attr.top, attr.width, attr.height,
parent ? parent->GetHandle() : 0, 0,
tApp::hInst, 0);
if (!hWnd)
throw tXWindow();
hDC = GetDC(hWnd);
if (!hDC)
throw tXWindow();
SetWindowLong(hWnd, GWL_USERDATA, (LONG)this);
if (parent)
parent->AddChild(this);
}
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, 0);
if (!hWnd)
throw tXWindow();
orgWndProc = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC,
(LONG)::WndProc);
if (!orgWndProc)
throw tXWindow();
if (parent)
parent->AddChild(this);
}
Do you see any problems with this? As far as I can tell the app is
running.
Thanks for help.
Martin
Technical Details
Message-ID:
<3FCCA981.209B2B0@gmx.de>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.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> <3fc75c8b@newsgroups.borland.com>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-12-02 07:09:35 PST Message-ID: <3FCCA981.209B2B0@gmx.de> Date: Tue, 02 Dec 2003 16:02:25 +0100 From: Martin Golm <golm@gmx.de> X-Mailer: Mozilla 4.72 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Subclassing an edit control 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> <3fc75c8b@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 62.153.9.30 X-Trace: newsgroups.borland.com 1070377552 62.153.9.30 (2 Dec 2003 07:05:52 -0700) Lines: 65 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail