NO

Author Topic: Using Pelles C with IUP toolkit  (Read 18230 times)

Jean-Pierre Leroy

  • Guest
Using Pelles C with IUP toolkit
« on: June 24, 2014, 10:52:44 AM »
Dear all,

I would like to use Pelles C with the IUP toolkit (http://www.tecgraf.puc-rio.br/iup/)

Is there any tutorial explaining how to set up Pelles C in order to use it with the IUP tookit.

By the way do you think it could be possible in a future version of Pelles C to add in the list of "Template projects" or "Empty projects" new options for IUP tookit like :

"32 bits IUP project"
"64 bits IUP project"

Thanks for your help.

Regards,
Jean-Pierre Leroy

Offline jcfuller

  • Member
  • *
  • Posts: 36
Re: Using Pelles C with IUP toolkit
« Reply #1 on: June 24, 2014, 11:49:09 AM »
Why would you want to use a Gui toolkit, primarily used for cross platform development, with a windows only compiler?

James

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Using Pelles C with IUP toolkit
« Reply #2 on: June 24, 2014, 12:04:08 PM »
As general rule you can use PellesC to compile C only project with prebuild iup libraries compiled with VC++10 (see).
I don't think that a dedicated template for iup will never added, but you can do it yourself creating the wizard.
You'll find the documentation for wizards in the compiler help, and also some examples on PellesC site.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

WRP

  • Guest
Re: Using Pelles C with IUP toolkit
« Reply #3 on: June 26, 2014, 02:25:42 AM »
Why would you want to use a Gui toolkit, primarily used for cross platform development, with a windows only compiler?

Short answer: It is an easier way to build a Windows interface.

IUP is a GUI toolkit that on Windows uses the native widgets. You can code the interface with either LED, C, or Lua.

LED is a declarative language to specify just the layout of the GUI; the logic has to be done elsewhere in C. The advantage of LED is that it is very concise and can be modified live. It is a bit like coding a web page.

Lua with IUP is rather like Tcl/Tk, except that Lua is a nicer language than Tcl and IUP has much nicer looking (native) widgets, including some very powerful ones for data manipulation and visualization.

Developing with the C API, while more involved than with Lua, is much cleaner than using the Win32 API directly. For comparison, I find C projects with IUP are a bit simpler than with GTK+.

Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

As I indicated above, I think Lua/IUP is a significant improvement over Tcl/Tk, but it has a major drawback. There is currently a terrible lack of tutorial material.

WRP

  • Guest
Re: Using Pelles C with IUP toolkit
« Reply #4 on: June 26, 2014, 03:18:02 AM »
Is there any tutorial explaining how to set up Pelles C in order to use it with the IUP tookit.

Building IUP projects with Pelles C works well, but I found a few gotchas in setting up. There is no need for a specialized IUP template in the Wizard.

Here is to get you started quickly.

Step 1: Download and install Pelles C (32 or 64-bit version).

Step 2: Download and unpack the most recent 32 or 64-bit static and dynamic IUP library packages for Windows. Be sure to choose the right ones for the version of Microsoft C Runtime that you have. Also get the Tools, Docs, and Examples packages.

Step 3: Read the Pelles C manual, at least the part about using the IDE.

Step 4: Get the appropriate version of libcmt.lib and msvcrt.lib from Microsoft. I got them out of Visual Studio Express. Put them in Pelles C\Libs.

OR

Replace the iupstub.lib with frankie's Pelles C native version.

Step 5: In the IDE, create a new project with the Wizard, choosing "Win32 Program (EXE)". Add to the project the IUP resource file, found in the static libs \etc directory. Add to the project one of the C examples from the Examples package. To build with dynamic linking, in project options add iup.lib and iupstub.lib to the linker options and add the IUP dynamic libs package and include directory to the folder path. Update dependencies and build.

Static linking is more involved. We had some discussion here.

Some of the example programs require DLLs from outside the IUP project. You can find them in the Tools package.
« Last Edit: June 26, 2014, 03:21:17 AM by WRP »

Offline jcfuller

  • Member
  • *
  • Posts: 36
Re: Using Pelles C with IUP toolkit
« Reply #5 on: June 26, 2014, 12:59:22 PM »

Quote
Short answer: It is an easier way to build a Windows interface.
Easier than using a WYSIWYG Dialog editor and direct api? I don't see it.

Quote
Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

I agree but why use Pelles in this situation? I am not a seasoned c coder but I would use gcc for cross platform coding with IUP.
I would assume fewer code gocha's (?)

James

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Using Pelles C with IUP toolkit
« Reply #6 on: June 26, 2014, 05:53:10 PM »

Quote
Short answer: It is an easier way to build a Windows interface.
Easier than using a WYSIWYG Dialog editor and direct api? I don't see it.

Quote
Of course, since IUP is cross-platform, there is the added benefit that you can move your project to Unix/Linux mostly unchanged.

I agree but why use Pelles in this situation? I am not a seasoned c coder but I would use gcc for cross platform coding with IUP.
I would assume fewer code gocha's (?)

James
Sorry but GCC is a behemoth, and I would not use it for any cross-platform work.

The point is that you could use Pelle's C to produce a Windows version of a cross-platform application, regardless of what compiler someone else might be using for the same application on a different OS...

Ralf

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Using Pelles C with IUP toolkit
« Reply #7 on: June 27, 2014, 12:52:04 PM »
IUP is a GUI toolkit that on Windows uses the native widgets.

Can you zip the executable of a Hello World example, with a few "widgets" (I assume you mean controls), just to see how it looks like?

Offline jcfuller

  • Member
  • *
  • Posts: 36
Re: Using Pelles C with IUP toolkit
« Reply #8 on: June 27, 2014, 04:59:51 PM »
IUP is a GUI toolkit that on Windows uses the native widgets.

Can you zip the executable of a Hello World example, with a few "widgets" (I assume you mean controls), just to see how it looks like?

It uses native controls so the example will look just like an Win api version.

James

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Using Pelles C with IUP toolkit
« Reply #9 on: June 27, 2014, 05:38:18 PM »
The IUP real advantage is that it creates a sort of GUI abstraction language that when application is built links to the native GUI subsystem for the machine where it runs.
In plain words you define the graphical widgets you want and when running it will use windows controls on MS, GTK on Linux and so on...
I don't think that it is a real benefit if your program have to run only on MS platforms, but it is very efficient when it have to run on different platforms.
I forget to add that the libraries are compiled with __cdecl calling conventions, on systems where this make any sense, and user program starts with standard 'main' function to allow the compilation of GUI applications with any kind of standard C compiler without any graphic libraries apart from IUP.

I'm trying to natively compile IUP on PellesC, and I have compiled parts of it, but unfortunately many modules are in C++ ...
« Last Edit: June 27, 2014, 05:46:00 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Using Pelles C with IUP toolkit
« Reply #10 on: June 27, 2014, 07:14:58 PM »
I'm trying to natively compile IUP on PellesC, and I have compiled parts of it, but unfortunately many modules are in C++ ...
I have downloaded but not played with the code myself, but according to the site, it should be plain C... ?!?!?!

Ralf

WRP

  • Guest
Re: Using Pelles C with IUP toolkit
« Reply #11 on: June 27, 2014, 08:25:27 PM »
... but unfortunately many modules are in C++ ...

IUP was developed all in ANSI C, but recently they have incorporated some outside projects in C++. So far, there is MathGL, PPlot, Scintilla, TUIO, and support for Haiku.

I noticed that the OLE and web browser controls are C++. I wonder if that was really necessary.

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Using Pelles C with IUP toolkit
« Reply #12 on: June 27, 2014, 08:51:21 PM »
It uses native controls so the example will look just like an Win api version.

Can we see an example? There must be somebody around who has a simple GUI example... can't be so difficult to zip it and post it here.

Offline jcfuller

  • Member
  • *
  • Posts: 36
Re: Using Pelles C with IUP toolkit
« Reply #13 on: June 27, 2014, 09:09:00 PM »
This is a demo I created with my bc9Basic -> c/c++ translator and compiled with VS2013 Express.

James

Edit:
  This is the code produced by bc9Basic:
Code: [Select]

// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.1.8.8 (2014/06/17)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-2) 4.8.1
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C Compiler
//                           On MS Windows
// *********************************************************************
#include <windows.h>    // Win32 Header File
#include <windowsx.h>   // Win32 Header File
#include <commctrl.h>   // Win32 Header File
#include <commdlg.h>    // Win32 Header File
#include <mmsystem.h>   // Win32 Header File
#include <shellapi.h>   // Win32 Header File
#include <shlobj.h>     // Win32 Header File
#include <richedit.h>   // Win32 Header File
#include <objbase.h>    // Win32 Header File
#include <ocidl.h>      // Win32 Header File
#include <winuser.h>    // Win32 Header File
#include <olectl.h>     // Win32 Header File
#include <oaidl.h>      // Win32 Header File
#include <ole2.h>       // Win32 Header File
#include <oleauto.h>    // Win32 Header File
#include <winsock.h>    // Win32 Header File
#include <process.h>    // dos
#include <direct.h>     // dos
#include <io.h>         // dos
#include <conio.h>      // dos
#include <wchar.h>      // dos/linux
#include <ctype.h>      // dos/linux
#include <fcntl.h>      // dos/linux
#include <math.h>       // dos/linux
#include <stdio.h>      // dos/linux
#include <string.h>     // dos/linux
#include <stddef.h>     // dos/linux
#include <stdlib.h>     // dos/linux
#include <setjmp.h>     // dos/linux
#include <time.h>       // dos/linux
#include <stdarg.h>     // dos/linux
#include <sys/types.h>
#include <sys/stat.h>


// ***************************************************
// Compiler Defines
// ***************************************************

// C++
#if defined( __cplusplus )
#define overloaded
#define C_EXPORT EXTERN_C __declspec(dllexport)
#define C_IMPORT EXTERN_C __declspec(dllimport)
#else
#define C_EXPORT __declspec(dllexport)
#define C_IMPORT __declspec(dllimport)
#endif


// Microsoft VC++
#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined ( __cplusplus )
#define DECLSPEC_UUID(x)    __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif

// $HEADER BEGIN
#pragma comment(lib,"iup.lib")
#pragma comment(lib,"iupcontrols.lib")
#pragma comment(lib,"iupcd.lib")
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
// $HEADER END

#include "iup.h"

// *************************************************
// Instruct Linker to Search Object/Import Libraries
// *************************************************
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"advapi32.lib")
#pragma comment(lib,"winspool.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"oleaut32.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"odbc32.lib")
#pragma comment(lib,"odbccp32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"comdlg32.lib")
#pragma comment(lib,"imagehlp.lib")
#pragma comment(lib,"version.lib")
// *************************************************
// End of Object/Import Libraries To Search
// *************************************************

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const char* ccptr;
#define CCPTR const char*
#define cfree free
#define WAITKEY system("pause")
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************


