[C#] Get menu strip from active window

Discussion in 'Mixed Languages' started by AviiNL, Oct 2, 2012.

  1. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    229
    0
    Hello all,

    I was wondering,
    Is it possible to hook into the active window (eg. notepad.exe) and get the menu strip from that window or application to copy it into a windows form in my application.

    Kind regards,
    AviiNL
     
  2. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    60
    #2 Muerto, Oct 2, 2012
    Last edited: Aug 22, 2021
    ...
     
  3. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    229
    0
    No, It's a bit more complicated then that.

    For example I run notepad, and have it on the foreground, i want the menu of notepad cloned into my application but remaining the functionality with the notepad process.
    Now, I think the functionality will be possible using automation.. but i have no way to copy or clone the menu from an running process into my form.
     
  4. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    60
    #4 Muerto, Oct 2, 2012
    Last edited: Aug 22, 2021
    ...
     
  5. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    120
    If you do it, the imported menu won't will work on your application because the notepad.exe isn't a managed process. But it looks to work on the same notepad.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    229
    0
    I Managed to get the text of the menu from any application in my project using user32 api calls :)

    now to figure out how to send the commands back (eg, hit file -> new in my program, and execute it in notepad)

    Thanks for thinking with me,
    Appriciated it:)
     
  7. master131

    master131 MDL Novice

    Apr 12, 2011
    45
    22
    0
    You might want to have a look at SendMessage.
     
  8. BobSheep

    BobSheep MDL Guru

    Apr 19, 2010
    2,330
    1,377
    90
    As Notepad is just a multiline TextBox you could easily write your own version in c++ or Managed Code and control it with whatever mechanism you choose.
     
  9. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    229
    0
    I fixed it, and it is done, using Automation..
    the notepad refrenced is just an example, it needs to work with.... everything that is running.

    What I did is to give my windows box an osx look :) and it turned out pretty nicely =]