|
Hint: atof returns 0.0 whenever the conversion fails.
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]
|
|
|
|
|
But what if the value entered is 0.0. That may well be a valid entry. I could compare the source string with "0.0" to account for that one case, but that just seems ugly.
Thanks for your time
|
|
|
|
|
No it's NOT ugly and it is the way my suggestion pointed to. You have to deal only with 1 case and that's much more simpler than the general validation. Anyway you have to accomplish carefully your task. For instance 0 is a valid entry too (and, depending on your level of user-noise tolerance, also 0.00 , 0.000 ,... are).
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]
|
|
|
|
|
Hello Pallini,
I really do appreciate the time you spent answering my question. But we do disagree on something. Elegant is something like this.
CString source = "1.23e6";
double target;
int status;
status = source.ConvertToFloat( &target );
If atof returns 0.0 in the double variable for an error, this it must also write 0.0 to the variable when the text is 0, or 0.0, or any of several other conditions as you have noted. In this event, either before the convert or after, we must have additonal code to check for any text string that would result in 0.0 to determine if we have an error, or if we really have a 0. Having to writing extra code to do that is indeed downright ugly.
Maybe I have missunderstood you. If so please help me out.
Thanks for your time
|
|
|
|
|
No, you haven't misunderstood me.
I mean atof , returning 0 on error, gives you the support to implement the elegant solution you proposed: it's a starting point.
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]
|
|
|
|
|
Unfair vote[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Already balanced, sir.
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]
|
|
|
|
|
Thank you [Military tone] Sirrrr! [/Military tone]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
You can also use the functions isalfa () or isdigit ().
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hello Nelek,
I had forgotton about those. But then I would need to write some code that checks the string one char at a time.
I think that the best way is to use the CFilterEdit. But that requires getting and installing the Boost package mentioned elsewhere. It does seem to be far better than any than any thing else I have see.
But think about this for a minute. All user interface with dialogs involve the user typing in a string and the programmer converting at needed. The interface between the dialog and the remainder of the program is a string, period. The very idea that any programmer needs to go to this amount of effort just to get a string ( CString ) converted to an integer, float, double or what have you, is just down right absurd.
Am I the only one that recognizes this. If so, maybe I am the crazy one. Let me know.
Meanwhile, following Nelek's note in his/her signature:
I am grateful for each and every one of you that responded. Maybe this will be documented here or somewhere so others can find it.
Indeed, which I get this straight, I will write it up and add it to my site here:
www.bkelly.ws/software
I am very much open to suggestions and if you have a page written, put your name in there showing credit to you and I will be happy to post it and give you credit.
But first, I want to get my program working.
Thank you.
Thanks for your time
|
|
|
|
|
bkelly13 wrote: in his/her signature
His :P
Actually the MFC let you set a member variable for a CEdit as number typ and it gives the error message when you are giving letters by itself. Just put the member variable as double insteads of CEdit*
Problem... when using APIs this can't be used.
But there is another way to do it, with the DDX or DDV (don't remember it well). I read in a manual that the checking can be automated using one of them and you can use the same validation for more than one control. But not sure about it because I was lazy and I used the other option (member variable as the type of number I needed)
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Have you considered a masked-edit control? Several exist here on CP's site.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
i have a GUI in which i will have to indicate my status and progresses and so i have embedded the progress bar in my statusbar using the following code inside a button click(show progress),but when i use this code twice,i mean if i click the showprogress button twice i get error in wincore at line 703...and the error and code are ..
void AFXAPI AfxHookWindowCreate(CWnd* pWnd)
{
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
if (pThreadState->m_pWndInit == pWnd)
return;
#ifndef _WIN32_WCE
if (pThreadState->m_hHookOldCbtFilter == NULL)
{
pThreadState->m_hHookOldCbtFilter = ::SetWindowsHookEx(WH_CBT,
_AfxCbtFilterHook, NULL, ::GetCurrentThreadId());
if (pThreadState->m_hHookOldCbtFilter == NULL)
AfxThrowMemoryException();
}
ASSERT(pThreadState->m_hHookOldCbtFilter != NULL);
#endif // !_WIN32_WCE
ASSERT(pWnd != NULL);
ASSERT(pWnd->m_hWnd == NULL);
ASSERT(pThreadState->m_pWndInit == NULL);
pThreadState->m_pWndInit = pWnd;
}
void Ctest::OnBnClickedButton4()
{
m_bar.Create(this);
m_bar.SetIndicators(indicators,2);
CRect rect;
GetClientRect(&rect);
m_bar.SetPaneInfo(0,progressbarn, SBPS_NORMAL,rect.Width()-100);
m_bar.SetPaneInfo(1,progressbarm,SBPS_STRETCH ,0);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
progressbarn);
pPrgCtrl->Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 288, 35), this,0x16);
pPrgCtrl->SetParent(&m_bar);
CRect crPaneRect;
m_bar.GetStatusBarCtrl().GetRect( 1, &crPaneRect );
crPaneRect.DeflateRect( 0, 2, 2, 2 );
pPrgCtrl->MoveWindow( crPaneRect );
s="showing progress ";
m_bar.SetPaneText(0,s);
}
what should be done??
modified on Saturday, June 21, 2008 5:40 AM
|
|
|
|
|
sanjayvenkat wrote: ,i mean if i click the showprogress button twice i get error in wincore at line 703...and the error and code are ..
That's because you are trying to create m_bar twice.
sanjayvenkat wrote: m_bar.Create(this); //We create the status bar
Try this...
if( !m_Bar.GetSafeHwnd() )
m_bar.Create(this);
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Hi All,
Is it possible to change width of a combo box at run time ?
ex:
I have data like
One
two
Thirteen
ThousandFourty
in the combo box.
whenever user select a string from above, combo box should be resized with the length of selected string.
Thanks..
Sheshidar P
|
|
|
|
|
Can you use of MoveWindow ?
|
|
|
|
|
|
I have a CTreeCtrl object in my dialog, this control is initialized as follows:
m_imgList.Create(16, 16, ILC_COLOR32, 1, 4);
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
m_imgList.Add(&bitmap, RGB(0, 0, 0));
bitmap.DeleteObject();
bitmap.LoadBitmap(IDB_BITMAP2);
m_nFolderImgNdx = m_imgList.Add(&bitmap, RGB(0, 0, 0));
bitmap.DeleteObject();
m_wndTree.SetImageList(&m_imgList, TVSIL_STATE);
hNewItem = m_wndTree.InsertItem(
TVIF_IMAGE | TVIF_PARAM | TVIF_STATE | TVIF_TEXT,
_T(""), 1, -1, nState,
TVIS_EXPANDED | TVIS_STATEIMAGEMASK,
(LPARAM)pData, hItem, TVI_LAST);
Later in the code I update each item of the tree control - text and image.
m_wndTree.SetItemImage(hItem, 0, -1);
However the tree control item does not update its image icon. It always display's its 1st image even I set the 0th image during the update. Any idea what is the problem ?
Thanks,
Abyss
|
|
|
|
|
Hello ALL,
I have an NTFS Compressed Disk named "J:\" & there is only one file in that disk, say "Sample.txt"
I can see the sample.txt's RAW data using WinHex in compressed form.
The Compressed's data size is 512 Bytes ( I see that in the properties of that file )
OPERATIONS STEPS:
=================
Now I open that compressed drive using LZOpenFile() function, like
// Open the compressed drive
OFSTRUCT lInputStruct;
int lSrcHandle = LZOpenFile("\\.\\J:", &lInputStruct, OF_READ); //compressed drive
// I know that the compress data of Sample.txt file starts from 3858432 location
// So I seek to that position by
long seek = LZSeek(lSrcHandle,3858432,0);
// Then I read the contents
// LZRead automatically decompress the data
unsigned char chBuffer[1024] // this buffer should be bigger
INT ret = LZRead( lSrcHandle, (LPSTR)chBuffer, 512 );
// I open another file to write the decompressed data
HANDLE lNorFile = CreateFile("I:\\sample_dec.txt", GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, NULL, NULL ); // normal file
// chBuffer holds the decompressed data
WriteFile(lNorFile , chBuffer, ret, &lBytesWrite, NULL );
// Close all the open handle
LZClose(lSrcHandle);
CloseHandle( lNorFile );
RESULT:
======
The data into I:\sample_dec.txt is similar as compressed data.
So it means the data is not decompressed.
QUESTION:
========
1. How I exactly get the Raw data of a Compressed NTFS file ?
1. How I decompress the RAW Compressed NTFS data ?
Please help me if someone can...
Thanks in Advanced
-Same
|
|
|
|
|
Can I change the default position of OK button when calling AfxMessageBox() function, by default it is on center.
Thanks,
Mushq
|
|
|
|
|
I think the only way is to create your own Dialog and place your button anywhere you want.
AfxMessageBox does not allow you to change the coordinates of buttons.
|
|
|
|
|
|
Hi,
I want to remove or disable Minimize and Maximize box from SDI Frame...
Please anybody help me....
usha
|
|
|
|
|
Hi,
The CWnd::OnCreate() method is used to create a window and it is usually meant to do this using its default configured features. Therefore, anything you want to display on the frame when the application displays, you can do so when creating the application. Therefore, the frame is typically used to create and display the toolbar(s), dialog bar(s), and status bar.
After the frame has been created, if you want to modified something on it, you can do so after it has been created but before it is displayed to the user. To do this, you can use the PreCreateWindow() method of the CWnd class.
Its syntax is:
virtual void PreCreateWindow(CREATESTRUCT& cs);
This method takes a reference to CREATESTRUCT class, modifies and returns it with the new characteristics. For example, you can use this method to remove the Minimize and the Maximize system buttons on the title bar as follows:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
return CFrameWnd::PreCreateWindow(cs);
}
Hope this help you..!
Good Luck..
|
|
|
|
|
Hi Jagdish,
The codes did not working..any other solutions???
regards,
usha
|
|
|
|
|