在vba中
Sub EditPaste()
    MsgBox "EditPaste"
End Sub
这样就能重写office的粘贴动作了。当用菜单项,图标按钮,键盘快捷键都能响应。
请问各位:如果在vc这能不能实现呢?或者将这段代码如何转换成vc的,谢谢大家了。 已经被office的粘贴折麽n久了。

解决方案 »

  1.   

    vc中可以使用Selection类来实现
    其中粘贴时 Selection.Paste
    修改剪贴板的内容,可以使用OpenClipboard打开,使用GetClipboardData读取数据进行修改,使用CloseClipboard关闭。单纯将你那段代码改成vc的就是:
    void EditPaste()
    {
        AfxMessageBox("EditPaste");
    }
    呵呵,开玩笑
      

  2.   

    c++的粘贴必须用到比较底层的东西,不像VBA那么高级。
    其中一个方法是打开剪切板,将数据输入剪切板,执行其他的操作,最后还要关闭剪切板。
      

  3.   

    对于office粘贴 是不是都要经过GetClipboardData这个函数 操作剪贴板 ,不是的话,请大家,广出主意,到底是怎样才能将这个粘贴拦截住
    拜托了。
      

  4.   

    知道的,大家帮忙啊,已经被折磨n久了,大家肯定有做过的吧,虽然vc操作office室有点不太容易,但是总有人知道吧。
      

  5.   

    我没有在msdn找到响应的文档啊。请问您所说的是哪篇呢?我想做的是对粘贴的重写啊(快捷键,菜单项,命令按钮)
      

  6.   

    我没做过vc,我见别人做过,我只做过C#,你好好查查,C#代码我给你一部分
    Word.ApplicationClass wordApp = new Word.ApplicationClass();
                Word.DocumentClass myDoc;
                object oMissing = System.Reflection.Missing.Value;
                string path = Server.MapPath(Request.ApplicationPath);
                path = path + "\\user\\upload\\template.dot";
                object template = @path;
                wordApp.Documents.Add(ref template, ref oMissing, ref oMissing, ref oMissing);            myDoc = (Word.DocumentClass)wordApp.ActiveDocument;
                wordApp.Visible = false;
                object missing = Type.Missing;
                wordApp.Selection.Find.Replacement.Text = "";
                wordApp.Options.ReplaceSelection = true;
                wordApp.Selection.Find.Format = true;
                wordApp.Selection.Find.Wrap = Word.WdFindWrap.wdFindContinue;
                wordApp.Selection.Find.Format = false;
                wordApp.Selection.Find.MatchCase = false;
                wordApp.Selection.Find.MatchWholeWord = false;
                wordApp.Selection.Find.MatchByte = true;
                wordApp.Selection.Find.MatchWildcards = false;
                wordApp.Selection.Find.MatchSoundsLike = false;
                wordApp.Selection.Find.MatchAllWordForms = false;
                for (int i = 1; i < 10; i++)
                {
                    string findtext = "**" + i.ToString();
                    object replaceAll = Word.WdReplace.wdReplaceAll;
                    wordApp.Application.Selection.Find.ClearFormatting();
                    wordApp.Selection.Find.Text = findtext;
                    wordApp.Selection.Find.Replacement.ClearFormatting();
                    string lab = "label" + i.ToString();
                    Label tem = (Label)this.MyDataList.Items[0].FindControl(lab);
                    string tempt = tem.Text;
                    if (i == 2)
                    {
                        tempt = ((Label)this.MyDataList.Items[0].FindControl("label1")).Text + "(" + tem.Text + ")";
                    }
                    string replacetext = tempt.Replace("<br/>", "");
                    wordApp.Selection.Find.Execute(
                        ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing);
                    wordApp.Selection.TypeText(replacetext);
                }
    myDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                object missingValue = Type.Missing;
                object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;            myDoc.Close(ref doNotSaveChanges, ref missingValue, ref missingValue);
                wordApp.Quit(ref missingValue, ref missingValue, ref missingValue);
            }
    上面包含了打开一个Word模板,查找,粘贴,关闭等功能
      

  7.   

    我晓得是要用剪贴板,关键是截获不到office的粘贴消息啊。没能截获住的话,怎样重写??
    我正是因为不想让粘贴的时候走剪贴板,想让去访问我自己可控的一段内存区,所以才要重写粘贴啊。
      

  8.   

    你要重写的话就需要拦截 WM_COPY, WM_PASTE消息,然后自己处理了。
      

  9.   

    主要是对于office这样的应用程序,他粘贴时候,并不是发送WM_PASTE消息。所以没办法拦截啊。
      

  10.   

    我的思路是要么就是能够知道粘贴消息是什么?然后Hook住。
    要么就是将每个粘贴途径都重写,但是似乎都不容易啊。