Finding Window Handle

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Chevron.

If I was to call a purebasic .dll from blitz, how would I know the window handle of the blitz window from within purebasic if I wanted to say minimize this window. Is it possible to find the window handle from the title of the window?

Many Thanks
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Paul.

viewtopic.php?t=1792 PLEASE READ%21&Forum_Title=Beginners
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Is it possible to find the window handle from the title of the window?

handle=FindWindow_(0, "window title") ; Returns 0 if window not found.

(And please read Paul's response too).


PB - Registered PureBasic Coder

Edited by - PB on 05 August 2002 22:22:59
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Chevron.

Thanks for the fast response, much appreiated.
Sorry for not trying a search first , i'll bear that in mind. Its just that I'm new to PB and didn't really know how to phrase the search for the problem I had.

just another quick question

When calling this routine It draws to the desktop and not the active window, could anyone tell me why. Just point me in the right direction and I'll work it out I'm sure.


;-------------------------------------------------------------------------------
ProcedureDLL plot_pix()

;find the window
handle=FindWindow_(0,"pix")
;set to current
thread1=getwindowthreadprocessid_(getforegroundwindow_(),0)
thread2=getwindowthreadprocessid_(handle,0)
If thread1thread2 : attachthreadinput_(thread1,thread2,#TRUE) : EndIf
setforegroundwindow_(handle)
If thread1thread2 : attachthreadinput_(thread1,thread2,#FALSE) : EndIf

StartDrawing(WindowOutput())

Circle(100,100,50,RGB(0,0,255)) ; a nice blue circle...

Box(150,20,20,20, RGB(0,255,0)) ; and a green box

StopDrawing()

EndProcedure

;-------------------------------------------------------------------------------




Edited by - Chevron on 05 August 2002 19:45:47
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Sorry for not trying a search first

No real problem... we were just letting you (and any lurkers) know.

> When calling this routine It draws to the desktop and not the active window,
> could anyone tell me why.
>
> handle=FindWindow_(0,"pix")
> [snip]
> StartDrawing(WindowOutput())

The values of handle and WindowOutput() are not the same. WindowOutput() is a
variable holding an internal PureBasic window number -- it's not a window handle.

I don't have any real 2D drawing experience, so somebody else will have to take
over from here and explain how to use StartDrawing with the value of "handle"...


PB - Registered PureBasic Coder

Edited by - PB on 05 August 2002 22:31:09
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

> When calling this routine It draws to the desktop and not the active window,
> could anyone tell me why. Just point me in the right direction and I'll work
> it out I'm sure.

Look at this small example - not nice, but works sometimes.
Hope you get the idea...

I tested with Notepad (start it first) and it draws
into the Notepad window:

Code: Select all

;--------------------
;--------------------


Structure WinOutStruc
a.l
b.l
c.l
d.l
EndStructure


Procedure.l WinOut(WindowHandle)
 Shared WinOutVar.WinOutStruc
 Shared WinOutA


   WinOutVar\a = 1
   WinOutVar\b = WindowHandle
   WinOutA = GetDC_(WindowHandle)
    !EXTERN _PB_2DDrawing_CurrentDC
    !MOV dword EAX,[v_WinOutA]
    !MOV dword [_PB_2DDrawing_CurrentDC],EAX
ProcedureReturn @WinOutVar
EndProcedure


ProcedureDLL plot_pix()
   ;find the window
   handle=FindWindow_(0,"Untitled - Notepad")   ;"pix") 
   If handle
      ;set to current
      thread1=getwindowthreadprocessid_(getforegroundwindow_(),0)
      thread2=getwindowthreadprocessid_(handle,0) 
      If thread1thread2 : attachthreadinput_(thread1,thread2,#TRUE) : EndIf 
      setforegroundwindow_(handle) 
      If thread1thread2 : attachthreadinput_(thread1,thread2,#FALSE) : EndIf


      Delay(10)


      StartDrawing( WinOut(handle) )   ;WindowOutput())
         Circle(100,100,50,RGB(0,0,255)) ; a nice blue circle...
         Box(150,20,20,20, RGB(0,255,0)) ; and a green box
      StopDrawing()
   EndIf
EndProcedure


plot_pix()
Delay(1000)


;--------------------
;--------------------
Disable the so called "Debugger" before using this.

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Chevron.

Thanks alot for that, I know I can plot to a window using findwindow_ getDc_ and setpixel_ but wanted to see how to do it using purebasics generic drawing commands and not windows API.
Thanks again.
Post Reply