Announcement

Collapse
No announcement yet.

queston about this program example

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • queston about this program example

    COMPILE EXE
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "win32api.inc"

    %IDC_LABEL = 100
    %IDC_TEXT = 101

    DECLARE CALLBACK FUNCTION DlgProc

    FUNCTION PBMAIN

    LOCAL hDlg AS LONG

    DIALOG NEW 0, "Example",,,115, 70, %DS_CENTER TO hDlg
    CONTROL ADD LABEL, hDlg, %IDC_LABEL, "Add Text:",5,5,100,14
    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT, "",5,15,100,14
    CONTROL ADD BUTTON, hDlg, %IDOK, "&OK",5,35,40,14
    CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel",65,35,40,14
    DIALOG SHOW MODAL hDlg CALL DlgProc

    END FUNCTION

    CALLBACK FUNCTION DlgProc

    LOCAL s AS STRING

    SELECT CASE CBMSG
    CASE %WM_INITDIALOG
    CASE %WM_COMMAND
    SELECT CASE LOWRD(CBWPARAM)
    CASE %IDOK
    CONTROL GET TEXT CBHNDL, %IDC_TEXT TO s
    IF s = "" THEN
    MSGBOX "There is no text!",,"Example"
    ELSE
    DIALOG END CBHNDL
    MSGBOX "The text is:" & $CR & s,,"Example"
    MSGBOX "Thank You for using Example",,"Example"
    END IF
    CASE %IDCANCEL
    DIALOG END CBHNDL
    END SELECT
    END SELECT

    END FUNCTION



    I have questons about parts of this program and what they do.

    WHAT DO THIS TWO LINE LET ME DO?
    #DIM ALL
    #REGISTER NONE

    IN THE LINE
    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXT, "",5,15,100,14

    1. hDlg is set as a long in Function PBMAIN
    but it not defind in Callback FUNCTION DlgProc
    can this be replaced with with a an verible?

    The book has hDlg& = Handle of the dialog in wich the button will be created
    So that is pre defind can't be sub with any other name so is it that
    you have to declerd it "LOCAL hDlg AS LONG"


    2. This line uses %IDC_TEXT in this book in the syntax has this
    as unique identifier for the control it is set up to 101 in this
    example. what dose this control?

    3. DIALOG SHOW MODAL hDlg CALL DlgProc
    I think this is call function DlgProc that is defind as a CALLBACK
    and pass hDlg to that function. am I right?

    4. In every program I see there is two Functions. I understand
    PBMAIN wich is like main function in c++. but the CALLBACK FUNCTION
    Dose it have to be a CALLBACK FUNCTION? It seems to me that
    CALLBACK is a type of FUNCTION what is the this meen?

    5. what do this case do and what dose two verbal have stored
    in them?
    CASE %WM_INITDIALOG
    CASE %WM_COMMAND
    SELECT CASE LOWRD(CBWPARAM)


    6. in the line CONTROL GET TEXT CBHNDL, %IDC_TEXT TO s
    what dose CBHNDL do? Is it some type of veribale it use elsewhere in the

    7. what DIALOG END CBHNDL DO?

    Sorry so long with the questons. I just like to usdersand every part of
    a program so I can use part in other programs thanks for all your
    help

    Joe


    ------------------

  • #2
    #DIM ALL <---- Forces you to declare variables same as
    option explict in VB
    #REGISTER NONE <---- The #REGISTER metastatement determines the method of
    automatic allocation of register variables when you
    disable this you can allocate register variables by
    the REGISTER keyword
    hDlg <---- Identifier for DDT Dialog

    DlgProc <---- Function Windows calls when sonmething
    happens on your Dialog (called Events)

    You need to get a good Windows API Book, if you search these
    fourms a few will pop up.



    ------------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

    Comment


    • #3
      1. At the end of the pbmain function there is a very important line
      DIALOG SHOW MODAL hDlg CALL DlgProc, what this means is,
      "Show the dialog modal and let DlgProc handle all the messages"
      So you internally DlgProc already gets the handle of hdlg internally.

      2. %IDC_TEXT is the unique identifier for the textbox. It's more usefull
      to use constant declares, because names make more sense then numbers.

      4. Callback means: "if something happens with hdlg then call DlgProc"

      5. These messages are like (4) for example when the dialog is initialising
      everything after CASE %WM_INITDIALOG will be executed.

      6. Because everything from hdlg is passed to DlgProc the handlers of
      buttons or text fields are also passed to DlgProc. So when you
      press the ok button then that event is being catched by DlgProc
      CASE %WM_COMMAND <-- A button is pressed
      SELECT CASE LOWRD(CBWPARAM) <-- get the loword of the parameter passed
      CASE %IDOK <-- If the button is the ok button the do the things after this case

      7. DIALOG END CBHNDL End the dialog.


      Good luck with your powerbasic exploration







      ------------------

      Comment


      • #4
        Joe, are you a registered PowerBASIC customer? You may also wish to try using the "search" feature of this BBS, as much information can be found in 30,000+ message base here.

        That said, we are here to help you get started, but you also have to take it upon yourself to read the documentation...

        To answer some of your questions:
        1. hDlg is set as a long in Function PBMAIN but it not defind in Callback FUNCTION DlgProc can this be replaced with with a an verible?
        In the callback function, you can identify the handle of the dialog that 'owns' the control with the CBHNDL function, and obtain the ID of the control originating a message with the CBCTL function. Also of importance is the CBCTLMSG function... it identifes the message that the callback is processing.

        2. This line uses %IDC_TEXT in this book in the syntax has this as unique identifier for the control it is set up to 101 in this example. what dose this control?
        Each DDT control can use a programmer-defined ID (identity) value. When Windows crates a control it assigns it a handle whose value is not predictable, but by using a programmer-assigned ID, the control *can* be identifed. If the dialog handle (hDlg in this example, or CBHNDL in the callback) is known, and the control's ID is known (which its is by the use of an eqate), then the Windows-assigned control handle can be obtained from Windows. See the CONTROL HANDLE statement for more information.

        3. DIALOG SHOW MODAL hDlg CALL DlgProc I think this is call function DlgProc that is defind as a CALLBACK and pass hDlg to that function. am I right?
        No. This tells windows to create the dialog identified by the value stored in 'hDlg', and that Windows should call the named callback function whenever a message for that dialog needs to be processed (such as redraw the dialog or in response to a 'click' on a control, etc).

        4. In every program I see there is two Functions. I understand PBMAIN wich is like main function in c++. but the CALLBACK FUNCTION Dose it have to be a CALLBACK FUNCTION? It seems to me that CALLBACK is a type of FUNCTION what is the this meen?
        A callback function is a special type function that is specifically constructed by PowerBASIC to receive the message and accompanying data associated with a message. Functionally, a CALLBACK FUNCTION is equivalent to:
        Code:
        FUNCTION MyCallback(BYVAL hDLg&, BYVAL wMsg&, BYVAL wParam&, BYVAL lParam&) EXPORT AS LONG
        Internally, PB/DLL constructs a callback function like this, but translates the parameters in to the functions CBHNDL, CBMSG, CBWPARAM and CBLPARAM respectively.

        5. what do this case do and what dose two verbal have stored in them?
        CASE %WM_INITDIALOG
        CASE %WM_COMMAND
        These are handlers for particular messages... %WM_INITDIALOG message is sent once when a dialog is first created. %WM_COMMAND is a "notification message" sent to tell the callback that a control was clicked or something related occurred (like keyboard focus was set or lost, etc).

        6. in the line CONTROL GET TEXT CBHNDL, %IDC_TEXT TO s
        what dose CBHNDL do? Is it some type of veribale it use elsewhere in the
        As I outlined above, CBHNDL identifies the parent dialog of the control whose ID value is %IDC_TEXT, which in this case is 101.

        7. what DIALOG END CBHNDL DO?
        It tells Windows to destroy the dialog identified by CBHNDL. Once this occurs, the DIALOG SHOW MODAL statement will return, and code in PBMAIN will continue (or wherever the DIALOG SHOW MODAL statement is located).

        Joe, you *really* need to get an understanding of how Windows applications (and especially dialogs) operate at the O/S level for a full understanding of how DDT applications work. A good WIndows programming book like "Programming Windows" will help you immencely here. If you have a background in C or C++ (non-MFC) in Windows, you'll adapt to DDT very quickly.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X