NO

Author Topic: New to Cprogramming, new to Pelles C, GUI ?  (Read 13821 times)

vmars316

  • Guest
New to Cprogramming, new to Pelles C, GUI ?
« on: April 20, 2012, 07:28:42 PM »
Greetings,
I am learning "C" via 'K&R C programming book.
Are the examples in that book compatible with Pelles C ?
I have been looking for a "C" GUI Designer.
Until today, and from your ScreenShots, you got the goods.
There seemed to be only "C++ GUI Designers".
So I am quite excited!
Also, I plan to download PellesC today.
Are there any helps along the line of "do dis, dont do dat",
regarding PellesC install ?

Thanks...Vernon

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #1 on: April 20, 2012, 08:06:06 PM »
In general you just install to the default location and you are done.

You can of course install anywhere you want and there shouldn't be any drawbacks.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #2 on: April 20, 2012, 10:23:27 PM »
Greetings,
I am learning "C" via 'K&R C programming book.
Are the examples in that book compatible with Pelles C ?
I have been looking for a "C" GUI Designer.
Until today, and from your ScreenShots, you got the goods.
There seemed to be only "C++ GUI Designers".
So I am quite excited!
Also, I plan to download PellesC today.
Are there any helps along the line of "do dis, dont do dat",
regarding PellesC install ?

Thanks...Vernon

Pelles C does not include a GUI designer.  It has a full set of resource editors, including a dialog editor but nothing to create top level windows for you.  Those you do by hand, just like with any C implementation.  C coders are "nuts and bolts" people, who actually like doing things "from the ground up".
 
 
K&R only teaches about Console mode Windows programs. 
If you want to get into GUI programming...
 
1) Finish K&R, page by page, example by example... learn C first.
 
2) Get a copy of TheForger's Tutorial  for Win32 and work it the same way.
 
But do be aware... Windows GUI is very different than console mode programming.  It's unlike any C code you've ever seen before.
 
You will also need to install a copy of the Windows SDK as a reference source for windows API calls, there are about 20,000 of them.
 
 
 
 
 
« Last Edit: April 20, 2012, 10:26:42 PM by CommonTater »

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #3 on: April 21, 2012, 01:28:09 AM »
Im my opion is a good to begin with windows GUI and Pelles C to create a with the wizard a dialog base program an play with the resource editor. ;)
best regards
 Alex ;)

vmars316

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #4 on: April 21, 2012, 06:36:12 AM »
btw: The reason i thought 'Pelles C' has a Gui Designer is because of this:
 http://www.smorgasbordet.com/pellesc/images/screen2.png
Wishful thinking.
...vm

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #5 on: April 21, 2012, 07:43:11 AM »
btw: The reason i thought 'Pelles C' has a Gui Designer is because of this:
 http://www.smorgasbordet.com/pellesc/images/screen2.png
Wishful thinking.
...vm

That's the dialog editor... used for pop up dialogs like the "find" one in the screen shot. 

You can make simple programs that are based upon a dialog if you only need one window but they are rather limited in their capabilities.  If you are writing something more complex, then you need to create "top level" windows with the RegisterClass(), CreateWindow() and CreateWindowEx() api calls... as explained in the tutorial I linked for you.

Generally a windows program has it's main window which is created "top level" and a series of dialogs that pop up to aid in data entry, settings, searching, whatever.... The dialog designs are not part of the main program code, rather they are stored in the "resource" part of the program, are owned by the main window and are loaded and unloaded on demand

See the attached image for an example....
 


Edit:
Also note that as you get more into this you will find the *absence* of a formulaic GUI designer is an advantage, not a problem.  For example: Most top level windows are resizeable and the support code for that can be rather complex in GUI designers, whereas when doing it yourself, you can streamline and customize your code exactly for your needs... This most often results in smaller programs that run considerably faster than what you'd get from a cookie cutter GUI designer. 
 
