UsedWindow()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

UsedWindow()

Post by tinman »

And anywhere else you can "use" something, it would be nice to be able to find out what number of item is currently being "used".
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: UsedWindow()

Post by ricardo »

tinman wrote:And anywhere else you can "use" something, it would be nice to be able to find out what number of item is currently being "used".
EventWindowID()
EventGadgetID()

Does what you want, or maybe i don't understand you question.
ARGENTINA WORLD CHAMPION
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: UsedWindow()

Post by fsw »

ricardo wrote:
tinman wrote:And anywhere else you can "use" something, it would be nice to be able to find out what number of item is currently being "used".
EventWindowID()
EventGadgetID()

Does what you want, or maybe i don't understand you question.
EventWindowID() and EventGadgetID() only gives you a hint what was used IF there WAS an EVENT.

I suppose Tinman likes to see a command that tells him what was the last used Window or Gadget or whatever.
Something like a specialized GetFocus for each GUI control :?:
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: UsedWindow()

Post by ricardo »

EventWindowID() and EventGadgetID() only gives you a hint what was used IF there WAS an EVENT.

I suppose Tinman likes to see a command that tells him what was the last used Window or Gadget or whatever.
Something like a specialized GetFocus for each GUI control :?:
But you can store it on a variable.

But maybe he is asking for some command to know the actuall/selected window, i mean with UseWindow()

However, all this info can be stored in a variable
ARGENTINA WORLD CHAMPION
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: UsedWindow()

Post by tinman »

ricardo wrote:But maybe he is asking for some command to know the actuall/selected window, i mean with UseWindow()

However, all this info can be stored in a variable
Yes, it's very easy to do with something like this:

Code: Select all

DefType.l my_used_window : Global my_used_window
Procedure.l mUseWindow(window_number..l)
    my_used_window = window_number
    ProcedureReturn UseWindow(window_number)
EndProcedure

Procedure.l mUsedWindow()
    ProcedureReturn my_used_window
EndProcedure
Problems with this:
- I don't know if that is valid, for when I try to use a window that does not exist.
- you could end up in a situation where the value of my_used_window is different from the actual used window, if you are working in threads (although this would also be the case if done in the wrong way in a library)
- I need to do that for every library, which means (at the moment) all code will be included in the program. I assume the libraries would be written in the split format.
- PureBasic exe's are pretty quick, but a few lines of assembly kick the ass off any code written in basic.

Besides, people ask for all sorts of pointless crap here, I thought I'd join in ;)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

try this:

Code: Select all

Procedure UsedWindow()
  result=-1
  aktiveWindow=GetFocus_()
  for i=0 to 100
     if aktiveWindow=WindowID()
        result=i:i=99999
     endif
  next
  procedurereturn result
endprocedure
Note: This works only, when you use window-numbers under 101 and when no one of your window is active, the result is -1

GPI
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

@ GPI

your example will not work.
The WindowID is the hWnd of the OS, and this is never between 0 and 100.
Before, you could use an array, where you store the hWnd/WindowIDs together with the PB #Window number

Code: Select all

Procedure UsedWindow() 
  result=-1 
  aktiveWindow=GetFocus_() 
  for i=0 to 100 
     if aktiveWindow=window(i):aktiveWindow=i
        result=i:i=99999 
     endif 
  next 
  procedurereturn result 
endprocedure
Johannes
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

@JoRo: yes and no.

I had a little misstake. I write WindowID() instead of WindowID(i). If the Window i is not open, WindowID(i) will return 0.

Code: Select all

Procedure UsedWindow()
  result=-1
  aktiveWindow=GetFocus_()
  for i=0 to 100
     if aktiveWindow=WindowID(i)
        result=i:i=99999
     endif
  next
  procedurereturn result
endprocedure
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

@ GPI

I think, GetFocus_ delivers the hWnd of every active Window, incl. ChildWindows, and that are the Gadgets.

It is enough to move the mouse over a button and it gets the focus.

It is really not so simple, to get the active Window. In your example , you could store the active Window, Global Variable, it would hold the last change of the active Window.

The array, you are right, is not necessary.

Johannes
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

Ok, GetFocus_() isn't the right function, try GetActiveWindow_(). It returns the WindowHandle of the active window, if the program create this window, otherwise 0. Try this:

Code: Select all

OpenWindow(0,0,200,100,100,0,"hallo")
creategadgetlist(WindowID())
ButtonGadget(0,10,10,80,80,"TEST")
OpenWindow(1,200,200,10,10,0,"hallo2")
oldfocus=-1
Repeat 
  WindowEvent()
  x=Getactivewindow_()
  If oldfocus<>x
    oldfocus=x
    Debug oldfocus
  EndIf
ForEver
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Ok, here are some Used-Functions, that might be Use-full :lol:
They all return the OS Handles, no PB Numbers.
What they return is the actual object set by the Use...() function, just like
timnam want's it :wink:

The info about these internal variables can be easily got from the
"PureBasic library descriptor.txt" file in the LibrarySDK folder.

Code: Select all

Procedure.l UsedWindow() ; returns WindowID() of current used window
  !EXTRN _PB_Window_Current
  !MOV EAX, dword [_PB_Window_Current]
  ProcedureReturn
EndProcedure

Procedure.l UsedFile()   ; returns HANDLE of current used File
  !EXTRN _PB_File_Current
  !MOV EAX, dword [_PB_File_Current]
  ProcedureReturn
EndProcedure 

Procedure.l UsedFont()   ; returns HFONT of current used font
  !EXTRN _PB_Font_Current
  !MOV EAX, dword [_PB_Font_Current]
  ProcedureReturn
EndProcedure

Procedure.l UsedMenu()   ; returns HMENU of currenmt used menu
  !EXTRN _PB_Menu_Current
  !MOV EAX, dword [_PB_Menu_Current]
  ProcedureReturn
EndProcedure

Procedure.l UsedDrawingDC() ; returns DC (Device Context) of current drawing operation
  !EXTRN _PB_2DDrawing_CurrentDC
  !MOV EAX, dword [_PB_2DDrawing_CurrentDC]
  ProcedureReturn
EndProcedure

Procedure.l UsedImage()  ; returns ImageID() of current used Image
  !EXTRN  _PB_Image_CurrentObject
  !MOV EAX, dword [ _PB_Image_CurrentObject]
  ProcedureReturn
EndProcedure
Timo
quidquid Latine dictum sit altum videtur
JoRo
User
User
Posts: 70
Joined: Sat May 10, 2003 2:03 pm
Location: Essen, Germany
Contact:

Post by JoRo »

@freak,

thats it. I just took a first look in the text of the sdk. Only problem: ASM

Johannes
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 »

freak wrote:What they return is the actual object set by the Use...() function, just like timnam want's it :wink:
Who's that ;p

Besides, it is nothing like what I want. You've just sent some procedures which are *exactly* the same as "WindowID()". I'd like the window number.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply