SendCmdLine and GetCmdLine

Started by Zlatko Vid, June 09, 2023, 08:41:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

I was playing with ideas Pierre give me in another topic
so i open new one to be more visible.
Pierre suggested using ShellExecute and this on i tested
I made to similar programs one is Sender.exe and  another Receiver.exe
With Sender ..i sand message (string - text) to Receiver by clicking
button to getText from edit control and send to .
this is part of code which do that:

CASE WM_COMMAND
       controlID = LoWord(wParam)  'get control ID
       notifyCode = HiWord(wParam) 'get notification message

      select controlID

         case b0ID
           if notifycode = 0
               'get text from single line edit control and put it into text buffer
                 SendMessage edit1, WM_GETTEXT, 256 , txbuff
                 'use ShellExecute to send text to Receiver.exe
                 ShellExecute(0, "open", "Receiver.exe", txBuff, "", 5)

           end if
and that part work well but i get ...not only text then
full path of Receiver.exe + text ...which is in my case this :

"D:\o2Progress\OxygenBasic\microAInterpreter\Receiver.exe" New Text

but that is not problematic and can be extracted + trimmed
extracted using let say some char like ~ or # or $
for example $text or ~text
main problem for me is ShellExecute which tend to open exe
but i want just to send not to open..i understand that command was "open"
is there more options?
  •  

Pierre Bellisle

#1
Aurel> "but i get ...not only text then full path of Receiver.exe + text"

To get arguments without the exe filename, you may use this in receiver.exe.
! PathGetArgsA lib "shlwapi.dll" alias "PathGetArgsA"(zstring pszPath) as sys
zstring ptr ArgNoFilename = PathGetArgsA(GetCommandLineA())
print "ArgNoFilename [" ArgNoFilename "]"

  •  

Zlatko Vid

Ahh Ok ...i will  try that one
  •  

Pierre Bellisle

> main problem for me is ShellExecute which tend to open exe but i want just to send not to open..

Hi Aurel,

Is that what you want to do?

Receiver is a window program, not a console program.
If Receiver.exe is not running you want Sender.exe to start it with the command line.
If Receiver.exe is running you do not want Sender.exe to start a new Receiver.exe.
You only want the already running Receiver.exe to get the  command line.
  •  

Zlatko Vid

QuoteIf Receiver.exe is running you do not want Sender.exe to start a new Receiver.exe.
You only want the already running Receiver.exe to get the  command line.

yes that is , i already say i want just send error message from interpreter to
code editor...
  •  

Pierre Bellisle

In this case, command line argument is not what you need.
We will enter the world of InterProcess communication.

There are many ways to do what you need.
A simple one is to use WM_SETTEXT message that can send text to another program.

To make it easy, I gave Receiver.exe a unique ClassName as "OXYGEN BASIC Receiver 20230610".
FindWindow() will have no trouble to get the window handle.
Then sending text to a hidden edit control and send a WM_APP message to Receiver.exe so it knows that new text is in the hidden edit control.

Here, Sender.exe is console and  Receiver.exe is a window.

$filename "Sender.exe"

 uses console
 uses dialogs

 %EditHidden 102
 %WM_APP     0x08000

 sys hReceiver
 string MessageToSend

 do
   'for this example, Receiver.exe must have a unique ClassName
   hReceiver = FindWindow("OXYGEN BASIC Receiver 20230610", null)
   printl "hReceiver 0x" + hex(hReceiver)
   if hReceiver then
     printl "strike a key to send one message to receiver.exe"
     waitkey
     MessageToSend = "Hi! GetTickCount is 0x" & hex(GetTickCount()) & "."
     SendDlgItemMessage(hReceiver, EditHidden, WM_SETTEXT, 0, strptr MessageToSend)
     PostMessage(hReceiver, WM_APP, 0, 0)
     printl "message sent to 0x" + hex(hReceiver) + " at WM_APP"
   else
     printl "receiver.exe handle not found. strike a key to retry"
     waitkey
   endif
 loop


$filename "Receiver.exe"

uses dialogs

$CRLF = Chr(13, 10)

%Edit                    101
%EditHidden              102

%WM_NCACTIVATE           0x086
%WM_GETMINMAXINFO        0x0024
%WM_SETCURSOR            0x0020
%WM_NEXTDLGCTL           0x28
%WM_APP                  0x08000
%HWND_DESKTOP            0
%SIZE_MINIMIZED          1
%SPI_GETICONTITLELOGFONT 0x001F
%COLOR_BTNFACE           15
%EM_SETSEL               0xB1

type NONCLIENTMETRICS
 long    cbSize
 long    iBorderWidth
 long    iScrollWidth
 long    iScrollHeight
 long    iCaptionWidth
 LOGFONT iCaptionHeight
 long    lfCaptionFont
 long    iSMCaptionWidth
 LOGFONT iSMCaptionHeight
 long    lfSMCaptionFont
 long    iMenuWidth
 LOGFONT iMenuHeight
 LOGFONT lfMenuFont
 LOGFONT lfStatusFont
 LOGFONT fMessageFont
end type
'_____________________________________________________________________________

function WndProc(sys hWnd, wMsg, wParam, lparam) as sys callback
 point DlgArea, long TextLen, string sText
 static sys hEdit, hEditHidden

 select case wMsg

   case WM_CREATE //Sent immediately after main window CreateWindowEx(), received even before any subsequent control created after.
     hEditHidden = GetDlgItem(hWnd, EditHidden)
     PostMessage(hEdit, EM_SETSEL, -1, -1) 'Set caret at the end of text
     return(1)

   case WM_APP 'Received from Sender.exe
     'Get text lenght from hidden edit control
     TextLen = SendDlgItemMessage(hWnd, EditHidden, WM_GETTEXTLENGTH , 0, 0)
     'Get text from hidden edit control
     sText = nuls(TextLen)
     SendDlgItemMessage(hWnd, EditHidden, WM_GETTEXT, TextLen + 1, strptr sText)
     sText = Chr(13, 10) & sText
     'Move the caret to the end of text.
     SendDlgItemMessage(hWnd, Edit, EM_SETSEL, -2, -2)
     'Add text to the edit control
     SendDlgItemMessage(hWnd, Edit, EM_REPLACESEL, true, strptr(sText))

   case WM_COMMAND
     sys id    = loword(wParam)
     sys event = hiword(wParam)
     select case id
       case IDCANCEL 'Escape key
         SendMessage(hwnd, WM_CLOSE, 0, 0)
         return(0)
     end select

   case WM_SIZE //Size has changed. wParam for minimized, restored, etc. lParam-lo: width in pixels, lParam-hi: height.
     if wParam <> SIZE_MINIMIZED then
       DlgArea.X  = loword(LPARAM)
       DlgArea.Y  = hiword(LPARAM)
       if hEdit = 0 then hEdit = GetDlgItem(hWnd, Edit) 'Init on app start
       MoveWindow(hEdit, 3, 3, DlgArea.X - 6, DlgArea.Y - 6, true)
       return(0)
     end if

   case WM_KEYDOWN 'An application should return zero if it processes this message.
     Select wParam
         Case 27
           SendMessage(hwnd, WM_CLOSE, 0, 0) 'Escape key to exit
           return(0)
     End Select

    case WM_DESTROY 'An application should return zero if it processes this message.
      PostQuitMessage(0)
      return(0)

 end select

 'Calls the default window procedure to provide default processing
 'for any window messages that an application does not process.
 return(DefWindowProc(hWnd, wMsg, wParam, lParam))

end function
'_____________________________________________________________________________

