Thread: Problem with SetWindowLongPtr

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    12

    Unhappy Problem with SetWindowLongPtr

    Hi!

    I've got a problem with using SetWindowLongPtr. I tried using this code, but it doesn't seem to work:

    Code:
    LONG toolWindowExStyle = WS_EX_TOOLWINDOW;
    ShowWindow(hwnd, SW_HIDE);
    
    SetWindowLongPtr(hwnd, GWL_EXSTYLE, (LONG_PTR) &toolWindowExStyle);
    
    ShowWindow(hwnd, SW_SHOW);

    However, this works perfectly:

    Code:
    ShowWindow(hwnd, SW_HIDE);
    
    SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
    
    ShowWindow(hwnd, SW_SHOW);
    I'd really appreciate it if someone could point out the mistake.

    Thanks!

    PS: BTW, I'm using Windows XP, Microsoft Visual Studio 2005 and have used "#undef UNICODE" and "#undef _UNICODE" on top of the source code.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    12

    Question Got the solution, but an explanation?

    Hi!

    I just figured out from looking at source code on the 'net that I can use:

    ShowWindow(hwnd, SW_HIDE);
    SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
    ShowWindow(hwnd, SW_SHOW);

    However, isn't WS_EX_TOOLWINDOW supposed to be a LONG rather than a pointer to a LONG? I mean I thought the function expected a pointer to a long so I initially tried giving it a pointer to a long.

    -Confused

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The function takes a LONG, not a pointer to LONG.

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    LONG_PTR SetWindowLongPtr(      
    
        HWND hWnd,
        int nIndex,
        LONG_PTR dwNewLong
    );
    --MSDN

    It does infact expect a pointer to a LONG.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    No it doesnt. If you look in the intsafe.h or baseTsd.h header file, you will see
    Code:
    typedef [public]          __int3264 LONG_PTR;
    The fact that the type name has PTR stuck at the end means absolutely nothing. The LONG_PTR variable is used whenever a pointer is casted to a signed long.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM