Erweiterungen
Übersicht
Windows
Event
Ressourcen
Beispiele
 

AppIcon


Ein Icon als Programmicon, in der Titelleiste und im Tray.
Das Icon kann als ico-Datei extern im gleichen Verzeichnis oder als Ressource in der EXE stecken.
#Include Once "window9.bi" Function AppIcon(ByVal icon As String, ByVal art As Integer=0) As Integer '------ Icon in der Titelleiste 'art=0 as file icon="icon.ico" 'art=1 from resource icon="FB_PROGRAM_ICON" If art = 1 Then art=LR_COPYFROMRESOURCE Else art=LR_LOADFROMFILE EndIf Var IMAGEID=LoadImage(GetModuleHandle(0),icon,IMAGE_ICON,16,16,art) SendMessage (GetActiveWindow,WM_SETICON,ICON_BIG,Cast(UInteger,IMAGEID)) Return SetClassLong(GetActiveWindow,GCL_HICON,Cast(UInteger,IMAGEID)) End Function Function ConsoleIcon (ByVal icon As String, ByVal art As Integer=0) As Integer Dim As Any Ptr SetIcon_Lib = DylibLoad ("Kernel32.dll") If SetIcon_Lib = 0 Then Print "Error 'SetIcon_Lib'" Return 0 Else Dim SetConsoleIcon As Function(ByVal hicon As HICON) As Integer SetConsoleIcon = DylibSymbol(SetIcon_Lib,"SetConsoleIcon") If SetConsoleIcon = 0 Then Print "Error 'SetConsoleIcon' (> WinXP ?)" DylibFree(SetIcon_Lib) Return 0 Else If art=0 Then 'mit ICOn-Datei SetConsoleIcon(Cast(HICON,LoadImage(GetModuleHandle(0), _ icon,IMAGE_ICON,0,0, LR_LOADFROMFILE Or LR_DEFAULTSIZE))) Else 'mit Ressource-Datei SetConsoleIcon(Cast(HICON,LoadImage(GetModuleHandle(0), _ icon,IMAGE_ICON,0,0,LR_COPYFROMRESOURCE))) EndIf EndIf DylibFree(SetIcon_Lib) EndIf Return 1 End Function

LoadPrivateFont


Ich wollte eine Anzeige für technische Werte haben, die wie ein LCD-Display erscheint.
Alles selbst zu zeichnen war mir zu aufwändig. Eine passende LCD-Schriftart ließ sich finden.
Die ttf-Datei kann extern im gleichen Verzeichnis oder als Ressource in der EXE stecken (in Ressourcen finden Sie ein Beispiel).
#Include Once "window9.bi" 'LoadPrivateFont("LCD.TTF") <-ext. File '34 FONT "LCD.TTF" <-in .rc File 'LoadPrivateFont("",34) 'If the function fails, the return value is zero. 'A font that is added by LoadPrivateFont is always private to the process that made 'the call and is not enumerable. When the process terminates, the system 'will remove all fonts installed by the process with the LoadPrivateFont function. Function LoadPrivateFont(ByVal filename as string, ByVal ResNr As Integer=0) As HANDLE If ResNr Then Dim As HRSRC Resource = FindResource(0,MAKEINTRESOURCE(ResNr),RT_FONT) Dim As Integer Length = SizeofResource(0,Resource) Dim As HGLOBAL Address = LoadResource(0,Resource) Dim As UInteger Count 'http://msdn.microsoft.com/en-us/library/dd183325 Return AddFontMemResourceEx(Address,Length,0,@Count) Else 'http://msdn.microsoft.com/en-us/library/dd183327 Return Cast(Handle,AddFontResourceEx(filename,FR_PRIVATE,0)) EndIf End Function

GetFileDate


#Include Once "window9.bi" Function FileExists(ByVal FileName As String) As Integer If GetFileAttributes(FileName) = -1 Then Return 0 Return 1 End Function Function FTime2String(ByVal fTime As FILETIME) As String Dim sTime As SYSTEMTIME FileTimeToLocalFileTime @fTime,@fTime FileTimeToSystemTime @fTime,@sTime Function = _ Right("0"+Str(sTime.wDay)+".",3) +_ Right("0"+Str(sTime.wMonth)+".",3) +_ Str(sTime.wYear)+", " +_ Right("00"+Str(sTime.wHour)+":",3) +_ Right("00"+Str(sTime.wMinute)+":",3) +_ Right("00"+Str(sTime.wSecond),2) End Function Function GetFileDate(ByVal Filename As String, ByVal tmp As Integer) As String '1=Datei erstellt (CreationTime) '2=letzte Aenderung (LastWriteTime) '3=letzter Zugriff (LastAccessTime) If FileExists(Filename)=0 Then Return "0" Dim As FILETIME cTime, lTime, lwTime Var handle=Open_File(Filename) GetFileTime(handle,@cTime,@lTime,@lwTime) Close_file(handle) Select Case tmp Case 1 : Return FTime2String(cTime) Case 2 : Return FTime2String(lwTime) Case 3 : Return FTime2String(lTime) Case Else : Return "0" End Select End Function Function SetFileLocalTime(ByVal Filename As String, ByVal tmp As Integer) As Integer '1=Datei erstellt (CreationTime) '2=letzte Aenderung (LastWriteTime) '3=letzter Zugriff (LastAccessTime) If FileExists(Filename)=0 Then Return 0 Dim As FILETIME cTime, lTime, lwTime, fTime Dim As SYSTEMTIME sTime Var handle=Open_File(Filename) GetFileTime(handle,@cTime,@lTime,@lwTime) GetLocalTime @sTime SystemTimeToFileTime @sTime, @fTime Select Case tmp Case 1 : LocalFileTimeToFileTime @fTime, @cTime Case 2 : LocalFileTimeToFileTime @fTime, @lwTime Case 3 : LocalFileTimeToFileTime @fTime, @lTime Case Else : Return 0 End Select Var erg= SetFileTime (handle, @cTime, @lTime, @lwTime) Close_file(handle) Return erg End Function

RecycleFile


Statt eine Datei zu löschen kann es von Vorteil sein sie in den Papierkorb zu lagern.
#Include Once "window9.bi" 'RecycleFile schickt eine Datei in den Papierkorb. 'Um eine Datei rekonstruieren zu können, müssen Sie deren voll- 'ständigen Pfadnamen und natürlich das Flag FOF_ALLOWUNDO angeben Function RecycleFile(filename As String) As Integer Dim filestruct As SHFILEOPSTRUCT With filestruct .pFrom = StrPtr(filename) .wFunc = FO_DELETE .fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION End With Return SHFileOperation(@filestruct) End Function

GERMAN_DATE


#Include Once "windows.bi" Function TIME_24HOURFORMAT() As String Dim sdt As String*64 GetTimeFormat LANG_GERMAN, TIME_FORCE24HOURFORMAT, 0, 0, sdt, SizeOf(sdt) Function = sdt End Function Function GERMAN_DATE(typ As Integer) As String Dim sdt As String*64 Select Case typ Case 1 GetDateFormat LANG_GERMAN, DATE_SHORTDATE, 0, 0, sdt, SizeOf(sdt) Case 2 GetDateFormat LANG_GERMAN , DATE_LONGDATE, 0, 0, sdt, SizeOf(sdt) Case 3 'DIN 5008, Schreib- und Gestaltungsregeln für die Textverarbeitung GetDateFormat LANG_GERMAN, 0, 0, "yyyy'-'MM'-'dd", sdt, SizeOf(sdt) Case 4 'ohne vorangestellte „0“, wenn einstelliges Tagesdatum GetDateFormat LANG_GERMAN , 0, 0, "d'. 'MMMM' 'yyyy", sdt, SizeOf(sdt) Case 5 GetDateFormat LANG_GERMAN , 0, 0, "d'. 'MMM' 'yyyy", sdt, SizeOf(sdt) End Select Function = sdt End Function

ProgressState im TrayIcon


