Re: Why does this cause "data abort" ?
This will probably work, but beware that WM_CREATE is not
the first message sent to the window. WM_NCCREATE has
that honor I believe. Consequently, it can't be handled in the
class' message map, e.g. you can't implement your own borders.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
news:OlO6jUoFIHA.1184@TK2MSFTNGP04.phx.gbl...
"Lisa Pearlson" <no@spam.plz> wrote in message
news:OrgRWwmFIHA.4196@TK2MSFTNGP04.phx.gbl...
I'm using the SetWindowLong and GetWindowLong like so:
class MyWnd
{
BOOL Create(..)
{
m_hWnd = CreateWindow( .... );
SetWindowLong(hWnd, GWL_USERDATA, (LONG) hWnd);
}
virtual OnCreate(LPCREATESTRUCT lpcs)
{
return 0;
}
LRESULT OnMessage(MSG msg, WPARAM w, LPARAM l)
{
switch (msg)
{
case WM_CREATE:
return OnCreate( (LPCREATESTRUCT) lParam);
}
}
}
in WndProc I do:
LRESULT WndProc(HWND hWnd, MSG msg, WPARAM w, LPARAM l)
{
MyWnd* pWnd = reinterpret_cast<MyWnd*>( GetWindowLong(hWnd,
GWL_USERDATA);
return pWnd->OnMessage(msg, w, l);
}
The problem with this is construction is that WM_CREATE will never get
called properly because SetWindowLong occurs AFTER window has been
created, and I think WM_CREATE is sent just before..
So not sure how to solve this problem..
The static WndProc needs to handle WM_CREATE itself.
LRESULT WndProc(HWND hWnd, MSG msg, WPARAM wParam, LPARAM lParam)
{
MyWnd* pWnd;
if (msg == WM_CREATE) {
const CREATESTRUCT const* pCS = (const CREATESTRUCT const*)lParam;
pWnd = reinterpret_cast<MyWnd*>(pCS->lpCreateParams);
SetWindowLongPtr(hWnd, GWL_USERDATA, pWnd);
}
else
pWnd = reinterpret_cast<MyWnd*>( GetWindowLongPtr(hWnd,
GWL_USERDATA);
return pWnd->OnMessage(msg, wParam, lParam);
}
Pass the "this" pointer as the last parameter of CreateWindow(Ex)
Lisa