In this exercise, you will create a message box using both the Win32 API and the inherent Visual Basic function,
MsgBox .
* To create a message box using the Win32 API:
- Start Microsoft Visual Basic and create a new standard EXE project.
- From the Project menu, select Add Module .
- In General Declarations , type the following code:
Declare Function MessageBox Lib "user32" Alias "MessageBoxA"(ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
- Add a new command button control to Form1 .
- In the Click event of Command1 , type the following code:
MessageBox Me.hwnd, "API MessageBox function", "API", 0
- Run the application.
- Click Command1 .
The MessageBox Win32 API function has been called directly from Visual Basic code.
* To create a message box in Visual Basic:
- Start Visual Basic and select Standard EXE .
- Add a command button control to Form1 .
- In the Click event of Command2 , enter the following code:
MsgBox "Visual Basic MsgBox function"
- From the Run menu, click Start to run the program.
- Click Command12 .
Notice that a message box has been displayed. Visual Basic internally utilizes the Win32 API to call the MessageBox function in the User32.dll library.