Microsoft KB Archive/326254

= Mouse Pointer Disappears When You Press F4 to Open the ComboBox Control =

Article ID: 326254

Article Last Modified on 7/11/2005

-

APPLIES TO

 Microsoft Platform Software Development Kit-January 2000 Edition, when used with:  Microsoft Windows XP Professional

 Microsoft Windows 2000 Standard Edition

 Microsoft Windows NT 4.0

 Microsoft Windows Millennium Edition</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q326254

<div class="symptoms_section">

SYMPTOMS
When a standard ComboBox appears in a Windows application, the mouse pointer disappears when the following sequence of events occurs:
 * First, you click in the ComboBox edit field.
 * Next, you type some text.
 * Last, you press F4 to cause the ComboBox to open (drop down).

If you press F4 and then move the mouse, the pointer reappears.

This behavior does not occur if, after you start to type, you move the mouse and then press F4.

NOTE: The mouse pointer is referred to as a &quot;cursor&quot; in code.

<div class="cause_section">

CAUSE
This behavior occurs because the edit portion of the ComboBox control hides the pointer while you type and displays the pointer when the mouse moves.

When the ComboBox control is dropped down, the ComboBox captures the mouse to use its input to select the items that are in the ComboBox. Therefore, the edit portion of the ComboBox control does not receive the mouse message so that it can display the pointer again.

<div class="resolution_section">

RESOLUTION
To prevent his behavior, you can cause the mouse pointer to appear when you press the F4 key:
 * 1) Handle the message CBN_DROPDOWN.
 * 2) Call SendMessage(WM_SETCURSOR,0,0) from inside the dropdown handler function. This causes the pointer to appear when the ComboBox opens.

A Truncated Example from an MFC Dialog-based Application
CCombofixDlg::CCombofixDlg(CWnd* pParent /*=NULL*/) : CDialog(CCombofixDlg::IDD, pParent) {   //AFX_DATA_INIT // Note that LoadIcon does not require a DestroyIcon in Win32 after this m_hIcon = AfxGetApp->LoadIcon(IDR_MAINFRAME); }

void CCombofixDlg::DoDataExchange(CDataExchange* pDX) {   CDialog::DoDataExchange(pDX); //AFX_DATA_MAP }

BEGIN_MESSAGE_MAP(CCombofixDlg, CDialog) //AFX_MSG_MAP END_MESSAGE_MAP

// CCombofixDlg message handlers void CCombofixDlg::OnDropdownCombomain {   SendMessage(WM_SETCURSOR,0,0); }

A Simple Windows Program

 * 1) include <windows.h>
 * 2) include <commctrl.h>

LPSTR lpClassName = &quot;TestWindow&quot;;  //Class of the window HWND hWndMain,hWndComboBox; HINSTANCE hInst; MSG msg;

WNDCLASSEX MyWnd,MyCtrl;

LRESULT CALLBACK MyWndProc(HWND hWnd,           UINT msg,            WPARAM wParam,            LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,       HINSTANCE hPrevInstance,        LPSTR lpCmdLine,        int nShow) {

hInst = hInstance;

ZeroMemory(&MyWnd,sizeof(MyWnd));

MyWnd.cbSize = sizeof(MyWnd); MyWnd.lpfnWndProc = MyWndProc; MyWnd.hInstance = hInstance; MyWnd.lpszClassName = lpClassName; MyWnd.hbrBackground =(HBRUSH)(COLOR_WINDOW+1); MyWnd.style = CS_VREDRAW |CS_HREDRAW;

RegisterClassEx(&MyWnd); //Make the main window hWndMain=CreateWindowEx(0,lpClassName,&quot;Combo Control Test&quot;,           WS_OVERLAPPEDWINDOW | WS_VISIBLE,            CW_USEDEFAULT,CW_USEDEFAULT,            CW_USEDEFAULT,CW_USEDEFAULT,                                NULL,NULL,hInstance,NULL);

//Now for the ComboBox control. hWndComboBox = CreateWindowEx(0,&quot;COMBOBOX&quot;,&quot;CTL&quot;,               CBS_DROPDOWN | WS_CHILD |WS_VISIBLE,                100,100,100,100,hWndMain,1234,                hInstance,NULL); SendMessage(hWndComboBox, CB_ADDSTRING, 0, &quot;hello world&quot;); UpdateWindow(hWndComboBox);

while(GetMessage(&msg,NULL,0,0)) {       TranslateMessage(&msg); DispatchMessage(&msg); }   return msg.wParam;

}

LRESULT CALLBACK MyWndProc(HWND hWnd,           UINT msg,            WPARAM wParam,            LPARAM lParam) {   PAINTSTRUCT ps;

switch (msg) {       case WM_COMMAND:

if(lParam == hWndComboBox) {   //This is a command from the Combo box check to         //see if it is CBN_DROPDOWN, and if so, to         //force the cursor (pointer) to appear. if(HIWORD(wParam) == CBN_DROPDOWN) SendMessage(hWndMain,WM_SETCURSOR,0,0); }

break;

case WM_PAINT: BeginPaint(hWndMain,&ps); EndPaint(hWndMain,&ps); break;

case WM_SETFOCUS:

break;

case WM_SIZE: break;

case WM_CREATE: break; case WM_CLOSE:

DestroyWindow(hWnd); break;

case WM_DESTROY: PostQuitMessage(0);

break; default : return DefWindowProc(hWnd,msg,wParam,lParam); }

return 0;

}

Additional query words: combobox list hidden disappear behind lost virtual key select dropdown cursor drop-down listbox

Keywords: kbpending kbprb KB326254

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.