I have written code in Visual Studio 2005 to show list box as a pop-up window.
On Clicking the main window, I show/hide the window accordingly.
Yea the program working as I expected without having any problems.
When I had some issues, i decided to debug the program.
On showing the Listbox( cursor will be clipped ), I stopped debugging using Shift+F5.
The thing is, the Cursor Clipping was still there. After closing some opened windows from Visual Studio IDE and Switching to other windows resolved issue. but it was hectic for minute.
I’m sure the process was not at all active. because it’s a very small application which exit on Shift+F5 press
// Code to clip the cursor on showing/hdie the window
void CListBoxEx::OnShowWindow(BOOL bShow, UINT nStatus)
{
CListBox::OnShowWindow(bShow, nStatus);
if( SW_SHOWNORMAL == bShow ) // Clip the cursor if window showing
{
CRect rect;
GetWindowRect(rect);
ClipCursor( rect );
}
else if( SW_HIDE == bShow ) // remove clipping on hiding
{
ClipCursor(NULL);
}
}
One Comment
Somebody pointed out the reason for the same.
“The cursor is a shared resource. If an application confines the cursor, it must release the cursor by using ClipCursor before relinquishing control to another application.”
One Trackback
[...] if( SW_SHOWNORMAL == bShow ) // Clip the cursor if window showing { CRect rect; GetWindowRect(rect); ClipCursor( rect ); } else if( SW_HIDE == bShow ) // remove clipping on hiding { ClipCursor(NULL); }} Posted by S a r a t hIt’s useful article i think.Link to original article [...]