|
-
Mar 9th, 2002, 01:16 AM
#1
Thread Starter
Hyperactive Member
this pointer to access
in my window creation class, i have a static WndProc which will be used for adding events. i read here http://www.mvps.org/windev/cpp/class.html that by passing the this pointer to the lParam of CreateWindow, i can then retrieve that pointer when i handle WM_CREATE in my WndProc, and store it.. after i can cast it back to the class, and use the pointer to access and modify members...the problem is that everytime i try to actually modify a member, the program crashes..could anybody help me?
thanks
Amon Ra
Amon Ra
The Power of Learning.
-
Mar 9th, 2002, 12:19 PM
#2
Thread Starter
Hyperactive Member
ok so here is my wndproc, which is a static member of the WINDOW class
PHP Code:
//WindowProc: this is the real one...the one that does all the work
LRESULT CALLBACK WINDOW::WindowProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
WINDOW *const ptThis = (WINDOW*) lParam; //store "this" in variable;
switch (Msg)
{
case WM_CREATE:
SetWindowLong (hWnd, GWL_USERDATA, (LONG) lParam); //stores "this" on window data just in case
return 0;
case WM_LBUTTONDOWN:
MessageBox (hWnd, ptThis->m_pcText , "BLAH", MB_OK | MB_ICONINFORMATION);
return 0;
case WM_PAINT: // this must be handled
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY: // must also be handled in the main window
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, Msg, wParam, lParam);
} //WindowProc
to have the "this" pointer stored in the lParam, i used:
PHP Code:
hWnd = CreateWindowEx ( m_dwExStyle,
m_pcClassName,
m_pcText,
m_dwStyle,
m_XPos, m_YPos, m_Width, m_Height,
m_hParent,
NULL,
m_hInstance,
this );
The problem is that when i get to
PHP Code:
MessageBox (hWnd, ptThis->m_pcText , "BLAH", MB_OK | MB_ICONINFORMATION);
it crashes the program. anyone have any idea? thanks in advance
Amon Ra
Amon Ra
The Power of Learning.
-
Mar 9th, 2002, 05:34 PM
#3
Thread Starter
Hyperactive Member
any body please? basically i want a class with a windowproc in it, so that the user has no acces to it
Amon Ra
The Power of Learning.
-
Mar 10th, 2002, 02:07 AM
#4
Thread Starter
Hyperactive Member
great! i got it..after adjusting a few things.. =)
Amon Ra
The Power of Learning.
-
Mar 10th, 2002, 08:01 AM
#5
Not sure if you already have the solution...
the lParam passed to the WM_CREATE message is not the lParam you passed to CreateWindow, but rather the address of a CREATESTRUCT.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 10th, 2002, 12:47 PM
#6
Thread Starter
Hyperactive Member
yea exactly..i found that out in the msdn... i did this
PHP Code:
pThis = (WINDOW*) ((LPCREATESTRUCT)lParam)->lpCreateParams;
and i passed the "this" to the lParam of CreateWindow
Amon Ra
The Power of Learning.
-
Mar 10th, 2002, 02:01 PM
#7
Monday Morning Lunatic
You didn't notice the code I posted ages ago about this then? 
Everyone and his dog seems to be writing window-wrapper classes at the moment, strange really.
I want .NET *sigh* Was so much easier to use
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 10th, 2002, 02:08 PM
#8
Thread Starter
Hyperactive Member
lol..no i didn't see it..i ma writing this for the info tech class at our school (high school)... =)
Amon Ra
The Power of Learning.
-
Mar 11th, 2002, 10:00 AM
#9
The problem of passing the class as create parameter and saving it in a static variable of the WndProc is that every new class will replace the last! Keep that in mind! (someone here did it that way)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 11th, 2002, 05:35 PM
#10
Monday Morning Lunatic
Use a method like the SetWindowLong(hWnd, GWL_USERDATA, this) one.
I've posted about that one a LOT now...so I won't repeat it
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 11th, 2002, 06:46 PM
#11
Thread Starter
Hyperactive Member
ok apparently, as you said CornedBee, when everything is created , and i use the pointer to this, i get an error..
i am gonna see how i can fix, and try to find yours Parksie..
thanks =
Amon Ra
Amon Ra
The Power of Learning.
-
Mar 11th, 2002, 09:20 PM
#12
Thread Starter
Hyperactive Member
i fixed it and it works beautifully now 
Amon Ra
Amon Ra
The Power of Learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|