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