Funktion zum Text zeilenweise auslesen

Übersicht BlitzBasic Beginners-Corner

Gehe zu Seite Zurück  1, 2

Neue Antwort erstellen

Xeres

Moderator

BeitragMi, Apr 25, 2012 17:00
Antworten mit Zitat
Benutzer-Profile anzeigen
Poste dein Code, bzw. die wichtigen Abschnitte davon direkt ins Forum.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

KnorxThieus

BeitragMi, Apr 25, 2012 17:06
Antworten mit Zitat
Benutzer-Profile anzeigen
1. hat das Codearchiv nur eingeschränkte "Haltbarkeit". Ich möchte aber, dass auch spätere Leser das noch verstehen.
2. wie soll ich das ordnen? ohne funktionen funktioniert das nicht. Rolling Eyes
Version: BlitzPlus / Blitz+

Xeres

Moderator

BeitragMi, Apr 25, 2012 17:10
Antworten mit Zitat
Benutzer-Profile anzeigen
Du wirst es doch schaffen, die wichtigen Zeilen in Code- oder Syntaxboxen in einen Beitrag zu kopieren? Das geht nicht verloren und ist für alle ein zu sehen.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

KnorxThieus

BeitragMi, Apr 25, 2012 17:13
Antworten mit Zitat
Benutzer-Profile anzeigen
naja ich versuchs mal.
Version: BlitzPlus / Blitz+

KnorxThieus

BeitragMi, Apr 25, 2012 17:16
Antworten mit Zitat
Benutzer-Profile anzeigen
BlitzBasic: [AUSKLAPPEN]
Dim farray(0)




Include "Files\bb\Functions.bb"

;Read Settings
Dim settings$(CountFileRows("Files\kts\settings.kts"))
sf = ReadFile("Files\kts\settings.kts")

Repeat
settings$(a) = ReadLine$(sf)
a = a + 1
Until Eof(sf)
CloseFile sf


Global win = CreateWindow("KnorxThieus Translater", 0, 0, 1000, 400, Desktop(), 13)
CenterWindow
AddMinimizeButton


;Load menu
menu1 = CreateMenu("&Datei", 1, WindowMenu(win))
menu11 = CreateMenu("&Neu", 11, menu1)
menu12 = CreateMenu("Ö&ffnen", 12, menu1)
menu13 = CreateMenu("&Original speichern", 13, menu1)
menu131 = CreateMenu("(Bestehende Datei &erneuern)", 131, menu13)
menu132 = CreateMenu("Speichern &u&nter... (Datei &wählen)", 132, menu13)
menu14 = CreateMenu("Übersetzung &speichern", 14, menu1)
menu141 = CreateMenu("(Bestehende Datei &erneuern)", 141, menu14)
menu142 = CreateMenu("Speichern &u&nter... (Datei &wählen)", 142, menu14)
menu_0 = CreateMenu("", 0, menu1)
menu15 = CreateMenu("S&chließen", 15, menu1)
menu16 = CreateMenu("Schließen und& Änderungen verwerfen", 16, menu1)
menu_0 = CreateMenu("", 0, menu1)
menu17 = CreateMenu("&B&eenden", 17, menu1)
menu2 = CreateMenu("&B&earbeiten", 2, WindowMenu(win))
menu21 = CreateMenu("&Rü&ckgängig", 21, menu2)
menu22 = CreateMenu("Wie&derherstellen", 22, menu2)
menu23 = CreateMenu("Aktion &wiederholen", 23, menu2)
menu_0 = CreateMenu("", 0, menu1)
menu24 = CreateMenu("&Ausschneiden", 24, menu2)
menu25 = CreateMenu("&Kopieren", 25, menu2)
menu26 = CreateMenu("E&infügen", 26, menu2)
menu27 = CreateMenu("&Löschen", 27, menu2)
menu_0 = CreateMenu("", 0, menu2)
menu28 = CreateMenu("&S&uchen " + Chr$(43) + " &E&rsetzen", 28, menu2)
menu29 = CreateMenu("Weitersuche&n", 29, menu2)
menu_0 = CreateMenu("", 0, menu2)
menu2A = CreateMenu("Wörter&buch", $2A, menu2)


;Stop

UpdateWindowMenu win


txt1gb = CreateGroupBox("&Lateinischer Text", 10, 10, ClientWidth(win) / 2 - 15, ClientHeight(win) - 50, win)

Global txt1area = CreateTextArea(1, 15, ClientWidth(txt1gb) - 3, ClientHeight(txt1gb) - 17, txt1gb)


txt2gb = CreateGroupBox("Englische &Übersetzung", ClientWidth(win) / 2 + 2.5, 10, ClientWidth(win) / 2 - 10, ClientHeight(win) - 50, win)

Global txt2area = CreateTextArea(1, 15, ClientWidth(txt2gb) - 3, ClientHeight(txt2gb) - 17, txt2gb)







SetTextAreaTabs txt1area, tabs
SetTextAreaTabs txt2area, tabs

For a = 1 To CountFileRows("Files\kts\settings.kts")
If Instr(settings$(a), ";textareas' background color")
c$ = Left$(settings$(a), Instr(settings$(a), ";textareas' background color") - 2)
r = Int(Left$(c$, 3))
g = Int(Mid$(c$, 5, 3))
b = Int(Right$(c$, 3))
Exit
EndIf
Next

DebugLog r + ", " + g + ", " + b
SetTextAreaColor txt1area, r, g, b, 1
SetTextAreaColor txt2area, r, g, b, 1

translb = CreateButton("Übersetzen", ClientWidth(win) - 80, ClientHeight(win) - 30, 75, 25, win, 4)



Global txtpm = CreatePopupMenu()
AddPopupMenuItem(txtpm, "Löschen")
AddPopupMenuItem(txtpm, "-")
AddPopupMenuItem(txtpm, "Ausschneiden")
AddPopupMenuItem(txtpm, "Kopieren")
AddPopupMenuItem(txtpm, "Einfügen")
AddPopupMenuItem(txtpm, "-")
AddPopupMenuItem(txtpm, "Alles auswählen")





;hotkeyevents
HotKeyEvent 1, 0, $803
HotKeyEvent 38, 4, $404, 1
HotKeyEvent 18, 4, $404, 2
HotKeyEvent 26, 4, $404, 2
HotKeyEvent 28, 4, $401, 0, 0, 0, 0, translb
HotKeyEvent 156, 4, $401, 0, 0, 0, 0, translb






tmptxt2$ = TextAreaText(txt2area)

Repeat
Select WaitEvent()
Case $202
If EventData() = 2 Then DebugLog OpenPopUpMenu(txtpm)
Case $401
Select EventSource()
Case translb
SetTextAreaText txt2area, Translate(Trim(Lower(TextAreaText(txt1area))));"Übersetzung nicht möglich";
tmptxt2$ = TextAreaText(txt2area)
tmptac2 = TextAreaCursor(txt2area)
Case txt2area
If TextAreaText(txt2area) <> tmptxt2$
If Not ChannelPlaying(w) w = PlayWAV()
SetTextAreaText txt2area, tmptxt2$
tmptxt2$ = TextAreaText(txt2area)
EndIf
DebugLog EventData()
End Select
Case $404
Select EventData()
Case 1
ActivateGadget txt1area
Case 2
ActivateGadget txt2area
End Select
Case $803
Quit()
Case $1001
Select EventData()
Case 17
Quit()
End Select
End Select
Forever




Function Quit()
;If Trim(TextAreaText(txt1area)) = "" End
DeletePopupMenu(txtpm)
End
End Function



;PS: Die Functions...
;globals


Function CenterWindow(window = 0)
If window = 0 window = win
SetGadgetShape window, ClientWidth(Desktop()) / 2 - GadgetWidth(window) / 2, ClientHeight(Desktop()) / 2 - GadgetHeight(window) / 2, GadgetWidth(window), GadgetHeight(window)
End Function

Function CreateGroupBox(name$, x, y, width, height, parent)
groupbox = CreateButton(name$, x, y, width, height, parent)
hwnd = QueryObject(groupbox, 1)
api_SetWindowLong(hwnd, -16, api_GetWindowLong(hwnd, -16)+7)
Return CreatePanel(GadgetX(groupbox), GadgetY(groupbox), GadgetWidth(groupbox), GadgetHeight(groupbox), parent)
End Function

Function AddMinimizeButton(window = 0)
If window = 0 Then
window_hwnd = api_GetForegroundWindow()
Else
window_hwnd = QueryObject(window, 1)
EndIf
window_oldstyle = api_GetWindowLong(window_hwnd,(-16))
api_SetWindowLong(window_hwnd, -16, window_oldstyle Or $00020000)
If window Then
HideGadget window
ShowGadget window
Else
api_ShowWindow(window_hwnd, 0)
api_ShowWindow(window_hwnd, 1)
EndIf
End Function

Function GetFileText$(file$)
If Not FileType(file$) Return
f = ReadFile(file$)
If Not f Return
ret$ = ReadLine$(f)
Repeat
ret$ = ret$ + Chr$(10) + ReadLine$(f)
Until Eof(f)
Return ret$
End Function

Function PlayWAV(typ = 1)
p$ = GetEnv$("WINDIR") + "\Media\"
Select typ
Case 1
s = LoadSound(p$ + "Windows Ding.wav")
Case 2
s = LoadSound(p$ + "Windows Error.wav")
Case 3
s = LoadSound(p$ + "Windows Exclamation.wav")
Case 4
s = LoadSound(p$ + "Windows Critical Stop.wav")
End Select
Return PlaySound(s)
End Function

Function CountFileRows(file$)
ft = FileType(file$)
If ft = 0 Then Return
If ft = 1 Then stream = ReadFile(file$)
If ft = 2 Then stream = ReadDir(file$)
nf$ = 1
Repeat
;Stop
If ft = 1 Then ReadLine$(stream)
If ft = 2 Then nf$ = NextFile$(stream)
nor = nor + 1
If ft = 1 nf$ = Eof(stream) - 1
Until Int(nf$) = 0
Return nor
End Function

;Function LoadFileArray(file$)
; rows = CountFileRows(file$)
; ;Dim farray$(rows)
; If Not FileType(file$) Return
; f = ReadFile(file$)
; If Not f Return
; For a = 1 To rows
; farray$(a) = ReadLine$(f)
; Next
; Return True
;End Function


;PopUpMenus
Function CreatePopupMenu()
;==============================================================================================================
; Create PopUp or SubMenu. Gives back a handle to add or insert items.
;==============================================================================================================

Return api_CreatePopupMenu()

End Function



Function OpenPopUpMenu( hMenu, x=-1, y=-1 )
;==============================================================================================================
; Opens the PopUp menu on the given X, Y position and tracks the user input. Gives back the choosen itemhandle
; or 0 if the user cancel the menu.
;
; If x and y is specified, the menu opens on this position relative to the inside of the application window.
; Without x any y the function opens the menu on the actual mouse position on the screen.
;==============================================================================================================

Local hWnd = GetActiveWindow() ;--> get app window handle
Local hrec = CreateBank( 16 ) ;--> rect structure
Local hpnt = CreateBank( 8 ) ;--> pointer structure

;--> use user position?
If x <> -1 And y <> -1 Then
api_GetWindowRect( hWnd, hrec )
hMsx = PeekInt( hrec, 0 ) + api_GetSystemMetrics(7) + x
hMsy = PeekInt( hrec, 4 ) + api_GetSystemMetrics(8) + api_GetSystemMetrics(4) + y
Else
api_GetCursorPos( hpnt )
hMsx = PeekInt( hpnt, 0 )
hMsy = PeekInt( hpnt, 4 )
End If

FreeBank hrec
FreeBank hpnt

