How to hide propertysheet? - mfc

I had a propertysheet where I am facing an issue in hiding the sheet.I will briefly explain what I had done.
In the PropertySheet OnWizardFinish() I am trying hide the sheet and do the following ,
BOOL CSecondEditpage::OnWizardFinish()
{
BOOL bAsyRet = ShowWindowAsync(m_hWnd,SW_HIDE);
int MsgRet = ::MessageBox(NULL,L"Do you want to restart",L"Test",MB_YESNO | MB_ICONINFORMATION);
if(IDYES == MsgRet)
{
SystemRestart();
}
else
{
//Do Nothing..
}
return CPropertyPage::OnWizardFinish();
}
So here only the message box should be visible and the sheet should be hidden this is what I am expecting that ShowWindowAsync does.But in the background sheet still exists.
Same thing I tried with a dialog based application there it is working as expected like as,the background window is hidden and only message box is shown .
For more details:
And now when I click finish the sheet should be hidden and should show a message box something like this,
Can anyone please let me know how can achieve this in propertysheet wizard.

You're trying to hide PropertyPage not a PropertySheet.
Do like this.
CPropertySheet* prop = (CPropertySheet*)GetParent();
ShowWindowAsync(prop->m_hWnd, SW_HIDE);

Related

MDI Tab names changing back... / Taskbar Preview not selecting

I'm creating an MDI application, WITHOUT the Document/View.
I am also using MDITabbedGroups.
I had a problem, because I have to name may tabs dynamically (names are in the DB and user created), meaning I couldn't use resources for the names.
I create all the tabs as 'Program name', then rename them by calling the following after create:
BEGIN_MESSAGE_MAP(CChildView, CWnd)
ON_COMMAND(ID_SET_COLOR, CCOnSetColor)
END_MESSAGE_MAP()
PostMessage(WM_COMMAND, (WPARAM)ID_SET_COLOR);
void CChildView::CCOnSetColor()
{
CMDIChildWndEx* pFrame = (CMDIChildWndEx*)GetParent();
CMFCTabCtrl* pTabCtrl = pFrame->GetRelatedTabGroup();
if (pTabCtrl != NULL)
{
pTabCtrl->SetTabBkColor(pTabCtrl->GetActiveTab(), GetTabCol());
pTabCtrl->SetTabLabel(pTabCtrl->GetActiveTab(), GetTabName());
pTabCtrl->RedrawWindow();
}
}
But the problem was that when I switched tabs the names would change back to 'Program Name'.
I managed to avoid this by skipping over CMDIChildWndEx in the OnMDIActivate call as so:
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* activated, CWnd* disbled)
{
CWnd::OnMDIActivate(bActivate, activated, disbled);
}
I know, I know, bad. However:
This worked fine, all other functionality seemed to be working, tabs were switching, active window was correct etc etc...
Until I noticed that on mouse over of the task bar, I got a preview of all open tabs, and if I clicked on one of the inactive tabs things went wrong.
Now the active frame / view (GetActiveFrame() / GetActiveView() in MainFrame) was the one I click on, but it is not drawn and the tab not switched to.
So I tried:
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* activated, CWnd* disbled)
{
CMDIChildWndEx::OnMDIActivate(bActivate, activated, disbled);
CMFCTabCtrl* pTabCtrl = GetRelatedTabGroup();
if (pTabCtrl != NULL)
{
pTabCtrl->SetTabBkColor(pTabCtrl->GetActiveTab(), m_wndView.GetTabCol());
pTabCtrl->SetTabLabel(pTabCtrl->GetActiveTab(), m_wndView.GetTabName());
// pTabCtrl->SetTabIcon(pTabCtrl->GetActiveTab(), 2);
pTabCtrl->RedrawWindow();
}
}
&&&
void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* activated, CWnd* disbled)
{
CMDIChildWndEx::OnMDIActivate(bActivate, activated, disbled);
m_wndView.PostMessage(WM_COMMAND, (WPARAM)ID_SET_COLOR);
if(disbled) ((CChildFrame*)disbled)->m_wndView.PostMessage(WM_COMMAND, (WPARAM)ID_SET_COLOR);
}
Now the tab switches correctly, but only the tab being activated gets the correct name, all inactive tabs go back to 'Program Name'
interestingly the color remains correct.
So the Question:
Can I permanently change the name some how / where.
I saw in MS Documentation that it can be set in CDocument, but I don't have a Document...
Alternatively what call / calls do I need to catch to set my name every time?
Also Bonus Q:
Can I make the Preview show only the 'Active' Tab, and not the others?
After much hunting around in the AFX source files, I found this:
CString CMDIChildWndEx::GetFrameText() const
{
ASSERT_VALID(this);
CString strText;
GetWindowText(strText);
return strText;
}
& this
void CMDIFrameWnd::OnUpdateFrameTitle(BOOL bAddToTitle)
{
if ((GetStyle() & FWS_ADDTOTITLE) == 0)
return; // leave it alone!
... // rest of func
}
so it is as simple as removing the style flag the MS puts in automatically (via wizard create project), on the func BOOL PreCreateWindow(CREATESTRUCT& cs).
Then setting the title of the Frame via SetWindowText(title);

how to change the icon on action bar in android

