分不是白拿的
呵呵我们再WinForm下用Combobox的时候
可能需要向EditControl里面Paste一些东西
可是当字符串里面含有回车的时候就被截掉了
所以我想截获他的WM_PASTE消息
把回车替换成其他字符
可是在WndProc里面根本得不到WM_PASTE消息哪位兄弟知道
可否告知此问题如何解决
祝大家周末愉快PS:在TextBox里面是可以截获的

解决方案 »

  1.   

    win不会,顶了   呵呵
      

  2.   

    <<Windows api 编程 程序员书库>>
      

  3.   

    EditControl是什么东西?是不是说combobox的那个能手工输入的文本框?
      

  4.   

    试过了确实没有没有那个消息。
    手上没有查MsgID的书。
    觉得既然Testbox可以实现,那Combox也行的。
      

  5.   

    把combobox的右键菜单换成自己的。监视一下剪贴板。。
      

  6.   

    接分挨~~~~~~~~~~~EditControl是什么东东?
      

  7.   

    Public b As Boolean = False
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
            If e.Control = True And e.KeyCode = Keys.V And b = False Then
                b = True
                SendKeys.Send("^(Z)")
                Dim i As IDataObject = Clipboard.GetDataObject()
                Dim str As String
                str = CType(i.GetData("System.String"), String)
                Clipboard.SetDataObject(str.Replace(vbCrLf, "@"))
                SendKeys.SendWait("^(V)")
                b = False
                Clipboard.SetDataObject(str)
            End If
        End Sub
      

  8.   

    bool b;//用于判断是用户输入还是程序输入
    b=false;在combobox的keydown事件里:
    if(e.Control = True && e.KeyCode = Keys.V && b = False)
    {
    b=true;
    SendKeys.Send("^(Z)");//程序输入ctrl+z撤销刚才ctrl+v操作
    //呵呵,bt的想法
    IDataObject i= Clipboard.GetDataObject();
    string str;
    str=(string)i.GetData("System.String");//从剪贴板取string
    Clipboard.SetDataObject(str.Replace(vbCrLf, "@"))//更改剪贴板内容
    SendKeys.SendWait("^(V)");//程序输出ctrl +v,粘贴
    //必须用sendwait,否则死循环
    b=false;
    Clipboard.SetDataObject(str);//恢复剪贴板内容
    }
      

  9.   

    发现欧也蛮BT的,从sendkeys找思路
      

  10.   

    不过我执行了一下 好象不行啊
    在SendWait哪里 循环半天 然后出错
      

  11.   

    foyuan() ( ) 信誉:98  2006-04-07 14:50:00  得分: 0  
     
     
       不过我执行了一下 好象不行啊
    在SendWait哪里 循环半天 然后出错
      
     那个b是要放在事件处理函数外边的否则每次重新初始化b(无法判断是否为程序输入还是用户输入),就产生死循环了
      

  12.   

    xxuu503(我爱郭芙蓉!) 
    那右键的菜单怎么办?
    换成自己的?
    如果是控制键盘操作直接用ProcessDialogKey就可以了
    不用SendKey
      

  13.   

    用户输入的时候就让他输入好了,当他确定这个输入时再处理吧。例如用户确实从不可修改的源复制了两行的东西,准备贴进去后再手动删除第一行,而你的程序一贴就报错或者自动把第二行截掉,这时候用户必须手工打开notepad用它做中转先把东西贴进去然后再复制第二行(因为复制源是不能修改甚至不能局部复制的)。这样做还不如等用户输入完全定时,在提醒用户你确实输入了多行信息,这确定是你要输入的吗。
      

  14.   

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    using System.Windows.Forms;public class ExactComboBox : ComboBox 

    private IContainer components;  public ExactComboBox() 

    this.components = new Container(); 
    }  protected override void Dispose(bool disposing) 

    if (disposing == true) 

    if (!(this.components == null)) 

    this.components.Dispose(); 


    base.Dispose(disposing); 
    }  [DllImport("USER32.DLL")] 
    private static extern bool GetComboBoxInfo(IntPtr comboBoxHandle, ref ComboBoxInfo pComboBoxInfo); 

    [StructLayout(LayoutKind.Sequential)] 
    private struct ComboBoxInfo 

    public int Size; 
    public Rectangle RectItem; 
    public Rectangle RectButton; 
    public int ButtonState; 
    public IntPtr ComboBoxHandle; 
    public IntPtr EditBoxHandle; 
    public IntPtr ListBoxHandle; 


    private class EditBoxWindow : NativeWindow 
    { public EditBoxWindow(ComboBox parentComboBox) 

    parentComboBox.HandleDestroyed += new EventHandler(this.OnHandleDestroyed); 
    }  private void OnHandleDestroyed(object sender, EventArgs e) 

    this.ReleaseHandle(); 
    }  [PermissionSet(SecurityAction.Demand)] 
    protected override void WndProc(ref Message m) 
    {
    const int WM_PASTE = 770;
    if (m.Msg == WM_PASTE)
    {
    MessageBox.Show("WM_PASTE");//在这里处理
    }
    base.WndProc(ref m);
    }
    } protected override void OnHandleCreated(EventArgs e)
    {
    ComboBoxInfo tComboBoxInfo = new ComboBoxInfo();
    tComboBoxInfo.Size = Marshal.SizeOf(tComboBoxInfo);
    if (GetComboBoxInfo(this.Handle, ref tComboBoxInfo) == false)
    {
    return;
    }
    if (tComboBoxInfo.EditBoxHandle.Equals(IntPtr.Zero)) 
    {
    return;
    }
    EditBoxWindow hEditBoxWindow = new EditBoxWindow(this);
    hEditBoxWindow.AssignHandle(tComboBoxInfo.EditBoxHandle);
    }
    }
      

  15.   

    上面的原文网址
    http://www.atit.co.jp/bbs/phpBB/viewtopic.php?topic=28307&forum=7&4
      

  16.   

    汗。。原址怎么是日文的。Boss肯定以为我看不良网站了。
      

  17.   

    en,you are right!俺的确是忘掉右键菜单了俺一想粘贴,就想起来了ctrl+V了,就忘掉右键菜单了