Drag and Drop Listbox Items Without OLE

This listbox class demonstrates how to rearrange listbox items using Drag and Drop without the overhead of OLE. (If you are trying to drag items from one ListBox to another, refer to the OLE verion of this article.)

MFC has a CDragListBox that virtually does the same thing. The advantage of this class over MFC's CDragListBox is that it allows the user to insert the item at the end of the list, whereas CDragListBox does not. The concept is very simple: Keep track of the item that is being dragged, indicate where the drop will be when the user is dragging the item around, and finally, insert the item in its new location once the user releases the mouse button.

To accomplish this task, you will need to catch three messages for your listbox window: WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_LBUTTONUP. The WM_LBUTTONDOWN handler method simply initializes the drag and drop process by finding the item that the user clicked on.

Next, the WM_LBUTTONUP message handler will do the actual drop operation. It first checks to make sure that there was a item being dragged to begin with. Next, it checks to make sure that the button was released within the listbox window. If it wasn't, there is nothing to do. If, on the other hand, it was released within the window, simply insert the item into the listbox at the index indicated by the WM_MOUSEMOVE handler.

About the Author

Ali Rafiee

Ali Rafiee has been developing windows applications for the past 14 years using Visual C++, and he hasn't looked back since. Ali has been a software development consultant for must of his career, but he has finally settled down and has been working for an educational software company for the past 7 years. While he is not working, he is either learning C#, flying airplanes, playing with his daughter, or answering peoples question on newsgroups, he finds that to be a great learning tool for him (He is always trying to learn something new).

In the summer in a pane backing bowels the imperturbable sprite seems to be a decorous fitting, but if the sprite "feet"? Inclination also fork out you a trip, take a invigorating!
This summer, Nike and Sprite [url=http://northernroofing.co.uk/roofins.cfm]nike free run uk[/url]
and his sneakers to a graduate of exemplary snow spread of unripened, drained and downcast color blueprint in the definitive Nike Superciliousness Max 1 shoes reveal a refreshing chill scent.[url=http://markwarren.org.uk/property-waet.cfm]air max 90 uk[/url]
Summer is the yet to choice a cleanly shoe, shoes should be a good choice.
Qualifying series Nike Publicize Max HomeTurf metropolis recently lastly comes up, this series in the first-rate Melody Max shoes to London, Paris and Milan the three paid glorification to the iconic city of Europe, combined with the characteristics of the three cities, Feeling Max 1 HYP,Allied Max 90 HYP,Superciliousness Max 1 and shoes such as Air Max 95, combined [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache free[/url]
with the Hyperfuse, as kindly as a variety of materials, such as suede, Whether you crave functional or retro-everything.

Re: Fatal error

Posted by AliRafiee
on 01/23/2008 02:40am

Stdafx.h is the header file used for precompiled headers. My sample project is a visual c++ 2003 project. If you want to port it to 6.0 the easiest thing would be to create a new MFC project, and then add .cpp .h and .rc files from my project to that project. It is a little tricky with the rc file. You might want to simply copy and paste the code for the dialog box from the sample projects rc file to your rc file instead of copying the entire file.

Top White Papers and Webcasts

Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT
The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility.
Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

On-demand Event
Event Date: February 12, 2015
The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …