For some reason GetStockObject() is not defined. You need to add the following lines to windows.h
void * GetStockObject(int value);
If that does not work then replace this line
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH) with
wincl.hbrBackground = NULL; and the window should turn transparent.
Here is some code that partially accomplishes what you want.
It does lock the icons on the desktop, although you will not
be able to click on them(A nasty trick you could play on someone ).
Press the 'Arrange Icons' button to lock the desktop icons.
To reenable the desktop icons uncomment this line
EnableWindow(childOfChildWindow,TRUE);
in the 'void arrange()' function and recompile.
Here is the code:
#include <windows.h>
#include <Reason.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void arrange();
void noSaveSettings();
void restart();
HWND hwnd;
HWND hLeftArrangeButton;
HWND hDoNotSaveSettings;
#define WINDOWCLASSNAME "WindowsApp" /* Class Name */
#define WINDOWTITLE "Auto Arrange"
#define WINDOWWIDTH 640
#define WINDOWHEIGHT 480
#define BUTTONONETEXT "Arrange Icons"
#define BUTTONTWOTEXT "Add 'NoSaveSettingsKey'"
#define ERRORTITLE "Error!"
#define REGKEYNAME "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"
#ifndef SHTDN_REASON_MAJOR_OPERATINGSYSTEM
#define SHTDN_REASON_MAJOR_OPERATINGSYSTEM 0x00020000 //from reason.h
#endif
#ifndef SHTDN_REASON_MINOR_RECONFIG
#define SHTDN_REASON_MINOR_RECONFIG 0x00000004 //from reason.h
#endif
#ifndef SHTDN_REASON_FLAG_PLANNED
#define SHTDN_REASON_FLAG_PLANNED 0x80000000 //from reason.h
#endif
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = WINDOWCLASSNAME;
wincl.lpfnWndProc = WndProc;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = NULL;
if(!RegisterClassEx(&wincl))
{
MessageBox(NULL, "Window Registration Failed!", ERRORTITLE,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
0,
WINDOWCLASSNAME,
WINDOWTITLE,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
WINDOWWIDTH,
WINDOWHEIGHT,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
hLeftArrangeButton = CreateWindow("BUTTON", BUTTONONETEXT, WS_CHILD | WS_VISIBLE | BS_TEXT,
20, 80, 240, 30, hwnd, NULL, hThisInstance, NULL);
hDoNotSaveSettings = CreateWindow("BUTTON", BUTTONTWOTEXT, WS_CHILD | WS_VISIBLE | BS_TEXT,
20, 120, 240, 30, hwnd, NULL, hThisInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", ERRORTITLE,
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nFunsterStil);
UpdateWindow(hwnd);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
void arrange()
{
const int arrange = 4118;
const int leftAlign = 1;
HWND desktopHandle;
HWND childWindow;
HWND childOfChildWindow;
desktopHandle = FindWindow("Progman", NULL);
childWindow = GetWindow(desktopHandle, GW_CHILD);
childOfChildWindow = GetWindow(childWindow, GW_CHILD);
SendMessage(childOfChildWindow, arrange, leftAlign, 0);
EnableWindow(childOfChildWindow,FALSE);
}
void noSaveSettings()
{
HKEY hk;
DWORD dwDisposition;
DWORD value = 1;
if (RegCreateKeyEx(HKEY_CURRENT_USER, REGKEYNAME,
0, NULL, REG_OPTION_NON_VOLATILE,KEY_WRITE, NULL, &hk, &dwDisposition))
{
MessageBox(NULL,"Unable to create Explorer key",ERRORTITLE,MB_OK);
}
if (RegSetValueEx(hk,"NoSaveSettings",0, REG_DWORD, (LPBYTE) &value, sizeof(DWORD)))
{
MessageBox(NULL,"Unable to add NoSaveSettings",ERRORTITLE,MB_OK);
RegCloseKey(hk);
}
RegCloseKey(hk);
}
void restart()
{
HANDLE tokenHandle;
TOKEN_PRIVILEGES theTokenPrivilege;
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tokenHandle))
{
MessageBox(NULL,"Could not obtain a token",ERRORTITLE,MB_OK);
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &theTokenPrivilege.Privileges[0].Luid);
theTokenPrivilege.PrivilegeCount = 1;
theTokenPrivilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(tokenHandle, FALSE, &theTokenPrivilege, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
MessageBox(NULL,"Unable to restart the computer",ERRORTITLE,MB_OK);
return;
}
if (!ExitWindowsEx(EWX_REBOOT | EWX_FORCE, SHTDN_REASON_MAJOR_OPERATINGSYSTEM |
SHTDN_REASON_MINOR_RECONFIG | SHTDN_REASON_FLAG_PLANNED))
{
MessageBox(NULL,"Unable to restart the computer",ERRORTITLE,MB_OK);
return;
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
HWND hwndCtl = (HWND)lParam;
int code = HIWORD(wParam);
if (hwndCtl == hLeftArrangeButton)
{
arrange();
}
if (hwndCtl == hDoNotSaveSettings)
{
noSaveSettings();
restart();
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
|