|
double d =whatever;
int i = (int)(d + .5);
Please note that, as pointed out by Rage it doesn't work properly with negative numbers See the fix here [^].
-- modified at 8:10 Tuesday 10th July, 2007
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.
|
|
|
|
|
d=-5.6 => i=-5, not -6. Is this ok ?
|
|
|
|
|
he probably should take the absolute value, and then apply it the original sign...
|
|
|
|
|
Rage wrote: d=-5.6 => i=-5, not -6. Is this ok ?
No, of course. I (naively) assumed d > 0 .
But there is an easy fix to account for negative numbers:
i = (int) ( d < .0 ? d -.5 : d + .5 );
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.
|
|
|
|
|
Hi everybody,
i put a ListControl on a dialog and want to catch the LVN_BEGINDRAG Handler.
I know that LVN_BEGINDRAG is a notify message.
I tried already :
ON_NOTIFY_REFLECT(LVN_BEGINDRAG,OnBeginDrag)
and via :
OnNotify(WPARAM w,LPARAM l, ...
{
if(((LPNMHDR)l)->code == LVN_BEGINDRAG)
int ok = 1; --> breakpoint
but i can't catch it
I tried also directly to add a handler via the ressource editor by adding a new handler,
but there i can't find the LVN_BEGINDRAG handler, only DoubleClick, Set & KillFocus ...
How should i catch it?
Big thanks
|
|
|
|
|
Try this:
ON_NOTIFY(LVN_BEGINDRAG, IDC_LISTVIEW1, OnLvnBeginDrag)
This should work.
"Some people believe football is a matter of life and death.
I'm very disappointed with that attitude.
I can assure you it is much, much more important than that. -- Bill Shankly"
|
|
|
|
|
Thanks for your answer
Is it necessairy to create a class from this Listbox from which i want to catch the Drag?
Because it won't work
|
|
|
|
|
|
Thanks for the tutorial,
but i really don't find where i can add the LVN_BEGINDRAG-handler via the classwizard.
I tried a lot of things, but no way to find a LVN_BEGINDRAG.
|
|
|
|
|
You may actually have to type it in by hand
For the handler prototype(s), see ON_NOTIFY and WM_NOTIFY Messages[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
Insert this code to your program
BEGIN_MESSAGE_MAP(CDialogDlg, CDialog)
ON_NOTIFY(LVN_BEGINRDRAG, IDC_LIST2, OnLvnBeginrdragList2)
END_MESSAGE_MAP()
void CDialogDlg::OnLvnBeginrdragList2(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
}
afx_msg void OnLvnBeginrdragList2(NMHDR *pNMHDR, LRESULT *pResult);
|
|
|
|
|
Big thanks ,
my code was completely correct, but probably the CListbox don't support drag&drop,
with CListCtrl it works fine
|
|
|
|
|
I suggest use of CListCtrl on your program its better and very flexible than CListBox.;)
|
|
|
|
|
Hi All,
I calling the method SetEnvironmentVariable and i getting back return value that is nonzero and the last Error does not return to me nothing.
BUT
The Environment Variable is not set !?
What to do ?
Thanks for any help.
|
|
|
|
|
Yanshof wrote: SetEnvironmentVariable
This function will set the environment variable for the current process only. I will not change the whole system's environment variable.
|
|
|
|
|
Thanks,
How can i create new environment variable and/or change exist one data ?
|
|
|
|
|
|
To change system environment variables, modify the HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment registry key.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I wanted to make my program to work on the desktop.
like http://desktop-tools.net/clock.html
i tried many things but i just dont know how did they do it? i dont know about any technique to make it transparant.
Is this possible or is it somesort of rendercode that creates a picture from what you need to have on the desktop and so making everything arround the text transparant? i hope there is a easier way.
Greetz
Rob
|
|
|
|
|
See IActiveDesktop::SetWallpaper for set wallpaper on the desktop.
|
|
|
|
|
thx but then iam setting the whole wallpaper on every refresh of the application :P
isnt there a more useable way then creating wallpapers the whole time?
|
|
|
|
|
|
Did your solve solve or no?
|
|
|
|
|
One way (Windows 2000+) is to use Layered Windows[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
I am trying to print all the characters in MIDI command to a file.
If I open and see file in binary editor, all the characters like 0xF0, 0x43 are OK except the zero. How can I print zero in file.
If I add zero to CString it is not added in CString actually.
The code is:
FILE *pFile;<br />
CString strOut = "";<br />
unsigned char uc;<br />
pFile = fopen("DEBUG_FILE.TXT","a");<br />
for(int i = 0; i < lpMIDIOut->Header.dwBufferLength; i++){<br />
strOut = "\0";<br />
uc = lpMIDIOut->bBuffer[i];<br />
strOut += uc; <br />
if(uc == 0){<br />
fprintf(pFile,"0","%d");<br />
}<br />
else<br />
fprintf(pFile, strOut, "%c");<br />
}<br />
fprintf(pFile, "\n");<br />
fclose(pFile);<br />
Best Regards,
Suman
|
|
|
|