Hide Dialog from Taskbar....

I have a Visual C++ dialog application.  I wish to hide the main window when the program is launched while adding an icon to the system tray to restore it from.  For some reason, no matter where I call ShowWindow(SW_HIDE) from, the window is still displayed when launched.  After the program is launched, then if ShowWindow is called on some event it works fine.
I found some answer about this... but it didn´t work... It told me to post a userdefined message in the OnInitDialog()... when I recieve the message I should ShowWindow(SW_HIDE)... Didn´t Work Fro Me Though
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.

abdijCommented:
Hi,

 You said yours was a Dialog based application.
 
The Dialog is Popped in the InitInstance of the app. Why dont you add the icon and restore before the the main dialog is popped (DoModal)?

Bye
Feel free to ask
Abdij
0
nietodCommented:
Did you try it from WM_NCCREATE, Like I suggested?

Why the 2nd question, the 1st one is still open?

Is this an MFC app?
0
TYBAuthor Commented:
Hmmm Abdij.... how do you mean ??

I would like to run the app in the systemtray and not in the taskbar, would your answer help me then ??
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

TYBAuthor Commented:
nietod

I have tried it from WM_CREATE but it didn´t work... what´s the different when calling WM_NCCREATE ? ... isn´t this called before WM_CREATE ?

0
abdijCommented:
Hi,
 No. But i dont think thats possible. Of course i may be wrong. But ShowWindow() needs a window pointer which is created only on DoModal(). If DoModal() is done then the window is displayed.

Why dont you have a SDI with the current dialog in it. There in the MainFrame.cpp modify the display type to SW_HIDE, place the Icon in the system tray and Add the OnTrackingMenu() to track the Menu. On clicking of a particular menu pop this dialog.

Bye
Abdij
0
TYBAuthor Commented:
I would like to have this app as an dialog-based one.... And theré´s maybe something you doesn´t realize... I would like to see the dialog on the screen whenever I choose too... BUT I still doesn´t want it to show up in the taskbar when the dialog is visible...
0
abdijCommented:
Hi,

 Sorry OnTrackingMenu() is not the one the correct one is TrackPopupMenu().

Bye
Abdij
0
abdijCommented:
Hi,
 Sorry for not undrstanding you requirement. I donot think it is possible since if the application window is seen on the monitor then it will also be there on the taskbar. If you hide the application window nothing is visible. With a dialog based application it is probably not possible (again i may be wrong) with the SDI/MDI do waht i suggested. Still whenever the dialog is displayed on the screen the application will be there on the task bar too!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

can you quote one App that works your way?????????????????????????????????

Bye
All the best
Abdij
0
nietodCommented:
>> I have tried it from WM_CREATE
>> but it didn´t work
That should be fine too.  Can you post your code?

>> But i dont think thats possible.
>> Of course i may be wrong
Why wouldn't it be possible?

>> But ShowWindow() needs a window pointer
>> which is created only on
>> DoModal(). If DoModal() is done then the
>> window is displayed.
When DoModal() is done the window ISN'T displayed, it is already destroyed!  But while DoModal() is running, the window exists and the windo handle may be used to minimize the window.

>> BUT I still doesn´t want it to show up in the
>> taskbar when the dialog is visible...
The technique for that is a bit-round-a-bout.  I don't think you can do this in a simple MFC dialog based-app.  Is this an MFC app?  If so, I think you will have to change it to a non-dialog based app.  The reason is, in order to hide the window from the task bar, it has to have an owner window that is hidden.  I don't think you can do that with the MFC dialog based app design.
0
TYBAuthor Commented:
nietod
Still no one hasn´t answered how I could do to start the dialog hidden ... It worked fine for me with SW_MINIMIZE but SW_HIDE didn´t go to well (not at all actually)...
0
abdijCommented:
Hi,

Neitod: When DoModal() is done the window ISN'T displayed, it is already destroyed!  But while DoModal() is running, the window exists and the windo handle may be used to minimize the window.

Sorry if i miscommunicated what i wanted to say. You are right.

TYB: You have not yet answered my question??

Bye
Abdij
0
abdijCommented:
Hi,