Return api_TrackPopupMenu( hMenu, TPM_RETURNCMD, hMsx, hMsy, 0, hWnd, CreateBank(0) )

End Function



Function DeletePopupMenu( hMenu )
;==============================================================================================================
; Deletes the whole menu.
;==============================================================================================================

api_DestroyMenu( hMenu )

End Function



Function AddPopupMenuItem( hMenu, Item$="-", hItem=0 )
;==============================================================================================================
; Adds Item$ to the given hMenu. If Item$="-" a seperator will created, except if the Item opens a submenu.
; hItem is a specific handle (int) or you give a submenu handle. Then Item$ will open the given submenu.
;==============================================================================================================

;--> empty strings not allowed
If Item$ = "" Then Item$ = " "

;--> create seperator or Item?
If Item$ = "-" Then
api_AppendMenu( hMenu, MF_SEPERATOR, 0, CreateBank(0) )
Else
;--> if hItem is a menu handle, then hItem opens a submenu
If api_IsMenu( hItem ) Then
api_AppendMenu( hMenu, MF_STRING Or MF_POPUP, hItem, CM_StringToBank( Item$ ) )
Else
api_AppendMenu( hMenu, MF_STRING, hItem, CM_StringToBank( Item$ ) )
End If
End If

End Function



Function InsertPopUpMenuItem( hMenu, hPos, Item$="", hItem=0 )
;==============================================================================================================
; Inserts Item$ into the given hMenu. If Item$="-" a seperator will created, except if the Item opens a submenu
; hItem is a specific handle (int) or you give a submenu handle. Then Item$ will open the given submenu.
;==============================================================================================================

;--> empty strings not allowed
If Item$ = "" Then Item$ = " "

;--> create seperator or Item?
If Item$ = "-" Then
api_InsertMenu( hMenu, hPos, MF_SEPERATOR, 0, CreateBank(0) )
Else
;--> if hItem is a menu handle, then hItem opens a submenu
If api_IsMenu( hItem ) Then
api_InsertMenu( hMenu, hPos, MF_STRING Or MF_POPUP, hItem, CM_StringToBank( Item$ ) )
Else
api_InsertMenu( hMenu, hPos, MF_STRING, hItem, CM_StringToBank( Item$ ) )
End If
End If

End Function



Function ModifyPopUpMenuItem( hMenu, hItem, Item$="" )
;==============================================================================================================
; Modify item text.
;==============================================================================================================

;--> empty strings not allowed
If Item$ = "" Then Item$ = " "

api_ModifyMenu( hMenu, hItem, MF_STRING, hItem, CM_StringToBank( Item$ ) )

End Function



Function DeletePopUpMenuItem( hMenu, hItem )
;==============================================================================================================
; Deletes a item.
;==============================================================================================================

api_DeleteMenu( hMenu, hItem, 0 )

End Function



Function EnablePopUpMenuItem( hMenu, hItem )
;==============================================================================================================
; Enables a item.
;==============================================================================================================

api_EnableMenuItem( hMenu, hItem, MF_ENABLED )

End Function



Function DisablePopUpMenuItem( hMenu, hItem )
;==============================================================================================================
; Disables a item.
;==============================================================================================================

api_EnableMenuItem( hMenu, hItem, MF_GRAYED )

End Function



Function PopUpMenuItemEnabled( hMenu, hItem )
;==============================================================================================================
; If item is enabled the function gives True, otherwise False.
;==============================================================================================================

If ( api_GetMenuState( hMenu, hItem, 0 ) And MF_GRAYED ) = MF_GRAYED Then Return False Else Return True

End Function



Function CheckPopUpMenuItem( hMenu, hItem )
;==============================================================================================================
; Check a item.
;==============================================================================================================

api_CheckMenuItem( hMenu, hItem, MF_CHECKED )

End Function



Function UncheckPopUpMenuItem( hMenu, hItem )
;==============================================================================================================
; Uncheck a item.
;==============================================================================================================

