Help.....need to know how to create a gui to execute a C script

This is a discussion on Help.....need to know how to create a gui to execute a C script within the Windows Programming forums, part of the Platform Specific Boards category; I need to create a gui that will accept a number of text box inputs (with default values), have 2 ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    Help.....need to know how to create a gui to execute a C script

    I need to create a gui that will accept a number of text box inputs (with default values), have 2 browse for file toggles (to input tabular data from 2 input files), and have a submit/cancel button to execute the code. The output of the code is tabular data. I have been reading this forum for a couple of days before I decided to post. The only thing that I came across is some information about MFC. I have never heard of MFC, let alone know where to start. I should probably also state that I am not a programmer, but instead an engineer. The reason I want to create this gui is to circulate some code through our department in an easy to use format. Currently it is text driven, and the user is required to have a c compiler to execute it. I have been successful in importing the code to visual c++ and creating an *.exe file, but then the input file names have to be hardcoded into the *.exe.......... not very user friendly. Thanks in advance for the help

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Did you compile and make any sense out of the example program I gave you on the earlier thread on the C++ board?

    I've closed the old thread by the way, this is the right place for this discussion.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    Originally posted by adrianxw
    Did you compile and make any sense out of the example program I gave you on the earlier thread on the C++ board?

    I've closed the old thread by the way, this is the right place for this discussion.
    I was able to compile and execute the code you provided. It seems fairly straight forward. Thank you. I do need additional functionality. I found the link that Magos provided ( http://sunlightd.virtualave.net/Windows/ ) for an API tutorial to provide most of the functionality I need. That being file browse, text input, OK and cancel buttons. It seems the difference between your example and the tutorial Magos provided the link to is that you did all of your gui creation in your *.cpp file where as the tutorial created a *.rc file then referenced it using "resource.h" that seems to be created automatically. I like using the resource creator in VC++, but I am struggling with all of the files that VC++ creates during compilation.

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    The only files you have to worry about during a compilation are .obj files, which are then linked together to create an executable. What exactly is the problem?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The reason I code my tutorial examples that way, is that only one file needs to be loaded. If I zip together a .cpp, .rc and .h file, frequently newcomers do not understand what to do with them.

    The example I gave was a real noddy one to show a window creation, a window message processing loop and a control creation. Most people would build their UI as a dialog box, or series of dialog boxes which were created using the resource editor.

    VC++ throws numerous files all over the place, unless you really know what you are doing, I would not move or change any of these files - let the IDE do it. Sooner or later you will, and a little later, you'll be starting a new project and trying to get it back to how it was again!

    TheForgers tutorial at www.winprog.org is also a good one, I don't know if that one is linked from the board FAQ.

    Have a play around, there is always someone here that will help you if/when you get stuck.

    Good luck.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    Question

    Originally posted by adrianxw
    The reason I code my tutorial examples that way, is that only one file needs to be loaded. If I zip together a .cpp, .rc and .h file, frequently newcomers do not understand what to do with them.

    The example I gave was a real noddy one to show a window creation, a window message processing loop and a control creation. Most people would build their UI as a dialog box, or series of dialog boxes which were created using the resource editor.

    VC++ throws numerous files all over the place, unless you really know what you are doing, I would not move or change any of these files - let the IDE do it. Sooner or later you will, and a little later, you'll be starting a new project and trying to get it back to how it was again!

    TheForgers tutorial at www.winprog.org is also a good one, I don't know if that one is linked from the board FAQ.

    Have a play around, there is always someone here that will help you if/when you get stuck.

    Good luck.

    A couple of VC++ resource editor questions:

    1/ How do I create a text entry field with a default value visible to the user in the text field?

    2/ How do I insert a *.bmp? I used the resource editor to create a bitmap icon, but I can't figure out how to associate a file with it. In the picture property menu I tried to put a path to the image, but it wouldn't take it..... tells me identifier contains illegal characters???

    Thanks in advance.
    Last edited by djamie; 01-23-2003 at 12:36 PM.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Sorry, in a bit of a rush today.

    If you created the edit box with the resource editor, I'll guess it is in a dialog. That being the case, use the SetDlgItemText() API function in your WM_INITDIALOG handler. To read it use GetDlgItemTxt().

    If you used a dynamic creation, use SetWindowText() and GetWindowText().

    LOading an icon can be done when you set up the window class structure. There are 2 members, WindowClass.hIcon and WindowClass.hIconSm both take the icon's handle, use LoadIcon() if necessary.

    That should get you going. Hopefully I'll heve more time later.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    Originally posted by adrianxw
    Sorry, in a bit of a rush today.

    If you created the edit box with the resource editor, I'll guess it is in a dialog. That being the case, use the SetDlgItemText() API function in your WM_INITDIALOG handler. To read it use GetDlgItemTxt().

    If you used a dynamic creation, use SetWindowText() and GetWindowText().

    LOading an icon can be done when you set up the window class structure. There are 2 members, WindowClass.hIcon and WindowClass.hIconSm both take the icon's handle, use LoadIcon() if necessary.

    That should get you going. Hopefully I'll heve more time later.
    I have been out of the office so I haven't had a chance to implement your suggestions. I do have one question though.... is there a good resource I can access online for looking up the parameters necessary for SetDlgItemText() , GetDlgItemTxt(). LoadIcon(), etc.???

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Yup...

    http://msdn.microsoft.com/library/default.asp

    ... be warned, some people find MSDN a little difficult to navigate, but you get used to it. Everything is there, use the search box with the API routine you want to look up and there it is, then look at the frame on the left and see where it fits into the heirachy, you start to get used to where things are then.

    Actually, if you have some spare time, it is well worth browsing the stuff on the site.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    Originally posted by adrianxw
    Sorry, in a bit of a rush today.

    If you created the edit box with the resource editor, I'll guess it is in a dialog. That being the case, use the SetDlgItemText() API function in your WM_INITDIALOG handler. To read it use GetDlgItemTxt().

    If you used a dynamic creation, use SetWindowText() and GetWindowText().

    LOading an icon can be done when you set up the window class structure. There are 2 members, WindowClass.hIcon and WindowClass.hIconSm both take the icon's handle, use LoadIcon() if necessary.

    That should get you going. Hopefully I'll heve more time later.
    I attempted to use "SetDlgItemText()" in the following example API code (from tutorial). The values I inputed didn't show up in the text edit boxes until AFTER I selected OK. I am interested in having default values appear in the text input box prior to selecting OK so the user can see them and decide whether or not they are acceptable

    Code:
    // Step2.cpp : edit box handling
    //
    
    #include <windows.h>
    #include <math.h>
    #include <stdio.h>
    #include <tchar.h>
    
    #include "resource.h"
    
    // Calculate the real and imaginary roots of the given quadratic equation
    void GetQuadraticRoots(double a, double b, double c, 
    	double *pReal1, double *pReal2, double *pImag1, double *pImag2)
    {
    	*pImag1 = *pImag2 = 0;
    	if (a == 0)
    	{
    		if (b == 0)	// indeterminate - 'c = 0' so just set it to 0
    			*pReal1 = *pReal2 = 0;
    		else		// linear: bx + c = 0 (so x = -c/b)
    			*pReal1 = *pReal2 = -c / b;
    		return;
    	}
    
    	*pReal1 = *pReal2 = -b / (2 * a);
    	if ((b * b) >= (4 * a * c))
    	{
    		// Real roots
    		*pReal1 += sqrt(b*b - 4*a*c) / (2 * a);
    		*pReal2 += sqrt(b*b - 4*a*c) / (2 * a);
    	}
    	else
    	{
    		// Complex roots
    		*pImag1 = sqrt(4*a*c - b*b) / (2 * a);
    		*pImag2 = -*pImag1;
    	}
    }
    
    BOOL MainDialog_OnCommand(HWND hWnd, WORD wCommand, WORD wNotify, HWND hControl)
    {
    	double	a, b, c, r1, r2, i1, i2;
    	TCHAR	buffer[64], *pEnd;
    
    	switch (wCommand)
    	{
    	case IDOK:
    		
    		SetDlgItemText(hWnd,IDC_A, "2");
    		GetDlgItemText(hWnd, IDC_A, buffer, sizeof(buffer) / sizeof(TCHAR));
    		a = _tcstod(buffer, &pEnd);
    		SetDlgItemText(hWnd,IDC_B, "4");
    		GetDlgItemText(hWnd, IDC_B, buffer, sizeof(buffer) / sizeof(TCHAR));
    		b = _tcstod(buffer, &pEnd);
    		SetDlgItemText(hWnd,IDC_C, "6");
    		GetDlgItemText(hWnd, IDC_C, buffer, sizeof(buffer) / sizeof(TCHAR));
    		c = _tcstod(buffer, &pEnd);
    		GetQuadraticRoots(a, b, c, &r1, &r2, &i1, &i2);
    		_sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), 
    			_T("Roots: %f%+fj, %f%+fj\n"), r1, i1, r2, i2);
    		MessageBox(hWnd, buffer, _T("Quadratic Solver"),  MB_OK);
    		break;
    
    	case IDCANCEL:
    		EndDialog(hWnd, 1);
    		break;
    	}
    	return TRUE;
    }
    
    // Main dialog message-handling function
    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (uMsg)
    	{
    	case WM_COMMAND:
    		return MainDialog_OnCommand(hWnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
    
    	case WM_CLOSE:
    		EndDialog(hWnd, 0);
    		return TRUE;
    	}
    	return FALSE;
    }
    
    int _tmain(void)
    {
    	DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), 
    		NULL, (DLGPROC)MainDialogProc, 0);
    	return 0;
    }

    Another result of this code is that the default values are not editable....... they remain the input values regardless what I type in.
    Last edited by djamie; 02-07-2003 at 12:02 PM.

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Ugly.

    Try putting the SetDlgItemText() calls in a WM_INITDIALOG message handler in your main dialog process.

    You are having paint problems. You cannot, (generally at least, certainly not as you are doing), write to and read from a control in the same control loop iteration, to update the contents of a control requires the processing of WM_PAINT messages, you are not doing that/giving anything else the chance to do that.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    Originally posted by adrianxw
    Ugly.

    Try putting the SetDlgItemText() calls in a WM_INITDIALOG message handler in your main dialog process.

    You are having paint problems. You cannot, (generally at least, certainly not as you are doing), write to and read from a control in the same control loop iteration, to update the contents of a control requires the processing of WM_PAINT messages, you are not doing that/giving anything else the chance to do that.

    Can you give me an example of how to incorporate this suggestion in the code that I previously posted?

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Code:
    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (uMsg)
    	{
            case WM_INITDIALOG:
    		SetDlgItemText(hWnd,IDC_A, "2"); //
    		SetDlgItemText(hWnd,IDC_B, "4"); // These here and deleted from the other routine
    		SetDlgItemText(hWnd,IDC_C, "6"); //
    	case WM_COMMAND:
    		return MainDialog_OnCommand(hWnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
    
    	case WM_CLOSE:
    		EndDialog(hWnd, 0);
    		return TRUE;
    	}
    	return FALSE;
    }
    I can't test this as I cannot compile your program without the header and resource script. If you want me to compile it, zip the necessary files together and attach them to your post.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    Registered User
    Join Date
    Jan 2003
    Posts
    14
    Thanks!!!!!!! It did exactly what I needed it to. I am sure I will have some more questions soon. Right now I am going to work on adding "browse" functionality for loading files. I am going to give it a shot before I ask for assistance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. win32 GUI components
    By abraham2119 in forum Windows Programming
    Replies: 5
    Last Post: 06-18-2009, 11:18 AM
  2. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 01:27 AM
  3. Messages and global scripts?
    By suzakugaiden in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2005, 11:38 PM
  4. C++: Reference Book, GUI, Networking & Beyond
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 11-10-2001, 08:03 PM
  5. GUI (Graphical User Interface) Help Needed
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-11-2001, 11:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21