Scintilla with Windows API [SOLVED]
-
- Posts: 268
- Joined: Dec 16, 2006 20:52
- Contact:
Just for fun or not ...
Code: Select all
'Scintila MDI Application
#include once "windows.bi"
#include once "win/commctrl.bi"
#include once "win/commdlg.bi"
#define PLAT_WIN 1
#include "scintilla.bi"
#include "scilexer.bi"
DyLibLoad("SciLexer.dll")
#DEFINE RGBX(r,g,b) RGBA(b,g,r,0)
const black = RGBX(0,0,0)
const white = RGBX(&hff,&hff,&hff)
const red = RGBX(&hFF, 0, 0)
const offWhite = RGBX(&hFF, &hFB, &hF0)
const darkGreen = RGBX(0, &h80, 0)
const darkBlue = RGBX(0, 0, &h80)
const lightBlue = RGBX(&hA6, &hCA, &hF0)
declare function WinMain( byval hInstance as HINSTANCE, byval hPrevInstance as HINSTANCE, byval iCmdShow as integer ) as integer
end WinMain( GetModuleHandle( null ), null, SW_NORMAL )
static shared as integer ChildCount
static shared as HWND MainWnd, ActiveWindow
static shared as HWND Childs()
sub SetAStyle(hwndScintilla as hWnd, style As Integer, fore As COLORREF = NULL, back As COLORREF = white, size As Integer = -1)
SendMessage(hwndScintilla,SCI_STYLESETFORE, style, fore)
SendMessage(hwndScintilla,SCI_STYLESETBACK, style, back)
if size >= 1 then SendMessage(hwndScintilla,SCI_STYLESETSIZE, style, size)
end sub
function EnumChildWindowsProc(hDlg as hwnd,lData as lparam) as integer
dim as string s = space( 255 )
dim as integer l = GetClassName( hDlg, s, 255)
if ucase(left( s,l )) = "CHILDSCIEDIT" then
redim preserve Childs( ubound(Childs) + 1 )
Childs( ubound(Childs) - 1 ) = hDlg
end if
return true
end function
function ChildWndProc ( byval hWnd as HWND, byval wMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
select case( wMsg )
case WM_CREATE
CreateWindowEx(0,"Scintilla","", WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or WS_CLIPCHILDREN,0,0,700,500,hWnd, Cast(HMENU, 1001), GetModuleHandle(NULL),NULL)
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETLEXER, SCLEX_LUA, NULL)
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETSTYLEBITS, 7, NULL)
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETMARGINTYPEN,1,SC_MARGIN_NUMBER )
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETMARGINWIDTHN,1,48)
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETKEYWORDS,0,Cast(LPARAM,@"case select and break do else elseif end false for function if in local nil not or repeat return then true until while wend with declare operator property namespace"))
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETKEYWORDS,1,Cast(LPARAM,@"_VERSION assert collectgarbage dofile error gcinfo loadfile loadstring print tonumber tostring type unpack _ALERT _ERRORMESSAGE _INPUT _PROMPT _OUTPUT _STDERR _STDIN _STDOUT call dostring foreach foreachi getn globals newtype rawget rawset require sort tinsert tremove _G getfenv getmetatable ipairs loadlib next pairs pcall rawegal rawget rawset require setfenv setmetatable xpcall string table math coroutine io os debug"))
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETKEYWORDS,2,Cast(LPARAM,@"abs acos asin atan atan2 ceil cos deg exp floor format frexp gsub ldexp log log10 max min mod rad random randomseed sin sqrt strbyte strchar strfind strlen strlower strrep strsub strupper tan string.byte string.char string.dump string.find string.len string.lower string.rep string.sub string.upper string.format string.gfind string.gsub table.concat table.foreach table.foreachi table.getn table.sort table.insert table.remove table.setn math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.deg math.exp math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan"))
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETKEYWORDS,3,Cast(LPARAM,@"openfile closefile readfrom writeto appendto remove rename flush seek tmpfile tmpname read write clock date difftime execute exit getenv setlocale time coroutine.create coroutine.resume coroutine.status coroutine.wrap coroutine.yield io.close io.flush io.input io.lines io.open io.output io.read io.tmpfile io.type io.write io.stdin io.stdout io.stderr os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname"))
SendMessage(GetDlgItem(hWnd, 1001),SCI_SETKEYWORDS,4,Cast(LPARAM,@"AddBody3D AddBody CircularVelocity SetInterval CircularOrbit SetScale SetHistoryLog"))
SetAStyle(GetDlgItem(hWnd, 1001), STYLE_DEFAULT, black, white, 10)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETFONT, STYLE_DEFAULT, Cast(LPARAM,@"lucida console"))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLECLEARALL, NULL, NULL) '// Copies global style to all others
SetAStyle(GetDlgItem(hWnd, 1001), STYLE_LINENUMBER,white,RGBX(200,200,200),10)
SetAStyle(GetDlgItem(hWnd, 1001), SCE_LUA_STRING, RGBX(255,0,0))
SetAStyle(GetDlgItem(hWnd, 1001), SCE_LUA_OPERATOR, RGBX(0,128,192))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_OPERATOR, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETITALIC, SCE_LUA_COMMENT, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETFORE, SCE_LUA_COMMENT, Cast(LPARAM,RGBX(100,100,100)))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBACK, SCE_LUA_COMMENT, Cast(LPARAM,&HFFEFD0))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETEOLFILLED, SCE_LUA_COMMENT, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETITALIC, SCE_LUA_COMMENTLINE, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETFORE, SCE_LUA_COMMENTLINE, Cast(LPARAM,RGBX(100,100,100)))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBACK, SCE_LUA_COMMENTLINE, Cast(LPARAM,&HFFEFD0))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETEOLFILLED, SCE_LUA_COMMENTLINE, 1)
SetAStyle(GetDlgItem(hWnd, 1001),SCE_LUA_WORD, RGBX(0,0,255))
SetAStyle(GetDlgItem(hWnd, 1001),SCE_LUA_WORD5, RGBX(0,128,0))
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_WORD, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_WORD2, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_WORD3, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_WORD4, 1)
SendMessage(GetDlgItem(hWnd, 1001),SCI_STYLESETBOLD, SCE_LUA_WORD5, 1)
SetAStyle(GetDlgItem(hWnd, 1001), SCE_LUA_NUMBER, RGBX(0,0,255))
SetProp(hWnd, "Saved", Cast(Integer Ptr, -1))
SetProp(hWnd, "File", 0)
case WM_SIZE
MoveWindow(GetDlgItem(hWnd, 1001),0,0,loword(lparam),hiword(lparam),TRUE)
case WM_NOTIFY
dim as SCNotification ptr NM = Cast( SCNotification ptr, lParam )
select case NM->nmhdr.code
case SCN_DOUBLECLICK
'
case SCN_MARGINCLICK
'
case SCN_MODIFIED
SetProp(hWnd, "Saved", 0)
case SCN_CHARADDED
'
case SCN_UPDATEUI
'
end select
case WM_PARENTNOTIFY
dim as integer y = (lParam and &HFFFF0000) shr 16
dim as integer x = (lParam and &HFFFF)
dim as dword Btn = (wParam and &H0000FFFF)
if (Btn = WM_LBUTTONDOWN) then
end if
if (Btn = WM_RBUTTONDOWN) then
end if
if (Btn = WM_MBUTTONDOWN) then
end if
case WM_CLOSE
if Cast(Integer,GetProp(hWnd, "Saved")) = 0 then
select case MessageBox( hWnd, "Do you want to save ?","SciEditor",MB_ICONQUESTION OR MB_YESNOCANCEL )
case IDYES
SendMessage( MainWnd, WM_COMMAND, MakeLong( 102, 0 ), 0)
case IDNO
'''
case IDCANCEL
return FALSE
end select
end if
case WM_DESTROY
RemoveProp(hWnd, "Saved")
RemoveProp(hWnd, "File")
ChildCount -= 1
case WM_MDIACTIVATE
ActiveWindow = Cast( hWnd, lParam )
end select
return DefMDIChildProc( hWnd, wMsg, wParam, lParam )
end function
function WndProc ( byval hWnd as HWND, byval wMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
select case( wMsg )
case WM_CREATE
Dim As CLIENTCREATESTRUCT CCS
Dim As HMENU Menu = CreateMenu
Dim As HMENU File = CreatePopupMenu
Dim As HMENU Windows = CreatePopupMenu
AppendMenu(Menu,MF_POPUP,CInt(File),"&File")
AppendMenu(File,MF_STRING,100,!"&New\tCtrl + N")
AppendMenu(File,MF_STRING,101,!"&Open...\tCtrl + O")
AppendMenu(File,MF_STRING,102,!"&Save\tCtrl + S")
AppendMenu(File,MF_STRING,103,"&Save As...")
AppendMenu(File,MF_STRING,104,"&Save All")
AppendMenu(File,MF_SEPARATOR,0,"-")
AppendMenu(File,MF_STRING,105,"&Close")
AppendMenu(File,MF_STRING,106,"&Close All")
AppendMenu(File,MF_SEPARATOR,0,"-")
AppendMenu(File,MF_STRING,107,!"&Exit\tCtrl + Q")
AppendMenu(Menu,MF_POPUP,CInt(Windows),"&Windows")
AppendMenu(Windows,MF_STRING,10,"&Cascade")
AppendMenu(Windows,MF_STRING,11,"&Tile Vertical")
AppendMenu(Windows,MF_STRING,12,"&Tile Horizontal")
AppendMenu(Windows,MF_STRING,13,"&Arrange Icons")
CCS.hWindowMenu = Windows
CCS.idFirstChild = &H00FF
CreateWindowEx(WS_EX_CLIENTEDGE,"MDICLIENT","",WS_CHILD OR WS_CLIPSIBLINGS OR WS_CLIPCHILDREN OR WS_HSCROLL OR WS_VSCROLL OR WS_VISIBLE,0,0,0,0,hWnd,Cast(HMENU,&HCAC),GetModuleHandle( NULL ),@CCS)
SetMenu( hWnd, Menu )
DrawMenuBar ( hWnd )
case WM_COMMAND
select case LOWORD( wParam )
case 100
ChildCount += 1
CreateWindowEx( WS_EX_MDICHILD, _
@"ChildSciEdit", _
"Editor" & ChildCount, _
WS_OVERLAPPEDWINDOW OR WS_CLIPCHILDREN OR WS_CLIPSIBLINGS OR WS_VISIBLE, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
GetDlgItem(hWnd, &HCAC), _
NULL, _
GetModuleHandle( NULL ), _
NULL )
case 101
dim as OPENFILENAME ofn
dim as zstring ptr File = callocate(255)
ofn.lStructSize = sizeof(OPENFILENAME)
ofn.hWndOwner = MainWnd
ofn.lpstrFilter = strptr(!"Basic Code File (*.bas)\0*.bas\0Basic Include File (*.bi)\0*.bi\0All Files (*.*)\0*.*\0\0")
ofn.lpstrFile = File
ofn.nMaxFile = 255
ofn.Flags = OFN_FILEMUSTEXIST or OFN_LONGNAMES
if GetOpenFileName( @ofn ) then
if open(*File for binary access read as #1) = 0 then
dim as string text = Space(Lof(1))
get #1, , text
close(1)
SendMessage( hWnd, WM_COMMAND, MakeLong( 100,0 ), 0)
SendMessage(GetDlgItem( ActiveWindow, 1001 ),SCI_SETTEXT,NULL,Cast(LPARAM,strptr(text)))
SendMessage(GetDlgItem( ActiveWindow, 1001 ),SCI_COLOURISE,0,-1)
SetWindowText( ActiveWindow, Mid( *File, InStrRev(*File, "\")+1, Len(*File) ))
dim as zstring ptr FileName = allocate(len(*File))
*FileName = *File
SetProp(ActiveWindow, "File", FileName )
SetProp(ActiveWindow, "Saved", Cast(Integer Ptr, -1))
end if
end if
case 102
dim as zstring ptr File = Cast( zstring ptr, GetProp( ActiveWindow, "File" ))
if File <> 0 then
dim as integer TextLen = SendMessage( GetDlgItem( ActiveWindow, 1001 ), SCI_GETTEXTLENGTH, 0, 0 )
dim as zstring ptr Text = callocate( TextLen + 1 )
SendMessage( GetDlgItem( ActiveWindow, 1001 ), SCI_GETTEXT, TextLen + 1, CInt( Text ))
if open(*File for binary access write as #1) = 0 then
put #1, , *Text
close(1)
end if
SetProp(ActiveWindow, "Saved", Cast(Integer Ptr, -1))
else
SendMessage( hWnd, WM_COMMAND, MakeLong( 103,0 ), 0)
end if
case 103
dim as OPENFILENAME ofn
dim as zstring ptr File = callocate(255)
dim as integer l = GetWindowTextLength( ActiveWindow )
dim as string s = space( l +1 )
GetWindowText( ActiveWindow, s, len( s ))
*File = s
ofn.lStructSize = sizeof(OPENFILENAME)
ofn.hWndOwner = MainWnd
ofn.lpstrFile = File
ofn.lpstrFilter = strptr(!"Basic Code File (*.bas)\0*.bas\0Basic Include File (*.bi)\0*.bi\0All Files (*.*)\0*.*\0\0")
ofn.nMaxFile = 255
ofn.Flags = OFN_LONGNAMES
if GetSaveFileName( @ofn ) then
select case ofn.nFilterIndex
case 1
s = Mid(*File, 1, InStrRev(*File, ".")-1) + ".bas"
case 2
s = Mid(*File, 1, InStrRev(*File, ".")-1) + ".bi"
case 3
s = Mid(*File, 1, InStrRev(*File, ".")-1)
end select
dim as integer TextLen = SendMessage( GetDlgItem( ActiveWindow, 1001 ), SCI_GETTEXTLENGTH, 0, 0 )
dim as zstring ptr Text = callocate( TextLen + 1 )
SendMessage( GetDlgItem( ActiveWindow, 1001 ), SCI_GETTEXT, TextLen + 1, CInt( Text ))
if open(s for binary access write as #1) = 0 then
put #1, , *Text
close(1)
end if
SetProp(ActiveWindow, "Saved", Cast(Integer Ptr, -1))
dim as zstring ptr FileName = allocate(len(*File))
*FileName = s
SetProp(ActiveWindow, "File", FileName )
SetWindowText( ActiveWindow, Mid( s, InStrRev(s, "\")+1, Len(s) ))
end if
case 104
dim as hwnd SaveActive = ActiveWindow
redim Childs( 0 )
EnumChildWindows( GetDlgItem( hWnd, &HCAC ), @EnumChildWindowsProc, NULL )
for i as integer = 0 to ubound(Childs) -1
ActiveWindow = Childs( i )
SendMessage( hWnd, WM_COMMAND, MakeLong( 102,0 ), 0)
next i
ActiveWindow = SaveActive
case 105
SendMessage( ActiveWindow, WM_CLOSE, 0 ,0 )
case 106
redim Childs( 0 )
EnumChildWindows( GetDlgItem( hWnd, &HCAC ), @EnumChildWindowsProc, NULL )
for i as integer = 0 to ubound(Childs) -1
SendMessage( Childs( i ), WM_CLOSE, 0 ,0 )
next i
case 107
SendMessage( hWnd, WM_CLOSE, 0, 0 )
case 10
SendMessage( GetDlgItem( hWnd, &HCAC ),WM_MDICASCADE, 0, 0 )
case 11
SendMessage( GetDlgItem( hWnd, &HCAC ),WM_MDITILE, MDITILE_VERTICAL, 0 )
case 12
SendMessage( GetDlgItem( hWnd, &HCAC ),WM_MDITILE, MDITILE_HORIZONTAL, 0 )
case 13
SendMessage( GetDlgItem( hWnd, &HCAC ),WM_MDIICONARRANGE, 0, 0 )
end select
case WM_CLOSE
select case MessageBox( hWnd, "Do you want to terminate appliication ?","SciEditor",MB_ICONQUESTION OR MB_YESNO )
case IDYES
SendMessage( hWnd, WM_COMMAND, MakeLong( 106,0 ), 0)
case IDNO
return FALSE
end select
case WM_DESTROY
PostQuitMessage( 0 )
end select
return DefFrameProc( hWnd, GetDlgItem(hWnd, &HCAC), wMsg, wParam, lParam )
end function
'':::::
function WinMain ( byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval iCmdShow as integer ) as integer
dim as MSG wMsg
dim as WNDCLASS wcls
dim as HACCEL AccelTable
dim as ACCEL A(0 to 4)
A(0).fVirt = FCONTROL Or FVIRTKEY
A(0).key = Asc("N")
A(0).cmd = 100
A(1).fVirt = FCONTROL Or FVIRTKEY
A(1).key = Asc("O")
A(1).cmd = 101
A(2).fVirt = FCONTROL Or FVIRTKEY
A(2).key = Asc("S")
A(2).cmd = 102
A(3).fVirt = FCONTROL Or FVIRTKEY
A(3).key = Asc("Q")
A(3).cmd = 107
AccelTable = CreateAcceleratorTable( cast( LPACCEL, @A(0) ), ubound( A ) )
InitCommonControls
with wcls
.style = 8
.lpfnWndProc = @WndProc
.cbClsExtra = 0
.cbWndExtra = 4
.hInstance = hInstance
.hIcon = LoadIcon( NULL, IDI_APPLICATION )
.hCursor = LoadCursor( NULL, IDC_ARROW )
.hbrBackground = GetStockObject( WHITE_BRUSH )
.lpszMenuName = NULL
.lpszClassName = @"SciEdit"
end with
if( RegisterClass( @wcls ) = FALSE ) then
MessageBox( null, "Failed to register class.", "Error", MB_ICONERROR OR MB_TOPMOST OR MB_APPLMODAL )
exit function
end if
with wcls
.style = 8
.lpfnWndProc = @ChildWndProc
.cbClsExtra = 0
.cbWndExtra = 4
.hInstance = hInstance
.hIcon = LoadIcon( NULL, IDI_APPLICATION )
.hCursor = LoadCursor( NULL, IDC_ARROW )
.hbrBackground = GetStockObject( WHITE_BRUSH )
.lpszMenuName = NULL
.lpszClassName = @"ChildSciEdit"
end with
if( RegisterClass( @wcls ) = FALSE ) then
MessageBox( null, "Failed to register class.", "Error", MB_ICONERROR OR MB_TOPMOST OR MB_APPLMODAL )
exit function
end if
MainWnd = CreateWindowEx( 0, _
@"SciEdit", _
"SciEdit", _
WS_OVERLAPPEDWINDOW, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
CW_USEDEFAULT, _
NULL, _
NULL, _
hInstance, _
NULL )
ShowWindow( MainWnd, iCmdShow )
UpdateWindow( MainWnd )
while( GetMessage( @wMsg, NULL, 0, 0 ) <> FALSE )
if TranslateMDISysAccel( GetDlgItem( MainWnd, &HCAC ), @wMsg ) = 0 Then
if TranslateAccelerator( MainWnd, AccelTable, @wMsg ) = 0 Then
TranslateMessage( @wMsg )
DispatchMessage( @wMsg )
end if
end if
wend
DestroyAcceleratorTable( AccelTable )
return wMsg.wParam
end function
Re: Scintilla with Windows API [SOLVED]
I know that this topic is really old
but i never exactly figured how to properly use
Find next / Replace / ReplaceAll functions
using just scintilla constant with SendMessage ...
so ..is anyone here who have this functions ?
tnx
but i never exactly figured how to properly use
Find next / Replace / ReplaceAll functions
using just scintilla constant with SendMessage ...
so ..is anyone here who have this functions ?
tnx
Re: Scintilla with Windows API [SOLVED]
Ouhhh
After testing and testing and trying
(i broke my fingers with typing ;D )
i get it FindNext() and ReplaceOnce() functions to work
i have no clue why local var loc must be 1 .... :-[
but seems that nust be to get another selection
well here is modification and anyone interested can try ...
(ps...testing code is in o2...heck o2 is written in FB )
After testing and testing and trying
(i broke my fingers with typing ;D )
i get it FindNext() and ReplaceOnce() functions to work
i have no clue why local var loc must be 1 .... :-[
but seems that nust be to get another selection
well here is modification and anyone interested can try ...
(ps...testing code is in o2...heck o2 is written in FB )
Code: Select all
Sub FindNext () as long
INT loc=1
'search next
'loc=SENDMESSAGE hsci,SCI_SEARCHNEXT,temp,GetText(fwed1)
' print "search:" + str(loc)
if loc
loc=SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
' print "is selected-LOC: " + str(loc)
else
loc=SENDMESSAGE hsci,SCI_GETSELECTIONSTART,0,0
' print "selection start-LOC: " + str(loc)
end if
'SENDMESSAGE hsci, SCI_SETANCHOR, loc ,0
'SENDMESSAGE hsci, SCI_SETCURRENTPOS,loc,0
'SENDMESSAGE hsci, SCI_SEARCHANCHOR, 0 ,0
'temp = SCFIND_WHOLEWORD
' print "TEMP: " + str(temp)
loc = SENDMESSAGE hsci,SCI_SEARCHNEXT, SCFIND_WHOLEWORD, GetText(fwed1)
'temp = loc + len(fwed1)+1
'print "SEARCH-NEXT-LOC: " + str(loc)
'---------------------------------------------
IF loc > 0
SENDMESSAGE hsci,SCI_SCROLLCARET,0,0
ELSE
Msgbox "No matches found","Search"
Return 0
END IF
'>>>>>>>>>>>
Return loc
'>>>>>>>>>>
End Sub
'------------------------------------------------
Function ReplaceOnce(RepeatStep As Long) As Long
int curloc,selected
If FindNext() = 0
Return 0
Else
selcted = SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
'print "SELECTED:" + str(selected)
'curloc = : print "CURRENT LOCATION:" + str(curloc)
curloc = selected
End if
'Replace selexted text
SENDMESSAGE hsci,SCI_REPLACESEL, curloc ,GetText(fwed2)
Return 1
End Function
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub ReplaceAll
dim iResult As Long
'If FindNext() = 0 then
' Exit Function
'End If
iResult = ReplaceOnce(1)
If iResult = 0 then Exit Sub
While iResult =1
FindNext()
iResult = ReplaceOnce(1)
Wend
MsgBox " All words Replaced!","Info"
End Sub