How to hide form from taskbar in c++ builder? - c++

I have simple VCL Forms application which on start show on taskbar button if is in use, what i want to do is to hide those button, so that mean whatever is happen with form that those button don't appear. Case can be that forms is shown or hidden or any other but button have to be hidden, how to do that?
P.S. I see that question like this exist but they don't work in my cause.

Not only did I have to do what Spook answered, but also (thanks to http://codeverge.com/embarcadero.cppbuilder.ide/builder-c++-xe-and-hiding-taskbar/1073223)
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Application->MainFormOnTaskBar = false;
DWORD dwExStyle = GetWindowLong(Application->Handle, GWL_EXSTYLE);
dwExStyle &= ~WS_EX_APPWINDOW;
dwExStyle |= WS_EX_TOOLWINDOW;
SetWindowLong(Application->Handle, GWL_EXSTYLE, dwExStyle);
}
void __fastcall TForm1::FormActivate(TObject *Sender)
{
ShowWindow(Application->Handle, SW_HIDE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
TForm::CreateParams(Params);
Params.ExStyle &= ~WS_EX_APPWINDOW;
Params.ExStyle |= WS_EX_TOOLWINDOW;
}

Try the following approach:
Set MainFormOnTaskBar to false
Call ShowWindow(Application->Handle, SW_HIDE); inside the main form's OnShow event handler.
Call ShowWindow(Application->Handle, SW_HIDE); inside the main form's OnActivate event handler.
Source: http://delphi.about.com/od/delphitips2008/qt/hide_taskbutton.htm

Related

Restore Console Default properties (and help for their Linux equivalents)

For my Console Application, I needed to prevent user input and window resizing. I used
HWND consoleWindow = GetConsoleWindow();
SetWindowLong(consoleWindow, GWL_STYLE, GetWindowLong(consoleWindow, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);
and
void disableInput()
{
DWORD prev_mode;
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &prev_mode);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_EXTENDED_FLAGS |
(prev_mode & ~ENABLE_QUICK_EDIT_MODE));
}
However, after finishing the program, it would be nice to enable these settings again.
I think this
void enableInput()
{
DWORD prev_mode;
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &prev_mode);
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS);
}
should work for the input but how do I enable window resizing again?
Also, a little bit off this topic but how to enable/disable console resizing and input for Linux?

How do I hide the mouse cursor in a Win32 console?

I have a function that sets a Win32 console to full screen. The problem is when it goes into full screen, it's not hiding the mouse cursor.
It doesn't seem to matter if it's in full screen or not. The mouse cursor still shows when I call ShowCursor(FALSE). How can it be hidden?
As in the docs for ShowCursor(), the cursor will hide if the function returns a value greater than 0. If it's negative, it will hide. The value is returning -2 for me, so it should hide in this case, but it is not.
bool Console::setFullScreen(const bool fullScreen)
{
HWND handle;
if (fullScreen)
{
// Hide the scrollbar
showScrollBar(false);
// Set the window style
handle = GetConsoleWindow();
LONG style = GetWindowLong(handle, GWL_STYLE);
style &= ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME);
SetWindowLong(handle, GWL_STYLE, style);
// Set the window to full screen in windowed mode
ShowWindow(getHandle(), SW_MAXIMIZE);
// Hide the cursor
ShowCursor(FALSE); // Fails
}
else
{
showScrollBar(true);
// Set the window style
handle = GetConsoleWindow();
LONG style = GetWindowLong(handle, GWL_STYLE);
style |= WS_BORDER;
style |= WS_CAPTION;
style |= WS_THICKFRAME;
SetWindowLong(handle, GWL_STYLE, style);
// Set the window to full screen in windowed mode
ShowWindow(getHandle(), SW_NORMAL);
// Show the cursor
ShowCursor(TRUE);
}
return true;
}
I haven't tried this, but you can probably change the mouse cursor of the console window by calling GetConsoleWindow to get the HWND of the console window, then calling SetClassLong to set the cursor.
HCURSOR hNewCursor = LoadCursor(/* whatever*/);
SetClassLong(GetConsoleWindow(), GCL_HCURSOR, hNewCursor);
To make the cursor disappear, create a cursor which is entirely transparent.

