requester+ set position, preview

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

requester+ set position, preview

Post 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)
Last edited by eddy on Tue Nov 04, 2008 8:46 pm, edited 7 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

InputRequester is not a common dialogbox using WM_INITDIALOG

:?:
Last edited by eddy on Tue Dec 14, 2004 11:52 am, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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
Last edited by eddy on Tue Dec 14, 2004 11:53 am, edited 2 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

eddy,

VERY NICE!

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

Eric
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

It would be nice if this procedure was a common PB command :roll:
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

eddy,

Maybe you could convert it into a library?

Eric
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

I don't knonw how to do it.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Use Tailbite of ElChoni !
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

I mean "I'm too lazy" :)
Later perhaps
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

LOL
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

update for PB4.20 - 4.30
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> It would be nice if this procedure was a common PB command :roll:

+1
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply