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. Creating a button without using CButton

Creating a button without using CButton

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphicshelp
4 Posts 3 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.
  • H Offline
    H Offline
    Harco
    wrote on last edited by
    #1

    Hi, Don't ask me why, but I wanna create a button the hard way. I don't want to use the CButton class. So basically I want to call the CreateWindow function with a class I registered my self. I already discovered I can use the predefined control-class WC_BUTTON with the following call to get a button on my window: CreateWindow(WC_BUTTON,"caption",,0,0,200,200,hWnd,NULL,hInstance,NULL); only problem is, I can't link an eventhandler to the button, right? Or maybe I just don't know how.. Anyways, the other way I thought of was registering my own class (using RegisterClass and the WNDCLASS struct) and specifying my own WndProc to handle events. But how do I configure the class as a button, in other words how do I make it look like a button, which is pushable? Or will it actually be that hard that I need to define my own graphics, on MBUTTONDOWN the sunken box is painted, etc. I'm just interested in the way this stuff works... if somebody knows something, please let me know too :) Many thanks in advance, DanglingDude.

    S P 2 Replies Last reply
    0
    • H Harco

      Hi, Don't ask me why, but I wanna create a button the hard way. I don't want to use the CButton class. So basically I want to call the CreateWindow function with a class I registered my self. I already discovered I can use the predefined control-class WC_BUTTON with the following call to get a button on my window: CreateWindow(WC_BUTTON,"caption",,0,0,200,200,hWnd,NULL,hInstance,NULL); only problem is, I can't link an eventhandler to the button, right? Or maybe I just don't know how.. Anyways, the other way I thought of was registering my own class (using RegisterClass and the WNDCLASS struct) and specifying my own WndProc to handle events. But how do I configure the class as a button, in other words how do I make it look like a button, which is pushable? Or will it actually be that hard that I need to define my own graphics, on MBUTTONDOWN the sunken box is painted, etc. I'm just interested in the way this stuff works... if somebody knows something, please let me know too :) Many thanks in advance, DanglingDude.

      S Offline
      S Offline
      skaanji
      wrote on last edited by
      #2

      If i right understand your question it can be done creating button using CreateWindow(WC_BUTTON ...) and then setting its WndProc to your own defined using LONG DefWndProc=SetWindowLong(hWndButton,GWL_WNDPROC,lpfnYourOwnWndProc); you should also call default button process using pointer returned by SetWindowLong() at return of your own WndProc.

      H 1 Reply Last reply
      0
      • S skaanji

        If i right understand your question it can be done creating button using CreateWindow(WC_BUTTON ...) and then setting its WndProc to your own defined using LONG DefWndProc=SetWindowLong(hWndButton,GWL_WNDPROC,lpfnYourOwnWndProc); you should also call default button process using pointer returned by SetWindowLong() at return of your own WndProc.

        H Offline
        H Offline
        Harco
        wrote on last edited by
        #3

        Aaaah, this is exactly what I needed. Thanks alot!

        1 Reply Last reply
        0
        • H Harco

          Hi, Don't ask me why, but I wanna create a button the hard way. I don't want to use the CButton class. So basically I want to call the CreateWindow function with a class I registered my self. I already discovered I can use the predefined control-class WC_BUTTON with the following call to get a button on my window: CreateWindow(WC_BUTTON,"caption",,0,0,200,200,hWnd,NULL,hInstance,NULL); only problem is, I can't link an eventhandler to the button, right? Or maybe I just don't know how.. Anyways, the other way I thought of was registering my own class (using RegisterClass and the WNDCLASS struct) and specifying my own WndProc to handle events. But how do I configure the class as a button, in other words how do I make it look like a button, which is pushable? Or will it actually be that hard that I need to define my own graphics, on MBUTTONDOWN the sunken box is painted, etc. I'm just interested in the way this stuff works... if somebody knows something, please let me know too :) Many thanks in advance, DanglingDude.

          P Offline
          P Offline
          Phil Martin
          wrote on last edited by
          #4

          An alternative to providing a new wndproc for the button, the button control sends a BN_CLICKED message through a WM_COMMAND to the parent window when the button is click. You'll be able to listen out for that. I find that easier (depending on the circumstances) than providing a new wndproc for the button. Phil

          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