Dominic Mitchell
you said you have some samples you could post! could you?
thanks
you said you have some samples you could post! could you?
thanks
#COMPILE EXE #DIM ALL '-------------------------------------------------------------------- %UNICODE = 1 #INCLUDE "WIN32API.INC" #INCLUDE "COMMCTRL.INC" '-------------------------------------------------------------------- %IDC_LISTVIEW1 = 181 '==================================================================== FUNCTION PBMAIN () AS LONG LOCAL c, hDlg, dwStyle AS LONG DIALOG NEW 0, "Double line test",,, 150, 130, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg '------------------------------------------------------------------ dwStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %LVS_REPORT OR _ %LVS_OWNERDRAWFIXED OR %LVS_SHOWSELALWAYS CONTROL ADD LISTVIEW, hDlg, %IDC_LISTVIEW1, "", 5, 5, 140, 99, _ dwStyle, %WS_EX_CLIENTEDGE '------------------------------------------------------------------ LISTVIEW INSERT COLUMN hDlg, %IDC_LISTVIEW1, 1, "Item", 30, 1 LISTVIEW INSERT COLUMN hDlg, %IDC_LISTVIEW1, 2, "Text", 96, 2 FOR c = 1 TO 200 LISTVIEW INSERT ITEM hDlg, %IDC_LISTVIEW1, c, 0, FORMAT$(c) LISTVIEW SET TEXT hDlg, %IDC_LISTVIEW1, c, 2, "Yadda Yadda " + FORMAT$(c) + $CR + "Blah Blah Blah Blah" NEXT '------------------------------------------------------------------ IMAGELIST NEW ICON 1, 30, %ILC_COLOR32, 0 TO c ' sets line height (here 30) - experiment.. LISTVIEW SET IMAGELIST hDlg, %IDC_LISTVIEW1, c, %LVSIL_SMALL '------------------------------------------------------------------ CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Quit", 92, 110, 50, 14 '------------------------------------------------------------------ DIALOG SHOW MODAL hDlg, CALL DlgProc END FUNCTION '==================================================================== ' Main Dialog procedure '-------------------------------------------------------------------- CALLBACK FUNCTION DlgProc() AS LONG SELECT CASE CB.MSG CASE %WM_COMMAND SELECT CASE CB.CTL CASE %IDCANCEL IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN DIALOG END CB.HNDL, 0 END IF END SELECT CASE %WM_DRAWITEM IF CB.WPARAM = %IDC_LISTVIEW1 THEN DrawLVitems GetDlgItem(CB.HNDL, CB.WPARAM), CB.LPARAM END IF CASE %WM_NOTIFY IF LO(WORD, CB.WPARAM) = %IDC_LISTVIEW1 THEN LOCAL nmLvPtr AS NM_LISTVIEW PTR nmLvPtr = CB.LPARAM SELECT CASE @nmLvPtr.hdr.code CASE %LVN_ITEMCHANGED 'Selection change IF (@nmLvPtr.uNewState AND %LVIS_SELECTED) = %LVIS_SELECTED THEN ' Frank Rogers solution DIALOG SET TEXT CB.HNDL, "Selected Row" + STR$(@nmLvPtr.iItem+1) END IF CASE %NM_DBLCLK 'Double-click in list IF @nmLvPtr.iItem > -1 THEN DIALOG SET TEXT CB.HNDL, "Double-clicked Row" + STR$(@nmLvPtr.iItem+1) END IF END SELECT END IF END SELECT END FUNCTION '==================================================================== ' %WM_DRAWITEM procedure '-------------------------------------------------------------------- SUB DrawLVitems(hListView AS DWORD, lParam AS LONG) LOCAL cw1, cw2, iBkColor, iTextColor AS LONG LOCAL lpdis AS DRAWITEMSTRUCT PTR, pt AS POINTAPI, rc AS RECT LOCAL zTxt AS WSTRINGZ * 200 lpdis = lParam SELECT CASE @lpdis.itemAction CASE %ODA_DRAWENTIRE, %ODA_SELECT 'CLEAR BACKGROUND, SET SYSTEM BRUSH AND COLORS IF (@lpdis.itemState AND %ODS_SELECTED) THEN FillRect @lpdis.hDC, @lpdis.rcItem, GetSysColorBrush(%COLOR_HIGHLIGHT) iBkColor = SetBkColor(@lpdis.hDC, GetSysColor(%COLOR_HIGHLIGHT)) iTextColor = SetTextColor(@lpdis.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT)) ELSE ' NOT SELECTED FillRect @lpdis.hDC, @lpdis.rcItem, GetSysColorBrush(%COLOR_WINDOW) iBkColor = SetBkColor(@lpdis.hDC, GetSysColor(%COLOR_WINDOW)) iTextColor = SetTextColor(@lpdis.hDC, GetSysColor(%COLOR_WINDOWTEXT)) END IF 'GET COORDINATES - DRAW TEXT ListView_GetItemPosition(hListView, 0, pt) 'get ev. scrollpos cw1 = ListView_GetColumnWidth(hListView, 0) 'width, column 1 cw2 = ListView_GetColumnWidth(hListView, 1) 'width, column 2 rc = @lpdis.rcItem 'whole item rect 'COLUMN 1 centered rc.nLeft = pt.x : rc.nRight = rc.nLeft + cw1 - 5 ListView_GetItemText hListView, @lpdis.itemID, 0, BYVAL VARPTR(zTxt), SIZEOF(zTxt) DrawText @lpdis.hDC, zTxt, LEN(zTxt), rc, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER 'COLUMN 2 left-aligned, set some margins rc.nLeft = rc.nRight + 5 : rc.nRight = rc.nLeft + cw2 - 5 : rc.nTop = rc.nTop + 2 ListView_GetItemText hListView, @lpdis.itemID, 1, BYVAL VARPTR(zTxt), SIZEOF(zTxt) DrawText @lpdis.hDC, zTxt, LEN(zTxt), rc, %DT_WORDBREAK 'DRAW FOCUSRECT (if control has focus) IF GetFocus() = hListView AND (@lpdis.itemState AND %ODS_SELECTED) THEN SetBkColor(@lpdis.hDC, iBkColor) SetTextColor(@lpdis.hDC, iTextColor) DrawFocusRect(@lpdis.hDC, @lpdis.rcItem) END IF END SELECT END SUB '
' LOG FILE READER - EVENT SELECTION ' listview sample using underscore highlight for current row, modeless popup details window on click ' help from Michael Mitchell, Dominic Mitchell,Peter Lameijn, Erik Christensen and countless others ' data by Donald Darden & Geoffrey Chaucer ' mixed and compiled by Chris Holbrook 10 Mar 2006. Use at your own risk but take my name off first! ' #compile exe #dim all #option ansiapi #include "commctrl.inc" #include "win32api.inc" %idc_arc_lv = 1000 %IDD_help_dialog = 123 %IDC_help_tb = 1241 %IDC_help_lb = 1242 %IDC_exit_bn = 1243 'declare function Showarc_dd(byval hParent as dword) as long 'declare function Showhelp_dialog(byval hParent as dword) as long global garcpath, gevent, ghelptext as string global ghelpx, ghelpy, ghelpdialog as long function pbmain () as long dim gqarcarray(100,2) as global string ghelpdialog = -1 showarc_dd(0) end function function arcLViewCustomDraw ( byval ptlvcd as NMLVCUSTOMDRAW ptr ) as long local szItem as asciiz * %max_path ' item text local trcItem as RECT ' bounding rectangle of item/subitem local tlv_item as LV_ITEMA ' listview item information local tlb as LOGBRUSH ' specifies information used to create background brush local hWndHdr as dword ' handle of header child control local hBrush as dword local hBrushOld as dword local hPenOld as dword local dwBackColor as dword local nBkModeOld as integer ' Get the item or subitem info tlv_item.mask = %LVIF_TEXT or %LVIF_IMAGE or %LVIF_STATE tlv_item.stateMask = %LVIS_FOCUSED or %LVIS_SELECTED tlv_item.iItem = @ptlvcd.nmcd.dwItemSpec tlv_item.iSubItem = @ptlvcd.iSubItem tlv_item.pszText = varptr(szItem) tlv_item.cchTextMax = %max_path SendMessage @ptlvcd.nmcd.hdr.hwndFrom, %lvm_getitem, 0, byval varptr(tlv_item) ' Get the bounding rectangle of the subitem(cell) trcItem.nLeft = %LVIR_BOUNDS trcItem.nTop = @ptlvcd.iSubItem SendMessage @ptlvcd.nmcd.hdr.hwndFrom, %lvm_getsubitemrect, @ptlvcd.nmcd.dwItemSpec, byval varptr(trcItem) ' set background colour if @ptlvcd.nmcd.dwItemSpec mod 2 = 0 then dwBackColor = rgb(200,255,255) ' green background else dwBackColor = %white ' white background end if tlb.lbStyle = %BS_SOLID tlb.lbColor = dwBackColor tlb.lbHatch = 0 hBrush = CreateBrushIndirect(tlb) FillRect @ptlvcd.nmcd.hdc, trcItem, hBrush DeleteObject hBrush ' Draw the text nBkModeOld = SetBkMode(@ptlvcd.nmcd.hdc, %TRANSPARENT) DrawTextEx @ptlvcd.nmcd.hdc, szItem, len(szItem), trcItem, %DT_SINGLELINE or %DT_LEFT or %DT_VCENTER or %DT_END_ELLIPSIS, byval %NULL SetBkMode @ptlvcd.nmcd.hdc, nBkModeOld ' Draw focus rectangle ' Note: it is drawn when the last column is painted. if (tlv_item.STATE and %LVIS_FOCUSED) = %LVIS_FOCUSED then hWndHdr = SendMessage(@ptlvcd.nmcd.hdr.hwndFrom, %lvm_getheader, 0, 0) if @ptlvcd.iSubItem = SendMessage(hWndHdr, %hdm_getitemcount, 0, 0) - 1 then ' Get the bounding rectangle of the entire item(this includes all subitems) trcItem.nLeft = %LVIR_BOUNDS SendMessage @ptlvcd.nmcd.hdr.hwndFrom, %lvm_getitemrect, @ptlvcd.nmcd.dwItemSpec, byval varptr(trcItem) ' purple pen 4 pixels thick hPenOld = SelectObject(@ptlvcd.nmcd.hdc, CreatePen(%PS_SOLID, 4 * GetSystemMetrics(%SM_CXBORDER), &H8c08c08c0???)) ' A hollow brush is used to avoid erasing what was painted already hBrushOld = SelectObject(@ptlvcd.nmcd.hdc, GetStockObject(%NULL_BRUSH)) ' modifed rectanlge to give an underscore rectangle @ptlvcd.nmcd.hdc, trcItem.nLeft, trcItem.nbottom-1, trcItem.nRight, trcItem.nBottom SelectObject @ptlvcd.nmcd.hdc, hBrushOld DeleteObject SelectObject(@ptlvcd.nmcd.hdc, hPenOld) end if end if function = %CDRF_SKIPDEFAULT end function ' ------------------------------------------------ function show_arc_lv(byval hDlg as dword, byval lID as long) as long local hfile as long, lcol as long, lRow as long, lrowcount as long, nwords as long local hCtl as dword local tLVC as LV_COLUMNA local tLVI as LV_ITEMA local szBuf as asciiz * 32 local i as long, j as long, k as long, lStyle as long, q as long, r as long, x as long local s as string, rowtype as string, sword as string function = %false '------------------------------------- initialise listview control handle hDlg, lID to hCtl 'lStyle = ListView_GetExtendedListViewStyle(hCtl) lStyle = lStyle or %lvs_ex_gridlines or %lvs_ex_fullrowselect or %lvs_ex_underlinehot or %lvs_ex_oneclickactivate 'OR %LVS_EX_FULLROWSELECT call SendMessage(hCTL, %lvm_setextendedlistviewstyle, 0, byval lStyle) control send hDLG, %IDC_arc_lv, %lvm_deleteallitems ,0,0 control send hDLG, %IDC_arc_lv, %lvm_setitemcount, 100 ,%LVSICF_NOINVALIDATEALL or %LVSICF_NOSCROLL ' -------------------------------------Load column headers. tLVC.mask = %LVCF_FMT or %LVCF_TEXT or %LVCF_SUBITEM tLVC.pszText = varptr(szBuf) szbuf = "timestamp" : tLVC.iOrder = 0 SendMessage(hCtl, %lvm_insertcolumnA, 1, varptr(tLVC)) szbuf = "event" : tLVC.iOrder = 1 SendMessage(hCtl, %lvm_insertcolumnA, 1, varptr(tLVC)) SendMessage(hCtl, %lvm_setcolumnwidth, 0, maklng(100, 0)) ' timestamp SendMessage(hCtl, %lvm_setcolumnwidth, 1, maklng(750, 0)) ' event '--------------------------------------- populate the listview's data source redim gqarcArray(100, 2) '------------------------------------- populate the listview's data source data "Whan","that","Aprill,","with","his","shoures","soote" data "The","droghte","of","March","hath","perced","to","the" data "And","bathed","every","veyne","in","swich","licour," data "Of","which","vertu","engendred","is","the","flour" data "Whan","Zephirus","eek","with","his","sweete","breeth" data "Inspired","hath","in","every","holt","and","heeth" data "The","tendre","croppes,","and","the","yonge","sonne" data "Hath","in","the","Ram","his","halfe","cours","yronne" data "With","so","many","different","methods","and","ways","to","alter" data "the","order","that","the","deck","will","be","dealt","out","in," data "what","are","the","real","prospects","of","detecting","the","work" data "of","a","pseudo","random","number","generator","process","being" data "employed","in","the","background?","I'd","think","extremely","unlikely" data "unless","they","are","using","the","most","predictable,","barebones," data "and","straightforward","shuffling","and","dealing","methods","possible." data "Even","then,","can","you","really","tell","what","possible","PRNG" data "sequence","you","are","on","just","by","observing","a","2d","5h","8h" data "Js","Ac","being","dealt","to","the","table","top?","Like","I","said," data "unless","you","guessed","a","lot","of","things","right,","or","had" data "insider","information,","you","are","not","likely","to","nail","the" data "sequence","down" for k = 1 to 100 'create a record of a random no of lines of text r = rnd(1,24) s = "" for q = 1 to r ' create a line of random text nwords = rnd(1,20) for i = 1 to nwords j = rnd(1,120) sword = read$(j) s = s + " " + sword next s = s + $crlf next gqarcarray(k-1,2) = s gqarcarray(k-1, 1) = string$(12, "A") next '------------------------------------- force redraw redrawwindow hCtl, byval 0, byval 0, %RDW_ERASE or %RDW_INVALIDATE or %RDW_ALLCHILDREN function = %true end function '------------------------------------------------------------------------------ callback function Showarc_ddProc() static myrect as rect, rowrect as RECT static hLV as long, lstyle as long local pnmh as nmhdr ptr local pnm as NMLVCUSTOMDRAW ptr local lpLVDispInfo as LV_DISPINFOA ptr local lpia as NMITEMACTIVATE ptr local hparent as long ' asciiz buffer for populating listview local szString as asciiz * 256 select case as long cbmsg case %wm_initdialog ' Initialization handler InitCommoncontrols show_arc_lv cbhndl, %IDC_arc_lv case %wm_ncactivate static hWndSaveFocus as dword if isfalse cbwparam then ' Save control focus hWndSaveFocus = GetFocus() elseif hWndSaveFocus then ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 end if case %wm_notify pnmh = cblparam select case as long @pnmh.code case %nm_customdraw ' specify font and color. pnm = cblparam select case as long @pnm.nmcd.dwDrawStage case %CDDS_PREPAINT SetWindowLong cbhndl,%DWL_MSGRESULT,%CDRF_NOTIFYITEMDRAW function = 1 exit function case %CDDS_ITEMPREPAINT SetWindowLong cbhndl,%DWL_MSGRESULT,%CDRF_NOTIFYSUBITEMDRAW function = 1: exit function case %CDDS_SUBITEM or %CDDS_ITEMPREPAINT if @pnmh.idFrom = %IDC_arc_lv then function = arcLViewCustomDraw(byval pnm) exit function end if SetWindowLong cbhndl,%DWL_MSGRESULT,(%CDRF_NEWFONT or %CDRF_NOTIFYSUBITEMDRAW) end select ' case %lvn_getdispinfo 'Virtual ListView ask for Item text lpLVDispInfo = cblparam if (@lpLVDispInfo.item.mask and %LVIF_TEXT) then ' Specify text to be used if @pnmh.idFrom = %IDC_arc_lv then szString = gqarcarray( @lpLVDispInfo.item.iItem + 1, @lpLVDispInfo.item.iSubItem + 1) end if @lpLVDispInfo.item.pszText = varptr(szString) end if case %nm_click ' SINGLE CLICK if ghelpdialog <> -1 then dialog send ghelpdialog, %WM_SYSCOMMAND, %sc_close, 0 ghelpdialog = -1 end if lpia = cblparam gevent = gqarcarray( @lpia.iItem + 1, 2) showhelp_dialog(cbhndl) end select case %wm_command ' Process control notifications select case as long cbctl case %IDC_arc_lv function = 1 exit function end select end select end function '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ function Showarc_dd(byval hParent as dword) as long local lRslt as long local hfont1 as dword local hDlg as dword dialog new hParent, "Log file reader: Event Selection", 70, 70, 538, 286, _ %ws_popup or %ws_border or %ws_dlgframe or %ws_sysmenu or _ %ws_clipsiblings or %ws_visible or %ds_modalframe or %ds_3dlook or _ %ds_nofailcreate or %ds_setfont, %ws_ex_controlparent or %ws_ex_left _ or %ws_ex_ltrreading or %ws_ex_rightscrollbar to hDlg ' control add "SysListView32", hDlg, %IDC_arc_lv, "", 5, 5, 530, 275, _ %ws_child or %ws_visible or %ws_tabstop or %lvs_report or _ %lvs_showselalways or %lvs_ownerdata or %ws_ex_left or %ws_ex_rightscrollbar dialog show modal hDlg, call Showarc_ddProc to lRslt function = lRslt end function '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ callback function Showhelp_dialogProc() static hparent as dword static htext as string local l as long dim r as RECT dim szText as asciiz * 2048 local hfont as long, hfont2 as long, x as long, y as long local hDC as dword local ps as paintstruct select case as long cbmsg case %wm_initdialog ' Initialization handler dialog set loc cbhndl, ghelpx, ghelpy hParent = GetParent(cbhndl) ghelpdialog = cbhndl htext = gevent getclientrect cbhndl, r szText = htext hDC = GetDC( cbhndl) hfont = SendMessage(cbhndl, %WM_GETFONT, 0, 0) hfont2 = SelectObject(hDC, hfont) '-----------------fix text width r.nright = 250 '---------------- calculate pixel depth of wrapped text DrawText hDC, szText, len(szText), r, %DT_WORDBREAK or %DT_CALCRECT or %DT_LEFT '---------------- convert to dialog units dialog pixels cbhndl, r.nright, r.nbottom to units x, y '---------------- allow for border width, exit button, and scale depth dialog set size cbhndl, x+3,22 + y' (y*.66) '---------------- set dialog dimensions.... control set size cbhndl, %idc_help_lb, x,5 + y'*.66 '---------------- ...and insert text which should wrap to predicted dimensions control set text cbhndl, %idc_help_lb, htext SelectObject ps.hdc, hfont2 releaseDC cbhndl, hDC case %wm_ncactivate static hWndSaveFocus as dword if isfalse cbwparam then ' Save control focus hWndSaveFocus = GetFocus() elseif hWndSaveFocus then ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 end if case %wm_lbuttondown SendMessage cbhndl, %wm_nclbuttondown, %HTCAPTION, byval %NULL ' force drag dialog get loc cbhndl to ghelpx, ghelpy ' CASE %WM_COMMAND ' ' Process control notifications ' SELECT CASE AS LONG CBCTL ' CASE %idc_exit_bn ' 'CONTROL SEND hparent, %IDC_stm_graphic1, %WM_user+1, 0, 0 ' DIALOG END CBHNDL,0 ' END SELECT end select end function '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ function Showhelp_dialog(byval hParent as dword) as long local lRslt as long local hDlg as dword dialog new hParent, "", 176, 133, 190, 29, %ws_popup or %ws_thickframe or _ %ws_clipsiblings or %ws_visible or %ds_3dlook or %ds_nofailcreate or _ %ds_setfont, %ws_ex_controlparent or %ws_ex_toolwindow or _ %ws_ex_topmost or %ws_ex_left or %ws_ex_ltrreading or _ %ws_ex_rightscrollbar, to hDlg dialog set color hDlg, -1, rgb(255, 255, 155) control add label, hDlg, %IDC_help_lb, "", 0, 5, 120, 13, %ws_child or _ %ws_visible or %ss_left, %ws_ex_transparent or %ws_ex_left or _ %ws_ex_ltrreading control set color hDlg, %IDC_help_lb, -1, -2 'CONTROL ADD BUTTON, hDlg, %IDC_exit_bn, "X close", 0, 0, 35, 10 control send hDlg, %IDC_help_lb, %EM_SETLIMITTEXT,2048,0 dialog show modeless hDlg, call Showhelp_dialogProc to lRslt function = lRslt end function
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment