Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "win32api.inc"
Global hDlg, hDlgB, hFont As Dword, iRow, iCol As Long
Enum Equates Singular
IDC_ListView = 500
IDC_ListBox
IDM_One
IDM_Two
IDM_Exit
End Enum
Function PBMain() As Long
Dialog Default Font "Tahoma",10,0
Dialog New Pixels, 0, "ListView Test",300,300,320,200,%WS_SysMenu, 0 To hDlg
CreateListView
CreatePopup
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iReturn As Long, temp$
Select Case Cb.Msg
Case %WM_InitDialog
Case %WM_Command
Select Case Cb.Ctl
Case %IdCancel : HidePopup 'hide Popup when ESC is pressed
End Select
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_ListView
Select Case Cb.NmCode
Case %NM_Click : HidePopup
End Select
End Select
Case %WM_ContextMenu 'detect right mouse click in ListView, then make Popup visible (hide if click outside allowed cells)
iReturn = GetDlgCtrlID (Cb.WParam)
Select Case iReturn
Case %IDC_ListView : ShowPopup
End Select
End Select
End Function
Sub HidePopup
Dialog Hide hDlgB
Control Set Focus hDlg, %IDC_ListView
Control ReDraw hDlg, %IDC_ListView
End Sub
Sub CreateListview
Local i As Long
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,300,180
ListView Insert Column hDlg, %IDC_ListView, 1, "Column1", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "Column2", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 3, "Column3", 100, 0
For i = 1 To 8
ListView Insert Item hDlg, %IDC_ListView, i, 1, Trim$(Str$(i))
ListView Set Text hDlg, %IDC_ListView, i, 2, Trim$(Str$(i+100))
ListView Set Text hDlg, %IDC_ListView, i, 3, Trim$(Str$(i+200))
Next i
End Sub
Sub ShowPopup
Local rc As Rect, i,j As Long, temp$
Local pt As Point, x,y As Long, LVHT As LVHitTestInfo
'get row/col under cursor
GetCursorPos LVHT.pt
ScreenToClient GetDlgItem(hDlg,%IDC_ListView), LVHT.pt
Control Send hDlg, %IDC_ListView, %LVM_SubItemHitTest, 0, VarPtr(LVHT)
iRow = LVHT.iItem
iCol = LVHT.isubItem
'move/resize TextBox over ListView cell
If iCol = 2 Then 'only show popup on selected column (0=first column)
Control Get Loc hDlg, %IDC_ListView To i,j
ListView_GetSubItemRect GetDlgItem(hDlg,%IDC_ListView), iRow,iCol, %LVIR_Label, rc
'show/position popup
Dialog Set Loc hDlgB, i+rc.nLeft+30, j+rc.nBottom
Dialog Show Modeless hDlgB, Call DlgProcB
Control Set Focus hDlgB, %IDC_ListBox
Else
HidePopup
End If
End Sub
Sub CreatePopup
Dialog New Pixels, hDlg, "",0,0,40,65, %WS_Popup To hDlgB
Control Add ListBox, hDlgB, %IDC_ListBox,,0,0,40,65, %LBS_Notify Or %LBS_NoIntegralHeight
Control Set Color hDlgB, %IDC_ListBox, %Black, %rgb_Yellow
ListBox Add hDlgB, %IDC_ListBox, " one"
ListBox Add hDlgB, %IDC_ListBox, " two"
ListBox Add hDlgB, %IDC_ListBox, " three"
ListBox Add hDlgB, %IDC_ListBox, " four"
End Sub
CallBack Function DlgProcB() As Long
Local temp$
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IdCancel : HidePopup 'hide popup when ESC is pressed
Case %IDC_ListBox
Select Case Cb.CtlMsg
Case %LBN_SelChange
ListBox Get Text hDlgB, %IDC_ListBox To temp$
ListView Set Text hDlg, %IDC_ListView, iRow+1, iCol+1, temp$
HidePopup
End Select
Case %IdCancel : HidePopup 'hide popup when ESC is pressed
Case %IdOk 'detect if user presses ENTER
ListBox Get Text hDlg, %IDC_ListBox To temp$
ListView Set Text hDlg, %IDC_ListView, iRow+1, iCol+1, temp$
HidePopup
End Select
End Select
End Function
http://www.garybeene.com/sw/gbsnippets.htm