|
Oops, I thought about this for the floor(), but it wasn't the case. Forgot about the casting one.
And yes, the percentage is small, but as a game developer any clock cycles I can save by simple things like this are worth it. I guess my views of what is important may differ from others, I prefer high performance over clarity.
|
|
|
|
|
I can understand that - to a point. If you are that concerned with performance there are a lot of other techniques you can use to get big gains in performance. One simple example : if a complex expression or calculation is repeated then save the result in a temporary variable. I have lost count of how many times I have seen people repeat expressions in code. Not only will this have higher performance it will also help maintenance and that is one of my highest priorities. It is been frequently stated that software usually spends more time undergoing maintenance than it does being developed and in my experience this is very true so I believe in making software as maintainable as possible and clarity is very important for this.
One more thing - as you said before, the compiler will convert to multiplies automatically when it can so, to me, it makes no sense to sacrifice clarity for something that is done for you transparently. In fact, I find it completely ridiculous but opinions vary.
|
|
|
|
|
You're putting too much value on your solution if you ask me.
|
|
|
|
|
thanks for the tip. I hadn't noticed that.
|
|
|
|
|
See also my answer to your previous question.
I must get a clever new signature for 2011.
|
|
|
|
|
I require some result based on the a float value to multiply with an int value.
like 146 * (1/1.3333333) result should be 109.50 but through program it's come out with 108.95. I have also tried float( 146 * (1/1.333333)) and float(146) * float(1/1.333333) but the result is same. I am getting surprised from this result. Can anyone help me out.
|
|
|
|
|
hi
for me its giving right answer. i did like this.
char ms[100];
int tk = 146;
int tl = 1;
float tm = 1.333333;
float tr = ((float)tk)*(tl/tm);
sprintf(ms, "%f", tr);
AfxMessageBox(ms);
how you are doing?
Regards,
A. Gopinath.
|
|
|
|
|
Do not use floats or doubles if you want to get accuracy in the decimal portion of your values. Floating point values in computers are held in such a way that accuracy cannot be guaranteed. There are many articles on the internet that explain why this is so.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi everyone. I would like to know if it is possible to use Windows Forms from the System::Windows::Forms namespace in unmanaged C++. If it is possible, how is it done? Thanks.
|
|
|
|
|
It is not. If you wanna create gui apps with c++, dig around win32 APIs. CreateWindow is your friend.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I really need the datagridview tool in .net, any way of using it in Win32 API programming?
|
|
|
|
|
Just an idea! Can you have the WinForms dialogs in a COM compatible dll/class library? Then you might be able to use the WinForm dialogs in your unmanaged application. This might sound easier said then done but thought of just sharing the idea with you. You might also need to investigate on the feasiblity of this.
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
Is there any possibility to retrieve clicked menu item text?
In this example i can only get an ID, like:
unsigned in clicked = TrackPopupMenu(hContextMenu,
TPM_RETURNCMD |
TPM_VERPOSANIMATION,
rectangle.left+2, rectangle.bottom-2,
0,
hParent,
NULL);
So "clicked" contains ID now, like:
switch(clicked)
{
case MY_ID:
{
do_something();
}
}
I am interested in getting selected item text instead, because trying to implement dynamic popup menu. Lets say, there are some items in database, they could be changed, added, removed, and when i click a button - it should show a context menu with current items from DB (there are just about 10 items max).
Is there any "easy" way to do it? Or i am better off using combobox for that particular task?
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Well, once you have the ID of the menu item, you can use GetMenuItemInfo[^] to retrieve its text. However, since -as far as i understood- you fill the menu with the items yourself you have a way to know which ID represents which text, so you could also try e.g. putting the strings in an array and store their index in some way in the menu item ID, like, 1+index, and then when you got the ID from TrackPopup..., you subtract one and get the array index and don't need to fiddle around with GetMenuItemInfo.
p.s: in case you try the array thing, don't use 0 as a menu item ID (dunno if you can do that or not) because then you would not be able to distinguish between that menu item and the user dismissing the menu without a selection. That's why i suggested index+1...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Great! Thanks. Here is the algo (my own classes but the algo is good):
case CATS_BUTTON:
{
ContextMenu *ctx = new ContextMenu();
wchar_t *err = NULL;
ctx->Create();
wchar_t **Cats = db->ListTables(DB_FILE, err);
int i;
for(i = 1; ; i++)
{
if(!IsNullOrEmpty(Cats[i - 1]))
{
ctx->AddItem(i, Cats[i - 1]);
}
else break;
}
unsigned int Clicked = ctx->TrackMenuHit2(hWnd,
Fbuttons[1]->operator HWND());
switch(Clicked)
{
case 0:
break;
default:
{
MessageBoxW(0,Cats[Clicked - 1],NULL,0);
}
break;
}
ctx->Destroy();
delete ctx;
}
break;
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Nicely done.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Make it a habit not to use new/delete when you don't have to. You code will become simpler, potential resource leaks are eliminated, and you will be halfway to writing exception safe code.
|
|
|
|
|
i want to handle scrollbar properties in Cedit class like change width and color of scroll bar.
i use GetScrollBarCtrl function but it return null address. how can i change color and width.
|
|
|
|
|
|
Hi everyone . I try to use SetWindowLongPtr function to change behaviour of CComboBox control , but I get an error :
error C2065: 'SetWindowLongPtr' : undeclared identifier
what I can do ? I read somewhere that I need to install SDK , it's really necesary ? I mention that I use VC6 .
|
|
|
|
|
I think you will find that <a href="http://msdn.microsoft.com/en-us/library/ms633591(VS.85).aspx">SetWindowLong()</a>[<a href="http://msdn.microsoft.com/en-us/library/ms633591(VS.85).aspx" target="_blank" title="New Window">^</a>] should do what you want.
I must get a clever new signature for 2011.
|
|
|
|
|
I'd agree, although it's worth to mention that it's not supported for 64-bit versions of Windows.
After a bit of googling I found this[^] forum post, which seems to solve the problem.
Sadly, the download link to the feb 2003 platform SDK is broken, but maybe you can get it from somewhere else (I haven't tried).
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thaddeus Jones wrote: it's not supported for 64-bit versions of Windows.
Something which is clearly explained if one reads through the documentation for both functions.
I must get a clever new signature for 2011.
|
|
|
|
|
mesajflaviu wrote: what I can do ?
Are you including the correct header file?
mesajflaviu wrote: I read somewhere that I need to install SDK , it's really necesary ?
Not for SetWindowsLong() , but it is highly recommended.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Actually it is indeed required to install the SDK in the case of Visual Studio 6, since it predates 64-bit versions of Windows and doesn't have SetWindowLongPtr without the SDK.
modified 13-Sep-18 21:01pm.
|
|
|
|