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. void CWnd::CenterWindow(CWnd* pAlternateOwner) small (?) bug [modified]

void CWnd::CenterWindow(CWnd* pAlternateOwner) small (?) bug [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelp
6 Posts 4 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.
  • C Offline
    C Offline
    Cristian Amarie
    wrote on last edited by
    #1

    Not really a question, but rather signaling a MFC pitfall... wincore.cpp, approx. line 3152 (Visual C++ 6.0, SP6) void CWnd::CenterWindow(CWnd* pAlternateOwner) { ASSERT(::IsWindow(m_hWnd)); // determine owner window to center against DWORD dwStyle = GetStyle(); HWND hWndCenter = pAlternateOwner->GetSafeHwnd(); if (pAlternateOwner == NULL) { ... Seems to me that pAlternateOwner calls first GetSafeHwnd, then is tested if is NULL... -- modified at 1:55 Monday 7th August, 2006

    M H D 3 Replies Last reply
    0
    • C Cristian Amarie

      Not really a question, but rather signaling a MFC pitfall... wincore.cpp, approx. line 3152 (Visual C++ 6.0, SP6) void CWnd::CenterWindow(CWnd* pAlternateOwner) { ASSERT(::IsWindow(m_hWnd)); // determine owner window to center against DWORD dwStyle = GetStyle(); HWND hWndCenter = pAlternateOwner->GetSafeHwnd(); if (pAlternateOwner == NULL) { ... Seems to me that pAlternateOwner calls first GetSafeHwnd, then is tested if is NULL... -- modified at 1:55 Monday 7th August, 2006

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      GetSafeHwnd() works fine if pAlternateOwner is null:

      HWND CWnd::GetSafeHwnd() const { return this == NULL ? NULL : m_hWnd; }

      If the this object is NULL, it just returns NULL.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      C 1 Reply Last reply
      0
      • C Cristian Amarie

        Not really a question, but rather signaling a MFC pitfall... wincore.cpp, approx. line 3152 (Visual C++ 6.0, SP6) void CWnd::CenterWindow(CWnd* pAlternateOwner) { ASSERT(::IsWindow(m_hWnd)); // determine owner window to center against DWORD dwStyle = GetStyle(); HWND hWndCenter = pAlternateOwner->GetSafeHwnd(); if (pAlternateOwner == NULL) { ... Seems to me that pAlternateOwner calls first GetSafeHwnd, then is tested if is NULL... -- modified at 1:55 Monday 7th August, 2006

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Is pAlternateOwner valid?

        _**


        **_

        WhiteSky


        C 1 Reply Last reply
        0
        • M Michael Dunn

          GetSafeHwnd() works fine if pAlternateOwner is null:

          HWND CWnd::GetSafeHwnd() const { return this == NULL ? NULL : m_hWnd; }

          If the this object is NULL, it just returns NULL.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          C Offline
          C Offline
          Cristian Amarie
          wrote on last edited by
          #4

          Correct, I didn't checked. Sorry about that.

          1 Reply Last reply
          0
          • H Hamid Taebi

            Is pAlternateOwner valid?

            _**


            **_

            WhiteSky


            C Offline
            C Offline
            Cristian Amarie
            wrote on last edited by
            #5

            Can be NULL or not, but Mike Dunn corrected me. GetSafeHwnd returns NULL if "this" is NULL. A little bit strange to me to have CWnd *pAlternateOwner = NULL; HWND hwndAlternate = pAlternateOwner->GetSafeHwnd(); // NULL because pAlternateOwner is NULL

            1 Reply Last reply
            0
            • C Cristian Amarie

              Not really a question, but rather signaling a MFC pitfall... wincore.cpp, approx. line 3152 (Visual C++ 6.0, SP6) void CWnd::CenterWindow(CWnd* pAlternateOwner) { ASSERT(::IsWindow(m_hWnd)); // determine owner window to center against DWORD dwStyle = GetStyle(); HWND hWndCenter = pAlternateOwner->GetSafeHwnd(); if (pAlternateOwner == NULL) { ... Seems to me that pAlternateOwner calls first GetSafeHwnd, then is tested if is NULL... -- modified at 1:55 Monday 7th August, 2006

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Cristian Amarie wrote:

              HWND hWndCenter = pAlternateOwner->GetSafeHwnd();

              GetSafeHwnd() is an inline function, so there's nothing to dereference.


              "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

              "Judge not by the eye but by the heart." - Native American Proverb

              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