Making my own GUI...

Started by
3 comments, last by Nibbles 21 years, 3 months ago
Hi, I''m working on a GUI class and so far i''ve got (working) button, checkboxes, and labels. Next I''d like to add Textboxes however I''m at a loss of how to do them. Can anyone give me any advice, or resources on creating Gui''s? Thank you! Scott
------------------------------------------------------------
Email
Website

"If you try and don''t succeed, destroy all evidence that you tried."
------------------------------------------------------------
Advertisement
You could do it the "real" way - intercept all of the paint messages and draw the controls in hardware. It''s a pain, but this way you have real control over what you''re doing and windows handles all of the underlying formatting stuff (e.g. multiline textboxes, string placement, etc.). You can allow windows to use some custom-defined font (CreateFont() and WM_SETFONT) to do the actual text drawing. That''s the bulk of it. For text- or editboxes, have a look at ES_xxx style, EN_xxx notification and EM_xxx message constants. It''s all in the docs.

Creating a neat-looking GUI can be a real pain - so be patient.

Hope this helps,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Crispy: You wouldn''t happen to have an example of how to customize a button would you? I was able to do a custom static / edit boxes with no problem ( just handle the WM_PAINT/WM_NCPAINT message ), but buttons are more complicated. I could manage to get it to show up right to start off with but when I clicked it, it would go back to the old style.

I''m also at a loss of how to do groupboxes. I can draw my own border with no problem, but the old one stays there.
I don''t have much time right now, try this out first - I can dig up some code sample tomorrow (I think - if I still have them - did this GUI stuff quite some time ago). Anyway, regarding buttons - be sneaky! Intercept the BN_CLICKED notification message and keep track of the button''s state. In one state set the button''s image to something, in the other state to something else. WM_SETIMAGE, I think (although it''s too obvious for ms - so it''s probably somehting else) - not sure off the top of my head. See if this works first - it''s the easier way. Groupboxes - tomorrow - gotta run.

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:Original post by Hawkeye3
Crispy: You wouldn''t happen to have an example of how to customize a button would you? I was able to do a custom static / edit boxes with no problem ( just handle the WM_PAINT/WM_NCPAINT message ), but buttons are more complicated. I could manage to get it to show up right to start off with but when I clicked it, it would go back to the old style.

I''m also at a loss of how to do groupboxes. I can draw my own border with no problem, but the old one stays there.


Follow these steps:

1) Create wrappers for all of the controls so that you can set any of the properties the easy EditBox-&gtSetColor(COLOR) kind of way
2) Subclass your controls (check out Olyseyi''s article if you don''t know how to do that), or reply accordingly - I''ll explain it to you if need be
3) For buttons, intercept the WM_CTLCOLORBTN and do all of the custom drawing there. Use as much GDI as possible - no need to pull the extra hassle of fighting with Windows as-to-who-draws-the-control onto yourself.
4) If at all possible, refrain from using a resource editor to place your controls. Do them from scratch and you''ll know precisely what is going on.

Groupboxes are essentially the same as buttons with the BS_GROUPBOX style flag set. The problems you''ll need to tackle in both cases are therefore the same.

Here''s a piece of code that overrides a button''s paint (WM_CTLCOLORBTN) message. Simply bind the rendering contect (RC) to the button''s DC and you''ll be able to draw on/in it:


     if(msg == WM_CTLCOLORBTN)   	{                CreateWindow      SetTextColor((HDC)wParam, hTextColor);      SetBkColor((HDC)wParam, hBgColor);      GetClientRect((HWND)lParam, &r);      TStaticButton* sb = AquireStaticBtn((HWND)lParam);      SelectObject((HDC)wParam, (HFONT)treeviewFont);      TEXTMETRIC tm;      GetTextMetrics((HDC)wParam, &tm);      SetTextColor((HDC)wParam, (COLORREF)sb->GetCtlTextColor());      TextOut((HDC)wParam,  r.left + 2, r.top + 4, sb->GetCaption(), strlen(sb->GetCaption()));      UnrealizeObject(hBgBrush);      return((LRESULT)hBgBrush);      }  


If there are any more questions, ask.

Hope this helps,
Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

This topic is closed to new replies.

Advertisement