Drawing on a button.

This is a discussion on Drawing on a button. within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to draw on a button that i have the handle to, but i did not create or own. ...

  1. #1
    Registered User DutchStud's Avatar
    Join Date
    Oct 2001
    Posts
    43

    Drawing on a button.

    I'm trying to draw on a button that i have the handle to, but i did not create or own. I tried to use the SetClassLong() to set the WndProc, just process the WM_PAINT message, and return the rest to the old WndProc message. It doesn't work though. Does anyone have any ideas? Thanks.

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You don't need to override the button wndproc. If you give the button the BS_OWNERDRAW style, whenever the button needs to be drawn you'll get a WM_DRAWITEM messagein your main wndproc. The LPARAM for this message is a pointer to a DRAWITEMSTRUCT, which gives info on what button needs to be drawn (if you have several) and if the button has been clicked etc. You'll have to draw the whole button, though.
    zen

  3. #3
    Registered User DutchStud's Avatar
    Join Date
    Oct 2001
    Posts
    43
    Doesn't owner drawn send it to the parent window? My program is not the parent window, so i can't do it that way.

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Yes, sorry I didn't realise you didn't create the button (should have read your post properly). I'm not sure if it's possible, overriding will only work if the window your trying to override is a child of your window. Why do you want to draw on someone else's program?
    zen

  5. #5
    Registered User DutchStud's Avatar
    Join Date
    Oct 2001
    Posts
    43

    Why...

    Why would Windows Blinds (or whatever it's called) want to change how a window looks? Same concept, I think people might like it.
    Anyway...You don't think I can override it like that. Do you have any other ideas on how to do it?
    Thanks for the help.

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Actually, you might be on the right track with subclassing, but you'll have to implement a system wide hook. I'm not entirely sure how it would work but you may want to look at SetWindowsHookEx() and intercept button paint messages. There are a few tutorials that can be found using google.
    zen

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Comment from an inexperienced (but logical) Windows programmer

    I am learning Windows programming (and I absolutely love it), but I'm not sure of the technical way to do this.

    But I do have an idea. Why not just make your own custom button and the WndProc for that so you don't have to worry about intervening in the button control?

    Does that sound plausible?

    --Garfield
    1978 Silver Anniversary Corvette

  8. #8
    Registered User DutchStud's Avatar
    Join Date
    Oct 2001
    Posts
    43
    >Why not just make your own custom button and the WndProc for that so you don't have to worry about intervening in the button control?

    Because the button is in a different window, and i don't want to program what it does when clicked, i just want to redraw it.

    I'll try the hook idea. Just might work.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    You could try SetParent() to take control of the button then pass its messages back to the owner with SendMessage() after you have repainted.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User DutchStud's Avatar
    Join Date
    Oct 2001
    Posts
    43

    Question some more help...

    I'm working on the SetWindowsHookEx() method, but i need a thread id from the button and i don't have that. i couldn't find a function to give me that from a window handle. anyone have any ideas?

  11. #11
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    If you're implementing a global hook then you'll want to set this parameter to zero so that it handles all threads. I'm not sure what you're trying to do, but this might help.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing a bitmap when a button is pressed
    By h3ro in forum Windows Programming
    Replies: 5
    Last Post: 08-05-2008, 11:41 AM
  2. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 01:15 AM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. advanced problem
    By Tclord in forum C++ Programming
    Replies: 1
    Last Post: 02-07-2005, 01:37 AM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM

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