A RS 232 Communication Library

Share your advanced PureBasic knowledge/code with the community.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

BTW: Fred,
PureGUI is dead, long live Connect.DLL 8O

Fred, you have done a good job with the Event Stuff in PureBasic that PureGUI is no longer needed.
I can have all special gadget events I need with PureBasic 3.7 - sweet!
( seems to work fine now - not all Gadgets tested though... )

The only thing remaining is the automatic calling of events for Gadgets.
(...and #PB_ANY for Memory, Directories and files etc. :wink: )
I've put the remaining functions in a DLL with 3 Functions in it:
InitConnect(), Connect() and GetConnection().

My PureBasic code now looks like this: (example)

Code: Select all

OpenWindow(1,100,200,320,240,#PB_Window_SystemMenu | #PB_Window_SizeGadget,"Test")
CreateGadgetList(WindowID(1))
AdvancedGadgetEvents(#TRUE)
InitConnect()

CreateMenu(1,WindowID(1))
  MenuTitle("File")
  MenuItem(Connect(#PB_Event_Menu, ?MenuNew),"New")
  MenuItem(Connect(#PB_Event_Menu, ?MenuOpen),"Open")
  MenuItem(Connect(#PB_Event_Menu, ?MenuSave),"Save")
  
CreateToolBar(1,WindowID(1))
  ToolBarStandardButton(Connect(#PB_Event_Menu, ?MenuNew),#PB_ToolBarIcon_New)
  ToolBarStandardButton(Connect(#PB_Event_Menu, ?MenuOpen),#PB_ToolBarIcon_Open)
  ToolBarStandardButton(Connect(#PB_Event_Menu, ?MenuSave),#PB_ToolBarIcon_Save)
      
ButtonGadget(Connect(#PB_Event_Gadget, ?Button1),10,30,100,25,"Button 1")
ButtonGadget(Connect(#PB_Event_Gadget, ?Button2),10,80,100,25,"Button 2")
ButtonGadget(Connect(#PB_Event_Gadget, ?Button3),10,130,100,25,"Button 3")


Repeat
  Event.l = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Menu
      CallFunctionFast(GetConnection(#PB_Event_Menu, EventMenuID()))

    Case #PB_Event_Gadget
      CallFunctionFast(GetConnection(#PB_Event_Gadget, EventGadgetID()))
      
  EndSelect
Until Event = #PB_Event_CloseWindow

End
and what remains is building the 'sub routines' for each Event.
Something like this: (example - only menues are shown...)

Code: Select all

;- User Functions
MenuNew:
  Debug "SubDir MenuNew"
  Debug GetConnection(#PB_Event_Menu, ?MenuNew)
Return

MenuOpen:
  Debug "SubDir MenuOpen"
  Debug GetConnection(#PB_Event_Menu, ?MenuOpen)
  DisableMenuItem(GetConnection(#PB_Event_Menu, ?MenuOpen),1)
Return

MenuSave:
  Debug "SubDir MenuSave"
  Debug GetConnection(#PB_Event_Menu, ?MenuSave)
  If GetMenuItemState(1,GetConnection(#PB_Event_Menu, ?MenuSave)) = 1
    SetMenuItemState(1,GetConnection(#PB_Event_Menu, ?MenuSave),0)      
  Else
    SetMenuItemState(1,GetConnection(#PB_Event_Menu, ?MenuSave),1)      
  EndIf 
Return

InitConnect() = is needed beause it's a DLL not a OBJ.
Connect(ChildType, EventFunctionSubroutine) = gives a number to a gadget and connects it to a sub routine.
GetConnection(ChildType, EventID) = returns the address of the EventFunctionSubroutine
or
GetConnection(ChildType, EventFunctionSubroutine) = returns the GadgetNumber connected to the EventFunctionSubroutine

Now GUI coding is a breeze - for lazy coders like me :wink:

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

fsw wrote:for lazy coders like me :wink:
Not too lazy to upload it somewhere surely ;)
I always liked the look of PureGUI for an event based approach.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

And I thought I'm alone...

Thanks Tinman for the flowers :wink:

Upload....yeah sure - but first I have to clean it up, for the public :roll:

BTW:
It would be nicer if it wasn't a 6KB DLL but a 2KB OBJ (compressed 1KB).
Tried to tweak purebasic's asm code of it (13KB) and made a OBJ - but there is some memory mismach (it's not working right as OBJ...).
I'm not that familiar with asm... (this said, I could never ever optimize asm code :oops: )

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Agree with Fred.

PB is characterized specially by small and powerful executables generated by the PB compilation.

For sure Fred doesn't want never to loose this characteristic which makes PB to be distinguished from the most of the rest of compilers (included some C++ ones i've compared).

If Fred loose this policy, PB could loose its position.
Post Reply