3 Questions: 2 Easy and one hard
-
- Enthusiast
- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
3 Questions: 2 Easy and one hard
Hi there
2 Easy questions but i just do not know how to do it.
1. How can i close a PB Application from an external application? Is there an easy built-in Procedure i can pass to PB from my external programme?
2. How can the Listview show the last item added. Everytime when i use the code to add some more item to the Listview Gadget, it always highlight the first item.
Now come a more difficult one.
How can i create my own gadget? Any documentation i can download? I want to create my own gadget and can alter its properties and add my own methods and events to this gadgets.
Cecil
2 Easy questions but i just do not know how to do it.
1. How can i close a PB Application from an external application? Is there an easy built-in Procedure i can pass to PB from my external programme?
2. How can the Listview show the last item added. Everytime when i use the code to add some more item to the Listview Gadget, it always highlight the first item.
Now come a more difficult one.
How can i create my own gadget? Any documentation i can download? I want to create my own gadget and can alter its properties and add my own methods and events to this gadgets.
Cecil
Last edited by cecilcheah on Mon Dec 13, 2004 4:05 pm, edited 1 time in total.
-
- Enthusiast
- Posts: 665
- Joined: Fri Sep 12, 2003 10:40 pm
- Location: Tallahassee, Florida
simple way to do the listicon thing using the example from the help.
NOTICE that if you use countgadgetitems you MUST subtract 1 from the result. countgadgetitems() retieves the # of items, but the listicon index starts at 0. so if there are 10 items, they are item #0- item #9. just use setgadgetstate(whatever,countgagetitems(whatever)-1)
Code: Select all
#MyWindow = 0
#MyGadget = 1
If OpenWindow(#MyWindow,100,100,300,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"ListIcon Example")
If CreateGadgetList(WindowID())
ListIconGadget(#MyGadget,5,5,290,90,"Name",100,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#MyGadget,1,"Address",250)
AddGadgetItem(#MyGadget,-1,"Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(#MyGadget,-1,"Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
item=AddGadgetItem(#MyGadget,-1,"Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
SetGadgetState(#MyGadget,CountGadgetItems(#MyGadget)-1)
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow And EventWindowID() = #MyWindow
EndIf
EndIf
Code: Select all
!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
-
- User
- Posts: 11
- Joined: Tue Jun 01, 2004 7:24 pm
Use the SetGadgetState and CountGadgetItems commands to show the last item added to a listview. I've attached a line of code from a program I'm working on right now which does that exact thing.
Code: Select all
SetGadgetState(#Gadget_MainWindow_SerialOutput, CountGadgetItems(#Gadget_MainWindow_SerialOutput)-1)
what about the lib from siegfried rings :
PureBasic process investigation library
http://www.purearea.net/pb/download/use ... essLib.zip
PureBasic process investigation library

http://www.purearea.net/pb/download/use ... essLib.zip
-
- Enthusiast
- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Creating your own Gadgets aint so tough, thanks to Erland:
viewtopic.php?t=10857
If you want to do it yourself, then I recommend you follow this C++ win32 tutorial:
http://www.relisoft.com/book/win/index.htm
Pay particular attention to Subclassing. Theres some converted code here to start you off:
viewtopic.php?t=11827
viewtopic.php?t=10857
If you want to do it yourself, then I recommend you follow this C++ win32 tutorial:
http://www.relisoft.com/book/win/index.htm
Pay particular attention to Subclassing. Theres some converted code here to start you off:
viewtopic.php?t=11827
Re: 3 Questions: 2 Easy and one hard
> How can i close a PB Application from an external application? Is there an
> an easy built-in Procedure i can pass to PB from my external programme?
Not really. You can close one PureBasic app from another PureBasic app
though... just use this small line in the app that does the closing:
hWnd = Handle of your PureBasic app's window. This will make your app get
a #PB_EventCloseWindow event, and thus it will act as though you hit ALT+F4
on it. If the other external apps know your app's handle, they too can send
the same command above to close it. Reply if you need more help, and I'll
code an example.
> an easy built-in Procedure i can pass to PB from my external programme?
Not really. You can close one PureBasic app from another PureBasic app
though... just use this small line in the app that does the closing:
Code: Select all
PostMessage_(hWnd,#WM_CLOSE,0,0)
a #PB_EventCloseWindow event, and thus it will act as though you hit ALT+F4
on it. If the other external apps know your app's handle, they too can send
the same command above to close it. Reply if you need more help, and I'll
code an example.

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
So i have to get the HWnd value of my external programme, add in the repeat loop that if Hwnd = null, then close itself. Like this:
Correct? How do i do this hwnd(external programme) stuff? hwnd is a number, not a function or procedure that requires a parameter?
Cecil
Code: Select all
Repeat
if hwnd (external programme) = null
closeSelf = 1
endif
until closeSelf = 1
Cecil
cecilcheah wrote:Correct? How do i do this hwnd(external programme) stuff? hwnd is a number, not a function or procedure that requires a parameter?
Code: Select all
hwnd.l = FindWindow_("Name of App")
viewtopic.php?t=10046
Here's a working example.
Compile both of these as exes, then run the
first one, and then the second one while the first is running.

first one, and then the second one while the first is running.
Code: Select all
If OpenWindow(1,300,200,400,100,#PB_Window_SystemMenu,"AppToBeClosed")
CreateGadgetList(WindowID())
Repeat
ev=WaitWindowEvent()
; Your normal gadget-handling routine goes here.
Until ev=#PB_Event_CloseWindow ; The other app will trigger this.
EndIf
Code: Select all
If OpenWindow(1,300,400,400,100,#PB_Window_SystemMenu,"AppThatClosesTheOther")
CreateGadgetList(WindowID())
ButtonGadget(0,10,10,100,25,"Close other")
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget
PostMessage_(FindWindow_(0,"AppToBeClosed"),#WM_CLOSE,0,0)
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Enthusiast
- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
-
- Enthusiast
- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Hi there
The 2 easy questions are resolved. Thanks for the help.
However after downloading the ownGadget_Example.pb, i run into an error when compiling the example.
Error: Constant not found: #OG_HPosition
What is the constant value for #OG_HPosition?
Cecil
The 2 easy questions are resolved. Thanks for the help.
However after downloading the ownGadget_Example.pb, i run into an error when compiling the example.
Code: Select all
Procedure paint(gadget)
GetWindowRect_(gadget,rc.rect)
x=GetGadgetItemState(0,#OG_HPosition)
y=GetGadgetItemState(0,#OG_VPosition)
DrawingMode(0)
Box(0,0,rc\right,rc\bottom,RGB(255,0,100))
LineXY(0,y,rc\right,y,RGB(0,255,0))
LineXY(x,0,x,rc\bottom,RGB(0,255,0))
EndProcedure
What is the constant value for #OG_HPosition?
Cecil