Maybe someone could help to improve:
- remove the console window (starting with #PB_Program_Hide is no option, for you won't see the camera selector dialog, too)
- invoke the camera selector dialog
- show detection frame (as usually shown by zbarlib)
- use libzbar-0.dll instead of cmd line tool
Code: Select all
;- Scan Barcode using ZBar barcode cmdline tool
;- https://zbar.sourceforge.net/download.html
; Compile with option threadsafe enabled
Structure tScan
iMainWindow.i
sResult.s
EndStructure
Enumeration #PB_Event_FirstCustomValue+$ff
#event_qrcode
EndEnumeration
Procedure ScanQRCode(*t.tscan)
Define.RECT WinPos
Define.l Scanner, ZBarHandle, SizeX, SizeY
Protected sret$
sparams$="--prescale="+WindowWidth(*t\iMainWindow)+"x"+WindowHeight(*t\iMainWindow)
Scanner = RunProgram(GetPathPart(ProgramFilename())+"zbarcam.exe",sparams$,"",#PB_Program_Open | #PB_Program_Read)
Delay(100)
If IsProgram(scanner)
SetParent_(ProgramID(Scanner),WindowID(*t\iMainWindow))
While Not FindWindow_(0,"ZBar") And ProgramRunning(Scanner)
Delay(10)
Wend
EndIf
ZBarHandle = FindWindow_(0,"ZBar")
SetWindowLongPtr_(ZBarHandle, #GWL_STYLE, GetWindowLongPtr_(ZBarHandle, #GWL_STYLE) ! (#WS_DLGFRAME | #WS_BORDER | #WS_SIZEBOX))
SetParent_(ZBarHandle,WindowID(*t\iMainWindow))
MoveWindow_(ZBarHandle,0,0,WindowWidth(*t\iMainWindow),WindowHeight(*t\iMainWindow),#True)
;ShowWindow_(ZBarHandle,#SW_SHOWNORMAL)
If IsProgram(scanner)
While ProgramRunning(Scanner)
If AvailableProgramOutput(Scanner)
sret$ =ReadProgramString(Scanner)
If StringField(UCase(sret$),1,":")="QR-CODE"
sret$=Right(sret$,Len(sret$)-8)
*t\sResult=sret$
Beep_(100,100)
PostEvent(#event_qrcode ,*t\iMainWindow,#Null)
EndIf
EndIf
If IsWindow(*t\iMainWindow)=#False
Break
EndIf
Wend
If IsProgram(scanner)
KillProgram(scanner)
EndIf
EndIf
CloseWindow_(ZBarHandle)
EndProcedure
Define tScanInfo.tScan
iScannerWindow=OpenWindow(#PB_Any,0,0,640,480,"Barcode Scannen",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
tScanInfo\imainwindow=iScannerWindow
CreateThread(@Scanqrcode(),@tScanInfo)
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #event_qrcode
Debug tScanInfo\sResult
Case #PB_Event_CloseWindow
CloseWindow(iScannerWindow)
bExit=1
EndSelect
Until bExit=#True