0

Is it possible to use/call programs' GUI abilities directly without using the GUI (programmatically, not by keyboarding)?

For example, a program with abilities nested too deeply in cascading submenus:

Trigger directly?

Would it be possible to use/trigger any of those menu items directly/programmatically... as if you had clicked it directly using the GUI?

I guess sort of like a reverse-engineered "API". I'd assume it'd require some sort of live debugging to see where the program reaches or calls for in memory when a GUI item is clicked. Then hopefully after you've seen where that is, you could call it yourself at will, or record the program's messaging/queuing to do it, and then you could replay that at will, able to use or activate abilities of the program without having to touch the GUI.

Another simple example:

Notepad GUI

In Windows Notepad, the only way to enable "Word-Wrap" is by clicking it in the menu bar menus (keyboard navigating the same). But behind the GUI curtain, somewhere in memory there's a function that gets called or flag bit set.

I'm wondering if it's possible to trigger/call those abilities/functions directly yourself (programmatically), pulling the GUI puppet-strings manually, activating the functions on the other end of the strings without using the GUI.

Since a GUI is basically just a point-and-click map with strings attached to back-end functions/code in memory, I would think this might be possible, barring program memory protections.

Note: I'm asking this question 100% from a reverse-engineering perspective, and not for how to do this via macro/scripting/automation. I'm well aware of tools like AutoHotkey, AutoIt, etc., but that's not why I'm asking the question.

  • Tools such as AutoIt, AutoHotHey, Pulover's Macro Creator are developed for the exact same purpose. Doesn't need reverse engineering at all. – 0xec Dec 7 '19 at 11:07
  • @0xec I'm not looking for macros, which all of those tools essentially equate to. I'm asking from a reverse-engineering perspective, otherwise I'd ask this on Superuser. I'm asking this only from a reversing conceptual perspective, not merely trying to find a way to do things quicker. – Coldblackice Dec 7 '19 at 12:10
  • This is a very broad question. Alone the two examples you gave are worlds apart. While classical Notepad uses windows and controls, Sublime Text has a single window only and drawing happens completely internally. Typically stuff like PostMessage/SendMessage should/would work, but that makes assumptions about how an application creates its windows/controls. What you're asking will likely be possible, but have to be customized for each and every target application. So macros would be the appropriate pick from the tool chest. Use Spy++ to investigate what I explained. – 0xC0000022L Dec 9 '19 at 11:04
  • Tools such as WinSpy and WinSpyEx exist as alternatives to Spy++ (which comes with Visual Studio since at least version 6). – 0xC0000022L Dec 9 '19 at 11:09
2

not sure what methodology you are looking for if the said gui is under some debugger

you can simply detour a patch

or if you are under the wndproc Thread of the gui You can use apis
(for example for checking the menu wordwrap in notepad use CheckMenuItem(); )

or use the oldest trick SendMessage From an external App a demo and src of the third method is below

enter image description here

src compiled with 2017 community 32bit on a 32bit win 7 x86 machine using

cl /Zi /W4 /analyze /Od /EHsc /nologo MENU.CPP /link /release

src

#include <windows.h>
#include <stdio.h>
#pragma comment(lib,"user32.lib")
#define MAXSUBMENUS 100
int main(void) {
    printf("lets wrappify the notes pad\n");
    HWND notewnd = FindWindowA("Notepad", NULL);
    if (notewnd != NULL) {
        printf("notepad handle is %p\n", notewnd);
        HMENU menubar = GetMenu(notewnd);
        if (menubar != NULL) {
            printf("menubar handle is %p\n", menubar);
            int menuitemcount = GetMenuItemCount(menubar);
            printf("menubar contains %d Items\n", menuitemcount);
            if (menuitemcount > MAXSUBMENUS) { menuitemcount = MAXSUBMENUS; }
            HMENU submenus[MAXSUBMENUS] = { 0 };
            int submenuitemcount[MAXSUBMENUS] = { 0 };
            for (int i = 0; i < menuitemcount; i++) {
                submenus[i] = GetSubMenu(menubar, i);
                if (submenus[i] != NULL) {
                    submenuitemcount[i] = GetMenuItemCount(submenus[i]);
                    printf("submenu[%d] handle is %p and contains %d Items\n",
                        i, submenus[i], submenuitemcount[i]);
                }
            }
            for (int i = 0; i < submenuitemcount[2]; i++) {
                printf("format menu bypos %d ID = %u\n", i, 
                    GetMenuItemID(submenus[2], i));
            }
            printf ("%x\n" , SendMessage(notewnd,WM_COMMAND,
            MAKEWPARAM(GetMenuItemID(submenus[2],0),0),(LPARAM)NULL));
        }
    }
    return 0;
}

