|
Why doesn't CString.Format do what you want...it will give you a formatted string. If you want an array of strings then check out CStringArray.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Would it then look like this?
void CGraphView::OnBnClickedBtnplot()<br />
{<br />
<br />
CStringArray strings;<br />
strings.SetSize(26);<br />
double* Labels;<br />
<br />
GetDlgItem(IDC_PICT)->GetWindowRect(pictRect);<br />
ScreenToClient(pictRect);<br />
<br />
Labels = GetLabelVals();<br />
<br />
strings[1].Format("%.3d\n", Labels[1]);<br />
<br />
SetDlgItemText(IDC_EDITINTERSECT, "INT"); <br />
SetDlgItemText(IDC_EDITX1, strings[1]); <br />
SetDlgItemText(IDC_EDITX2, "x2"); <br />
SetDlgItemText(IDC_EDITX3, "x3"); <br />
SetDlgItemText(IDC_EDITX4, "x4");<br />
SetDlgItemText(IDC_EDITX5, "x5"); <br />
SetDlgItemText(IDC_EDITY1, "y1");<br />
SetDlgItemText(IDC_EDITY2, "y2"); <br />
SetDlgItemText(IDC_EDITY3, "y3");<br />
<br />
InvalidateRect(pictRect);<br />
}
Am I using the .Format correctly? The output on the screen is not correct. If Labels[1] is 10.26356897 then I get something like -85478 or something like that in the edit control when i run it. Could you give me an example of what it would take for my output to look like this: 10.3 I don't have a lot of space in the picture box so the output needs to be rounded to have only one number after the decimal place.
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
student() wrote:
Would it then look like this?
Yes, however keep in mind that C arrays are 0 based...when you add a string to the CStringArray it will start at the 0 index. You can either handle it with the index or add a dummy string to the 0th location.
student() wrote:
Am I using the .Format correctly?
No, change the d to an f
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Alright! That worked perfectly! I REALLY appreciate the help.
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
Disregard the first part of my last post...I didn't see that you had used SetSize. Since the array is zero based, in order to start at an index of 1 then you will need to make the array size one larger than the number of items you are storing.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
One last question..
Why will this work...
strLabels[3].Format("%.2f\n", dblLabels[3]);
But this won't?
for (int i = 1; i < 26; i++)<br />
strLabels[i].Format("%.2f\n", dblLabels[i]);
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
I don't see anything wrong with what you posted. What does it do?
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
The output on the screen shows -9255 for every string no matter what is in my dblLabels array when I use a for loop. If I put the literal index in it works but that would be too many lines of code.
Heres the whole thing again just in case:
void CGraphView::OnBnClickedBtnplot()<br />
{<br />
GetDlgItem(IDC_PICT)->GetWindowRect(pictRect);<br />
ScreenToClient(pictRect);<br />
<br />
CStringArray strLabels;<br />
strLabels.SetSize(26);<br />
<br />
double* dblLabels = GetLabelVals();<br />
<br />
for (int i = 1; i < 26; i++)<br />
strLabels[i].Format("%.2f\n", dblLabels[i]);<br />
<br />
SetDlgItemText(IDC_EDITINTERSECT, "INT"); <br />
SetDlgItemText(IDC_EDITY1, strLabels[3]);<br />
SetDlgItemText(IDC_EDITY2, strLabels[6]); <br />
SetDlgItemText(IDC_EDITY3, strLabels[9]);<br />
SetDlgItemText(IDC_EDITX1, strLabels[12]); <br />
SetDlgItemText(IDC_EDITX2, strLabels[15]); <br />
SetDlgItemText(IDC_EDITX3, strLabels[18]); <br />
SetDlgItemText(IDC_EDITX4, strLabels[21]);<br />
SetDlgItemText(IDC_EDITX5, strLabels[24]); <br />
<br />
InvalidateRect(pictRect);<br />
}
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
Should work... Run it in debug mode and check each value set by this call
student() wrote:
double* dblLabels = GetLabelVals();
make sure each value in dblLabels is set properly.
I ran the following on my machine at it worked perfectly
CStringArray strLabels;
strLabels.SetSize(26);
double arr[] = { 0 , 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 18, 20,
21, 22, 23, 26, 25 };
for (int i = 1; i < 26; i++)
{
strLabels[i].Format("%.2f\n", arr[i]);
AfxMessageBox(strLabels[i]);
}
Other than that I don't know what to tell you
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Gary...
Yeah something weird is going on. I ran it in the debugger and my dbl array is fine. The weird part is that after only one iteration of the for loop, all 26 of the values in the string array are set to -9255 plus about ten other numbers after that. I don't understand how one iteration could change all the values in the array.
Anyway..Thanks for your help..I really appreciate it.
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
Just for kicks, try using the CStringArray GetAt and SetAt functions instead of the [] operator.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
You can also us a vector. Here is an example
vector<CString> strLabels;
strLabels.reserve(26);
CString string;
strLabels.push_back("");
for (int i = 1; i < 26; i++)
{
string.Format("%.2f\n", dblLabels[i]);
strLabels.push_back(string);
}
put this at the top of you cpp file
#include <vector>
using std::vector;
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
the first line of code sould look like this
vector<CString>strLabels;
I forgot the message software doesn't like the <> symbols
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Just thought I would let you know since you helped me so much...
I didn't even need to convert to strings. I add some code to my GetLabelVals function and changed the name of it to SetLabels(). I didn't realize it before but you can attach a double variable to the edit controls then, I just set the var attached to each box using the corresponding element in my double array. Then to have it appear on the screen -- I call UpdateData(false). I knew I could get the value in the box with an attached variable but I just figured out that I can set it using a variable also, using the UpdateData(false) call. So much work just for that!!
...Brent
"It has become appallingly obvious that our technology has exceeded our humanity."
- Albert Einstein (1879-1955)
"I think there is a world market for maybe five computers."
- Thomas Watson (1874-1956), Chairman of IBM, 1943
"640K ought to be enough for anybody."
- Bill Gates (1955-), in 1981
"Half this game is ninety percent mental."
- Yogi Berra
|
|
|
|
|
#include <stdio.h>
#include <stdlib.h>
char buf1[50]="",buf2[50]="";
DWORD x1=1923;
float x2=0.5;
sprintf(buf1,"%d",x1);
sprintf(buf2,"%f",x2);
x1=atol(buf1);
x2=atof(buf2);
quite simple ? right !
//be cool
I am the mighty keeper of the book on knowledge . Contact me to get your copy .
|
|
|
|
|
I've written some code to try and authenticate with a proxy server but I'm having some difficulty, and I suspect it's something to do with supplying a domain name. The proxy server I use to connect to the Internet requires a user, password and a domain. Here's my code:
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy = "proxy:80";
proxyinfo.lpszProxyBypass = NULL;
session.SetOption(INTERNET_OPTION_PROXY, (LPVOID)&proxyinfo,
sizeof(INTERNET_PROXY_INFO));
pConn = session.GetHttpConnection(svr, port, user, pwd);
pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_GET, obj, NULL, 1,
NULL, NULL, dwHttpRequestFlags);
pFile->AddRequestHeaders(szHeaders);
pFile->SendRequest();
pFile->QueryInfoStatusCode(dwRet);
...
Note that I've already set the members svr , port , and obj by calling the AfxParseUrl() function. I've also set the variables pwd to my password and user to the following:
<domain>/<user>
Unfortunately dwRet is always set to 407 (failed authentication). I've tried the following format instead as some info on the Internet suggested:
<domain>\<user>
This didn't work either!
Strangely, I've written some Java which successfuly authenticates with the proxy server by creating an authorisation string using the following format:
<domain>/<user>:<password>
Can anyone suggest a solution?
"The folly of man is that he dreams of what he can never achieve rather than dream of what he can."
"If you think education is expensive, try ignorance."
|
|
|
|
|
OK, found the problem at MSDN - Q254396
Set the INTERNET_FLAG_KEEP_CONNECTION flag when you call the HttpOpenRequest WinInet API or add the "Proxy-Connection: Keep-Alive" header in the Execute method of Internet Transfer Control.
So we have:
proxyinfo.dwAccessType =
INTERNET_OPEN_TYPE_PROXY | INTERNET_FLAG_KEEP_CONNECTION;
...and the format of domain and username is as follows:
<domain>\<user>
"The folly of man is that he dreams of what he can never achieve rather than dream of what he can."
"If you think education is expensive, try ignorance."
|
|
|
|
|
What is "windowsx.h" and for what purposes it is used?
Thank you.
|
|
|
|
|
the file ? or what's inside ?
anyway, it looks like help macros to commonly used stuff.
Max.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi,
does anybody have some code to draw a marching ants rectangle? I found two techniques on the web, one using the LineDDA (http://www.undu.com/DN960901/00000009.htm) function, and one using a specific brush (http://www.funducode.com/freevc/gdi/gdi3.htm).
I would like to combine this with the CRectTracker. Does anybody have experiences with this?
Thanks
Dirk
|
|
|
|
|
In the sample theres a class derived from CTolbar. In it I see, generated by the CWizard:
/ Overrides
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
However if I do a context menu on the class in the class view pane, I dont see any way to add a virtual function to the class (like it exists for say the MyCview class). However this above was written by t he class wizard, so how did they do it? If I add it manually I am not supposed to type in the afx area right? Yet somehow in the sample the CW generated it...(I am assuming the author didnt put in in there himself). Is is okay to override this function by hand in any class I wish?
Appreciate your help,
ns
|
|
|
|
|
OnCommand is virtual-ized by CWnd and not the CToolbar class. That what they are doing in the class wizard. They are just overriding the function from up the heriarchy. I don't think CToolbar does anything with it at all. If you'd like to override it on your (by hand) it shouldn't cause any problems. The one stipulation about overriding the method is that it must be done from a CWnd derived class. Hopes this helps.
Joseph Dempsey
joseph_r_dempsey@yahoo.com
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
|
|
|
|
|
THat sure makes me feel more comfortable...
How they ever got it in the grey afx are I dont know. I dont plan to put it in that area. I tested it out...I can put the declare anywhere in the class definition and it still works.
Appreciate your help,
ns
|
|
|
|
|
In a dialog based appl. is it possible to create a region outside the dialog window?
|
|
|
|
|
Someone may end up correcting me here but i don't think you are going to be able to do that simply. I would need more information by making a final decsion. A region is created within a window and drawn by the gdi device context for that window. If you want to draw a region outside of your dialog that you will have to get the device context for the window that the region will be drawn in.
// guess work begins here.
// You would have do something like.. ( to draw the region over the desktop )
HDC hDC = ::GetDC( GetDesktopWnd() );
// ... Do region Creation code ...
// .. use device context to draw region
::ReleaseDC( hDC );
Of course a major problem will be repainting your region when the desktop draws over it.
Having said all that... it would probably be easier for you to create an "invisible"/transparent window and just position it as need be and then draw inside its space using its device context. This would allow you to retrieve the proper WM_PAINT messages so that you could redraw your region as need be when the rect becomes invalidated.
Hope this helps.
Joseph Dempsey
joseph_r_dempsey@yahoo.com
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
|
|
|
|
|