|
The problem with that is that when you add a new element to the map, only a pointer will be copied, not the contents of the array. So you need to keep track of these pointers and make sure they'll be deleted later.
The STL construct suggested above doesn't suffer from these problems, they'd do the copying for you.
I can think of no reason at all why anyone would want to use MFC when there is an easy to use alternative. Much of the MFC library is ancient and in a very bad shape. My personal experience is that, while you don't run into problems often, when you do it can take days to resolve the cause. I know for a fact that back in the time when I still used MFC I've lost weeks of valuable time just due to sloppy programming inside MFC. I've never had any such problems with STL.
|
|
|
|
|
2 threads call same global function at almost same time, the global function looks like
void MyFunction(int iWho)
{
CString cs;
cs.Format("%d",iWho);
edit.SetWindowText(cs);
edit.RedrawWindow();
Sleep(3000);
edit.SetWindowText(cs);
edit.RedrawWindow();
Sleep(3000);
edit.SetWindowText(cs);
edit.RedrawWindow();
Sleep(3000);
}
2 threads pass param 0 and 1 respectively to the function.
I hope that I can see 2 treads call the function in turn.
In other words, '0' and '1' are displayed in turn in some way.
But, at test, '1' appears only when all of 3 '0' are displayed.
Any suggestion for the "in turn" thread test?
.
|
|
|
|
|
Why would you think manipulating a UI control (i.e., edit box) from a secondary thread would be a good idea?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
You cannot force such a behaviour (expecially on a single core machine ).
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]
|
|
|
|
|
Dual or more cores machine as I use now?
|
|
|
|
|
Well even on multiple cores, there's no way for user code to predict thread scheduling sequence.
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]
|
|
|
|
|
includeh10 wrote: I hope that I can see 2 treads call the function in turn.
Hope away. In software development, there is no room for hope.
FWIW: the macroscopic behavior of threads (at a rate the human eye can discern) often is quite different from their actual, microscopic behavior. That is due to the specific scheduling algorithms implemented in the operating system; there always are some constants (e.g. "time slice") and, at least with Windows, there even is some cheating as far as thread priorities go.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
this kind replies should be thrown into rubbish bin.
|
|
|
|
|
You shouldn't throw away knowledge. Instead you should accept reality as it is.
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]
|
|
|
|
|
Don't ask questions if you don't want to have answers.
Watched code never compiles.
|
|
|
|
|
The point of multithreading is to work in parallel on objectives that are not dependent on each other, and therefore don't care about order of execution.
If you do care about order of execution, use a single thread.
If you try to let your threads do only some things in a particular order, then you need synchronisation objects, such as a mutex or semaphore.
|
|
|
|
|
how to use the CFileDialog box to open the folder.....
i had done to open the .file extension which successfully opening but i am not able to open the folder plz help out this .....
|
|
|
|
|
sarfaraznawaz wrote: how to use the CFileDialog box to open the folder.....
Why not use SHBrowseForFolder() instead?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
CFileDialog automatically opens folders as they are selected by the user navigating a directory tree. Perhaps you could clarify your question.
The best things in life are not things.
|
|
|
|
|
i tried but not able to open or select the particular folder .....
here my code forit
void CfolderlockUIDlg::OnBnClickedAdd()
{
TCHAR szFilters[] = _T (" Allfolders(* *)¦* *¦¦");
CFileDialog dlg (TRUE, _T ("folder "), _T ("folders "),OFN_FILEMUSTEXIST |OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilters,this);
//CFileDialog dlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT ,NULL,NULL,0);
if (dlg.DoModal () == IDOK)
{
filepath = dlg.GetPathName();
m_edit.SetWindowText(filepath);
}
}
by this it shows all the folder but i cant select the or open the folder
|
|
|
|
|
Do you want to select the folder or the the file inside the folder? if its the folder then you can use the function that was mentioned by David
here is an example for that
BROWSEINFO bi;
ZeroMemory(&bi, sizeof(bi));
TCHAR szDisplayName[MAX_PATH];
szDisplayName[0] = '';
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = _T("Please select a folder for storing received files :");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lParam = NULL;
bi.iImage = 0;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
TCHAR szPathName[MAX_PATH];
if (NULL != pidl)
{
BOOL bRet = SHGetPathFromIDList(pidl,szPathName);
if(FALSE == bRet)
return;
AfxMessageBox(szPathName);
}
and if you are selecting a file then you can see this example
SelectDialog - A Multiple File and Folder Select Dialog[^]
|
|
|
|
|
thanks its working.....
but one thing that its necessary to make browseinfo as zero memory ......
|
|
|
|
|
CString str;
str.Format(_T("All Files (*.dat)|*.dat||"));// change name .dat to any extension you want
CFileDialog file_dlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,str);
INT_PTR iRet = file_dlg.DoModal();

|
|
|
|
|
|
What do you mean 'passing arguments'? That code is complete and should compile and run without any additions.
The best things in life are not things.
|
|
|
|
|
I ran the program sucessfully with out put as "This sample takes a file name as a parameter".
Now i am having a file like c:\temp.txt and i want to know timestamp for this what is supposed to be done for this.
vikas da
|
|
|
|
|
You'll have to provide the name of the file as command line parameter.
For example lets consider the compiled executable is called TimeStamp.exe.
Execute the program from the command line (console): TimeStamp.exe c:\textfile.txt
As the name implies it, a command line parameter is passed from the command line.
In the code you've linked you can see how the parameter is accessed using the argv array.
modified on Monday, May 23, 2011 7:52 AM
|
|
|
|
|
I do not see any such exe in my Debug or Release folder,I am using VS 2008 Pro.
Apart from that i have to use this sample in one of my application to find the creation timestamp of a file,so help me achieving that same.
Thanks,
vikas da
|
|
|
|
|
The builded exe is in your Release and / or Debug folder. Look for it. I didn't say the exe will be called TimeStamp.exe at you local PC! It was just an example. The name of the exe depends on your Project Settings (the project name by default).
But then if you want to use only the logic shown in the code that you've linked in a program of yours, of course you don't need to build this exe at all but rather use the code that fullfills the desired task. And then again you dont have to provide the filename as command line parameter. This is totally up to you.
For the beginning .. it would for your case probably enough if you change the following line.
hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, 0, NULL);
The argv[1] here contains the file name. You could also hard code this filename like
hFile = CreateFile("C:\tmp.txt", GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, 0, NULL);
You'd also have to remove this if you dont want the code to be dependent of the number of command line parameters..
if( argc != 2 )
{
printf("This sample takes a file name as a parameter\n");
return 0;
}
Or get the filename somewhere else. i dont know what you want to do but you'll have to think of stuff like that for yourself.
I strongly advise you to go through some basic C/C++ tutorials, since you seem to lack some basic understandings of the language here.
|
|
|
|
|
Having compiled and built this program you must have a program (xxx.exe?) in either your Debug or Release folder; check again. This is a simple console program that can be run in a command prompt window (are you really saying you do not understand this basic facility?) thus:
ProgramName C:\filename.txt
In order to add this functionality to your own project you can just copy and paste the relevant parts of the sample into your own project.
The best things in life are not things.
|
|
|
|