[問題] 請問 這迴圈在哪?

看板C_Sharp (C#)作者 (Mango)時間14年前 (2011/08/18 16:29), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
最近在學API API的GetWindowText 這程式大概是 根據視窗title 來找到 該視窗介的控件 在表單上 建立一個button 就好了 我不懂的是 究竟是怎樣產生迴圈效果 讓他可以不斷執行 後面這行: Console.WriteLine(" Contains text of contro:"+ editText); 程式是用XP的 音量控制 來測試的 程式碼: using System; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace user32_api_test1 { public partial class Form1 : Form { [DllImport("User32.dll")] public static extern Int32 FindWindow(String lpClassName, String lpWindowName); [DllImport("User32.dll")] public static extern Boolean EnumChildWindows(int hWndParent, Delegate lpEnumFunc, int lParam); [DllImport("User32.dll")] public static extern Int32 GetWindowText(int hWnd, StringBuilder s, int nMaxCount); [DllImport("User32.dll")] public static extern Int32 GetWindowTextLength(int hwnd); [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")] public static extern int GetDesktopWindow(); int hWnd; public delegate int Callback(int hWnd,int lParam); public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { }// private void button1_Click(object sender, EventArgs e) { Callback myCallBack = new Callback(EnumChildGetValue); hWnd = FindWindow(null, "主音量"); if(hWnd == 0) { MessageBox.Show("Please Start Calling Window Application"); } else { EnumChildWindows(hWnd,myCallBack,0); } } public int EnumChildGetValue(int hWnd,int lParam) { StringBuilder formDetails = new StringBuilder(256); int txtValue; string editText=""; txtValue =GetWindowText(hWnd,formDetails,256); editText = formDetails.ToString().Trim(); Console.WriteLine(" Contains text of contro:"+ editText); return 1; } }// } Thanks in advance for any help -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.145.193
文章代碼(AID): #1EJCrrqJ (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1EJCrrqJ (C_Sharp)