关于 EnumChildWindows函数问题

昨夜冷雨 2011-07-16 05:59:54
下面是我的代码
有时程序运行到
::Sleep(3500);
EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
::Sleep(3000);
这段时线程就会停止
是什么原因呢


//---------------------------------------------------------------------------

// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall simu::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------

__fastcall simu::simu(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall simu::Execute()
{
int s;
double c;
AnsiString a;
;
c=(StrToInt(Form1->Edit1->Text)-Form1->d)/5;
c= RoundTo(c,0);
a=c;
s=0;
// F//orm1->ListBox1->Items->Add(IntToStr(Form1->d)) ;
//str="lala";
//Synchronize((TThreadMethod)List) ;
while(s<5)
{
Form1->pl=Form1->Edit1->Text+"MHz";

if(Simulation_mouse(c))
{
break;

}
::Sleep(3500);
s++;
}
//---- Place thread code here ----
}
//---------------------------------------------------------------------------

...全文
86 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
昨夜冷雨 2011-07-18
  • 打赏
  • 举报
回复
应该是线程的同步问题 问一下如何能使EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
遍历完成后 再执行后面的代码
昨夜冷雨 2011-07-17
  • 打赏
  • 举报
回复
应该不是这个原因
CppFile 2011-07-16
  • 打赏
  • 举报
回复
代码太长,注意到c=(StrToInt(Form1->Edit1->Text)-Form1->d)/5;
在线程中访问主线程vcl,要用synchronize
看说明:
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall simu::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------


昨夜冷雨 2011-07-16
  • 打赏
  • 举报
回复
bool MyEnumProc(HWND hwnd, LPARAM lParam)
{ AnsiString data;
AnsiString data1;
int x1,y1,jg;
char content[512];
char content1[512];
if (hwnd)
{
GetClassName(hwnd, content, 512);
data=(char*)content;
GetWindowText(hwnd, content1, 512);
data1=(char*)content1;
if(data=="WindowsForms10.BUTTON.app.0.33c0d9d")
{ //Form1->ListBox1->Items->Add("qqqxx "+data+" xx "+Form1->pl+" xx "+data1+" xx");
if(data1=="Enable Manual Fan Control")
{
Form1->lag=1;
if(SendMessage(hwnd,BM_GETCHECK, 0, 0))
{
Form1->lag1=1;
}
else
{
Form1->lag1=0;
}
GetWindowRect(hwnd,&Form1->fszb);

}
}
else
{
//Form1->ListBox1->Items->Add("rrrrxx "+data+" xx "+Form1->pl+" xx "+data1+" xx");
jg=data1.Pos(Form1->pl) ;

if(jg>0)
{

Form1->lag2=1;
}

}
return true;
}
else
{
return false;
}






}
昨夜冷雨 2011-07-16
  • 打赏
  • 举报
回复


//--------------------选择显卡--------------------------//

::Sleep(1500);
x=zb.left+443;
y=zb.top+275;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(1500);
x=zb.left+443;
y=zb.top+310;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
//----------------------条数据---------------------------------------//
x=zb.left+330;
y=zb.top+350;
SetCursorPos(x,y);
i=0;
while(i<25)
{
::Sleep(200) ;
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
i++;
}

i=0;
while(i<10)
{
::Sleep(200) ;
keybd_event(37, 37, 0 ,0);
keybd_event(37, 37, KEYEVENTF_KEYUP ,0);
i++;
}

::Sleep(500) ;
i=0;
while(i<p)
{
x=zb.left+328;
y=zb.top+350;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(100) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
i++;
}

//-----------------------------------------------------------------------//

::Sleep(1500);
x=zb.left+744;
y=zb.top+742;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);


//-----------------------------------------------------------------------//
::Sleep(2000);
open_mouse() ;
::Sleep(2000);

h=FindWindow(NULL, "Catalyst Control Center");
SetForegroundWindow(h);
GetWindowRect(h,&zb);

::Sleep(1500);
x=zb.left+443;
y=zb.top+275;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(1500);
x=zb.left+443;
y=zb.top+310;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);


::Sleep(3500);
Form1->lag2=0;
Form1->lag=0;
EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
::Sleep(3000);
if(Form1->lag2==0)
{
Form1->ListBox1->Items->Add("设置失败") ;
return 0;
}

::Sleep(5500);
//-----------------------------------------------------------------------//
if(Form1->lag==1)
{
if( Form1->lag1==0)
{
::Sleep(500);
x=Form1->fszb.left+5;
y=Form1->fszb.top+10;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
::Sleep(500);
x=Form1->fszb.left+140;
y=Form1->fszb.top+42;
SetCursorPos(x,y);

i=0;
while(i<20)
{
::Sleep(100);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
i++;
}
::Sleep(200) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
::Sleep(200) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
}
//------------------------------------------------------------------//

::Sleep(2000);
x=zb.left+784;
y=zb.top+24;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

Form1->ListBox1->Items->Add("设置频率成功!") ;
}
else
{
Form1->ListBox1->Items->Add("窗体打开失败!") ;
}

return 1;
}
昨夜冷雨 2011-07-16
  • 打赏
  • 举报
回复
bool simu:: Simulation_mouse(int p)
{
HWND h;
int i;
int x,y;
RECT zb;
//---------------------判断窗体已经打开关闭-------------------------------------//
h=FindWindow(NULL, "Catalyst Control Center");
if(h!=NULL)
{
SetForegroundWindow(h);
GetWindowRect(h,&zb);
x=zb.left+784;
y=zb.top+24;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}

//---------------------重新打开窗体-------------------------------------//
::Sleep(1500);
SetCursorPos(833,19);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0 ,0 , 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP,0 ,0 , 0, 0);
SetCursorPos(903,31);
mouse_event(MOUSEEVENTF_RIGHTDOWN,0 ,0 , 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP,0 ,0 , 0, 0);
::Sleep(5000);
h=FindWindow(NULL, "Catalyst Control Center");
if(h!=NULL)
{
SetForegroundWindow(h);
GetWindowRect(h,&zb);
//------------------------选择窗体----------------------------------//
x=zb.left+43;
y=zb.top+328;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(1500);
x=zb.left+62;
y=zb.top+351;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
//------------------------检测窗体是否打开----------------------------------//

::Sleep(3500);
EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
::Sleep(3000);

i=0;
while(i<5&&Form1->lag==0)
{
EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
y=zb.top+351;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(5000);

i++;
}
if( Form1->lag==0)
{
// Form1->ListBox1->Items->Add("异常 结束本次设置") ;
::Sleep(2000);
x=zb.left+784;
y=zb.top+24;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
return 0;
}
else
{
if( Form1->lag1==0)
{
x=Form1->fszb.left+5;
y=Form1->fszb.top+10;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(500);
}
}
//----------------------------选则显卡----------------------------------//
x=zb.left+443;
y=zb.top+275;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(1500);
x=zb.left+443;
y=zb.top+295;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
//------------------------条数据-------------------------------------//
x=zb.left+330;
y=zb.top+350;
SetCursorPos(x,y);
i=0;
while(i<25)
{
::Sleep(200) ;
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
i++;
}

i=0;
while( i<10)
{
::Sleep(200) ;
keybd_event(37, 37, 0 ,0);
keybd_event(37, 37, KEYEVENTF_KEYUP ,0);
i++;
}
::Sleep(500) ;
i=0;
while(i<p)
{
x=zb.left+328;
y=zb.top+350;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(200) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
i++;

}

//--------------------------风扇---------------------------------//



::Sleep(500);
x=Form1->fszb.left+140;
y=Form1->fszb.top+42;
SetCursorPos(x,y);
i=0;
while( i<20)
{
::Sleep(100);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
i++;
}
::Sleep(200) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
::Sleep(200) ;
keybd_event(39, 39, 0 ,0);
keybd_event(39, 39, KEYEVENTF_KEYUP ,0);
::Sleep(1500);
x=zb.left+744;
y=zb.top+742;
SetCursorPos(x,y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
::Sleep(2000);
open_mouse() ;
::Sleep(2000);
h=FindWindow(NULL, "Catalyst Control Center");
SetForegroundWindow(h);
GetWindowRect(h,&zb);
::Sleep(3000);
EnumChildWindows(h, (WNDENUMPROC)MyEnumProc, 0);
::Sleep(3000);
if(Form1->lag2==0)
{
//Form1->ListBox1->Items->Add("设置失败") ;
return 0;
}


13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