How to write C or C++ program that locks desktop icons placement?
-
How to write C or C++ program that locks desktop icons placement? I have googled around it and all I found were commercial software or closed source software. Any hints are welcome. thanks!
The following answer makes the assumption that you are using windows XP/vista/7. The following website should help: http://www.activewin.com/tips/reg/desktop_3.shtml[^] If you follow the instructions it locks the desktop icon(s); although it is still possible to rearrange them. To accomplish this in a windows application you will need to use the registry api's(use the 'RegCreate' function(s)) here http://msdn.microsoft.com/en-us/library/aa383729%28VS.85%29.aspx[^] to create a registry key. I tested this on xp and realised that I had auto arrange on, after turning this off it is no longer working. I am now looking for the registry key for auto arrange. I have code in c/c++ that can change the alignment of desktop icons on the (e.g. left align icons), I will post this if you want it.
My blog:[^]
modified on Sunday, January 10, 2010 10:05 PM
-
The following answer makes the assumption that you are using windows XP/vista/7. The following website should help: http://www.activewin.com/tips/reg/desktop_3.shtml[^] If you follow the instructions it locks the desktop icon(s); although it is still possible to rearrange them. To accomplish this in a windows application you will need to use the registry api's(use the 'RegCreate' function(s)) here http://msdn.microsoft.com/en-us/library/aa383729%28VS.85%29.aspx[^] to create a registry key. I tested this on xp and realised that I had auto arrange on, after turning this off it is no longer working. I am now looking for the registry key for auto arrange. I have code in c/c++ that can change the alignment of desktop icons on the (e.g. left align icons), I will post this if you want it.
My blog:[^]
modified on Sunday, January 10, 2010 10:05 PM
The instructions from the website http://www.activewin.com/tips/reg/desktop_3.shtml[^][^] are now working(make sure you restart/logoff or it will not work, as I found). Here is the code for a working program that accomplishes the following: 1. Left Align icons on the screen(test this by moving desktop icon(s) to a different part of the screen and then press the 'Arrange Icons' button in the compiled app) 2. Lock icons on the desktop so that they can only be rearranged. The application accomplishes this be creating the NoSaveSettings key as mentioned in the above given website(this sets the Auto Arrange to on after the system has been shutdown/restart/user logged off). 3. Restart the computer. CAUTION before pressing the Add 'NoSaveSettingsKey' button save all of your work as it will restart the computer. You have been warned, use the code at your own risk. Here is the code:
#include <windows.h>
#include <Reason.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Declare Windows procedure */
// Forward function(s) declarations
void arrange();
void noSaveSettings();
void restart();// Handles
//The main window handle
HWND hwnd;HWND hLeftArrangeButton; //Handle to the Arrange button
HWND hDoNotSaveSettings; // Handle to the NoSaveSettings button// definitions
#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
#endifint WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil){
MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszCl
-
The instructions from the website http://www.activewin.com/tips/reg/desktop_3.shtml[^][^] are now working(make sure you restart/logoff or it will not work, as I found). Here is the code for a working program that accomplishes the following: 1. Left Align icons on the screen(test this by moving desktop icon(s) to a different part of the screen and then press the 'Arrange Icons' button in the compiled app) 2. Lock icons on the desktop so that they can only be rearranged. The application accomplishes this be creating the NoSaveSettings key as mentioned in the above given website(this sets the Auto Arrange to on after the system has been shutdown/restart/user logged off). 3. Restart the computer. CAUTION before pressing the Add 'NoSaveSettingsKey' button save all of your work as it will restart the computer. You have been warned, use the code at your own risk. Here is the code:
#include <windows.h>
#include <Reason.h>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* Declare Windows procedure */
// Forward function(s) declarations
void arrange();
void noSaveSettings();
void restart();// Handles
//The main window handle
HWND hwnd;HWND hLeftArrangeButton; //Handle to the Arrange button
HWND hDoNotSaveSettings; // Handle to the NoSaveSettings button// definitions
#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
#endifint WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil){
MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszCl
Great code, but I have 1 problem (I used Code::Blocks to compile) C:\Documents and Settings\rain\My Documents\fail.o:fail.cpp:(.text+0x96)||undefined reference to `_GetStockObject@4'| ||=== Build finished: 1 errors, 0 warnings ===| I tried this manually but it didn't work (I use win xp pro). Is there any solutions that works like lockig icons works in linux? I have seen linux desktops which are made so if you lock icons then u cant move them, icons just won't come with ur mouse, can I do this kond locking in windows too?
-
Great code, but I have 1 problem (I used Code::Blocks to compile) C:\Documents and Settings\rain\My Documents\fail.o:fail.cpp:(.text+0x96)||undefined reference to `_GetStockObject@4'| ||=== Build finished: 1 errors, 0 warnings ===| I tried this manually but it didn't work (I use win xp pro). Is there any solutions that works like lockig icons works in linux? I have seen linux desktops which are made so if you lock icons then u cant move them, icons just won't come with ur mouse, can I do this kond locking in windows too?
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 :-D ). 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); /* Declare Windows procedure */
// Forward function(s) declarations
void arrange();
void noSaveSettings();
void restart();// Handles
//The main window handle
HWND hwnd;HWND hLeftArrangeButton; //Handle to the Arrange button
HWND hDoNotSaveSettings; // Handle to the NoSaveSettings button// definitions
#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
#endifint 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; win
-
How to write C or C++ program that locks desktop icons placement? I have googled around it and all I found were commercial software or closed source software. Any hints are welcome. thanks!