Click here to Skip to main content
15,888,208 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: IHtmlPopup Error Pin
Ranjan Banerji8-Jul-06 7:37
Ranjan Banerji8-Jul-06 7:37 
QuestionYow can I serialize Color object (GDI+) Pin
NoName II7-Jul-06 19:34
NoName II7-Jul-06 19:34 
AnswerRe: Yow can I serialize Color object (GDI+) Pin
NiceNaidu7-Jul-06 20:59
NiceNaidu7-Jul-06 20:59 
GeneralRe: Yow can I serialize Color object (GDI+) Pin
NoName II7-Jul-06 21:09
NoName II7-Jul-06 21:09 
GeneralRe: Yow can I serialize Color object (GDI+) Pin
NiceNaidu7-Jul-06 21:18
NiceNaidu7-Jul-06 21:18 
GeneralRe: Yow can I serialize Color object (GDI+) Pin
NoName II7-Jul-06 21:21
NoName II7-Jul-06 21:21 
GeneralRe: Yow can I serialize Color object (GDI+) Pin
NoName II7-Jul-06 21:32
NoName II7-Jul-06 21:32 
GeneralRe: Yow can I serialize Color object (GDI+) Pin
NiceNaidu7-Jul-06 21:52
NiceNaidu7-Jul-06 21:52 
Copying Data to the Clipboard
Having registered a Clipboard format, we can look at copying data to the Clipboard. Let's first look at the OnUpdate. . . handler for the Edit Copy command:

void CClipView::OnUpdateEditCopy(CCmdUI* pCmdUI)<br />
{<br />
    int i = m_wndList.GetSelCount();<br />
    pCmdUI->Enable(i > 0 ? TRUE : FALSE);<br />
}

If no items are selected, the command is disabled. This does two things: It shows the user the command won't do anything (it's grayed out), and it prevents us from getting Copy commands when there is nothing to copy. Let's look at the code for doing the actual copy operation:

void CClipView::OnEditCopy()<br />
{<br />
    // Get the number of selected items.<br />
    int iCount = m_wndList.GetSelCount();<br />
    ASSERT(iCount > 0);<br />
    // Get the list of selection IDs.<br />
    int* pItems = new int [iCount];<br />
    m_wndList.GetSelItems(iCount, pItems);<br />
    // Create a list.<br />
    CMyObList ObList;<br />
    // Add all the items to the list.<br />
    int i;<br />
    CMyObj* pObj;<br />
    for (i=0; i<iCount; i++) {<br />
        pObj = (CMyObj*) m_wndList.GetItemData(pItems[i]);<br />
        ObList.Append(pObj);<br />
    }<br />
    // Done with the item list.<br />
    delete pItems;<br />
    // Create a memory-file-based archive.<br />
    CSharedFile mf (GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);<br />
    CArchive ar(&mf, CArchive::store);  <br />
    ObList.Serialize(ar);<br />
    ar.Close(); // Flush and close.<br />
    HGLOBAL hMem = mf.Detach();<br />
    if (!hMem) return;<br />
    // Nuke the list but not the objects.<br />
    ObList.RemoveAll();<br />
    // Send the Clipboard the data.<br />
    OpenClipboard();<br />
    EmptyClipboard();<br />
    SetClipboardData(theApp.m_uiMyListClipFormat, hMem);<br />
    CloseClipboard();<br />
} 

The number of selected items is used to create a temporary array of selection IDs. The IDs are set into the array by calling GetSelItems. A new CMyObList is created and the pointer to each object is added to the list. Note that we are adding a reference to an object that is in use elsewhere, so it's important that we don't delete these objects by mistake when we're done here.

Once the new CMyObList object has been built, a CSharedFile is created and an archive is created on top of the shared file. We can now serialize the list to the archive and, hence, to the shared file in memory. Once that's done, the memory of the shared file is detached, ready for sending to the Clipboard. The temporary CMyList object has all its items removed, not destroyed. The list object itself is, of course, destroyed when the function exits. The Clipboard is opened, emptied, and set with the data from the shared file. The memory block now becomes the property of the Clipboard. Finally, the Clipboard is closed.

If you use the Clipboard viewer after copying a list to the Clipboard, you'll see an item from your private format. You can't view the data, of course, because the Clipboard has no way of understanding it. You can add that capability for owner-drawn Clipboard items if you want the user to be able to see the data in the Clipboard viewer.



Appu..
"If you judge people, you have no time to love them."
QuestionHow do you go about making a custom control? [modified] Pin
Lord Kixdemp7-Jul-06 19:27
Lord Kixdemp7-Jul-06 19:27 
AnswerRe: How do you go about making a custom control? Pin
NiceNaidu7-Jul-06 21:32
NiceNaidu7-Jul-06 21:32 
GeneralRe: How do you go about making a custom control? Pin
Lord Kixdemp8-Jul-06 13:12
Lord Kixdemp8-Jul-06 13:12 
Questionstack simulation [modified] Pin
trinh_van7-Jul-06 18:00
trinh_van7-Jul-06 18:00 
QuestionArray/CListBox Issue Pin
SySt7-Jul-06 17:07
SySt7-Jul-06 17:07 
AnswerRe: Array/CListBox Issue Pin
Steve Echols7-Jul-06 20:38
Steve Echols7-Jul-06 20:38 
GeneralRe: Array/CListBox Issue Pin
SySt8-Jul-06 1:31
SySt8-Jul-06 1:31 
QuestionCTabCtrl with CFormViews instead of CDialogs Pin
Tygernoot7-Jul-06 14:00
Tygernoot7-Jul-06 14:00 
Questionproblem selecting listview item Pin
method0077-Jul-06 11:22
method0077-Jul-06 11:22 
Questionstrange prototype [modified] Pin
Jay037-Jul-06 11:08
Jay037-Jul-06 11:08 
AnswerRe: strange prototype Pin
Steve Echols7-Jul-06 11:19
Steve Echols7-Jul-06 11:19 
QuestionSir , I am in need of math library. Pin
CodeVarma7-Jul-06 9:07
CodeVarma7-Jul-06 9:07 
AnswerRe: Sir , I am in need of math library. Pin
earl7-Jul-06 11:27
earl7-Jul-06 11:27 
AnswerRe: Sir , I am in need of math library. Pin
ThatsAlok9-Jul-06 22:00
ThatsAlok9-Jul-06 22:00 
QuestionSerialize CListCtrl Pin
DanYELL7-Jul-06 8:44
DanYELL7-Jul-06 8:44 
AnswerRe: Serialize CListCtrl Pin
Ravi Bhavnani7-Jul-06 8:46
professionalRavi Bhavnani7-Jul-06 8:46 
QuestionFormating of Date in class CTime? Pin
G Haranadh7-Jul-06 8:38
G Haranadh7-Jul-06 8:38 

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.