Click here to Skip to main content
15,914,014 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Simulating keys Pin
Johan Rosengren13-Jun-04 19:45
Johan Rosengren13-Jun-04 19:45 
GeneralLinker error "fatal error LNK1201: error writing to program database" Pin
User 665812-Jun-04 7:13
User 665812-Jun-04 7:13 
GeneralRe: Linker error "fatal error LNK1201: error writing to program database" Pin
Ghazi H. Wadi12-Jun-04 8:18
Ghazi H. Wadi12-Jun-04 8:18 
GeneralHide From CTRL+ALT+DEL Pin
Archer28212-Jun-04 6:59
Archer28212-Jun-04 6:59 
GeneralRe: Hide From CTRL+ALT+DEL Pin
gamitech12-Jun-04 8:29
gamitech12-Jun-04 8:29 
QuestionCan put a Tree in a List Pin
Tcpip200512-Jun-04 6:09
Tcpip200512-Jun-04 6:09 
AnswerRe: Can put a Tree in a List Pin
bikram singh13-Jun-04 1:44
bikram singh13-Jun-04 1:44 
GeneralProgramming with clipboard problem Pin
nguyenvhn12-Jun-04 3:28
nguyenvhn12-Jun-04 3:28 
Hello every body.

I am developing an application with clipboard supporting. When users press Ctrl+C or Ctrl+X, the application copies three types of data into clipboard: application defined data, text only data, windows metafile data.

I've used COleDataSource to implement that capacities. The below is my code:
//Application defined data implementation
CSharedFile sf(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
CArchive ar (&sf, CArchive::store);
//Serialize application defined data to ar;
ar.Close();

DWORD dwLen = (DWORD) sf.GetLength();
HGLOBAL hMem = sf.Detach();
COleDataSource* pSource=NULL;
if (hMem){
  hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
  if (hMem){
    pSource = new COleDataSource();
    pSource->CacheGlobalData(CF_APPLICATIONDEFINED, hMem);
  }
}

//Text clipboard implementation
CSharedFile txtsf(GMEM_ZEROINIT|GMEM_DDESHARE|GMEM_MOVEABLE);
txtsf.Write((LPCTSTR)st, st.GetLength()+1);

dwLen = (DWORD) txtsf.GetLength();
hMem = txtsf.Detach();
if (hMem){
  hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
  if (hMem){
    if (!pSource)
      pSource = new COleDataSource();
      pSource->CacheGlobalData(CF_TEXT, hMem);
    }
}

//Metafile clipboard implementation
CDC DC;
CDC* pDC = NULL;
CMetaFileDC MetaDC;
DC.CreateCompatibleDC(NULL);
CRect rect(0,0,width, height);
CRect rectMeta(0,0,0,0);	
rectMeta.left  = MulDiv(rect.left*100, DC.GetDeviceCaps(HORZSIZE),  DC.GetDeviceCaps(HORZRES));
rectMeta.top = MulDiv(rect.top*100, DC.GetDeviceCaps(VERTSIZE), DC.GetDeviceCaps(VERTRES));
rectMeta.right  = MulDiv(rect.right*100, DC.GetDeviceCaps(HORZSIZE),  DC.GetDeviceCaps(HORZRES));
rectMeta.bottom = MulDiv(rect.bottom*100, DC.GetDeviceCaps(VERTSIZE), DC.GetDeviceCaps(VERTRES));
// Create an enhanced Metafile DC
MetaDC.CreateEnhanced(&DC, NULL, rectMeta, _T("Anything\0Image\0\0"));
MetaDC.SetAttribDC(DC.m_hDC);
MetaDC.SetMapMode(MM_TEXT);

pDC = &MetaDC;
CBrush brush;
brush.CreateSysColorBrush(COLOR_WINDOW);
pDC->FillRect(rect, &brush);
brush.DeleteObject();

Draw(pDC);
	
STGMEDIUM std;
std.tymed=TYMED_ENHMF;
std.hEnhMetaFile=MetaDC.CloseEnhanced();

if (!pSource)
  pSource = new COleDataSource();

pSource->CacheData(CF_ENHMETAFILE, &std);

//Put on clipboard
pSource->SetClipboard();

Everything worked well but when application was closed, an exception occured in an ole module. After application has been closed, I could not paste the image to Paint either. But I could paste text to Notepad or ran application again and pasted to it well.

I hope you could understand what I mean.
Does anyone show me why?

Thanks for reading.
QuestionHow can i close my SDI Applcation? Pin
RonnyS11-Jun-04 22:16
RonnyS11-Jun-04 22:16 
AnswerRe: How can i close my SDI Applcation? Pin
bneacetp11-Jun-04 22:24
bneacetp11-Jun-04 22:24 
GeneralRe: How can i close my SDI Applcation? Pin
RonnyS11-Jun-04 22:40
RonnyS11-Jun-04 22:40 
GeneralRe: How can i close my SDI Applcation? Pin
vcplusplus12-Jun-04 2:17
vcplusplus12-Jun-04 2:17 
GeneralRe: How can i close my SDI Applcation? Pin
RonnyS12-Jun-04 2:39
RonnyS12-Jun-04 2:39 
GeneralRe: How can i close my SDI Applcation? Pin
testtests12-Jun-04 11:47
testtests12-Jun-04 11:47 
GeneralRe: How can i close my SDI Applcation? Pin
vcplusplus13-Jun-04 3:22
vcplusplus13-Jun-04 3:22 
AnswerRe: How can i close my SDI Applcation? Pin
gamitech12-Jun-04 11:17
gamitech12-Jun-04 11:17 
AnswerRe: How can i close my SDI Applcation? Pin
ImtiazQureshi12-Jun-04 21:48
ImtiazQureshi12-Jun-04 21:48 
AnswerRe: How can i close my SDI Applcation? Pin
John R. Shaw13-Jun-04 11:30
John R. Shaw13-Jun-04 11:30 
GeneralRe: How can i close my SDI Applcation? Pin
RonnyS15-Jun-04 3:47
RonnyS15-Jun-04 3:47 
GeneralA doc file has some properties called summary and i want to do this in my app Pin
Filomela11-Jun-04 21:24
Filomela11-Jun-04 21:24 
GeneralSaving multiple html files to excel worksheets Pin
Member 51425211-Jun-04 18:54
Member 51425211-Jun-04 18:54 
Questionhow can i add TOOL Bar in MFC Dialog based window Pin
Zeeshan Bilal11-Jun-04 18:15
Zeeshan Bilal11-Jun-04 18:15 
AnswerRe: how can i add TOOL Bar in MFC Dialog based window Pin
Johan Rosengren11-Jun-04 21:01
Johan Rosengren11-Jun-04 21:01 
GeneralRe: how can i add TOOL Bar in MFC Dialog based window Pin
Zeeshan Bilal11-Jun-04 21:22
Zeeshan Bilal11-Jun-04 21:22 
GeneralRe: how can i add TOOL Bar in MFC Dialog based window Pin
Johan Rosengren11-Jun-04 22:13
Johan Rosengren11-Jun-04 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.