Subject Re: attachment for mv_mail programm
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 18 Nov 2023 09:44:58 +0200
Newsgroups dbase.getting-started
Attachment(s) bijlage_test.wfm

On 2023/11/18 09:07, Mervyn Bick wrote:

> The example form uses code ("stolen" from Marc van den Berghen MANY
> years ago :-) ) to deselect the first entry in the listbox so that the
> user starts with a clean sheet.  This is only possible where the
> listbox's multiple property is set true. The user can, of course still
> select the first entry if required.

Using the listbox's onRightMoueUp event handler to clear the selection
in the listbox causes an annoying flicker.  Using the onRightMouseDown
event sorts this out.

A revised example is attached.

Mervyn.



clear
** END HEADER -- do not remove this line
//
// Generated on 2023-11-17
//
parameter bModal
local f
f = new bijlage_testForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class bijlage_testForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      metric = 6        // Pixels
      height = 413.0
      left = 190.0
      top = 33.0
      width = 713.0
      text = ""
   endwith

   this.KNOP_BIJLAGE = new PUSHBUTTON(this)
   with (this.KNOP_BIJLAGE)
      onClick = class::KNOP_BIJLAGE_ONCLICK
      height = 57.0
      left = 374.0
      top = 177.0
      width = 131.0
      text = "Run function bijlageB() to select files."
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 57.0
      left = 374.0
      top = 261.0
      width = 131.0
      text = "Run function bijlageA() to display selected files"
   endwith

   this.EDITOR1 = new EDITOR(this)
   with (this.EDITOR1)
      height = 126.0
      left = 320.0
      top = 34.0
      width = 321.0
      value = ""
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      height = 22.0
      left = 35.0
      top = 36.0
      width = 213.0
      value = "D:\examples"
   endwith

   this.PUSHBUTTON2 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON2)
      onClick = class::PUSHBUTTON2_ONCLICK
      height = 24.0
      left = 50.0
      top = 68.0
      width = 107.0
      text = "Change directory"
   endwith

   this.LISTBOX1 = new LISTBOX(this)
   with (this.LISTBOX1)
      onRightMouseDown = class::LISTBOX1_ONRIGHTMOUSEDOWN
      height = 232.0
      left = 35.0
      top = 162.0
      width = 218.0
      id = 106
      colorHighLight = "HighLightText/HighLight"
      multiple = true
      vScrollBar = 1        // On
   endwith

   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 22.0
      left = 35.0
      top = 105.0
      width = 267.0
      text = "Use Ctrl-key to select/deselect multiple files"
   endwith

   this.TEXTLABEL2 = new TEXTLABEL(this)
   with (this.TEXTLABEL2)
      height = 22.0
      left = 35.0
      top = 132.0
      width = 226.0
      text = "Right-click to clear selection "
   endwith

   this.PUSHBUTTON3 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON3)
      onClick = class::PUSHBUTTON3_ONCLICK
      height = 57.0
      left = 374.0
      top = 341.0
      width = 131.0
      text = "Print listbox1.selected()"
   endwith


   function KNOP_BIJLAGE_onClick()
      //save the array returned by bijlageB in
      form.editor1.value = ''
      form.bijlage_array = class::bijlageB()
      return

   function LISTBOX1_onRightMouseDown(flags, col, row)
       class::renew_listbox_list()
      this.cursel =  1
      class::deselectEntry()      
      return

   function PUSHBUTTON1_onClick()
      if type('form.bijlage_array') ='A'
         class::bijlageA(form.bijlage_array)
      else
         msgbox("bijlageB hasn't been executed")
      endif        
      return
      
      

   function bijlageB
      aGroep = new array()
      aGroep = form.listbox1.selected()
      return aGroep
      

   function PUSHBUTTON2_onClick()
       form.entryfield1.value = getdir()
      class::renew_listbox_list()
      form.listbox1.cursel = 1
      class::deselectEntry()
      return
      

   function renew_listbox_list
      form.listbox1.selected() = null
      form.listbox1.datasource = null
      aList = class::get_file_list()
      form.aList_first = aList[1]
      form.listbox1.datasource = 'ARRAY aList'
      class::deselectentry()
      return

   function PUSHBUTTON3_onClick()
      if form.listbox1.selected().size = 0
         msgbox('Nothing selected')
      endif  
      for n = 1 to form.listbox1.selected().size
         ? form.listbox1.selected()[n]
      next  
      return

   function bijlageA(aArray)  
      //Replace with code to set email attachments
      if aArray.size = 0
         msgbox('Nothing selected')
      endif  
      form.editor1.value = ''
      for n = 1 to aArray.size
         form.editor1.value += aArray[n]
         form.editor1.value += chr(13)+chr(10)
      next  
      return
      

   function get_file_list
      //Creates the array aList containing a list of
      //filenames held in the directory shown in entryfield1
      local aFiles,nFiles,cSkeleton
      private aList
      #define ARRAY_DIR_NAME 1
      aFiles = new Array() // Array will be resized as needed
      aList = new array()  //One dimension array for listbox
      cFileType = '\*.*'  //Change as appropriate
      cSkeleton = form.entryfield1.value+cFileType
      nFiles = aFiles.dir(cSkeleton)
      for nFile = 1 to nFiles
          aList.add(aFiles[nFile,ARRAY_DIR_NAME])
      next
      return aList
      

   function setcontrolkey(onoff,nstate)
      local keybuffer,state,vk_control
      vk_control = 0x11  //virtual key code for control key
      keybuffer = Space(256)
      GetKeyboardState(keybuffer)    
      state=keybuffer.getbyte(vk_control)
      If onoff # 0              
         nstate=bitor(128,state)
      endif
      keybuffer.setbyte(vk_control,nstate)
      SetKeyboardState(keybuffer)  
      return state

   function deselectEntry
      wm_lbuttondown = 0x0201
      wm_lbuttonup = 0x0202
      class::setcontrolkey(1,0)    
      sendmessage(form.listbox1.hwnd,wm_lbuttondown,9,0x100010)
      sendmessage(form.listbox1.hwnd,wm_lbuttonup,9,0x100010)
      class::setcontrolkey(0,1)
      return  

   function form_onOpen()
      if type("SendMessage") # "FP"
          extern clong SendMessage(chandle,cuint,clong,clong) user32 ;
                from "SendMessageA"
      endif
      if type("GetKeyboardState") # "FP"
         extern CVOID GetKeyboardState(CPTR) User32
      endif
      if type("SetKeyboardState") # "FP"
         extern CVOID SetKeyboardState(CPTR) User32
      endif
      //get list of files in diretory shown in entryfield1
      aList = class::get_file_list()
      form.listbox1.datasource = 'ARRAY aList'
      class::deselectEntry()
      return

endclass