VC++:在文本框中插入文本,不重复

VC++: Insert text in textBox without repeat

本文关键字:插入文本 文本 VC++      更新时间:2023-10-16

我很难在textBox或RichtextBox中插入文本而不重复。

这是使用的代码:

#包括"windows.h"#pragma注释(lib,"user32")void actwnd(){wchar_t最后一个窗口[MAX_PATH];wchar_t当前窗口[MAX_PATH];HWND主窗口;mainwindow=GetForegroundWindow();GetWindowText(主窗口,当前窗口,sizeof(当前窗口));if(lastwindow==currentwindow){}其他的if(lastwindow!=currentwindow){strcpy((char*)lastwindow,(char*currentwindow);String^strNew=gcnew字符串(当前窗口);//String^wnd=gcnew字符串(interpret_cast(currentwindow));textBox1->Text+=strNew;}}//设置测试间隔1000msprivate:System::Void timer1_Tick(System::Object^sender,System::EventArgs^e){actwnd();}

如有任何帮助,将不胜感激

如果(lastwindow==currentwindow)不比较字符串,它会比较数组的地址,所以它们永远不会相等。使用wcscmp比较wchar_t数组。由于这些是wchar_t数组,因此使用strcpy复制它们也是无效的,strcpy仅用于char数组。请改用wcscpy。