Forum > Windows

Can't hide main window

(1/2) > >>

TyneBridges:
I'm trying to create a project in Windows where the main window is hidden. It's converted from Delphi where the usual advice worked. However, trying to replicate this in Lazarus gives me a visible window that looks like a console window except that it has my application icon, as shown. The obvious cause would be writing to the console but I've searched through my code for references to Write and Writeln followed immediately by (' and there are none.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---My project source file ends as follows: begin     Application.Initialize;     Application.ShowMainForm:= False;     Application.Title:= 'My Title';     Application.CreateForm(THSForm, HSForm);     Application.Run;end.     

There is a lot of code in FormCreate that I tried commenting out completely (leaving just the header and Begin and End) but, after recompiling, the form still showed. I have no OnShow or OnActivate event. Has anybody any idea why the application would be visible despite this?

My application is a Windows GUI one and does not use the Console.

dseligo:
I just tried this to put this line "Application.ShowMainForm:=False;" in some test project and form isn't shown - Lazarus 2.0.10 on Windows. So I guess generally Lazarus is working fine.

Try to create new project, put "Application.ShowMainForm:=False;" in it and see if it works.

If it works, then make some other form main in your project - see if it is related to the main form.

You don't create anything else (forms, data modules) in your project source? Code you've shown between "begin" and "end." is all?

TyneBridges:
Thanks dseligo. Yes, the code I quoted is everything apart from the preamble below. I'll try your suggestion with a blank project. (DiscFrm referenced below is a disclaimer that I do show after the main form is initialised and, ironically, that isn't displaying correctly either - it shows only as a title bar; but I'll tackle that when I get this issue fixed.)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Logr; {$MODE Delphi} uses  Forms, Interfaces,  hsave in 'hsave.pas' {HSForm},  discfrm in 'discfrm.pas' {Disclaimer},  Windows; {$R *.res}  

TyneBridges:
The blank project test worked. The application was invisible and could only be seen in Windows' task list, as I would expect.

Would my problem be related to having a tray icon? The following was in the code I had commented out but my original application window still showed even when this wasn't invoked.
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      With TrayIconData do        begin            cbSize:= SizeOf(TrayIconData);            hWnd:= Handle; // Note: different from Delphi which was just Wnd            uID:= 0;            uFlags:= NIF_MESSAGE + NIF_ICON + NIF_TIP;            uCallBackMessage:= WM_ICONTRAY;            hIcon:= Application.Icon.Handle;            StrPCopy(szTip, Application.Title);        end;        Shell_NotifyIconW(NIM_ADD, @TrayIconData); //Note: needed amendment from Delphi        If Debugging then        begin            Writeln(DL, 'Added Tray Icon ' + DateTimeToStr(Now));            Flush(DL);        end;    
Maybe that's a red herring: I've just commented out the above again and recompiled, and my application still showed as in my original image. 

I don't think I can change my main form without messing up the project badly, since there's a lot of initialisation (opening of files behind the scenes) in the initial form's OnCreate event. %)

Any further ideas/help from anyone would be welcome. Thanks.

PascalDragon:

--- Quote from: TyneBridges on January 09, 2021, 05:20:32 pm ---Any further ideas/help from anyone would be welcome. Thanks.

--- End quote ---

Is Project Settings -> Compiler Settings -> Configuration and Targets -> Win32-GUI-Application enabled in your project?

Alternatively you could display the value of the System.IsConsole variable in your application to see whether the RTL considered your application to be a console one.

Navigation

[0] Message Index

[#] Next page

Go to full version