  'PEROXIDE.O2BAS
  'derived from finded

  '============
  'SEARCH FILES
  '============

  '00:00 22/03/2014
  '20:55 17/03/2017
  '16:00 20/10/2018
  '18:59 03/08/2019
  '13:44 26/03/2022
  '13:44 20/06/2022
  '12:04 01/10/2022
  '14:57 17/06/2023
  '09:17 11/07/2023
  '16:04 08/01/2024
  '00:46 01/03/2024

  '
  'Charles E V Pegge

  #compact
  $filename "peroxide.exe"
  uses rtl64
  uses oxide.res
  uses searchutil
  uses richutil
  uses filedialogs


  string cfgs="peroxide.cfg"

  'http://msdn.microsoft.com/en-us/library/ms632598(VS.85).aspx
  '
  '
  'when all the keywords are found within close range
  'of each other, the region of text is displayed



  function SetFont(sys *hwnd,int n,height,width,weight, string fontname) as sys
  =============================================================================
  indexbase 1
  sys hFont
  int i
  hfont=CreateFont( height,width,0,0,weight,0,0,0,0,0,0,0,0,fontname)
  for i=1 to n
    SendMessage hwnd(i),WM_SETFONT,hfont,0
  next
  return hFont
  end function

 
  % ID_FIRSTCHILD  100 'Each window 100... 


  sys hinstance
  sys hWndMain

  ======================================
  
  sys inst=GetModuleHandle 0
  asciiz * cmdline 
  @cmdline=GetCommandLine

  ======================================


  'STANDARD CHILD WINDOWS STYLES
  '=============================
  '
  'Button	The class for a button.
  'ComboBox	The class for a combo box.
  'Edit	        The class for an edit control.
  'ListBox	The class for a list box.
  'MDIClient	The class for an MDI client window.
  'ScrollBar	The class for a scroll bar.
  'Static	The class for a static control.



  function GetSelTextLine(sys h) as string
  ========================================
  sys b
  int je,le,st,en
  static string s
  s=nuls 512
  b=strptr(s)
  *b=512 'put buffer length info into buffer string
  SendMessage h, EM_GETSEL, @st, @en       'LOCATE CARET / SELECTED AREA
  je=SendMessage h, EM_LINEFROMCHAR, st, 0 'IDENTIFY LINE
  st=SendMessage h, EM_LINEINDEX, je, 0    'LOCATE START OF LINE
  le=SendMessage h, EM_GETLINE, je, b      'GET LINE STRING AND LENGTH
  SendMessage h,EM_SETSEL,st,st+le         'HIGHLIGHT LINE
  return left s,le                         'RETURN LINE STRING
  end function


  sub SetSelColor(sys hd, int c)
  ==============================
  CHARFORMATA cf 'charformatW
  cf.cbsize=sizeof(cf)
  SendMessage hd,EM_GETCHARFORMAT,SCF_SELECTION,@cf
  cf.dweffects and= not(CFE_AUTOCOLOR)
  cf.crTextColor = c
  SendMessage hd,EM_SETCHARFORMAT,SCF_SELECTION,@cf
  end sub


  sub AdjustForCRLF(string *s, int *a)
  ====================================
  int i,c
  do
    i=instr(i+1,s,chr(13,10))
    if i=0
      exit do
    endif
    if i<a
      c++
    else
      exit do
    endif
  loop
  a-=c
  end sub


  function PostFileContent(string *f,sys hl,hd) as int
  ====================================================
  int a
  string s,sl
  f=GetSelTextLine hl
  if f
    s=getfile f
    sl=lcase s
    a=SearchString sl
  else
    s=chr 0
    a=0
  endif
  '
  SendMessage hd, WM_SETTEXT, 0 , s
  '
  AdjustForCRLF(s,a)
  if a>0 
    a-=1
  endif
  'SetSelColor hd,0xf00040
  SendMessage hd,EM_SETSEL,a,a
  'SendMessage hd, EM_SCROLLCARET, 0, 0
  return a
  end function


  function GetTextFromWindow(sys h,int *e) as string
  ==================================================
  int a
  a=SendMessage h, WM_GETTEXTLENGTH,0,0
  function=nuls a
  e=SendMessage h, WM_GETTEXT,a+1 , strptr(function)
  function=left function,e
  end function


  function LocateHighlightKeyword(sys hl,hd, int le) as int
  =========================================================
  int a,e
  a=val GetSelTextLine hl
  string s
  s=GetTextFromWindow(hd,e)
  AdjustForCRLF(s,a)
  if a>0
    a-=1
  endif
  'SendMessage hd,EM_SETSEL,a,a+le
  'SetSelColor hd,0xff2040
  SendMessage hd,EM_SETSEL,a,a+le
  SendMessage hd, EM_SCROLLCARET, 0, 0
  return a
  end function


  function PostLocationList(sys hd, string f)
  ===========================================
  indexbase 0 'windows arrays
  int a
  string s,sl
  s=""
  if wordlist
    if f
      s=getfile f
    else
      s=GetTextFromWindow w[3],a
      wordlist=lcase(GetTextFromWindow(w[4],a))
    endif     
    sl=lcase s
    s=KeywordPosList sl
  endif
  '
  SendMessage hd, WM_SETTEXT, 0 , *s
  '
  end function

