show pop-up message in front of SaveAs dialog - c++

In Windows application, is it possible to show a popup message in front of SaveAs dialog after SaveAs dialog is being opened? All I managed to get is that popup shows after dialog is closed.
I need to edit an old application written in C++ (I am not author) but can't manage this task. This is part of code:
/* ---- called to display the save file dialog ---- */
ofn.hwndOwner = hwnd;
ofn.lpstrFile = lpstrFileName;
ofn.lpstrTitle = lpstrTitleName;
res = GetSaveFileNameW( &ofn );
/* ---- fix file extension ---- */
MessageBox(NULL, "Test", "Testing", MB_OK);
Thanks,
Ilija

If I understand you correct, you want check some stuff (for example, file extension) before closing dialog and show message withou closing. If it's so please look at OFN_ENABLEHOOK flag in OPENFILENAME Structure. In this case your code will look something like
ofn.hwndOwner = hwnd;
ofn.lpstrFile = lpstrFileName;
ofn.lpstrTitle = lpstrTitleName;
/* enables the hook function */
ofn.Flags |= OFN_ENABLEHOOK;
ofn.ofn.lpfnHook = (LPOFNHOOKPROC) MyHookProc;
/* some code here */
res = GetSaveFileNameW( &ofn );
Code for MyHookProc will look like this:
static UINT CALLBACK MyHookProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_NOTIFY) {
OFNOTIFYW *notify = (OFNOTIFYW *) lParam;
if (notify->hdr.code == CDN_FILEOK) {
/* your code here */
}
}
}
Hope it will be helpful for you.

You can but it would be quite a hack. You would have to create the FileDialog and open it modeless rather than modal, and hidden. So the window is there but you can't see it. When you click your "popup" you can then could unhide the windows dialog.

It sounds like you want to extend the GUI of a save file dialog box. You can extend the GUI by using your own dialog resource template, and specify OFN_ENABLETEMPLATE. This is how many apps show previews / metadata of documents.

Related

Dynamic Tooltips: TTN_GETDISPINFO not send when using LPSTR_TEXTCALLBACK

