Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord, hFont As DWord, byteArray() As Byte
%ID_Data = 500
Function PBMain() As Long
Local Style&
Dialog New Pixels, 0, "Test Code",300,300,500,250, %WS_OverlappedWindow To hDlg
style& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %WS_TabStop
Control Add Button, hDlg, 100,"Create From File", 10,10,100,20
Control Add Button, hDlg, 200,"Retrieve Method 1", 10,40,100,20
Control Add Button, hDlg, 300,"Retrieve Method 2", 10,70,100,20
Control Add TextBox, hDlg, %ID_Data,"<result>", 10,100,480,200, Style&
Font New "Courier New" To hFont
Control Set Font hDlg, %ID_Data, hFont
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local temp$, i As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case 100
'create the data lines (put in a string variable, display in TextBox
Control Set Text hDlg, %ID_Data, CreateAsmStringsFromFile("smallface.bmp")
Case 200
'read the data into a byte array
ReadAsmDATA (1) '1=DIM ..AT method, 2 = PEEK method
For i = 1 To UBound(ByteArray)
temp$ = temp$ + Str$(byteArray(i))
Next i
Control Set Text hDlg, %ID_Data, temp$
Case 300
'read the data into a byte array
ReadAsmDATA (2) '1=DIM ..AT method, 2 = PEEK method
For i = 1 To UBound(ByteArray)
temp$ = temp$ + Str$(byteArray(i))
Next i
Control Set Text hDlg, %ID_Data, temp$
End Select
End Select
End Function
Function CreateAsmStringsFromFile(fName$) As String
Local i As Long, temp$
Dim B() As Byte
'read file content into Byte array
Open fName$ For Binary As #1
ReDim B(Lof(1)-1)
Get #1,, B()
Close #1
'create lines
For i = 0 To UBound(B)
If i Mod 40 = 0 Then 'limit width to IDE/compiler constraints
temp$ = temp$ + $CrLf + "!db " 'start a new line
Else
temp$ = temp$ + " &h" + Hex$(B(i),2) + ","
End If
Next i
Function = LTrim$(temp$, $CrLf)
End Function
Sub ReadAsmDATA (iMethod&)
'these put data in byteArray positions 1 to n
Local iSize As Long, iPos as Long
If iMethod& Then
'Method 1: DIM ... AT
iSize = CodePTR(EndData) - CodePTR(StartData)
ReDim byteArray(1 To iSize) As Byte At CodePTR(StartData)
Else
'Method 2:- PEEK
For iPos = CodePTR(StartData) to CodePTR(EndData)-1
byteArray(iPos - CodePTR(StartData) + 1) = Peek(Byte,iPos)
Next i
End If
Exit Sub
startdata:
!db 1,2,3,4,5,6,7,6,5,4,3,2,1
enddata:
End Sub
'gbs_00479
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm