|
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:
CSharedFile sf(GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
CArchive ar (&sf, CArchive::store);
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);
}
}
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);
}
}
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));
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);
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.
|
|
|
|
|
Hello!
I have tried to Close my SDI Apllication with Destroy(); or with OnClose(); but it didnt works!
Does somebody know what function i have to use?
Thanks a lot!
Ronny
|
|
|
|
|
Try CMainFrame's PostMessage(WM_CLOSE)
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hello ant thanks!!
But it didnt works, is there another way to close the App?
|
|
|
|
|
You might need to process the WM_CLOSE message.
void CMainFrame::OnClose()
{
CFrameWnd::OnClose();
return;
}
|
|
|
|
|
Thanks that was a good idea, but i have forgotten to tell i need a function wich i can start in the View Class. I have tried to make a public function in Mainframe and use it in the View Class and it was complile able but it also didnt works...
|
|
|
|
|
Try this:
CWnd *pWnd;
pWnd = CWnd::FindWindow(NULL, _T("MyWindowsName"));
pWnd->SendMessage(WM_CLOSE);
Let me know if it works.
Regards,
Testtests
|
|
|
|
|
From CView:
AfxGetMainWnd()->SendMessage(WM_CLOSE);
or
AfxGetMainWnd()->PostMessage(WM_CLOSE);
|
|
|
|
|
probably the most accurate closing of app is this
HANDLE handle
DWORD lpExitCode;
handle=GetCurrentProcess();
GetExitCodeProcess(handle,&lpExitCode);
TerminateProcess(handle,lpExitCode);
Clean Exit right ?
gabby
|
|
|
|
|
try using
AfxGetMainWnd()->PostQuitMessage(0);
good luck
Imtiaz Qureshi
|
|
|
|
|
AfxGetApp()->GetMainWnd()->PostMessage(WM_CLOSE);
INTP
|
|
|
|
|
THANKS TO ALL!!!
Thank you very very very much!! (Sorry for my late Answer!!!) It works great!!
Thanks!!
Ronny
|
|
|
|
|
A doc file has some properties called summary and i want to do this in my app, in fact my app works with rtf files.For example i have enter some properties like title and i saw that Microsoft put them at the end of the doc file wnhen you press CTRL+Q in Windows Commander.I want to do the same in my app.Does somebody know how can i do this.Every suggestion is appreciated.Thanks a lot.
|
|
|
|
|
Hi friends,
I am saving my reports in excel. First i format my reports in html tags and then open the html files as excel file programattically. The problem is Excel worksheet can hold only 65535 rows. My reports have enormous data to save. So i am generating multiple html files with the max of 65500 rows.
Now , i need to know how to convert the html files into excel worksheets of a single excel workbook.
Please help me out.
Thanks in advance
Kumari
|
|
|
|
|
HI,
How can i add TOOL bar in MFC dailog based window.
Not in SDI or other only in MFC dialog based
send me sample or code
thanx
|
|
|
|
|
|
thanx it helped me ..
But if i want to add my images in Tool Bar.
for example myown BMP / JPG etc..
how can i do it.
BCoz i cannot draw image in the ToolBar editor ..
wt is the way to insert my own image in tool bar.
and of wt type of image i can insert into it ,, e.g.
BMP or JPG . or ICON .???
thanx
|
|
|
|
|
You'll find a ton of articles on toolbars here:
http://www.codeproject.com/docking/[^].
As I don't know why you can't use the toolbar editor - only 16 colors? want to load dynamically? - I really don't know what article might be of further interest. You might also want to check the bitmap articles on classes for conversions.
|
|
|
|
|
i seem to be having trouble getting keybd_event to simulate keys such as ".!@#$%" anything non-alphanumeric
in some cases it causes some problem like putting the system into standby
my guess is that i need to something else for the scan code, however MSDN says that that parameter is not used, that or there is something that needs to be put in the ExtraInfo parameter other than 0
anyone know how to get around this?
note: im using Windows M.E. and microsofts note about this function being deprecated by SendInput() only applies to Windows NT/2000/XP
|
|
|
|
|
Hi,good day.
I want control USB device in vc program.The USB device's driver have been installed.I know use to WIN32's API function CreateFile(...) open the USB device,and use to WIN32's API function ReadFile(),WriteFile() read or write this device.
I question:
How to use this WIN32's API function to control USB device!
|
|
|
|
|
Visit the usb.org site. Get the IOCTLS you need. Read the documentation. You may need to read the USB specs too.
Bikram Singh
|
|
|
|
|
How to capture and save the selected dialog as ".bmp" in VC++?
Aparna
|
|
|
|
|
|
|
Hi.
I'm trying to use direcdraw in order to make some image processing for a project of my own. In the samples that came with the SDK there is one "stillcap" that I modified, however, it is one shot at time, and what I need is to intercept the stream, to process it, and finally to display it, almost in real time. I don't know so much about directx, so if someone can help me I would appreciate it a lot.
|
|
|
|