Supafly Blitz3D Window!!!

Blitz3D Forums/Blitz3D Programming/Supafly Blitz3D Window!!!

JoshK(Posted 2004) [#1]
It's fairly easy to make a Blitz window resizable. There's also a method out there to change the default startup window size. However, this isn't enough.

To make a window truly resizable, you have to initiate the Graphics3D program using the largest window size the user might experience. If your window client area goes any bigger than the area you initialize with graphics3d, DirectX just won't render.

This means that you have to start the window out at the desktop size. When you click to un-maximize the window, it is still at the desktop size. It's hard or impossible to grab the corner and drag to resize it smaller. The only way to fix this is to resize the window smaller after the graphics3d command. So you have the initial 400x300 window, then a large window flashes on sized at the desktop size, and then you finish with an 800x600 window. Very unprofessional.

Well, thanks to Spindeln, there is finally a way around it. He hacked runtime.dll so that the Blitz window starts off hidden, and any graphics3d() command creates a hidden window. The result is a windowed Blitz3D app that starts off with no flashing. Even cooler, the window stays hidden while the program media is loading, and doesn't appear until the program is really ready to start.

Of course, we can't post the hacked runtime.dll file, and I also want to get him a little cash for his work, so we are talking about distribution right now.

Check it out here:
http://www.leadwerks.com/post/windemo.zip


IPete2(Posted 2004) [#2]
Josh,

That is SOOOO cool!

Nice one!

IPete2.


JoshK(Posted 2004) [#3]
Spindeln deserves the credit. I just told him what I wanted, and he did the work.

Re-uploaded, with an example of the non-hacked program included, so you can see the ugliness I had to deal with before.


boomboom(Posted 2004) [#4]
there was a post a while ago (severel months) on BC or this site that detailed the exact thing to change with resource hacker to do this.


Red(Posted 2004) [#5]
there was a post a while ago (severel months) on BC or this site that detailed the exact thing to change with resource hacker to do this

no exactly
On BC, the hack changed the blitz runtime window size.
In this example there's no blitz runtime.

It works.


boomboom(Posted 2004) [#6]
ok, this is pretty cool, the only downside is it would have to be rehacked everytime a new version of blitz came out (not oftern then)


jfk EO-11110(Posted 2004) [#7]
Sounds very good. I guess one could combine this with robs blitzsys "window without titlebar and borders" to popup an app startup logo picture.

Anyway, what we need is some code that will hack the runtime.dll, because it should also be possible to patch upcoming versions of the runtime.


AntonyWells(Posted 2004) [#8]
Halo, I need this(badly) for a sdl lib I'm doing...any chance you're going to release it? (I can't mark having a problem, it's a useful addition)


Richard Betson(Posted 2004) [#9]
Neat!

L8r,


JoshK(Posted 2004) [#10]
It's up to the author. ^_^


Jeremy Alessi(Posted 2004) [#11]
Sweet!


BODYPRINT(Posted 2004) [#12]
OK guys, here's how to make any Blitz3D program hide the startup windows. It's too easy.

In your game code add the following lines

;My Game is called ARK 3D
Const TITLE$="ARK 3D"
AppTitle TITLE$
hwnd=FindWindow("Blitz Runtime Class",TITLE)

Graphics3D 800,600,32,2

;Add the following line when you want window to appear !!
ShowWindow hwnd,5


Now, with a Hex editor, like UltraEdit, load the runtime.dll from the bin directory in Blitz3D.
Do a search for CA 10 8B

When the first one comes up change 10 to 00 and save.

That's it, your done.

Any programs you run from the editor or compile will now work with this.
Don't forget that all your old programs will have to be modified otherwise they will come up blank. :-)

Enjoy :-)


Bot Builder(Posted 2004) [#13]
WOW this is nice!! thanks.

Btw, here are the userlib entries:
.lib "user32.dll"
FindWindow%(runtime$, name$):"FindWindowA"
ShowWindow%(hwnd,val):"ShowWindow"


Note I figured them out myself :] even though it was cuz I was lazy and didn't want to search, so the parameter names might be off a bit.


poopla(Posted 2004) [#14]
Holy god in heaven. Halo smiled! Is it your birthday Halo? :)


Bot Builder(Posted 2004) [#15]
LOL I actually thought you said modify the produced exe :P this worked anyway, but eh. I guess now I'll have to modify samples to let them run.....


Floyd(Posted 2004) [#16]
Lately I've been using my old Win98SE / DX7 PC for some testing. The program doesn't start up properly on this machine.

1. I put a shortcut to WindowDemo.exe on my desktop and close all windows.

2. When I double click the shortcut I see the outline of a window. There is nothing inside the window. I just see through to the desktop.

3. I can drag the window border to resize. The window is still empty while this is happening.

4. As soon as I release the mouse button the bird demo begins running in the resized window. Everything works correctly now.

EDIT: See my message farther down this thread. The real culprit was a 640x480 desktop.


Bot Builder(Posted 2004) [#17]
Hmm. Doesn't sound so good :/

Well you can always include a Win95/98 version of your app.

Here's a proggie to patch your runtimedll for you:
Graphics 640,480,0,2

CopyFile "runtime.dll","runtime_backup.dll"

fil=OpenFile("runtime.dll")
siz=FileSize("runtime.dll")

For i=0 To siz
	byt=ReadByte(fil)
	If Frst=True Then
		If scnd=True Then
			If byt=$8B Then
				pos=i-1
				Exit
			Else
				scnd=False
				If byt<>$CA Then frst=False
			EndIf
		ElseIf byt=$10 Then
			scnd=True
		Else
			If byt<>$CA Then Frst=False
		EndIf
	ElseIf byt=$CA Then
		Frst=True
	EndIf	
Next

Print "Changing byte "+pos+" (value $10) to $00"

SeekFile fil,pos
WriteByte fil,$00

CloseFile fil

Print "Done. Press any key to continue."


You have to compile this to an exe in blitz\bin, and then run.

And a handy function:
Function AppName(title$,close_prompt$="")
	AppTitle title$,close_prompt$
	hwnd=FindWindow("Blitz Runtime Class",title$)
	ShowWindow hwnd,5
End Function


A tip, if you resize the app in program then set ShowWindow Hwnd,0 then resize, and then set ShowWindow Hwnd,5.


Red(Posted 2004) [#18]
@Floyd

Did yu try the Phil74's hack code or Halo's code ?


BODYPRINT(Posted 2004) [#19]
Well done bot builder.

I was going to make a patch program, but didn't get around to it yet:-)
Thanks.

You were correct about the produced executable.
That's originally what I said to modify :-D
Then I found it in the runtime.dll (I was looking at the wrong dll intially !! >:-( Me bad !! )

You could actually use your patch program to modify any produced exe if you don't want to change the runtime.dll.


Floyd(Posted 2004) [#20]
Regarding halo's windemo: It looks like my previous post about Win98 missed the real problem.

On my WinXp machine the program runs flawlessly. If I set WinDemo.exe to run in Win98/Me compatibility mode it still works. But when set to run in 640x480 mode it fails as before. Turning off Win98/Me compatibility, but leaving 640x480 still fails.

Next I tried again on the old Win98 PC. The desktop was set to 640x480. After changing to 800x600 the problem went away. The program starts up with the window filling the screen.

A look at the BirdDemo.bb source confirms that it is forces an 800x600 window, ignoring desktop resolution.


martonic(Posted 2004) [#21]
Phil74 and Bot Builder: thanks!
This also works in full-screen mode.
Phil74: Can you give a brief explanation of what your "hack" changes in the blitz execution, and how you figured out your genius solution? Thanks again.


Spinduluz(Posted 2004) [#22]
Just use a disassembler. Things like this are real easy in win32 since (at least my disassembler) marks all exported/imported functions. Then just sort out all imported functions that can set window style flags and see if and what flags they enable. (In this case its SetWindowLong).


jfk EO-11110(Posted 2004) [#23]
hehe, I guess theoreticly this was reverse engineering... but since it is for the sake of the product, blitzresearch may close both eyes.

Very useful stuff here, one of those threads that is worth to be saved in the goodies folder.


JoshK(Posted 2004) [#24]
It would be a lot simpler if Graphics3D() just returned the hwnd.


Picklesworth(Posted 2004) [#25]
It would be even easier if mark saved us from our misery and fixed the problem himself if it is so bloody easy...

Thanks for the stuff!

Here is a nice and quick program patcher. 99% credit to botbuilder :D
http://www.freewebs.com/bass-line/misc/StartWindowRemover.zip

Notice the wonderful nonexistant background :)


JoshK(Posted 2004) [#26]
Here is my version. I used Blitz+, so there is no need for a DLL:
http://www.leadwerks.com/post/BlitzEXEHacker.zip

Now what would be cool is if someone could hack in an icon, and eliminate the need to use ResHacker.

Repeat

	path$=RequestFile("Modify Executable","exe")
	If path="" Exit
	;Print "Modifying "+Chr(34)+path+Chr(34)+"..."
	fil=OpenFile(Path$)
	If fil
		siz=FileSize(Path$)
		For i=0 To siz
			byt=ReadByte(fil)
			If Frst
				If scnd
					If byt=$8B
						pos=i-1
						Exit	
					Else
						scnd=False
						If byt<>$CA frst=False
					EndIf
				ElseIf byt=$10
					scnd=True
				Else
					If byt<>$CA Frst=False
				EndIf
			ElseIf byt=$CA
				Frst=True
			EndIf	
		Next
		SeekFile fil,pos
		WriteByte fil,$00
		CloseFile fil
		EndIf
	
	Forever

;Print "Done."
;WaitKey
End



BlitzSupport(Posted 2004) [#27]

Now what would be cool is if someone could hack in an icon, and eliminate the need to use ResHacker.


For what it's worth, if you're hacking about with runtime.dll, you might want to try using ResHack on it once to replace the built-in icon (the crap rocket thing). At least then you get your own icon each time you create an executable...


ryan scott(Posted 2004) [#28]
well, then a plug for protean ide. It writes out an icon for ya everytime you compile to exe.


jfk EO-11110(Posted 2005) [#29]
Just an additional note (no, not exhuming this thread, just put some flowers onto it) you can get the Blitz HWND now by:
SystemProperty$("AppHWND")


Picklesworth(Posted 2005) [#30]
This is now (not then, but now) a matter of grabbing the window's handle and setting WS_THICKFRAME to it.

Const GWL_STYLE = (-16)
Const WS_THICKFRAME = $00040000

Graphics 1024,768,0,2

hWnd=SystemProperty$("AppHWnd")
style=api_GetWindowLong(hWnd,GWL_STYLE)
style=style Or WS_THICKFRAME
api_SetWindowLong(hWnd,GWL_STYLE,style)

Rect 50,50,400,500

WaitKey
End


Need a reasonably decent version of User32.decls

If you have a way to grab the user's desktop width/height, I suggest using that for the Graphics command.


jfk EO-11110(Posted 2005) [#31]
hu? What is this about, Mr. Picklesworth? Altering the frame of the window?


Blaine(Posted 2005) [#32]
See what I had asked in this topic.
Basically this disables the Blitz window so that you have to explicitely show it.


jfk EO-11110(Posted 2005) [#33]
Yes, I know, but I was wondering what Mr. Picklesworth meant in the last post.


Picklesworth(Posted 2005) [#34]
WS_THICKFRAME makes it resizeable.


jfk EO-11110(Posted 2005) [#35]
Ah, ok , thanks! But - will this also resize the blitz back- and frontbuffer (and GraphicsWidth() etc.)?


Picklesworth(Posted 2005) [#36]
Ah, that's the point: It doesn't resize them, thus allowing for you to rearrange the graphics yourself :)
Of course, for that you would need a way to check the size of the application's window every frame... Which I can not immeadiately recall how to do.

If you want resizeable windows with resizeable contents, I think Graphics(1024,768,0,3) should do.


videz(Posted 2014) [#37]
I'm looking for such a functionality to hide the opening startup window, anyone has a copy of the above or alternate solution?

I can't seem to get Bot Builder's patch code to work. there's still a black square when I run my app. I'm using v1.106..