🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #12660

Re: Subclassing an edit control (quite long post)

#12660
From: Gary Setter
Date: Thu, 27 Nov 2003 15:59
53 lines
2790 bytes
<snip> Now I'd like EditWindowProc to be a member function of tEdit so I can
> call some of tEdit's member functions. Is there any way to achieve this?
> (Static member functions could be a solutions, as there's momentarily
> exactly one instance of tEdit in the whole app. But if there's a way
> without using static member function I'd prefer that.)
>
>
> Thanks,
> Martin

This is what I did. I have a static WinProc for each base class and use
SetWindowLong(HWnd,GWL_USERDATA,(long) this); in the constructor to tie the
window handle to the class object. This is not all there is to the problem.
You must take care to break the connection between GWL_USERDATA and the
handle when the object is deleted or the window is destroyed. And you must
not use GWL_USERDATA for anything else, natch ;-)
Any comments concerning this approach are welcome.

Best regards,
Gary

#include <windows.h>
#pragma hdrstop
#include "CREdit.h"

static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM
lParam)
{
 CREdit * me = (CREdit *)GetWindowLong(hWnd,GWL_USERDATA);
 if (me)
  return me->WndProc(hWnd, iMsg, wParam, lParam);

   return DefWindowProc(hWnd, iMsg, wParam, lParam);
 }

 return FALSE;
}
/*
 Setup a subclass for edit boxes.
 Save the current message handler
 Set the message handler to our own.
 Messages that out handler can not handle will be sent to the original
*/

CREdit::CREdit(HWND papa,UINT controlID)
 {
 HWnd = GetDlgItem(papa, controlID);
 if (HWnd) {
  PrevProc = (WNDPROC) GetWindowLong(HWnd,GWL_WNDPROC);
  SetWindowLong(HWnd,GWL_WNDPROC, (long) ::WndProc);
  SetWindowLong(HWnd,GWL_USERDATA,(long) this);
 }
}
Technical Details
Message-ID: <3fc61f76@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3FC37DC6.8A69A621@gmx.de> <3fc39946@newsgroups.borland.com> <3FC4C880.15E477D2@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-27 08:05:45 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>
Subject: Re: Subclassing an edit control (quite long post)
Date: Thu, 27 Nov 2003 09:59:27 -0600
Lines: 54
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.6
Message-ID: <3fc61f76@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1069948790 12.74.20.6 (27 Nov 2003 07:59:50 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail