3 Questions: 2 Easy and one hard

Just starting out? Need help? Post your questions and find answers here.
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

3 Questions: 2 Easy and one hard

Post 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
Last edited by cecilcheah on Mon Dec 13, 2004 4:05 pm, edited 1 time in total.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post 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)

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
aaron_at_work
User
User
Posts: 11
Joined: Tue Jun 01, 2004 7:24 pm

Post 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) 
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

@question 1:
Look at your API manual. ExitProcess etc..
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

what about the lib from siegfried rings :

PureBasic process investigation library :idea:
http://www.purearea.net/pb/download/use ... essLib.zip
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

what is this again?
PureBasic process investigation library
Cecil
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: 3 Questions: 2 Easy and one hard

Post 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:

Code: Select all

PostMessage_(hWnd,#WM_CLOSE,0,0)
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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post 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
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
--Kale

Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> hwnd.l = FindWindow_("Name of App")

You missed a parameter; it should be: hwnd.l=FindWindow_(0,"Name of App")

;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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! :oops: he he...
--Kale

Image
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post by cecilcheah »

Thanks. I will try it.

Cecil
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

Post 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
Post Reply