Jump to content
astrionn

DllCall, user32&uxtheme and colorchanging tooltips

Recommended Posts

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:

Quote

;2550255 yellow
;00255 red
;0255255 green
;000 black

 

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.

https://pastebin.com/q525f7mS

Edited by astrionn
added OS

Share this post


Link to post
Share on other sites

The calls are fine, your real problem is how you are evaluating each if statement. You can't do "1 <= $ping < 250" in AutoIt. This is how it should be done:

HotKeySet("{ESC}","close")

pingpong()

Func pingpong()
   While True
      $ping=ping("8.8.8.8",3000)
      $s = string($ping)

      If $ping = 0 Then
         ToolTip("N/A",0,0)
         $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", 000, "int", 0)
      ElseIf $ping >= 1 And $ping < 250 Then
         ToolTip($s&" ms",0,0)
         $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", 0255255, "int", 0)
      ElseIf $ping >= 250 And $ping < 750 Then
         ToolTip($s&" ms",0,0)
         $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", 2550255, "int", 0)
      ElseIf $ping >= 750 Then
         ToolTip($s&" ms",0,0)
         $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", 00255, "int", 0)
      EndIf
      Sleep(500)
   WEnd
EndFunc

Func close()
    Exit
EndFunc

 


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

Nice job, but this code creates a new Tooltip at every ping, and changes it color - even if nothing changed.

Is it possible to update the Tooltip text/title with a DLLCall too?

Share this post


Link to post
Share on other sites

There is a ToolTip UDF included with AutoIt, look in the help file for the _GUIToolTip* functions.


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

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

  • Similar Content

    • By supersonic
      Hi -
      Currently I'm playing around with Windows Credential Manager. I'm trying to access it with DllCall("advapi32.dll", ...) using the functions 'CredWriteW', 'CredReadW' and 'CredDeleteW'. All well. Another function I have to deal with is 'CredEnumerateW': https://docs.microsoft.com/en-us/windows/desktop/api/wincred/nf-wincred-credenumeratew/ .
      That's the test code I have so far:
      #include <Array.au3> #include <String.au3> Local $tCredentialsCount = DllStructCreate("DWORD;") Local $tPointerToArrayOfPointers = DllStructCreate("PTR;") ; Local $tPointerToArrayOfPointers = DllStructCreate(_StringRepeat("PTR;", 200)) ; ??? Local $aResult = DllCall("advapi32.dll", "BOOL", "CredEnumerateW", _ "WSTR", Null, "DWORD", 1, "DWORD", DllStructGetPtr($tCredentialsCount), "PTR", DllStructGetPtr($tPointerToArrayOfPointers)) If (Not @error) Then Local $iCredentialsCount = DllStructGetData($tCredentialsCount, 1) _ArrayDisplay($aResult, $iCredentialsCount) Local $hPointerToArrayOfPointers = DllStructGetData($tPointerToArrayOfPointers, 1) MsgBox(0, "$hPointerToArrayOfPointers", $hPointerToArrayOfPointers) ; Fails... For $i = 1 To 10 ; $iCredentialsCount MsgBox(0, $i & "___" & (($i * 2) - 1), DllStructGetData($tPointerToArrayOfPointers, ($i * 2) - 1)) Next $tCredentialsCount = 0 $tPointerToArrayOfPointers = 0 DllCall("advapi32.dll", "NONE", "CredFreeW", "PTR", $hPointerToArrayOfPointers) EndIf The DllCall seems to function properly - I get a valid count of credentials (on my computer ~ 133) and a pointer "to array of pointers".
      What is meant by "array of pointers"?
      Microsoft says: Pointer to an array of pointers to credentials. The returned credential is a single allocated block. Any pointers contained within the buffer are pointers to locations within this single allocated block.
      How to access these pointers... Contained within the buffer???
      Any information you can provide me would be greatly appreciated.
    • By bladem2003
      Hello,
      i need help to translate the c code to autoit .
      I don't understand the callback function.
       
      #include <windows.h> #include <stdio.h> // native IR Data by PAnsiChar typedef void CALLBACK CallBackPAnsiChar(char*, char*, char*, char*); typedef int (__stdcall *impInitPAnsiChar)(CallBackPAnsiChar); CALLBACK MyCallBackPAnsiChar(char* Protocol, char* Address, char* Command, char* Flags) { printf("\nIR Data received: Protocol: %s, Address: 0x%s, Command: 0x%s, Flags: 0x%s", Protocol, Address, Command, Flags); fflush(stdout); } int main(int argc, char **argv) { impInitPAnsiChar InitPAnsiChar = NULL; // Load DLL file HINSTANCE hinstLib = LoadLibrary(TEXT("USB_IR_Remote_Receiver.dll")); if (hinstLib == NULL) { printf("\nERROR: unable to load DLL\n"); return 1; } // Get function pointer InitPAnsiChar InitPAnsiChar = (impInitPAnsiChar)GetProcAddress(hinstLib, "InitPAnsiChar"); if (InitPAnsiChar == NULL) { printf("\nERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); return 1; } if (InitPAnsiChar(*MyCallBackPAnsiChar)) { printf("\nInit DLL with InitPAnsiChar successfull"); } else { // Unload DLL file FreeLibrary(hinstLib); return 0; } while(1) { } //return 0; }  
    • 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 Yirrlaar
      Hello All,
      I'm using "ImageSearch2015.au3" and i'm trying to figure out WHY, for the life of me, I can't find an image is hidden.
      So what I came up with, is as follows:
      _ImageSearchAreaHidden("C:\icon.png", 1, 0, 0, 800, 600, $x1, $y1, 80, 0) Func _ImageSearchAreaHidden($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $transparency = 0) Local $h, $result local $TestScreen = "C:\TestScreen.png" ;previsous screenshot of the image looking for, fully visible If Not FileExists($findImage) Then Return "Image File not found" If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0 If $h_ImageSearchDLL = -1 Then _ImageSearchStartup() If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall($h_ImageSearchDLL, "str", "ImageSearchEx", "str", $TestScreen, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) If @error Then Return "DllCall Error=" & @error If $result = "0" Then Return False $array = StringSplit($result[0], "|") If (UBound($array) >= 4) Then $x = Int(Number($array[2])) ; Get the x,y location of the match $y = Int(Number($array[3])) If $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) ; Account for the size of the image to compute the centre of search $y = $y + Int(Number($array[5]) / 2) EndIf Return True EndIf EndFunc ;==>_ImageSearchAreaHidden Now when the folder with the icon is completely visible, it finds the icon without any issues, however if I cover up the icon, it no longer finds the image in the folder.
      Any ideas?
    • 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...