or as extremecoder pointed out use the various available packages

edit for 0xc0000022's comment

not sure whats special about sublime having never used it just installed it and ran a brute based on the PID of sublime it seems to work i gathered the Menu ID from spy++ for demo purposes but as seen from the output one can see the Number of MEnu Item Count as 10 in case of sublimes main window handle

code as follows

#include <windows.h>
#include <stdio.h>
int  GetHwnds(DWORD InPID, HWND *somewind){
    HWND hCurWnd = NULL;
    int i =0;
    do {
        hCurWnd = FindWindowEx(NULL, hCurWnd, NULL, NULL);
        DWORD pid = 0;        
        GetWindowThreadProcessId(hCurWnd, &pid);
        if (pid == InPID){
            somewind[i++] = hCurWnd;
            printf("Found hWnd %p\n", hCurWnd);
        }
    }
    while (hCurWnd != NULL);
    return i;
}
void main(int argc,char *argv[]) {
    if(argc !=2){
        printf ("usage %s pid",argv[0]);
        exit(0);
    }
    HWND subyuck[0x50] = {NULL};    
    int yucks = GetHwnds(atoi(argv[1]),subyuck);
    for(int i=0;i<yucks;i++){
        if(subyuck[i] != NULL){
            printf("menu %p MenuItemCount %d\n",GetMenu(subyuck[i]),GetMenuItemCount(GetMenu(subyuck[i])));
            SendMessage(subyuck[i],WM_COMMAND,MAKEWPARAM(436,0),MAKELPARAM(0,0));
        }
    }
}

output

C:\Users\XXX\Desktop\yucketyyuck>cl /Zi /W4 /analyze /Od yucketyyuck.cpp /link /release user32.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27025.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

yucketyyuck.cpp
Microsoft (R) Incremental Linker Version 14.16.27025.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:yucketyyuck.exe
/debug
/release
user32.lib
yucketyyuck.obj

C:\Users\XXX\Desktop\yucketyyuck>tasklist |grep -i sub*
sublime_text.exe              3272 Console                    1     18,684 K

C:\Users\XXX\Desktop\yucketyyuck>yucketyyuck.exe 3272
Found hWnd 002104DE
Found hWnd 00240586
Found hWnd 00070322 <<<<<<<<<<<<<< gui thread 
Found hWnd 001D02AA
menu 00000000 MenuItemCount -1
menu 00000000 MenuItemCount -1
menu 001A033D MenuItemCount 10 <<<<<<<<<<<<<< 
menu 00000000 MenuItemCount -1

a gif just in case

enter image description here

normally ResHack should show the Control ID's of Menu
but in case of sublime text reshack does not show the Menus
I have not checked why but i just retrieved all the ControlIDS (632 of them) for which you can SendMessage WM_COMMAND->wNotify

using code below

#include <windows.h>
#include <stdio.h>
#define MAXANY 0x100

void enumenu(HMENU hMenu) {

    for (int i = 0; i < GetMenuItemCount(hMenu); i++)
    {
        char menustring[MAXANY] = { 0 };
        MENUITEMINFO mii = { 0 };
        mii.cbSize = sizeof(MENUITEMINFO);
        mii.fMask = MIIM_STATE | MIIM_TYPE | MIIM_SUBMENU | MIIM_ID;
        mii.dwTypeData = menustring;
        mii.cch = MAXANY;
        GetMenuItemInfoA(hMenu, i, TRUE, &mii);
        printf("%8u   ", mii.wID);
        if( (mii.fState & MFS_CHECKED) == MFS_CHECKED)
            printf("X   ");
        else 
            printf("    ");

        if (mii.fType == MFT_SEPARATOR)
        {
            printf("------------------\n");
        }
        if (mii.fType == MFT_STRING)
        {
            printf("---%s\n", menustring);
        }
        if (mii.hSubMenu != NULL)
        {
            enumenu(mii.hSubMenu);
        }
    }
}

