Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Modal Window 2

Status
Not open for further replies.

idog

Programmer
Mar 18, 2001
11
IL
Hello,
I want to create a modal window like modal dialog box.
But I don't want to Inherit my class from CDialog, only from CWnd.


I mean something like that:
myWnd.DoModal()


any idea??

thanks in advance
/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
Yes it is possible:

The function that makes the Window modal is
RunModalLoop which is a member of the CWnd Class.
To finish the modal loop you need a call to EndModalLoop.

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Well.
I've try this:

int CMyWnd::DoModal(CWnd *p)
{
CString st = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,0,::CreateSolidBrush(RGB(0,255,0)));
Create(st,"idog",WS_VISIBLE | WS_OVERLAPPEDWINDOW,CRect(20,30,50,70),p,0);

RunModalLoop();

return 0;
}

From the calling window:
m_myWnd.DoModal(this)

It almost work.. But the parent window is still proccessing messages. Do I need to manualy disable it.. I thought that the RunModalLoop Should make all the job for me?

/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
Create your window with styles WS_POPUP and WS_EX_DLGMODALFRAME. Use CreateWindowsEx instead of CreateWindow. John Fill
1c.bmp


ivfmd@mail.md
 
To see how exactly the Microsoft is implementing a modal loop, do a CDialog derived clas and with the debug press F11(get in) when you are on the line myDialog.DoModal().

You can pick some interesting ideeas from there.
Warning: Not all the Afx... functions that you will see can be used.

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Well..
I have manage to ceate a popup window.
But I want it to be a child window.
I can't do it because When I disable that parent window the child window is also disable.

How can I make it to work as a child window?
/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
there is also a style WS_CHILD, but is incompatible with WS_POPUP. When you create a child window, you sould set also the parent with SetParent or specify the parent handle in CreateWindow* function. John Fill
1c.bmp


ivfmd@mail.md
 
The problem occurs when I create a child window.
I can't disable the parent because when I disable the parents the child are also disabled
How can I prevent it?
I want only the parent to be disabled.

/*********************/
// Ido Grinblat
// ido@grinblat.com
// idog@cet.ac.il
/********************/
 
I don't know if you can do that.

I am thinking at a workaround like:
1.- put a flag like
private bIsDisabled;
in the parent window class

2. - in the PreTranslateMessage put at the begging
if (bIsDisabled)
return TRUE;
(this will prevent the message from being dispatched further to the window)

You will have to manipulate the bIsDisabled variabile.
As for the color of the window, if you want to change it to gray color this is much easyer. In the OnDraw(or OnPaint method) put something like:

if(bIsDisabled)
{
CDC pDC->GetDC(); //if you don't have it already
CRect rcThis;
GetWindowRect(&rcThis);
pDC->FillSolidRect(&rcThis,RGB(x,y,z));
}

And in the code after you put the bISDisabled=TRUE put also InvalidateRect(NULL) to redraw the window.

Hope this helps,
{Maybe others know a better way}
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top