Page 1 of 1
OpenFileRequester question
Posted: Fri Oct 07, 2011 9:06 am
by Joestes
Is there any way to add gadgets to the OpenFileRequester?
I need to add a checkbox

Or do I just need to create my own requester?
Thanks
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 9:29 am
by Shield
It is possible but only by using the WinAPI. If I remember correctly,
there should be an example in the Code Archive.
Unfortunately I can't provide any code now because I don't have PB installed here.
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 10:14 am
by Joestes
You're absolutely right, I found it in the Code Archive!
Thank you for pointing that out!!
Regards
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 10:38 am
by Joestes
However... This window looks completely diffrent than the one used by PureBasic...
Does anyone know how to reproduce that one?
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 11:32 am
by RASHAD
Code: Select all
; *****************************************************
; Code : OpenFileRequester with "Don't ask me again"
; Author : Sparkie
; Modified: RASHAD
; Date : November 18, 2006
; OS : Windows only
; License : It's all yours to use as you so desire
; (props/credit would be nice)
; *****************************************************
Global hHook.l = 0, oldProc.l = 0, askagain.l = 0
;...Make sure Checkbox ID <> any of the other MessageRequester buttons
#CheckBoxID = 12
;...Subclassed MessageRequester Procedure()
Procedure MsgBoxProc(hwnd.l, msg.l, wParam.l, lParam.l)
result.l = CallWindowProc_(oldProc, hwnd, msg, wParam, lParam)
Select msg
Case #WM_DESTROY
;...Get handle to our checkbox
hCheckBox.l = GetDlgItem_(hwnd, #CheckBoxID)
;...Get the checkbox state. <0 = not checked> <1 = checked>
;...For this test I'll set a Global var to = CheckBox state
;...In a real app you could set the value in a config/ini file
;...or maybe a use a Registry setting
askagain = SendMessage_(hCheckBox, #BM_GETCHECK, 0, 0)
EndSelect
ProcedureReturn result
EndProcedure
;...Our hook Procedure()
Procedure CBTProc(nCode.l, wParam.l, lParam.l)
result.l = CallNextHookEx_(hHook, nCode,wParam,lParam)
If nCode = #HCBT_ACTIVATE
hMsgBox.l = wParam
oldProc = SetWindowLong_(hMsgBox, #GWL_WNDPROC, @MsgBoxProc())
hFont.l = GetStockObject_(#DEFAULT_GUI_FONT)
StartDrawing(WindowOutput(0))
DrawingFont(hFont)
cbWidth = TextWidth("Don't ask me this again.") + 22 ; add room for checkbox
cbHeight = TextHeight("Don't ask me this again.")
StopDrawing()
;...Determine Checkbox placement
GetWindowRect_(hMsgBox, @winRC.RECT)
pt.POINT\x = winRC\left
pt.POINT\y = winRC\bottom
ScreenToClient_(hMsgBox, pt)
cbX = 20
cbY = (pt\y - cbHeight) + 60
hCheckBox.l = CreateWindowEx_(0, "Button", "Don't ask me this again.", #BS_AUTOCHECKBOX | #BS_TEXT | #WS_GROUP | #WS_TABSTOP | #WS_CHILD | #WS_VISIBLE, cbX, cbY, cbWidth, cbHeight, hMsgBox, #CheckBoxID, GetModuleHandle_(0), 0)
SendMessage_(hCheckBox, #WM_SETFONT, hFont, 0)
;...Release the hook
UnhookWindowsHookEx_(hHook)
hHook = 0
result = 0
EndIf
ProcedureReturn result
EndProcedure
Procedure AskAgainRequester()
hHook = SetWindowsHookEx_(#WH_CBT, @CBTProc(), 0, GetCurrentThreadId_())
If hHook
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0
result$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, -300, 0, 0, 0, "")
AskAgainRequester()
EndIf
;...Just in case it's still there
If hHook
UnhookWindowsHookEx_(hHook)
hHook = 0
EndIf
End
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 11:35 am
by MachineCode
RASHAD wrote:; Code : OpenFileRequester with "Don't ask me again"
No checkbox here on XP. Just a standard OpenFileRequester.
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 11:51 am
by Joestes
Thanks Rashad!
Is there any way to change the text on the button?
I want to change "Open" in something else...

Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 2:15 pm
by RASHAD
@MachineCode
I will see what I can do
@Joestes
Code: Select all
; *****************************************************
; Code : OpenFileRequester with "Don't ask me again"
; Author : Sparkie ,Hroudtwolf
; Modified: RASHAD
; Date : November 18, 2006
; OS : Windows only
; License : It's all yours to use as you so desire
; (props/credit would be nice)
; *****************************************************
Global hHook.l = 0, oldProc.l = 0, askagain.l = 0
#CheckBoxID = 12
Structure tDLGHook
hHook.i
sExpr.s [ $FF ]
EndStructure
this.tDLGHook
Procedure DLG_Hook()
Static this.tDLGHook
ProcedureReturn this
EndProcedure
Procedure DLGHook_SetExpression ( idDLGItem.i , sText.s )
Protected *this.tDLGHook = DLG_Hook ()
*this\sExpr [ idDLGItem ] = sText
ProcedureReturn #Null
EndProcedure
;...Subclassed MessageRequester Procedure()
Procedure MsgBoxProc(hwnd.l, msg.l, wParam.l, lParam.l)
result.l = CallWindowProc_(oldProc, hwnd, msg, wParam, lParam)
Select msg
Case #WM_DESTROY
;...Get handle to our checkbox
hCheckBox.l = GetDlgItem_(hwnd, #CheckBoxID)
;...Get the checkbox state. <0 = not checked> <1 = checked>
;...For this test I'll set a Global var to = CheckBox state
;...In a real app you could set the value in a config/ini file
;...or maybe a use a Registry setting
askagain = SendMessage_(hCheckBox, #BM_GETCHECK, 0, 0)
EndSelect
ProcedureReturn result
EndProcedure
;...Our hook Procedure()
Procedure CBTProc(nCode.l, wParam.l, lParam.l)
Protected *this.tDLGHook = DLG_Hook()
Protected sBuffer.s = Space ( $FF )
result.l = CallNextHookEx_(hHook, nCode,wParam,lParam)
If nCode = #HCBT_CREATEWND
*cbt_cw.CBT_CREATEWND = lParam
*lpcs.CREATESTRUCT = *cbt_cw\lpcs
;...Take action only if this is our MessageRequester
If *lpcs\lpszClass = 32770
;...Resize the MessageRequester to make room for our CheckBoxGadget
*lpcs\cy + 20
EndIf
result = 0
EndIf
If nCode = #HCBT_ACTIVATE
For nI = 0 To $FE
If *this\sExpr [ nI ] And GetDlgItemText_( wParam , nI , @ sBuffer , $FF )
SetDlgItemText_( wParam , nI , *this\sExpr [ nI ] )
EndIf
Next nI
hMsgBox.l = wParam
oldProc = SetWindowLong_(hMsgBox, #GWL_WNDPROC, @MsgBoxProc())
hFont.l = GetStockObject_(#DEFAULT_GUI_FONT)
StartDrawing(WindowOutput(0))
DrawingFont(hFont)
cbWidth = TextWidth("Don't ask me this again.") + 22 ; add room for checkbox
cbHeight = TextHeight("Don't ask me this again.")
StopDrawing()
;...Determine Checkbox placement
GetWindowRect_(hMsgBox, @winRC.RECT)
pt.POINT\x = winRC\left
pt.POINT\y = winRC\bottom
ScreenToClient_(hMsgBox, pt)
If OSVersion() = #PB_OS_Windows_XP
cbX = 100
cbY = pt\y - cbHeight - 40
Else
cbX = 20
cbY = pt\y - cbHeight + 25
EndIf
hCheckBox.l = CreateWindowEx_(0, "Button", "Don't ask me this again.", #BS_AUTOCHECKBOX | #BS_TEXT | #WS_GROUP | #WS_TABSTOP | #WS_CHILD | #WS_VISIBLE, cbX, cbY, cbWidth, cbHeight, hMsgBox, #CheckBoxID, GetModuleHandle_(0), 0)
SendMessage_(hCheckBox, #WM_SETFONT, hFont, 0)
;...Release the hook
UnhookWindowsHookEx_(hHook)
hHook = 0
result = 0
EndIf
ProcedureReturn result
EndProcedure
Procedure AskAgainRequester()
hHook = SetWindowsHookEx_(#WH_CBT, @CBTProc(), 0, GetCurrentThreadId_())
If hHook
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0
result$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)
EndIf
ProcedureReturn result
EndProcedure
If OpenWindow(0, -300, 0, 0, 0, "")
DLGHook_SetExpression ( #IDOK , "OK to Open" )
AskAgainRequester()
EndIf
;...Just in case it's still there
If hHook
UnhookWindowsHookEx_(hHook)
hHook = 0
EndIf
End
Re: OpenFileRequester question
Posted: Fri Oct 07, 2011 4:29 pm
by RASHAD
Previous code updated for XP compat.
Re: OpenFileRequester question
Posted: Sat Oct 08, 2011 2:20 am
by MachineCode
RASHAD wrote:Previous code updated for XP compat.
Which code? Both sources in this thread still don't show a checkbox on XP, and they're not marked as "Edited" by phpBB (unless you're a secret moderator).
Re: OpenFileRequester question
Posted: Sat Oct 08, 2011 9:47 am
by Lord
MachineCode wrote:RASHAD wrote:Previous code updated for XP compat.
Which code? Both sources in this thread still don't show a checkbox on XP, and they're not marked as "Edited" by phpBB (unless you're a secret moderator).
Because he edited his posting before he wrote the new posting.
Re: OpenFileRequester question
Posted: Sat Oct 08, 2011 10:14 am
by MachineCode
Now it works with XP. Good job.
Re: OpenFileRequester question
Posted: Sun Oct 09, 2011 3:59 am
by RASHAD
Revised
Taking Size/Move into consideration
Code: Select all
; *****************************************************
; Code : OpenFileRequester with "Don't ask me again"
; Author : Sparkie ,Hroudtwolf
; Modified: RASHAD
; Date : November 18, 2006
; OS : Windows only
; License : It's all yours to use as you so desire
; (props/credit would be nice)
; *****************************************************
Global hHook.l = 0, oldProc.l = 0, askagain.l = 0,hCheckBox.l
#CheckBoxID = 12
Structure tDLGHook
hHook.i
sExpr.s [ $FF ]
EndStructure
this.tDLGHook
Procedure DLG_Hook()
Static this.tDLGHook
ProcedureReturn this
EndProcedure
Procedure DLGHook_SetExpression ( idDLGItem.i , sText.s )
Protected *this.tDLGHook = DLG_Hook ()
*this\sExpr [ idDLGItem ] = sText
ProcedureReturn #Null
EndProcedure
Procedure MsgBoxProc(hwnd.l, msg.l, wParam.l, lParam.l)
result.l = CallWindowProc_(oldProc, hwnd, msg, wParam, lParam)
Select msg
Case #WM_DESTROY
hCheckBox.l = GetDlgItem_(hwnd, #CheckBoxID)
askagain = SendMessage_(hCheckBox, #BM_GETCHECK, 0, 0)
Case #WM_SIZE,#WM_MOVE,#WM_PAINT
GetWindowRect_(FindWindow_("#32770",0), r.RECT)
p.POINT\x = r\left
p.POINT\y = r\bottom
ScreenToClient_(FindWindow_("#32770",0), p)
If OSVersion() = #PB_OS_Windows_XP
cbX = p\x + 104
cbY = p\y - 31
Else
cbX = p\x + 30
cbY = p\y - 40
EndIf
MoveWindow_(hCheckBox,cbX,cbY,140,20,1)
EndSelect
ProcedureReturn result
EndProcedure
Procedure CBTProc(nCode.l, wParam.l, lParam.l)
Protected *this.tDLGHook = DLG_Hook()
Protected sBuffer.s = Space ( $FF )
result.l = CallNextHookEx_(hHook, nCode,wParam,lParam)
Select nCode
Case #HCBT_CREATEWND
*cbt_cw.CBT_CREATEWND = lParam
*lpcs.CREATESTRUCT = *cbt_cw\lpcs
If *lpcs\lpszClass = 32770 And OSVersion() = #PB_OS_Windows_XP
*lpcs\cy + 25
EndIf
result = 0
Case #HCBT_ACTIVATE
For nI = 0 To $FE
If *this\sExpr [ nI ] And GetDlgItemText_( wParam , nI , @ sBuffer , $FF )
SetDlgItemText_( wParam , nI , *this\sExpr [ nI ] )
EndIf
Next nI
hMsgBox.l = wParam
oldProc = SetWindowLong_(hMsgBox, #GWL_WNDPROC, @MsgBoxProc())
hFont.l = GetStockObject_(#DEFAULT_GUI_FONT)
hCheckBox.l = CreateWindowEx_(0, "Button", "Don't ask me this again.", #BS_AUTOCHECKBOX | #BS_TEXT | #WS_GROUP | #WS_TABSTOP | #WS_CHILD | #WS_VISIBLE, 0, 0, 140, 20, hMsgBox, #CheckBoxID, GetModuleHandle_(0), 0)
SendMessage_(hCheckBox, #WM_SETFONT, hFont, 0)
UnhookWindowsHookEx_(hHook)
hHook = 0
result = 0
EndSelect
ProcedureReturn result
EndProcedure
Procedure AskAgainRequester()
hHook = SetWindowsHookEx_(#WH_CBT, @CBTProc(), 0, GetCurrentThreadId_())
If hHook
Pattern$ = "Text (*.txt)|*.txt;*.bat|PureBasic (*.pb)|*.pb|All files (*.*)|*.*"
Pattern = 0
result$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)
EndIf
ProcedureReturn result
EndProcedure
DLGHook_SetExpression ( #IDOK , "OK to Open" )
AskAgainRequester()
If hHook
UnhookWindowsHookEx_(hHook)
hHook = 0
EndIf
End