|
Hi guys what i want to do is to show some data in a ClistCtrl column like the following:
________________________________________
stuff |$ 434.55 |
----------------------------------------
stuff2|$ 22,333.55 |
----------------------------------------
stuff2|$ 86.55 |
----------------------------------------
have the dollar sign at the left side, and the number be always at the right side, can someone point me how to do this?? maybe calculing the size of the text and compare it to the cell rect and to some math there? but how how do you get the size of the text?, i remember seeing a function for that but i don't remember the name of it, or if you have an another suggestion please
|
|
|
|
|
manchukuo wrote: but how how do you get the size of the text?
GetTextExtentPoint32[^].
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]
|
|
|
|
|
Thanks CPallini that is the one i was looking for, so there is no easy way to achieve what i need? or i will have to do all the mungle jumble that i already wrote?
|
|
|
|
|
I would go with the mungle jumble (i.e. sorry, I don't know an alternative).
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]
|
|
|
|
|
Have you tried GetNumberFormat() to properly insert the commas and decimal? Then just prefix a '$' and a number of spaces to the resulting string.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Have you tried GetCurrencyFormat[^]?
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Hello All!
I want to read a number from CMD [For example: 1234]. Then put each of its components in an array [ For example: a[0]=1, a[1]=2, a[2]=3, a[3]=4 ].
Could anyone help me with my duty?!
The case is urgent!
Thanks for your further cooperation.
|
|
|
|
|
in most programming languages a string is an array of characters;
and in ASCII (and Unicode) the digits 0-9 have consecutive values
(actually 0x30-0x39, but you don't need to know that since you could do (int)(mychar-'0') ).
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Try this code.
It reads a number from CMD [For example: 1234].
Then puts each of its components in an array - digitArray[3]=1, digitArray[2]=2, digitArray[1]=3, digitArray[0]=4
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
int digit=0,digitInput=0;
int digitArray[4]={0},digitn;
void getIntKey(void)
{
digitArray[0]=0;
digitArray[1]=0;
digit=0;
digitInput=0;
while((digit<4))
{
if (kbhit())
{
digitInput=getch();
if ((digitInput>47) && (digitInput<59))
{
digitArray[digit]=(unsigned char)digitInput-48;
digit++;
}
if (digitInput==13) { digitn=digitArray[0]; break; }
}
}
if (digitInput!=13) digitn=digitArray[3]*1+digitArray[2]*10+digitArray[1]*100+digitArray[0]*1000 ;
printf("\n%i\n\n",digitn);
}
int main()
{
system("color 1F");
printf("This program by TopCoder requires you to input 4 digits \n ");
printf("Input Digits (ex. 1=0001 , 1234=1234) \n ");
printf("\nInput Digits >");
getIntKey();
printf("\ndigitArray[3]=%d \n",digitArray[3]);
printf("digitArray[2]=%d \n",digitArray[2]);
printf("digitArray[1]=%d \n",digitArray[1]);
printf("digitArray[0]=%d \n",digitArray[0]);
printf("\n%i\n\n",digitn);
return 0;
}
..
|
|
|
|
|
That was co0l, realy!!
But, is it possible to wait until Enter pressed to diagnose the number of digits? And then the program dynamicaly tunes itself in order to put these digits into the char array which its dimension is defined by the number of digits, the user entered?
|
|
|
|
|
Yes, digit++ can sets the dimension.
Lets say you want to limit the user input to a 9 figure number or 100,000,000,
just set while((digit<4)) to be 9 or whatever and then write the code to process it.
eg.. digitn=digitArray[3]*1+digitArray[2]*10+digitArray[1]*100+digitArray[0]*1000 to digitArray[n]*100000000
This method is clunky .
|
|
|
|
|
Now it is just clunky
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
int digit=0,digitInput=0;
int digitArray[10]={0},digitn;
void getIntKey(void)
{
digitArray[0]=0;
digitArray[1]=0;
digit=0;
digitInput=0;
while((digit<9))
{
if (kbhit())
{
digitInput=getch();
if ((digitInput>47) && (digitInput<59))
{
digitArray[digit]=(unsigned char)digitInput-48;
digit++;
printf("%d",digitInput-48);
}
if (digitInput==13) { digitn=digitArray[0]; break; }
}
}
switch(digit)
{
case 0:
case 1:
digitn=digitArray[0]*1 ;
break;
case 2:
digitn= digitArray[1]*1 +digitArray[0]*10 ;
break;
case 3:
digitn= digitArray[2]*1+digitArray[1]*10 +digitArray[0]*100 ;
break;
case 4:
digitn=digitArray[3]*1+digitArray[2]*10+digitArray[1]*100+digitArray[0]*1000 ;
break;
case 5:
digitn=digitArray[4]*1+digitArray[3]*10+digitArray[2]*100+digitArray[1]*1000+digitArray[0]*10000 ;
break;
case 6:
digitn=digitArray[5]*1+digitArray[4]*10+digitArray[3]*100+digitArray[2]*1000+digitArray[1]*10000
+digitArray[0]*100000;
break;
case 7:
digitn=digitArray[6]*1+digitArray[5]*10+digitArray[4]*100+digitArray[3]*1000+digitArray[2]*10000
+digitArray[1]*100000 +digitArray[0]*1000000;
break;
case 8:
digitn=digitArray[7]*1+digitArray[6]*10+digitArray[5]*100+digitArray[4]*1000+digitArray[3]*10000
+digitArray[2]*100000 +digitArray[1]*1000000+digitArray[0]*10000000;
break;
case 9:
digitn=digitArray[8]*1+digitArray[7]*10+digitArray[6]*100+digitArray[5]*1000+digitArray[4]*10000
+digitArray[3]*100000 +digitArray[2]*1000000+digitArray[1]*10000000 +digitArray[0]*100000000;
break;
}
printf("\n%i\n\n",digitn);
}
int main()
{
system("color 1F");
printf("DigitsIntoArrayComponents 3.1 by TopCoder \n ");
printf("Max Input is 8 Digits ( . 99,999,999) \n ");
printf("\nInput Digits >");
getIntKey();
printf("\ndigitArray[7]=%d \n",digitArray[7]);
printf("digitArray[6]=%d \n",digitArray[6]);
printf("digitArray[5]=%d \n",digitArray[5]);
printf("digitArray[4]=%d \n",digitArray[4]);
printf("digitArray[3]=%d \n",digitArray[3]);
printf("digitArray[2]=%d \n",digitArray[2]);
printf("digitArray[1]=%d \n",digitArray[1]);
printf("digitArray[0]=%d \n",digitArray[0]);
printf("\n%i\n\n",digitn);
return 0;
}
...
|
|
|
|
|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
The most cplusplusy way of doing this is to just copy the input from std::cin into your array of characters:
std::vector<char> text;
std::copy( std::istream_iterator<char>( std::cin ), std::istream_iterator<char>(), std::back_inserter( text ) );
You'd have to press CTRL-Z to terminate the input though.
If I've misread what you want and you really want an array of integers, one per digit in the number you have to do a bit of conversion instead of a copy:
std::vector<int> digits;
std::transform( std::istream_iterator<char>( std::cin ), std::istream_iterator<char>(), std::back_inserter( digits ), []( const char c ) { return int( c - '0' ); } );
If your compiler doesn't support Lambda functions (For VC++ it's VC++ 2010 or for gcc it's version 4.3 or later) then it's a bit fiddlier but you need a function object instead of the Lambda function. (The Lamba's the final parameter to the std::transform call, []( const char c ) { return int( c - '0' ); ).
Cheers,
Ash
|
|
|
|
|
bijan.8k wrote: I want to read a number from CMD...
Do you mean the command line?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hallo,
I try to open the html return from an Internet URL, for example http://leavemusic.de/live/leavemusic/index.php, and I want to get the html code in a CString. What is the best way to do it? It does not work with CFile for me.
Thank you!
|
|
|
|
|
Have you tried URLDownloadToFile()?
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
If you don't want to use the function David suggested and if you've got time to experiment I can wholeheartedly recommend using cURL[^] for what you're trying to do. It's very customisable, flexible and portable. It's also got a bit of a clunky C handle based interface only it's programmer could love but for the sort of thing you're after it's not too bad. It took me about 4 hours of reading and playing to get a small file downloader working with it.
If you know how to use sockets then you could just open a socket on the remote computer, send and HTTP get and read everything between the opening <HEAD> tag and the closing </BODY> tag. I'd only recommend this method if you're already comfy with network programming otherwise the small details might get a bit much.
Cheers,
Ash
|
|
|
|
|
I encountered a hard question:
#include <windows.h>
#include <time.h>
int main(int argc, char* argv[])
{
LPCTSTR fileName = "\\\\192.169.3.9\\tempdir\\MYFILE.TXT";
HANDLE hFile;
DWORD dwError;
time_t nowTick = time(NULL);
hFile = CreateFile(fileName, // open MYFILE.TXT
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
CREATE_ALWAYS, // overwrite existing
FILE_ATTRIBUTE_NORMAL | // normal file
FILE_FLAG_OVERLAPPED, // asynchronous I/O
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
dwError = GetLastError();
printf("error:%x, diff:%d\n",dwError, time(NULL) - nowTick);
return 0;
}
CloseHandle(hFile);
return 0;
}
Question:
1.Why does the function CreateFile block a long time when the path specified by the variable fileName is not exist?
2.If i does not expect the function CreateFile block a long time, does it have a better solution?
3.what's the best solution of accessing the file on the net?
I am a c++ programer!
It's cheerful to cooperate with you!
|
|
|
|
|
the API is accessing the file via networking, so you got a long timeout.
C++ programmer are writing for lenghtly operations threads.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
...and go for a coffee or play some game during.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
thats what i do. or listening to some music.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
When you create a file over the network there's loads of things that can go wrong - the OS has got to wait a while to see if the remote system responds before failing.
There's probably not a lot you can do to speed things up, but there's a couple of tricks that can work.
First one is to do the opening assynchronously. Spin off a thread and use a future to signal when the file's open. If you can reorder your logic a bit so you start opening the file, process what you can in memory then write to the file when it's open you might be able to make it look like the file open opened quicker.
The second one only works if you know you're going to want to open the file well in advance of needing to use it. Just open the file as one of the first things your program does. When you need the file just open it again. This uses the fact that most OS filesystems are better at reopening already open files as it just needs to duplicate the file handle. Of course if you don't know what the file is well in advance this is absolutely no use to you whatsoever.
Cheers,
Ash
|
|
|
|
|
Any has any experience with these two?
I searched throughout the Internet for some getting started/tutorial/documentation for libmms but found absolutely nothing.
ffmpeg is a bit better documented, but I want to go one step at a time... I need to get the stream first...
We are using Linux daily to UP our productivity - so UP yours!
|
|
|
|
|
Hi,
I have to create a dll file to bind all the source code in a sinle library to ease of use.
For which dll I should go for
1. Regular DLL using shared MFC DLL
2. Regular DLL with MFC statically linked
3. MFC extension DLL
|
|
|
|