// *************************************************
//               Standard Prototypes
// *************************************************

char*   BCX_TmpStr(size_t, size_t    , int    );
char*   join (int, ... );
char*   enc (const char*, int    , int    );
// *************************************************
//          User Defined Types And Unions
// *************************************************


// *************************************************
//                System Variables
// *************************************************


// *************************************************
//            User Global Variables
// *************************************************

static PCHAR   *g_argv;
static int     g_argc;


// *************************************************
//               User Prototypes
// *************************************************

int     main (int, PCHAR*);
long    quit_cb (void);
void    AddChild (Ihandle* , Ihandle*);
Ihandle* Create (char *, char *, Ihandle*);

// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

#ifndef BCXTmpStrSize
#define BCXTmpStrSize  2048
#endif
char *BCX_TmpStr (size_t Bites, size_t  iPad, int iAlloc)
{
    static int   StrCnt;
    static char *StrFunc[BCXTmpStrSize];
    StrCnt = (StrCnt + 1) & (BCXTmpStrSize - 1);
    if(StrFunc[StrCnt]) {
        free (StrFunc[StrCnt]);
        StrFunc[StrCnt] = NULL;
    }
#if defined BCX_MAX_VAR_SIZE
    if(Bites * sizeof(char) > BCX_MAX_VAR_SIZE)
    {
        printf("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n", (int)(Bites * sizeof(char)), BCX_MAX_VAR_SIZE);
        abort();
    }
#endif
    if(iAlloc) StrFunc[StrCnt] = (char*)calloc(Bites + iPad + 1, sizeof(char));
    return StrFunc[StrCnt];
}


