Contextmenü für B3D
Übersicht

![]() |
EPSBetreff: Contextmenü für B3D |
![]() Antworten mit Zitat ![]() |
---|---|---|
Die decls befindet sich am Ende des Quellcodes.
Damit das Beispiel funktioniert wird eine "on.bmp", "off.bmp", "on.ico" und "off.ico" Datei im gleichen Verzeichnis erwartet. Diese Grafiken (Icons) sollten 13 x 13 Pixel groß sein. Have Fun. Code: [AUSKLAPPEN] ;==============================================================================================================
; PopUp Menu for B3D by East-Power-Soft ; ; Needs windows API user32 functions. DECLS on the bottom. ;============================================================================================================== Const IMAGE_BITMAP = $0 Const IMAGE_ICON = $1 Const LR_LOADFROMFILE = $10 Const MF_BITMAP = $4 Const MF_STRING = $0 Const MF_ENABLED = $0 Const MF_GRAYED = $1 Const MF_CHECKED = $8 Const MF_UNCHECKED = $0 Const MF_POPUP = $10 Const MF_SEPERATOR = $800 Const TPM_RETURNCMD = $100 ;-------------------------------------------------------------------------------------------------------------- ; SAMPLE, press F5 and hit the right mouse button. ;-------------------------------------------------------------------------------------------------------------- PopUp = CM_Create() ;--> create the PopUp Root CM_Item_Add( PopUp, "Entry 1", 1 ) ;--> create a view entrys CM_Item_Add( PopUp, "Entry 2", 2 ) CM_Item_Add( PopUp, "Entry 3", 3 ) CM_Item_Add( PopUp, "Entry 4", 4 ) CM_Item_Add( PopUp, "Entry 5", 5 ) CM_Item_Add( PopUp, "-" ) ;--> create a seperator CM_Item_Add( PopUp, "Entry 6", 6 ) Sub01 = CM_Create() ;--> create submenu CM_Item_Add( PopUp, "Submenu", Sub01 ) ;--> submenu goes from this item CM_Item_Add( Sub01, "Entry 7", 7 ) ;--> add entrys to submenu CM_Item_Add( Sub01, "Entry 8", 8 ) CM_Item_Insert( Sub01, 8, "before Entry 8", 9 ) ;--> insert items is also possible CM_Item_Modify( Sub01, 5, "New Entry 5" ) ;--> Modify item text CM_Item_Delete( PopUp, 2 ) ;--> Delete a item CM_Item_Disable( PopUp, 1 ) ;--> Items can be enabled or disbled CM_Item_Checked( PopUp, 3 ) ;--> Items can be checked or unchecked CM_Item_SetIcon( PopUp, 5, "off.bmp" ) ;--> Add ONE icon to item CM_Item_SetIcon( PopUp, 4, "off.bmp", "on.bmp" ) ;--> Add TWO icons ( bitmaps ) to item CM_Item_Checked( PopUp, 4 ) ;--> Items can be enabled or disbled CM_Item_SetIcon( PopUp, 6, "off.ico", "on.ico" ) ;--> Add TWO icons ( real icons ) to item Repeat ;--> open menu if "right mouse" or "contextmenu key" hit If MouseHit(2) Or KeyHit(221) Then CM_Result = CM_Open( PopUp ) Until KeyHit(1) ;--> Kill the Menu cm_Delete( PopUp ) End Function CM_Create() ;============================================================================================================== ; Create PopUp or SubMenu. Gives back a handle to add or insert items. ;============================================================================================================== Return cm_CreatePopupMenu() End Function Function CM_Open( hMenu, x=-1, y=-1 ) ;============================================================================================================== ; Opens the PopUp menu on the given X, Y position and tracks the user input. Gives back the choosen itemhandle ; or 0 if the user cancel the menu. ; ; If x and y is specified, the menu opens on this position relative to the inside of the application window. ; Without x any y the function opens the menu on the actual mouse position on the screen. ;============================================================================================================== Local hWnd = cm_GetActiveWindow() ;--> get app window handle Local hrec = CreateBank( 16 ) ;--> rect structure Local hpnt = CreateBank( 8 ) ;--> pointer structure ;--> use user position? If x <> -1 And y <> -1 Then cm_GetWindowRect( hWnd, hrec ) hMsx = PeekInt( hrec, 0 ) + cm_GetSystemMetrics(7) + x hMsy = PeekInt( hrec, 4 ) + cm_GetSystemMetrics(8) + cm_GetSystemMetrics(4) + y Else cm_GetCursorPos( hpnt ) hMsx = PeekInt( hpnt, 0 ) hMsy = PeekInt( hpnt, 4 ) End If FreeBank hrec FreeBank hpnt Return cm_TrackPopupMenu( hMenu, TPM_RETURNCMD, hMsx, hMsy, 0, hWnd, CreateBank(0) ) End Function Function CM_Delete( hMenu ) ;============================================================================================================== ; Deletes the whole menu. ;============================================================================================================== cm_DestroyMenu( hMenu ) End Function Function CM_Item_Add( hMenu, Item$="", hItem=0 ) ;============================================================================================================== ; Adds Item$ to the given hMenu. If Item$="-" a seperator will created, except if the Item opens a submenu. ; hItem is a specific handle (int) or you give a submenu handle. Then Item$ will open the given submenu. ;============================================================================================================== ;--> empty strings not allowed If Item$ = "" Then Item$ = " " ;--> create seperator or Item? If Item$ = "-" Then cm_AppendMenu( hMenu, MF_SEPERATOR, 0, CreateBank(0) ) Else ;--> if hItem is a menu handle, then hItem opens a submenu If cm_IsMenu( hItem ) Then cm_AppendMenu( hMenu, MF_STRING Or MF_POPUP, hItem, CM_StringToBank( Item$ ) ) Else cm_AppendMenu( hMenu, MF_STRING, hItem, CM_StringToBank( Item$ ) ) End If End If End Function Function CM_Item_Insert( hMenu, hPos, Item$="", hItem=0 ) ;============================================================================================================== ; Inserts Item$ into the given hMenu. If Item$="-" a seperator will created, except if the Item opens a submenu ; hItem is a specific handle (int) or you give a submenu handle. Then Item$ will open the given submenu. ;============================================================================================================== ;--> empty strings not allowed If Item$ = "" Then Item$ = " " ;--> create seperator or Item? If Item$ = "-" Then cm_InsertMenu( hMenu, hPos, MF_SEPERATOR, 0, CreateBank(0) ) Else ;--> if hItem is a menu handle, then hItem opens a submenu If cm_IsMenu( hItem ) Then cm_InsertMenu( hMenu, hPos, MF_STRING Or MF_POPUP, hItem, CM_StringToBank( Item$ ) ) Else cm_InsertMenu( hMenu, hPos, MF_STRING, hItem, CM_StringToBank( Item$ ) ) End If End If End Function Function CM_Item_Modify( hMenu, hItem, Item$="" ) ;============================================================================================================== ; Modify item text. ;============================================================================================================== ;--> empty strings not allowed If Item$ = "" Then Item$ = " " cm_ModifyMenu( hMenu, hItem, MF_STRING, hItem, CM_StringToBank( Item$ ) ) End Function Function CM_Item_Delete( hMenu, hItem ) ;============================================================================================================== ; Deletes a item. ;============================================================================================================== cm_DeleteMenu( hMenu, hItem, 0 ) End Function Function CM_Item_Enable( hMenu, hItem ) ;============================================================================================================== ; Enables a item. ;============================================================================================================== cm_EnableMenuItem( hMenu, hItem, MF_ENABLED ) End Function Function CM_Item_Disable( hMenu, hItem ) ;============================================================================================================== ; Disables a item. ;============================================================================================================== cm_EnableMenuItem( hMenu, hItem, MF_GRAYED ) End Function Function CM_Item_IsEnabled( hMenu, hItem ) ;============================================================================================================== ; If item is enabled the function gives True, otherwise False. ;============================================================================================================== If ( cm_GetMenuState( hMenu, hItem, 0 ) And MF_GRAYED ) = MF_GRAYED Then Return False Else Return True End Function Function CM_Item_Checked( hMenu, hItem ) ;============================================================================================================== ; Check a item. ;============================================================================================================== cm_CheckMenuItem( hMenu, hItem, MF_CHECKED ) End Function Function CM_Item_Unchecked( hMenu, hItem ) ;============================================================================================================== ; Uncheck a item. ;============================================================================================================== cm_CheckMenuItem( hMenu, hItem, MF_UNCHECKED ) End Function Function CM_Item_IsChecked( hMenu, hItem ) ;============================================================================================================== ; If item is checked the function gives True, otherwise False. ;============================================================================================================== If ( cm_GetMenuState( hMenu, hItem, 0 ) And MF_CHECKED ) = MF_CHECKED Then Return True Else Return False End Function Function CM_Item_SetIcon( hMenu, hItem, hIcon1$, hIcon2$="" ) ;============================================================================================================== ; Adds 1 or 2 Icon(s) to the Item. You can use bmp or ico files. The resolution should be 13x13 Pixel. ; Otherwise the image will be resized automaticly. White color will be transparent in bmp files. Transparancy ; map in ico files will be ignored. If you use 2 icons, the second icon appears If the item is checked. ;============================================================================================================== Local bMap1 Local bMap2 Local hinfo = CreateBank( 20 ) ;--> iconinfo structure ;--> File exists? If FileType( hIcon1$ ) = 0 Then RuntimeError "File " + hIcon1$ + " not Found !" ;--> BMP or ICO? If Lower$( Right$( hIcon1$, 3 ) ) = "bmp" Then bMap1 = cm_LoadImage( 0, hIcon1$, IMAGE_BITMAP, 13, 13, LR_LOADFROMFILE ) Else bMap1 = cm_LoadImage( 0, hIcon1$, IMAGE_ICON, 13, 13, LR_LOADFROMFILE ) cm_GetIconInfo( bMap1, hinfo ) bMap1 = PeekInt( hinfo, 16 ) End If ;--> second icon? If hIcon2$ <> "" Then ;--> BMP or ICO? If Lower$( Right$( hIcon2$, 3 ) ) = "bmp" Then bMap2 = cm_LoadImage( 0, hIcon2$, IMAGE_BITMAP, 13, 13, LR_LOADFROMFILE ) Else bMap2 = cm_LoadImage( 0, hIcon2$, IMAGE_ICON, 13, 13, LR_LOADFROMFILE ) cm_GetIconInfo( bMap2, hinfo ) bMap2 = PeekInt( hinfo, 16 ) End If End If ;--> attach icon cm_SetMenuItemBitmaps( hMenu, hItem, MF_BITMAP, bMap1, bMap2 ) End Function Function CM_StringToBank( cm_str$ ) ;============================================================================================================== ; Puts the given string into a bank and gives back the handle to the bank. ;============================================================================================================== Local i Local length = Len( cm_str$ ) Local tbank ;--> poke the string in the bank tbank = CreateBank( length + 1) For i = 1 To length PokeByte tbank, i - 1, Asc( Mid$( cm_str$, i, 1 ) ) Next Return tbank End Function ;============================================================================================================== ; DECLS. Remove the REM, save it as "contextmenu.decls" into your decls path. ;============================================================================================================== ; Author: East-Power-Soft ; Date: 2007-10-26 12:10:00 ;.lib "user32.dll" ;cm_AppendMenu% (hMenu%, wFlags%, wIDNewItem%, lpNewItem*) : "AppendMenuA" ;cm_CheckMenuItem% (hMenu%, wIDCheckItem%, wCheck%) : "CheckMenuItem" ;cm_CreatePopupMenu% () : "CreatePopupMenu" ;cm_DeleteMenu% (hMenu%, nPosition%, wFlags%) : "DeleteMenu" ;cm_DestroyMenu% (hMenu%) : "DestroyMenu" ;cm_EnableMenuItem% (hMenu%, wIDEnableItem%, wEnable%) : "EnableMenuItem" ;cm_GetActiveWindow% () : "GetActiveWindow" ;cm_GetCursorPos% (lpPoint*) : "GetCursorPos" ;cm_GetIconInfo% (hIcon%, piconinfo*) : "GetIconInfo" ;cm_GetMenuState% (hMenu%, wID%, wFlags%) : "GetMenuState" ;cm_GetMenuString% (hMenu%, wIDItem%, lpString*, nMaxCount%, wFlag%) : "GetMenuStringA" ;cm_GetSystemMetrics% (nIndex%) : "GetSystemMetrics" ;cm_GetWindowRect% (hwnd%, lpRect*) : "GetWindowRect" ;cm_InsertMenu% (hMenu%, nPosition%, wFlags%, wIDNewItem%, lpNewItem*) : "InsertMenuA" ;cm_IsMenu% (hMenu%) : "IsMenu" ;cm_LoadImage% (hInst%, lpsz$, un1%, n1%, n2%, un2%) : "LoadImageA" ;cm_ModifyMenu% (hMenu%, nPosition%, wFlags%, wIDNewItem%, lpString*) : "ModifyMenuA" ;cm_SetMenuItemBitmaps% (hMenu%, nPosition%, wFlags%, hBitmapUnchecked%, hBitmapChecked%) : "SetMenuItemBitmaps" ;cm_TrackPopupMenu% (hMenu%, wFlags%, x%, y%, nReserved%, hwnd%, lprc*) : "TrackPopupMenu" |
||
mGUI - Graphical User Interface für Blitz3D...Informationen gibt es hier
Man kann sich öfter als zweimal im Leben halb tot lachen. |
![]() |
Abrexxes |
![]() Antworten mit Zitat ![]() |
---|---|---|
Sehr Praktisch. | ||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group