Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying images with scrolling
#1
Hello Gintaras and QM users,

I was trying to display some big images in a scrollable dialog. When I resize the main dialog, the child dialog doesn't resize. How can I fix this?

Thanks for any help.

Function dlg_cd_simple_main2
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

type DCSCONTROLS843 ~controls ~sb6
DCSCONTROLS843 d.controls="6"

d.sb6="$desktop$\Example_1.jpg"

#compile __ChildDialog
ChildDialog- cd
cd.Init(3 "dlg_cd_simple_child2" 0 &d 0 0xffffff)

str controls = "3"

if(!ShowDialog("dlg_cd_simple_main2" &dlg_cd_simple_main2 0)) ret

;BEGIN DIALOG
;0 "" 0x90CC0A48 0x10100 0 0 223 135 "Dialog"
;3 Static 0x44000000 0x0 0 0 223 135 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040300 "*" "" "" ""

ret
;messages
cd.Message(hDlg message wParam lParam)
sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Function dlg_cd_simple_child2
Code:
Copy      Help
;\Dialog_Editor

;BEGIN DIALOG
;0 "" 0x10040440 0x0 0 0 255 255 ""
;6 Static 0x5000000E 0x0 0 0 16 16 ""
;END DIALOG
;DIALOG EDITOR: "DCSCONTROLS843" 0x2040300 "" "" "" ""

;When creating a child dialog, in dialog editor unset most default styles of the dialog.
;Set only WS_VISIBLE (if you need it), DS_CONTROL, and optionally WS_EX_CLIENTEDGE or other style that adds frame.
;Parent dialog style should include WS_EX_CONTROLPARENT. Other styles can be default or as you need.

   
#2
Function dlg_cd_simple_main3
Code:
Copy      Help
\Dialog_Editor

str dd=
;BEGIN DIALOG
;0 "" 0x90CC0A48 0x10100 0 0 226 140 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 226 140 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040300 "*" "" "" ""

str controls = "3"
str ax3SHD
ax3SHD="$desktop$\Example_1.jpg"
;ax3SHD="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 IDOK
,case IDCANCEL
ret 1
#3
Thanks for your help.

Why do you use an ActiveX control and not a Static/bitmap control?
#4
It is easier. Web browser control can display images. Don't need to manage scrollbars.
#5
Function dialog_ImageScroll_control_example
Code:
Copy      Help
\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
Code:
Copy      Help
;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
#6
Wow! What a nice piece of code! Thank you for your invaluable help.

BTW, congratulations for the new QM version. Best regards.
#7
Sorry, could not find how to do this:

How do you clear a QM_ImageScroll, for example if it has ID '3', how do I empty/clear it?
I tried an empty string but that does not seem to work.
#8
I updated function InitWinClass_ImageScroll. Now empty string clears.
#9
THANK YOU!!!
#10
Can add the following functions? 
 1. Use the mouse wheel to scroll pictures up and down 
 2 Hold down the Shift key and use the mouse wheel to scroll pictures left and right

I can't find any mouse wheel event code on the forum. Thank you in advance


Forum Jump:


Users browsing this thread: 2 Guest(s)