|
In theory - it depends on processor data "word" size and not on software (e.a. compiler) running on it.
Unsigned integer on 4 bit mashine has max size of decimal 16.
|
|
|
|
|
An int is a logical construct of a programming language. While the register of a CPU often determines the maximum size of an int, this is by no means a requirement of a compiler. (For example, there are 8-bit microprocessors that can mimic 16-bit operations.) Furthermore, as register sizes have increased to 64-bit, an int in C/C++ has tended to stay at 32-bit (in part because that would leave a hole in the data size scheme.)
|
|
|
|
|
It is platform dependent constant which is proposed by ANSI.
And if you take a work with a 16 bit Turbo C compiler on a 32 bit processor.
The value of int will be -32768 to 32767. So i believe it depends on compiler, isnt it?
If i am wrong please do correct.
Величие не Бога может быть недооценена.
|
|
|
|
|
It's entirely dependent on the compiler, which is why I corrected Vaclav_Sal.
The only requirement is that the size of an int is as big or bigger than that of a short and as big or smaller than that of a long. A compliant compiler could make a char, short, int and long all 5 bits long if it chose. Likewise, it could make them all 64-bits long regardless of the underlying CPU and/or system architecture.
However, Vaclav_Sal is correct if he's suggesting that in the past, an int generally reflected the optimal "WORD" size of a CPU--a point I made earlier. However, for 64-bit and greater processors, int has lost that meaning and is generally 32-bits long.
|
|
|
|
|
Thanks
Величие не Бога может быть недооценена.
|
|
|
|
|
I created a listbox (owner drawn) using the code given below. the problem with my application is that when i click on any item in the listbox it gets selected .
how to rectify that ?
Here's my code :-
CChatHistory is my ListBox's class name
#include "stdafx.h"
#include "sock.h"
#include "ChatHistory.h"
IMPLEMENT_DYNAMIC(CChatHistory, CListBox)
CChatHistory::CChatHistory()
{
}
CChatHistory::~CChatHistory()
{
}
BEGIN_MESSAGE_MAP(CChatHistory, CListBox)
END_MESSAGE_MAP()
void CChatHistory::AddItem(const CString& str, COLORREF rgbText)
{
int nIndex;
nIndex = AddString(str);
if( CB_ERR != nIndex )
SetItemData(nIndex, rgbText);
}
void CChatHistory::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC dc;
CRect rcItem(lpDIS->rcItem);
UINT nIndex = lpDIS->itemID;
COLORREF rgbBkgnd = ::GetSysColor((lpDIS->itemState & ODS_SELECTED) ?COLOR_HIGHLIGHT : COLOR_WINDOW);
dc.Attach(lpDIS->hDC);
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
CBrush br(rgbBkgnd);
dc.FillRect(rcItem, &br);
if( lpDIS->itemState & ODS_FOCUS )
dc.DrawFocusRect(rcItem);
if( nIndex != (UINT)-1 )
{
COLORREF rgbText = (lpDIS->itemState & ODS_SELECTED) ?::GetSysColor(COLOR_HIGHLIGHTTEXT) : GetItemData(nIndex);
CString str;
GetText(nIndex, str);
dc.SetBkColor(rgbBkgnd);
dc.SetTextColor(rgbText);
dc.TextOut(rcItem.left + 2, rcItem.top + 2, str);
}
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
void CChatHistory::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
CClientDC dc(this);
TEXTMETRIC tm;
CFont* pFont = GetFont();
CFont* pOldFont = dc.SelectObject(pFont);
dc.GetTextMetrics(&tm);
dc.SelectObject(pOldFont);
lpMIS->itemHeight = tm.tmHeight + 4;
}
int CChatHistory::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
{
CString str1, str2;
GetText(lpCIS->itemID1, str1);
GetText(lpCIS->itemID2, str2);
return str1.Compare(str2);
}
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
Remove the following lines from the DrawItem method.
if( lpDIS->itemState & ODS_FOCUS )
dc.DrawFocusRect(rcItem);
if( nIndex != (UINT)-1 )
{
COLORREF rgbText = (lpDIS->itemState & ODS_SELECTED) ?::GetSysColor(COLOR_HIGHLIGHTTEXT) : GetItemData(nIndex);
CString str;
GetText(nIndex, str);
dc.SetBkColor(rgbBkgnd);
dc.SetTextColor(rgbText);
dc.TextOut(rcItem.left + 2, rcItem.top + 2, str);
}
|
|
|
|
|
removing these lines causes my control to not even display a single line.
now my listbox is not displaying anything in it.
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
OK. Try this -
Replace
COLORREF rgbBkgnd = ::GetSysColor((lpDIS->itemState & ODS_SELECTED) ?COLOR_HIGHLIGHT : COLOR_WINDOW); with
COLORREF rgbBkgnd = COLOR_WINDOW;
Remove
if( lpDIS->itemState & ODS_FOCUS )
dc.DrawFocusRect(rcItem);
Replace
if( nIndex != (UINT)-1 )
{
COLORREF rgbText = (lpDIS->itemState & ODS_SELECTED) ?::GetSysColor(COLOR_HIGHLIGHTTEXT) : GetItemData(nIndex);
CString str;
GetText(nIndex, str);
dc.SetBkColor(rgbBkgnd);
dc.SetTextColor(rgbText);
dc.TextOut(rcItem.left + 2, rcItem.top + 2, str);
}
with
if( nIndex != (UINT)-1 )
{
COLORREF rgbText = GetItemData(nIndex);
CString str;
GetText(nIndex, str);
dc.SetBkColor(rgbBkgnd);
dc.SetTextColor(rgbText);
dc.TextOut(rcItem.left + 2, rcItem.top + 2, str);
}
|
|
|
|
|
now background goes black for each line added to the listbox.
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
It's solved
just done as you said with some modification:-
REPLACE
COLORREF rgbBkgnd = COLOR_WINDOW;
WITH
COLORREF rgbBkgnd = ::GetSysColor(COLOR_WINDOW);
Thanks SUPERMAN
Future Lies in Present.
Manmohan Bishnoi
|
|
|
|
|
At best, that does not prevent selection, all it attempts to do is not show the selected status...
|
|
|
|
|
Hi again,
I am not here to be a pain, it a OpenGL compiling problem I have with my 3D project. I have went to properties and linked all the libraries and used the #pragma comment (lib, "glut32.lib") and the whole list of error went away then I got 1 last error saying.
fatal error LNK1104: cannot open file 'GLU32.lib, GLUT32.lib, OpenGL32.lib'
Thank you.
Andrew McIntyre
|
|
|
|
|
Have you added the directory path of these libraries to your project? Go to project properties and add the path to the "Additional Library Directories" item under Linker -> General.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Can anyone give me the precise difference between
GetAsyncKeyState(vk_shift) and GetKeyState(vk_shift) ?
I can and did read the explainment of MS, but i guess i still don't get it. In my apps i use
GetAsyncKeyState(vk_shift)!=0
to find out if the shift-key is pressed. Should i use GetKeyState() instead and if yes, why? And could you give me an example of how to check the shift key with that one.
If no, where is GetKeyState() then good for? Can you give an example of its use?
Thanks
|
|
|
|
|
I think the hint is in the name: you should call GetKeyState after a Keyboard message has been sent to your thread (MSDN [^]: "An application calls GetKeyState in response to a keyboard-input message."). On the other hand, you may call GetASyncKeyState whenever you need it.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ok, get it but:
CPallini wrote: On the other hand, you may call GetASyncKeyState whenever you need it.
What does it give back then: The current state or the state it had after the last keyboard message or ...?
According to MSDN: The key status returned from this function (GetKeyState) changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
"The status does not reflect the interrupt-level state associated with the hardware." What's this? (i do know the concept of interrupts) Is it a strange way of telling me that GetKeyState() could give me a key-status that is actually outdated already?
|
|
|
|
|
GetAsyncKeyState gives the current state.
Rozis wrote: s it a strange way of telling me that GetKeyState() could give me a key-status that is actually outdated already?
Yes, it maybe outdated.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: GetAsyncKeyState gives the current state.
OK. What I learned so far (correct me please if i'm wrong):
GetKeyState() returns if a key is pressed based on the current status of the messagequeue. The status of the messagequeue is formed by the keyboard messages sent and processed to this queue.
GetAsyncKeyState(), on the other hand, returns if a key is pressed based on the current status of the keyboard hardware. In most cases both functions have the same outcome.
There are some differences:
1) Synthesizing a keypress would work when GetKeyState() was used but not when GetAsyncKeyState() was used. - Am i right? And what about keyboard hooks?
2) As Adam Roderick J 09 points out GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values. GetKeyState buffers these values. GetAsyncKeyState gives you only if these keys are currently pressed or not, not if they are on or off.
Avi Berger gave this link: http://blogs.msdn.com/oldnewthing/archive/2004/11/30/272262.aspx[^]
modified on Sunday, March 21, 2010 5:01 PM
|
|
|
|
|
|
Then it must be a peace of cake for you to point me out the precise difference between
GetAsyncKeyState() and GetKeyState() ?
|
|
|
|
|
GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).
Above explanation as per msdn.
Now the case of SHIFT button applied to these cases to a normal application as example.
Now if you click the SHIFT key before calling this API in your application then
SHORT nVirtAsyc = GetAsyncKeyState(VK_LSHIFT);
SHORT nVirtSync = GetKeyState(VK_LSHIFT);
Async = 0
Sync = 1;
Now again you click SHIFT key
Aync = 0
Sync = 0
Now i think you got the point, GetKeyState gives the toggle values.
While GetAyncKeyState will be 1 when you have Pressed the SHIFT button.
Not the released button.
GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values
Величие не Бога может быть недооценена.
modified on Sunday, March 21, 2010 12:35 PM
|
|
|
|
|
Adam Roderick J 09 wrote: GetKeyState is useful for VK_NUMLOCK or VK_CAPITAL, which depends on toggle values
Of course you're right: there's no (practical) way to get vk_numlock with GetAsyncKeyState. I didn't thought of that - Good answer!
Does this also mean that a synthesized keystroke (with SendInput() or sending keyboard messages) will not be handled with GetAsyncKeyState() ?
|
|
|
|
|
why not?
Just check with a sample code man
Величие не Бога может быть недооценена.
|
|
|
|
|
Rozis wrote: In my apps i use
GetAsyncKeyState(vk_shift)!=0
to find out if the shift-key is pressed.
In most cases you want to use GetKeyState() and not GetAsyncKeyState().
If the shift-key was pressed when?
Are you processing a particular keystroke? (Such as in an OnKeyDown handler?)
GetKeyState() tells you the state at the time of the event that you are processing.
GetAsyncKeyState() tells you the state at the instant that you call it. This is not coordinated with where your program is in processing its input stream.
For a longer explanation, see here[^].
Please do not read this signature.
|
|
|
|