Page 1 of 3
3 Questions: 2 Easy and one hard
Posted: Mon Dec 13, 2004 8:32 am
by cecilcheah
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
Posted: Mon Dec 13, 2004 3:56 pm
by localmotion34
simple way to do the listicon thing using the example from the help.
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
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)
Posted: Mon Dec 13, 2004 4:22 pm
by aaron_at_work
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)
Posted: Mon Dec 13, 2004 4:28 pm
by thefool
@question 1:
Look at your API manual. ExitProcess etc..
Posted: Mon Dec 13, 2004 10:53 pm
by ABBKlaus
what about the lib from siegfried rings :
PureBasic process investigation library
http://www.purearea.net/pb/download/use ... essLib.zip
Posted: Mon Dec 13, 2004 10:56 pm
by cecilcheah
what is this again?
PureBasic process investigation library
Cecil
Posted: Mon Dec 13, 2004 11:25 pm
by GedB
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
Re: 3 Questions: 2 Easy and one hard
Posted: Tue Dec 14, 2004 9:54 am
by PB
> 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.

Posted: Tue Dec 14, 2004 12:36 pm
by cecilcheah
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:
Code: Select all
Repeat
if hwnd (external programme) = null
closeSelf = 1
endif
until closeSelf = 1
Correct? How do i do this hwnd(external programme) stuff? hwnd is a number, not a function or procedure that requires a parameter?
Cecil
Posted: Tue Dec 14, 2004 1:28 pm
by Kale
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")
Look into WinAPI here:
viewtopic.php?t=10046
Posted: Tue Dec 14, 2004 8:01 pm
by PB
> hwnd.l = FindWindow_("Name of App")
You missed a parameter; it should be: hwnd.l=FindWindow_(0,"Name of App")

Posted: Tue Dec 14, 2004 8:03 pm
by PB
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.
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
Posted: Tue Dec 14, 2004 8:28 pm
by Kale
PB wrote:You missed a parameter; it should be: hwnd.l=FindWindow_(0,"Name of App")
Aye, posted at work without my trusty APIGuide!

he he...
Posted: Tue Dec 14, 2004 9:18 pm
by cecilcheah
Thanks. I will try it.
Cecil
Posted: Wed Dec 15, 2004 8:56 pm
by cecilcheah
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.
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
Error: Constant not found: #OG_HPosition
What is the constant value for #OG_HPosition?
Cecil