×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Basic GUI

Basic GUI

Basic GUI

(OP)
I was wondering how I could go about making a simple GUI like that of a Visual Basic App.  This would be like a Window a button and a text box.  

Thanks,
~Ben

RE: Basic GUI

Your best bet is to look at either Borland's VCL or Microsoft's MFC. There are also some freeware/shareware libraries like GNU.

James P. Cottingham
www.ivcusa.com

RE: Basic GUI

(OP)
Yes but how do you make a button or a textfile from scratch or is it possible to call it from a .h file.

thanks,
~ben

RE: Basic GUI

By "from scratch" do you mean without using the resource compiler and just calling the CreateWindow() API function from your program and specifing if you want BUTTON, EDIT, SCROLLBAR, etc styles? Remember that all controls are actually "windows".
Or do you mean, "How do I create a NEW resource file and place new resources such as BUTTONs, EDITs, SCROLLBARs, etc within it?

 
Kim_Christensen@telus.net
http://www3.bc.sympatico.ca/Kim_Christensen/index.html
 

RE: Basic GUI

(OP)
i mean creating button and the like from raw code.  And how what i need to do to act apon their actions.  You know like what kind of .h file is used what commands.

Thank you for all the help,

~ben

RE: Basic GUI

Ok, here is a modified version of a Hello Windows example.
I have added a scroll bar and a button.

#define SCROLL_ME 101
#define PRESS_ME 100
#include <windows.h>

HANDLE ThisInstance;

long FAR PASCAL WndProc (HWND, UINT, UINT, LONG) ;

int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
            LPSTR lpszCmdParam, int nCmdShow)
    {
    static char szAppName[] = "HelloWin" ;
    HWND        hwnd ;
    MSG        msg ;
    WNDCLASS    wndclass ;

    if (!hPrevInstance)
     {
     wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc    = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance    = hInstance ;
     wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName    = NULL ;
     wndclass.lpszClassName    = szAppName ;

     RegisterClass (&wndclass) ;
     }

    hwnd = CreateWindow (szAppName,    // window class name
          "The Hello Program",    // window caption
          WS_OVERLAPPEDWINDOW,    // window style
          CW_USEDEFAULT,    // initial x position
          CW_USEDEFAULT,    // initial y position
          CW_USEDEFAULT,    // initial x size
          CW_USEDEFAULT,    // initial y size
          NULL,            // parent window handle
          NULL,            // window menu handle
          hInstance,        // program instance handle
          NULL) ;        // creation parameters

    ShowWindow (hwnd, nCmdShow) ;
    UpdateWindow (hwnd) ;
    ThisInstance = hInstance;

    while (GetMessage (&msg, NULL, 0, 0))
     {
     TranslateMessage (&msg) ;
     DispatchMessage (&msg) ;
     }
    return msg.wParam ;
    }

long FAR PASCAL WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
    {
    HDC        hdc ;
    PAINTSTRUCT    ps ;
    RECT    rect ;

    switch (message)
     {
     case WM_CREATE:

          CreateWindow ("BUTTON",    // window class name
          "Press Me!",            // window caption
          WS_VISIBLE | WS_CHILDWINDOW,    // window style
          100,                // initial x position
          100,                // initial y position
          100,                // initial x size
          50,                // initial y size
          hwnd,                // parent window handle
          PRESS_ME,            // window menu handle
          ThisInstance,            // program instance handle
          NULL) ;            // creation parameters

          CreateWindow ("SCROLLBAR",    // window class name
          "Scroll Me!",            // window caption
          WS_VISIBLE | WS_CHILDWINDOW,    // window style
          250,                // initial x position
          100,                // initial y position
          200,                // initial x size
          25,                // initial y size
          hwnd,                // parent window handle
          SCROLL_ME,            // window menu handle
          ThisInstance,            // program instance handle
          NULL) ;            // creation parameters



     return 0;


     case WM_COMMAND:
          if ( wParam == PRESS_ME) MessageBox ( hwnd, "I was pressed!", "BUTTON", MB_OK);
          return 0;

     case WM_HSCROLL:

          if ( wParam == SB_LINEDOWN )
          MessageBox ( hwnd, "I was scrolled right", "SCROLLBAR", MB_OK);
          if ( wParam == SB_LINEUP )
          MessageBox ( hwnd, "I was scrolled left", "SCROLLBAR", MB_OK);
          return 0;

     case WM_PAINT :
          hdc = BeginPaint (hwnd, &ps) ;

          GetClientRect (hwnd, &rect) ;

          DrawText (hdc, "Hello, Windows!", -1, &rect,
            DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;

          EndPaint (hwnd, &ps);
          return 0 ;

     case WM_DESTROY :
          PostQuitMessage (0) ;
          return 0 ;
     }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
    }


 
Kim_Christensen@telus.net
http://www3.bc.sympatico.ca/Kim_Christensen/index.html
 

RE: Basic GUI

(OP)
I entered it in and this is what i got:


line 26
untitled1.cpp
ANSI C++ forbids implicit conversion from `void *' in assignment

line 43
untitled1.cpp
ANSI C++ forbids implicit conversion from `void *' in argument passing

line 77
untitled1.cpp
passing `int' to argument 10 of `CreateWindowExA(long unsigned int, const CHAR *, const CHAR *, long unsigned int, int, int, int, int, HWND__ *, HMENU__ *, HINSTANCE__ *, void *)' lacks a cast

line 77
untitled1.cpp
ANSI C++ forbids implicit conversion from `void *' in argument passing

line 89
untitled1.cpp
passing `int' to argument 10 of `CreateWindowExA(long unsigned int, const CHAR *, const CHAR *, long unsigned int, int, int, int, int, HWND__ *, HMENU__ *, HINSTANCE__ *, void *)' lacks a cast

line 89
untitled1.cpp
ANSI C++ forbids implicit conversion from `void *' in argument passing




I don't know why it is doing this.  I cut and pasted it to see how it worked and this is what I got.


My greatest thanks for your troubles,
~Ben

RE: Basic GUI

Just to add something: the PASCAL keyword has been replaced by WINAPI and CreateWindowEx() offers the Windows9X/2K style Window features. CreateWindow() is still included for compatability with Windows 3.X - but is also obsolete. As for your error - I don't use a Borland compiler, so I can't help you here.

Rob Marriott
rob@career-connections.net

RE: Basic GUI

(OP)
Neither do I.  I use Dev-C++.  I think that could be a problem.

RE: Basic GUI

As CTCC1 noted, my example was win16. If your compiler can create a 16bit target, try that. I'm not familiar with Dev-C++ at all, but I did cut and paste the code back into my compiler and it ran fine with one little mod. (I had to unwrap one line to eliminate an unterminated string error due to TekTips formatting) The key function to look up in your compilers help file is CreateWindowEx() for WIN32 or CreateWindow() for win16.

 
Kim_Christensen@telus.net
http://www3.bc.sympatico.ca/Kim_Christensen/index.html
 

RE: Basic GUI

Dev-C++ comes with a lot of built in features for Win32 programming. It has a built in window maker and popup box generator.

You should check them out if you want a basis in the language.

Hope this helps,

-Vic

vic cherubini
vikter@epicsoftware.com
www.epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close