先日からの続き.
次の様なコードでドラッグできる様に.
void CXxxDlg::OnDropFiles(HDROP hDropInfo)
{
Drop_files = ::DropFilesTo(hDropInfo) ;
// ...
}
void CXxxDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if (nFlags == MK_LBUTTON) {
::String_DoDrag(Drop_files) ;
}
// ...
}
CXxxxApp::InitInstance() に AfxOleInit() の追加.
今回作成したコード.
v_char String_to_nnts (c_v_tstring& str_ary)
{
v_char vchr_2zts ;
{
tstring join_str = ::String_Join(str_ary,_T('\n'))+_T("\n\n") ;
tstring str_2zts = join_str ;
for (size_t index=0 ; index<str_2zts.size() ; index++) {
TCHAR tc = str_2zts[index] ;
if (tc == _T('\n')) {
str_2zts[index] = _T('\0') ;
}
}
size_t str_bytes = str_2zts.size() * sizeof(TCHAR) ;
vchr_2zts.resize(str_bytes) ;
::MemMove(&vchr_2zts[0],str_bytes,&str_2zts[0],str_bytes) ;
}
return vchr_2zts ;
}
HDROP String_to_HDROP (c_v_tstring& str_ary)
{
// ::Dump_String_nnts(str_ary) ;
v_char vchr = ::String_to_nnts(str_ary) ;
int len = int(vchr.size()) ;
HDROP hDrop = (HDROP)::GlobalAlloc(GHND,sizeof(DROPFILES) + len + sizeof(TCHAR)) ;
if (hDrop == NULL) { return hDrop ; }
LPDROPFILES lpdf = (LPDROPFILES)::GlobalLock(hDrop) ;
{
lpdf->pFiles= sizeof(DROPFILES) ;
lpdf->pt.x = 0 ;
lpdf->pt.y = 0 ;
lpdf->fNC = FALSE ;
lpdf->fWide = FALSE ;
#ifdef _UNICODE
lpdf->fWide = TRUE ;
#endif
LPCTSTR lpFileNames = LPCTSTR(LPCSTR(lpdf)+lpdf->pFiles) ;
::MemMove(LPVOID(lpFileNames),len,&vchr[0],len) ;
}
::GlobalUnlock(hDrop) ;
return hDrop ;
}
BOOL String_DoDrag (c_v_tstring& str_ary)
{
HDROP hDrop = ::String_to_HDROP(str_ary) ;
if (hDrop == NULL) { return FALSE ; }
{
COleDataSource* ods = new COleDataSource ;
ods->CacheGlobalData(CF_HDROP,hDrop) ;
ods->DoDragDrop(DROPEFFECT_COPY) ;
ods->InternalRelease() ;
}
return TRUE ;
}
コードが揃っていないため,そのままでは利用できません.
ニーズがあれはどこかのタイミングでビルドできるものを用意します.