1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

_wintctitle variable

Discussion in 'Suggestions' started by TimButterfield, Sep 19, 2012.

  1. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    I could use 'window top' before getting the title of the TCMD window from _winfgwindow, but I would like to be able to use the activate command to resize the TCMD window without bringing it to the front. Having a _wintctitle variable with the title of the TCMD window would allow for that.
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    I'm tempted to try that in a plugin (say _TCHOSTWIN) but I don't have a vision of exactly how it should work or how it could be done. What if TCC is not in a TCMD tab or more than one TCMD exist? If TCC is in a TCMD tab (easy to detect with _TCTAB) there's no guarantee that TCMD is TCC's parent process so it's not clear how to get from knowing TCC is in a tab to the title of its host TCMD's main window. Any ideas? I'll see if TakeCpmmandIPC() can be of any value.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    TakeCommandIPC() turned out to be just what was needed. I have this (below); commments are welcome.

    In a standalone TCC ...
    Code:
    v:\> help _TCHOSTWIN
    Title of TCMD host's main window
     
    v:\> echo %_tchostwin
    -1
    In a TCMD tab ...
    Code:
    v:\> echo %_wintitle
    14.02  [336]  v:\
    
    v:\> echo %_tchostwin
    TC 14.0 - 14.02  [336]  v:\
    It works like this.
    Code:
    INT WINAPI _TCHOSTWIN ( WCHAR *psz )
    {
        HWND hWndTCMD;
        Sprintf(psz, L"-1");
        WCHAR szBuffer[32] = L"%_TCTAB";
        ExpandVariables(szBuffer, 1);
        if ( szBuffer[0] == L'1'
                && TakeCommandIPC(L"HWND", szBuffer) == 0
                && (hWndTCMD = (HWND) wcstoul(szBuffer, NULL, 10)) != NULL )
            GetWindowText(hWndTCMD, psz, 4096);
        return 0;
    }
    
     
  4. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    Would something like this work to move/resize the parent TCMD window?

    C:\>activate "%_tchostwin" /POS=...

    This is a variable I would like to have built in. My reason for wanting this is the switching of my laptop between the built-in screen and when using an attached 24" LCD. When I start up TCMD using one or the other, I would like to detect screen size and move/resize TCMD to fit that visible area. With multiple apps starting together, even calling window top immediately before getting _winfgwindow can sometimes get the name of another app. The last time, when my start.btm ran, it resized my Lotus Notes window instead, not quite what I wanted. ;)

    Tim
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    That ought to work (it works here). If you want to try it, I uploaded new 4UTILS plugins to ftp://lucky.syr.edu/4plugins/

    It was easy enough to do. Rex might include it in a future version.

    You might even be able to make a user-defined function, say %TCHOSTWIN[], using @WINAPI[] and the functions TakeCommandIPC() (from TAKECMD.DLL) and GetWindowText() (from USER32.DLL).
     
  6. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    That worked fine on my home laptop. Thanks.
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    As for doing it with internal stuff, this works (at least with the latest 32-bit version).

    Code:
    v:\> function TCHOSTWIN `%@winapi[user32.dll,GetWindowTextW,%@winapi[g:\tc14\takecmd.dll,?TakeCommandIPC@@YAHPA_W0@Z,"HWND",BUFFER],BUFFER,4096]`
     
    v:\> echo %@tchostwin[]
    TC 14.0 - 14.02  [2160]  v:\
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    Better make that
    Code:
    function TCHOSTWIN `%@winapi[user32.dll,GetWindowTextW,%@capi[g:\tc14\takecmd.dll,?TakeCommandIPC@@YAHPA_W0@Z,"HWND",BUFFER],BUFFER,4096]`
     
  9. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    The @capi usage fails with incorrect function, though the @winapi usage of takecmd.dll worked fine. I did tweak the path location to be: %@path[%_cmdspec]takecmd.dll to make it a bit more generic.

    Thanks again.
     
  10. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    Hmmm! @CAPI works here and it is the appropriate one. TakeCommandIPC is not a WINAPI function. Using the wrong one is likely to lead to corruption.
     
  11. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    I ran it on XP SP3. What did you run it on?
     
  12. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,962
    Likes Received:
    30
    Windows7/32-bit
     
  13. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    My other win laptop, the one for work, has Win7/32. I'll try it on Monday.
     
  14. TimButterfield

    Joined:
    May 20, 2008
    Messages:
    402
    Likes Received:
    2
    On my Win7/32 system, using either api functions return the right value.
     

Share This Page