News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Listbox

Started by FlySky, December 22, 2007, 03:42:33 PM

Previous topic - Next topic

FlySky

Hey there guys,

I have this code, which is mainly based on a listbox example I found on the website: http://webster.cs.ucr.edu/

The code looks like this:

;#####################################################
WinMain2 proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

        ;====================
        ; Put LOCALs on stack
        ;====================

        LOCAL msg  :MSG
        LOCAL Wwd  :DWORD
        LOCAL Wht  :DWORD
        LOCAL Wtx  :DWORD
        LOCAL Wty  :DWORD
;LOCAL hWnd :DWORD
        mov Wwd, 670 ;Width
        mov Wht, 450 ;Height

        invoke GetSystemMetrics,SM_CXSCREEN
        invoke TopXY,Wwd,eax
        mov Wtx, eax

        invoke GetSystemMetrics,SM_CYSCREEN
        invoke TopXY,Wht,eax
        mov Wty, eax

        szText szClassName,"LISTBOX"

        invoke CreateWindowEx,WS_EX_PALETTEWINDOW or WS_EX_CLIENTEDGE,
                              ADDR szClassName,
                              ADDR szDisplayName,
                              WS_OVERLAPPEDWINDOW or WS_VSCROLL or \
                              LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or \
                              LBS_DISABLENOSCROLL, \
                              Wtx,Wty,Wwd,Wht,
                              NULL,NULL,
                              hInst,NULL
        mov   hWnd2,eax

        invoke SetWindowLong,hWnd2,GWL_WNDPROC,ADDR WndProc2
        mov lpfnWndProc, eax

        invoke GetStockObject,OEM_FIXED_FONT;åñëè íàäî âèíîâûé øðèôò òàê è ïèøèòå ANSI_FIXED_FONT
        invoke SendMessage,hWnd2,WM_SETFONT,eax,0

        jmp @123
 
       
        include ascii.inc
       
        @123:

        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item1
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item2
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item3
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item4
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item5
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item6
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item7
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item8
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item9
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item10
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item11
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item12
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item13
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item14
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item15
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item16
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item17
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item18
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item19
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item20
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item21
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item22
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item23
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item24
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item25
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item26
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item27
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item28
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item29
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item30
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item31
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item32
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item33
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item34
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item35
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item36
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item37
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item38
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item39
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item40
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item41
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item42
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item43
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item44
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item45
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item46
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item47
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item48
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item49
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item50
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item51
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item52
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item53
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item54
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item55
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item56
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item57
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item58
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item59
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item60
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item61
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item62
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item63
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item64
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item65
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item66
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item67
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item68
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item69
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item70
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item71
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item72
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item73
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item74
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item75
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item76
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item77
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item78
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item79
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item80
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item81
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item82
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item83
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item84
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item85
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item86
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item87
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item88
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item89
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item90
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item91
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item92
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item93
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item94
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item95
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item96
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item97
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item98
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item99
        ;invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item100
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item101
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item102
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item103
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item104
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item105
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item106
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item107
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item108
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item109
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item110
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item111
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item112
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item113
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item114
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item115
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item116
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item117
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item118
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item119
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item120
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item121
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item122
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item123
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item124
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item125
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item126
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item127
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item128
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item129
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item130
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item131
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item132
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item133
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item134
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item135
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item136
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item137
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item138
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item139
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item140
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item141
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item142
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item143
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item144
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item145
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item146
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item147
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item148
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item149
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item150
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item151
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item152
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item153
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item154
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item155
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item156
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item157
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item158
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item159
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item160
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item161
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item162
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item163
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item164
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item165
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item166
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item167
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item168
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item169
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item170
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item171
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item172
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item173
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item174
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item175
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item176
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item177
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item178
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item179
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item180
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item181
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item182
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item183
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item184
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item185
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item186
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item187
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item188
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item189
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item190
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item191
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item192
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item193
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item194
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item195
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item196
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item197
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item198
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item199
        ;invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item200
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item201
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item202
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item203
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item204
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item205
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item206
        invoke SendMessage,hWnd2,LB_ADDSTRING,0,ADDR item207
       

        invoke ShowWindow,hWnd2,SW_SHOWNORMAL
        invoke UpdateWindow,hWnd2

      ;===================================
      ; Loop until PostQuitMessage is sent
      ;===================================

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain2 endp

; #########################################################################

WndProc2 proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    .if uMsg == WM_CLOSE

    .elseif uMsg == WM_DESTROY
        ;invoke PostQuitMessage,NULL
        ;return 0
        invoke EndDialog,hWin,0
        xor eax,eax
        ret
    .endif

    invoke CallWindowProc,lpfnWndProc,hWin,uMsg,wParam,lParam

    ret

WndProc2 endp

; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen dimension

    return sDim

TopXY endp

; ########################################################################

I am having a very hard time changing the color of the background from the listbox.

I know WM_CTLCOLORLISTBOX can deal with the color of the listbox,

But it just doesn't want to turn black if I use this:

.elseif uMsg == WM_CTLCOLORLISTBOX
invoke GetStockObject, BLACK_BRUSH

