Click here to Skip to main content
15,899,474 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCRichEditCtrl question Pin
YaronNir7-Jul-06 20:51
YaronNir7-Jul-06 20:51 
AnswerRe: CRichEditCtrl question Pin
Naveen7-Jul-06 21:15
Naveen7-Jul-06 21:15 
GeneralRe: CRichEditCtrl question Pin
YaronNir8-Jul-06 3:05
YaronNir8-Jul-06 3:05 
AnswerRe: CRichEditCtrl question Pin
Hamid_RT7-Jul-06 22:52
Hamid_RT7-Jul-06 22:52 
GeneralRe: CRichEditCtrl question Pin
YaronNir8-Jul-06 3:05
YaronNir8-Jul-06 3:05 
Questionhow to add Menu to my window [modified] Pin
LakshmiPathiRao7-Jul-06 20:48
LakshmiPathiRao7-Jul-06 20:48 
AnswerRe: how to add Menu to my window Pin
Naveen7-Jul-06 21:12
Naveen7-Jul-06 21:12 
AnswerRe: how to add Menu to my window Pin
NiceNaidu7-Jul-06 21:15
NiceNaidu7-Jul-06 21:15 
QuestionCommand routing Pin
RockyJames7-Jul-06 20:25
RockyJames7-Jul-06 20:25 
AnswerRe: Command routing Pin
NiceNaidu7-Jul-06 20:53
NiceNaidu7-Jul-06 20:53 
GeneralRe: Command routing Pin
RockyJames7-Jul-06 20:59
RockyJames7-Jul-06 20:59 
QuestionIHtmlPopup Error [modified] Pin
Ranjan Banerji7-Jul-06 19:58
Ranjan Banerji7-Jul-06 19:58 
AnswerRe: IHtmlPopup Error Pin
NiceNaidu7-Jul-06 21:49
NiceNaidu7-Jul-06 21:49 
GeneralRe: IHtmlPopup Error Pin
Ranjan Banerji7-Jul-06 22:45
Ranjan Banerji7-Jul-06 22:45 
GeneralRe: IHtmlPopup Error Pin
Stephen Hewitt8-Jul-06 2:54
Stephen Hewitt8-Jul-06 2:54 
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 

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.