#Include Once "window9.bi" Enum TBPFLAG TBPF_NOPROGRESS = 0 TBPF_INDETERMINATE = 1 TBPF_NORMAL = 2 TBPF_ERROR = 4 TBPF_PAUSED = 8 End Enum Enum THUMBBUTTONMASK THB_BITMAP = 1 THB_ICON = 2 THB_TOOLTIP = 4 THB_FLAGS = 8 End Enum Enum THUMBBUTTONFLAGS THBF_ENABLED = 0 THBF_DISABLED = 1 THBF_DISMISSONCLICK = 2 THBF_NOBACKGROUND = 4 THBF_HIDDEN = 8 THBF_NONINTERACTIVE = 10 End Enum Type THUMBBUTTON As THUMBBUTTONMASK dwMask As UINT iId As UINT iBitmap As HICON hIcon As WString*260 szTip As THUMBBUTTONFLAGS dwFlags End Type Type ITaskbarList3Vtbl_ As ITaskbarList3Vtbl Type ITaskbarList3 lpVtbl As ITaskbarList3Vtbl_ Ptr End Type Type ITaskbarList3Vtbl QueryInterface As Function (ByVal As ITaskbarList3 Ptr,ByVal As IID Ptr, ByVal As Any Ptr Ptr) As HRESULT AddRef As Function(ByVal As ITaskbarList3 Ptr) As HRESULT Release As Function(ByVal As ITaskbarList3 Ptr) As HRESULT HrInit As Function(ByVal As ITaskbarList3 Ptr) As HRESULT AddTab As Function(ByVal As ITaskbarList3 Ptr,a As HWND) As HRESULT DeleteTab As Function(ByVal As ITaskbarList3 Ptr,a As HWND) As HRESULT ActivateTab As Function(ByVal As ITaskbarList3 Ptr,a As HWND) As HRESULT SetActiveAlt As Function(ByVal As ITaskbarList3 Ptr,a As HWND) As HRESULT MarkFullscreenWindow As Function(ByVal As ITaskbarList3 Ptr,a As HWND,fFullscreen As BOOL) As HRESULT SetProgressValue As Function (ITL As ITaskbarList3 Ptr,hwnd As HWND ,ullCompleted As ULongInt,ullTotal As ULongInt) As HRESULT SetProgressState As Function(ITL As ITaskbarList3 Ptr,hwnd As HWND,tbpFlags As TBPFLAG) As HRESULT RegisterTab As Function(ITL As ITaskbarList3 Ptr,hwndTab As HWND ,hwndMDI As HWND) As HRESULT UnregisterTab As Function(ITL As ITaskbarList3 Ptr,hWndTab As HWND) As HRESULT SetTabOrder As Function(ITL As ITaskbarList3 Ptr,hWndTab As HWND,hWndInsertBefore As HWND) As HRESULT SetTabActive As Function(ITL As ITaskbarList3 Ptr,hWndTab As HWND,hWndMDI As HWND,tbatFlags As DWORD)As HRESULT ThumbBarAddButtons As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,cButtons As UINT,pButton As THUMBBUTTON Ptr)As HRESULT ThumbBarUpdateButtons As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,cButtons As UINT,pButton As THUMBBUTTON Ptr)As HRESULT ThumbBarSetImageList As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,himl As HIMAGELIST)As HRESULT SetOverlayIcon As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,hIcon As HICON,pszDescription As LPCWSTR)As HRESULT SetThumbnailTooltip As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,pszTip As LPCWSTR)As HRESULT SetThumbnailClip As Function(ITL As ITaskbarList3 Ptr,hWnd As HWND,prcClip As LPRECT)As HRESULT End Type Dim Shared CLSID_TaskbarList As IID _ = Type(&h56FDF344, &hFD6D, &h11D0, {&h95, &h8a, &h00, &h60, &h97, &hc9, &ha0, &h90}) Dim Shared IID_ITaskbarList3 As IID _ = Type(&hEA1AFB91, &h9E28, &h4B86, {&h90, &hE9, &h9E, &h9F, &h8A, &h5E, &hEF, &hAF}) Dim As ITaskbarList3 Ptr tl3 Dim As HWND hwnd = OpenWindow("", 0, 0, 300, 100) CenterWindow(hwnd) 'Mitte Desktop ProgressBarGadget(1, 10, 10, 260, 20, 0, 100, PBS_SMOOTH) SetGadgetColor(1,0,BGR(50,255,50),2) CoInitialize(0) CoCreateInstance(@CLSID_TaskBarList, 0, CLSCTX_INPROC_SERVER, @IID_ITaskBarList3, @tl3) tl3->lpVtbl->HrInit(tl3) tl3->lpVtbl->SetProgressValue(tl3, hwnd, 0, 100) tl3->lpVtbl->SetProgressState(tl3, hwnd, 2)'2 green, 4 red, 8 yello Dim As Integer ev, pct Do ev = WindowEvent() If ev = EventClose Then Exit Do If pct < 101 Then SetWindowText(hwnd, Str(pct)+" %") SetGadgetState(1, pct) tl3->lpVtbl->SetProgressValue(tl3, hwnd, pct, 100) pct += 1 Sleep 50 EndIf Loop If tl3 Then tl3->lpVtbl->Release(tl3) CoUninitialize() EndIf

prueft ob das eigene Programm XP - Styles nutzen kann


#Include Once "windows.bi" #Include Once "vbcompat.bi" ' prueft ob das eigene Programm XP - Styles nutzen kann Function IsXPStyleApp() As Integer Dim OSV As OSVERSIONINFO OSV.dwOSVersionInfoSize = SizeOf(OSV) ' Laenge angeben GetVersionEx(@OSV) ' Funktion aufrufen If OSV.dwPlatformId = 2 And OSV.dwMajorVersion >= 5 Then ' ist >=XP ' ist eine manifest Resource in der .exe If FindResource(NULL, "#1", "#24") Then Return -1 ' gibt es eine manifest Datei zu der .exe Dim As String fname = __FILE__ fname = Left(fname, Len(fname)-4) + ".exe.manifest" If FileExists(fname) Then Return -1 End If Return 0 End Function