零点教学网(www.0djx.com)-学电脑,学软件,学编程,学网站,学设计!

纯sdk创建能接收文件拖放的窗体

零点教学网 c++教程 2020-07-08 02:58:37 3
#include windows.h

int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow );
BOOL InitApplication( HINSTANCE hInstance );
BOOL InitInstance( HINSTANCE hInstance,int nCmdShow );
LRESULT CALLBACK MainWndProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam );
BOOL ShowFileInfo( HWND hWnd,HDC hDC,HDROP hDropInfo );

int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow )
{
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 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;
}

 


如果以上内容你喜欢,请持续关注:零点教学网软件编程教程栏目

分享:

本文来自投稿,不代表本人立场,如若转载,请注明出处:http://0djx.com/ruanjianbianchengjiaocheng/cjj/7277.html

  单片机c语言必背代码   纯sdk创建能接收文件拖放的窗体   零点教学网C++教程   免费下载纯sdk创建能接收文件拖放的窗体  

(3)
打赏 微信扫一扫
« 上一篇 2020年07月08日 02:58:22
下一篇 » 2020年07月08日 02:58:50

纯sdk创建能接收文件拖放的窗体_相关内容

免费下载纯sdk创建能接收文件拖放的窗体_相关内容