I don't get it why in my example win api message #EM_GETLINE not work.
problem is under For/next loop under button 2 event.
You must be asking why i use 'EDIT' instead of editor gadget.
Editor gadget is richedit control ,right and don't have by default popup contextmenu
like 'EDIT' control from api.
Like you may see #EM_GETLINECOUNT work fine.
Anyone might have idea what i do wrong?
Code: Select all
Global EditControl
Global font1.i,pos.i,count.i
Define sysMenu.i,minBox.i,maxBox.i
Define wMsg.i,CloseWin.i
Define win.i,CenterWin.i,editStyle.i
Global staticControl.i
staticControl=16
;Global line.s
sysMenu = #PB_Window_SystemMenu
minBox = #PB_Window_MinimizeGadget
maxBox = #PB_Window_MaximizeGadget
CloseWin = #PB_Event_CloseWindow
CenterWin = #PB_Window_ScreenCentered
win=1
Procedure CreateEditText()
font1=LoadFont(1,"Courier New",10, 0)
;create EDIT control
hInstance = GetModuleHandle_(0)
EditControl = CreateWindowEx_(131072,"EDIT","",#WS_VISIBLE|#WS_CHILDWINDOW|#ES_AUTOHSCROLL|#ES_AUTOVSCROLL|#WS_VSCROLL|#WS_HSCROLL| #ES_MULTILINE | #ES_WANTRETURN |#ES_NOHIDESEL, 50,60,640,480,WindowID(0),200,hInstance,0)
;set font
SendMessage_(EditControl,#WM_SETFONT,font1, 0)
EndProcedure
If OpenWindow(0,0,0,800,600,"Basic Text Control",SysMenu | CenterWin)
CreateEditText()
;If CreatePopupMenu(0)
;MenuItem(1, "Undo")
;MenuItem(2, "Cut")
; MenuItem(3, "Copy")
;MenuItem(4, "Paste")
;MenuBar()
;OpenSubMenu("Options")
;MenuItem(5, "Window...")
;MenuItem(6, "Gadget...")
;CloseSubMenu()
; MenuBar()
; MenuItem( 7, "Quit")
; EndIf
TextGadget(staticControl, 10, 40, 250, 20, "Empty")
ButtonGadget(1,10,10,80,24,"LOAD")
ButtonGadget(2,100,10,80,24,"RUN")
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1 ;open file -----------------------------------------------------------------------
file$ = OpenFileRequester("Select a file","","Text (.txt)|*.txt|All files (*.*)|*.*",0)
If file$
If ReadFile(0, file$)
length = Lof(0) ; get the length of opened file
*mem = AllocateMemory(length) ; allocate the needed memory
If *mem
ReadData(0, *mem, length) ; read all data into the memory block
text.s=PeekS(*mem, length)
FreeMemory(*mem)
EndIf
CloseFile(0)
;set text
SendMessage_(editControl,#WM_SETTEXT,0,text)
EndIf
EndIf
;--------------------------------------------------------------------------------------------
Case 2
;read text line by line and show line in STATIC (text) control
count=SendMessage_(editControl,#EM_GETLINECOUNT,0,0)
MessageRequester("Number of Lines:", "Lines:"+Str(count), 0)
;next loop not work? ****************************************************
For i = 0 To 10
;line.s = GetGadgetItemText(200, i)
SendMessage_(editControl,#EM_GETLINE,i,line.s)
SetGadgetText(16,line.s)
SendMessage_(staticControl,#WM_SETTEXT,0,line)
;MessageRequester("Text",line.s, 0)
Next
;*********************************************************************
EndSelect
Case #PB_Event_Menu
Select EventMenu() ; To see which menu has been selected
Case 1
SendMessage_(GetFocus_(),#WM_UNDO,0,0)
Case 2
SendMessage_(GetFocus_(),#WM_CUT,0,0)
Case 3
SendMessage_(GetFocus_(),#WM_COPY,0,0)
Case 4
SendMessage_(GetFocus_(),#WM_PASTE,0,0)
Case 7
Q = 1
EndSelect
Case #WM_RBUTTONDOWN
DisplayPopupMenu(0, WindowID(0))
EndSelect
Until Q = 1
CloseLibrary(0)
End