Jump to content
xisto Community
Sign in to follow this  
DeveloperX

Cooolest Winapi Functions power manag., registry...

Recommended Posts

First function will instantly reboot your PC

Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPublic Const EWX_FORCE = 4Public Const EWX_LOGOFF = 0Public Const EWX_REBOOT = 2Public Const EWX_SHUTDOWN = 1

This function using:

ExitWindowsEx EWX_FORCE + EWX_REBOOT, 0

Second function will open/close your CD-ROM drive

Option ExplicitPublic Declare Function mciSendString Lib "winmm.dll" _Alias "mciSendStringA" _(ByVal lpstrCommand As String, _ByVal lpstrReturnString As String, _ByVal uReturnLength As Long, _ByVal hwndCallback As Long) As Long

Using for opening:

Call mciSendString("Set CDAudio Door Open Wait", 0&, 0&, 0&)

Using to close:

Call mciSendString("Set CDAudio Door Closed Wait", 0&, 0&, 0&)

Third function will show/hide your taskbar
Declare Function SetWindowPos Lib "user32" (ByVal hwnd _As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal _wFlags As Long) As LongDeclare Function FindWindow Lib "user32" Alias _"FindWindowA" (ByVal lpClassName As String, ByVal _lpWindowName As String) As LongConst SWP_HIDEWINDOW = &H80Const SWP_SHOWWINDOW = &H40

Using for showing:
Dim Thwnd as LongThwnd = FindWindow("Shell_traywnd", "")Call SetWindowPos(Thwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)

Using foor hiding:
Dim Thwnd as LongThwnd = FindWindow("Shell_traywnd", "")Call SetWindowPos(Thwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)

And last function will set new screen resolution:
Public Const DM_BITSPERPEL = &H40000Public Const DM_PELSWIDTH = &H80000Public Const DM_PELSHEIGHT = &H100000Public Const CCHDEVICENAME = 32Public Const CCHFORMNAME = 32Type DEVMODE  dmDeviceName As String * CCHDEVICENAME  dmSpecVersion As Integer  dmDriverVersion As Integer  dmSize As Integer  dmDriverExtra As Integer  dmFields As Long  dmOrientation As Integer  dmPaperSize As Integer  dmPaperLength As Integer  dmPaperWidth As Integer  dmScale As Integer  dmCopies As Integer  dmDefaultSource As Integer  dmPrintQuality As Integer  dmColor As Integer  dmDuplex As Integer  dmYResolution As Integer  dmTTOption As Integer  dmCollate As Integer  dmFormName As String * CCHFORMNAME  dmUnusedPadding As Integer  dmBitsPerPel As Integer  dmPelsWidth As Long  dmPelsHeight As Long  dmDisplayFlags As Long  dmDisplayFrequency As LongEnd TypeDeclare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As DEVMODE, ByVal dwFalgs As Long) As LongPublic Sub SetVideoMode(Width As Long, height As Long, Depth As Long)  Dim dm As DEVMODE  dm.dmPelsWidth = Width  dm.dmPelsHeight = height  dm.dmBitsPerPel = Depth  dm.dmSize = Len(dm)  dm.dmFields = DM_PELSWIDTH + DM_PELSHEIGHT + DM_BITSPERPEL  ChangeDisplaySettings dm, 0End Sub

Using:
SetVideoMode 1024, 768, 8

It's my favorite WinApi functions... and you?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.