Page 1 of 1

requester+ set position, preview

Posted: Mon Dec 13, 2004 8:30 am
by eddy
includefile for PB4.20 & PB4.30


:arrow: Changes :
- set requester position (x,y or mouse cursor)
- no globals, all shared variables
- requester keeps standard behaviour (parent window is locked)
- updated code for PB4.xx ( you can find an old version here )

Code: Select all

;{ SetRequesterPosition Functions
Procedure RequesterPositionCB(Window, Message, wParam, lParam)
   Shared RequesterPositionX.l
   Shared RequesterPositionY.l
   Shared RequesterPositionCB.l
   Shared RequesterPositionHook.l
   Shared RequesterPositionWindow.l
   
   Select Message
      Case #WM_DESTROY
         ;close fake window if necessary
         If RequesterPositionWindow
            CloseWindow(RequesterPositionWindow)
            RequesterPositionWindow=0
         EndIf
         
         ;restore Requester CALLBACK
         SetWindowLong_(Window, #GWL_WNDPROC, RequesterPositionCB)
         
      Case #WM_CREATE
         ;update requester position ;(special case for InputRequester)
         SetWindowPos_(Window, 0, RequesterPositionX, RequesterPositionY, 0, 0, #SWP_NOSIZE | #SWP_NOACTIVATE)
         
      Case #WM_INITDIALOG
         ;update requester position
         SetWindowPos_(Window, 0, RequesterPositionX, RequesterPositionY, 0, 0, #SWP_NOSIZE | #SWP_NOACTIVATE)
         ;result=CallWindowProc_(RequesterPositionCB, Window, Message, wParam, lParam)
         ;SetWindowPos_(Window, 0, RequesterPositionX, RequesterPositionY, 0, 0, #SWP_NOSIZE | #SWP_NOACTIVATE)
         ;ProcedureReturn result
         
   EndSelect
   
   ProcedureReturn CallWindowProc_(RequesterPositionCB, Window, Message, wParam, lParam)
EndProcedure
Procedure RequesterPositionHook(idHook, wParam, lParam)
   Shared RequesterPositionX.l
   Shared RequesterPositionY.l
   Shared RequesterPositionCB.l
   Shared RequesterPositionHook.l
   Shared RequesterPositionWindow.l
   
   Protected *RequesterPositionCWP.CWPSTRUCT=lParam
   Protected Message=*RequesterPositionCWP\Message
   Protected Window=*RequesterPositionCWP\hwnd
   Protected Result
   
   ;(special case for InputRequester)
   Protected WindowClass.s=Space(255)
   GetClassName_(Window, WindowClass, 255)
   If LCase(WindowClass)="inputrequester" : Message=#WM_INITDIALOG : EndIf
   
   Select Message
      Case #WM_INITDIALOG
         ;modify Requester callback
         RequesterPositionCB=SetWindowLong_(Window, #GWL_WNDPROC, @RequesterPositionCB())
         
         ;restore parent HOOK
         Result=CallNextHookEx_(RequesterPositionHook, idHook, wParam, lParam)
         UnhookWindowsHookEx_(RequesterPositionHook)
         RequesterPositionHook=0
         
      Default
         Result=CallNextHookEx_(RequesterPositionHook, idHook, wParam, lParam)
   EndSelect
   
   ProcedureReturn Result
EndProcedure

ProcedureDLL SetRequesterPosition(x=#PB_Ignore, y=#PB_Ignore) ; set requester position (x,y OR mouse position)
   Shared RequesterPositionX.l
   Shared RequesterPositionY.l
   Shared RequesterPositionCB.l
   Shared RequesterPositionHook.l
   Shared RequesterPositionWindow.l
   
   ;use mouse position if x,y are undefined
   If x=#PB_Ignore Or y=#PB_Ignore
      Protected MouseCursor.POINT
      GetCursorPos_(@MouseCursor)
      RequesterPositionX=MouseCursor\x
      RequesterPositionY=MouseCursor\y
   Else
      RequesterPositionX=x
      RequesterPositionY=y      
   EndIf
   
   ;fake window if there's no parent window
   Protected WindowID
   If Not IsWindow(GetActiveWindow())
      RequesterPositionWindow=OpenWindow(#PB_Any, x, y, 0, 0, "", #PB_Window_Invisible)
      WindowID=WindowID(RequesterPositionWindow)
   Else
      WindowID=WindowID(GetActiveWindow())
   EndIf
   
   ;modify parent HOOK
   RequesterPositionHook=SetWindowsHookEx_(#WH_CALLWNDPROC, @RequesterPositionHook(), GetModuleHandle_(0), GetWindowThreadProcessId_(WindowID, 0))
EndProcedure
;}

; =========================
; EXAMPLE
; =========================

OpenWindow(1, 500, 10, 320, 20, "Ultimate Requester Position", #PB_Window_SystemMenu)

SetRequesterPosition(10, 10)
ColorRequester()
Delay(1000)

SetRequesterPosition(30, 30)
InputRequester("IN", "Input", "Input")
Delay(1000)

SetRequesterPosition(50, 50)
PathRequester("", "")
Delay(1000)

SetRequesterPosition(80, 80)
OpenFileRequester("", "", "", 0)
Delay(1000)

SetRequesterPosition(100, 100)
SaveFileRequester("", "", "", 0)
Delay(1000)

SetRequesterPosition(130, 130)
FontRequester("", 0, 0)
Delay(1000)

SetRequesterPosition()
MessageRequester("Message", "Next to mouse cursor")
Delay(1000)

Posted: Mon Dec 13, 2004 9:14 am
by eddy
InputRequester is not a common dialogbox using WM_INITDIALOG

:?:

Posted: Mon Dec 13, 2004 9:24 am
by eddy
[UPDATED]
I added a special case for InputRequester :idea:

Code: Select all

   
   WindowClass.s=Space(255) 
   GetClassName_(Window,WindowClass,255)  
   If LCase(WindowClass)="inputrequester" : Message=#WM_INITDIALOG : EndIf

Posted: Mon Dec 13, 2004 2:39 pm
by ebs
eddy,

VERY NICE!

I'm just working on a program with an InputRequester and this will come in very handy. Thanks!

Eric

Posted: Tue Dec 14, 2004 11:48 am
by eddy
It would be nice if this procedure was a common PB command :roll:

Posted: Tue Dec 14, 2004 1:42 pm
by ebs
eddy,

Maybe you could convert it into a library?

Eric

Posted: Mon May 16, 2005 7:29 am
by eddy
I don't knonw how to do it.

Posted: Mon May 16, 2005 7:36 am
by Progi1984
Use Tailbite of ElChoni !

Posted: Mon May 16, 2005 7:38 am
by eddy
I mean "I'm too lazy" :)
Later perhaps

Posted: Mon May 16, 2005 8:08 am
by Progi1984
LOL

Posted: Mon Jul 04, 2005 4:00 am
by eddy
A new precompiled version of this lib will be available on PureArea.Net website

It will be here soon : http://www.purearea.net/pb/english/userlibs.php

Posted: Sat Sep 20, 2008 8:57 pm
by eddy
update for PB4.20 - 4.30

Posted: Tue Oct 14, 2008 1:37 pm
by PB
> It would be nice if this procedure was a common PB command :roll:

+1

Posted: Tue Oct 14, 2008 2:16 pm
by ts-soft
Thanks :D

You should change Shared RequesterPositionCB.l to
Shared RequesterPositionCB.i and change all SetWindowLong to SetWindowLongPtr
and ich works on X64 to

greetings
Thomas