Announcement

Collapse
No announcement yet.

Detect Main Display

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Detect Main Display

    Hello everyone.. i only learn from reading here and from samples given from users.

    Now i have found a sample to Detect 2 display using PablokoMonitor

    my question now is i have 2 monitors AOC in 1920x1080 and Acer in 1600x900
    how can the apps detect which the Main Display?



  • #2
    Never heard of it post the apz I am sure there will be a way to edit find monitor one if it finds monitor 2
    Plugins or Sources MokoX
    BunnyHop 2021 Here

    Comment


    • #3
      Code:
      local user32 = Library.Load("user32.dll");
      
      MONITOR_DEFAULTTONULL    = 0;
      MONITOR_DEFAULTTOPRIMARY = 1;
      MONITOR_DEFAULTTONEAREST = 2;
      
      RECT = MemoryEx.DefineStruct{
          DWORD         "left";
          DWORD        "top";
          DWORD        "right";
          DWORD        "bottom";
      };
      
      MONITORINFO = MemoryEx.DefineStruct{
          DWORD         "cbSize";
          RECT         "rcMonitor";
          RECT        "rcWork";
          DWORD        "dwFlags";    
      };
      
      function MonitorFromWindow(hWnd, dwFlags)
          return user32.MonitorFromWindow(hWnd, dwFlags);
      end
      
      function GetMonitorInfo(hMonitor)
          local info = MONITORINFO:New();
          if(not info)then
              error("memory allocation failure", 2);
          end 
          
          info.cbSize = info:Size();
          local result = user32.GetMonitorInfoA(hMonitor, info:GetPointer());
          if(result == 0)then
              info:Free();
              return nil;
          end
          
          return info;
      end
      
      function IsOnPrimaryMonitor(hWnd)
          local hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL);
          if(hMonitor == 0)then 
              return false;
          end 
          
          local info = GetMonitorInfo(hMonitor);
          if(info)then
              local result = info.rcMonitor.left == 0 and info.rcMonitor.top == 0;
          
              info:Free();
              
              return result;
          end 
          
          return false;
      end;
      Put that in Globals, call as IsOnPrimaryMonitor(Application.GetWndHandle()) from a button or On Show. Tell me if it works

      It uses the MemoryEx plugin (https://www.memoryex.net/mx.html)
      Bas Groothedde
      Imagine Programming :: Blog

      AMS8 Plugins
      IMXLH Compiler

      Comment


      • #4
        Post the next code in Globals:
        Code:
        local user32 = Library.Load("user32.dll");
        
        MONITOR_DEFAULTTONULL    = 0;
        MONITOR_DEFAULTTOPRIMARY = 1;
        MONITOR_DEFAULTTONEAREST = 2;
        
        RECT = MemoryEx.DefineStruct{
            DWORD         "left";
            DWORD        "top";
            DWORD        "right";
            DWORD        "bottom";
        };
        
        MONITORINFO = MemoryEx.DefineStruct{
            DWORD         "cbSize";
            RECT         "rcMonitor";
            RECT        "rcWork";
            DWORD        "dwFlags";    
        };
        
        function MonitorFromWindow(hWnd, dwFlags)
            return user32.MonitorFromWindow(hWnd, dwFlags);
        end
        
        function GetMonitorInfo(hMonitor)
            local info = MONITORINFO:New();
            if(not info)then
                error("memory allocation failure", 2);
            end 
            
            info.cbSize = info:Size();
            local result = user32.GetMonitorInfoA(hMonitor, info:GetPointer());
            if(result == 0)then
                info:Free();
                return nil;
            end
            
            return info;
        end
        
        function IsOnPrimaryMonitor(hWnd)
            local hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL);
            if(hMonitor == 0)then 
                return false;
            end 
            
            local info = GetMonitorInfo(hMonitor);
            if(info)then
                local result = info.rcMonitor.left == 0 and info.rcMonitor.top == 0;
            
                info:Free();
                
                return result;
            end 
            
            return false;
        end;
        Use in On Show or in a button, not in On Preload;
        Code:
        local mainMonitor = IsOnPrimaryMonitor(Application.GetWndHandle());
        It requires the MemoryEx Action Plugin to do the advanced stuff.
        Bas Groothedde
        Imagine Programming :: Blog

        AMS8 Plugins
        IMXLH Compiler

        Comment


        • #5
          Originally posted by telco View Post
          Hello everyone.. i only learn from reading here and from samples given from users.

          Now i have found a sample to Detect 2 display using PablokoMonitor

          my question now is i have 2 monitors AOC in 1920x1080 and Acer in 1600x900
          how can the apps detect which the Main Display?

          Post the next code in Globals:
          Code:
          local user32 = Library.Load("user32.dll");
          
          MONITOR_DEFAULTTONULL    = 0;
          MONITOR_DEFAULTTOPRIMARY = 1;
          MONITOR_DEFAULTTONEAREST = 2;
          
          RECT = MemoryEx.DefineStruct{
              DWORD         "left";
              DWORD        "top";
              DWORD        "right";
              DWORD        "bottom";
          };
          
          MONITORINFO = MemoryEx.DefineStruct{
              DWORD         "cbSize";
              RECT         "rcMonitor";
              RECT        "rcWork";
              DWORD        "dwFlags";    
          };
          
          function MonitorFromWindow(hWnd, dwFlags)
              return user32.MonitorFromWindow(hWnd, dwFlags);
          end
          
          function GetMonitorInfo(hMonitor)
              local info = MONITORINFO:New();
              if(not info)then
                  error("memory allocation failure", 2);
              end 
              
              info.cbSize = info:Size();
              local result = user32.GetMonitorInfoA(hMonitor, info:GetPointer());
              if(result == 0)then
                  info:Free();
                  return nil;
              end
              
              return info;
          end
          
          function IsOnPrimaryMonitor(hWnd)
              local hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL);
              if(hMonitor == 0)then 
                  return false;
              end 
              
              local info = GetMonitorInfo(hMonitor);
              if(info)then
                  local result = info.rcMonitor.left == 0 and info.rcMonitor.top == 0;
              
                  info:Free();
                  
                  return result;
              end 
              
              return false;
          end;
          Use in On Show or in a button, not in On Preload;
          Code:
          local mainMonitor = IsOnPrimaryMonitor(Application.GetWndHandle());
          It requires the MemoryEx Action Plugin to do the advanced stuff.
          Bas Groothedde
          Imagine Programming :: Blog

          AMS8 Plugins
          IMXLH Compiler

          Comment


          • #6
            I want to help you, but the IR forums tell me my reply is unapproved each time I post something....
            Bas Groothedde
            Imagine Programming :: Blog

            AMS8 Plugins
            IMXLH Compiler

            Comment


            • #7
              Let's try it like this (see the Globals Section for the reply I was going to post)
              Attached Files
              Bas Groothedde
              Imagine Programming :: Blog

              AMS8 Plugins
              IMXLH Compiler

              Comment


              • #8
                Thanks Imagine but i can find how to fix the error..

                Comment


                • #9
                  thanks imagine i restart the app.. and it works... thanks so much

                  Comment


                  • #10
                    Originally posted by telco View Post
                    thanks imagine i restart the app.. and it works... thanks so much
                    I'm glad that it works.
                    Bas Groothedde
                    Imagine Programming :: Blog

                    AMS8 Plugins
                    IMXLH Compiler

                    Comment


                    • #11
                      Hello imagine,, maybe there is wrong with my post.. detecting which is the main display is great but i realize this is not what i need to achieve...
                      what really in my mind is detecting which is the monitor 1 and which is the Monitor 2..

                      The the settings of windows on display there is a button identify and it shows on screen the number of each monitor.. can you help me on this?

                      example: Get the Monitor # and get the current resolutoion of the monitor..

                      Monitor 1, 1920x1080, location is Left , -1920, Top-0,
                      Monitor 2, 1366x768, location is, Right 1600, Top 0



                      Comment


                      • #12
                        Check this example, which lists all available monitors. It also shows you how you can determine the primary monitor in the list with code.

                        Read more about the rcMonitor and rcWork fields of the MONITORINFO structure here: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

                        Edit: Fixed a bug in the example code and added more verbose comments
                        Attached Files
                        Last edited by Imagine Programming; 09-26-2017, 06:40 AM.
                        Bas Groothedde
                        Imagine Programming :: Blog

                        AMS8 Plugins
                        IMXLH Compiler

                        Comment


                        • #13
                          Thanks for this imagine.. i will look unto it and study all the codes.. Thank you and God Bless

                          Comment


                          • #14
                            Hello imagine.. can i ask a little help? i know this is very very easy for you but for me i spend more than a day already finding solution ;(
                            here it is. i have found the scroll bar plugin here:

                            i want to make the label print the current pos of the scrollbar.
                            scrollbar.apz

                            Comment


                            • #15
                              Originally posted by telco View Post
                              Hello imagine.. can i ask a little help? i know this is very very easy for you but for me i spend more than a day already finding solution ;(
                              here it is. i have found the scroll bar plugin here:

                              i want to make the label print the current pos of the scrollbar.
                              [ATTACH]n298362[/ATTACH]
                              It's best that you start another thread for a question with a different subject. I also don't have that plugin, so I don't know what is happening.
                              Bas Groothedde
                              Imagine Programming :: Blog

                              AMS8 Plugins
                              IMXLH Compiler

                              Comment

                              Working...
                              X