|
How do I format a number to kb?
//--------------------------------------
__int64 = sizeWritten;
long sw = sizeWritten / 1024;
sprintf( szBuffer, "%d Kb", sw);
//--------------------------------------
now returns something like 1234567 Kb
but i want it to return 1.234.567 Kb
is there an easy way or function to do this?
TIA
|
|
|
|
|
I dont think there is a ready-made function for that. But you can write your own huh?
Nish
p.s. I might be wrong though. There might be some obscure function.
|
|
|
|
|
The STL locale support includes functions to format numbers with correct grouping and and separators. You are right, they are obscure and nearly undocumented in MSVC++.
|
|
|
|
|
|
Amazing Michael
You sure do know all of them API calls don't you!
A for you Michael
Nish
|
|
|
|
|
Thanks for the feedback so far,
Came up with the following, how does this look?
any input, comment welcome...
//----------------------------------------------------------------
#include "string.h"
char szOutput[20];
char* formatKB(long input)
{
char szInput[20];
int j=0, k=0;
sprintf( szInput, "%d", input);
_strrev(szInput);
for (int i = 0; i < strlen(szInput); i +=3)
{
strncpy( szOutput + k, szInput + j, 3);
if (j < strlen(szInput) - 3 )
strcat( szOutput , ".");
j+=3;
k+=4;
}
_strrev(szOutput);
return szOutput;
}
int main(int argc, char* argv[])
{
long sizeWritten = 1234567890;
printf("%s Kb\n", formatKB(sizeWritten));
return 0;
}
//----------------------------------------------------------------
Xenion
|
|
|
|
|
Okay, I wrote a perl script for a signup area in my MFC application. When the user fills in the data for the perl script on my webpage, it creates a file in the settlers.net/snetdownload/users folder called $username.$password - $username being the data the person entered into the username field and $password being the password the user entered into the field.
Okay, now in my program. I have 2 edit controls. m_username and m_password. Okay, say in my perl script I entered Ashman as the username and cheese as the password it would create a file, Ashman.cheese
I need my program to check that the I have put in Ashman in the username and cheese in the password field and then validate that the file exists with the server. If I put in Ashman as the username and choose as the password, it will not find the file ashman.choose so it will say, Could not login.
Get my drift?
Ashman
|
|
|
|
|
I don't do perl, but I know a thing or two about security and I can't see much point in a password at all if its going to be so easy to see what it is.
Assuming your user names have to be unique anyway you do not need the password to be on display at all.
I would pass the username and password to the system to do the validation, then if your program wants to know who is logged in it can ask.
We do it for the joy of seeing the users struggle.
|
|
|
|
|
- In MSDN, it is said TLS index is stored in a global variable.
- I do not know whether it is a process-wide global variable or a thread-wide variable?
- Can you help?
- Regards,
Maer
|
|
|
|
|
If I understand your question correctly, then...
The TLS *index* ("slot" location) is a process-wide global variable. The value that is stored in the TLS (slot) location referenced by the index is Thread-specific.
-=- James.
|
|
|
|
|
- Thanks pal!
- Your reply clarifies my doubts.
- Have a nice weekend,
Maer
|
|
|
|
|
I constructed a resizeable dialog and of course put a class behind it. I want to create an instance of this class and then do several DoModals on it. This means I want to open the Dialog and then close it several times. Because the window can be resized and repositioned I want to store this data and set it back when the dialog opens again. I tried it with Get/SetWindowPosition(), but if I do the SetWindowPosition() in OnInitDialog() and the window was maximized before, the window is drawn two times. The first time it is in its initial size and the second time in the correct stored size. So when the window is opened it is flickering. Has anybody an idea how to restore the old window size after the dialog is opened again without drawing it twice?
Thank you very much!
|
|
|
|
|
Good idea.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
What's a good idea?
Nish
|
|
|
|
|
Bla?
What's that mean?
Nish
|
|
|
|
|
Sorry, I hit the submit button instaed of the preview button...
I just edited the posting...
KHB.
|
|
|
|
|
Use the PreCreateWindow virtual function in your dialog class. Modify CREATESTRUCT& cs to contain your desired window size, and Bob's your Uncle.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
How do I set focus & "thick border" to a button, as If the user had Tabbed to it?
SetFocus only sets the focus (dotted rectangle). The "Default-Like" state remains at the original button.
I guess SetDefID to set the default button is the wrong way, since the default button is by default preserved when I tab away from the buttons (e.g. to an edit)
TIA
Peter
|
|
|
|
|
The default button is the button that is activated when you press [enter]
When you press tab, the button that got focus is actually made the default button. This continues till the focus goes to a control that's not a button. Then the original default button is again made default.
You can do that too from within your code
Nish
|
|
|
|
|
>> made the default button
is this BS_DEFBUSHBUTTON button style, or setDefID in the dialog, or both? Do I have to reset it, handle Button.KillFocus etc?
|
|
|
|
|
m_button.SetFocus();
DWORD original_default_id=SetDefID (IDC_BUTTON10);
That should do the trick.
By default you'll only get BN_CLICKED and BN_DOUBLECLICKED
If you wanta handle the KillFocus events you'll have to subclass it I guess....
Nish
|
|
|
|
|
Thanks Nish, works perfect!
|
|
|
|
|
Hi,
I am working on SDI Database application. I have a class CLibraryView inherited from the CRecordView. CLibraryView class has a formview dialog. I have inserted a CTabCtrl on the Form in the resource editor. OnInitialUpdate method of the CLibraryView I have updated the CTabCtrl to insert tabs.
// Insert First Tab
tci.pszText = "Issued Books";
((CTabCtrl *)GetDlgItem(IDC_TABMAIN))->InsertItem(0,&tci);
// Insert Second Tab
tci.pszText = "Library Books";
((CTabCtrl *)GetDlgItem(IDC_TABMAIN))->InsertItem(1,&tci);
// Insert Third Tab
tci.pszText = "Library Members";
((CTabCtrl *)GetDlgItem(IDC_TABMAIN))->InsertItem(2,&tci);
Now I want to insert the different layouts of CEdits & CButtons on different tabs. How can I do so? I mean each should have different layout. How to make it possible any idea in CRecordView scenario? I have an example in my book but it tells in simple CFrameWnd scenario where each stuff is created with Create member function.
Plz help......
Thanks for ur time .....
~Statbat( );
|
|
|
|
|
Hello Gurus,
I have small issue about on building DLL using MFC win32.
We have written, a DLL to call from ASP page by having the DLL instance
in ASP page to send the mail to a ID ( SMTP of the WinNT ).
When asked my system admin to register it to place in System32 folder, he
done.
But, is depended on following dlls
MFC42d.dll, MFCn42.dll, MFC042.dll, MSVCrtd.dll
How to include these required dll at compile time, so that I can give only
one DLL ?
Will solve my problem? Please give me suggestion?
Thank you inadvance.
--
SubbaReddy M
Sr programmer,
Frontlinesoft Ltd, Hyderabad, India
Ph: 91 40 3392147 (O)
SubbaReddy M
Sr programmer,
Frontlinesoft Ltd, Hyderabad, India
Ph: 91 40 3392147 (O)
|
|
|
|
|
First, if you don't want to distribute the VC and MFC dlls with your dll you have to link statically to MFC. Not sure about the VC dll though, although they're probably present on all machines (I think they are Win2K system DLLs).
Second, your dll depends on debug versions of the VC and MFC dlls. This is a no-no. You should distribute a release version of your dll, not a debug one. Actually, you're not allowed to distribute the debug versions of the MFC dlls (don't know about the VC ones) - but since you don't want to distribute any additional dlls I guess this is an academic question Anyway, distribute a release version of your dll, not a debug one.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|