473,770 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(H WND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(h wnd, message, wParam, lParam);
}

But at certain point this static wndproc should be switched to the
BaseWindow::Wnd Proc 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(HWN D hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__ v2 );
return DefWindowProc(h wnd, 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
6 6634
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******** ********@newsre ad4.news.pas.ea rthlink.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(H WND hwnd, UINT message, WPARAM
wParam, LPARAM lParam)
{
return DefWindowProc(h wnd, message, wParam, lParam);
}

But at certain point this static wndproc should be switched to the
BaseWindow::Wnd Proc 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(HWN D hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SetWindowLong( hWnd, GWL_USERDATA, (long) g_window_ptr );
SetWindowLong( hWnd, GWL_WNDPROC, (long) StaticWndProc__ v2 );
return DefWindowProc(h wnd, 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
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
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
"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
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.program mer.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.program mer.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
> 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::Ini t() {
HWND hWnd = CreateWindow();
... <- manupulate with the map
}

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

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1464
by: Leonard J. Reder | last post by:
Hello, Although posted this a few weeks ago I still have gotten much feedback so I want to put this out again and see if the response gets a bit more interesting. I have been searching on the web for a while now for a specific Python implementation of an FSM. More specifically what I am looking for is a Python implementation of the so called UML Harel State Machine notion of a state machine. These are multi-threaded capable state
3
267
by: kirk g | last post by:
When I run the following code: OleDbConnection conn = new OleDbConnection( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\moneymakin.mdb"); String stmt = "INSERT INTO Person (FirstName, LastName, Email, LoginID, Password) VALUES (" + "'" + this.m_perFirstName + "', '" + this.m_perLastName +
6
3622
by: Turbo_King | last post by:
Hi, I am trying to write a class which creates a window and then assigns a method of the class as the wndproc function for the window so that each instance of the class can handle the messages for its repective form. I am trying to do the following: class myWinClass {
1
1786
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group members. It works fine on W2k - machines. It works on a WinNT 4 - server, too, but it stops with a runtime error on any Windows 4.0 Workstation. The error is: System.Runtime.InteropServices.COMException 0x800500F. at...
0
1624
by: Tom Shelton | last post by:
This is a simple example of a numeric only text box. It allows only the entry of integer values. The advantage of this example is that it also handles user attempts to past non integer text data into the text box... Option Strict On Option Explicit On Imports System Imports System.Windows.Forms Imports System.ComponentModel
13
3114
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those sorts of clients. Mine are all small businesses whose sites will never reach those sorts of scales. I deal with businesses whose sites get maybe a few hundred visitors per day (some not even that much) and get no more than ten orders per day....
176
8463
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write their own unit test framework, and then in a lab session see if I can get them to write their own. To give them an example I've created the following UTF class (with a simple test program following). I would welcome and suggestions on how anybody...
4
4261
by: Tony M | last post by:
VS 2005 - XP media - VB .net - winforms - .net 2.0 Just trying to send an email, here is the code and the error message that I get. I can't figure out how to fix it?
30
3545
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.