NO

Author Topic: GUI code generator  (Read 5123 times)

khyron

  • Guest
GUI code generator
« on: June 16, 2005, 07:54:50 PM »
hi there,

i find GUI coding a little bit boring when i have to create all the controls by code and Windows Dialog Based apps seem to be good enough just for simple stuff (you can´t add a menu easily for example, etc, etc).

So i was wondering if there´s a tool that I can use with C that works like the dialog editor but outputs c code instead of a rc file?.  (i know about Glade for windows but i don´t want to rely on gtk).

any suggestions?

khyron

  • Guest
GUI code generator
« Reply #1 on: June 17, 2005, 05:04:41 PM »
after searching the web for hours i found a little utility called frm2asm that takes a Visual Basic Form as an input and creates a compilable MASM file with the equivalent CreateWindowEx functions.... it´s fairly easy translating the MASM file to C.

when i have time i will probably code something similar that outputs C code.

JohnF

  • Guest
GUI code generator
« Reply #2 on: June 17, 2005, 08:03:22 PM »
Attaching a Menu to a dialog is not a problem. Have you tried using a dialog that has its own class?

Code: [Select]


WNDCLASS wc;
memset(&wc,0,sizeof(WNDCLASS));
wc.lpfnWndProc = DefDlgProc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ;
wc.cbWndExtra = DLGWINDOWEXTRA;
wc.hInstance = hinst;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_FINDFILE));
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDMENU_MAIN);
wc.lpszClassName = "findfile";
if(!RegisterClass(&wc))
return 0;



John

khyron

  • Guest
GUI code generator
« Reply #3 on: June 17, 2005, 10:27:43 PM »
#-o

it works and it´s very simple.... i didn't try that... thx

when i was researching about how to add a menu to a dialog I stumbled with this article and I guess I probably misunderstood some parts, now that I read it again it seems they were talking about MFC apps and the AppWizard.

http://www.codeguru.com/forum/showthread.php?t=267664

after reading that and converting my app from dialog based to an app in which I create every control by code I started avoiding dialog based apps like the pest....  :wink:

anyway, are there any cases in which you wouldn´t recommend a dialog based app?

JohnF

  • Guest
GUI code generator
« Reply #4 on: June 17, 2005, 11:14:04 PM »
Quote from: "khyron"
#-o

it works and it´s very simple.... i didn't try that... thx

when i was researching about how to add a menu to a dialog I stumbled with this article and I guess I probably misunderstood some parts, now that I read it again it seems they were talking about MFC apps and the AppWizard.

http://www.codeguru.com/forum/showthread.php?t=267664

after reading that and converting my app from dialog based to an app in which I create every control by code I started avoiding dialog based apps like the pest....  :wink:

anyway, are there any cases in which you wouldn´t recommend a dialog based app?


Well, the obvious case where much graphical output is required. If I think of other situations I'll get back to you.

John

JohnF

  • Guest
GUI code generator
« Reply #5 on: June 18, 2005, 11:02:49 AM »
Also the advantage of using a dialog is that the controls will resize for different DPI settings.

John

Anonymous

  • Guest
GUI code generator
« Reply #6 on: June 18, 2005, 04:13:03 PM »
Quote from: "JohnF"
Also the advantage of using a dialog is that the controls will resize for different DPI settings.


And don't I know all about that one!

One gets the impression that when designing windows they were working with the MSPaint as their base model.  The gui design model is one of an open field for drawing (and window text is drawn) and a bunch of little pop up dialogs to support it.  It certainly doesn't look like they predicted the final use very well at all... most programs are just a collection of controls, often covering the entire parent window, where users enter data.  

Indeed DPI settings are a problem in windows created as windows (as opposed to dialogs) one has to put in special code to artificially upsize  everything when DPI settings go beyond the standard 96dpi.
Code: [Select]

// get the scaling factor based on DPI settings
INT WINAPI GetFontScale(void)
  { INT scale = -1;
    HDC screen = GetDC(NULL);  
    if (screen)
      { scale = (GetDeviceCaps(screen,LOGPIXELSX) * 100) / 96;
        ReleaseDC(NULL,screen);
        scale = (scale < 100) ? 100 : scale; }
    return scale; }

// get child window coordinates inside it's parent
BOOL WINAPI GetChildRect(HWND hWin, PRECT pRect)
  { if (!(GetWindowLong(hWin,GWL_STYLE) & WS_CHILD))
      return 0;
    // parent window's client offsets
    POINT pr = {0,0};
    ClientToScreen(GetParent(hWin),&pr);
    // now we need the child rect
    GetWindowRect(hWin,pRect);
    pRect->left   -= pr.x;
    pRect->top    -= pr.y;
    pRect->right  -= pr.x;
    pRect->bottom -= pr.y;
    return 1; }

// adjust a window or control size for DPI setting
BOOL WINAPI AdjustForDPI(HWND win )
  { HWND parent = NULL;
    RECT wrect,prect;
    INT  width;
    INT  height;
    INT  fscale = GetFontScale();
    // get the window's rectangle
    GetWindowRect(win,&wrect);
    // adjust for child windows
    if (GetWindowLong(win,GWL_STYLE) & WS_CHILD)
      { parent = GetParent(win);
        if (parent)
          { GetClientRect(parent,&prect);
            ClientToScreen(parent,(LPPOINT)&prect);
            wrect.left -= prect.left;
            wrect.top  -= prect.top;
            wrect.right -= prect.left;
            wrect.bottom -= prect.top; } }

    wrect.left    = MulDiv(wrect.left,fscale,100);
    wrect.top     = MulDiv(wrect.top,fscale,100);
    wrect.right   = MulDiv(wrect.right,fscale,100);
    wrect.bottom  = MulDiv(wrect.bottom,fscale,100);
    width         = wrect.right - wrect.left;
    height        = wrect.bottom - wrect.top;
    return MoveWindow(win,wrect.left,wrect.top,width,height,1); }


 :-({|=