By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

Looking for a simple and interesting implementation of Windows' WndProc in C++ classes

P: n/a
Hi:

I've searched newsgroups and various archives, including MSDN & MFC sources,
but at this point failed to locate an accurate and simple implementation of
WndProc function for MSWindows window objects.
Something like:

class BaseWindow {
virtual LRESULT WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam);
virtual OnPaint();
};

Then I would create a window pointing to a static StaticWndProc

static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}

But at certain point this static wndproc should be switched to the
BaseWindow::WndProc or gain access to the instance of the BaseWindow object
somehow. What is the simplest technique to make it happen?

So far, I figured only a way to throw an exclusive global pointer of this to
GWL_USERDATA and retrieve the object instance from it within every event
thrown to the static window procedure.

BaseWindow* g_window_ptr;
static LRESULT CALLBACK InitWndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__v2 );
return DefWindowProc(hwnd, message, wParam, lParam);
}

static LRESULT CALLBACK StaticWndProc__v2(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
BaseWindow* l_window_ptr = (BaseWindow *) GetWindowLong( hWnd,
GWL_USERDATA );
return l_window_ptr->WndProc(hwnd, message, wParam, lParam);
}

What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?

Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Check http://www.codeproject.com/system/chotkeyhandler.asp
It got an implementation of WndProc inside a C++ class.

--
Elias
"Beach Potato" <do***************************@yahoo.com> wrote in message
news:i8****************@newsread4.news.pas.earthli nk.net...
Hi:

I've searched newsgroups and various archives, including MSDN & MFC sources, but at this point failed to locate an accurate and simple implementation of WndProc function for MSWindows window objects.
Something like:

class BaseWindow {
virtual LRESULT WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam);
virtual OnPaint();
};

Then I would create a window pointing to a static StaticWndProc

static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, message, wParam, lParam);
}

But at certain point this static wndproc should be switched to the
BaseWindow::WndProc or gain access to the instance of the BaseWindow object somehow. What is the simplest technique to make it happen?

So far, I figured only a way to throw an exclusive global pointer of this to GWL_USERDATA and retrieve the object instance from it within every event
thrown to the static window procedure.

BaseWindow* g_window_ptr;
static LRESULT CALLBACK InitWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__v2 );
return DefWindowProc(hwnd, message, wParam, lParam);
}

static LRESULT CALLBACK StaticWndProc__v2(HWND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
BaseWindow* l_window_ptr = (BaseWindow *) GetWindowLong( hWnd,
GWL_USERDATA );
return l_window_ptr->WndProc(hwnd, message, wParam, lParam);
}

What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?

Jul 19 '05 #2

P: n/a
WW
Beach Potato wrote:
Hi:

I've searched newsgroups and various archives, including MSDN & MFC
sources, but at this point failed to locate an accurate and simple


This group is for the standard C++ languge and not Windows programming.
Please read this for pointers:

http://www.slack.net/~shiva/welcome.txt

--
WW aka Attila
Jul 19 '05 #3

P: n/a
WW
lallous wrote:
Check http://www.codeproject.com/system/chotkeyhandler.asp
It got an implementation of WndProc inside a C++ class.


Stop posting off-topic to comp.lang.c++ and stop top-posting please:

http://www.slack.net/~shiva/welcome.txt

http://www.slack.net/~shiva/offtopic.txt

http://www.parashift.com/c++-faq-lit...t.html#faq-5.4

Thanks

--
WW aka Attila
Jul 19 '05 #4

P: n/a
"Beach Potato" <do***************************@yahoo.com> wrote
So far, I figured only a way to throw an exclusive global pointer of this to
GWL_USERDATA and retrieve the object instance from it within every event
thrown to the static window procedure. [...] What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?


One other way is to use a global 'std::map <HWND, BaseWindow*>'.

Regards,
Buster.
Jul 19 '05 #5

P: n/a
On Sun, 21 Sep 2003 21:56:30 GMT, "Beach Potato" <do***************************@yahoo.com> wrote:
...
What other simple ways do you use to build windows classes, inheriting
WndProc and event handlers?


As Attila Fehler wrote, this question is _off-topic_ in clc++.

Try to ask in [comp.os.ms-windows.programmer.win32], and please do read
Shiva's welcome-message as well as the FAQ before posting more in clc++.

This response has been crossposted to [comp.os.ms-windows.programmer.win32],
with follow-ups set there (that means if you answer, your answer will by
default be submitted to that group).

Hth.,

- Alf

Jul 19 '05 #6

P: n/a
> One other way is to use a global 'std::map <HWND, BaseWindow*>'.

The question is at what point and where I'd tie these two together.
CreateWindow throws a bunch of calls, like WM_NCCREATE, WM_CREATE before
releasing the handle to the caller.
So if I do:

void BaseWindow::Init() {
HWND hWnd = CreateWindow();
... <- manupulate with the map
}

it may be too late, and I'll miss the events.

Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.