TLISTVIEW Used - Drag and Wave

zhaozj2021-02-16  51

The following procedure is a small process written according to the user's operation in the software development process, mainly to drag and drop file function to the listView control, and its source code is as follows:

procedure tyanzheng.AppMessage (var Msg: TMsg; var Handled: Boolean); varnFiles, I: Integer; ListItem: TListItem; beginif (Msg.message = WM_DROPFILES) and (msg.hwnd = ListView1.Handle) thenbeginif MessageDlg ( 'OK to Add? ', MTConfirmation, [mbyes, mbno], 0) = mryes dam // N amounts of Dropped Files NFILES: = DragQueryFile (msg.wparam, $ fffffff, nil, 0); // Take each drag Full file name of the file Tryfor i: = 0 to nfiles - 1 dobegin // Assign allocate memorysetLength (filename, 80) for file name; // Take the file name read the file namedragQueryFile (Msg.WParam, i, pchar (filename), 80); filename: = pChar (filename); // Put the full file name breakfast file name and path ListItem: = listView1.Items.add; ListItem.caption: = extractFileName (FileName); ListItem.ImageIndex: = 6; ListItem.Subitems .Add (extractfilepath (filename)); filepath: = extractFilePath (filename); // Drage: = true; end; finally // End this drag and drop operation Dragfinish (msg.wparam); end; // identifier has been processed This message Handled: = true; movefile (pchar (filename), pchar (filesis)); end; end; end; Note: This program function is complete, the program is used in the program, that is, Implementing the files to the operation to the directory where the system is located, it is recommended not to use important files during debugging. .

The program is used to send messages to Windows. If you don't understand, it is recommended to look at some articles (this program can be run directly, you must join the system), this program is used in combination with "TListView display folder content, effect better"

The program is used in the showForm event: Usage is as follows:

// Setup Need to Process File WM_DropFiles Drag and drop message DragAcceptFiles (ListView1.Handle, True); // Set the appMessage process to capture all messages Application.onMessage: = AppMessage;

Thank you for supporting

转载请注明原文地址:https://www.9cbs.com/read-24671.html

New Post(0)