Switch progressbar from normal to marquee

I have a Dialog that has an progress bar.
I wan't to add a Method to that dialog that sets the progressbar to marquee.
I try following:
void CDownloader::SetIntermediate(wstring info)
{
SetDlgItemText(IDC_DOWNLOADER_LABEL, info.c_str());
auto style = GetWindowLong(GWL_STYLE);
style &= ~( PBS_SMOOTH | PBS_SMOOTHREVERSE | PBS_VERTICAL);
style |= PBS_MARQUEE;
SetWindowLong(GWL_STYLE, style);
RECT windowRect;
GetWindowRect(&windowRect);
SetWindowPos(HWND_TOP, &windowRect,SWP_FRAMECHANGED);
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
::SendMessage(progress, PBM_SETMARQUEE, TRUE, 100);
}
However this does not work :(
I set the Window Style to MARQUEE removing styles that may conflict with it, using setWindowPos to update the style and the set the Progress to MARQUEE.
I can set the progress bar in the designer to marquee, but can't switch bac to normal.
For all that whant the correct code:
void CDownloader::SetPending(bool value)
{
if(value)
{
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
auto style = ::GetWindowLong(progress, GWL_STYLE);
style |= PBS_MARQUEE;
::SetWindowLong(progress, GWL_STYLE, style);
::SendMessage(progress, PBM_SETMARQUEE, TRUE,0);
}
else
{
HWND progress = GetDlgItem(IDC_DOWNLOADER_PROGRESS);
auto style = ::GetWindowLong(progress, GWL_STYLE);
style &= ~PBS_MARQUEE;
::SetWindowLong(progress, GWL_STYLE, style);
::SendMessage(progress, PBM_SETMARQUEE, FALSE,0);
}
}

MFC redirect/catching MESSAGE_MAP | PreTranslateMessage?

I have a problem using MESSAGE_MAP &/or PreTranslateMessage. This may be a design issue but I'm not sure. The main issue is MESSAGE_MAP code not being called & not sure how to do same via PreTranslateMessage. ie as follows:
//MyCDialogEx : public CDialogEx
class MyCDialogEx::Init()
{
CFlatSplitterWnd m_cSplitter; //http://www.codersource.net/2010/01/29/mfc-splitter-window/
m_pFrame = new CFlatFrameWnd;
m_pFrame->Create(strMyClass, L"", WS_CHILD, rect, this);
m_pFrame->ShowWindow(SW_SHOW);
m_cSplitter.CreateStatic(m_pFrame, 1, 2);
m_cSplitter.ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_NOSIZE | SWP_NOACTIVATE);
m_cSplitter.CreateView(0, 0, RUNTIME_CLASS(CHolderView), CSize(100, 100), &ccc);
CHolderView* pView = (CHolderView*)m_cSplitter.GetPane(0, 0);
ASSERT_VALID(pView);
pView->setWnd(&m_TreeCtrl);
pView->setOwner(this, IDC_TREECTRL);
const DWORD dwStyle = LBS_NOTIFY | WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES
| TVS_LINESATROOT | TVS_CHECKBOXES | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP;
m_TreeCtrl.Create(dwStyle, CRect(0, 0, 1, 1), pView, IDC_TREECTRL);
}
BEGIN_MESSAGE_MAP(MyCDialogEx, CDialogEx)
ON_NOTIFY_REFLECT(WM_ONMYCLICK, OnClickTreectrl) //this & following not called
ON_NOTIFY(NM_CLICK, IDC_TREECTRL, OnClickTreectrl)
ON_NOTIFY(TVN_ITEMCHANGED, IDC_TREECTRL, OnItemchangedTreectrl)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREECTRL, OnSelchangedTreectrl)
ON_NOTIFY(TVN_KEYDOWN, IDC_TREECTRL, OnKeydownTreectrl)
END_MESSAGE_MAP()
BOOL MyCDialogEx::PreTranslateMessage(MSG* pMsg)
{
if (GetFocus() && GetFocus()->GetDlgCtrlID() == IDC_TREECTRL)
{
//what/how goes in here to catch NM_CLICK, TVN_ITEMCHANGED etc??
if (pMsg->message == WM_LBUTTONDOWN)
{
switch (LOWORD(pMsg->wParam))
{
case NM_CLICK:
break;
}
}
if (pMsg->message == WM_KEYDOWN)
TRACE(L"WM_KEYDOWN\n");
if (pMsg->message == WM_KEYUP)
TRACE(L"WM_KEYUP\n");
}
return MyCDialogEx::PreTranslateMessage(pMsg);
}
void MyCDialogEx::OnClickTreectrl(NMHDR *pNMHDR, LRESULT *pResult) //not called
{
TRACE(L"tree click\n");
*pResult = 0;
}
MESSAGE_MAP works if I house these in CHolderView class MESSAGE_MAP, but I rather not as it's just a container class & will possibly be used elsewhere in my project.
What I'd really like to do is use MESSAGE_MAP to minimize coding via PreTranslateMessage (& if it's possible to redirect to MESSAGE_MAP, how?). If I must resort to PreTranslateMessage or other, then how do I use this so I can catch the relevant NM_CLICK, TVN_ITEMCHANGED for tree control etc.
Thank you.
EDIT: oh & the following don't help, not relevant or don't sufficiently explain:
How to get Click Event of Treeview(CTreeCtrl) in MFC created at runtime?
How to redirect MFC messages to another object?
How can identify Mouse Click event in PreTranslateMessage?
The problem is that the tree view will send all its notifications to the parent window. And the parent windows is the CHolderWindow.
Messages are not routed like WM_COMMAND messages. So handler for WM_COMMAND messages may reside anywhere in the notification path.
But regular window control notifications are always handled in the direct parent of the window. In MFC you can redirect such notfications to the child window control itself. Using ON_..._REFLECT.
A trick can be: Set a pointer to a window to the holder window, that should receive all messages. Than accept all WM_COMMAND and all WM_NOTIFY messages in the holder window and resend them to the new window.
PreTranslateMessage is another thing. The target window always receives a call first. Than all parents will get a chance until somebody in the chain of PreTranslateMessage calls returns TRUE.

How to make CDHTMLDialog hidden until the page is loaded?

after calling the DoModal method the dialog will be shown immediately. but i need to make it invisible until the page is loaded. is that possible?
thanks
xx
Hi you can make it hidden at start in
OnInitDialog()
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
dwStyle -= WS_VISIBLE;
SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle);
and then in OnNavigateComplete make it visible.
But if your page will load slow it will seems like your app hangup
//CYourDialog.cpp
void CYourDialog::OnWindowPosChanging(WINDOWPOS* lpwndpos)
{
//allow to hide dialog at the startup of dialog,
//delay the show of dialog until m_bVisible is set
if(!m_bVisible)
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
}
CDialog::OnWindowPosChanging(lpwndpos);
}
//CYourHtmlView.cpp
void CYourHtmlView::OnDocumentComplete()
{
m_pYourDlg->m_bVisible=TRUE;
m_pYourDlg->ShowWindow(SW_SHOW);
}
BOOL CYourDialog::OnInitDialog()
{
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
dwStyle -= WS_VISIBLE;
SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle);
Invalidate();
CDHtmlDialog::OnInitDialog();
...
Navigate(_T("www.google.com"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CYourDialog::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
DWORD dwStyle = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
dwStyle += WS_VISIBLE;
SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle);
Invalidate();
}