home *** CD-ROM | disk | FTP | other *** search
/ BUG 4 / BUGCD1997_05.BIN / aplic / clip4win / clip4win.exe / C4W30E.HUF / SOURCE / MEMOEDIT.PRG < prev    next >
Text File  |  1994-06-22  |  4KB  |  129 lines

  1. /////////////////////////
  2. //
  3. //    memoedit.prg - alternative MEMOEDIT() function using an edit control
  4. //
  5. //    Written by:    John M. Skelton, 12-May-93.
  6. //
  7. //    Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds LS25 5HP, UK.
  8. //    All Rights Reserved.
  9. //
  10. /////////////////////////
  11.  
  12. /*
  13.  *  You can define C4W_V1 to get the version 1 behaviour.
  14.  */
  15. //#define C4W_V1
  16.  
  17. #ifndef    C4W_V1
  18. #define    WIN_WANT_ALL
  19. #endif    // C4W_V1
  20. #include "windows.ch"
  21.  
  22.  
  23. #ifdef    C4W_V1
  24.   #define IDD_EDIT    "edit"
  25.   #define IDD_OK    "ok"
  26.   #define IDD_CANCEL    "cancel"
  27. #else    // C4W_V1
  28.   #define IDD_EDIT    500    // avoid internal values (which start at 100)
  29.   #define IDD_OK    IDOK
  30.   #define IDD_CANCEL    IDCANCEL
  31. #endif    // C4W_V1
  32.  
  33. function memoedit(cText)
  34. local    aDlg, cRet
  35. #ifndef    C4W_V1
  36. local    hFocus := GetFocus()
  37. #endif    // C4W_V1
  38. aDlg = CreateDialog("Memo Edit",                    ;
  39.             WS_CAPTION + WS_SYSMENU + WS_GROUP + WS_TABSTOP    ;
  40.             + WS_THICKFRAME + WS_VISIBLE + WS_POPUP,        ;
  41.             50, 30, 250, 165)
  42.  
  43. aDlg = AppendDialog(aDlg, IDD_EDIT, DLG_EDIT,                ;
  44.             ES_LEFT + ES_MULTILINE + ES_NOHIDESEL        ;
  45.             + ES_AUTOVSCROLL + ES_AUTOHSCROLL + ES_WANTRETURN    ;
  46.             + WS_VSCROLL + WS_HSCROLL + WS_BORDER + WS_TABSTOP    ;
  47.             + WS_CHILD + WS_VISIBLE,                ;
  48.             10, 10, 230, 120,                    ;
  49.             cText)
  50. #ifdef    C4W_V1
  51.  
  52. aDlg = AppendDialog(aDlg, IDD_OK, DLG_BUTTON,                ;
  53.             BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
  54.             50, 140, 50, 15,                    ;
  55.             "&Ok")
  56. aDlg = AppendDialog(aDlg, IDD_CANCEL, DLG_BUTTON,            ;
  57.             BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,    ;
  58.             150, 140, 50, 15,                    ;
  59.             "&Cancel")
  60.  
  61. if ModalDialog(aDlg) = 0 .or. GetDialogResult(aDlg, "cancel") = .T.
  62.     cRet = cText
  63. else
  64.     cRet = GetDialogResult(aDlg, "edit")
  65. endif
  66. return cRet
  67.  
  68. #else    // C4W_V1
  69.  
  70. aDlg = AppendDialog(aDlg, IDD_OK, DLG_BUTTON,                ;
  71.             BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
  72.             50, 145, 50, 15,                    ;
  73.             "&Ok")
  74. aDlg = AppendDialog(aDlg, IDD_CANCEL, DLG_BUTTON,            ;
  75.             BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,    ;
  76.             150, 145, 50, 15,                    ;
  77.             "&Cancel")
  78. aDlg = AppendDialog(aDlg, -1, DLG_STATIC,                ;
  79.             SS_CENTER + WS_CHILD + WS_VISIBLE,            ;
  80.             50, 133, 150, 10,                    ;
  81.             "For Tab press Control-Tab")
  82. /*
  83.  *  Note: ModalDialog() returns 0 if cancelled, e.g. by Esc or
  84.  *        if EndDialog() is used with IDCANCEL
  85.  */
  86. if ModalDialog(aDlg, , ,                    ;
  87.            {|hDlg, nMsg, nwParam, nlParam|            ;
  88.         Dlg(hDlg, nMsg, nwParam, nlParam, @cText)}) == 0
  89.     // cancelled
  90.     cRet = cText
  91. else
  92.     cRet = cText
  93. endif
  94. SetFocus(hFocus)
  95. return cRet
  96.  
  97. #define    MAKELPARAM(nLow, nHigh)        ((nLow) + (nHigh) * 65536)
  98.  
  99. static function Dlg(hDlg, nMsg, nwParam, nlParam, cText)
  100. local    hEdit
  101. do case
  102. case nMsg == WM_INITDIALOG
  103.     // Nothing much needed: the edit control is first and has WS_TABSTOP,
  104.     // so it will automatically get the input focus.
  105.     // Let's allow rather large strings (maybe you should WinExec() an
  106.     // editor!)...
  107.     hEdit = GetDlgItem(hDlg, IDD_EDIT)
  108.     SendMessage(hEdit, EM_LIMITTEXT, 0, 0)    // & see edit.prg
  109.     // ... and deselect the text (not sure why SendMessage() doesn't work!)
  110.     PostMessage(hEdit, EM_SETSEL, 0, 0)
  111.     // the SendMessage() above could be:
  112.     //    SendDlgItemMessage(hDlg, IDD_EDIT, EM_LIMITTEXT, 0, 0)
  113. case nMsg == WM_COMMAND
  114.     do case
  115.     case nwParam == IDD_OK .or. nwParam == IDD_CANCEL
  116.         if nwParam == IDD_OK
  117.             // see edit.prg for many Edit*() functions
  118.             cText = GetDlgItmText(hDlg, IDD_EDIT)
  119.         endif
  120.         EndDialog(hDlg, nwParam)
  121.     endcase
  122. otherwise
  123.     return 0
  124. endcase
  125. return 1
  126.  
  127. #endif    // C4W_V1
  128.  
  129.