char *enc (const char *A, int L, int R)
{
    register int tmplen = strlen(A);
    register char *BCX_RetStr = BCX_TmpStr(tmplen + 3, 1, 1);
    memcpy(BCX_RetStr + 1, A, tmplen);
    *BCX_RetStr = (char)((L == 0) ? 34 : L);
    BCX_RetStr[++tmplen] = (char)((R == 0) ? *BCX_RetStr : R);
    BCX_RetStr[++tmplen] = 0;
    return BCX_RetStr;
}


char * join(int n, ...)
{
    register int i = n, tmplen = 0;
    register char *s_;
    register char *strtmp;
    va_list marker;
    va_start(marker, n); // Initialize variable arguments
    while(i-- > 0)
    {
        s_ = va_arg(marker, char *);
        if(s_) tmplen += strlen(s_);
    }
    strtmp = BCX_TmpStr(tmplen, 1, 1);
    va_end(marker); // Reset variable arguments
    i = n;
    va_start(marker, n); // Initialize variable arguments
    while(i-- > 0)
    {
        s_ = va_arg(marker, char *);
        if(s_) strcat(strtmp, s_);
    }
    va_end(marker); // Reset variable arguments
    return strtmp;
}



// ************************************
//       User Subs and Functions
// ************************************

int main (int argc, PCHAR* argv)
{
    g_argc = argc;
    g_argv = argv;
    Ihandle*  win;
    Ihandle*  vbox;
    Ihandle*  topBox;
    Ihandle*  serverFrame;
    Ihandle*  serverBox;
    Ihandle*  serverCombo;
    Ihandle*  btnFetch;
    Ihandle*  controlFrame;
    Ihandle*  controlBox;
    Ihandle*  btnAbout;
    Ihandle*  btnClear;
    Ihandle*  btnExit;
    Ihandle*  dictFrame;
    Ihandle*  serverList;
    Ihandle*  transFrame;
    Ihandle*  text;
    Ihandle*  bottomBox;
    Ihandle*  label;
    Ihandle*  entry;
    Ihandle*  btnSearch;
    Ihandle*  chkAll;
    Ihandle*  chkUTF;
    IupOpen(0, 0);
    win = Create("dialog", "TITLE=Thesaurus, SIZE=500x300", NULL);
    vbox = Create("vbox", "MARGIN=10x10", NULL);
    topBox = Create("hbox", " GAP=10", vbox);
    serverFrame = Create("frame", "TITLE=Servers, EXPAND=YES", topBox);
    serverBox = Create("hbox", "GAP=5", serverFrame);
    serverCombo = Create("list", "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1", serverBox);
    btnFetch = Create("button", "TITLE=Fetch, SIZE = 50x", serverBox);
    controlFrame = Create("frame", "TITLE=Controls", topBox);
    controlBox = Create("hbox", "Margin=6x6, GAP=5", controlFrame);
    btnAbout = Create("button", "TITLE=About, SIZE = 50x", controlBox);
    btnClear = Create("button", "TITLE=Clear, SIZE = 50x", controlBox);
    btnExit = Create("button", "TITLE=Exit, SIZE = 50x", controlBox);
    IupSetCallback(btnExit, "ACTION", (Icallback)quit_cb);
    dictFrame = Create("frame", "TITLE=Dictionaries", vbox);
    serverList = Create("list", "EXPAND=YES, VISIBLELINES=1", dictFrame);
    transFrame = Create("frame", "TITLE=Translation", vbox);
    text = Create("text", "MULTILINE=YES, EXPAND=YES", transFrame);
    bottomBox = Create("hbox", "GAP=10", vbox);
    label = Create("label", join( 3, "TITLE=", enc("Enter Word to Search For:", 34, 34), ", SIZE=x12"), bottomBox);
    entry = Create("text", " EXPAND=HORIZONTAL", bottomBox);
    btnSearch = Create("button", "TITLE=Search, SIZE=50x", bottomBox);
    chkAll = Create("toggle", "TITLE=ALL, VALUE=ON,SIZE=x12", bottomBox);
    chkUTF = Create("toggle", "TITLE=UTF-8, SIZE=x12", bottomBox);
    AddChild(win, vbox);
    IupShow(win);
    IupSetFocus(btnFetch);
    IupMainLoop();
    IupClose();
}


long quit_cb (void)
{
    return IUP_CLOSE;
}


void AddChild (Ihandle* parent, Ihandle* child)
{
    IupAppend(parent, child);
    IupRefresh(parent);
}


Ihandle* Create (char *Value, char *Attr, Ihandle* parent)
{
    Ihandle*  iHwnd = {0};
    iHwnd = IupCreate( Value);;
    if(iHwnd )
    {
        if(strlen(Attr))
        {
            IupSetAttributes(iHwnd, Attr);
        }
        if(parent )
        {
            AddChild(parent, iHwnd);
        }
        return iHwnd;
    }
    return NULL;
}


« Last Edit: June 27, 2014, 09:23:50 PM by jcfuller »