I create a sliding menu and i want to open it using ( ... ) but i try alot to change the icon which is(<-).
this my code .
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer1, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle("hello");
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle("ohhh");
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
// getSupportActionBar().setDisplayShowHomeEnabled(true);
// getActionBar().setHomeButtonEnabled(true);
//getSupportActionBar().setIcon(R.drawable.ic_drawer1);
getSupportActionBar().setIcon(R.drawable.ic_drawer1);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
It has been asked already. Try to change in manifest file to change your app logo or if it doesn't work then try this link. Android: How to change the ActionBar "Home" Icon to be something other than the app icon?. This might help.

Split view in two with a menu button? (MFC)

I have an MFC program written that reads files, stores the data, and draws it as text on the client view.
I want to make a menu button View->Split that splits the client area into two, separately scrolling views displaying the same data.
I saw some things about CWndSplitter online and read through some documentation but none of it has proved to be useful because they talk about using OnCreate and deleting the default view to get it to work. This is not an option. I want to keep the default view, but split it in two if the user clicks the button.
I've currently created a CWndSplitter member variable and defined a menu button event handler in my SDI-1View.cpp. When called, it does absolutely nothing but cause the screen to flicker and a second click crashes the program.
void CSDI1View::OnViewSplit32778()
{
// TODO: Add your command handler code here
/*
int rows = 2;
int columns = 1;
if (!m_wndSplitter.CreateStatic(this, rows, columns))
return;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CSDI1View), CSize(100, 100), NULL) ||
(!m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CSDI1View), CSize(100, 100), NULL)))
{
m_wndSplitter.DestroyWindow();
return;
}
*/
}
Can anyone tell me what the normal approach to splitting a client view in half is? I just want to integrate that into an event handler.
Any help would be greatly appreciated.
Thanks.
--------------------------------EDIT----------------------------------
I now have the following code in my Split button event handler, thanks to the outline provided by xMRi, but it is still not working properly...
void CMainFrame::OnViewSplit()
{
// TODO: Add your command handler code here
//calculate client size
CRect cr;
GetClientRect(&cr);
if (!m_mainSplitter.CreateStatic(this, 2, 1))
{
MessageBox(_T("Error setting up splitter frames! (CreateStatic)"),
_T("Init Error!"), MB_OK | MB_ICONERROR);
return;
}
// Set the parent of the splitter window to the current view
CSDI1View * view = CSDI1View::GetView();
m_mainSplitter.SetParent(this);
view->SetParent(&m_mainSplitter);
// Create a CCreateContext
CCreateContext cc;
CRuntimeClass* prt = RUNTIME_CLASS(CSDI1View);
cc.m_pNewViewClass = prt;
cc.m_pCurrentDoc = view->GetDocument();
cc.m_pNewDocTemplate = NULL;
cc.m_pLastView = NULL;
cc.m_pCurrentFrame = this;
if (!m_mainSplitter.CreateView(0, 0,
cc.m_pNewViewClass,
CSize(cr.Width(), cr.Height()/2), &cc))
{
MessageBox(_T("Error setting up splitter frames! (CreateView 1)"),
_T("Init Error!"), MB_OK | MB_ICONERROR);
return;
}
if (!m_mainSplitter.CreateView(1, 0,
cc.m_pNewViewClass,
CSize(cr.Width(), cr.Height()/2), &cc))
{
MessageBox(_T("Error setting up splitter frames! (CreateView 2)"),
_T("Init Error!"), MB_OK | MB_ICONERROR);
return;
}
m_bInitSplitter = TRUE;
}
Upon clicking the view->split button, I get a "Debug Assertion Error" popup and the first call to CreateView returns FALSE, displaying my messagebox: "Error setting up splitter frames! (CreateView 1)"
A static splitter is for a static split--i.e., a window that's always split. You usually use it when you want to have a different view in each pane of the split (e.g. display a column of numbers in one pane, and a graph in the other pane).
For a situation like yours that you want to be able to have the window, then later split it and have two essentially identical views, you (at least normally) want to use a dynamic splitter.
At least normally, you create the splitter when you create the view. That will create a window that has a handle at the top, right-hand corner that the user pulls down to split the view:
To split the window, the user pulls down on the handle:
When the split is where they want it, they release the mouse button, and the view splits into two separately scrollable sections:
Since you didn't specify whether you wanted vertical or horizontal splitting, I set this one up to allow either or both:
The code for this looks something like this:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext) {
return my_splitter.Create(this,
2, 2, // 2 rows, 2 columns
CSize(20, 20), // minimum pane size
pContext);
}
where my_splitter is defined something like this:
CSplitterWnd my_splitter;
If you want to use a splitter window on demand, you need to change the parent of the current view.
So the steps are:
create a simple SDI application
On demand create a splitter window
Use SetParent to the current view and set it as a parent in the splitter window.
Create another window in the second splitter.
And the way back.
Use SetParent and attach the normal view back to the main frame.
Destroy the splitter
There are active samples how to switch a view in a current document (MSDN). It helps you how IDs must be replaced and changed.

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

help with the edit box/Input Box

I created a simple dialog with a label and edit box, then created a class, CInputDlg, added member variables for the label and edit box, and called it
CInputDlg dialog
dialog.m_label = TEXT("Enter a number:");
if (dialog.DoModal() == IDOK) {
// Do something
}
Now how do I display the text which is entered into the edit box?
Try WM_GETTEXT
http://msdn.microsoft.com/en-us/library/ms632627(v=VS.85).aspx
In the Handler for the OK button on the Dialog, you should get the TextBox.GetText(), and put it back into a public CString member m_InputString. Then, from the calling function, you can read dialog.m_InputString.