Besides... creating your own main windows is not really all that hard to begin with. (See the forger's tutorial)
 
« Last Edit: April 21, 2012, 08:07:15 AM by CommonTater »

vmars316

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #6 on: April 21, 2012, 08:44:58 AM »
Tater,
VisualControls.png is why i thought there was a GuiDesigner.
For me it is a dreaded chore to add all that api code.
I have been using HotBasic for a few years.
And programming is so easy, even without GuiDesigner.
Just for fun, i made my own GuiDesigner.
Blocks style.
Just move the blocks where i want them.
Name them "button" "panel" "richedit" etc.
When I have all the blocks where i want them,
i just click on the "SOURCE" button,
and the program creates the source code
and fires up HotBasic compiler. 
hbDesigner looks like "hbDesign_Screen....png".

Maybe, i can modify that program to work for "C".

...vm

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #7 on: April 21, 2012, 10:55:42 AM »
You can make simple programs that are based upon a dialog if you only need one window but they are rather limited in their capabilities.
I don't think that dialog based program is limited. It depends on the data with which the program is working. If it is well display in normal text window, take normal window. If you have many choices and few data take a dialog.
I use many programs with one main dialog and many subdialogs and windows.
And for a dialog based program you can use the resource editor to create you GUI ;), but to fill it with live you mast code it by hand. :(
best regards
 Alex ;)

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #8 on: April 21, 2012, 04:09:16 PM »
Tater,
VisualControls.png is why i thought there was a GuiDesigner.
For me it is a dreaded chore to add all that api code.

Ummm... no offense intended.... but if you don't like writing source code why are you programming?
 
Let me give you a small example....  This code creates a complete unicode text editor... it's a little crude and somewhat limited but it demonstrates most of the important windows principles...
Code: [Select]
/*
Tiny Unicode Editor Example
*/
// for the compiler
#define UNICODE
#define _UNICODE
#define WIN32_DEFAULT_LIBS
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0502
#define _X86_
// Windows headers
#include <windows.h>
#include <commdlg.h>
//  PellesC headers
#include <stdlib.h>
#include <wchar.h>
#include <tchar.h>
#define BOM_FLAG 0xFFFE

// Window handles
HWND      Wind[5]; 
HINSTANCE Inst;
TCHAR     FileName[MAX_PATH]; // filename when opened
BOOL      RevBytes = 0;

