100分新手问题
我在头文件中stdafx.h和源文件中stdafx.cpp都加入了
#include <windows.h>
然后写上以下代码
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
HWND hwnd;
hwnd =::FindWindow(NULL,L"我的电脑")
MessageBox::Show(hwnd);
};
}
却老是出现很多错误,谁帮我修改一下代码,可以成功输出窗口句柄的一百分全给他
[解决办法]
FindWindow是API,在托管的C++里要像C#一样调用系统Api才行。
[解决办法]
using namespace System::Runtime::InteropServices; typedef void* HWND; [DllImport("user32.dll", CharSet=CharSet::Ansi)] extern "C" HWND FindWindow(String ^, String ^); private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { HWND f= FindWindow("CalcFrame", "计算器"); }
[解决办法]
可以参考:
http://msdn.microsoft.com/en-us/library/ms235282(v=VS.100).aspx
[解决办法]
可以参考:
http://msdn.microsoft.com/en-us/library/ms235282(v=VS.100).aspx
[解决办法]
using namespace System::Runtime::InteropServices;
typedef void* HWND;
[DllImport("user32.dll", CharSet=CharSet::Ansi)]
extern "C" HWND FindWindow(String ^, String ^);
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
HWND f= FindWindow("CalcFrame", "计算器");
}