How to create a window in general?
-
Even with the WS_OVERLAPPEDWINDOW style added? Can you post the line(s) of code calling Create()? Mark
Hi Mark: Sure, here it is:
CRuntimeClass* pRTC; pRTC = RUNTIME_CLASS( COneView ); pWindow = (CWnd *)pRTC->CreateObject( ) ; pWindow->Create( (LPCTSTR)m_strTypeOneView, TEXT("One Little View"), WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, CRect(0, 0, 400, 300), this, 4567 );
The "mstrTypeOneView" string contains the result returned from an earlier call to AfxRegisterWndClass:try { m_strTypeOneView = AfxRegisterWndClass( 0, ::LoadCursor(NULL, IDC_CROSS), (HBRUSH)reinterpret_cast(COLOR_BACKGROUND+1), ::LoadIcon(NULL, IDI_APPLICATION)); } catch (CResourceException* pEx) { AfxMessageBox(_T("Couldn't register class! (Already registered?)")); pEx->Delete(); }
I'm sure that the window registration is working because I have made alterations to the background color and the ICON and the window responds as expected. Thanks, Mark -
Hi Mark: Sure, here it is:
CRuntimeClass* pRTC; pRTC = RUNTIME_CLASS( COneView ); pWindow = (CWnd *)pRTC->CreateObject( ) ; pWindow->Create( (LPCTSTR)m_strTypeOneView, TEXT("One Little View"), WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, CRect(0, 0, 400, 300), this, 4567 );
The "mstrTypeOneView" string contains the result returned from an earlier call to AfxRegisterWndClass:try { m_strTypeOneView = AfxRegisterWndClass( 0, ::LoadCursor(NULL, IDC_CROSS), (HBRUSH)reinterpret_cast(COLOR_BACKGROUND+1), ::LoadIcon(NULL, IDI_APPLICATION)); } catch (CResourceException* pEx) { AfxMessageBox(_T("Couldn't register class! (Already registered?)")); pEx->Delete(); }
I'm sure that the window registration is working because I have made alterations to the background color and the ICON and the window responds as expected. Thanks, MarkJethro63 wrote:
The "mstrTypeOneView" string contains the result returned from an earlier call to AfxRegisterWndClass:
How much earlier. It's not safe to store the returned pointer. It should be copied into your own buffer (a CString is easiest). The title bar isn't hidden under a toolbar is it? If so, adjust the CRect top and left params. Mark
-
Jethro63 wrote:
The "mstrTypeOneView" string contains the result returned from an earlier call to AfxRegisterWndClass:
How much earlier. It's not safe to store the returned pointer. It should be copied into your own buffer (a CString is easiest). The title bar isn't hidden under a toolbar is it? If so, adjust the CRect top and left params. Mark
Hi Mark: "m_strTypeOneView" is a CString member of CMainFrame. The call to AfxRegisterWindClass is carried out in CMainFrame::OnCreate. The string returned is copied to "m_strTypeOneView" at that point. So, I believe that the returned class name is protected and not volatile. I thought of your second point shortly after I sent my last reply to you and moved the upper-left coordinates of the window to 40,40. The window moves but does not change in appearance. Mark
-
Hi Mark: "m_strTypeOneView" is a CString member of CMainFrame. The call to AfxRegisterWindClass is carried out in CMainFrame::OnCreate. The string returned is copied to "m_strTypeOneView" at that point. So, I believe that the returned class name is protected and not volatile. I thought of your second point shortly after I sent my last reply to you and moved the upper-left coordinates of the window to 40,40. The window moves but does not change in appearance. Mark
Jethro63 wrote:
"m_strTypeOneView" is a CString member of CMainFrame. The call to AfxRegisterWindClass is carried out in CMainFrame::OnCreate. The string returned is copied to "m_strTypeOneView" at that point. So, I believe that the returned class name is protected and not volatile.
:doh: Cool sorry about that :)
Jethro63 wrote:
I thought of your second point shortly after I sent my last reply to you and moved the upper-left coordinates of the window to 40,40. The window moves but does not change in appearance.
Hmm That's just not cool! What if you create it using the default class (pass NULL for 1st param of Create())? In my little MFC tester app (that I use to test code I post here) I have this: pWnd->Create(NULL, _T("Window Name"), WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW, CRect(50,50,300,200), this, 12345, NULL); And it creates as intended - caption, system menu, max/minimize buttons, etc.
-
Hi Mark: "m_strTypeOneView" is a CString member of CMainFrame. The call to AfxRegisterWindClass is carried out in CMainFrame::OnCreate. The string returned is copied to "m_strTypeOneView" at that point. So, I believe that the returned class name is protected and not volatile. I thought of your second point shortly after I sent my last reply to you and moved the upper-left coordinates of the window to 40,40. The window moves but does not change in appearance. Mark
CRuntimeClass* pRTC; pRTC = RUNTIME_CLASS( COneView ); pWindow = (CWnd *)pRTC->CreateObject( ) ; I haven't looked at the MFC source code in a while but if COneView is CView-derived then maybe some style flags are getting stripped off by MFC since views are meant to be used in a frame.
-
CRuntimeClass* pRTC; pRTC = RUNTIME_CLASS( COneView ); pWindow = (CWnd *)pRTC->CreateObject( ) ; I haven't looked at the MFC source code in a while but if COneView is CView-derived then maybe some style flags are getting stripped off by MFC since views are meant to be used in a frame.
I think you might be right about that and I am going to quickly try to create a different view derived directly from CWnd. Unfortunately, I have to go and put my son to bed now, so I will not be able to continue this thread this evening (unless much later). Thanks again for your advice. I will let you know what happens next. Mark
-
I think you might be right about that and I am going to quickly try to create a different view derived directly from CWnd. Unfortunately, I have to go and put my son to bed now, so I will not be able to continue this thread this evening (unless much later). Thanks again for your advice. I will let you know what happens next. Mark
Jethro63 wrote:
I am going to quickly try to create a different view derived directly from CWnd.
You may like to derive it from
CView
instead ofCWnd
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
Jethro63 wrote:
I am going to quickly try to create a different view derived directly from CWnd.
You may like to derive it from
CView
instead ofCWnd
.Prasad Notifier using ATL | Operator new[],delete[][^]
Hi Prasad. Thank you for your response. The original window that I am having trouble creating was derived from CView. The suggestion that Mark Salsbery is making is that this could be the problem. I am going to try creating a window derived from CWnd, just to see what happens. Cheers, Mark
-
Hi Prasad. Thank you for your response. The original window that I am having trouble creating was derived from CView. The suggestion that Mark Salsbery is making is that this could be the problem. I am going to try creating a window derived from CWnd, just to see what happens. Cheers, Mark
Jethro63 wrote:
The suggestion that Mark Salsbery is making is that this could be the problem
Mark was refering to certain styles like
WS_OVERLAPPEDWINDOW
, would be inappropriate for view class.Prasad Notifier using ATL | Operator new[],delete[][^]
-
Hi Prasad. Thank you for your response. The original window that I am having trouble creating was derived from CView. The suggestion that Mark Salsbery is making is that this could be the problem. I am going to try creating a window derived from CWnd, just to see what happens. Cheers, Mark
Probably, this is last post this year. Its friday 11:37 PM here. Can continue on your problem on tuesday. Happy new year.:)
Prasad Notifier using ATL | Operator new[],delete[][^]