|
//linear transformation
#define GetRandom(min,max) rand()*((float)((max)-(min)))/(float)(RAND_MAX)+(min)
//this only works when min and max are small
/* GetRandom returns a random integer between min and max. */
#define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I'm trying to make an icon editor, but i don't know which colors to use for the palettes. Do you use the standard windows system palette? Is there any way to find out what the color values are for it? For example:
COLORREF stdpal16[] = {/*color values*/};
COLORREF stdpal256[] = {/*color values*/};
thanks.
|
|
|
|
|
i need to be able to read a line from a text file and store what is read in int.
|
|
|
|
|
|
Try this,
CFileException ex;
CFile myfile;<br />
<br />
myfile.Open("c:/b.txt", CFile::modeRead, &ex);<br />
<br />
int z=myfile.GetLength();<br />
char* data=new char[z];<br />
myfile.Read(data,z);<br />
<br />
int* value=new int[z/3];<br />
for(int i=0;i<z;i=i+3)<br />
value[i/3]=atol(&data[i]);
<br />
myfile.Close();
|
|
|
|
|
what header file to i need for this code?
|
|
|
|
|
No header is required. Stdafx.h is sufficient i think. CFile is a class of MFC. Refer to MSDN
|
|
|
|
|
what do you man when you say that you want to store the data in int.
do you want to store the number of bytes you read from a file in int'or do you want to store the data in int(in that case -> ???????)?
regards,
Eli
|
|
|
|
|
i want to store the data in int.
|
|
|
|
|
Assuming that your file has CR/LF at end of each line.
The code below might be easier
<br />
CStdioFile myFile("Sample.txt",CFile::modeRead );<br />
CString myBuffer;<br />
int myInteger = 0;<br />
LPCTSTR pMyBuffer,<br />
pMyBufferEnd;<br />
<br />
myFile.ReadString(myBuffer);<br />
<br />
while(!myBuffer.IsEmpty()){<br />
pMyBuffer = myBuffer;<br />
pMyBufferEnd = pMyBuffer + myBuffer.GetLength();<br />
cout << pMyBuffer << endl;<br />
<br />
for( pMyBuffer;pMyBuffer <= pMyBufferEnd; pMyBuffer++)<br />
{<br />
<br />
if((*pMyBuffer < '0') ||(*pMyBuffer > '9'))<br />
{<br />
cout << myInteger << (LPCTSTR) " ";<br />
myInteger = 0;<br />
}<br />
<br />
else<br />
{<br />
myInteger *= 10;<br />
myInteger += *pMyBuffer - 48;<br />
}<br />
<br />
}<br />
<br />
cout << endl;<br />
<br />
myFile.ReadString(myBuffer);<br />
}<br />
<br />
myFile.Close();<br />
I'll e-mail you a demo. It's a console app (don't worry it supports MFC!)
Good luck, happy programming,
Alton
|
|
|
|
|
Hello,
This is regarding the listview app.
I am able to compile this in debug mode but it does not work when i try to run the executable. Does anyone know why this is?
void CReportCtrlDemoView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
srand((unsigned)time(NULL));
CRASHES HERE: m_wndList.Create(this, 0, NULL, 0);
Please help with this.
thanks,
Lino
this is the link to the code:
http://www.codeproject.com/listctrl/ReportControl.asp?df=100&forumid=29500&select=1048274"
|
|
|
|
|
Hmmm, are you using DDX to create the m_wndList control? If so it already exists by the time you hit the code that causes the crash and the crash is in fact an ASSERT telling you that the list control already exists. This would explain why it works in release (implied in the title) but not in debug.
Rob Manderson
I'm working on a version for Visual Lisp++
My blog http://blogs.wdevs.com/ultramaroon/[^]
|
|
|
|
|
how do i fix it?
if you are referring to:
DDX_Control(pDX, IDC_LIST1, m_wndList);
inside the DoDataExchange() it does not exist.
Let me caution u that i am not an expert in this so if you have the patience be as explicit as possible.
thanks,
Lino
|
|
|
|
|
Hi
The exact issue is in PreSubclassWindow() method of ReportCtrl class.
ASSERT(GetHeaderCtrl() != NULL);
ASSERT macro will work only in debug version and not in Release.
so it wont throw exception in release mode.
comment the above code in your class and try.
thks
Jibesh.V.P
Jibesh.V.P
www.m2India.com
|
|
|
|
|
that was it thank you...
greatly appreciate your help.
Lino
|
|
|
|
|
Hi, I've been creating, a semi-portable thread class.
all of it works fine, but i'm having trouble,
understanding how to pass the address of my structure,
through the void* of beginthreadex, and if then how to,
access the structure again from there.
here's a little code to help better explain my problem:
typedef struct {
char* szReference;
__w64 unsigned uHwnd;
unsigned uReferenceLength,
uIdentity,
uState;
} Thread_barrer;
void CCThread::SetFunction(unsigned(__stdcall *uFunction)(void*))
{
this->vfThreadProc = uFunction;
}
void CCThread::InitThread(Thread_barrer &tbObj)
{
tbObj.uHwnd = _beginthreadex(
0,0,vfThreadProc,(void*)&tbObj,
0,&tbObj.uIdentity);
}
but to pass the address of the context (&tbObj <above>) through void*
and access it inside:
unsigned __stdcall ThreadCentre(void *vArguments)
{
Thread_barrer tbObj;
printf("predicted address of tbObj: %d\n",vArguments);
return (1);
}
i'd assume that you could set another context to that address,
but it's not easy to find viable info , on such unique tasks.
note: this all compiles fine, I'm having trouble with using the address,
passed through __beginthreadex to access the context there of.
any tips, or ideals will help.
thank you.
A world without knowledge, is a world without life.
|
|
|
|
|
When you call _beginthreadex() you cast a Thread_ barrier* to void* , so in the thread function you just cast it back:
unsigned __stdcall ThreadCentre(void *vArguments)
{
Thread_barrer* ptbObj = (Thread_barrer*) vArguments;
...
}
--Mike--
LINKS~! Ericahist updated! | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Thanks Mike, i had been trying stuff, close to that, but thanks.
|
|
|
|
|
Ok, i have a problem with classes. I have searched the forums, but all classes on here are so much more complex. (I know i'm a beginner, but we all have to start somewhere ) I have tried, but can't figure it out. I want this program to do two functions, as seen, and then show the sum of these two functions. I have to learn classes for a more difficlut uni assignment, so help would be great!
cheers!!!
#include <iostream.h>
class rectangle
{
public:
rectangle();
double sumA();
double sumB();
private:
double a,b,c,d,e,f,g;
};
int main ()
{
double a=0,b=0,c=0,d=0,e=0,f=0,sumA,sumB;
cout << "enter a\n";
cin >> a;
cout << "enter b\n";
cin >> b;
cout << "enter d\n";
cin >> d;
cout << "enter e\n";
cin >> e;
cout << "the size is: " << sumA()+sumB() << endl;
return 0;
}
rectangle::rectangle()
{
}
double rectangle :: sumA()
{
return c=a+b;
}
double rectangle :: sumB()
{
return f=d+e;
}
|
|
|
|
|
may want to declare an instance of the class in main()
rectangle rectMyClass;
rectMyClass.sumA();
rectMyClass.sumB();
and another tip, that may help you keep track of what is what,
is to make your variable names a bit more descriptive.
|
|
|
|
|
Cheers, I have managed to get it sorted now, thanks for the advice. I have managed to make another basic class program too. Thanks again.
|
|
|
|
|
Hi,
I've subclassed CComboBox. I've called WM_CTLCOLR_REFLECT. Which works perfectly well with the edit box. It's when I dropdown it's crashing the app. I want to able to change the colour of the listbox part as well.
I'm confident that someone here can supply code snippet that would solve the problem.
Thanks in advance,
Alton
|
|
|
|
|
Hi,
I'd like to be able to add items to cursor right-click menus in MS Word on-the-fly. For example, while editing a document I would like to add frequently used phrases to the context menu, then right-click and select a phrase, which would then be copied to the clipboard or copied into the document.
Any help on this topic or pointers will be appreciated. I couldn't find an Office-specific board to post this message, so I am posting it here!
Thanks in advance,
Todd
|
|
|
|
|
Hi there:
Has anyone had problems with crashes in a program that works perfectly in a Canadian/US Windows O/S, but has odd crashes when installed on a European Windows systems? Are there any problem places to look for possible errors? This crash occurs in the middle, not at initialization, at the beginning of loading a file.
I have been using plain ASCII not Unicode for some strings but these are hard coded. I know this is one of those idiotic non specific questions, but just sending it out in case someone has has seen this before.
Thanks in advance.
|
|
|
|
|
That's not really enough info to go by. But since you mentioned loading a file, are you by chance assuming the file will contain only ASCII (bytes 0-127), and your code breaks when it encounters data in another code page and/or characters above 127?
If you have the crash address, look that up in the .map file to find what function the address is in. If you don't currently make .map files, change your linker settings to do so and keep the .map file for any build you release publicly so you'll have them available in the future.
--Mike--
LINKS~! Ericahist updated! | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|