_VSC++2010 windows窗体应用程序_不能将参数 1 从“HWND”转换为“System::String ^”

//
//获得坐标。
POINT mouse;
GetCursorPos(&mouse);
int x=(int)mouse.x ;
int y=(int)mouse.y ;
this->textBox1 ->Text =x.ToString() +","+y.ToString ();
//
//获得句柄。
HWND hWnd;
hWnd=WindowFromPoint(mouse);
this->textBox2 ->Text =hWnd;//代码出错。。。

请高手帮忙看下。。。。哪里错了怎么改??
……/*Form1.h(195) : error C2664: “void System::Windows::Forms::Control::Text::set(System::String ^)”: 不能将参数 1 从“HWND”转换为“System::String ^”
没有用户定义的转换运算符,或者
无法将非托管类型转换为托管类型*/

第1个回答  2011-08-16
HWND是非托管类型,这里可以先转换HWND到int,在用ToString方法转换到System::String ^类型
this->textBox2 ->Text =((int)hWnd).ToString();
第2个回答  2011-08-13
hWnd应该先强制转换一下再转换成string才能给string赋值啊追问

怎么强制转??给代码下。。。 我强制转的时候总是错误

第3个回答  2011-08-13
unsigned int un = hWnd;
this->textBox2 ->Text =un.ToString();本回答被提问者采纳
第4个回答  2011-08-13
不能
相似回答