;TODO first, we not should use id 0 ,Example:
Code: Select all
OpenWindow(1,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
bb=ButtonGadget(0, 5,165,100, 20,"Gad0")
Debug GetDlgCtrlID_(bb);=0 function succeeds, Return id 0
Debug GetDlgCtrlID_(22);=0 function fails, also return NULL 0
;TODO but:
Debug Bool(bb=22);=0
While WindowEvent():Wend
Repeat:ev=WaitWindowEvent():Select ev
Case #PB_Event_CloseWindow:Break
EndSelect:ForEver
End
Code: Select all
;pb-event-fast.pb
; by gurj
; ataorj.ys168.com
Enumeration Window
#win1=1
#win2
EndEnumeration
Dim Window(#PB_Compiler_EnumerationValue):Window(0)=#PB_Compiler_EnumerationValue
a=1:Window(a)=?Win1
a+1:Window(a)=?Win2
Enumeration Gadget
#Gad1=1
#Gad2
#Gad3
#Gad4
#Gad5
EndEnumeration
Dim Gadget(#PB_Compiler_EnumerationValue):Gadget(0)=#PB_Compiler_EnumerationValue
Enumeration Gadget;TODO staticGad
#staticGad1
#staticGad2
EndEnumeration
a=1:Gadget(a)=?Gad1
a+1:Gadget(a)=?Gad2
a+1:Gadget(a)=?Gad3
a+1:Gadget(a)=?Gad4
a+1:Gadget(a)=?Gad5
Enumeration MenuItem
#MenuIt1=1
#MenuIt2
EndEnumeration
Dim MenuIt(#PB_Compiler_EnumerationValue):MenuIt(0)=#PB_Compiler_EnumerationValue
a=1:MenuIt(a)=?MenuIt1
a+1:MenuIt(a)=?MenuIt2
Enumeration PbEven
#Event_Gadget=1
#Event_Menu
#Event_SysTray
#Event_ActivateWindow=4
#Event_WindowDrop
#Event_GadgetDrop
#Event_MinimizeWindow
#Event_MaximizeWindow
#Event_RestoreWindow
#Event_Timer
#Event_RightClick
#Event_LeftClick
#Event_LeftDoubleClick
#Event_DeactivateWindow
#Event_Repaint
#Event_CloseWindow
#Event_MoveWindow
#Event_SizeWindow
EndEnumeration
Dim EventIt(#PB_Compiler_EnumerationValue):EventIt(0)=#PB_Compiler_EnumerationValue
; 13100=#PB_Event_Gadget
; 13101=#PB_Event_Menu
; 13102=#PB_Event_SysTray
;TODO no 13103,Event_Window use 13104
; 13104=#PB_Event_ActivateWindow
; 13105=#PB_Event_WindowDrop
; 13106=#PB_Event_GadgetDrop
; 13107=#PB_Event_MinimizeWindow
; 13108=#PB_Event_MaximizeWindow
; 13109=#PB_Event_RestoreWindow
; 13110=#PB_Event_Timer
; 13111=#PB_Event_RightClick
; 13112=#PB_Event_LeftClick
; 13113=#PB_Event_LeftDoubleClick
; 13114=#PB_Event_DeactivateWindow
; 13115=#PB_Event_Repaint
; 13116=#PB_Event_CloseWindow
; 13117=#PB_Event_MoveWindow
; 13118=#PB_Event_SizeWindow
a=1:EventIt(a)=?Event_Gadget
a+1:EventIt(a)=?Event_Menu
a+1:EventIt(a)=?Event_SysTray
a+1:EventIt(a)=?addressTop;or =?Event_ActivateWindow;no 13103,NOT use 13103
a+1:EventIt(a)=?Event_ActivateWindow
a+1:EventIt(a)=?Event_WindowDrop
a+1:EventIt(a)=?Event_GadgetDrop
a+1:EventIt(a)=?Event_MinimizeWindow
a+1:EventIt(a)=?Event_MaximizeWindow
a+1:EventIt(a)=?Event_RestoreWindow
a+1:EventIt(a)=?Event_Timer
a+1:EventIt(a)=?Event_RightClick
a+1:EventIt(a)=?Event_LeftClick
a+1:EventIt(a)=?Event_LeftDoubleClick
a+1:EventIt(a)=?Event_DeactivateWindow
a+1:EventIt(a)=?Event_Repaint
a+1:EventIt(a)=?Event_CloseWindow
a+1:EventIt(a)=?Event_MoveWindow
a+1:EventIt(a)=?Event_SizeWindow
; Gadgettype Gadget 支持事件类型不连续, 不均匀等原因, 不适合使用虚拟表, 这里没有虚拟表。
;GadgetEventType Gadget to EventType support discontinuous, not uniform and other reasons, not suitable for the use of virtual tables, here is no virtual table.
; 0=#PB_EventType_LeftClick
; 1=#PB_EventType_RightClick
; 2=#PB_EventType_LeftDoubleClick
; 3=#PB_EventType_RightDoubleClick:
; 14000=#PB_EventType_Focus
; 14001=#PB_EventType_LostFocus
; 14002=#PB_EventType_DragStart
; 768=#PB_EventType_Change
win1=OpenWindow(#win1,0,0,200,190,"win1",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
EditorGadget(#Gad1, 0, 0,200, 100)
SetGadgetText(#Gad1, ~"Gad1\nplease LeftClick Gad3\nRightClick image and Item1\nRightClick Window's blank or staticGad")
FrameGadget(#staticGad1, 0, 108, 110, 80, "staticGad1")
TextGadget(#staticGad2, 5,125,100, 20,"staticGad2")
StringGadget(#Gad2, 5,145,100, 20,"Gad2")
ButtonGadget(#Gad3, 5,165,100, 20,"Gad3")
win2=OpenWindow(#win2,WindowX(#win1)-150,WindowY(#win1),150,180,"win2",#PB_Window_SystemMenu)
image=LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\PureBasic.bmp")
ImageGadget(#Gad4, 5,5,20, 20,image)
CreatePopupMenu(1)
MenuItem(1, "Item1:create #Gad5")
MenuItem(2, "Item2:create Gad 15")
While WindowEvent():Wend
EnableASM
gadgad=Gadget(0)+1
addressTop:;Repeat
ev=WaitWindowEvent()
If ev>13099 And ev<13119
addre=EventIt(ev-13099)
jmp addre
Else:Select ev
Case #WM_LBUTTONDOWN
EndSelect
EndIf
Goto addressTop ;ForEver
addressEnd:
;kay add code
End
Event_Gadget:
eg=EventGadget()
If eg<gadgad ;all Gadget not use 0
addre=Gadget(eg)
jmp addre
Else
Goto addressTop
EndIf
;TODO {优化方法:不想处理Gad1,Gad2事件时可这样:
;Optimization method: This can be done when you do not want to handle Gad1,Gad2 events:
Gad1:
Gad2:
;TODO ?Gad1=?Gad2}
Goto addressTop
Gad3:
Debug "Gad3"
Goto addressTop
;Gad5 will created by exe runing
Gad5:
Debug "Gad5"
Goto addressTop
Gad4:
Debug "Gad4"
If EventType()=#PB_EventType_RightClick
DisplayPopupMenu(1, win2)
EndIf
Goto addressTop
Event_Menu:
; TODO {MenuIt仅一个时还可优化,删除开始:
;MenuIt only one time can also be optimized to delete the start:
addre=MenuIt(EventMenu())
jmp addre
MenuIt1:
Debug "MenuIt1"
ButtonGadget(#Gad5, 5,100,100, 20,"Gad5")
Goto addressTop
MenuIt2:
;}删除结束
;EndDelete
;then has this...:
Debug "MenuIt2"
ButtonGadget(15, 5,130,100, 20,"Gad 15")
Goto addressTop
Event_ActivateWindow:
addre=Window(EventWindow())
jmp addre
Win1:
Debug "Win1"
Goto addressTop
Win2:
Debug "Win2"
Goto addressTop
Event_RightClick:
Debug "Window's blank or staticGad RightClicked"
Goto addressTop
Event_CloseWindow:
Goto addressEnd
;TODO 不处理的事件优化为合并:
; Events that are not handled are optimized to merge.
Event_SysTray:
Event_WindowDrop:
Event_GadgetDrop:
Event_MinimizeWindow:
Event_MaximizeWindow:
Event_RestoreWindow:
Event_Timer:
Event_LeftClick:
Event_LeftDoubleClick:
Event_DeactivateWindow:
Event_Repaint:
Event_MoveWindow:
Event_SizeWindow:
Goto addressTop
; TODO {不处理的事件优化为更彻底的合并:
;Events that are not handled are optimized for more thorough consolidation.
;del:
; Gad1:
; Gad2:
; Goto addressTop
; [To changed:
; Gadget(1)=?addressTop
; Gadget(2)=?addressTop
; }
; IDE Options = PureBasic 5.71 beta 1 LTS (Windows - x86)
; CursorPosition = 14
; Folding = -
; EnableXP
; DPIAware
; Watchlist = addre