Topics in C ++ builder

I am new to C ++ builder and unfamiliar with streaming loading. I was hoping that someone could post an example or point me in the right direction.

I have a form that loads the formShow() function in a C ++ builder. It does what I want my program to execute, but only after that will display the actual form.

To do this, I need to draw the form and background course of the program. Can someone help me?

+6
source share
1 answer

It may be easier to simply defer your logic until the OnShow event OnShow , without using a thread at all. For instance:

 const UINT WM_DO_WORK = WM_USER + 1; void __fastcall TForm1::FormShow(TObject *Sender) { PostMessage(Handle, WM_DO_WORK, 0, 0); } void __fastcall TForm1::WndProc(TMessage &Message) { if (Message.Msg == WM_DO_WORK) { // do work here ... } else TForm::WndProc(Message); } 

If you really want to use the code, you can do it like this:

 class TMyThread : public TThread { protected: virtual void __fastcall Execute(); public: __fastcall TMyThread(); }; __fastcall TMyThread::TMyThread() : TThread(true) { FreeOnTerminate = true; // setup other thread parameters as needed... } void __fastcall TMyThread::Execute() { // do work here ... // if you need to access the UI controls, // use the TThread::Synchornize() method for that } void __fastcall TForm1::FormShow(TObject *Sender) { TMyThread *thrd = new TMyThread(); thrd->OnTerminate = &ThreadTerminated; thrd->Resume(); } void __fastcall TForm1::ThreadTerminated(TObject *Sender) { // thread is finished with its work ... } 
+8
source

Source: https://habr.com/ru/post/921245/


All Articles