• Create Account

## Differens bettwen window and controls

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

122
Like
Likes
Like

Posted 20 January 2002 - 06:09 AM

What is the diffrent and how do you do a control. Can someone please write the code for a control in BC++ please. If someone wondring i am folowing the tutorial on winprog.org and have camed to the chapther on controls but now I am stuck please please help. Mullvad

### #2Colin Jeanne  Members

1114
Like
Likes
Like

Posted 20 January 2002 - 11:18 AM

Technically controls are types of windows. To create a control you can create it just like you would a window but you dont have to register a class (for normal controls at least) because they''re already pre-registered classes like:

"EDIT" (which makes an edit control)

Look up CreateWindowEx on MSDN and it lists some other pre-registered window classes.

What problems are you having exactly?

122
Like
Likes
Like

Posted 21 January 2002 - 06:14 AM

No I dont have any problem thanks for you saved my days
thanks very much

122
Like
Likes
Like

Posted 22 January 2002 - 08:55 AM

I have one more quetien How the **** do you create a EDIT control and it most be some diffrens bettwen Controls and windows or??

### #5Colin Jeanne  Members

1114
Like
Likes
Like

Posted 22 January 2002 - 12:56 PM

The classname param in CreateWindowEx needs to be "EDIT".

Search MSDN for CreateWindowEx and you will find this page listing many predefined class names for various controls.

### #6Lugie  Members

122
Like
Likes
Like

Posted 22 January 2002 - 01:02 PM

although i DO know how to do this, it is quite confusing for a new person as to where to accually place this code from the f''ing manual. it might look simple to somebody doing it for a while, but it is hard for me and probably mullvad from that explanation. i was hoping somebody could clarify where to accually place the functions that accually modify the control im wanting to change, which is the static text font, color, and background.

122
Like
Likes
Like

Posted 23 January 2002 - 04:27 AM

Exactly Lugie

### #8Colin Jeanne  Members

1114
Like
Likes
Like

Posted 23 January 2002 - 03:36 PM

I''m not exactly sure what you mean by "where to place this code". Do you mean where "EDIT" goes in CreateWindowEx() or where CreateWindowEx() goes in your code?

1415
Like
Likes
Like

Posted 23 January 2002 - 04:18 PM

Generally, you want your controls to be child windows of your main window. The typical place to create controls is in the WM_CREATE handler. You'll want to use the HWND value for your main window as the parent for the controls.

The combination of styles that you can apply to a child window vary according to the type of control you want to create. For the most part, you can mix and match until you find a style that appeals to you - but there are a couple of styles that you can't mix together. WS_POPUP doesn't always play nice with the WS_CHILD style - you'll have to pay attention to what the docs for the particular type of control have to say about which styles to use. The extended styles - used with CreateWindowEx - provide a few more styles to choose from.

Most of the time you can use CW_USEDEFAULT for the dimensions to the child windows, but not always. You'll have to figure out when on your own. You can leave the HMENU value NULL or you can assign a resource id to the child - but you have to cast the id as a HMENU. The HINSTANCE value should be the same as that passed in to WinMain - you can use a global variable for that - or use GetModuleHandle(NULL) as the NULL parameter will force the return of the HMODULE for your application. HMODULE and HINSTANCE are the same thing - it's a throw back to the days of 16 bit windows. For best results, cast the return from GetModuleHandle(NULL) as a HINSTANCE. The very last parameter can be used to store a pointer to data. You won't need to use it much now, but after you get more comfortable with creating child windows, you'll find that parameter to be very helpful.

After you create the child window, you can then set the font, the color etc. Here's a little snippet:

  HWND hEdit = CreateWindowEx(WS_EX_TOOLWINDOW , TEXT("EDIT") , TEXT("") , WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | ES_AUTOHSCROLL , CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT, CW_USEDEFAULT , hwndParent , (HMENU)IDC_CHILD_EDIT , (HINSTANCE)GetModuleHandle(NULL) , NULL); if ( hEdit != NULL ) { // don't set the font if the windows bad SendMessage(hEdit , WM_SETFONT , (WPARAM)GetStockObject(ANSI_FIXED_FONT) , MAKELPARAM(TRUE, 0)); }

I should have added that this is C, so YMMV - and the TEXT macro takes care of making the string unicode when you're using unicode, but otherwise leaves the string as ansi. Sometimes you'll see _T("string") instead. It's not required, it's just good practice.

‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley

Edited by - lessbread on January 23, 2002 11:28:25 PM

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.