BOOL CallContextDayNote(SYSTEMTIME Time, HWND hCalendar) { CStringArray arr; arr.Add(_l("New reminder")); arr.Add(_l("Add date to clipboard")); int iSelection=SelectFromMenu(arr,0); if(iSelection<0){ return 0; } if(iSelection==0){ return -1; } CString s=""; COleDateTime tm;//=COleDateTime(Time); tm.SetDate(Time.wYear,Time.wMonth,Time.wDay); if(strlen(szDateFormat)==0){ s=DateFormat(tm,FALSE); }else{ SYSTEMTIME EventTime; tm.GetAsSystemTime(EventTime); char szTmp[1020]={0}; GetDateFormat(LOCALE_USER_DEFAULT,0,&EventTime,szDateFormat,szTmp,sizeof(szTmp)); s=szTmp; } BOOL bThroughGlobal=0; USES_CONVERSION; SetClipboardText(A2W(s),bThroughGlobal,0); return 0; };
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; }
static void SysMenu_OnCopyClipboard(HWND hDlg, int x, int y) { Minimal::ProcessHeapString result; for (int i = 0; i < _countof(s_listColumns); ++i) { if (s_listColumns[i].fmt == LVCFMT_LEFT) { result += s_listColumns[i].text; for (int j = ::lstrlen(s_listColumns[i].text); j < s_listColumns[i].cx / 7; ++j) result += _T(" "); } else { for (int j = ::lstrlen(s_listColumns[i].text); j < s_listColumns[i].cx / 7; ++j) result += _T(" "); result += s_listColumns[i].text; } } result += _T("\x0D\x0A"); HWND listWnd = GetDlgItem(hDlg, IDC_LIST_SCORELINE); int count = ListView_GetItemCount(listWnd); for (int i = 0; i < count; ++i) { for (int j = 0; j < _countof(s_listColumns); ++j) { TCHAR text[64]; ListView_GetItemText(listWnd, i, j, text, _countof(text)); if (s_listColumns[j].fmt == LVCFMT_LEFT) { result += text; for (int k = ::lstrlen(text); k < s_listColumns[j].cx / 7; ++k) result += _T(" "); } else { for (int k = ::lstrlen(text); k < s_listColumns[j].cx / 7; ++k) result += _T(" "); result += text; } } result += _T("\x0D\x0A"); } SetClipboardText(result, result.GetSize()); }
void CXTPEyeDropper::OnLButtonUp(UINT nFlags, CPoint point) { CWnd::OnLButtonUp(nFlags, point); if (::GetCapture() == m_hWnd) { CPoint pt; ::GetCursorPos(&pt); CWindowDC dc(NULL); m_color = dc.GetPixel(pt.x, pt.y); CWnd* pWnd = GetOwner(); if (pWnd) { pWnd->SendMessage(WM_XTP_EYEDROPPER_SELECT, (WPARAM)m_color, MAKELPARAM(pt.x,pt.y)); } if (m_bSetClipboard) { CString strClip; strClip.Format(_T("%i,%i,%i"), GetRValue(m_color), GetGValue(m_color), GetBValue(m_color)); SetClipboardText(strClip); } m_hCurPrevious = NULL; ReleaseCapture(); RedrawWindow(); } }
INT_PTR CALLBACK CHdrPropSheet::DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { PROPSHEETPAGE *pPSP = reinterpret_cast<PROPSHEETPAGE *>(lParam); ::SetWindowLongPtr(hwnd, DWLP_USER, pPSP->lParam); CAnalyzer ana; if (ana.Open(hwnd, reinterpret_cast<CHdrPropSheet *>(pPSP->lParam)->m_szPath)) { ana.Close(); HWND hwndHdrList = ::GetDlgItem(hwnd, IDC_HDR_LIST); HWND hwndDirList = ::GetDlgItem(hwnd, IDC_DIR_LIST); HWND hwndSecList = ::GetDlgItem(hwnd, IDC_SEC_LIST); ::ShowWindow(hwndHdrList, SW_NORMAL); ::ShowWindow(hwndDirList, SW_HIDE); ::ShowWindow(hwndSecList, SW_HIDE); ana.AnalyzeExeHdrInit(hwndHdrList, hwndDirList, hwndSecList); ana.AnalyzeExeHdr(hwndHdrList, hwndDirList, hwndSecList); } } return TRUE; // case WM_DESTROY: // reinterpret_cast<CImpPropSheet *>(::GetWindowLongPtr(hwnd, DWLP_USER))->Release(); // return TRUE; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { switch (LOWORD(wParam)) { case IDC_HDR: ::ShowWindow(::GetDlgItem(hwnd, IDC_HDR_LIST), SW_NORMAL); ::ShowWindow(::GetDlgItem(hwnd, IDC_DIR_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(hwnd, IDC_SEC_LIST), SW_HIDE); return TRUE; case IDC_DIR: ::ShowWindow(::GetDlgItem(hwnd, IDC_HDR_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(hwnd, IDC_DIR_LIST), SW_NORMAL); ::ShowWindow(::GetDlgItem(hwnd, IDC_SEC_LIST), SW_HIDE); return TRUE; case IDC_SEC: ::ShowWindow(::GetDlgItem(hwnd, IDC_HDR_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(hwnd, IDC_DIR_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(hwnd, IDC_SEC_LIST), SW_NORMAL); return TRUE; case IDC_SAVE: { CWnd wnd; wnd.Attach(hwnd); CString strWork; strWork.LoadString(IDS_FILE_MATCH); CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR, strWork, &wnd); if (dlg.DoModal() == IDOK) { CStdioFile file; if (file.Open(dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive | CFile::typeText)) { try { file.WriteString(GetText(hwnd, false)); } catch (CException *e) { e->Delete(); } file.Close(); } } wnd.Detach(); return TRUE; } case IDC_COPY: SetClipboardText(hwnd, GetText(hwnd, true)); return TRUE; } } break; } return FALSE; }
BOOL OnKeyDown(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/) { BOOL rc = FALSE; // convert virtual key code TCHAR ch = (TCHAR) wParam; // if the most significant bit is set, the key is down BOOL bCtrlIsDown = GetAsyncKeyState(VK_CONTROL) < 0; if (bCtrlIsDown && (ch == _T('C'))) { rc = TRUE; // user hit Ctrl-C -- copy contents to clipboard if (::IsWindow(hWnd)) { TCHAR *pszDivider = _T("---------------------------\r\n"); TCHAR *pszText = new TCHAR [8192]; lstrcpy(pszText, pszDivider); size_t n = lstrlen(pszText); ::GetWindowText(hWnd, &pszText[n], 1000); // caption _tcscat(pszText, _T("\r\n")); _tcscat(pszText, pszDivider); HWND hMsgHwnd = ::GetDlgItem(hWnd, MessageControlId); if (::IsWindow(hMsgHwnd)) { n = lstrlen(pszText); ::GetWindowText(hMsgHwnd, &pszText[n], 4000); // message _tcscat(pszText, _T("\r\n")); _tcscat(pszText, pszDivider); } TCHAR szClassName[MAX_PATH]; TCHAR szButton[200]; HWND hwndChild = ::GetWindow(hWnd, GW_CHILD); while (hwndChild) { if (::IsWindow(hwndChild)) { ::GetClassName(hwndChild, szClassName, COUNTOF(szClassName)-2); if (_tcsicmp(szClassName, _T("Button")) == 0) { ::GetWindowText(hwndChild, szButton, COUNTOF(szButton)-1); // button text size_t i = lstrlen(pszText); TCHAR *cp = szButton; while (*cp) { if (*cp != _T('&')) pszText[i++] = *cp; cp++; } pszText[i] = 0; _tcscat(pszText, _T(" ")); } } hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT); } _tcscat(pszText, _T("\r\n")); _tcscat(pszText, pszDivider); SetClipboardText(pszText); delete [] pszText; } } return rc; }
BOOL CMFCExampleApp::InitInstance () { new_t new_array_f = &(::operator new[]); new_dbg_crt_t new_dbg_crt_array_f = &(::operator new[]); #ifdef _DEBUG new_dbg_mfc_t new_dbg_mfc_array_f = &(::operator new[]); #endif new_t new_f = &(::operator new ); new_dbg_crt_t new_dbg_crt_f = &(::operator new ); #ifdef _DEBUG new_dbg_mfc_t new_dbg_mfc_f = &(::operator new ); #endif void * p1 = FindRealCode (new_array_f); void * p2 = FindRealCode (new_dbg_crt_array_f); #ifdef _DEBUG void * p3 = FindRealCode (new_dbg_mfc_array_f); #endif void * p4 = FindRealCode (new_f); void * p5 = FindRealCode (new_dbg_crt_f); #ifdef _DEBUG void * p6 = FindRealCode (new_dbg_mfc_f); #endif #ifdef _DEBUG #ifndef _UNICODE #if _MFC_VER == 0x0700 // VS 2003 #define MFCDLLNAME _T("mfc70d.dll") #elif _MFC_VER == 0x0800 // VS 2005 #define MFCDLLNAME _T("mfc80d.dll") #elif _MFC_VER == 0x0900 // VS 2008 #define MFCDLLNAME _T("mfc90d.dll") #elif _MFC_VER == 0x0A00 // VS 2010 #define MFCDLLNAME _T("mfc100d.dll") #elif _MFC_VER == 0x0B00 // VS 2012 #define MFCDLLNAME _T("mfc110d.dll") #endif #else #if _MFC_VER == 0x0700 // VS 2003 #define MFCDLLNAME _T("mfc70ud.dll") #elif _MFC_VER == 0x0800 // VS 2005 #define MFCDLLNAME _T("mfc80ud.dll") #elif _MFC_VER == 0x0900 // VS 2008 #define MFCDLLNAME _T("mfc90ud.dll") #elif _MFC_VER == 0x0A00 // VS 2010 #define MFCDLLNAME _T("mfc100ud.dll") #elif _MFC_VER == 0x0B00 // VS 2012 #define MFCDLLNAME _T("mfc110ud.dll") #elif _MFC_VER == 0x0C00 // VS 2013 #define MFCDLLNAME _T("mfc120ud.dll") #endif #endif #else #ifndef _UNICODE #if _MFC_VER == 0x0700 // VS 2003 #define MFCDLLNAME _T("mfc70.dll") #elif _MFC_VER == 0x0800 // VS 2005 #define MFCDLLNAME _T("mfc80.dll") #elif _MFC_VER == 0x0900 // VS 2008 #define MFCDLLNAME _T("mfc90.dll") #elif _MFC_VER == 0x0A00 // VS 2010 #define MFCDLLNAME _T("mfc100.dll") #elif _MFC_VER == 0x0B00 // VS 2012 #define MFCDLLNAME _T("mfc110.dll") #endif #else #if _MFC_VER == 0x0700 // VS 2003 #define MFCDLLNAME _T("mfc70u.dll") #elif _MFC_VER == 0x0800 // VS 2005 #define MFCDLLNAME _T("mfc80u.dll") #elif _MFC_VER == 0x0900 // VS 2008 #define MFCDLLNAME _T("mfc90u.dll") #elif _MFC_VER == 0x0A00 // VS 2010 #define MFCDLLNAME _T("mfc100u.dll") #elif _MFC_VER == 0x0B00 // VS 2012 #define MFCDLLNAME _T("mfc110u.dll") #elif _MFC_VER == 0x0C00 // VS 2013 #define MFCDLLNAME _T("mfc120u.dll") #endif #endif #endif HMODULE module = GetModuleHandle (MFCDLLNAME); if (NULL == module) { return FALSE; } int o1 = GetProcOrdinal (module, p1); int o2 = GetProcOrdinal (module, p2); #ifdef _DEBUG int o3 = GetProcOrdinal (module, p3); #else int o3 = -2; #endif int o4 = GetProcOrdinal (module, p4); int o5 = GetProcOrdinal (module, p5); #ifdef _DEBUG int o6 = GetProcOrdinal (module, p6); #else int o6 = -2; #endif TCHAR msg[256]; _stprintf (msg, _T ("%d, %d, %d, %d, %d, %d"), o1, o2, o3, o4, o5, o6); SetClipboardText (msg); MessageBox (NULL, msg, _T ("MFC ordinals"), MB_ICONINFORMATION | MB_OK); return FALSE; }