Page 1 of 1

[C] GUIs

Posted: Wed 16 Dec, 2009 3:35 am
by Wesley
I'm going to be learning C (finally) next semester, so I started looking in an old book I had on my shelf about C. I couldn't find anything in it about GUI programming, and I can't seem to find any GUI examples on the web either.

Is it practical to create GUI programs in C?

Re: [C] GUIs

Posted: Wed 16 Dec, 2009 12:48 pm
by benryves
Wesley wrote:I'm going to be learning C (finally) next semester, so I started looking in an old book I had on my shelf about C. I couldn't find anything in it about GUI programming, and I can't seem to find any GUI examples on the web either.
If you're on Windows, MSDN has extensive documentation on Win32 GUI development.
Is it practical to create GUI programs in C?
Is it practical to do anything much in C these days? ;) Raw Win32 GUI programming is pretty horrible; it's several orders of magnitude easier to just use WinForms with C#.

Re: [C] GUIs

Posted: Wed 16 Dec, 2009 12:59 pm
by tr1p1ea
GUI's are overrated anyway! :).

Re: [C] GUIs

Posted: Thu 17 Dec, 2009 12:24 am
by Spencer
If you want nice native controls and obsessively need UIs to behave exactly how you want them to, C is the way to go!

Here are some keywords to get you started:
CreateWindow
GetMessage
DispatchMessage
DefWindowProc
WM_PAINT
BeginPaint
SelectObject
GetStockObject
FillRect
DrawText
EndPaint

The first result in any search engine is always MSDN. The documentation is excellent. I recommend using the Visual Studio 2010 beta. It gives you real time feedback on your C code with error and warning badges in the gutter. The Windows SDK comes with hundreds of samples.

Re: [C] GUIs

Posted: Thu 17 Dec, 2009 12:33 am
by benryves
Spencer wrote:If you want nice native controls and obsessively need UIs to behave exactly how you want them to, C is the way to go!
Or WinForms+C#. ;) You get direct access to the control handle and can override WndProc if required, and P/Invoke can be used to call Win32 functions if you're feeling obsessive. (WinForms is a pretty thin wrapper around the Win32 API). The advantage is that if you just need to bung a few buttons on a form and call it a day you can, but you still have the option of dropping down a level if need be.

Re: [C] GUIs

Posted: Thu 17 Dec, 2009 2:52 pm
by Spencer
I admit WinForms and WPF are pretty nice, I use them for small projects. One problem I've noticed with WinForms is the controls don't smoothly fade to the hot color on mouse-over on Vista and 7. I have a feeling, for buttons at least, they simply use DrawThemeBackground to approximate the control. This is similar to how scrollbars in IE are different than normal scrollbars, since IE uses "window-less" controls.

Re: [C] GUIs

Posted: Thu 17 Dec, 2009 7:05 pm
by King Harold
I wouldn't call much about WPF nice - except perhaps some of the resulting graphics. On the other hand, WPF apps usually end up looking like a flash ad, and even when they don't the text rendering is broken by default (has been fixed very recently) and ignores your ClearType setting just for laughs (I am not laughing! ClearType is so horrible on CRT's that it causes your eyes to bleed!)

Re: [C] GUIs

Posted: Thu 17 Dec, 2009 7:45 pm
by benryves
King Harold wrote:I wouldn't call much about WPF nice - except perhaps some of the resulting graphics. On the other hand, WPF apps usually end up looking like a flash ad, and even when they don't the text rendering is broken by default (has been fixed very recently) and ignores your ClearType setting just for laughs (I am not laughing! ClearType is so horrible on CRT's that it causes your eyes to bleed!)
WPF is a nicely designed API and (when you can get your head around its "magic") very pleasant to develop in. However, I do agree with all of your gripes - the text rendering is atrocious, and the look and feel is "off" from native apps (this is due to it not using native rendering at all - everything is driven by theme files, so if you don't use Luna or Aero you end up with a Windows Classic look).

I've stuck with keeping WPF for the web (Silverlight) myself.