🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3792

Re: WM_MOUSEMOVE

#3792
From: Remy Lebeau (TeamB)
Date: Mon, 24 Apr 2006 18:57
156 lines
5974 bytes
"JD" <nospam@nospam.com> wrote in message
news:444a0026$1@newsgroups.borland.com...

> Minimal sample:

Just an FYI, since you are now using a descendant class to manage the
subclassing, you can do so much more efficiently by not intercepting the
CM_RECREATEWND message at all.  Use the virtual CreateWnd() and DestroyWnd()
methods instead.  For example:


    --- Unit1.cpp ---

    #include "MyListView.h"

    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
        TMyListView *lv = new TMyListView(this);
        lv->Parent = this;
        lv->Align = alClient;

        TListColumn *pColumn;
        for(int x = 0; x < 3; ++x)
        {
            pColumn = lv->Columns->Add();
            pColumn->Caption = "Column " + IntToStr(x);
            pColumn->Width = (lv->Width - 20) / 3;
        }

        TListItem *pItem;
        for(int x = 0; x < 3; ++x)
        {
            pItem = lv->Items->Add();
            pItem->Caption = "Col " + IntToStr(0) + ", Row " + IntToStr(x);
            for(int y = 0; y < lv->Columns->Count; ++y)
                pItem->SubItems->Add("Col " + IntToStr(y+1) + ", Row " +
IntToStr(x));
        }
    }


    --- MyListView.h ---

    //--------------------------------------------------------------
    #ifndef MyListViewH
    #define MyListViewH
    //--------------------------------------------------------------
    #include <Classes.hpp>
    #include <ComCtrls.hpp>
    //--------------------------------------------------------------
    #ifdef STRICT
    #define HEADERWNDPROC WNDPROC
    #else
    #define HEADERWNDPROC FARPROC
    #endif
    //--------------------------------------------------------------
    class TMyListView : public TListView
    {
        typedef TListView inherited;
    private:
        HWND hHeader;
        LONG HeaderWndProcPtr;
        HEADERWNDPROC OldHeaderWndProc;
        void  __fastcall HeaderWndProc(TMessage &Message);
    protected:
        virtual void __fastcall CreateWnd();
        virtual void __fastcall DestroyWnd();
        virtual void  __fastcall HeaderMouseMove(TShiftState Shift, int X,
int Y);
    public:
        __fastcall  TMyListView(TComponent* Owner);
        __fastcall ~TMyListView();
    };
    //--------------------------------------------------------------
    #endif

    //--------------------------------------------------------------
    #pragma hdrstop
    #include "MyListView.h"
    #include "shlwapi.h"
    #pragma package(smart_init)
    //--------------------------------------------------------------
    __fastcall TMyListView::TMyListView(TComponent* Owner)
        : TListView(Owner)
    {
        ShowColumnHeaders = true;
        ViewStyle = vsReport;
        HeaderWndProcPtr =
reinterpret_cast<LONG>(MakeObjectInstance(HeaderWndProc));
    }
    //--------------------------------------------------------------
    __fastcall TMyListView::~TMyListView()
    {
        FreeObjectInstance(reinterpret_cast<void*>(HeaderWndProcPtr));
    }
    //--------------------------------------------------------------
    void __fastcall TMyListView::CreateWnd()
    {
        inherited::CreateWnd();
        if( HandleAllocated() )
        {
            hHeader = ListView_GetHeader(Handle);
            if( hHeader )
                OldHeaderWndProc =
reinterpret_cast<HEADERWNDPROC>(::SetWindowLong(hHeader, GWL_WNDPROC,
HeaderWndProcPtr));
        }
    }
    //--------------------------------------------------------------
    void __fastcall TMyListView::DestroyWnd()
    {
        if( hHeader )
        {
            ::SetWindowLong(hHeader, GWL_WNDPROC,
reinterpret_cast<LONG>(OldHeaderWndProc));
            hHeader = NULL;
            OldHeaderWndProc = NULL;
        }
        inherited::DestroyWnd();
    }
    //--------------------------------------------------------------
    void __fastcall TMyListView::HeaderWndProc(TMessage &Message)
    {
        switch( Message.Msg )
        {
            case WM_MOUSEMOVE:
                HeaderMouseMove(KeysToShiftState(Message.WParam),
LOWORD(Message.LParam), HIWORD(Message.LParam));
                Message.Result = 0;
                break;
            case WM_DESTROY:
                ::SetWindowLong(hHeader, GWL_WNDPROC,
reinterpret_cast<LONG>(OldHeaderWndProc));
                Message.Result = ::CallWindowProc(OldHeaderWndProc, hHeader,
Message.Msg, Message.WParam, Message.LParam);
                hHeader = NULL;
                OldHeaderWndProc = NULL;
                break;
            default:
                Message.Result = ::CallWindowProc(OldHeaderWndProc, hHeader,
Message.Msg, Message.WParam, Message.LParam);
                break;
        }
    }
    //--------------------------------------------------------------
    void __fastcall TMyListView::HeaderMouseMove(TShiftState Shift, int X,
int Y)
    {
        //
    }
    //--------------------------------------------------------------


Gambit
Technical Details
Message-ID: <444d202d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <444a0026$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,75696ebf01497ced
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <444a0026$1@newsgroups.borland.com>
Subject: Re: WM_MOUSEMOVE
Date: Mon, 24 Apr 2006 11:57:19 -0700
Lines: 158
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <444d202d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1145905197 68.69.17.41 (24 Apr 2006 11:59:57 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail