|
that did the trick, just adding those two to the linker
|
|
|
|
|
Hi,
I have a dialog, a main dialog(MainDlg) that on press of a button creates another 12 dialogs, hidden.
All 12 dialogs hava about 20-25 controls on them and when i all Create for each of them the maindlg freezes for 1-3 seconds. I am thinking of creating a thread that creates all 12 dialogs when MainDlg begins to initialize.
So what I am doing now and it's not working. I have created a new class derived from CWinThread.
OnInitialise I have put: create(FirstDialog:IDD,g_thisParent)...g_thisParent is CWnd * pointing to 'this'. I made a function, Setup(CWnd *, Cdialog **dialogs); this is the pointer sent from OnInit of the maindlg functio.
On mainDlg ->Oninit, i have created CDialog *dialogs[12];
all dialogs are NULL and then dialogs[1]->new....(this);
anyhow: i start the thread with AfxBeginThread suspended, i call for Setup, and then I resume the thread.
I get assertion faild when I try to create using this as parent, but not when i use (CWnd*)this->GetParent wich is 0 . I don't want my dialogs to be the child of desktop window, I want them to inherit maidlg....what shall i do?
Is this a corect approach of the problem?
|
|
|
|
|
Do not create UI stuff (dialogs, controls, ...) from you secondary thread.
In you thread, you need to notify (for example using PostMessage) your main dialog to create the child dialogs.
read : http://www.flounder.com/workerthreads.htm[^]
excerpt :
"That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc."Watched code never compiles.
|
|
|
|
|
But the problem is that I must create the dialogs at sometime.
I have a menu
Backup
Restore
shedule
whatever
backup has 12 dialogs........ if i click on backup button i must wait.
I cannot avoid the creation of those dialogs. when clicking on backup they must be created, and when i create them, each oninit function in the dialog starts from 1 to 12.
In thread everything is ok....i win a lot of time(3 seconds) and when I click on backup......i seems it instantly loads. The only problem I get is that i can't set the parent right...
|
|
|
|
|
Why do you need to create ALL your dialogs when the main dialog starts ?
Me think it's bad design to do so, only create dialogs when you need them.
Anyway, unless you are doing some weird things, creating a dialog should not take that much time.Watched code never compiles.
|
|
|
|
|
Yes indeed the design is bad, and the problem problem started from weird things. There were some variables uninitialized entering in a loop from 0 to a few milions;)) so i was suggested to use a thread to create dialogs so i got stuck on this ideea:P
the problem is, that i can jump from a dialog to another.
|
|
|
|
|
I don't think this will work as you are creating them as part of the second (temporary?) thread when you want them to be part of the main GUI thread.
Instead, since these dialogs start out hidden, why not defer their creation. Set up a wrapper to create them on first display. This distributes the work so that you don't take the full hit all at once and it should be less noticeable.
You could also set up something to create them one at a time in CWinApp::OnIdle(), though you will need to make sure they are not used until created. You could combine this with the create on first demand scheme if you want.Please do not read this signature.
|
|
|
|
|
Good point, but using UI thread it's ok, my question is why i cannot set the parrent right, I think it has something to do with sending 'this' as param in Setup function....should I sent a handle to the window instead....the problem is I don't know how, I'm new in MFC GUI;))
|
|
|
|
|
In your thread, just post a message to your main dialog with (no data) and in that message handler in your main dialog you should be able to create your dialogs without problems. Watched code never compiles.
|
|
|
|
|
After doing a little checking, evidently you can do it with child windows on a 2nd UI thread. You do have to be careful about communications between the threads since there is a possibility of creating a deadlock between the threads. I would still tend to favor using OnIdle() instead of a 2nd thread to try and deal with your performance issue.
Apart from some quibbling over precise wording, I don't see the problem with what you are doing. As far as my quibbling goes, in the parent window code you call a setup function passing "this" as a parameter so that the thread class can save its value in a member variable called g_thisParent. g_thisParent is not a pointer to "this", it is a CWnd * to the parent window object. Also, in the second thread, you never, ever use "this" in an attempt to refer to the parent window, you use the variable you have named g_thisParent.
Other than that, my only thought would be some sort of synchronization issue - but I don't see what it would be.
Please do not read this signature.
|
|
|
|
|
bu7ch3r wrote: ...that on press of a button creates another 12 dialogs...
...the maindlg freezes for 1-3 seconds.
...what shall i do?
Do not press any button to create them,
just create them all in CMainDlg::OnInitDialog() virtual void BeHappy() = 0;
|
|
|
|
|
yes, but that makes the gui start slow .
|
|
|
|
|
Place a good splash window in another thread for your start virtual void BeHappy() = 0;
|
|
|
|
|
=))))) i am creating a serious application for my university degree:P I's a good ideea anyhow
|
|
|
|
|
How Could I Use a define macro identifier in an other define macro replacement list?
for example in the following example:
#define APP_TEST1 L"Test1"
#define APP_TEST2 L"Test2"
#define APP_TEST L"Test1 With Test2"
I want to represent the third define macro with 2 first macro?
|
|
|
|
|
#define APP_TEST APP_TEST1 " With " APP_TEST2
|
|
|
|
|
|
be really careful with macros, because it is hard to debug and in can lead to really bogouis errors.
=>
//const LPTCSTR APP_TEST1 = L"Test1";
const LPCTSTR APP_TEST1 = L"Test1";
...
Code quality is also an important issue
Press F1 for help or google it.
Greetings from Germany
modified on Friday, March 19, 2010 3:30 AM
|
|
|
|
|
KarstenK wrote: const LPTCSTR APP_TEST1 = L"Test1";
It should be LPCTSTR .
|
|
|
|
|
Good catch
|
|
|
|
|
Hi;
I am working on a project involving a PC onboard a robotic vehicle transceiving (say using Wifi 802.11 connection) sensors' info to another PC housed in another moving vehicle. There are data exhchanges in both directions in real-time. I am totally new to networking/comm between PCs. Please point me to sample code/tutorial on this topic.
Thanks.
Fun Wey
|
|
|
|
|
|
I have a function that will be called for all sorts of windows (it gets the HWND), and I want it to process only static icons, but not other types of controls like buttons, combos, etc. There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
|
can i convert unicode string to multibyte?
|
|
|
|