Announcement

Collapse
No announcement yet.

Tutorial for beginner of powerbasic compiler for windows concerning gui

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

    Tutorial for beginner of powerbasic compiler for windows concerning gui

    please
    nobody make any post until i am done writing all my posting to this thread.
    i will make a final post when i am done/finished and probably make an announcement in the cafe section when i am through so
    if there is anybody wanting to help this thread out can do so.
    i am a very slow writer and communicator with words on paper and it takes me long periods of time to create something and proof read it.
    thanks for the courtesy you extended me.
    i have edits and post to add and we are in a holiday season with little time to spare.
    i do not want to have to ask the forum supervisor to erase any unnecessary posting by others at this time.




    FINALLY! FINALLY! FINALLY!
    I HAVE SEEN THE LIGHT OF GUI PROGRAMMING IN POWERBASIC.

    I want to share with others and if somebody wants to edit my writing so other will understand clearer or where i might of picked the wrong words, please do so and do so entirely so i can delete my words or maybe i can copy and give you credit and you can delete the a post where we have one continuous thought and we can have a join post for the person to read and not be confused with several posting in this threads

    I have finally gotten the picture of how programming for windows works. I thought i would never understand and was so frustrated over the idea of even programming with a windows gui interface.

    I am going to attempt to communicate the "how to program" for people wanting to use powerbasic for windows compiler to create a gui program.

    I wish that i could communicate somethings in a illustration, this would some much easier to understand what is actually happening. Maybe somebody would do this, as i have little skills in the drawing.

    all discussion i am using is on the compiler language of "Powerbasic Compiler for Windows"
    i am a beginner and want to share my thoughts right this minute as a beginner to others before i forget about the basics and start looking and using the compiler as a more advanced user.

    so lets start

    LESSON ONE

    You can use the compiler to produce executable code into a EXE or DLL file.
    The program you create does not even have to have a graphical user interface (GUI) at for the user. There many things you can do with a program other than display information or ask the user for input.

    While using windows operating systems, there are many things happening all at the same time, it is a multitasking operating system. You may want to start something, control something, change something or perform some kind of operation, all not ever needing a GUI.
    Windows is a operating environment where messages are constantly being created and sent somewhere to cause an event to occur. The key words in the last line are messages and events.

    Powerbasic compiler(PB) gives us the tools by which we can program to create those messages or receive those events. When programming for windows operation system (OS), there are many many windows functions that can be used from the compiler. To make use of those functions, the programmer only has to learn the function, what the function does, and then place code in the program to call that function. These functions are call API function.

    So using PB you can do some powerful programming inside of an EXE or DLL without ever creating and using a GUI. A DLL a file that executable code line an EXE, but the DLL is different in that it contains functions that an EXE can call to make use of.

    so the first lesson is that you can write a program in PB that does not even have to use a GUIi to perform some kind to task.
    One reason for not using a GUI in a program, is you may want your program to monitor something in the background.

    LESSON TWO
    It is very important to understand that when anything that happens, that is an an event and when an event happens, that event creates a message. An example of that is a click of a mouse is an event. When you click the mouse, that event creates and sends a message. In order for a programmer to make use of a gui for a user, the programmer has to catch the message and interpet the message. So ever action(event) creates a message and the program reacts on the message.

    LESSON THREE
    Now onto using a graphical user interface(GUIi)

    In most cases your program will be displaying information or interacting with a user.
    In order to do this, you must create a window.
    In PB that window is called a dialog, so in order to create a window, you use the dialog commands.

    We are now going to refer to a window as a dialog.

    In helping to understand what a dialog is all about, i like to think of a dialog as just like a dialog between two people. One person talks to the other person, one person talks, the other person listens. There is always a message sending and a message being received.

    When a dialog displays text or graphics or plays music, a user is the person listening with their senses. The user maybe listening with sound coming to their ears, seeing the display with their eyes, feeling with hands(maybe the user has a game that vibrates a joystick), but it comes down to one thing, the user is listening.
    Now, on the other side of that dialog is the user.
    When the user uses a keyboard, mouse, joystick, or any kind of input, it creates a message and sends the message to the dialog. The dialog is now listening. The dialog can also listen using any of the computers senses This is just my way of explaining something in a non technical way, but i hope you understand the dialog listens also.
    So that is how i picture a dialog in my mind, communications having the ability to go both ways.
    So now we understand a window is a dialog.

    LESSON FOUR
    It has taken me so long to really understand the above. It is already time for a break. If you can understand the above now without programming in PB, you are much farther than it took me several years to understand the fundmentals of windows programming.
    While taking that break and read the glossary that is in the back of your book on Powerbasic Compiler for Windows.

    I am very serious about the next sentence and you should be tool
    If you do not have a book, get a book written by Powerbasic for the compiler Powerbasic Compiler for Windows, if you are not going to get a book and do not need a book, then you are much to advanced to be needing to read this on how to program for windows GUI, i can not help you, maybe you need to be helping me.

    Read the glossary at the back of the books slowly so we can communicated much better. Maybe not to other people, but the glossary is worth the price of the book itself, although not very long, it condenses down subjects need for the beginner. There is even a line in the book itself that suggest this very act. If you are a beginner or new to powerbasic compiler and you are not going to get a book, i really believe you are not interested that much about programming with powerbasic. The best thing you can do for yourself is purchase a book and you will not be sorry that you ever did.
    lesson five will be a new post in this thread and while i am writing it, if you do not have that book, go ahead and order it.
    Last edited by Paul Purvis; 31 Dec 2007, 12:39 AM.
    p purvis

    #2
    Now that you have read the glossary we can continue.

    First i want to repeat the thought i am not trying to be perfect on my technical wording in these post, although, i will do my best to not lead you wrong either, just remember, i am also a beginner.

    Before we get into the programming part there are also a few things i should mention. For one thing, if you are a beginner, it would probably be best if you had a computer to practice on. I do not recommend you practice on a computer you are using at work or a computer that you depend on for any source of income or where depend on your computer for some kind of important tool. A computer is just a tool and a tool only. Purchase a laptop for learning, you do not need an expense one to learn on. I am using a laptop right now that only cost 400 dollars. I remember when a good quality adding machine cost just about that much. I am using the Windows 2000 Professional as my operating system on a new computer purchase in the summer of 2007 and it allows me to do just about everything i need to do. Although i like the newer AMD processors, i feel newer computers with the Intel processors have drivers more compatible with the older operating systems. If you want something a little better than that, then get Windows XP Professional as your operating system, it will give you a few more advanced features and conveniences that windows 200 professional does not have built in but also windows xp has some features i do not want in an operating system also.

    There are a few other things also you need to know about using computers that will help you program.
    The first thing is that computers use an operating system, and inside that operation system, there is a such a thing as hierarchy of actions that the computer performs. What i mean is that there are certain operations a computer performs, where there exist a priority on what happens inside the computer and/or the operating systems. Believe it or not, if you know what a floppy drive is, when a floppy drive is in use, it has a higher priority than the hard drive. It has to be that way because floppy drives are much slower devices than hard drives. To give you an good example of priorities, let use suppose you and i where having a dialog with each other and we both where standing up. While you are talking and listening to me, you also have to keep your balance and not fall. If you where talking to me and you felt yourself unbalanced and about to fall, you would correct your balance not so to fall and hurt yourself. So your balance would be of a greater priority to you than what you where saying or listening to me.
    So that all goes on pretty much unchecked, or at least some things are assumed, but there is still a priority of what you are doing. The same goes for computers, the operating system pretty much monitors what is going on and creates what is called events, and the operating system sends notifications of those events out where something else can act on them. Something will be running inside the operating system or your program that catches those notifications and takes an action.

    Now about actions, we always want to remember that in taking an actions, there usually is always an opportunity to make choices.
    There is most of the time always one choice most people do not ever consider when making choices. There can be a choice to not make a choice, take no action, do nothing. Doing nothing is a choice even though there might be some results when not making a choice, like standing in the middle of a road and making no choice of what to do if a car is driving your way. So most the time you always have that choice, to not make a choice, remember that, you need to use that later in my discussions.

    So lets get back to programming.

    DDT stands for Dynamic Dialog Tools which was created by Powerbasic and the DDT features where placed into the Powerbasic windows compiler to allow you to create a program that uses a window without having to learn all the details required to perform certain duties in the creation of a GUI(a dialog window for windows operating system). Although you can probably program without using the features in DDT, and one day as you learn more, you may want to program using built in windows functions only, that would be a bad choice because of the learning curve is way to steep.

    So using DDT only is the best way to go to get the results you want in the shortest amount of time.
    We are only going to learn the basics to help you see the light of what is happening to make it easier for you to start programming.

    All my teaching will be based a Windows NT type operating system know was Windows 2000 Professional(Pro). You should be fine with Windows XP Home or Professional editions, but i highly suggest the Professional edition of XP. Vista is new and it is very much like Windows XP and 2000 Pro, but the new OS may have different phrasing to perform certain duties that may have been changed, and most of the back ground of help in this forum concerns the OS prior to Vista. If you are on Windows 98, i highly suggest that you upgrade for many reasons. One of the best reasons to move from Windows 98 for me, is i lost so many files due to the operating system and the way windows formats the hard drives and how it works with the hard drives. There are a lot of limitations to Windows 98 and making the change to Vista or something from Microsoft in the future will be or should be much easier from Windows 2000 Pro or Windows XP.

    So more basics, lets learn a few more things. It is ok to be slow in learning.
    You should be logged onto the computer as a user with administrator rights to do the following, if not so, do so now.
    I am going to touch on the subject of the desktop first, to make sure we are building the right foundation. You are going to have to remember or print this paragraph out. We are going to learn what a desktop actually is by removing the main features of the desktop then restarting those features. Follow exactly, if you get stuck, reboot your computer and try again, you may have to use the rest button on your computer if you get confused and want to retry. Close all your programs running include the program you are using to read this. Access the task manager by right clicking on a blank area of the taskbar on your computer, probably it is on the bottom of the screen.
    Once in task manager goto processes and click on explorer.exe and at the bottom right of the screen, you should see an end process button. Click on End Process while explorer.exe is hightlighted. What you should now see is a blank screen and you may have the task manager windows still on the screen. You can close that screen using the x button in the upper right of your task manager windows, the x button is on the caption line of the window. Now your computer is still running fine. If you now have a blank screen, press the three keys together Ctrl-Alt-Del, that should now bring you back to task manager windows. You may have to click on a window to get back to the task manager. Once there, click on the applications tab to bring up that window. Click on New Task, then type the words CMD or COMMAND to bring up a prompt window. Now once at a prompt type the work EXPLORER and you get back your working desktop. So now you know the difference in a blank desktop and the desktop that explorer provides for using your computer and you know your computer will operate fine without the desktop that explorer provides you with although just about all of use the desktop provided by the explorer program.
    The desktop is mother window of all windows, and you just found that out.

    So now we want to write a program that produces a GUI that runs on top of the desktop.
    Our GUI window has a lower priority than the desktop window, remember that, the desktop is a window that has a higher level of preliviges and priority than our window that we are going to create.
    This all comes down to the fact that some processes the computer is running, have higher priorities, priliviges, rights, etc. So our gui will run under the desktop's priority, which leads us back to events causing a messages or notifications and actions being taken on those messages.

    When an event occurs, which could be anything and everything that happens, the windows operating system creates a notification that is sent out as a message and programs react to those messages by setting up prebuilt traps for those messages. And your program can create an event that in turn causes the windows operating system to create a notification and send a message that some other program or your own program that has traps setup to catch a message. Now trap is not a technical term that we want to us, but i hope you understand.

    next we will create a gui window using the DDT functions that powerbasic has placed into their compiler for windows.
    Last edited by Paul Purvis; 31 Dec 2007, 03:30 AM.
    p purvis

    Comment


      #3
      Powerbasic is a compiler that uses the basic dialect for programming a source code document that will be compiled into machine language.
      It is mandatory that one knows some basic programming before trying to learn Powerbasic.
      Basic is easy to learn and if you do not know how to program in basic, i suggest learning the basic language first by using a much simpler program that uses the basic dialect before continuing on with powerbasic.
      Any person willing to learn, can easily learn in less than 6 weeks or less, but you must have some skills with the basic programming dialect before you move onto into the gui programming.

      Using the standard basic language , you can place source code into special blocks of sections that give a sense of centralization of particular source code. These sections make it convenient to place code that may perform a specific procedure or routine, or a routine of source code that used more that once in a program. The word for those blocks of code are GOSUB routines, useful for placing programming instructions into a neatly grouped section. At the end of the instructions located in the GOSUB rountine, there is a statement used,usually the word RETURN, that forces the routine automatically back to point in the program where the program was at in the code just after the programming statement GOSUB was made.
      ---------------------------------------------------------------------------------------------------------------------
      Here is an example of a gosub routine in a program written using the basic dialect.

      A$="hello"
      GOSUB DISPLAY
      B$="goodbye"
      GOSUB DISPLAY
      end

      SUB DISPLAY
      PRINT A$
      RETURN

      -------------------------------------------------------------------------------
      your program will print to the screen the following

      hello
      goodbye
      --------------------------------------------------------------------------------------------------------------------
      So the first thing that you noticed is the fact you did not have write the code twice in the GOSUB routine


      he GOSUB routine is known as function. You make use of functions in most of today's programming languages.
      Power basic still supports GOSUB routines, but let us get use to referring to them as functions.

      In powerbasic, the main lines of code are located in a main function that is started first, you do not have to make a call to the function, it is run automatically.
      Using the newest version of powerbasic, which i am now using the compiler version named PBWIN 8.04. In your powerbasic source code , you must have at least one function, which is run once when the program has started.

      --------------------------------------------------------------------------------------------------------------------------------
      Here is all the code necessary to create a program, although it does absolutely nothing.
      There is no code in the main routine at all, the routine is now going to be referred to as a function.
      Remember what i said about a choice to do nothing earlier, this program's source code will compile to create a executable program, but does absolutely nothing.

      #COMPILE EXE

      FUNCTION PBMAIN() AS LONG
      END FUNCTION


      -------------------------------------------------------------------------------------------------------------------------------
      Here is another program's source code that assigns the string variable A$ the word HELLO, then reassigns the same string variable the word GOODBYE, but does not display anything either.


      #COMPILE EXE

      FUNCTION PBMAIN() AS LONG
      A$="HELLO"
      B$="GOODBYE"
      END FUNCTION
      --------------------------------------------------------------------------------------------------------------------------------
      There is a special routine built into widows operation system referred to as msgbox.
      Routines are now mostly know as functions these days.
      So we now referred to the msgbox as a msgbox function.
      The statemnt MSGBOX "HELLO" will call the msgbox function to print the word HELLO to the screen.
      When you run any routine, that routine is now described as a function such as the GOSUB routine in older basic languages, and the process of running that routine is now know as calling a function.
      You call the function msgbox.

      So for now, forget about the word ROUTINE, you will now use the term FUNCTION.

      So now, you know that inside the source code to be compiled, must have to have at least one function.


      You can run or should i say call a function using several different ways, but the easiest way to call a function brings 3 ways to do so.

      If we create a function to assign two number variables then add those two variables to a third variable, we could place the code into a function and use the following 3 ways to CALL the function. Calling or to CALL is the word used for making code placed into the function perform an action.

      here is a function

      FUNCTION ADDNUMBERS () AS LONG
      A&=10 'assign the number 10 to numeric variable A& the variable is a long interger
      B&=20 'assign the number 20 to numeric variable B&
      C&=A&+B& 'add variable A& plus B& to numeric variable C&
      END FUNCTION 'similiar to the return key word in a gosub routine


      You can use the following statements to run the function(routine)
      CALL ADDNUMBERS
      ADDNUMBERS
      or
      D&=ADDNUMBERS 'this actually returns a value to be assigned to the variable D&

      if you want D& to equal C&, you need to add one statement before the statement END FUNCTION that says FUNCTION=C&
      Well, so that you know have an idea of what functions can do for you, read your manual on functions and how to use them.

      Now to create a gui in powerbasic for windows
      Read on slowly
      The biggest rule is in creating a gui using DDT is for you to create one function outside of the main function to act as a trap to catch messages sent by windows. The function will be very special and have a special characteristics, and it is referred to as a CALLBACK FUNCTION.
      read that again.

      So how do you do this.
      The callback function will not be located inside the main function that starts with PBMAIN, but remain outside the main function.
      Now get this, you can write a perfectly good program that has no instructions in the function that you use as the main callback function for your dialog.
      Now your confused, confess up.

      You can have more than one callback function, but you must have a main callback function that is tied to the dialog(which is a window).
      With just using one single callback function, all events such as moving a mouse or clicking on something in the dialog or in the caption area of the dialog or client area of the dialog, will cause the windows operating system to generate notification messages that will be sent to the single callback function, where you will place code to trap and catch those messages. Then at that time by trapping those messages/notifications, you will know what action actually happened inside your window.

      It is that simple, i am going to pound the idea to you. An event causes the windows operating system to create a notification message where you are going to place code to trap and catch and interpret those messages into something useful. Which messages you catch are up to you, the first program we are going to write, we will not try to catch any messages, you will see.


      So lets do one.
      Last edited by Paul Purvis; 31 Dec 2007, 04:29 AM.
      p purvis

      Comment


        #4
        #COMPILE EXE "CLRWNDW.EXE"
        #INCLUDE "WIN32API.INC"

        CALLBACK FUNCTION hDlgcallback
        END FUNCTION


        FUNCTION PBMAIN() AS LONG
        DIALOG NEW hInstance&, "A CLEAR DIALOG", , , 200, 200, %WS_POPUP OR %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR _
        %WS_CAPTION OR %WS_SYSMENU OR %WS_MAXIMIZE OR %DS_CENTER TO hDlg&

        DIALOG SHOW MODAL hDlg& CALL hDlgcallback
        END FUNCTION
        -----------------------------------------------------------------------------------------------------------------------------------------
        Here above is a great program that you can use now, i use it to clear my computer screen so nobody can see my screen, i have that program at over 40 work stations so visitors cannot see our screens that may or may not have confidential information.

        to create a dialog(window) using DDT in powerbasic, you only need a few lines of code

        Two lines make the dialog
        DIALOG NEW
        DIALOG SHOW

        and the two lines to create a callback function for the dialog.

        CALLBACK FUNCTION ________
        END FUNCTION

        Notice that the program runs and has absolutely no lines of code in the callback function to catch any messages.
        Go ahead and click the mouse in the middle of the client area while the program is running.
        Those clicks that you are making, are events that make the windows operation system create messages/notifications that are passing right through the callback function where we do not have any code placed to trap any messages or notifactions.
        Last edited by Paul Purvis; 31 Dec 2007, 04:35 AM.
        p purvis

        Comment


          #5
          I have some editing to do, but i want to reinforce the subject on having books or manuals. From past experience, i have had people borrow my computer books and magazines and only one person ever returned what they borrowed.
          Do not lend your books to anybody, even when they look at you like you are crazy after you deny lending the book to them. You are much better off looking crazy, than being without your manuals and books, if you lend one out, plan on not getting it back and if you really like the manual or book, either have the person pay you and tell them you will give the money back to them when they return the book. If the book is out of print, tell them they can only use the book at your location and not to bring it anywhere else.
          If your book is really needed, purchase two, sooner or later you will not be able to get another if you only have one and something happens to the only one you have, learn to say no.

          My ex fiance tried even destroying my high school year books which she claimed was her property when we lived together even though i meet her when i was 35 and she went to a school over 70 miles from where i did, so i never wish these kind of actions on you, but it just goes to show, you never know what can happen. Keep the second book separate from the first, somebody might accidentally destroy it, i have even had a hot water heater burst in the attic and water destroyed programming books, you just never know.
          Last edited by Paul Purvis; 31 Dec 2007, 07:36 PM.
          p purvis

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