sub GetBasicWord(string*bu,int*i)
=================================
  indexbase 1
  int a,j
  byte bt at strptr(bu)
  sttw=i
  do
    ascb=bt[i]
    select ascb
    case 0 to 32
      exit do
    case 0x30 to 0x39 'numbers
    case 0x41 to 0x5a 'uppercase
      bt[i]+=32       'to lowercase
    case 0x61 to 0x7a 'lowercase
    case 0x80 to 0xff 'higher ascii
    case 35,46,95
    case 34,96
      a=bt[i]
      j=i+1
      'skio over quote
      do
        i++
        select bt[i]
        case 0
          i=j
          a=0
          exit do
        case a
          i++
          exit do
        end select  
      loop
      'a=instr i,bu,chr(a)
      if a
        exit do
      endif
      continue do
    case else
      if i=sttw
        i++
      endif
      exit do
    end select
    i++
  loop
  lenw=i-sttw
end sub

sub colorize(sys h)
===================
  '
  fvp=fvc
  '
  int a,b,c,d,e,g,i,j
  int line
  int se[7]
  string wr,bu
  static int mpl[255]
  static string keyw
  line = SendMessage(h,EM_GETFIRSTVISIBLELINE,0,0)
  fvc = SendMessage(h,EM_LINEINDEX,line,0)
  fvp=fvc
  'if fvc
  SendMessage(h,EM_EXGETSEL,0,@se[2])
  'saves current selection
  SendMessage(h,EM_HIDESELECTION,1,0)
  'clear sel
  SendMessage(h,EM_EXSETSEL,0,@se[0])
  se[0]=fvc
  se[1]=fvc+0x1000
  'SendMessage(h,EM_EXSETSEL,0,@se)
  'select part of visible text
  if not keyw
    keyw=getfile "inf/keywordsSorted.txt"
    if not keyw
      goto excolorize
    endif
    i=1
    b=0
    e=len(keyw)
    'map keyw by first ascii
    'must start with blank line
    'must exclude ' ascii 39 40 41 59
    do
      skiplspace(keyw,i) 'ascb
      sttw=i
      endline(keyw,i)
      if i=sttw
        i+=2
      endif
      if i>=e
        exit do
      endif
      if b<ascb
        b=ascb 'start of new ascii group
        mpl(b)=sttw
      endif
    loop
  endif
  int n
  bu=GetTextFromWindow h,n
  'clears existing coloring
  SendMessage h,WM_SETTEXT,0,""
  SendMessage h,WM_SETTEXT,0,strptr(bu)
  i=1
  c=0
  d=0
  e=0
  do
    skiplspace(bu,i)
    if ascb=13
      e++
      i+=2
      continue do
    endif
    select ascb
    case 39,59
      endline (bu,i) 'BASIC or ASM comment
      continue do
    case 47
      a=asc(bu,i+1)
      if a=42
        g=instr(i,bu,"*/") 'skip C comment
        if g
          do
            endline(bu,i)
            if i>g
              i=g+2
              exit do
            endif
            i+=2
            e++
          loop
        endif
        continue do
      elseif a=47 'skip C line comment
        endline(bu,i)
        continue do
      endif
    end select
    '
    GetBasicword(bu,i)
    '
    if lenw<1
      goto excolorize
    elseif lenw<2
      'heuristic ignore symbols
      continue do
    endif
    wr=mid bu,sttw,lenw
    'multiline quotes / crlf
    if (ascb=34)or(ascb=96)
      j=1
      do
        endline(wr,j)
        if asc(wr,j)=13
          j+=2
          e++
        else
          exit do
        endif
      loop
    endif
    c++
    a=asc wr
    a=mpl(a)
    if a=0
      continue do
    endif
    '
    lookon:
    =======
    '
    g=instr(a,keyw,wr)
    if g
      b=asc(keyw,g-1)
      if b>32
        a+=1
        goto lookon
      endif
      b=asc(keyw,g+lenw)
      if b>32
        a=g+lenw
        goto lookon
      endif
      d++
      b=sttw
      b--
      b-=e 'correctforcr
      'partial coloring
      'a=fvp+1000
      'if b>fvp and b<a
        se[4]=b
        se[5]=b+lenw
        SendMessage(h,EM_EXSETSEL,0,@se[4])
        SetSelColor h,0xFF4040
        '
        'testing EM_GETSELTEXT & EM_EXSETSEL
        'wstring wwr=nuls 32
        'SendMessageW(h,EM_GETSELTEXT,0,wwr) 'always wide-chars
        'wr=wwr
        'print wr
        'SendMessage(h,EM_EXSETSEL,0,@se[2])
      'endif
    endif
  loop
  'alt EM_REPLACESEL
  '
  excolorize:
  ===========
  SendMessage(h,EM_EXSETSEL,0,@se[2]) 'restore prior selection
  SendMessage(h,EM_HIDESELECTION,0,0)