function WinMain()

 NONCLIENTMETRICS NonClient
 WndClass         wc
 Msg              wm
 sys              inst, hwnd, hControl, hIcon, inst
 sys              WindowWidth, WindowHeight, WindowPosX, WindowPosY

 WindowWidth  = 350
 WindowHeight = 300
 WindowPosX   = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth)  \ 2
 WindowPosY   = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) \ 2

 NonClient.cbSize = SIZEOF(NONCLIENTMETRICS)
 hIcon            = ExtractIcon GETMODULEHANDLE(""), "Shell32.dll", 294 'o
 inst             = GetModuleHandle(0)
 wc.style         = CS_HREDRAW | CS_VREDRAW
 wc.lpfnWndProc   = @WndProc
 wc.cbClsExtra    = 0
 wc.cbWndExtra    = 0
 wc.hInstance     = inst
 wc.hIcon         = hIcon 'LoadIcon 0, IDI_APPLICATION
 wc.hCursor       = LoadCursor(0, IDC_ARROW)
 wc.hbrBackground = COLOR_BTNFACE + 1
 wc.lpszMenuName  = null
 wc.lpszClassName = strptr("OXYGEN BASIC Receiver 20230610")

 RegisterClass(@wc)

 sys hFont = CreateFont(14, 0,      'Height 14 = 9, 16=12, 15=11, 14=11, Width usually 0,
                        0, 0,       'Escapement(angle), Orientation
                        0, 0, 0, 0, 'Bold, Italic, Underline, Strikethru
                        0, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY, FF_DONTCARE, "Segoe UI") 'Fixed width font ("Segoe UI", 9 Arial Consolas)

 hwnd = CreateWindowEx(0, wc.lpszClassName, "Receiver" & sizeof(sys) * 8 & " - o2 v. " & o2version,
                       WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU |
                       WS_MINIMIZEBOX | WS_SIZEBOX | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX, //WS_VISIBLE will be fatal here
                       WindowPosX, WindowPosY, WindowWidth, WindowHeight, HWND_DESKTOP, 0, inst, 0)
                       'If the WS_VISIBLE style is specified, CreateWindow sends the window all the messages required to activate and show the window.

 string sEdit = "You may receive message from Sender.exe" & chr(13, 10)

 hControl = CreateWindowEx(WS_EX_LEFT | WS_EX_CLIENTEDGE,         'StyleEx
                           "Edit",                                'Class name
                           StrPtr(sEdit),                         'Caption
                           WS_CHILD | WS_VISIBLE | WS_TABSTOP | _ 'Window styles
                           WS_VSCROLL | ES_MULTILINE | ES_LEFT,   'Class styles
                           2, 106,                                'Left, top
                           246, 90,                               'Width, height
                           hWnd, Edit,                            'Handle of parent, control ID
                           inst, NULL)                            'Handle of instance, creation parameters
 SendMessage(hControl, WM_SETFONT, hFont, true)

 hControl = CreateWindowEx(0,                                     'StyleEx
                           "Edit",                                'Class name
                           "Hidden edit",                         'Caption
                           WS_CHILD | _                           'Window styles
                           WS_VSCROLL | ES_LEFT,                  'Class styles
                           0, 0,                                  'Left, top
                           0, 0,                                  'Width, height
                           hWnd, EditHidden,                      'Handle of parent, control ID
                           inst, NULL)                            'Handle of instance, creation parameters


 ShowWindow(hwnd, SW_SHOW)
 UpdateWindow(hwnd)

 sys bRet
 do while bRet := GetMessage(@wm, 0, 0, 0)
   if bRet <> -1 then
     TranslateMessage(@wm)
     DispatchMessage(@wm)
   end if
 wend

 DeleteObject(hFont)
 DestroyIcon(hIcon)

end function
'_____________________________________________________________________________

 WinMain()
 end
'_____________________________________________________________________________
'


  •  

Pierre Bellisle

After a thought, no WM_App needed no more. 
EN_CHANGE can do it all...
Even easier Receiver.exe. 

$filename "Receiver.exe"

uses dialogs
$CRLF = Chr(13, 10)

%Edit                    101
%EditHidden              102

%WM_NCACTIVATE           0x086
%WM_GETMINMAXINFO        0x0024
%WM_SETCURSOR            0x0020
%WM_NEXTDLGCTL           0x28
%WM_APP                  0x08000
%HWND_DESKTOP            0
%SIZE_MINIMIZED          1
%SPI_GETICONTITLELOGFONT 0x001F
%COLOR_BTNFACE           15
%EM_SETSEL               0xB1

