generic window class

generic window class

Post by Trevor Balco » Wed, 23 May 2001 06:42:28



I've been wondering about this for a while how do I make the WindowProc in
my class so it can access all the protected class members ? As of now I just
have the function outside of the class like so

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam);

class Window
{
public:
...
bool Create(...);
...
protected:
HWND m_hwnd;
...

Quote:};

Then in the constructor I register the WNDCLASSEX etc but if I put the
WindowProc function inside of my class it is passing a "this->WindowProc"
and it expects a "WNDPROC" type. I am aware if i make it a static function
then it can access ONLY STATIC members and functions and it removes the
this-> associated with it but I dont want everything to be static! Has
anyone written a simple bare-bones window class like this ? I know MFC is
available and im reinventing the wheel but I think most of the stuff in MFC
is not needed anyways and im looking for complete customization.
 
 
 

generic window class

Post by Jussi Jumppane » Wed, 23 May 2001 07:35:32



> I've been wondering about this for a while how do I make the WindowProc in
> my class so it can access all the protected class members ?
> ..
> .. [snip]
> ..
> Then in the constructor I register the WNDCLASSEX etc but if I put the
> WindowProc function inside of my class it is passing a "this->WindowProc"
> and it expects a "WNDPROC" type. I am aware if i make it a static function
> then it can access ONLY STATIC members and functions and it removes the
> this-> associated with it but I dont want everything to be static! Has
> anyone written a simple bare-bones window class like this ?

All you need to do is store the 'this' against the hwnd. In my case
I use the GWL_USERDATA pointer to hold the 'this' pointer. But there
are several ways to store the this pointer against the hwnd (ie link
list, maps etc etc).

Quote:> I know MFC is
> available and im reinventing the wheel but I think most of the stuff in MFC
> is not needed anyways and im looking for complete customization.

I dumped MFC a long time ago and the bug count has never been lower :)

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
"The C/C++, Java, HTML, Pascal, Cobol, Fortran programmers text editor"
Home Page: http://www.zeusedit.com

 
 
 

generic window class

Post by Aaron Robinso » Wed, 23 May 2001 08:02:58


jussi, have you ever done dockable windows in a non-mfc app?

i read that you don't use MFC, and i just had to ask...i can't find any help
anywhere.



> > I've been wondering about this for a while how do I make the WindowProc
in
> > my class so it can access all the protected class members ?
> > ..
> > .. [snip]
> > ..
> > Then in the constructor I register the WNDCLASSEX etc but if I put the
> > WindowProc function inside of my class it is passing a
"this->WindowProc"
> > and it expects a "WNDPROC" type. I am aware if i make it a static
function
> > then it can access ONLY STATIC members and functions and it removes the
> > this-> associated with it but I dont want everything to be static! Has
> > anyone written a simple bare-bones window class like this ?

> All you need to do is store the 'this' against the hwnd. In my case
> I use the GWL_USERDATA pointer to hold the 'this' pointer. But there
> are several ways to store the this pointer against the hwnd (ie link
> list, maps etc etc).

> > I know MFC is
> > available and im reinventing the wheel but I think most of the stuff in
MFC
> > is not needed anyways and im looking for complete customization.

> I dumped MFC a long time ago and the bug count has never been lower :)

> Jussi Jumppanen
> Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
> "The C/C++, Java, HTML, Pascal, Cobol, Fortran programmers text editor"
> Home Page: http://www.zeusedit.com

 
 
 

generic window class

Post by Trevor Balco » Wed, 23 May 2001 07:56:55


Thanks for the response, It sounds good but how would I implement it ? I've
never dealt with this before.



> > I've been wondering about this for a while how do I make the WindowProc
in
> > my class so it can access all the protected class members ?
> > ..
> > .. [snip]
> > ..
> > Then in the constructor I register the WNDCLASSEX etc but if I put the
> > WindowProc function inside of my class it is passing a
"this->WindowProc"
> > and it expects a "WNDPROC" type. I am aware if i make it a static
function
> > then it can access ONLY STATIC members and functions and it removes the
> > this-> associated with it but I dont want everything to be static! Has
> > anyone written a simple bare-bones window class like this ?

> All you need to do is store the 'this' against the hwnd. In my case
> I use the GWL_USERDATA pointer to hold the 'this' pointer. But there
> are several ways to store the this pointer against the hwnd (ie link
> list, maps etc etc).

> > I know MFC is
> > available and im reinventing the wheel but I think most of the stuff in
MFC
> > is not needed anyways and im looking for complete customization.

> I dumped MFC a long time ago and the bug count has never been lower :)

> Jussi Jumppanen
> Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
> "The C/C++, Java, HTML, Pascal, Cobol, Fortran programmers text editor"
> Home Page: http://www.zeusedit.com

 
 
 

generic window class

Post by Alex Blekhma » Wed, 23 May 2001 15:11:01



Quote:> I've been wondering about this for a while how do I make the
WindowProc in
> my class so it can access all the protected class members ? As of
now I just
> have the function outside of the class like so

> LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM
> lParam);

> class Window
> {
> public:
> ...
> bool Create(...);
> ...
> protected:
> HWND m_hwnd;
> ...
> };

> Then in the constructor I register the WNDCLASSEX etc but if I put
the
> WindowProc function inside of my class it is passing a
"this->WindowProc"
> and it expects a "WNDPROC" type. I am aware if i make it a static
function
> then it can access ONLY STATIC members and functions and it removes
the
> this-> associated with it but I dont want everything to be static!
Has
> anyone written a simple bare-bones window class like this ? I know
MFC is
> available and im reinventing the wheel but I think most of the stuff
in MFC
> is not needed anyways and im looking for complete customization.

