A pure SDK creates a form that can receive file drag and drop

Source: Internet
Author: User
Tags bool textout
#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 (&AMP;MSG);
DispatchMessage (&AMP;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 (&AMP;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,&AMP;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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.