|
<br />
void CDigitalclockDlg::OnPaint()<br />
{<br />
if (IsIconic())<br />
{<br />
CPaintDC dc(this);
. ........<br />
............<br />
............<br />
<br />
}<br />
else<br />
{<br />
<br />
<br />
<br />
<br />
CDialog::OnPaint();<br />
<br />
GetLocalTime(&time);<br />
<br />
<br />
char str[256];<br />
sprintf_s(str,"02d%:02d%:02d%",time.wHour,time.wMinute,time.wSecond);<br />
int len;<br />
int slength = (int)str.length() + 1;<br />
len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, 0, 0);<br />
wchar_t* buf = new wchar_t[len];<br />
MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, buf, len);<br />
SetDlgItemText(IDC_STATIC,(LPCTSTR)str); <br />
<br />
}<br />
}<br />
|
|
|
|
|
amistry_petlad wrote: sprintf_s(str,"02d%:02d%:02d%",time.wHour,time.wMinute,time.wSecond);
This should not even compile (bad format string).
amistry_petlad wrote: int slength = (int)str.length() + 1;
This should not even compile (integral types have no methods).
"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
|
|
|
|
|
When I had simply used sprintf complier generated warning for sprintf AND give suggestion fo sprintf_s
i am using MSVS2008 ON VISTA
I have change the code following way it compile succesful but rund time break the application
<br />
GetLocalTime(&time);<br />
char str[256]; <br />
<br />
<br />
sprintf_s(str,"02d%:02d%:02d%",time.wHour,time.wMinute,time.wSecond);<br />
<br />
std::string str1(str);<br />
int len;<br />
int slength = (int)str1.length() + 1;<br />
len = MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, 0, 0);<br />
wchar_t* buf = new wchar_t[len];<br />
MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, buf, len);<br />
SetDlgItemText(IDC_STATIC1,buf);<br />
|
|
|
|
|
amistry_petlad wrote: ...but rund time break the application
And rightfully so since you did not change sprintf_s() .
"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
|
|
|
|
|
now its working when i used sprintf but in the dialog it should be print hh:mm:yy
I have debug the application i got the perfect string in all varibals but when display in the static control its only shows the hour nothing more. So here in US 1:40:40 so must be displayed but it show me 1 only ?
|
|
|
|
|
amistry_petlad wrote: ...now its working when i used sprintf but...
It makes no difference whether you use sprintf() or sprintf_s() . If you have a malformed format string, you can't expect correct results.
What is the value of buf prior to calling SetDlgItemText() ?
"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
|
|
|
|
|
buf has garbage value now In my debugging i have seen that if 15:22:34
Then in buf shows L(1) only show what is the reason?
so then this character display in the static control
|
|
|
|
|
amistry_petlad wrote: sprintf_s(str,"02d%:02d%:02d%",time.wHour,time.wMinute,time.wSecond);
The format string is "02d%:02d%:02d%" or "%02d:%02d:%02d" ? Need to brushup those old C lessons?
BTW, Why can't you use CString?
SYSTEMTIME time;
GetLocalTime(&time);
CString csTime;
csTime.Format( _T("%02d:%02d:%02d"), time.wHour,time.wMinute,time.wSecond );
SetDlgItemText(IDC_STATIC1,csTime);
I apoligize that since i don't have VS2008 installed, the above code snippet is compiled in VS6.0. So try it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
sorry ,in hurry i had type that things but in my code it is ok but sorry for that.
and you are genius becoz you find that mistake anyways thanks for this code
|
|
|
|
|
amistry_petlad wrote: and you are genius
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
You guys dont like _strdate and _strtime functions, do you??
Regards,
Sandip.
|
|
|
|
|
Why do you do this in the OnPaint ?
SetDlgItemText(IDC_STATIC,(LPCTSTR)str);
you want to print str or buf ?
This signature was proudly tested on animals.
|
|
|
|
|
ya buf i have chnaged , the code is working but its not display the hh:mm:yy its only shows current hours in the static control
<br />
GetLocalTime(&time);<br />
char str[256]; <br />
<br />
sprintf(str,"%d:%d:%d",time.wHour,time.wMinute,time.wSecond);<br />
<br />
std::string str1(str);<br />
int len;<br />
int slength = (int)str1.length() + 1;<br />
len = MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, 0, 0);<br />
wchar_t* buf = new wchar_t[len];<br />
MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, buf, len);<br />
SetDlgItemText(IDC_STATIC1,(LPCTSTR)buf);<br />
|
|
|
|
|
Can you show your code,please?
|
|
|
|
|
the code working but display hours only i have increased the size of control but still not able to see the entire string
<br />
GetLocalTime(&time);<br />
char str[256]; <br />
<br />
sprintf(str,"%d:%d:%d",time.wHour,time.wMinute,time.wSecond);<br />
<br />
std::string str1(str);<br />
int len;<br />
int slength = (int)str1.length() + 1;<br />
len = MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, 0, 0);<br />
wchar_t* buf = new wchar_t[len];<br />
MultiByteToWideChar(CP_ACP, 0, str1.c_str(), slength, buf, len);<br />
SetDlgItemText(IDC_STATIC1,(LPCTSTR)buf);<br />
|
|
|
|
|
You can set size of font for this control.
|
|
|
|
|
How to convert grayscale image(.tif )to black & white ?
|
|
|
|
|
To do that, you just need to de-saturate the image.
The RGB colour-space does not easily lend itself to this operation, and the HSL colour model is far more useful here.
In an entirely non optimized method, you would:
Repeat loop for all pixels in source image
(1) convert pixel RGB to HSL
(2) drop the S value to 0
(3) convert back to RGB
(4) dump the converted pixel back
Here's some routines for colour-space conversion:
void hsvToRgb(float h, float s, float v, float *r, float *g, float *b)
{
int i;
float aa, bb, cc, f;
if (s == 0.0)
*r = *g = *b = v;
else
{
if (h == 1.0) h = 0.0;
h *= 6.0;
i = floor(h);
f = h - (float)i;
aa = v * (1.0 - s);
bb = v * (1.0 - (s * f));
cc = v * (1.0 - (s * (1.0 - f)));
switch(i)
{
case 0: *r = v; *g = cc; *b = aa; break;
case 1: *r = bb; *g = v; *b = aa; break;
case 2: *r = aa; *g = v; *b = cc; break;
case 3: *r = aa; *g = bb; *b = v; break;
case 4: *r = cc; *g = aa; *b = v; break;
case 5: *r = v; *g = aa; *b = bb; break;
}
}
}
#define myMin(a,b) (a<b?a:b)>
#define myMax(a,b) (a>b?a:b)
#define noHue 0
void rgbToHsv(float r, float g, float b, float *h, float *s, float *v)
{
float max = myMax(r, myMax(g, b)), min = myMin(r, myMin(g, b));
float delta = max - min;
*v = max;
if (max != 0.0)
*s = delta / max;
else
*s = 0.0;
if (*s == 0.0) *h = noHue;
else
{
if (r == max)
*h = (g - b) / delta;
else if (g == max)
*h = 2 + (b - r) / delta;
else if (b == max)
*h = 4 + (r - g) / delta;
*h *= 60.0;
if (*h < 0) *h += 360.0;
*h /= 360.0;
}
}
</b?a:b)>
I'll leave it to you to make them work with RGB values in the range [0..255]
|
|
|
|
|
enhzflep wrote: Here's some routines for colour-space conversion:
These functions does the same, right?
ColorRGBToHLS
ColorHLSToRGB
Nibu 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
|
|
|
|
|
|
enhzflep wrote: That'll teach me for using a 11 year old API help file..
Nibu 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
|
|
|
|
|
Hello,
I have written a BHO for explorer.exe.
It is working fine with Win XP but same code is not working with Windows 2003 Server.
Does anybody has any idea about this?
Regards,
Tony
|
|
|
|
|
tony_udz wrote: but same code is not working with Windows 2003 Server.
Oh, it's not working? Well that explains a lot. Thanks for all the specific information.
led mike
|
|
|
|
|
I mean to say BHO Dll is not loaded when exlorer.exe is laucnched.
If you have any idea about this please let me know.
My concern is that is ther any significant difference between Win XP and Win 2003 Server with reference to BHo.
|
|
|
|
|
tony_udz wrote: I mean to say BHO Dll is not loaded when exlorer.exe is laucnched.
And how did you determine that?
Is it listed in the add-ons list?
led mike
|
|
|
|
|