Article View: borland.public.cppbuilder.nativeapi
Article #12565Re: Subclassing an edit control
From: Gary Setter
Date: Wed, 03 Dec 2003 14:27
Date: Wed, 03 Dec 2003 14:27
87 lines
4515 bytes
4515 bytes
"Martin Golm" <golm@gmx.de> wrote in message news:3FCCA981.209B2B0@gmx.de...
> 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.
>
Hi Martin,
I still don't understand what you mean by "my code cannot work as intended".
Please, please please. State how you expected your code to work and your
code 'failed'.
> > 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:
>
Martin,
You can't replace GWL_WNDPROC with GWL_USERDATA. What I was doing was
replacing Get/SetWindowLong(hWnd,0) with Get/SetWindowLong(hWnd,
GWL_USERDATA) in the tWindow and static WndProc code.
GetWindowLong(hWnd,0) is only valid for classes that have extra space
allocated for each window, which you did when you registered your tWindow
class. But you can't do that with a pre-defined class like EDIT. The only
way to consistenly manage the tie between the c++ class and the window
handle (other then a std::map or something) is to use GWL_USERDATA.
> 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.
The only problem I can see is the GetDC without a matching RleaseDC.
Hope that helps.
Gary
Technical Details
Message-ID:
<3fcdf7b1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!newsfeed.icl.net!newsfeed.fjserv.net!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> <3fc75c8b@newsgroups.borland.com> <3FCCA981.209B2B0@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-12-03 07:09:52 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> <3fc75c8b@newsgroups.borland.com> <3FCCA981.209B2B0@gmx.de> Subject: Re: Subclassing an edit control Date: Wed, 3 Dec 2003 08:27:05 -0600 Lines: 88 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.73 Message-ID: <3fcdf7b1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1070462897 12.74.20.73 (3 Dec 2003 06:48:17 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail