C++ builder FMX 遍历窗口所有控件 并 动态消失

原创  可转载  请注明 来处

 

cpp:

void TForm1::HideAllControl(bool vshow){
if(! vshow){
FOldPostion->Clear();
for (int i = 0; i < ComponentCount - 1; i++) {
TPropInfo *info;
TPropInfo *infoVisiable;
TObject* objTemp;
objTemp = GetObjectProperty(Components[i], "Position");

infoVisiable =    GetPropInfo(Components[i],"Visible");

if ((objTemp) && (infoVisiable)) {
info = GetPropInfo(objTemp,'Y');
if (info) {
float y = GetFloatProp(objTemp, 'Y');
FOldPostion->Values[Components[i]->Name] = FloatToStr(y);
int j = y;
int x = 1;
for (j; j < ClientHeight; j += x) {
SetFloatProp(objTemp, info, j);
Sleep(3);
Application->ProcessMessages();
Updated;
x += 1;
}

if (infoVisiable) {
SetVariantProp(Components[i], infoVisiable, 0);
}

}

}

}
}
else {
for (int i = 0; i < ComponentCount - 1; i++) {
TPropInfo *info;
TPropInfo *infoVisiable;
TObject* objTemp;
objTemp = GetObjectProperty(Components[i], "Position");

infoVisiable = GetPropInfo(Components[i], "Visible");

if ((objTemp) && (infoVisiable)) {
info = GetPropInfo(objTemp, 'Y');
if (info) {
float y = 0;
int k = StrToInt(FOldPostion->Values[Components[i]->Name]);

int j = y;
int x = 1;
for (j; j < k; j += x) {
SetFloatProp(objTemp, info, j);
Sleep(3);
Application->ProcessMessages();
Updated;
x += 1;
}

if (infoVisiable) {
SetVariantProp(Components[i], infoVisiable, 1);
}

}

}

}

}
}

 

.h

Public:

void HideAllControl(bool vshow);

 

匿名线程调用:

//定义个  cpp 调用delphi  proc 的类 窗口继承 Form

class TSleepFunc : public TCppInterfacedObject<TProc> {
public:
//这里建议用自己继承的TForm。由于后面所需參数要从Form获得
TSleepFunc(TForm1* Form) : FForm(Form) {
}

virtual void __fastcall Invoke(void) {
//这里处理你多线程代码
//參数所有是 TForm3的变量,多线程中所需參数从TForm中声明
FForm->HideAllControl(false);
FForm->HideAllControl(true);
//这里处理和TForm交互内容
//    TThread::Synchronize(TThread::CurrentThread,UpdateCaption );
}

void __fastcall UpdateCaption(void) {
FForm->Caption = "OK";
}


private:
TForm1* FForm;
};

 

void __fastcall TForm1::btn14Click(TObject *Sender) {
// std:: thread T1(HideAllControl,false);
// T1.join() ;

TThread::CreateAnonymousThread(new TSleepFunc(this))->Start();
}

posted @ 2020-09-03 11:39  黑贝是条狗  阅读(374)  评论(0编辑  收藏  举报