I want to learn control programming from [Ground-UP]

General FreeBASIC programming questions.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

I want to learn control programming from [Ground-UP]

Post by HACK3R ADI »

I wanna learn control programming like buttons,txtbox,combobox,progressbar,etc... from ground-up without using any lib,etc.....So can anyone guide me where to go.......please help me..
BasicCoder2
Posts: 3955
Joined: Jan 01, 2009 7:03
Location: Australia

Re: I want to learn control programming from [Ground-UP]

Post by BasicCoder2 »

HACK3R ADI wrote:I wanna learn control programming like buttons,txtbox,combobox,progressbar,etc... from ground-up without using any lib,etc.....So can anyone guide me where to go.......please help me..
Professional programmers don't waste time reinventing the wheel. Is it just a case of academic curiosity that you wish to understand how they work?

A GUI is a MAJOR project which is the reason programmers use the libraries used by the operating system's Graphic User Interface. Everything has to work together and it is perfect for object orientated programming techniques. If I wanted, needed, a GUI environment for a project I would use a library or another language like Java, Visual Basic etc.

A simple example might be implementing a button but it is not part of a proper GUI environment.

Code: Select all

screenres 640,480,32
dim as integer mx,my,mb,ox,oy  'mouse variables
dim shared as uinteger ink,paper
ink = rgb(0,0,0)  'black ink
paper = rgb(255,255,255) 'white paper

dim as integer exitFlag   'flag to end program loop set by exit button

type BUTTON
    as integer  x
    as integer  y
    as integer  w
    as integer  h
    as uinteger fg  'forground color
    as uinteger bg  'background color
    as string   t
end type

dim shared as BUTTON btnExit

'initialize button data
btnExit.x = 320
btnExit.y = 240
btnExit.w = 71
btnExit.h = 31
btnExit.fg = rgb(10,10,10)
btnExit.bg = rgb(255,255,0) 'yellow
btnExit.t = " EXIT "

sub drawButtons()
    line (btnExit.x,btnExit.y)-(btnExit.x+btnExit.w,btnExit.y+btnExit.h),btnExit.bg,bf
    line (btnExit.x,btnExit.y)-(btnExit.x+btnExit.w,btnExit.y+btnExit.h),btnExit.fg,b
    draw string (btnExit.x+12,btnExit.y+13),btnExit.t
end sub

sub update()
    color ink,paper    'black ink, white paper
    screenlock
    cls                'implement colors clear screen
    drawButtons()
    screenunlock    
end sub

'initialize
exitFlag = 0

'wait for button event
do
    update()   'update display
    
    getmouse mx,my,,mb
    ox = mx
    oy = my
    if mb = 1 then
        'check for mouse down over something event
        if mx>btnExit.x and my>btnExit.y and mx<btnExit.x+btnExit.w and my<btnExit.y+btnExit.h then
            exitFlag = 1
        end if

    end if

loop until exitFlag = 1
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: I want to learn control programming from [Ground-UP]

Post by MichaelW »

I’m assuming that you mean API controls in an API window, and that “from ground-up” means creating everything at run time with CreateWindowEX. A very simple example:

Code: Select all

''=============================================================================
#define WIN_INCLUDEALL
#include "windows.bi"

#define IDC_BUTTON  101
''=============================================================================


function WindowProc( byval hWnd as HWND,_
                     byval uMsg as uint,_
                     byval wParam as WPARAM,_
                     byval lParam as LPARAM ) as LRESULT

  static as HWND hwndButton
  dim as PAINTSTRUCT ps
  dim as integer style

  #define BASE_STYLE WS_CHILD or WS_VISIBLE

  select case uMsg

      case WM_CREATE

          style = BASE_STYLE or WS_TABSTOP or BS_PUSHBUTTON

          hwndButton = CreateWindowEx( 0, _
                                       "BUTTON", _
                                       "OK", _
                                       style, _
                                       58, _
                                       70, _
                                       80, _
                                       30, _
                                       hWnd, _
                                       cast(HMENU,IDC_BUTTON), _
                                       0, _
                                       0 )

      case WM_COMMAND

          select case loword(wParam)
              case IDCANCEL
                  PostQuitMessage( null )
              case IDC_BUTTON
                  PostQuitMessage( null )
          end select

      case WM_PAINT

          BeginPaint( hWnd, @ps )
          EndPaint( hWnd, @ps )

      case WM_CLOSE

          PostQuitMessage( null )

      case WM_DESTROY

          DestroyWindow( hWnd )

    case else

          return DefWindowProc( hWnd, uMsg, wParam, lParam )

    end select

    return 0

end function

''=============================================================================
'' Start of implicit main.
''=============================================================================

dim as HWND hWnd
dim as MSG wMsg
dim as integer wx, wy, nWidth, nHeight
dim as WNDCLASSEX wcx
dim as string className = "test_class"

with wcx
  .cbSize = sizeof( WNDCLASSEX )
  .style = CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
  .lpfnWndProc = cast(WNDPROC,@WindowProc)
  .cbClsExtra = null
  .cbWndExtra = null
  .hInstance = GetModuleHandle( null )
  .hbrBackground = cast(HBRUSH,COLOR_WINDOW + 1)
  .lpszMenuName = null
  .lpszClassName = strptr( className )
  .hIcon = LoadIcon( null, IDI_APPLICATION )
  .hCursor = LoadCursor ( null, IDC_ARROW )
  .hIconSm = 0
end with

RegisterClassEx( @wcx )

nWidth = 200
nHeight = 150
wx = (GetSystemMetrics( SM_CXSCREEN ) / 2) - nWidth / 2
wy = (GetSystemMetrics( SM_CYSCREEN ) / 2) - nHeight / 2

