Zhorn Software
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Orest
Posts : 3
Join date : 2024-07-07

How to toggle Stickies note size between 420x316 and 840x960? Empty How to toggle Stickies note size between 420x316 and 840x960?

Sun Jul 07, 2024 10:31 am
Hello, Stickies users!

I'm looking for a way to implement a quick toggle function for a sticky note between two specific sizes:

- Small size: 420x316
- Large size: 840x960

Requirements:
1. Instant switching between sizes (no stretch animation).
2. Activation via hotkeys or a button on the sticky note.
3. Preserve visibility of all text when changing size.

An attempt with AutoHotkey failed: when expanding from 420x316 to 840x960, only part of the text is displayed. For example, if 10 lines of text are visible in the smaller size, after expansion the window becomes larger, but still shows only those 10 lines, with the rest of the field remaining empty. However, if you stretch the window manually with the mouse, all 20 lines of text become visible. The problem occurs only when using AutoHotkey to change the size.

Is it possible to implement such a function in Stickies?
How can we implement switching between these two sizes so that the sticky note changes size instantly and displays all text correctly? Is there a way to do this without glitches or errors?
Thanks for any help!
avatar
guest_today
Posts : 126
Join date : 2022-12-29

How to toggle Stickies note size between 420x316 and 840x960? Empty Re: How to toggle Stickies note size between 420x316 and 840x960?

Mon Jul 08, 2024 3:26 pm
You are using AHK so you can use the API calls to set parameters using WM_COPYDATA function . You can find info here:

https://www.zhornsoftware.co.uk/stickies/api.html

There is a demo  api.exe to try out some api calls but the first must be :     do register

https://www.zhornsoftware.co.uk/stickies/api/sample_cpp.zip  ( the exe is in the Release folder ) .

The string send to stickies is ansi not unicode so i had to change the example in the ahk helpfile ( i use V1 !! ).

To get the stickies ID you can use the windows title of the sticky and extract the ID ( regex ).

Code:
Receive_WM_COPYDATA(wParam, lParam)
  {
    Global datastring ,CopyOfData
    ID                := NumGet(lParam + 0)
    len               := NumGet(lParam + A_PtrSize)
    StringAddress     := NumGet(lParam + 2*A_PtrSize)

    VarSetCapacity(CopyOfData, len,0)
    CopyOfData:= StrGet(StringAddress,len,"cp0")


    Ifinstring,CopyOfData,will send
        SoundBeep

    datastring:= CopyOfData
    return true
  }

Send_(StringToSend,IDc)
  {
    global TargetScriptTitle


    DetectHiddenWindows On
    SetTitleMatchMode 2

    VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)

    StringToSend=api %StringToSend%
    len := StrPutVar(StringToSend, StringToSend, "cp0")+1

    NumPut(IDc          , CopyDataStruct, 0)
    NumPut(len , CopyDataStruct, 4)
    NumPut(&StringToSend, CopyDataStruct,

    SendMessage, 0x4a, %A_ScriptHwnd%, &CopyDataStruct,, %TargetScriptTitle%

    If (errorlevel="fail")
      {
        MsgBox SendMessage failed. Does the target application runs?

      }

    return
  }

StrPutVar(string, ByRef var, encoding)
  {
    VarSetCapacity(var, StrPut(string, encoding) * ((encoding="UTF-16"||encoding="CP1200") ? 2 : 1))
    return StrPut(string, &var, encoding)
  }

Orest likes this post

avatar
Orest
Posts : 3
Join date : 2024-07-07

How to toggle Stickies note size between 420x316 and 840x960? Empty Re: How to toggle Stickies note size between 420x316 and 840x960?

Wed Jul 10, 2024 4:58 am
Thank you, I will study your method later as it is better than what I have done. I might still reach out for help to learn how to do it properly. Currently, I used AutoHotkey. I noticed that when I expand or shrink the size of the window, the text appears across the entire text area. Therefore, I made it so that when the size increases, it first expands to the right, then shrinks to the left, and everything is fine. Similarly, when I reduce the window size, it first moves to the right, then to the left, and the text is in place. It happens so quickly that I barely notice it.
Here is the code.
ahk

Копіювати код

Code:
; AutoHotkey Script

; Stores window positions and sizes in a dictionary
global WindowData := {}

; Function to save window position and size
SaveWindowData(WinID) {
    global WindowData
    WinGetPos, X, Y, Width, Height, ahk_id %WinID%
    WindowData[WinID] := [X, Y, Width, Height]
}

; Function to restore window position with fixed size
RestoreWindowData(WinID) {
    global WindowData
    if (WinID in WindowData) {
        X := WindowData[WinID][1]
        Y := WindowData[WinID][2]
        WinMove, ahk_id %WinID%, , X, Y, 420, 316
        Sleep, 100 ; Small delay to ensure the window resized
        Send, ^!{Right} ; Send Ctrl+Alt+Right Arrow
        Sleep, 100 ; Another delay before the next resize
        WinMove, ahk_id %WinID%, , X, Y, 420, 316 ; Resize again to 420x316
    }
}

; Resize to 840x960 and position at 415+38, 28, then send Ctrl+Alt+Right Arrow
^+S:: ; Ctrl + Shift + S
    WinGet, active_id, ID, A
    SaveWindowData(active_id)
    WinMove, ahk_id %active_id%, , 434, 28, 840, 960 ; 453 = 415 + 38 (1 cm to the right)
    Sleep, 100 ; Small delay to ensure the window resized
    Send, ^!{Right} ; Send Ctrl+Alt+Right Arrow
return

; Restore original position with fixed size 420x316
^+D:: ; Ctrl + Shift + D
    WinGet, active_id, ID, A
    RestoreWindowData(active_id)
return
avatar
guest_today
Posts : 126
Join date : 2022-12-29

How to toggle Stickies note size between 420x316 and 840x960? Empty Re: How to toggle Stickies note size between 420x316 and 840x960?

Wed Jul 10, 2024 2:22 pm
Resizing a sticky window has its side effects , it is not a " standard " window because of the skin elements . The use of the api calls overcomes this problem but the code is more complicated . But once you get the basic of sending the commands using WM_COPYDATA its very easy to code whatever you like to do with the stickies , its just one line with the command and parameters .

I only get the code to work with 32bit ahk ( stickies is 32bit ) and i have not the knowledge to find a solution for using 64bit ahk . If you want to use it with an installed 64 ahk you could rename the autohotkey32u.exe with the name of the ahk file you want to run as 32bit , running this renamed exe will look for a similar named ahk and run it . ( or you can compile it as 32bit)

Here is a demo of the the code for resizing with a debug window to see the return values send by stickies . If you have any idea why it does not work with 64ahk can you let me know ?

Code:

#noenv
SetTitleMatchMode, slow
DetectHiddenWindows On
SetTitleMatchMode 2
setworkingdir:=a_scriptdir

 msgbox ahk version :  %A_AhkVersion%   ; tested with ahk 32bit unicode

;*************** debug window **********
Gui, +AlwaysOntop
Gui,add,edit,w250
Gui,show, x100 y100 ,debug_window
; **************************************

TargetScriptTitle = ZhornSoftwareStickiesMain

OnMessage(0x4a, "Receive_WM_COPYDATA")
send_("do register",20)
return


F4::    
;  get ID from active sticky title
WinGetActiveTitle,title
ID := regexreplace(title,"\D")

msgbox,4,, %ID% ,2  ; just for debugging the ID must be an integer number

;  set dimensions

StringToSend = set desktop %ID% size 500x500
send_(StringToSend , 20)
return


esc::ExitApp


Receive_WM_COPYDATA(wParam, lParam)
{
      Global DataString ,edit1
      ID                := NumGet(lParam + 0)
      len               := NumGet(lParam + A_PtrSize)
    StringAddress     := NumGet(lParam + 2*A_PtrSize)
  
    VarSetCapacity(CopyOfData, len,0)
    CopyOfData:= StrGet(StringAddress,len,"cp0")
    
;  ****** debug *******  set return values to Gui

ControlSetText,edit1,%CopyOfData%,debug_window

;  ********************

datastring:= CopyOfData
return true
}

Send_(StringToSend,IDc)
{
global TargetScriptTitle


    DetectHiddenWindows On
    SetTitleMatchMode 2

    VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)
    
    StringToSend=api %StringToSend%
    len := StrPutVar(StringToSend, StringToSend, "cp0")+1

    NumPut(IDc          , CopyDataStruct, 0)
    NumPut(len , CopyDataStruct, 4)  
    NumPut(&StringToSend, CopyDataStruct,  

    SendMessage, 0x4a, %A_ScriptHwnd%, &CopyDataStruct,, %TargetScriptTitle%
    
  if (errorlevel="fail")
   {
  MsgBox SendMessage failed. Does the target application runs?
   
   }
  
    return  
}

StrPutVar(string, ByRef var, encoding)
{
    VarSetCapacity(var, StrPut(string, encoding) * ((encoding="UTF-16"||encoding="CP1200") ? 2 : 1))
    return StrPut(string, &var, encoding)
}





Last edited by guest_today on Fri Jul 12, 2024 3:11 pm; edited 1 time in total (Reason for editing : 12-07-2024 i removed the errorlevel check because it was changed in versions >10.1a ,stickies send true or fail and not 0 / 1 .)
avatar
Orest
Posts : 3
Join date : 2024-07-07

How to toggle Stickies note size between 420x316 and 840x960? Empty Re: How to toggle Stickies note size between 420x316 and 840x960?

Sat Jul 13, 2024 7:27 am
Unfortunately, I am not a programmer, and I don't even know English Sad . I did this with the help of Artificial Intelligence(AI), trying many options. Thank you once again for the advice. Smile
Sponsored content

How to toggle Stickies note size between 420x316 and 840x960? Empty Re: How to toggle Stickies note size between 420x316 and 840x960?

Back to top
Permissions in this forum:
You can reply to topics in this forum