type NONCLIENTMETRICS
 long    cbSize
 long    iBorderWidth
 long    iScrollWidth
 long    iScrollHeight
 long    iCaptionWidth
 LOGFONT iCaptionHeight
 long    lfCaptionFont
 long    iSMCaptionWidth
 LOGFONT iSMCaptionHeight
 long    lfSMCaptionFont
 long    iMenuWidth
 LOGFONT iMenuHeight
 LOGFONT lfMenuFont
 LOGFONT lfStatusFont
 LOGFONT fMessageFont
end type
'_____________________________________________________________________________

function WndProc(sys hWnd, wMsg, wParam, lparam) as sys callback
 point DlgArea, long TextLen, string sText
 static sys hEdit, hEditHidden

 select case wMsg

   case WM_CREATE 'Sent immediately after main window CreateWindowEx(), received even before any subsequent control created after.
     hEditHidden = GetDlgItem(hWnd, EditHidden)
     PostMessage(hEdit, EM_SETSEL, -1, -1) 'Set caret at the end of text
     return(1)

   case WM_COMMAND
     sys id    = loword(wParam)
     sys event = hiword(wParam)
     select case id

       case EditHidden 'Hidden edit
         if event = EN_CHANGE then
           'Get text lenght from hidden edit control
           TextLen = SendDlgItemMessage(hWnd, EditHidden, WM_GETTEXTLENGTH , 0, 0)
           'Get text from hidden edit control
           sText = nuls(TextLen)
           SendDlgItemMessage(hWnd, EditHidden, WM_GETTEXT, TextLen + 1, strptr sText)
           sText = Chr(13, 10) & sText
           'Move the caret to the end of text.
           SendDlgItemMessage(hWnd, Edit, EM_SETSEL, -2, -2)
           'Add text to the edit control
           SendDlgItemMessage(hWnd, Edit, EM_REPLACESEL, true, strptr(sText))
           return(0)
         endif

       case IDCANCEL 'Escape key
         if (event = BN_CLICKED) OR (event = 1)
           SendMessage(hwnd, WM_CLOSE, 0, 0)
           return(0)
         endif

     end select

   case WM_SIZE //Size has changed. wParam for minimized, restored, etc. lParam-lo: width in pixels, lParam-hi: height.
     if wParam <> SIZE_MINIMIZED then
       DlgArea.X  = loword(LPARAM)
       DlgArea.Y  = hiword(LPARAM)
       if hEdit = 0 then hEdit = GetDlgItem(hWnd, Edit) 'Init on app start
       MoveWindow(hEdit, 3, 3, DlgArea.X - 6, DlgArea.Y - 6, true)
       return(0)
     end if

   case WM_KEYDOWN 'An application should return zero if it processes this message.
     Select wParam
    Case 27
       SendMessage(hwnd, WM_CLOSE, 0, 0) 'Escape key to exit
       return(0)
     End Select

    case WM_DESTROY 'An application should return zero if it processes this message.
      PostQuitMessage(0)
      return(0)

 end select

 'Calls the default window procedure to provide default processing
 'for any window messages that an application does not process.
 return(DefWindowProc(hWnd, wMsg, wParam, lParam))

end function
'_____________________________________________________________________________