hWnd = CreateWindowEx( WS_EX_OVERLAPPEDWINDOW,_
                       strptr( className ),_
                       "Test",_
                       WS_OVERLAPPED or WS_SYSMENU,_
                       wx, wy, nWidth, nHeight,_
                       null, null,_
                       GetModuleHandle( null ), null )

ShowWindow( hWnd, SW_SHOWNORMAL )
UpdateWindow( hWnd )

do until( GetMessage( @wMsg, null, 0, 0 ) <= 0 )
    if IsDialogMessage( hWnd, @wMsg ) = 0 then
        TranslateMessage( @wMsg )
        DispatchMessage( @wMsg )
    end if
loop

''=============================================================================
Sorry, no time to comment the code.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: I want to learn control programming from [Ground-UP]

Post by HACK3R ADI »

Sir,I prefer to do everything from scratch and I also wanted to learn How/How To/WHY I always wanted to learn new thing and I wanted ti do it from extreme ground-up even without using line() of FB

And Thank you to all for giving your precious time to my post
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: I want to learn control programming from [Ground-UP]

Post by Richard »

HACK3R ADI wrote:So can anyone guide me where to go.......please help me..
A GUI from the ground up will take you about 10 years. Rather than starting with FB you should consider beginning with assembler. FB is really a runtime library, so assembler is much more fundamental than FB.

There are many people who can help you use FB, but you can only be helped if you can ask a specific question.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: I want to learn control programming from [Ground-UP]

Post by HACK3R ADI »

@Richard
Sir I asked It as a curiosity of Mie and I can spend 10 years to learn it to clear my curiosity

A quote:
"Easy way is easy but it will mislead you in your way and difficult way is full of thorn but it will get you to your destination"
marcov
Posts: 3504
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: I want to learn control programming from [Ground-UP]

Post by marcov »

HACK3R ADI wrote:Sir,I prefer to do everything from scratch and I also wanted to learn How/How To/WHY I always wanted to learn new thing and I wanted ti do it from extreme ground-up even without using line() of FB
Start by reading MSDN? IIRC for the core sets there used to be CHMs available, that makes it easy to read (and reread) everything in order.
HACK3R ADI
Posts: 27
Joined: Jun 17, 2012 10:16

Re: I want to learn control programming from [Ground-UP]

Post by HACK3R ADI »

MSDN have nothing of my interest and it's win32 based
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: I want to learn control programming from [Ground-UP]

Post by Gonzo »

if you want to write a GUI system yourself then:
1. learn to code
2. write code, games, programs
3. learn about UIs, systems and managing projects
4. write GUI system

or.. since you're just going to skip to 4 anyway
just write your GUI with whatever tools you feel like
it doesnt look like anyone here can help you with that, except to start with a rectangle and some user input
get fonts working... all that jazz
im sure googling for "graphical user interfaces" can tell you all about what you want to do
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: I want to learn control programming from [Ground-UP]

Post by Richard »

@ HACK3R ADI
Do you have a question about FreeBASIC ?
leodescal
Posts: 165
Joined: Oct 16, 2009 14:44
Location: Jodhpur, Rajputana, Empire of Aryavart
Contact:

Re: I want to learn control programming from [Ground-UP]

Post by leodescal »

Want to learn how to drive before you can speak or even walk? Just imagine what would happen if a baby is given Ferrari in mid road.

Everything have steps. You are targeting one thing -"I want to make my own!" and this shows your impatience. I have never seen such a person with any success(even a near success) in anything.

lol. Just imagine what what have happened if your teacher tried to teach you how to write a great book before you can even write 'A' properly. You have to be the master of C(well if you can do this, assembler like FASM would be best). Have to master win32. Learn the internals of you OS well.

And I have no aim to just condemn you. You are just at a wrong place. FASM forum would be a better place- http://board.flatassembler.net/
Kot
Posts: 336
Joined: Dec 28, 2006 10:34

Re: I want to learn control programming from [Ground-UP]

Post by Kot »

You can find many examples here:

Code: Select all

http://qbasicgui.datacomponents.net/
D.J.Peters
Posts: 8642
Joined: May 28, 2005 3:28
Contact:

Re: I want to learn control programming from [Ground-UP]

Post by D.J.Peters »

Hello kot,
I never saw this big collection of home made text and gfx gui's before.
After viewing 50+ screen's feeling like in the 80th's year. :-)

Thanks for sharing.

Joshy
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: I want to learn control programming from [Ground-UP]

Post by albert »

The best way to go , is start from scratch and invent your own API..

Windows API uses tons of builtin variables and function calls , that you have to learn about..
And then when you look on the Microsoft MSDN Library web-site, it leads you round in circles without explaining what you entered as a question.

Microsoft doesn't want anyone programming, unless they first went to a multi-thousand dollar Micorosoft programming course.

According to Borland each control needs to be self aware and know how to draw itself and return a click or keypress to the parent and then the parent decides what to do with the message.( from the Borland turbo C++ 3.0 manual )

Good luck !!!
I'm also working on developing a full-blown API..


If you want to make games:
http://www.toymaker.info/Games/html/windows_api.html

Otherwise:
http://www.relisoft.com/win32/index.htm

There are still a lot of unanswered questions , and you have to port the examples to FB from C or C++ or VB
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: I want to learn control programming from [Ground-UP]

Post by albert »

If you want to start writing Windows apps, here is a link to the SDK for windows 8

http://msdn.microsoft.com/en-us/windows ... p/hh852363

I think the headers would need to be converted to FreeBasic..

The Software Developers Kit (SDK) should have all the help files you need..
Post Reply