The background stays white. Anyone can help me out?

Thanks FlySky

MichaelW

You code is incomplete, but it looks like you are trying to use a subclassed list box as an application window. While there might be some hack that will allow you to make this work, it's not anything resembling the normal methods of creating application windows and using controls. The WM_CTLCOLORLISTBOX message is sent to the parent window of the list box control, so there is no need to subclass the control. You process the message in the window procedure of the parent, returning a brush that the control will use to paint the background. Depending on how you want the control to appear and/or your choice of background color, you may need to also specify the text foreground and background colors. Here is a simple example based on an in-memory dialog.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      hInst dd 0
      hList dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
DlgProc proc hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL rc:RECT

    Switch uMsg

      Case WM_INITDIALOG

        invoke GetDlgItem, hDlg, 100
        mov hList, eax
        invoke GetClientRect, hDlg, ADDR rc
        invoke MoveWindow, hList, 0, 0, rc.right, rc.bottom, TRUE

        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string0")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string1")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string2")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string3")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string4")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string5")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string6")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string7")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string8")
        invoke SendMessage, hList, LB_ADDSTRING, 0, chr$("string9")

        return TRUE

      Case WM_CTLCOLORLISTBOX

        invoke SetBkColor, wParam, 0
        invoke SetTextColor, wParam, 0ffffffh
        invoke GetStockObject, BLACK_BRUSH
        return eax

      Case WM_COMMAND

        Switch wParam

          Case IDCANCEL

            invoke EndDialog, hDlg, NULL

        EndSw

      Case WM_CLOSE

        invoke EndDialog, hDlg, NULL

    EndSw

    return 0

DlgProc endp
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    invoke GetModuleHandle, NULL
    mov hInst, eax

    Dialog  "Test", \                         ; caption
            "FixedSys", 12, \                 ; font,pointsize
            WS_OVERLAPPED or WS_SYSMENU or \  ; window style
            WS_MINIMIZEBOX or DS_CENTER, \
            1, \                              ; number of controls
            0,0,120,90, \                     ; x, y, width, height
            1024                              ; memory buffer size

    DlgList WS_VSCROLL or LBS_NOINTEGRALHEIGHT, 0, 0, 0, 0, 100

    CallModalDialog hInst, 0, DlgProc, NULL

    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

FlySky

Thanks a lot for the reply man it made some stuff clear for sure :U. I am gonna play around a bit. But I can create a listbox control also when using the CreateWindowEx API?, yes I know the reference is also used when creating dialogboxes;). I will practice on creating a listbox using a Dialogbox, thanks for the help man.

MichaelW

QuoteBut I can create a listbox control also when using the CreateWindowEx API?
Yes, you can, and that is essentially how the system creates the window for the dialog box, and the windows for the controls in the dialog. I used an in-memory dialog because I had a list box example, and I was trying to provide a complete, working source that demonstrated how to handle the WM_CTLCOLORLISTBOX message.
eschew obfuscation

Larry Hammick

In the handler for WM_INITDIALOG (for a dialog box) or WM_CREATE (for a list box control created with CreateWindowEx) you might also want to include
invoke SetBkMode, wParam, TRANSPARENT
to keep the background uniform in color if you add strings at run time.
But the key move is to exit the handler while the brush is still in eax. Googling on "WM_CTLCOLORLISTBOX" shows that a number of other people have had this problem.

MichaelW

I can't find any circumstances where setting the background mix mode to TRANSPARENT makes any visible difference. The WM_CTLCOLORLISTBOX message gets sent each time a new string is added to the visible part of the list, and each time a string is brought into view.
eschew obfuscation

Larry Hammick

Quote from: MichaelW on December 23, 2007, 05:14:35 AM
I can't find any circumstances where setting the background mix mode to TRANSPARENT makes any visible difference. The WM_CTLCOLORLISTBOX message gets sent each time a new string is added to the visible part of the list, and each time a string is brought into view.
Are you sure? I don't the API very well but I knocked up the attached demo. Click "test" on the menu, and a string is added to the list box. Now if you disbable the line about transparency, and reassemble, it behaves differently.




[attachment deleted by admin]

MichaelW

#7
QuoteIn the handler for WM_INITDIALOG (for a dialog box) or WM_CREATE (for a list box control created with CreateWindowEx) you might also want to include
invoke SetBkMode, wParam, TRANSPARENT

to keep the background uniform in color if you add strings at run time.

I interpreted this to mean using SetBkMode...TRANSPARENT in addition to SetBkColor, and when used in this way it made no visible difference in any of my tests. Your code is using SetBkMode...TRANSPARENT instead of SetBkColor. I decided to use SetBkColor instead of SetBkMode...TRANSPARENT because I have seen problems with it in edit controls when the user scrolled the text horizontally (which could be corrected by forcing an update on EN_CHANGE, but it's much easier to just use SetBkColor). Now that I test, SetBkMode...TRANSPARENT used alone in a list box seems to produce the same visual result as SetBkColor used alone.
eschew obfuscation