當前位置: 首頁>>代碼示例>>C++>>正文


C++ EmptyClipboard函數代碼示例

本文整理匯總了C++中EmptyClipboard函數的典型用法代碼示例。如果您正苦於以下問題:C++ EmptyClipboard函數的具體用法?C++ EmptyClipboard怎麽用?C++ EmptyClipboard使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了EmptyClipboard函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: CopyToClipboard

void CopyToClipboard(HWND hwnd) {
  if (!hwnd || !OpenClipboard(hwnd)) return;
  LRESULT len = SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXTLENGTH, 0, 0);
  HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (++len)*sizeof(TCHAR));
  if (!mem) { CloseClipboard(); return; }
  TCHAR *txt = (TCHAR *)GlobalLock(mem);
  if (!txt) { CloseClipboard(); return; }
  EmptyClipboard();
  txt[0] = 0;
  SendDlgItemMessage(hwnd, IDC_LOGWIN, WM_GETTEXT, (WPARAM)(len), (LPARAM)txt);
  GlobalUnlock(mem);
#ifdef _UNICODE
  SetClipboardData(CF_UNICODETEXT, mem);
#else
  SetClipboardData(CF_TEXT, mem);
#endif
  CloseClipboard();
}
開發者ID:GEO-IASS,項目名稱:nsis,代碼行數:18,代碼來源:utils.cpp

示例2: sys_clipboard_set

Status sys_clipboard_set(const wchar_t* text)
{
	if(!OpenClipboard(hWndNewOwner))
		WARN_RETURN(ERR::FAIL);

	WARN_IF_FALSE(EmptyClipboard());

	// NB: to enable copy/pasting something other than text, add
	// message handlers for WM_RENDERFORMAT and WM_RENDERALLFORMATS.
	HGLOBAL hMem;
	Status ret = SetClipboardText(text, hMem);

	WARN_IF_FALSE(CloseClipboard());	// must happen before GlobalFree

	ENSURE(GlobalFree(hMem) == 0);	// (0 indicates success)

	return ret;
}
開發者ID:2asoft,項目名稱:0ad,代碼行數:18,代碼來源:wclipboard.cpp

示例3: sel1

//////////////////////////////////////////////////////////////////////////////////////////////////
// clipboard
//////////////////////////////////////////////////////////////////////////////////////////////////
void cGUIEdit::ClipboardCopy()
{
	int s1 = sel1(), s2 = sel2();
	int size = s2-s1;
	if(size==0) return; // no selection

	if(!OpenClipboard(NULL)) return;
	if(EmptyClipboard())
	{
		HGLOBAL handler = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,size+1); assert(handler!=NULL);
		void* data = GlobalLock(handler); assert(data!=NULL);
		memcpy(data,txt.c_str() + s1,size);
		((LPWSTR)data)[size]=0;
		GlobalUnlock(handler);
		SetClipboardData(CF_UNICODETEXT,handler);
	}
	CloseClipboard();
}
開發者ID:leprosarium,項目名稱:prolozzy,代碼行數:21,代碼來源:GUIEdit.cpp

示例4: EmptyClipboard

BOOL CClipboard::SetTextW(HWND owner, const wchar_t* str, int len)
{
	if (str && *str && OpenClipboard(owner))
	{
		EmptyClipboard();
		HANDLE hmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, len + 4);
		if (hmem)
		{
			wchar_t* buf = (wchar_t*)GlobalLock(hmem);
			memcpy(buf, str, len + 4);
			GlobalUnlock(hmem);
			SetClipboardData(CF_UNICODETEXT, hmem);
		}
		CloseClipboard();
		return TRUE;
	}
	return FALSE;
}
開發者ID:Kerlifw,項目名稱:pcman-windows,代碼行數:18,代碼來源:Clipboard.cpp

示例5: EmptyClipboard

void CCommunicationTrafficDlg::OnBnClickedCopy()
{
//--------------------------------------------------------------------------------------------------------------------

   
    CArray <int, int> aryListSel;
    int nCount= m_DataList.GetSelCount();
    aryListSel.SetSize(nCount);
    m_DataList.GetSelItems(nCount, aryListSel.GetData()); 

  //  aryListSel中存的就是選中列的index值,如果需要取內容,加以下語句:
        CString str,content;
        for (int i= nCount-1; i>= 0; i--)
        {
            m_DataList.GetText(aryListSel.GetAt(i), (CString&)str);
            str+=_T("\n");
            content==str;
        }


//--------------------------------------------------------------------------------------------------------------------
     
    HGLOBAL hClip; 
    //定義一個HGLOBAL句柄變量用來指向分配的內存塊
    if (OpenClipboard())
    {
        EmptyClipboard();                            //將剪貼板內容清空
        hClip=GlobalAlloc(GMEM_MOVEABLE,content.GetLength()+1); 
        //在堆上分配可移動的內存塊,程序返回一個內存句柄
        char * buff;                                 //定義指向字符型的指針變量
        buff=(char*)GlobalLock(hClip);
        //對分配的內存塊進行加鎖,將內存塊句柄轉化成一個指針,並將相應的引用計數器加1
        strcpy(buff,(char*)content.GetBuffer());
        //將用戶輸入的數據複製到指針變量中,實際上就是複製到分配的內存塊中
        GlobalUnlock(hClip);
        //數據寫入完畢,進行解鎖操作,並將引用計數器數字減1
        SetClipboardData(CF_TEXT,hClip);
        //將存放有數據的內存塊放入剪貼板的資源管理中
        CloseClipboard();
        //關閉剪貼板,釋放剪貼板資源的占用權
      
    }
//--------------------------------------------------------------------------------------------------------------------
}
開發者ID:ALEXLCC,項目名稱:T3000_Building_Automation_System,代碼行數:44,代碼來源:CommunicationTrafficDlg.cpp

示例6: CopyToClipboard

void CopyToClipboard(const char* text) ///Copies a string to the clipboard.
{
    HGLOBAL hText;
    char *pText;

    hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, strlen(text)+1);
    pText = (char*)GlobalLock(hText);
    strcpy(pText, text);

    OpenClipboard(0);
    EmptyClipboard();
    if(!SetClipboardData(CF_OEMTEXT, hText))
    {
        MessageBeep(MB_ICONERROR);
    }
    MessageBeep(MB_ICONINFORMATION);
    CloseClipboard();
}
開發者ID:cdaze,項目名稱:akt,代碼行數:18,代碼來源:main.cpp

示例7: OpenClipboard

LRESULT CMainDlg::OnCopyClip(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	OpenClipboard();
	EmptyClipboard();

	FrqValue atk = GetSetting(gen1AtkEd);
	AmpValue pk  = GetSetting(gen1VolEd);
	FrqValue dec = GetSetting(gen1DecEd);
	AmpValue sus = GetSetting(gen1SusEd);
	FrqValue rel = GetSetting(gen1RelEd);

	FrqValue mul1 = GetSetting(gen2MulEd);
	AmpValue amp1 = GetSetting(gen2NdxEd);
	FrqValue atk1 = GetSetting(gen2AtkEd);
	AmpValue pk1  = GetSetting(gen2PckEd);
	FrqValue dec1 = GetSetting(gen2DecEd);
	AmpValue sus1 = GetSetting(gen2SusEd);
	FrqValue rel1 = GetSetting(gen2RelEd);
	AmpValue end1 = GetSetting(gen2EndEd);

	FrqValue mul2 = GetSetting(gen3MulEd);
	AmpValue amp2 = GetSetting(gen3NdxEd);
	FrqValue atk2 = GetSetting(gen3AtkEd);
	AmpValue pk2  = GetSetting(gen3PckEd);
	FrqValue dec2 = GetSetting(gen3DecEd);
	AmpValue sus2 = GetSetting(gen3SusEd);
	FrqValue rel2 = GetSetting(gen3RelEd);
	AmpValue end2 = GetSetting(gen3EndEd);

	char txt[1024];
	sprintf(txt, "{ %4d, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f,\r\n%6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f,\r\n%6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f, %6.3f },\r\n",
		algorithm, 0.0, atk, pk, dec, sus, rel, 0.0,
		mul1, amp1, atk1, pk1, dec1, sus1, rel1, end1,
		mul2, amp2, atk2, pk2, dec2, sus2, rel2, end2);

	HANDLE mem = GlobalAlloc(0, strlen(txt)+1);
	char *ptxt = (char*)GlobalLock(mem);
	strcpy(ptxt, txt);
	GlobalUnlock(mem);

	SetClipboardData(CF_TEXT, mem);
	CloseClipboard();
	return 0;
}
開發者ID:travisgoodspeed,項目名稱:basicsynth,代碼行數:44,代碼來源:MainDlg.cpp

示例8: CutOrCopyFiles

void CutOrCopyFiles(LPCTSTR lpBuffer,UINT uBufLen,BOOL bCopy)
{
	UINT uDropEffect;
	DROPFILES dropFiles;
	UINT uGblLen,uDropFilesLen;
	HGLOBAL hGblFiles,hGblEffect;
	char *szData,*szFileList;

	DWORD *dwDropEffect;

	uDropEffect=RegisterClipboardFormat(L"Preferred DropEffect");
	hGblEffect=GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE,sizeof(DWORD));
	dwDropEffect=(DWORD*)GlobalLock(hGblEffect);
	if(bCopy)
		*dwDropEffect=DROPEFFECT_COPY;
	else 
		*dwDropEffect=DROPEFFECT_MOVE;
	GlobalUnlock(hGblEffect);

	uDropFilesLen=sizeof(DROPFILES);
	dropFiles.pFiles =uDropFilesLen;
	dropFiles.pt.x=0;
	dropFiles.pt.y=0;
	dropFiles.fNC =FALSE;
	dropFiles.fWide =TRUE;

	uGblLen=uDropFilesLen+uBufLen*2+20;
	hGblFiles= GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE, uGblLen);
	szData=(char*)GlobalLock(hGblFiles);
	memset(szData, 0, uGblLen);
	memcpy(szData,(LPVOID)(&dropFiles),uDropFilesLen);
	szFileList=szData+uDropFilesLen;
	memcpy(szFileList, lpBuffer, uBufLen*sizeof(TCHAR));

	GlobalUnlock(hGblFiles);

	if( OpenClipboard(NULL) )
	{
		EmptyClipboard();
		SetClipboardData( CF_HDROP, hGblFiles );
		SetClipboardData(uDropEffect,hGblEffect);
		CloseClipboard();
	}
}   
開發者ID:boogunote,項目名稱:bn1,代碼行數:44,代碼來源:Common.cpp

示例9: _glfwPlatformSetClipboardString

void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string)
{
    WCHAR* wideString;
    HANDLE stringHandle;
    size_t wideSize;

    wideString = _glfwCreateWideStringFromUTF8(string);
    if (!wideString)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Win32: Failed to convert string to UTF-16");
        return;
    }

    wideSize = (wcslen(wideString) + 1) * sizeof(WCHAR);

    stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize);
    if (!stringHandle)
    {
        free(wideString);

        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Win32: Failed to allocate global handle for clipboard");
        return;
    }

    memcpy(GlobalLock(stringHandle), wideString, wideSize);
    GlobalUnlock(stringHandle);

    if (!OpenClipboard(window->win32.handle))
    {
        GlobalFree(stringHandle);
        free(wideString);

        _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to open clipboard");
        return;
    }

    EmptyClipboard();
    SetClipboardData(CF_UNICODETEXT, stringHandle);
    CloseClipboard();

    free(wideString);
}
開發者ID:RubenMagallanes,項目名稱:comp308sheepSim,代碼行數:44,代碼來源:win32_window.c

示例10: CopyTextToClipboard

