Jump to content
Sign in to follow this  
wolf9228

BBCODE TO HTML

Recommended Posts

wolf9228

All Files
BBCode.zip

In this example is convert BBCode to HTML language :)

BBCode.au3

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Func GetCoordinatesOfBBCode($BBCodeText)
Local $OpenSquare = "(?:\[)" , $ClosSquare = "(?:\])"
Local $nOffset = 1,$uOffset = 0,$CodeArray[7]
Local $nRtArray = StringRegExp($BBCodeText,$OpenSquare,3,1)
if (@error) Then Return SetError(1,0,0)
Local $UBound = UBound($nRtArray)
For $i = 1 To $UBound
StringRegExp($BBCodeText,$OpenSquare,1,$nOffset)
If @error = 0 Then
$nOffset = @extended
StringRegExp($BBCodeText,$ClosSquare,1,$nOffset)
If @error = 0 Then
$uOffset = @extended
Local $nLen = (($uOffset - $nOffset) - 1), $EqualString = ""
Local $CodeName = StringStripWS(StringMid($BBCodeText,$nOffset,$nLen),3),$nCodeName = $CodeName
$CodeName = StringUpper($CodeName)
$IsEquals = StringInStr($CodeName,"=")
if ($IsEquals) Then
$EqualString = StringStripWS(StringMid($nCodeName,$IsEquals + 1,-1),3)
$CodeName = StringStripWS(StringMid($CodeName,1,$IsEquals - 1),3)
EndIf
$IsSlash = StringInStr($CodeName,"/")
if ($IsSlash) Then ContinueLoop
Select
Case StringCompare($CodeName,"EMAIL") == 0
Case StringCompare($CodeName,"URL") == 0
Case StringCompare($CodeName,"IMG") == 0
Case StringCompare($CodeName,"NOPARSE") == 0
Case StringCompare($CodeName,"LEFT") == 0
Case StringCompare($CodeName,"CENTER") == 0
Case StringCompare($CodeName,"RIGHT") == 0
Case StringCompare($CodeName,"FONT") == 0
Case StringCompare($CodeName,"SIZE") == 0
Case StringCompare($CodeName,"COLOR") == 0
Case StringCompare($CodeName,"U") == 0
Case StringCompare($CodeName,"I") == 0
Case StringCompare($CodeName,"B") == 0
Case Else
ContinueLoop
EndSelect
Local $wnOffset = $uOffset,$wuOffset = 0
For $j = $i To $UBound
StringRegExp($BBCodeText,$OpenSquare,1,$wnOffset)
If @error = 0 Then
$wnOffset = @extended
StringRegExp($BBCodeText,$ClosSquare,1,$wnOffset)
If @error = 0 Then
$wuOffset = @extended
Local $wnLen = (($wuOffset - $wnOffset) - 1)
Local $wCodeName = StringStripWS(StringMid($BBCodeText,$wnOffset,$wnLen),3)
$IsSlash = StringInStr($wCodeName,"/")
if Not($IsSlash) Then ContinueLoop
$wCodeName = StringUpper(StringStripWS(StringMid($wCodeName,$IsSlash + 1,-1),3))
Select
Case StringCompare($wCodeName,"EMAIL") == 0
Case StringCompare($wCodeName,"URL") == 0
Case StringCompare($wCodeName,"IMG") == 0
Case StringCompare($wCodeName,"NOPARSE") == 0
Case StringCompare($wCodeName,"LEFT") == 0
Case StringCompare($wCodeName,"CENTER") == 0
Case StringCompare($wCodeName,"RIGHT") == 0
Case StringCompare($wCodeName,"FONT") == 0
Case StringCompare($wCodeName,"SIZE") == 0
Case StringCompare($wCodeName,"COLOR") == 0
Case StringCompare($wCodeName,"U") == 0
Case StringCompare($wCodeName,"I") == 0
Case StringCompare($wCodeName,"B") == 0
Case Else
ContinueLoop
EndSelect
if StringCompare($wCodeName,$CodeName) = 0 Then
$nTest = True
;[BBCode].....[/BBCode]
$CodeArray[0] = $CodeName ;Name Of BBCode
$CodeArray[1] = $nOffset ;position Of First Open Square Bracket ; [BBCode
$CodeArray[2] = $uOffset ;position Of First Clos Square Bracket ; BBCode]
$CodeArray[3] = $wnOffset ;position Of Next Open Square Bracket ; [/BBCode
$CodeArray[4] = $wuOffset ;position Of Next Clos Square Bracket ; /BBCode]
$CodeArray[5] = (($wnOffset - $uOffset) - 1) ; The length of the middle string ]...String...[
$CodeArray[6] = $EqualString ;String after the equals sign
Return SetError(0,$UBound,$CodeArray)
EndIf
Else
ExitLoop
EndIf
Else
ExitLoop
EndIf
Next
Else
ExitLoop
EndIf
Else
ExitLoop
EndIf
Next
Return SetError(2,0,0)
EndFunc

Func BBCodeToHtml($BBCodeText,$ProgressBar = 0)
$BBCodeText = StringReplace($BBCodeText,"&", "&amp;")
$BBCodeText = StringReplace($BBCodeText,"<", "&lt;")
$BBCodeText = StringReplace($BBCodeText,">", "&gt;")
$BBCodeText = StringReplace($BBCodeText,'"', "&quot;")
$BBCodeText = StringReplace($BBCodeText,"'", "&#039;");
$BBCodeText = StringReplace($BBCodeText,@CR,'<br />' & @CR)
if ($ProgressBar) Then GUICtrlSetData($progressbar,0)
Local $iProg = 0 ,$CodeArray = 0 , $Prog = 0
While 1
$CodeArray = GetCoordinatesOfBBCode($BBCodeText)
if @error Then ExitLoop
if Not($Prog) Then $Prog = @extended / 2
if ($ProgressBar) Then GUICtrlSetData($ProgressBar,(100 / $Prog) * (($iProg + 1)))
Local $CodeName = $CodeArray[0]
Local $PonA = $CodeArray[2]
Local $PonB = $CodeArray[3]
Local $MidLen = $CodeArray[5]
Local $EqualString = $CodeArray[6]
Local $StaA = ($CodeArray[1] - 1)
Local $EndA = $CodeArray[2]
Local $StaB = ($CodeArray[3] - 1)
Local $EndB = $CodeArray[4]
Select
Case StringCompare($CodeName,"EMAIL") == 0
if $EqualString == "" Then
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<a href="mailto:' & $BStr & '">' & $BStr & '</a><br />' & $CStr
Else
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<a href="mailto:' & $EqualString & '">' & $BStr & '</a><br />' & $CStr
EndIf
Case StringCompare($CodeName,"URL") == 0
if $EqualString == "" Then
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<a href="' & $BStr & '" target="_self">' & $BStr & '</a><br />' & $CStr
Else
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<a href="' & $EqualString & '" target="_self">' & $BStr & '</a><br />' & $CStr
EndIf
Case StringCompare($CodeName,"IMG") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
if FileExists($BStr) Then $BStr = "file:///" & StringReplace(StringReplace($BStr,"\","/")," ","%20")
$BBCodeText = $AStr & '<img src="' & $BStr & '" border="0" alt="" />' & $CStr
Case StringCompare($CodeName,"NOPARSE") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BStr = StringReplace($BStr,"[","&#91;")
$BStr = StringReplace($BStr,"]","&#93;")
$BBCodeText = $AStr & '<div class="desc">' &  $BStr & '</div>' & $CStr
Case StringCompare($CodeName,"LEFT") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<div align="left">' & $BStr & '</div>' & $CStr
Case StringCompare($CodeName,"CENTER") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<div align="center">' & $BStr & '</div>' & $CStr
Case StringCompare($CodeName,"RIGHT") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<div align="right">' & $BStr & '</div>' & $CStr
Case StringCompare($CodeName,"FONT") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = $EqualString
$CStr = StringMid($BBCodeText,$EndA,$MidLen)
$DStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<font face=' & $BStr & '>' & $CStr & '</font>' & $DStr
Case StringCompare($CodeName,"SIZE") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = $EqualString
$CStr = StringMid($BBCodeText,$EndA,$MidLen)
$DStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<font size=' & $BStr & '>' & $CStr & '</font>' & $DStr
Case StringCompare($CodeName,"COLOR") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = $EqualString
$CStr = StringMid($BBCodeText,$EndA,$MidLen)
$DStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<font color=' & $BStr & '>' & $CStr & '</font>' & $DStr
Case StringCompare($CodeName,"U") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<u>' & $BStr & '</u>' & $CStr
Case StringCompare($CodeName,"I") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<i>' & $BStr & '</i>' & $CStr
Case StringCompare($CodeName,"B") == 0
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$EndA,$MidLen)
$CStr = StringMid($BBCodeText,$EndB,-1)
$BBCodeText = $AStr & '<b>' & $BStr & '</b>' & $CStr
Case Else
$AStr = StringMid($BBCodeText,1,$StaA - 1)
$BStr = StringMid($BBCodeText,$StaA,($EndB - $StaA))
$CStr = StringMid($BBCodeText,$EndB,-1)
$BStr = StringReplace($BStr,"[","&#91;")
$BStr = StringReplace($BStr,"]","&#93;")
$BBCodeText = $AStr & $BStr  & $CStr
EndSelect
$iProg += 1
WEnd
if ($ProgressBar) Then GUICtrlSetData($progressbar,0)
Return $BBCodeText
EndFunc

Func ViewFunc($BBCodeText,$hGUI = 0)
$HtmlText = '<html>' & @CRLF
$HtmlText &= "<head>" & @CRLF
$HtmlText &= "</head>" & @CRLF
$HtmlText &= "<body>" & @CRLF
$HtmlText &= $BBCodeText & @CRLF
$HtmlText &= "</body>" & @CRLF
$HtmlText &= "</html>" & @CRLF
$oIE = ObjCreate("Shell.Explorer.2")
if Not IsObj($oIE) Then Return SetError(1,0,False)
$BStr = _TempFile(@TempDir & "\", "prefix_", ".htm", Default)
$FileOpen = FileOpen($BStr,2)
if @error Then Return SetError(2,0,False)
FileWrite($FileOpen,$HtmlText)
$TrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")
$Pos = WinGetPos($TrayWnd)
$BBCodeGui = GUICreate("View", @DesktopWidth, @DesktopHeight - $Pos[3] - 30,0, 0)
GUISetBkColor(15790320)
GUISetFont(12, 400, 0, "MS Sans Serif")
$GUIActiveX = GUICtrlCreateObj($oIE, 0, 30, @DesktopWidth - 10, (@DesktopHeight - ($Pos[3] + 70)))
$Close = GUICtrlCreateButton("Close", (@DesktopWidth - 120) / 2,2,120,25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
if ($hGUI) Then GUISwitch($BBCodeGui)
FileClose($FileOpen)
$BStr = "file:///" & StringReplace(StringReplace($BStr,"\","/")," ","%20")
$oIE.navigate($BStr)
GUISetState()
$oIE.document.execCommand("Refresh")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE Or $msg = $Close
if ($hGUI) Then
GUIDelete($BBCodeGui)
GUISwitch($hGUI)
ExitLoop
Else
Exit
EndIf
EndSelect
WEnd
Return True
EndFunc

Example.au3

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <GuiRichEdit.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>
#include <Color.au3>
#include "BBCode.au3"
$hGUI = GUICreate("Forums Editor",650, 335,@DesktopWidth - (650), 0)
GUISetBkColor(15790320)
$iButton1 = GUICtrlCreateButton( "B" ,5,5 ,75 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton2 = GUICtrlCreateButton( "I" ,90,5 ,75 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton3 = GUICtrlCreateButton( "U" ,175,5 ,75 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton4 = GUICtrlCreateButton( "LEFT" ,260,5 ,80 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton5 = GUICtrlCreateButton( "CENTER" ,350,5 ,85 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton6 = GUICtrlCreateButton( "RIGHT" ,445,5 ,80 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton7 = GUICtrlCreateButton( "Color" ,535,5 ,80 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("",85, 40,160,25,BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
Dim $Font = ""
$Font &= "Arial|"
$Font &= "Arial Black|"
$Font &= "Monotype Koufi|"
$Font &= "DecoType Naskh Special|"
$Font &= "Arial Narrow|"
$Font &= "Book Antiqua|"
$Font &= "Century Gothic|"
$Font &= "Comic Sans MS|"
$Font &= "Courier New|"
$Font &= "Fixedsys|"
$Font &= "Franklin Gothic Medium|"
$Font &= "Garamond|"
$Font &= "Georgia|"
$Font &= "Impact|"
$Font &= "Lucida Console|"
$Font &= "Lucida Sans Unicode|"
$Font &= "Microsoft Sans Serif|"
$Font &= "Palatino Linotype|"
$Font &= "System|"
$Font &= "Tahoma|"
$Font &= "Times New Roman|"
$Font &= "Trebuchet MS|"
$Font &= "Verdana|Fonts"
GUICtrlSetData(-1,$Font,"Fonts")
$Combo2 = GUICtrlCreateCombo("", 5, 40,70,25,BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
Dim $iFontSize = ""
$iFontSize &= "1|"
$iFontSize &= "2|"
$iFontSize &= "3|"
$iFontSize &= "4|"
$iFontSize &= "5|"
$iFontSize &= "6|"
$iFontSize &= "7|"
$iFontSize &= "8|"
$iFontSize &= "9|"
$iFontSize &= "10|"
$iFontSize &= "11|"
$iFontSize &= "12|"
$iFontSize &= "13|"
$iFontSize &= "14|"
$iFontSize &= "15|Sizes"
GUICtrlSetData(-1,$iFontSize,"Sizes")
$iButton8 = GUICtrlCreateButton( "NOPARSE" ,500,40 ,115 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton9 = GUICtrlCreateButton( "EMAIL" ,255,40 ,110 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$iButton10 = GUICtrlCreateButton( "Image" ,375,40 ,115 ,25 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$progressbar = GUICtrlCreateProgress(5, 70, 633, 10)
$iButton11 = GUICtrlCreateButton("View" ,7,295 ,100,30 , $BS_CENTER + $BS_BOTTOM + $WS_GROUP)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$dwStyle = $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_MULTILINE + $WS_BORDER
$EditText = "[CENTER][COLOR=#FF0000][FONT=Impact][SIZE=13]Wolf9228[/SIZE][/FONT][/COLOR][/CENTER]"
$hRichEdit = _GUICtrlRichEdit_Create($hGUI,$EditText,7,85,635 ,200 ,$dwStyle)
Dim $aiInput[3] = [244, 244, 244]
$aiRGB = _ColorSetRGB($aiInput)
_GUICtrlRichEdit_SetBkColor($hRichEdit, $aiRGB)
$tag_charformat = "int cbSize;DWORD dwMask;DWORD dwEffects;LONG yHeight;LONG yOffset;" & _
"int crTextColor;BYTE bCharSet;BYTE bPitchAndFamily;char szFaceName[32]"
$CHARFORMAT = DllStructCreate($tag_charformat)
DllStructSetData($CHARFORMAT,"cbSize",DllStructGetSize($CHARFORMAT))
DllStructSetData($CHARFORMAT,"dwMask",$CFM_SIZE)
DllStructSetData($CHARFORMAT,"yHeight",14 * 20)
_SendMessage($hRichEdit, $EM_SETCHARFORMAT, $SCF_DEFAULT,DllStructGetPtr($CHARFORMAT))
$CHARFORMAT = DllStructCreate($tag_charformat)
DllStructSetData($CHARFORMAT,"cbSize",DllStructGetSize($CHARFORMAT))
DllStructSetData($CHARFORMAT,"dwMask",$CFM_FACE)
DllStructSetData($CHARFORMAT,"szFaceName",'Arial')
_SendMessage($hRichEdit,$EM_SETCHARFORMAT, $SCF_DEFAULT,DllStructGetPtr($CHARFORMAT))
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($hRichEdit)
ExitLoop
Case $msg = $Combo1
if ("Fonts" == GUICtrlRead($Combo1)) Then
_WinAPI_SetFocus($hRichEdit)
ContinueLoop
EndIf
Add_CodeA("FONT=" & GUICtrlRead($Combo1))
Case $msg = $Combo2
if ("Sizes" == GUICtrlRead($Combo2)) Then
_WinAPI_SetFocus($hRichEdit)
ContinueLoop
EndIf
Add_CodeA("SIZE=" & GUICtrlRead($Combo2))
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton1
Add_CodeA("B")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton2
Add_CodeA("I")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton3
Add_CodeA("U")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton4
Add_CodeA("LEFT")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton5
Add_CodeA("CENTER")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton6
Add_CodeA("RIGHT")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton7
if Not _GUICtrlRichEdit_IsTextSelected($hRichEdit) Then
_WinAPI_SetFocus($hRichEdit)
$Pos = WinGetPos($hGUI)
$Text = "You must select the text"
$Form1 = GUICreate("MSG", 372, 77, $Pos[0],$Pos[1] + (($Pos[3] / 2) - (77 / 2)))
GUISetBkColor(15790320)
$Label1X = GUICtrlCreateLabel($Text, 5, 5, 360, 30, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Button1X = GUICtrlCreateButton("OK", (372 / 2) - (169 / 2), 42, 169, 30, $WS_GROUP)
GUICtrlSetFont(-1, 15, 800, 0, "Arial")
GUISetState(@SW_SHOW,$Form1)
GUISwitch($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE , $Button1X
ExitLoop
EndSwitch
WEnd
GUIDelete($Form1)
GUISwitch($hGUI)
_WinAPI_SetFocus($hRichEdit)
Else
$Color = _ChooseColor(2, 0x0080C0, 2, $hGUI)
if Not @error Then
Add_CodeA("COLOR=#" & StringTrimLeft($Color,2))
EndIf
EndIf
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton8
Add_CodeA("NOPARSE")
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton9
Add_EmailCode()
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton10
Add_ImageCode()
_WinAPI_SetFocus($hRichEdit)
Case $msg = $iButton11
$BBCodeText = _GUICtrlRichEdit_GetText($hRichEdit)
_WinAPI_SetFocus($hRichEdit)
$BBCodeText = BBCodeToHtml($BBCodeText,$progressbar)
ViewFunc($BBCodeText,$hGUI)
EndSelect
WEnd
Exit

Func Add_CodeA($CodeStr)
$Pos = WinGetPos($hGUI)
_WinAPI_SetFocus($hRichEdit)
if _GUICtrlRichEdit_IsTextSelected($hRichEdit) Then
$Array = _GUICtrlRichEdit_GetSel($hRichEdit)
_GUICtrlRichEdit_SetSel($hRichEdit,$Array[0],$Array[0])
$StringSplit1 = StringSplit("[" & $CodeStr & "]","")
For $i = 1 To $StringSplit1[0]
_SendMessage($hRichEdit,$WM_CHAR, AscW($StringSplit1[$i]),0)
Next
_GUICtrlRichEdit_SetSel($hRichEdit,$Array[1] + $StringSplit1[0],$Array[1] + $StringSplit1[0])
$position = StringInStr($CodeStr,"=")
if ($position) Then $CodeStr = StringMid($CodeStr,1,($position - 1))
$StringSplit2 = StringSplit("[/" & $CodeStr & "]","")
For $i = 1 To $StringSplit2[0]
_SendMessage($hRichEdit,$WM_CHAR, AscW($StringSplit2[$i]),0)
Next
_GUICtrlRichEdit_SetSel($hRichEdit,$Array[0],$Array[1] + $StringSplit1[0] + $i)
Else
$Text = "You must select the text"
$Form1 = GUICreate("MSG", 372, 77, $Pos[0],$Pos[1] + (($Pos[3] / 2) - (77 / 2)))
GUISetBkColor(15790320)
$Label1X = GUICtrlCreateLabel($Text, 5, 5, 360, 30, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Button1X = GUICtrlCreateButton("OK", (372 / 2) - (169 / 2), 42, 169, 30, $WS_GROUP)
GUICtrlSetFont(-1, 15, 800, 0, "Arial")
GUISetState(@SW_SHOW,$Form1)
GUISwitch($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE , $Button1X
ExitLoop
EndSwitch
WEnd
GUIDelete($Form1)
GUISwitch($hGUI)
EndIf
_WinAPI_SetFocus($hRichEdit)
EndFunc

Func Add_EmailCode()
$Pos = WinGetPos($hGUI)
Local $URText = "SendEmail" , $UrTest = False
$Array = _GUICtrlRichEdit_GetSel($hRichEdit)
if _GUICtrlRichEdit_IsTextSelected($hRichEdit) Then
$URText = _GUICtrlRichEdit_GetSelText($hRichEdit)
$UrTest = True
EndIf
$Form3 = GUICreate("Email", 320, 150, $Pos[0],$Pos[1] + (($Pos[3] / 2) - (150 / 2)))
GUISetBkColor(15790320)
$Input1 = GUICtrlCreateInput($URText, 5, 35,310, 23,BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("Email Text", 5, 5, 310, 25, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_DISABLE)
$Input2 = GUICtrlCreateInput("oman9228@hotmail.com", 5, 35 + 63,310, 23,BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Email Url", 5, 5 + 63, 310, 25, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Checkbox1 = GUICtrlCreateCheckbox("Advanced", 5, 126, 150, 23, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_CENTER,$WS_TABSTOP,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$Button1 = GUICtrlCreateButton("Ok", 160, 126,150, 23, $WS_GROUP)
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
GUISwitch($Form3)
if $UrTest Then
GUICtrlSetState($Label1, $GUI_DISABLE)
GUICtrlSetState($Input1, $GUI_DISABLE)
GUICtrlSetState($Checkbox1, $GUI_CHECKED)
GUICtrlSetState($Checkbox1, $GUI_DISABLE)
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form3)
GUISwitch($hGUI)
ExitLoop
Case $Checkbox1
if BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($Label1, $GUI_ENABLE)
GUICtrlSetState($Input1, $GUI_ENABLE)
Else
GUICtrlSetState($Label1, $GUI_DISABLE)
GUICtrlSetState($Input1, $GUI_DISABLE)
EndIf
Case $Button1
if BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
$CodeStr = '[email=' & GUICtrlRead($Input2) & ']' & GUICtrlRead($Input1)
Else
$CodeStr = '[email]' & GUICtrlRead($Input2)
EndIf
GUIDelete($Form3)
GUISwitch($hGUI)

$StringSplit1 = StringSplit($CodeStr,"")
For $i = 1 To $StringSplit1[0]
_SendMessage($hRichEdit,$WM_CHAR, AscW($StringSplit1[$i]),0)
Next

_GUICtrlRichEdit_SetSel($hRichEdit,$Array[1] + $StringSplit1[0],$Array[1] + $StringSplit1[0])

$StringSplit2 = StringSplit('[/email]',"")
For $i = 1 To $StringSplit2[0]
_SendMessage($hRichEdit,$WM_CHAR, AscW($StringSplit2[$i]),0)
Next
_GUICtrlRichEdit_SetSel($hRichEdit,$Array[0],$Array[1] + $StringSplit1[0] + $i)
ExitLoop
EndSwitch
WEnd
EndFunc


Func Add_ImageCode()
_WinAPI_SetFocus($hRichEdit)
$Pos = WinGetPos($hGUI)
Local $var = "", $error = 0
Local $URText = "Image Url" , $UrTest = False
if _GUICtrlRichEdit_IsTextSelected($hRichEdit) Then
$URText = _GUICtrlRichEdit_GetSelText($hRichEdit)
$UrTest = True
EndIf
$Array = _GUICtrlRichEdit_GetSel($hRichEdit)
$Form3 = GUICreate("Image File", 320, 235,$Pos[0],$Pos[1] + (($Pos[3] / 2) - (235 / 2)))
GUISetBkColor(15790320)
$Input1 = GUICtrlCreateInput("http://www.microsoft.com/windows/Framework/images/win_logo.png", 5, 35,310, 23,BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("FileOpenDialog", 5, 34,310, 26,$WS_GROUP)
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Image Url", 5, 5, 310, 25, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Input2 = GUICtrlCreateInput("http://www.microsoft.com/windows/default.aspx", 5, 95,310, 23,BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("Url", 5, 65, 310, 25, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Input3 = GUICtrlCreateInput($URText, 5, 153,310, 23,BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("Url Text", 5, 123, 310, 25, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Checkbox1 = GUICtrlCreateCheckbox("Image File", 5, 181, 150, 23, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_CENTER,$WS_TABSTOP,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$Checkbox2 = GUICtrlCreateCheckbox("Image Url", 160, 181,150, 23, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_CENTER,$WS_TABSTOP,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Checkbox3 = GUICtrlCreateCheckbox("Advanced", 5, 209, 150, 23, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_CENTER,$WS_TABSTOP,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$Button2 = GUICtrlCreateButton("OK", 160, 208,150, 25, $WS_GROUP)
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
GUISwitch($Form3)
if $UrTest = False Then
GUICtrlSetState($Label2, $GUI_DISABLE)
GUICtrlSetState($Input2, $GUI_DISABLE)
GUICtrlSetState($Label3, $GUI_DISABLE)
GUICtrlSetState($Input3, $GUI_DISABLE)
Else
GUICtrlSetState($Checkbox3,$GUI_CHECKED)
GUICtrlSetState($Checkbox3,$GUI_DISABLE)
GUICtrlSetState($Input3,$GUI_DISABLE)
EndIf
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetState($Button1, $GUI_HIDE)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form3)
GUISwitch($hGUI)
ExitLoop
Case $Checkbox3
if BitAND(GUICtrlRead($Checkbox3), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($Label2, $GUI_ENABLE)
GUICtrlSetState($Input2, $GUI_ENABLE)
GUICtrlSetState($Label3, $GUI_ENABLE)
GUICtrlSetState($Input3, $GUI_ENABLE)
Else
GUICtrlSetState($Label2, $GUI_DISABLE)
GUICtrlSetState($Input2, $GUI_DISABLE)
GUICtrlSetState($Label3, $GUI_DISABLE)
GUICtrlSetState($Input3, $GUI_DISABLE)
EndIf
Case $Checkbox1
if BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($Checkbox2, $GUI_UNCHECKED)
GUICtrlSetData($Label1,"FileOpenDialog")
GUICtrlSetState($Input1, $GUI_HIDE)
GUICtrlSetState($Button1, $GUI_SHOW)
Else
GUICtrlSetState($Checkbox2,$GUI_CHECKED)
GUICtrlSetData($Label1,"Image Url")
GUICtrlSetState($Input1, $GUI_SHOW)
GUICtrlSetState($Button1, $GUI_HIDE)
EndIf
Case $Checkbox2
if BitAND(GUICtrlRead($Checkbox2), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
GUICtrlSetData($Label1,"Image Url")
GUICtrlSetState($Input1, $GUI_SHOW)
GUICtrlSetState($Button1, $GUI_HIDE)
Else
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlSetData($Label1,"FileOpenDialog")
GUICtrlSetState($Input1, $GUI_HIDE)
GUICtrlSetState($Button1, $GUI_SHOW)
EndIf
Case $Button1
$var = FileOpenDialog("FileOpenDialog", @MyDocumentsDir & "\", "Images (*.jpg;*.bmp;*.gif;*.png)", 1 + 4 )
Case $Button2
if ($var == "") And BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
$Form1 = GUICreate("MSG", 372, 77, $Pos[0],$Pos[1] + (($Pos[3] / 2) - (77 / 2)))
GUISetBkColor(15790320)
$Label1X = GUICtrlCreateLabel("You must select the image file", 5, 5, 360, 30, _
BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Button1X = GUICtrlCreateButton("OK", (372 / 2) - (169 / 2), 42, 169, 30, $WS_GROUP)
GUICtrlSetFont(-1, 15, 800, 0, "Arial")
GUISetState(@SW_SHOW,$Form1)
GUISwitch($Form1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE , $Button1X
ExitLoop
EndSwitch
WEnd
GUIDelete($Form1)
GUISwitch($Form3)
ContinueLoop
EndIf

Local $ImagePtch = $var
if BitAND(GUICtrlRead($Checkbox2), $GUI_CHECKED) = $GUI_CHECKED Then $ImagePtch = GUICtrlRead($Input1)
if BitAND(GUICtrlRead($Checkbox3), $GUI_CHECKED) = $GUI_CHECKED Then
$CodeStr = '[url=' & GUICtrlRead($Input2) & '] [img]' & $ImagePtch & '[/img] [/url] (' & GUICtrlRead($Input3) & ')'
Else
$CodeStr = '[img]' & $ImagePtch & '[/img]'
EndIf
GUIDelete($Form3)
GUISwitch($hGUI)
_WinAPI_SetFocus($hRichEdit)

$StringSplit1 = StringSplit($CodeStr,"")
For $i = 1 To $StringSplit1[0]
_SendMessage($hRichEdit,$WM_CHAR, AscW($StringSplit1[$i]),0)
Next
_GUICtrlRichEdit_SetSel($hRichEdit,$Array[0],$Array[0] + $i)

ExitLoop
EndSwitch
WEnd
EndFunc
Edited by wolf9228
  • Like 1

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×