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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How do I cast a LPARAM?

How do I cast a LPARAM?

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 4 Posters 1 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.
  • B Offline
    B Offline
    bbranded
    wrote on last edited by
    #1

    Hello, I'm stuck on a problem casting an LPARAM. I'm attempting to broadcast a message to all window handles using:

    SendMessageTimeout(
    HWND_BROADCAST,
    WM_SETTINGCHANGE,
    SPI_SETNONCLIENTMETRICS,
    (LPARAM)"WindowMetrics",
    SMTO_NORMAL|SMTO_ABORTIFHUNG,
    10000, NULL);

    But the cast (LPARAM) does not seem to work. {I think that's call a cast) Can anyone help me write the (LPARAM)"WindowMetrics" attribute properly? Thanks, Matt Brown

    L E 2 Replies Last reply
    0
    • B bbranded

      Hello, I'm stuck on a problem casting an LPARAM. I'm attempting to broadcast a message to all window handles using:

      SendMessageTimeout(
      HWND_BROADCAST,
      WM_SETTINGCHANGE,
      SPI_SETNONCLIENTMETRICS,
      (LPARAM)"WindowMetrics",
      SMTO_NORMAL|SMTO_ABORTIFHUNG,
      10000, NULL);

      But the cast (LPARAM) does not seem to work. {I think that's call a cast) Can anyone help me write the (LPARAM)"WindowMetrics" attribute properly? Thanks, Matt Brown

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Hey Matt, you posted this in the C# forum but there is no indication in your post that you are using C# so can you verify you are using C#?

      bbranded wrote:

      But the cast (LPARAM) does not seem to work.

      On what are you basing that statement?

      bbranded wrote:

      Can anyone help me write the (LPARAM)"WindowMetrics" attribute properly?

      Those are called function "parameters" not "attributes".

      B 1 Reply Last reply
      0
      • L led mike

        Hey Matt, you posted this in the C# forum but there is no indication in your post that you are using C# so can you verify you are using C#?

        bbranded wrote:

        But the cast (LPARAM) does not seem to work.

        On what are you basing that statement?

        bbranded wrote:

        Can anyone help me write the (LPARAM)"WindowMetrics" attribute properly?

        Those are called function "parameters" not "attributes".

        B Offline
        B Offline
        bbranded
        wrote on last edited by
        #3
        1. Since I posted in the c# forum, assume I'm using C# 2) I'm not sure I'm using the right terminology by using the word "cast." I tried it, it's not working. 3) Great. I'm trying to refresh the desktop icon cache and found this page[^] (see "Flushing Cache Entries"). This is[^] what I'm working on doing at this moment. I have hopes it will work. [FYI: this[^] works fine]

        private static extern long SendMessageTimeout(
        int hWnd,
        int Msg,
        int wParam,
        string lParam,
        int fuFlags,
        int uTimeout,
        out int lpdwResult
        );

        RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
        k.SetValue("Shell Icon Size", "33");
        k.Flush(); k.Close();

        int res = 0;
        SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

        k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
        k.SetValue("Shell Icon Size", "32");
        k.Flush(); k.Close();

        SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

        I believe the common misconception with this strategy of icon cache clearing is that all of the icons move to the left side, to their "default" position (as if you click on the "align icons by name" verb in the progman context menu, etc). However, it is notable that this is only the case when (like TweakUI) you originally resize the icons to a very low number (let's say 4), causing their "foot print" to be very small (but in the same "positions" as you were before (like zooming out on a picture), before calling WM_SETTINGCHANGE. Therefore, when you resize them again (let's say to 32), then call WM_SETTINGCHANGE; all of your icons will assume this size and "force each other out of the way," and they will now appear to be aligned on the left side of the screen. That's why it's suggested in both the Microsoft KB, and in various other sources, to resize the icon size value one lesser than or one greater than you current size. Hope that's clear. :l

        D L 2 Replies Last reply
        0
        • B bbranded

          Hello, I'm stuck on a problem casting an LPARAM. I'm attempting to broadcast a message to all window handles using:

          SendMessageTimeout(
          HWND_BROADCAST,
          WM_SETTINGCHANGE,
          SPI_SETNONCLIENTMETRICS,
          (LPARAM)"WindowMetrics",
          SMTO_NORMAL|SMTO_ABORTIFHUNG,
          10000, NULL);

          But the cast (LPARAM) does not seem to work. {I think that's call a cast) Can anyone help me write the (LPARAM)"WindowMetrics" attribute properly? Thanks, Matt Brown

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          I've not used these stuff before except processing messages. However, I think you should convert the string to char[] and set it fixed then pass a pointer in the LParam.

          Eslam Afifi

          1 Reply Last reply
          0
          • B bbranded
            1. Since I posted in the c# forum, assume I'm using C# 2) I'm not sure I'm using the right terminology by using the word "cast." I tried it, it's not working. 3) Great. I'm trying to refresh the desktop icon cache and found this page[^] (see "Flushing Cache Entries"). This is[^] what I'm working on doing at this moment. I have hopes it will work. [FYI: this[^] works fine]

            private static extern long SendMessageTimeout(
            int hWnd,
            int Msg,
            int wParam,
            string lParam,
            int fuFlags,
            int uTimeout,
            out int lpdwResult
            );

            RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
            k.SetValue("Shell Icon Size", "33");
            k.Flush(); k.Close();

            int res = 0;
            SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

            k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
            k.SetValue("Shell Icon Size", "32");
            k.Flush(); k.Close();

            SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

            I believe the common misconception with this strategy of icon cache clearing is that all of the icons move to the left side, to their "default" position (as if you click on the "align icons by name" verb in the progman context menu, etc). However, it is notable that this is only the case when (like TweakUI) you originally resize the icons to a very low number (let's say 4), causing their "foot print" to be very small (but in the same "positions" as you were before (like zooming out on a picture), before calling WM_SETTINGCHANGE. Therefore, when you resize them again (let's say to 32), then call WM_SETTINGCHANGE; all of your icons will assume this size and "force each other out of the way," and they will now appear to be aligned on the left side of the screen. That's why it's suggested in both the Microsoft KB, and in various other sources, to resize the icon size value one lesser than or one greater than you current size. Hope that's clear. :l

            D Offline
            D Offline
            Dan Neely
            wrote on last edited by
            #5

            You'd be surprised and appalled at how often people new to the forums post here instead of the c++ forum, and what you were doing could just as easily be c++. Like it or not, sanity checks are inevitable.

            Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

            1 Reply Last reply
            0
            • B bbranded
              1. Since I posted in the c# forum, assume I'm using C# 2) I'm not sure I'm using the right terminology by using the word "cast." I tried it, it's not working. 3) Great. I'm trying to refresh the desktop icon cache and found this page[^] (see "Flushing Cache Entries"). This is[^] what I'm working on doing at this moment. I have hopes it will work. [FYI: this[^] works fine]

              private static extern long SendMessageTimeout(
              int hWnd,
              int Msg,
              int wParam,
              string lParam,
              int fuFlags,
              int uTimeout,
              out int lpdwResult
              );

              RegistryKey k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
              k.SetValue("Shell Icon Size", "33");
              k.Flush(); k.Close();

              int res = 0;
              SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

              k = Registry.CurrentUser.OpenSubKey("Control Panel").OpenSubKey("Desktop").OpenSubKey("WindowMetrics", true);
              k.SetValue("Shell Icon Size", "32");
              k.Flush(); k.Close();

              SendMessageTimeout(0xffff, 0x001A, 0, "", 0x0002, 5000, out res);

              I believe the common misconception with this strategy of icon cache clearing is that all of the icons move to the left side, to their "default" position (as if you click on the "align icons by name" verb in the progman context menu, etc). However, it is notable that this is only the case when (like TweakUI) you originally resize the icons to a very low number (let's say 4), causing their "foot print" to be very small (but in the same "positions" as you were before (like zooming out on a picture), before calling WM_SETTINGCHANGE. Therefore, when you resize them again (let's say to 32), then call WM_SETTINGCHANGE; all of your icons will assume this size and "force each other out of the way," and they will now appear to be aligned on the left side of the screen. That's why it's suggested in both the Microsoft KB, and in various other sources, to resize the icon size value one lesser than or one greater than you current size. Hope that's clear. :l

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              Nice reply. As Dan points out, it is rare and a pleasure when someone posts as clear and complete as you have been. :beer: What I believe you are struggling with is managed versus native memory issues. Some managed types match native types but strings are not one of them ( because they are pointers to memory) and require marshaling. Check out this article[^] it should get you started down the path to your solution.

              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