我很难在textBox或RichtextBox中插入文本而不重复。
这是使用的代码:
#include "windows.h" #pragma comment(lib, "user32") void actwnd() { wchar_t lastwindow[MAX_PATH]; wchar_t currentwindow[MAX_PATH]; HWND mainwindow; mainwindow = GetForegroundWindow(); GetWindowText(mainwindow,currentwindow,sizeof(currentwindow)); if(lastwindow==currentwindow) { } else if(lastwindow!=currentwindow) { strcpy ((char*)lastwindow,(char*)currentwindow); String^ strNew = gcnew String(currentwindow); // String^ wnd = gcnew String(reinterpret_cast(currentwindow)); textBox1->Text += strNew; } } // Set interval for 1000ms in test private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { actwnd(); }
任何帮助都将受到赞赏
答案 0 :(得分:0)
如果(lastwindow == currentwindow)不比较字符串,它会比较数组的地址,因此它们永远不会相等。使用wcscmp比较wchar_t数组。由于这些是wchar_t数组,因此使用strcpy复制它们也是无效的,strcpy仅用于char数组。请改用wcscpy。