Switch progressbar from normal to marquee - c++

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);
}
}

Related

Need to Make CDockablePane Background Transparent in c++ MFC

I'm developing an application in MFC C++ and I have derived a CDockablePane object that I can view on the main window. I need the dockable pane's background to be transparent so you can see the main window through the dockable pane.
How would I accomplish this? Thanks.
this how i create the CDockable Pane object:
if (!FeaturePane.Create("Features", this, CSize (400,500), TRUE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
{
TRACE0("Failed to create Program window\n");
//return false; // failed to create
return FALSE;
}
i Know you can clear the background of a CDroDialog using the following code:
BOOL CDroDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
SetLayeredWindowAttributes(RGB(255,0,255),0, LWA_COLORKEY);
}
BOOL CDroDialog::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect clientRect ;
GetClientRect(&clientRect) ;
pDC->FillSolidRect(clientRect, RGB(255,0,255)) ; // paint background in magenta
//return CDialog::OnEraseBkgnd(pDC);
return FALSE;
}

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.

Thin border lines in MFC/MDI

I would like to have thin child frame borders in my MFC/MDI application. Microsoft suggests changing window styles in PreCreateWindow function and it seems like proper window style is WS_BORDER. However something like this doesn't work;
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_BORDER;
return CMDIChildWnd::PreCreateWindow(cs);
}
What am I missing here?
Thanks
You can try something like this:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_CHILD | WS_VISIBLE | WS_BORDER;
if(! CMDIChildWnd::PreCreateWindow(cs))
return FALSE;
return TRUE;
}

C++ Windows remove maximize box

I'm using these window styles when calling CreateWindow
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
This disables the maximize box, but is there any way I can completely remove it?
No easy way, but if you are going to draw the title bar yourself - in this case you can do it.
To give you an idea, this article Adding a 'Minimize to tray'-button to a Form's caption bar explains how to add a button. Removing standard button is about the same - customization of non-client area.
This will remove the close, minimize and maximize buttons from a Windows 7 panel I realize this is very (very) late in coming, but posted it here as it may help someone else with same problem.
void ClearButtons(void)
{
int index = WS_BORDER;
unsigned int a = (unsigned int)((WS_BORDER | WS_CAPTION) & (~WS_ICONIC));
LONG_PTR lPtr;
HWND hWnd = GetActiveWindow();
lPtr = GetWindowLongPtr(hWnd, index);
SetWindowLongPtr(hWnd, GWL_STYLE, a);
}

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();
}