[PATCH] comctl32: Handle NULL text in COMBOEX_NotifyEndEdit().

Dmitry Timoshkov dmitry at baikal.ru
Wed Jun 2 02:43:51 CDT 2021


Haoyang Chen <chenhaoyang at uniontech.com> wrote:

> --- a/dlls/comctl32/comboex.c
> +++ b/dlls/comctl32/comboex.c
> @@ -223,6 +223,10 @@ static INT COMBOEX_NotifyEndEdit (const COMBOEX_INFO *infoPtr, NMCBEENDEDITW *ne
>  {
>      /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
>      if (infoPtr->NtfUnicode) {
> +        if (!wstr) {
> +            neew->szText[0] = 0;
> +            return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
> +        }
>  	lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
>  	return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
>      } else {

It would be better to avoid duplication, and use something like this:
if (!wstr)
    neew->szText[0] = 0;
else
    lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);

> --- a/dlls/comctl32/tests/combo.c
> +++ b/dlls/comctl32/tests/combo.c
> @@ -46,7 +46,7 @@ static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
>  
>  static HWND hComboExParentWnd, hMainWnd;
>  static HINSTANCE hMainHinst;
> -static const char ComboExTestClass[] = "ComboExTestClass";
> +static const WCHAR ComboExTestClass[] = L"ComboExTestClass";
>  
>  static HBRUSH brush_red;
>  
> @@ -67,7 +67,7 @@ static void get_combobox_info(HWND hwnd, COMBOBOXINFO *info)
>  }
>  
>  static HWND createComboEx(DWORD style) {
> -   return CreateWindowExA(0, WC_COMBOBOXEXA, NULL, style, 0, 0, 300, 300,
> +   return CreateWindowExW(0, WC_COMBOBOXEXW, NULL, style, 0, 0, 300, 300,
>              hComboExParentWnd, NULL, hMainHinst, NULL);
>  }
>  
> @@ -263,7 +263,7 @@ static void test_comboex_WM_LBUTTONDOWN(void)
>      WCHAR buffer[3];
>      static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
>  
> -    hComboEx = CreateWindowExA(0, WC_COMBOBOXEXA, NULL,
> +    hComboEx = CreateWindowExW(0, WC_COMBOBOXEXW, NULL,
>              WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150,
>              hComboExParentWnd, NULL, hMainHinst, NULL);
>  
> @@ -281,8 +281,10 @@ static void test_comboex_WM_LBUTTONDOWN(void)
>             "Failed to add item %d\n", i);
>      }
>  
> -    hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
> -    hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
> +    addItem(hComboEx, 4, NULL);
> +
> +    hCombo = (HWND)SendMessageW(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
> +    hEdit = (HWND)SendMessageW(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
>  
>      get_combobox_info(hCombo, &cbInfo);
>      hList = cbInfo.hwndList;
> @@ -552,7 +554,7 @@ static void init_functions(void)
>  
>  static BOOL init(void)
>  {
> -    WNDCLASSA wc;
> +    WNDCLASSW wc;
>  
>      wc.style = CS_HREDRAW | CS_VREDRAW;
>      wc.cbClsExtra = 0;
> @@ -564,18 +566,18 @@ static BOOL init(void)
>      wc.lpszMenuName = NULL;
>      wc.lpszClassName = ComboExTestClass;
>      wc.lpfnWndProc = ComboExTestWndProc;
> -    RegisterClassA(&wc);
> +    RegisterClassW(&wc);
>  
>      brush_red = CreateSolidBrush(RGB(255, 0, 0));
>  
> -    hMainWnd = CreateWindowA(WC_STATICA, "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
> +    hMainWnd = CreateWindowW(WC_STATICW, L"Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
>      ShowWindow(hMainWnd, SW_SHOW);
>  
> -    hComboExParentWnd = CreateWindowExA(0, ComboExTestClass, "ComboEx test", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
> -      CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
> +    hComboExParentWnd = CreateWindowExW(0, ComboExTestClass, L"ComboEx test", WS_OVERLAPPEDWINDOW|WS_VISIBLE,
> +      CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleW(NULL), 0);
>      ok(hComboExParentWnd != NULL, "failed to create parent window\n");
>  
> -    hMainHinst = GetModuleHandleA(NULL);
> +    hMainHinst = GetModuleHandleW(NULL);
>  
>      return hComboExParentWnd != NULL;
>  }
> @@ -584,14 +586,14 @@ static void cleanup(void)
>  {
>      MSG msg;
>      
> -    PostMessageA(hComboExParentWnd, WM_CLOSE, 0, 0);
> +    PostMessageW(hComboExParentWnd, WM_CLOSE, 0, 0);
>      while (GetMessageA(&msg,0,0,0)) {
>          TranslateMessage(&msg);
>          DispatchMessageA(&msg);
>      }
>      
>      DestroyWindow(hComboExParentWnd);
> -    UnregisterClassA(ComboExTestClass, GetModuleHandleA(NULL));
> +    UnregisterClassW(ComboExTestClass, GetModuleHandleA(NULL));

Please avoid unrelated A to W API changes.

-- 
Dmitry.



More information about the wine-devel mailing list