I have seen at least one commercial product (VisualTest) that has a horizontal splitter window with a title. That is, the top gripper bar is wider than normal, and has text in it that describes the contents of the window below. A screen shot is available at:
I can sort of simulate that if the window contains a ListView by setting the ListCtrl to REPORT style and adding one column heading with the text, but that leaves you with that annoying column sizing thing in the header, which I find unaesthetic. Further, you're out of luck entirely if the window contains a TreeCtrl--and the window I'm making does.
I have tried every solutuion I can think of, including attaching a custom CHeaderCtrl, but nothing seems to work.
Thanks, I had tried that too but have the exact same problem!
I should prob add that it works ok with text in define in the code but not with text I read from an edit box...
Really don't understand what I'm doing wrong???
Actually I've only just realised that only the first digit is being converted. I.e. if I enter 2.3 I get 2.00 but if I enter 14.6 I get 1.00.
I must do something really wrong somewhere but I can't see where!
Thanks for your help!
Something's definitely amiss here. If you don't make the call to GetDlgItemText but, instead, just set txtEdit to "2.334" (for example), boxval ends up being 2.334 (or whatever you ste in txtEdit). This works just fine...tested it m'self, I did.
So something's not right, and it's definitely something to do with the conditions under which GetDlgItemText is called. Maybe you're only responding to single keystrokes in the edit box, I'm not sure.
Some things to try testing:
* GetDlgItemText returns the number of characters copied. Store this returned value to an int and make sure it's returning the right number of characters.
* sscanf returns the number of arguments extracted from the string. So if your sscanf() isn't returning '1', then something's wrong.
Try putting a breakpoint at the start of the function, then single step through it (with F10). Use your Watch window to watch the values of tmp, txtEdit, boxval, and d as each line is executed. Validate the values at each step, and make sure you see the following:
CString tmp, txtEdit="82.45"; // tmp = "", txtEdit = "82.45"
float boxval; // boxval is undefined at this point
char *txt = (char *)(LPCTSTR)txtEdit; // txt = "82.45"
sscanf(txt, "%f", &boxval); // boxval = 82.45
double d = atof(txt); // d = 82.45
tmp.Format(_T("atof is %f", d); // what is tmp here?
// AfxMessageBox(tmp); // don't need this for testing
tmp.Format(_T("sscanf is %f", boxval); // what is tmp here?
// AfxMessageBox(tmp); // single step is your friend!
Definitely a stumper, but it's definitely worth single stepping.
As a side note on programming practice, you should do the following: const char * txt = (LPCTSTR)txtEdit; instead of your original char * txt = (char *)(LPCTSTR)txtEdit;. You may run into unintended consequences if you force a const to a non-const. It's not hurting you here, but it could bite you in bad places. I'm curious to know if you get a compiler warning from your original statement.
So using the debugger I've now realised that the line char *txt = (char *)(LPCTSTR)txtEdit; is the one causing the problem. In the debbuger the value for txt is 8.00. Funny the message box was returning the right charactere when reading from the edit box..
I have tried using char * txt = (char *)(LPCTSTR)txtEdit; instead but it gives me the error cannot convert from 'const unsigned short *' to 'const char *'.
I didn't say that was the line causing the problem I was just touching on coding practice. So have you single-stepped through the code and checked the values of the variables after each line is executed?
Last Visit: 31-Dec-99 18:00 Last Update: 15-Apr-21 3:04