subclassing a window 
Author Message
 subclassing a window

I am not sure if the control has been subclasses elsewhere.  3d controls
does some subclassing too.  Either way, the old style method uses:
OldProc =  (WNDPROC)::SetWindowLong( HWND, GWL_WNDPROC, (LONG)MyProc );

and at the end of MyProc:

default:
    lResult = CallWindow( OldProc, HWND, msg, wParam, lParam );

Quote:
}

return lResult;

Quote:
}

This leaves you cracking the messages by yourself, but if you have to get
inside, and MFC won't let you, this will do it.

--
Dan Stephens
Sapphire Software, Inc.
www.SapphireOnline.com

Quote:

>How do I subclass a window? I want to subclass an edit control to a
>rich-edit control.
>(from memory...I do something like this...)
>CRichEdit re;
>re.Create(<params>);

>HWND &hWnd = re.m_hWnd;
>HWND hOldWnd = Detach();  // called within MFC edit control class
>SubclassWindow(hWnd);
>::DestroyWIndow(hOldWnd);
>this is the way the docs say it should be done, but crashes on
>SubclassWindow call.
>In SubclassWindow CWnd::Attach is called,

>   BOOL CWnd::Attach(HWND hWndNew)
>   {
>      ASSERT(m_hWnd == NULL);   // Only attach once, detach on destroy
>      ASSERT(FromHandlePermanent(hWndNew) == NULL);  <---bombs here
>         // Must not be already in permanent map

>according to a Tech Note:
>This implies that the control that we are attempting to subclass has
already
>been subclassed.
>With MFC dialog boxes, you can specify DDX/DDV member variables to
associate
>with the controls of an MFC dialog class. These member variables can be
real
>values (for example, int, CString) or control variables (for example,
CEdit,
>CListBox). If the member variables are control variables, then the DDX/DDV
>handlers actually do subclass the dialog box controls using the control
>member variables. If you try to subclass those controls yourself, the above
>error can result

>but the window doesn't have any member variables associated with the MFC
>richedit
>control, so what is the problem then?
>......so close, yet so far.....
>   ...



Tue, 01 Aug 2000 03:00:00 GMT  
 subclassing a window


Quote:

>according to a Tech Note:
>This implies that the control that we are attempting to subclass has already
>been subclassed.
>With MFC dialog boxes, you can specify DDX/DDV member variables to associate
>with the controls of an MFC dialog class. These member variables can be real
>values (for example, int, CString) or control variables (for example, CEdit,
>CListBox). If the member variables are control variables, then the DDX/DDV
>handlers actually do subclass the dialog box controls using the control
>member variables. If you try to subclass those controls yourself, the above
>error can result

>but the window doesn't have any member variables associated with the MFC
>richedit
>control, so what is the problem then?

If your window is a dialog or form view, then MAKE an instance variable
of CRichEditCtrl and follow the tech note's instructions on DDX_Control().

--------------------------------------------------------------------------------

Principal Software Engineer       Corporate Web Page:     http://www.xiotech.com

Eden Prairie, MN                  Personal Home Page:   http://www.visi.com/~nde

"Question authority...and the authorities will end up questioning YOU!"
--------------------------------------------------------------------------------



Tue, 01 Aug 2000 03:00:00 GMT  
 subclassing a window

How do I subclass a window? I want to subclass an edit control to a
rich-edit control.
(from memory...I do something like this...)
CRichEdit re;
re.Create(<params>);

HWND &hWnd = re.m_hWnd;
HWND hOldWnd = Detach();  // called within MFC edit control class
SubclassWindow(hWnd);
::DestroyWIndow(hOldWnd);
this is the way the docs say it should be done, but crashes on
SubclassWindow call.
In SubclassWindow CWnd::Attach is called,

   BOOL CWnd::Attach(HWND hWndNew)
   {
      ASSERT(m_hWnd == NULL);   // Only attach once, detach on destroy
      ASSERT(FromHandlePermanent(hWndNew) == NULL);  <---bombs here
         // Must not be already in permanent map

according to a Tech Note:
This implies that the control that we are attempting to subclass has already
been subclassed.
With MFC dialog boxes, you can specify DDX/DDV member variables to associate
with the controls of an MFC dialog class. These member variables can be real
values (for example, int, CString) or control variables (for example, CEdit,
CListBox). If the member variables are control variables, then the DDX/DDV
handlers actually do subclass the dialog box controls using the control
member variables. If you try to subclass those controls yourself, the above
error can result

but the window doesn't have any member variables associated with the MFC
richedit
control, so what is the problem then?
......so close, yet so far.....
   ...



Wed, 02 Aug 2000 03:00:00 GMT  
 subclassing a window

Martin,
the problem is that you are *creating* the control you want to subclass.
Although this is intuitive, its a little more convoluted in MFC. DONT create
the rich edit control. Simply declare it and then subclass the window you
want.

Use the classwizard to create a class based on the richedit control.

class CMyRichEdit : public CRichEdit
{
...

Quote:
};

Then in the dialog class where you want the control subclassed, declare:

CMyRichEdit re;

Finally in the dialogs OnInitialize() function, call:
re.SubclassDlgItem (hWnd);

Make sure you unsubclass the control when the dialog is closed.

Aspi



Sat, 05 Aug 2000 03:00:00 GMT  
 subclassing a window

Quote:

>Finally in the dialogs OnInitialize() function, call:
>re.SubclassDlgItem (hWnd);

This call should actually have been
re.SubclassDlgItem (IDC_MYEDIT, this);


Sat, 05 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Subclassing foreign window and changing memory in it

2. Subclassing a window in different process

3. Problems subclassing a window

4. Subclassing a window

5. Subclassing a window in another application?

6. Subclassing a Window

7. Subclassing MFC windows

8. Subclassing System.Windows.Forms.ListBox

9. Subclassing window

10. Subclassing window

11. Subclassing Problem with Unicode Windows

12. Q: subclassing problem, with hook and windows messages

 

 
Powered by phpBB® Forum Software