RASHAD 08/09/2010
The Default behavior is the left top corner of the parent window
This code is for control the position And size w/o any parent window
1 : Using Watching Thread
1-1 OpenFileRequester
Code: Select all
Global hwnd,ReqText$,x,y,w,h,flag
Procedure Center(parameter)
Repeat
hwnd = FindWindow_(0,ReqText$)
r.RECT
GetWindowRect_(hwnd,r)
ExamineDesktops()
If w =0 Or h = 0 Or OSVersion() <= #PB_OS_Windows_XP
w = r\right - r\left
h = r\bottom - r\top
EndIf
If hwnd And flag = 0
MoveWindow_(hwnd,x,y,w,h,1)
InvalidateRect_(hwnd,0,1)
ElseIf hwnd And flag = 1
x = (DesktopWidth(0) - w)/2
y = (DesktopHeight(0) - h)/2
MoveWindow_(hwnd,x,y,w,h,1)
InvalidateRect_(hwnd,0,1)
EndIf
run = run + 1
Until run = 1000
EndProcedure
;ClassName$ = "#32770" ;"InputRequester"
ReqText$ = "Please choose file to load" ;For OpenFileRequester or Any Text else
x = 100
y = 100
w = 900 ; 0 = OS Default Width & Height
h = 600 ; 0 = OS Default Width & Height
flag = 1 ; 1 = Center 0 = At x,y Position
Thread = CreateThread(@Center(),100)
StandardFile$ = "C:\autoexec.bat" ; set initial file+path to display
; With next string we will set the search patterns ("|" as separator) for file displaying:
; 1st: "Text (*.txt)" as name, ".txt" and ".bat" as allowed extension
; 2nd: "PureBasic (*.pb)" as name, ".pb" as allowed extension
; 3rd: "All files (*.*) as name, "*.*" as allowed extension, valid for all files
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0 ; use the first of the three possible patterns as standard
File$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)
If File$
MessageRequester("Information", "You have selected following file:" + Chr(10) + File$, 0)
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIf
If IsThread(Thread)
KillThread(Thread)
EndIf
Code: Select all
Global hwnd,ReqText$,x,y,w,h,flag
Procedure Center(parameter)
Repeat
hwnd = FindWindow_(0,ReqText$)
r.RECT
GetWindowRect_(hwnd,r)
ExamineDesktops()
If w =0 Or h = 0
w = r\right - r\left
h = r\bottom - r\top
EndIf
If hwnd And flag = 0
MoveWindow_(hwnd,x,y,w,h,1)
ElseIf hwnd And flag = 1
x = (DesktopWidth(0) - w)/2
y = (DesktopHeight(0) - h)/2
MoveWindow_(hwnd,x,y,w,h,1)
EndIf
run = run + 1
Until run = 1000
EndProcedure
ReqText$ = "Font" ;For FontRequester
x = 100 ;Upper Corner Left Pos
y = 100 ;Upper Corner Top Pos
flag = 1 ;1 = Center 0 = At x,y Position
Thread = CreateThread(@Center(),100)
FontName$ = "Arial" ; set initial font (could also be blank)
FontSize = 14 ; set initial size (could also be null)
Result = FontRequester(FontName$, FontSize, #PB_FontRequester_Effects)
If Result
Message$ = "You have selected following font:" + #LF$
Message$ + "Name: " + SelectedFontName() + #LF$
Message$ + "Size: " + Str(SelectedFontSize()) + #LF$
Message$ + "Color: " + Str(SelectedFontColor()) + #LF$
If SelectedFontStyle() & #PB_Font_Bold
Message$ + "Bold" + #LF$
EndIf
If SelectedFontStyle() & #PB_Font_StrikeOut
Message$ + "StrikeOut" + #LF$
EndIf
If SelectedFontStyle() & #PB_Font_Underline
Message$ + "Underline" + #LF$
EndIf
Else
Message$ = "The requester was canceled."
EndIf
MessageRequester("FontRequester", Message$, #PB_MessageRequester_Ok)
If IsThread(Thread)
KillThread(Thread)
EndIf
2-1 OpenFileRequester
Code: Select all
Global hwnd,ReqText$
Procedure HookCB ( uMsg , wParam , lParam)
Select uMsg
Case #HCBT_SETFOCUS
For i = 1 To 10
hwnd = FindWindow_(0,ReqText$)
r.RECT
GetWindowRect_(hwnd,r)
ExamineDesktops()
w = r\right - r\left
h = r\bottom - r\top
x = (DesktopWidth(0) - w)/2
y = (DesktopHeight(0) - h)/2
MoveWindow_(hwnd,x,y,w,h,1)
Next
EndSelect
ProcedureReturn #False
EndProcedure
Hook = SetWindowsHookEx_ ( #WH_CBT , @ HookCB () , GetModuleHandle_ (0) , GetCurrentThreadId_ () )
ReqText$ = "test"
OpenFileRequester ( "test" , "*.*" , "*.*" , 0 )
UnhookWindowsHookEx_( Hook )