home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
DIALOG.PRG
< prev
next >
Wrap
Text File
|
1995-07-04
|
65KB
|
2,035 lines
////////////////////////////
//
// Clip-4-Win dialog demo
//
// Copyright (C) 1993 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// Shows modal and modeless dialogs, both dynamic dialogs and
// using dialog resources.
//
// Also, how to get a dialog from a DLL. In this case, it is a
// resource-only DLL, but the same technique applies to any DLL.
// (See BigDialog(), below.) See the clip4win\dll directory for
// information about creating a resource-only DLL, and an empty
// DLL you can copy and use.
//
// Compile and link: rmake dialog
//
// NOTE: Some people have whether they can distribute CTL3D.DLL
// with their apps. Yes. Say thanks to Microsoft. They
// want you to use it because it provides the sort of
// appearance that's going to be standard in future versions
// of Windows.
//
// There are some lengthy comments further on about validating input.
//
// Data-driven: can be done using dynamic dialogs (obviously),
// but also using a resource dialog which has just some
// of the fields you will need. Then, during the
// WM_INITDIALOG, make the rest of the dialog
// using CreateWindow() and the hWndDlg as the parent
// window. If you wish, you can change the details of
// some existing controls using e.g. SetWindowText().
// This is useful with static text and other controls.
//
// NOTE: To understand the usage of the dialog resources, you
// need to look closely at the DIALOG.RC file. It defines
// three dialogs (called "dlg", "dlg2" and sample3d), containing
// various controls. The file is as follows:
/*
#define WIN_WANT_CB
#define WIN_WANT_LBS
#include "windows.ch"
#include "dlog.ch"
dlg DIALOG 6, 18, 160, 100
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Main Dialog"
FONT 8, "MS Sans Serif"
BEGIN
EDITTEXT IDD_EDIT, 9, 15, 32, 12, ES_AUTOHSCROLL
PUSHBUTTON "&Ok", IDOK, 92, 44, 40, 14
PUSHBUTTON "&Cancel", IDCANCEL, 93, 72, 40, 14
PUSHBUTTON "&Push", IDD_PUSH, 91, 12, 40, 14
GROUPBOX "Group", IDD_GROUP, 6, 36, 54, 54, WS_GROUP
CONTROL "&A", IDD_A, "Button", BS_AUTORADIOBUTTON, 11, 50, 39, 10
CONTROL "&B", IDD_B, "Button", BS_AUTORADIOBUTTON, 12, 70, 39, 10
END
dlg2 DIALOG 200, 18, 160, 100
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog #2"
FONT 12, "MS Sans Serif"
BEGIN
CONTROL "Check", IDD_CHECK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 5,
87, 40, 10
LTEXT "Text", IDD_TEXT, 71, 68, 55, 16
EDITTEXT IDD_EDIT2, 4, 26, 32, 12, ES_AUTOHSCROLL
PUSHBUTTON "&OK", IDD_OK, 59, 22, 40, 14
END
dlguser DIALOG 20, 20, 183, 127
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "User Details"
FONT 10, "MS Sans Serif"
BEGIN
PUSHBUTTON "&Ok", IDOK, 132, 13, 37, 12
PUSHBUTTON "&Cancel", IDCANCEL, 132, 37, 37, 12
PUSHBUTTON "&Next", IDD_NEXT, 132, 61, 37, 12
PUSHBUTTON "&Previous", IDD_PREV, 132, 85, 37, 12
PUSHBUTTON "&Save", IDD_SAVE, 132, 109, 37, 12
LTEXT "User ID:", IDD_TUSERID, 7, 2, 50, 8
EDITTEXT IDD_USERID, 7, 13, 115, 13, ES_AUTOHSCROLL
LTEXT "User Name:", IDD_TUSERNAME, 7, 28, 50, 8
EDITTEXT IDD_USERNAME, 7, 37, 115, 13, ES_AUTOHSCROLL
LTEXT "Department:", IDD_TDEPT, 7, 52, 50, 8
EDITTEXT IDD_DEPT, 7, 61, 115, 13, ES_AUTOHSCROLL
LTEXT "Phone:", IDD_TPHONE, 7, 76, 50, 8
EDITTEXT IDD_PHONE, 7, 85, 115, 13, ES_AUTOHSCROLL
LTEXT "Extension:", IDD_T_EXT, 7, 100, 50, 8
EDITTEXT IDD_EXT, 7, 109, 115, 13, ES_AUTOHSCROLL
END
sample3d DIALOG 0, 0, 327, 195
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "CTL3D Samples"
FONT 8, "Helv"
BEGIN
DEFPUSHBUTTON "&OK", IDOK, 261, 174, 56, 16
PUSHBUTTON "&Message Box", 130, 261, 129, 56, 16
PUSHBUTTON "&File Open", 131, 261, 151, 56, 16
EDITTEXT 101, 9, 17, 72, 12, ES_AUTOHSCROLL
EDITTEXT 102, 89, 17, 72, 31, ES_MULTILINE | ES_AUTOVSCROLL |
ES_AUTOHSCROLL | WS_VSCROLL | WS_HSCROLL
COMBOBOX 105, 15, 80, 72, 35, CBS_SIMPLE | CBS_SORT | WS_VSCROLL |
WS_TABSTOP
COMBOBOX 106, 119, 80, 72, 35, CBS_DROPDOWN | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
LISTBOX 107, 15, 139, 72, 43, LBS_SORT | LBS_DISABLENOSCROLL |
WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
CONTROL "", 108, "Static", SS_BLACKFRAME, 121, 167, 37, 16
COMBOBOX 109, 219, 80, 72, 35, CBS_DROPDOWNLIST | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
CONTROL "", 110, "Static", SS_BLACKRECT, 121, 139, 36, 16
CONTROL "Check", 112, "Button", BS_AUTOCHECKBOX | WS_TABSTOP,
186, 15, 40, 10
CONTROL "Check", 113, "Button", BS_AUTOCHECKBOX | WS_TABSTOP,
186, 25, 40, 10
CONTROL "Check", 114, "Button", BS_AUTOCHECKBOX | WS_TABSTOP,
186, 35, 40, 10
CONTROL "Radio", 115, "Button", BS_AUTORADIOBUTTON, 252, 15, 39,
10
CONTROL "Radio", 116, "Button", BS_AUTORADIOBUTTON, 252, 25, 39,
10
CONTROL "Radio", 117, "Button", BS_AUTORADIOBUTTON, 252, 35, 39,
10
GROUPBOX "Check / Radio Buttons", 121, 175, 3, 140, 52
GROUPBOX "Edit Controls", 103, 4, 3, 165, 52
LTEXT "Simple", 104, 13, 70, 72, 8
LTEXT "Drop Down", 122, 118, 70, 72, 8
LTEXT "Drop Down List", 123, 218, 70, 72, 8
GROUPBOX "Combo Boxes", 124, 3, 60, 313, 58
GROUPBOX "List Box", 125, 3, 124, 98, 65
CONTROL "", 111, "Static", SS_GRAYRECT, 166, 139, 36, 16
CONTROL "", 118, "Static", SS_WHITERECT, 210, 139, 36, 16
CONTROL "", 119, "Static", SS_WHITEFRAME, 210, 167, 37, 16
CONTROL "", 120, "Static", SS_GRAYFRAME, 166, 167, 37, 16
GROUPBOX "Static Frames and Rects", 126, 110, 125, 139, 65
LTEXT "Black", 127, 130, 157, 20, 8
LTEXT "Gray", 128, 173, 157, 20, 8
LTEXT "White", 129, 214, 157, 25, 8
END
*/
//
////////////////////////////
#define WIN_WANT_ALL
#define WIN_WANT_EN
#define WIN_WANT_LBS
#define WIN_WANT_CLIPBOARD
#define WIN_WANT_CTL_CODES
#define WIN_WANT_GETDEVCAPS
#include "windows.ch"
#include "font.ch"
#include "dialog.ch"
//#define SAY_IN_WINDOW
//#include "say.ch"
#include "dlog.ch"
//////////
//
// Try defining this to see a trace of the messages sent during the
// life of a dialog (it's less intrusive than MessageBox):
//
//////////
//#define SEE_MESSAGES // can be interesting
#define CR chr(13)
static cAppName := "C4WDialogs"
static hWnd
static cText := ""
static cFontName := "MS Sans Serif"
static nPointSize := 8
static hLibCtl3d
#ifdef SEE_MESSAGES
static aDlg := {}
static hDlg
static aDlog := {}
static aEdit := {}
#endif // SEE_MESSAGES
function main()
local hMenu, nEvent
set scoreboard off
set confirm on
SetColor("n/w,+w/n,+w,+w,+w/n")
hWnd = WinSetup(cAppName, "Clip-4-Win Dialog Demo")
hMenu = MenuSetup()
Ctl3d(.t.) // default to 3D controls
HideCaret(hWnd)
AddHandler(hWnd, {|nEvent| MainEvent(nEvent)})
#ifdef SEE_MESSAGES
MessageBox( , "Compiled with SEE_MESSAGES", cAppName)
#else
MessageBox( , "Compiled without SEE_MESSAGES", cAppName)
#endif // SEE_MESSAGES
do while .t.
do while (nEvent := ChkEvent()) == EVENT_NONE
enddo
HandleEvent(nEvent)
if nEvent == EVENT_QUIT
DoExit()
endif
enddo
return nil
procedure MainEvent(nEvent)
#ifdef SEE_MESSAGES
local i, a := array(10)
if nEvent == EVENT_RCLICK
MessageBox( , asString(cText), "cText")
MessageBox( , asString(IsWindow(hDlg)), "IsWindow(hDlg)")
MessageBox( , asString(len(aDlg)), "len(aDlg)")
MessageBox( , asString(atail(aDlg)), "atail(aDlg)")
if len(aDlg) > len(a)
// just show the last few msgs
for i = 1 to len(a)
a[i] = aDlg[len(aDlg) - len(a) + i]
next i
else
a = aDlg
endif
MessageBox( , asString(a), "a")
endif
#endif // SEE_MESSAGES
return
procedure DoAbout()
MessageBox( , "Demo written by John Skelton", "About", ;
MB_ICONEXCLAMATION + MB_OK)
return
static procedure DoFont()
local aFont[14], nPt, hDC := GetDC(hWnd)
aFont[LF_FaceName] = cFontName
// the following scales the font from point size to screen size:
aFont[LF_Height] = - GetDeviceCaps(hDC, LOGPIXELSY) * nPointSize / 72
ReleaseDC(hWnd, hDC)
if ChooseFont(aFont, @nPt) != nil
cFontName = aFont[LF_FaceName]
// the returned value is in tenths of a point
nPointSize = nPt / 10
endif
return
procedure DoExit(c)
MessageBox(0, "Thanks for running this Clip-4-Win demo!", "Exiting", ;
MB_ICONHAND + MB_OK)
Ctl3d(.f.) // stop using 3D controls
if IsWindow(hWnd)
DestroyWindow(hWnd)
endif
UnregisterClass(cAppName)
quit
return
function DynModal()
local aDlg, cText := "Some text"
aDlg = CreateDialog("DynModal", ;
DS_MODALFRAME + WS_POPUP + WS_VISIBLE + WS_CAPTION ;
+ WS_SYSMENU, ;
6, 18, 160, 100, ;
nPointSize, cFontName)
aDlg = AppendDialog(aDlg, "edit", DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
9, 15, 32, 12, ;
cText, ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynEdit(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "ok", DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,;
92, 44, 40, 14, ;
"&Ok")
aDlg = AppendDialog(aDlg, "cancel", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
93, 72, 40, 14, ;
"&Cancel", ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynCancel(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "push", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
91, 12, 40, 14, ;
"&Push", ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynPush(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "group", DLG_BUTTON, ;
BS_GROUPBOX + WS_GROUP + WS_CHILD + WS_VISIBLE, ;
6, 36, 54, 54, ;
"Group")
aDlg = AppendDialog(aDlg, "radioa", DLG_BUTTON, ;
BS_AUTORADIOBUTTON ;
+ WS_CHILD + WS_VISIBLE, ;
11, 50, 39, 10, ;
"&A")
aDlg = AppendDialog(aDlg, "radiob", DLG_BUTTON, ;
BS_AUTORADIOBUTTON + WS_CHILD + WS_VISIBLE, ;
12, 70, 39, 10, ;
"&B")
if ModalDialog(aDlg, , hWnd) = 0 .or. GetDialogResult(aDlg, "cancel") = .T.
cText = "<cancelled>"
else
cText = GetDialogResult(aDlg, "edit")
endif
MessageBox( , asString(cText), "Edit Control result")
return nil
// This demonstrates using numeric id's _and_ a code block with ModalDialog().
// NOTE: You must do _both_ at the same time.
// ALSO: You can't use code blocks with individual controls as well.
function DynModalGet()
local i, aDlg
local nVar // used by DIALOG GET in DynDlgModal()
aDlg = CreateDialog("DynModalGet", ;
DS_MODALFRAME + WS_POPUP + WS_VISIBLE + WS_CAPTION ;
+ WS_SYSMENU, ;
6, 18, 160, 100, ;
nPointSize, cFontName)
aDlg = AppendDialog(aDlg, IDD_EDIT, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
9, 15, 32, 12, ;
cText)
aDlg = AppendDialog(aDlg, IDOK, DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,;
92, 44, 40, 14, ;
"&Ok")
aDlg = AppendDialog(aDlg, IDCANCEL, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
93, 72, 40, 14, ;
"&Cancel")
aDlg = AppendDialog(aDlg, IDD_PUSH, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
91, 12, 40, 14, ;
"&Push")
aDlg = AppendDialog(aDlg, IDD_GROUP, DLG_BUTTON, ;
BS_GROUPBOX + WS_GROUP + WS_CHILD + WS_VISIBLE, ;
6, 36, 54, 54, ;
"Group")
aDlg = AppendDialog(aDlg, IDD_A, DLG_BUTTON, ;
BS_AUTORADIOBUTTON ;
+ WS_CHILD + WS_VISIBLE, ;
11, 50, 39, 10, ;
"&A")
aDlg = AppendDialog(aDlg, IDD_B, DLG_BUTTON, ;
BS_AUTORADIOBUTTON + WS_CHILD + WS_VISIBLE, ;
12, 70, 39, 10, ;
"&B")
i = ModalDialog(aDlg, , hWnd, ;
{|hDlg, msg, wparam, lparam| ;
DynDlgModal(hDlg, msg, wparam, lparam, @nVar)})
if i == 0 // .or. GetDialogResult(aDlg, IDCANCEL) = .T.
cText = "<cancelled>"
else
// NOT this (will be NIL): cText = GetDialogResult(aDlg, IDD_EDIT)
MessageBox( , asString(nVar), "Dialog GET result (nVar)")
endif
MessageBox( , asString(cText), "Edit Control result")
return nil
// This demonstrates using numeric id's _and_ a code block with ModalDialog().
// NOTE: You must do _both_ at the same time.
// ALSO: You can't use code blocks with individual controls as well.
//
// This is the dynamic version of UserModal() below.
function DynUserModal()
local i, aDlg
// This demonstrates stepping through a DBF file. It doesn't
// return anything much, but if you wanted just to have a
// dialog for a single set of values (and return any alterations),
// pass them by reference (i.e. @cVar) in the code block below,
// (_after_ lparam makes most sense).
aDlg = CreateDialog("User Details (Dynamic)", ;
DS_MODALFRAME + WS_POPUP + WS_VISIBLE + WS_CAPTION ;
+ WS_SYSMENU, ;
20, 20, 183, 127, ;
nPointSize, cFontName)
aDlg = AppendDialog(aDlg, IDOK, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
132, 13, 37, 12, ;
"&Ok")
aDlg = AppendDialog(aDlg, IDCANCEL, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
132, 37, 37, 12, ;
"&Cancel")
aDlg = AppendDialog(aDlg, IDD_NEXT, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
132, 61, 37, 12, ;
"&Next")
aDlg = AppendDialog(aDlg, IDD_PREV, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
132, 85, 37, 12, ;
"&Previous")
aDlg = AppendDialog(aDlg, IDD_SAVE, DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
132, 109, 37, 12, ;
"&Save")
aDlg = AppendDialog(aDlg, IDD_TUSERID, DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
7, 2, 50, 8, ;
"User ID:")
aDlg = AppendDialog(aDlg, IDD_USERID, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
7, 13, 115, 13)
aDlg = AppendDialog(aDlg, IDD_TUSERNAME, DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
7, 28, 50, 8, ;
"User Name:")
aDlg = AppendDialog(aDlg, IDD_USERNAME, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
7, 37, 115, 13)
aDlg = AppendDialog(aDlg, IDD_TDEPT, DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
7, 52, 50, 8, ;
"Department:")
aDlg = AppendDialog(aDlg, IDD_DEPT, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
7, 61, 115, 13)
aDlg = AppendDialog(aDlg, IDD_TPHONE, DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
7, 76, 50, 8, ;
"Phone:")
aDlg = AppendDialog(aDlg, IDD_PHONE, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
7, 85, 115, 13)
aDlg = AppendDialog(aDlg, IDD_T_EXT, DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
7, 100, 50, 8, ;
"Extension:")
aDlg = AppendDialog(aDlg, IDD_EXT, DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
7, 109, 115, 13)
i = ModalDialog(aDlg, , hWnd, ;
{|hDlg, msg, wparam, lparam| ;
UserDlgModal(hDlg, msg, wparam, lparam)})
if i == 0 // .or. GetDialogResult(aDlg, IDCANCEL) = .T.
MessageBox( , "Results ignored", "Cancel")
endif
return nil
function ResModal()
local nVar // used by DIALOG GET in ResDlgModal()
local i
#ifdef SEE_MESSAGES
aDlg = {}
aDlog := {}
aEdit := {}
#endif // SEE_MESSAGES
// This demonstrates getting values for a file-wide static (cText),
// and a local (nVar). Both could be file-wide statics, or locals,
// or even statics within this function. If file-wide statics are not
// used, be sure to pass the variables in the parameter list of
// ResDlgModal(), otherwise it won't be able to access them.
//
// In this example, cText is the result of an edit control, and
// nVar is a DIALOG GET.
//
// A more general technique would be to pass an array of values,
// together with valid code blocks, initial values, etc. That would
// just obscure this code, though.
// Note: the dialog id ("dlg" in this example) can be numeric if you prefer.
i = DialogBox( , "dlg", , ;
{|hDlg, msg, wparam, lparam| ;
ResDlgModal(hDlg, msg, wparam, lparam, @nVar)})
if i == IDCANCEL
MessageBox( , "Results ignored", "Cancel")
else
MessageBox( , asString(cText), "Edit Control result")
MessageBox( , asString(nVar), "Dialog GET result (nVar)")
endif
#ifdef SEE_MESSAGES
DumpDlog()
DumpEdit()
#endif // SEE_MESSAGES
return nil
function ResModify()
local nVar // used by DIALOG GET in ResDlgModal()
local i
#ifdef SEE_MESSAGES
aDlg = {}
aDlog := {}
aEdit := {}
#endif // SEE_MESSAGES
// Note: the dialog id ("dlg" in this example) can be numeric if you prefer.
i = DialogBox( , "dlg", , ;
{|hDlg, msg, wparam, lparam| ;
ResDlgModify(hDlg, msg, wparam, lparam, @nVar)})
if i == IDCANCEL
MessageBox( , "Results ignored", "Cancel")
else
MessageBox( , asString(cText), "Edit Control result")
MessageBox( , asString(nVar), "Dialog GET result (nVar)")
endif
#ifdef SEE_MESSAGES
DumpDlog()
DumpEdit()
#endif // SEE_MESSAGES
return nil
function UserModal()
local i
// This demonstrates stepping through a DBF file. It doesn't
// return anything much, but if you wanted just to have a
// dialog for a single set of values (and return any alterations),
// pass them by reference (i.e. @cVar) in the code block below,
// (_after_ lparam makes most sense).
i = DialogBox( , "dlguser", , ;
{|hDlg, msg, wparam, lparam| ;
UserDlgModal(hDlg, msg, wparam, lparam)})
if i == IDCANCEL
MessageBox( , "Results ignored", "Cancel")
endif
return nil
function DynModeless()
local i, aDlg, cText := "Some text"
aDlg = CreateDialog("DynModeless", ;
DS_MODALFRAME + WS_POPUP + WS_VISIBLE + WS_CAPTION ;
+ WS_SYSMENU, ;
6, 18, 160, 100, ;
nPointSize, cFontName)
aDlg = AppendDialog(aDlg, "edit", DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
9, 15, 32, 12, ;
cText, ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynEdit(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "ok", DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,;
92, 44, 40, 14, ;
"&Ok")
aDlg = AppendDialog(aDlg, "cancel", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
93, 72, 40, 14, ;
"&Cancel", ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynCancel(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "push", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
91, 12, 40, 14, ;
"&Push", ;
{|hDlg, nMsg, nwParam, nlParam| ;
DynPush(hDlg, nMsg, nwParam, nlParam)})
aDlg = AppendDialog(aDlg, "group", DLG_BUTTON, ;
BS_GROUPBOX + WS_GROUP + WS_CHILD + WS_VISIBLE, ;
6, 36, 54, 54, ;
"Group")
aDlg = AppendDialog(aDlg, "radioa", DLG_BUTTON, ;
BS_AUTORADIOBUTTON ;
+ WS_CHILD + WS_VISIBLE, ;
11, 50, 39, 10, ;
"&A")
aDlg = AppendDialog(aDlg, "radiob", DLG_BUTTON, ;
BS_AUTORADIOBUTTON + WS_CHILD + WS_VISIBLE, ;
12, 70, 39, 10, ;
"&B")
#ifdef NOTDEF // Don't define this !! (There is no ModelessDialog() yet.)
i = ModelessDialog(aDlg, , hWnd)
#ifdef SEE_MESSAGES
hDlg = i
#endif // SEE_MESSAGES
#else
MessageBox( , "Sorry, not yet implemented", "Notice")
#endif // NOTDEF
return nil
function ResModeless()
local i
#ifdef SEE_MESSAGES
aDlg = {}
#endif // SEE_MESSAGES
i = CreateDialog( , "dlg", , ;
{|hDlg, msg, wparam, lparam| ;
ResDlgModeless(hDlg, msg, wparam, lparam)})
#ifdef SEE_MESSAGES
MessageBox( , asString(i), "CreateDialog( ) result")
MessageBox( , "cText = " + asString(cText), "DialogBox")
hDlg = i
#endif // SEE_MESSAGES
return nil
function DynDialog()
return nil
function DynEdit(hDlg, nMsg, nwParam, nlParam)
local nEN
if (nEN := _LastHilParam()) == EN_ERRSPACE .or. nEN == EN_MAXTEXT
MessageBox(hDlg, "Edit control full", "Info")
endif
return 0 // means msg not processed (and want default action)
function DynCancel(hDlg, nMsg, nwParam, nlParam)
if MessageBox(hDlg, "Really Cancel?", "Cancel", MB_YESNO) == IDYES
EndDialog(hDlg, 0)
endif
return .t.
function DynPush(hDlg, nMsg, nwParam, nlParam)
local aDlg, cText := "DynPush"
aDlg = CreateDialog("DynPush", ;
WS_CAPTION + WS_SYSMENU + WS_GROUP + WS_TABSTOP ;
+ WS_THICKFRAME + WS_VISIBLE + WS_POPUP, ;
200, 18, 160, 100, ;
12, "MS Sans Serif")
aDlg = AppendDialog(aDlg, "check", DLG_BUTTON, ;
BS_AUTOCHECKBOX + WS_TABSTOP + WS_CHILD + WS_VISIBLE,;
5, 87, 40, 10, ;
"Check")
aDlg = AppendDialog(aDlg, "", DLG_STATIC, ;
SS_LEFT + WS_CHILD + WS_VISIBLE, ;
71, 68, 55, 16, ;
"Text")
aDlg = AppendDialog(aDlg, "edit2", DLG_EDIT, ;
ES_AUTOHSCROLL + WS_BORDER ;
+ WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
4, 26, 32, 12, ;
cText)
aDlg = AppendDialog(aDlg, "ok", DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE,;
59, 22, 40, 14, ;
"&Ok")
if ModalDialog(aDlg, , hDlg) = 0 .or. GetDialogResult(aDlg, "cancel") = .T.
cText = "<cancelled>"
else
cText = GetDialogResult(aDlg, "edit2")
endif
MessageBox( , asString(cText), "Edit Control result")
return .t.
static function ValidChk(nVar, hWndDlg)
if nVar > 0
return .t.
endif
MessageBox(GetFocus(), "Must be > 0", "ValidChk failed")
SetFocus(GetDlgItem(hWndDlg, IDD_EDIT))
return .f.
function DynDlgModal(hWndDlg, nMsg, nwParam, nlParam, nVarRet)
// this example uses the same function as Modal/Resource
// just to show that dynamic dialogs can be treated almost
// like resource dialogs if you wish
return ResDlgModal(hWndDlg, nMsg, nwParam, nlParam, @nVarRet)
function ResDlgModal(hWndDlg, nMsg, nwParam, nlParam, nVarRet)
static nCtrl := IDD_A
static GetList, nVar, cBmp
local i, hWnd, hDC, nX, nY
#ifdef SEE_MESSAGES
aadd(aDlg, {hWndDlg, nMsg, nwParam, nlParam})
aadd(aDlog, {hWndDlg, nMsg, nwParam, nlParam})
#endif // SEE_MESSAGES
do case
case nMsg == WM_INITDIALOG
CheckDlgButton(hWndDlg, nCtrl, 1)
// SendDlgItemMessage(hWndDlg, IDD_EDIT, WM_SETTEXT, 0, "Initial Text")
cBmp = ReadDIB("c4wtiny.bmp")
/////////////
//
// The code below does validation using a GET object.
// There's some sample code later on showing how you might
// use the edit controls themselves to do your own
// validation. You can use a combination of the two, of course.
//
/////////////
GetList := {}
nVar = 0
@ dialog hWndDlg id IDD_EDIT get nVar when nVar < 15 ;
font GetStockObject(ANSI_VAR_FONT) valid ValidChk(nVar, hWndDlg)
return 1 // want system to set the focus
case nMsg == WM_SYSCOMMAND
if nwParam == SC_CLOSE // system menu double click, or Alt-F4
CANCEL DIALOG hWndDlg
endif
// You don't have to handle this message, but here's how you can
case nMsg == WM_PAINT
// this shows one way of dynamically doing output (in this case a bitmap)
hWnd = GetDlgItem(hWndDlg, IDD_GROUP)
i = GetClientRect(hWnd)
nX = i[3] / 2 // half-way across
nY = i[4] / 3 // a third of the way down
hDC = GetDC(hWnd)
// ShowDIB(hDC, cBmp, nX, nY)
StretchDIBits(hDC, ;
nX, nY, nX / 2, nY, ; // quarter width, third height
, , , , ;
, cBmp)
ReleaseDC(hWnd, hDC)
case nMsg == WM_COMMAND
do case
case nwParam == IDD_OK ;
.or. nwParam == IDOK
if IsDialogOK(hWndDlg, nwParam)
cText = GetDlgItmText(hWndDlg, IDD_EDIT)
// could do:
// nVarRet := val(cText)
nVarRet := nVar
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
endif
return 1 // means msg has been processed
case nwParam == IDCANCEL
// don't change cText
CANCEL DIALOG hWndDlg // cancel any GETs
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
return 1 // means msg has been processed
case nwParam == IDABORT ;
.or. nwParam == IDRETRY ;
.or. nwParam == IDIGNORE ;
.or. nwParam == IDYES ;
.or. nwParam == IDNO
// not used in this example
case nwParam == IDD_EDIT
#ifdef SEE_MESSAGES
aadd(aEdit, {hWndDlg, nMsg, nwParam, nlParam})
#endif // SEE_MESSAGES
if (i := _LastHilParam()) == EN_ERRSPACE .or. i == EN_MAXTEXT
MessageBox(hWndDlg, "Edit control full", "Info")
endif
case nwParam == IDD_PUSH
// start a sub-dialog
i = DialogBox( , "dlg2", hWndDlg, ;
{|hDlg, msg, wparam, lparam| ;
ResDlg2(hDlg, msg, wparam, lparam)})
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(i), "ResDialog (from Push)")
#endif // SEE_MESSAGES
MessageBox(hWndDlg , asString(cText), "Edit Control result")
case nwParam == IDD_GROUP
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_GROUP)")
#endif // SEE_MESSAGES
case nwParam == IDD_A
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_A)")
#endif // SEE_MESSAGES
nCtrl = IDD_A
case nwParam == IDD_B
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_B)")
#endif // SEE_MESSAGES
nCtrl = IDD_B
case nwParam == IDD_CHECK
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_CHECK)")
case nwParam == IDD_TEXT
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_TEXT)")
case nwParam == IDD_EDIT2
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_EDIT2)")
endcase
endcase
return 0 // means msg not processed (and want default action)
//
// Perform major surgery on the dialog, to show the kinds of things
// that can be done (e.g. for data-driven dialogs).
//
function ResDlgModify(hWndDlg, nMsg, nwParam, nlParam, nVarRet)
local w, h, pt
do case
case nMsg == WM_INITDIALOG
w = GetDialogBaseUnits()
h = C4W_Int(C4W_HiWord(w) / 8)
w = C4W_Int(C4W_LoWord(w) / 4)
ClientToScreen(hWndDlg, pt := {40,40})
MoveWindow(hWndDlg, pt[1], pt[2], 145*w, 115*h, .f.)
ShowWindow(GetDlgItem(hWndDlg, IDD_A), SW_HIDE)
ShowWindow(GetDlgItem(hWndDlg, IDD_B), SW_HIDE)
ShowWindow(GetDlgItem(hWndDlg, IDD_GROUP), SW_HIDE)
SetWindowText(GetDlgItem(hWndDlg, IDD_PUSH), "&Sub-dialog")
MoveWindow(GetDlgItem(hWndDlg, IDD_PUSH), 10*w, 70*h, 40*w, 15*h, .f.)
MoveWindow(GetDlgItem(hWndDlg, IDOK), 90*w, 15*h, 40*w, 15*h, .f.)
MoveWindow(GetDlgItem(hWndDlg, IDCANCEL), 90*w, 70*h, 40*w, 15*h, .f.)
endcase
// now pass the msg along
return ResDlgModal(hWndDlg, nMsg, nwParam, nlParam, @nVarRet)
function UserDlgModal(hWndDlg, nMsg, nwParam, nlParam)
static GetList
static cUserID, cUserName, cDept, cPhone, cExt
static oUserID, oUserName, oDept, oPhone, oExt
// these are tiny functions/procedures:
static bScatter := {|| cUserID := users->UserID, ;
cUserName := users->UserName, ;
cDept := users->Department, ;
cPhone := users->Phone, ;
cExt := users->Extension }
static bGather := {|| users->UserID := cUserID, ;
users->UserName := cUserName, ;
users->Department := cDept, ;
users->Phone := cPhone, ;
users->Extension := cExt }
static bUpdate := {|| oUserID :killFocus() ;
:varPut( users->UserID ), ;
oUserName :killFocus() ;
:varPut( users->UserName ), ;
oDept :killFocus() ;
:varPut( users->Department ), ;
oPhone :killFocus() ;
:varPut( users->Phone ), ;
oExt :killFocus() ;
:varPut( users->Extension ) }
static hBrush // only used for example of WM_CTLCOLOR
#define C_WHITE RGB(255,255,255)
do case
case nMsg == WM_INITDIALOG
use users new shared
users->( dbGoTop() )
eval(bScatter) // fetch fields to static vars
/////////////
//
// The code below does validation using GET objects.
//
// The objects need to be saved because we want to change
// them as we move from record to record.
//
/////////////
GetList = {}
@ dialog hWndDlg id IDD_USERID get cUserID
oUserID = ATail(GetList)
@ dialog hWndDlg id IDD_USERNAME get cUserName
oUserName = ATail(GetList)
@ dialog hWndDlg id IDD_DEPT get cDept
oDept = ATail(GetList)
@ dialog hWndDlg id IDD_PHONE get cPhone
oPhone = ATail(GetList)
@ dialog hWndDlg id IDD_EXT get cExt
oExt = ATail(GetList)
hBrush = CreateSolidBrush(C_WHITE) // only used for example WM_CTLCOLOR
return 1 // want system to set the focus
case nMsg == WM_SYSCOMMAND
if nwParam == SC_CLOSE // system menu double click, or Alt-F4
#ifdef ThisIsTheDefault
// By default, Windows sends a WM_COMMAND with IDCANCEL,
// which does the same as this code:
// cancel the GETs
CANCEL DIALOG hWndDlg
close users
EndDialog(hWndDlg, IDCANCEL) // *not* DestroyWindow()
return 1 // means msg has been processed
#endif // ThisIsTheDefault
endif
case nMsg == WM_COMMAND
do case
case nwParam == IDOK
// don't change record
// (it's only done if SAVE button pressed, i.e. IDD_SAVE)
CANCEL DIALOG hWndDlg // cancel any GETs
close users
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
DeleteObject(hBrush)
return 1 // means msg has been processed
case nwParam == IDCANCEL
// don't change record
CANCEL DIALOG hWndDlg // cancel any GETs
close users
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
DeleteObject(hBrush)
return 1 // means msg has been processed
case nwParam == IDD_NEXT
// Don't define NOT_DEFINED !!! (It's just used for commenting)
#ifdef NOT_DEFINED // this is to avoid using /* ... */ over many lines
// which causes problems if you have another
// /* ... */ comment within the code
/*
* This code is commented out because it's NOT the
* way to do it!! You're not closing the dialog.
* You're just moving to a new record. If you use
* this code you get very confused edit controls.
*/
// need to cancel current GETs, skip, and re-issue them
CANCEL DIALOG hWndDlg // cancel any GETs
users->( dbSkip(1) )
if users->( Eof() )
users->( dbGoBottom() )
endif
eval(bScatter) // fetch fields to static vars
GetList = {}
@ dialog hWndDlg id IDD_USERID get cUserID
@ dialog hWndDlg id IDD_USERNAME get cUserName
@ dialog hWndDlg id IDD_DEPT get cDept
@ dialog hWndDlg id IDD_PHONE get cPhone
@ dialog hWndDlg id IDD_EXT get cExt
#else
/*
* Here's how to make moving to a different record work.
*/
// need to skip, then update GETs
users->( dbSkip(1) )
if users->( Eof() )
users->( dbGoBottom() )
endif
eval(bUpdate) // update the GETs and vars
#ifdef YouCanDoItThisWay
// this way is a little slower, but uses the PICTURE
// (if any) -- see GETSYS.PRG for the function
// DReadSetInfo().
DReadSetInfo(hWndDlg, IDD_USERID, GetList, 1)
DReadSetInfo(hWndDlg, IDD_USERNAME, GetList, 2)
DReadSetInfo(hWndDlg, IDD_DEPT, GetList, 3)
DReadSetInfo(hWndDlg, IDD_PHONE, GetList, 4)
DReadSetInfo(hWndDlg, IDD_EXT, GetList, 5)
#else // OrThisWay
// This is good enough for char vars with no picture.
//
// For the general-case, use:
// SetDlgItem(hWndDlg, IDD_xxx, ;
// transform(oXXX:varGet(), oXXX:picture))
// which currently works even if the picture is nil.
// CA may "fix" that, of course, in which case you
// need cautious code as in DReadSetInfo().
SetDlgItem(hWndDlg, IDD_USERID, oUserID :varGet())
SetDlgItem(hWndDlg, IDD_USERNAME, oUserName:varGet())
SetDlgItem(hWndDlg, IDD_DEPT, oDept :varGet())
SetDlgItem(hWndDlg, IDD_PHONE, oPhone :varGet())
SetDlgItem(hWndDlg, IDD_EXT, oExt :varGet())
#endif
#endif // NOT_DEFINED
return 1 // means msg has been processed
case nwParam == IDD_PREV
// need to skip, then update GETs
users->( dbSkip(-1) )
if users->( Bof() )
users->( dbGoTop() )
endif
eval(bUpdate) // update the GETs and vars
SetDlgItem(hWndDlg, IDD_USERID, oUserID :varGet())
SetDlgItem(hWndDlg, IDD_USERNAME, oUserName:varGet())
SetDlgItem(hWndDlg, IDD_DEPT, oDept :varGet())
SetDlgItem(hWndDlg, IDD_PHONE, oPhone :varGet())
SetDlgItem(hWndDlg, IDD_EXT, oExt :varGet())
return 1 // means msg has been processed
case nwParam == IDD_SAVE
if IsDialogOK(hWndDlg, nwParam)
users->( RLock() )
eval(bGather) // update the fields from the vars
users->( dbUnlock() )
endif
return 1 // means msg has been processed
endcase
// You don't have to handle this message, but here's how you do it
//
// You have to create a brush to be used for the control's background
// during (or before) WM_INITDIALOG, return it here, and remember to
// free the brush using DeleteObject() after calling EndDialog().
//
// NOTE: Turn off the 3-D effects if you want this to do anything!
case nMsg == WM_CTLCOLOR
if C4W_HiWord(nlParam) == CTLCOLOR_STATIC .and. hLibCtl3d == nil
// hDC is given to us in nwParam
SetTextColor(nwParam, RGB(255,0,0))
SetBkColor(nwParam, C_WHITE)
return hBrush
endif
endcase
return 0 // means msg not processed (and want default action)
// Don't define NOT_DEFINED !!! (It's just used for commenting)
#ifdef NOT_DEFINED // this is to avoid using /* ... */ over many lines
// which causes problems if you have another
// /* ... */ comment within the code
/////////////
//
// The code below does validation using the edit controls
// themselves to do your own validation. You can use this as
// well as GETs in a dialog, of course.
//
// NOTE: There are two approaches to this. Both check all the fields
// on exit from the dialog box. Prior to that, the first one below does
// validation on each field as it is entered _and_ all lower-numbered
// fields. (So that in effect it forces you to enter them in sequence.)
// The second approach lets you enter the data in any order, validating
// each field as it is finished, and then validates all the values at
// the end.
//
// With thanks for the help of Hugh and Jerry.
//
/////////////
// Approach 1...
/////////////
STATIC FUNCTION RatePage1(lEdit)
LOCAL hOldWnd := GetFocus()
LOCAL nResults
LOCAL aValids := {{101,{|hDlg|ChkRateCode(hDlg)}},;
{102,{|hDlg|ChkRateDisc(hDlg)}},;
{112,{|hDlg|ChkRateMaxD(hDlg)}},;
{113,{|hDlg|ChkRateDHrs(hDlg)}},;
{114,{|hDlg|ChkRatePHrs(hDlg)}}}
nResults :=DialogBox(_GetInstance() , "rate1", , ;
{|hDlg, msg, wparam, lparam| ;
MRatePg1(hDlg, msg, wparam, lparam,aValids)})
SetFocus(hOldWnd)
RETURN(nResults)
STATIC FUNCTION MRatePg1(hDlgWnd, nMsg, nwParam, nlParam,aValids)
STATIC lForceFocus // Flag to indicate focus has been forced backward
STATIC nHasFocus // Counter to show which control/field has focus
STATIC lValid // Flag to indicate if a valid check failed/passed
LOCAL nCtr // Counter to go through array of valids
DO CASE
CASE nMsg == WM_INITDIALOG
// Set all our defaults/initial values
// this function is in center.zip, but is not required
CenterWindow(hDlgWnd) // Thanks Gerald this one is great!
SetDlgItemText(hDlgWnd, 101, S_RATE_CODE)
SetDlgItemText(hDlgWnd, 102, S_DESCRIPT )
SendDlgItemMessage(hDlgWnd, 103, BM_SETCHECK,IIF(S_BILL_PER=='W',1,0))
SendDlgItemMessage(hDlgWnd, 104, BM_SETCHECK,IIF(S_BILL_PER=='M',1,0))
SendDlgItemMessage(hDlgWnd, 105, BM_SETCHECK,IIF(S_BILL_PER=='B',1,0))
SendDlgItemMessage(hDlgWnd, 106, BM_SETCHECK,IIF(S_BREAKFAST=='Y',1,0))
SendDlgItemMessage(hDlgWnd, 107, BM_SETCHECK,IIF(S_LUNCH =='Y',1,0))
SendDlgItemMessage(hDlgWnd, 108, BM_SETCHECK,IIF(S_DINNER =='Y',1,0))
SendDlgItemMessage(hDlgWnd, 109, BM_SETCHECK,IIF(S_SNACK =='Y',1,0))
SetDlgItemText(hDlgWnd, 112, LTRIM(STR(S_MAXDAYS)))
SetDlgItemText(hDlgWnd, 113, LTRIM(STR(S_DREGHRS)))
SetDlgItemText(hDlgWnd, 114, LTRIM(STR(S_PREGHRS)))
// Set initial state of our flags
lForceFocus := .F.
nHasFocus := 101
lValid := .T.
RETURN(1)
CASE nMsg == WM_COMMAND
DO CASE
CASE nwParam == IDCANCEL // Real clean no need for special
EndDialog(hDlgWnd,nwParam) // checks or other junk
RETURN(1)
CASE lForceFocus == .T. // Filters out gain/kill focus
IF nwParam == nHasFocus // messages caused by a validation
lForceFocus := .F. // failure - we just ignore everything
ENDIF // until the new control id is received
RETURN(1)
// The "heart" of the validation routine
CASE (nwParam != nHasFocus) .AND.;
(C4W_HiWord(nlParam) == EN_SETFOCUS .OR.;
C4W_HiWord(nlParam) == 0) // Buttons return 0
// If the control id is not equal to the current value
// of the focus counter and we got a setfocus message
// or a button was pressed then we have to check the
// fields that have valids
FOR nCtr := 1 TO LEN(aValids)
IF aValids[nCtr][1] < nwParam .OR.;
nwParam == 1 // Ok button look at all valids
// Set your flags to indicate a failure ahead of time
// cause if one occurs you will not get control back
// until all the junk has been processed!
lForceFocus := .T.
lValid := .F.
IF EVAL(aValids[nCtr][2],hDlgWnd) == .F.
nHasFocus := aValids[nCtr][1]
SetFocus(GetDlgItem(hDlgWnd,nHasFocus))
EXIT
ELSE
nHasFocus := aValids[nCtr][1]
lForceFocus := .F.
lValid := .T.
ENDIF
ELSE
EXIT
ENDIF
NEXT
// If we get here without interruption then everything was
// valid now we check to see if the Ok button was pressed
IF lValid == .T.
IF nwParam == IDOK
Page1Vals(hDlgWnd)
EndDialog(hDlgWnd,1)
ENDIF
// This routine has two "pages" of data to be input so
// we have a next page button to contend with
IF nwParam == 16 // Next Page
Page1Vals(hDlgWnd)
EndDialog(hDlgWnd,3)
ENDIF
ENDIF
RETURN(1)
ENDCASE
ENDCASE
RETURN(0)
// This gets the values of the controls and assigns them to some
// statics used in place of the database fields. Since it is
// called from two different places it makes sense to make it
// a stand-alone funciton - also gets all that code out of
// the case statement. Could do the same thing with the setup
// part to make the basic function shorter and neater.
STATIC FUNCTION Page1Vals(hDlgWnd)
S_RATE_CODE := GetDlgItmText(hDlgWnd,101)
S_DESCRIPT := GetDlgItmText(hDlgWnd,102)
S_BILL_PER := IIF(IsDlgButtonChecked(hDlgWnd,103)==1,'W',;
IIF(IsDlgButtonChecked(hDlgWnd,104)==1,'M','B'))
S_BREAKFAST := IIF(IsDlgButtonChecked(hDlgWnd,106)==1,'Y','N')
S_LUNCH := IIF(IsDlgButtonChecked(hDlgWnd,107)==1,'Y','N')
S_DINNER := IIF(IsDlgButtonChecked(hDlgWnd,108)==1,'Y','N')
S_SNACK := IIF(IsDlgButtonChecked(hDlgWnd,109)==1,'Y','N')
S_MAXDAYS := VAL(GetDlgItmText(hDlgWnd,112))
S_DREGHRS := VAL(GetDlgItmText(hDlgWnd,113))
S_PREGHRS := VAL(GetDlgItmText(hDlgWnd,114))
RETURN(NIL)
// Following are the validation functions
STATIC FUNCTION ChkRateCode(hDlgWnd)
S_RATE_CODE := GetDlgItmText(hDlgWnd,101)
IF EMPTY(S_RATE_CODE)
SelectWindow(hDlgWnd)
ErrorMsg("RATE CODE CANNOT BE BLANK!","PROBLEM")
RETURN(.F.)
ENDIF
RETURN(.T.)
STATIC FUNCTION ChkRateDisc(hDlgWnd)
S_DESCRIPT := GetDlgItmText(hDlgWnd,102)
IF EMPTY(S_DESCRIPT)
SelectWindow(hDlgWnd)
ErrorMsg("DESCRIPTION CANNOT BE BLANK!",'E')
RETURN(.F.)
ENDIF
RETURN(.T.)
STATIC FUNCTION ChkRateMaxD(hDlgWnd)
S_MAXDAYS := GetDlgItmText(hDlgWnd,112)
IF EMPTY(S_MAXDAYS) .OR.;
ISDIGIT(S_MAXDAYS) == .F.
SelectWindow(hDlgWnd)
ErrorMsg("MAXDAYS CANNOT BE BLANK/INVALID DATA ENTERED!","E")
RETURN(.F.)
ENDIF
RETURN(.T.)
STATIC FUNCTION ChkRateDHrs(hDlgWnd)
S_DREGHRS := GetDlgItmText(hDlgWnd,113)
IF VAL(S_DREGHRS) < 0 .OR.;
EMPTY(S_DREGHRS)
SelectWindow(hDlgWnd)
ErrorMsg("DAILY HOURS CANNOT BE BLANK!",'E')
RETURN(.F.)
ENDIF
RETURN(.T.)
STATIC FUNCTION ChkRatePHrs(hDlgWnd)
S_PREGHRS := GetDlgItmText(hDlgWnd,114)
IF EMPTY(S_PREGHRS) .OR.;
ISDIGIT(S_PREGHRS) == .F.
SelectWindow(hDlgWnd)
ErrorMsg("PERIOD HOURS CANNOT BE BLANK!",'E')
RETURN(.F.)
ENDIF
RETURN(.T.)
/////////////
// Approach 2...
/////////////
// Program..: Enternam.prg
// Author...: Gerald Barber
// Date.....: Sun 1-31-1993; Last Updated June 19, 1993 04:25 pm
// Notice...: Copyright 1993, Gerald Barber
// Notes....: Name Entry Dialog Box for Rebreath Program
#define WIN_WANT_ALL
#define WIN_WANT_EN
#include "windows.ch"
#include "\clipper5\userinc\clip.ch"
#include "resource.h"
#include "rebreath.h"
static aData_[2]
function entername(hWnd)
local aResult_[2]
local aValids_ := {{IDC_LNAME, {|hDlg|ChkName(hDlg, IDC_LNAME)}}, ;
{IDC_FNAME, {|hDlg|ChkName(hDlg, IDC_FNAME)}}}
afill(aData_, "")
afill(aResult_, "")
if DialogBox(_GetInstance(), "DEMO", hWnd, { |hDlg, msg, wparam, lparam| ;
DemoDialog(hDlg, msg, wparam, lparam, aValids_) } ) <> IDCANCEL
aResult_ := aData_
endif
return (aResult_)
static function DemoDialog(hWndDlg, nMsg, nwParam, nlParam, aValids_)
static lForceFocus // Flag to indicate focus has been forced backward
static nHasFocus // Counter to show which control/field has focus
static lValid // Flag to indicate if a valid check failed/passed
local nCtr // Counter to go through array of valids
DO CASE
CASE nMsg == WM_INITDIALOG
center(hWndDlg)
// Set all our defaults/initial values
nHasFocus := SayData(hWndDlg)
// Set initial state of our flags
lForceFocus := .F.
lValid := .T.
RETURN(1)
CASE nMsg == WM_COMMAND
DO CASE
CASE nwParam == IDCANCEL .OR. ; // Real clean no need for special
nwParam == IDABORT .OR. ; // checks or other junk
nwParam == IDRETRY .OR. ;
nwParam == IDIGNORE .OR. ;
nwParam == IDNO
EndDialog(hWndDlg, IDCANCEL)
return(1)
CASE lForceFocus == .T. // Filters out gain/kill focus
if nwParam == nHasFocus // messages caused by a validation
lForceFocus := .F. // failure - we just ignore everything
endif // until the new control id is received
return(1)
// The "heart" of the validation routine
CASE (nwParam != nHasFocus) .AND. ;
(C4W_HiWord(nlParam) == EN_SETFOCUS .OR.;
C4W_HiWord(nlParam) == 0) // Buttons return 0
// If the control id is not equal to the current value
// of the focus counter and we got a setfocus message
// or a button was pressed then we have to check the
// fields that have valids
for nCtr := 1 to len(aValids_)
// 06/11/93 GB - Modified so that
// On IDOK - all fields get validity check
// Else - only modified field gets validity check
// This solves problem that occurs when the order
// of fields selected does not correspond with the order
// in aValids_
// Was
// if aValids_[nCtr][1] < nwParam .OR. ;
// nwParam == 1 // Ok button look at all valids
// Now
if aValids_[nCtr][1] == nHasFocus .OR. ;
nwParam == 1 // Ok button look at all valids
// Set your flags to indicate a failure ahead of time
// cause if one occurs you will not get control back
// until all the junk has been processed!
lForceFocus := .T.
lValid := .F.
if eval(aValids_[nCtr][2],hWndDlg) == .F.
nHasFocus := aValids_[nCtr][1]
SetFocus(GetDlgItem(hWndDlg,nHasFocus))
exit
else
nHasFocus := aValids_[nCtr][1]
lForceFocus := .F.
lValid := .T.
endif
// 06/11/93 GB - Deleted so that
// On IDOK - all fields get validity check
// Else - only modified field gets validity check
// This solves problem that occurs when the order
// of fields selected does not correspond with the order
// in aValids_
// Was
// else
// exit
// Now
// No Exit - continue processing until all
// entries in aValid_ checked for possible
// match with nHasFocus
endif
next
// If we get here without interruption then everything was
// valid now we check to see if the Ok button was pressed
if lValid == .T. .AND. nwParam == IDOK
GetData(hWndDlg)
EndDialog(hWndDlg,IDOK)
// 06/11/93 GB - Added so that
// On IDOK - all fields get validity check
// Else - only modified field gets validity check
// This solves problem that occurs when the order
// of fields selected does not correspond with the order
// in aValids_
elseif lValid == .T.
// No errors and not exiting dialog
// Set nHasFocus to the newly selected field
nHasFocus := nwParam
endif
return(1)
ENDCASE
ENDCASE
return(0)
// Following are the data display functions
static function SayData(hWndDlg)
SetDlgItemText(hWndDlg,IDC_LNAME,aData_[IDD_LNAME])
SetDlgItemText(hWndDlg,IDC_FNAME,aData_[IDD_FNAME])
return (IDC_LNAME)
// Following are the data retrieval functions
static function GetData(hWndDlg)
aData_[IDD_LNAME] := alltrim(GetDlgItmText(hWndDlg, IDC_LNAME))
aData_[IDD_FNAME] := alltrim(GetDlgItmText(hWndDlg, IDC_FNAME))
return .T.
// Following are the validation functions
static function ChkName(hWndDlg,nID)
local cText := alltrim(GetDlgItmText(hWndDlg,nID))
if !ChkAlpha(hWndDlg,nID)
return(.F.)
endif
if Empty(cText)
SelectWindow(hWndDlg)
MessageBox(hWndDlg,"Please Try Again","Invalid Entry", ;
MB_OK + MB_ICONEXCLAMATION)
return(.F.)
endif
return(.T.)
#endif // NOT_DEFINED // and not meant to be!
function ResDlgModeless(hWndDlg, nMsg, nwParam, nlParam)
static nCtrl := IDD_A
local i
#ifdef SEE_MESSAGES
aadd(aDlg, {hWndDlg, nMsg, nwParam, nlParam})
#endif // SEE_MESSAGES
do case
case nMsg == WM_INITDIALOG
CheckDlgButton(hWndDlg, nCtrl, 1)
SendDlgItemMessage(hWndDlg, IDD_EDIT, WM_SETTEXT, 0, "Initial Text")
return 1 // want system to set the focus
case nMsg == WM_COMMAND
do case
case nwParam == IDD_OK ;
.or. nwParam == IDOK
cText = GetDlgItmText(hWndDlg, IDD_EDIT)
DestroyWindow(hWndDlg) // *not* EndDialog()
return 1 // means msg has been processed
case nwParam == IDCANCEL
// don't change cText
DestroyWindow(hWndDlg) // *not* EndDialog()
return 1 // means msg has been processed
case nwParam == IDABORT ;
.or. nwParam == IDRETRY ;
.or. nwParam == IDIGNORE ;
.or. nwParam == IDYES ;
.or. nwParam == IDNO
// not used in this example
case nwParam == IDD_EDIT
if (i := _LastHilParam()) == EN_ERRSPACE .or. i == EN_MAXTEXT
MessageBox(hWndDlg, "Edit control full", "Info")
endif
case nwParam == IDD_PUSH
// start a sub-dialog
i = DialogBox( , "dlg2", hWndDlg, ;
{|hDlg, msg, wparam, lparam| ;
ResDlg2(hDlg, msg, wparam, lparam)})
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(i), "ResDialog (from Push)")
#endif // SEE_MESSAGES
MessageBox(hWndDlg , asString(cText), "Edit Control result")
case nwParam == IDD_GROUP
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_GROUP)")
#endif // SEE_MESSAGES
case nwParam == IDD_A
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_A)")
#endif // SEE_MESSAGES
nCtrl = IDD_A
case nwParam == IDD_B
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_B)")
#endif // SEE_MESSAGES
nCtrl = IDD_B
case nwParam == IDD_CHECK
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_CHECK)")
case nwParam == IDD_TEXT
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_TEXT)")
case nwParam == IDD_EDIT2
MessageBox(hWndDlg, asString(nwParam), "WRONG FUNCTION: DialogBox (IDD_EDIT2)")
endcase
endcase
return 0 // means msg not processed (and want default action)
function ResDlg2(hWndDlg, nMsg, nwParam, nlParam)
local i
do case
case nMsg == WM_INITDIALOG
return 1 // want system to set the focus
case nMsg == WM_COMMAND
do case
case nwParam == IDD_OK ;
.or. nwParam == IDOK
cText = GetDlgItmText(hWndDlg, IDD_EDIT2)
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
return 1 // means msg has been processed
case nwParam == IDCANCEL
// don't change cText
EndDialog(hWndDlg, nwParam) // *not* DestroyWindow()
return 1 // means msg has been processed
case nwParam == IDABORT ;
.or. nwParam == IDRETRY ;
.or. nwParam == IDIGNORE ;
.or. nwParam == IDYES ;
.or. nwParam == IDNO
// not used in this example
case nwParam == IDD_CHECK
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_CHECK)")
#endif // SEE_MESSAGES
case nwParam == IDD_TEXT
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_TEXT)")
#endif // SEE_MESSAGES
case nwParam == IDD_EDIT2
#ifdef SEE_MESSAGES
MessageBox(hWndDlg, asString(nwParam), "DialogBox (IDD_EDIT2)")
#endif // SEE_MESSAGES
endcase
endcase
return 0 // means msg not processed (and want default action)
static procedure Ctl3dColorChange()
local cDLL := GetProcAddress(hLibCtl3d, "Ctl3dColorChange", "Pascal", ;
"void", "")
CallDLL(cDLL)
return
static procedure Ctl3dRegister(hInst)
local cDLL := GetProcAddress(hLibCtl3d, "Ctl3dRegister", "Pascal", ;
"void", "int")
CallDLL(cDLL, hInst)
return
static procedure Ctl3dAutoSubclass(hInst)
local cDLL := GetProcAddress(hLibCtl3d, "Ctl3dAutoSubclass", "Pascal", ;
"void", "int")
CallDLL(cDLL, hInst)
return
static procedure Ctl3dUnregister(hInst)
local cDLL := GetProcAddress(hLibCtl3d, "Ctl3dUnregister", "Pascal", ;
"void", "int")
CallDLL(cDLL, hInst)
return
//
// Dialog Procedure
//
static function Ctl3dDialog(hDlg, nMsg, nwParam, nlParam)
do case
case nMsg == WM_INITDIALOG
SendDlgItemMessage(hDlg, 101, WM_SETTEXT, 0, "Try Tabbing")
SendDlgItemMessage(hDlg, 102, WM_SETTEXT, 0, "Try Tabbing")
return 1 // want system to set the focus
case nMsg == WM_COMMAND
do case
case nwParam == IDOK
EndDialog(hDlg, nwParam)
case nwParam == 130
MessageBox(hDlg, "This is a sample Message Box", "3d Look", MB_OK)
endcase
case nMsg == WM_SYSCOLORCHANGE
// this only happens if the desktop colours are changed
// (so you can omit it if you like)
Ctl3dColorChange()
otherwise
return 0
endcase
return 1
static procedure BigDialog()
local hDLL
// first, from this app's EXE file
DialogBox( , "sample3d", , ;
{|hWndDlg, msg, wparam, lparam| Ctl3dDialog(hWndDlg, msg, wparam, lparam)})
// next, from a resource-only DLL
hDLL = LoadLibrary("dlgres.dll")
DialogBox(hDLL, "sample3d", , ;
{|hWndDlg, msg, wparam, lparam| Ctl3dDialog(hWndDlg, msg, wparam, lparam)})
FreeLibrary(hDLL)
return
static procedure Ctl3d(lOn)
local hInst := _GetInstance()
if lOn .and. hLibCtl3d == nil
hLibCtl3d := LoadLibrary("ctl3d.dll")
if hLibCtl3d == nil .or. hLibCtl3d < 32
MessageBox( , "Unable to find CTL3D.DLL", "Error", MB_ICONSTOP)
hLibCtl3d := nil
else
Ctl3dRegister(hInst)
Ctl3dAutoSubclass(hInst)
endif
elseif !lOn .and. hLibCtl3d != nil
Ctl3dUnregister(hInst)
FreeLibrary(hLibCtl3d)
hLibCtl3d := nil
endif
Menu3dUpdate()
return
static procedure Menu3dUpdate()
local cItem := "3d"
local hMenu
if !IsWindow(hWnd)
return
endif
hMenu := GetMenu(hWnd) // get reference to main menu
if hLibCtl3d == nil
// either turned it off, or an error (e.g. no DLL)
CheckMenuItem(hMenu, cItem, MF_UNCHECKED)
else
// 3d is now on
CheckMenuItem(hMenu, cItem, MF_CHECKED)
endif
return
static procedure DoMenu3d(cItem)
local hMenu := GetMenu(hWnd) // get reference to main menu
local nCheck := CheckMenuItem(hMenu, cItem) // current state
Ctl3d(nCheck != MF_CHECKED) // want opposite of current
return
function nstr(n)
return alltrim(str(n)) + " "
function asString(x)
local v := valtype(x), i, n, c
do case
case v == "C"
case v == "N"
return nstr(x)
case v == "L"
return iif(x, ".T.", ".F.")
case v == "D"
return dtoc(x)
case v == "U"
return "NIL"
case v == "A"
c = "{"
n := len(x)
for i = 1 to n
c += asString(x[i])
if i != n
c += ", "
endif
next i
c += "}"
return c
case v == "O"
return x:classname() + " {...}"
case v == "B"
return "{|| ...}"
otherwise
return ""
end case
return x
#ifdef SEE_MESSAGES
function asMsg(nMsg)
static aMsg := ;
{ ;
{WM_COMPACTING, "WM_COMPACTING"}, ;
{WM_WININICHANGE, "WM_WININICHANGE"}, ;
{WM_SYSCOLORCHANGE, "WM_SYSCOLORCHANGE"}, ;
{WM_QUERYNEWPALETTE, "WM_QUERYNEWPALETTE"}, ;
{WM_PALETTEISCHANGING, "WM_PALETTEISCHANGING"}, ;
{WM_PALETTECHANGED, "WM_PALETTECHANGED"}, ;
{WM_FONTCHANGE, "WM_FONTCHANGE"}, ;
{WM_SPOOLERSTATUS, "WM_SPOOLERSTATUS"}, ;
{WM_DEVMODECHANGE, "WM_DEVMODECHANGE"}, ;
{WM_TIMECHANGE, "WM_TIMECHANGE"}, ;
{WM_NULL, "WM_NULL"}, ;
{WM_USER, "WM_USER"}, ;
{WM_PENWINFIRST, "WM_PENWINFIRST"}, ;
{WM_PENWINLAST, "WM_PENWINLAST"}, ;
{WM_COALESCE_FIRST, "WM_COALESCE_FIRST"}, ;
{WM_COALESCE_LAST, "WM_COALESCE_LAST"}, ;
{WM_POWER, "WM_POWER"}, ;
{WM_QUERYENDSESSION, "WM_QUERYENDSESSION"}, ;
{WM_ENDSESSION, "WM_ENDSESSION"}, ;
{WM_QUIT, "WM_QUIT"}, ;
{WM_SYSTEMERROR, "WM_SYSTEMERROR"}, ;
{WM_CREATE, "WM_CREATE"}, ;
{WM_DESTROY, "WM_DESTROY"}, ;
{WM_NCCREATE, "WM_NCCREATE"}, ;
{WM_NCDESTROY, "WM_NCDESTROY"}, ;
{WM_SHOWWINDOW, "WM_SHOWWINDOW"}, ;
{WM_SETREDRAW, "WM_SETREDRAW"}, ;
{WM_ENABLE, "WM_ENABLE"}, ;
{WM_SETTEXT, "WM_SETTEXT"}, ;
{WM_GETTEXT, "WM_GETTEXT"}, ;
{WM_GETTEXTLENGTH, "WM_GETTEXTLENGTH"}, ;
{WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING"}, ;
{WM_WINDOWPOSCHANGED, "WM_WINDOWPOSCHANGED"}, ;
{WM_MOVE, "WM_MOVE"}, ;
{WM_SIZE, "WM_SIZE"}, ;
{WM_QUERYOPEN, "WM_QUERYOPEN"}, ;
{WM_CLOSE, "WM_CLOSE"}, ;
{WM_GETMINMAXINFO, "WM_GETMINMAXINFO"}, ;
{WM_PAINT, "WM_PAINT"}, ;
{WM_ERASEBKGND, "WM_ERASEBKGND"}, ;
{WM_ICONERASEBKGND, "WM_ICONERASEBKGND"}, ;
{WM_NCPAINT, "WM_NCPAINT"}, ;
{WM_NCCALCSIZE, "WM_NCCALCSIZE"}, ;
{WM_NCHITTEST, "WM_NCHITTEST"}, ;
{WM_QUERYDRAGICON, "WM_QUERYDRAGICON"}, ;
{WM_DROPFILES, "WM_DROPFILES"}, ;
{WM_ACTIVATE, "WM_ACTIVATE"}, ;
{WM_ACTIVATEAPP, "WM_ACTIVATEAPP"}, ;
{WM_NCACTIVATE, "WM_NCACTIVATE"}, ;
{WM_SETFOCUS, "WM_SETFOCUS"}, ;
{WM_KILLFOCUS, "WM_KILLFOCUS"}, ;
{WM_KEYDOWN, "WM_KEYDOWN"}, ;
{WM_KEYUP, "WM_KEYUP"}, ;
{WM_CHAR, "WM_CHAR"}, ;
{WM_DEADCHAR, "WM_DEADCHAR"}, ;
{WM_SYSKEYDOWN, "WM_SYSKEYDOWN"}, ;
{WM_SYSKEYUP, "WM_SYSKEYUP"}, ;
{WM_SYSCHAR, "WM_SYSCHAR"}, ;
{WM_SYSDEADCHAR, "WM_SYSDEADCHAR"}, ;
{WM_KEYFIRST, "WM_KEYFIRST"}, ;
{WM_KEYLAST, "WM_KEYLAST"}, ;
{WM_MOUSEMOVE, "WM_MOUSEMOVE"}, ;
{WM_LBUTTONDOWN, "WM_LBUTTONDOWN"}, ;
{WM_LBUTTONUP, "WM_LBUTTONUP"}, ;
{WM_LBUTTONDBLCLK, "WM_LBUTTONDBLCLK"}, ;
{WM_RBUTTONDOWN, "WM_RBUTTONDOWN"}, ;
{WM_RBUTTONUP, "WM_RBUTTONUP"}, ;
{WM_RBUTTONDBLCLK, "WM_RBUTTONDBLCLK"}, ;
{WM_MBUTTONDOWN, "WM_MBUTTONDOWN"}, ;
{WM_MBUTTONUP, "WM_MBUTTONUP"}, ;
{WM_MBUTTONDBLCLK, "WM_MBUTTONDBLCLK"}, ;
{WM_MOUSEFIRST, "WM_MOUSEFIRST"}, ;
{WM_MOUSELAST, "WM_MOUSELAST"}, ;
{WM_NCMOUSEMOVE, "WM_NCMOUSEMOVE"}, ;
{WM_NCLBUTTONDOWN, "WM_NCLBUTTONDOWN"}, ;
{WM_NCLBUTTONUP, "WM_NCLBUTTONUP"}, ;
{WM_NCLBUTTONDBLCLK, "WM_NCLBUTTONDBLCLK"}, ;
{WM_NCRBUTTONDOWN, "WM_NCRBUTTONDOWN"}, ;
{WM_NCRBUTTONUP, "WM_NCRBUTTONUP"}, ;
{WM_NCRBUTTONDBLCLK, "WM_NCRBUTTONDBLCLK"}, ;
{WM_NCMBUTTONDOWN, "WM_NCMBUTTONDOWN"}, ;
{WM_NCMBUTTONUP, "WM_NCMBUTTONUP"}, ;
{WM_NCMBUTTONDBLCLK, "WM_NCMBUTTONDBLCLK"} ;
}
// these 2 arrays are separate because some Clipper compiler
// versions fail with Memory Overbooked or other errors
static aMsg2 := ;
{ ;
{WM_MOUSEACTIVATE, "WM_MOUSEACTIVATE"}, ;
{WM_CANCELMODE, "WM_CANCELMODE"}, ;
{WM_TIMER, "WM_TIMER"}, ;
{WM_INITMENU, "WM_INITMENU"}, ;
{WM_INITMENUPOPUP, "WM_INITMENUPOPUP"}, ;
{WM_MENUSELECT, "WM_MENUSELECT"}, ;
{WM_MENUCHAR, "WM_MENUCHAR"}, ;
{WM_COMMAND, "WM_COMMAND"}, ;
{WM_HSCROLL, "WM_HSCROLL"}, ;
{WM_VSCROLL, "WM_VSCROLL"}, ;
{WM_SETCURSOR, "WM_SETCURSOR"}, ;
{WM_SYSCOMMAND, "WM_SYSCOMMAND"}, ;
{WM_MDICREATE, "WM_MDICREATE"}, ;
{WM_MDIDESTROY, "WM_MDIDESTROY"}, ;
{WM_MDIACTIVATE, "WM_MDIACTIVATE"}, ;
{WM_MDIRESTORE, "WM_MDIRESTORE"}, ;
{WM_MDINEXT, "WM_MDINEXT"}, ;
{WM_MDIMAXIMIZE, "WM_MDIMAXIMIZE"}, ;
{WM_MDITILE, "WM_MDITILE"}, ;
{WM_MDICASCADE, "WM_MDICASCADE"}, ;
{WM_MDIICONARRANGE, "WM_MDIICONARRANGE"}, ;
{WM_MDIGETACTIVE, "WM_MDIGETACTIVE"}, ;
{WM_MDISETMENU, "WM_MDISETMENU"}, ;
{WM_CHILDACTIVATE, "WM_CHILDACTIVATE"}, ;
{WM_INITDIALOG, "WM_INITDIALOG"}, ;
{WM_NEXTDLGCTL, "WM_NEXTDLGCTL"}, ;
{WM_PARENTNOTIFY, "WM_PARENTNOTIFY"}, ;
{WM_ENTERIDLE, "WM_ENTERIDLE"}, ;
{WM_GETDLGCODE, "WM_GETDLGCODE"}, ;
{WM_CTLCOLOR, "WM_CTLCOLOR"}, ;
{WM_SETFONT, "WM_SETFONT"}, ;
{WM_GETFONT, "WM_GETFONT"}, ;
{WM_DRAWITEM, "WM_DRAWITEM"}, ;
{WM_MEASUREITEM, "WM_MEASUREITEM"}, ;
{WM_DELETEITEM, "WM_DELETEITEM"}, ;
{WM_COMPAREITEM, "WM_COMPAREITEM"}, ;
{WM_VKEYTOITEM, "WM_VKEYTOITEM"}, ;
{WM_CHARTOITEM, "WM_CHARTOITEM"}, ;
{WM_QUEUESYNC, "WM_QUEUESYNC"}, ;
{WM_COMMNOTIFY, "WM_COMMNOTIFY"}, ;
{WM_CUT, "WM_CUT"}, ;
{WM_COPY, "WM_COPY"}, ;
{WM_PASTE, "WM_PASTE"}, ;
{WM_CLEAR, "WM_CLEAR"}, ;
{WM_UNDO, "WM_UNDO"}, ;
{WM_RENDERFORMAT, "WM_RENDERFORMAT"}, ;
{WM_RENDERALLFORMATS, "WM_RENDERALLFORMATS"}, ;
{WM_DESTROYCLIPBOARD, "WM_DESTROYCLIPBOARD"}, ;
{WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD"}, ;
{WM_PAINTCLIPBOARD, "WM_PAINTCLIPBOARD"}, ;
{WM_SIZECLIPBOARD, "WM_SIZECLIPBOARD"}, ;
{WM_VSCROLLCLIPBOARD, "WM_VSCROLLCLIPBOARD"}, ;
{WM_HSCROLLCLIPBOARD, "WM_HSCROLLCLIPBOARD"}, ;
{WM_ASKCBFORMATNAME, "WM_ASKCBFORMATNAME"}, ;
{WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN"} ;
}
static lNotDone := .t.
local i, n := len(aMsg), cRet := alltrim(str(nMsg))
if lNotDone
aeval(aMsg2, {|a| aadd(aMsg, a)})
// MessageBox( , atail(aMsg)[2], "Should be CHANGECBCHAIN")
lNotDone := .f.
endif
for i = 1 to n
if aMsg[i, 1] == nMsg
cRet = aMsg[i, 2]
exit
endif
next i
return cRet
function aShow(aChoices)
local aDlg, nRet, cText
aDlg = CreateDialog("aShow", ;
WS_CAPTION + WS_SYSMENU + WS_GROUP + WS_TABSTOP ;
+ WS_THICKFRAME + WS_VISIBLE + WS_POPUP, ;
20, 10, 300, 200)
aDlg = AppendDialog(aDlg, "listbox", DLG_LISTBOX, ;
WS_CHILD + WS_VISIBLE + WS_VSCROLL + WS_BORDER ;
+ WS_TABSTOP + LBS_USETABSTOPS, ;
10, 10, 280, 160, ;
aChoices)
aDlg = AppendDialog(aDlg, "ok", DLG_BUTTON, ;
BS_DEFPUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
100, 175, 40, 15, ;
"&Ok")
aDlg = AppendDialog(aDlg, "cancel", DLG_BUTTON, ;
BS_PUSHBUTTON + WS_TABSTOP + WS_CHILD + WS_VISIBLE, ;
160, 175, 40, 15, ;
"&Cancel")
if ModalDialog(aDlg) = 0 .or. GetDialogResult(aDlg, "cancel") = .T.
nRet = 0
else
cText = GetDialogResult(aDlg, "listbox")
nRet = ascan(aChoices, cText)
endif
return nRet
static procedure DumpDlog()
local i, n := len(aDlog), a := {}, aDlogi
MessageBox( , asString(n), "len(aDlog)")
for i = 1 to n
aDlogi = aDlog[i]
aadd(a, asString(aDlogi[1]) ;
+ chr(9) + asMsg(aDlogi[2]) ;
+ chr(9) + asString(aDlogi[3]) ;
+ chr(9) + asString(C4W_LoWord(aDlogi[4])) ;
+ chr(9) + asString(C4W_HiWord(aDlogi[4])))
next i
aShow(a)
return
static procedure DumpEdit()
local i, n := len(aEdit), a := {}, aEditi
for i = 1 to n
aEditi = aEdit[i]
aadd(a, asString(aEditi[1]) ;
+ chr(9) + asMsg(aEditi[2]) ;
+ chr(9) + asString(aEditi[3]) ;
+ chr(9) + asString(C4W_LoWord(aEditi[4])) ;
+ chr(9) + asString(C4W_HiWord(aEditi[4])))
next i
aShow(a)
return
#endif // SEE_MESSAGES
static function ToggleItem(cItem)
local hMenu := GetMenu(hWnd) // retrieve reference to main menu
local nCheck := CheckMenuItem(hMenu, cItem)
CheckMenuItem(hMenu, cItem, if(nCheck == MF_CHECKED, MF_UNCHECKED, MF_CHECKED))
return nil
function MenuSetup()
local hWnd := SelectWindow(), hMenu, hPopupMenu
if (hMenu := GetMenu(hWnd)) != nil
DestroyMenu(hMenu)
endif
// do new one (forget old value)
hMenu = CreateMenu()
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "file", MF_ENABLED + MF_POPUP, "&File", hPopupMenu)
AppendMenu(hPopupMenu, "exit", MF_ENABLED + MF_STRING, "E&xit", {|c| DoExit(c) })
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "view", MF_ENABLED + MF_POPUP, "&View", hPopupMenu)
AppendMenu(hPopupMenu, "big", MF_ENABLED + MF_STRING, "&Big Dialog", {|| BigDialog()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "modal", MF_ENABLED + MF_POPUP, "&Modal", hPopupMenu)
AppendMenu(hPopupMenu, "dynmodal", MF_ENABLED + MF_STRING, "&Dynamic", {|| DynModal()})
AppendMenu(hPopupMenu, "dynget", MF_ENABLED + MF_STRING, "Dynamic &Get", {|| DynModalGet()})
AppendMenu(hPopupMenu, "dynusermodal", MF_ENABLED + MF_STRING, "&User details (dyn)", {|| DynUserModal()})
AppendMenu(hPopupMenu, "resmodal", MF_ENABLED + MF_STRING, "&Resource", {|| ResModal()})
AppendMenu(hPopupMenu, "resmodify", MF_ENABLED + MF_STRING, "&Modified Res", {|| ResModify()})
AppendMenu(hPopupMenu, "usermodal", MF_ENABLED + MF_STRING, "&User details (res)", {|| UserModal()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "modeless", MF_ENABLED + MF_POPUP, "Modele&ss", hPopupMenu)
AppendMenu(hPopupMenu, "dynmodeless", MF_ENABLED + MF_STRING, "&Dynamic", {|| DynModeless()})
AppendMenu(hPopupMenu, "resmodeless", MF_ENABLED + MF_STRING, "&Resource", {|| ResModeless()})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "options", MF_ENABLED + MF_POPUP, "&Options", hPopupMenu)
AppendMenu(hPopupMenu, "font", MF_ENABLED + MF_STRING, "&Font", {|| DoFont()})
AppendMenu(hPopupMenu, "3d", MF_ENABLED + MF_STRING, "3&d Effects", {|c| DoMenu3d(c)})
hPopupMenu = CreatePopupMenu()
AppendMenu(hMenu, "help", MF_ENABLED + MF_POPUP, "&Help", hPopupMenu)
AppendMenu(hPopupMenu, "about", MF_ENABLED + MF_STRING, "&About", {|| DoAbout()})
SetMenu(hWnd, hMenu)
return hMenu