Solved

QueryAcceptData Problem

Posted on 2006-11-13
3
533 Views
Last Modified: 2013-11-20
Hi,

I am trying to override QueryAcceptData in my CRichEditview derived class.

HRESULT MyView::QueryAcceptData(LPDATAOBJECT lpdataobj,CLIPFORMAT *lpcfFormat,DWORD dwReco,BOOL bReally,HGLOBAL hMetaFile)
{
              ASSERT(lpcfFormat != NULL);
      if (!bReally) // not actually pasting
            return S_OK;
      // if direct pasting a particular native format allow it
      if (IsRichEditFormat(*lpcfFormat))
            return S_OK;

      COleDataObject dataobj;
      dataobj.Attach(lpdataobj, FALSE);
      // if format is 0, then force particular formats if available
      if (*lpcfFormat == 0 && (m_nPasteType == 0))
      {
            if (dataobj.IsDataAvailable((CLIPFORMAT)_oleData.cfRichTextAndObjects)) // native avail, let richedit do as it wants
                  return S_OK;
            else if (dataobj.IsDataAvailable((CLIPFORMAT)_oleData.cfRichTextFormat))
            {
                  *lpcfFormat = (CLIPFORMAT)_oleData.cfRichTextFormat;
                  return S_OK;
            }
            else if (dataobj.IsDataAvailable(CF_TEXT))
            {
                  *lpcfFormat = CF_TEXT;
                  return S_OK;
            }
      }
      // paste OLE formats
      DoPaste(dataobj, *lpcfFormat, hMetaPict);
      return S_FALSE;
}

as you can see thus far i am just copying the code from the CRichEditView implementation.  But I receive the following errors which i dont understand


error C2065: '_oleData' : undeclared identifier
error C2065: 'hMetaPict' : undeclared identifier

I have other errors after this but i think they relate to this, any ideas please.  FYI i am doing this because I dont want DoPaste to be called under certain circumstances DoPaste is not virtual so i didnt think i could override it, if this isnt the case then please suggest your ideas for this, thanks

Will


0
Comment
Question by:wdhough
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 500 total points
Comment Utility
because there is no declaration for _oleData and hMetaPict...

probably you need hMetaFile instead of hMetaPict and you need to register clipboard formats  cfRichTextFormat & cfRichTextAndObjects .......

so try this :

HRESULT MyView::QueryAcceptData(LPDATAOBJECT lpdataobj,CLIPFORMAT *lpcfFormat,DWORD dwReco,BOOL bReally,HGLOBAL hMetaFile)
{
     ASSERT(lpcfFormat != NULL);
     if (!bReally) // not actually pasting
          return S_OK;
     
// if direct pasting a particular native format allow it
     if (IsRichEditFormat(*lpcfFormat))
          return S_OK;

     COleDataObject dataobj;
     dataobj.Attach(lpdataobj, FALSE);

UINT cfRichTextFormat = ::RegisterClipboardFormat(_T("Rich Text Format"));       //**NOTE
UINT cfRichTextAndObjects = ::RegisterClipboardFormat(_T("RichEdit Text and Objects")); //**NOTE
 
     // if format is 0, then force particular formats if available
     if (*lpcfFormat == 0 && (m_nPasteType == 0))
     {
          if (dataobj.IsDataAvailable(CLIPFORMAT)cfRichTextAndObjects) //**NOTE
               return S_OK;
          else if (dataobj.IsDataAvailable((CLIPFORMAT)cfRichTextFormat) //**NOTE
          {
               *lpcfFormat = (CLIPFORMAT)cfRichTextFormat; //**NOTE
               return S_OK;
          }
          else if (dataobj.IsDataAvailable(CF_TEXT))
          {
               *lpcfFormat = CF_TEXT;
               return S_OK;
          }
     }
     // paste OLE formats
     DoPaste(dataobj, *lpcfFormat, hMetaFile); //**NOTE
     return S_FALSE;
}

Have a look at commented as **NOTE statements above.

-MAHESH
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
I confirmed what mahesh1402 pointed out:  You are getting those errors because you made some typographical errors when you copied the original MFC source code.  Replace...
    hMetaFile
...with...
    hMetaPict
...and replace...
     _oleData
...with...
   dataobj
0
 
LVL 22

Expert Comment

by:mahesh1402
Comment Utility
No ! I dont think you need to replace  _oleData with dataobj...

What you are doing is correct to attach lpdataobj to dataobj....

COleDataObject dataobj;
dataobj.Attach(lpdataobj, FALSE);

you need to define cfRichTextAndObjects and cfRichTextFormat for rich text formats as shown above...as there are no class member as such for 'COleDataObject' type class.

-MAHESH
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 47
sumDigits challenge 9 96
scoreUp challenge 14 48
Thin secure Windows 10 5 47
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now