I am trying to add dynamic tooltips to my mfc application. I am able to display tooltips using CToolTipCtrl with static text. But when I change the text to LPSTR_TEXTCALLBACK I don't get a TTN_GETDISPINFO notification to set the text and nothing gets displayed anymore.
I created a new MFC project from scratch and there it works. So something must be different in my application. But I am not able to find out, what I do wrong or where I should start looking.
What could be possible reasons for this behaviour? Is it possible that the notifications diverted to somewhere else?
I added the handler like this:
ON_NOTIFY(TTN_GETDISPINFO, NULL, OnToolTipNotify)
void CChildView::OnToolTipNotify(NMHDR* pNMHDR, LRESULT* pResult)
{
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
wsprintf(pTTTW->szText,L"Hello World!");
}
The tooltip was added in the OnCreate function using the CMyToolTipCtrl class from Jeff Prosise MFC book:
CToolTipCtrl* tooltip = new CToolTipCtrl;
tooltip->Create(this, TTS_ALWAYSTIP);
TOOLINFO ti;
ti.cbSize = sizeof (TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
ti.hwnd = this->GetSafeHwnd ();
ti.uId = (UINT) tooltip->GetSafeHwnd ();
ti.hinst = AfxGetInstanceHandle ();
ti.lpszText = (LPTSTR) LPSTR_TEXTCALLBACK;
SendMessage (TTM_ADDTOOL, 0, (LPARAM) &ti);
If I change the second to last line to
ti.lpszText = (LPTSTR) L"Hello World!";
the tooltip gets displayed in my application, too.
It might be a problem of your project setting.
What kind of project is it? Unicode or MBCS.
If it is an MBCS message you might miss the notification because the tooltip is an unicode window and sends TTN_GETDISPINFOW!
So best practice for me is to implement always both notifications TTN_GETDISPINFOW and TTN_GETDISPINFOA.
You might check this with Spy++

How to change office tab's backcolor in a MFC multi document project?

Use Vistual Studio 2012 or up
Create a MFC project
In the Wizard, set to Multiple document project
Set to Office style
Run it.
Click new button to create some empty documents.
Now I want to know how to change tab's header backcolor in these empty documents?
You can disable auto-color in MainFrm.cpp
int CMainFrame::OnCreate(...)
{
//...
mdiTabParams.m_bAutoColor = FALSE; // set to FALSE to disable auto-coloring of MDI tabs
}
Perhaps you knew about that already! To change the tab's background color to something specific can be very tricky because it's all tied in to the selected theme. But you can do it, for example by the following method:
ON_REGISTERED_MESSAGE(AFX_WM_CHANGING_ACTIVE_TAB, &CMainFrame::OnAfxWmChangingActiveTab)
LRESULT CMainFrame::OnAfxWmChangingActiveTab(WPARAM wParam, LPARAM lParam)
{
CMFCTabCtrl* tab = (CMFCTabCtrl*)lParam;
if (tab)
tab->SetTabBkColor(wParam,RGB(255,0,0));
return 0;
}
You can also disable the tab colors by the following code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(-1 == CMDIFrameWndEx::OnCreate(lpCreateStruct))
return -1;
....
CMFCTabCtrl& MFCTabCtrl = GetMDITabs();
MFCTabCtrl.EnableAutoColor(FALSE);
....

How to map help id of a error messagebox in MFC?

I have a dialog box in MFC which has help button.
I am able to map help button with my help content.
on my dialog box, I have a edit box also i which user can enter anything.
i am validating the edit control box that if something wrong user enters it will open
error message box which display error and having help button too.
i wanted to map this error message box helpid to my content (which different from parent dialog box) but whenever click help button it shows me parent help content.
NOTE: i tried both APIs Afxmessagebox and Messagebox.
Solution from my side , (i don't know if it is correct )
Create another dialog box and mapp to help id as i di fro parent dialog box.
and treat this dialog box as a error messagebox with domodal.
I feel i we can do this with messagebox itself but didn't find anything on web.
What i tried -
I tried following link but couldn't get success.
http://www.codeproject.com/Articles/562/Add-a-Help-Button-to-a-MessageBox
VOID CALLBACK MsgBoxCallback(LPHELPINFO lpHelpInfo)
{
CString str = AfxGetApp()->m_pszHelpFilePath;
AfxGetApp()->WinHelp(lpHelpInfo->dwContextId);
}
UINT AfxMessageBox(HWND hWnd, LPCTSTR szText, UINT nType, UINT nIDHelp = 0)
{
MSGBOXPARAMS mbp;
memset(&mbp, 0, sizeof mbp);
mbp.cbSize = sizeof MSGBOXPARAMS;
mbp.hwndOwner = hWnd;
mbp.hInstance = AfxGetInstanceHandle();
mbp.lpszText = szText;
AfxGetApp()->m_pszHelpFilePath = "C:\\Program Files (x86)\\\HELP\\130.htm";
// if you wanted to specify a different caption, here is where you do it
mbp.lpszCaption = AfxGetAppName();
// if Help ID is not 0, then add a help button
if (nIDHelp != 0)
{
mbp.dwStyle = nType | MB_HELP;
}
else
{
mbp.dwStyle = nType;
}
// mbp.lpszIcon = ; // note, you could provide your own custom ICON here!
mbp.dwContextHelpId = nIDHelp;
mbp.lpfnMsgBoxCallback = &MsgBoxCallback;
mbp.dwLanguageId = 0x0409;
return ::MessageBoxIndirect(&mbp);
}
Here's how to do it:
Create a string resource for each message box.
Be sure to name the resource with an IDP_ prefix. Although IDS_ also corresponds to strings, the makehm command-line tool will not look for IDS_ when it builds the HTMLDefines.h file.
Change your message box call(s) to AfxMessageBox(IDP_FOO, MB_OK|MB_HELP, IDP_FOO), substituting in other flags, as needed.
(Note: I had another answer, but it was way off, so I decided to start clean with a new answer instead of updating it.)

create window in tab c++

I create tab with createwindow. I have 2 tab item and I want to create some static window in 2 tab item. I have use createwindow with parent is the handle to tab. But the child window is present in both tab1 and tab2. I want 2 tab item have a different content. So How can I do that.
Is there another way to create a Static control belong to the specific tab1 or tab 2 ...
Not hwnd of tab from create window. I don't know how to do that so this is my solution
I use win api
Thanks
Here some of my code
TabCtrl_InsertItem(hwndTab,0,&tcitem);
TabCtrl_InsertItem(hwndTab,1,&tcitem);
hwndTab_1_1_1 = CreateWindow(L"BUTTON",L"sample",WS_CHILD|WS_VISIBLE,0,29,100,50,hwndTab,(HMENU)4,hInstance,NULL);
hwndTab_1_2_1 = CreateWindow(L"BUTTON",L"sample2",WS_CHILD|BS_AUTOCHECKBOX,20,80,100,50,hwndTab,(HMENU)4,hInstance,NULL);
and I'm using this:
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == TCN_SELCHANGE) {
switch(TabCtrl_GetCurSel(hwndTab)) {
case 0:
ShowWindow(hwndTab_1_1_1,SW_SHOW);
ShowWindow(hwndTab_1_2_1,SW_HIDE);
break;
case 1: //
ShowWindow(hwndTab_1_1_1,SW_HIDE);
ShowWindow(hwndTab_1_2_1,SW_SHOW);
break;
default: return DefWindowProc(hwnd, Message, wParam, lParam);
}
}
else {
return DefWindowProc(hwnd, Message, wParam, lParam);
}
break;
I need the code to the same thing with these code. I don't want to use to much show and hide too many time if we have many child window.
you can try like this:
assume you have 3 tab pages.
T *pTabPage[3]; point to your 3 tab pages;
int nCurrentPage; to save your current tab page.
and when you want to change the tab page,
1.hide the "current page" that saved in the nCurrentPage: ShowWindow(pTabPage[nCurrentPage], SW_HIDE);
2.Get the really current page: nCurrentPage = GetCurSelect();
3.Show the really current page: ShowWindow(pTabPage[nCurrentPage], SW_SHOW);
the code is incorrect, just to explain the method
Hope to help you!

How to set tooltip at runtime in MFC Treeview?

How to set tooltip at runtime in MFC Treeview ?
I am creating treeview like this :
m_pTreeview->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
TVS_SINGLEEXPAND,CRect(38, 82, 220 ,250), this, IDC_NDS_TREEVIEW);
Any help is appreciated..
Here some code : -- In .H file
afx_msg void OnMyTreeGetInfoTip(NMHDR pNMHDR, LRESULT pResult);
In BEGIN MESSAGE MAP block add -
ON_NOTIFY_REFLECT (TVN_GETINFOTIP, OnMyTreeGetInfoTip)
And use handler
void CMyTreeView::OnMyTreeGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTVGETINFOTIP pGetInfoTip = (LPNMTVGETINFOTIP)pNMHDR;
CString strItemTxt = m_TreeCtrl.GetItemText(pGetInfoTip->hItem);
strcpy(pGetInfoTip->pszText, strItemTxt);
*pResult = 0;
}
If you're referring to the tooltips for items in the tree control, you need to add TVS_INFOTIP to the window styles in Create (see list of tree-view styles). You'll also have to handle the TVN_GETINFOTIP notification message to provide the tooltip text depending on the item.
Use TVS_INFOTIP style to tree-view, and handle the TVN_GETINFOTIP notification using an ON_NOTIFY handler. Typecast the NMHDR ptr to NMTVGETINFOTOOLTIP ptr as
(NMTVGETINFOTOOLTIP *)pnmhdr and then set the tooltip string in this structure.
Pankaj's answer works if you are deriving your own control from CTreeControl.
Cassablanca's answer is correct only the code is missing.
So here are some tips from my own experience.
If you are not creating the control explicitly the GETINFOTIP style can be specified in the resource file where the control is being defined.
otherwise the style can be modified at runtime by getting the tree's window handle
HWND htreectrl = m_TreeCtrl.GetSafeHwnd();
LONG nOldStyle = GetWindowLong( htreectrl, GWL_STYLE);
LONG nNewStyle = nOldStyle & TVS_INFOTIP;
SetWindowLong( htreectrl, GWL_STYLE, nNewStyle);
To be able to handle GETINFOTIP:
If you are using the TreeControl as a member control inside a dialog:
ON_NOTIFY (TVN_GETINFOTIP, IDC_TREE, OnMyTreeGetInfoTip)
Else if you are deriving your own control from CTreeControl then use this:
ON_NOTIFY_REFLECT(TVN_GETINFOTIP, OnMyTreeGetInfoTip)
Hope this helps someone.