Author Topic: Using Dynamic Dialogs  (Read 10279 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Hero Member
  • *****
  • Posts: 973
Re: Using Dynamic Dialogs
« Reply #45 on: September 12, 2018, 01:08:31 PM »
I tried this workaround in sub Dialog:

  int e = int(title) : if e != 0 or title=0 then mbox "Warning: title in Dialog probably not a string"
#ifdef review
...

This should help to catch at least some of the faulty parameterization. Would there be a better solution?

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4330
    • Oxygen Basic
Re: Using Dynamic Dialogs
« Reply #46 on: September 14, 2018, 08:18:31 AM »
Hi Roland,

I think the solution is to restrict some of the type-polymorphism that o2 deploys.

It would be quite easy to switch off string<-->number conversion and others like float<--> integer conversion. These restrictions would be very useful for verifying the larger pieces of code where smart-compiling is not always desirable.

I could introduce this feature in the self-compiling o2, which I hope to release shortly.

AutoConverting parameter types:
  level 0:  param types must match exactly
  level 1:  compatible types like long,int and dword
  level 2:  types of varying width like byte, word and dword
  level 3:  expressions passed by reference (using temp variable)
  level 4:  (default) interconversion of strings and numbers

jack

  • Full Member
  • ***
  • Posts: 155
Re: Using Dynamic Dialogs
« Reply #47 on: September 14, 2018, 08:27:53 AM »
Hi Charles Pegge :)
I am excited about the forthcoming self-compiling release.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4330
    • Oxygen Basic
Re: Using Dynamic Dialogs
« Reply #48 on: September 15, 2018, 08:44:47 AM »
I'm excited too! All the source code goes into the inc folder. My main task is to make it more comprehensible for other developers.

Arnold

  • Hero Member
  • *****
  • Posts: 973
Re: Using Dynamic Dialogs
« Reply #49 on: September 15, 2018, 10:20:22 AM »
Hi Charles,

probably some of my questions are rather naive, it is remarkable that you can make something of it which could be useful in some respect. But of course I know that I as a programmer are responsible to use the correct arguments. I could even reduce the runtime errors if I did not use the 'optional' feature, but this would be a loss of flexibility. The bug itself was found immediately after I looked at the code. And most of the time the error messages of O2 are really helpful in my opinion.

Roland

Arnold

  • Hero Member
  • *****
  • Posts: 973
Re: Using Dynamic Dialogs - Treeview example
« Reply #50 on: September 15, 2018, 10:37:48 AM »
This is a small Treeview example running in a modal Dialog, combined with a Multiline Edit control. It should run in 32-bit mode and can also be compiled to a 64-bit exe file.

Probably there are not many controls left, which must be checked? I always want to compare the behaviour in 32-bit and 64-bit.

