Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to write C or C++ program that locks desktop icons placement?

How to write C or C++ program that locks desktop icons placement?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rain 13
    wrote on last edited by
    #1

    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!

    A R 2 Replies Last reply
    0
    • R rain 13

      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!

      A Offline
      A Offline
      A
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • A A

        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

        A Offline
        A Offline
        A
        wrote on last edited by
        #3

        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
        #endif

        int WINAPI WinMain(HINSTANCE hThisInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpszArgument,
        int nFunsterStil)

        {

        MSG messages;            
        WNDCLASSEX wincl;        
        
        wincl.hInstance = hThisInstance;
        wincl.lpszCl
        
        R 1 Reply Last reply
        0
        • A A

          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
          #endif

          int WINAPI WinMain(HINSTANCE hThisInstance,
          HINSTANCE hPrevInstance,
          LPSTR lpszArgument,
          int nFunsterStil)

          {

          MSG messages;            
          WNDCLASSEX wincl;        
          
          wincl.hInstance = hThisInstance;
          wincl.lpszCl
          
          R Offline
          R Offline
          rain 13
          wrote on last edited by
          #4

          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?

          A 1 Reply Last reply
          0
          • R rain 13

            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?

            A Offline
            A Offline
            A
            wrote on last edited by
            #5

            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
            #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;
            win
            
            1 Reply Last reply
            0
            • R rain 13

              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!

              R Offline
              R Offline
              Rolf Kristensen
              wrote on last edited by
              #6

              No, you can't lock icons to the user's desktop[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups