C 獲取控制台控制代碼的方法

2021-06-01 21:02:21 字數 1539 閱讀 2757

1.建立類user32api.cs,**如下:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.runtime.interopservices;

using system.collections;

namespace ***

}[dllimport("user32.dll", entrypoint = "enumwindows", setlasterror = true)]

public static extern bool enumwindows(wndenumproc lpenumfunc, uint lparam);

[dllimport("user32.dll", entrypoint = "getparent", setlasterror = true)]

public static extern intptr getparent(intptr hwnd);

[dllimport("user32.dll", entrypoint = "getwindowthreadprocessid")]

public static extern uint getwindowthreadprocessid(intptr hwnd, ref uint lpdwprocessid);

[dllimport("user32.dll", entrypoint = "iswindow")]

public static extern bool iswindow(intptr hwnd);

[dllimport("kernel32.dll", entrypoint = "setlasterror")]

public static extern void setlasterror(uint dwerrcode);

public static intptr getcurrentwindowhandle()

else

}bool bresult = enumwindows(new wndenumproc(enumwindowsproc), uipid);

// 列舉視窗返回 false 並且沒有錯誤號時表明獲取成功

if (!bresult && marshal.getlastwin32error() == 0)

}return ptrwnd;

}private static bool enumwindowsproc(intptr hwnd, uint lparam)

}return true;}}

}2.呼叫類user32api獲取控制台控制代碼的**:

using system;

using system.collections.generic;

using system.linq;

using system.text;

namespace ***x

", hwnd);

console.readline();  }}

}

獲取控制台視窗的控制代碼(hWnd)

謝謝合作 測試環境 vc 6.0 視窗,都有其唯一的控制代碼 hwnd 得到了視窗控制代碼,能夠做很多事情。控制台程式,若能在視窗效果上下文章,那麼這個第三方工具將會很成功。網上給出的常用方法 hwnd hw findwindow consolewindowclass null 這不失為乙個好方法,...

認識控制台 控制台控制代碼 附著到控制台 關閉控制台

1.附著到乙個控制台 乙個程序可以使用 attachconsole 函式來附著到乙個控制台上,乙個程序只能附著乙個控制台。乙個控制台可以有許多程序附著到它上面,呼叫 getconsoleprocesslist 函式可以得到附著到乙個控制台的列表。2.關閉乙個控制台 程序可以使用 freeconsol...

認識控制台 控制台控制代碼 附著到控制台 關閉控制台

附著到乙個控制台 乙個程序可以使用 attachconsole 函式來附著到乙個控制台上,乙個程序只能附著乙個控制台。乙個控制台可以有許多程序附著到它上面,呼叫 getconsoleprocesslist 函式可以得到附著到乙個控制台的列表。關閉乙個控制台 程序可以使用 freeconsole 函式...