|
This isn't what I'm looking for. I want to print an integer number like:
100000
as
100,000
or
10000000
as
10,000,000
using a printf() like function that also works with the other printf formatting fields.
|
|
|
|
|
Oh, misunderstood your question, sorry.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Use the GetNumberFormat API, which returns a new string with commas/decmial points inserted. You can then use that string in your printf call.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
That is the function that I have been using, but it lakes the convenience of a good-ol simple printf. I have to allocate a return buffer, plus fill out a format structure. Nothing beats the single line of code that printf offers.
My task today is going to write a replacement for printf (sprintf actually) that does this formatting.
Thanks.
|
|
|
|
|
you can use the following function; it's not mine and I havent tried it to be honest but it looks persuasive "
// Function inputs a num with commas every 3 places
// e.g. for 1000, add_commas prints 1,000
//
// Program uses recursion (non tail end)z
#include <iostream.h>
void add_commas(int num,int count)
{
if(num < 10)
{
cout << num << endl; // num by now only 1 digit
return;
}
else
{
count++; // count=count+1
if(count%3==0)
{
add_commas(num/10,count); // recursive call
cout << ',' << num%10; // cout comma then remainder of
// num / 10
}
else
{
add_commas(num/10,count); // recursive call
cout << num%10; // no comma just remainder of num/10
}
}
}
void main(void)
{
add_commas(123456789,0); // call add_commas (second param must be 0!)
}
try it you will lose nothing
|
|
|
|
|
I am an extreme newbie to C++!
I am using CreateWindow() to create a window, and it is successful, but I can not find a way to set the window's font size, style, etc...
Is there a simple way to do this or am I missing something completely?
All help is extremely appreciated!!!
Sample:
m_hWnd = ::CreateWindow(TEXT("EDIT"),
TEXT("My Text"),
WS_CHILD | ES_LEFT | WS_VISIBLE | SS_LEFT,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
m_hWndParent,
NULL,
NULL,
NULL);
Thanks,
Troy
troygtroy@hotmail.com
|
|
|
|
|
To change a window's font, you will have to get the device context using GetDC(), then create a font (look up CreateFont), then call SelectObject() to select the font.
Be sure to call DeleteObject() when you are finished with the font, and ReleaseDC() when you no longer need the device context.
Documentation for these functions can be found on MSDN.
Like it or not, I'm right.
|
|
|
|
|
Geez, out with vb's Me.Font = "" and into a whole new world. Thanks for the help and for the quick response. I will follow your lead in MSDN.
Thanks again,
Troy
|
|
|
|
|
Hi, everyone
I am trying to develop some code to connect my local MS Access database. Now I have a very long char string, the length of this string could vary very differently. In my Access database, the field type is Memo. Now I am using ODBC function SQLBindParamenter to try to bind this string dynamically. My question is how should I set the columnsize parameter of the SQLBindParamenter method? I can always set a very huge number, like 50000, but the length of that string still could be larger. what should I do?
Anyone has any suggestions?
Thanks a lot in advance.
|
|
|
|
|
Hi !
Anyone knows about a tutorial where I could learn how to use CSpinButtonCtrl ?
Well, admit I have a MFC App with a CEdit and a CSpin.. next to it. How do I assign the CEdit as the buddy window for the CSpin ? My question could be : how do you retrieve the Cwnd * from a given control ?
Thanks
RaGe
|
|
|
|
|
Well, I got it alone =)
CWnd *tmp=GetDlgItem(IDC_EDIT);
m_Spin.SetBuddy(tmp);
in case other are interested ...
RaGe
Unfortunately, brute-force solutions tend to be slow
even when performed by modern-day microcomputers,
which are capable of several MIPS except when I'm late
for an appointment and want to finish a compile and
run just one more test before I leave, in which case
the crystal in my computer is apparently designed to
automatically revert to 1 Hz.
-- Michael Abrash
|
|
|
|
|
Just place Spin near edit in the dialog editor, invoke "Layout->Tab Order" menu command, and set spin tab number after edit tab number. Then select "AutoBuddy" property of spin and it will be automatically attached to edit control. In OnInitDilog function set the spin behavior, for example:
<br />
CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*) GetDlgItem(IDC_FREQ_SPIN);<br />
pSpin->SetRange(0, 20000);<br />
|
|
|
|
|
Sorry to nitpick, but the proximity of the two controls is meaningless. Only the tab order is important. Having them near each other makes the dialog easier to understand and maintain, but has no effect on functionality.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Michael Dunn wrote:
proximity of the two controls is meaningless
I know, I don't said, that it's needed. I recommended to use it for design purposes only.
|
|
|
|
|
hi !
I need to display a dialog box built in resource editor at a certain precise coordinate on
screen.
Is there anyway I can achive this without modifying the resource .RC file.
Actually I need to so this on the fly.
DeepBlue
|
|
|
|
|
SetWindowPos or MoveWindow, your choice.
-c
Cheap oil. It's worth it!
|
|
|
|
|
I tried using this one.. but couldn't get around the first parameter.
BOOL SetWindowPos( const CWnd* pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
How do I use it ??
Thanks again
DeepBlue
|
|
|
|
|
it's usually of a set of predefined window ptrs. i just use wndTop (think that's what it is)
-c
Cheap oil. It's worth it!
|
|
|
|
|
Guys, I prefer to use SetWindowPlacement under win32 or CWnd::SetWindowPlacement Under MFC...
Regards
Carlos Antollini.
www.wanakostudios.com
Sonork ID 100.10529 cantollini
|
|
|
|
|
Carlos Antollini wrote:
I prefer to use SetWindowPlacement under win32
Well, if you want to do it quickly, MoveWindow() works really fine ... no other structure required ... a DOITINONELINE function
~RaGE();
|
|
|
|
|
In VB is
Form.Top = nTop
Form.Left = nLeft
hhmmm Two lines....
I prefer to return to Visual C++...., I like to write thousond of lines for make the same....
Carlos Antollini.
www.wanakostudios.com
Sonork ID 100.10529 cantollini
|
|
|
|
|
Try a MoveWindow() (you can even resize your dialog with this one) like this :
MoveWindow(x,y,DialogSizex,DialogSizey,TRUE);
where x and y are your coordinates, DialogSizex the width and DialogSizey the height of your window.
RaGe
|
|
|
|
|
hi friend
i always prefer SetWindowHandle()API..BCzthat i sthe simple and traditional way to locate the window
the way must use
SetWindowPos(
HWND hWnd, // handle to window
HWND hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
UINT uFlags // window-positioning options
)
i think ur doubt is about the second parameter hWndInsertAfter here just put HWND_TOPMOST which Places the window above all non-topmost windows
The TRUE CP -ian
|
|
|
|
|
In your WM_INITDIALOG handler, call SetWindowPos() and pass the x,y values you want the dialog to appear in. (Note that in MFC, you cannot use (0,0) since that is the default location and MFC will call CenterWindow() for you. Using any other position overrides this behavior.)
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
just try the CRect class members .. it works ..
|
|
|
|