Neitod: When DoModal() is done the window ISN'T displayed, it is already destroyed!  But while DoModal() is running, the window exists and the windo handle may be used to minimize the window.

Sorry if i miscommunicated what i wanted to say. You are right.

TYB: You have not yet answered my question??

Bye
Abdij
0
TYBAuthor Commented:
Abdij:
Ok... I cannot quote on app that works that way...but that´s what´s gonna be different with my appz... :)

So you state there´s no answer to this ? Or ? I would really like to have an answer to this.. my hair is turning grey by sitting here thinking :))



0
WynCommented:
ShowWindow(hwnd,SW_MINIMIZE);
and
ShowWindow(hwnd,SW_HIDE);

and TYB,
why my last answer to you fail?
I try both and succeed,you really have tried it?
0
abdijCommented:
Hi,

TYB: Ok... I cannot quote on app that works that way...but that´s what´s gonna be different with my appz... :)

ALL THE BEST!!!!!!!!!!!!!!!!!!!!!!!!!!

Bye
Abdij
0
TYBAuthor Commented:
Wyn:

Because I doesn´t want any if-statement in the OnPaint()-function... All I wanna do is to hide the dialog based application when I start it (I would like to hide ONE time, and not run the if-statement every time the window is redrawn...)
0
nietodCommented:
TYP, I thought you wanted the dialog minimized, not hidden.  In that case WM_CREATE or WM_NCCREATE is too early a message.  At that boind the window is already hidden, but the CreateWindow() function will show the window after those messages are sent to it.  So you attempt to hide the window is too soon.  I'm not sure what message to use however...  I'll have to look at that.
0
TYBAuthor Commented:
tnx ... nietod .
0
nietodCommented:
There isn't a good message for this.  WM_INITDIALOG would be nice, but it is sent immediately before the window is shown, so it is too early too.  Your best bet is to use the WM_SHOWWINDOW message.  This message will be sent when the window is 1st shown, but the problem is the message will be called on other occasions too.  So you will need to use an if to prevent the window from being hidden after that.  This is a lot like XXX's (can't remember who) solution, but I feel that WM_SHOWWINDOW is a better place to hook because it is called much less often than WM_PAINT.   (And it is logically connected).  To make it foolproof, you can use a static boolean variable to insure that the window is show only once, like

case wm_showwindow:
{
   bool FirstTime = true;
   // call default window procedure.
    if (FirstTime)
    {
       ShowWindow(hwnd,SW_HIDE);
       FirstTime = false;
    }
    return 0;
}
0
WynCommented:
>>For some reason, no matter where I call ShowWindow(SW_HIDE) from, the window is still displayed when launched.
>>

the wm_ncpaint is the only place i  know but you hate the condition.
Once I wrote a program exactly like yours.I make it start as hidden and put a icon in the tray bar.I use exactly this way:)

Regards
Wyn


 
0
nietodCommented:
WM_PAINT is called a lot. Its not a good place to perform a taskt that is needed only once.  The other messages are ideal since they occur only once, but unfortunately too early.
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
ZoppoCommented:
Hi TYB,

in CDialog::DoModal() there's following code:

if (m_nFlags & WF_CONTINUEMODAL)
{
 // enter modal loop
 DWORD dwFlags = MLF_SHOWONIDLE;
 if (GetStyle() & DS_NOIDLEMSG)
 dwFlags |= MLF_NOIDLEMSG;
 VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
}

this code makes it impossible to start a modal dialog hidden, because RunDoModalLoop() shows the window when MLF_SHOWONIDLE is passed.

Why don't you just use a modeless dialog?

ZOPPO
0
chensuCommented:
ON_WM_NCPAINT()

void CMyDlg::OnNcPaint()
{
    if (m_bHide)
        this->ShowWindow(SW_HIDE);
     
    CDialog::OnNcPaint();
}
0
TYBAuthor Commented:
This Idea I have got already from another.... I would like to place it somewhere in a function that´s is called only once....
0
TYBAuthor Commented:
Tnx again....
0
ZoppoCommented:
Hi TYB,

Do you have any problems using a modeless dialog? With a modeless dialog it's very simple, just don't call ShowWindow after creating it ...

ZOPPO
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.