Load,Save,Cut,Copy etc....
The rest is yours
Code: Select all
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