🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Controls Class BC5 vs BC6

#7825
From: Elias Berelian
Date: Wed, 22 Dec 2004 17:32
152 lines
5596 bytes
I guess I was subclassing the main form.
I copied the idea from the following. Except in this case they are
subclassing a Memo.
What should I do to be able to accept files anywhere on the form?

El
-----------------------
  Coded Article:  Drag and drop files from Explorer
By: Damon Chandler
   The ease of use of an interface (GUI) is of utmost importance in today's
applications.
 Indeed, Windows itself is based upon the idea that the user should be able
to accomplish
 everyday chores without keyboard interaction.  I still remember the MS-DOS
days when
 copying a group of files took at least a dozen keystrokes, not accounting
for the
 backspaces due to typos.  Today, with the GUI of Windows, I can move a
group of files
 without even touching the keyboard.  Forget typos, they are a thing of the
past.

        This technology is called drag and drop, and it allows the user
freedom from the
 keyboard.  Windows has native support for drag and drop, unlike some other
operating
 systems.  Implementing this functionality for objects within your
applications is
 relatively simple since TControl has built in support for drag and drop.

  What about objects beyond your application?  You may be wondering how you
would call
 BeginDrag() for files on the desktop, for instance.  Luckily, Windows
performs most of
 the work for you.

       There are a couple ways to accomplish this: (1) Handling the
WM_DROPFILES message
 and (2) Using the OLE interface.  The examples below demonstrate dragging a
file from
 explorer to a TMemo control. The OLE interface can be extended to handle
many more data
 types than just files.  For example, you can drag a section of text or even
a bitmap into
 your application.






(1) Handling the WM_DROPFILES message:

If a window is registered as a drop site, it will receive the WM_DROPFILES
message when
 the user is dragging a file within its bounds.  This message is sent to the
control
 itself, not the Form or Parent of the control.  Therefore, to get
notification of the
 WM_DROPFILES message, you'll have to subclass the Memo control, and look
for the message
 in the subclass procedure.  In the message handler, call the
DragQueryFile() function to
 extract the filename and number of files.  In this case, we'll accept only
one file at a
 time...



 //in header...
   Controls::TWndMethod OldMemoWP;
   void __fastcall NewMemoWP(TMessage &Msg);







 //in source...
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    // turn on file d&d for the TreeView
    DragAcceptFiles(Memo1->Handle, true);
    // subclass the Memo
    OldMemoWP = Memo1->WindowProc;
    Memo1->WindowProc = NewMemoWP;
}

void __fastcall TForm1::NewMemoWP(TMessage &Msg)
{
   if (Msg.Msg == WM_DROPFILES)
    {
       // find the number of files dropped
       int num_files = DragQueryFile((HDROP)Msg.WParam, 0xFFFFFFFF,
                                      (LPSTR)NULL, NULL);

       // only accept one file at a time
       if (num_files != 1)
       {
            ShowMessage("too many files!");
            Msg.Result = 0;
           return;
       }

       // find the length of the filename
       int NameLength = DragQueryFile((HDROP)Msg.WParam, 0,
                                       NULL, NULL) + 1;

       // get the filename
       char *FileName = new char[NameLength];
       DragQueryFile((HDROP)Msg.WParam, 0, FileName, NameLength);

       // load the file
       Memo1->Lines->LoadFromFile(FileName);

       delete [] FileName;

       DragFinish((HDROP)Msg.WParam);
       Msg.Result = 0;
       return;
    }

    OldMemoWP(Msg);
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    // restore the original window procedure
    Memo1->WindowProc = OldMemoWP;
}
-----------------------
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41c36850$1@newsgroups.borland.com...
>
> "El" <elias.berelian@snet.net> wrote in message
> news:41c35862$1@newsgroups.borland.com...
>
> > I didn't understand the bit about subClass. I used the Controls class
> > as you had pointed it to me several months ago. I had not created
> > any subclasses of my own.
>
> You are subclassing someone's WindowProc property.  Whose are you
> subclassing?  Your code suggests that you having the caller subclass its
own
> WindowProc.  If that is the case, then you should never do that.
>
>
> Gambit
>
>
Technical Details
Message-ID: <41c9af28@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41c31afb$1@newsgroups.borland.com> <41c35862$1@newsgroups.borland.com> <41c36850$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,a08d779203a41a49
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Elias Berelian" <eliasb@voyager.snetnsa.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41c31afb$1@newsgroups.borland.com> <41c35862$1@newsgroups.borland.com> <41c36850$1@newsgroups.borland.com>
Subject: Re: Controls Class BC5 vs BC6
Date: Wed, 22 Dec 2004 12:32:05 -0500
Lines: 154
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 204.60.2.28
Message-ID: <41c9af28@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1103736616 204.60.2.28 (22 Dec 2004 09:30:16 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail