Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maximizing and Resizing Dialog
#1
How do I allow maximizing and resizing of dialogs? I can maximize the entire window but the edit control and buttons won't resize along with it. 

This may have been asked before. Can't find anything about this in the program documentation and I've tried Styles in the Dialog Editor to no avail yet.
#2
Search for dt_SetautosizeControls or something like that not at my pc
#3
Here you have a full example, I had this lying around.
It contains a simple multiline inputfield which resizes with the dialog.
Compile this to .exe to make the systray icon appear. (you have to first check a setting in the compile to exe dialog, read below green comment)
When you minimized the dialog you can left click on the systray icon to make it re appear.

Read the green comments for further instructions/info.

This can probably be done much better/cleaner it is meant as a starting point for you.
Create a new smart dialog and copy and paste all the below code over the existing code then compile to exe and run it.
(you do not have to run the .exe you can run the code itself, it just has to be compiled to exe once this is to make the icon appear)


Function autosize_test_dlg
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 224 136 "Dialog"
;3 Edit 0x54231044 0x200 0 0 225 138 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

str controls = "3"
str e3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,int- dlg_id
,,dlg_id=hDlg ;; Put the id of th dialog in this variable
,,;;........................................................
,,;;. The below code is for resizing the multiline inputfield
,,;;[1]...............................................
,,
,,;; 1. Go to dialog editor and click on the dialog, the red dot needs to be on the dialog! (NOT a on a control within in the dialog)
,,;; 2. In dialog editor, above from the left click on the third icon next to the i- icon (it has a small red check mark at top left)
,,;; 3. In the next dialog that appears (that has all the dialog styles) click on 'WS_THICKFRAME' (if you want minimize/maximize, also click on 'WS_MINIMIZEBOX' and 'WS_MAXIMIZEBOX')
,,;; 4. Below line, press [F1] on  light blue function, 3s ==> '3'=control ID  's'=resize
,,
,,DT_SetAutoSizeControls hDlg "3s"
,,
,,;;........................................................
,,;;. The below code is for showing a systray icon and a simple menu when click on the systray icon.
,,;;. You can ignore (delete) it, if you do not need it.
,,;;[2]...............................................
,,
,,
,,
,,;; 1. replace 'shell32.dll,9' in 'str icons=' with path to .ico, example: 'x:\path\to\some_icon.ico'
,,;; 2. compile this application to .exe
,,;;    In the compile to exe dialog, check the checkbox: "Auto add file used in macro if resource id specified...."
,,;; - When you run this dialog with 'shell32.dll,9' specified as icon, you will see a default icon (probably network icon) as the systray icon
,,;; - you can right click the systray and 2 menu items appear 'test 1' and 'test 2' when you select of them it will output 'test 1' or 'test 2'
,,;; - [CONTROL]+right clicking the systray icon closes/exists this dialog
,,;; - A left click on the systray icon activates this dialog (minimize the dialog then press the systray icon)
,,str icons=
,,;:97 shell32.dll,9
,,;
,,Tray- t.AddIcon(":97" "dialog title" 0 &sub.TrayCallback) ;; You can change "dialog title", this will be displayed when you hover over the systray icon
,,
,,;; Or in stead of 'sub.TrayCallback' you can use an external function, below I used 'autosize_test_dlg_SystrayClick'
,,;; create function 'autosize_test_dlg_SystrayClick' and put code of above 'sub.TrayCallback' in it
,,;; Tray- t.AddIcon(":97" "dialog title" 0 &autosize_test_dlg_SystrayClick)
,,
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1



#sub TrayCallback
function Tray&x message

;Callback function for Tray.AddIcon.
;Called for each received message - when tray icon clicked, or mouse moved.
;
;x - reference to this object.
;message - mouse message (WM_MOUSEMOVE, WM_LBUTTONDOWN, etc).


;OutWinMsg message 0 0 ;;uncomment to see received messages
int- dlg_id ;; This is the id of the dialog
sel message
,case WM_LBUTTONUP
,,act dlg_id

,case WM_RBUTTONUP
,,sel GetMod
,,,case 0 ;; NORMAL RIGHT CLICK ON SYSTRAY ICON
,,,,sub.OnTrayIconRightClick x.param
,,,case 2 ;; [CTRL]+ SYSTRAY CLICK CLOSES THIS APPLICATION
,,,,shutdown -7



,case WM_MBUTTONUP
,;out "middle click"


;;........................................................
;;. GETMOD
;;[JIDM955]...............................................
;
;#GetMod ;;Returns: 1 Shift, 2 Ctrl, 4 Alt, 8 Win.
;Checks whether modifier keys are pressed. The return value is combination of the following values: 1 - Shift is pressed, 2 - Ctrl is pressed, 4 - Alt is pressed, 8 Win is pressed. For example, if Ctrl and Alt are pressed, the return value is 6.
;;;
;Example
;if(GetMod&2) out "Ctrl pressed"
;;;
;---------------------------------
;
;FormatKeyString !vk !mod str&s ;;mod:   1 Shift, 2 Ctrl, 4 Alt, 8 Win.
;Gets key name for a key and/or modifiers. The text will be like "Ctrl+Page Up".
;;;;
;vk - virtual-key code.
;mod - modifiers. See GetMod.
;s - variable that receives the text. If the variable initially is not empty, appends to the end.


#sub OnTrayIconRightClick

function param

;created and can be edited with the Menu Editor
int- dlg_id
str md=
;BEGIN MENU
;Test 1 :601
;Test 2 :602
;END MENU

int i=ShowMenu(md)
if(i=601)out "Test 1"
if(i=602)out "Test 2"
#4
Wow Ron this is great thank you so much!

Working very smoothly. Guess I now got some reading and studying to do to apply this to my own dialogs ;-)

Much obliged.
#5
much simpler way add a tray icon. With a dialog can use 

case WM_USER+101 for the tray icon actions

no need to make exe and no subfunctions

also includes simple autosize controls example

Function DialogExample
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x0 0 0 224 136 "Dialog"
;4 Edit 0x54231044 0x200 8 24 198 84 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040800 "*" "" "" ""

str controls = "4"
str e4
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam
Tray-- t_ti
sel message
,case WM_INITDIALOG
,t_ti.AddIcon("$qm$\dialog.ico" "this is the tray icon tooltip" 1 hDlg)
,DT_SetAutoSizeControls(hDlg "1m 2m 4s")
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_USER+101
,sel lParam
,,case WM_LBUTTONUP ;;on left click tray icon
,,act hDlg;;Show dialog
,,case WM_RBUTTONUP ;;on right click tray icon
,,;;the if else code block below will vary the tray icon right click menu depending on if dialog is visable or not
,,if !IsWindowVisible(hDlg)
,,,sel ShowMenu("1 Show[]2 Exit" hDlg)
,,,,case 1 act hDlg;;Show dialog
,,,,case 2 DT_EndDialog hDlg;;;;Close dialog
,,else
,,,sel ShowMenu("1 Hide[]2 Exit" hDlg)
,,,,case 1 hid hDlg;;Hide dialog
,,,,case 2 DT_EndDialog hDlg;;;;Close dialog
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#6
Way cool Kevin, Thanks! This works like a charm and seems a bit easier indeed.


Forum Jump:


Users browsing this thread: 1 Guest(s)