Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag and drop files 1

Status
Not open for further replies.

computerwhiz

Programmer
May 1, 2002
28
US
I cannot figure out what I am doing wrong. I cannot get my program to pull the file name from the dropped files structure. I am using dev-cpp and I am getting the error:

97 C:\WINDOWS\Desktop\mysourceC++\main.cpp
invalid conversion from `void*' to `HDROP__*'

msdn.com says this is the way to attain the structure. I am confused. help please.

Code:
    case WM_DROPFILES:
    {
      HDROP hDrop;
      hDrop = (HANDLE) wParam;
      LPTSTR  lpszFile;
      DragQueryFile(
      hDrop,	// handle of structure for dropped files
      0,	// index of file to query
      lpszFile,	// buffer for returned filename
      sizeof(lpszFile) 	// size of buffer for filename
      );
      SetWindowText(GetDlgItem(hwnd, IDC_MAIN_TEXT), lpszFile);
      DragFinish(hDrop);
      break;
    }
 
> hDrop = (HANDLE) wParam;
Perhaps

hDrop = (HDROP) wParam;

--
 
You might also want to provide a real buffer for the third argument to DragQueryFile(), not just an uninitialized pointer to one.

Also, [tt]sizeof (lpszFile)[/tt] returns the size of the pointer, which is 4 on 32-bit Windows. I'm guessing what you really meant was the size of your real buffer.
 
This is a fully working WndProc for DragDrop files
Code:
#include<windows.h>
#include<strstream>
using std::strstream;
using std::endl;
using std::ends;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDROP hDrop;
	POINT pt;
	int cnt;
	char fileName[512];
	char szWndCaption[512];
	strstream names;
	switch(message)
	{
	case WM_CREATE:
		DragAcceptFiles(hWnd, TRUE);
		break;
	case WM_DROPFILES:
		
		hDrop = (HDROP) wParam;
		DragQueryPoint(hDrop, &pt);
		sprintf(szWndCaption, "files dropped at the x = %d; y =  %d;", pt.x, pt.y);
		cnt = DragQueryFile(hDrop, 0xFFFFFFFF, 0, 0);
		names<<"files count = "<< cnt<< ";"<< endl;
		{
			for(int i = 0; i < cnt; i++)
			{
				DragQueryFileA(hDrop, i, fileName, 512);
				names<< "file "<< (i + 1)<< ": " << fileName<< endl;
			}
		}
		names<< ends;
		MessageBoxA(0, names.str(), szWndCaption, 0);
		DragFinish(hDrop);

		break;
	case WM_DESTROY:
		PostQuitMessage(0);
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top