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

2008-02-23 05:36:53来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

#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;
}




标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: DriverStudio套件包的安装和运行环境配置

下一篇: 自画标题栏的一个例子

热门词条
热门标签