flat assembler
Message board for the users of flat assembler.

Index > Windows > Solution: LISTBOX with LBS_OWNERDRAW and WS_POPUP

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
It is known fact, this combination doesn't work. The owner window never receive WM_MEASUREITEM and WM_DRAWITEM messages. If the listbox have WS_CHILD style set, everything goes OK.
This probably is bug in user32.dll, because other controls (for example LISTVIEW) behave properly.

So, the solution:
Code:
proc CreatePopupListbox, .parent
begin
        invoke  CreateWindowEx, 0,  cListboxClassName,  0,         \
                WS_CHILD or WS_VSCROLL or WS_SIZEBOX or            \
                LBS_NOINTEGRALHEIGHT or LBS_OWNERDRAWFIXED or      \
                LBS_HASSTRINGS,                                    \
                0, 0, 300, 120, [.parent], 0, [hInstance], 0
        mov     ebx, eax

; Strange magic in order to receive owner draw messages from popup listbox
        invoke  SetParent, ebx, 0
        invoke  GetWindowLong, ebx, GWL_STYLE
        and     eax, not WS_CHILD
        or      eax, WS_POPUP
        invoke  SetWindowLong, ebx, GWL_STYLE, eax
        invoke  SetWindowLong, ebx, GWL_HWNDPARENT, [.parent]

        return
endp
    
Post 14 Nov 2010, 20:09
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
JohnFound,
Why to use a WS_POPUP style for any control at all?
Post 15 Nov 2010, 10:02
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
edemko wrote:
JohnFound,
Why to use a WS_POPUP style for any control at all?


Well, there is no difference between controls and non-controls in Windows. If you create the window with WS_CHILD it is "control", if you create it without WS_CHILD it is normal window.
You can use one "control" as a parent for other control.
In the case with the list box, I wanted to use it as a drop down pop up window in Fresh auto complete function, but I wanted the list box to be owner draw, so I faced this problem and also found solution, that can be useful for someone else.
Post 15 Nov 2010, 10:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.