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. Why Use this Return Statement?

Why Use this Return Statement?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++graphics
4 Posts 2 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.
  • U Offline
    U Offline
    ursus zeta
    wrote on last edited by
    #1

    I am reading "Windows Graphics Programming", by Feng Yuan, and in the beginning he writes his own custom Window class to demonstrate a number of code techniques. It's C++, and looks a lot like the classic style of Petzold (I'm sure many of you are familiar with Petzold). Anyway, he writes two Windows Procedures for his class, one virtual and one static, (this is kind of confusing) so that the Windows system will dispatch messages to the correct message handler (he subclasses his child windows from this class). Anyway, forget all that, my question is about something else entirely. In his header file for this custom window class, he lists the usual function calls you would make: the two Windows Procedures, constructor(void), destructor, Create, RegisterClass, and sets up the default message loop. Then, and this is what I don't understand, he does this: BOOL ShowWindow(int nCmdShow) const { return ::ShowWindow(m_hWnd, nCmdShow); } BOOL UpdateWindow(void) const { return ::UpdateWindow(m_hWnd); } What exactly do those return statements do? Oh, sorry, m_hWnd is the handle to the Window(type HWND). In his constructor, he does this: KWindow(void) //this is his custom window class { m_hWnd = NULL; }

    N 1 Reply Last reply
    0
    • U ursus zeta

      I am reading "Windows Graphics Programming", by Feng Yuan, and in the beginning he writes his own custom Window class to demonstrate a number of code techniques. It's C++, and looks a lot like the classic style of Petzold (I'm sure many of you are familiar with Petzold). Anyway, he writes two Windows Procedures for his class, one virtual and one static, (this is kind of confusing) so that the Windows system will dispatch messages to the correct message handler (he subclasses his child windows from this class). Anyway, forget all that, my question is about something else entirely. In his header file for this custom window class, he lists the usual function calls you would make: the two Windows Procedures, constructor(void), destructor, Create, RegisterClass, and sets up the default message loop. Then, and this is what I don't understand, he does this: BOOL ShowWindow(int nCmdShow) const { return ::ShowWindow(m_hWnd, nCmdShow); } BOOL UpdateWindow(void) const { return ::UpdateWindow(m_hWnd); } What exactly do those return statements do? Oh, sorry, m_hWnd is the handle to the Window(type HWND). In his constructor, he does this: KWindow(void) //this is his custom window class { m_hWnd = NULL; }

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      I assume this isn't MFC related code. He is wrapping global Windows API functions as functions within his class. The :: in ::ShowWindow() means call the global function, not one in a class. By wrapping these functions he doesn't need to a) use ::FuncName everywhere and b) doesn't need to pass m_hWnd as the wrapped function does this for him. Hope that helps. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

      U 1 Reply Last reply
      0
      • N Neville Franks

        I assume this isn't MFC related code. He is wrapping global Windows API functions as functions within his class. The :: in ::ShowWindow() means call the global function, not one in a class. By wrapping these functions he doesn't need to a) use ::FuncName everywhere and b) doesn't need to pass m_hWnd as the wrapped function does this for him. Hope that helps. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

        U Offline
        U Offline
        ursus zeta
        wrote on last edited by
        #3

        Neville, Thanks for the response. And, yes, it is non-MFC code. The ShowWindow and UpdateWindow calls are standard Win32 functions, I recognize the same calls from Petzold. But, what I don't understand is: Why return anything? Typically, when creating a window, you just write the same code as above, but without a return statement. I'm thinking that he intends to make the two variables (the HWND and the int type) available for some other potential action, I don't know what. I realize that it's an insignificant issue, but, his return statements are often of this style (and he never returns a this*). Weird.

        N 1 Reply Last reply
        0
        • U ursus zeta

          Neville, Thanks for the response. And, yes, it is non-MFC code. The ShowWindow and UpdateWindow calls are standard Win32 functions, I recognize the same calls from Petzold. But, what I don't understand is: Why return anything? Typically, when creating a window, you just write the same code as above, but without a return statement. I'm thinking that he intends to make the two variables (the HWND and the int type) available for some other potential action, I don't know what. I realize that it's an insignificant issue, but, his return statements are often of this style (and he never returns a this*). Weird.

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          Hi NB, From the ShowWindow() docs: Return Values If the window was previously visible, the return value is nonzero. If the window was previously hidden, the return value is zero. And for UpdateWindow() Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. So returning the same value as the wrapped function makes perfect sense to me. :) Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com

          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