• Advertisement

Archived

This topic is now archived and is closed to further replies.

Differens bettwen window and controls

This topic is 5843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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?

Invader X
Invader''s Realm

Share this post


Link to post
Share on other sites
I have one more quetien How the **** do you create a EDIT control and it most be some diffrens bettwen Controls and windows or??

Mullvad

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement