|
How would one convert a float to an int without rounding it? Currently:
float f = 1.9;
int i = (int)f;
i would equal 2. How do I get it to not round, and have i equal 1 in the above example? Any help is appreciated.
-Dev578
|
|
|
|
|
As defined by the C++ standard, floating to integer conversions truncate. So 1.9 would convert to 1.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
int i = (int)(f + 0.5);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
You expression rounds, which I think is the opposite of what he wants, which is simple truncation.
Software Zen: delete this;
|
|
|
|
|
i would not equal 2. Simple 'C'-style casts truncate, so you will see i == 1 .
Software Zen: delete this;
|
|
|
|
|
Ok, i cannot get of this stupid error
Process ViewerDlg.cpp(151) : error C2664: 'EnumWindows' : cannot convert parameter 1 from 'int (struct HWND__ *,long)' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type
Line 151: EnumWindows( GetWindows, 0 );
and my definition of GetWindows
BOOL CALLBACK GetWindows( HWND hwnd, LPARAM lParam );
Note: this is an MFC project
|
|
|
|
|
sure about that CALLBACK part? It provides exactly the __stdcall part the compiler is missing. Search your project for other occurences / definitions of GetWindows
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
its not the GetWindows name, i even tried renaming the function
and i dont know what to do about the CALLBACK do you?
|
|
|
|
|
Sorry, I meant: please double check that the "CALLBACK actually is there.
What platform are you compiling for? Win32 / Intel?
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
ohh, yes, the CALLBACK is there,
i even tried replacing CALLBACK with __stdcall
i have never had any problems using EnumWindows outside of MFC projects,
if it comes down to it i may just use GetTopWindow()
and GetNextWindow();
although i really prefer not too
|
|
|
|
|
Do you use the CALLBACK function as a member-function of your dialog class?
In case you do, take a look at this article
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This worked fine for me:
BOOL CALLBACK GetWindows( HWND, LPARAM )
{
return 0;
}
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
EnumWindows(GetWindows, 0);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
I've been trying desperately integrating the new compiler into the VC++ 6.0 IDE. I put the directories (bin, include and lib) of the toolkit at top of the list and the new compiler compiles
But now I get either linker errors (LNK2001, over 300 times...) for all the STL-Stuff or - if i change the order of the directories - get over 1000 compiler errors in the header files of the toolkit.
has anybody successfully integrated the toolkit to vc6 or knows good links about this topic (i searched the web but didn't manage to find something useful)
|
|
|
|
|
For your situation, I hope that I am wrong, but I don't think that you can put the MS VC Toolkit 2003 into VC6.0, partly if not entirely because of the vast version differences.
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hello!
I've been told that everything to be drawn in a dialog needs to be in the OnPaint method. Or else when you minimize and maximize again you won't seen anything.
i have these two functions that paint on the dialog when i click the left mouse button :
<br />
void CVentanaPizarra::OnMouseMove(UINT nFlags, CPoint point) <br />
{<br />
if (nFlags == MK_LBUTTON)<br />
{<br />
CClientDC dc(this);<br />
CPen Lapiz; <br />
<br />
Lapiz.CreatePen (PS_SOLID,1,RGB(0,0,0)); <br />
dc.SelectObject(Lapiz); <br />
<br />
if ((m_PosMouse.x!=-1)&&(m_PosMouse.y!=-1))<br />
{<br />
dc.MoveTo(point.x, point.y);<br />
dc.LineTo(m_PosMouse.x,m_PosMouse.y);<br />
}<br />
dc.MoveTo(point.x, point.y);<br />
dc.LineTo(point.x+(int).5, point.y+(int).5);<br />
m_PosMouse=dc.GetCurrentPosition(); <br />
}<br />
CDialog::OnMouseMove(nFlags, point);<br />
}<br />
<br />
void CVentanaPizarra::OnLButtonUp(UINT nFlags, CPoint point) <br />
{<br />
m_PosMouse.x=-1;<br />
m_PosMouse.y=-1;<br />
CDialog::OnLButtonUp(nFlags, point);<br />
}<br />
the problem is that it's not in the OnPaint function.
How could i do to stop what i've drawn from erasing when i minimize the window?
thanks!
|
|
|
|
|
kfaday wrote:
the problem is that it's not in the OnPaint function.
How could i do to stop what i've drawn from erasing when i minimize the window?
The OnDraw function is the funtion that repaints the view whenever it needs to be painted. Place your drawing code within that function (or call the function that you have doing the drawing in OnDraw) and that should solve your problem. You can also call your view class's Invalidate() function to repaint the view as you need to.
Good luck on your programming efforts.
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
i'm trying to store points, and then redraw in the OnDraw function, but i'm not successful.
I've declared in the header file
typedef std::list<CPoint> CListaPuntos; inside the class there's:
CListaPuntos ListaPuntos;
In the constructor of the class, i've written:
m_PosMouse.x=-1;
m_PosMouse.y=-1;
this->ListaPuntos.push_back(m_PosMouse);
In the list, i store a Cpoint variable with (-1,-1)
Then, this is the function which draws and stores points in the list
void CVentanaPizarra::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_DibLapiz)
{
CRect rect;
GetClientRect(rect);
if ((nFlags == MK_LBUTTON) && ((m_PosMouse.x>rect.left+90) || (m_PosMouse.x==-1)))
{
CClientDC dc(this);
CPen Lapiz;
Lapiz.CreatePen (PS_SOLID,1,RGB(0,0,0));
dc.SelectObject(Lapiz);
if (point.x>rect.left+90)
{
CPoint punto;
if ((m_PosMouse.x!=-1)&&(m_PosMouse.y!=-1))
{
this->ListaPuntos.push_back(point);
dc.MoveTo(point.x, point.y);
dc.LineTo(m_PosMouse.x,m_PosMouse.y);
}
dc.MoveTo(point.x, point.y);
this->ListaPuntos.push_back(point);
punto.x=point.x+(int).5;
punto.y=point.y+(int).5;
dc.LineTo(punto.x, punto.y);
this->ListaPuntos.push_back(punto);
}
m_PosMouse=dc.GetCurrentPosition();
}
}
CDialog::OnMouseMove(nFlags, point);
}
this function compliments the abovementioned one:
void CVentanaPizarra::OnLButtonUp(UINT nFlags, CPoint point)
{
m_PosMouse.x=-1;
m_PosMouse.y=-1;
this->ListaPuntos.push_back(m_PosMouse);
CDialog::OnLButtonUp(nFlags, point);
}
and this is the onpaint function:
void CVentanaPizarra::OnPaint()
{
CPaintDC dlgDC(this);
PintarBlanco(dlgDC);
if (ListaPuntos.size()>1)
{
CPoint punto1, punto2;
for (CListaPuntos::iterator i = ListaPuntos.begin(); i != ListaPuntos.end(); i++)
{
punto1= *i;
if (i==ListaPuntos.end())
break;
if (punto1.x!=-1)
{
dlgDC.LineTo(punto1.x,punto1.x);
dlgDC.MoveTo(punto1.x,punto1.y);
}
i++;
if (i==ListaPuntos.end())
break;
punto2= *i;
if (punto1.x!=-1)
dlgDC.LineTo(punto2.x,punto2.x);
dlgDC.MoveTo(punto2.x,punto2.y);
}
}
}
something is drawn, but not what i want, or what i've drawn with the mouse.
any ideas?
thanks!
|
|
|
|
|
First of all, you are still drawing in the mousemove handler, which will not exactly make it easy for you to know what drawing works and what don't. Moreover, this code is leaking GDI-handles, as you don't unselect the pen you have created and selected. The paint handler, on the other hand, will use whatever pen happens to be selected into the CDC.
You are adding point twice to the list, which looks slightly odd. You seem to be moving to the current position, drawing backwards, and then forward again, is this really what you intended.
The OnPaint -handler is definitely odd as well - you are drawing and then moving?
I think you should get some pen and paper, and outline what you really want to do. Basically, when all prerequisits for drawing is fullfilled in OnMouseMove, just add the current point to the list. Invalidate and redraw the window as appropriate. Then, in OnPaint, create and select the pen you want to draw with. Set the initial position with MoveTo . Loop the list, and call LineTo for each point. Voilà!
|
|
|
|
|
thanks for all the tips!!
they really helped me!
|
|
|
|
|
Hi,
We are planning to send some Fax related data as a SOAP with Attachments messages to a Fax consuming Service over MQ. I would like to know if it is possible (in .NET, PocketSOAP or SOAPToolkit) to create the SOAP Message along with attachments and then serialize it to a byte stream, which can then be used to populate the MQ Message. What I am looking for is the equivivalent of the SAAJ library in Java. Can anybody point me to some info on this or give advise.
Thanks,
Kris
|
|
|
|
|
One note, AFAIK .NET uses DIME, and cannot read MIME, so you won't get 100% compatibility. I think in the future there is supposed to be a "standard" format that everyone will use. Now, if you are 100% Microsoft on all sides, this won't be a problem. And some non-Microsoft code (e.g., Apache Axis) can understand both.
Somebody correct me if I'm wrong, though.
"Fish and guests stink in three days." - Benjamin Franlkin
|
|
|
|
|
Thanks for your reply. Unfortunately I dont have a choice about the receiving end. It expects SOAP with MIME Attachments. I couldnt find any examples with MIME attachments and .NET. That's why I had mentioned - PocketSOAP which seems to support it but was wondering if it was tranport dependent (as I am not using HTTP but MQ). Apache also has a C++ Axis implementation. I should probably look at it too. Any other suggestions would be welcome.
|
|
|
|
|
That is what we found as well. Also we got DIME working between ASP.NET (IIS) and Tomcat. It wasn't easy but it works.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
How can i load the icon from antother application/process and set it as the icon for a MFC list control item
|
|
|
|
|
hi!
I never did THIS but... here is a code sample
how to load some ressource from a DLL
extern "C" DllExport BYTE* GetLogo(int &nSize) {
DWORD dw;
HRSRC hRes = FindResource(g_hInstance,_T("IDR_LOGO"),_T("Images"));
dw = GetLastError();
HGLOBAL hg=LoadResource(g_hInstance,hRes);
LPVOID lpRes=LockResource(hg);
nSize = SizeofResource(g_hInstance,hRes);
dw = GetLastError();
return (BYTE*)lpRes;
}
I think you have just to get the HINSTACE to the app you want, and then load the ICON from it!
good luck!
|
|
|
|