Click to See Complete Forum and Search --> : Callback procs in a class


Quell
September 25th, 2005, 05:51 PM
Hello.
I am initializing a WNDCLASS variable using a callback proc that is in a class ....here is some related code:

WNDCLASS wc; // Windows Class Structure
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "Test"; // Set The Class Name

I get an erro at wndProc...where it is defined as such in my class:"

//definitions
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//initialization
LRESULT CALLBACK CFrame::WndProc( HWND hWnd,UINT uMsg,WPARAM wParam, LPARAM lParam)

i get an erro that the types are not compatable and i can;t use it like that.....any way to get it working using this function inside of a class?
Thx Alo.t

Calculator
September 25th, 2005, 06:12 PM
This article shares your pains, but has the solution! A static member function allows you to do this, it removes the associated this pointer with the function, making it independent of a class object, and so that it will then fit into the constrints of the WNDCLASSEX function pointer ;) Here's the link that has more info:
http://www.codeproject.com/win32/win32windowwrapperclass.asp

Quell
September 28th, 2005, 03:40 PM
a little late with the response, i was too busy coding using ur tip:D
thx alot man, great help, i got it worked out now.

Calculator
September 28th, 2005, 09:15 PM
This topic is also covered in the FAQ I discovered.
Q: How to use class member functions as callbacks? (http://www.codeguru.com/forum/showthread.php?t=312457)