C language > User contributions

SGL - win32 made simple!

(1/8) > >>

henrin:
I have read many posts looking for easy win32 gui programming.
Not founding a good solution, and considering Win32 is almost
fantastic, I decided to fill the gap.

Here is SGL - Features:
 - easy Win32 programming (better OOP)
 - grid layout with alignmment and padding
 - scalable GUI

The kit contains:
 - help file (sgl.chm)
 - dev kit: x.lib and x.h
 - sample programs (source, project and exe files)
 
The available objects are:
 - buttons
 - table (data grid)
 - image
 - edit
 - graph
 - popups
 
The mandatoty Hello progam is just 12 lines:
 
    #include "sgl.h"
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPInst, PSTR cmdLine, int cmdShow)
    {
       SGL_Init(hInst, NULL) ;
       HWND panel = SGL_New(0, SGL_PANEL, 0, "SGL", -1, -1) ;
       HWND btn   = SGL_New(panel, SGL_CTRL_BUTTON, 0, "Hello!", 0, 0) ;
       SGL_Layout(panel) ;
       SGL_VisibleSet(panel, 1) ;
       SGL_Run() ;
       SGL_Exit() ;
       return 0 ;
    }

More samples in the downloadable kit.

jj2007:
Compliments, it works like a charm, in just 40 lines!


--- Code: ---#include "sgl.h" // all sgl*.h must be in include folder (includes <stdio.h>)
#pragma comment(linker, "sgl32.lib" ) // sgl32.lib must be in lib folder

#pragma warn(disable:2216)    // retval never used
#pragma warn(disable:2018)    // Undeclared function 'sprintf'
#pragma warn(disable:2118)    // para not referenced
#pragma comment(linker, "/Subsystem:Windows" )
#pragma warn(disable:2215)    // conversion ... loss of data

#define BTN_NB 6
#define TEXT_LEN 10

int buttonCB(HWND hwnd, UINT event, WPARAM wParm, LPARAM lParm) {
  if (event == WM_LBUTTONUP) {
RECT rect ; // rectangle for the edit box
GetClientRect(hwnd, &rect) ;
MapWindowPoints(hwnd, NULL, (POINT*) &rect, 2) ;
char* text ; // edited text
SGL_CallbackDataGet(hwnd, (void*) &text) ;
SGL_PopupEdit(hwnd, &rect, ES_CENTER, SGL_WHITE,
text, TEXT_LEN, NULL, NULL) ;
return 1 ;
  }
  return 0 ;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
  static char btnText[BTN_NB][TEXT_LEN] ; // buttons' text
  SGL_Init(hInstance, NULL) ;
  HWND topPanel = SGL_New(0, SGL_PANEL, 0, "BUTTONS", 90, 30) ;
  for (int i = 0 ; i < BTN_NB ; i++) { // create each button
sprintf(btnText[i], "Button #%d", i + 1) ;
HWND btn = SGL_New(topPanel, SGL_CTRL_BUTTON, 0, btnText[i], 0, i) ;
SGL_CallbackFunctionSet(btn, buttonCB) ;
SGL_CallbackDataSet(btn, (void*) &btnText[i]) ;
  }
  SGL_Layout(topPanel) ;
  SGL_VisibleSet(topPanel, 1) ;
  SGL_Run() ;
  SGL_Exit() ;
  return 0 ;
}
--- End code ---

migf1:
Although I've personally settled in GTK+ when it comes to GUI programming with C, I want to congratulate you for this effort!

I went through SGL docs, though in a hurry. Was impressed and I believe SGL deserves to go open-source, ideally in its own git repo. If not, it may be a good idea to also provide ming32 and/or mingw-w64 pre-compiled binaries.

Thanks for sharing and once again congrats for the effort so far.

henrin:
Thank you jj2007 and migf1.
The story continues: here is the v1.1 version.

Some improvements in resizing and default values:

* Panel sizing is now possible.
* SGL fonts are now strictly linked to the desktop menu font.
* The separator object is now spanned to its parent border.New features:

* New macros for testing the mouse buttons.
* New tool for Automatic resizing.
* New object OpenGL
To remain in upload size limit, only the 32-bit sample executables are included.
You still have:

* the help file
* the .h and the .lib (32 & 64-bit) files
* the samples: source, project files, .exe files
Next step : make it open source.

DD:
i've been using it for some tests.
thanks for the hard work!

Navigation

[0] Message Index

[#] Next page

Go to full version