static void test_listbox_styles(DWORD cb_style) { BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); HWND combo; COMBOBOXINFO info; DWORD style, exstyle, expect_style, expect_exstyle; BOOL ret; pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } expect_style = WS_CHILD|WS_CLIPSIBLINGS|LBS_COMBOBOX|LBS_HASSTRINGS|LBS_NOTIFY; if (cb_style == CBS_SIMPLE) { expect_style |= WS_VISIBLE; expect_exstyle = WS_EX_CLIENTEDGE; } else { expect_style |= WS_BORDER; expect_exstyle = WS_EX_TOOLWINDOW; } combo = build_combo(cb_style); info.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(combo, &info); ok(ret, "Failed to get combobox info structure.\n"); style = GetWindowLongW( info.hwndList, GWL_STYLE ); exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE ); ok(style == expect_style, "%08x: got %08x\n", cb_style, style); ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle); if (cb_style != CBS_SIMPLE) expect_exstyle |= WS_EX_TOPMOST; SendMessageW(combo, CB_SHOWDROPDOWN, TRUE, 0 ); style = GetWindowLongW( info.hwndList, GWL_STYLE ); exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE ); ok(style == (expect_style | WS_VISIBLE), "%08x: got %08x\n", cb_style, style); ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle); SendMessageW(combo, CB_SHOWDROPDOWN, FALSE, 0 ); style = GetWindowLongW( info.hwndList, GWL_STYLE ); exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE ); ok(style == expect_style, "%08x: got %08x\n", cb_style, style); ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle); DestroyWindow(combo); }
static void test_WM_LBUTTONDOWN(void) { HWND hComboEx, hCombo, hEdit, hList; COMBOBOXINFO cbInfo; UINT x, y, item_height; LRESULT result; UINT i; int idx; RECT rect; WCHAR buffer[3]; static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; static const WCHAR stringFormat[] = {'%','2','d','\0'}; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } hComboEx = CreateWindowExA(0, WC_COMBOBOXEXA, NULL, WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150, hComboExParentWnd, NULL, hMainHinst, NULL); for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){ COMBOBOXEXITEMW cbexItem; wsprintfW(buffer, stringFormat, choices[i]); memset(&cbexItem, 0x00, sizeof(cbexItem)); cbexItem.mask = CBEIF_TEXT; cbexItem.iItem = i; cbexItem.pszText = buffer; cbexItem.cchTextMax = 0; ok(SendMessageW(hComboEx, CBEM_INSERTITEMW, 0, (LPARAM)&cbexItem) >= 0, "Failed to add item %d\n", i); } hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0); hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0); cbInfo.cbSize = sizeof(COMBOBOXINFO); result = pGetComboBoxInfo(hCombo, &cbInfo); ok(result, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hList = cbInfo.hwndList; ok(GetFocus() == hComboExParentWnd, "Focus not on Main Window, instead on %p\n", GetFocus()); /* Click on the button to drop down the list */ x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; result = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have appeared after clicking the button.\n"); idx = SendMessageA(hCombo, CB_GETTOPINDEX, 0, 0); ok(idx == 0, "For TopIndex expected %d, got %d\n", 0, idx); result = SendMessageA(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); /* Click on the 5th item in the list */ item_height = SendMessageA(hCombo, CB_GETITEMHEIGHT, 0, 0); ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n"); x = rect.left + (rect.right-rect.left)/2; y = item_height/2 + item_height*4; result = SendMessageA(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y)); ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); result = SendMessageA(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should still be visible.\n"); result = SendMessageA(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); todo_wine ok(GetFocus() == hEdit || broken(GetFocus() == hCombo), /* win98 */ "Focus not on ComboBoxEx's Edit Control, instead on %p\n", GetFocus()); result = SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0); ok(!result || broken(result != 0), /* win98 */ "The dropdown list should have been rolled up.\n"); idx = SendMessageA(hComboEx, CB_GETCURSEL, 0, 0); ok(idx == 4 || broken(idx == -1), /* win98 */ "Current Selection: expected %d, got %d\n", 4, idx); ok(received_end_edit, "Expected to receive a CBEN_ENDEDIT message\n"); SetFocus( hComboExParentWnd ); ok( GetFocus() == hComboExParentWnd, "got %p\n", GetFocus() ); SetFocus( hComboEx ); ok( GetFocus() == hEdit, "got %p\n", GetFocus() ); DestroyWindow(hComboEx); }
static void test_editselection(void) { HWND hCombo; INT start,end; HWND hEdit; COMBOBOXINFO cbInfo; BOOL ret; DWORD len; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); char edit[20]; pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } /* Build a combo */ hCombo = build_combo(CBS_SIMPLE); cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; /* Initially combo selection is empty*/ len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len)); /* Set some text, and press a key to replace it */ edit[0] = 0x00; SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason1"); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason1")==0, "Unexpected text retrieved %s\n", edit); /* Now what is the selection - still empty */ SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len)); /* Give it focus, and it gets selected */ SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now emulate a key press */ edit[0] = 0x00; SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now what happens when it gets more focus a second time - it doesn't reselect */ SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len)); DestroyWindow(hCombo); /* Start again - Build a combo */ hCombo = build_combo(CBS_SIMPLE); cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; /* Set some text and give focus so it gets selected */ edit[0] = 0x00; SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason2"); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason2")==0, "Unexpected text retrieved %s\n", edit); SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); /* Now what is the selection */ SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now change the selection to the apparently invalid start -1, end -1 and show it means no selection (ie start -1) but cursor at end */ SendMessage(hCombo, CB_SETEDITSEL, 0, -1); edit[0] = 0x00; SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit); DestroyWindow(hCombo); }
static void test_WM_LBUTTONDOWN(void) { HWND hCombo, hEdit, hList; COMBOBOXINFO cbInfo; UINT x, y, item_height; LRESULT result; int i, idx; RECT rect; CHAR buffer[3]; static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; static const CHAR stringFormat[] = "%2d"; BOOL ret; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } hCombo = CreateWindow("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150, hMainWnd, (HMENU)COMBO_ID, NULL, 0); for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){ sprintf(buffer, stringFormat, choices[i]); result = SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)buffer); ok(result == i, "Failed to add item %d\n", i); } cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; hList = cbInfo.hwndList; trace("hMainWnd=%p, hCombo=%p, hList=%p, hEdit=%p\n", hMainWnd, hCombo, hList, hEdit); ok(GetFocus() == hMainWnd, "Focus not on Main Window, instead on %p\n", GetFocus()); /* Click on the button to drop down the list */ x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; result = SendMessage(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have appeared after clicking the button.\n"); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); result = SendMessage(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); /* Click on the 5th item in the list */ item_height = SendMessage(hCombo, CB_GETITEMHEIGHT, 0, 0); ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n"); x = rect.left + (rect.right-rect.left)/2; y = item_height/2 + item_height*4; result = SendMessage(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); result = SendMessage(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y)); ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); ok(SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should still be visible.\n"); result = SendMessage(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); ok(!SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have been rolled up.\n"); idx = SendMessage(hCombo, CB_GETCURSEL, 0, 0); ok(idx, "Current Selection: expected %d, got %d\n", 4, idx); DestroyWindow(hCombo); }