|
Hi all,
I have a problem with multithreading I want to make a dialog in a new thread. And I want to paint in this dialog a scale view of what is painted in the parent window (of an MDI application) . I have studied the MSDN reference but still now is not clear to me how to do this. So my questions are:
1- Where can I find some sample that fit my necessity?
2- I have to start a UI Thread or a work thread?
3- If this is simple can anyone give me some little indication on where to start?
Thank you in advance for your help
|
|
|
|
|
No really an answer to your question, but a tip:
Try to avoid multithreading if possible . For almost all situations, the CWinApp::OnIdle can be used for doing things in the background. I personally strongly think that multithreading is for drivers and low-level system software only.
Regards,
Mattias
|
|
|
|
|
Thank you for your answer mattias.
So if I had understood well to make the dialog That I have to do you think that it is better to do a modeless dialog?
I wanted to use multithreading in my application in order to make pratice with multithreading. That's because the next task I had to reach with my software is the link of the user interface with a hub that will pass the information required to the interface. You think that I will do this only by using CWinApp::OnIdle?
|
|
|
|
|
Yes, I think that you could accomplish that with OnIdle , and probably easier and more robust than with multithreading. In the implentation of OnIdle , check for changes in the datasource and update user interface accordingly. Or, if the changes in data aren't that frequent, you could even get by using a timer (SetTimer and handling WM_TIMER )
But if you want to get some experience using threads, go ahead! I would recommend doing it the "hard" way without any help from any class libraries, look for CreateThread in the Win SDK. A short sample is: http://msdn.microsoft.com/en-us/library/ms682516(VS.85).aspx[^]. But I can guarantee that you will end up with lots and lots of debugging problems and very complicated code
Cheers
|
|
|
|
|
Thank you!
I will prove your solution I hope that I can do anything without any addictional thread but I think that for the connection whit the hub at the end I will have to develop at least one additional thread besides the main thread because if I have understood well the OnIdle (that I'm studying right now) if I put in this function an infinite loop that listen the hub messages I will block the User Interface . And unfortunately I think that I have to do a never ended loop. So I think that for this task I will use your advise and instead of AfxBeginThread I will use the "hard way" to make multithreading . Thank you again
|
|
|
|
|
Why do you need a new thread?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
In the case that I have posted in the first post only to make practice with multithreading (I know that I can do the dialog with the characteristics required also with a simple modeless dialog). In the second situation that I have described (the connection with an hub) instead I want to make a thread that listen continuosly to the hub (that receive an send message to six linked servive) and than communicate to the main thread any message of interess. In my company we are developing a multiservice software and I'm developing the User interface of it.
|
|
|
|
|
Laan82 wrote: I want to make a thread that listen continuosly to the hub...and than communicate to the main thread any message of interess.
Use PostMessage() for this. Don't put UI components in the secondary thread(s). See here for more.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank you I will try also this solution!
|
|
|
|
|
I want to release memory for
int a[4][6] which is allocated dynamically.
I m allocating this memory as
for(int i = 0;i<4; i++)
{
a[i] = new int [6];
}
And deallocating it as
for(int j = 0; j<4; j++)
{
delete []a[i];
}
Is the way of allocating & deallocating memory is right or not?
Thanks in advance.
Regards
Nikesh
|
|
|
|
|
I want to release memory for
int a[4][6] which is allocated dynamically.
I m allocating this memory as
for(int i = 0;i<4; i++)
{
a[i] = new int [6];
}
And deallocating it as
for(int j = 0; j<4; j++)
{
delete []a[i];
}
Is the process of allocating & deallocating memory is right or not?
Thanks in advance.
Regards
Nikesh
|
|
|
|
|
Seems to be but in your second loop you are using i and not j as you probably should, that!s just a copy-paste problem in the post here i supose...
for(int j = 0; j<4; j++)
{
delete []a[i];
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
as addendum to Code-o-mat, you may use (instead of hard-wired limits)
for (int j=0; j< sizeof(a)/sizeof(a[0]); j++)
{
delete [] a[j];
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, i wonder why C++ doesn't have something like an itemcountof or such operator for that by default. Many times it would be useful, i keep making macros for sizeof(array)/sizeof(array[0]) and i keep forgetting where i put them.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Nikesh Jagtap wrote: int a[4][6] which is allocated dynamically.
Not unless you've declared it as:
int **a = new int*[4];
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi. I have a dll app I've downloaded from web and now trying to modify it to suit my needs. But when I try to make some changes I'm getting this message. How to save my work?
Thanks in advance.
|
|
|
|
|
Copy the contents of the file you have changed via Ctrl-C, and then paste it into Notepad and save it to a new file. Then close VS, change all the RO files to RW, and reopen the project. Then copy/paste the saved contents to the file you were editing.
To change file attributes (optionally including all subdirectories) I use the free Properties Plus: http://www.softlookup.com/display.asp?id=25161[^]
|
|
|
|
|
Well, without knowing anything more about what you are trying to do i can think of 2 general things:
-Your target file has the read-only proparty set to it, remove it for example with Explorer (right-click the file, select "Properties" and uncheck "read only")
-Your target file is in use by another process (could be also a thread by the same process)
What exactly are you trying to save there? And how do you wish to modify a DLL? You have sources for it? Or you are editing it with some binary editor or such? Maybe that DLL has been loaded by some app and that is while it is locked.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
i want to display numeric values in edit box whenever i scroll up or down.
thanks in advance
|
|
|
|
|
Anjali Patil wrote: i want to display numeric values in edit box whenever i scroll up or down.
Hi Anjali,
I think you need the CSpinButtonCtrl[^].
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hi Experts,
I have big problem,
Am new to MFC.
problem :: I want to create a modelless dialog from inside a thread..Am using RunModalLoop. But my parent window has got stucked....
Any suggestion will be welcome
Please do help me
|
|
|
|
|
If you want a modeless dialog, why use RunModalLoop ? Prototype for creating modeless dialogs could be something like:
void DoTheDialog(CWnd* wndParent)
{
static CMyDialogClass* pDlg = NULL;
if(!(pDlg && ::IsWindow(pDlg->GetSafeHwnd())){
pDlg = new CMyDialogClass();
pDlg->Create(IDD_DIALOG_CLASS, wndParent);
}
pDlg->ShowWindow(SW_SHOW);
}
|
|
|
|
|
|
Hello!
I run my MFC application using the .exe icon from the debug folder, now my requirement is if once i start my application, if again i press the same exe icon it shoud give a message "one instance is already running !" and shouldn't launch the application !!
how to do it ?
thanks!
|
|
|
|
|
Did you read here here[^] and there a lot of other articles on the net. Just google and pick up the one that best suits your needs.
If just you had googled
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|