Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide to Clip-4-Win version 3.0 - <b>createdialog()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
CreateDialog()
Make a new dialog structure, or start a modeless dialog
------------------------------------------------------------------------------

Syntax
CreateDialog( <cTitle>, <nStyle>, <nX>, <nY>, <nWidth>, <nHeight>,
              [ <nPointSize> ]  [ , <cFaceName> ] )   -->   aDlg

OR:

CreateDialog( [ <hInst> ] , <cDlgName>, [ <hWnd> ] , <bAction> )
         -->   hWndDlg

Arguments

EITHER:

<cTitle> is the text to put in the title bar of the dialog.

<nStyle> is the window style to use (a combination of the WS_*
values from WINDOWS.CH).

<nX>, <nY> specify the position of the top left-hand corner of
the dialog window in pixels.

<nWidth>, <nHeight> specify the size of the dialog window in
pixels.

<nPointSize> is an optional numeric value specifying the point
size of the font to be used for the dialog.  The default is 8.

<cFaceName> is an optional string specifying the name of the font
to be used for the dialog.  The default is "MS Sans Serif".

OR:

<hInst> is the handle of the instance of the application (as
returned by the _GetInstance() function), or a handle of a DLL
(as returned by the LoadLibrary() function).  The default is the
current application.

<cDlgName> is the name of the dialog in the resource file
identified by <hInst>.

<hWnd> is the handle to the window that is to own the dialog
box.  The default is the currently selected window.

<bAction> is a code block to be executed every time Windows
sends a message to the dialog box.


Returns

EITHER:
An array of information about the dialog, which may be passed to
the related functions AppendDialog(), GetDialogResult() and
ModalDialog().  This array should not be altered or examined,
and is subject to change in future versions of Clip-4-Win.

OR:
If successful, the value returned is the handle of the
modeless dialog window created.  Otherwise, zero (0) is
returned.  (The handle is returned after the dialog has been
created and sent several messages, including WM_INITDIALOG.)

Description
This function is used for two purposes, depending on the
parameters.

EITHER:
With the first syntax shown above, this function is used to
create an empty dialog structure, which can be added to using
AppendDialog(), and displayed using ModalDialog().  This
type of dialog is a dynamic dialog.

OR:
With the second syntax shown above, this function is used to
display and activate a modeless dialog from a  dialog
resource.  (It is the resource equivalent of the ModalDialog()
function.)  The dialog resource is usually stored in the
application's EXE file, but can be in another EXE or DLL.

Note:  a modeless dialog is terminated by calling
DestroyWindow(), and not by calling EndDialog(), which is
only used for a modal dialog.

The code block <bAction> is passed each message from Windows,
together with the associated parameters, as the dialog is
created, used, and terminated.  This occurs automatically
(there is no need for the IsDialogMessage() function you
might read about elsewhere).  The code block should be as
follows:

          { | hDlg, nMsg, nwParam, nlParam |                ;
             DlgFunc( hDlg, nMsg, nwParam, nlParam ) }

The messages from Windows have 4 parameters:

          hDlg      the handle of the dialog window
          nMsg      the WM_* value identifying the message
          nwParam   depends on nMsg
          nlParam   depends on nMsg

The code block should return a value to indicate whether it
processed the message.  In practice, you'll probably just call
a function (as shown above), so it's up to the function to
behave correctly.

Most of the messages can be ignored, in which case the dialog
function should return zero (0).  However, the WM_INITDIALOG
message, which is sent before the dialog is made visible, is
different: you should only return zero if you use SetFocus()
to give the input focus to a particular control within the
dialog.  You should return a non-zero value (one (1) is
usually used) if you don't set the focus, in which case the
focus will be set by default (typically to the first control
with the WS_TABSTOP setting).  For this message, nwParam is
the handle of the control that will be given the focus by
default.

The other important message is WM_COMMAND, which is sent when
a control sends a notification message to its parent.
Examples of controls are buttons, list boxes, edit controls
and combo boxes.  The parent will be the dialog box itself
(identified by hDlg).

The numeric id of the control is passed in the nwParam
parameter.

The nlParam value is really two values joined together.  These
may be fetched using _LastLolParam(), which identifies the handle
of the control, and _LastHilParam(), which identifies the
notification code the control is sending (one of the BN_*, CBN_*,
EN_*, LBN_* values).  Alternatively, you can isolate these values
using C4W_LOWORD( nlParam ) and C4W_HIWORD( nlParam ).

Example

//  This is a DYNAMIC DIALOG:

aDlg = CreateDialog("Sample Dialog",                        ;
              WS_CAPTION + WS_VSCROLL + WS_HSCROLL          ;
              + WS_SYSMENU + WS_GROUP + WS_TABSTOP          ;
              + WS_THICKFRAME + WS_VISIBLE + WS_POPUP,      ;
              24, 12, 180, 160)

aDlg = AppendDialog(aDlg, "ok", DLG_BUTTON,                 ;
              BS_DEFPUSHBUTTON + WS_TABSTOP                 ;
              + WS_CHILD + WS_VISIBLE,                      ;
              136, 112, 24, 14,  "&Ok")

aDlg = AppendDialog(aDlg, "edit", DLG_EDIT,                 ;
              ES_LEFT + ES_MULTILINE + ES_NOHIDESEL         ;
              + ES_AUTOVSCROLL + ES_AUTOHSCROLL             ;
              + WS_VSCROLL + WS_HSCROLL + WS_BORDER         ;
              + WS_TABSTOP + WS_CHILD + WS_VISIBLE,         ;
              122, 64, 40, 38,  "")

// Hitting ESCAPE returns 0, in case you want to try it...
i = ModalDialog(aDlg, hInst, hWnd)
s = GetDialogResult(aDlg, "edit")
? "Item chosen", i
? "Result of edit ", s


//  This is a dialog using a DIALOG RESOURCE:

hWnd = CreateDialog(  , "dlg",  ,                         ;
                     { | hDlg, msg, wparam, lparam |      ;
                        ResDlgModeless( hDlg, msg, wparam, lparam ) } )
if hWnd = = 0
     // error - check you added the resource to the EXE
     //         (also check the name of the dialog)
endif


See Also: AppendDialog() DialogBox() GetDialogResult() ModalDialog()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson