错误提示:[C++ Error] Unit1.cpp(25): E2040 Declaration terminated incorrectly,大家指点一下。

  • 主题发起人 主题发起人 路远
  • 开始时间 开始时间

路远

Unregistered / Unconfirmed
GUEST, unregistred user!
错误提示:[C++ Error] Unit1.cpp(25): E2040 Declaration terminated incorrectly,大家指点一下。(100分)<br />void &nbsp;MENumChildWindows(HWND h);<br><br>char &nbsp;tempstr[255];<br><br><br>HWND &nbsp;h=GetWindow(h, GW_CHILD);<br><br><br>while(h)////在此提示:[C++ Error] Unit1.cpp(25): E2040 Declaration terminated incorrectly<br><br>{<br><br>&nbsp; &nbsp;GetWindowText(h, tempstr, 256);<br><br>&nbsp; &nbsp;if( !strcmp(tempstr, "WorkerA") || !strcmp( tempstr, "WorkerW"))<br><br><br>&nbsp; &nbsp;h = GetWindow(h, GW_HWNDNEXT);<br><br><br><br>{<br><br>&nbsp; &nbsp; SendMessage(h, WM_SETTEXT, 0, (LPARAM)"text");<br>&nbsp; }<br>//---------------------------------------------------------------------------<br><br>void __fastcall TForm1::Timer1Timer(TObject *Sender)<br>{<br>char &nbsp; Text[255];<br><br>if (HWND &nbsp;h := FindWindow("IEFrame", 0) &gt; 0) &nbsp; &nbsp;<br><br>EnumChildWindows(h);<br><br><br><br>}
 
void &nbsp;MENumChildWindows(HWND h);<br><br>char &nbsp;tempstr[255];<br><br><br>h=GetWindow(h, GW_CHILD);<br><br><br>while(h)////在此提示:[C++ Error] Unit1.cpp(25): E2040 Declaration terminated incorrectly<br><br>{<br><br>&nbsp; &nbsp;GetWindowText(h, tempstr, 256);<br><br>&nbsp; &nbsp;if( !strcmp(tempstr, "WorkerA") || !strcmp( tempstr, "WorkerW"))<br><br><br>&nbsp; &nbsp;h = GetWindow(h, GW_HWNDNEXT);<br><br><br><br>{<br><br>&nbsp; &nbsp; SendMessage(h, WM_SETTEXT, 0, (LPARAM)"text");<br>&nbsp; }<br>//---------------------------------------------------------------------------<br><br>void __fastcall TForm1::Timer1Timer(TObject *Sender)<br>{<br>char &nbsp; Text[255];<br><br>if (HWND &nbsp;h := FindWindow("IEFrame", 0) &gt; 0) &nbsp; &nbsp;<br><br>EnumChildWindows(h);<br><br><br><br>}
 
好象不大对头 再把源码贴全一点!
 
原文件是一篇<br>文章C++Builder 高手进阶 &nbsp;<br><br>(一) &nbsp; 编写弹出广告杀手<br><br>nxyc_twz@163.com<br><br>一、系统分析<br><br>&nbsp; 作为一名软件开发人员,必然会经常上网查找资料,可讨厌的广告真让人心烦。有没有办法自动关闭这些广告呢?答案是肯定的!也许你会说:“网上这类软件多的是,随便找一个不就行了?”,你说的确实不错,可作为一名软件开发人员,总不能什么都靠别人吧?自己动手作一个如何?说干就干,首先得找出弹出广告窗口的工作原理:<br><br>1. &nbsp;使用自己的《系统窗口分析器》(在下一期讲述其开发过程),轻易地就发现弹出广告窗口的特征:其窗口类是CabinetWClass或IEFrame。<br><br>2. &nbsp;如果找出窗口类是CabinetWClass或IEFrame的窗口,向其发送WM_CLOSE不就OK了吗?心里不由一阵窃喜!<br><br>3. &nbsp;使用定时器定时进行检测,找到符合条件的窗口就向其发送WM_CLOSE消息。<br><br>二、实战前沿<br><br>道理讲明了,可如何找到窗口类名呢?这就需要使用API函数了:<br><br>GetWindowText :取得窗口文本<br><br>GetWindow &nbsp;:取得窗口句柄<br><br>GetClassName :取得类名<br><br>PostMessage :发送消息<br><br>SetWindowLong :设置方式<br><br>具体用法请查阅相关资料。<br><br>三、设计流程<br><br>1. &nbsp;启动C++Builder 5,新建一个Application,将Form的Name设置为Form1,其BoldStyle设置为bsNone,在Form的Icon中设置好图标。<br><br>2. &nbsp;定义数据变量:<br><br>TRAYICON_ID = 1;<br><br>ICONEVENT = WM_APP + 100;<br><br>TNotifyIconData &nbsp;TrayIcon ;<br><br>3. &nbsp;拖放一个Timer控件和一个Popmenu控件到窗体上。Timer的属性:Name-&gt;Timer1,Interval-&gt;1000;Popmenu1上追加三个子项:继续-&gt;ContinueCmd,PauseCmd-&gt;暂停,ExitCmd-&gt;退出。<br><br>4. &nbsp;使应用程序进入系统托盘:void &nbsp;TrayIconCmd(void);<br><br>TrayIcon.cbSize = sizeof(TNotifyIconData);<br><br>TrayIcon.hWnd = Handle;<br><br>TrayIcon.uID = ID_TRAYICON;<br><br>TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;<br><br>TrayIcon.uCallBackMessage = ICONEVENT;<br><br>TrayIcon.hIcon = Form1-&gt;Icon-&gt;Handle;<br><br>TrayIcon.szTip = “广告窗口杀手”;<br><br>Shell_NotifyIcon(NM_ADD, &amp;TrayIcon);<br><br>5. &nbsp;使应用程序退出系统托盘:void &nbsp;TrayIconExit(void);<br><br>Shell_NotifyIcon(NIM_DELETE, &amp;TrayIcon );<br><br>6. &nbsp;使应用程序启动后直接进入系统托盘:编写Form1的OnCreate事件<br><br>TrayIconCmd(); &nbsp;//在系统托盘中安装图标<br><br>Width = 0;<br><br>&nbsp; &nbsp; SetWindowLong(Application-&gt;Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);<br><br>7. &nbsp;从系统托盘中卸载图标:编写Form1的OnClose事件<br><br>TrayIconExit();<br><br>8. &nbsp;自定义消息TrayIconOnClick:<br><br>在头文件.h中定义:<br><br>private:<br><br>MESSAGE &nbsp;void &nbsp;__fastcall &nbsp;TrayIconOnClick(Tmessage &amp;message);<br><br>BEGIN_MESSAGE_MAP<br><br>&nbsp; MESSAGE_HANDLER(ICONEVENT, Tmessage, TrayIconOnClick);<br><br>END_MESSAGE_MAP(Tform)<br><br>9. &nbsp;鼠标点击系统托盘图标(TrayIconOnClick),则弹出菜单:<br><br>Tpoint &nbsp;p;<br><br>if( message.lParam == WM_LBUTTONDOWN ||<br><br>&nbsp; &nbsp;message.lPram == WM_RBUTTONDOWN)<br><br>{<br><br>PopupMenu1-&gt;PopupComponent = Form1;<br><br>&nbsp; &nbsp; &nbsp; SetForegroundWindow(Handle); &nbsp; <br><br>GetCursorPos(p);<br><br>&nbsp; &nbsp; &nbsp; PopupMenu-&gt;Popup(p.x,p.y);<br><br>} &nbsp; &nbsp;<br><br>10. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;枚举指定窗口句柄的所有子窗口:void &nbsp;MENumChildWindows(HWND &nbsp;hand);<br><br>char &nbsp;tempstr[255];<br><br>bool &nbsp;IsPopWindow = true;<br><br>HWND &nbsp;h = GetWindow(hand, GW_CHILD);<br><br>while(h)<br><br>{<br><br>&nbsp; &nbsp;GetClassName(h, tempstr, 256);<br><br>&nbsp; &nbsp;if( !strcmp(tempstr, “WorkerA”) || !strcmp( tempstr, “WorkerW”))<br><br>&nbsp; &nbsp; &nbsp; if( IsWindowVisible(h) ) IsPopWindow = false;<br><br>h = GetWindow(h, GW_HWNDNEXT);<br><br>}<br><br>if( IsPopWindw )PostMessage(hand, WM_CLOSE, 0, 0); &nbsp; &nbsp;<br><br>11. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;双击Timer控件,添加其事件OnTimer:<br><br>char &nbsp; Text[255];<br><br>HWnd &nbsp;h := GetWindow(Handle, GW_HWNDFIRST);<br><br>while(h)<br><br>{<br><br>&nbsp; &nbsp; &nbsp;if (GetWindowText(h, Text, 255) &gt; 0)<br><br>&nbsp; &nbsp; &nbsp; &nbsp;if (GetClassName(h,Text , 255)&gt;0)<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( !strcmp( Text, “CabinetWClass”) || !strcmp(Text, “IEFrame”))<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EnumChildWindows(h);<br><br>&nbsp; &nbsp; &nbsp; h &nbsp;= GetWindow(h, GW_HWNDNEXT); <br><br>}<br><br>12.编写菜单响应事件:<br><br>ContinueCmd:继续<br><br>Timer1-&gt;Enabled = true;<br><br>&nbsp; &nbsp; &nbsp; PauseCmd-&gt;Checked = false;<br><br>&nbsp; &nbsp; &nbsp; ContinueCmd-&gt;Checked = true;<br><br>PauseCmd:暂停<br><br>Timer1-&gt;Enabled = false;<br><br>&nbsp; &nbsp; &nbsp; PauseCmd-&gt;Checked = true;<br><br>&nbsp; &nbsp; &nbsp; ContinueCmd-&gt;Checked = false;<br><br>ExitCmd::退出<br><br>Close();<br><br>
 
接受答案了.
 
后退
顶部