Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Captionless, movable smart dialog?
#1
Hi all,

I'm building a little catalog app and want to use a captionless dialog but it needs to be movable.

All the item info is in images but they have to be .png format so as far as I can tell I'm stuck using SHDocVw.WebBrowser control to display the images.

I've got the dialog with the control setup no problem but you can't move a captionless window and this just does not look as good as it does captionless.

I found the following example here but I can't figure out how to get it to work.


Gintaras Wrote:Toolbar Toolbar12
Code:
Copy      Help
;/hook TB_MoveLeftButton
button :mes 1

Function TB_MoveLeftButton
Code:
Copy      Help
;/
function# hWnd message wParam lParam

def TB_HITTEST (WM_USER + 69)

int+ g_tb_move_htb g_tb_move_hfore
POINT+ g_tb_move_pos
POINT p

sel message
,case WM_SETCURSOR
,if(lParam=WM_LBUTTONDOWN<<16|HTCLIENT)
,,if(wParam=hWnd)
,,else if(GetDlgCtrlID(wParam)=9999)
,,,GetCursorPos &p; ScreenToClient wParam &p
,,,if(SendMessage(wParam TB_HITTEST 0 &p)>=0) ret ;;button
,,else ret
,,
,,GetCursorPos &g_tb_move_pos
,,g_tb_move_htb=hWnd
,,g_tb_move_hfore=win
,,act hWnd ;;for SetCapture
,,SetCapture hWnd
,
,case [WM_LBUTTONUP,WM_CANCELMODE]
,g_tb_move_htb=0
,SetCapture 0
,act g_tb_move_hfore; err
,
,case WM_MOUSEMOVE
,if(g_tb_move_htb=hWnd)
,,RECT r; GetWindowRect hWnd &r
,,GetCursorPos &p
,,mov r.left+p.x-g_tb_move_pos.x r.top+p.y-g_tb_move_pos.y hWnd
,,g_tb_move_pos=p
,,
,

How do I set the hook like you did in the toolbar? I tried placing the line
Code:
Copy      Help
;/hook TB_MoveLeftButton
to start my smart dialog, tried it to start the macro then called from another mac...I even tried calling the function after a case WM_LBUTTONDOWN event. All I ended up doing was setting a hook at some point that ate all the left mouse events in the QM editor and I had to restart. :?

I'm thinking this might be a bit more of a pain to do because I'm running the dialog as transparent.

Any ideas?
#2
Should have mentioned this is to be compiled.
#3
The dialog function is almost the same as the toolbar hook function, so any additional hooking is not needed. Anyway there is an easy to use function for moving dialogs:

Pseudo tool bar
#4
check the attached qml file.


edit: oops gintaras was faster Confusedhock:


Attached Files
.qml   drag dialog.qml (Size: 1.44 KB / Downloads: 693)
pi
#5
Thanks guys as always QM's got the best support around!!

I thought I remembered an example but when I saw the one I posted I figured that must have been the one I had seen.
#6
Well...

Works great in the example but the browser control is eatting the mouse clicks and in my app the control is actually bigger than the dialog so there is no dialog to click on.

Is there a child/parent relationship I don't have set correctly or any other way this might work?
#7
FUNCTIONS

Function DialogDrag
Code:
Copy      Help
;/
function# hDlg message [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win

;Moves the dialog when the user presses left mouse button on the client area and drags.
;Returns 1 if suscessful, 0 if not (then the message should be passed to the default window procedure).
;The dialog must be a smart dialog, ie with dialog procedure.
;Call this function from the dialog procedure as shown below:


,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message

;To enable moving the dialog by dragging a control, call DialogDragSubclassControl on WM_INITDIALOG.
;If the control has scroll bars, use Ctrl or other modifier key to scroll.



dll user32 #DragDetect hwnd POINT'pt

POINT-- pp_drag
POINT p
RECT r
int-- t_indrag

