Posts: 135
Threads: 33
Joined: Aug 2009
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
\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
;\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.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Function dlg_cd_simple_main3
\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
Posts: 135
Threads: 33
Joined: Aug 2009
Thanks for your help.
Why do you use an ActiveX control and not a Static/bitmap control?
Posts: 12,073
Threads: 140
Joined: Dec 2002
It is easier. Web browser control can display images. Don't need to manage scrollbars.
Posts: 12,073
Threads: 140
Joined: Dec 2002
06-06-2015, 07:05 PM
(This post was last modified: 01-28-2019, 10:34 AM by Gintaras.)
Function dialog_ImageScroll_control_example
\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
Posts: 135
Threads: 33
Joined: Aug 2009
Wow! What a nice piece of code! Thank you for your invaluable help.
BTW, congratulations for the new QM version. Best regards.
Posts: 763
Threads: 261
Joined: Jul 2012
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.
Posts: 12,073
Threads: 140
Joined: Dec 2002
I updated function InitWinClass_ImageScroll. Now empty string clears.
Posts: 763
Threads: 261
Joined: Jul 2012
Posts: 1,031
Threads: 246
Joined: Jul 2022
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
|