|
|
Comments and Discussions
|
|
 |

|
Good article,How to use this class on WINCE project?
|
|
|
|
|
|

|
Hi Alexy,
Have you an idea on how to pass parameters to my frame or view after is been created . I ment after the frame is already on air!
comment: it was a very good MFC application!
Thanks
chiheb
|
|
|
|

|
A simple way to solve а problem:
class MyFrame
{
public:
MyFrame * instance;
...
MyFrame()
{
...
instance = this;
...
}
~MyFrame()
{
instance = NULL;
...
}
...
}
Usage:
MyFrame::instance->SendMessge(...);
MyFrame::instance->method(...);
|
|
|
|

|
thanks for your help.
chiheb
|
|
|
|

|
Hello,
this works very well in my SDI application but I'm having a very peculiar problem: Once a modal frame was opened (and closed), the application crashes in an MFC function as soon as I open a folder on my Windows desktop. Weird but true, I can reproduce it at will, here's a debugger stack trace:
myprog.exe!CWnd::WalkPreTranslateTree(HWND__ * hWndStop=0x0040053e, tagMSG * pMsg=0x00168470) Zeile 3129 + 0x5 C++
myprog.exe!AfxInternalPreTranslateMessage(tagMSG * pMsg=0x00168470) Zeile 238 + 0xe C++
myprog.exe!CWinThread::PreTranslateMessage(tagMSG * pMsg=0x00168470) Zeile 795 + 0x9 C++
myprog.exe!AfxPreTranslateMessage(tagMSG * pMsg=0x00168470) Zeile 260 C++
myprog.exe!AfxInternalPumpMessage() Zeile 183 + 0xf C++
myprog.exe!CWinThread::Run() Zeile 637 + 0x7 C++
myprog.exe!AfxWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00141f06, int nCmdShow=1) Zeile 49 + 0x7 C++
myprog.exe!WinMainCRTStartup() Zeile 251 + 0x1d C
myprog.exe!WinMainCRTStartup() Zeile 150 + 0xc C
Any idea what's happening?
Thanks and best regards
W. Rösler
|
|
|
|

|
I can't reproduce any crash on my test machine (WinXP Professional EN) with demo project code compiled with VS2005.
Do you?
|
|
|
|

|
No, the demo program works fine for me but my application crashes. It's a rather complex application, and a copyrighted one so I can't disclose the source code. I'm using XP SP2 and Visual Studio 7.
|
|
|
|

|
Thanks, Alexey. Your modal frame window is amazing. I used it and found it very useful and practical. I appreciate your work~~~
let's do programming!!
|
|
|
|

|
Hey, first off, great work to start with, windows should have this from the beginning, I don't know why it is not more prevelant.
However, when I add a new function in that lets me create a new modal frame "on top of" the existing frame, by calling a function from within that modal frame, i get an assertion failure.
It happens after i open a few successive modal frames, and then start closing them down.
It occurs in CModalFrame::FromHandle() on this line:
if (c->m_hWnd == hwnd)
Also, separately, if I set the parent of the frame to be null, it does not show up as system level top window (i.e., does not show up in the taskbar) as it does with a normal CFrameWnd
Thanks in advance for any help. I would be glad to work on a solution for this if you can get me started.
Thanks.
Brad Ulrich
|
|
|
|

|
Thanks for finding this bug!
Bug fix:
CModalFrameLock::~CModalFrameLock()
{
if (this != &_barier)
(_prev->_next = _next)->_prev = _prev;
}
To show up your top-level modal frame in the taskbar you should make the following changes in frame creation code:
int CTestFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (lpCreateStruct->hwndParent == NULL) ModifyStyleEx(0, WS_EX_APPWINDOW);
....
}
regards,
Alexey
|
|
|
|

