Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    So finally, using show is impossible basically (the way I am doing things)? I have to use showmodal?
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Originally Posted by DLPB
    So finally, using show is impossible basically (the way I am doing things)? I have to use showmodal?
    That is too simplistic; but before finding some complicated way to still use Show
    we need to know why ShowModal (the simplest solution) is not acceptable.
    If show is required then you have to add something in the thread that keeps the thread busy
    doing something until you are ready to close the form.

    Clive
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    Originally Posted by clivew
    That is too simplistic; but before finding some complicated way to still use Show
    we need to know why ShowModal (the simplest solution) is not acceptable.
    If show is required then you have to add something in the thread that keeps the thread busy
    doing something until you are ready to close the form.

    Clive
    The reason why I don't like showmodal is really... small. But I like to do things properly. The small issue here is that when using Showmodal, I do not know how to make the form Hide from the beginning. A modal form cannot start up invisible. It will give an error. So, I have to show it first, then onpaint tell it to hide. The result is that it flashes on and off (but obviously still works in the background).

    It looks unprofessional basically.
  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Well, why didn't you say so from the start

    The normal way to use a form this way is to create it on demand e.g.

    Code:
    procedure TForm1.DoConfig;
    var
      form2: TForm2;
      _mr: ModalResult;
    begin
       form2 := TForm2.Create(nil);
       try
         _mr := form2.ShowModal;
         //put code here that depends upon the value of _mr
       finally
          form2.Free;
       end;
    end;
    You do not necessarily need the two local variables form2 and _mr; but that is for another day.

    NOTE: I have not syntax checked the above code.

    Clive
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    Doesn't appear to work even when I corrected it (I think i did). Also, the form I make must be able to be brought back with shortcut and then hidden again by the user. At moment I can do that but as I say modal window has to be shown first.

    I am not sure if your code was designed for that also?
  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    It works.

    Of course, your context might be quite different, in fact, from what you are describing it is.
    What prevents you from creating the form each time you want it?
    Why do you have to hide it?
    If you need it to be permanent (hide/show and not create/free) why are you creating it in a thread?

    Clive
  12. #22
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    I explained why before, if I don't create a new thread, bass.dll will crash. It must be initialised and used on a separate thread to the game. I am also analysing changes in memory (of Final fantasy 8) from the created form in the created thread (via a TTimer).

    The menu is for user to change volume and display info, its also on the form.

    I need it hiding until user presses a shortcut key, then it displays, then if they press again it hides.

    At the moment It does this, but the form flashes on first and causes the game to lose focus and they have to reclick the game window, not to mention flashing on and off when the game starts looks bad.

    The code I have so far is:

    begin


    Code:
    CreateThread(nil,0,@funcStart,nil,0,dwtemp);
    In the main DLL begin end. and the procedure is

    Code:
    procedure funcStart;
    begin
    Form1 := tForm1.create(nil);
    form1.showmodal;
    end;
    Form 1 is the form already designed and made with the bass code and ttimer and other code present on it. Form1 does everything. It analyses memory, allows user to change volume and also plays the game music (vorbis ogg) via bass.dll using delphi bass.pas

    The form MUST be present at all times, since it is working to provide the game music and checking memory addresses. See here for finished product:

    http://www.youtube.com/watch?v=_ht1bzkqQAU
    http://www.youtube.com/watch?v=bTQ4XYcWHdU

    Can't see menu there though he doesnt bring it up and he is using fraps for that. As you can see, music works perfectly and at this moment in time the form is hidden. It is only the initial show that is the problem. The form has to be in operation and for that I have to show it. If I could have the form use showmodal but not actually display it on FIRST show only, that would be cool. So far everything I have tried it shows for a fraction of a second beforehand. It cannot create in the background without actually displaying to the user.

    edit. Another work around (for the lost focus) would be for me to somehow make ff8 focused again, but how do I do that from the dll thats been attached to the main game thread?
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    Well the sloppy way around this is to set the alphablend to 0 and then make it 255 afterwards but that still doesnt address the loss of focus.

    I suppose I could do that the cheapo way as well with SetForegroundWindow( HWND )

    edit.

    I have done this the sloppy way. Onpaint I set the foreground window by SetForegroundWindow(FindWindow(NIL,'FINAL FANTASY VIII'));

    And I set the window to be alphablend 0 on a first show, eliminating the flash.
  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    I suppose I could do that the cheapo way as well with SetForegroundWindow( HWND )
    An option I would have considered also given the detailed explanation.

    The other approach that I would take myself (and I do not know enough about your situation to know if it makes sense)
    would be to move all the management and persistence into a custom class and create the form on demand,
    as per my example, simply to manipulate the properties of my custom class.

    Or perhaps use a TDataModule for all the code and create the form on demand.

    Clive
    Last edited by clivew; October 30th, 2012 at 12:02 PM. Reason: Added the TDataModule idea
  18. #25
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    19
    Rep Power
    0
    Originally Posted by clivew
    An option I would have considered also given the detailed explanation.

    The other approach that I would take myself (and I do not know enough about your situation to know if it makes sense)
    would be to move all the management and persistence into a custom class and create the form on demand,
    as per my example, simply to manipulate the properties of my custom class.

    Or perhaps use a TDataModule for all the code and create the form on demand.

    Clive
    Thank you for your input on this thread. It is appreciated. I will certainly look into TDataModule at a later time
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo