[Bug 9155] New: CBN_SELCHANGE and WM_GETTEXT bug/"feature" in Windows

Wine Bugs wine-bugs at winehq.org
Wed Aug 1 19:54:40 CDT 2007


http://bugs.winehq.org/show_bug.cgi?id=9155

           Summary: CBN_SELCHANGE and WM_GETTEXT bug/"feature" in Windows
           Product: Wine
           Version: CVS
          Platform: PC
               URL: http://source.winehq.org/source/dlls/user32/combo.c#L134
                    7
        OS/Version: All
            Status: UNCONFIRMED
          Severity: minor
          Priority: P4
         Component: wine-user
        AssignedTo: wine-bugs at winehq.org
        ReportedBy: megajocke at notsohotmail.com


When writing code for a dialog that uses a combo box of type CBS_DROPDOWN I
stumbled upon something strange in Windows XP. In the CBN_SELCHANGE notification
from the combo box the text of the edit box has not updated yet, which means
WM_GETTEXT or APIs that use it return the old value instead of the newly
selected. This does happen to CBS_SIMPLE too as it has an edit control but does
not happen to CBS_DROPDOWNLIST. 

I had a look in WINE's combo box code and it looks like in WINE the edit box
text gets updated (line 1358) before the notification is sent (line 1374). So
this means that WM_GETTEXT will return the current value instead of the previous
one which it does in Windows. The problem with this that I can see is probably
more that applications written for WINE won't work correctly in Windows as it is
 not a far fetch to assume that WM_GETTEXT would work in the CBN_SELCHANGE handler.

Just changing it to how it work in Windows might break something in WINE if some
dialog somewhere is using WM_GETTEXT, GetDlgItemText or GetWindowText to get the
value from a combo box with edit control. For example, I saw code in the printer
dialog that uses WM_GETTEXT. (But this doesn't matter if the combo is of
DROPDOWNLIST type which I didn't check if it was or not)

To "fix" it, all CBN_SELCHANGE references in WINE need to be checked (not that
many) and then CB_NOTIFY needs to be moved before the if block. Is it really
correct though that the combo box sends CBN_SELCHANGE even when the list box
reported LBN_SELCANCEL? Maybe it should be the first thing to do in the first if
block?

Here is a page from Microsoft on this behaviour, and it seems like it has worked
like that from the beginning, look at that stuff about Win32 :P. The article is
not entirely accurate though as WM_GETTEXT would return the newly selected value
in a CBS_DROPDOWNLIST:
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B66365

Here is someone else who has discovered this "feature" in Windows: 
http://groups.google.com/group/microsoft.public.vc.mfc/browse_thread/thread/5e0d715e5ab27bce/9496df69dd437e58?lnk=st&q=CBN_SELCHANGE+WM_GETTEXT&rnum=2#9496df69dd437e58

And here someone proposes that the OP use it to get the old value, relying on
this "feature":
http://groups.google.com/group/comp.os.ms-windows.programmer.win32/browse_thread/thread/ef6833c8abc67ef3/f9f90a0ce0c67e8a?lnk=st&q=CBN_SELCHANGE+WM_GETTEXT&rnum=1#f9f90a0ce0c67e8a

More:
http://www.powerbasic.com/support/forums/Archives/Archive-000003/HTML/20020808-6-000469.html

/Joakim Asplund

-- 
Configure bugmail: http://bugs.winehq.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the wine-bugs mailing list