I need to add a checkbox

Thanks
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
No checkbox here on XP. Just a standard OpenFileRequester.RASHAD wrote:; Code : OpenFileRequester with "Don't ask me again"
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
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).RASHAD wrote:Previous code updated for XP compat.
Because he edited his posting before he wrote the new posting.MachineCode wrote: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).RASHAD wrote:Previous code updated for XP compat.
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