日期:2011-03-22 13:55:00 来源:本站整理
纯sdk成立能接纳文件拖放的窗体[VC/C++编程]
本文“纯sdk成立能接纳文件拖放的窗体[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
#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;
}
以上是“纯sdk成立能接纳文件拖放的窗体[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论