Jump to content
Sign in to follow this  
Kovacic

Trouble making a decent color border around screen

Recommended Posts

Hello all.. I am working on a client server application, and part of the client application is to create color borders on the screen, while the script is performing various tasks. So far, I am using the following method:

#include <WinAPI.au3>

Border(0xFFFF00)

sleep(10000)

func border($color)
_WinAPI_DrawRect(0,0, @DesktopWidth, @DesktopHeight, $color)
_WinAPI_DrawRect(1,1, @DesktopWidth -1, @DesktopHeight -1, $color)
_WinAPI_DrawRect(2,2, @DesktopWidth -2, @DesktopHeight -2, $color)
_WinAPI_DrawRect(3,3, @DesktopWidth -3, @DesktopHeight -3, $color)
endfunc



Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor)
    Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, 1, $start_x)
    DllStructSetData($tRect, 2, $start_y)
    DllStructSetData($tRect, 3, $iWidth)
    DllStructSetData($tRect, 4, $iHeight)
    Local $hBrush = _WinAPI_CreateSolidBrush($iColor)
    _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush)
    ; clear resources
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC(0, $hDC)
EndFunc   ;==>_WinAPI_DrawRect

The above code should turn your screen border yellow (0xFFFF00) for about 10 seconds..  

The first issue is, it doesn't turn yellow, it turns Cyan...

The second problem is, Windows redraws the screen frequently, so if anything is drawn over the border, it goes away, unless I either AdlibRegister to call the draw every few seconds, OR just have it call during the while loop.

Is there a simple way I can create a good screen border, maybe as a transparent GUI that still lets users click on areas of the screen without the gui being in the way? Or is there a simple method to make that border on the screen (which will change color depending on the current state of the script) that is not effected by the windows screen redraw?

thanks in advance!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Try using the color in BGR (0x00FFFF) format instead of RGB (0xFFFF00)


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You can try this (2 other methods):

 

#include <WinAPI.au3>
#include <WindowsConstants.au3>

$h1 = Border1(0xFFFF00)
Sleep(5000)
GUIDelete($h1)
$h2 = Border2(0xFF0000)
Sleep(5000)
GUIDelete($h2)

Func border1($color, $iSize = 4, $iX = 0, $iY = 0, $iW = @DesktopWidth, $iH = @DesktopHeight) ;coded by UEZ 2014
    Local $hGUI = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_APPWINDOW))
    Local $iLabel_bg = GUICtrlCreateLabel("", 0, 0, $iW, $iH)
    GUICtrlSetBkColor(-1, $color)
    Local $iLabel_fg = GUICtrlCreateLabel("", $iSize, $iSize, $iW - 2 * $iSize, $iH - 2 * $iSize)
    GUICtrlSetBkColor(-1, 0x010101)
    GUISetBkColor(0x010101)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0x010101, 255)
    GUISetState(@SW_SHOWNA)
    Return $hGUI
EndFunc

Func border2($color, $iSize = 4, $iX = 0, $iY = 0, $iW = @DesktopWidth, $iH = @DesktopHeight) ;coded by UEZ 2014
    Local $hGUI = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_APPWINDOW))
    Local $iLabel = GUICtrlCreateLabel("", 0, 0, $iW, $iH)
    GUICtrlSetBkColor(-1, $color)
    Local $hRegion1 = _WinAPI_CreateRectRgn(0, 0, $iW, $iH)
    Local $hRegion2 = _WinAPI_CreateRectRgn($iSize, $iSize, $iW - $iSize, $iH - $iSize)
    Local $hRegion = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($hRegion, $hRegion1, $hRegion2, $RGN_DIFF)
    _WinAPI_DeleteObject($hRegion1)
    _WinAPI_DeleteObject($hRegion2)
    _WinAPI_SetWindowRgn($hGUI, $hRegion)
    GUISetState(@SW_SHOWNA)
    Return $hGUI
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • By DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By user4157124
      ConsoleWrite('>Message here.' & @CRLF) outputs colored text (per + > - ! characters).
      ConsoleWrite('warning' & @TAB & '38' & @TAB & 'more text ...' & @CRLF) enables jump to line 38 on doubleclick.

      Using "jump to line" format, only red and pink text coloring seems possible (simply prefixing color directives to output-text disables jump to line functionality). Is it possible to combine the two (define custom color while keeping "jump to line" functionality)?
    • By Miliardsto
      I have the following code. You can see there are $color_normal and $color_trans
      In my case normal is too dark . And color trans is to much violet.
      If you run it you will see how its looks. I want gui with listView have the same color like taskbar in windows 10.
      How to achieve that?
       
       
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> HotKeySet("{ESC}", "Terminate") $color_normal = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) $color_trans = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) $trans = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") ConsoleWrite("Transpart = " & $trans & @CRLF) ConsoleWrite("Color normal = " & $color_normal & @CRLF) ConsoleWrite("Color trans = " & $color_trans & @CRLF) ConsoleWrite(_Get_taskbar_color()); It return AARRGGBB $taskbarColor = _Get_taskbar_color() Global $gui = GUICreate("Test", 150, 58,@DesktopWidth-300,@DesktopHeight-58,$WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) Global $idListview = GUICtrlCreateListView("", 0, 0, 150, 58,BitOR($LBS_NOTIFY,$LBS_SORT), 0) ;_GuiCtrlMakeTrans(-1,100) ; Add column _GUICtrlListView_AddColumn($idListview, "Msgs", 100) GUICtrlSetFont(-1, 7, 400, 0, "Segoe UI") GUICtrlSetColor(-1, 0x470C4F) GUICtrlSetBkColor($idListview, 0x310638) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Terminate() Exit EndFunc Func _Get_taskbar_color() If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "ColorPrevalence") Then If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) Else Return "0xFF" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) EndIf Else If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9000000" Else Return "0xFF000000" EndIf EndIf EndFunc  
    • By dejhost
      Happy New Year everyone!
      I would like to extract the color values of certain pixels in an image.  This is how I picture the workflow: 
      User opens an image of his choice. Image is shown on the screen. User draws a line into the image. This happens by marking the startpixel and the endpixel of the line The line is drawn, so the user can check visually if he is happy with the line.  The following pixel based properties belonging to the line are stored in Excel: X-Coordinate Y-Coordinate Color Value Additional operations: Extracting for max- and min. color values; Statistical operations.   Browsing through the helpfile of AutoIt I find plenty of functions for treating images (e.g. GDIPlus), but I am completely unsure if Autoit will get me there. Should I read the entire image into an array? Should I rather attempt to script an external image software (e.g. IrfanView, Gimp)?
      I would be very thankful if someone could give some recommendations and maybe list a couple of the most important commands to use.
      Thank you very much.
      Dejhost
       
       
    • By Skeletor
      Hi All,
      While creating a few excel spreadsheets using AutoIt, I came across something which to my limiting time to research the forums I don't anyone has mentioned. 
      The color pallettes are reversed. 
      Huge shock to me.
       
      I wanted to produce a red row but kept on getting blue. 
      Seems like 0xFF0000 was red on the charts but when running the script, I got blue. 
      I then played around with the colors, and after a few tries, I finally got Red. 
      Reversed the FF0000 and the result is 0000FF.
       
      So for Excel compared to Html
      0000FF (Red) - Excel
      0000FF (Blue) - Html

      FFFF00 (Cyan) - Excel
      FFFF00(Yellow) - Html
       
×
×
  • Create New...