api_CheckMenuItem( hMenu, hItem, MF_UNCHECKED )

End Function



Function PopUpMenuItemChecked( hMenu, hItem )
;==============================================================================================================
; If item is checked the function gives True, otherwise False.
;==============================================================================================================

If ( api_GetMenuState( hMenu, hItem, 0 ) And MF_CHECKED ) = MF_CHECKED Then Return True Else Return False

End Function



Function SetPopUpMenuItem( hMenu, hItem, hIcon1$, hIcon2$="" )
;==============================================================================================================
; Adds 1 or 2 Icon(s) to the Item. You can use bmp or ico files. The resolution should be 13x13 Pixel.
; Otherwise the image will be resized automaticly. White color will be transparent in bmp files. Transparancy
; map in ico files will be ignored. If you use 2 icons, the second icon appears If the item is checked.
;==============================================================================================================

Local bMap1
Local bMap2
Local hinfo = CreateBank( 20 ) ;--> iconinfo structure

;--> File exists?
If FileType( hIcon1$ ) = 0 Then RuntimeError "File " + hIcon1$ + " not Found !"

;--> BMP or ICO?
If Lower$( Right$( hIcon1$, 3 ) ) = "bmp" Then
bMap1 = api_LoadImage( 0, hIcon1$, IMAGE_BITMAP, 13, 13, LR_LOADFROMFILE )
Else
bMap1 = api_LoadImage( 0, hIcon1$, IMAGE_ICON, 13, 13, LR_LOADFROMFILE )
api_GetIconInfo( bMap1, hinfo )
bMap1 = PeekInt( hinfo, 16 )
End If

;--> second icon?
If hIcon2$ <> "" Then
;--> BMP or ICO?
If Lower$( Right$( hIcon2$, 3 ) ) = "bmp" Then
bMap2 = api_LoadImage( 0, hIcon2$, IMAGE_BITMAP, 13, 13, LR_LOADFROMFILE )
Else
bMap2 = api_LoadImage( 0, hIcon2$, IMAGE_ICON, 13, 13, LR_LOADFROMFILE )
api_GetIconInfo( bMap2, hinfo )
bMap2 = PeekInt( hinfo, 16 )
End If
End If

;--> attach icon
api_SetMenuItemBitmaps( hMenu, hItem, MF_BITMAP, bMap1, bMap2 )

End Function



Function CM_StringToBank( cm_str$ )
;==============================================================================================================
; Puts the given string into a bank and gives back the handle to the bank.
;==============================================================================================================

Local i
Local length = Len( cm_str$ )
Local tbank

;--> poke the string in the bank
tbank = CreateBank( length + 1)
For i = 1 To length
PokeByte tbank, i - 1, Asc( Mid$( cm_str$, i, 1 ) )
Next

Return tbank

End Function

;that were they






Kürzer hab ichs nicht gekriegt.
Intereesant sind Zeile 1 sowie die auskommentierte Funktion LoadFileArray

Außerdem: Wieso lässt sich das PopUpMenu nicht IN der Textarea öffnen? Ist die nicht von Windows?

PS: Die Functions...
Version: BlitzPlus / Blitz+
  • Zuletzt bearbeitet von KnorxThieus am Mi, Apr 25, 2012 17:39, insgesamt einmal bearbeitet

Xeres

Moderator

BeitragMi, Apr 25, 2012 17:27
Antworten mit Zitat
Benutzer-Profile anzeigen
Fein. Und das nächste mal bitte gleich so und ohne Doppelpost, ja?
Es könnte auch nicht schaden, die Fehlerzeile im Code mit einem Kommentar zu identifizieren
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

KnorxThieus

BeitragMi, Apr 25, 2012 17:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Zeile 1: Ursprungs-Array-Erstellung
Und die auskommentierte Funktion LoadFileArray.

Die anderen Angaben waren irrtümlich, das werde ich sofort löschen. Embarassed
Version: BlitzPlus / Blitz+

Gehe zu Seite Zurück  1, 2

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group