Function dialog_ImageScroll_control_example
Function InitWinClass_ImageScroll
\Dialog_Editor
InitWinClass_ImageScroll
str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 224 136 "Dialog"
;3 QM_ImageScroll 0x54000000 0x20000 72 8 144 120 ""
;4 Button 0x54032000 0x0 8 8 48 14 "Browse..."
;5 Button 0x54032000 0x0 8 28 48 14 "Capture"
;6 Button 0x54032000 0x0 8 48 48 14 "Clear"
;1 Button 0x54030001 0x4 8 92 48 14 "OK"
;2 Button 0x54030000 0x4 8 112 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040800 "*" "" "" "3"
str controls = "3"
str qmis3
qmis3="C:\Program Files (x86)\Audacity\help\manual\m\images\1\19\mixer_board.png"
if(!ShowDialog(dd &sub.DlgProc &controls)) ret
#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,DT_SetAutoSizeControls hDlg "3s"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4 ;;Browse
,if(!OpenSaveDialog(0 _s "bmp, png, jpg, gif[]*.bmp;*.png;*.jpg;*.gif[]")) ret
,_s.setwintext(id(3 hDlg))
,
,case 5 ;;Capture
,if(!CaptureImageOrColor(_i 0 hDlg)) ret
,_s=_i
,_s.setwintext(id(3 hDlg))
,
,case 6 ;;Clear
,_s.setwintext(id(3 hDlg))
,
,case IDOK
,case IDCANCEL
ret 1
Function InitWinClass_ImageScroll
;Registers and implements window class "QM_ImageScroll".
;A control of "QM_ImageScroll" class displays an image and can have scrollbars. Supports .bmp, .png, .jpg, .gif files, and bitmap handle.
;Call this function when QM starts, eg in function "init2". In exe - in main function.
;Then controls of the class can be used in dialogs and other windows.
;To add a control to a dialog, in Dialog Editor click "Other controls", type "QM_ImageScroll", OK.
;To set image file path, use a dialog variable or str.setwintext.
;You can use a bitmap handle as control text. The control will delete the bitmap when destroyed. The bitmap must be not selected in a DC.
__RegisterWindowClass+ ___ImageScroll_class.Register("QM_ImageScroll" &sub.WndProc 4 0 CS_GLOBALCLASS)
#sub WndProc
function# hWnd message wParam lParam
;OutWinMsg message wParam lParam
type __IMAGESCROLL __MemBmp'b cx cy
__IMAGESCROLL* d
sel message
,case WM_NCCREATE SetWindowLong hWnd 0 d._new
,case WM_NCDESTROY d._delete
,case else d=+GetWindowLong(hWnd 0)
sel message
,case WM_SETTEXT sub.SetText hWnd d +lParam
,case WM_SIZE sub.SetScroll hWnd d 0
,case [WM_VSCROLL,WM_HSCROLL] sub.Scroll(hWnd message wParam d)
,
,case WM_PAINT
,if d.b.bm
,,PAINTSTRUCT ps; BeginPaint(hWnd &ps)
,,BitBlt ps.hDC 0 0 d.cx d.cy d.b.dc 0 0 SRCCOPY
,,EndPaint hWnd &ps
int R=DefWindowProcW(hWnd message wParam lParam)
ret R
#sub SetText
function hWnd __IMAGESCROLL&d word*wName
if wName=0 or wName[0]=0
,d.b.Delete; d.cx=0; d.cy=0
,goto gr
_s.ansi(wName)
;out _s
int hb=val(_s 0 _i) ;;handle
if(!(hb and _i=_s.len)) hb=LoadPictureFile(_s); if(!hb) ret
BITMAP _b; if(!GetObjectW(hb sizeof(BITMAP) &_b)) ret
d.b.Attach(hb)
d.cx=_b.bmWidth; d.cy=_b.bmHeight
;gr
sub.SetScroll hWnd d 1
#sub SetScroll
function hWnd __IMAGESCROLL&d !erase
RECT r; GetClientRect(hWnd &r)
SCROLLINFO si.cbSize=sizeof(si)
si.fMask=SIF_RANGE|SIF_PAGE|SIF_POS
si.nMax=d.cy; si.nPage=r.bottom; SetScrollInfo hWnd SB_VERT &si 0
si.nMax=d.cx; si.nPage=r.right; SetScrollInfo hWnd SB_HORZ &si 0
SetViewportOrgEx d.b.dc 0 0 0
InvalidateRect hWnd 0 erase
#sub Scroll
function hWnd message wParam __IMAGESCROLL&d
int H(message=WM_HSCROLL) SB scpage scmax x y code(wParam&0xffff) pos(wParam>>16) ppos
RECT r; GetClientRect(hWnd &r)
if(H) SB=SB_HORZ; scpage=r.right; scmax=d.cx-scpage
else SB=SB_VERT; scpage=r.bottom; scmax=d.cy-scpage
ppos=GetScrollPos(hWnd SB)
sel code
,case SB_THUMBTRACK
,case SB_LINEDOWN pos=ppos+16
,case SB_LINEUP pos=ppos-16
,case SB_PAGEDOWN pos=ppos+scpage
,case SB_PAGEUP pos=ppos-scpage
,case else ret
if(pos<0) pos=0; else if(pos>scmax) pos=scmax
SetScrollPos(hWnd SB pos 1); pos=GetScrollPos(hWnd SB) ;;setscrollpos may not set correctly
_i=pos-ppos; if(H) x=_i; else y=_i
if x|y
,OffsetViewportOrgEx d.b.dc x y 0
,InvalidateRect hWnd 0 0