Code archives/User Libs/Misc' Window Functions

This code has been declared by its author to be Public Domain code.

Download source code

Misc' Window Functions by B+man
(Posted 21 years ago)
Some things I thought people might find useful
;Extra Little BP functions
;Which I thought some people may find handy
;
;There's two or three not written by me, though, I have included
;them because they are pretty handy!
;
;Note: Please make sure that the userlib declarations at the
;bottom of this doc is located in your blitz userlibs folder


;Internal Arrays
Dim dabzCloseAllWindowsArraydabz%(200)

;CONSTANTS
;GetWindowLong Index Codes
Const GWL_WNDPROC    		=   (-4)
Const GWL_HINSTANCE     	=   (-6)
Const GWL_HWNDPARENT    	=  	(-8)
Const GWL_STYLE         	=  	(-16)
Const GWL_EXSTYLE       	=  	(-20)
Const GWL_USERDATA      	=   (-21)
Const GWL_ID            	=   (-12)

;GetDriveType return codes
;Removable/fixed and CDROM are implemented in this file, if you
;need anything else, build new functions with these codes
Const DRIVE_UNKNOWN     = 0
Const DRIVE_NO_ROOT_DIR = 1
Const DRIVE_REMOVABLE   = 2
Const DRIVE_FIXED       = 3
Const DRIVE_REMOTE      = 4
Const DRIVE_CDROM       = 5
Const DRIVE_RAMDISK     = 6

;Window placement
Const HWND_TOPMOST = $FFFFFFFF

;TYPES
Type MSG
	Field hTopWnd
	Field message
	Field wParam
	Field lParam
	Field time
	Field point
End Type

;Always handy to have the RECT structure
Type WIN_RECT 
	Field leftRect
	Field topRect
	Field rightRect
	Field bottomRect
End Type


;Dabz Blitz+ Functions
Function PrintImage(filepath$)
	ExecFile ("c:\windows\system32\mspaint.exe "+filepath$+" /p")
End Function

Function GetWinOSHandle(win)
	Return(QueryObject(win,1))	
End Function

Function GetWindowInstance(hWnd)
	Return(GetWindowLong(hWnd,GWL_HINSTANCE))
End Function

Function GetWindowProc(hWnd)
	Return(GetWindowLong(hWnd,GWL_WNDPROC))
End Function

Function GetWindowParent(hWnd)
	Return(GetWindowLong(hWnd,GWL_HWNDPARENT))
End Function
 
Function GetWindowStyle(hWnd)
	Return(GetWindowLong(hWnd,GWL_STYLE))
End Function

Function GetWindowDC(hWnd)
	Return(GetDC(hWnd))
End Function

Function ChangeWindowPosition(hWnd,x,y)
	SetWindowPos(hWnd,0,x,y,0,0,1)
End Function

Function ReformatWindow(hWnd,x,y,width,height)
	SetWindowPos(hWnd,0,x,y,width,height,0)
End Function

Function SetTopWindow(hWnd,x,y)
	SetWindowPos(hWnd,HWND_TOPMOST,x,y,0,0,1)
End Function

Function WindowReady(hWnd)
	SetForegroundWindow(hWnd)
End Function

Function GetFocusedWindow()
	Return(GetForegroundWindow())
End Function

Function MoveCursor(x,y)
	SetCursorPos(x,y)
End Function

Function OpenEmailClient(email$ = "")
	ExecFile("mailto:"+email$)
End Function

Function CurrentUser$()
	bnkName = CreateBank(256)
	bnkSize = CreateBank(1)
	PokeByte(bnkSize,255,0)

	GetUserName(bnkName,bnkSize)
	
	copiedChar = PeekByte(bnkSize,0)

	For loop = 0 To copiedChar-1
		userName$ = userName$ + Chr$(PeekByte(bnkName,loop))
	Next
	
	Return(Left(userName$,(Len(userName$)-1)))
	End Function

Function GetComputerName$()
	bnkName = CreateBank(256)
	bnkSize = CreateBank(1)
	PokeByte(bnkSize,255,0)

	GetComputerNameA(bnkName,bnkSize)
	
	copiedChar = PeekByte(bnkSize,0)

	For loop = 0 To copiedChar-1
		userName$ = userName$ + Chr$(PeekByte(bnkName,loop))
	Next
	
	Return(Left(userName$,(Len(userName$)-1)))