// save a file
void SaveToFile(void)
  { OPENFILENAME  ofn;        // filename struct
    HANDLE        fh;         // handle for opening files
    DWORD         fs;         // size of the data
    PTCHAR        fd;         // pointer to data
    // get the filename
    memset(&ofn,0,sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner    = Wind[0];
    ofn.hInstance    = Inst;
    ofn.lpstrFilter  = _T("All Files\0*.*\0\0");   
    ofn.lpstrFile    = FileName;
    ofn.nMaxFile     = MAX_PATH;
    ofn.lpstrTitle   = L"Save your work";
    ofn.Flags        = OFN_NONETWORKBUTTON |
                       OFN_HIDEREADONLY |
                       OFN_NOTESTFILECREATE |
                       OFN_OVERWRITEPROMPT;
    if (!GetSaveFileName(&ofn))
      return;
    // get unicode adjusted file size from edit control
    fs = (SendMessage(Wind[4],WM_GETTEXTLENGTH,0,0) * sizeof(TCHAR));
    if (fs < 1)
      return;
    // create text buffer
    fd = malloc(fs);
    // get the text from the control
    SendMessage(Wind[4],WM_GETTEXT,fs,(LPARAM)fd);
    // open the file
    fh = CreateFile(FileName,GENERIC_WRITE,0,NULL,
                            CREATE_ALWAYS,
                            FILE_ATTRIBUTE_NORMAL |
                            FILE_FLAG_WRITE_THROUGH,NULL);
    // save the file
    if (fh != INVALID_HANDLE_VALUE)
      { WriteFile(fh,fd,fs,&fs,NULL);
        CloseHandle(fh); }
    free(fd); }
 
// open a file
void OpenFromFile(void)
  { OPENFILENAME  ofn;        // filename struct
    HANDLE        fh;         // handle for opening files
    DWORD         fs;         // size of the data
    PTCHAR        fd;         // pointer to data
    // get the filename
    memset(&ofn,0,sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner    = Wind[0];
    ofn.hInstance    = Inst;
    ofn.lpstrFilter  = L"All Files\0*.*\0\0";   
    ofn.lpstrFile    = FileName;
    ofn.nMaxFile     = MAX_PATH;
    ofn.lpstrTitle   = L"Open a file";
    ofn.Flags        = OFN_NONETWORKBUTTON |
                       OFN_HIDEREADONLY |
                       OFN_NOTESTFILECREATE |
                       OFN_OVERWRITEPROMPT;
    if (!GetOpenFileName(&ofn))
      return;
    // open the file
    fh = CreateFile(FileName,GENERIC_READ,FILE_SHARE_READ,NULL,
                            OPEN_EXISTING,
                            FILE_ATTRIBUTE_NORMAL,NULL);
    if (fh == INVALID_HANDLE_VALUE)
      { MessageBox(Wind[0],L"Error opening the file",L"OOPS!",0);
        return; }
    // get the file size
    fs = GetFileSize(fh,NULL) + sizeof(TCHAR);
    // create text buffer
    fd = malloc(fs);
    // clear to 0
    memset(fd,0,fs);
    // read from disk 
    ReadFile(fh,fd,fs,&fs,NULL);
    // close the file
    CloseHandle(fh);
    // put the text in the control
    SendMessage(Wind[4],WM_SETTEXT,fs,(LPARAM)fd);
    free(fd); }
 
// resize the window
VOID ResizeWindow(LPARAM lParm)
  { MoveWindow(Wind[4],60,2,LOWORD(lParm) - 62,HIWORD(lParm) - 4,1); }
 
// Message Loop
LRESULT CALLBACK MsgProc(HWND wnd,UINT msg,WPARAM wparm,LPARAM lparm)
  { switch (msg)
      { case WM_COMMAND :
          switch (LOWORD(wparm))
            { case 1001 :
                OpenFromFile();
                return 0;
              case 1002 :
                SaveToFile();
                return 0;
              case 1003 :
                PostMessage(Wind[0],WM_CLOSE,0,0);
                return 0;
              default :
                return DefWindowProc(wnd,msg,wparm,lparm); }
        case WM_SIZE  :
          ResizeWindow(lparm);
          return 0;
        case WM_CLOSE :         // close window
          DestroyWindow(Wind[0]); 
          return 0;
        case WM_DESTROY :       // NC Exit button
          PostQuitMessage(0);
          return 0;
        default :
          return DefWindowProc(wnd,msg,wparm,lparm); } }
 
// create the window
VOID CreateMainWindow(void)
  { WNDCLASS  wc;                     
    // register App Class
    memset(&wc,0,sizeof(wc));
    wc.style          = CS_CLASSDC;
    wc.hInstance      = Inst;
    wc.hCursor        = LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground  = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    wc.lpfnWndProc    = &MsgProc;
    wc.lpszClassName  = L"TINY_UNICODE";
    RegisterClass(&wc);
    // create the main window
    Wind[0] = CreateWindowEx( WS_EX_CONTROLPARENT,
                    L"TINY_UNICODE",L"Tiny Unicode Editor",
                    WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT,0,500,300,NULL,NULL,Inst,NULL);
    // buttons
    Wind[1] = CreateWindow(L"BUTTON",L"Open",
                    WS_CHILD | WS_VISIBLE | BS_FLAT,
                    2,2,50,25,Wind[0],(HMENU) 1001,Inst,NULL);
    Wind[2] = CreateWindow(L"BUTTON",L"Save",
                    WS_CHILD | WS_VISIBLE | BS_FLAT,
                    2,30,50,25,Wind[0],(HMENU) 1002,Inst,NULL);
    Wind[3] = CreateWindow(L"BUTTON",L"Quit",
                    WS_CHILD | WS_VISIBLE | BS_FLAT,
                    2,60,50,25,Wind[0],(HMENU) 1003,Inst,NULL);
    // edit window
    Wind[4] = CreateWindowEx(WS_EX_CLIENTEDGE,L"EDIT",NULL,
                    WS_CHILD | WS_VISIBLE |
                    ES_MULTILINE,
                    60,2,200,200,Wind[0],NULL,Inst,NULL); 
    UpdateWindow(Wind[0]);
    ShowWindow(Wind[0],SW_SHOWNORMAL);    }
 
         
// Program Entry Procedure
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE pinst, LPSTR cmdl, int show)
  { MSG wmsg;
    // save instance handle
    Inst =    hinst;   
    // make the window
    CreateMainWindow();
    // dispatch window messages
    while (GetMessage(&wmsg,NULL,0,0))
      { TranslateMessage(&wmsg);
        DispatchMessage(&wmsg); }
    return 0; }

You can go ahead and copy-paste it and run it.  You'll discover it's just over 200 lines for a working mutilingual text editor.  But as you examine it you will discover there isn't much there a GUI designer could help you with... the end result would be more complex and bigger for shure... The compiled executable comes in around 12k and that's the point of C ... small and fast.
 
About the only part of that you could get from a GUI Designer would be the CreateMainWindow() function... roughly 30 lines.  In about the same time you mess with your widgets and adjustments, you could have typed that in by hand twice.
 
C is not the place to be if you're looking to do "high level programming" or "rapid application design"; that is the work of labourers...
 
However; if you're looking to become a craftsman....
 

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #9 on: April 21, 2012, 04:22:02 PM »
You can make simple programs that are based upon a dialog if you only need one window but they are rather limited in their capabilities.
I don't think that dialog based program is limited. It depends on the data with which the program is working. If it is well display in normal text window, take normal window. If you have many choices and few data take a dialog.
I use many programs with one main dialog and many subdialogs and windows.
And for a dialog based program you can use the resource editor to create you GUI ;) , but to fill it with live you mast code it by hand. :(
Alex... to be clear, I've not said there is anything wrong with dialog based programs... They have their uses. 

I will use a dialog based program if it's only going to be a single window that does not need to be resized.  But when things get more complicated like POIDE or the inventory programs I've written, I would never dream of starting from a Dialog window. 

I imagine you and I do things differently and that's no problem at all. 
 
Our friend, however, will not learn programming by avoiding programming...
 

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #10 on: April 21, 2012, 04:40:34 PM »
UltraDefrag uses a single dialog as the main window, which allows resizing and contains a graphical area.

Pelles C is shipping with a resizer library for dialogs, which is easy to implement, and can be enabled through the dialog editor.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #11 on: April 21, 2012, 04:49:43 PM »
UltraDefrag uses a single dialog as the main window, which allows resizing and contains a graphical area.

Pelles C is shipping with a resizer library for dialogs, which is easy to implement, and can be enabled through the dialog editor.

That's interesting.... I use UltraDefrag (as we discussed once before).  It's a choice I wouldn't have made... but it does work quite well.

Myabe I'm just "old school" or something :D ... but I still like coding by hand.


Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #12 on: April 21, 2012, 05:40:14 PM »
Sorry, I have to revise my information, since a dialog was used until v5.0.0, starting with v5.0.0 we use our own window class.
I haven't had to change anything of the application window creation code, so I had to check again to make sure I haven't posted false information, but I apparently did, sorry :'(

I think that the dialog editor is a good thing to get started with GUI programming and to learn the fundamentals of it.
The more experience one gains, the more he will let loose of the wizards and do his own thing.

I am currently using Notepad++ to apply changes to the code, even so code-completion would be a handy thing.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #13 on: April 21, 2012, 06:43:11 PM »
Sorry, I have to revise my information, since a dialog was used until v5.0.0, starting with v5.0.0 we use our own window class.
I haven't had to change anything of the application window creation code, so I had to check again to make sure I haven't posted false information, but I apparently did, sorry :'(

No worries.... 

Quote
I think that the dialog editor is a good thing to get started with GUI programming and to learn the fundamentals of it.
The more experience one gains, the more he will let loose of the wizards and do his own thing.

I am currently using Notepad++ to apply changes to the code, even so code-completion would be a handy thing.

Again, we do things differently...  I've always found that if I do things the hard way first, the lessons stay with me better.  Then when more confident I'll start with the convenience tools...  But hey, that's just me :D


Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: New to Cprogramming, new to Pelles C, GUI ?
« Reply #14 on: April 21, 2012, 07:12:05 PM »
I will use a dialog based program if it's only going to be a single window that does not need to be resized.
One of the most complex windows program on that I worked was dialog based (not my decision) and each button at the front dialog, opened a new dialog, which many new buttons. And when all forms was filled the program started calculating.
I think it is a design decision to create application with a common window (if you have many similar data like text, numbers, graphics ...) or you show the data in forms (one or much more).

But to start I thinks it's a little bit easier to start with a dialog based. With the wizard you can create a simple program which is easy to modify with the resource editor to get a feeling for the work with window controls.

But let us stop the discussion about window and dialog based, everbody should do in way which is most familar for him/her.
best regards
 Alex ;)