-
26-05-2011, 02:11 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Cảm ơn hai anh, vậy ví dụ em có tên class là "Notepad", làm thế nào để lấy handle của tất cả các cửa sổ có class đó?
Dạ không phải Instance mà là Handle của Window luôn ấy.View more random threads:
- giải pháp truyền hình ảnh qua mạng wan ( họp trực tuyến)
- bỏ bớt cột trong Gridview của DevExpress khi dùng SearchLookUpEdit
- Hiển thị mảng nguyên trên form
- Lưu ảnh từ PictureBox trong lập trình C#?
- Không thể tính sum trong Crystal Report?
- Cách tạo form chon trong form con
- in crystalreport theo dataset trong lập trình C#?
- Thêm nhiều dòng vào datagirdview
- Đặt điều kiện cho các supitem trong listview
- Làm Thế Nào Để Thay Đổi Password Trong Windows Server 2003/2008
-
26-05-2011, 03:30 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Bạn có thể sử dụng SetForegoundWindow để active cửa sổ notepad rồi dùng lớp SendKeys của .Net
-
26-05-2011, 03:47 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
FindWindow nhận vào 2 tham số 1 là class name của cửa sổ cần tìm, 2 là cái caption(tức là chữ trên thanh title bar ấy).
viết như của bác tức là nó tìm cửa sổ nào cứ có caption là "Untitled - Notepad" là dc. Bác có thể bổ xung thêm class name của notepad là "Notepad":
int Handle = FindWindow("Notepad","Untitled - Notepad");
Việc tìm class name & caption thì có thể dùng spy++ đi kèm với VS để làm.
Cái này k chắc đã tìm dc cửa sổ cần tìm-vì nó chỉ trả về 1 cửa sổ đầu tiên tìm dc thôi.
Phần còn lại làm như 2Y nói ấy. Ko nên dùng SendMessage để gửi phím.
-
26-05-2011, 07:50 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Cách sử dụng SendMessage truyền tổ hợp phím vào Notepad?
Em cần hỏi là làm thế nào để SendMessage truyền tổ hợp phím Ctrl V vào control Edit trên Notepad.
Em có search cái này rồi, nhưng mà toàn ra C/C++ thôi, đọc không hiểu gì luôn, anh nào có code mẫu bằng C# cho em xin với [IMG]images/smilies/thinking.gif[/IMG]
Em biết được có tới đây thôi
Mã:namespace SendMessage{ class Program { [DllImport("User32.dll")] private static extern int FindWindow(string Class, string Title); [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); public static void Main(string[] args) { int Handle = FindWindow(null,"Untitled - Notepad"); // Cái này là Handle của Notepad Console.WriteLine(Handle); Console.ReadKey(true); } }}
-
27-05-2011, 08:42 AM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Lâu lắm mới thấy bác drew vào đây nhỉ?
Thứ 1:K nên vì nghe giang hồ đồn đại là muốn là cao thủ .net thì k dc dùng api-phải mò đến khi nào k mò dc thì mới dùng.
Thứ 2:K nên vì hàm SendMessage sau khi gửi message đi nó sẽ đợi phản hồi do vậy sẽ lâu hơn hàm PostMessage thì phải-ngu kiến của m-các bác cứ chém-nếu send thì send lần lượt wm_keydown,wm_char, wm_keyup thì phải->gõ mất 9 dòng-trong khi SendKeys có 1 dòng thôi.
@thitgaluoc: ý bác drew là handle của tất cả các íntance
Về mấy cái api kiểu thế này có thể google với từ khóa là "cac ham api lien quan den cua so".
m đâu có nói là bác sai nhỉ? có thế mà tranh cãi mãi:
code đây
Mã:private void textBox1_KeyUp(object sender, KeyEventArgs e) { MessageBox.Show("KeyUp"); } private void textBox1_KeyDown(object sender, KeyEventArgs e) { MessageBox.Show("KeyDown"); } [DllImport("user32")] static extern void SendMessage(IntPtr handle, int wMsg, int wParam, int lParam); const int WM_KEYUP = 0x101; const int VK_OEM_6 = 0xDD; const int WM_CHAR = 0x102; private void button1_Click(object sender, EventArgs e) { SendMessage(textBox1.Handle, WM_CHAR,(int)Keys.A, 0); }
-
31-05-2011, 05:56 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Đang ở
- Hà Nội
- Bài viết
- 0
wowo Cái này có thắc mắc lâi lắm rồi mà không tìm ra giải pháp.
em làm với vb.net thế này
AppActivate("tieudewindow")
SendKeys.Send("chuoikitu")
cái này gửi text từ ứng dụng của mình đến 1 ứng dụng khác.
Ví dụ ừng dụng của em (tạm gọi là A)
và 2 ứng dụng khác vi dụ như Calculator và Notepad (tạm gọi là B và C)
giờ em muốn dùng A lấy 1 giá trị trên B rồi gửi giá trị đó đến C không biết có được không các anh? Mong các anh giúp dùm.
-
31-05-2011, 06:00 PM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Dạ em cần send tổ hợp phím Ctrl + V ạ:|
E, đã biết gửi phím V còn kết hợp cả Ctrl thì chưa được :|
Mã:IntPtr hwnd = FindWindow("Notepad","Untitled - Notepad"); IntPtr Control = FindWindowEx(hwnd,0,"Edit",null); SendMessage(Control, 0x100,0x11,0); // Keydown - Ctrl SendMessage(Control, 0x100,0x56,0); // Keydown - V SendMessage(Control, 0x101,0x56,0); // Keyup - V SendMessage(Control, 0x101,0x11,0); // Keyup - Ctrl
-
04-06-2011, 11:26 AM #8Junior Member
- Ngày tham gia
- Dec 2015
- Bài viết
- 0
Đây dành cho tất cả. Từ việc paste vào notepad. Và copy thông tin của calculator.
Cái này viết trên Window7.
Mã:public Form1() { InitializeComponent(); } public const int WM_COPY = 0x0301; public const int WM_PASTE = 0x0302; public const int WM_COMMAND = 0x0111; [DllImport("user32.dll")] public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); public IntPtr ActiveNotepadEditAreaHandle() { IntPtr hwndParentRoot = FindWindow("Notepad", null); IntPtr hwnd = FindWindowEx(hwndParentRoot, IntPtr.Zero, "Edit", null); return hwnd; } public IntPtr ActiveCalculatorStaticAreaHandle() { IntPtr hwndParentRoot = FindWindow("CalcFrame", null); // Khong dung den cai static cua calculator. //IntPtr hwnd = FindWindowEx(hwndParentRoot, IntPtr.Zero, "CalcFrame", null); //hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Static", null); return hwndParentRoot; } // Send paste to notepad private void PasteToActiveNotepad() { IntPtr hwndNotepad = ActiveNotepadEditAreaHandle(); if (hwndNotepad != null) { SendMessage(hwndNotepad, WM_PASTE, (IntPtr)0, (IntPtr)0); } } // Copy from calculator. private void CopyValueFromActiveCalculate(object sender, EventArgs e) { IntPtr hwndCalculator = ActiveCalculatorStaticAreaHandle(); if (hwndCalculator != null) { SendMessage(hwndCalculator, WM_COMMAND, (IntPtr)0x0000012C, (IntPtr)0); } } private void button1_Click(object sender, EventArgs e) { CopyValueFromActiveCalculate(sender, e); PasteToActiveNotepad(); }
-
04-06-2011, 03:31 PM #9Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Hi. sáng nay dùng find của spy để tìm mà tìm đến cái class #32770 là dừng nên gettext mới trả về rỗng-sơ xuất wa, không để ý nó có cái dấu cộng to đùng ở đầu.
code đây:
Mã:public partial class Form2 : Form { public Form2() { InitializeComponent(); } [DllImport("user32")] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32")] static extern IntPtr FindWindowEx(IntPtr h1, int h2, string lpsz1, string lpsz2); [DllImport("user32")] static extern int SendMessage(IntPtr h, int l, int p, int o); [DllImport("user32")] static extern int SendMessage(IntPtr h, int l, int p, StringBuilder o); [DllImport("user32")] static extern int SendMessage(IntPtr h, int l, bool p, StringBuilder o); [DllImport("user32")] static extern void PostMessage(IntPtr h, int l, int p, int o); private void Form1_Load(object sender, EventArgs e) { } void Command1_Click() { } delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); [DllImport("user32")] static extern void GetWindowText(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount); private void button1_Click(object sender, EventArgs e) { IntPtr hwndNotepad = FindWindow("Notepad", null); IntPtr hwndedit = FindWindowEx(hwndNotepad, 0, "Edit", null); IntPtr hwnd = FindWindow(null, "Calculator"); IntPtr Control = FindWindowEx(hwnd, 0, "CalcFrame", null); IntPtr Control1 = FindWindowEx(Control, 0, "#32770", null); EnumWindowsProc proc = delegate(IntPtr hwnd1, IntPtr lParam) { StringBuilder sx = new StringBuilder(123); GetWindowText(hwnd1, sx, sx.Capacity); if (sx.Length > 0) { SendMessage(hwndedit, 0xc2, 0, sx); return false; } return true; }; EnumChildWindows(Control1, proc, IntPtr.Zero); } }
Có thể code theo bác dungnn07 nhưng mà như vậy sẽ bị mất dữ liệu trong clipboard.
-
04-06-2011, 04:30 PM #10Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi thuyan1990
SendKeys.Send thì dùng y hệt VB luôn.
Lấy thông tin từ B rồi gửi cho C:Cái này còn tùy thuộc vào việc bạn muốn lấy thông tin gì ở B rồi gửi gì đến C, nói cụ thể m sẽ hướng dẫn cho bác nếu biết.
@thitgaluoc:Gửi như bạn k hiểu sao lại k chạy, thứ tự vậy là đúng rồi. bác dùng thế này thử xem: SendMessage(Control, 0x102,22,0);
Khi muốn gửi ctrl+ 1 phím thì có thể thay số 22 bằng vị trí của ký tự đó trong thứ tự alphabet, viết trong c# sẽ là thế này (Keys.V-Keys.A+1) nếu muốn gửi phím ctrl + V, cái đấy =22 luôn.
Hiện nay trên thị trường xuất hiện rất nhiều loại thuốc bôi tăng kích thước dương vật được lăng xê là có khả năng làm tăng kích cỡ dương vật của cánh mày râu. Tuy nhiên không phải loại thuốc nào cũng...
Thuốc tăng kích thước chim có tác...