Drag and drop from Internet Explorer

This is a discussion on Drag and drop from Internet Explorer within the Windows Programming forums, part of the Platform Specific Boards category; I am wondering if someone could point me in the right direction. I want to drag and drop hyperlinks (.url ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    39

    Drag and drop from Internet Explorer

    I am wondering if someone could point me in the right direction. I want to drag and drop hyperlinks (.url files) from Internet Explorer to my application, but I can't get any part of my application to accept these files -- I only get a black circle with a line through it, which indicates that a drag drop operation cannot be performed.

    Can someone tell me what site(s) I can visit which will show me how to get a window to accept this operation, and which windows message(s) to process afterwards?

    Here is what I have tried, among other things...

    Using windows Spy++ I monitored Internet Explorer while dropping a hyperlink to its own ComboBox -- which, of course, accepts this operation. Here is what was recorded in the log file:

    <00001> 00000198 S WM_NCHITTEST xPos:207 yPos:133
    <00002> 00000198 R WM_NCHITTEST nHittest:HTCLIENT
    <00003> 00000198 S WM_SETCURSOR hwnd:00000198 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00004> 00000198 R WM_SETCURSOR fHaltProcessing:True
    <00005> 00000198 P WM_MOUSEMOVE fwKeys:0000 xPos:54 yPos:21
    <00006> 00000198 S WM_NCHITTEST xPos:329 yPos:133
    <00007> 00000198 R WM_NCHITTEST nHittest:HTCLIENT
    <00008> 00000198 S WM_NCHITTEST xPos:329 yPos:132
    <00009> 00000198 R WM_NCHITTEST nHittest:HTCLIENT
    <00010> 00000198 S WM_NCHITTEST xPos:329 yPos:131
    <00011> 00000198 R WM_NCHITTEST nHittest:HTCLIENT
    <00012> 00000198 S .CB_GETCOUNT
    <00013> 00000198 R .CB_GETCOUNT cItems:0
    <00014> 00000198 S .CB_RESETCONTENT
    <00015> 00000198 R .CB_RESETCONTENT lResult:0001
    <00016> 00000198 S .CB_GETCURSEL
    <00017> 00000198 R .CB_GETCURSEL index:CB_ERR
    <00018> 00000198 S .WM_GETFONT
    <00019> 00000198 R .WM_GETFONT hfont:00000400 ("MS Sans Serif" 8pt)
    <00020> 00000198 S ..CB_SETITEMHEIGHT index:-1 (the selection field) height:16
    <00021> 00000198 S ...WM_WINDOWPOSCHANGING lpwp:005874D6
    <00022> 00000198 R ...WM_WINDOWPOSCHANGING
    <00023> 00000198 R ..CB_SETITEMHEIGHT lResult:CB_OKAY
    <00024> 00000198 S ...WM_WINDOWPOSCHANGING lpwp:00587244
    <00025> 00000198 R ...WM_WINDOWPOSCHANGING
    <00026> 00000198 S ...WM_WINDOWPOSCHANGED lpwp:00587284
    <00027> 00000198 R ...WM_WINDOWPOSCHANGED
    <00028> 00000198 S ...WM_GETFONT
    <00029> 00000198 R ...WM_GETFONT hfont:00000400 ("MS Sans Serif" 8pt)
    <00030> 00000198 S ...WM_ERASEBKGND hdc:000005FE
    <00031> 00000198 R ...WM_ERASEBKGND fErased:True
    <00032> 00000198 S ...CB_SETDROPPEDWIDTH wWidth:200
    <00033> 00000198 R ...CB_SETDROPPEDWIDTH wWidth:488
    <00034> 00000198 S .CB_SETITEMHEIGHT index:0 height:16
    <00035> 00000198 R .CB_SETITEMHEIGHT lResult:CB_OKAY
    <00036> 00000198 S .WM_GETFONT
    <00037> 00000198 R .WM_GETFONT hfont:00000400 ("MS Sans Serif" 8pt)
    <00038> 00000198 S .CB_SETDROPPEDWIDTH wWidth:200
    <00039> 00000198 R .CB_SETDROPPEDWIDTH wWidth:488
    <00040> 00000198 S .CB_SETEXTENDEDUI fExtended:True
    <00041> 00000198 R .CB_SETEXTENDEDUI lResult:CB_OKAY
    <00042> 00000198 S ..WM_COMMAND wNotifyCode:EN_UPDATE wID:41477 hwndCtl:000001A0
    <00043> 00000198 R ..WM_COMMAND
    <00044> 00000198 S ..WM_COMMAND wNotifyCode:EN_CHANGE wID:41477 hwndCtl:000001A0
    <00045> 00000198 S ...CB_GETCURSEL
    <00046> 00000198 R ...CB_GETCURSEL index:CB_ERR
    <00047> 00000198 R ..WM_COMMAND
    <00048> 00000198 S .WM_SETCURSOR hwnd:000001A0 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00049> 00000198 R .WM_SETCURSOR fHaltProcessing:True
    <00050> 00000198 P WM_PAINT hdc:00000000
    <00051> 00000198 S WM_ERASEBKGND hdc:00000E36
    <00052> 00000198 R WM_ERASEBKGND fErased:True
    <00053> 00000198 S WM_CTLCOLOREDIT hdcEdit:00000E36 hwndEdit:000001A0
    <00054> 00000198 R WM_CTLCOLOREDIT hBrush:00000756
    <00055> 00000198 S WM_CTLCOLOREDIT hdcEdit:00000E36 hwndEdit:000001A0
    <00056> 00000198 R WM_CTLCOLOREDIT hBrush:00000756
    <00057> 00000198 S .WM_SETCURSOR hwnd:000001A0 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00058> 00000198 R .WM_SETCURSOR fHaltProcessing:True
    <00059> 00000198 S WM_NCHITTEST xPos:330 yPos:131
    <00060> 00000198 R WM_NCHITTEST nHittest:HTCLIENT
    <00061> 00000198 S WM_SETCURSOR hwnd:00000198 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
    <00062> 00000198 R WM_SETCURSOR fHaltProcessing:True
    <00063> 00000198 P WM_MOUSEMOVE fwKeys:0000 xPos:177 yPos:19

    This would be somewhat helpful if I could get my application's ComboBox to accept files dragged to it from Internet Explorer -- Yes, I tried WS_EX_ACCEPTFILES.

    Any suggestions???

    Thanks a lot

    Echidna

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Enjoy!!!

    Code:
    #include <windows.h>
    #include <tchar.h>
    
    LRESULT CALLBACK WndProc(HWND hWnd, 
    						 UINT msg, 
    						 WPARAM wParam, 
    						 LPARAM lParam)
    {
    
    	HDROP hDrop;
    	int nFiles,
    		i;
    	TCHAR szPath[MAX_PATH];
    
    
     	switch(msg){
    	case WM_CREATE:
    		DragAcceptFiles(hWnd,TRUE);
    		break;
    	case WM_DROPFILES:
    		hDrop = (HDROP) wParam; 
    			
    		nFiles = DragQueryFile(hDrop,0xFFFFFFFF,szPath,MAX_PATH);
    		for(i = 0;i < nFiles;i++){
    			DragQueryFile(hDrop,i,szPath,MAX_PATH);
    			MessageBox(hWnd,szPath,_T("Result!"),MB_OK);
    		}
    		break;
    	case WM_CLOSE:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hWnd, msg, wParam, lParam);
    	}
    
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInst,
    				   HINSTANCE,LPSTR,int nShow){
    
    	TCHAR szWindowName[]= _T("DragNDrop");
    	WNDCLASSEX wc= {0};
    	HWND hWnd;
    	MSG msg;
    
    	wc.cbSize= sizeof(WNDCLASSEX);
    	wc.style= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    	wc.lpfnWndProc= WndProc;
    	wc.hInstance= hInst;
    	wc.hIcon= LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor= LoadCursor(NULL,IDC_ARROW);
    	wc.lpszClassName= szWindowName;
    	wc.hbrBackground= CreateSolidBrush(RGB(255, 255, 255));
    	wc.hIconSm= LoadIcon(NULL, IDI_WINLOGO);
    
    	if(!RegisterClassEx(&wc))return EXIT_FAILURE;
    
    	hWnd= CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_ACCEPTFILES,
    						   szWindowName, 
    						   szWindowName, 
    						   WS_OVERLAPPEDWINDOW,
    						   CW_USEDEFAULT, 
    						   CW_USEDEFAULT, 
    						   400, 
    						   400, 
    						   HWND_DESKTOP, 
    						   NULL, 
    						   hInst, 
    						   NULL);
    	if(!hWnd) {
    		return EXIT_FAILURE; 
    	}
    
    	ShowWindow(hWnd, nShow);
    	UpdateWindow(hWnd);
    
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	
    	return msg.wParam;
    		
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    39
    Thanks "Fordy," but the code you provided doesn't differ much from what I have already tried. Still, when I drag a link from Internet Explorer 5.0 to my application it won't allow the drag and drop operation.

    Using e.g. DragQueryFile((HDROP) wParam,0, szFileName, MAX_PATH); works great when dragging files from e.g. Windows Explorer to my application -- I have used this method many times before -- but when trying to drag a hyper link from a browser, namely Internet Explorer, it doesn't work.

    Actually, the applications I have used Spy++ with that accept drag and drop operations from Internet Explorer 5 never process WM_DROPFILES. Unless, of course, I missed something.

    Were you actually able to handle drag and drop operations from Internet Explorer 4 or 5 using the code you provided? If so, I must be doing something very wrong

    Thanks for the help

    Echidna

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    16
    Internet Explorer implements OLE Drag and Drop to handle the dragging of hyperlinks.
    You must do the following (look into the APIs especially on MSDN)

    1) OleInitialize
    2) use RegisterClipboardFormat to get a handle for "UniformResourceLocator" (no spaces). This is the clipboard format the IE uses (note that Netscape does not use this format).
    3) RegisterDragDrop on your window
    4) Implement the IDropTarget interface including DragEnter, DragDrop and DragOver at the very least

    If you have an app to spy on Clipboard contents it'll come in handy.

    --Chorus

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    39
    Thanks a lot "Chorus," that is exactly what I was talking about.

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Sorry Echnida....I missread your question....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] Drag and drop controls
    By pc2-brazil in forum Windows Programming
    Replies: 1
    Last Post: 09-02-2008, 03:41 AM
  2. Drag & Drop files into my (and other) apps
    By Mastadex in forum Windows Programming
    Replies: 1
    Last Post: 11-07-2007, 05:59 AM
  3. DataGrid drag and drop
    By gtriarhos in forum C# Programming
    Replies: 0
    Last Post: 10-11-2005, 01:36 PM
  4. Drag and Drop using CImageList, Device contexts and BitBlt
    By MJWhiteman2 in forum Windows Programming
    Replies: 0
    Last Post: 03-03-2005, 07:22 AM
  5. drag and drop
    By depsypher in forum Windows Programming
    Replies: 2
    Last Post: 01-05-2002, 10:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21