Mimimized Dialog At Start ??

How do I make an Dialog minimized/hidden at the start of the application... ??
TYBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brain2000Commented:
Do you want to minimize a dialog box or the actual application?  Also, how are you running the application?  Just by double clicking the icon, or are you actually running it by calling an API function?
0
TYBAuthor Commented:
I would like the dialog box to be minimized... And I´m running the application by double clicking the icon....
0
ajitmCommented:
I think from dialog box setting you can do this.Else otherwise take pointer to the dialogbox window type cast it to CWnd* and call the relevant function.It offers you plenty of functions.
This code will go in OnInitDialog() where you can get the this pointer.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

nietodCommented:
Are you using MFC or the windows API directly?  Is this dialog box a dialog box created inside an application you are writting? How are you creating the dialog box?
0
WynCommented:
if you use MFC,this way

void CDlg::OnNcPaint()
{
    this->ShowWindow(SW_MINIMIZE);
     
    CDialog::OnNcPaint();
}
0
WynCommented:
to hide,this way
void CMyDlg::OnNcPaint()
{
    this->ShowWindow(SW_HIDE);
     
    CDialog::OnNcPaint();
}

if you dont use MFC,hook corresponding message WM_NCPAINT
Regards
Wyn
0
WynCommented:
this is the kill-all way,hope helpful
0
WynCommented:
but if you create it dynamically,you also can create it as hide,just a parameter you can consult the help file
Regards
Wyn
0
nietodCommented:
Wyn, why would you wnat to minimize on a non-client paint!   And the way you are doing this it would forever be minimized!  If you ever restored the window it would minimize again.   This should be done on WM_CREATE or WM_NCCREATE.   But also we don't know if TYB uses MFC and we don't even know if this dialog is in a window of an application that TYB is writting.
0
WynCommented:
Okay,thanx Nietod this advice.

I dont wanna talk more 'cause i dont know what TYP need exactly.

It's my fault ,sorry to TYP and Nietod as well.

Just reject me and we can give you more elaborate answer and help:)

However I give this answer 'cause i think to hide or minimize a dialogue is trivial in non-MFC .Thus this goes:)

>>And the way you are doing this it would forever be minimized!  If you ever restored the window it would minimize again.  
>>

What do you mean by this ,nietod?
Why i use restore ?

Regards
Wyn
0
WynCommented:
And ,nietod,i think the WM_NCPAINT is prior to WM_CREATE, if you use the latter ,the default window process of WM_NCPAINT will make the dialogue fleeting away.
It's side effect and maybe it is not what TYP need.
Regards
Wyn
0
WynCommented:
And ,nietod,i think the WM_NCPAINT is prior to WM_CREATE, if you use the latter ,the default window process of WM_NCPAINT will make the dialogue fleeting away.
It's side effect and maybe it is not what TYP need.
Regards
Wyn
0
nietodCommented:
>> i think to hide or minimize a
>> dialogue is trivial in non-MFC
Then it is trivial in MFC too.  Since you can always use the windows API directly from MFC.  

>> What do you mean by this ,nietod?
>> Why i use restore ?
A minimized dialog is useless.  So most likely TYB wants to create it minimized, but later on restore it.  Otherwise he wouldn't need it all.

>> i think the WM_NCPAINT is
>> prior to WM_CREATE
No. The first is WM_NCCREATE then WM_CREATE.  (Depending on the window's styles, there may be 1 or 2 messages before WM_NCCREATE, like WM_GETMINMAXINFO, but these tend not to be important)  WM_NCPAINT will occur much much later, when the window is painted.  It willl occur ever time the window is painted!  If the dialog is hidden on a WM_NCPAINT, then each time the window is restored, it will be repainted, causing the window to minimize again.  so you will see the window flash up and minimize again each time the use tries to restore it.
0
WynCommented:
Thank,great nietod,i will try to dig something more,
thank you again:)
Regards
Wyn

>>Then it is trivial in MFC too.  Since you can always use the windows API directly from MFC.  
>>
but what TYB needs is ,at the beginning,to hide it.
In MFC ,dialogue-base,it's a little bit more troublesome.
Thanx .
0
WynCommented:
However,my way is feasible for dialogue-base MFC application all in all:)

Happy the 2nd millennium!
0
nietodCommented:
Feasaible in what sense?  Yes, it will minimize the dialog.  But then what?  How is the dialog ever to be used then?
0
WynCommented:
? just restore,what fail?
0
WynCommented:
? just restore or setwindowpos,what fail?
0
nietodCommented:
Your "solution" makes the window minimize every time the window needs to be redrawn.  So if the windiw is restored the OS will try to redraw it, causing it to be minimized again.  Thus whenever the window is restored it will be minimized again.
0
WynCommented:
:)
That's not a problem.


to hide,this way
void CDlg::OnNcPaint()
{   if(m_hide)
    ShowWindow(SW_HIDE);
       
    CDialog::OnNcPaint();
}
then can change the m_hide somewhere.

0
nietodCommented:
True that works, but why do that when you don't have to?  When simply placing the code to minimize the dialog in the right place works.  Besides, we still don't know if this is for code that TYB has written.
0
TYBAuthor Commented:
I would like the application to be hidden (ShowWindow(SW_HIDE)) from the start....So I want to create it hidden, but later on restore it.
I don´t wanna add a if-statement in the OnPaint-function...making it test if TRUE every time OnPaint() Executes....
0
TYBAuthor Commented:
The reason for this that I have a system with many appz and their icons would occupy(Correct Spelling??) the whole line to the right of the start-button.
Instead I have trayicons for each and every application. Every trayicon has a menu where the user can choose between Showing or Hiding an application....
I would like to initially have the application hidden (but present in the tray)....
0
TYBAuthor Commented:
Wyn´s solution also would make the application "blip" just between the window being displayed for the first time and being hidden in the OnPaint()-function...
0
nietodCommented:
Then just minimize the window when it is created by calling the ShowWindow() function with an SW_MINIMIZE command when the window receives the WM_NCCREATE message.  This occurs before the window is displayed, so the window will never bee seen by the user.  Also the message only occurs as the window is first created so the message won't occur again and again, like the paint message.
0
TYBAuthor Commented:
I´ve tried this in WM_CREATE... didn´t work... what´s the difference if I´ll do it in WM_NCCREATE ?
And I´ll will have to map WM_NCCREATE by myself then ?
0
TYBAuthor Commented:
SW_MINIMIZE works fine that way.... but I have done a little mistake in my question... I would like to hide (SW_HIDE) the dialog and this flag doesn´t work fine.. the dialog still shows.. : ((
0
WynCommented:
first minimize and hide it,my answer works,why you said "blip"?
Have you really tried my answer?
:(
0
TYBAuthor Commented:
There´s must be a better way to solve this problem. When running the application later it will always have to test this if-statement whenever the window is being redrawn....
0
nietodCommented:
Wyn's answer is looking a little better.

The problem (as I explained in another of TYP's questions) is that when WM_CREATE/WM_NCCREATE is sent, the window is hidden, the CreateWindow function then shows the window AFTER those messages are sent.  So those messages are good for minimizing the window, but not for hiding it, because it will be shown after they are done.

The best message I can see to use is WM_SHOWWINDOW.  Like WM_PAINT this message is potentially called repeatedly, not just when the window is created, so a mechanism must be used to prevent the window from being hidden th 2nd time it is called, thus a solution like Wyn's if() statement will be needed.  However I think WM_SHOWWINDOW is a better message to do this on.  It is called far less frequently, it is logically related to the task, and it occurs before the window is ever drawn, so it will prevent any screen flashing.
0
TYBAuthor Commented:
Where do you map this WM_SHOWWINDOW ?? And how ?
0
nietodCommented:
Sorry, I forgot this was MFC.  You want to overide the OnShowWindow() procedure for the dialog.  MFC does allow you to dot hat for dialogs, right?  I know it does for regular windows.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TYBAuthor Commented:
Tnx Nietod for all of your help ( and Wyn and the others also ) you helped out a lot with your knowledge...

0
WynCommented:
Oh,no thanx,my pleasure:)

Thank nietod to give me a deeper understanding of this prob.:)

Best Regards to TYB and nietod:)

Wyn

0
nietodCommented:
Thankyou and you're welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.