#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    7
    Rep Power
    0

    Borland C++ Builder with win32api problem


    Hi guys.

    i am creating a new form. and i dont want to use the Show() method provided by BCB so i use

    ShowWindow(hWnd, SW_SHOW);

    after i do that the new form opens but the problem is that, the form is blank. NON of its buttons or textboxes etc etc appear!

    i think we need to repaint, so after that i even did

    SendMessage(hWnd, WM_SETREDRAW, 1, 0);
    InvalidateRect( hWnd, NULL, TRUE );
    UpdateWindow(hWnd);

    BUT NO LUCK. PLZ HELP GUYS. THANKS.

    invictus
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    How are you creating the controls on the form? Have you made the form the owner/parent of the child controls? Also, what's the reason for not using the Show() method?
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    7
    Rep Power
    0
    Originally Posted by Scorpions4ever
    How are you creating the controls on the form? Have you made the form the owner/parent of the child controls? Also, what's the reason for not using the Show() method?
    Hi!

    Yes i have made the form owner/parent of the child controls.

    i am not using show() because

    i want to use ShowWindow(hWnd, SW_SHOWNOACTIVATE);

    this will display the new form without activating it and keeping the focus to the main form.

    I had done this way in VB and it worked but it doesnt work here. YES, Its showing the form without activation but the buttons and all the controls of the new form are gone. The new form doesnt even have eventhandlers as a result when i click on X of the new form, it will not close!

    Another thing.
    When I set the new window's property to Visible=true by default, it works and shows all the buttons and stuffs even when i call ShowWindow(hWnd, SW_SHOWNOACTIVATE); but this time the new window is shown Activated (similar to Show() method)!!!

    Are there any other ways to Show the form without activating it and keeping the focus to the previous window?

    I think this is the way, but what might i be doing wrong.

    If you have a better way, please suggest.

    Thanks In Advance

    Invictus
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Why not use SetFocus() right after Show(), so that the focus comes back to the first form immediately after the second form is displayed. The code could go something like this:
    Code:
    TForm2 *frm2;
    
    frm2 = new TForm2(this);
    frm2->Show();      // Show the new form and ...
    this->SetFocus();  // bring back the focus to our form.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    7
    Rep Power
    0
    Hi,

    Thanks for the idea. I have tried that before. It works, but i just wanted to learn a better way, because the method u mentioned will make the new form take focus for a fraction of a second

    Is it possible to eliminate that as well ?

    Anyway that method should be okay i guess.

    Thanks.

    Invictus
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    3
    Rep Power
    0

    One possible solution


    I'm having the same problem. Did you find any solution yet?

    The reason none of the buttons apear on the form is because their visible property is set to false. This property is set to true when you set their parents visible property to true. When using SWM_SHOWWINDOW, windows will display the window, send a repaint message on the controls, but none of them will actually repaint itself, because they check their visible property (which is set to false) before displaying.
    One solution i could think of is to set all controls owned by the form to be visible:

    for all ChildControls do
    Controls[i]->Visible = true;

    and then
    ShowWindow(Handle, SW_SHOWNOACTIVATE)

    But this is not a good approach, because you will force all controls to be visible, and you probably have some visible controls too.

    Please let me know if you found another solution.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    3
    Rep Power
    0

    Exclamation Another solution


    Ahh, the previous post is bad

    What I did to solve the problem is to set the form as visible. In the constructor, I call
    SetWindowPos(Handle, HWND_BOTTOM, Left, Top, Width, Height, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

    which hides the window. So we have a hidden window, but with the visible property set to true. Then, I control the form just with SetWindowPos with SWP_HIDEWINDOW or SWP_SHOWWINDOW. Do not call Close() on this form!!! Just SetWindowPos. By doing so, the components on the form will repaint themself when calling Repaint() on the form.

    I hope I explained this well

IMN logo majestic logo threadwatch logo seochat tools logo