WinBlitz 3d

Blitz3D Forums/Blitz3D Programming/WinBlitz 3d

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

@ Cygnus : here it is, I only tested it with one of the examples that came with it (button.bb) and it works, but maybe not with everything... and maybe only on some windows platforms (I'm at work, using win2000, I'll test with xp later today).
it's quick and dirty, meaning I just commented out some sections etc, but anyway :

Function CreateWindow(title$,x,y,width,height,group=0,style=0)

	Local CLASSbank
	Local WINBLITZ3D_CLASS_NAME$ = "WinBlitz3D_CLASS"
	Local statusCLASS$ = ""
	Local hwnd
	Local statusbar

	; create class and winproc function.
	If FIRST_CREATE_CLASS = 0 Then

		; hide the blitz runtime window.
		RUNTIME_Window$ = "Initializing GUI"
		AppTitle RUNTIME_Window
		runtimewindow = apiFindWindow("",RUNTIME_Window$)
		;apiShowWindow runtimewindow,SW_HIDE

		; INITCOMMONCONTROLSEX struct
		CommonControls = CreateBank(8)
		PokeInt CommonControls,0,BankSize(CommonControls)
		PokeInt CommonControls,4,ICC_WIN95_CLASSES

		; Registers and initializes the common controls.
		bm = apiInitCommonControls(GRAB_BankAddr(CommonControls))

		; create the winproc function.
		WinProcBank = CreateBank(1256)
		Restore CREATE_WINPROC_FUNCTION
		Repeat
			Read e_data
			If e_data = 999 Then Exit
			PokeByte WinProcBank,next_entry_data,e_data
			next_entry_data = next_entry_data + 1
		Forever

		; location offset where to copy defwindowproc data.
		winproc_poke_offset = next_entry_data

		; store address of bank to hold winproc return values.
		WinProcReturn = CreateBank(124)
		WinProcReturnAddr = GRAB_BankAddr(WinProcReturn)

		; poke the address of the bank to store winproc return values.
		PokeByte WinProcBank,03,WinProcReturnAddr And 255
		PokeByte WinProcBank,04,WinProcReturnAddr Shr 8 And 255
		PokeByte WinProcBank,05,WinProcReturnAddr Shr 16 And 255
		PokeByte WinProcBank,06,WinProcReturnAddr Shr 24

		;
		defwinbank = CreateBank(256)
		Restore DEF_WINDOW_PROC
		next_entry_data = 0
		Repeat
			Read e_data
			If e_data = 999 Then Exit
			PokeByte defwinbank,next_entry_data,e_data
			next_entry_data = next_entry_data + 1
		Forever

		; get thunk to defwindowproc
		USER32 = apiGetModuleHandle(GRAB_StringAddr("user32.dll"))
		DefProcA = apiGetProcAddress(USER32,"DefWindowProcA")

		; poke defwindowproc thunk memory pointer.
		PokeByte defwinbank,18,DefProcA And 255
		PokeByte defwinbank,19,DefProcA Shr 8 And 255
		PokeByte defwinbank,20,DefProcA Shr 16 And 255
		PokeByte defwinbank,21,DefProcA Shr 24

		; copy defwindowproc bank to winproc bank.
		CopyBank defwinbank,0,WinProcBank,winproc_poke_offset,26

		FreeBank defwinbank

		; create winblitz3d's class.
		;WINBLITZ3D_CLASS_NAME$ = "WinBlitz3D_CLASS"
		CLASSbank = CreateBank($30)
		PokeInt CLASSbank,$00,BankSize(CLASSbank)
		PokeInt CLASSbank,$04,CS_HREDRAW Or CS_VREDRAW Or CS_GLOBALCLASS
		PokeInt CLASSbank,$08,GRAB_BankAddr(WinProcBank)
		PokeInt CLASSbank,$14,apiGetModuleHandle(0)
		PokeInt CLASSbank,$18,apiLoadIcon(hModule,32512)
		PokeInt CLASSbank,$20,apiGetSysColorBrush(COLOR_BTNFACE)
		PokeInt CLASSbank,$28,GRAB_StringAddr(WINBLITZ3D_CLASS_NAME$)

		; attempt to register the class.
		WinBlitzClass = apiRegisterClass(GRAB_BankAddr(CLASSbank))

		If WinBlitzClass = 0 Then
			DebugLog "Error Creating WinBlitz3D Class!"
			Stop
		EndIf

		;WinProcBlitz3D = apiGetWindowLong(runtimewindow,GWL_WNDPROC)
		;apiSetWindowLong runtimewindow,GWL_WNDPROC,GRAB_BankAddr(WinProcBank)

		FIRST_CREATE_CLASS = 1

	EndIf

	If group = 0 Then
		group = apiGetDesktopWindow()
	EndIf

	Select style

		Case 0 ; borderless popup window
			style = WS_POPUP

		Case 1 ; no resize with close button
			style = WS_CAPTION 	Or WS_SYSMENU Or  WS_POPUP

		Case 2 ; resize and statusbar
			statusCLASS$ = "msctls_statusbar32"
			style = WS_MINIMIZEBOX Or WS_SYSMENU Or WS_TABSTOP Or WS_THICKFRAME Or WS_VISIBLE

	Default
		; passed own style
		style = style				
	End Select

	;hwnd = apiCreateWindow(0,WINBLITZ3D_CLASS_NAME$,title$,style,x,y,width,height,group,0,apiGetModuleHandle(0),0)
	;apiShowWindow hwnd,$5
	;apiUpdateWindow(hwnd)

	hwnd=runtimewindow

	; attach window status bar
	If statusCLASS$ = "msctls_statusbar32" Then 		
		statusbar = apiCreateWindow(0,statusCLASS$,"",WS_CHILD Or WS_VISIBLE,0,0,100,100,hwnd,0,apiGetModuleHandle(0),0)	
		statuspartsbank = CreateBank(255)
		apiSetWindowLong statusbar,GWL_USERDATA,statuspartsbank
	EndIf
	
	;
	bank = CreateBank(256)
	PokeByte bank,0,BB_ID_WINDOW
	PokeInt bank,4,statusbar
		
	apiSetWindowLong hwnd,GWL_USERDATA,bank
		
	Return hwnd
	
End Function