|
Thanks for the speedy response.
I looked on the msdn library and i didnt find much about AddString, so i'm unclear as to how to use it. do i need to create a new class derived from CCombobox? or can i just do something like
my_combobox.AddString("yabbadabbadoo");
In my dodataexchange, i put
DDX_CBIndex(pDX, IDC_LANG, combo_box);
combo_box.AddString("hi");
where combo_box is defined as an int in my dialog class. it returned the error:
error C2228: left of '.AddString' must have class/struct/union type
|
|
|
|
|
keegan wrote:
or can i just do something like
my_combobox.AddString("yabbadabbadoo");
Correct, assuming that my_combobox is of type CComboBox.
|
|
|
|
|
ok, I've created a CComboBox Class called MyCombo. In the veiw.h file, i defined
MyCombo my_combobox;
now i've tried putting the my_combobox.AddString("yabbadabbadoo"); everywhere that i can think of. i tried putting it right before the DoMOdal(), i put it in the constructor of the Vew Class. darnit, where does ti go?
thanks for yer help...
|
|
|
|
|
The dialog window, nor any of its controls, exist prior to calling DoModal(). The only thing that exists at that point is the dialog object itself. The most common place to initialize controls is in the OnInitDialog() method.
|
|
|
|
|
yay! it works. i ended up adding the AddString function in my dodataexchange. but it works now.
Thanks for all your help!
|
|
|
|
|
I have a list of 50 variables all of type double.
They all have a min and max value that they have to be within.
I am trying to generate a numbers within this range for each of the variables, one that changes 3 times a second.
I thought about using the rand() function.
Any ideas on geting a random number between a specified range?
Do you think this is the way to go?
Thanks for the help,
sj;P
|
|
|
|
|
How about something like:
::srand(::time(NULL));
int min = 10;
int max = 20;
for (int i = 0; i < 100; i++)
{
int n = min + (::rand() % (max - min + 1));
TRACE(_T("n = %d\n"), n);
}
Or something similar?
When I am king, you will be first against the wall.
|
|
|
|
|
Robert,
Makes sense but, I am not familiar with the TRACE
could you explain this a bit more?
TRACE(_T("n = %d\n"), n);}
Thanks,
sj
|
|
|
|
|
It's part of MFC. It outputs to the debug window when in Debug mode, and does nothing in Release mode.
|
|
|
|
|
It works great thanks,
sj
|
|
|
|
|
Not to pick nits or anything, but I believe that the randomness of rand() is not guaranteed if you do a mod. You are essentially only using a subset of the random bits. If you want to be proper, you should divide the result by RAND_MAX to get a float in [0.0,1.0) which you can then scale apropriately.
J
"You can get anything you want at Alice's Restaurant."
|
|
|
|
|
When I divide by RAND_MAX, I get a 0 as the value.
When I divided by the mod I get a number between my min and max value, but it was a int.
How can I get the rand() to return a value between 2 doubles.
Here is my code, it might give you a better idea.
thanks,
sj
<br />
double createRandNum(TSimSignal &s, double min, double max){<br />
<br />
double n; <br />
<br />
for(int i = 0; i < 100; i++){ <br />
n = min + ((double)rand()) % (max - min + 1.0));<br />
or<br />
n = min + ((double)rand()/RAND-MAX) % ((double)(max - min + 1))); <br />
}<br />
cout << endl << "The random number is : " << rand()<< " N is : " << n << "\n";<br />
return n;<br />
}<br />
<br />
|
|
|
|
|
int randInRange(int minVal, int maxVal)
{
double scale = rand() / static_cast<double>(RAND_MAX);
return static_cast<int>(minVal + scale * (maxVal - minVal));
}
This returns a value in the range [minVal, maxVal). If you need [minVal, maxVal] you'll have to add 1 to the (maxVal - minVal) in the last line.
J
"You can get anything you want at Alice's Restaurant."
|
|
|
|
|
Does anyone know if it is possible to find the creation date\time of an executable from within the file ?
thanks in advance!
|
|
|
|
|
You could try fetching the full path of the EXE using ::GetModuleFileName and then use CFileStatus::GetStatus(...) to get the creation date...
When I am king, you will be first against the wall.
|
|
|
|
|
Hello guys. I'm new in this place and I'm new in the VC++ programming world (although I have tackled on C++ before). Well the thing is that we have 2 CCD cameras, specifically 2 EDCN2000N Cameras from Electrim Corp. and everything is fine and cool but ... they gave us a software that allows us to view the output of 1 camera and change some options, etc. but the most important thing is that it has a Save function (to save the image).
Now, the thing is that we want to have output from the 2 cameras (since we have 2 connected to the same interface card.) We contacted them and they sent us the source code for the new software and it works flawlessly but ... IT DOESN'T HAVE A SAVE FUNCTION!!!!! (you can look at the code in a zip file here: http://www.prtc.net/~eagle1/soft.zip ).
Now, I don't know much about VC++ so I sent them another email and they sent me a code that has a save function (to save to tiff) but again, it works for one camera at the time and I have tried like to copy and paste the code to save as tiff file to the program with multiple camera support but it does nothing (http://www.prtc.net/~eagle1/readedcn.zip) .
So question is, is there an easy way to save those images using the code from the soft.zip and readedcn.zip I posted?
I was also looking at CxImage (or something similar) but ... it seems difficult to use! I made changes in the .rc file and added a Save button and in the sdk_mh.c file I added a case for IDM_Save but I just put a message box to know it was working but,
HOW do I Save the Window contents (i.e. the image) to a Tiff file or jpeg? Can you help me with this?
Thanks in advance!!
|
|
|
|
|
|
when I call as :
CFileFind localFind;
localFind.FindFile (_T("*.*"));
localFind.FindNextFile ();
FILETIME timeLastWrite;
localFind.GetLastWriteTime (&timeLocalFile);
SYSTEMTIME timeFile;
FileTimeToSystemTime(&timeLastWrite,&timeFile);
i found that the file'w lastwritetime I got is inconsistent with the info. displayed by win2k.
win2k: 2003-06-25 23:50
programme: 2002-06-25 23:50
wrong with Year?
thx for advance
|
|
|
|
|
Does this happen with all files?
What happens if you use this instead:
CTime timeLastWrite;
localFind.GetLastWriteTime(timeLastWrite);
TRACE("%d\n", timeLastWrite.GetYear());
|
|
|
|
|
Hello you out there,
I am currently developing a tiny database program and therefore using a CMapStringToOb to store my user-defined objects in memory. During development, I suddenly faced a strange problem concerning memory usage and memory leaks. I thought that something was wrong with my class and therefore created a small class called CTest, which in fact is only a "box" or an int, I know it's silly, but, hey, it's at least maybe more easy to understand than a class with CStrings and so on...
<br />
class CTest : public CObject<br />
{<br />
private:<br />
int m_TestInt;<br />
<br />
public:<br />
CTest() { m_TestInt = 0; }<br />
CTest(int NewTestInt) { m_TestInt = NewTestInt; }<br />
~CTest() {}<br />
void SetInt(int NewTestInt) { m_TestInt = NewTestInt; }<br />
int GetInt() const { return m_TestInt; }<br />
};<br />
Then I'm using it with my CMapStringToOb:
<br />
CMapStringToOb *pTestObs = new CMapStringToOb;
pTestObs->InitHashTable(50000,TRUE);
<br />
char buffer[6];<br />
<br />
for(int i = i; i<= 49999; i++)<br />
{<br />
pTestObs->SetAt(_itoa(i,Buffer,10), new CTest(i));<br />
}<br />
Ok, up to here, everything works fine. I can retrieve my elements by calling "Lookup" and so on.
But now, please have a look at that piece of code in which I'm trying to delete my objects as well as the pointers and the "Map" as stated in the MSDN:
<br />
POSITION pos = pTestObs->GetStartPosition();
<br />
while(pos != NULL)<br />
{<br />
CString String;<br />
CTest* pTest = NULL;<br />
pTestObs->GetNextAssoc(pos, String, (CObject*&)pTest);<br />
pTestObs->RemoveKey(String);<br />
delete pTest;<br />
}<br />
<br />
<br />
delete pTestObs;<br />
The problem with this piece of code now is that, in Debug mode, everything seems to work just fine, I added some ::AfxMessageBox(...); statements in order to know what goes right and what goes wrong.
These CObjects need roughly 7 MB of RAM on my machine. In Debug mode, the upper code frees 7 MB, as previously needed and allocated. But in Release mode, after creating these objects and inserting them into the CMapStringToOb, this part of the code only frees round 3 MB of the memory. But... where is the rest?! I am leaking 4 MB of memory and dealing with much larger objects in the REAL program, which might easily mean around 20 MBytes.
Can any one help me? Does anyone know what I am doing wrong?
Best regards and thanks in advance,
pf7
(@ All Americans: I live in Germany, so please do not think that I won't reply immediately. It's just because of the difference in time. I'll reply!)
|
|
|
|
|
No one to help me out there?
|
|
|
|
|
Get rid of the RemoveKey statement. After deleting all the objects, you can call RemoveAll().
onwards and upwards...
|
|
|
|
|
Thanks, but, as you can see, I've already commented the "RemoveAll()" out with the statement "didn't help either!" The fact is that, as stated in my first question, it seems as if the objects are not deconstructed correctly. But only in Release mode, not in Debug mode. I've heared that the debug mode features some type of "garbage collection" but when executing my script I do not get compiler warnings or debugger messages saying that it is deleting / destructing any instances of my object.
It's strange, I know, but if any one of you tried it out the way I did, it would - hopefully - have the same result: a memory leak of which I don't know what the cause might be.
|
|
|
|
|
@basementman: Thanks for at least reading the whole thing Seems as if no one except you has any tips or wants to help me finding the solution
|
|
|
|
|
Are you still having this problem. I have used code like this a hundred times in the past. I avoid MFC template classes and I recommend STL now because after learning STL you will get template classes with much more flexibility, functionality and portability. However looking at your code I do not see any reason why there is a memory leak.
John
|
|
|
|