Changing the Background and Static Text Color of your MFC Dialog box

By default, VC++ doesn’t have a backcolor or forecolor control properties unlike other visual programming languages such as VB or VFP. But you can change the dialog box text and back color by following these simple steps.

1. Start VC++ by clicking the start button>All Programs>Microsoft Visual Studio 6.0> Microsoft Visual C++ 6.0.
2. Click File>New>Select MFC AppWizard (exe)>Type the Project name>Click Ok>Select Dialog based>Click Finish.
3. Right click your dialog box>In the Class name list box>Select CprojectnameAPP>Double click the InitInstance member function.

The following codes will appear:

CBkColorApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBkApp initialization
BOOL CBkColorApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
//  the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic();// Call this when linking to MFC statically
#endif
4. Type the following before or after the line AfxEnableControlContainer(). Change the numbers inside the oval brace to create different background or text colors.
SetDialogBkColor(RGB(255,255,255),RGB(255,255,255));
5. The first RGB is for the backcolor and the other one is for the text.
6. Click the run icon to view the result.

Adding Colors to you C++ Program Output

There are several methods that can be used to add colors to your C++ program output but the simplest way is by using the system function. The system function allows you to pass commands to the operating system for execution. The syntax of using system varies in different programming languages. In C++, system function takes the following syntax:

system(“command”);
example:

system(“logoff”);
To add a color to your program output, use the color command which has the following syntax:

color bf
Were b is the background and f is the foreground.
Available colors for background and foreground are as follows:

0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
So if you want to have a black background with light green text, use:

system(“color oa”);

system function is typed inside your main function (or inside other functions) just after the opening curly brace and before the closing curly brace.

example:
#include<iostream>
using namespace std;
int main()
{
system(“Color 0a”);
cout<<”I am blue”;
cin.get();
}

The codes above produce a red text in black background. There are several things that you can do with the system function, and it’s up to you to discover. Good luck!

Viewing the Control Toolbox in Microsoft Visual C++ 6.0 MFC

Unlike other application and development tools, Visual C++ does not permit viewing some of its Integrated Development Environment (IDE) components such as dialog box or control toolbox using the View menu. Unintentionally closing an IDE component could result to total disarray. To show one of its important components, the Control toolbox, use any of the following methods:

Method 1:

1. Right-click an empty pane in the Microsoft Visual C++ toolbar. A pop-up menu containing several options will be displayed>Select Controls option.

Note: The Controls option only appears on the pop-up menu if your dialog-based application is shown on the screen. If you dialog-box is hidden, click the resource tab on the right pane of you Visual C++ IDE> Expand the Dialog tree control item>Double-click IDD_Nameofyouproject_DIALOG.

Or

Method 2:

1. Click on the tools menu>Customize>Click the toolbars tab.

2. Check Controls from the toolbars list box>Click the close button.

ISAPLHA and ISDIGIT functions in Visual FoxPro 9

ISALPHA function is one of the powerful functions in Visual FoxPro 9 that can be used to test if the inputted data is a string or character. By default, ISALPHA has a false value and returns a true value when the Expression is a string data. It is very helpful in filtering illegal inputs:

Syntax:
ISALPHA(Expression)

Where;
1. Expression can be a variable, a text, or a control. ISAPLHA can be entered in any capitalization.

Examples:
ISALPHA(“John”)
ISALPHA(strname)
ISALPHA(Thisform.NameTextbox.Value)

To see ISALPHA in action, follow these steps:

1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.
2. Click File>New>Form>New File.
3. Design your interface as follows:



4. Double-click the control named OkButton then enter the following codes:



5.Press F5 to test our sample application.

Another useful input validation function in Visual FoxPro 9.0 is the ISDIGIT function. It works like ISNUMERIC function in PHP wherein it allows you to test whether the input is a numeric data. Just like the ISALPHA function, the default value of is numeric function is false and it returns true whenever the contents of the expression is a numeric value.

Syntax:
IDIGIT (Expression)

Where;
1. Expression can be a variable, a number, or a control. ISDIGIT can be entered in any capitalization.

Examples:
ISDIGIT (“John”)
ISDIGIT (intage)
ISDIGIT (Thisform.AgeTextbox.Value)

The following example demonstrates the capability of ISDIGIT function:

1. Click Start>All Programs>Microsoft Visual FoxPro 9.0.
2. Click File>New>Form>New File.
3. Design your interface as follows:



4. Double-click the OkButton then enter the following:



5. Press F5 to test our sample application.

Those are the two powerful input validation functions in Visual FoxPro 9. Hope you learn something from it. Till next time.

Changing the header text of a grid control in Visual FoxPro 9

By default, grid control gets its header text from the fieldname caption of a record value displayed in a grid column. To change the grid control header text, follow these steps:

1. Click Start > All Programs > Visual FoxPro 9.

2. Click File>New>Table>New File> Type the table name. For the sake of example, use tblNames as a filename>Click Save. Alternatively, you can type CREA tblNames in the command window. Enter the following fieldname captions and data type:



3. Then Click the Ok Button.

4. Press CTRL + F2 to view the command window. Type APPE then press enter. The APPE or APPEND commands pops-up the append window which enables you to add new records.

5. Add the following records:



6. Click the close button [x] to save the inputted records.

7. Create a new form by clicking File>New>Form>New File. Alternatively, type CREA form in the command window then press enter.

8. Click View> Form Control Toolbar(twice) to activate the toolbox window then click and drag a Grid control from the toolbox to your form.

9. Right-click the Grid control on your form>Select builder. A dialog box containing the following options should then appear:



10. Click the [>>] button. This transfers the fieldnames in the Available fields list box to the selected fields list box.

11. Click the layout tab. The following should then appear:



12. Click the grid control’s column header then enter your desired caption in the caption textbox.




13. Click the Ok button to apply the changes then press CTRL + E to run your form. Alternatively, you can click the run [!] icon.