function WinMain()

 NONCLIENTMETRICS NonClient
 WndClass         wc
 Msg              wm
 sys              inst, hwnd, hControl, hIcon, inst
 sys              WindowWidth, WindowHeight, WindowPosX, WindowPosY

 WindowWidth  = 350
 WindowHeight = 300
 WindowPosX   = (GetSystemMetrics(SM_CXSCREEN) - WindowWidth)  \ 2
 WindowPosY   = (GetSystemMetrics(SM_CYSCREEN) - WindowHeight) \ 2

 NonClient.cbSize = SIZEOF(NONCLIENTMETRICS)
 hIcon            = ExtractIcon GETMODULEHANDLE(""), "Shell32.dll", 294 'o
 inst             = GetModuleHandle(0)
 wc.style         = CS_HREDRAW | CS_VREDRAW
 wc.lpfnWndProc   = @WndProc
 wc.cbClsExtra    = 0
 wc.cbWndExtra    = 0
 wc.hInstance     = inst
 wc.hIcon         = hIcon 'LoadIcon 0, IDI_APPLICATION
 wc.hCursor       = LoadCursor(0, IDC_ARROW)
 wc.hbrBackground = COLOR_BTNFACE + 1
 wc.lpszMenuName  = null
 wc.lpszClassName = strptr("OXYGEN BASIC Receiver 20230610")

 RegisterClass(@wc)

 sys hFont = CreateFont(14, 0,      'Height 14 = 9, 16=12, 15=11, 14=11, Width usually 0,
                        0, 0,       'Escapement(angle), Orientation
                        0, 0, 0, 0, 'Bold, Italic, Underline, Strikethru
                        0, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
                        DEFAULT_QUALITY, FF_DONTCARE, "Segoe UI") 'Fixed width font ("Segoe UI", 9 Arial Consolas)

 hwnd = CreateWindowEx(0, wc.lpszClassName, "Receiver" & sizeof(sys) * 8 & " - o2 v. " & o2version,
                       WS_OVERLAPPED | WS_BORDER | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU |
                       WS_MINIMIZEBOX | WS_SIZEBOX | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX, //WS_VISIBLE will be fatal here
                       WindowPosX, WindowPosY, WindowWidth, WindowHeight, HWND_DESKTOP, 0, inst, 0)

 string sEdit = "You may receive message from Sender.exe" & chr(13, 10)

 hControl =  CreateWindowEx(WS_EX_LEFT | WS_EX_CLIENTEDGE,         'StyleEx
                            "Edit",                                'Class name
                            StrPtr(sEdit),                         'Caption
                            WS_CHILD | WS_VISIBLE | WS_TABSTOP | _ 'Window styles
                            WS_VSCROLL | ES_MULTILINE | ES_LEFT,   'Class styles
                            2, 106,                                'Left, top
                            246, 90,                               'Width, height
                            hWnd, Edit,                            'Handle of parent, control ID
                            inst, NULL)                            'Handle of instance, creation parameters
 SendMessage(hControl, WM_SETFONT, hFont, true)

 hControl =  CreateWindowEx(0,                                     'StyleEx
                            "Edit",                                'Class name
                            "",                                    'Caption, keep it empty
                            WS_CHILD | _                           'Window styles
                            WS_VSCROLL | ES_LEFT,                  'Class styles
                            0, 0,                                  'Left, top
                            0, 0,                                  'Width, height
                            hWnd, EditHidden,                      'Handle of parent, control ID
                            inst, NULL)                            'Handle of instance, creation parameters

 ShowWindow(hwnd, SW_SHOW)
 UpdateWindow(hwnd)

 sys bRet
 do while bRet := GetMessage(@wm, 0, 0, 0)
   if bRet <> -1 then
     TranslateMessage(@wm)
     DispatchMessage(@wm)
   end if
 wend

 DeleteObject(hFont)
 DestroyIcon(hIcon)

end function
'_____________________________________________________________________________

 WinMain()
 end
'_____________________________________________________________________________
'
  •  

Zlatko Vid

Hi Pierre

BIG THANKS !  :)

This is excellent !
It works as it should be ...
So ..if i figured it ,main thing is in

FindWindow
and
PostMessage

I almost never make console programs they are simply strange to me  ::)
Also my interpreter is GUI app but all this can be easy used.
just one small question..

why we need hidden control, i mean why must be hidden?
huh..i need to analyze code  ::)
and to show how look ..here is a screenshot:
  •  

Theo Gottwald

Alternatively you can use shared Memory.
While i have such sample code only in PB.


Pierre Bellisle

Aurel, 
I used an hidden edit, but no problem if it is not hidden.
Just set valid position, size, style and styleEx you want for EditHidden. And do not forget WS_VISIBLE of course.
You also may send directly to Edit instead of  EditHidden. In that case, you do not need two edit control for the demo.
You will have to adapt code in WM_SIZE...
  •  

Pierre Bellisle

Note that WM_SETTEXT erase and set the entire text of the control. 
It does not add text at the end.
  •  

Theo Gottwald

@Pierre, I think the sending program will need Admin rights to be able to send text to other Executables, not?

Zlatko Vid

Pierre
I tried crazy thing , instead of using

SendDlgItemMessage(hReceiver, EditHidden, WM_SETTEXT, 0, strptr MessageToSend

i use just SendMessage like this:
case b0ID
           if notifycode = 0
               'get text from single line edit control and put it into text buffer
                 SendMessage edit1, WM_GETTEXT, 256 , txbuff
                 'use FindWindow api
                 hReceiver = FindWindow("O2_RECEIVER_1162023", null)
                 errMessage = txbuff
                 If hReceiver > 0
                     print errMessage
                     SendMessage(hReceiver, WM_SETTEXT, edit2, errMessage)
                 End if
           end if

and get Window Title changed.. ;D
that is funny part ...
OK ..i will test it with

SendDlgItemMessage

And this one is for Dialogs..but i hope that should work for Window too.
  •  

Zlatko Vid

Hi Pierre
and thanks Again!  :)

Yes it work fine with SendDlgItemMessage

case b0ID
           if notifycode = 0
               'get text from single line edit control and put it into text buffer
                 SendMessage edit1, WM_GETTEXT, 256 , txbuff
                 'use FindWindow api
                 hReceiver = FindWindow("O2_RECEIVER_1162023", null)
                 errMessage = txbuff
                 If hReceiver > 0
                     print errMessage
                     'SendMessage(hReceiver, WM_SETTEXT, edit2, errMessage)
                     SendDlgItemMessage(hReceiver, editID2, WM_SETTEXT, 0, strptr errMessage)
                 Else
                    print "Receiver not found"
                 End if
  •  

Zlatko Vid

Also if someone is interested in my version
or want to try here are both code :

sender :
'o2 sender app GUI + awinh037.inc
$ filename "Sender.exe"
% WM_NCACTIVATE = 0x0086
' new awinh037
include "rtl32.inc" : include "awinh037.inc" : #lookahead
Declare Function IsDialogMessage Lib "user32.dll" Alias "IsDialogMessageA" (ByVal hDlg As Long, lpMsg As MSG) As Long

'globals
INT win,x=0,y=0,w=540,h=430,wstyle = WS_MINMAXSIZE
INT inbox
INT butt, b0ID = 100
INT edit1, editID1 = 101
'edit hidden ID -> 102
INT edit2, editID2 = 102
string crlf = chr(13)+chr(10)
string txbuff = space(256)
char buff[4096]
int sRet
'------------------------------
int hReceiver
string errMessage 
' open window...
win = SetWindow("Sender",x,y,w,h,0,wstyle)

butt = SetButton(win ,430,350,88,26,"SEND",0x50001000 | WS_TABSTOP  ,0x200,b0ID)
'single line edit control
edit1 = SetEditBox(win,20,320,500,23,"Enter message...",0x50800000| WS_TABSTOP  ,0x200,editID1)
ControlFont(edit1, 16,7, 100, "Consolas")
'multi line edit control
edit2 = SetEditBox(win,20,40,500,200,"",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL,0x200,editID2)
ControlFont(edit2, 16,7, 100, "Consolas")

'///  message loop ///
 WHILE GetMessage (wm,0,0,0)<>0
    if IsDialogMessage(win,wm)=0
       TranslateMessage wm
       DispatchMessage wm
    end if
 WEND

Function WndProc(sys hwnd,wmsg,wparam,lparam) as sys callback
win = hwnd 'assign WIN with HWND
SELECT hwnd
CASE win
Select wmsg

   

   CASE WM_COMMAND
       controlID = LoWord(wParam)  'get control ID
       notifyCode = HiWord(wParam) 'get notification message

      select controlID

         case b0ID
           if notifycode = 0
               'get text from single line edit control and put it into text buffer
                 SendMessage edit1, WM_GETTEXT, 256 , txbuff
                 'use FindWindow api
                 hReceiver = FindWindow("O2_RECEIVER_1162023", null)
                 errMessage = txbuff
                 If hReceiver > 0
                     print errMessage
                     'SendMessage(hReceiver, WM_SETTEXT, edit2, errMessage)
                     SendDlgItemMessage(hReceiver, editID2, WM_SETTEXT, 0, strptr errMessage)
                 Else
                    print "Receiver not found"
                 End if
               

           end if

         case IDOK
            if  notifycode = 0
                'get text and put it into buffer
                SendMessage edit1, WM_GETTEXT, 256 , txbuff
                buff = buff + crlf + txbuff
               ' print buff
                SetText(edit2,buff  )
                'clear control edit1
                SendMessage edit1, WM_SETTEXT, 0, ""
               
                'set text to multi-line
                'SendMessage edit2, WM_SETTEXT, 0,strptr(txbuff) + CRLF
               
            end if

         case IDCANCEL
            print "ESCAPE"


     end select
       

CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT


RETURN Default
END FUNCTION
 

receiver:
'receiver app GUI + awinh037.inc
$ filename "Receiver.exe"
% WM_NCACTIVATE = 0x0086
' new awinh037
include "rtl32.inc" : include "awinh037.inc" : #lookahead
Declare Function IsDialogMessage Lib "user32.dll" Alias "IsDialogMessageA" (ByVal hDlg As Long, lpMsg As MSG) As Long

'globals
INT win,x=0,y=0,w=620,h=430,wstyle = WS_MINMAXSIZE
INT inbox
INT butt, b0ID = 100
INT edit1, editID1 = 101
INT edit2, editID2 = 102
string crlf = chr(13)+chr(10)
string txbuff = space(256)
char buff[4096]
'set unique ClassName /////////////////
ClassName = "O2_RECEIVER_1162023"
' open window...
win = SetWindow("Receiver",x,y,w,h,0,wstyle)

butt = SetButton(win ,430,350,88,26,"ENTER",0x50001000 | WS_TABSTOP  ,0x200,b0ID)
'single line edit control
edit1 = SetEditBox(win,20,320,500,23,"Edit_1",0x50800000| WS_TABSTOP  ,0x200,editID1)
ControlFont(edit1, 16,7, 100, "Consolas")
'multi line edit control
edit2 = SetEditBox(win,20,40,580,200,"",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL,0x200,editID2)
ControlFont(edit2, 16,7, 100, "Consolas")

'txbuff = errMessage
SendMessage edit2, WM_SETTEXT, 0, txbuff


'///  message loop ///
 WHILE GetMessage (wm,0,0,0)<>0
    if IsDialogMessage(win,wm)=0
       TranslateMessage wm
       DispatchMessage wm
    end if
 WEND

Function WndProc(sys hwnd,wmsg,wparam,lparam) as sys callback
win = hwnd 'assign WIN with HWND
SELECT hwnd
CASE win
Select wmsg

   
   CASE WM_COMMAND
       controlID = LoWord(wParam)  'get control ID
       notifyCode = HiWord(wParam) 'get notification message

      select controlID

         case b0ID
           if notifycode = BN_CLICKED OR notifycode = 1
               print "ENTER PRES!"
           end if

         case IDOK
            if  notifycode = 0
                'get text and put it into buffer
                SendMessage edit1, WM_GETTEXT, 256 , txbuff
                buff = buff + crlf + txbuff
               ' print buff
                SetText(edit2,buff  )
                'clear control edit1
                SendMessage edit1, WM_SETTEXT, 0, ""
               
                'set text to multi-line
                'SendMessage edit2, WM_SETTEXT, 0,strptr(txbuff) + CRLF               
            end if

         case IDCANCEL
            print "ESCAPE"


     end select
       

CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT


RETURN Default
END FUNCTION
 
  •