14#ifdef _TnbCLIPBOARD_OtherType_ENABLE
24 #pragma comment(lib,"gdi32.lib")
60 explicit CClipboard(HWND hWnd = NULL, DWORD dwOpenTimeout = 500,
bool boHasErrBox =
false)
61 : m_hWnd(hWnd), m_dwOpenTimeout(dwOpenTimeout), m_boHasErrBox(boHasErrBox)
103 uFormat = CBFMT_TEXT;
107 boRc = !! ::IsClipboardFormatAvailable(uFormat);
122 int r = ::GetClipboardFormatName(uFormat, str.
GetBuffer(1024), 1024);
123 _GetLastError(
"GetClipboardFormatName");
139 return ::RegisterClipboardFormat(lpszDataTypeName);
152 if ( ::IsClipboardFormatAvailable(CBFMT_TEXT) )
154 HANDLE hMem = ::GetClipboardData(CBFMT_TEXT);
157 strRc =
static_cast<LPCTSTR
>(GlobalLock(hMem));
176 if ( ! m_Open(! isAdd) )
181 HGLOBAL hMem = m_AllocAndCopy((iStrLen + 1) *
sizeof(TCHAR), lpszText);
182 bool boRc = m_SetData(CBFMT_TEXT, hMem);
201 if ( ::IsClipboardFormatAvailable(dataTypeId) )
203 HGLOBAL h = ::GetClipboardData(dataTypeId);
204 size_t len = ::GlobalSize(h);
205 _data.
Reset(len,
static_cast<BYTE*
>(GlobalLock(h)));
225 bool SetUserData(UINT dataTypeId,
size_t dataSize, LPCVOID pData,
bool isAdd =
false)
227 if ( ! m_Open(! isAdd) )
231 HGLOBAL h = m_AllocAndCopy(dataSize, pData);
232 bool r = m_SetData(dataTypeId, h);
250 if ( ::IsClipboardFormatAvailable(CF_BITMAP) )
252 HBITMAP hBmp =
static_cast<HBITMAP
>(::GetClipboardData(CF_BITMAP));
255 rc =
static_cast<HBITMAP
>(::CopyImage(hBmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
273 if ( ! m_Open(! isAdd) )
277 BITMAPINFOHEADER bmi;
278 RGBQUAD* pRgb = NULL;
284 HGLOBAL h = ::GlobalAlloc(GHND,
sizeof(bmi) + bmi.biWidth * bmi.biHeight *
sizeof(RGBQUAD));
285 BYTE* B =
static_cast<BYTE*
>(::GlobalLock(h));
287 MemCopy(&B[
sizeof(bmi)], pRgb, bmi.biWidth * bmi.biHeight *
sizeof(RGBQUAD));
289 bool boRc = m_SetData(CF_DIB, h);
297 #ifdef _TnbCLIPBOARD_OtherType_ENABLE
310 bool GetDropInfo(
CStrVector& _vstrFiles, DWORD& _dwEffect)
const
317 if ( ::IsClipboardFormatAvailable(CF_HDROP) )
319 HDROP hDrop =
static_cast<HDROP
>(::GetClipboardData(CF_HDROP));
320 TCHAR atcBuf[MAX_PATH];
321 int iCount =
ToInt(::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, NULL));
322 for (
int i = 0; i < iCount; i++ )
324 ::DragQueryFile(hDrop, i, atcBuf, MAX_PATH);
325 _vstrFiles.
Add(atcBuf);
328 UINT uFmt = ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT);
329 HANDLE hDropEffect = ::GetClipboardData(uFmt);
330 if ( hDropEffect != NULL )
332 _dwEffect = *
static_cast<DWORD*
>(::GlobalLock(hDropEffect));
333 ::GlobalUnlock(hDropEffect);
352 bool SetDropInfo(
const CStrVector& vstrFiles, DWORD dwEffect = DROPEFFECT_COPY)
354 if ( ! m_Open(
true) )
363 DROPFILES dfs = {
sizeof(dfs) };
367 size_t size = dnt.
GetSize() *
sizeof(TCHAR);
368 HGLOBAL hDrop = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
sizeof(DROPFILES) + size);
369 BYTE* B =
static_cast<BYTE*
>(::GlobalLock(hDrop));
370 MemCopy(B,
reinterpret_cast<const BYTE*
>(&dfs),
sizeof(DROPFILES));
371 B +=
sizeof(DROPFILES);
372 MemCopy(B,
reinterpret_cast<const BYTE*
>(LPCTSTR(dnt)), size);
373 ::GlobalUnlock(hDrop);
375 HGLOBAL hDropEffect = m_AllocAndCopy(
sizeof(DWORD), &dwEffect);
377 UINT uFmt = ::RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT);
378 if ( ::SetClipboardData(CF_HDROP, hDrop) == NULL )
380 ::GlobalFree(hDropEffect);
383 else if ( ::SetClipboardData(uFmt, hDropEffect) == NULL )
385 ::GlobalFree(hDropEffect);
409 bool GetAll(CDataMap& _data,
bool boIsWithMetafile =
false,
bool boIsWithRegData =
false)
const
420 UINT r = ::EnumClipboardFormats(uFormat);
423 DWORD dwError = _GetLastError(
"EnumClipboardFormats");
424 if ( dwError == NO_ERROR )
435 bool boIsValid =
false;
444 boIsValid = boIsWithMetafile;
448 if ( boIsWithRegData )
450 boIsValid = (r >= 0x8000);
458 HANDLE hMem = ::GetClipboardData(r);
460 if ( r == CF_ENHMETAFILE )
462 HENHMETAFILE h = (HENHMETAFILE)hMem;
463 UINT l = ::GetEnhMetaFileBits(h, 0, NULL);
464 ::GetEnhMetaFileBits(h, l, v.
GetBuffer(l));
470 v.
SetElements(
static_cast<size_t>(::GlobalSize(hMem)),
static_cast<BYTE*
>(GlobalLock(hMem)));
493 bool SetAll(
const CDataMap& data)
495 if ( ! m_Open(
true) )
502 loop ( i, data.GetSize() )
504 VERIFYLIB(data.Get(i, uFormat, v));
505 bool boIsValid =
false;
518 boRc &= m_SetData(uFormat, h);
525 if ( uFormat >= 0x8000 || boIsValid )
529 if ( uFormat == CF_TEXT )
531 LPCSTR P =
reinterpret_cast<LPCSTR
>(v.
ReferBuffer());
537 uFormat = CF_UNICODETEXT;
541 boRc &= m_SetData(uFormat, hMem);
553 enum { CBFMT_TEXT = CF_UNICODETEXT };
555 enum { CBFMT_TEXT = CF_TEXT };
559 DWORD m_dwOpenTimeout;
563 void m_MsgBox(LPCTSTR lpsz)
const
567 TRACE1(
"%s\n", lpsz);
568 ::MessageBox(NULL, lpsz, _T(
"TNB::CClipboard"), MB_OK);
578 bool m_Open(
bool boWithEmpty =
false)
const
580 DWORD dwTick = ::GetTickCount();
583 if ( ::OpenClipboard(m_hWnd) )
585 if ( boWithEmpty && ! ::EmptyClipboard() )
588 m_MsgBox(_T(
"クリップ・ボードが一杯です"));
595 while ( (::GetTickCount() - dwTick) < m_dwOpenTimeout );
596 m_MsgBox(_T(
"クリップ・ボードが利用できません。"));
601 void m_Close(
void)
const
612 HGLOBAL m_AllocAndCopy(
size_t size, LPCVOID P)
614 HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
617 m_MsgBox(_T(
"メモリが一杯です"));
621 ::CopyMemory(GlobalLock(hMem), P, size);
634 bool m_SetData(UINT uFormat, HGLOBAL hMem)
640 if ( ::SetClipboardData(uFormat, hMem) == NULL )
#define loop(VAR, CNT)
loop構文.
Double Null Terminate(DNT)型文字列操作関係のヘッダ
static HBITMAP Create32bitDibSection(HBITMAP hbm, RGBQUAD *&_pRgb, BITMAPINFOHEADER *pHeader=NULL)
[作成] 32bitビットマップ作成.
bool IsAvailable(UINT uFormat=0) const
[確認] 存在確認.
bool SetBitmap(HBITMAP bmp, bool isAdd=false)
[設定] ビットマップ登録.
bool SetUserData(UINT dataTypeId, size_t dataSize, LPCVOID pData, bool isAdd=false)
[設定] ユーザ定義データ設定.
static UINT RegisterUserDataType(LPCTSTR lpszDataTypeName)
[登録] ユーザ定義データ型登録.
CStr GetString(void) const
[取得] 文字列取得.
CClipboard(HWND hWnd=NULL, DWORD dwOpenTimeout=500, bool boHasErrBox=false)
コンストラクタ
bool GetUserData(CWorkMem &_data, UINT dataTypeId) const
[取得] ユーザ定義データ取得.
static CStr GetFormatName(UINT uFormat)
[取得] データ型名取得
void SetHandle(HWND hWnd)
[登録] ウィンドウハンドル設定
bool SetString(LPCTSTR lpszText, bool isAdd=false)
[設定] 文字列登録.
HBITMAP GetBitmap(void) const
[取得] ビットマップ取得.
Double Null Terminate(DNT)型文字列管理
void Set(LPCTSTR lpszStr)
[設定] 代入
size_t GetSize(void) const
[取得] DNT型文字列数種特
virtual bool RemoveAll(void)
[削除] すべてのキーと値を削除
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
size_t GetLength(void) const
[取得] 文字列長
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
virtual size_t GetSize(void) const
[取得] サイズ取得
TYP * GetBuffer(size_t size=0)
[操作] データアドレス取得
void ReleaseBuffer(void)
[操作] データの管理を元に戻す.
virtual bool RemoveAll(void)
[削除] 空化
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
virtual size_t SetElements(size_t size, const TYP *P=NULL)
[設定] 複数要素設定.
void Reset(size_t l, const TYP *P)
[設定] 再設定
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー