当前位置: 首页>>代码示例>>C++>>正文


C++ IsClipboardFormatAvailable函数代码示例

本文整理汇总了C++中IsClipboardFormatAvailable函数的典型用法代码示例。如果您正苦于以下问题:C++ IsClipboardFormatAvailable函数的具体用法?C++ IsClipboardFormatAvailable怎么用?C++ IsClipboardFormatAvailable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了IsClipboardFormatAvailable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnCmdClipboard

void CMainDialog::OnCmdClipboard(UINT, int, HWND)
{
	HANDLE hData = NULL;
	LPTSTR lptstr = NULL;
	CString strIdKey;
	CString strSNDigit;
	CString strIdKeys;

	if (!IsClipboardFormatAvailable(CF_TTEXT))
		return;

	if (!OpenClipboard())
		return;

	hData = GetClipboardData(CF_TTEXT);
	if (hData == NULL)
		goto end;
	
	lptstr = (LPTSTR)GlobalLock(hData);
	if (!lptstr)
		goto end;

	ATLTRACE(_T("lptstr(%s) "), lptstr);

	// scan & check Mac Address
	int len = _tcslen(lptstr);
	int nMacNibbles = 0;
	TCHAR nibbles[12];

	for (int i = 0; i < len; i++)
	{
		TCHAR x = _totupper(lptstr[i]);
		switch(_totupper(lptstr[i]))
		{
		case _T('0'): case _T('1'): case _T('2'): case _T('3'): case _T('4'): 
		case _T('5'): case _T('6'): case _T('7'): case _T('8'): case _T('9'): 
		case _T('A'): case _T('B'): case _T('C'): case _T('D'): case _T('E'): case _T('F'):
			if (nMacNibbles < 12)
			{
				nibbles[nMacNibbles] = _totupper(lptstr[i]);
				nMacNibbles++;
			}

			if (nMacNibbles == 12)
			{
				TCHAR hex[3] = {0,};
				for (int i = 0; i < 6; i++)
				{
					hex[0] = nibbles[i * 2];
					hex[1] = nibbles[i * 2 +1];
					m_wndAddresses[i].SetWindowText(hex);

				}

				SendMessage(WM_COMMAND, IDOK);

				strIdKey.Empty();
				_GetNdasIdString(strIdKey);

				strSNDigit = pGetSNDigitString(nibbles);

				strIdKeys += strSNDigit + " " + strIdKey + _T("\r\n");

				nMacNibbles = 0;
			}

			break;
		}
	}

	GlobalUnlock(hData);
	lptstr = NULL;

	len = strIdKeys.GetLength();
	HANDLE hAlloc = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(TCHAR));
	if (NULL == hAlloc)
		goto end;

	LPVOID lpData = GlobalLock(hAlloc);
	CopyMemory(lpData, static_cast<LPCTSTR>(strIdKeys), (len + 1) * sizeof(TCHAR));
	GlobalUnlock(hAlloc);

	EmptyClipboard();

	SetClipboardData(CF_TTEXT, hAlloc);

	ATLTRACE(strIdKeys);

end:
	if (lptstr && hData)
	{
		GlobalUnlock(hData);
		lptstr = NULL;
	}

	if (hData)
	{
		CloseClipboard();
		hData = NULL;
	}
//.........这里部分代码省略.........
开发者ID:Nevermore2015,项目名称:ndas4windows,代码行数:101,代码来源:maindlg.cpp

示例2: RtfNotify

BOOL RtfNotify(HWND hDlg, NMHDR* nmhdr)
{
    static BOOL FindFirst = TRUE;
#define BUFF_LEN 2048
    static TCHAR FindWhat[BUFF_LEN];

    if (nmhdr->code == EN_PROTECTED && !PuttingChar) {
        //block
        ENPROTECTED* enp = (ENPROTECTED*) nmhdr;
        CHARRANGE cr;
        INT TextLen = RtfWindowTextLength();
        BOOL Reset = FALSE, Disallow = FALSE;


        // just let it go ahead anyway
        if (enp->msg == WM_COPY)
            return FALSE;

        // they hit backspace
        if (enp->wParam == VK_BACK) {
            if ((DWORD) enp->chrg.cpMin < StartOfInput ||
                    ((DWORD) enp->chrg.cpMin == StartOfInput &&
                     enp->chrg.cpMin == enp->chrg.cpMax)) {
                Reset = TRUE;
                Disallow = TRUE;
            }
        } else if ((DWORD) enp->chrg.cpMin < StartOfInput) {
            Reset = TRUE;
            Disallow = (enp->wParam == VK_DELETE);
        }

        if (Reset) {
            cr.cpMin = TextLen;
            cr.cpMax = cr.cpMin;
            SendMessage(hWndRtf, EM_EXSETSEL, 0, (LPARAM) &cr);
        }

        // we don't want to paste rich text, as that makes it look weird
        // so send only plain text paste commands
        if ((enp->msg == WM_PASTE) && !Disallow) {
            LPTSTR Buffer = NULL;
            Disallow = TRUE;
#if defined _UNICODE
#define CLIP_FORMAT  CF_UNICODETEXT
#else
#define CLIP_FORMAT  CF_TEXT
#endif
            if (IsClipboardFormatAvailable(CLIP_FORMAT) &&
                    OpenClipboard(hWndMain)) {
                HGLOBAL hGlb;
                LPTSTR str;

                if ((hGlb = GetClipboardData(CLIP_FORMAT)) != NULL &&
                        (str = GlobalLock(hGlb)) != NULL) {
                    Buffer = StringDup(str);
                    GlobalUnlock(hGlb);
                }
                CloseClipboard();
            }

            if (Buffer != NULL) {
                // strip trailing new line characters
                INT i;
                for (i = StringLen(Buffer)-1;
                        i >= 0 && (Buffer[i] == TEXT('\r') || Buffer[i] == TEXT('\n'));
                        i--)
                    Buffer[i] = 0;

#if defined _UNICODE
                {
                    SETTEXTEX stt;

                    stt.codepage = CP_UNICODE;
                    stt.flags = ST_SELECTION;
                    SendMessage(hWndRtf,EM_SETTEXTEX,(WPARAM)&stt,(LPARAM)Buffer);
                }
#else
                SendMessage(hWndRtf, EM_REPLACESEL, FALSE, (LPARAM)Buffer);
#endif


                free(Buffer);
            }
        }

        return (Disallow ? TRUE : FALSE);
    } else if (nmhdr->code == EN_LINK) {
        // should really fire on up
        // but that screws up the cursor position

        ENLINK* enl = (ENLINK*) nmhdr;
        if (enl->msg == WM_LBUTTONDOWN) {
            TEXTRANGE tr;
            TCHAR Buffer[1000];
            tr.lpstrText = Buffer;
            tr.chrg.cpMin = enl->chrg.cpMin;
            tr.chrg.cpMax = enl->chrg.cpMax;

            SendMessage(hWndRtf, EM_GETTEXTRANGE, 0, (LPARAM) &tr);
            ExecuteFile(Buffer);
//.........这里部分代码省略.........
开发者ID:ElfridaDwi,项目名称:winghci,代码行数:101,代码来源:RtfWindow.c

示例3: ClipboardIsFormatAvailableHDROP

bool ClipboardIsFormatAvailableHDROP()
{
  return BOOLToBool(IsClipboardFormatAvailable(CF_HDROP));
}
开发者ID:borneq,项目名称:bind7z,代码行数:4,代码来源:Clipboard.cpp

示例4: win_update_menus

void
win_update_menus(void)
{
  bool shorts = !term.shortcut_override;
  bool clip = shorts && cfg.clip_shortcuts;
  bool alt_fn = shorts && cfg.alt_fn_shortcuts;
  bool ct_sh = shorts && cfg.ctrl_shift_shortcuts;

  ModifyMenu(
    sysmenu, IDM_NEW, 0, IDM_NEW,
    alt_fn ? "Ne&w\tAlt+F2" : ct_sh ? "Ne&w\tCtrl+Shift+N" : "Ne&w"
  );
  ModifyMenu(
    sysmenu, SC_CLOSE, 0, SC_CLOSE,
    alt_fn ? "&Close\tAlt+F4" : ct_sh ? "&Close\tCtrl+Shift+W" : "&Close"
  );

  uint sel_enabled = term.selected ? MF_ENABLED : MF_GRAYED;
  EnableMenuItem(menu, IDM_OPEN, sel_enabled);
  ModifyMenu(
    menu, IDM_COPY, sel_enabled, IDM_COPY,
    clip ? "&Copy\tCtrl+Ins" : ct_sh ? "&Copy\tCtrl+Shift+C" : "&Copy"
  );

  uint paste_enabled =
    IsClipboardFormatAvailable(CF_TEXT) ||
    IsClipboardFormatAvailable(CF_UNICODETEXT) ||
    IsClipboardFormatAvailable(CF_HDROP)
    ? MF_ENABLED : MF_GRAYED;
  ModifyMenu(
    menu, IDM_PASTE, paste_enabled, IDM_PASTE,
    clip ? "&Paste\tShift+Ins" : ct_sh ? "&Paste\tCtrl+Shift+V" : "&Paste"
  );

  ModifyMenu(
    menu, IDM_SEARCH, 0, IDM_SEARCH,
    alt_fn ? "S&earch\tAlt+F3" : ct_sh ? "S&earch\tCtrl+Shift+H" : "S&earch"
  );

  ModifyMenu(
    menu, IDM_RESET, 0, IDM_RESET,
    alt_fn ? "&Reset\tAlt+F8" : ct_sh ? "&Reset\tCtrl+Shift+R" : "&Reset"
  );

  uint defsize_enabled =
    IsZoomed(wnd) || term.cols != cfg.cols || term.rows != cfg.rows
    ? MF_ENABLED : MF_GRAYED;
  ModifyMenu(
    menu, IDM_DEFSIZE_ZOOM, defsize_enabled, IDM_DEFSIZE_ZOOM,
    alt_fn ? "&Default size\tAlt+F10" :
    ct_sh ? "&Default size\tCtrl+Shift+D" : "&Default size"
  );

  uint fullscreen_checked = win_is_fullscreen ? MF_CHECKED : MF_UNCHECKED;
  ModifyMenu(
    menu, IDM_FULLSCREEN_ZOOM, fullscreen_checked, IDM_FULLSCREEN_ZOOM,
    alt_fn ? "&Full Screen\tAlt+F11" :
    ct_sh ? "&Full Screen\tCtrl+Shift+F" : "&Full Screen"
  );

  uint otherscreen_checked = term.show_other_screen ? MF_CHECKED : MF_UNCHECKED;
  ModifyMenu(
    menu, IDM_FLIPSCREEN, otherscreen_checked, IDM_FLIPSCREEN,
    alt_fn ? "Flip &Screen\tAlt+F12" :
    ct_sh ? "Flip &Screen\tCtrl+Shift+S" : "Flip &Screen"
  );

  uint options_enabled = config_wnd ? MF_GRAYED : MF_ENABLED;
  EnableMenuItem(menu, IDM_OPTIONS, options_enabled);
  EnableMenuItem(sysmenu, IDM_OPTIONS, options_enabled);
}
开发者ID:Jactry,项目名称:mintty,代码行数:71,代码来源:wininput.c

示例5: Scan_clipboard

//------------------------------------------------------------------------------
//http://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx
DWORD WINAPI Scan_clipboard(LPVOID lParam)
{
  //check if local or not :)
  if (!LOCAL_SCAN)
  {
    h_thread_test[(unsigned int)lParam] = 0;
    check_treeview(htrv_test, H_tests[(unsigned int)lParam], TRV_STATE_UNCHECK);//db_scan
    return 0;
  }

  //db
  sqlite3 *db = (sqlite3 *)db_scan;
  if(!SQLITE_FULL_SPEED)sqlite3_exec(db_scan,"BEGIN TRANSACTION;", NULL, NULL, NULL);

  //lecture du contenu du presse papier et extraction
  if (OpenClipboard(0))
  {
    char description[MAX_LINE_SIZE], format[DEFAULT_TMP_SIZE],
    data[MAX_LINE_SIZE],user[NB_USERNAME_SIZE+1]="";
    unsigned int session_id = current_session_id;
    HGLOBAL hMem;

    //user
    DWORD s=NB_USERNAME_SIZE;
    GetUserName(user,&s);

    int nb_items = CountClipboardFormats();
    if (nb_items > 0)
    {
      unsigned int uFormat = EnumClipboardFormats(0);
      #ifdef CMD_LINE_ONLY_NO_DB
      printf("\"Clipboard\";\"format\";\"code\";\"description\";\"user\";\"session_id\";\"data\";\r\n");
      #endif // CMD_LINE_ONLY_NO_DB
      while (uFormat && start_scan && GetLastError() == ERROR_SUCCESS && --nb_items>0)
      {
        //check if ok
        if (IsClipboardFormatAvailable(uFormat) == FALSE)
        {
          uFormat = EnumClipboardFormats(uFormat);
          continue;
        }

        description[0] = 0;
        data[0]= 0;
        if (GetClipboardFormatName(uFormat, description, MAX_LINE_SIZE) != 0)
        {
          hMem = GetClipboardData(uFormat);
          if (hMem != NULL)
          {
            switch(uFormat)
            {
              case CF_TEXT:
                //format
                strncpy(format,"CF_TEXT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Text",DEFAULT_TMP_SIZE);
                //datas
                strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE);
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_BITMAP:
                //format
                strncpy(format,"CF_BITMAP",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Bitmap Picture",DEFAULT_TMP_SIZE);
                //do in bitmap to hexa
                SaveBitmapToHexaStr((HBITMAP)hMem , data, MAX_LINE_SIZE);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_METAFILEPICT:
                //format
                strncpy(format,"CF_METAFILEPICT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Meta-File Picture",DEFAULT_TMP_SIZE);
                //datas
                DatatoHexa(GlobalLock(hMem), GlobalSize(hMem), data, MAX_LINE_SIZE);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
                GlobalUnlock(hMem);
              break;
              case CF_SYLK:
                //format
                strncpy(format,"CF_SYLK",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Microsoft Symbolic Link (SYLK) data",DEFAULT_TMP_SIZE);
                //datas
                snprintf(data,MAX_LINE_SIZE,"%s",(char*)GlobalLock(hMem));
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
              case CF_OEMTEXT:
                //format
                strncpy(format,"CF_OEMTEXT",DEFAULT_TMP_SIZE);
                if (description[0]==0)strncpy(description,"Text (OEM)",DEFAULT_TMP_SIZE);
                //datas
                strncpy(data,GlobalLock(hMem),MAX_LINE_SIZE);
                convertStringToSQL(data, MAX_LINE_SIZE);
                GlobalUnlock(hMem);
                addClipboardtoDB(format, uFormat, description, data, user, session_id, db);
              break;
//.........这里部分代码省略.........
开发者ID:treejames,项目名称:omnia-projetcs,代码行数:101,代码来源:test_clipboard.c

示例6: OpenClipboard

void AuthKeyWindow::PasteFromClipboard()
{
	bool gotClipboardText = false;
	
	// Read key into clipboard
#ifdef TARGET_MSVC	
    bool opened = OpenClipboard(NULL);
    if( opened )
    {
        bool textAvailable = IsClipboardFormatAvailable(CF_TEXT);
        if( textAvailable )
        {
            HANDLE clipTextHandle = GetClipboardData(CF_TEXT);
            if( clipTextHandle )
            {
                char *text = (char *) GlobalLock(clipTextHandle); 
                if(clipTextHandle) 
                { 
                    strncpy( m_key, text, AUTHENTICATION_KEYLEN-1 );
					m_key[AUTHENTICATION_KEYLEN] = '\0';
					gotClipboardText = true;
					
                    GlobalUnlock(text); 
                }
            }
        }
        CloseClipboard();
    }
#elif TARGET_OS_MACOSX
	PasteboardRef clipboard = NULL;
	ItemCount numItems = 0;
	CFDataRef clipboardData = NULL;
	CFStringRef clipboardString;
	
	PasteboardCreate(kPasteboardClipboard, &clipboard);
	if ( clipboard )
	{
		PasteboardGetItemCount(clipboard, &numItems);
		
		// Use the first item, if it exists. Multiple items are only for drag-and-drop, AFAIK
		if ( numItems > 0 )
		{
			PasteboardItemID firstItem;
			PasteboardGetItemIdentifier( clipboard, 1, &firstItem );
			PasteboardCopyItemFlavorData( clipboard, firstItem,
										  CFSTR("public.utf16-plain-text"), &clipboardData);
			if ( clipboardData )
			{
				clipboardString = CFStringCreateWithBytes(NULL, CFDataGetBytePtr(clipboardData),
														  CFDataGetLength(clipboardData),
														  kCFStringEncodingUnicode, false);
				
				// Convert to Latin 1 encoding, and copy as much as will fit
				memset(m_key, 0, sizeof(m_key));
				CFStringGetBytes(clipboardString, CFRangeMake(0, CFStringGetLength(clipboardString)),
								 kCFStringEncodingWindowsLatin1, 0, false,
								 (UInt8 *)m_key, AUTHENTICATION_KEYLEN-1, NULL);
				gotClipboardText = true;
				
				CFRelease(clipboardString);
				CFRelease(clipboardData);
			}
		}
	}
	
	CFRelease( clipboard );
#endif // platform specific

	// Cross-platform code, once we've gotten the clipboard contents into m_key
	//
	if ( gotClipboardText )
	{
		strupr( m_key );
		Authentication_SetKey( m_key );
		Authentication_SaveKey( m_key, App::GetAuthKeyPath() );
	}
}
开发者ID:BITINT,项目名称:DEFCON2,代码行数:77,代码来源:authkey_window.cpp

示例7: IsClipboardFormatAvailable

size_t Clipboard::Get(LPTSTR aBuf)
// If aBuf is NULL, it returns the length of the text on the clipboard and leaves the
// clipboard open.  Otherwise, it copies the clipboard text into aBuf and closes
// the clipboard (UPDATE: But only if the clipboard is still open from a prior call
// to determine the length -- see later comments for details).  In both cases, the
// length of the clipboard text is returned (or the value CLIPBOARD_FAILURE if error).
// If the clipboard is still open when the next MsgSleep() is called -- presumably
// because the caller never followed up with a second call to this function, perhaps
// due to having insufficient memory -- MsgSleep() will close it so that our
// app doesn't keep the clipboard tied up.  Note: In all current cases, the caller
// will use MsgBox to display an error, which in turn calls MsgSleep(), which will
// immediately close the clipboard.
{
	// Seems best to always have done this even if we return early due to failure:
	if (aBuf)
		// It should be safe to do this even at its peak capacity, because caller
		// would have then given us the last char in the buffer, which is already
		// a zero terminator, so this would have no effect:
		*aBuf = '\0';

	UINT i, file_count = 0;
	BOOL clipboard_contains_text = IsClipboardFormatAvailable(CF_NATIVETEXT);
	BOOL clipboard_contains_files = IsClipboardFormatAvailable(CF_HDROP);
	if (!(clipboard_contains_text || clipboard_contains_files))
		return 0;

	if (!mIsOpen)
	{
		// As a precaution, don't give the caller anything from the clipboard
		// if the clipboard isn't already open from the caller's previous
		// call to determine the size of what's on the clipboard (no other app
		// can alter its size while we have it open).  The is to prevent a
		// buffer overflow from happening in a scenario such as the following:
		// Caller calls us and we return zero size, either because there's no
		// CF_TEXT on the clipboard or there was a problem opening the clipboard.
		// In these two cases, the clipboard isn't open, so by the time the
		// caller calls us again, there's a chance (vanishingly small perhaps)
		// that another app (if our thread were preempted long enough, or the
		// platform is multiprocessor) will have changed the contents of the
		// clipboard to something larger than zero.  Thus, if we copy that
		// into the caller's buffer, the buffer might overflow:
		if (aBuf)
			return 0;
		if (!Open())
		{
			// Since this should be very rare, a shorter message is now used.  Formerly, it was
			// "Could not open clipboard for reading after many timed attempts. Another program is probably holding it open."
			Close(CANT_OPEN_CLIPBOARD_READ);
			return CLIPBOARD_FAILURE;
		}
		if (   !(mClipMemNow = g_clip.GetClipboardDataTimeout(clipboard_contains_text ? CF_NATIVETEXT : CF_HDROP))   )
		{
			// v1.0.47.04: Commented out the following that had been in effect when clipboard_contains_files==false:
			//    Close("GetClipboardData"); // Short error message since so rare.
			//    return CLIPBOARD_FAILURE;
			// This was done because there are situations when GetClipboardData can fail indefinitely.
			// For example, in Firefox, pulling down the Bookmarks menu then right-clicking "Bookmarks Toolbar
			// Folder" then selecting "Copy" puts one or more formats on the clipboard that cause this problem.
			// For details, search the forum for TYMED_NULL.
			//
			// v1.0.42.03: For the fix below, GetClipboardDataTimeout() knows not to try more than once
			// for CF_HDROP.
			// Fix for v1.0.31.02: When clipboard_contains_files==true, tolerate failure, which happens
			// as a normal/expected outcome when there are files on the clipboard but either:
			// 1) zero of them;
			// 2) the CF_HDROP on the clipboard is somehow misformatted.
			// If you select the parent ".." folder in WinRar then use the following hotkey, the script
			// would previously yield a runtime error:
			//#q::
			//Send, ^c
			//ClipWait, 0.5, 1
			//msgbox %Clipboard%
			//Return
			Close();
			if (aBuf)
				*aBuf = '\0';
			return CLIPBOARD_FAILURE; // Return this because otherwise, Contents() returns mClipMemNowLocked, which is NULL.
		}
		// Although GlobalSize(mClipMemNow) can yield zero in some cases -- in which case GlobalLock() should
		// not be attempted -- it probably can't yield zero for CF_HDROP and CF_TEXT because such a thing has
		// never been reported by anyone.  Therefore, GlobalSize() is currently not called.
		if (   !(mClipMemNowLocked = (LPTSTR)GlobalLock(mClipMemNow))   )
		{
			Close(_T("GlobalLock"));  // Short error message since so rare.
			return CLIPBOARD_FAILURE;
		}
		// Otherwise: Update length after every successful new open&lock:
		// Determine the length (size - 1) of the buffer than would be
		// needed to hold what's on the clipboard:
		if (clipboard_contains_text)
		{
			// See below for comments.
			mLength = _tcslen(mClipMemNowLocked);
		}
		else // clipboard_contains_files
		{
			if (file_count = DragQueryFile((HDROP)mClipMemNowLocked, 0xFFFFFFFF, NULL, 0))
			{
				mLength = (file_count - 1) * 2;  // Init; -1 if don't want a newline after last file.
				for (i = 0; i < file_count; ++i)
//.........这里部分代码省略.........
开发者ID:HotKeyIt,项目名称:ahkdll,代码行数:101,代码来源:clipboard.cpp

示例8: strlen


//.........这里部分代码省略.........
                
                CloseClipboard();
                
                if (event.diKeyCode == DIK_X)
                {
                    strcpy(buf, &text[blockEnd]);
                    cursorPos = blockStart;
                    strcpy(&text[blockStart], buf);
                }
                
                blockStart = 0;
                blockEnd = 0;
            }
            return;
            
         case DIK_V:
            char buf[SimpleText::MAX_STRING_LENGTH + 1];
            
            //delete anything hilited
            if (blockEnd > 0)
            {
                //save the current state
                saveUndoState();
                
                strcpy(buf, &text[blockEnd]);
                cursorPos = blockStart;
                strcpy(&text[blockStart], buf);
                blockStart = 0;
                blockEnd = 0;
            }
      
            HGLOBAL   hglb; 
            LPTSTR    lptstr; 
            if (!IsClipboardFormatAvailable(CF_TEXT)) 
                return; 
            if (! OpenClipboard(getCanvas()->getHandle()))
                return; 
     
            hglb = GetClipboardData(CF_TEXT); 
            if (hglb != NULL) 
            { 
                lptstr = (char*)GlobalLock(hglb); 
                if (lptstr != NULL) 
                { 
                    int pasteLen = strlen(lptstr);
                    if ((stringLen + pasteLen) > maxStrLen)
                    {
                        pasteLen = maxStrLen - stringLen;
                    }
                                             
                    if (cursorPos == stringLen)
                    {
                        strncpy(&text[cursorPos], lptstr, pasteLen);
                        text[cursorPos + pasteLen] = '\0';
                    }
                    else
                    {
                        strcpy(buf, &text[cursorPos]);
                        strncpy(&text[cursorPos],lptstr, pasteLen);
                        strcpy(&text[cursorPos + pasteLen], buf);
                    }
                    cursorPos += pasteLen;
                    GlobalUnlock(hglb); 
                } 

            } 
开发者ID:AltimorTASDK,项目名称:TribesRebirth,代码行数:67,代码来源:simGuiTextEdit.cpp

示例9: SetFocus

void CRichEditExtn::OnContextMenu(CWnd* pWnd, CPoint point)
{
  if (m_vmenu_items.empty()) {
    CRichEditExtn::OnContextMenu(pWnd, point);
    return;
  }

  SetFocus();
  CMenu menu;
  menu.CreatePopupMenu();

  BOOL bReadOnly = GetStyle() & ES_READONLY;
  DWORD flags = CanUndo() && !bReadOnly ? 0 : MF_GRAYED;

  int iPos(0);
  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, EM_UNDO,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_UNDO)));

  menu.InsertMenu(iPos++, MF_BYPOSITION | MF_SEPARATOR);

  long lStart, lEnd;
  GetSel(lStart, lEnd);
  flags = lStart == lEnd ? MF_GRAYED : 0;
  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, WM_COPY,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_COPY)));

  flags = (flags == MF_GRAYED || bReadOnly) ? MF_GRAYED : 0;
  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, WM_CUT,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_CUT)));

  flags = (flags == MF_GRAYED || bReadOnly) ? MF_GRAYED : 0;
  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, WM_CLEAR,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_DELETE)));

  flags = IsClipboardFormatAvailable(EDIT_CLIPBOARD_TEXT_FORMAT) &&
                                     !bReadOnly ? 0 : MF_GRAYED;
  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, WM_PASTE,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_PASTE)));

  menu.InsertMenu(iPos++, MF_BYPOSITION | MF_SEPARATOR);

  int len = GetWindowTextLength();
  flags = (!len || (lStart == 0 && lEnd == len)) ? MF_GRAYED : 0;

  menu.InsertMenu(iPos++, MF_BYPOSITION | flags, EM_SELECTALL,
                  CString(MAKEINTRESOURCE(IDS_MENUSTRING_SELECTALL)));

  menu.InsertMenu(iPos++, MF_BYPOSITION | MF_SEPARATOR);

  for (size_t i = 0; i < m_vmenu_items.size(); i++) {
      menu.InsertMenu((int)i + iPos, MF_BYPOSITION | m_vmenu_items[i].flags,
                      m_vmenu_items[i].message_number,
                      m_vmenu_items[i].menu_string.c_str());
      if (!m_vmenu_items[i].bEnable)
        menu.EnableMenuItem((int)i + iPos, MF_BYPOSITION | MF_GRAYED);
  }

  if (point.x == -1 || point.y == -1) {
    CRect rc;
    GetClientRect(&rc);
    point = rc.CenterPoint();
    ClientToScreen(&point);
  }

  // For some reason - weird cursor
  m_bContextMenu = true;
  
  // Now show menu
  UINT_PTR nCmd = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
                                      TPM_RETURNCMD | TPM_RIGHTBUTTON, 
                                      point.x, point.y, this);
  // Restore cursor
  m_bContextMenu = false;

  if (nCmd == 0)
    return;

  std::vector<st_context_menu>::iterator iter;
  iter = std::find_if(m_vmenu_items.begin(), m_vmenu_items.end(),
                      equal_cmd(nCmd));
  if (iter != m_vmenu_items.end()) {
    this->GetParent()->SendMessage((UINT)nCmd, iter->wParam, iter->lParam);
    return;
  }

  switch (nCmd) {
    case EM_UNDO:
    case WM_CUT:
    case WM_COPY:
    case WM_CLEAR:
      SendMessage((UINT)nCmd);
      break;
    case WM_PASTE:
      SendMessage(EM_PASTESPECIAL, CF_UNICODETEXT, NULL);
      break;
    case EM_SELECTALL:
      SendMessage(EM_SETSEL, 0, -1);
      break;
    default:
      break;
//.........这里部分代码省略.........
开发者ID:macduff,项目名称:passwordsafe,代码行数:101,代码来源:ControlExtns.cpp

示例10: Paste

void Paste( LPCLASSDATA lpcd )
{
	HANDLE		hData;
	LPCTSTR		lpszText;
	BOOL		bDeleted = FALSE;

	/*
	 *	Are we read-only?
	 */
	if ( ISREADONLY )
		return;

	/*
	 *	Valid format on the clipboard?
	 */
	if ( IsClipboardFormatAvailable( CF_TEXT ) == FALSE )
		return;

	/*
	 *	Any marks set?
	 */
	if ( HasMark( lpcd ))
		bDeleted = Delete( lpcd );

	/*
	 *	Hide the caret.
	 */
	DisplayCaret( lpcd, FALSE );

	/*
	 *	Open the clipboard.
	 */
	if ( OpenClipboard( lpcd->hWnd ))
	{
		/*
		 *	Get data handle.
		 */
		if (( hData = GetClipboardData( CF_TEXT )) != NULL )
		{
			/*
			 *	Lock the data.
			 */
			if (( lpszText = GlobalLock( hData )) != NULL )
			{
				/*
				 *	Insert the clipboard contents
				 *	into the text.
				 */
				InsertText( lpcd, lpcd->ptCaretPos.y, lpcd->ptCaretPos.x, lpszText, &lpcd->ptCaretPos, ! bDeleted );

				/*
				 *	Unlock the data handle.
				 */
				GlobalUnlock( hData );
			}
		}
		/*
		 *	Close the clipboard.
		 */
		CloseClipboard();
	}

	/*
	 *	Update column position.
	 */
	lpcd->nLastColumnPos = GetCaretOffset( lpcd, lpcd->ptCaretPos.x );

	/*
	 *	Is the caret inside
	 *	the view?
	 */
	if ( CaretInView( lpcd ) == FALSE )
		/*
		 *	No. Move the view to
		 *	make it visible.
		 */
		MakeCaretVisibleNoRedraw( lpcd );

	/*
	 *	Re-render.
	 */
	InvalidateRect( lpcd->hWnd, NULL, FALSE );

	/*
	 *	Setup scrollers.
	 */
	SetupHScroller( lpcd );
	SetupVScroller( lpcd );

	/*
	 *	We are modified.
	 */
	SetModified( lpcd, TRUE );

	/*
	 *	Show the caret.
	 */
	DisplayCaret( lpcd, TRUE );
}
开发者ID:jcbaar,项目名称:Brainchild,代码行数:99,代码来源:clip.c

示例11: OnCanPaste

LRESULT OnCanPaste( HWND hWnd, WPARAM wParam, LPARAM lParam, LPCLASSDATA lpcd )
{
	return ( BOOL )(( ! ISREADONLY ) && IsClipboardFormatAvailable( CF_TEXT ));
}
开发者ID:jcbaar,项目名称:Brainchild,代码行数:4,代码来源:clip.c

示例12: InitializeMenuItems

void InitializeMenuItems(HMENU popupMenu)
{
    int count = GetMenuItemCount(popupMenu);
    for (int i = 0; i < count; ++i)
    {
        MENUITEMINFO info;
        info.cbSize = sizeof(info);
        info.fMask = MIIM_ID | MIIM_STATE;

        if (!GetMenuItemInfo(popupMenu, i, TRUE, &info))
            break;

        bool check = false;
        bool disable = false;

        switch (info.wID)
        {
        case ID_EDIT_COPY:
            disable = g_text.empty();
            break;

        case ID_EDIT_PASTE:
            disable = !IsClipboardFormatAvailable(CF_TEXT);
            break;

        case ID_EDIT_DECREASETEXTSIZE:
            disable = (g_fontSize == g_minFontSize);
            break;

        case ID_VIEW_SHOWMAGNIFIER:
            check = g_magnifier.visible;
            break;

        case ID_MAGNIFIERTYPE_VECTOR:
            check = (g_magnifier.type == MagnifierInfo::Vector);
            disable = (g_measuringMode != DWRITE_MEASURING_MODE_NATURAL);
            break;

        case ID_MAGNIFIERTYPE_PIXELS:
            check = (g_magnifier.type == MagnifierInfo::Pixel);
            break;

        case ID_MAGNIFIERTYPE_SUBPIXELS:
            check = (g_magnifier.type == MagnifierInfo::Subpixel);
            disable = (g_rendererID == RendererD2D);
            break;

        case ID_MAGNIFIERSCALE_3X:
            check = (g_magnifier.scale == 3);
            break;

        case ID_MAGNIFIERSCALE_6X:
            check = (g_magnifier.scale == 6);
            break;

        case ID_OPTIONS_NATURALMODE:
            check = (g_measuringMode == DWRITE_MEASURING_MODE_NATURAL);
            break;

        case ID_OPTIONS_GDICLASSICMODE:
            check = (g_measuringMode == DWRITE_MEASURING_MODE_GDI_CLASSIC);
            break;

        case ID_OPTIONS_GDINATURALMODE:
            check = (g_measuringMode == DWRITE_MEASURING_MODE_GDI_NATURAL);
            break;

        case ID_OPTIONS_USEDIRECT2D:
            check = (g_rendererID == RendererD2D);
            break;

        case ID_OPTIONS_USEDIRECTWRITE:
            check = (g_rendererID == RendererDWrite);
            break;
        }

        UINT newState = 
            (check ? MFS_CHECKED : 0) | 
            (disable ? MFS_DISABLED : 0);

        if (newState != info.fState)
        {
            info.fMask = MIIM_STATE;
            info.fState = newState;
            SetMenuItemInfo(popupMenu, i, TRUE, &info);
        }
    }
}
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:88,代码来源:RenderTest.cpp

示例13: WndProc

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static PTSTR pText ;
     BOOL         bEnable ;
     HGLOBAL      hGlobal ;
     HDC          hdc ;
     PTSTR        pGlobal ;
     PAINTSTRUCT  ps ;
     RECT         rect ;
     
     switch (message)
     {
     case WM_CREATE:
          SendMessage (hwnd, WM_COMMAND, IDM_EDIT_RESET, 0) ;
          return 0 ;

    case WM_INITMENUPOPUP:
          EnableMenuItem ((HMENU) wParam, IDM_EDIT_PASTE,
               IsClipboardFormatAvailable (CF_TCHAR) ? MF_ENABLED : MF_GRAYED) ;

          bEnable = pText ? MF_ENABLED : MF_GRAYED ;

          EnableMenuItem ((HMENU) wParam, IDM_EDIT_CUT,   bEnable) ;
          EnableMenuItem ((HMENU) wParam, IDM_EDIT_COPY,  bEnable) ;
          EnableMenuItem ((HMENU) wParam, IDM_EDIT_CLEAR, bEnable) ;
          break ;
          
     case WM_COMMAND:
          switch (LOWORD (wParam))
          {
          case IDM_EDIT_PASTE:
               OpenClipboard (hwnd) ;

               if (hGlobal = GetClipboardData (CF_TCHAR))
               {
                    pGlobal = GlobalLock (hGlobal) ;

                    if (pText)
                    {
                         free (pText) ;
                         pText = NULL ;
                    }
                    pText = malloc (GlobalSize (hGlobal)) ;
                    lstrcpy (pText, pGlobal) ;
                    InvalidateRect (hwnd, NULL, TRUE) ;
               }
               CloseClipboard () ;
               return 0 ;

          case IDM_EDIT_CUT:
          case IDM_EDIT_COPY:
               if (!pText)
                    return 0 ;

               hGlobal = GlobalAlloc (GHND | GMEM_SHARE, 
                                      (lstrlen (pText) + 1) * sizeof (TCHAR)) ;
               pGlobal = GlobalLock (hGlobal) ;
               lstrcpy (pGlobal, pText) ;
               GlobalUnlock (hGlobal) ;

               OpenClipboard (hwnd) ;
               EmptyClipboard () ;
               SetClipboardData (CF_TCHAR, hGlobal) ;
               CloseClipboard () ;

               if (LOWORD (wParam) == IDM_EDIT_COPY)
                    return 0 ;        
                                             // fall through for IDM_EDIT_CUT
          case IDM_EDIT_CLEAR:
               if (pText)
               {
                    free (pText) ;
                    pText = NULL ;
               }
               InvalidateRect (hwnd, NULL, TRUE) ;
               return 0 ;

          case IDM_EDIT_RESET:
               if (pText)
               {
                    free (pText) ;
                    pText = NULL ;
               }

               pText = malloc ((lstrlen (szDefaultText) + 1) * sizeof (TCHAR)) ;
               lstrcpy (pText, szDefaultText) ;
               InvalidateRect (hwnd, NULL, TRUE) ;
               return 0 ;
          }
          break ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;

          GetClientRect (hwnd, &rect) ;
          
          if (pText != NULL)
               DrawText (hdc, pText, -1, &rect, DT_EXPANDTABS | DT_WORDBREAK) ;

          EndPaint (hwnd, &ps) ;
//.........这里部分代码省略.........
开发者ID:Jeanhwea,项目名称:petzold-pw5e,代码行数:101,代码来源:ClipText.c

示例14: winClipboardFlushXEvents


//.........这里部分代码省略.........
                /*
                 * Notify the requesting window that
                 * the operation has completed
                 */
                iReturn = XSendEvent(pDisplay,
                                     eventSelection.requestor,
                                     False, 0L, (XEvent *) &eventSelection);
                if (iReturn == BadValue || iReturn == BadWindow) {
                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
                           "XSendEvent () failed\n");
                }
                break;
            }

            /* Close clipboard if we have it open already */
            if (GetOpenClipboardWindow() == hwnd) {
                CloseClipboard();
            }

            /* Access the clipboard */
            if (!OpenClipboard(hwnd)) {
                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
                       "OpenClipboard () failed: %08x\n", (unsigned int)GetLastError());

                /* Abort */
                fAbort = TRUE;
                goto winClipboardFlushXEvents_SelectionRequest_Done;
            }

            /* Indicate that clipboard was opened */
            fCloseClipboard = TRUE;

            /* Check that clipboard format is available */
            if (data->fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
                static int count;       /* Hack to stop acroread spamming the log */
                static HWND lasthwnd;   /* I've not seen any other client get here repeatedly? */

                if (hwnd != lasthwnd)
                    count = 0;
                count++;
                if (count < 6)
                    ErrorF("winClipboardFlushXEvents - CF_UNICODETEXT is not "
                           "available from Win32 clipboard.  Aborting %d.\n",
                           count);
                lasthwnd = hwnd;

                /* Abort */
                fAbort = TRUE;
                goto winClipboardFlushXEvents_SelectionRequest_Done;
            }
            else if (!data->fUseUnicode && !IsClipboardFormatAvailable(CF_TEXT)) {
                ErrorF("winClipboardFlushXEvents - CF_TEXT is not "
                       "available from Win32 clipboard.  Aborting.\n");

                /* Abort */
                fAbort = TRUE;
                goto winClipboardFlushXEvents_SelectionRequest_Done;
            }

            /* Setup the string style */
            if (event.xselectionrequest.target == XA_STRING)
                xiccesStyle = XStringStyle;
#ifdef X_HAVE_UTF8_STRING
            else if (event.xselectionrequest.target == atomUTF8String)
                xiccesStyle = XUTF8StringStyle;
#endif
开发者ID:mirror,项目名称:xserver,代码行数:67,代码来源:xevents.c

示例15: clip_ISCLIPBOARDFORMATAVAILABLE

int
clip_ISCLIPBOARDFORMATAVAILABLE(ClipMachine * mp)
{
	_clip_retl(mp, IsClipboardFormatAvailable(_clip_parni(mp,1)));
	return 0;
}
开发者ID:amery,项目名称:clip-itk,代码行数:6,代码来源:_clipboard.c


注:本文中的IsClipboardFormatAvailable函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。