Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8328511
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类:

2007-02-25 11:29:08

通过这两个小程式,我们可以看到purebasic在写GUI程序的简易性,以及他的事件处理过程,虽然没有VB方便,不过已经算是不错了.
;展示了一个只有按钮和文本框,但做不了什么事的窗体:

Global Window_0, Button_0, String_0

Procedure Open_Window_0()
Window_0 = OpenWindow(#PB_Any, 5, 5, 400, 200, "Window 0", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If Window_0
If CreateGadgetList(WindowID(Window_0))
Button_0 = ButtonGadget(#PB_Any, 150, 150, 110, 20, "确定")
String_0 = StringGadget(#PB_Any, 90, 90, 220, 30, "")
EndIf
EndIf
EndProcedure

Open_Window_0()

Repeat
Event = WaitWindowEvent()

Until Event = #PB_Event_CloseWindow

End

;通过Purebasic visual designer设计,然后写的一些相关代码:
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)


;- Window Constants
;
Enumeration
#Window_0
EndEnumeration

;- MenuBar Constants
;
Enumeration
#MenuBar_3
EndEnumeration

Enumeration
#MENU_1
#MENU_2
#MENU_3
#MENU_4
#MENU_5
#MENU_8
#MENU_11
#MENU_6
EndEnumeration

;- Gadget Constants
;
Enumeration
#Listview_0
#Button_0
#TrackBar_0
EndEnumeration
Global list1 , button1

Procedure Open_Window_0()
If OpenWindow(#Window_0, 214, 35, 341, 271, "New window ( 0 )", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If CreatePopupMenu(#MenuBar_3)
MenuTitle("sdfsd")
MenuItem(#MENU_1, "sdfdsf")
MenuItem(#MENU_2, "sdfdfdf")
MenuItem(#MENU_3, "sfsdfsdf")
MenuItem(#MENU_4, "sdfsdfdsf")
MenuItem(#MENU_5, "sdfsdfdf")
MenuBar()
MenuItem(#MENU_8, "dfgfd")
MenuItem(#MENU_11, "sdfd")
MenuItem(#MENU_6, "sdfsdf")
EndIf

If CreateGadgetList(WindowID(#Window_0))
list1=ListViewGadget(#Listview_0, 10, 10, 200, 170)
button1=ButtonGadget(#Button_0, 240, 140, 70, 30, "")
TrackBarGadget(#TrackBar_0, 10, 190, 230, 30, 0, 10)
EndIf
EndIf
EndProcedure


Open_Window_0()

Procedure WindowUnderCursor(hWnd)
GetCursorPos_(cursor.POINT)
MapWindowPoints_(0,hWnd,cursor,1)
ProcedureReturn ChildWindowFromPoint_(hWnd,cursor\x,cursor\y)
EndProcedure

Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_Event_Gadget
If GadgetID = #Listview_0
ElseIf GadgetID = #Button_0
If EnvntType = #PB_EventType_RightClick
Debug "RightClick"
ElseIf EnvntType = #PB_EventType_LeftClick
Debug "LeftClick"
EndIf
ElseIf GadgetID = #TrackBar_0
If EnvntType = #PB_EventType_LeftClick
Debug "LeftClick"
ElseIf EnvntType = #PB_EventType_RightClick
Debug "RightClick"
EndIf
EndIf
ElseIf Event = #WM_RBUTTONUP
Select WindowUnderCursor(WindowID(#Window_0))
Case list1 ,button1
DisplayPopupMenu(#MenuBar_3,WindowID(0))
Debug "RBUTTONUP"
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop

End

;展示了简单的事件处理过程
Enumeration
EndEnumeration

Enumeration
#String_0
#Button_0
EndEnumeration

Global Window_0

Procedure Open_Window_0()
Window_0 = OpenWindow(#PB_Any, 5, 5, 400, 200, "Window 0", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
If Window_0
If CreateGadgetList(WindowID(Window_0))
ButtonGadget(#Button_0, 150, 150, 110, 20, "确定")
StringGadget(#String_0, 90, 90, 220, 30, "")
EndIf
EndIf
EndProcedure

Open_Window_0()

Repeat
Event = WaitWindowEvent()
windowID=EventWindow()
;gadgetID=EventGadget()
EventType=EventType()
If event=#PB_Event_Gadget
Select EventGadget()
Case #Button_0
SetGadgetText(#String_0,"hello,purebasic")
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow

End

































阅读(2961) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~