sel message
,case WM_LBUTTONDOWN
,t_indrag=0
,if(GetMod!=modifiers) ret
,if(GetWinStyle(hDlg)&WS_CHILD) ;;need to detect drag, or the control will not respond to clicks
,,xm p
,,if(!DragDetect(hDlg p))
,,,ScreenToClient hDlg &p
,,,PostMessage hDlg WM_LBUTTONUP 0 p.y<<16|p.x
,,,ret
,xm pp_drag
,SetCapture hDlg
,t_indrag=1
,
,case [WM_LBUTTONUP,WM_CANCELMODE]
,if(!t_indrag or GetCapture!=hDlg) ret
,ReleaseCapture
,t_indrag=0
,
,case WM_MOUSEMOVE
,if(!t_indrag or GetCapture!=hDlg) ret
,hDlg=GetAncestor(hDlg 2) ;;in case hDlg is a subclassed control
,GetWindowRect hDlg &r
,xm p
,mov r.left+p.x-pp_drag.x r.top+p.y-pp_drag.y hDlg
,pp_drag=p

ret 1

Function DialogDragSubclassControl
Code:
Copy      Help
;/
function hwndctrl [modifiers] ;;modifiers: 1 Shift, 2 Ctrl, 4 Alt, 8 Win

;Use this function to subclass a control to enable dialog moving.
;Call it eg under WM_INITDIALOG.



SetProp hwndctrl "qm_wndproc" SetWindowLong(hwndctrl GWL_WNDPROC &DialogDragSubclassProc)
SetProp hwndctrl "qm_modifiers" modifiers

Function DialogDragSubclassProc
Code:
Copy      Help
;/
function# hWnd message wParam lParam

;Used internally in case a control is subclassed. Don't call explicitly.


sel message
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE]
,if(DragDialog(hWnd message GetProp(hWnd "qm_modifiers"))) ret

int wndproc=GetProp(hWnd "qm_wndproc"); if(!wndproc) end
ret CallWindowProc(wndproc hWnd message wParam lParam)

EXAMPLES

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

if(!ShowDialog("DialogDragExample" &DialogDragExample)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Edit 0x54030080 0x200 6 6 96 14 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message
ret
;messages2
sel wParam
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9

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

if(!ShowDialog("DialogDragExample2" &DialogDragExample2)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "Dialog"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 Button 0x54032000 0x0 8 10 54 42 "Drag Me"
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,DialogDragSubclassControl id(3 hDlg) ;;subclass button 3
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message ;;this also can be used
ret
;messages2
sel wParam
,case 3 out "clicked"
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9

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

str controls = "3"
str ax3SHD
ax3SHD="http://www.google.com"
if(!ShowDialog("DialogDragExample3" &DialogDragExample3 &controls)) ret

;BEGIN DIALOG
;0 "" 0x90400A44 0x180 0 0 223 147 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 224 148 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2020008 "" ""


ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam) ;;*
,;subclass web browser
,int hctrl=child("" "Internet Explorer_Server" id(3 hDlg)); if(!hctrl) out "Warning: Web browser control not initialized. Assign an url or ''about:blank'' to the control variable before ShowDialog."; ret
,DialogDragSubclassControl hctrl
,ret 1 ;;*
,case WM_DESTROY DT_DeleteData(hDlg) ;;*
,case WM_COMMAND goto messages2
,;case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE,WM_CANCELMODE] DragDialog hDlg message ;;this also can be used
ret
;messages2
sel wParam
,case IDOK
,DT_Ok hDlg ;;*
,case IDCANCEL DT_Cancel hDlg ;;*
ret 1

;* - not necessary in QM >= 2.1.9
#8
Gintaras you sir are a coding madman Big Grin

And I don't know how to say this but....it's still not working.

I've modified nothing just copy/paste escaped all those functions.

Example one works fine.

Example two when I click on the "drag me" button it kinda blinks a few times then disapears and the only way to drag that example is via the caption bar dragging the client area does not work.

Example three will not drag at all and generates the "Warning" msg in QM output even though I've changed nothing and google loads.

I'm using QM 2.2.0.7 and have noticed some "quirkyness" if you will since upgrading. For instance sometimes when clicking the run button to start a macro it just hangs. The QM icon goes red but the macro never starts. Killing the thread and starting it again always works.

Or a new problem thats just developed is if I click the run button to edit a smart dialog its not working and only on some dialogs others work fine. I've triple checked the code and they all start the same with dialog procedures. I was going to start a new thread but now I'm wondering if this has something to do with it? Should I reinstall or maybe revert versions?

Thank you for all the help Gintaras (you too _pi)!
#9
Sounds like you call DialogDragSubclassControl but still use old DialogDrag.
#10
Quote:Example two when I click on the "drag me" button it kinda blinks a few times then disapears and the only way to drag that example is via the caption bar dragging the client area does not work.

Sounds like you call DialogDragSubclassControl but still use old DialogDrag. Then instead of moving dialog is moved control, and it disappears. New DialogDrag cannot move controls because it gets dialog handle using GetAncestor before moving.


Quote:Example three will not drag at all and generates the "Warning" msg in QM output even though I've changed nothing and google loads.

Maybe it depends on IE version. I tested with IE7. If the message is displayed, it means that the page is still not loaded at that time, and Internet Explorer_Server child window is still not created. Try to use "about:blank" before ShowDialog (instead of google url), and on WM_INITDIALOG use _s.setwintext(id(3 hDlg) "http://www.google.com").

Quote:I'm using QM 2.2.0.7 and have noticed some "quirkyness" ...

Don't know what it could be. Try to install QM 2.2.0.8.
#11
You are the man!

Yes I mistakenly named the new function DialogDrag. *smacks self* :oops:

Thanks again Gintaras.

Any ideas about what might be going on with the two problems I mentioned?
#12
Don't know what it could be. Try to install QM 2.2.0.8.

When dialog editor does not start, does Dialog_Editor is displayed in Threads (assuming no other dialog editor instances are running)?
#13
Quote:when clicking the run button to start a macro it just hangs. The QM icon goes red but the macro never starts. Killing the thread and starting it again always works.

Does it can happen with any macro?
#14
Ah we cross posted...

Yes you were right about the old function it works fine now.

And Although this will pull pages from the web from it stores them locally and views local pages 90% of the time.

You've been a huge help Gin thank you once again.
#15
Gintaras Wrote:
Quote:when clicking the run button to start a macro it just hangs. The QM icon goes red but the macro never starts. Killing the thread and starting it again always works.

Does it can happen with any macro?

I'll have to try running some of the standard macros more to test when I have a chance.
#16
Gintaras Wrote:Don't know what it could be. Try to install QM 2.2.0.8.

When dialog editor does not start, does Dialog_Editor is displayed in Threads (assuming no other dialog editor instances are running)?


No, no threads show up. I can edit the dialog if I go to Dialog on the floating toolbar and select edit this dialog, that works fine.

Oh and It's not just my dialogs some of yours give the same problem.
#17
Please post here one of these dialogs.
#18
Code:
Copy      Help
\Dialog_Editor

function# hDlg message wParam lParam
if(hDlg) goto messages

;BEGIN DIALOG
;0 "" 0x92000A40 0x0 0 0 230 273 "Dialog"
;1 Button 0x54030001 0x0 94 154 48 14 "OK"
;3 ActiveX 0x54000000 0x50000 64 44 248 179 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2020007 "Macro43" ""


ret
;messages
sel message
,case WM_LBUTTONDOWN
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case [WM_LBUTTONDOWN,WM_LBUTTONUP,WM_MOUSEMOVE] DragDialog(hDlg message)
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Macro43 just called this function and passed the page to the browser.
#19
Dialog Editor starts only if the function begins with space or semicolon. It is in all QM versions. It is a quick way to switch between dialog design and run mode - right click the selection bar before \Dialog_Editor. If it begins with space, starts dialog editor, else runs the function.
#20
I'm so not worthy Tongue

I know you have to want to smack me by now Gin but is it possible to make it so that Ctrl+Left Drag is what moves the window? :?
#21
I replaced code in previous post (all three functions). Now can be set modifier keys. Use 2 as third argument of DragDialog (if using dialog to drag) or/and as second argument of DragDialogSubclassControl (if using a control to drag).
#22
They all work great Gintaras thanks man I don't know what I would do without you.

You ever think about writing an OS? :lol:


Forum Jump:


Users browsing this thread: 1 Guest(s)