delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/01/07/16:37:53

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <205934.59166.qm@web32007.mail.mud.yahoo.com>
Date: Thu, 7 Jan 2010 13:37:39 -0800 (PST)
From: Collin Monahan <cmonahan AT yahoo DOT com>
Subject: changing cygwin's console window title
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

I noticed Lynx kept changing my window title. According to the source code it was a call to SetConsoleTitle, part of the Windows API. Rather than modifying the Lynx source code I wrote a short console program in Visual C++ which I can use after exiting Lynx. It compiled under Visual Studio 2010 demo version to a 7168 byte executable.

Then I created a version of the program to compile under GCC. I felt this version was simpler in the code because I was able to dispense with wide character handling, and I guess that's possible in Visual C++ but I think it might require changing some obscure compiler settings. The result was 9728 bytes when compiled with default gcc settings.

These may not be appropriate to use with an xterm window.

////////////////////////////////////////////////////////////////////////////////
// Visual C++ version
#include <windows.h>
#include <wchar.h>

int _tmain(int argc, _TCHAR* argv[]) {
    TCHAR *field;
    int i;
    size_t st;
    if (argc > 1) {
        for (i = 1, st = 0; i < argc; i++) {
            st += wcslen(argv[i]);
        }
        st += argc - 2;
        field = (TCHAR*)malloc(st * sizeof(TCHAR));
        field[0] = 0;
        for (i = 1; i < argc; i++) {
            wcscat(field, argv[i]);
            if (i < argc - 1)
                wcscat(field, _T(" "));
        }
        SetConsoleTitle(field);
    }
    else {
        SetConsoleTitle(_T(""));
    }
    return 0;
}

////////////////////////////////////////////////////////////////////////////////
// GCC version
#include <windows.h>

int main(int argc, char **argv) {
    char *field;
    int i;
    size_t st;
    if (argc > 1) {
        for (i = 1, st = 0; i < argc; i++) {
            st += strlen(argv[i]);
        }
        st += argc - 2;
        field = (char*)malloc(st);
        field[0] = 0;
        for (i = 0; i < argc; i++) {
            strcat(field, argv[i]);
            if (i < argc - 1)
                strcat(field, " ");
        }
        SetConsoleTitle(field);
    }
    else {
        SetConsoleTitle("");
    }
    return 0;
}


      

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019