VOID
CopyTextToClipboard(LPCWSTR lpszText)
{
    if(OpenClipboard(NULL))
    {
        HGLOBAL ClipBuffer;
        WCHAR *Buffer;

        EmptyClipboard();
        ClipBuffer = GlobalAlloc(GMEM_DDESHARE, (wcslen(lpszText) + 1) * sizeof(TCHAR));
        Buffer = (WCHAR*)GlobalLock(ClipBuffer);
        wcscpy(Buffer, lpszText);
        GlobalUnlock(ClipBuffer);

        SetClipboardData(CF_UNICODETEXT, ClipBuffer);

        CloseClipboard();
    }
}
開發者ID:RareHare,項目名稱:reactos,代碼行數:19,代碼來源:misc.c

示例11: GlobalAlloc

int CBitmap::SetClipboard() {
	HANDLE hGMem = GlobalAlloc(GHND, m_bmpInfoHeader.biSize + m_image.buf.size());
	BITMAPINFOHEADER *pBih = (BITMAPINFOHEADER *)GlobalLock(hGMem);
	*pBih = *(BITMAPINFOHEADER *)&m_bmpInfoHeader;
	//pBih->biBitCount = 32;
	//pBih->biCompression = BI_RGB;
	
	int width	= m_image.width;
	int height	= m_image.height;
	int bytesPerPixel = m_bmpInfoHeader.biBitCount / 8;
	int bytesPerLine = ( (width + (m_bmpInfoHeader.biBitCount % 32 != 0) ) * bytesPerPixel >> 2) << 2;
//	int writeSize = bytesPerLine * height;
	
	printf("Setting... w=%d, h=%d", width, height);
	int offset = pBih->biSize + pBih->biClrUsed * (pBih->biBitCount > 24 ? sizeof(RGBQuad) : sizeof(RGBTriple));
	u8 *imgData = (u8 *)pBih + offset;
	u32 *pBuf = (u32 *)&m_image.buf[0];
	
	switch(m_bmpInfoHeader.biBitCount) {
		case 24: {
			if(m_bmpInfoHeader.biHeight < 0) // Top to bottom
				REP(y, height)	REP(x, width) *(RGBTriple *)&imgData[bytesPerLine*y + 3*x] = *(RGBTriple *)&pBuf[width*y+x];
			else // Bottom to top
				REV(y, height)	REP(x, width) *(RGBTriple *)&imgData[bytesPerLine*y + 3*x] = *(RGBTriple *)&pBuf[width*y+x];
		} break;
		
		case 32: {
			if(m_bmpInfoHeader.biHeight < 0) // Top to bottom
				REP(y, height)	REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[width*y+x];
			else // Bottom to top
				REV(y, height)	REP(x, width) *(u32 *)&imgData[(width*y+x)*4] = pBuf[width*y+x];
		} break;
	}
	GlobalUnlock(hGMem);
	
	if( !OpenClipboard(NULL) ) return -1;
	EmptyClipboard();
	SetClipboardData(CF_DIB, hGMem);
	CloseClipboard();
	
	puts("OK");
	return 0;
}
開發者ID:Um6ra1,項目名稱:GimpPlugin,代碼行數:43,代碼來源:BmpUtil.cpp

示例12: GetSelectedGumpID

void CGumpListView::OnPopupCopygumpid()
{
	int iGumpID = GetSelectedGumpID();
	CString strText = GfxXtoA(iGumpID);
	
	if  (!OpenClipboard()) return;
	
	EmptyClipboard();
	HGLOBAL hClipboardData;
	hClipboardData = GlobalAlloc(GMEM_DDESHARE, strText.GetLength()+1);

	char * pchData = (char*)GlobalLock(hClipboardData);
	strcpy(pchData, strText);
	GlobalUnlock(hClipboardData);
	SetClipboardData(CF_TEXT,hClipboardData);

	CloseClipboard();

}
開發者ID:BackupTheBerlios,項目名稱:iris-svn,代碼行數:19,代碼來源:GumpListView.cpp

示例13: set

