Archived

This topic is now archived and is closed to further replies.

Smacker_626

Window Class

Recommended Posts

I need help with SetWindowLong() and GetWindowLong(). My Window Class Basically works, But in my WndProc Function when I try to Store or Retrieve the UserData from the Window it doesnt work, ive used GetLastError() with FormatMessage() to see what was wrong but it said "The operation completed succesfully". Can anyone tell me howto fix this? And also I would like to know why CWindow::Create() exits the program when i use throw CWindowException(string, __FILE__, __LINE__); it never even does the code in my catch block, it just closes the program. Any help would be appreciated. CWindow.h/CWindow.cpp/main.cpp are here - www.dragonruins.com/CWindow.h - www.dragonruins.com/CWindow.cpp - www.dragonruins.com/main.cpp BTW im using Dev-C++ (www.bloodshed.net) with Mingw/GCC 3.2, with Enable exception handling on in the Project Options

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i see 2 things wrong:

o your CreateWindow call does not have the class object''s this pointer passed as the last parm of that call - this means that the lpCreateParams value of the CREATESTRUCT that has it''s address passed as the LPARAM of the WM_NCCREATE message, won''t be a pointer to a CWindow object, but will instead be NULL

o your SetWindowLong call is testing the return value and assuming it should be returning a non-zero value, which is not the correct way to determine if an error occured for this function - from the docs,

"If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure. To deal with this, you should clear the last error information by callingSetLastError(0) before calling SetWindowLong. Then, function failure will be indicated by a return value of zero and a GetLastError result that is nonzero."

Share this post


Link to post
Share on other sites
Heh, Ive been copying code from other programs to try and get SetWindowLong() to work I guess I forgot to add "this" to CreateWindow() somewhere along the way.

Thanks alot, It works now

-EDIT: I took the files off of my site.

[edited by - smacker_626 on October 13, 2003 12:16:26 PM]

Share this post


Link to post
Share on other sites