NOTEPAD like EXAMPLE with RICHEDIT
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by ricardo.
;This example creates a NOTEPAD like with RICHEDIT (RICHED32) by Ricardo Arias
;You can set ALL the parameters in ONE CONSTANT to call the CreateWindowEx API CALL
#RICHEDIT = #WS_CHILD | #WS_VISIBLE |#WS_VSCROLL |#ES_MULTILINE |#ES_AUTOVSCROLL
#WINDOW_PARAMETERS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
#WindowHeight = 400
#WindowWidth = 470
#WM_CUT = $300
#WM_COPY = $301
#WM_PASTE = $302
text.s = ""
RichEditText.s = "This is a simple example of RichEdit in PureBasic" + chr(10) + chr(10) + "Multiline is enable!! and scrollbar"
If CreateMenu(0)
MenuTitle("File")
MenuItem( 1, "&Read RichEdit")
MenuItem( 2, "&Destroy RichEdit")
MenuItem( 3, "&Create RichEdit")
MenuTitle("Edition")
MenuItem( 4, "&Cut")
MenuItem( 5, "&Copy")
MenuItem( 6, "&Paste")
EndIf
If OpenWindow(0,100,100, #WindowWidth, #WindowHeight, #WINDOW_PARAMETERS ,"NotePad in PB")
AttachMenu(0, WindowID())
class$ = "Class1" ;The class of the window
exe$ = "NotePad in PB" ;The caption of the window
RESULTADO = FindWindow_(class$,exe$)
module = GetModuleHandle_("abc.EXE")
result = FindWindow_(class$,exe$)
LoadLibrary_("RICHED32.DLL")
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit",RichEditText,#RICHEDIT,5,5,450,340,result,1,module,0)
EndIf
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventMenu
Select EventMenuID()
Case 1 ; Read RichEdit
len = GetWindowTextLength_(hwn)
GetWindowText_(hwn,text,len + 2)
messagerequester("This is the text displayed on the RichEditGadget",text,0)
Case 2 ; Destroy it
dsthwn = DestroyWindow_(hwn)
hwn = 0
Case 3 ; Create a new richedit
If dsthwn = 1 ;if we dont use this condition, the user can create any number of controls
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit",RichEditText,#RICHEDIT,5,5,450,340,result,1,module,0)
dsthwn = 0
EndIf
Case 4 ; Cut
SendMessage_(hwn,#WM_CUT,0,0)
Case 5 ; Copy
SendMessage_(hwn,#WM_COPY,0,0)
Case 6 ; Paste
SendMessage_(hwn,#WM_PASTE,0,0)
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
End
;This example creates a NOTEPAD like with RICHEDIT (RICHED32) by Ricardo Arias
;You can set ALL the parameters in ONE CONSTANT to call the CreateWindowEx API CALL
#RICHEDIT = #WS_CHILD | #WS_VISIBLE |#WS_VSCROLL |#ES_MULTILINE |#ES_AUTOVSCROLL
#WINDOW_PARAMETERS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
#WindowHeight = 400
#WindowWidth = 470
#WM_CUT = $300
#WM_COPY = $301
#WM_PASTE = $302
text.s = ""
RichEditText.s = "This is a simple example of RichEdit in PureBasic" + chr(10) + chr(10) + "Multiline is enable!! and scrollbar"
If CreateMenu(0)
MenuTitle("File")
MenuItem( 1, "&Read RichEdit")
MenuItem( 2, "&Destroy RichEdit")
MenuItem( 3, "&Create RichEdit")
MenuTitle("Edition")
MenuItem( 4, "&Cut")
MenuItem( 5, "&Copy")
MenuItem( 6, "&Paste")
EndIf
If OpenWindow(0,100,100, #WindowWidth, #WindowHeight, #WINDOW_PARAMETERS ,"NotePad in PB")
AttachMenu(0, WindowID())
class$ = "Class1" ;The class of the window
exe$ = "NotePad in PB" ;The caption of the window
RESULTADO = FindWindow_(class$,exe$)
module = GetModuleHandle_("abc.EXE")
result = FindWindow_(class$,exe$)
LoadLibrary_("RICHED32.DLL")
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit",RichEditText,#RICHEDIT,5,5,450,340,result,1,module,0)
EndIf
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventMenu
Select EventMenuID()
Case 1 ; Read RichEdit
len = GetWindowTextLength_(hwn)
GetWindowText_(hwn,text,len + 2)
messagerequester("This is the text displayed on the RichEditGadget",text,0)
Case 2 ; Destroy it
dsthwn = DestroyWindow_(hwn)
hwn = 0
Case 3 ; Create a new richedit
If dsthwn = 1 ;if we dont use this condition, the user can create any number of controls
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit",RichEditText,#RICHEDIT,5,5,450,340,result,1,module,0)
dsthwn = 0
EndIf
Case 4 ; Cut
SendMessage_(hwn,#WM_CUT,0,0)
Case 5 ; Copy
SendMessage_(hwn,#WM_COPY,0,0)
Case 6 ; Paste
SendMessage_(hwn,#WM_PASTE,0,0)
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
End
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Mr.Skunk.
That's a really cool tip, thanks
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
That's a really cool tip, thanks
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
You missed my point, which is that your app is going to have
to check that riched32.dll is installed. That is, you can't
just assume that it will be on all systems, even if it does
get installed with Windows. Remember that files can get
corrupted or deleted by users by mistake...
You missed my point, which is that your app is going to have
to check that riched32.dll is installed. That is, you can't
just assume that it will be on all systems, even if it does
get installed with Windows. Remember that files can get
corrupted or deleted by users by mistake...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
the benefit of any lurkers here, that's all.
I hope I didn't offend you... I was just pointing that out forah, ok.
well, this was just an example not an application...
however, yes, in a real application every one has to look for every external file before calling it
the benefit of any lurkers here, that's all.
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Good work Ricardo!
Question:
you load a DLL with: LoadLibrary_("RICHED32.DLL")but you don't use the
'FreeLibrary_("RICHED32.DLL")' command at the end of your code.
Is this not needed? I'm worried about memory leaks.
Have a nice day...
Franco
Good work Ricardo!
Question:
you load a DLL with: LoadLibrary_("RICHED32.DLL")but you don't use the
'FreeLibrary_("RICHED32.DLL")' command at the end of your code.
Is this not needed? I'm worried about memory leaks.
Have a nice day...
Franco
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
This is not necessary as an application ALWAYS free unnucessary stuffs at end (Thanks to Windows)..Good work Ricardo!
Question:
you load a DLL with: LoadLibrary_("RICHED32.DLL")but you don't use the
'FreeLibrary_("RICHED32.DLL")' command at the end of your code.
Is this not needed? I'm worried about memory leaks.
Have a nice day...
Franco
Fred - AlphaSND