[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
    228
    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. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    228
    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.
     
  3. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,323
    60
  4. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,110
    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...
  5. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    228
    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:)
     
  6. master131

    master131 MDL Novice

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

    BobSheep MDL Guru

    Apr 19, 2010
    2,326
    1,362
    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.
     
  8. AviiNL

    AviiNL MDL Novice

    Aug 6, 2012
    22
    228
    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 =]