Window::WNDPROC?

Started by
4 comments, last by pex22 19 years, 3 months ago
how can i use a WndProc from a class (for use in WNDCLASSEX)? i have tried to use a static (global) SWndProc and it will return ActiveWindow->WndProc() (ActiveWindow is the current active Window class) but it doesn't seems to work. SWndProc:
static LRESULT CALLBACK SWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
    {
	case WM_SYSCOMMAND:
	case WM_PAINT:
    case WM_CLOSE:
    case WM_DESTROY:
		break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
	if (&ActiveWindow)
		return ActiveWindow->WndProc(hwnd,msg,wParam,lParam);
	return 0;
}
RegisterClassEx:
	wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = SWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = title.c_str();
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
	if (!RegisterClassEx(&wc))
	{
		r=0;
		goto RETURN;
	}
and i get an access violation and error code 2(GetLastError(), 2 means: "The system cannot find the file specified.")..its probably because SWndProc. i remember that in past, i changed many things (in switch(msg)) and i didnt get access violation.. how can i handle more than one WndProc for using multiple windows and each window will have a different 'main loop', or it is done in an other way? thanks, pex.
pex.
Advertisement
I don't think you can. The way it is set up, it cannot be part of a class or structure. (I could be wrong, so lets see what others have to say [smile]).
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
using WndProc inside the window creation function doesn't work because it is a part of a class, so you right about that.
but why SWndProc doesn't work, i dont understand.
am i just wasting time at this and it is not important?
pex.
Two recent threads on the topic (I mean yesterday and last week recent, in addition to the dozens that have come before):
Win32 Wrapper WOES
[win32 c++] Creating a window using a class, not working

Also, an article on the topic, by yours truly:
Creating a Win32 Window Wrapper Class (might be overkill for your purposes).
You only have one main loop in your program. However, each window / dialog box has it's own callback procedure. An example can be found in this topic.

If you want to know how to create a class wrapper then try here or here.

[Edit: Fixed one of your links.]

C++ is a mixed paradigm language - do you need to have the callback procedures encapsulated in a class?


HTH,
Jim.

Edit : beaten again...

[Edited by - Oluseyi on December 30, 2004 11:15:01 AM]
hmm..i get a bit confused. sorry, i haven't seen the previous threads on this topic (i didnt knew its called wrapper class. it means i dont know what im coding. ahh!).
thanks guys!
pex.

This topic is closed to new replies.

Advertisement