void Clipboard::set(std::string text)
{
   if ( !OpenClipboard(NULL) )
   {
      //AfxMessageBox( _T("Cannot open the Clipboard") );
      std::cout << "Clipboard.set(): Cannot open the Clipboard" << std::endl;
      return;
   }
   // Remove the current Clipboard contents 
   if( !EmptyClipboard() )
   {
      std::cout << "Clipboard.set(): Cannot empty the Clipboard" << std::endl;
      return;
   }
   // Get the currently selected data
   //std::cout << "this is causing a crash somewhere: sizeof(text):" << sizeof(text) << " text.length():" << text.length();
   HGLOBAL hGlob = GlobalAlloc(GMEM_MOVEABLE, text.size()+1);
   //strcpy_s((char*)hGlob, 64, text.c_str());
   if (!hGlob)
   {
      std::cout << "Clipboard.set(): could not allocate hGlob" << std::endl;
      CloseClipboard();
      return;
   }

   memcpy(GlobalLock(hGlob),text.c_str(),text.size()+1);
   GlobalUnlock(hGlob);

   // For the appropriate data formats... 
   if ( ::SetClipboardData( CF_TEXT, hGlob ) == NULL )
   {
      std::cout << "Clipboard.set(): Unable to set Clipboard data, error: " << GetLastError() << std::endl;
      //CString msg;
      //msg.Format(_T("Unable to set Clipboard data, error: %d"), GetLastError());
      //AfxMessageBox( msg );
      CloseClipboard();
      GlobalFree(hGlob);
      return;
   }
   CloseClipboard();

   get_instance()->__text = text;
}
開發者ID:MarkOates,項目名稱:allegro_flare,代碼行數:43,代碼來源:clipboard_win.cpp

示例14: Copy

  void Copy( const char * data, int len )
  {
    HWND hWnd = GetForegroundWindow();
    if (!::OpenClipboard( hWnd ))
      return;

    EmptyClipboard();

    HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE,(len + 1) * sizeof(WCHAR));
    WCHAR * pMem = (WCHAR*)GlobalLock(h);

    ZeroMemory( pMem, (len + 1) * sizeof(WCHAR) );
    CopyMemory( pMem, data, (len + 1) * sizeof(WCHAR) );

    GlobalUnlock(h);
    SetClipboardData(CF_TEXT,h);

    CloseClipboard();
  }
開發者ID:OniDaito,項目名稱:Bonzomatic,代碼行數:19,代碼來源:Clipboard.cpp

示例15: win_set_clipboard_text

static bool win_set_clipboard_text(ALLEGRO_DISPLAY *display, const char *text)
{
   HWND handle = get_window_handle(display);
   HANDLE hMem = NULL;
   wchar_t *tstr = NULL;
   size_t size;
   size_t len;
   LPTSTR dst;

   if (!OpenClipboard(handle)) {
      ALLEGRO_DEBUG("Could not open clipboard for handle %p", handle);
      return false;
   }

   /* Convert the text from UTF-8 to Windows Unicode */
   tstr = _al_win_utf16(text);
   len  = wcslen(tstr);
   size = (len+1) * sizeof(wchar_t);
   /* Save the data to the clipboard */
   hMem = GlobalAlloc(GMEM_MOVEABLE, size);

   if (!hMem) {
      al_free(tstr);
      ALLEGRO_DEBUG("GlobalAlloc failed to allocate memory for the clipboard data");
      return false;
   }

   dst = (LPTSTR)GlobalLock(hMem);
   /* Copy the text over. Unlike SDL, do NOT convert newlines, that's for the
    * use to decide. */
   memmove(dst, tstr, size);
   dst[len] = 0;
   GlobalUnlock(hMem);
   EmptyClipboard();
   if (!SetClipboardData(TEXT_FORMAT, hMem)) {
      al_free(tstr);
      ALLEGRO_DEBUG("Couldn't set clipboard data");
      return false;
   }
   al_free(tstr);
   CloseClipboard();
   return true;
}
開發者ID:BorisCarvajal,項目名稱:allegro5,代碼行數:43,代碼來源:wclipboard.c


注:本文中的EmptyClipboard函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。