|
Alexey,
I couldn't get either of the fixes you showed there to work??? I'm not sure what the problems are. Here are the changes I made:
I added this an existing handler because it was fast, so when you toggle to the green view, you get a new modal frame just like the last one...
void CTestView::OnViewGreen()
{
CMyCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CTestView);
context.pszMessage = _T("Hello!");
if (!CModalFrame::Run(*RUNTIME_CLASS(CTestFrame),
0 ,
IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
{
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
}
_bYellow = false; Invalidate();
and then I made the exact change you suggested for the App level window, but it doesn't seem to work either.
Hope you can help,
Thanks,
Brad
|
|
|
|

|
Thanks for bug report.
This bug fixed in version 1.2
|
|
|
|

|
Thanks for bug report.
This bug fixed in version 1.2
|
|
|
|

|
Hi.. Thanks for Your Present... Given much helpiness to me Supplementary.. Curiosity got the better of me, How to embody Modeless Frame Window ?
Good Luck ..
high
|
|
|
|

|
My projects is COM DLL's with MFC support. I'm using modal frames as a sort of properties "dialogs". By using your class, my SDI frames is working like a dream
However I have tried to do the same thing with CMDIFrameWnd too but it doesn't look good. There's something wrong with the painting of the frame. The grey area where the Childframes is supposed to reside isn't painted correctly. Can someone smarter than me, like the author of this article tell me what I might be doing wrong?
The reason for using a CMDIFrameWnd is that I want to place Listview's, Treeview's and TreeListView's in the different child windows and use MDI tabs to switch between them ( I have just purchased a commercial library with a lot of nice features in it). There is no opening of documents involved however. I just pass a pointer to it when there is a need to display the frame.
|
|
|
|

|
I am also developing a COM DLL that has a user interface. ModalFrame is the perfect solution.
CMDIFramWnd's are no problem. Create an MDI ap using appwizzard, then pass CMainFrame to ModalFrame.
Since I open the GUI in response to a call to the COM server dll, I have put the ModalFrame code into
a new method in my CWinApp derived class as shown below. You will need to add the following lines to
CModalFrameLock::DoModal() so MFC can get at the mainframe pointer:
if (CWinApp* pApp = AfxGetApp())
pApp->m_pMainWnd = pFrameWnd;
Also, your CMainFrame must use DECLARE_DYNCREATE and not DECLARE_DYNAMIC. I am using Stingray MFC
extensions, and it all works very well. Great work Alexey Nikitin!
BOOL PlugInApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance, &LIBID_STKPHASEDARRAYPLUGINLib);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_PLUGINTYPE,
RUNTIME_CLASS(CPlugInDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CPlugInView));
AddDocTemplate(pDocTemplate);
return CWinApp::InitInstance();
}
BOOL PlugInApp::InitGUI(CWnd *pParentWnd)
{
CCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CPlugInView);
POSITION TempPos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = NULL;
if (TempPos && (pTemplate = GetNextDocTemplate(TempPos)))
context.m_pNewDocTemplate = pTemplate; //GetDocument()->GetTemplate();
CRuntimeClass * pFrameClass = RUNTIME_CLASS(CMainFrame);
DWORD Style = FWS_ADDTOTITLE | WS_OVERLAPPEDWINDOW;
if (!CModalFrame::Run(*pFrameClass, false, IDR_PLUGINTYPE,
Style, pParentWnd, &context))
{
AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
}
return TRUE;
}
//changes to DoModal() below
int CModalFrameLock::DoModal()
{
//...... ommitted code
TRY
{
// create frame window
{
if (CFrameWnd * pFrameWnd = CreateFrame(CWnd::FromHandle(hWndParent)))
{
//**** add next two lines *** set mainframe pointer in CWinApp derived class so MFC can get at it.
if (CWinApp* pApp = AfxGetApp())
pApp->m_pMainWnd = pFrameWnd;
//************ end added lines **********************************************************
if (_pParentWnd && _bTopLevelParentPlacement)
{
WINDOWPLACEMENT wp = {0};
wp.length = sizeof(wp);
if (CWnd * pParentWnd = _pParentWnd->GetTopLevelParent())
{
pParentWnd->GetWindowPlacement(&wp);
pFrameWnd->SetWindowPlacement(&wp);
}
}
if (_pContext && _pContext->m_pCurrentDoc)
{
CDocument * pDocument = _pContext->m_pCurrentDoc;
CDocTemplate * pTemplate = pDocument->GetDocTemplate();
pTemplate->InitialUpdateFrame(pFrameWnd, pDocument);
}
else
{
pFrameWnd->InitialUpdateFrame(NULL, true);
}
//************** send message to frame window to open document
pFrameWnd->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL); //open a document
|
|
|
|

|
I'm just an amateur pogrammer who is bulding some plugins for a CAD program. Your excellent class has been very helpful to me, because I sometimes want to display a window with menus, toolbars and so on.
I have however run into a problem that I need some help with: I want to pass parameters to my CFrameWnd class, but I don't know how to do it. Can you or someone else help me?
I tried the code below but I got an error message that said "GetThisClass : is not a member of 'operator``global namespace"
if (!CModalFrame::FRun(*RUNTIME_CLASS(CMyFrame(Parameter)), 0 != _bPlacement, IDR_MYFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, &context))
|
|
|
|

|
1. Add your own create context struct declaration in TestFrame.h. For example:
struct CMyCreateContext : CCreateContext
{
LPCTSTR pAdditionalParamPtr;
};
2. Add the following code in CTestFrame::OnCreate method's implementation:
int CTestFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.....
CCreateContext * pContext = reinterpret_cast<CCreateContext *>(lpCreateStruct->lpCreateParams);
CMyCreateContext * pMyContext = static_cast<CMyCreateContext *>(pContext);
AfxMessageBox(pMyContext->pAdditionalParamPtr); // additional param's usage
....
}
3. Change modal frame intialization code:
CMyCreateContext context;
context.m_pNewViewClass = RUNTIME_CLASS(CTestView);
context.pAdditionalParamPtr = _T("Hello!");
if (!CModalFrame::Run( ......
3. Enjoy!
|
|
|
|

|
Wow!!
Thanks.
It's not often the author of an article will help you here at Code Project, but you did it.
Thanks again!
|
|
|
|

|
Hi,
I'm looking for an example of calling one modal from another. I have a project that I'm working on that I'm creating a modal dialog to modify a config file. However, the user should have entered a password, so I wish to before being able to access the first modal, have a second modal popup to request the password; upon successfully getting the password, the second modal will be closed, and the user will be brought back to the first so that they can do whatever updates.
If there already exists a tutorial for this, can someone point me to it? Otherwise, any help in how to do this will be greatly appreciated.
Thanks
bagsmode
|
|
|
|

|
Hi, thank you for this helper class. It really solved my problem.
One remark though, it cannot be used with any CFrameWnd derived class. It does not work with CMdiChildWnd. This for the obvious reason that a MdiChild expects a MdiFrame as its parent. With some rewriting (having a new CFrameWnd derived frame) it worked right away.
In our application we use many views which are used for editing, displaying data. In some cases such a view could be triggered from a dialog, in which case it appears behind the dialog and cannot be used untill the dialog is closed. In stead of making the dialog modeless and hiding them we now use your solution, great.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Utility class that helps to implement a modal dialog's behavior for any CFrameWnd-derived window class in an easy way.
| Type | Article |
| Licence | CPOL |
| First Posted | 31 May 2003 |
| Views | 102,011 |
| Bookmarked | 42 times |
|
|