Hi Angus,

The irritating thing with Windows is that all stdout messages get lost
somewhere when using the GUI subsystem. You would have to add additional
code to handle all debugging messages. Now that isn´t that hard to do, but
another issue was that some shell script stopped working when linking to the
gui subsystem. I cannot remember what worked and what didn´t. Maybe the
mingw runtime does a better job, but you´ll have to try that out.

Anyway, at that time I´ve looked around, but there didn´t seem to be a more
elegant solution. The console closing code is not that sophisticated, so
that could be improved.

BTW The WinMain stuff get´s added by qtmain automatically.

Ruurd

"Angus Leeming" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Good evening, Ruurd.
>
> I wonder if you could help out a Windows novice --- me?
> My question concerns the way that Windows treats LyX --- as
> a Windows GUI app or as a console one. At the moment, Windows
> believes that LyX is a console app because it has a "main"
> function rather than a "WinMain".
>
> You've added code in os_win32.C's init function to close
> down the console window that Windows helpfully displays
> for us:
>
> void os::init(int /* argc */, char * argv[])
> {
> #ifdef _WIN32
>     // Close the console when run (probably)
>     // not run from command prompt
>     char WindowTitle[1024];
>     HWND hwndFound;
>     GetConsoleTitle(WindowTitle,1024);
>     if ((strcmp(WindowTitle, argv[0]) == 0) ||
>         (strcmp(WindowTitle,"LyX") == 0)) {
>         // format a "unique" newWindowTitle
>         wsprintf(WindowTitle,"%d/%d",
>             GetTickCount(),
>             GetCurrentProcessId());
>         // change current window title
>         SetConsoleTitle(WindowTitle);
>         // ensure window title has been updated
>         Sleep(40);
>         // look for newWindowTitle
>         hwndFound=FindWindow(NULL, WindowTitle);
>         // If found, hide it
>         if ( hwndFound != NULL)
>             ShowWindow( hwndFound, SW_HIDE);
>     }
> #endif
> }
>
>
> Would it not be more elegant to tell Windows that LyX
> is actually a GUI-based app by giving it a WinMain?
>
> The code below compiles fine for me with
> $ g++ -mwindows -o trial trial.C
>
> #if defined (_WIN32)
> # define WIN32_LEAN_AND_MEAN
> # include <stdlib.h>  // for __argc, __argv
> # include <windows.h> // for WinMain
> #endif
>
>
> #if defined (_WIN32)
> int mymain(int argc, char * argv[])
> #else
> int main(int argc, char * argv[])
> #endif
> {
>     // LyX's code, unchanged, goes here.
>     Sleep(5000);
>     return 0;
> }
>
>
> // This will require the "-mwindows" flag when linking with
> // gcc under MinGW.
> // For MSVC, use "/subsystem:windows".
> #if defined (_WIN32)
> int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
> {
>     std::cout << "WinMain" << std::endl;
>     return mymain(__argc, __argv);
> }
> #endif
>
> Regards,
> Angus
>



Reply via email to