A pure SDK creates a form that can receive file drag and drop
Last Update:2017-02-27
Source: Internet
Author: User
#include <windows.h> int WINAPI WinMain (hinstance hinstance,hinstance hprevinstance,lpstr lpcmdline,int); BOOL initapplication (hinstance hinstance); BOOL InitInstance (hinstance hinstance,int ncmdshow); Lresult CALLBACK Mainwndproc (HWND hwnd,uint umsg,wparam wparam,lparam); BOOL showfileinfo (HWND hwnd,hdc hdc,hdrop hdropinfo); int WINAPI WinMain (hinstance hinstance,hinstance hprevinstance,lpstr lpcmdline,int) { MSG msg; if (! InitApplication (HINSTANCE)) return FALSE; if (! InitInstance (Hinstance,ncmdshow)) return FALSE; while (GetMessage (&msg,null,0,0)) { TranslateMessage (&MSG); DispatchMessage (&MSG); } return msg.wparam; } BOOL initapplication (hinstance hinstance) { WNDCLASS WC; Wc.style = 0; Wc.lpfnwndproc = (WNDPROC) Mainwndproc; Wc.cbclsextra = 0; Wc.cbwndextra = 0; Wc.hinstance = hinstance; Wc.hicon = LoadIcon (null,idi_application); Wc.hcursor = LoadCursor (Null,idc_arrow); Wc.hbrbackground = Getstockobject (White_brush); Wc.hbrbackground = (hbrush) getstockobject (White_brush); Wc.lpszmenuname = NULL; Wc.lpszclassname = "Dropfileclass"; Return registerclass (&WC); } BOOL InitInstance (hinstance hinstance,int ncmdshow) { HWND hwnd; HWnd = CreateWindowEx ( 0, "Dropfileclass", "Dropfile Demo", Ws_overlappedwindow, Cw_usedefault, Cw_usedefault, Cw_usedefault, Cw_usedefault, Null Null HINSTANCE, Null ); if (!hwnd) return FALSE; ShowWindow (hwnd,ncmdshow); UpdateWindow (HWND); return TRUE; } Lresult CALLBACK Mainwndproc (HWND hwnd,uint umsg,wparam Wparam,lparam) { HDC HDC; Switch (umsg) { Case WM_CREATE: DragAcceptFiles (hwnd,true); Break Case Wm_dropfiles: Hdrop Hdropinfo; Hdropinfo = (hdrop) WParam; Hdropinfo = (HANDLE) WParam; HDC = GetDC (hWnd); Showfileinfo (Hwnd,hdc,hdropinfo); Dragfinish (Hdropinfo); ReleaseDC (HWND,HDC); Break Case Wm_destroy: DragAcceptFiles (Hwnd,false); PostQuitMessage (0); Break Default return DefWindowProc (Hwnd,umsg,wparam,lparam); } return 0; } BOOL showfileinfo (HWND hwnd,hdc hdc,hdrop hdropinfo) { Point pt; WORD Cfiles; HINSTANCE Hcurrentinst; Hicon Hicon; Shfileinfo SFI; Char lpszfile[80]; Char szbuff[1024]; Dragquerypoint (HDROPINFO,&PT); Cfiles = Dragqueryfile (Hdropinfo, (UINT) 0xFFFFFFFF, (LPTSTR) null, (UINT) null); if (Cfiles > 1) { wsprintf (Szbuff, "Dragfilenumber:%d", (int) cfiles); TextOut (Hdc,pt.x,pt.y,szbuff,lstrlen (Szbuff)); return FALSE; } Else { Dragqueryfile (hdropinfo,0,lpszfile,sizeof (lpszfile)); if (Shgetfileinfo lpszfile,0,&sfi,sizeof (shfileinfo), Shgfi_displayname | Shgfi_typename)) { memset (szbuff,0,sizeof (Szbuff)); wsprintf (Szbuff, "Name:%s Type:%s", sfi.szdisplayname,sfi.sztypename); } Hcurrentinst = (hinstance) GetWindowLong (hwnd,gwl_hinstance); Hicon = ExtractIcon (hcurrentinst,lpszfile,0); if (Hicon = NULL | | hicon = = (HICON) 1) { TextOut (Hdc,pt.x,pt.y,szbuff,lstrlen (Szbuff)); } Else { DrawIcon (Hdc,pt.x,pt.y,hicon); TextOut (Hdc,pt.x,pt.y + 32,szbuff,lstrlen (szbuff)); } } return TRUE; }