WindowEx: setting the background color to transparent - user-interface

I'm using the following code:
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global Const $WC_LINK = "SysLink"
Global Const $WC_LINKA = $WC_LINK
Global Const $WC_LINKW = $WC_LINK
$g_hLink = _WinAPI_CreateWindowEx(0, $WC_LINK, _
'Test, [url="http://www.microsoft.com"]click here[/url], [url="http://www.microsoft.com"]here[/url] or [url=""]here[/url]', _
BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP), _
10, 10, 300, 60, $Form2 _
)
GUIRegisterMsg($WM_NOTIFY, "MY_LINK_NOTIFY")
Func MY_LINK_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local Const $tagNMLINK = $tagNMHDR & ";" & "UINT mask; int iLink; UINT state; UINT stateMask; WCHAR szID[48]; WCHAR szUrl[2083];"
Local $NMHDR = DllStructCreate($tagNMHDR, $lParam)
Local $hwndFrom = DllStructGetData($NMHDR, "hwndFrom");
Switch $hwndFrom
Case $g_hLink
Switch DllStructGetData($NMHDR, "code")
Case $NM_CLICK
ContinueCase
Case $NM_RETURN
$NMHDR = DllStructCreate($tagNMLINK, $lParam)
Local $iLink = DllStructGetData($NMHDR, "iLink")
Local $szURL = DllStructGetData($NMHDR, "szURL")
Local $szID = DllStructGetData($NMHDR, "szID")
If $szURL <> "" Then
ShellExecute($szURL, "", "", "open", #SW_SHOW);
EndIf
EndSwitch
EndSwitch
EndFunc
To make my syslinks clickable:
The problem is that I want it to display only the text... and set this white/gray background to transparent.
How can I do this?

It seems that it's impossible.
There is the LWS_TRANSPARENT style, but it doesn't make SysLink transparent, it just set its background color to the window background color.
Also, SysLink supports the WM_CTLCOLORSTATIC message, but you can't make background color transparent with it.

Related

How to get Firefox version number?

Trying to get Firefox version number, why is the line not copied from the dll file?
#RequireAdmin
$DLL = DllOpen("xul.dll")
$st = FileReadLine('C:\Program Files\Mozilla Firefox\xul.dll', 175055);  
$st2 = StringLeft($st, 80)
$st3 = StringRight($st2, 12);
FileWriteLine('1.txt', $st3)
DllClose($DLL)
Do I need to convert to UTF-8?
"Trying to get Firefox version number …"
Using cmdline output:
#include <AutoItConstants.au3>
#include <StringConstants.au3>
Global Const $g_sVersion = _FirefoxGetVersion('C:\Program Files\Mozilla Firefox\firefox.exe')
ConsoleWrite($g_sVersion & #CRLF)
Func _FirefoxGetVersion(Const $sPath)
Local Const $sRgx = '([\d\.]+)', _
$sCmd = StringFormat('%s /c "%s" -v | more', #ComSpec, $sPath)
Local Const $iPID = Run($sCmd, '', #SW_HIDE, $STDOUT_CHILD)
If Not $iPID Then Return ''
ProcessWaitClose($iPID)
Local Const $sStd = StdoutRead($iPID)
Local Const $aRes = StringRegExp($sStd, $sRgx, $STR_REGEXPARRAYMATCH)
StdioClose($iPID)
Return $aRes[0]
EndFunc

Optimizing Tab Control With AutoIT

So I wrote this to simulate a program that would have a start and stop feature, and has a tab design. Right now there is a tab that has a RichEdit object intended to be a running log.
As you can see, after we "start" the program I put just some milliseconds of sleep to simulate running instructions. I created a function to check for requests that would be called on a larger scale randomly throughout code to ping the GUI per say.
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
Global Const $h_numOfTabs = 2
Global Enum $H_TAB_1, $H_TAB_2, $H_TAB_END
Global $hGui, $h_logRichEdit, $iMsg, $h_tabs, $h_startButton, $h_stopButton
Example()
Func Example()
$hGui = GUICreate("Example (" & StringTrimRight(#ScriptName, StringLen(".exe")) & ")", 400, 550, -1, -1)
; ADD START AND STOP BUTTONS
$h_startButton = GUICtrlCreateButton( "Start", 50, 450 )
$h_stopButton = GUICtrlCreateButton( "Stop", 150, 450 )
$h_tabs = GUICtrlCreateTab( 5, 5, 390,375 )
; LOG TAB
GUICtrlCreateTabItem( "Log" )
$h_logRichEdit = _GUICtrlRichEdit_Create ( $hGui, "", 8, 30, 384, 347, BitOR( $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ) )
; STATS TAB
GUICtrlCreateTabItem( "Stats" )
; Close TABS
GUICtrlCreateTabItem( "" )
GUISetState( #SW_SHOW ) ; initialize the gui
While True
CheckRequests()
WEnd
EndFunc ;==>Example
Func Start()
while true
Sleep(100)
CheckRequests()
WEnd
EndFunc
Func Stop()
EndFunc
Func CheckRequests()
$iMsg = GUIGetMsg()
while $iMsg <> 0
Select
Case $iMsg = $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($h_logRichEdit) ; needed unless script crashes
; GUIDelete() ; is OK too
Exit
Case $iMsg = $h_tabs
Switch GUICtrlRead( $h_tabs )
Case $H_TAB_1
ControlShow( $hGui, "", $h_logRichEdit )
Case Else
ControlHide( $hGui, "", $h_logRichEdit )
EndSwitch
Case $iMsg = $h_startButton
Start()
Case $iMsg = $h_stopButton
Stop()
EndSelect
$iMsg = GUIGetMsg()
WEnd
EndFunc
At about 500ms sleep, the lag when switching tabs is visible.
My question: On a larger scale, is this how we would handle/update things that are specific to a tab while running a larger program? If not, what would be a more efficient way of updating tab specific properties while running a larger overall program.
I have also seen a design recently where all the tabs and related components were their own GUI's but I am not sure the relevance of everything being its own GUI and if it pertains to this question.
Any help or clarification is greatly appreciated, I am new to AutoIT and trying to figure out some do's and dont's as well as efficiency.
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
Global Const $h_numOfTabs = 2
Global Enum $H_TAB_1, $H_TAB_2, $H_TAB_END
Global $hGui, $h_logRichEdit, $iMsg, $h_tabs, $h_startButton, $h_stopButton
Example()
Func Example()
$hGui = GUICreate("Example (" & StringTrimRight(#ScriptName, StringLen(".exe")) & ")", 400, 550, -1, -1)
; ADD START AND STOP BUTTONS
$h_startButton = GUICtrlCreateButton( "Start", 50, 450 )
$h_stopButton = GUICtrlCreateButton( "Stop", 150, 450 )
$h_tabs = GUICtrlCreateTab( 5, 5, 390,375 )
; LOG TAB
GUICtrlCreateTabItem( "Log" )
$h_logRichEdit = _GUICtrlRichEdit_Create ( $hGui, "", 8, 30, 384, 347, BitOR( $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY ) )
_GUICtrlRichEdit_AppendText($h_logRichEdit, "{\rtf {Showing \b1 Rich Text \b0}")
; STATS TAB
GUICtrlCreateTabItem( "Stats" )
; Close TABS
GUICtrlCreateTabItem( "" )
; Register Windows message.
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState( #SW_SHOW ) ; initialize the gui
GuiMessageLoop()
EndFunc
Func GuiMessageLoop()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($h_logRichEdit) ; needed unless script crashes
; GUIDelete() ; is OK too
Exit
Case $h_startButton
Start()
Case $h_stopButton
Stop()
EndSwitch
WEnd
EndFunc
Func Start()
ConsoleWrite('# Sleep' & #CRLF)
Sleep(5000)
ConsoleWrite('# Awake' & #CRLF)
EndFunc
Func Stop()
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $iLoWord = _WinAPI_LoWord($lParam)
Local $iHiWord = _WinAPI_HiWord($lParam)
ConsoleWrite('- WM_NOTIFY' & ' ' & $iLoWord & ' ' & $iHiWord & #CRLF)
Switch GUICtrlRead( $h_tabs )
Case $H_TAB_1
ControlShow( $hGui, "", $h_logRichEdit )
Case Else
ControlHide( $hGui, "", $h_logRichEdit )
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Try this example. It uses GuiRegisterMessage to capture
WM_NOTIFY Windows messages. WM_NOTIFY is not an ideal
message code for this, though have not found something
more suitable for only changing Tabs.
The code to hide and show the Rich Edit control has been
moved into the WM_NOTIFY function so that each time a
message is received, the Tab hide and show code executes.
ConsoleWrite is used to show what the events of interest
are doing during testing. If your editor has a output
console pane, then you may be able to view the writes to
the console pane.
If an event such as function Start takes a long time,
then multi-processing may help to allow the Gui to
remain responsive with the message loop.
Want a do don't, avoid (cyclic) recursive function
calls and avoid getting trapped in loops.
Additional References:
Windows Message Codes
AutoIt Wiki about Tabs

How can i style my GUI as Aero Glass GUI with AutoIt?

How can i get the Aero Glass effect for my Autoit GUI?
I am playing a bit with AutoIt to increase my knowledge about GUI stuff. Usually i just create scripts without the usage of a GUI, but i would like to have a nice looking areo glass GUI when i just start to work with.
I already experiment with WinSetTrans but this is not exactly what i want. It should look more like the image below.
My current code is:
#include <GUIConstants.au3>
$iWidthGui = 450
$iHeightGui = 300
$hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
$cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW )
WinSetTrans($hGui, "", 180)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
Is it possible with Autoit? How can i do that?
Yes it is possible. This should work at least for Windows 7. I couldn't test the script on a Windows 10 machine.
Improved code:
#include-once
#include <GUIConstants.au3>
Global $iWidthGui = 450
Global $iHeightGui = 300
Global $hGui = GUICreate("Glass GUI", $iWidthGui, $iHeightGui, -1, -1, -1, $WS_EX_TOPMOST)
Global $cExit = GUICtrlCreateButton("Exit", $iWidthGui / 2 - 50, $iHeightGui / 2 - 15, 100, 30)
GUISetState( #SW_SHOW, $hGui )
Func _aeroGlassEffect( $hWnd, $iLeft = #DesktopWidth, $iRight = #DesktopWidth, $iTop = #DesktopWidth, $iBottom = #DesktopWidth )
$hStruct = DllStructCreate( 'int left; int right; int height; int bottom;' )
DllStructSetData( $hStruct, 'left', $iLeft )
DllStructSetData( $hStruct, 'right', $iRight )
DllStructSetData( $hStruct, 'height', $iTop )
DllStructSetData( $hStruct, 'bottom', $iBottom )
GUISetBkColor( '0x000000' )
Return DllCall( 'dwmapi.dll', 'int', 'DwmExtendFrameIntoClientArea', 'hWnd', $hWnd, 'ptr', DllStructGetPtr( $hStruct ) )
EndFunc
_aeroGlassEffect( $hGui )
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $cExit
GUIDelete($hGui)
ExitLoop
EndSwitch
WEnd
I switched WinSetTrans() for _aeroGlassEffect(). You can change the function parameters $iLeft, $iRight, $iTop, $iBottom.

AutoIT script - Compare Paint's Rotated Image with GDI's rotated image

I have an image and rotate it with both MS Paint and GDI. I want to show that the rotated image from both methods are the same.
Here is the code I have to rotate image with GDI
#include <GDIPlus.au3>
_GDIPlus_Startup()
$hImage1 = _GDIPlus_ImageLoadFromFile(#ScriptDir & "\Picture.gif")
$hGraphic1 = _GDIPlus_ImageGetGraphicsContext($hImage1)
$hImage2 = _GDIPlus_BitmapCreateFromGraphics(_GDIPlus_ImageGetWidth($hImage1), _GDIPlus_ImageGetHeight($hImage1), $hGraphic1)
$hGraphic2 = _GDIPlus_ImageGetGraphicsContext($hImage2)
$matrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixRotate($matrix,90)
_GDIPlus_GraphicsSetTransform($hGraphic2, $matrix)
_GDIPlus_GraphicsDrawImage($hGraphic2, $hImage1, 0, -590)
_GDIPlus_ImageSaveToFile($hImage2, #ScriptDir & "\out.gif")
_GDIPlus_MatrixDispose($matrix)
_GDIPlus_GraphicsDispose($hGraphic1)
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ShutDown ()
Then I used this code to compare 2 images:
$bm1 = _GDIPlus_ImageLoadFromFile(#ScriptDir & "\Picture1.gif")
$bm2 = _GDIPlus_ImageLoadFromFile(#ScriptDir & "\out.gif")
if ComparePicture($bm1, $bm2) == True Then
MsgBox(0, "Test result", "Same image!")
Else
MsgBox(0, "Test result", "Different image!")
EndIf
_GDIPlus_ImageDispose($bm1)
_GDIPlus_ImageDispose($bm2)
_GDIPlus_Shutdown()
Func ComparePicture($bm1, $bm2)
$Bm1W = _GDIPlus_ImageGetWidth($bm1)
$Bm1H = _GDIPlus_ImageGetHeight($bm1)
$BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF08INDEXED )
$Stride = DllStructGetData($BitmapData1, "Stride")
$Scan0 = DllStructGetData($BitmapData1, "Scan0")
$ptr1 = $Scan0
$size1 = ($Bm1H - 1) * $Stride + ($Bm1W - 1) * 4
$Bm2W = _GDIPlus_ImageGetWidth($bm2)
$Bm2H = _GDIPlus_ImageGetHeight($bm2)
$BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF08INDEXED)
$Stride = DllStructGetData($BitmapData2, "Stride")
$Scan0 = DllStructGetData($BitmapData2, "Scan0")
$ptr2 = $Scan0
$size2 = ($Bm2H - 1) * $Stride + ($Bm2W - 1) * 4
$smallest = $size1
If $size2 < $smallest Then $smallest = $size2
$call = DllCall("msvcrt.dll", "int:cdecl", "memcmp", "ptr", $ptr1, "ptr", $ptr2, "int", $smallest)
_GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
_GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
Return ($call[0]=0)
EndFunc
I tried changing the file type, color depth, etc. but I could not get the code to show that they are the same. When I do not rotate the picture i.e
_GDIPlus_MatrixRotate($matrix,0)
then it recognize the same image. When I rotate right 90, it doesn't. Does anyone knows what might be going on?
Thanks
For reference, this question has also been asked on the AutoIt forums here.
I think $GDIP_PXF08INDEXED is modifying the images differently. Try it without setting it and it should work.
Furthermore, you can use this code to flip the image:
$hImage1 = _GDIPlus_ImageLoadFromFile(#ScriptDir & "\Picture1.gif")
_GDIPlus_ImageRotateFlip($hImage1, 1) ;90°
_GDIPlus_ImageSaveToFile($hImage1, #ScriptDir & "\out.gif")
_GDIPlus_ImageDispose($hImage1)
Br,
UEZ

Add local Printer port with VBS

first of all i'm sorry for my english.
I've one question about windows WMI and how to add a local port to shared printer. I've this script:
Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "Ricoh3300C"
objNewPort.Protocol = 2
objNewPort.HostAddress = "XXX.XXX.X.XXX"
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = False
objNewPort.Put_
With this i can add a printer with IP address but i want to add a printer in samba server with an address like "\\XXX.XXX.X.XXX\printerColor". I've lost a lot of time in google trying to find an script and all that i've seen is for TCPIP ports. I wan't to do it but in local port.
I've tried to use this script with prnadmin.dll and no luck.
function PortAdd(strPort, portType)
on error resume next
dim oMaster
dim oPort
dim iResult
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
set oPort = CreateObject("Port.Port.1")
iResult = kErrorFailure
oPort.PortName = strPort
oPort.PortType = portType
oMaster.PortAdd oPort
if Err = 0 then
iResult = kErrorSuccess
else
wscript.echo "Error: 0x" & Hex(Err.Number) & ". " & Err.Description
end if
PortAdd = iResult
end function
I get this error:
Error: 0x1A8. Se requiere un objeto
in english is like
Error: 0x1A8. An object is required
How can i fix that error or what script can i use to add a local port?. Thanks in advance.
I forgot to say that i want to do it with normal user without admin access. The first script works fine in that users but is for TCPIP.
Consider using XcvData, e.g.
private static void AddPort(string portName)
{
var def = new PRINTER_DEFAULTS();
def.pDatatype = null;
def.pDevMode = IntPtr.Zero;
def.DesiredAccess = 1; //Server Access Administrator
IntPtr hPrinter = IntPtr.Zero;
int n = OpenPrinter(",XcvMonitor Local Port", ref hPrinter, def);
if (n == 0)
throw new Exception("Local Port monitor has not been opened.");
if (!portName.EndsWith("\0"))
portName += "\0";
// .NET strings are formed by 2-byte characters
var size = (uint) (portName.Length*2);
IntPtr portPtr = Marshal.AllocHGlobal((int) size);
Marshal.Copy(portName.ToCharArray(), 0, portPtr, portName.Length);
uint needed, xcvResult;
XcvData(hPrinter, "AddPort", portPtr, size, IntPtr.Zero, 0, out needed, out xcvResult);
ClosePrinter(hPrinter);
Marshal.FreeHGlobal(portPtr);
}
[DllImport("winspool.drv", EntryPoint = "XcvDataW", SetLastError = true)]
private static extern bool XcvData(
IntPtr hXcv,
[MarshalAs(UnmanagedType.LPWStr)] string pszDataName,
IntPtr pInputData,
uint cbInputData,
IntPtr pOutputData,
uint cbOutputData,
out uint pcbOutputNeeded,
out uint pwdStatus);

Resources