Article View: comp.windows.ms.programmer
Article #2150Associating window handle with C++ object
From: Ron Burk
Date: Tue, 16 Apr 1991 15:36
Date: Tue, 16 Apr 1991 15:36
26 lines
1751 bytes
1751 bytes
Suppose you are creating a C++ class which corresponds to a Windows 3.0 window. Obviously, you will want to associate a Windows 3.0 window handle with the C++ window object. I would think the most natural way to do this would be: a) Allocate enough "extra" bytes to hold a pointer to "this" when you register your window class. b) Using a single window function for all windows. c) In your single window function, extract the "this" pointer and pass the window message on to the correct C++ window object. Unfortunately, CreateWindow() will send messages to the window before it returns the window handle, so the scheme just described doesn't quite work. In the "whello.cpp" that comes with Borland C++, they assume that any "extra" window bytes will be initialized to zero. When their Window constructor calls CreateWindow(), it passes "this" in the last parameter. In their single window function, they first extract the "this" pointer from the "extra" window bytes and if it is zero and the message is WM_PAINT, they get the "this" pointer from lParam->lpCreateParams and store it in the window "extra" bytes. How do other C++ classes associate the window handle with the C++ window object? Is it safe to assume that WM_PAINT is the first message received by any window created by CreateWindow()?
Technical Details
Message-ID:
<0J7H11w163w@burklabs>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ns.uoregon.edu!milton!sumax!polari!rwing!seaeast!burklabs!ronbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ns.uoregon.edu!milton!sumax!polari!rwing!seaeast!burklabs!ronb From: ronb@burklabs (Ron Burk ) Newsgroups: comp.windows.ms.programmer Subject: Associating window handle with C++ object Message-ID: <0J7H11w163w@burklabs> Date: 16 Apr 91 15:36:56 GMT Organization: Burk Labs, Redmond WA Lines: 26