Getting extra data from control

This is a discussion on Getting extra data from control within the Windows Programming forums, part of the Platform Specific Boards category; You know when you create a control you can add something you want at the very end? Code: HWND CreateWindow( ...

  1. #1
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293

    Getting extra data from control

    You know when you create a control you can add something you want at the very end?
    Code:
    HWND CreateWindow(
      LPCTSTR lpClassName,  // pointer to registered class name
      LPCTSTR lpWindowName, // pointer to window name
      DWORD dwStyle,        // window style
      int x,                // horizontal position of window
      int y,                // vertical position of window
      int nWidth,           // window width
      int nHeight,          // window height
      HWND hWndParent,      // handle to parent or owner window
      HMENU hMenu,          // handle to menu or child-window identifier
      HANDLE hInstance,     // handle to application instance
      LPVOID lpParam        // pointer to window-creation data
    );
    How can I access that?

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Code:
    /*...*/
    case WM_CREATE:
    {
       CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lParam);
      void*  extraData = cs->lpCreateParams;
      /*...*/
      return 0;
    }
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Is that the only way?
    I'm trying to store a pointer to the controls class,
    Code:
    void MCButon::Init()
    {
       ctrl = CreateWindow(...,(VOID*)this);
    }
    like that, so that if I want to handle it's paint routine I can just subclass it, however I'd like to be able to use the one window proc to do it...which I would just test a member of the class which I would be able to get from that pointer.

    Did that even make sense? lol.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Maybe you want something like this.

    Code:
    SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) ptrToSomething);
    
    ...
    
    // and retrieve it later...
    ptrToSomething = (cast) GetWindowLongPtr(hwnd, GWLP_USERDATA);

  5. #5
    Semi n00b Mithoric's Avatar
    Join Date
    Jun 2003
    Posts
    293
    Excellent, works like a charm..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 02:27 AM
  2. Replies: 3
    Last Post: 02-29-2008, 12:29 PM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  5. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 07:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21