none
利用API,複製資料到控制項 RRS feed

  • 問題

  • 大大您們好,我想做copy某一字串到textBox控制項上,利用api,由於我在網路上找尋到的資料不多,結合起來,但效果不如預期,希望大大幫我解答,是否有我疏失地方,謝謝
            private void Form1_Load(object sender, EventArgs e)
            {
                byte[] sarr = System.Text.Encoding.Default.GetBytes(textBox1.Text);
                int len = sarr.Length;
                COPYDATASTRUCT cds;
                cds.dwData = (IntPtr)100;
                cds.lpData = "aa";
                cds.cbData = len + 1;
                SendMessage(textBox1.Handle, WM_COPY, 0, ref cds); 
            }
           [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
            private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, ref COPYDATASTRUCT lParam);//int lParam);
            const int WM_COPYDATA = 0x004A;
            const int WM_COPY = 0x301;
            public struct COPYDATASTRUCT
            {
                public IntPtr dwData;
                public int cbData;
                [MarshalAs(UnmanagedType.LPStr)]
                public string lpData;
            }

    2010年3月3日 上午 05:51

解答

所有回覆