end sub


  sub DisplayHelp
  '==============
  '
  string s= "HOW TO USE:" cr cr +
  "In the top line, Enter keywords or phrases separated by 2 commas ,," cr +
  "then press Enter to execute search." cr cr +

  "Click on filename to get list of line numbers" cr cr +
  "Click on line number to scroll down to the line" cr cr +
  "Search groups can be edited in the left-most panel, and these" cr +
  "will be retained for future use in tools/peroxide.cfg." cr cr +

  "F3 actions a key search" cr+
  "F4 or Shift-F3 searches the current file only." cr cr+
  "Each search-group is separated by a blank line. A search-group is" cr+
  "selected by clicking on the first line in the group" cr cr+

  "The keywords are not case-sensitive" cr cr+

  "Files can be edited. Press F9 or ctrl-s to save the file after editing." cr+
  "Shift F9 will 'Save As', using the file dialog" cr cr+
  ".o2bas Files can be run. Press F5 or ctrl-e to run the selected file." cr
  MessageBox 0,s,"Instructions",MB_ICONINFORMATION
  end sub

 

  indexbase 0


  =================================================================
  function WndProc(sys hwnd, uMsg, wParam, lParam) as long callback
  =================================================================
  '
  static RECT rcClient 
  static sys a,b,c,
    h,i,px,py,lx,ly,id,
    style,stylr,
    newfile,wfocus
  static sys ce=-1, pe=-1
  static sys hfont[4]
  '
  static string s,f,cf,fnt,st,ff
  if wfocus=101 'FILE LIST
    a=0xffff and SendMessage w[1], EM_GETSEL, 0, 0 'loword
    if a<>ce
      ce=a
      f=GetSelTextLine w[1]
      if f<>cf
        PostLocationList w[2],f
        a=PostFileContent f,w[1],w[3]
        'ce=0xffff and SendMessage w[1], EM_GETSEL, 0, 0 'loword
        'LocateHighlightKeyword w[2],w[3],len wordlist
        cf=f
      endif
    endif
  elseif wfocus=102 'KEYWORD LOCATION LIST
    a=0xffff and SendMessage w[2], EM_GETSEL, 0, 0 'loword
    if a<>pe
      pe=a
      a=LocateHighlightKeyword w[2],w[3],len wordlist
      '
      'display line number
      int je
      je=SendMessage w[3], EM_LINEFROMCHAR, a, 0 'IDENTIFY LINE
      SendMessage w[5],WM_SETTEXT, 0, str(je+1) 
    endif
  elseif wfocus=105 'LINE NUMBER
    'goproc
  endif
 
  select uMsg
  
  case WM_COMMAND
  ===============

    select wParam
    '
    case 4001 'SEARCH (F3)
    ======================
    '
    wholeword=0

    if GetAsyncKeyState(VK_SHIFT) and 0x8000
      PostLocationList w[2],""
    else
      gosub DoSearch
    endif
    '
    case 4002 'Save File (F9)
    =========================
    '
    s=GetTextFromWindow w[3],a
    if GetAsyncKeyState(VK_SHIFT) and 0x8000
      scope
        string ff
        char ch[256]
        GetCurrentDirectory 255,ch
        ff=GetFileName "t.txt",1 'SAVE AS
        SetCurrentDirectory ch 'restore dir
        'SendMessage w[1], WM_SETTEXT, 0 , s 'file list
        if ff
          cf=ff
        endif
      end scope
    endif
    if len cf
      putfile cf,s
      SetWindowText hwnd, cf " saved"
    endif
    '
    case 4003 'Exec File (F5)
    =========================
    '
    if len cf
      scope
      string sd=nuls(256)
      GetCurrentDirectory 256,sd
      sd=rtrim sd
      string sp=dirpath(cf,1)
      if sp
        SetCurrentDirectory(sp)
      endif
      string f=trimpath(cf)
      if right(cf,6)=".o2bas"
        string sc
        sc=AppExePath()
        QuExec(sc+"co2.exe","",f)
        SetWindowText hwnd, cf " Exec"
      elseif right(cf,4)=".bat"
        DOS(f,0)
        SetWindowText hwnd, cf " Exec"
      endif
      SetCurrentDirectory(sd)
      end scope
    endif
    '
      case 4004 'WORD SEARCH (F4)
    ===========================
    '
    'wholeword=1
    'gosub DoSearch
    wholeword=0
    PostLocationList w[2],""
    '
    '
    case 4005
    =========
    '
    'pvc=1-pvc 'toggle line numbering
    '
    colorize w[3]
    '
  case 4006 'Exec File (shift F5)
    ===============================
    '
    if len cf
      scope
      string sd=nuls(256)
      GetCurrentDirectory 256,sd
      sd=rtrim sd
      string sp=dirpath(cf,1)
      if sp
        SetCurrentDirectory(sp)
      endif
      string f=trimpath(cf)
      if right(cf,6)=".o2bas"
        string sc
        sc=AppExePath()
        QuExec(sc+"co2m64.exe","",f)
        SetWindowText hwnd, cf " Exec"
      elseif right(cf,4)=".bat"
        DOS(f,0)
        SetWindowText hwnd, cf " Exec"
      endif
      SetCurrentDirectory(sd)
      end scope
    endif
    '
    end select

    '
    if hiword(wparam)=EN_SETFOCUS
      wfocus=loword(wparam)
    endif
    return 0
 
 
  case WM_CREATE
  ==============
  '
  ' Create child windows.
  style=WS_CHILD | WS_BORDER | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_NOHIDESEL
  stylr=style | ES_READONLY
  int idmenu
  idmenu=0
  id=ID_FIRSTCHILD
  py=0 : ly=0
  px=0 : lx=0
  '
  w[0]=CreateWindowExW(0,l"RichEdit50W", null, style, px,py,lx,ly, hwnd, id, inst, null)
  w[1]=CreateWindowEx 0,"edit", NULL, stylr, px,py,lx,ly, hwnd, id+1, inst, NULL
  w[2]=CreateWindowEx 0,"edit", NULL, stylr, px,py,lx,ly, hwnd, id+2, inst, NULL
  w[3]=CreateWindowExW(0,l"RichEdit50W", null, style, px,py,lx,ly, hwnd, id+3, inst, null)
  '
  SendMessage w[3],EM_LIMITTEXT,0x100000,0 '1 meg limit
  'a=SendMessage w[3],EM_GETLIMITTEXT,0,0 ' = &HC5 limit for XP.. 7fffffff (before: XP 7fff)
  'print a
  sys h=w[3]
  '
  id=104 : i=4 : px=10 : lx=10 : py=10 : ly=10
  style=WS_CHILD | WS_BORDER | WS_VISIBLE
  stylr=style | ES_READONLY

  'for keywords:
  w[4]=CreateWindowEx 0,"edit", NULL, style, px,py,lx,ly, hwnd, id+4, inst, NULL
  'for line number
  w[5]=CreateWindowEx 0,"edit", NULL, style, 0,0,0,0, hwnd, id+5, inst, NULL

  'action buttons
  style=WS_CHILD | BS_TEXT | BS_PUSHBOX | WS_VISIBLE
  w[6]=CreateWindowEx(0,"button", "find",  style, 0,0,0,0, hwnd, 4001, inst, null)
  w[7]=CreateWindowEx(0,"button", "color", style, 0,0,0,0, hwnd, 4005, inst, null)
  w[8]=CreateWindowEx(0,"button", "save",  style, 0,0,0,0, hwnd, 4002, inst, null)
  w[9]=CreateWindowEx(0,"button", "exec",  style, 0,0,0,0, hwnd, 4003, inst, null)
  w[10]=CreateWindowEx(0,"button", "ex64",  style, 0,0,0,0, hwnd, 4006, inst, null)
  '
  % EC_LEFTMARGIN 1
  '
  SendMessageW(w[3],EM_SETBKGNDCOLOR,0,0xeeffff)
  SendMessageW(w[3],EM_SETMARGINS,EC_LEFTMARGIN,10)
  int scid
  scid = id+3
  SetWindowSubClass(w[3],@EdProc,@scid,0)
  scid = id+5
  SetWindowSubClass(w[5],@GoProc,@scid,0)

  'SetFont(sys *hwnd,n,height,width,weight,string fontname) as sys
  hFont[1]=SetFont(w[0],3,12,8,400,"Lucida Console")
  hFont[2]=SetFont(w[3],1,14,10,400,"Lucida Console")
  hFont[3]=SetFont(w[4],5,14,10,400,"Lucida Console")


  ff=getfile cfgs
  '
  if not ff
    ff="'Default list"+cr+"-r .\*.o2bas"+cr+"-r .\*.inc"+cr+"-r .\*.txt"
  endif
  SendMessage w[0],WM_SETTEXT,0,*ff

  return 0

  'case WM_NOTIFY
  'case WM_HELP

  case WM_SIZE
  ============ 

  'Set the window order
  'https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos
  '
  'sys hw=-1 'HWND_TOPMOST 'hw must be sys as a window handle
  'SetWindowPos(hwnd,hw,0,0,0,0,0x3)

 
  GetClientRect(hwnd, @rcClient) 
 
  'Size and position the child window.  
  int a,i,v,vb
  a=rcClient.right>>1
  for i=0 to 10
    v=rcClient.right*.25
    if v>160
      v=160
    endif
    vb=v*i
    if i<4
      if i=0
        v*=.75
      elseif i=1
        vb=v*.75
        v*=1.25
      elseif i=2
        v*=.5
      elseif i=3
        vb-=v*.5
        v=rcClient.right-vb-5 ' wide window on the right
      endif
      MoveWindow(w[i], vb, 30, v, rcClient.bottom-60, TRUE) 
    else 'i>=4
      if i=4
        'keyword entry
        a=240
        MoveWindow(w[4], 0, 5, a-20, 20, TRUE)
      endif
      if i=5
        'line number display
        MoveWindow(w[5], a, 5,70, 20, TRUE)
        a+=80
      endif
      if i>5
        'action buttons
        MoveWindow(w[i], a, 5,55, 20, TRUE)
        a+=60
      endif
    endif
    '
    ShowWindow(w[i], SW_SHOW)
  next
  return 0 

  case WM_CLOSE
  ============= 

  h=w[0]
  ff=GetTextFromWindow h,a
  putfile cfgs,ff
  DestroyWindow(hwndMain) 

  case WM_DESTROY: 
    DeleteObject hfont[1]
    DeleteObject hfont[2]
    DeleteObject hfont[3]
    PostQuitMessage(0) 
    return 0

  end select
  '
  return DefWindowProc(hwnd, uMsg, wParam, lParam)
    '
    ===================
    subroutine DoSearch
    ===================
    '
    int a,b,c,d,e,aa,bb
    st=GetTextFromWindow w[4],a
    wordlist=lcase st
    c=len(st)
    SendMessage w[4], EM_SETSEL, 0, c
    SendMessage w[0], EM_GETSEL, @b, @c
    ff=GetTextFromWindow w[0],a
    SendMessage w[0], WM_SETTEXT, 0, ff
    b++
    d=1
    e=1
    do
      c=asc(ff,d)
      select c
        case 0 : exit do
        case 10 : e=d+1 : b++ 'adjust position for lf
      end select
      if d>=b
        exit do
      endif
      d++
    loop
    b=e 'StartOfLine ff,b
    a=instr(b,ff,cr+cr)
    if a=0
      a=len(ff)+1
    endif
    aa=a
    bb=b
    AdjustForCRLF ff,b
    AdjustForCRLF ff,a
    SendMessage w[0], EM_SETSEL, b , a
    SetSelColor w[0],0x4040F0
    SendMessage w[0], EM_SETSEL, b , b
    ff=mid ff,bb,aa+2-bb
    SetFocus w[4]
    s=GetFilteredFileLists ff
    SendMessage w[1], WM_SETTEXT, 0 , s 'file list
    SendMessage w[1], EM_SETSEL, 0 , 0
    f=GetSelTextLine w[1]
    'if f<>cf
    PostLocationList w[2],f
    a=PostFileContent f,w[1],w[3]
    'LocateHighlightKeyword w[2],w[3],len wordlist
    cf=f
    'endif
    ce=0
    SetFocus w[4]
    end subroutine

  end function




  Function WinMain(sys inst, prevInst, zstring* cmdline , sys show) as long
  '========================================================================
                    '
  ; window handle
  
  dim a,b,c,hWnd as long
  dim wc as WndClass
  dim wm as MSG

  with wc                '
    .style=CS_HREDRAW or CS_VREDRAW
    .lpfnWndProc=&WndProc '#long#long#long#long
    .cbClsExtra=0
    .cbWndExtra=0    
    .hInstance=inst
    .hIcon=LoadIcon 0, IDI_APPLICATION
    .hCursor=LoadCursor 0,IDC_ARROW
    .hbrBackground=GetStockObject WHITE_BRUSH '
    .lpszMenuName=0
    .lpszClassName=@"Wins"
  end with


  hinstance=inst

  if not RegisterClass &wc
    MessageBox 0,`Registration failed`,`Problem`,MB_ICONERROR
    exit function
  endif 


  int style=WS_OVERLAPPEDWINDOW

  ' Create the main window. 

   hwndMain = CreateWindowEx( 
    0,                   ' no extended styles           
    "Wins",              ' class name                   
    "Find words in files (F1 help)",' window name  
    style,               '                
    CW_USEDEFAULT,       ' default horizontal position  
    CW_USEDEFAULT,       ' default vertical position    
    800,                 ' default width                
    400,                 ' default height               
    NULL,                ' no parent or owner window    
    NULL,                ' class menu used              
    hinstance,           ' instance handle              
    NULL                 ' no window creation data      
    )


  ' Show the window using the flag specified by the program 
  ' that started the application, and send the application 
  ' a WM_PAINT message. 

  hwnd=hwndMain
      
  if not hWnd
    MessageBox 0,`Unable to create window`,`problem`,MB_ICONERROR
    exit function
  endif
  '
  ShowWindow hWnd,show
  UpdateWindow hWnd
  ' 
  '
  bool bRet
  '
  while bRet := GetMessage (wm, 0, 0, 0)
    if bRet==-1
      mbox "windows message loop error "
      exit while
    else
      if wm.message=WM_KEYDOWN
       select wm.wparam
        '
        'case 0x1B 'Esc
        '  SendMessage hwnd,WM_DESTROY,0,0 
        '  continue do
        case 83 'S
          if GetAsyncKeyState(VK_CONTROL) and 0x8000
            SendMessage hWnd,WM_COMMAND, 4002, 0 'to save file
            continue do
          endif
        case 69 'E
          if GetAsyncKeyState(VK_CONTROL) and 0x8000
            SendMessage hWnd,WM_COMMAND, 4003, 0 'to run file
            continue do
          endif
        case VK_F9 'save file
          SendMessage hWnd,WM_COMMAND, 4002, 0 'to save file
          continue do
        case VK_F5 'exec file
          if GetAsyncKeyState(VK_SHIFT) and 0x8000
            SendMessage hWnd,WM_COMMAND, 4006, 0 'to run file 64bit
          else
            SendMessage hWnd,WM_COMMAND, 4003, 0 'to run file 32bit
          endif
          continue do
        case VK_F2 'color
          SendMessage hWnd,WM_COMMAND, 4005, 0 'to colorize
          continue do
        case VK_F1
          DisplayHelp
          continue do
        case VK_F3 '
          SendMessage hWnd,WM_COMMAND, 4001, 0 'to execute search
        case VK_F4 '
          SendMessage hWnd,WM_COMMAND, 4004, 0 'to execute local search
        case 0x0D 'CR / Enter
          if wm.hwnd=w[4]
            SendMessage hWnd,WM_COMMAND, 4001, 0 'to execute search
            continue do
          endif
        end select
      endif
      TranslateMessage &wm
      DispatchMessage &wm
    endif
  wend
  '
  '
  function=wm.wparam

  end function



  WinMain inst,0,cmdline,SW_NORMAL
  end

