|
acerunner316 wrote: in method 1, mMyDialog will be destroyed when its parent is closed, correct?
The windows object (HWND) will be destroyed when the parent is destroyed.
The CMyDialog object is destroyed when it goes out of scope. If it goes out of
scope while its wrapped HWND is valid, the Windows object (HWND) will be destroyed
as well.
I suppose which method you use (in addition to DavidCrow's reply) depends on the
desired scope of the object and/or whether you want it on the stack or the heap.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
acerunner316 wrote: In method 2, I have to call delete mptrMyDialog before closing
wrong. after !!!
otherwise, you delete a dialog still being displayed !
|
|
|
|
|
acerunner316 wrote: So why is method 2 generally the preferred way?
I never heared this before ... the 2 methods are exactly the same for me.
The only difference that I can see is that using pointers you can pass the pointer from function to function, or, in a class, you can store the dialog pointer on a member variable of that class.
Russell
|
|
|
|
|
method 2 is preferred because the purpose of Create is to create a modeless dialog
so imagine you have this function somewhere
<br />
void OpenMyModelessDialog()<br />
{<br />
CMyDialog mMyDialog;<br />
mMyDialog.Create(CMyDialog::IDD, this);<br />
}<br />
as soon as the function returns the modeless dialog will be destroyed OOPS!!!
|
|
|
|
|
VC++,CClientDC and OnDraw's CDC
What is the difference of drawing a geomtric shape in the CClientDC and OnDraw's CDC?
|
|
|
|
|
OnDraw's CDC is a CPaintDC - a DC obtained through the BeginPaint() API in response to WM_PAINT.
CClientDC is obtained with GetDC.
OnDraw's DC will have a clipping region selected into it which excludes areas outside the area that
needs repainting. With a CClientDC, you'd need to do that yourself.
They draw to the same place though
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a C++ Program which in which I have to read a XML file contents. The code is
#include "fstream.h"
#include "string.h"
#import "msxml2.dll" named_guids raw_interfaces_only
using namespace MSXML2;
using namespace std;
void main()
{
IXMLDOMDocumentPtr m_pXmlDoc;
IXMLDOMNodePtr m_pProductNode;
HRESULT hr = m_pXmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument);
_variant_t vtFileName("my_xml.xml");
VARIANT_BOOL vtRetVal;
m_pXmlDoc->load(vtFileName,&vtRetVal);
}
The CreateInstance() call fails and m_pXmlDoc is NULL.
Why am I not getting the instance? What is wrong in this piece of code?
|
|
|
|
|
koumodaki wrote: The CreateInstance() call fails...
And the value of hr would be what?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
On my PC hr = -2147221008 while debugging......guess its some junk value
|
|
|
|
|
It appears you have failed to call CoInitialize() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks David. I had not called CoInitialize(). It works now.
|
|
|
|
|
You have guessed wrong. Use the Error Lookup tool to get the description of that error.
|
|
|
|
|
Michael Dunn wrote: You have guessed wrong.
Well that hardly ever happens.
|
|
|
|
|
Try
HRESULT hr = m_pXmlDoc.CreateInstance( __uuidof(MSXML2::DOMDocument40));
This way, you ask explicitly for a DOM document version 4.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I get an error while compiling.
error C2039: 'DOMDocument40' : is not a member of 'MSXML2'
error C2065: 'DOMDocument40' : undeclared identifier
Could you please tell me th eproper file to include?
|
|
|
|
|
*I* do
#import "../thirdparty/msxmlbase/msxmlinclude/msxml2.tlb" named_guids but the path will be totally different for you.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I'm building an SDI app in VC++6. From Document, user can click on a button which opens a Dialog. Dialog has a CComboBox. The values of the CComboBox are populated from a dynamic array (~200 items) stored in the Document.
I figured out how to populate the CComboBox with static values using AddString in the InitDialog method of the Dialog.
BOOL CMslDatabase::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
m_msl_list.AddString("ICBM");<br />
m_msl_list.AddString("SRBM");<br />
return TRUE;<br />
}
Here's my problem. How do I pass the array to the Dialog so I can use AddString to populate the ComboBox with ~200 dynamic values?
|
|
|
|
|
penny black wrote: Here's my problem. How do I pass the array to the Dialog
You can do it when constructing the CMslDatabase object, or after by calling a CMslDatabase method. If you opt for the latter, be sure and do it before calling DoModal() .
penny black wrote: m_msl_list.AddString("ICBM");
Missles, eh?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
from where you call the dialog, something like (pseudo c++ code):
...
CMslDatabase dlg;
dlg.SetArray( m_YourArray );
dlg.DoModal();
...
class CMslDatabase
{
void SetArray ( std::vector& v ){ m_vector = v;};
std::vector< std::string > m_vector;
};
BOOL CMslDatabase::OnInitDialog()
{
CDialog::OnInitDialog();
std::vector< std::string >::iterator it = m_vector.begin();
while ( it != m_vector.end()
{
std::string aString = *it;
m_msl_list.AddString( aString.c_str() );
++it;
}
return TRUE;
}
|
|
|
|
|
Either have your document fill the dialog between object creation and dialog Display,
CMyDialogWithComboBox dlg;
dlg.m_Array = Array; or hand the dialog in its constructor a pointer to your document, and fill in OnInitDialog()
BOOL CMslDatabase::OnInitDialog()
{
if( !m_pDoc) {
return;
}
CDialog::OnInitDialog();
m_msl_list.AddString( m_pDoc->m_List[0]);
m_msl_list.AddString( m_pDoc->m_List[1]);
return TRUE;
}
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Thanks for all the quick responses. Simpler than I was trying to make it.
Working on a "video game"
|
|
|
|
|
I'll give you a complex answer if it will *help* ?
But as you've been shown, there are fewer ways of skinning a cat than passing parameters.
For an array that could be large, I'd favour passing a pointer to the array, or to the doc containing the array.
If the array can be large, then you'll also want to look at CWnd::SetRedraw on the combobox so it doesn't fill slowly and visibly.
Iain.
|
|
|
|
|
I am trying to create a System Wide hook to listen to Window Creation events in the system .
For this purpose , I set up a new Project - > an regular MFC DLL
I have created SHARED regions where I Store the hook id created , the module and the HOOKPROC values .
The problem is that I am still not able to intercept any Window Creation Events .
Clearly am missing something
Help is appreciated.
Below is the main code of my DLL
<br />
<br />
#include "stdafx.h"<br />
#include "HookEg.h"<br />
#include "HookCommon.h"<br />
<br />
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif<br />
<br />
<br />
<br />
<br />
#pragma data_seg(".SHARED")<br />
<br />
HHOOK hookid = 0;
HINSTANCE mod =NULL;
HOOKPROC proc =NULL;
<br />
#pragma data_seg()<br />
#pragma comment(linker, "/section:.SHARED,rws")<br />
<br />
<br />
static LRESULT CALLBACK ShellProc(int nCode,WPARAM wParam,LPARAM lParam)<br />
{ <br />
TRACE("Shell message rcvd nCode = %d wParam = %d lParam=%d \n",nCode,wParam,lParam);<br />
if(nCode == HSHELL_WINDOWCREATED )<br />
{<br />
TRACE("new window created \n");<br />
<br />
}<br />
else if(nCode == HSHELL_WINDOWDESTROYED)<br />
{ <br />
<br />
}<br />
<br />
return CallNextHookEx(hookid, nCode, wParam, lParam); <br />
}<br />
<br />
<br />
<br />
<br />
BEGIN_MESSAGE_MAP(CHookEgApp, CWinApp)<br />
END_MESSAGE_MAP()<br />
<br />
<br />
CHookEgApp::CHookEgApp()<br />
{<br />
}<br />
<br />
<br />
CHookEgApp theApp;<br />
<br />
BOOL CHookEgApp::InitInstance() <br />
{<br />
<br />
<br />
return CWinApp::InitInstance();<br />
}<br />
<br />
int CHookEgApp::ExitInstance() <br />
{<br />
if(hookid)<br />
{<br />
if(UnhookWindowsHookEx(hookid))<br />
hookid = 0; <br />
else<br />
TRACE("Error = %d\n",GetLastError());<br />
}<br />
<br />
return CWinApp::ExitInstance();<br />
}<br />
<br />
<br />
HOOKEG_API void HookegInit() <br />
{<br />
<br />
hookid = 0;<br />
<br />
mod = GetModuleHandle("HookEg.dll");<br />
<br />
proc = ShellProc;<br />
<br />
hookid = SetWindowsHookEx(WH_SHELL , proc , mod , NULL);<br />
<br />
<br />
}<br />
<br />
|
|
|
|
|
Try using WH_CBT instead of WH_SHELL, and watch for the HCBT_CREATEWND code.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I didnt realize
1. You cannot debug a Hook or expect TRACE statements in the IDE while debugging
2. I was adding the Hook creation in the InitInstance method so even though my app exited the Hook was alive !!!
Just learnt these the HARD way !
Engineering is the effort !
|
|
|
|