Featured Posts

MessageBox Function Visual Programming

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 31-10-2009

0

The MessageBox function is designed to display short messages.

Syntax

int MessageBox(
HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);

Parameters

hWnd –> Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.

lpText –> Pointer to a null-terminated string that contains the message to be displayed. If the string consists of more than one line, you can separate the lines using a carriage return and/or linefeed character between each line.

lpCaption –> Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title is Error.

uType –> Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.

You can pick one constant from the first set to indicate what buttons you wish to appear in the dialog box:

  • #define MB_OK                       0x00000000L
  • #define MB_OKCANCEL                 0x00000001L
  • #define MB_ABORTRETRYIGNORE         0x00000002L
  • #define MB_YESNOCANCEL              0x00000003L
  • #define MB_YESNO                    0x00000004L
  • #define MB_RETRYCANCEL              0x00000005L

When you set the fourth argument to 0 in HELLOMSG, only the OK button appears.

Return Value

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

If the function fails, the return value is zero. To get extended error information, call GetLastError

If the function succeeds, the return value is one of the following menu-item values.

IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDCONTINUE Continue button was selected.
IDIGNORE Ignore button was selected.
IDNO No button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDTRYAGAIN Try Again button was selected.
IDYES Yes button was selected.

#include <windows.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MessageBox (NULL, TEXT (“Hello, vdiscussion.com”), TEXT (“Vdiscussion.com”), 0) ;

return 0 ;
}

Output

Helloprogramoutput

Helloprogramoutput

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Basic Visual Program C++ and Explaination

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 31-10-2009

0

#include <windows.h>

# Preprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always preceded by a hash sign (#). The preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements.

These preprocessor directives extend only across a single line of code. As soon as a newline character is found, the preprocessor directive is considered to end. No semicolon (;) is expected at the end of a preprocessor directive. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash (\).

WINDOWS.H is a master include file that includes other Windows header files, some of which also include other header files. The most important and most basic of these header files are:

  • WINDEF.H Basic type definitions.
  • WINNT.H Type definitions for Unicode support.
  • WINBASE.H Kernel functions.
  • WINUSER.H User interface functions.
  • WINGDI.H Graphics device interface functions.

These header files define all the Windows data types, function calls, data structures, and constant identifiers. They are an important part of Windows documentation. You might find it convenient to use the Find In Files option from the Edit menu in the Visual C++ Developer Studio to search through these header files. You can also open the header files in the Developer Studio and examine them directly.

The entry point to a Windows program is WinMain

Looks Like this

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

WINAPI must be included because windows expects a WinMain that is of the _stdcall calling convention, not the default _cdecl.

The first parameter HINSTANCE hInstance is a instance handle.  Handle is simply a number that an application uses to identify something. In this case, the handle uniquely identifies the program. It is required as an argument to some other Windows function calls. In early versions of Windows, when you ran the same program concurrently more than once, you created multiple instances of that program. All instances of the same application shared code and read-only memory (usually resources such as menu and dialog box templates). A program could determine if other instances of itself were running by checking the hPrevInstance Second parameter. It could then skip certain chores and move some data from the previous instance into its own data area.

In the 32-bit versions of Windows, this concept has been abandoned. The second parameter to WinMain is always NULL (defined as 0).

The third parameter to PSTR szCmdLine is the command line used to run the program. Some Windows applications use this to load a file into memory when the program is started.

The fourth parameter to int iCmdShow indicates how the program should be initially displayed—either normally or maximized to fill the window, or minimized to be displayed in the task list bar.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Simple Visual C++ Program

Posted by admin | Posted in Software Programs, Visual Programming | Posted on 28-10-2009

0

#include <windows.h>

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{

MessageBox (NULL, TEXT (“Hello, Windows 98!”), TEXT (“HelloMsg”), 0) ;

return 0 ;
}

Step by Step Procedure :

How to Compile and Build the project in Visual C++
Step 1: Select New from the File menu. In the New dialog box, pick the Projects tab.
Step 2: Select Win32 Application. In the Location field, select a subdirectory. In the Project Name field, type the name of the project, which in this case is HelloMsg .  This will be a subdirectory of the directory indicated in the Location field.
Step 3: Create New Workspace button should be checked. The Platforms section should indicate Win32. Choose OK.

Step 4: A dialog box labeled Win32 Application – Step 1 Of 1 will appear. Indicate that you want to create an Empty Project, and press the Finish button.
Step 5: Select New from the File menu again. In the New dialog box, pick the Files tab. Select C++ Source File. The Add To Project box should be checked, and HelloMsg should be indicated. Type HelloMsg.c in the File Name field. Choose OK.Step 6 : Paste the Program

Step 6 : When you’re ready to compile HELLOMSG, you can select Build Hellomsg.exe from the Build menu, or press F7, or select the Build icon from the Build toolbar. (The appearance of this icon is shown in the Build menu. If the Build toolbar is not currently displayed, you can choose Customize from the Tools menu and select the Toolbars tab. Pick Build or Build MiniBar.)

Step 7: You can select Execute Hellomsg.exe from the Build menu, or press Ctrl+F5, or click the Execute Program icon (which looks like a red exclamation point) from the Build toolbar. You’ll get a message box asking you if you want to build the program.

Sample Output will be displayed.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Scroll Bar Messages:Visual Programming

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 25-10-2009

0

Windows sends the window procedure WM_VSCROLL (vertical scroll) and WM_HSCROLL (horizontal scroll) messages when the scroll bar is clicked with the mouse or the thumb is dragged. Each mouse action on the scroll bar generates at least two messages, one when the mouse button is pressed and another when it is released.

WM_VSCROLL and WM_HSCROLL are accompanied by the wParam and lParam message parameters. For messages from scroll bars created as part of your window, you can ignore lParam; that’s used only for scroll bars created as child windows, usually within dialog boxes.

The wParam message parameter is divided into a low word and a high word. The low word of wParam is a number that indicates what the mouse is doing to the scroll bar. This number is referred to as a “notification code.” Notification codes have values defined by identifiers that begin with SB, which stands for “scroll bar.” Here’s how the notification codes are defined in WINUSER.H:

#define SB_LINEUP           0
#define SB_LINELEFT         0
#define SB_LINEDOWN         1
#define SB_LINERIGHT        1
#define SB_PAGEUP           2
#define SB_PAGELEFT         2
#define SB_PAGEDOWN         3
#define SB_PAGERIGHT        3
#define SB_THUMBPOSITION    4
#define SB_THUMBTRACK       5
#define SB_TOP              6
#define SB_LEFT             6
#define SB_BOTTOM           7
#define SB_RIGHT            7
#define SB_ENDSCROLL        8

Scroll Bar Messages

If you hold down the mouse button on the various parts of the scroll bar, your program can receive multiple scroll bar messages. When the mouse button is released, you’ll get a message with a notification code of SB_ENDSCROLL. You can generally ignore messages with the SB_ENDSCROLL notification code. Windows will not change the position of the scroll bar thumb. Your application does that by calling SetScrollPos.

When you position the mouse cursor over the scroll bar thumb and press the mouse button, you can move the thumb. This generates scroll bar messages with notification codes of SB_THUMBTRACK and SB_THUMBPOSITION. When the low word of wParam is SB_THUMBTRACK, the high word of wParam is the current position of the scroll bar thumb as the user is dragging it. This position is within the minimum and maximum values of the scroll bar range. When the low word of wParam is SB_THUMBPOSITION, the high word of wParam is the final position of the scroll bar thumb when the user released the mouse button. For other scroll bar actions, the high word of wParam should be ignored.

To provide feedback to the user, Windows will move the scroll bar thumb when you drag it with the mouse as your program is receiving SB_THUMBTRACK messages. However, unless you process SB_THUMBTRACK or SB_THUMBPOSITION messages by calling SetScrollPos, the thumb will snap back to its original position when the user releases the mouse button.

A program can process either the SB_THUMBTRACK or SB_THUMBPOSITION messages, but doesn’t usually process both. If you process SB_THUMBTRACK messages, you’ll move the contents of your client area as the user is dragging the thumb. If instead you process SB_THUMBPOSITION messages, you’ll move the contents of the client area only when the user stops dragging the thumb.

The WINUSER.H header files includes notification codes of SB_TOP, SB_BOTTOM, SB_LEFT, and SB_RIGHT, indicating that the scroll bar has been moved to its minimum or maximum position. However, you will never receive these notification codes for a scroll bar created as part of your application window.

Although it’s not common, using 32-bit values for the scroll bar range is perfectly valid. However, the high word of wParam, which is only a 16-bit value, cannot properly indicate the position for SB_THUMBTRACK and SB_THUMBPOSITION actions. In this case, you need to use the function GetScrollInfo

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Scroll Bar Range and Position

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 25-10-2009

0

Every scroll bar has an associated “range” and “position.” The scroll bar range is a pair of integers representing a minimum and maximum value associated with the scroll bar. The position is the location of the thumb within the range. When the thumb is at the top (or left) of the scroll bar, the position of the thumb is the minimum value of the range. At the bottom (or right) of the scroll bar, the thumb position is the maximum value of the range.

By default, the range of a scroll bar is 0 (top or left) through 100 (bottom or right), but it’s easy to change the range to something that is more convenient for the program:

SetScrollRange (hwnd, iBar, iMin, iMax, bRedraw) ;

iBar argument is either SB_VERT or SB_HORZ.

iMin and iMax are the new minimum and maximum positions of the range.

bRedraw to TRUE if you want Windows to redraw the scroll bar based on the new range. (If you will be calling other functions that affect the appearance of the scroll bar after you call SetScrollRange, you’ll probably want to set bRedraw to FALSE to avoid excessive redrawing.)

