I need some help testing Win API functions EM_SETSEL & EM_REPLACESEL (? is the hilight issue just my PC's)
With EM_SETSEL it is selecting the text in edit box but its not hilight'd (verified by paste & the selection is overwritten)
as I want to hilight some text in response to an error message i am a bit stuck.
SendMessage(Editor1, EM_SETSEL, SelStrt, SelEnd)
Setting focus on the edit box selects all text SetFocus(Editor1) '< Selects all text!
The other issue is a Type mismatch error on the last parameter of EM_REPLACESEL, it should be of type text but if I set an integer is no error(but not work of course)
SendMessage(Editor1, EM_REPLACESEL, UndoEn, Text)
If below code is working for you then I maybe have a local issue.
All the functions & subs that I use with WinGUI.bi work perfectly.
Code: Select all
'-------------------------------------------------
' Testing SendMessage EM_SETSEL EM_REPLACESEL Windows API Function
' 2 Issues...
' EM_SETSEL does not highlite selected text but the selection handles are present(evident when paste).
' EM_REPLACESEL may be a bug somewhere as 4th parameter in SendMessage should be String (expecting int)
'-------------------------------------------------
#Include "WinGUI.bi"
Dim Shared As HWND Window_Main, Editor1, EditB, Btn_Sel, Btn_Paste, Btn_Clear, Btn_Exit, Group1
Dim Shared As HWND Edit_Font
Dim Shared As HFONT hFont
Dim As MSG msg
Dim As Long x0, y0, W1, H1, Rpos, Vpos1, Vpos2
Dim As Integer BtnX, pos1, pos2
Dim Shared As String CR_LF, OutString, Text1, Text2
Declare Sub Process (Editor1 As HWND)
W1 = 1050 ' Window Width
H1 = 720 ' Window Height
Vpos1 = 40 ' Editor 1
Vpos2 = 410 ' Editor 2
Rpos = 210 ' Right ref
BtnX = 30 ' Button x ref
CR_LF = Chr(13, 10)
Text1 = "Editor1"
Text2 = "Select/Copy, below text then Clik Paste Button before and after clik Select Button"
' Create window Form with edit & buttons
Window_Main = Window_New (500, 100, W1, H1, "Test EM_SETSEL, EM_REPLACESEL")
' X Y W H
Editor1 = Editor_New (20, 40, 800, 350, "",, Window_Main)
EditB = EditBox_New (100, 10, 100, 20, "0",, Window_Main)
Var Label_txt1 = Label_New (30, Vpos1 - 20, 800, 20, Text1,, Window_Main) ' & chr(38) does not show in label
Var Label_txt2 = Label_New (30, Vpos2 - 20, 800, 20, Text2,, Window_Main)
Btn_Paste = Button_New (W1-180, 100, 100, 40, "Paste",, Window_Main)
Btn_Clear = Button_New (W1-180, 100, 100, 40, "Clear",, Window_Main)
Btn_Sel = Button_New (W1-180, 100, 100, 40, "Select",, Window_Main)
Btn_Exit = Button_New (W1-180, 100, 100, 40, "EXIT",, Window_Main)
Group1 = GroupBox_New (W1-180, 100, W1-10, H1-10, "", Window_Main) ' Main window border
OutString = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
'EditBox_SetText(Editor1, OutString) '< WinGUI same
SetWindowText(Editor1, OutString) '< Testing API function here = ok
EditBox_SetText(EditB, "-0123456789-")
hFont = Control_Createfont("Courier New",,, FW_BOLD)
Control_SetFont(Editor1), hFont
Sub Process (Editor1 As HWND)
OutString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + CR_LF + "||||||||||||||||||||||||||"
SetWindowText(Editor1, OutString ) ' Test here in Sub = ok
Dim As String Text = "-1--++--9-"
Dim As Integer UndoEn = 1, SelStrt = 10, SelEnd = 12 ' ( selection end is SelEnd-1)
SendMessage(Editor1, EM_SETSEL, SelStrt, SelEnd) '< This line seems to select, but no highlite can see
' SendMessage(Editor1, EM_REPLACESEL, UndoEn, Text) '< This line expects an integer at param 4 !!
' (62) error 58: Type mismatch, at parameter 4 of SENDMESSAGE() in 'SendMessage(Editor1, EM_REPLACESEL, UndoEn, Text)'
' Uncomment line SendMessage(Editor1, EM_REPLACESEL, ... to see Error
End Sub
'-------------------------------
'Event loop: This loop runs continuously, capture events from WinAPI
Do
WaitEvent(Window_Main, msg)
Select Case msg.hwnd
Case Btn_Paste
If msg.message = WM_LBUTTONUP Then
EditBox_Paste(Editor1)
End If
Case Btn_Clear
If msg.message = WM_LBUTTONUP Then
' EditBox_Clear(Editor1) '< This clears selected text
EditBox_SetText(Editor1,"")
End If
Case Btn_Sel
If msg.message = WM_LBUTTONUP Then
Process(Editor1)
End If
Case Btn_Exit
If msg.message = WM_LBUTTONUP Then
' SendMessage(Window_Main, WM_CLOSE,0,0)'< this just removed KBD focus
' DestroyWindow(Window_Main) '< Close window but exe still run as task
' PostQuitMessage(0) '< Seems to do nothing
Exit Do '< Exit Application- yai
End If
Case Else
'Resize/Repos Controls x if window size change
Window_GetSize(Window_Main, x0, y0, W1, H1)
Control_Resize(Editor1, 20, Vpos1, W1-Rpos, 350)
Control_Resize(EditB , 20, Vpos2, W1-(Rpos+300), 20)
Control_Resize(Btn_Paste, W1-(Rpos-BtnX), Vpos1, 100, 40)
Control_Resize(Btn_Clear, W1-(Rpos-BtnX), Vpos1 + 60, 100, 40)
Control_Resize(Btn_Sel, W1-(Rpos-BtnX), Vpos1 + 220, 100, 40)
Control_Resize(Btn_Exit, W1-(Rpos-BtnX), H1- 60, 100, 40)
Control_Resize(Group1,x0+5, y0+5, W1-15, H1-15) '< Main window border
' Group1 = GroupBox_New (510, 110, W1-10, H1-10, "PointerGen", Window_Main)
' Vpos1 = 40, Vpos2 = 410, W1 = 1000, H1 = 750
End Select
Loop Until Window_Event_Close(Window_Main, msg)
Control_DeleteFont(hFont) ' < If exit pressed
End
'Wait until window is closed:
Do
WaitEvent(Window_Main, msg) ' How to test this code(file write?)
Loop Until Window_Event_Close(Window_Main, msg)
'Delete font:
Control_DeleteFont(hFont)
End