You already did a half of the way. Both window and dialog allow to
pass LPARAM parameter at creation time. You can use this parameter to
pass 'this' pointer. Also, add to window class a member function that
mimics winproc parameters. From inside static routine call this
function via saved 'this' pointer and pass all messages parameters. It
can look like this for dialog:

class X {
public:
    static INT_PTR CALLBACK DialogProc(HWND hwndDlg,
        UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
    INT_PTR RealWorker(HWND hwndDlg,
        UINT uMsg, WPARAM wParam, LPARAM lParam);

    int m_SomeData;

Quote:};

INT_PTR CALLBACK X::DialogProc(HWND hwndDlg,
    UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static X* pseudoThis = NULL;
    if(WM_INITDIALOG == uMsg)
        pseudoThis = (X*)lParam;

    // you can access class members from this func
    return pseudoThis->RealWorker(hwndDlg,
                        uMsg, wParam, lParam);

Quote:}

INT_PTR X::RealWorker(HWND hwndDlg,
    UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    // handle messages
    }

    m_SomeData = 1; // accessing any class member

Quote:}

int main()
{
    // ....
    X x;
    DialogBoxParam(g_hInst, "resourcename", hwnd,
        X::DialogProc, (LPARAM)&x);

    // ...
    return 0;

- Show quoted text -

Quote:}

 
 
 

generic window class

Post by Jussi Jumppane » Thu, 24 May 2001 07:50:26



> Thanks for the response, It sounds good but how would I implement
> it ? I've never dealt with this before.

Taking the example that Alex Blekhman posted I would change it to
do somehting like this:

class X {
public:
    static INT_PTR CALLBACK DialogProc(HWND hwndDlg,
        UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
    INT_PTR RealWorker(HWND hwndDlg,
        UINT uMsg, WPARAM wParam, LPARAM lParam);

    int m_SomeData;

Quote:};

INT_PTR CALLBACK X::DialogProc(HWND hwndDlg,
    UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    X* pseudoThis = NULL;

    // for windows trap the WM_CREATE message and
    // use CreateWindow to pass the this pointer
    if (WM_INITDIALOG == uMsg)
    {
        pseudoThis = (X*)lParam;

        SetWindowLong(hwndDlg, GWL_USERDATA, pseudoThis);      
    }
    else
    {
        pseudoThis = (X*)GetWindowLong(hwndDlg, GWL_USERDATA);  
    }

    if (pseudoThis)
    {
      return pseudoThis->RealWorker(hwndDlg,uMsg, wParam, lParam);
    }
    else
    {
      DefWindowProc(hwndDlg,uMsg, wParam, lParam);
    }

Quote:}

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
"The C/C++, Java, HTML, Pascal, Cobol, Fortran programmers text editor"
Home Page: http://www.zeusedit.com
 
 
 

generic window class

Post by Jussi Jumppane » Thu, 24 May 2001 07:55:55



> jussi, have you ever done dockable windows in a non-mfc app?

> i read that you don't use MFC, and i just had to ask...i can't
> find any help anywhere.

The one thing that MFC is good for is lots of fancy features
like dockable windows split windows etc etc that you get for
free.

I have never tried or wanted to implemented dockable windows
but if I was to I would start by looking at the MFC code. The
code tells you which Win32 calls you will need to used to code
the feature. Once you have the names of the API's just learn
about these API's then design a solution then code it.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
"The C/C++, Java, HTML, Pascal, Cobol, Fortran programmers text editor"
Home Page: http://www.zeusedit.com

 
 
 

generic window class

Post by rz » Mon, 28 May 2001 04:50:12


Small addendum to the other notes: If you really want your "generic"
function to allow access to _all_ protected class members, then I think you
need to declare the function a friend of the class.

--
-----------------------------------------
To reply to me, remove the underscores (_) from my email address.

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com


Quote:>I've been wondering about this for a while how do I make the WindowProc in
>my class so it can access all the protected class members ? As of now I
just
>have the function outside of the class like so

>LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
>lParam);

>class Window
>{
>public:
>...
>bool Create(...);
>...
>protected:
>HWND m_hwnd;
>...
>};

>Then in the constructor I register the WNDCLASSEX etc but if I put the
>WindowProc function inside of my class it is passing a "this->WindowProc"
>and it expects a "WNDPROC" type. I am aware if i make it a static function
>then it can access ONLY STATIC members and functions and it removes the
>this-> associated with it but I dont want everything to be static! Has
>anyone written a simple bare-bones window class like this ? I know MFC is
>available and im reinventing the wheel but I think most of the stuff in MFC
>is not needed anyways and im looking for complete customization.

 
 
 

1. ActiveX problem,,Derving from as generic class

Hi all,

     My namwe is Rajesh. I am new to ActiveX
programming,please help me.
    When am deriving a control class from a generic class ,
my server app. is crashing while running!.,I need to get
like the follwoeing,

class CMMControlCtrl :public COleControl,public CPipe
{
        DECLARE_DYNCREATE(CMMControlCtrl)

// Constructor
public:
where CPipe is a generic class!

Cam any body give me a clue.>>

Rajesh

2. how to: SelectNodes like G%

3. ANSWER: Generic Dialog Centering Class for OWL

4. Cyrillic fonts and Mosaic?

5. looking for a generic table/array class (MFC)

6. ? Hibernation Automation

7. Window Class #37220 (Checking a window for this class)

8. benchmarking

9. a CFifo generic class ?

10. Generic pointer to class method ( without template possibly)

11. Question about classes and generic functions...

12. Newbie to C++....Question about classes and generic functions...

13. Generic Date Class