|
|
Sorry I dont' know what you mean. The dialog is created via clicking a button on a CFormView derived class and its pointer (this) is passed to the Modeless Dialog constructor.
|
|
|
|
|
a window's parent is set by the code that creates the window (in the case of a modeless dialog, that's generally your code). if you don't set a parent wnd (usually in the dlg ctor, or in Create) it will remain NULL.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Look at my first post. I am setting the parent window to the dialog.
Please give me an example if I am off base.
|
|
|
|
|
|
Here is the code that creates the modeless dialog box
void CFormsFormsFormsView::OnModelessheap() {
if(m_pModeless){
m_pModeless->SetForegroundWindow();
m_pModeless->CenterWindow();
}
else {
m_pModeless = new CModelessDialogHeap(this);
m_pModeless->Create(CModelessDialogHeap::IDD);
m_pModeless->CenterWindow();
m_pModeless->ShowWindow(SW_SHOW);
}
}
It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box.
Thanks
|
|
|
|
|
can you step into that Create call ?
i suspect some other bit of code somewhere is setting the dlg's m_pParentWnd to NULL. Create is another common place to set that variable.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Yes I've stepped through the code. Like I said, the parent is passed into it just fine because I can assign that pointer to a member variable.
But GetParent() should do the same thing...right?
Appreciate your help. Here is the code
CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/)
: CDialog(CModelessDialogHeap::IDD, pParent)
{
//{{AFX_DATA_INIT(CModelessDialogHeap)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_parent=pParent;
}
|
|
|
|
|
mx483 wrote:
m_pModeless->Create(CModelessDialogHeap::IDD);
The only thing I do different for my modeless dialogs is to call Create(IDD) from within the dialog's constructor.
Does commenting out the call to CenterWindow() have any effect?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I've tried this several different ways and it works fine each time (i.e., GetParent() returns the correct value). What does the constructor of CModelessDialogHeap look like? From where are you calling GetParent() ? Is CModelessDialogHeap derived from CDialog ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I sent the constructor of CModelessDialogHeap already. Here it is again.
CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/)
: CDialog(CModelessDialogHeap::IDD, pParent)
{
//{{AFX_DATA_INIT(CModelessDialogHeap)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_parent=pParent;
}
CModelessDialogHeap is derived from CDialog.
As long as the parent exists it shouldn't matter where GetParent is called. But I put a button on the dialog and attempted it while it was still active.
void CModelessDialogHeap::OnButton1()
{
CWnd * tmpPtr = this->GetParent();
}
Thanks for your help as well David.
|
|
|
|
|
At this point my suggestion would be to create a little dialog-based test application that does nothing but create and show a modeless dialog in the OnInitDialog() method. Let me know how that works out.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Okay I created a dialog based app and the GetParent function works as advertised. So now we know that the problem is more likely a conceptual one. The mainApp dialog is a popup and the CDialog derived modeless dialog is also a popup. Code is exactly the same as the problem project.
In the problem project example I couldn't get to work I had an MDI application that had a CFormView derived class. It was a child. That child had a button when pressed would create the CDialog derived class modeless dialog. The CDialog derived class was set as PopUp. So can't a child spawn a modeless dialog (works) and can't that dialog in turn know it's spawning entity as Parent (GetParent).
I won't mention anything about child as it was demonstrated to me by David that a modeless dialog shouldn't have a child style. I agree.
I think this is important because these are pretty basic concepts.
Thanks for your help.
|
|
|
|
|
hi
i want to display the bitmap on the picture box in visual c++.code i had used is below if the loadbitmap the id of bitmap present in the resource is passed it loads and displays but if the id is not in the resource then it does not displays the bitmap.
bitmap=LoadBitmap(NULL,MAKEINTRESOURCE("C:\\ff.bmp"));
if(bitmap==NULL) //it displays the fail
MessageBox("fail ");
m_pic.SetBitmap(bitmap);
i want to display the image whose id is not present in the resource. how to do that.
ddd
|
|
|
|
|
if youwant show a bimap file , you can use CImage Class.
|
|
|
|
|
if you want show a bitmap file ,like c:\\ff.bmp, you can use CImage MFC Class(VC++7 ).
|
|
|
|
|
tasleem143 wrote:
bitmap=LoadBitmap(NULL,MAKEINTRESOURCE("C:\\ff.bmp"));
What's this? MAKEINTRESOURCE() does not take a string for its argument.
In the project's resource.h file:
#define IDC_MYBITMAP 1234 // or some other appropriate value In the project's .rc file:
IDC_MYBITMAP BITMAP DISCARDABLE "c:\\ff.bmp" In the .cpp file:
HBITMAP hBitmap = LoadBitmap(NULL, MAKEINTRESOURCE(IDC_MYBITMAP));
if (NULL == hBitmap)
AfxMessageBox("LoadBitmap() failed.");
else
m_pic.SetBitmap(hBitmap);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi
I have developed a dialogue based MFC application. On that dialogue I have used two ActiveX control called WebBrowserCtrl, Their IDs are as : IDC_EXPLOREER1 AND IDC_EXPLORER2.
I have declared it in my CWebBrowserDlg.h file as
CWebBrowser2 m_WebBrowserCtrl;
CWebBrowser2 m_WebBrowserCtrl2;
bool m_bWebBrowserCtrl;
Now what I want to do is when initially I load form It should show some site on it. Then after few seconds it should show another ActiveX control having different site loaded into it.
For this I have used OnTimer() function and have one boolean variable which i set to true and flase alternatively....
It works fine for the first time.....I mean first it shows content into IDC_EXPLORE1 then it shows Content into IDC_EXPLORER2 and after that it shows illegal error (Abort, Retry, Ignore) and on debuging it by pressing Retry button it takes me to following code in WINOCC.cpp file
Here it shows m_hWnd as NULL.
BOOL CWnd::ShowWindow(int nCmdShow)
{
ASSERT(::IsWindow(m_hWnd));
if (m_pCtrlSite == NULL)
return ::ShowWindow(m_hWnd, nCmdShow);
else
return m_pCtrlSite->ShowWindow(nCmdShow);
}
My code is as following.....
So for that I have written code like this :
//In WebBrowserDlg.cpp
BOOL CWebBrowserDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//Set the timer so that after every 15 seconds it will call OnTimer function
m_nTimer = SetTimer(1, 15000, 0);
m_bWebBrowserCtrl = true;
// navigate to main web page, my favorite web page
m_WebBrowserCtrl.Navigate(m_Site, NULL, NULL, NULL, NULL);
m_WebBrowserCtrl2.Navigate("http://www.google.co.in/", NULL, NULL, NULL, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWebBrowserDlg::OnTimer(UINT nIDEvent)
{
if (m_bWebBrowserCtrl == true)
{
m_WebBrowserCtrl.ShowWindow(SW_HIDE);
m_WebBrowserCtrl2.ShowWindow(SW_SHOW);
m_bWebBrowserCtrl = false; //I have forgotten to write this two
//sentence....where as actually it is in my code
}
else
{
m_WebBrowserCtrl.ShowWindow(SW_SHOW);
m_WebBrowserCtrl2.ShowWindow(SW_HIDE);
m_bWebBrowserCtrl = true;//I have forgotten to write this two
//sentence....where as actually it is in my code
}
}
Any help please....? Any other idea to show two control alternatively...
Regards
Amarelia Maehsh
Gujarat
India
-- modified at 9:36 Wednesday 14th September, 2005
|
|
|
|
|
Just a thought...
In your OnTimer you probably need to toggle the m_bWebBrowserCtrl variable:
void CWebBrowserDlg::OnTimer(UINT nIDEvent)<br />
{<br />
if (m_bWebBrowserCtrl == true)<br />
{<br />
m_WebBrowserCtrl.ShowWindow(SW_HIDE); <br />
m_WebBrowserCtrl2.ShowWindow(SW_SHOW);<br />
}<br />
else<br />
{<br />
m_WebBrowserCtrl.ShowWindow(SW_SHOW);<br />
m_WebBrowserCtrl2.ShowWindow(SW_HIDE);<br />
}<br />
m_bWebBrowserCtrl = !m_bWebBrowserCtrl;<br />
}<br />
Without that, the second time in, the m_WebBrowserCtrl is already hidden.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
<kmedcalf@ev1.net>
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-- modified at 9:24 Wednesday 14th September, 2005
|
|
|
|
|
Hi
thankx for taking time to see my question...
Actually the line you have told me was in my code but I have forgotten to write here while posting the question. Now I have corrected it and if you can check it out again it will be gr8 help
Regards and Thankx in advance
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
I'm not sure if this is the reason for your problem, but shouldn't you put this statement last in your OnTimer()-funcion?
CDialog::OnTimer(nIDEvent);
|
|
|
|
|
Hi to all,
Can u help me in How to disable a Menu Item. i am trying this code but not getting.
CMenu menu;
menu = AfxGetMainWnd()->GetMenu();
menu->EnableMenuItem(ID,MF_BYCOMMAND|MF_DISABLED);
Urgent
bye
|
|
|
|
|
Not exactly sure what your issue is. Is it that your code does not compile (sorry, not sure if your new to c++ / mfc or if it's just a typo)?
If your code is not getting through a compile, try:
CMenu *menu = AfxGetMainWnd()->GetMenu();<br />
if (menu)<br />
menu->EnableMenuItem(ID,MF_BYCOMMAND|MF_DISABLED);
That should work fine.
Also, you can insert an update hander with MFC. In your message map, insert
<br />
BEGIN_MESSAGE_MAP(yourClassName, yourBaseClass)<br />
ON_UPDATE_COMMAND_UI(ID , OnUpdateMyMenu)
END_MESSAGE_MAP()
In your class definition insert
afx_msg void OnUpdateMyMenu(CCmdUI *pCMDUI)<br />
And the implementation:
void yourClassName::OnUpdateMyMenu(CCmdUI *pCmdUI)<br />
{<br />
pCmdUI->Enable(FALSE );<br />
}<br />
-Dy
|
|
|
|
|
Hi to all,
Can u help me in How to disable a Menu Item. i am trying this code but not getting.
CMenu menu;
menu = AfxGetMainWnd()->GetMenu();
menu->EnableMenuItem(ID,MF_BYCOMMAND|MF_DISABLED);
|
|
|
|
|
From MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wcemfc4/html/aflrfcmenucolcolenablemenuitem.asp[^])
This method either enables or disables and dims a menu item.
UINT EnableMenuItem (
UINT nIDEnableItem,
UINT nEnable );
Parameters
nIDEnableItem
Specifies the menu item to be enabled, as determined by nEnable. This parameter can specify pop-up menu items as well as standard menu items.
nEnable
Specifies the action to take. It can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by using the bitwise OR operator. These values have the following meanings:
MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.
MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position zero.
MF_DISABLED Disables the menu item so that it cannot be selected but does not dim it.
MF_ENABLED Enables the menu item so that it can be selected and restores it from its dimmed state.
MF_GRAYED Disables the menu item so that it cannot be selected and dims it.
Return Value
Previous state (MF_DISABLED, MF_ENABLED, or MF_GRAYED) or –1 if not valid.
So, try MF_GRAYED. The the menu item will be both disabled and grayed.
-- modified at 8:56 Wednesday 14th September, 2005
|
|
|
|