Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

<< | Home | Stuff | Download | Link | >>


Play with WIN32 API using C++ Builder; create a "joke" program

I  inspired to create a "joke" program  when read a book : "Learn Borland C++ Builder" about win32-bit Application Programming Interface (WIN32 API). The original book is "Pemrograman Borland C++ Builder" by Budi Raharjo and Imam Heryanto. I think it's cool if I can modify my Windows and create my own Interfaces. I am still learning about it. I will thank to You if You can tell me more about WIN32 API. Before you try my program I have to say I'm sorry if there are something that unintended.

WIN32 API is a horde of functions that used to build interfaces in Windows Operating System. As we know that Windows is built using C. We can make Windows application easily by involving the WIN32 API by using C, especially in C++ Builder. C++ Builder allowed the Programmers and even developers to access and use WIN32 API functions.

C++ Builder is a development tool that applied visualization concept. This development program use a C++ language. For a beginner programmer will get easy to learn and make an application. And for an advance programmer will get a comfortable for creating a powerful application.

WIN32 API Programming is very complex. There are many different API for special purpose. Example : Multimedia API, Messaging (MAPI) API, Internet (ISAPI) API, Telephony (TAPI) API etc.

But I will tell you about simple WIN32 API. I am still in learning process.

Program Description

The program is trying to decoy by act as an URL ID Searcher. Try to tease and attract the user to try the program, maybe you can get any better idea than me. Actually I didn't make an URL ID Searcher  program. I made a Shutdown program  After they click "Get The ID" button, the computer will shutdown....;-p

I am using ExitWindowsEx WIN32 API function. The ExitWindowsEx function either logs off, shuts down, or shuts down and restarts the system.
Base Syntax :
BOOL ExitWindowsEx(

    UINT uFlags, // shutdown operation
    DWORD dwReserved // reserved
; this parameter is ignored.
);

Parameters  "uFlags"  specifies the type of shutdown. This parameter must be some combination of the following values:

Value

Meaning

EWX_FORCE

 

Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system.
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.

Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege.

Windows 95: Security privileges are not supported or required.

EWX_REBOOT Shuts down the system and then restarts the system.

Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege.

Windows 95: Security privileges are not supported or required.

EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.

Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege.

Windows 95: Security privileges are not supported or required.

Return Values

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

Remarks

The ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown or logoff then proceeds asynchronously.
During a shutdown or log-off operation, applications that are shut down are allowed a specific amount of time to respond to the shutdown request. If the time expires, Windows displays a dialog box that allows the user to forcibly shut down the application, to retry the shutdown, or to cancel the shutdown request. If the EWX_FORCE value is specified, Windows always forces applications to close and does not display the dialog box.

The ExitWindowsEx function sends a separate notification message, CTRL_SHUTDOWN_EVENT or CTRL_LOGOFF_EVENT as the situation warrants, to console processes. A console process routes these messages to its HandlerRoutine functions, which are added and removed by calls to the SetConsoleCtrlHandler function. ExitWindowsEx sends these notification messages asynchronously; thus, an application cannot assume that the console notification messages have been handled when a call to ExitWindowsEx returns.

Windows NT: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege.
Windows 95: Security privileges are not supported or required.
 

Listing Program

CPP listing program :

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "uIDSearch.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    UINT flag;                                  
 //3 lines; main program
    flag = EWX_SHUTDOWN;            
 //-----
    ExitWindowsEx(flag,0);               
//------
}
//---------------------------------------------------------------------------
 

I just used 3 lines in my main program. I used EWX_SHUTDOWN. I used this because Windows will send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. It will be not a joke any more if I use EWX_FORCE because Windows will not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. It isn't wise!!!!

For latest Windows operation like XP, you can use Windows NT notifications.

I just use a small part about WIN32 API. I'm still learning.......

Download Section :

Literatures :

 

Comment :

Any suggestions, comments, etc. E-mail me: fridiant@yahoo.com

_____________________________________________________________________________________________________________________

<< | Home | Stuff | Download | Link | >>

_______________________________________________________________________________________________________

Tiar Fridianto @ 2004 : fridiant@yahoo.com