YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ Code: Drag and Drop File in Dialog with WM_DROPFILES and WM_NCLBUTTONDOWN

 
 

Introduction

Here is a simple method to have a Drag and Drop feature in our dialog based applications. To provide Drag and Drop we have a windows Message Handler called WM_DROPFILES. Handle this message through ON_MESSAGE message map to capture the dropped files.

Message Handler

Collapse Copy Code
//
 BEGIN_MESSAGE_MAP(CComGuidFinderDlg, CDialog)
  //{{AFX_MSG_MAP(CComGuidFinderDlg)
  ON_WM_PAINT()
  ON_WM_LBUTTONDOWN()
  ON_MESSAGE(WM_DROPFILES,OnDropFiles)// Message Handler for Drang and Drop
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()
//

Now its time to handle the WM_DROPFILES messages through a user defined method. The function prototype should be like this

Collapse Copy Code
  LRESULT  OnDropFiles(WPARAM wParam,LPARAM lParam);

Finally we have a function to capture the drop events. The wParam is a handle to the HDROP structure describing the dropped files. To get the info about the dropped file i.e. the file name used :-

Collapse Copy Code
 DragQueryFile(hDrop,    // Struture Identifier
        -1,        // -1 to Drop more than one file or ( integer 0 to max )
                   // to drop selected No of files
        szDroppedFile,// Droped File Name
        MAX_PATH);   // Max char 

So now we did all possible coding in our dialog based application to handle Drag & Drop feature. But still it is handicapped. Handling the Drop event is not enough to ensure the Drag & Drop feature. We need to register our window to accept the dropped file using

Collapse Copy Code
  BOOL CComGuidFinderDlg::OnInitDialog()
  {
    ......
    .....
    DragAcceptFile(TRUE) // To Accept Dropped file Set this TRUE
  }

Good... That's all and we have done well!

I added one more feature in this sample i.e. Moving the our dialog by clicking on anywhere on the window. This can be do by posting WM_NCLBUTTONDOWN message to HTCAPTION Handle this statement in OnLButtonDownMessage(...)

Collapse Copy Code
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y))

 

 

 

Copyright ?1998-2022 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net