PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: John Messingham on September 19, 2004, 08:53:27 PM

Title: Passing Control
Post by: John Messingham on September 19, 2004, 08:53:27 PM
Hi,

I am not sure if this is a firefly question or not. I am implementing a logon screen into my new app. If I cancel the logon then the program exits ok. If I click ok, the main screen is displayed.

The problem is that I want to close the logon screen so it is not displayed behind the main form. I have tried the ff_control_showstate hwnd_frmlogon %sw_hide. When the program returns to the logon screen, it seems to end ok. The problem is that the application is still active, and will not run again.

I hope that is clear to someone.

Many Thanks
Title: Passing Control
Post by: Anonymous on September 19, 2004, 10:29:16 PM
John,

I think you are looking for:

FF_CloseForm HWND_frmlogon

Hope this helps,

John Thompson
Title: Passing Control
Post by: John Messingham on September 19, 2004, 10:49:12 PM
Hi,

I have tried that one.

If I close the logon form prior to showing the main form, when I exit the app, it stays active.

If I use the ff_closeform after showing the main form using modal, the logon screen stays active behind the main form. If I use the ff_closeform after showing the main form non-modal, the program justs exits.

The words chicken and egg come to mind.

I am new to firefly and powerbasic, so I may just be missing something.

Many Thanks
Title: Passing Control
Post by: TechSupport on September 20, 2004, 12:02:56 AM
Hi John,

There are several ways that I think you can tackle this problem. I think that you are on the right track. When you display your 'main screen' then display it as modeless. In that Form's WM_CREATE message you should make the function call to hide the initial logon screen.

In the WM_DESTROY message for the 'main screen' Form, make a call to close the logon form:
FF_CloseForm HWND_frmlogon

Therefore, when your main screen terminates, then so does your logon form.

If that doesn't work for you then please let me know and we'll dream up another scenario to fix it.
Title: Passing Control
Post by: Roger Garstang on September 20, 2004, 02:07:39 AM
I think I'm missing something here.  If you close your logon form, why is your main form opening?  And by close, do you mean with the X in the corner, the System Menu, or Al-F4...or are you "closing" when the cancel button is pressed?

Sounds to me like you are spawning the Logon Window off in WM_CREATE of the main window or making the code for OK/Cancel branch apart and back again where both open the main form or something.  Maybe even the main is hidden and you process OK of the Login window by showing it?

The logon form needs to be your startup form, use FF_CloseForm to close the form on pressing Cancel and either block closing the form with methods other than Cancel or process them the same way so OK has its own message that checks the login and password and opens the main form.  I'd have to see at least pseudo code or something to put it in terms of the actual code, but if the app stays running a form is open that shouldn't be.
Title: Passing Control
Post by: John Messingham on September 20, 2004, 10:13:42 AM
Hi,

My logon form is the startform.

If the cancel button is clicked the program exits ok.

If the ok button is clicked and valid details entered, the main form is now shown modless. I then hide the logon form with the ff_control_showstate hwnd_frmlogon, %SW_Hide.

In the frmmain_wm_destroy function I now have the command ff_closeform hwnd_frmlogon.

Unfortunatly, when I exit the app it is still left running in background.


Many Thanks
Title: Passing Control
Post by: TechSupport on September 20, 2004, 11:30:51 AM
Hi John,

I just built a quick little demo and you're right - it does stay in memory. Here is what you need to do to fix that.

When you go to show the 'main screen' form as modeless, make sure that you specify the owner window to be the Windows Desktop rather than the Logon form.

e.g.
frmMain_Show %HWND_DESKTOP, 0

or

frmMain_Show 0, 0
Title: Passing Control
Post by: TechSupport on September 20, 2004, 11:46:38 AM
... Here is another method that I have suggested to users in the past. This method will show the Main Screen first and then popup the Logon screen as soon as the Main Screen shows. This approach is okay if you don't mind the user seeing the Main Screen during logon.

Steps:
- Set the 'Main Screen' form as the Startup Form.

- Create a global equate:   %MSG_SHOWLOGON = %WM_USER + 1

- In the WM_CREATE message handler for the 'Main Screen' place the following code:

If wMsg = %MSG_SHOWLOGON Then
  frmLogon_Show hWndForm, 1
End If

That will show the Logon form as modal with the 'Main Screen' as the parent window.

- In order to actually initiate the showing of the Logon form you need to PostMessage rather than SendMessage the user defined message. This is because a SendMessage will send the message and wait for a response. PostMessage just sends the message and then continues on. This is much like the PowerBasic Shell command and function. If we use SendMessage then the WM_CREATE message will not complete until the Logon form is closed - we don't want that. Using PostMessage allows the Main Screen to complete creating and then it can process the user message. Therefore, in the WM_CREATE message handler for the 'Main Screen' place this code:

PostMessage hwndForm, %MSG_SHOWLOGON, 0, 0


That approach works well and I have used it in one of my applications for a long time.
Title: Passing Control
Post by: John Messingham on September 20, 2004, 12:08:16 PM
Using the %HWND_DESKTOP method works, I will look at the other method as well. All code samples are welcome at this point, they will assist me get to grips with powerbasic.

Many Thanks
Title: Passing Control
Post by: TechSupport on September 20, 2004, 12:33:14 PM
Hi John,

If I remember correctly, you are migrating from Visual Basic. I was a huge Visual Basic user until I switched to PB. It took a while to learn PB because it is much more low level, but the pay off has been fantastic. Being able to program at the Windows API level means that you don't have any of the limitations and slowness that VB forces on you. Granted, VB was so easy to use to create GUI interfaces and get an app up and running quickly. Also, it's 3rd party ActiveX controls made life easier as well.... but distribution and installation issues were always a problem. Having found PB, I'll never look back to VB.

:)
Title: Passing Control
Post by: John Messingham on September 20, 2004, 01:08:52 PM
I agree with the distribution and installation issues, that is why I am adding powerbasic to my list of development tools. I have invested a lot of time and money into vb and all the addons, but I will only be using them for existing applications and bespoke work from now on.

This all started when I purchased the Cheetah db system as a replacement for the mdac hell.

Many Thanks
Title: Passing Control
Post by: Roger Garstang on September 20, 2004, 04:41:57 PM
Yup, I forgot about %HWND_DESKTOP too.  I just figured that was a given.  And I would close the logon instead of hide it.
Title: Passing Control
Post by: TechSupport on September 20, 2004, 06:10:29 PM
Quote from: Roger GarstangYup, I forgot about %HWND_DESKTOP too.  I just figured that was a given.  And I would close the logon instead of hide it.

I don't think that closing the logon form will work in this case. The logon form is the Startup Form and closing it would mean that the application would end. (I am not at my development computer - this is from memory).
Title: Passing Control
Post by: Roger Garstang on September 20, 2004, 09:17:41 PM
Yup, it makes the whole app close.  Usually all my apps have some loop or thread running and when I click Cancel or Ok they don't do anything but disable themself, then the loop checks each iteration to see if the control is disabled and then exits.  That way there are no globals...at least from our point of view and it prevents multiple clicks.
Title: Closing Main Form
Post by: Anonymous on October 03, 2004, 07:32:47 PM
I am using the method described herein to close the main form (a logon form) in my project.  I wasn't sure from reading this thread, but is this a temporary fix or the suggested way to close any and all main forms?

I am starting a second project that has only one form that can be opened multiple times.  Is the hide method the recommended way to close these forms also?

Thanks!

John
Title: Re: Closing Main Form
Post by: TechSupport on October 03, 2004, 07:43:39 PM
Quote from: jptchiI am using the method described herein to close the main form (a logon form) in my project.  I wasn't sure from reading this thread, but is this a temporary fix or the suggested way to close any and all main forms?

A lot depends on the organization of your project. In this case, we have a Logon form and then the main form. If the Logon form is set as the Startup Form then you can not 'Close' it, you must hide it. Closing it will terminate the application. There are two methods described in this thread to handle a Logon form. Choose whichever you like best.

QuoteI am starting a second project that has only one form that can be opened multiple times.  Is the hide method the recommended way to close these forms also?
If you only have one Form then you will need to Hide rather than Close. Like I said earlier, if you Close a Form that is designated as a 'Startup Form' then your application will end.