Defeated by windows....

Started by
13 comments, last by guppy 21 years, 9 months ago
I''ll go ahead and apologize for my smartass comment too. I just see a lot of people here post problems that are somewhat vague and then turn around and start criticizing people who try to help them. It''s one of the few things that really gets me mad.

But I had read all your posts, I guess I was commenting more from the viewpoint of someone who has messed with exactly what you''re working on now, and some of the problem areas I had seen.

If you''ve debugged your app, and you see that the error occurs on this line:

long l = (this->callEventHandler(long_this, (long)message, wParam, lParam));

and your callEventHandler() function is just returning -1 without doing any work, I don'' know what the problem is. I''d need to run through it in a debugger myself.

two more questions: When your program crashes, which message are you handling and what is the value of ''this''? I''m assuming it''s valid since you''re able to call glWndProc().
Advertisement
I thougth (since my english is too bad to explain what my problem is) that you migth benifit from knowing that the type of message handling im trying to do is the kind That Oluseyi is talking about in his article Creating a Win32 Window Wrapper Class
the only difference is that im using a class (eventHandlerIF) wich must implement the method handleEvent(...)
(since this is more truely OO than function pointers)

/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
/Please excuse my bad spelling - My native language is binary not english|Visit meTake my advice - I don''t use it...
quote:Original post by JonStelly
If you''ve debugged your app, and you see that the error occurs on this line:

long l = (this->callEventHandler(long_this, (long)message, wParam, lParam));

and your callEventHandler() function is just returning -1 without doing any work, I don'' know what the problem is. I''d need to run through it in a debugger myself.

two more questions: When your program crashes, which message are you handling and what is the value of ''this''? I''m assuming it''s valid since you''re able to call glWndProc().


this is indeed valid, the message that first triggers is ''36'' (WM_GETMINMAXINFO) - but I belive that this is just beacource the first message after WM_NCCREATE...

/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
/Please excuse my bad spelling - My native language is binary not english|Visit meTake my advice - I don''t use it...
Well, two problems then: WM_GETMINMAXINFO is processed _BEFORE_ WM_NCCREATE. That''s why I''m really still thinking that it''s a problem with the pointer being NULL.

The order of messages I get is this:

WM_GETMINMAXINFO
WM_NCCREATE
WM_NCCALCSIZE
WM_CREATE

and in all of those messages, GetWindowLongPtr() returns NULL. Assuming all your code is correct, it can''t be functioning like you say it is.

If everything is how you''ve written it, you create your window. WM_GETMINMAXINFO is being processed and since it isn''t WM_NCCREATE, you just try to call GetWindowLongPtr() for a pointer to the instance of your class. The problem is that function returns NULL until after WM_CREATE. This means you''re trying to call a member function on a NULL pointer.

The way to fix this would be to add a test to see if your pointer is NULL after the GetWindowLongPtr() call. If so, just perform the default processing with DefWindowProc(). None of those messages are really all that important for normal operation and can pretty safely be omitted in an everyday window class. You can do most of your creation work on WM_CREATE, where you can use the lpParam parameter from CreateWindowEx() to pass your pointer to your class.


I''m 100% sure that this will fix your problem.
Well rigth you are :D

Turns out it's not enough to check if self == null I and since the LPCREATESTRUCT is not availible until WM_NCCREATE the solution turns out to be:

if (message == WM_GETMINMAXINFO)
return DefWindowProc(hwnd,message,wParam,lParam);

and then it works just fine :D

for any one who migth encounter similar problems in the future the static wndproc need to look linke this (or somthing verry similar)

    //in the glWindow.hstatic LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);//in glWindow.cppLRESULT CALLBACK glWindow::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){  glWindow *self = 0; //as oposed to 'this' ;)  if (message == WM_GETMINMAXINFO)   return DefWindowProc(hwnd,message,wParam,lParam);  if(message == WM_NCCREATE)  { // if the window is just beeing created we need to store window handle our self..     // don't ask - nobody seem to know why - except that it wont get set otherwise...    self = reinterpret_cast<glWindow *>(((LPCREATESTRUCT)lParam)->lpCreateParams);    SetWindowLong(hwnd, GWL_USERDATA, reinterpret_cast<long>(self));	// save window handle    self->hwnd=hwnd;  }  else    self = reinterpret_cast<glWindow *>(::GetWindowLong(hwnd, GWL_USERDATA));  //now call the real message handler!  if (self)    return self->glWndProc(hwnd, message, wParam, lParam);  else    return DefWindowProc(hwnd,message,wParam,lParam);}    


On a similar note:

when I drag the window it does not get updated, any one got a clue as to wich message I need to catch in order to be allowed to update?

(or can this only be acomplished by threads?)

/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''t use it...

[Edit]cant even cut & paste propperly these days :/[/Edit]

[edited by - guppy on July 15, 2002 3:18:49 PM]
/Please excuse my bad spelling - My native language is binary not english|Visit meTake my advice - I don''t use it...

This topic is closed to new replies.

Advertisement