TVEditModalDlg.o2bas
Code: OxygenBasic
  1. '====================================================================
  2. ' Treeview example, modal dialog as main.
  3. '====================================================================
  4.  
  5. $ filename "TVEditModalDlg.exe"
  6. 'uses rtl32
  7. 'uses rtl64
  8.  
  9. '% review
  10. uses dialogs
  11.  
  12. string crlf=chr(13,10)
  13. macro TreeView_GetItem(hwnd,pitem) SendMessage(hwnd, TVM_GETITEM,0, pitem)
  14. macro TreeView_GetNextItem(hwnd,hitem,code) SendMessage(hwnd, TVM_GETNEXTITEM, code, hitem)
  15. macro TreeView_GetSelection(hwnd) TreeView_GetNextItem(hwnd,null,TVGN_CARET)
  16. macro TreeView_InsertItem(hwnd,lpis) SendMessage(hwnd, TVM_INSERTITEM,0, lpis)
  17. macro TreeView_SetItem(hwnd,pitem) SendMessage(hwnd, TVM_SETITEM,0, pitem)
  18.  
  19. % TVGN_CARET=9
  20. % TVIF_TEXT=1
  21. % TVIF_HANDLE=16
  22. % TVIF_CHILDREN=64
  23. % TVM_INSERTITEM=4352
  24. % TVM_GETNEXTITEM=4362
  25. % TVM_GETITEM=4364
  26. % TVM_SETITEM=4365
  27. % TVN_SELCHANGED= -402
  28. % TVS_HASBUTTONS=1
  29. % TVS_HASLINES=2
  30. % TVS_LINESATROOT=4
  31.  
  32. type NMHDR  'WinData.inc
  33.  sys   hwndFrom
  34.   sys   idFrom     'UINT_PTR
  35.  uint  code
  36. end type
  37.  
  38. type TVITEM  
  39.   uint  mask
  40.   sys   hItem 'HTREEITEM
  41.  uint  state
  42.   uint  stateMask
  43.   char* pszText
  44.   int   cchTextMax
  45.   int   iImage
  46.   int   iSelectedImage
  47.   int   cChildren
  48.   sys   lParam
  49. end type
  50. typedef TVITEM TV_ITEM
  51.  
  52. type TVINSERTSTRUCT  
  53.   sys     hParent      'HTREEITEM
  54.  sys     hInsertAfter 'HTREEITEM
  55.  TV_ITEM item
  56. end type
  57. typedef TVINSERTSTRUCT TV_INSERTSTRUCT
  58.  
  59.  
  60. 'Identifiers
  61. % IDC_TREEVIEW = 1001
  62. % IDC_MLE      = 1002
  63. % IDC_BUTTON   = 1003
  64.  
  65. declare sub InitTreeView(sys hWnd, lID, int lCount)
  66.  
  67. =============================================
  68. 'MAIN CODE
  69. =============================================
  70.  
  71. init_common_controls()
  72.  
  73. char* cmdline
  74. @cmdline=GetCommandLine()
  75. sys hInstance = GetModuleHandle(null)
  76.  
  77.  
  78. function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
  79.    NMHDR ptnmhdr at lParam
  80.    
  81.    sys hMle=GetDlgItem(hDlg, IDC_MLE)
  82.    static string buffer, txt
  83.  
  84.    select case uMsg
  85.  
  86.       case WM_INITDIALOG
  87.          InitTreeView(hDlg,IDC_TREEVIEW, 1)
  88.        
  89.       case WM_COMMAND
  90.          select case loword(wParam)
  91.             case IDCANCEL, IDC_BUTTON
  92.                EndDialog( hDlg, null )
  93.         end select
  94.  
  95.       case WM_NOTIFY
  96.          select case ptnmhdr.idFrom
  97.             case IDC_TREEVIEW
  98.                select case ptnmhdr.code
  99.                  case TVN_SELCHANGED
  100.                    TV_ITEM tTVItem
  101.                                
  102.                    'Get handle of item
  103.                   sys hTV=GetDlgItem(hDlg, IDC_TREEVIEW)                
  104.                    sys hTVItem = TreeView_GetSelection(hTV)                                            
  105.                    buffer = nuls 128
  106.                    'Get text
  107.                   tTVItem.hItem = hTVItem                  
  108.                    tTVItem.mask = TVIF_TEXT                
  109.                    tTVItem.cchTextMax = 128                  
  110.                    tTVItem.pszText = buffer                  
  111.                    if TreeView_GetItem(hTV, &tTVItem) then                  
  112.                    if len(tTVItem.pszText) then
  113.                       txt=tTVItem.pszText
  114.                       if txt="Title 1" then
  115.                          txt="Ipsum lorem" & crlf & crlf &
  116.                          "At vero eos et accusam et justo" & crlf &
  117.                          "labore et dolore magna aliquyam erat," & crlf &
  118.                          "no sea takimata sanctus est."                  
  119.                          SendMessage(hMle, WM_SETTEXT, 0, txt)
  120.                       else  
  121.                          SendMessage(hMle, WM_SETTEXT, 0, txt & " is selected")
  122.                       end if                  
  123.                    end if                      
  124.                    end if              
  125.                  
  126.             end select
  127.          end select
  128.      
  129.       case WM_CLOSE
  130.          EndDialog( hDlg, null )
  131.                
  132.    end select
  133.  
  134.    return 0
  135. end function
  136.  
  137.  
  138. sub winmain()
  139.    uint Style, StyleEx
  140.    
  141.    Dialog( 0, 0, 520*0.6, 320*0.5, "Treeview example in modal dialog using OxygenBasic",
  142.            WS_OVERLAPPEDWINDOW or DS_CENTER or DS_SETFONT,
  143.            8, "MS Sans Serif", WS_EX_CLIENTEDGE)
  144.  
  145.    Style   = WS_CHILD OR WS_CLIPSIBLINGS OR WS_TABSTOP OR _
  146.              WS_VISIBLE OR TVS_HASBUTTONS OR TVS_HASLINES OR _
  147.              TVS_LINESATROOT
  148.    StyleEx = WS_EX_CLIENTEDGE
  149.    Control("Treeview",  IDC_TREEVIEW, "SysTreeView32", Style,
  150.            10*0.6,10*0.5,190*0.6,270*0.5 , StyleEx )        
  151.  
  152.    Style   = WS_CHILD OR WS_CLIPSIBLINGS OR WS_TABSTOP OR _
  153.              WS_VISIBLE OR ES_AUTOHSCROLL OR ES_AUTOVSCROLL OR _
  154.              ES_MULTILINE OR ES_WANTRETURN
  155.    Control("",  IDC_MLE, "EDIT", Style,
  156.            216*0.6,10*0.5,290*0.6,180*0.5 , StyleEx )        
  157.  
  158.    PushButton( "Close" , IDC_BUTTON, 320*0.6, 230*0.5, 100*0.6, 30*0.5 )
  159.    CreateModalDialog( null, @DialogProc, 0)
  160. end sub
  161.  
  162. winmain()
  163.  
  164. '=====================================================
  165.  
  166. sub TreeViewInsertItem(sys hTree, hParent, string sItem)
  167.    TV_INSERTSTRUCT tTVInsert
  168.    TV_ITEM tTVItem
  169.  
  170.    if hParent then
  171.      tTVItem.mask        = TVIF_CHILDREN or TVIF_HANDLE
  172.      tTVItem.hItem       = hParent
  173.      tTVItem.cchildren   = 1
  174.      TreeView_SetItem (hTree, tTVItem)
  175.    end if
  176.  
  177.    tTVInsert.hParent              = hParent
  178.    tTVInsert.Item.mask            = TVIF_TEXT
  179.    tTVInsert.Item.pszText         = strptr(sItem)
  180.    tTVInsert.Item.cchTextMax      = len(sItem)
  181.  
  182.    TreeView_InsertItem (hTree, &tTVInsert)
  183. end sub
  184.  
  185.  
  186. sub InitTreeView(sys hWnd, lID, int lCount)
  187.     sys hRoot, hParent
  188.     int i,j,k
  189.     sys hCtl
  190.  
  191.     hCtl = GetDlgItem(hWnd,lID)
  192.  
  193.     for i = 1 to lCount
  194.        hRoot = TreeViewInsertItem(hCtl, null, "Title " & str(i))
  195.        for j = 1 to 3
  196.           hParent = TreeViewInsertItem(hCtl, hRoot, "Chapter " & str(j))
  197.           for k = 1 to 4
  198.              TreeViewInsertItem(hCtl, hParent, "Paragraph " &  str(j) & "." & str(k))
  199.           next k
  200.         next j
  201.     next i
  202. end sub
  203.