Skip to content

Commit 50e6b5e

Browse files
committed
SciterAPIHost.CreateMainWindow parameters width and height is optional now, if it omit windows take half of current screen and center window
1 parent 2b24c0c commit 50e6b5e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

EmptyFlow.SciterAPI/Client/SciterAPIHost.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,28 @@ public static IntPtr WindowsDelegateImplementaion ( IntPtr hwnd, uint msg, IntPt
101101
return 0;
102102
}
103103

104-
public void CreateMainWindow ( int width, int height, bool enableDebug = false, bool enableFeature = false ) {
104+
public void CreateMainWindow ( int width = 0, int height = 0, bool enableDebug = false, bool enableFeature = false ) {
105105
if ( enableDebug ) m_basicApi.SciterSetOption ( IntPtr.Zero, RtOptions.SCITER_SET_DEBUG_MODE, new IntPtr ( 1 ) );
106106
if ( enableFeature ) m_basicApi.SciterSetOption ( IntPtr.Zero, RtOptions.SCITER_SET_SCRIPT_RUNTIME_FEATURES, new IntPtr ( (int) DefaultRuntimeFeatures ) );
107107

108-
var rectangle = new SciterRectangle ( 0, 0, width, height );
109-
108+
var rectangePointer = nint.Zero;
109+
if ( width > 0 && height > 0 ) {
110+
var rectangle = new SciterRectangle ( 0, 0, width, height );
111+
rectangePointer = Marshal.AllocHGlobal ( Marshal.SizeOf<SciterRectangle> () );
112+
Marshal.StructureToPtr ( rectangle, rectangePointer, false );
113+
}
110114
var ptr = Marshal.GetFunctionPointerForDelegate<WindowDelegate> ( WindowsDelegateImplementaion );
111115

112116
m_mainWindow = m_basicApi.SciterCreateWindow (
113117
WindowsFlags.Main | WindowsFlags.Resizeable | WindowsFlags.Titlebar | WindowsFlags.Controls,
114-
ref rectangle,
118+
rectangePointer,
115119
RuntimeInformation.IsOSPlatform ( OSPlatform.Windows ) ? ptr : IntPtr.Zero,
116120
IntPtr.Zero,
117121
IntPtr.Zero
118122
);
119123

124+
if ( rectangePointer != nint.Zero) Marshal.FreeHGlobal ( rectangePointer );
125+
120126
if ( enableDebug ) {
121127
m_basicApi.SciterSetupDebugOutput (
122128
m_mainWindow,

0 commit comments

Comments
 (0)