|
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
|
|
|
|
|
doh: I use WMI to set Ip Address for my local computer.
every function works well. but nothing changed.
Why?? I use vc6,xp OS. For some header files,you can found them from vc7, just copy them to the Include directory for vc6.
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
for a test,the above line must be modified.replace "MyComputerName" with your own computer name.
I paste all the code here. A win32 console app.
Thank you everyone.
#define _WIN32_DCOM
#include
#pragma comment(lib,"Wbemuuid.lib")
#include
//#include "wbemcli.h"
#include "objbase.h"
#include
#include
#pragma comment(lib, "comsupp.lib")
void CreateOneElementBstrArray(VARIANT* v, LPCWSTR s)
{
SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
// Determine number of bytes to be allocated for ANSI string. An
// ANSI string can have at most 2 bytes per character (for Double
// Byte Character Strings.)
cbAnsi = cCharacters*2;
// Use of the OLE allocator is not required because the resultant
// ANSI string will never be passed to another COM component. You
// can use your own allocator.
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
// Convert to ANSI.
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
void PrintWMIError(HRESULT hr)
{
IWbemStatusCodeText * pStatus = NULL;
HRESULT hres = CoCreateInstance(CLSID_WbemStatusCodeText, 0,
CLSCTX_INPROC_SERVER,IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
if(S_OK == hres)
{
BSTR bstrError;
hres = pStatus->GetErrorCodeText(hr, 0, 0, &bstrError);
if(S_OK != hres)
bstrError = SysAllocString(L"Get last error failed");
LPSTR pszStatusTextA;
UnicodeToAnsi(bstrError, &pszStatusTextA);
printf("%s\n",pszStatusTextA);
CoTaskMemFree(pszStatusTextA);
pStatus->Release();
SysFreeString(bstrError);
}
}
HRESULT ConfigNet()
{
IWbemLocator *pLocator=NULL;
IWbemServices *pNamespace=NULL;
IWbemClassObject *pClass=NULL;
IWbemClassObject *pInputParamClass=NULL;
IWbemClassObject *pInputParamInstance=NULL;
IWbemClassObject * pOutInst = NULL;
BSTR InstancePath = SysAllocString(L"Win32_NetworkAdapterConfiguration=2");
HRESULT hr;
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IPAddress";
VARIANT var1;
LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
__try
{
CreateOneElementBstrArray(&var1, L"10.0.0.101");
CreateOneElementBstrArray(&var2, L"255.255.255.0");
CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLocator);
hr = pLocator->ConnectServer(Path,NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
hr = CoSetProxyBlanket( pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pClass->GetMethod(MethodName, 0, &pInputParamClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamClass->SpawnInstance(0, &pInputParamInstance);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg1Name, 0, &var1, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg2Name, 0, &var2, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL,
pInputParamInstance, &pOutInst, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
}
__finally
{
if(pInputParamInstance)
pInputParamInstance->Release();
if(pInputParamClass)
pInputParamClass->Release();
if(pClass)
pClass->Release();
if(pNamespace)
pNamespace->Release();
if(pLocator)
pLocator->Release();
}
return hr;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ConfigNet();
CoUninitialize();
printf("Program end\n");
return 0;
}
|
|
|
|
|
for my computer Win32_NetworkAdapterConfiguration.Index=2
for which IPEnabled=TRUE.
The value of the index may be different for your computer.
|
|
|
|
|
unreadable
and where are you going with this title ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
and where are you going with this title ?
I think it has something to do with the same question having gone unanswered at least three other times in the past week or so.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
not surprising if he still ask the point the same awful way...
same question, same answers...
personnaly, when i saw the post, i just closed it !
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|