|
Hi all,
I have made a dialog based application in vc2008, in that application i have created a list control. In that list control i am displaying file names from a particular folder......
suppose folder contains 2500 files and allfiles are bmp type, i am also displaying system icon(which is picked up from system at runtime only) in front of every file.
Now the problem is as soon as i click on adding file to my list control only border of my list ctrl is displyed and everything becomes white and after some time not responding status is being shown and after some time application crashes. i have monitored its memory usage from task manager it exceeds very fast and its very high...
i am not getting how to resolve it and infact what exactly the problem is...
can anybody help me in this....
|
|
|
|
|
Hi,
the symptoms you describe typically appear when another thread is accessing some controls that were originally created by the main thread. Only the main thread should ever touch any of the controls,
they are not thread-safe. You probably have to rethink the threading scheme used.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
You could process messages from time to time in order to keep the UI alive, something like this:
MSG msg;
while (::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
if (!(AfxGetApp()->PumpMessage()))
{
::PostQuitMessage(0);
break;
}
}
Don't know why your app is using so much memory, 2500 items isn't that much...
|
|
|
|
|
Michael Schubert wrote: Don't know why your app is using so much memory, 2500 items isn't that much...
Except if he is loading 2500 big bmp files
|
|
|
|
|
it constitute about 7gb data
|
|
|
|
|
Are you just adding the file names to the list control or do you process the files in some way while adding?
|
|
|
|
|
Well, he's just displaying the file names for these files. It must be the icons he loads for each file.
|
|
|
|
|
So let the application always read as less data as possible.
|
|
|
|
|
What kind of technique have you followed to read and update the UI? Are you using a separate thread to read data about the files? If you are doing everything with your application's main thread, there's very little hope for the UI to respond. You can manually pump messages, but I don't see it is a great idea.
I would personally use a worker thread to read data from files and post user-defined messages from the thread to the main window and let the main window handle those messages to update the UI.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
1. I created a empty win32 project in VS2008.
2. Add a very simple cpp file to the project, it compiles.
3. Try to using the precompiled header mechanism by
(
1. Add stdafx.h and stdafx.cpp to the project
2. Set the project property by selecing "Use Precompiled Header (/Yu)"
(and it'll be stdafx.h by default)
)
Then failed to rebuild all, the first error is:
d:\test\test\stdafx.cpp(1) :
fatal error C1083:
Cannot open precompiled header file:
'Debug\test.pch':
No such file or directory
I compared the compiler option with a working MFC project, the compiler command are the same, so what is the project?
|
|
|
|
|
IDE shuold generate stdafx.pch first.
to achive that, select stdafx.cpp and change precompileheader option
to create one. (maybe /Yc)
|
|
|
|
|
I tried, the option /Yc can generate the .pch file.
After that I changed /Yc to /Yu , it got
compiling error.
Also, in an MFC project, the .pch file will be generated automatically
either when I delete the .pch file or I change stdafx.h, without using
/Yc but /Yu .
I seems a little compicated.
|
|
|
|
|
Hi
I am looking for an easy way to create GUI for my application. User needs to draw dots on a plane with 3 available colours. The program will then remember the coordinates/position of these dots and let the user inpute few parameters for each dot.
This will be a GUI for a computer simulation program, an interface for setting parameters of that simulation.
Can anyone advise an easy, fast way to program it? I can write a code in Visual Studio or some other IDE.
|
|
|
|
|
I think the easiest would be to create a MFC application and use GDI to draw the points (you can use CDC::Ellipse[^] for instance). But if you are completely new to MFC, I suggest you learn MFC from the start (using a book or online tutorial).
|
|
|
|
|
I don't know anything about MFC, that's why I'd rather avoid learning it to save my time. I am looking for some control that can be used to draw shapes, but I can't find it. I know that there are such components in Java in Netbeans and now I'm looking for something similar.
|
|
|
|
|
Member 4124956 wrote: I am looking for some control that can be used to draw shapes
That's rather vague. What are you looking for exactly ?
Anyway, even if you find such a control you will still need to learn some basic stuff with MFC. You'll have that problem with whatever you will choose: a minimum knowledge of the framework you are using is always needed.
|
|
|
|
|
In Java I used a panel or sth (I can't remember terminology) which I could add to my window, and I could draw what I wanted in that panel. I could easilly check the color, position etc of everything what I painted just using the object properties, functions.
I will check what it exactly was.
|
|
|
|
|
In Java we can use jPanel, jColorChooser and classes:
java.awt.Color
java.awt.Graphics
to obtain such a GUI. This function shows the simplicity of that solution:
private void jPanel1MousePressed(java.awt.event.MouseEvent evt) {
int X = evt.getX();
int Y = evt.getY();
Graphics gr = jPanel1.getGraphics();
gr.setColor(jColorChooser1.getColor());
gr.fillOval(X, Y, 10, 10);
}
Is there anything similar in C++?
|
|
|
|
|
Hi,
im using RemoveDirectoryW() ...the problem is..
RemoveDirectoryW(L"c:\\test\\testing");
the above deletes the folder testing but when....
the path to delete is present in two LPCWSTR"s then how can i add them ie...
LPCWSTR lpPath1=L"c:\\temp\\folder1\\";
LPCWSTR lpPath2=L"testing\\tester";
i need to pass the combination of the above to RemoveDirectoryW()(finally i should delete tester).....Please let me know how can i do this....
|
|
|
|
|
Not sure what you're trying to do. Do you want to delete a directory that has sub-directories? Could you re-phrase your request a bit?
|
|
|
|
|
Yes i will .....
I need to delete a folder named "Test" which is present in the folder TEMP(Environment variable)...
im able to get the path of TEMP using...
WCHAR buffer[1042]={'\0'};
DWORD size=1042;
::GetEnvironmentVariableW(L"TEMP",(LPWSTR)buffer,size);
CString csPath;
csPath=buffer;
im able to get the path of TEMP in csPath... now i have to delete the folder Test which is inside that TEMP folder....
When i use RemoveDirectoryW() i need to pass the path(in LPCWSTR) to Test folder....so please help me to attain this....
|
|
|
|
|
|
To concatenate the two strings, you could use something like this:
LPCWSTR lpPath1=L"c:\\temp\\folder1\\";
LPCWSTR lpPath2=L"testing\\tester";
std::basic_string<WCHAR> strPath = lpPath1;
strPath += lpPath2;
RemoveDirectoryW(strPath.c_str());
This requires a #include <string> . Note that I'd recommend generic text mappings (with _T , etc.) instead of just using Unicode directly.
|
|
|
|
|
Thanks for ur support....
May i know how to achieve this if lpPath1 is a Cstring.....
|
|
|
|
|
CString strPath1 = _T("c:\\temp\\folder1\\");
CString strPath2 = _T("testing\\tester");
CString strPath = strPath1 + strPath2;
RemoveDirectory(strPath);
|
|
|
|