Sign in to follow this  
Followers 0

Trouble making a decent color border around screen

4 posts in this topic

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>



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)

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_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)

1 person likes this

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

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

That worked Thanks!!

 That and also using just 0xFFFF


Still having issues with the redraw idea, but I might just go with what I got..

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post

Link to post
Share on other sites

#4 ·  Posted (edited)

You can try this (2 other methods):


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

$h1 = Border1(0xFFFF00)
$h2 = Border2(0xFF0000)

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)
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0x010101, 255)
    Return $hGUI

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_SetWindowRgn($hGUI, $hRegion)
    Return $hGUI



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

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  
Followers 0

  • Similar Content

    • astrionn
      By astrionn
      So I had this Idea of creating a tooltip which shows me my ping.
      That itself was made quickly and I thought too add a couple features.
      I want the tooltip background to be a different color depending on the ping. (good ping is green, medium ping is yellow,...)
      So how do I color in a tooltip? google brought me to this: 
      where in the comments I found this:
      $s = "LOW" ToolTip($s, 0, 0, "Battery Information");, $icon) $H_TOOLTIP1 = WinGetHandle($s) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $H_TOOLTIP1, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $H_TOOLTIP1, "int", 1043, "int", 2552550, "int", 0) Sleep(1000) Which I then used in my code with different color codes... Trial and Error brought me these that I wanted to use:
      The Problem is if I loop through my code it only sets the color for the 1st loop and then sticks to it.
      The real problem is tho that I don't exactly understand the dllcalls... And I guess that's why it isn't working
      So if someone would be so awesome to explain to me how they work, or at least can give me a list of these parameters then I would really appreciate that and learn something new
      Obviously a solution to my problem is awesome aswell ^^
      I run this under Windows 8.1
      There is my code in a paste.
    • cosmos
      By cosmos
      I must be missing something but I can't seem to work out how to open the standard Windows Color dialog box?
      Basically the equivalent of InputBox but for colors (so that the user can select a color). I think there are some external UDFs for this, but are there any ways of doing it with included UDFs, standard AutoIt functions or interfacing with Windows directly?
      Usage info: I'm making a database-like program and there are Categories (which work similar to Tables), and the user will be able to select unique colors for Categories so when they display multiple Categories at once (like displaying multiple Tables with similar columns in one list ) they can easily differentiate the Categories at quick glance.
    • chacoya121
      By chacoya121
      Local $count = 1 Local $x1= 100,$y1 = 100,$x2 = 110,$y2 = 110 $area = ($x2+$x1)*($y2+$y1) Local $array[$area][2] For $i = $x1 to $x2 Step 1 For $j = $y1 to $y2 Step 1 $color = PixelGetColor($i,$j) $scolor = Hex($color,6) $array[$count][2] = [$scolor,1] $position = _ArraySearch($array,$scolor,0,0,0,0,1) If $array[$position][0] = $scolor Then $array[$position][1] +=1 Else $count += 1 EndIf Next Next _ArrayDisplay($array) plz help adjust and shrink it down soo confusing playing with array
    • Miliardsto
      By Miliardsto
      Hello i have problem with function PixelGetColor. On my computer it working fine but in some cases it not working.
      And Im clicking on the active window on red color and it give me the same color still. But in other computers when clicking on the same color red it gives other values and returned color in MsgBox is not red.
      Dont know is it a real main thing what causing problem but,
      I noticed that problem was on one windows 10.
      I have windows 8 and working well. On other windows 10 works well to
      Maybe it is caused by windows aero or something like that
      How to deal with it?
      There is a code
      HotKeySet("{PAUSE}", "MouseCord") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func MouseCord() Global $MousePos = MouseGetPos() $clickedColor = PixelGetColor($MousePos[0], $MousePos[1]) MsgBox(0, "Done", $clickedColor) EndFunc  
    • litlmike
      By litlmike
      Hey there, I am trying to figure out how to fill an Excel row with a color, if some condition.  For example:
      $sColor = #FFF000 For $iCC = 1 To Ubound($aArray)-1 $sRange = "A:" & $iCC If _Excel_RangeReady($oWorkbook, $sRange) = "Some String" Then _Excel_FillInRowWithColor($iRowToFillIn, $sColor) Next  
      Anyone know how to do that?  Thanks!