How to make CDHTMLDialog hidden until the page is loaded? - mfc

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

Related

How should I change the IMAGE(doesn't matter the type) of the button in the toolbar in MFC applications?

I know that this is stupid problem but I am stuck with it for the past 4 days. Why it is so complicated to just modify the toolbar in the MFC apps?
I create New Visual studio MFC application that is dialog based. I create new Toolbar resource. And then how should I set images(png, bitmap, jpeg...) or whatever type to be used in my toolbar?
I have set size to w50 and h50 and I can draw inside the buttons. But I cant find way to use image.
Instead this 2 buttons that I have just tried if its working, I want to use 8 images that are in bitmap format and in png. I read somewhere that PNG is not supported by MFC applications so I converted to Bitmap.
I load my toolbar in the dialog app like this in the OnInitDialog() method:
DWORD dwCtrlStyle = TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CBRS_SIZE_DYNAMIC;
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE;
CMFCToolBar::m_dblLargeImageRatio = 1;
if (m_ToolBar.CreateEx(this, dwCtrlStyle, dwStyle, CRect(1, 1, 1, 1), IDR_TOOLBAR1))
{
dwStyle = CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC;
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() | dwStyle);
CMFCToolBarInfo info;
m_ToolBar.LoadToolBarEx(IDR_TOOLBAR1, info, FALSE);
CSize sizeToolBar = m_ToolBar.CalcFixedLayout(TRUE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy, SWP_NOACTIVATE |
SWP_NOZORDER);
CPoint ptOffset(0, sizeToolBar.cy);
}
Please if someone can help me I would be really grateful. The image format doesn't matter. I just want to put image in the toolbar.
This is my app currently:
UPDATE: I have tried this way. ID_BUTTON_1 if the first button in the toolbar and i tried to change its image. But with this there is no button in the toolbar at the place for the first button. What I am doing Wrong?
VERIFY(m_toolbar.LoadBitmap(IDB_BITMAP1));
CMFCToolBarButton mbutton;
mbutton.SetImage(m_toolbar.GetImages()->GetCount() - 1);
m_toolbar.ReplaceButton(ID_BUTTON_1, CMFCToolBarButton(ID_BUTTON_1, 0));
I answered this recently and can no longer find my answer. You can use PNG images for your toolbars. Under the hood you still use the BMP version for the resource editor to create your event handlers etc. But you can then add your PNG as a resource and then load it into your dialog.
For example, I call this in my OnInitDialog function:
void CMeetingScheduleAssistantDlg::CreateToolbar()
{
DWORD dwCtrlStyle = TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CBRS_SIZE_DYNAMIC;
DWORD dwStyle = AFX_DEFAULT_TOOLBAR_STYLE;
CMFCToolBar::m_dblLargeImageRatio = 1; // AJT v20.1.7 Bug fix
if (m_ToolBar.CreateEx(this, dwCtrlStyle,
dwStyle, CRect(1, 1, 1, 1), IDR_TOOLBAR))
{
dwStyle = CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC;
m_ToolBar.SetPaneStyle(m_ToolBar.GetPaneStyle() | dwStyle);
CMFCToolBarInfo info;
info.m_uiColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiHotResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeColdResID = IDB_PNG_MAIN_TOOLBAR;
info.m_uiLargeHotResID = IDB_PNG_MAIN_TOOLBAR;
m_ToolBar.LoadToolBarEx(IDR_TOOLBAR, info, FALSE);
CSize sizeToolBar = m_ToolBar.CalcFixedLayout(TRUE, TRUE);
m_ToolBar.SetWindowPos(NULL, 0, 0, sizeToolBar.cx, sizeToolBar.cy,
SWP_NOACTIVATE | SWP_NOZORDER);
// Move all controls down
CPoint ptOffset(0, sizeToolBar.cy);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
if (pwndChild->GetSafeHwnd() != m_ToolBar.GetSafeHwnd())
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
}
pwndChild = pwndChild->GetNextWindow();
}
// Resize the window
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.bottom += sizeToolBar.cy;
MoveWindow(rcWindow, FALSE);
}
}
I don't know where my previous answer has gone to, else I would have flagged this as duplicate. #confused.

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

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

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

Add tooltip to a CStatic

I haven't been able to find a concise chunk of code that allows me to add/display tooltips to a CStatic (and CLed) control. Obviously, the standard code to do so does not apply for this type of control. Can someone post code snippets?
I hope this code will solve your problem .One important thing make NOTIFY property of CStatic =TRUE.
if( !m_ToolTip.Create(this))
{
TRACE0("Unable to create the ToolTip!");
}
else
{
CWnd* pWnd = GetDlgItem(IDC_STATIC_MASTER_PWD);
m_ToolTip.AddTool(pWnd,"Ok");
m_ToolTip.Activate(TRUE);
}
Let me know if any problem.
I don't know if this is still needed, but here's what I used to solve the problem:
just add SS_NOTIFY to dwStyle when creating the static label. (or simply set "Nofity" "True" in the properties). That worked fine for me.
When I add CStatic on Dialog based autocreated mfc application, tooltips don't show until I add RelayEvent in pretranslate dialog message
BOOL CTooltipStaticDlg::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
I've had success with multiline tooltips using this simple class:
Create a class for ToolTips:
class ToolTip
{
public:
static HWND CreateToolTip(int toolID, HWND hDlg, UINT id);
};
Next, implement a tooltip creation function:
HWND ToolTip::CreateToolTip(int toolID, HWND hDlg, UINT id)
{
if (!toolID || !hDlg || !id)
{
return FALSE;
}
CString strTTText;
strTTText.LoadString( id );
// Get the window handle of the control to attach the TT to.
HWND hwndTool = ::GetDlgItem(hDlg, toolID);
// Create the tooltip window
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP,// | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
AfxGetInstanceHandle() , NULL);
if (!hwndTool || !hwndTip)
{
return (HWND)NULL;
}
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = (char*)(LPCTSTR)strTTText;
::SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
::SendMessageA(hwndTip, TTM_SETMAXTIPWIDTH, 0, 40); // force multi-line
return hwndTip;
}
Call it somewhere in your InitDialog:
CMyDialog::InitDialog()
{
ToolTip::CreateToolTip( PickAUniqueNumber, m_hWnd, IDS_MY_RESOURCE_STRING );
}
I've had on my dialog label with assigned custom ID IDC_PATH. I needed to turn on Notify flag (SS_NOTIFY) of the label and I needed to overload CWnd method OnToolHitTest and handle tooltip hit test like this:
INT_PTR CPath::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
INT_PTR r = CWnd::OnToolHitTest(point,pTI);
this->ClientToScreen(&point);
CRect rcLbl;
GetDlgItem(IDC_PATH)->GetWindowRect(&rcLbl);
if( rcLbl.PtInRect(point) )
{
pTI->uFlags |= TTF_IDISHWND;
pTI->uFlags &= ~TTF_NOTBUTTON;
pTI->uId = (UINT_PTR)GetDlgItem(IDC_PATH)->m_hWnd;
return IDC_PATH;
}
return r;
}
Then my dialog started to receive TTN_NEEDTEXT notification, which I handled and dynamicaly set text for tooltip.
BOOL CPath::OnTtnNeedText(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
UNREFERENCED_PARAMETER(id);
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT_PTR nID = pNMHDR->idFrom;
BOOL bRet = FALSE;
if (pTTT->uFlags & TTF_IDISHWND)
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
if(nID == IDC_PATH)
{
pTTT->lpszText = (LPSTR)(LPCTSTR)m_FullDestPath;
bRet = TRUE;
}
}
*pResult = 0;
return bRet;
}