Results 1 to 10 of 14

Thread: Need Help on making Window creating class

Hybrid View

  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    68
    Rep Power
    9

    Need Help on making Window creating class

    Hi,
    I am planning to make a class for making Windows gui easily with the help of win api functions. I am doing this for learning purpose.
    And i wrote code for my class. This is the pseudo code.

    In my class
    1. There is a Window creating method which uses CreateWindoweEx function. Name = Window_Create( )
    Parameters of that method is :
    Window_Title = String
    Pointer of WndProc function = Pointer
    Width & Height, Position = Integer
    WinStyles & WinExStyles = Long

    It has following steps.
    a. Getting the module handle
    b. Declare and fill the WNDCLASS structure.
    c. Registering window class with RegisterClassEx function.
    d. Calling the so called CreateWindoweEx
    e. This method returns the newly created window handle.
    2. A Message Pump Sub routene. Name = MessagePump( )
    It contains a while loop and GetMessage, TranslateMessage, and DispatchMessage functions.

    3. A Sub routene to show the window. Name = ShowForm( )
    It contains ;
    a. ShowWindow function
    b. UpdateWindow function.
    c. MessagePump Sub

    So in my main file looks like this;
    a. Declare a WndProc function.
    b. Create the instance of the class and call the Window_Create method.
    c. Write the complete WndProc function.
    d. Call the ShowForm( ) Sub

    With this setup, i can get almost any window Messages but i couldn't handle the second window. Can anybody guide me to make this class able to handle more than one window ? Thanks in advance.
    Note - I am making this class in FreeBasic language. But i thought that this is a logic problem rather than a language problem. Correct me if i am wrong.

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,338
    Blog Entries
    2
    Rep Power
    10
    Ciao,

    I do not understand if you are asking in order to create a thinBasic script or for developing in Freebasic.
    In thinBasic it is not possible to pass a script Functions pointer to a windows API because there is no compiled function to have a pointer to.
    So using classical RegisterClassEx api passing you window class and inside that a pointer to a function it not possible from a script
    You need program into a language able to create real executables. thinBasic do not create such king of executables.

    But let me know, maybe I misunderstood your request.
    Eros


    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    68
    Rep Power
    9
    Hi Eros,
    Let me explain my question a bit.
    Here is the 'Reason' of my whole question.
    In thinbasic we are using a callback function without any params and we can also use some macros like cbCtl, cbHNDL. I like this style. So i want to implement this style in FreeBasic. And i create my own gui library with windows api functions. But i cant create a callback function setup. I know that behind the scene, a wndproc function is working for us in thinbasic. But it is hidden. Programmer only see and use the callback function. How does it is possible ?

    Edit Note :- By the way, Jose Roca has created a CWstr library for FreeBasic. Its amazing. With that lib, we can easily use dynamic unicode string in our program. I know that you are working on a new version of thinBasic which supports unicode. I think it is worth checking that lib.
    FreeBasic has a fixed length wid string data type. Jose roca made it a fully dynamic unicode string.
    Last edited by kcvinu; 06-03-2018 at 10:24.

  4. #4
    Member zlatkoAB's Avatar
    Join Date
    Apr 2008
    Age
    49
    Posts
    283
    Blog Entries
    1
    Rep Power
    39

    Post

    Eros answer to you properly...
    So if you think to create WindowsClass you must use native compiler.
    If is not problem you may look in Oxygen Basic forum
    where you can find some examples ;

    like:

    Type WNDCLASSEX
     cbSize        as long
     Style         as long
     lpfnwndproc   as long
     cbClsextra    as long
     cbWndExtra    as long
     hInstance     as long
     hIcon         as long
     hCursor       as long
     hbrBackground as long
     lpszMenuName  as long
     lpszClassName as long
     hIconSm       AS long
    End Type
    
    and this:

    Function SetWindow (byval caption as string ,byval Wx as int,byval Wy as int, byval Ww as int, byval Wh as int, byval wparent as int, byval style as int) as int
    inst = GetModuleHandle 0
    'sys hbrush=RGB(250,250,255)
    wcx.cbSize        = sizeof(WNDCLASSEX)
    wcx.style         = CS_DBLCLKS |CS_OWNDC 
    wcx.lpfnWndProc   = &WndProc
    wcx.cbClsExtra    =0
    wcx.cbWndExtra    =0
    wcx.hInstance     = inst
    wcx.hIcon         =LoadIcon 0,IDI_APPLICATION        
    wcx.hCursor       =LoadCursor 0,IDC_ARROW       
    wcx.hbrBackground = CreateSolidBrush(GetSysColor(15))
    wcx.lpszMenuName  = ?0
    wcx.lpszClassName = @"Oxygen"
    wcx.hIconSm       =LoadIcon 0,IDI_APPLICATION 
    
    RegisterClassEx &wcx
    
    I hope that help ..

  5. #5
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    68
    Rep Power
    9
    @zlatkoAB,
    Hi, thanks for your reply. But as i stated my above comment, Registerclass is not my real problem. I am planning to hide WndProc from user. So i need a function which mimics WndProc but hide its complexities. Just like the CallBack function in thinBasic. At first, i thought that RegisterClass will do this trick for me. But after some google search and little experiments, i have realized that my assumption were wrong. Thanks for guiding me to OxygenBasic forum. Let me check.

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,338
    Blog Entries
    2
    Rep Power
    10
    Ciao,

    yes, I always follow Jose development in any forum he posts
    Is like following a great guru always having something to teach and for inspiration.

    Anyway ... back to your question: how do I'm able to use script functions as callbacks?
    The story is long but I will try to short it and then enter in few details if needed:
    • first create your window in the way you prefer
    • when you have your window, inside WM_CREATE message, allocate (once) a pointer into window user data. I use PowerBasic so acceding a dialog user data is as easy as using DIALOG SET/GET ... one of the 8 user data slot PowerBasic give to you
    • what do I allocate to that pointer? a pointer to a user defined type (a structure) in which I store any info I need to recall when needed. In my case actually I store 23 longs (23 * sizeof(long) array)
    • one of those element is a pointer to my script function internal data that the user has decided to use as window callback
    • when your real window callback function is called by the windows message pump, first of all GET your user data allocated during WM_CREATE, get your pointer, get the data you need
    • in my case I get the pointer to the script callback function
    • having that pointer, I can pass event data to my script function


    That's the short story.
    The very long story is about 10k lines of code just for handling windows events

    In any case let me know if you need more details

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. MyClass & MyClassCOM - simple demo of creating module class
    By Petr Schreiber in forum Module Classes
    Replies: 3
    Last Post: 21-05-2013, 00:09
  2. creating my own class
    By ReneMiner in forum thinBasic General
    Replies: 4
    Last Post: 17-11-2012, 20:07
  3. making .ini files
    By sandyrepope in forum INI
    Replies: 3
    Last Post: 20-08-2007, 10:01
  4. making programs pretty
    By sandyrepope in forum Console
    Replies: 9
    Last Post: 13-05-2007, 20:55
  5. making help files for our programs
    By sandyrepope in forum thinBasic General
    Replies: 1
    Last Post: 20-02-2007, 20:18

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •