Page 1 of 1

UsedWindow()

Posted: Sun Jun 01, 2003 11:48 pm
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".

Re: UsedWindow()

Posted: Mon Jun 02, 2003 5:58 am
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.

Re: UsedWindow()

Posted: Mon Jun 02, 2003 6:24 am
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 :?:

Re: UsedWindow()

Posted: Mon Jun 02, 2003 8:11 am
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

Re: UsedWindow()

Posted: Mon Jun 02, 2003 9:41 am
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 ;)

Posted: Mon Jun 02, 2003 5:55 pm
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

Posted: Fri Jun 06, 2003 8:15 am
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

Posted: Fri Jun 06, 2003 4:27 pm
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

Posted: Fri Jun 06, 2003 4:43 pm
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

Posted: Fri Jun 06, 2003 7:39 pm
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

Posted: Fri Jun 06, 2003 8:56 pm
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

Posted: Sat Jun 07, 2003 7:13 am
by JoRo
@freak,

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

Johannes

Posted: Sat Jun 07, 2003 9:09 am
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.