End Function

Function HideWindow(hWnd)
	ShowWindowA(hWnd,0)
End Function

Function ShowWindow(hWnd)
	ShowWindowA(hWnd,5)
End Function

Function OpenWebExplorer(add$ = "http://www.blitzbasic.com")
ExecFile(add$)
End Function

Function SetWindowIcon(hWnd,ICOfile$)
icon=ExtractIconA(hWnd,ICOfile$,0)
SetClassLongA(hWnd,-14,icon)
End Function

Function GetDesktopHandle()
Return(GetDesktopWindow())
End Function

Function CloseAllWindows()
dabzCloseAllWindowsArraydabz(0) = GetForegroundWindow()
For n = 1 To 50
	win = dabzCloseAllWindowsArraydabz(n-1)
	dabzCloseAllWindowsArraydabz(n) = GetWindow(win,2)
	If dabzCloseAllWindowsArraydabz(n) = 0 Then Exit
Next

For t = 0 To n-1
	If IsWindowVisible(dabzCloseAllWindowsArraydabz(t))
		CloseWindow%(dabzCloseAllWindowsArraydabz(t))
	End If
Next
End Function

Function OrganiseDesktop()
	deskHwnd = GetDesktopHandle()
	CascadeWindows(deskHwnd,$0004,0,0,0)
End Function

Function CreateCenterWindow (title$, width, height, group = 0, style = 15)
	Return CreateWindow (title$, (ClientWidth (Desktop ()) / 2) - (width / 2), (ClientHeight (Desktop ()) / 2) - (height / 2), width, height, group, style)
End Function



;------ This function may take some explaining ------
Function GetDrives$(logicalSeperatorChar$)
	LogicalDrivesOnSystemBank = CreateBank(254)
	SizeOfLogicalDrivesBuffer = GetDriveStr(255,LogicalDrivesOnSystemBank)
	For n = 0 To SizeOfLogicalDrivesBuffer-1
		char = PeekByte(LogicalDrivesOnSystemBank,n)
		If char = 0
			char = Asc(logicalSeperatorChar$)
		End If
		allLogicalDrivesOnSystem$ = allLogicalDrivesOnSystem$ + Chr$(char)
	Next
	Return allLogicalDrivesOnSystem$
End Function

;The [logicalSeperatorChar$] parameter is a character that
;seperates each drive in the returned string, for example, if you
;call the GetDrives$ function like this:-
;
;		drives$ = GetDrives$("|")
;
;The returned string may look a little like this:-
;
;		"A:\|C:\|D:\|E:\|F:\|H:\|I:\|"
;
;So you can then use your defined character (which is '|') to chop
;the string up into different drives, sort of like this:-

;[example code]
;		Include "C:\BPinc\Windows.bbh" ;File that contains the GetDrives$ function
;
;		Const DRIVES_MAX = 99
;
;		Dim AvailableDrives$(DRIVES_MAX)
;
;		drives$ = GetDrives("|")
;
;		For loop = 0 To Len(drives$)
;			char$ = Mid$(drives$,loop,1)
;			If char$ <> "|"
;				tempDrive$ = tempDrive$ + char$
;			Else
;				AvailableDrives$(driveCount) = tempDrive$
;				driveCount = driveCount + 1
;				tempDrive$ = ""
;			End If
;		Next
;
;
;		For n = 0 To driveCount-1
;			Print AvailableDrives$(n)
;		Next

;		WaitKey


Function IsDriveRemovable(rootPath$)
	If GetDriveType(rootPath$) = DRIVE_REMOVABLE
		Return(True)
	Else
		Return(False)
	End If
End Function

Function IsDriveFixed(rootPath$)
	If GetDriveType(rootPath$) = DRIVE_FIXED
		Return(True)
	Else
		Return(False)
	End If
End Function

Function IsDriveCDROM(rootPath$)
	If GetDriveType(rootPath$) = DRIVE_CDROM
		Return(True)
	Else
		Return(False)
	End If
