Code:
#Compile Exe #Register None #Dim All #Include "win32api.inc" %LBText = 100 %LISTBOX = 101 '-------------------------------------------------- Declare CallBack Function Form_DlgProc Function PbMain Local hDlg&,Style&,ExStyle&,Lst$(),i& Style& = %WS_POPUP OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR _ %DS_SYSMODAL OR %DS_CENTER ExStyle& = 0 Dialog New %HWND_DESKTOP,"Context-Menu in Listbox", 0, 0,267,177, _ Style&, ExStyle& TO hDlg& Control Add Label,hDlg&,%LBText,"", 3, 5,259, 12, _ %WS_CHILD OR %WS_VISIBLE OR %SS_LEFT OR %WS_DLGFRAME ReDim LST$(0:99) For i& = 0 to 99 lst$(i&)="**This is listindex " & Str$(i&) & " ---------" Next i& Control Add ListBox,hDlg&,%LISTBOX,lst(), 3, 20,259,153, _ %WS_CHILD OR %WS_VISIBLE OR %LBS_NOTIFY OR %WS_VSCROLL OR %WS_BORDER OR %WS_TABSTOP Dialog Show Modal hDlg&, Call Form_DlgProc End Function CallBack Function Form_DlgProc Local CurSel&,CurItem&,x&,y&,hPopUp&,Id& Local R As RECT Local pt AS POINTAPI Local TopItem&,ItemHight&,Tmp$ Select Case CBMsg Case %WM_TIMER Case %WM_SIZE Case %WM_CLOSE Case %WM_CONTEXTMENU Select Case GetDlgCtrlID(CBwParam ) Case %Listbox '--Execute only if in listbox---------------------------------------- CurSel& = SendMessage(CBwParam,%LB_GETCURSEL,0,0) x& = LoWrd(CBlParam ) : y& = HiWrd(CBlParam ) If (x&=65535) Or (y&=65535) Then '--Keyboard Shift F10 is used to trigger WM_CONTEXTMENU-------------- If CurSel& < 0 Then Exit Function TopItem& = SendMessage(CBwParam,%LB_GETTOPINDEX, 0, 0) ItemHight& = SendMessage(CBwParam,%LB_GETITEMHEIGHT,0,0) GetClientRect CBwParam,ByVal VarPtr(R) pt.x = (R.nRight-R.nLeft)/4 pt.y = ItemHight&*(CurSel&-TopItem&)+ItemHight& ClientToScreen CBwParam,pt x&=pt.x:y&=pt.y Else '--Mouse Right button is used to trigger WM_CONTEXTMENU-------------- pt.x = x& : pt.y = y& ScreenToClient CBwParam,pt CurItem& = LoWrd(SendMessage(CBwParam,%LB_ITEMFROMPOINT,0,MakLng(pt.x,pt.y))) If CurItem& <> CurSel& Then _ SendMessage CBwParam,%LB_SETCURSEL,CurItem&,0:CurSel& = CurItem& End If '--Build & Show the PopUp-menu--------------------------------------- Menu New Popup To hPopup& Menu Add String, hPopup&, "Show Listindex",900, %MF_ENABLED Menu Add String, hPopup&, "Show List-Text",901, %MF_ENABLED Menu Add String, hPopup&, "Delete this Line", 902, %MF_ENABLED Menu Add String, hPopup&, "Add a line here", 903, %MF_ENABLED Menu Add String, hPopup&, "Add a line at end", 904, %MF_ENABLED Id& =TrackPopupMenu(hPopup&, _ %TPM_LEFTALIGN Or %TPM_RIGHTBUTTON Or %TPM_RETURNCMD, _ x&, y&, 0,CBwParam, ByVal 0) '--Execute menu-command---------------------------------------------- Select Case Id& Case 900 Control Set Text CBHndl,%lbText,"Selected Listitem is no " & Format$(CurSel&) Case 901 ListBox Get Text CBHndl,%Listbox To Tmp$ Control Set Text CBHndl,%lbText,"Selected text is " & UCase$(Tmp$) Case 902 ListBox Delete CBHndl,%ListBox,CurSel& + 1 Control Set Text CBHndl,%lbText,"Line " & Format$(CurSel&) & " is deleted" Case 903 Control Set Text CBHndl,%lbText,"No code to execute" Case 904 CurItem& = SendMessage(CBwParam,%LB_GETCOUNT,0,0) Tmp$="**This is listindex " & Str$(CurItem&) & " ---------" Control Set Text CBHndl,%lbText,"This line hopefully added at end " & UCase$(Tmp$) ListBox Add CBHndl,%ListBox,Tmp$ Case Else Control Set Text CBHndl,%lbText,"No selection" End Select End Select End Select End Function
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment: