当前位置: 代码迷 >> VC >> VS2005环境,怎么获得其它线程窗口中的TextBox的Text内容
  详细解决方案

VS2005环境,怎么获得其它线程窗口中的TextBox的Text内容

热度:7039   发布时间:2013-02-25 00:00:00.0
VS2005环境,如何获得其它线程窗口中的TextBox的Text内容?
最近一直在偿试如何可以获得其它线程窗口中的TextBox的Text内容,目前还没有找到好方法。

我在网上搜索到相关资料都是VC++的,我在托管程序中调用这些函数,编译器会报无法解析的错,无法使用,如下:

=======Include========
#include   "Mqoai.h "
#include   "Winuser.h "

========Code:========
HWND   currentWindow   =   GetForegroundWindow();
GetWindowText(currentWindow,   (LPWSTR)pBuffer,   key-> Length);

========Output:=======
1> GetFormText.obj   :   error   LNK2028:   无法解析的标记(0A00000F)   "extern   "C "   int   __stdcall   GetWindowTextW(struct   HWND__   *,wchar_t   *,int) "   (?GetWindowTextW@@$$J212YGHPAUHWND__@@PA_WH@Z),该标记在函数   "private:   void   __clrcall   GetFormText::Form1::button_GetKey_Click(class   System::Object   ^,class   System::EventArgs   ^) "   (?button_GetKey_Click@Form1@GetFormText@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)   中被引用
……

我想问的是,关于此方法,.Net中有没有对应的类或方法可以使用?如果没有的话,那么如何才能使用这些非托管的函数?

------解决方案--------------------------------------------------------
调用api的一个例子


using System.Runtime.InteropServices;

class callAPICls {
[DllImport( "User32.dll ")]
public static extern int MessageBoxA(int h, string m, string c, int type);
public static int Main(){
return MessageBoxA(0, "Hello World! ", "Caption ", 0);
}
}
  相关解决方案