End Function


;----- USERLIB DECLS FILE CONTENTS ------
;----------------------------------------
;Windows.bbh Declarations
;Note - This makes 'Windows.bbh' functions turn yellow in the IDE
;-----------------------------------------
.lib "Windows.bbh"
PrintImage(imagePath$)
GetWinOSHandle%(win%)
GetWindowInstance%(hWnd%)
GetWindowProc%(hWnd%)
GetWindowParent%(hWnd%)
GetWindowStyle%(hWnd%)
GetWindowDC%(hWnd%)
ChangeWindowPosition(hWnd%,x%,y%)
ReformatWindow(hWnd%,x%,y%,width%,height%)
SetTopWindow(hWnd%,x%,y%)
WindowReady(hWnd%)
;GetWindowText$(hWnd)
GetFocusedWindow%()
MoveCursor(x%,y%)
OpenEmailClient(emailAdd$)
CurrentUser$()
GetComputerName$()
HideWindow(hWnd%)
ShowWindow(hWnd%)
OpenWebExplorer(address$)
SetWindowIcon(hWnd,ICOfile$)
GetDesktopHandle%()
CloseAllWindows()
OrganiseDesktop()
CreateCenterWindow%(title$,width%,height%,group%,style%)
GetDrives$(seperatorChar$)
IsDriveRemovable%(root$)
IsDriveFixed%(root$)
IsDriveCDROM%(root$)


;------------------------------------------



;---------------------------------------
;WinAPI Declarations
;----------------------------------------

.lib "user32.dll"
GetDC%(hWnd)
GetWindowLong%(hWnd%,index%):"GetWindowLongA"
ShowWindowA%(hWnd%,com%):"ShowWindow"
MoveWindow%(hWnd%,x%,y%,width%,height%,repaint%)
BringWindowToTop%(hWnd%)
SetWindowPos%(hWnd%,hWndInsertAfter,x%,y,cx%,cy%,flags%)
SetForegroundWindow%(hWnd%)
GetForegroundWindow%()
FindWindowText%(hWnd%,lpString$,maxCount%):"GetWindowTextA"
LoadCursor%(hInstance%,lpCursorName$):"LoadCursorA"
SetCursorPos%(x%,y%)
SwapMouseButton%(bSwap)
SetClassLongA%(hWnd%,nIndex%,Value%):"SetClassLongA"
PeekMessage%(MSG*,hWnd%,MsgFilterMin%,MsgFilterMax%,RemoveMsg%):"PeekMessageA"
GetMessage%(MSG*,hWnd%,MsgFilterMin%,MsgFilterMax%):"GetMessageA"
SetFocus%(hWnd%)
GetDesktopWindow%()
GetWindow%(hWnd%,Cmd%):"GetWindow"
CloseWindow%(hWnd%)
IsWindowVisible%(hWnd%)
GetTopWindow%(hWnd%)
CascadeWindows%(HwndParent%,How%,Rect,Kids%,hKids)
DrawIcon%(hDc%,x%,y%,hIcon%)


.lib "shell32.dll"
ExtractIconA%(hWnd%,File$,Index%):"ExtractIconA"

.lib "Advapi32.dll"
GetUserName%(strBuffer*,wSize*):"GetUserNameA"

.lib "Kernel32.dll"
GetComputerNameA%(strBuffer*,wSize*):"GetComputerNameA"
GetDriveStr%(bufferLen%,buffer*):"GetLogicalDriveStringsA"
GetDriveType%(rootPath$):"GetDriveTypeA"
GetLastAPIError%():"GetLastError"

(C++ Code Removed)

Comments

Malice
(Posted 18 years ago)
CreateWindow and QueryObject functions aren't defined.

markcw
(Posted 18 years ago)
It's BlitzPlus code.

Dabhand
(Posted 18 years ago)
Yep, BlitzPlus... And before you ask, its mine, though I moved the account on.

3 years, doesnt time fly! :)

Dabz

Malice
(Posted 18 years ago)
;Extra Little BP functions


Haha! Oops, sorry, didn't see that bit :)

Code Archives Forum