Archive for the 'Windows' Category

C, Source Code, Windows

Reboot or Shutdown a pc

This is a little how-to that explains how to shutdown or reboot a Windows machine in c++ .
In the source code you will find the function ShutDown, definied as follow:

bool ShutDown(bool restart)

The function shutdowns or reboots the pc, and returns false if the shutdown can’t be done (for example a process denied the power off).

Shut Down

So, to shutdown the pc, you only have to call the function and check if the shutdown was done.

if (!ShutDown(false))
{
	// shutdown not done.
}

Part of source code following:
Continue Reading »

C, Source Code, Windows

C++ Timer Class

Starting from the article “C++ timer”, we created a simply class that act as a wrapper to the Windows API and that easily allows to start a timer, stop it. and assign the function to call when the timer is elapsed.

Timer

The following is a little example that explains how to use the class:
Continue Reading »

C, Source Code, Windows

Detect when an usb device is inserted or removed.

Normally the autorun in usb storage devices like pendrives is disabled for security reasons, so i wrote a little utility in c++ to launch a custom application in my pendrive when I insert it in a usb port.

Logo usb

Normally if you want to detect when a “hotplug” device has been inserted or removed from your system, you have to intercept the system message “WM_DEVICECHANGE” in “WndProc” function of the main window of your application.
Continue Reading »

C, Windows

C++ Timer

To create a timer in c++ on Windows we must invoke the SetTimer() method, defined in windows.h.

UINT_PTR SetTimer(
// handle to the window associated to the timer
HWND hWnd,
// Timer ID
UINT_PTR nIDEvent,
// Elapse time in milliseconds
UINT uElapse,
// callback method to invoke when the timer expires
TIMERPROC lpTimerFunc
);

The hWnd argument is the handle to a window: for semplicity we don’t use any Handle, so we set it to NULL.

The function always returns an uint that represents the ID of the timer. if hWnd is NULL, the second parameter will be ignored and we can’t directly set the timer ID, but it will be assigned from the function. We can check if the creation of the timer didn’t have any problem if the uint returned from the function it’s not zero. Instead, if hWnd is not null, the timer ID will be assigned from the nIDEvent parameter

Add a global variable (ok, it’s not a good programming pratice adding global variabile, but this is only an howto) where we can save the timer ID:

uint m_timerID;

Continue Reading »

News, Windows

Vista 3.1

Today I installed Vista with my friends and we discovered that when Microsoft says that DirectX10 can run only on Vista because they are strongly legate with the new OS they are only saying bullshits, because the new OS depends yet from Windows 3.1!! :D
Windows Vista 3.1

It’s evident in the image that the directory selection is equal to the original Windows 3.1!!
LOL! :D

Windows

Vista 3.1

Oggi ho installato Vista a casa di amici e abbiamo scoperto che quando la Microsoft dice che le DirectX10 possono girare soltanto su Windows Vista perchè fortemente legate alle nuove funzionalità del sistema operativo sta semplicemente dicendo porcate, perchè quest’ultimo in realtà dipende ancora da Windows 3.1!!!! :f2:

Windows Vista 3.1

Come si nota dall’immagine infatti la schermata di selezione della directory è rimasta ancora quella di Windows 3.1!!! Su Windows Xp era già presente questo “bug” (Pannello di controllo->Font e aggiungete un carattere), ma la Microsoft non l’ha ancora corretto nonostante questa schermata risalga ormai ai tempi preistorici! :f8: