Maximus5 / ConEmu

Customizable Windows terminal with tabs, splits, quake-style, hotkeys and more
https://conemu.github.io/
BSD 3-Clause "New" or "Revised" License
8.61k stars 575 forks source link

how to create a "conemu here" button in totalcmd buttonbar #122

Open Hoxter opened 9 years ago

Hoxter commented 9 years ago

aslo need "conemu admin here“

Maximus5 commented 9 years ago

Why do you ask here how to use Total Commander??

eugenesvk commented 8 years ago

@Maximus5 I have a similar question – is it possible to attach a ConEmu instance in a separate pane within Total Commander? There is already an addon that allows to launch a cmd/powershell inside a tab in TC http://totalcmd.net/plugring/tconsole.html, so I was wondering if somehow I could attach the awesomeness of preconfigured ConEmu there as well. And if it's not possible to connect that addon with ConEmu, is there a chance you might add support of Total Commander in the same way you currently support the default File Explorer through integration of the "ConEmu inside", allowing to attach a terminal window to Explorer?

And the reason I'm asking here is because as far as I understand that's not a functionality TC can support on its own without changes in ConEmu (but maybe I'm totally wrong here). Also, I've also left a suggestion at TC's forums http://www.ghisler.ch/board/viewtopic.php?t=43677&highlight=).

Maximus5 commented 8 years ago

@eugenesvk You may check conemu-inside project. This is an example, how ConEmu may be started as child window in any application.

eugenesvk commented 8 years ago

@Maximus5 Thanks, that sound exactly what I need! Though I don't understand how to use it. Would you please provide some instructions there?

  1. I've managed to open the ConEmuInside.csproj file in VS 2015 Community 14.0.24720.0 and successfully launch the window with ConEmu (same as the one you have in your screenshot). But how do I actually attach it to TotalCommander? I can run the generated ConEmuInside.exe file, but then again it only shows what you have in your screenshot. By the way, the the settings window of ConEmu after you start the solution is not scaled properly and can't be resized (tried it both with default settings and my settings file from regular ConEmu installation): conemu inside settings And a minor bug: the last button where you select where to source settings file from is not working (no file selection dialogue is opened) conemu inside solution non-working button
  2. As a second step, I've tried to run the attach to process to TotalCommander, but then again, not sure what to expect from this. After trying to attache to explorer.exe, thought, I've got my Alt-Tab menu decrease in size and not fit the icons anymore conemu inside alt-tab menu

So how do I use this awesome tool ;)?

Maximus5 commented 8 years ago
  1. It would be better to ask TotalCmd author, no? At the moment I don't have plans to implement TCMD plugins.
  2. I have absolutely no idea why your OS is buggy. Also, I have no idea what OS you are using.
eugenesvk commented 8 years ago
  1. As I mentioned above I already have asked the TC author and also the author of the plugin that shows a shell inside TC. Tough I guess he could just say the same thing: "Ask ConEmu author". Also, given that it was you, not Microsoft, who enabled integration with Windows Explorer, I thought it'd also make sense to ask you about the TC integration.
  2. It's Windows 10.0.10586. And these bugs don't appear with default ConEmu installation (i.e. the one that can embed processes in Windows Explorer, both settings window and Alt-Tab work fine)
Maximus5 commented 8 years ago

The Inside mode is described in docs. As I said before, at the moment I don't want to pay my time to develop TC plugin, but if TC can provide the "space" for terminal, or there are existing plugins which may do that, you may run ConEmu inside TC easily. Obviously, I don't know if that is possible and you shall to ask TC authors.

After trying to attache to explorer.exe

What???

eugenesvk commented 8 years ago

The Inside mode is described in docs

You're right, I've only seen the first part before (on the ConEmu Inside option for Explorer). Still, after reading this I'm not sure as to where to get the HWND code of a tab inside TC. Is that something only TC developer would know or can it be check by some utility?

if TC can provide the "space" for terminal, or there are existing plugins which may do that, you may run ConEmu inside TC easily

And as I've mentioned and linked above, the answer to both is yes, TC provides such a functionality and there is already an addon that allows to show show cmd/powershell consoles inside a separate tab in TC. The question still remains how to utilize that space to 'inject' ConEmu instead of the terminal in that addon. And you're best suited to answer that question since you've already done this for Explorer. Is there a chance you could at least look at that addon and see if there is a simple fix that can place ConEmu in that space the addon creates? Otherwise of course it's up to you whether to spend time developing a TC addon, just thought that since there is already something similar maybe that wouldn't take much time, but I have no idea.

After trying to attache to explorer.exe

Nevermind, was just trying to do random things to try to see how the inside option worked, so thought if I chose the explorer.exe process it would spawn a ConEmu process inside.

eugenesvk commented 8 years ago

Ok, I've finally managed to get somewhere, but wow that ConEmu Inside github link (https://github.com/Maximus5/conemu-inside) just led me astray and wasted a lot of time because it didn't accept any of the commands to actually inject anything. And since I wasn't sure whether it was a wrong HWND or something else, I realized too late I should just ignore it and use the regular way to launch ConEmu.exe. Have no clue why you'd even link there instead of pasting a simple command line of the already existing ConEmu.exe. See the error message below (and I've tried all different combinations of the syntax, including the correct one that I found out) conemu inside wrong description2

And about that command — the main description (https://conemu.github.io/en/InsideParent.html) contains a mistake in command syntax that also took me a while to realize (I thought I entered wrong HWNDs): the commands should be with a slash / instead of a hyphen/dash -. And this insidewnd switch isn't anywhere in the help menu of the main program either.

Anyway, finally I realized that the proper syntax is ConEmu64.exe /insidewnd 0xHWND /config "inside" /single /cmd {PS} after I've looked how "ConEmu Inside" was launched from the registry.

Now, back to the HWND and TotalCommander, here is the rub — the only proper HWND space that can inject ConEmu is the space that addon creates, but the addon also overwrites ConEmu output because it has a console of its own.

  1. So you'd get something like this — notice the highlighted ConEmu status bar at the bottom with powershell while cmd is actually shown because that addon overwrites ConEmu output. conemu inside totalcommanderaddon2
  2. Alternatively, if I try to inject in an empty TC tab with folders I get the top and the bottom of the window, but not the middle. Notice the status bar at the bottom, command line at the top and regular TC window in the middle. conemu inside totalcommander

There is a chance there is some window HWND that I've missed, although I think I've tried all of the ones Spy++ showed. Otherwise I guess we're back to square one — you need an addon in TC to generate an empty window that ConEmu can hook into and no addon would do that because it would generate a window for its own purposes :(

I'll check with the TC author to see if there is an HWND that can be used as well as with the addon author to see if there is a way to generate a simple new HWND and call ConEmu with that HWND instead of hooking the default cmd/PS consoles.

eugenesvk commented 8 years ago

Ok, I've found two better spots and one additional problem (solving which would allow to embed almost like in WinExplorer) 1) Tree-view on the left hand side — this whole window gets hijacked, so it's almost perfect (there are just a few artifacts when you browse because TC sometimes overwrites parts of ConEmu) 2) In horizontal arrangement if you decrease the bottom panel to something like ~15% then you'd only see ConEmu window (since it injects itself at the top of the panel) so you'd get ~4 lines of text (of course if you have no tabs for ConEmu)

However, the additional problem is that HWNDs are dynamic, so then, @Maximus5, a few extra questions are: 1) Is there a way to identify a window's HWND by it's position relative to the process window (e.g. get an HWND of the left-most window)? 2) Is there a way to identify a window's HWND by its other attributes (e.g. Caption/Class seem to be the same regardless of dynamic HWNDs) 3) Is there a way to reference a window by its other attributes instead of HWND? As a side note, I've noticed that in Windows Explorer an empty preview area has no HWND, yet you're able to inject there. How do you find that area and can a similar process be maybe used in TC?

And if 1-3 are no-gos, would you be open to adding those additional fields so that ConEmu could be embedded in more applications? Thanks for your consideration.

Maximus5 commented 8 years ago

Awful... Why do you think that ConEmu requires slash-arguments? Posted link to docs describes both modes: Explorer and arbitrary HWND. Project conemu-inside is the example how developer may utilize second mode.

As for yourquestions How do you imagine these suggestions? HWND is strict and unambiguous option, and this value knows the parent application, and they often provide some macros to acquire the value. Obviously only their authors may advise you about. All other "options" to determine available space are ambiguous and they would be broken on minimal configuration changes in parent layout. That is not acceptable.

eugenesvk commented 8 years ago

I don't know why ConEmu requires them, but more importantly — it doesn't matter what I think the reason is. The problem is the lack of description of such requirement either in the docs or the app.

HWND is strict and unambiguous option

And those two qualities are not everything. For example, I use Autohotkey to enable some app-based shortcuts and practically there is always a combo of some window properties that are unique to the application I need to set up hotkeys for.

So here is how I'd imagine it — ConEmu would optionally read additional fields for a process/window (e.g. process name, window caption/class/style or whatever — you know this better than I do) and allow the user to pass those as arguments. If I know HWND — that's great! Strictness and clarity are awesome! If not — not a big deal. I can achieve exactly the same result through other standard process/window parameters. Can there be a fringe case when ConEmu would fail to attach itself because there is another process "Total Commander" with window caption"W_TreeList1" and class "LCLListBox" and style "56010153"? Theoretically — sure, practically — no way, it's as close to strict and unambiguous as HWND is. But wait, it's even better — I have no clue what HWND is, but I can check those other fields. And even if a bad match ever happens — no big deal, a 99% success rate is much better than 0% success rate, because currently I can't do anything.

Obviously only their authors may advise you about.

And that's exactly the problem! Currently you expect every other app to be aware of and make an adjustment for ConEmu. While there is no good reason for that. Autohotkey doesn't expect each app to pass some unique arguments so it can identify it and ConEmu could be the same.

eugenesvk commented 8 years ago

So would you please consider adding additional parameters to the mix besides PID and HWND? It's just such a waste of this awesome feature — ability to embed in any app that has some free window space lying around. No addons, no nothing, just pure ConEmu awesomeness inside :)