Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listbox with [ENTER] and images not working
#4
after looking further at the code the second subclass sub function is not needed as it does the same thing if you eliminate one of the subclass functions and call only one sub function for  both i think everything renders correctly  this renders both list boxes correctly

i think having 2 subfunctions doing the exact same thing was causing the conflict

Function playlist_test2a
Code:
Copy      Help
;g1
;;;below image resolutions: 64x64
str- imgs=
;$desktop$\test_image_0.png
;$desktop$\test_image_1.png
;$desktop$\test_image_2.png


str dd=
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 473 145 ""
;6 ListBox 0x54230151 0x200 3 2 194 131 ""
;8 ListBox 0x54230151 0x200 202 1 239 135 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "6 8"
str lb6 lb8
lb6="list 1[]list 2[]list 3"
lb8="song 1[]song 2[]song 3"
int r=ShowDialog(dd &sub.DlgProc &controls)
if(r=3)
,goto g1
if(!r) ret

#sub DlgProc
function# hDlg message wParam lParam

str- imgs
CB_ItemImageAndColor hDlg message wParam lParam 8 imgs 1|16 64 64 DT_WORDBREAK &sub.ColorCallback
CB_ItemImageAndColor hDlg message wParam lParam 6 0 1 0 0 DT_WORDBREAK &sub.ColorCallback

sel message
,case WM_INITDIALOG
,,;;;Font style for both listboxes
,,__Font-- t_f1.Create("Tahoma" 12 1)
,,t_f1.SetDialogFont(hDlg "6 8")
,,;;;Make sure [ENTER] can be used in listbox
,,SetWindowSubclass(id(6 hDlg) &sub.WndProc_Subclass_lbleft_enter 1 0)
,,SetWindowSubclass(id(8 hDlg) &sub.WndProc_Subclass_lbleft_enter 1 0) ;; <============= activate this and right listbox does not render correctly
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL

,;;;In a later (final) version of this dialog needs to restart and reload the right listbox contents
,;;;It's done when user double clicks (or [ENTER]) on left listbox. I already implented this so any conflicts
,;;;regarding restarting dialog and rendering listboxes could be handled early on.
,case LBN_DBLCLK<<16|6
,,_i=LB_SelectedItem(lParam)
,,DT_Ok hDlg 3
,
ret 1

#sub WndProc_Subclass_lbleft_enter ;;menu File -> New -> Templates -> Wndproc -> WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

sel message
,case WM_GETDLGCODE
,sel(wParam)
,,case [VK_SPACE] ret 0
,,case [VK_RETURN] ret DLGC_WANTALLKEYS ;;please send me WM_KEYDOWN instead of closing the dialog
,
,case WM_KEYDOWN
,sel(wParam) case [VK_RETURN,VK_SPACE] SendMessage GetParent(hwnd) WM_COMMAND LBN_DBLCLK<<16|GetDlgCtrlID(hwnd) hwnd; ret ;;to use the same code as for double-click
,;sel(wParam) case [VK_RETURN,VK_SPACE] SendMessage GetParent(hwnd) WM_COMMAND LBN_SELCHANGE<<16|GetDlgCtrlID(hwnd) hwnd; ret ;;to use the same code as for double-click

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass_lbleft_enter uIdSubclass)

ret R

#sub ColorCallback
function# CBITEMCOLOR&c

;This is a sample callback function that can be used with CB_ItemImageAndColor.
;Shows how to set combo/list box item background and text colors depending on item text.
;The function will be called for each item when displaying it.
;c contains various info that can be useful to draw the item.
;To set colors, change c.bkColor and/or c.textColor.
;Also you can change c.dtFlags and c.text.

;c.text - item text. In/out.
;c.bkColor - item background color. In/out.
;c.textColor - item text color. In/out.
;c.hwnd - control handle.
;c.item - item index.
;c.itemData - item data. To set item data, use message CB_SETITEMDATA or LB_SETITEMDATA, documented in MSDN.
;c.selected - 1 if the item is selected, 0 if not.
;c.isLB - 1 if the control is listbox, 0 if combobox.
;c.dtFlags - DrawText flags. Documented in the MSDN Library on the Internet. In/out.
;c.param - an user-defined value, passed to CB_ItemColor.


if(c.selected)
,c.bkColor=0
,c.textColor=0x00FFFF
,ret

sel c.text 2
,case "*list*" c.bkColor=ColorFromRGB(255 255 0)
,case "*song*" c.bkColor=0; c.textColor=0x00ff00


Messages In This Thread
RE: Listbox with [ENTER] and images not working - by Kevin - 01-01-2019, 09:26 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)