|
Are you keeping the CFont object during for the entire lifetime of the comboboxes? It does not suffice to create a CFont , use it with SetFont and forget about it. The object should be kept (usually as a member of the parent dialog) as long as the comboboxes are around.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm working with figures that will range from 0.00 to 999999999.00 that are entered in a dialog, these will always be monitary values. Whats the easiest way to deal with inputting this type of data to avoid constant conversions? Switching from CString to real to do calculations and then switching back seems like a waste sort of, and im not sure the best way to convert from cstring to real without writing a bunch of code..
I've seen money entering boxes in msmoney which were pretty cool..
any suggestions?
thanks!
-dz
|
|
|
|
|
In general, it is a good idea to store currency values entered by a user as pennies (i.e. assuming a decimal currency system is used) which are nothing but unsigned integers.
When filling an edit or text control, separate the last 2 digits with a period. You can do this using the / and % operators, but it's more efficient to just reformat the displayed string with an embedded decimal point.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
are you saying that when the user enters the values there should be a foced period in it, such that they would type 6 numbers with no periods, but the text control displays '1234.56'? and if so, how do i edit what a textbox displays realtime?
When i get the value as CString will i just take out the 3rd position('.') everytime? And once I have the value in as pennies in a cstring how do i convert that to a real (1234.56) value?
thanks in advance!
-dz
|
|
|
|
|
Not quite.
What I meant was save the user's data as an integer. If they type 123.45, treat it as 12345 pennies instead of 123.45 dollars (or whatever decimal currency you're using). When displaying a penny amount, insert the decimal point at the appropriate point just before you set the edit/text control's string.
You must guard against floating point round-off errors when dealing with currency. Remember, there's no way to accurately store a floating point number like 123.45. The loss of accuracy will show itself when you use the amount in other calculations.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
atof will convert from a string to a double. But like someone else pointed out, when working with money, you want to make sure that the cents decimal places aren't lost. IEEE floating point (doubles, floats) have a bad problem with being inexact.
You might look into VarCyFromStr if you don't mind working with Microsoft's VARIANT types.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I just started with visual C++. I'm writing a graphics program using openGL in an MDI application. But to make my life easier, I just took the example on this site which draws openGL graphics with MDI. I just deleted all the functions, globals, etc. that I didn't want. But now I'm starting to read up on some debugging stuff (breakpoints and single stepping). When I insert a breakpoint and then say "go" to debug I get a message box that my .exe doesn't contain debugging information. When I press OK, I get this message box:
One or more breakpoints cannot be set and have been disabled. Execution will stop at the beginning of the program.
And then some dissambly file comes up. I have a feeling all this has something to do with the fact that I used someone else's demo instead of starting from scratch with the necessary settings. Is there some way I can fix it so it will let me debug?
|
|
|
|
|
You active configuration is currently release mode.
Set this to debug mode, please.
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Are you trying to debug the release build ?
Try debugging the "Debug" build.
Jonathan de Halleux, Belgium.
|
|
|
|
|
Hi,
I am trying to learn programming snap-ins for MMC.
But the SDK documentation is cubersome and confusing,
and ATL also does not have any good tutorials.
Can any one point me to some tutorials to developing
MMC snapins using ATL.
Thx & Regards,
Prem
|
|
|
|
|
http://www.codeproject.com/atl/mmcsnap.asp?print=true
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
Hi Michel,
I have gone thru Leon Finker's article, but he wants
me to use his own class and does not actually
tell how to do it. Just lists the steps in a broad
sense and covers the whole subject in a few paras.
May be you could suggest something at a slower pace ?
Thx & Regards,
Prem
|
|
|
|
|
It is very difficult to find documentation/tutorials on MMC. I have written one myself, and MSDN is very incomplete. Their example suck.
I suggest that you pick up an MMC snapin sample that is the closest to what you want to build and start from there.
Another is to use ATL to build it. Start an ATL Dll project, and choose "Insert ATL object", and choose MMC snapin from the choice of different object types.
You will have a snapin with eveything correct (registration and all). Then in MSDN library search for an article entitled "Writing MMC Snapins is a Snap with ATL 3.0". This is a good article, but you must be familiar with MMC to fully understand it.
Sorry, but you are much on your own on this. I've been through there.
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
Hi,
I have a problem here:
When a thread(a client) sends a socket to another thread (the server), the server receives it and returns a message back to that client. The question is: When that client uses a for loop and tries to send something to the server many times, the socket can be received ONLY for the very first time by the server and the rest are blocked?? In my case, when I send a buffer to the server, only the first time can be sent, the rest cannot be sent.
CSocket Client; //Client side
Client.Create();
Client.Connect (...)
for (...)
Client.Send(buffer, strlen(buff));
CSocket socket; //Server side
if ( svrSocket.Accept(socket))
AfxMessageBox("Socket is created Succesfully");
socket.Receive(buff,sizeof(buff));
....
Can anyone explain why it happens?? Or did I do anything wrong?
Thank you!
|
|
|
|
|
Anonymous wrote:
socket.Receive(buff,sizeof(buff));
You are calling that just once.
You gotta keep calling that till all the data has arrived.
Nish
p.s. that's a very short answer and there is a lot more that you need to understand about this, but it's a start anyway...
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Thank you for you reply.
So, I've put a infinite loop to that:
for( ; ; )
CSocket socket;
if ( svrSocket.Accept(socket))
AfxMessageBox("Socket is created Succesfully");
socket.Receive(buff,sizeof(buff));
....
However, the same problem happens. Does it mean that the loop do not work?? How can I solve this problem??
Thank you
|
|
|
|
|
Noooooooo!
Dont put the whole thing in an endless loop.
Loop this one single line :-
socket.Receive(buff,sizeof(buff));
Loop it till it returns 0 which means the client has closed connection.
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Thank you so much!!
It works now! didn't know the solution is this simple!
|
|
|
|
|
Hi,
I just want to know how concurrent threads communicate to each other.
For example, there are 100 threads: thread1, thread2, thread3....thread100. AND thread1 acts as the server and all others are clients. (actually this point is not very important) All these threads are created by AfxBeginThread(...) and format liked:
UINT ThreadProc( LPVOID lpParam )
Now, thread2 sends an request to thread1 (server) for some services. (request will be sent to a global array that thread1 checks it very frequently) At this time, thread2 will suspend itself, and let thread1 to resume thread2 (ResumeThread())when thread1 thinks that it is OK to let thread2 continue. However, it is possible that thread1 will not resume thread2 very shortly due to some reasons, and it causes thread2 to wait for a long time. So, i want to add a time-out feature for thread2 here.
It is not very hard to keep track the waiting time in thread1 by using QueryPerformanceCounter(). However, how can thread1 send the time-out message telling thread2 to abort.
The main problem is TIME-OUT checking.........
*********************************************************************************
Someone told me the solution before, but i found error message when i using it:
"error C2664: 'PostThreadMessageA' : cannot convert parameter 1 from 'void *' to 'unsigned int'"
"error C2664: 'PostThreadMessageA' : cannot convert parameter 3 from 'void *' to 'unsigned int'"
Thanks Machel helping me, here is the code:
while (GetMessage(&msg, 0, 0, 0))
{
switch (msg.message)
{
case WM_USER:
HANDLE hEvent = (HANDLE)msg.wParam;
//.... Do some work.
::SetEvent(hEvent); // this tells client thread to resume.
break;
}
}
The code above is part of the thread1's message pump. Now the client thead:
HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
::PostThreadMessage(dwThread1ID, WM_USER, (HANDLE)hEvent, 0);
DWORD dwWaitResult = ::WaitForSingleObject(hEvent, dwMyTimeOutInMillisecond);
if (WAIT_OBJECT_0)
{ // I didn't timeout.
}
else
{
// I did timeout
}
**************************************************************
I think the problem is I'm using another type of thread (mine is created by AfxBeginThread) Can anyone help me?????? With example please..........
Thanks!!!! especially those helped me before..........
|
|
|
|
|
ChiYung wrote:
::PostThreadMessage(dwThread1ID, WM_USER, (HANDLE)hEvent, 0);
The 3rd parameter should be cast to WPARAM and not to HANDLE
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
oops, sorry for the mistake
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
Michel Prévost wrote:
oops, sorry for the mistake
Huh???
I thought it was ChiYung
Or was it you who gave him the wrong cast???
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
The code snippet in the post is from me. And I wanted to cast the HANDLE to WPARAM .
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
That's ok..........
Thanks all..............
|
|
|
|
|
There is only one type of thread. Concetrate on the error message. You are passing a parameter as a HANDLE where an unsigned int is called for. Try passing an unsigned int.
|
|
|
|