Compliments, it works like a charm, in just 40 lines!
#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 ;
}