I am relatively new at this, but I think I have the problem pinpointed. Of course I could also be entirely off.
I am attempting to superclass the windows EDIT window class.
I can successfully superclass it when not using c++ classes, but I would very much like to implement my new window class as a c++ class.
I am reasonable certain that the problem has to do with the last paragraph from the MSDN article:
"The superclass must not use the original extra bytes for the base class or the window for the same reasons that an instance subclass or a global subclass should not use them. Also, if the application adds extra bytes for its use to either the class or the window instance, it must reference the extra bytes relative to the number of extra bytes used by the original base class. Because the number of bytes used by the base class may vary from one version of the base class to the next, the starting offset for the superclass's own extra bytes may also vary from one version of the base class to the next. MSDN article"
I assume this is because I must use the Set/GetWindowLong(...) method of referencing my class from a static member function, but I do not understand what to do to fix it. How many bytes does the old EDIT window class use?
Here is the relevant code:
Code:
//file: ShEdit.cpp
#include "ShEdit.h"
#define ID_EDIT_SH 101
ShEdit::ShEdit(HWND hwndParent, HINSTANCE hInstance)
{
// retrieve the WNDCLASS of the windows EDIT window class
WNDCLASS wc;
ZeroMemory(&wc, sizeof(WNDCLASS));
GetClassInfo(hInstance, "EDIT", &wc);
wc.hInstance = hInstance;
wc.lpszClassName = "ShEdit";
// store the old WNDPROC of the EDIT window class
m_pfnPrevWndProc = wc.lpfnWndProc;
// replace it with local WNDPROC
wc.lpfnWndProc = WindowProc;
// register the new window class, "ShEdit"
RegisterClass(&wc);
// use the new window class to create a window
m_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "ShEdit", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
WS_HSCROLL | ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
hwndParent, (HMENU)ID_EDIT_SH, hInstance, (LPVOID)this);
}
LRESULT CALLBACK ShEdit::WindowProc(HWND hwnd , UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// retrieve the pointer to the creator instance of ShEdit
ShEdit* shEdit = NULL;
shEdit = (ShEdit*)GetWindowLong(hwnd, DWL_USER); // null until WM_CREATE
switch(uMsg)
{
case WM_CREATE:
{
// store the pointer to the instance of ShEdit passed in lParam
SetWindowLong(hwnd, DWL_USER, lParam);
shEdit = (ShEdit*)lParam;
// call the default WNDPROC for the EDIT window class
CallWindowProc(shEdit->m_pfnPrevWndProc, hwnd, uMsg, wParam, lParam);
break;
}
default:
{
// didn't handle message, so send it to the default WNDPROC
return CallWindowProc(shEdit->m_pfnPrevWndProc, hwnd, uMsg, wParam, lParam);
}
}
return 0;
}
I realize that this is a lot, but I have really come to a standstill on this. It seems to me that this must be a fairly common problem. However, most of the online documentation I can find either uses MFC, or it does not use c++ classes.
Thanks for your time at least,
cDir