Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to create a window in general?

How to create a window in general?

Scheduled Pinned Locked Moved C / C++ / MFC
c++adobehelptutorialquestion
15 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mark Salsbery

    Try this style in the sample code I posted (I changed it there as well) in the Create() call: WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW This will help you see the window better :-D

    J Offline
    J Offline
    Jethro63
    wrote on last edited by
    #4

    Hi Mark: Thanks for your response. Its working except the window is displaying without a caption. I'm getting only a rectangular frame with no caption and no way to move it around. I AM able to resize it though... Mark

    M 1 Reply Last reply
    0
    • J Jethro63

      Hi Mark: Thanks for your response. Its working except the window is displaying without a caption. I'm getting only a rectangular frame with no caption and no way to move it around. I AM able to resize it though... Mark

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #5

      Even with the WS_OVERLAPPEDWINDOW style added? Can you post the line(s) of code calling Create()? Mark

      J 1 Reply Last reply
      0
      • M Mark Salsbery

        Even with the WS_OVERLAPPEDWINDOW style added? Can you post the line(s) of code calling Create()? Mark

        J Offline
        J Offline
        Jethro63
        wrote on last edited by
        #6

        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

        M 1 Reply Last reply
        0
        • J Jethro63

          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

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #7

          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

          J 1 Reply Last reply
          0
          • M Mark Salsbery

            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

            J Offline
            J Offline
            Jethro63
            wrote on last edited by
            #8

            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

            M 2 Replies Last reply
            0
            • J Jethro63

              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

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #9

              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.

              1 Reply Last reply
              0
              • J Jethro63

                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

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #10

                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.

                J 1 Reply Last reply
                0
                • M Mark Salsbery

                  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.

                  J Offline
                  J Offline
                  Jethro63
                  wrote on last edited by
                  #11

                  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

                  P 1 Reply Last reply
                  0
                  • J Jethro63

                    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

                    P Offline
                    P Offline
                    prasad_som
                    wrote on last edited by
                    #12

                    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 of CWnd.

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    J 1 Reply Last reply
                    0
                    • P prasad_som

                      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 of CWnd.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      J Offline
                      J Offline
                      Jethro63
                      wrote on last edited by
                      #13

                      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

                      P 2 Replies Last reply
                      0
                      • J Jethro63

                        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

                        P Offline
                        P Offline
                        prasad_som
                        wrote on last edited by
                        #14

                        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[][^]

                        1 Reply Last reply
                        0
                        • J Jethro63

                          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

                          P Offline
                          P Offline
                          prasad_som
                          wrote on last edited by
                          #15

                          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[][^]

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups