Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QM to AL Help
#1
Hi All,
I have a simple menu that worked on windows 10, but now broken on windows 11.
I need to restructure or recode in LibreAutomate.
It's very small and simple but I am just starting out trying to learn c# Any help is much appreciated.
Thanks!


Function The_Menu
Trigger @3     Help - how to add the trigger to the macro
Code:
Copy      Help
\Dialog_Editor

;The_Menu
function# hDlg message wParam lParam
if(hDlg) goto messages
out "This is the Menu"

;int i
str controls = "3"
str lb3
lb3=
;-- Catagory 1 --
;01- QM Website
;02- Libre Automate
;03- LA Topic

if(!ShowDialog("The_Menu" &The_Menu &controls)) ret

;BEGIN DIALOG
;0 "" 0x90CF0AC8 0x20 0 0 224 444 "The Menu"
;3 ListBox 0x54270101 0x200 4 4 216 408 ""
;1 Button 0x54030001 0x4 114 420 48 14 "OK"
;2 Button 0x54030000 0x4 164 420 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C00 "*" "" "" ""

;ret
;messages
int i, ii iii iiii; str lb1004, sTL, sX, sY, sCX, sCY

int x y cx cy

sel message
,
,
,rget sTL "sTL" "Software\GinDi\QM2\Jim"
,case WM_INITDIALOG
,int w30=win("The Menu" "#32770")
,rget sX "sX" "Software\GinDi\QM2\Jim"
,rget sY "sY" "Software\GinDi\QM2\Jim"
,rget sCX "sCX" "Software\GinDi\QM2\Jim"
,rget sCY "sCY" "Software\GinDi\QM2\Jim"
,;out "rGet i = %i[]ii = %i[]iii = %i[]iiii = %i" i ii iii iiii
,i=val(sX)
,ii=val(sY)
,iii=val(sCX)
,iiii=val(sCY)
,
,mov+ i ii iii iiii w30 4    ;; remembered position of The menu.
,;mov+ -1962 35 289 640 w30 4    ;; <-- if enabled, overrides remembered position of The menu.
,
,case WM_SETFONT
,;int hwnd=id(2201 _hwndqm)
,;int+ g_hfont g_hfontprev
,;if(!g_hfontprev) g_hfontprev=SendMessage(hwnd WM_GETFONT 0 0)
,;if(!g_hfont) g_hfont=SetTheFont("Times" 20 700)
,;SendMessage(hwnd WM_SETFONT g_hfont 1)
,;5
,;SendMessage(hwnd WM_SETFONT g_hfontprev 1)
,
,case WM_MOVE
,int w1=win("The Menu" "#32770")
,GetWinXY(w1 x y cx cy)
,sX=x; sY=y
,sCX=cx; sCY=cy
,rset sX "sX" "Software\GinDi\QM2\Jim";; out "sWP is []%s" sWP
,rset sY "sY" "Software\GinDi\QM2\Jim"
,;out "rSet i = %i[]ii = %i[]iii = %i[]iiii = %i" i ii iii iiii
,rset sCX "sCX" "Software\GinDi\QM2\Jim"
,rset sCY "sCY" "Software\GinDi\QM2\Jim"
,
,case WM_DESTROY
,int w61=win("The Menu" "#32770")
,GetWinXY(w61 x y cx cy)
,sX=x; sY=y
,sCX=cx; sCY=cy
,rset sX "sX" "Software\GinDi\QM2\Jim";; out "sWP is []%s" sWP
,rset sY "sY" "Software\GinDi\QM2\Jim"
,rset sCX "sCX" "Software\GinDi\QM2\Jim"
,rset sCY "sCY" "Software\GinDi\QM2\Jim"
,;out "rSet i = %i[]ii = %i[]iii = %i[]iiii = %i" i ii iii iiii
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case 3
,i=LB_SelectedItem(id(3 hDlg)); out i
,lb3.getwintext(id(3 hDlg))
,
,
,
,case IDCANCEL
,case DS_SETFONT
,case LBN_SELCHANGE<<16|3
,_i=LB_SelectedItem(lParam)
,;out "ListBox1: item %i selected" _i
,;LINK LIST
;Category 1
,if _i=01
,,run "https://www.quickmacros.com/" "" "" "" 0x1000    ;; QM
,,err
,if _i=02
,,run "https://www.libreautomate.com/forum/" "" "" "" 0x1000    ;; Forum
,,err
,if _i=03
,,run "https://www.libreautomate.com/forum/forumdisplay.php?fid=8" "" "" "" 0x1000    ;; 16 Resource
,,err
,
,case EN_CHANGE<<16|1002
,;out "Edit text changed. Now it is ''%s''"
,sTL.getwintext(lParam)
,;sTL.getwintext(id(1002 hDlg))
,;w1=win("Master Controls" "#32770")
,;GetWinXY(w1 x y)
,;sX=x; sY=y
,rset sTL "sTL" "Software\GinDi\QM2\Jim"

,
,case LBN_SELCHANGE<<16|3
,
ret 1
#2
In LA, if need to save dialog position and other settings, use code from Cookbook topic "Dialog - save window placement, control values". Then add more code.

WPF ListBox does not have a Click event. This code uses event MouseDoubleClick. Double-click a listbox item to open a web page.

Code:
Copy      Help
// script "The_Menu.cs"
using System.Windows;
using System.Windows.Controls;

using var sett = MySettings.Load();

var b = new wpfBuilder("The Menu").WinSize(400, 800);
b.Row(-1).Add(out ListBox lb);
b.R.Add("Label", out TextBox t, sett.text);
b.R.AddOkCancel();
b.End();

#if WPF_PREVIEW
b.Window.Preview();
#endif

b.WinSaved(sett.placement, o => {
    sett.placement = o;
    sett.text = t.Text;
});


lb.AddItem("-- Catagory 1 --");
lb.AddItem("QM Website", () => run.itSafe("https://www.quickmacros.com/"));

if (!b.ShowDialog()) return;


record class MySettings : JSettings {
    public static readonly string File = folders.ThisAppDocuments + @"The_Menu.json";
    
    public static MySettings Load() => Load<MySettings>(File);
    
    public string placement;
    public string text;
}


static class Ext {
    public static ListBoxItem AddItem(this ListBox t, string text, Action doubleClicked = null) {
        var li = new ListBoxItem { Content = text };
        if (doubleClicked != null) li.MouseDoubleClick += (_, _) => doubleClicked();
        else li.IsEnabled = false;
        t.Items.Add(li);
        return li;
    }
}


Forum Jump:


Users browsing this thread: 1 Guest(s)