Link to home
Start Free TrialLog in
Avatar of TYB
TYB

asked on

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
Avatar of abdij
abdij

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
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?
Avatar of TYB

ASKER

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 ??
Avatar of TYB

ASKER

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 ?

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
Avatar of TYB

ASKER

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...
Hi,

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

Bye
Abdij
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
>> 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.
Avatar of TYB

ASKER

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)...
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
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
Avatar of TYB

ASKER

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 :))



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?
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
Avatar of TYB

ASKER

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...)
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.
Avatar of TYB

ASKER

tnx ... nietod .
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;
}
>>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


 
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zoppo
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
ON_WM_NCPAINT()

void CMyDlg::OnNcPaint()
{
    if (m_bHide)
        this->ShowWindow(SW_HIDE);
     
    CDialog::OnNcPaint();
}
Avatar of TYB

ASKER

This Idea I have got already from another.... I would like to place it somewhere in a function that´s is called only once....
Avatar of TYB

ASKER

Tnx again....
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