|
The key to having more than one dialog is to make sure that they are modeless dialogs. When you use the DoModal function to create dialogs, it creates a Modal dialog. This locks everything down in your application until the user exits from the modal dialog.
A modeless dialog allows the user to switch from window to window, even the dialog box that you have created. In order to create a modeless dialog, allocate a dialog object, call Create in order to create the actual window, then call ShowWindow You can do this as many times as you want to with modeless dialogs.
If you are simply using the Win32 SDK, you can use DialogBox to create modal dialogs, or CreateDialog to create modeless dialogs.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I want to use a QueryDef in my database application. I used a parameter query (Find Words: "PARAMETERS WordParam Text ( 255 ); SELECT * FROM EN_Words WHERE Word LIKE [WordParam];" ) but it doesn't work, m_pSet->GetRecordCount returns 0. When I pass a SQL string ( "SELECT * FROM EN_Words WHERE Word LIKE 'connect*' ". ("connect*" is the default value of m_strWord) ) to CDaoRecordset::Open() function instead of m_pQD, it works and m_pSet->GetRecordCount returns 5. How can I do this?
Note: I'm using VC++ 6.0 SP3
m_pDB = new CDaoDatabase;
m_pDB->Open( "data/db3.mdb" );
m_pQD = new CDaoQueryDef( m_pDB );
m_pQD->Open( "Find Words" );
COleVariant varParam( m_strWord );
m_pQD->SetParamValue( "WordParam", varParam );
m_pSet = new CDaoRecordset( m_pDB );
try
{
m_pSet->Open( m_pQD );
}
catch( CDaoException* e )
{
AfxMessageBox( e->m_pErrorInfo->m_strDescription );
e->Delete( );
return FALSE;
}
kozlu
|
|
|
|
|
Hi, friends,
I create more than one windows (different instance but belongs to the same
window class) on desktop, and want to manage them by "Cascade", "Tile
Horizontally" and "Tile Vertically" commands.
Of course the first idea is using window SDK functions: CascadeWindows(...),
TileWindows(...). The problem arise however, The two functions will restore all
other windows on desktop, which is not a good design of course.
The solution is to write my own CascadeWindows and TileWindows subroutines.
But I don't know how to do it. any idea? Thanks!
wuwu
|
|
|
|
|
If you look at the definition for CascadeWindows:
WORD CascadeWindows(
HWND hwndParent,
UINT wHow,
CONST RECT *lpRect,
UINT cKids,
const HWND *lpKids
);
lpKids is an array that allows you to specify only the windows that you want to cascade. Therefore if you use GetWindow to enumerate and find only the window handles that you are interested in, you will be able to cascade the set of windows that you want.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi,
Finally were you able to find the solution.
If yes please do post the same.
Priya Sundar
|
|
|
|
|
Hi,
i have got classes(actually GUI controls in IDD_CFormView Dialog) derived from CFormView,need to be displayed like a popup window(MDI child window) whenever the menu is choosen,this is an MDI application.
HELP!!
mohan
|
|
|
|
|
What do you mean the form needs to be displayed like a popup window? Do you mean as an mdi child window?
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Archer,
Yeah the form should be displayed like a mdi child window
mohan
|
|
|
|
|
This is not the easiest thing on the planet and does involve a few steps. I have a demo app I can send you if you want.
- Create the app (mine is called MDIFormViewTest).
- Create the dialog template resource. (I created two, IDD_DIALOG1 and IDD_DIALOG2).
- Change template's Style property to Child
- Create a CFormView derived class based on the template. Mine are CFormView1 and CFormView2.
- Create the menu option (using the MDI menu)
- Define a CMultiDocTemplate member variable in the document for each form view. For the two form views in my demo, here are their document template pointers.
class CMDIFormViewTestDoc : public CDocument
{
...
CMultiDocTemplate* m_pFormView1Template;
CMultiDocTemplate* m_pFormView2Template;
...
}
- Add the following include directive to the document's file for the childfrme.h and your formviews
#include "ChildFrm.h"
#include "FormView1.h"
#include "FormView2.h"
- Create and add the template to the application's doc manager in the document's constructor
CMDIFormViewTestDoc::CMDIFormViewTestDoc()
{
CWinApp* pApp = AfxGetApp();
ASSERT(pApp);
if (pApp)
{
m_pFormView1Template = new CMultiDocTemplate(IDR_MDIFormViewTestTYPE,
RUNTIME_CLASS(CMDIFormViewTestDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CFormView1));
pApp->AddDocTemplate(m_pFormView1Template);
m_pFormView2Template = new CMultiDocTemplate(IDR_MDIFormViewTestTYPE,
RUNTIME_CLASS(CMDIFormViewTestDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CFormView2));
pApp->AddDocTemplate(m_pFormView2Template);
}
}
- Define the following function in your document class. This function will either create the view if not present or activate it (bring it to the foreground).
void CMDIFormViewTestDoc ::CreateOrActivateFrame(CDocTemplate* pTemplate, CRuntimeClass* pViewClass)
{
CView* pView;
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
pView = GetNextView(pos);
if (pView->IsKindOf(pViewClass))
{
pView->GetParentFrame()->ActivateFrame(SW_RESTORE);
return;
}
}
CFrameWnd* pFrame = pTemplate->CreateNewFrame(this, NULL);
ASSERT(pFrame);
pTemplate->InitialUpdateFrame(pFrame, this);
}
- Add an event handler to the document for each form view menu entries and call the CreateOrActiveFrame function. Here are the two for my demo.
void CMDIFormViewTestDoc::OnFormviewsView1()
{
CreateOrActivateFrame(m_pFormView1Template, RUNTIME_CLASS(CFormView1));
}
void CMDIFormViewTestDoc::OnFormviewsView2()
{
CreateOrActivateFrame(m_pFormView2Template, RUNTIME_CLASS(CFormView2));
}
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
It's 5:30am so I'm headed off to bed in next few. Let me know if this is working for you or if you want me to send you the demo.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Archer,
Thanx,can u send me the demo, so,it would be helpfull to me.
Thanks very much for ur help.
mohan
|
|
|
|
|
You're very welcome. Demo is on the way.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Archer,
Very much thanks for the Demo, is that the code same even for if the dialog resource is IDD_FORMVIEW(now what u have done is IDD_DIALOG1).
By the way i've already develped number of of applicatons(15,every application is a single window) in MDI,now i have to integerate all the applicaton into an single MDI application, can u give me a idea.
Hope u understand my question.
THanking you
mohan
|
|
|
|
|
mohanrajh wrote:
Very much thanks for the Demo, is that the code same even for if the dialog resource is IDD_FORMVIEW(now what u have done is IDD_DIALOG1
The resource id doesn't matter as it's abstracted from my code via your CFormView-derived class.
mohanrajh wrote:
By the way i've already develped number of of applicatons(15,every application is a single window) in MDI,now i have to integerate all the applicaton into an single MDI application, can u give me a idea.
Sure. Shouldn't be too hard. I haven't actualy done the following steps, but something like this should be really close to what you need to do.
1) Open the MDI project where everything will end up
2) One by one, open the resource file of each MDI project that has only one view. Copy the needed dialog to the clipboard and then paste it into the main MDI project's resource view.
3) Copy each view's cpp and h file to the main project's folder and add it to the project.
4) If you've kept your code mainly in the view classes, you should be set at this point.
5) Now just follow the original instructions from the point at which you have your formview classes.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Hi,
Thanks for Ur step by step instruction, will try to do it.
The demo was fine, my project is in progress, is that the same kind of code, to display the window(CFormView) when the 'Button' is pressed,i.e. displaying from one view(window) to another. can i have some tips for this?
Whenever the new child is created in your Demo ,it is not destroyed, so it is addying up to the new window, so when the menu option 'New' is selected it just shows a listbox with several number of option to choose from.
is their any rectification?
Regards,
mohan
|
|
|
|
|
mohanrajh wrote:
Thanks for Ur step by step instruction, will try to do it
You're welcome
mohanrajh wrote:
to display the window(CFormView) when the 'Button' is pressed,i.e. displaying from one view(window) to another. can i have some tips for this
Same code. Just add the handler and inser the call to CreateOrActivateFrame
mohanrajh wrote:
Whenever the new child is created in your Demo ,it is not destroyed
When you call CWinApp::AddDocTemplate, the document pointer is added to the application's CDocManager m_templateList (a CPtrList object). When the CDocManager is destructed it walks this list, deleting all document templates from memory. Therefore, if you attempt to delete the entry without removing it from the list, you'll actually cause a GPF as the CDocManager will exepect it to be there.
mohanrajh wrote:
so it is addying up to the new window, so when the menu option 'New' is selected it just shows a listbox with several number of option to choose from.
is their any rectification?
Sorry. I didn't understand this question.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom,
What is the advantage of CFormView over CDialog Class, I was told by team leader to create windows(Classes) derived from CView or any classes that is derived from CView.
Actual problem is,
In half a way of our project my team leader has left the project, so i've been put in his position to integerate all the applications(window Dialogs derived from CFormView) done by other persons into a single application.
Im finding it difficult, so why not it be CDialog classes, that makes the job easier.
Is their any disadvantage to have CDialog derived GUI classes than CView.
Thanking You
Regards,
Mohan
|
|
|
|
|
I created a regular MFC DLL with a class like:
<br />
class CLASS_DECLSPEC CPacket<br />
{<br />
protected:<br />
static long m_counter;<br />
};<br />
I tried to initialize it below the class declaration as
<br />
long CPacket::m_counter = 1;<br />
but I got the redefinition problem in linking, and when i tried to initialize it in CMyWinApp::InitInstance() with
CPacket::m_counter = 1;
The compiler reported CMyWinApp can't access protected member declared in class CPacket.
How can I initialize it ?
Hiya, Everybody ^^
|
|
|
|
|
Try the following. (Note that the initialization of the static does not occur within a function.)
class __declspec(dllexport) CPacket
{
protected:
static long m_counter;
};
long CPacket::m_counter = 1;
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
By the way, as I mention in my VC++ book (had to get the plug in there), you can also do the following as long as _AFXDLL and _AFXEXT are defined.
class AFX_EXT_CLASS CPacket
{
protected:
static long m_counter;
};
long CPacket::m_counter = 1;
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
I tried before, and tried again, and I checked _AFXDLL is defined. However, it still won't work.
The compiler reported :
CPacketSender.obj : error LNK2005: "protected: static long CPacket::test" (?test@CPacket@@1JA) already defined in CpacketReceiver.obj
Hiya, Everybody ^^
|
|
|
|
|
I'm sending you a quick sample of it working...
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Hi!
Put
long CPacket::m_counter = 1;
into cpp file, not into header.
Mukkie
|
|
|
|
|
You're telling the wrong person I sent him a demo that shows how it works.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
|