Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Need Help on making Window creating class

  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    64
    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,313
    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
    64
    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
    64
    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,313
    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

  7. #7
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    64
    Rep Power
    9
    @Eros,
    Hi, Thanks for this well explained reply. I got a basic idea that i need to set the user's callback function's address with the help of SetWindowLongPtr function. And the flag is "GWLP_USERDATA". Am i right. But i am confused with this idea. This is my assumption, please correct me if i am wrong.

    This is in my window class.
    1. Register window class
    2. Create window and controls
    3. Write a WndProc function.
    4. In the WM_CREATE msg, use SetWindowLongPtr

    Thats ok, but how do i know that a WM_LBUTTONUP is occurred in the program ? In my concept, OS knows the address of my WndProc function. So it call that function when any events are happen. Say a WM_LBUTTONUP happened, but i didn't write anything related to WM_LBUTTONUP in my WndProc. So how do i route it to user's callback function ? Or do i need to write all possible windows messages in WndProc functon and tell it to call the user's callback function ?

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,313
    Blog Entries
    2
    Rep Power
    10
    I do not want you to go on the wrong track so I will reply under the hypotheses you are asking not for integrating thinBasic script but in general.
    To be able to do something like what we are talking about in thinBasic you need to write a compiled module, impossible inside a script.

    But talking in general, yes what you wrote is the general idea.
    In WM_CREATE of window class callback you setup what you need.
    Then inside window class callback in any message you need to pass to your personalized function, call your function passing WHNDL, MSG, WPARAM, LPARAM, ...
    Another way is to pass all messages to your personalized function returning true/false depending if you have handled the message.
    If yes, just exit
    If no, process the message inside window class callback
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  9. #9
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    64
    Rep Power
    9
    @Eros,
    Hi, Now, i am going to experiment something what i understood from your reply.

  10. #10
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    64
    Rep Power
    9
    @Eros,
    Hi, i am glad to write this because, i just succeeded to bypass WndProc function without setting any special data in window creation time. This is the steps.
    1. I wrote all window creation functions in a module.
    2. I wrote a WndProc function too in that module.
    3. Now user can declare a callback function in their main file. like - SetCallBack(Ptr_of_callback_function). This function call should be done before window creation.
    4. I just used this callback function inside my WndProc function with that pointer.
    5. In my module, i declared some global variables like-
    WinHndl = Window Handle
    WinMsg = a UINT message
    CtlHndl = a Control handle extracted from wParam in WM_COMMAND.
    Now, i am planning to extract control handle from WM_NOTIFY command too.

    But the problems are;
    1. Main window is hung when a second window created.
    2. All windows will close when any of the window is closed.

    Any suggestions how to deal this ? Thanks in advance.

Page 1 of 2 12 LastLast

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
  •