hwnd parameter to the window procedure is the handle of the window changing in size. (Remember that one window procedure could be handling messages for multiple windows that were created based on the same window class. The hwnd parameter lets the window procedure know which window is receiving the message.) The message parameter is WM_SIZE. The wParam parameter for a WM_SIZE message is the value SIZE_RESTORED, SIZE_MINIMIZED, SIZE_MAXIMIZED, SIZE_MAXSHOW, or SIZE_MAXHIDE (defined in the WINUSER.H header file as the numbers 0 through 4). That is, the wParam parameter indicates whether the window is being changed to a nonminimized or nonmaximized size, being minimized, being maximized, or being hidden.

The thumb position is always a discrete integral value. For instance, a scroll bar with a range of 0 through 4 has five thumb positions
Scroll Bar Range and Position

How to set the Thumb Position of the window

SetScrollPos (hwnd, iBar, iPos, bRedraw);

SetScrollPos to set a new thumb position within the scroll bar range.

iPos argument is the new position and must be within the range of iMin and iMax. Windows provides similar functions (GetScrollRange and GetScrollPos) to obtain the current range and position of a scroll bar.

Windows’ responsibilities for scroll bars:

  • Handle all processing of mouse messages to the scroll bar.
  • Provide a reverse-video “flash” when the user clicks the scroll bar.
  • Move the thumb as the user drags the thumb within the scroll bar.
  • Send scroll bar messages to the window procedure of the window containing the scroll bar.

Responsibilities of your program:

  • Initialize the range and position of the scroll bar.
  • Process the scroll bar messages to the window procedure.
  • Update the position of the scroll bar thumb.
  • Change the contents of the client area in response to a change in the scroll bar.
VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Scroll Bars – Visual Programming

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 24-10-2009

0

Scroll bars are one of the best features of a graphical user interface. They are easy to use and provide excellent visual feedback. You can use scroll bars whenever you need to display anything—text, graphics, a spreadsheet, database records, pictures, Web pages—that requires more space than is available in the window’s client area.

Scroll bars are positioned either vertically (for up and down movement) or horizontally (for left and right movement). You can click with the mouse the arrows at each end of a scroll bar or the area between the arrows. A “scroll box” (or “thumb”) travels the length of the scroll bar to indicate the approximate location of the material shown on the display in relation to the entire document. You can also drag the thumb with the mouse to move to a particular location.

Scroll Bars - Visual Programming

Programmers sometimes have problems with scrolling terminology because their perspective is different from the user’s. A user who scrolls down wants to bring a lower part of the document into view; however, the program actually moves the document up in relation to the display window. The Window documentation and the header file identifiers are based on the user’s perspective: scroll up means moving toward the beginning of the document; scroll down means moving toward the end.

It is easy to include a horizontal or vertical scroll bar in your application window. All you need do is include the window style (WS) identifier WS_VSCROLL (vertical scroll) or WS_HSCROLL (horizontal scroll) or both in the third argument to CreateWindow. The scroll bars specified in the CreateWindow function are always placed against the right side or bottom of the window and extend the full length or width of the client area. The client area does not include the space occupied by the scroll bar. The width of the vertical scroll bar and the height of the horizontal scroll bar are constant for a particular video driver and display resolution. If you need these values, you can obtain them (as you may have observed) from the GetSystemMetrics calls.

Windows takes care of processing all mouse messages to the scroll bars. However, scroll bars do not have an automatic keyboard interface. If you want the cursor keys to duplicate some of the functionality of the scroll bars, you must explicitly provide logic for that (as we’ll do when we make another version of the SYSMETS program in the next chapter).

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

An Introduction to GDI

Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 24-10-2009

0

Graphics Device Interface (GDI) functions is used to paint the client area of your window. Windows provides several GDI functions for writing text strings to the client area of the window. The most commonly used text output function is undoubtedly TextOut. This function has the following format:

TextOut (hdc, x, y, psText, iLength) ;

Explanatation:

TextOut writes a character string to the client area of the window.
hdc argument is a “handle to a device context,” and it is an important part of GDI. Virtually every GDI function requires this handle as the first argument to the function.
x and y arguments define the starting position of the character string in the client area.
The psText argument is a pointer to the character string.
iLength is the length of the string in characters.

More About GDI:(Wiki)

The Graphics Device Interface (GDI) is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers.

GDI is responsible for tasks such as drawing lines and curves, rendering fonts and handling palettes. It is not directly responsible for drawing windows, menus, etc.; that task is reserved for the user subsystem, which resides in user32.dll and is built atop GDI. GDI is similar to Macintosh’s QuickDraw.

Perhaps the most significant capability of GDI over more direct methods of accessing the hardware is its scaling capabilities, and abstraction of target devices. Using GDI, it is very easy to draw on multiple devices, such as a screen and a printer, and expect proper reproduction in each case. This capability is at the center of all What You See Is What You Get applications for Microsoft Windows.

Simple games which do not require fast graphics rendering use GDI. However, GDI cannot animate properly (no notion of synchronizing with the framebuffer) and lacks rasterization for 3D. Modern games tend to use DirectX or OpenGL, which give programmers the capabilities to use features of modern hardware.

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)