int  GetHwnds(DWORD InPID, HWND *somewind) {
    HWND hCurWnd = NULL;
    int i = 0;
    do {
        hCurWnd = FindWindowEx(NULL, hCurWnd, NULL, NULL);
        DWORD pid = 0;
        GetWindowThreadProcessId(hCurWnd, &pid);
        if (pid == InPID) {
            if (i > MAXANY) { return i; }
            somewind[i++] = hCurWnd;
        }
    } while (hCurWnd != NULL);
    return i;
}
void main(int argc, char *argv[]) {
    if (argc != 2) {
        printf("usage %s pid", argv[0]);
        exit(0);
    }
    HWND subyuck[MAXANY] = { NULL };
    int yucks = GetHwnds(atoi(argv[1]), subyuck);
    for (int i = 0; i < yucks; i++) {
        if (subyuck[i] != NULL) {
            HMENU submenu = GetMenu(subyuck[i]);
            enumenu(submenu);

        }
    }
}

and the menu controlIDS (436 in case of WordWrap is checked shown by an X)

  590370       ---&File
       0       ---&New File     Ctrl+N
       1       ---&Open Fileà   Ctrl+O
       2       ---Open Folderà
 1049112       ---Open &Recent
       3       ---Reopen Closed File    Ctrl+Shift+T
       4       ------------------
       5       ---Restored from abyss  (all invisible menu items with this name are dittoed with ""
       6       ""
       7       ""
       8       ""
       9       ""
      10       ""
      11       ""
      12       ""
      13       ""
      14       ""
      15       ""
      16       ""
      17       ""
      18       ""
      19       ""
      20       ""
      21       ""
      22       ""
      23       ---Clear Items
  262656       ---Reopen with Encoding
            removed allen coding IDS
      97       ---Save &Asà     Ctrl+Shift+S
      98       ---Save A&ll
      99       ------------------
     100       ---New &Window   Ctrl+Shift+N
     101       ---Close Window  Ctrl+Shift+W
     102       ------------------
     103       ---&Close File   Ctrl+W
     104       ---Re&vert File
     105       ---Close All Files
     106       ------------------
     107       ---E&xit
 1245462       ---&Edit
     108       ---&Undo Ctrl+Z
     109       ---&Redo Ctrl+Y
  590368       ---Undo Selection
     110       ---Soft Undo     Ctrl+U
     111       ---Soft Redo     Ctrl+Shift+U
     112       ------------------
     113       ---Cu&t  Ctrl+X
     114       ---&Copy Ctrl+C
     115       ---&Paste        Ctrl+V
     116       ---Paste and &Indent     Ctrl+Shift+V
     117       ---Paste from History    Ctrl+K, Ctrl+V
     118       ------------------
  262624       ---&Line
     119       ---Indent        Ctrl+]
     120       ---Unindent      Ctrl+[
     121       ---Reindent
     122       ---Swap Line Up  Ctrl+Shift+Up
     123       ---Swap Line Down        Ctrl+Shift+Down
     124       ---Duplicate Line        Ctrl+Shift+D
     125       ---Delete Line   Ctrl+Shift+K
     126       ---Join Lines    Ctrl+J
  590472       ---Co&mment
     127       ---Toggle Comment        Ctrl+/
     128       ---Toggle Block Comment  Ctrl+Shift+/
  197082       ---&Text
     129       ---Revert Modification   Ctrl+K, Ctrl+Z
     130       ""
     131       ------------------
     132       ---Insert Line Before    Ctrl+Shift+Enter
     133       ---Insert Line After     Ctrl+Enter
     134       ------------------
     135       ---Delete Word Forward   Ctrl+Delete
     136       ---Delete Word Backward  Ctrl+Backspace
     137       ---Delete Line   Ctrl+Shift+K
     138       ---Delete to End Ctrl+K, Ctrl+K
     139       ---Delete to Beginning   Ctrl+K, Ctrl+Backspace
     140       ------------------
     141       ---Transpose     Ctrl+T
  262582       ---Tag
     142       ---Close Tag     Alt+.
     143       ---Expand Selection to Tag       Ctrl+Shift+A
     144       ---Wrap Selection With Tag       Alt+Shift+W
  262672       ---Mark
     145       ---Set Mark      Ctrl+K, Ctrl+Space
     146       ---Select to Mark        Ctrl+K, Ctrl+A
     147       ---Delete to Mark        Ctrl+K, Ctrl+W
     148       ---Swap with Mark        Ctrl+K, Ctrl+X
     149       ---Clear Mark    Ctrl+K, Ctrl+G
     150       ------------------
     151       ---Yank  Ctrl+K, Ctrl+Y
  262674       ---Code Folding
     152       ---Fold  Ctrl+Shift+[
     153       ---Unfold        Ctrl+Shift+]
     154       ---Unfold All    Ctrl+K, Ctrl+J
     155       ------------------
     156       ---Fold All      Ctrl+K, Ctrl+1
       yyyyyyyyyyyyyyyyyyyyyyy
     165       ------------------
     166       ---Fold Tag Attributes   Ctrl+K, Ctrl+T
  131614       ---Convert C&ase
     167       ---Title Case
     168       ---Upper Case    Ctrl+K, Ctrl+U
     169       ---Lower Case    Ctrl+K, Ctrl+L
     170       ---Swap Case
  197238       ---Wrap
     171       ---Wrap Paragraph at Ruler       Alt+Q
      zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
     178       ---Show Completions      Ctrl+Space
     179       ------------------
     180       ---&Sort Lines   F9
     181       ---Sort Lines (Case Sensitive)   Ctrl+F9
  328312       ---Permute Lines
     182       ---Reverse
     183       ---Unique
     184       ---Shuffle
  131644       ---Permute Selections
     185       ---Sort
     186       ---Sort (Case Sensitive)
     187       ---Reverse
     188       ---Unique
     189       ---Shuffle
     190       ""
  131646       ---&Selection
     191       ---Split into Lines      Ctrl+Shift+L
     192       ---Add Previous Line     Ctrl+Alt+Up
     193       ---Add Next Line Ctrl+Alt+Down
     194       ---Single Selection      Escape
     195       ---Invert Selection
     196       ------------------
     197       ---Select All    Ctrl+A
     198       ---Expand Selection to Line      Ctrl+L
         tttttttttttttttttttttttttt
  131648       ---F&ind
     205       ---Findà Ctrl+F
     206       ---Find Next     F3
     207       ---Find Previous Shift+F3
     208       ---Incremental Find      Ctrl+I
     209       ------------------
     210       ---Replaceà      Ctrl+H
     211       ---Replace Next  Ctrl+Shift+H
     212       ------------------
     213       ---Quick Find    Ctrl+F3
     214       ---Quick Find All        Alt+F3
     215       ---Quick Add Next        Ctrl+D
     216       ---Quick Skip Next       Ctrl+K, Ctrl+D
     217       ------------------
     218       ---Use Selection for Find        Ctrl+E
     219       ---Use Selection for Replace     Ctrl+Shift+E
     220       ------------------
     221       ---Find in Filesà        Ctrl+Shift+F
  131692       ---Find &Results
     222       ---Show Results Panel
     223       ---
     224       ---Previous Result
  131716       ---&View
  131690       ---Side Bar
     225       ---Hide Side Bar Ctrl+K, Ctrl+B
     226       ------------------
     227       ---Show Open Files
     228       ---Hide Minimap
     229       ---Hide Tabs
     230       ---Hide Status Bar
     231       ---Hide Menu
     232       ---Show Console  Ctrl+`
     233       ------------------
     234       ---Enter Full Screen     F11
     235       ---Enter Distraction Free Mode   Shift+F11
     236       ------------------
  131688       ---&Layout
     237       ---Single        Alt+Shift+1
     238       ---Columns: 2    Alt+Shift+2
     239       ---Columns: 3    Alt+Shift+3
     240       ---Columns: 4    Alt+Shift+4
     241       ---Rows: 2       Alt+Shift+8
     242       ---Rows: 3       Alt+Shift+9
     243       ---Grid: 4       Alt+Shift+5
  131686       ---Groups
     244       ---Move File to New Group        Ctrl+K, Ctrl+Up
     245       ---New Group     Ctrl+K, Ctrl+Shift+Up
     246       ---Close Group   Ctrl+K, Ctrl+Down
     247       ------------------
     248       ---Max Columns: 1
     249       ---Max Columns: 2
     250       ---Max Columns: 3
     251       ---Max Columns: 4
     252       ---Max Columns: 5
  131684       ---&Focus Group
     253       ---Next  Ctrl+K, Ctrl+Right
     254       ---Previous      Ctrl+K, Ctrl+Left
     255       ------------------
     256       ---Group 1       Ctrl+1
     257       ""
     258       ""
     259       ""
  197250       ---&Move File to Group
     260       ---Next  Ctrl+K, Ctrl+Shift+Right
     261       ---Previous      Ctrl+K, Ctrl+Shift+Left
     262       ------------------
     263       ---Group 1       Ctrl+Shift+1
     264       ""
     265       ""
     266       ""
     267       ------------------
  131682       ---&Syntax
  131680       ---Open all with current extension as...
      uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
   66212       ---&Indentation
     417       ---Indent Using Spaces
     418       ------------------
     419       ---Tab Width: 1
     420       ---Tab Width: 2
     421       ---Tab Width: 3
     422   X   ---Tab Width: 4
     423       ---Tab Width: 5
     424       ---Tab Width: 6
     425       ---Tab Width: 7
     426       ---Tab Width: 8
     427       ------------------
     428       ---Guess Settings From Buffer
     429       ------------------
     430       ---Convert Indentation to Spaces
     431       ---Convert Indentation to Tabs
   66214       ---Li&ne Endings
     432   X   ---Windows
     433       ---Unix
     434       ---Mac OS 9
     435       ------------------
     436   X   ---&Word Wrap       <<<<<<<<<<<<<<<<<<<<<<<<<
   66216       ---Word Wrap Column
     437   X   ---Automatic
     438       ------------------
     439       ---70
     440       ---72
     441       ---78
     442       ---80
     443       ---100
     444       ---120
   66219       ---Ruler
     445   X   ---None
     446       ------------------
     447       ---70
     448       ---72
     449       ---78
     450       ---80
     451       ---100
     452       ---120
     453       ------------------
     454       ---Spell Check   F6
     455       ---Next Misspelling      Ctrl+F6
     456       ---Prev Misspelling      Ctrl+Shift+F6
   66221       ---Dictionary
     457       ---en_GB
     458   X   ---en_US
   66223       ---&Goto
     459       ---Goto &Anythingà       Ctrl+P
     460       ------------------
     461       ---Goto Symbolà  Ctrl+R
     462       ---Goto Symbol in Projectà       Ctrl+Shift+R
     463       ---Goto Definitionà      F12
     464       ---Goto Referenceà       Shift+F12
     465       ---Goto Lineà    Ctrl+G
     466       ------------------
     467       ---Next Modification     Ctrl+.
     468       ---Previous Modification Ctrl+,
     469       ------------------
     470       ---Jump Back     Alt+-
     471       ---Jump Forward  Alt+Shift+-
     472       ------------------
   66225       ---Swi&tch File
     473       ---Next File     Ctrl+Pagedown
     474       ---Previous File Ctrl+Pageup
     475       ------------------
     476       ---Next File in Stack    Ctrl+Tab
     477       ---Previous File in Stack        Ctrl+Shift+Tab
     478       ------------------
     479       ---Switch &Header/Implementation Alt+O
     480       ------------------
     481       ---yuckeyt yuck ddddddddddddddddddddddddddddddddddddd    Alt+1
     482       ""
     483       ""
     484       ""
     485       ""
     486       ""
     487       ""
     488       ""
     489       ""
     490       ""
     491       ------------------
   66227       ---&Scroll
     492       ---Scroll to Selection   Ctrl+K, Ctrl+C
     493       ---Line Up       Ctrl+Up
     494       ---Line Down     Ctrl+Down
   66229       ---&Bookmarks
     495       ---Toggle Bookmark       Ctrl+F2
     496       ---Next Bookmark F2
     497       ---Prev Bookmark Shift+F2
     498       ---Clear Bookmarks       Ctrl+Shift+F2
     499       ---Select All Bookmarks  Alt+F2
     500       ------------------
     501       ---(No Bookmarks)
     502       ""
     503       ""
     504       ""
     505       ""
     506       ""
     507       ""
     508       ""
     509       ""
     510       ""
     511       ""
     512       ""
     513       ""
     514       ""
     515       ""
     516       ""
     517       ------------------
     518       ---Jump to Matching Bracket      Ctrl+M
   66231       ---&Tools
     519       ---Command Paletteà      Ctrl+Shift+P
     520       ---Snippetsà
     521       ------------------
   66233       ---B&uild System
     522   X   ---Automatic
     523       ------------------
     524       ""
     525       ""
     526       ""
     527       ""
     528       ""
     529       ""
     530       ""
     531       ""
     532       ""
     533       ""
     534       ""
     535       ""
     536       ""
     537       ---ActionScript
     538       ---Ant
     539       ---C Single File
     540       ---C++ Single File
     541       ---Cargo
     542       ---D
     543       ---D dub
     544       ---Erlang
     545       ---Haskell
     546       ---JavaC
     547       ---Lua
     548       ---Make
     549       ---Python
     550       ---R
     551       ---Ruby
     552       ---Rust
     553       ---ShellScript
     554       ---Syntax Tests
     555       ------------------
     556       ---New Build Systemà
     557       ---&Build        Ctrl+B
     558       ---Build Withà   Ctrl+Shift+B
     559       ---&Cancel Build Ctrl+Break
   66235       ---Build &Results
     560       ---&Show Build Results
     561       ---&Next Result  F4
     562       ---&Previous Result      Shift+F4
     563       ---Save &All on Build
     564       ------------------
     565       ---Record &Macro Ctrl+Q
     566       ---&Playback Macro       Ctrl+Shift+Q
     567       ---Sa&ve Macroà
   66237       ---Macros
     568       ---Add Line Before
     569       ---Add Line in Braces
     570       ---Add Line
     571       ---Delete Left Right
     572       ---Delete Line
     573       ---Delete to BOL
     574       ---Delete to EOL
     575       ---Delete to Hard BOL
     576       ---Delete to Hard EOL
     577       ------------------
   66239       ---Developer
     578       ---New Pluginà
     579       ---New Snippetà
     580       ---New Syntaxà
     581       ""
     582       ------------------
     583       ---Profile Plugins
     584       ------------------
     585       ---Show Scope Name       Ctrl+Alt+Shift+P
     586       ---Install Package Controlà
     587       ""
   66241       ---&Project
     588       ---Open Projectà
     589       ---Switch Projectà
     590       ---Quick &Switch Projectà
   66243       ---Open Recent
     591       ""
     592       ""
     593       ""
     594       ""
     595       ""
     596       ""
     597       ""
     598       ""
     599       ""
     600       ---Clear Items
     601       ------------------
     602       ---Save Project &Asà
     603       ---&Close Project
     604       ---Edit Project
     605       ------------------
     606       ---New Workspace for Project
     607       ---Save Workspace &Asà
     608       ------------------
     609       ---A&dd Folder to Projectà
     610       ---Re&move all Folders from Project
     611       ---R&efresh Folders
   66245       ---Prefere&nces
     612       ---&Browse Packagesà
     613       ------------------
     614       ---Settings
     615       ---Settings û Syntax Specific
     616       ---Settings û Distraction Free
     617       ------------------
     618       ---Key Bindings
     619       ------------------
     620       ---Color Schemeà
     621       ---Themeà
   66247       ---Font
     622       ---Larger        Ctrl+=
     623       ---Smaller       Ctrl+Shift+Keypad Plus
     624       ------------------
     625       ---Reset
   66249       ---&Help
     626       ---Documentation
     627       ---Twitter
     628       ------------------
     629       ---Indexing Statusà
     630       ------------------
     631       ---Purchase License
     632       ""
     633       ---Enter License
     634       ""
     635       ------------------
     636       ---Check for Updatesà
     637       ---Changelogà
     638       ---&About Sublime Text
| improve this answer | |
  • Yuck, this isn't considerably different from the macro approach that was recommended in a comment (and turned down by the inquirer). Tools like AutoIt/AutoHotKey have these capabilities built in. Alas with tools like Sublime Text you'll be lucky to get a main menu handle based on the main window. Many cross-platform frameworks will forego the Windows "user" handle approach (with actual windows and control) in favor of a single window (in terms of Win32 API) and only have a single window on which custom drawing happens. So it works with Notepad. Did you try Sublime Text? – 0xC0000022L Dec 9 '19 at 10:59
  • @0xC0000022L iam not sure what there is to yuck about i added a brute force approach on the said sublime – blabb Dec 9 '19 at 17:54
1

Yes, that's certainly doable.

You would have to analyze what code exactly is executed when a certain GUI action is performed. That would likely require knowledge of the used GUI API. Faking a button press in Qt is completely different from faking a button press in standard WinAPI dialogs.

That would be the higher layer to solve it, understand what that GUI action does (send a WM_COMMAND message in WinAPI for example, or emitting a signal in Qt) and just do that.

If this is too closely to macroing/faking key presses for you, you'd have to see how the code does something.

Some made-up WinAPI pseudo code could be:

if(msg == WM_COMMAND and button_id == BTN_ENABLE_STATUSBAR)
    show_statusbar();

so if you don't want to send a fake WM_COMMAND, you could inject code that calls show_statusbar() directly. But the target doesn't have to neatly wrap its code like that. It could just set some global vars and the redraw function would then read those vars later, see the status bar flag was set to visible and thus render the status bar.

It all comes down to how cleanly the application separates GUI handling logic from application logic. Worst case the GUI handling code contains all of the application logic code. Then it would be difficult to just execute that code block.

And best case as the made-up example where the GUI logic just calls another application logic function so you can easily do that on your own.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.