It is currently Mon Nov 18, 2019 8:16 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Enhanced Text Editor [Windows]
PostPosted: Sun Jun 23, 2019 1:00 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3456
Hi all
Load,Save,Cut,Copy etc....
The rest is yours
Code:
Global HwndEditText, BColor,FColor ,brush

Bcolor = $CFFEFD
Fcolor = $FE1E0E

CreateImage(0,20,20,24,Bcolor)

brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)

#MNS_NOCHECK = $80000000
#MIM_BACKGROUND = 2
#MIM_STYLE = $00000010
#MIM_APPLYTOSUBMENUS = $80000000

Structure MENUINFO
   cbSize.l
   fMask.l
   dwStyle.l
   cyMax.l
   hbrBack.l
   dwContextHelpID.l
   dwMenuData.l
CompilerIf #PB_Compiler_Processor  = #PB_Processor_x64
    PB_Alignment2.b[12]
CompilerEndIf
EndStructure

If OSVersion() > #PB_OS_Windows_Server_2003
    CreateImage(0,250,400)
      StartDrawing(ImageOutput(0))
       DrawingMode(#PB_2DDrawing_Gradient )
       BackColor($C6FEFC)
       FrontColor($FEEBC6)     
       LinearGradient(30, 0, 250, 100)
       Box(0,0,250,400)
       DrawingMode(#PB_2DDrawing_Default )
       Box(0,0,18,400,$FCC15C)
    StopDrawing()
   
    myBrush.LOGBRUSH
    myBrush\lbStyle = #BS_PATTERN
    myBrush\lbColor = RGB(200, 0, 0)
    myBrush\lbHatch = ImageID(0)
    hBrush = CreateBrushIndirect_(myBrush)

    myMenu.MENUINFO
    myMenu\cbSize = SizeOf(myMenu)
    myMenu\fMask = #MIM_STYLE| #MIM_BACKGROUND |#MIM_APPLYTOSUBMENUS
    myMenu\dwStyle = #MNS_NOCHECK
    myMenu\hbrBack = hBrush
   
    space$ = "     "
Else
    space$ = ""
EndIf

Procedure WinProc(hWnd,uMsg,wParam,lParam)
Result = #PB_ProcessPureBasicEvents
  Select uMsg                               
    Case #WM_CTLCOLOREDIT
      SetBkColor_(wParam,BColor)
      SetTextColor_(wParam,FColor)
      result = brush
     
    Case #WM_SIZE
      MoveWindow_(HwndEditText,10,10,WindowWidth(0)-20,WindowHeight(0)-20,1)
    EndSelect
  ProcedureReturn Result
EndProcedure

LoadFont(0,"Tahoma",16)

flags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget
If OpenWindow(0,0,0,800,600,"Basic Text Control",flags)
SetWindowColor(0,$868686)
hInstance = GetModuleHandle_(0)
HwndEditText  = CreateWindowEx_(0,"EDIT","", #WS_VISIBLE | #WS_CHILDWINDOW | #WS_HSCROLL  | #WS_VSCROLL | #ES_MULTILINE | #ES_NOHIDESEL | #ES_WANTRETURN, 10,10,780,580,WindowID(0),200,hInstance,0)
SendMessage_(HwndEditText,#EM_SETLIMITTEXT,0,0)
SendMessage_(HwndEditText,#EM_CANUNDO, 0, 0)
SendMessage_(HwndEditText,#WM_SETFONT,FontID(0),0)
SendMessage_(HwndEditText, #EM_SETTARGETDEVICE, #Null, 0)
  If CreatePopupMenu(0)
    MenuItem(1, "     New     Ctrl+N")
    MenuItem(2, "     Open    Ctrl+O")
    MenuItem(3, "     Cut       Ctrl+X")
    MenuItem(4, "     Copy     Ctrl+C")
    MenuItem(5, "     Paste     Ctrl+V")
    MenuItem(6, "     Undo     Ctrl+Z")
    MenuBar()
    OpenSubMenu("     Save")
      MenuItem(7, "     Save All    Ctrl+S")
      MenuItem(8, "     Save Selected")
    CloseSubMenu()
    MenuBar()
    OpenSubMenu("     Print")
      MenuItem(9, "     Print")
      MenuItem(10, "     Print Selected")
    CloseSubMenu()
    MenuBar()
    MenuItem(20, "     Quit")
  EndIf
EndIf

SetMenuInfo_(MenuID(0), myMenu)
 
SetWindowCallback(@WinProc())

AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_N,11)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_O,22)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_X,33)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_C,44)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_V,55)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_Z,66)
AddKeyboardShortcut(0,#PB_Shortcut_Control|#PB_Shortcut_S,77)
Repeat
  Select WaitWindowEvent()
 
    Case #PB_Event_CloseWindow
      Quit = 1
             
    Case #PB_Event_Menu
 
      Select EventMenu()
        Case 1 ,11
          SendMessage_(HwndEditText, #WM_SETTEXT,0,"")
                   
        Case 2,22         
          FileName$ = OpenFileRequester("", "", "Text (*.txt)|*.txt;*.bat|All files (*.*)|*.*", 0)
          If FileName$
           If ReadFile(0, FileName$)
            length.q = Lof(0)
            rFormat = ReadStringFormat(0)
            *MemoryID = AllocateMemory(length)
            If *MemoryID             
              bytes = ReadData(0, *MemoryID, length)
              SetWindowText_(HwndEditText,PeekS(*MemoryID ,bytes,rFormat))
            EndIf
            CloseFile(0)
            FreeMemory(*MemoryID)
           EndIf
          EndIf
           
        Case 3 ,33
          SendMessage_(GetFocus_(),#WM_CUT,0,0)
          SendMessage_(GetFocus_(),#WM_CHAR,#VK_BACK,0)

        Case 4 ,44
          SendMessage_(GetFocus_(),#WM_COPY,0,0)

        Case 5 ,55
          SendMessage_(GetFocus_(),#WM_PASTE,0,0)
           
        Case 6 ,66
          SendMessage_(GetFocus_(),#EM_UNDO,0,0)
           
        Case 7 ,77
           sFormat = #PB_Ascii
           FileName$ = SaveFileRequester("", "", "Text (*.txt)|*.txt|All files (*.*)|*.*", 0)
           If FileName$
            slength = SendMessage_(HwndEditText, #WM_GETTEXTLENGTH, 0, 0) + SizeOf(Character)
            If slength > 0
              text$ = Space(slength)
              SendMessage_(HwndEditText, #WM_GETTEXT, slength,@text$)
            EndIf
             If CreateFile(0, Filename$)
               WriteStringFormat(0, sFormat)
               WriteString(0, text$,sFormat)
             EndIf
             CloseFile(0)
           EndIf

        Case 8,88
           sFormat = #PB_Ascii
           FileName$ = SaveFileRequester("", "", "Text (*.txt)|*.txt|All files (*.*)|*.*", 0)
           If FileName$
            SendMessage_(HwndEditText, #EM_GETSEL, @start.i, @finish.i)
            slength = SendMessage_(HwndEditText, #WM_GETTEXTLENGTH, 0, 0) + SizeOf(Character)
            If slength > 0
              text$ = Space(slength)
              SendMessage_(HwndEditText, #WM_GETTEXT, slength,@text$)             
              text$ = Mid(text$, start, finish-start+1)
            EndIf
             If CreateFile(0, Filename$)
               WriteStringFormat(0, sFormat)
               WriteString(0, text$,sFormat)
             EndIf
             CloseFile(0)
           EndIf

;         Case 9
;           If PrintRequester()
;             If StartPrinting("PureBasic Test")         
;               If StartDrawing(PrinterOutput())
;                 StopDrawing()
;               EndIf   
;               StopPrinting()
;             EndIf
;           EndIf         

        Case 20
          Quit = 1
           
      EndSelect
       
    Case #WM_RBUTTONDOWN
      DisplayPopupMenu(0, WindowID(0))
       
  EndSelect
Until Quit = 1
DeleteObject_(brush)
DestroyWindow_(HwndEditText)
End 

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Enhanced Text Editor [Windows]
PostPosted: Sun Jun 23, 2019 1:06 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1106
Location: Germany::Berlin()
Good template for an editor. Thank you for sharing. Image

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Enhanced Text Editor [Windows]
PostPosted: Sun Jun 23, 2019 4:48 pm 
Online
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1379
Thanks RASHAD for the nice and complete code, and for the hinting:
sFormat = #PB_Ascii
+ SizeOf(Character)

i have tried with sFormat = #PB_UTF8 to load a big Chinese file and it is indeed in one second or less the same timing like in windows notepad, in win7 may be speedier.
the Chinese file i have tried is here:
http://www.gutenberg.org/ebooks/26872
Plain Text UTF-8: 9988 Lines of complex characters


Top
 Profile  
Reply with quote  
 Post subject: Re: Enhanced Text Editor [Windows]
PostPosted: Sun Jun 23, 2019 11:41 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3456
Hi RSBasic
Thanks mate
To do:Printing :) which will be more difficult

Hi applePi
I tested it, in fact it is speeder than Notepad
PB 5.70 x86 win 10 x64

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Enhanced Text Editor [Windows]
PostPosted: Mon Jun 24, 2019 12:36 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 478
Quote:
Thanks mate
To do:Printing :) which will be more difficult


Rashad ,
i also hope you add Printing code :D

_________________
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison


Top
 Profile  
Reply with quote  
 Post subject: Re: Enhanced Text Editor [Windows]
PostPosted: Wed Jun 26, 2019 2:18 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4528
Location: Lyon - France
Works nice on W7 X86
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Opcode and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye