Sign in to follow this  

Window::WNDPROC?

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

This topic is 4729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this