Monday 28 November 2011

How do you create your own buttons or controls? in C programming

How do you create your own buttons or controls?

Controls such as buttons are typically created with a resource editor. With a resource editor, you can interactively design your windows and place pushbuttons, check boxes, radio buttons, and other controls in your window. You can then access them from within your Windows program by referring to each resource’s unique resource id (which you define).

This is not the only way, however, to create controls such as buttons. Buttons and other controls are called “child window controls.” Each child window control has the capability to trap incoming messages (such as the WM_COMMAND message) and pass them on to the parent window control. A child window control such as a pushbutton can be created by using the Windows API function CreateWindow(). It might seem odd to call the function CreateWindow() to create a pushbutton, but a control is, in effect, its own “virtual” window, and thus it needs to have its own handle. Here is some sample code that shows how this task is performed: ...
 
switch (message)
{
...
case WM_CREATE:
hwndCloseButton =
CreateWindow(“button”, /* Windows registered class name */
“Close”, /* Window text (title) */
WS_CHILD | WS_VISIBLE | PUSHBUTTON, /* Style */
50, /* Horizontal position */
50, /* Vertical position */
100, /* Width */
100, /* Height */
hwndParent, /* Handle of parent window */
0, /* Child-window identifier */
((LPCREATESTRUCT) lParam)->hInstance,
NULL); /* Window creation options */
...
}

No comments:

Post a Comment