Results 1 to 20 of 20

Thread: How to create VB form?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    How to create VB form?

    Hello,

    Well, I'm searching for creating a standard VB form with only code and without make an instance of another form designed in VB development interface.

    How can I do, please?


    Thanks in advance.

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to create VB form?

    http://www.pscode.com/vb/scripts/Sho...67548&lngWId=1

    you might want to take a look at the Sub_Main in the core module of this app

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    Fundamentaly this is what I search : creating form, except I can't do that in an object module : when I used createwindowex api and getmodulehandle (with vbnullstring to identify the object module) to inform the first api module link, well, all VB developpment interface go down ! Why?

    Do you also know a easy way to make form?

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to create VB form?

    why did it crash? because you did something wrong.

    is there an easier way? yes, using the IDE - that's the point of using VB, it's RAD

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to create VB form?

    What, in your module, do you need to use that is related to your form?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    is there an easier way? yes, using the IDE - that's the point of using VB, it's RAD
    Well I continue to search every solution while I haven't one that is satisfied me. I don't want to add another file for a form only to use it as a virgin one to support GDI+ operations. I want to create one dynamicaly. One solution is to make an instance of one existing, but I want a virgin one with no controls inside it (in reason of loading); I imagined that I could do a form object from VB librairies but it seems you can't do that easier than creating an instance of an common object !

    I have some troubles of VB as soon as VB is reading the line with createwindowex api. I may did something wrong, I don't often use this particular api ; I only paste this part of code from a standard module to an object module. For me, I've respected all syntax. VB don't show debug dialog, and only Xp shows the standard stop application window.
    I suppose that there's something wrong with getmodulehandle (in bold), and my feeling is that VB is overbooked or something like that in memory/handle operations... But how to run perfectly this code in my object module?

    I post the function extracted from TheBigB's link :
    VB Code:
    1. Public Function WinCreate(winClassInfo As String, winAppInfo As String, ByRef winProcAddress As Long) As Boolean
    2.   Dim hh As Long
    3.   'store class name
    4.   winClassName = winClassInfo
    5.   'create class info
    6.   With winClass
    7.     .style = 0&
    8.     .lpfnwndproc = winProcAddress
    9.     .hInstance = App.hInstance
    10.     'default icon
    11.     .hIcon = LoadIconByNum(0&, IDI_APPLICATION)
    12.     'arrow-style mouse cursor
    13.     .hCursor = LoadCursorByNum(0&, IDC_ARROW)
    14.     .hbrBackground = COLOR_WINDOW
    15.     .lpszClassName = winClassName
    16.     .lpszMenuName = vbNullString
    17.     .cbClsextra = 0&
    18.     .cbWndExtra2 = 0&
    19.   End With
    20.   'register our class
    21.   winRegResult = RegisterClass(winClass)
    22.   'ok?
    23.   If Not winRegResult = 0 Then
    24.     'create window
    25.      WinHandle = CreateWindowEx(WS_EX_ACCEPTFILES, winClassName, winAppInfo, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0&, 0&, [B]GetModuleHandle(vbNullString)[/B], ByVal 0&)
    26.     If Not WinHandle = 0 Then
    27.       'show
    28.     ''  ShowWindow winHandle, SW_SHOWNORMAL
    29.       'bring to front
    30.      '' SetForegroundWindow winHandle
    31.       'refresh
    32.     ''  UpdateWindow winHandle
    33.       'done
    34.       WinCreate = True
    35.     Else
    36.       'create failed
    37.       WinCreate = False
    38.     End If
    39.   Else
    40.     'can not register class
    41.     WinCreate = False
    42.   End If
    43. End Function

    What, in your module, do you need to use that is related to your form?
    Sorry I don't understand what you mean? Please could you reformulate?
    Last edited by IsWorking; Feb 19th, 2007 at 09:16 AM.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to create VB form?

    It is not clear to me why you need to do this.
    Quote Originally Posted by IsWorking
    Well, I'm searching for creating a standard VB form with only code and without make an instance of another form designed in VB development interface.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    I don't know if you have posted your message when I posted mine.

    Two major reasons to search that : the challenge to perform it, and the wish to reduce the number of source files. I only need a visible form without title, buttons, border or other controls that it could have.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: How to create VB form?

    One of the reasons the app crashed is that you can't run it in the IDE - there's no way to stop it other than using the IDE's stop button, which causes the IDE to crash since the window is subclassed. Put a command button on the form and use it to turn off the subclassing before destroying the window.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to create VB form?

    Quote Originally Posted by IsWorking
    I don't want to add another file for a form only to use it as a virgin one to support GDI+ operations
    Why not?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to create VB form?

    Create a formless form was my very first thread/post on VBF

    http://vbforums.com/showthread.php?t=67951
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    I use getmodulehandle or instead of that app.hinstance, the end is the same : crashing !

    Quote Originally Posted by Al42
    One of the reasons the app crashed is that you can't run it in the IDE - there's no way to stop it other than using the IDE's stop button, which causes the IDE to crash since the window is subclassed. Put a command button on the form and use it to turn off the subclassing before destroying the window.
    Well I don't known I'm subclassing something. I've thought that you can subclass only with callwindowproc api? How do I'm subclassing in my function please?

    In fact, in the original application where the piece of code has been extracted, the program is running correctly under IDE! The problem is before to destroy my window, I need to create it ! I haven't the time to ask me if I click on vb stop button or on window close button ; in fact i can't seen anything like a form which appears on screen except crash dialog!

    Create a formless form was my very first thread/post on VBF
    How did you do? could you explain me why I don't manage myself? Have you written your code in a standard module or an object module?

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: How to create VB form?

    Quote Originally Posted by IsWorking
    Well I don't known I'm subclassing something. I've thought that you can subclass only with callwindowproc api? How do I'm subclassing in my function please?
    Right here
    VB Code:
    1. Public Function WinCreate(winClassInfo As String, winAppInfo As String, ByRef winProcAddress As Long) As Boolean
    where you're creating the window with a proc. The IDE can't handle things correctly if there's a call to a procedure and you cause the program to close unexpectedly, making that procedure unavailable, but leaving something still hooked to it. If a WM_CLOSE message is sent to the window after it's been destroyed, the message has no procedure to handle it, so the IDE eventually crashes.
    Last edited by Al42; Feb 20th, 2007 at 11:10 AM.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to create VB form?

    The code is im my link I posted. Did you try it? Place it in a standard Module and set the sub main as the startup object.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to create VB form?

    @IsWorking: would you mind answering my question (if just purely for my curiosity) about why you need to create the form using API instead of just adding a blank one to your project. It's so much easier - and I can't see any (valid) reason why you wouldn't do it that way...

  16. #16
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: How to create VB form?

    I'm not 100% sure whether it is true, but check out the project in the link I've posted before. I'd bet it would render much faster in a API created form.

    I don't want to add another file for a form only to use it as a virgin one to support GDI+ operations. I want to create one dynamicaly. One solution is to make an instance of one existing, but I want a virgin one with no controls inside it (in reason of loading); I imagined that I could do a form object from VB librairies but it seems you can't do that easier than creating an instance of an common object !
    (you might have skipped this part)

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    Quote Originally Posted by Al42
    Right here
    VB Code:
    1. Public Function WinCreate(winClassInfo As String, winAppInfo As String, ByRef winProcAddress As Long) As Boolean
    where you're creating the window with a proc. The IDE can't handle things correctly if there's a call to a procedure and you cause the program to close unexpectedly, making that procedure unavailable, but leaving something still hooked to it. If a WM_CLOSE message is sent to the window after it's been destroyed, the message has no procedure to handle it, so the IDE eventually crashes.
    I don't really understand :
    I put this piece of code in an object module where a link in the initialise class sub call the function.
    When I'm running the program with the VB step-by-step function, the program crashes when the createwindowex api call line is colored in yellow... I never see at this step any instructions to close the window(and I don't stop the program of course), I haven't yet build the first form!?


    bushmobile, It could be very easier to create my form in the IDE but I really want to program it myself - it could not be so much impossible ! I don't want to add a file (and more a virgin form) in my source file collection.
    I would be able to use one of which I've already designed in IDE and make instances of it to create dynamicaly others forms, but all of them have already controls !
    Last edited by IsWorking; Feb 22nd, 2007 at 09:43 AM.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: How to create VB form?

    Quote Originally Posted by IsWorking
    I don't really understand :
    I put this piece of code in an object module where a link in the initialise class sub call the function.
    When I'm running the program with the VB step-by-step function, the program crashes when the createwindowex api call line is colored in yellow.
    The window is created with a handler that's subclassing the window. The IDE CAN NOT handle stepping through subclassing without special code (Bushmobile has an example in the code bank).
    I never see at this step any instructions to close the window(and I don't stop the program of course), I haven't yet build the first form!?
    You don't have to stop the program or close the window to cause a crash. If you create the window with a routine of yours handling the messages to that window (which is what you're doing), and the program stops (which is what single stepping is doing), the IDE crashes. Actually understandiong what's happening is a lot easier if you've worked in assembly and written TSRs or any other code that's hooked itself into a linked list. You can't do part of it and stop - all the code has to execute by itself to the point that everything is set up first - then you can step through it, which can't be done in the VB IDE if you're single stepping through creating the window.
    I don't want to add a file (and more a virgin form) in my source file collection.
    Just write all your code in your file form. You MUST have at least 2 files for any VB project.
    I would be able to use one of which I've already designed in IDE and make instances of it to create dynamicaly others forms, but all of them have already controls !
    You can do that with a form too.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  19. #19
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to create VB form?

    Quote Originally Posted by IsWorking
    bushmobile, It could be very easier to create my form in the IDE but I really want to program it myself - it could not be so much impossible ! I don't want to add a file (and more a virgin form) in my source file collection.
    Yes I'm aware you said that, I am curious as to the reason why you don't want to do that. How do you think it will be deterimental to your project?

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    157

    Re: How to create VB form?

    You don't have to stop the program or close the window to cause a crash. If you create the window with a routine of yours handling the messages to that window (which is what you're doing), and the program stops (which is what single stepping is doing), the IDE crashes. Actually understandiong what's happening is a lot easier if you've worked in assembly and written TSRs or any other code that's hooked itself into a linked list. You can't do part of it and stop - all the code has to execute by itself to the point that everything is set up first - then you can step through it, which can't be done in the VB IDE if you're single stepping through creating the window.
    I beg your pardon, but it's not very clear for me :
    I've understood that my sub is handling a window but what is the "single stepping"?
    What does mean TSR?

    What could be a solution for this ?

    I don't want to add forms and forms. My project is to make a splash screen with transparent png files and however keep my controls on the splash. Png need a form for layering but controls like labels disappear. Well, bushmobile's transparent form project in his codebank is a solution to manage to have png and controls. In conclusion I would need three forms (because transparent forms need already two, why?) only to have only one splash, one form for the user. it's a lot, isn't it? I found some pieces of code on internet and I was exciting to avoid me to multiply forms. But I can't perform that and I want to know why and how I can manage to do that?

Posting Permissions

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



Click Here to Expand Forum to Full Width