msg555
April 17th, 2005, 08:12 PM
How can I access controls like listboxs and buttons? or do I need to write them myself?
Also, if I wrote a control in VB, could I use it in c++?
Also, if I wrote a control in VB, could I use it in c++?
|
Click to See Complete Forum and Search --> : Controls msg555 April 17th, 2005, 08:12 PM How can I access controls like listboxs and buttons? or do I need to write them myself? Also, if I wrote a control in VB, could I use it in c++? The Wizard of Ogz April 19th, 2005, 02:16 AM There are several controls that have been predefined for windows, including buttons and listboxes. Here is an example of a call that creates a simple 'OK' button at (0,0). HWND hwnd_MyButton; int iChildIndex = 0; hwnd_MyButton = CreateWindow ( "button", "OK", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 40, 20, hwnd, (HMENU) iChildIndex, hInstance, NULL); "button" is the name of the predefined class. BS_PUSHBUTTON can be changed to any button style you like. iChildIndex is simply an identifier to differentiate this child window from any others that might be created. Listboxes are created the same way, just use "listbox" as the class name and include LBS_STANDARD in the style flags (don't use BS_PUTTON). msg555 April 20th, 2005, 06:41 AM Ok, I'll check it out. How do I know when the buttons are pushed? Should I subclass them? NoHero April 20th, 2005, 07:06 AM You have a main window and it's window procedure. The window procedure retrieves a WM_COMMAND notification with LOWORD() as the button id that was pressed. In your case iChildIndex. But it is recommended to make the id's of the button macros with a fixed value not a variable that will automatically incremented. And it's recommended to start over 100 because all values under 100 may be reserved by the system, and might cause undefined behaviour: #define ID_GOBUTTON 100 #define ID_BACKBUTTON 200 HWND hwnd_MyButton; hwnd_MyButton = CreateWindow ( "button", "OK", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 40, 20, hwnd, (HMENU) ID_GOBUTTON, hInstance, NULL); LRESULT CALLBACK MainWndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_COMMAND: { // Handle the commands ... switch ( LOWORD(wParam) ) { case 0: // iChildIndex { // Do whatever! } break; } } break; } return DefWindowProc(hwnd, msg, wParam, lParam); } msg555 April 20th, 2005, 02:58 PM Ahh. That's nice and easy :) Thanks codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |