Sign in to follow this  
Followers 0
johnmcloud

_WinAPI_CreateCompatibleBitmap to file

16 posts in this topic

#1 ·  Posted (edited)

Hi guys

I'm seaching an alternative way to ScreenCapture UDF. Why? I think GDI+ is slow if you need to capture many images  :D

Searching on the web for the fastest method i have found:

1) Using Surface DirectX method

2) Using BitBlt method

The Directx method ( here you can find and example in C# ) is probably tha fastest but it's totally out of my knowledge, and i'm not sure can be done in autoit.

For the second i'm sure can be done in autoit and this is what i have make:

#include <WinAPI.au3>
;~ #include <ScreenCapture.au3> ; Testin purpose

Global Const $SRCCOPY = 0x00CC0020

$hDDC = _WinAPI_GetDC(0)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, @DesktopWidth, @DesktopHeight)
_WinAPI_SelectObject($hCDC, $hBMP)
_WinAPI_BitBlt($hCDC, 0, 0, @DesktopWidth, @DesktopHeight, $hDDC, 0, 0, $SRCCOPY)
_WinAPI_ReleaseDC(0, $hDDC)
_WinAPI_DeleteDC($hCDC)
;~ _ScreenCapture_SaveImage(@ScriptDir & "\GDIPlus_Image.jpg", $hBMP) ; testing purpose
_WinAPI_SaveBMP(@ScriptDir & "\GDIPlus_Image.bmp", $hBMP) ; BMP is sure, PNG if possible. 

Func _WinAPI_SaveBMP($sFilename, $hData)
    $file = _WinAPI_CreateFile($sFileName)
    _WinAPI_CloseHandle($file)
;~  _WinAPI_WriteFile ; ---> Write file header and info header
;~  _WinAPI_CloseHandle($file) ; Close the handle
;~  _WinAPI_WriteFile ; ---> Write data of the bitmap
;~  _WinAPI_CloseHandle($file)
EndFunc

As you can see, work if i use GDI-ScreenCapture UDF but the goal is avoid that, if i need to use GDI i'll use the UDF :D

The main problem is i don't know how to write in the file the information stored in _WinAPI_CreateCompatibleBitmap ( so Save HBITMAP to file trans.gif?cver=0%0D%0A)

I need to create the file header, info header and then write the data? ( i think :D ) but i'm here because i need an help for do the last part of the code.

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

 

#include <WinAPI.au3>
#include <GDIPlus.au3>

Global Const $SRCCOPY = 0x00CC0020
_GDIPlus_Startup()

Local $t = TimerInit()
Local $hWnd = _WinAPI_GetDesktopWindow()
Local $hDDC = _WinAPI_GetDC($hWnd)
Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
Local $hHBMP = _WinAPI_CreateCompatibleBitmap($hDDC, @DesktopWidth, @DesktopHeight)
_WinAPI_SelectObject($hCDC, $hHBMP)
_WinAPI_BitBlt($hCDC, 0, 0, @DesktopWidth, @DesktopHeight, $hDDC, 0, 0, $SRCCOPY)
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBMP)
_GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test.jpg")
_GDIPlus_BitmapDispose($hBitmap)
_WinAPI_DeleteObject($hHBMP)
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
ConsoleWrite(TimerDiff($t) & @LF)

_GDIPlus_Shutdown()
Exit
 

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

Hi UEZ, thanks for the answer.

As i said before, i'd like to avoid gdi. I'd like to make at least 1 screen every 41ms, with the _ScreenCapture UDF( it use gdi ) i can make 1 screen every 100ms

I'll test your solution and let you know, anyway i'm searching a method like c++ with saving file creating header etc.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Look at WinAPIEx to get some ideas how to save GDI bitmaps. I don't know whether those methods are faster. Try it.

You can speed up the code above by using directly the calls instead of calling functions. This can give you some ms back.

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

#5 ·  Posted (edited)

Here the nacked version from post#2:

#include <GDIPlus.au3>

Global Const $SRCCOPY = 0x00CC0020
_GDIPlus_Startup()
Local $hDLL_user32 = DllOpen("user32.dll")
Local $hDLL_gdi32 = DllOpen("gdi32.dll")
Local $hDLL_ole32 = DllOpen("ole32.dll")

Local $t = TimerInit()
Local $aResult = DllCall($hDLL_user32, "hwnd", "GetDesktopWindow")
Local $hWnd = $aResult[0]
$aResult = DllCall($hDLL_user32, "handle", "GetDC", "hwnd", $hWnd)
Local $hDDC = $aResult[0]
$aResult = DllCall($hDLL_gdi32, "handle", "CreateCompatibleDC", "handle", $hDDC)
Local $hCDC = $aResult[0]
$aResult = DllCall($hDLL_gdi32, "handle", "CreateCompatibleBitmap", "handle", $hDDC, "int", @DesktopWidth, "int", @DesktopHeight)
Local $hHBMP = $aResult[0]
DllCall($hDLL_gdi32, "handle", "SelectObject", "handle", $hCDC, "handle", $hHBMP)
DllCall($hDLL_gdi32, "bool", "BitBlt", "handle", $hCDC, "int", 0, "int", 0, "int", @DesktopWidth, "int", @DesktopHeight, "handle", $hDDC, "int", 0, "int", 0, "dword", $SRCCOPY)
$aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHBITMAP", "handle", $hHBMP, "handle", 0, "ptr*", 0)
Local $hBitmap = $aResult[3]
Local $sCLSID = "{557CF401-1A04-11D3-9A73-0000F81EF32E}" ;JPG
Local $tGUID = DllStructCreate($tagGUID)
DllCall($hDLL_ole32, "long", "CLSIDFromString", "wstr", $sCLSID, "struct*", $tGUID)
DllCall($ghGDIPDll, "int", "GdipSaveImageToFile", "handle", $hBitmap, "wstr", @ScriptDir & "\Test.jpg", "struct*", $tGUID, "struct*", 0)
DllCall($ghGDIPDll, "int", "GdipDisposeImage", "handle", $hBitmap)
DllCall($hDLL_gdi32, "bool", "DeleteObject", "handle", $hHBMP)
DllCall($hDLL_user32, "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDDC)
DllCall($hDLL_gdi32, "bool", "DeleteDC", "handle", $hCDC)
ConsoleWrite(TimerDiff($t) & @LF)

DllClose($hDLL_gdi32)
DllClose($hDLL_ole32)
DllClose($hDLL_user32)

_GDIPlus_Shutdown()
Exit

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

#6 ·  Posted (edited)

So UEZ, i have tested both version but give me the same result. i can make 1 screen every 45,5ms, much better then the ScreenCapture UDF ( but for this i don't have any doubt ) but not like the result i'd like to make, but we are very close ;)

This is the test script i have make for check the screen for second:

DirCreate(@ScriptDir & "\Test")

$iCounter = 1
$iFramePerSec = 24
$iPause = 1000 / $iFramePerSec
$time = TimerInit()

Do
    $iStart = TimerInit()
    ;code @ScriptDir & "\Test\" & $iCounter & ".jpg"
    $iPauseLess = TimerDiff($iStart)
    $iStart2 = TimerInit()
    Sleep(Int($iPause - $iPauseLess))
    $iCounter += 1
Until TimerDiff($time) >= 1000

My last try is to use the WinAPIEx for save the file instead of GDI, but i don't know how to start, there are many func there :D

Suggestion?

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Well, i have found in WinAPIEx the _WinAPI_SaveHBITMAPToFile. I think that funcion do many "unecessary check" before creating the file ( in comparison with a C++ version like this ) and is more slow than the GDI, only 71ms for second

So for now the best was my first version + saving image in gdi by uez, but the goal I have set for myself i was not able to reach. I'm open to any other ideas ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

For me the real bottleneck seems to be the actual "save to disk" call.

#include <GDIPlus.au3>

Global Const $SRCCOPY = 0x00CC0020
_GDIPlus_Startup()
Local $hDLL_user32 = DllOpen("user32.dll")
Local $hDLL_gdi32 = DllOpen("gdi32.dll")
Local $hDLL_ole32 = DllOpen("ole32.dll")

Local $t = TimerInit()
Local $aResult = DllCall($hDLL_user32, "hwnd", "GetDesktopWindow")
Local $hWnd = $aResult[0]
$aResult = DllCall($hDLL_user32, "handle", "GetDC", "hwnd", $hWnd)
Local $hDDC = $aResult[0]
$aResult = DllCall($hDLL_gdi32, "handle", "CreateCompatibleDC", "handle", $hDDC)
Local $hCDC = $aResult[0]
$aResult = DllCall($hDLL_gdi32, "handle", "CreateCompatibleBitmap", "handle", $hDDC, "int", @DesktopWidth, "int", @DesktopHeight)
Local $hHBMP = $aResult[0]
DllCall($hDLL_gdi32, "handle", "SelectObject", "handle", $hCDC, "handle", $hHBMP)
DllCall($hDLL_gdi32, "bool", "BitBlt", "handle", $hCDC, "int", 0, "int", 0, "int", @DesktopWidth, "int", @DesktopHeight, "handle", $hDDC, "int", 0, "int", 0, "dword", $SRCCOPY)
$aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromHBITMAP", "handle", $hHBMP, "handle", 0, "ptr*", 0)
Local $hBitmap = $aResult[3]
Local $sCLSID = "{557CF401-1A04-11D3-9A73-0000F81EF32E}" ;JPG
Local $tGUID = DllStructCreate($tagGUID)
DllCall($hDLL_ole32, "long", "CLSIDFromString", "wstr", $sCLSID, "struct*", $tGUID)
ConsoleWrite(TimerDiff($t) & @LF)
DllCall($ghGDIPDll, "int", "GdipSaveImageToFile", "handle", $hBitmap, "wstr", @ScriptDir & "\Test.jpg", "struct*", $tGUID, "struct*", 0)
ConsoleWrite(TimerDiff($t) & @LF)
DllCall($ghGDIPDll, "int", "GdipDisposeImage", "handle", $hBitmap)
DllCall($hDLL_gdi32, "bool", "DeleteObject", "handle", $hHBMP)
DllCall($hDLL_user32, "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDDC)
DllCall($hDLL_gdi32, "bool", "DeleteDC", "handle", $hCDC)
ConsoleWrite(TimerDiff($t) & @LF)

DllClose($hDLL_gdi32)
DllClose($hDLL_ole32)
DllClose($hDLL_user32)

_GDIPlus_Shutdown()
Exit

 

Two things to overcome this come to my mind.

Either use a second child process for the saving (use some kind of stack for the bitmaps).

Or maybe take a look in the example section for how to save bitmaps as blobs to an (in memory) sqlite database for later processing.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I'm not totally conviced about the "save to disk" problem, i think is only a problem of "speed" of execution. If was a save to disk problem how can DirectX method saves 15-25ms at images? Tested a demo code on a couple of VM

Anyway i don't need a funcion faster like that but something in 41ms, so i can use a thing like _GDIPlus_SaveImageToStream for multiple images and than saves later?

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

What also came to my mind... saving pictures in such a short succession, wouldn't it be better to save them as a movie file? I remember seeing some code for that... by UEZ too?

Edit: Yep, by UEZ :), >here it is. I did not compare the performance, but might be worth a look. An option would be to save as avi and then, if really needed, to extract the single pictures afterwards

Edited by KaFu

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Many things comes to your mind :D

It save the hbitmap directly to AVI but the question is, how fast it is? It uses _ScreenCapture, from my test it's the worst method in terms of speed but now i'll check it and let you know

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

TESTED: If i put 24fps and one of the compression...the video is superfaster :D

If i use non-compressed format seems "normal" ( i don't know how many screen for second ) but the output for 5 second of video is 150MB.

Just for know, I don't have understand how to select the video compression without popop, example the Microsoft Video 1 with 100% Quality. I think is in the UDF, i don't have found any parameter in _CreateAVI

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

TESTED: If i put 24fps and one of the compression...the video is superfaster :D

If i use non-compressed format seems "normal" ( i don't know how many screen for second ) but the output for 5 second of video is 150MB.

Just for know, I don't have understand how to select the video compression without popop, example the Microsoft Video 1 with 100% Quality. I think is in the UDF, i don't have found any parameter in _CreateAVI

 

I guess that the answer to this questions might be buried somewhere in this >post (esp. the last post might give a clue).

Edited by KaFu

Share this post


Link to post
Share on other sites

Damn, you have right. The code was commented out in UDF I have think was unecessary/unused code

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'm checking what i can do with AVIWriter UDF. I have only a problem, based on the example by UEZ posted by KaFu's post, if i set the $rec_duration = 10 ; ten second and i want to stop it with a hotkey, how i can do?

I have try to:

1) Exit the main loop

2) _CloseAvi

But everytime autoit crash with -1073741819. Thanks for any help

EDIT: Wait, is with the HotKeySet the problem. If i use:

Func _Test1()
 Start()
EndFunc

Func _Test2()
 Stop()
EndFunc

With two different hotkey i don't have problem, if i use the same hotkey in this way:

Func _StartStop()
    If $fFlag Then
        Start()
    Else
        Stop()
    EndIf
    $fFlag = Not $fFlag
EndFunc   ;==>_StartStop

Crash! Yes, i have declared the flag, if i use ConsoleWrite work...that's strange

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Try something like this here:

#include "AVIWriter Extented.au3"
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()

Global Const $sFile = @ScriptDir & "\test.avi"
FileDelete($sFile)

Global $rec_duration = 20 ;20 seconds
Global $fps = 10

Global Const $dll = DllOpen("user32.dll")
Global $hGUI_Grab2AVI = GUICreate("", 0, 0, 0, 0, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW, WinGetHandle(AutoItWinGetTitle()))
GUISetBkColor(0xFF0000, $hGUI_Grab2AVI)
GUISetState(@SW_SHOW, $hGUI_Grab2AVI)
Global $aMPos, $hWin, $hWinAncestor, $hWnd, $aRet_prev, $aPos
Global Const $frame_size = 3
Global $tPoint = DllStructCreate($tagPOINT)
Global $esc = True
Global $mxo, $myo

While Not _IsPressed("1B", $dll) * Sleep(30)
    $aMPos = MouseGetPos()
    DllStructSetData($tPoint, 1, $aMPos[0])
    DllStructSetData($tPoint, 2, $aMPos[1])
    $hWin = _WinAPI_WindowFromPoint($tPoint)
    $hWinAncestor = _WinAPI_GetAncestor($hWin, 2)
    $hWnd = HWnd($hWinAncestor)
    $aRet_prev = -1
    $aPos  = WinGetPos($hWnd)
    If $hWnd <> $hGUI_Grab2AVI And $hWnd <> $aRet_prev Then
        $aRet_prev = $hWnd
        If $aMPos[0] <> $mxo Or $aMPos[1] <> $myo Then
            WinMove($hGUI_Grab2AVI, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3], 1)
            _GuiHole($hGUI_Grab2AVI, $frame_size, $frame_size, $aPos[2] - 2 * $frame_size, $aPos[3] - 2 * $frame_size, $aPos[2], $aPos[3])
            WinSetOnTop($hGUI_Grab2AVI, 0, 1)
            ToolTip("Press CTRL to start capturing of" & @LF & "marked window to a AVI file!" & @LF & @LF & _
                         "Duration: " & $rec_duration & " seconds @ " & $fps & " fps" & @LF & _
                          "Windows Size: " & $aPos[2] & " x " & $aPos[3], $aMPos[0] + 20, $aMPos[1] + 20)
            $mxo = $aMPos[0]
            $myo = $aMPos[1]
        EndIf
    EndIf
    If _IsPressed("11", $dll) Then
        $esc = False
        ExitLoop
    EndIf
WEnd
ToolTip("")
GUIDelete($hGUI_Grab2AVI)
If $esc Then Exit MsgBox(0, "Information", "Aborted", 10)

_StartAviLibrary()
Global $aAVI = _CreateAvi($sFile, $fps, $aPos[2], $aPos[3])
If @error Then close()

Global $hBmp

Global $fSleep = 1000 / $fps, $t, $td
Global $total_FPS = $rec_duration * $fps, $fps_c = 1
$k32_dll = DllOpen("kernel32.dll")
Do
    $fTimer = TimerInit()

    $hBmp = _ScreenCapture_CaptureWnd("", $hWnd)
    _AddHBitmapToAvi($aAVI, $hBmp)
    _WinAPI_DeleteObject($hBmp)

    $fps_c += 1
    $td = $fSleep - TimerDiff($fTimer)
    If $td > 0 Then
        DllCall($k32_dll, "none", "Sleep", "dword", $td)
    EndIf

    If $fps_c > $total_FPS Or _IsPressed("1B", $dll) Then
        Close()
    EndIf

Until False

Func Close()
    _GDIPlus_Shutdown()
    _CloseAvi($aAVI)
    _StopAviLibrary()
    ConsoleWrite($fps_c & " frames added" & @CRLF)
    ConsoleWrite("AVI filesize: " & Round(FileGetSize($sFile) / 1024 ^ 2, 2) & " MB" & @CRLF)
    DllClose($k32_dll)
    DllClose($dll)
    Exit MsgBox(0, "Information", "Done!", 15)
EndFunc   ;==>close

Func _GuiHole($hWnd, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $height)
    Local $outer_rgn, $inner_rgn, $combined_rgn
    $outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $height)
    $inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
    $combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    _WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)
    _WinAPI_DeleteObject($outer_rgn)
    _WinAPI_DeleteObject($inner_rgn)
    _WinAPI_SetWindowRgn($hWnd, $combined_rgn)
EndFunc   ;==>_GuiHole

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

  • Similar Content

    • NHD
      By NHD
      Hi,
      I've been translated code from FreeBasic to AutoIt. And it didn't work correctly.
      Please help me!
      FreeBasic:
      #Include Once "windows.bi" #Define _RGB(r,g,b) BGR(b,g,r) CONST GRADIENT_FILL_RECT_H = 0 CONST GRADIENT_FILL_RECT_V = 1 Dim Shared hInstance As HINSTANCE ' This dll is located in Windows directory DECLARE FUNCTION Gradientfill Lib "MSIMG32" ALIAS "GradientFill" _ (hDC AS HDC, pVertex As PTRIVERTEX, dwNumVertex As Integer,pMesh AS PGRADIENT_RECT, dwNumMesh As Integer, dwMode As Integer) As Integer '******************************************************************** ' A FB Control Template '******************************************************************** Declare Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT Declare FUNCTION IsMouseOver (hWnd As HWND )As Integer Declare SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) Declare FUNCTION Register_NiceButt()As Integer ' 'Windows calls this function when the dll is loaded. /'Function DllMain alias "MAIN"(byval hModule as HMODULE,byval reason as Integer,byval lpReserved as LPVOID) as BOOL Select case reason case DLL_PROCESS_ATTACH hInstance=hModule Register_NiceButt() MessageBox(GetActiveWindow(),"OK","OK",MB_OK) Return 0 case DLL_PROCESS_DETACH ' end select return TRUE end function '/ FUNCTION Register_NiceButt()As Integer Export DIM wc AS WNDCLASSEX DIM szClassName As String szClassName = "NiceButt" wc.cbSize = SIZEOF(WNDCLASSEX) wc.style = CS_HREDRAW OR CS_VREDRAW OR CS_GLOBALCLASS wc.hInstance = GetmoduleHandle(0) 'hInstance wc.hbrBackground = Cast(HBRUSH,COLOR_BTNFACE+1) wc.lpszClassName = StrPtr(szClassName) wc.lpfnWndProc = @NiceButt wc.cbClsExtra = 0 wc.cbWndExtra = 0 wc.hIcon = 0 wc.hCursor = 0 wc.lpszMenuName = 0 wc.hIconSm = 0 FUNCTION = RegisterClassEx(@wc) END FUNCTION '******************************************************************** ' Custom Control Procedure '******************************************************************** Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT STATIC As Integer ButtDown,mouseover STATIC Captured AS HWND SELECT Case Msg '************************** CASE WM_CREATE '************************** DIM Region AS HRGN DIM Rct AS RECT DIM As Integer x, y, w, h ButtDown = FALSE GetClientRect (hWnd,@Rct) ' <<-- Get the size of our control x = Rct.left y = Rct.top w = Rct.right - Rct.left h = Rct.bottom - Rct.top 'Region = CreateRoundRectRgn(10,10,w,h, h * 0.90 , h * 0.90 ) 'SetWindowRgn (hWnd,Region,True) InvalidateRect(hWnd,0,0) 'EXIT FUNCTION ' ******************* CASE WM_PAINT ' ******************* DIM hDC AS HDC DIM ps AS PAINTSTRUCT DIM hPen AS HPEN DIM hBrush AS HBRUSH DIM hOldBrush AS HBRUSH DIM Rct AS RECT DIM Size AS SIZE DIM T As ZString*2048 DIM As Integer i DIM As Integer XCtr DIM As Integer YCtr DIM As Integer x,y,w,h DIM As Integer r,g,b ' ******************* GetClientRect (hWnd,@Rct) ' <<-- Get the size of our control x = Rct.left y = Rct.top w = Rct.right - Rct.left h = Rct.bottom - Rct.top XCtr = (Rct.left + Rct.right) / 2 ' Horizontal center of our ctrl YCtr = (Rct.top + Rct.bottom) / 2 ' Vertical center of our ctrl GetWindowText(hWnd,T ,255) ' Grab a copy of control caption '********************************** ' Draw our control '********************************** hDC = BeginPaint (hWnd, @ps) GetTextExtentPoint32(hDC, T , LEN(T),@Size) ' Get caption size r = 30 : g = 90 : b = 90 Draw_Gradient (hDC, x, y, w, h, r, g, b) SetBkMode (hDC,TRANSPARENT) IF ButtDown THEN SetTextColor(hDC,_RGB(255,0,0)) TextOut(hDC, XCtr-(Size.cx/2)+1, YCtr-(Size.cy/2)+1,T,LEN(T)) ELSE SetTextColor(hDC,_RGB(0,0,255)) TextOut(hDC, XCtr-Size.cx/2, YCtr-Size.cy/2,T,LEN(T)) END IF EndPaint (hWnd,@ps) 'EXIT FUNCTION '****************************** CASE WM_LBUTTONUP '****************************** IF hWnd = Captured THEN DIM hParent AS HWND ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) hParent=GetParent(hWnd) SendMessage(hParent,WM_COMMAND,MAKELONG(GetWindowLong(hWnd,GWL_ID), BN_CLICKED),Cast(LONG,hWnd)) END IF 'EXIT FUNCTION '****************************** CASE WM_LBUTTONDOWN '****************************** SetCapture(hWnd) Captured = hWnd ButtDown = TRUE SetFocus (hWnd) InvalidateRect(hWnd,0,0) 'EXIT FUNCTION '****************************** CASE WM_MOUSEMOVE '****************************** IF ButtDown THEN IF IsMouseOver(hWnd) THEN ButtDown = TRUE InvalidateRect(hWnd,0,0) ELSE ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) END IF END IF 'EXIT FUNCTION '****************************** CASE WM_MOVING '****************************** ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) 'EXIT FUNCTION '****************************** CASE WM_SIZE '****************************** ReleaseCapture() ButtDown = FALSE InvalidateRect(hWnd,0,0) 'EXIT FUNCTION END Select Return DefWindowProc(hwnd,Msg,wparam,lparam) END FUNCTION SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) DIM Vert(2) AS TRIVERTEX DIM Rect AS GRADIENT_RECT '****************************************************** Vert (0).x = 0 Vert (0).y = 0 Vert (0).Red = 65535-(65535-(r*256)) Vert (0).Green = 65535-(65535-(g*256)) Vert (0).Blue = 65535-(65535-(b*256)) Vert (0).Alpha = 0 '****************************************************** Vert (1).x = w Vert (1).y = h/2 Vert (1).Red = 65535-(65535-(255*256)) Vert (1).Green = 65535-(65535-(255*256)) Vert (1).Blue = 65535-(65535-(255*256)) Vert (1).Alpha = 0 '****************************************************** Rect.UpperLeft = 0 Rect.LowerRight = 1 '****************************************************** Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) '****************************************************** Vert (0).x = 0 Vert (0).y = h/2 Vert (0).Red = 65535-(65535-(255*256)) Vert (0).Green = 65535-(65535-(255*256)) Vert (0).Blue = 65535-(65535-(255*256)) Vert (0).Alpha = 0 '****************************************************** Vert (1).x = w Vert (1).y = h Vert (1).Red = 65535-(65535-(r*256)) Vert (1).Green = 65535-(65535-(g*256)) Vert (1).Blue = 65535-(65535-(b*256)) Vert (1).Alpha = 0 '****************************************************** Rect.UpperLeft = 0 Rect.LowerRight = 1 '****************************************************** Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) END SUB FUNCTION IsMouseOver (hWnd As HWND )As Integer DIM Rect As RECT DIM Pt As POINT GetWindowRect (hWnd, @Rect) GetCursorPos(@Pt) FUNCTION = PtInRect (@Rect, Pt) END FUNCTION  
      AutoIt:
      #include-once #include <WinAPI.au3> #include <WinAPIGdi.au3> #include <WinAPISys.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;~ #Include <windows.bi> Global Const $_tagRect = "struct;long left;long top;long right;long bottom;endstruct" Global Const $_tagSize = "struct;long cx;long cy;endstruct" Global Const $_tagGradient_Rect = "struct;ulong UpperLeft;ulong LowerRight;endstruct" Global Const $_tagPoint = "struct;long x;long y;endstruct" Global Const $_tagTrivertex = "struct;long x;long y;int Red;int Greed;int Blue;int Alpha;endstruct" Global Const $_tagPaintStruct = "struct;handle hdc;bool fErase;long left;long top;long right;long bottom;bool fRestore;bool fIncUpdate;byte rgbReserved[32];endstruct" Global Const $_tagWNDCLASSEX = "struct;uint cbSize;uint style;ptr lpfnWndProc;int cbClsExtra;int cbWndExtra;ptr hInstance;ptr hIcon;" & _ "ptr hCursor; ptr hbrBackground; ptr lpszMenuName;ptr lpszClassName;ptr hIconSm;endstruct" Global Const $CS_VREDRAW = 0x0001, $CS_HREDRAW =0x0002, $CS_GLOBALCLASS = 0x4000 Global Const $BN_CLICKED = 0 ;~ #Define _RGB(r,g,b) BGR(b,g,r) Global Const $GRADIENT_FILL_RECT_H = 0 Global Const $GRADIENT_FILL_RECT_V = 1 ;~ Dim Shared hInstance As HINSTANCE ;~ ' This dll is located in Windows directory ;~ DECLARE FUNCTION Gradientfill Lib "MSIMG32" ALIAS "GradientFill" _ ;~ (hDC AS HDC, pVertex As PTRIVERTEX, dwNumVertex As Integer,pMesh AS PGRADIENT_RECT, dwNumMesh As Integer, dwMode As Integer) As Integer ;~ '******************************************************************** ;~ ' A FB Control Template ;~ '******************************************************************** ;~ Declare Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT ;~ Declare FUNCTION IsMouseOver (hWnd As HWND )As Integer ;~ Declare SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) ;~ Declare FUNCTION Register_NiceButt()As Integer #cs ' 'Windows calls this function when the dll is loaded. /'Function DllMain alias "MAIN"(byval hModule as HMODULE,byval reason as Integer,byval lpReserved as LPVOID) as BOOL Select case reason case DLL_PROCESS_ATTACH hInstance=hModule Register_NiceButt() MessageBox(GetActiveWindow(),"OK","OK",MB_OK) Return 0 case DLL_PROCESS_DETACH ' end select return True end function '/ #ce #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) RegisterButton() Global $Ctrl = _winapi_CreateWindowEx(0, "TestButton", "Test", BitOR($WS_VISIBLE, $WS_CHILD), 10, 10, 80, 30, $Form1) ConsoleWrite(@CRLF & $Ctrl) GUISetState(@SW_SHOW) _WinAPI_UpdateWindow($Form1) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func RegisterButton() Local $hDll = DllCallbackRegister('TestButtonProc', 'lresult', 'hwnd;uint;wparam;lparam') ;~ DIM wc AS WNDCLASSEX ;~ DIM szClassName As String Local $sClass = "TestButton" Local $wc = DllStructCreate($_tagWNDCLASSEX & ';wchar szClassName[' & (StringLen($sClass) + 1) & ']') ;~ szClassName = "NiceButt" ;~ wc.cbSize = SIZEOF(WNDCLASSEX) $wc.cbSize = DllStructGetPtr($wc, 'szClassName') - DllStructGetPtr($wc) ;~ wc.style = CS_HREDRAW OR CS_VREDRAW OR CS_GLOBALCLASS $wc.style = BitOR($CS_HREDRAW, $CS_VREDRAW, $CS_GLOBALCLASS) ;~ wc.hInstance = GetmoduleHandle(0) 'hInstance $wc.hInstance = _WinAPI_GetModuleHandle(0) ;~ wc.hbrBackground = Cast(HBRUSH,COLOR_BTNFACE+1) ;/// $wc.hbrBackground = _WinAPI_CreateSolidBrush(_WinAPI_GetSysColor($COLOR_BTNFACE)) ;~ wc.lpszClassName = StrPtr(szClassName) $wc.lpszClassName = DllStructGetPtr($wc, 'szClassName') ;~ wc.lpfnWndProc = @NiceButt $wc.lpfnWndProc = DllCallbackGetPtr($hDll) ;~ wc.cbClsExtra = 0 $wc.cbClsExtra = 0 ;~ wc.cbWndExtra = 0 $wc.cbWndExtra = 0 ;~ wc.hIcon = 0 $wc.hIcon = 0 ;~ wc.hCursor = 0 $wc.hCursor = 0 ;~ wc.lpszMenuName = 0 $wc.lpszMenuName = 0 ;~ wc.hIconSm = 0 $wc.hIconSm = 0 $wc.szClassName = $sClass ;~ FUNCTION = RegisterClassEx(@wc) Local $aRet = _WinAPI_RegisterClassEx($wc) Return $aRet ;~ END FUNCTION EndFunc ;******************************************************************** ; Custom Control Procedure ;******************************************************************** ;~ Function NiceButt(ByVal hWnd as HWND,byval Msg as UINT,byval wParam as WPARAM,byval lParam as LPARAM) as LRESULT Func TestButtonProc($hWnd, $iMsg, $wParam, $lParam) Static $bBtnDown, $bMouseOver, $hCaptured Switch $iMsg Case $WM_CREATE Local $Rct = DllStructCreate($_tagRect) Local $iX, $iY, $iW, $iH $bBtnDown = False GetClientRect($hWnd, $Rct) $iX = $Rct.left $iY = $Rct.top $iW = $Rct.right - $Rct.left $iH = $Rct.bottom - $Rct.top InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_PAINT Local $ps ;= DllStructCreate($_tagPaintStruct) Local $hPen, $hBrush, $hOldBrush Dim $Rct = DllStructCreate($_tagRect) Dim $Size = DllStructCreate($_tagSize) Dim $T = "", $i Dim $XCtr, $YCtr Dim $iX, $iY, $iW, $iH Dim $iR, $iG, $iB GetClientRect($hWnd, $Rct) $iX = $Rct.left $iY = $Rct.top $iW = $Rct.right - $Rct.left $iH = $Rct.bottom - $Rct.top $XCtr = ($Rct.left + $Rct.right) / 2 $YCtr = ($Rct.top + $Rct.bottom) / 2 ;~ GetWindowText(hWnd,T ,255) ' Grab a copy of control caption ;~ DllCall("user32.dll", "int", "GetWindowTextW", "hwnd", $hWnd, "LPTSTR ", $T, "int", 255) ; not work $T = "Test" ;********************************** ; Draw our control ;********************************** Local $hDC = BeginPaint($hWnd, $ps) ;~ GetTextExtentPoint32(hDC, T , LEN(T),@Size) ' Get caption size GetTextExtentPoint32($hDC, $T, StringLen($T), $Size) $iR = 30 $iG = 90 $iB = 90 Draw_Gradient($hDC, $iX, $iY, $iW, $iH, $iR, $iG, $iB) SetBkMode($hDC, $TRANSPARENT) If $bBtnDown Then ;~ SetTextColor(hDC,_RGB(255,0,0)) SetTextColor($hDC, Dec(0xFF0000)) TextOut($hDC, $XCtr-($Size.cx/2)+1, $YCtr-($Size.cy/2)+1, $T) Else ;~ SetTextColor(hDC,_RGB(0,0,255)) SetTextColor($hDC, Dec(0x0000FF)) TextOut($hDC, $XCtr-$Size.cx/2, $YCtr-$Size.cy/2, $T) EndIf EndPaint($hWnd, $ps) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_LBUTTONUP If $hWnd = $hCaptured Then ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, 0) Local $hParent = GetParent($hWnd) ;~ SendMessage(hParent,WM_COMMAND,MAKELONG(GetWindowLong(hWnd,GWL_ID), BN_CLICKED),Cast(LONG,hWnd)) DllCall("user32.dll", "LRESULT", "SendMessageW", _ "hwnd", $hParent, _ "uint", $WM_COMMAND, _ "WPARAM", _WinAPI_MakeLong(_WinAPI_GetWindowLong($hWnd, $GWL_ID), $BN_CLICKED), _ "LPARAM", $hWnd) EndIf ;~ EXIT FUNCTION Return 0 Case $WM_LBUTTONDOWN SetCapture($hWnd) $hCaptured = $hWnd $bBtnDown = True SetFocus($hWnd) InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION Return 0 Case $WM_MOUSEMOVE If $bBtnDown Then If IsMouseOver($hWnd) Then $bBtnDown = True InvalidateRect($hWnd, 0, False) ELSE ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) EndIf EndIf ;~ EXIT FUNCTION ;~ Return 0 Case $WM_MOVING ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 Case $WM_SIZE ReleaseCapture() $bBtnDown = False InvalidateRect($hWnd, 0, False) ;~ EXIT FUNCTION ;~ Return 0 EndSwitch ;~ Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam) Return DllCall("user32.dll", "lresult", "DefWindowProcW", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, _ "lparam", $lParam)[0] EndFunc ;~ SUB Draw_Gradient (hdc as HDC, x As Integer, y As integer, w As integer, h As Integer, r As integer, g As integer, b As integer) Func Draw_Gradient($hDC, $iX, $iY, $iW, $iH, $iR, $iG, $iB) ;~ DIM Vert(2) AS TRIVERTEX Local $Vert[2] $Vert[0] = DllStructCreate($_tagTrivertex) $Vert[1] = DllStructCreate($_tagTrivertex) ;~ DIM Rect AS GRADIENT_RECT Local $Rect = DllStructCreate($_tagGradient_Rect) ;~ Vert (0).x = 0 $Vert[0].x = 0 ;~ Vert (0).y = 0 $Vert[0].y = 0 ;~ Vert (0).Red = 65535-(65535-(r*256)) $Vert[0].Red = 65535-(65535-($iR*256)) ;~ Vert (0).Green = 65535-(65535-(g*256)) $Vert[0].Green = 65535-(65535-($iG*256)) ;~ Vert (0).Blue = 65535-(65535-(b*256)) $Vert[0].Blue = 65535-(65535-($iB*256)) ;~ Vert (0).Alpha = 0 $Vert[0].Alpha = 0 ;~ '****************************************************** ;~ Vert (1).x = w $Vert[1].x = $iW ;~ Vert (1).y = h/2 $Vert[1].y = $iH/2 ;~ Vert (1).Red = 65535-(65535-(255*256)) $Vert[1].Red = 65535-(65535-(255*256)) ;~ Vert (1).Green = 65535-(65535-(255*256)) $Vert[1].Green = 65535-(65535-(255*256)) ;~ Vert (1).Blue = 65535-(65535-(255*256)) $Vert[1].Blue = 65535-(65535-(255*256)) ;~ Vert (1).Alpha = 0 $Vert[1].Alpha = 0 ;~ '****************************************************** ;~ Rect.UpperLeft = 0 $Rect.UpperLeft = 0 ;~ Rect.LowerRight = 1 $Rect.LowerRight = 1 ;~ '****************************************************** ;~ Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) GradientFill($hDC, $Vert[0], 2, $Rect, 1, $GRADIENT_FILL_RECT_V) ;~ '****************************************************** ;~ Vert (0).x = 0 $Vert[0].x = 0 ;~ Vert (0).y = h/2 $Vert[0].y = $iH/2 ;~ Vert (0).Red = 65535-(65535-(255*256)) $Vert[0].Red = 65535-(65535-(255*256)) ;~ Vert (0).Green = 65535-(65535-(255*256)) $Vert[0].Green = 65535-(65535-(255*256)) ;~ Vert (0).Blue = 65535-(65535-(255*256)) $Vert[0].Blue = 65535-(65535-(255*256)) ;~ Vert (0).Alpha = 0 $Vert[0].Alpha = 0 ;~ '****************************************************** ;~ Vert (1).x = w $Vert[1].x = $iW ;~ Vert (1).y = h $Vert[1].y = $iH ;~ Vert (1).Red = 65535-(65535-(r*256)) $Vert[1].Red = 65535-(65535-($iR*256)) ;~ Vert (1).Green = 65535-(65535-(g*256)) $Vert[1].Green = 65535-(65535-($iG*256)) ;~ Vert (1).Blue = 65535-(65535-(b*256)) $Vert[1].Blue = 65535-(65535-($iB*256)) ;~ Vert (1).Alpha = 0 $Vert[1].Alpha = 0 ;~ '****************************************************** ;~ Rect.UpperLeft = 0 $Rect.UpperLeft = 0 ;~ Rect.LowerRight = 1 $Rect.LowerRight = 1 ;~ '****************************************************** ;~ Gradientfill(hdc,@Vert(0),2,@Rect,1,GRADIENT_FILL_RECT_V) GradientFill($hDC, $Vert[0], 2, $Rect, 1, $GRADIENT_FILL_RECT_V) ;~ END SUB EndFunc Func IsMouseOver($hWnd) Local $Rect = DllStructCreate($_tagRect) Local $Pt = DllStructCreate($_tagPoint) GetWindowRect ($hWnd, $Rect) GetCursorPos($Pt) Return PtInRect($Rect, $Pt) EndFunc Func _RGB($iR, $iG, $iB) Return ('0x' & Hex($iR, 2) & Hex($iG, 2) & Hex($iB, 2)) EndFunc Func _BGR($iB, $iG, $iR) Return ('0x' & Hex($iB, 2) & Hex($iG, 2) & Hex($iR, 2)) EndFunc Func InvalidateRect($hWnd, $tRECT = 0, $bErase = True) DllCall("user32.dll", "bool", "InvalidateRect", "hwnd", $hWnd, "struct*", $tRECT, "bool", $bErase) EndFunc Func SetFocus($hWnd) DllCall("user32.dll", "hwnd", "SetFocus", "hwnd", $hWnd) EndFunc Func PtInRect($tRect, $tPoint) Local $aRet = DllCall("user32.dll", "bool", "PtInRect", "ptr", DllStructGetPtr($tRect), "struct*", $tPoint) If IsArray($aRet) Then Return $aRet[0] Return False EndFunc Func GetWindowRect($hWnd, ByRef $tRect) DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $hWnd, "struct*", $tRect) EndFunc Func GetCursorPos(ByRef $tPoint) DllCall("user32.dll", "bool", "GetCursorPos", "struct*", $tPoint) EndFunc Func SetCapture($hWnd) DllCall("user32.dll", "hwnd", "SetCapture", "hwnd", $hWnd) EndFunc Func ReleaseCapture() DllCall("user32.dll", "bool", "ReleaseCapture") EndFunc Func SetTextColor($hDC, $iColor) DllCall("gdi32.dll", "INT", "SetTextColor", "handle", $hDC, "INT", $iColor) EndFunc Func BeginPaint($hWnd, ByRef $tPAINTSTRUCT) $tPAINTSTRUCT = DllStructCreate($tagPAINTSTRUCT) Local $aRet = DllCall('user32.dll', 'handle', 'BeginPaint', 'hwnd', $hWnd, 'struct*', $tPAINTSTRUCT) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc Func GetTextExtentPoint32($hDC, $sText, $iTextLen, ByRef $tSize) DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sText, "int", $iTextLen, "struct*", $tSize) EndFunc Func GradientFill($hDC, $tVertex, $nVertex, $tMesh, $nMesh, $ulMode) DllCall("Msimg32.dll", "BOOL", "GradientFill", _ "handle", $hDC, _ "struct*", $tVertex, _ "ulong", $nVertex, _ "struct*", $tMesh, _ "ulong", $nMesh, _ "ulong", $ulMode) EndFunc Func GetParent($hWnd) Local $aResult = DllCall("user32.dll", "hwnd", "GetParent", "hwnd", $hWnd) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func SetBkMode($hDC, $iBkMode) Local $aResult = DllCall("gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $iBkMode) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] EndFunc Func EndPaint($hWnd, ByRef $tPAINTSTRUCT) Local $aRet = DllCall('user32.dll', 'bool', 'EndPaint', 'hwnd', $hWnd, 'struct*', $tPAINTSTRUCT) If @error Then Return SetError(@error, @extended, False) Return $aRet[0] EndFunc Func GetClientRect($hWnd, ByRef $tRect) Local $aRet = DllCall("user32.dll", "bool", "GetClientRect", "hwnd", $hWnd, "struct*", $tRect) If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) Return $tRect EndFunc Func TextOut($hDC, $iX, $iY, $sText, $iTextLen = Default) If $iTextLen = Default Then $iTextLen = StringLen($sText) DllCall('gdi32.dll', 'bool', 'TextOutW', 'handle', $hDC, 'int', $iX, 'int', $iY, 'wstr', $sText, 'int', $iTextLen) EndFunc  
    • r0ash
      By r0ash
      Hey guys, MattDiesel over Stackoverflow mentioned this beautiful piece of code 
      #include <WindowsConstants.au3> #include <WinAPI.au3> Local $IDM_FONT = 33 Local $hWindow = WinGetHandle("Untitled - Notepad") _WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0) Local $hFontWin = WinWait("Font") $select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "") WinClose($hFontWin) MsgBox(0,"", $select) I realized that _WinAPI_PostMessage can trigger menu click event, even if Notepad is minimized.
      How do we know what is the decimal value of *any menu item or sub-menu item*? How we know "Format > Font" menu-item is 33 as wParam to _WinAPI_PostMessage()? Have a look at snapshot.
      Regards.

    • chacoya121
      By chacoya121
      plz help explain between GDI+ and Winapi, is it desktop inside another desktop, 3 layer dimension?
      i can't get the picture
      1. u get desktop u can visual see
      2. then u create GDI+ startup another desktop screen dimension?
      3. then u have Winapi command inside GDI+, is this another desktop screen dimension? cuz GDI+ could create bitmap that is one dimension? Winapi get windowDC also another dimension?
      plz help and explain, with picture would be nice, im not good with visualize ("dumb newbie"), still learning
      newbie to programming world
      thankyou.
    • IErrors
      By IErrors
      I am working on some functionality to detect whether a standard keyboard was used for input in my UI or if a barcode scanner (that acts like a keyboard) was used. Instead of dealing with a scanner SDK, I decided I would read from the raw input to get device info and make a determination.
      I discovered while testing with multiple UIs is that when the WM_INPUT message is received and the function called, the $hWnd param is always the same (apparently whatever handle I set the "hTarget" to in the RAWINPUTDEVICE struct).
      Is this normal behavior??
      Using the test code below, no matter what window you give input to the $hWnd param never changes.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISys.au3> $Form1 = GUICreate("Form 1", 300, 300, -1, 10) ConsoleWrite("$Form1 = " & $Form1 & @CRLF) $Edit1 = GUICtrlCreateEdit("", 0, 0, 300, 300) GUISetState(@SW_SHOW, $Form1) $Form2 = GUICreate("Form 2", 300, 300, -1, 350) ConsoleWrite("$Form2 = " & $Form2 & @CRLF) $Edit2 = GUICtrlCreateEdit("", 0, 0, 300, 300) GUISetState(@SW_SHOW, $Form2) GUIRegisterMsg($WM_INPUT, "WM_INPUT") ; https://msdn.microsoft.com/en-us/library/ms645590(v=vs.85).aspx $tRID = DllStructCreate($tagRAWINPUTDEVICE) ; https://msdn.microsoft.com/en-us/library/ms645565(v=vs.85).aspx DllStructSetData($tRID, "UsagePage", 1) DllStructSetData($tRID, "Usage", 6) DllStructSetData($tRID, "Flags", 0) DllStructSetData($tRID, "hTarget", $Form1) ; According to the struct def, if hTarget=NULL then it should follow keyboard focus. - nope :( $pRID = DllStructGetPtr($tRID) _WinAPI_RegisterRawInputDevices($pRID) ; https://msdn.microsoft.com/en-us/library/ms645600(v=vs.85).aspx Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) ConsoleWrite("hWnd = " & $hWnd & " | Title = " & WinGetTitle($hWnd) & @CRLF) ConsoleWrite("Active Window = " & WinGetTitle("[ACTIVE]") & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>WM_INPUT  
    • Adrian123
      By Adrian123
      Hi I need help with the code bellow, my goal is to make faster sqlite queries to Sqlite because _SQLite_GetTable2d seams to be slow on big tables.
      Thank you :
       
      https://www.autoitscript.com/forum/topic/182469-using-controls-to-edit-cells-in-a-listview/
       
      Well my code is faster but a I have 2 issues :
      1 Memory leaks
      2 Listview ( virtual) a little slow when scrolling (column headers delay )
      Please help I am not a WinApi specialist. (The hugetable its actuality much bigger I'm limited by upload size)
      Thank You.
       
      #comments-start C++ Source of Dll #include <vector> #include <string> #include <stdio.h> #include <string.h> #include "sqlite3.h" using namespace std; extern "C" { // A function adding two integers and returning the result char * SqliteSelect(char * path ,char * sSql , char * rowsep, char * tabsep ) { std::string rez=""; bool once=true; sqlite3 *db; if ( sqlite3_open_v2(path, &db,SQLITE_OPEN_READONLY, NULL) == SQLITE_OK) { sqlite3_stmt *stmt; if (sqlite3_prepare_v2(db, sSql, -1, &stmt, 0) == SQLITE_OK) { int nCols = sqlite3_column_count(stmt); while (sqlite3_step(stmt) == SQLITE_ROW) { for (int nCol = 0; nCol < nCols; nCol++) { if (once==true) { rez+=(char *) sqlite3_column_name(stmt, nCol); if (nCol < nCols-1 ) { rez+=tabsep; } else { rez+=rowsep; once=false; // sqlite3_reset(stmt); nCol=0; } } if (once==false){ if ( sqlite3_column_text(stmt, nCol)!=nullptr) { rez+=(char *) sqlite3_column_text(stmt, nCol); } if (nCol < nCols-1 ) rez+=tabsep; } } rez+=rowsep; } } else { return (char *)sqlite3_errmsg(db); sqlite3_close(db); } sqlite3_close(db); } char *cstr = new char[rez.length() + 1]; strcpy(cstr, rez.c_str()); return cstr; } char * SqliteExec(char * path ,char * sSql ) { std::string rez="Error: "; sqlite3 *db; char *error; if ( sqlite3_open_v2(path, &db,SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK) { sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL,&error); if( sqlite3_exec(db, sSql, NULL, NULL, &error) != SQLITE_OK ) { rez+= (char *)sqlite3_errmsg(db); sqlite3_exec(db, "ROLLBACK", NULL, NULL, &error); sqlite3_close(db); } sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &error); sqlite3_close(db); if (rez=="Error: " ) { rez="OK"; } char *cstr = new char[rez.length() + 1]; strcpy(cstr, rez.c_str()); return cstr; } } } #comments-end #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIvkeysConstants.au3> #include <WinAPIShellEx.au3> #include <GuiEdit.au3> Opt( "MustDeclareVars", 1 ) Global $hListView, $iItem = -1, $iSubItem = 0, $aRect Global $idComboOpen, $idComboClose, $bComboOpen = False, $bComboDoNotOpen = False Global $bEditEscape = True, $bEditUpDown = False, $bListboxOpen = False Global $bComboOpenOnEnter = True Global $bComboOpenOnSpace = False Global $bComboOpenOnDoubleClick = True Global $bListboxAcceptClickEnter = True Global $hEdit ;Global $Table Func __SQLite_StringToUtf8Struct($sString) Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _ "ptr", 0, "int", 0, "ptr", 0, "ptr", 0) If @error Then Return SetError(1, @error, "") ; DllCall error Local $tText = DllStructCreate("char[" & $aResult[0] & "]") $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _ "struct*", $tText, "int", $aResult[0], "ptr", 0, "ptr", 0) If @error Then Return SetError(2, @error, "") ; DllCall error Return $tText EndFunc ;==>__SQLite_StringToUtf8Struct Global $Headers ,$RowsArray Global $TabSep =@TAB Example() Func Compare_Headers($ArrayIni,$Array_) If UBound($ArrayIni)<> UBound($Array_) Then Return 1 EndIf For $R=0 to UBound($ArrayIni)-1 if $ArrayIni[$R] <> $Array_[$R] Then Return 1 EndIf Next Return 0 EndFunc #include <File.au3> Func nCheckDB( $sDBname , $SSQL , $idListView ) Local $iniH =$Headers; GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT,0, 0) Local $RowSep =@LF Local $tFilename = __SQLite_StringToUtf8Struct($sDBname) Local $tSsql = __SQLite_StringToUtf8Struct($SSQL ) Local $hDLL = DllOpen("libSlqiteFaster.dll") Local $Arrx = DllCall($hDLL,"STR" ,"SqliteSelect", "struct*", $tFilename ,"struct*" ,$tSsql ,"struct*" ,__SQLite_StringToUtf8Struct($RowSep) ,"struct*" ,__SQLite_StringToUtf8Struct($TabSep) ) DllClose($hDLL) $RowsArray= StringSplit($Arrx[0],$RowSep) $Headers=StringSplit($RowsArray[1],$TabSep) Local $iCols = $Headers[0] Local $iRows = $RowsArray[0] If Compare_Headers( $iniH,$Headers)=1 Then While _GUICtrlListView_GetColumnCount($idListView)>0 _GUICtrlListView_DeleteColumn ( $idListView, 0 ) WEnd For $i = 1 To $iCols _GUICtrlListView_AddColumn( $idListView,$Headers[ $i ], 75 ) Next EndIf GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $iRows-2, 0 ) ;$RowsArray=0 ;$Headers=0 $iRows=0 $iCols=0 $tFilename=0 $tSsql=0 EndFunc Func Example() Local $hGui = GUICreate( "LV_", @DesktopWidth-20, @DesktopHeight-40,-1,-1, $WS_SIZEBOX+$WS_MAXIMIZEBOX+ $WS_MINIMIZEBOX ) Global $Button3 = GUICtrlCreateButton("Ne3", 400, 0, 75, 25) Global $Button1 = GUICtrlCreateButton("NeSmler", 100, 0, 75, 25) Local $idListView Local $pListViewCallback Local $pEditCallback Local $pListCommand Local $pGuiCallback ;MsgBox(0,"","STOP") $idListView= GUICtrlCreateListView( "", 10, 40, @DesktopWidth-20-20, @DesktopHeight-80-100,$LVS_OWNERDATA ) ;$LVS_NOCOLUMNHEADER _GUICtrlListView_SetExtendedListViewStyle( $idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT,$LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES) ) ; $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT + GUICtrlSetResizing($hGui, $GUI_DOCKBORDERS) $hListView = GUICtrlGetHandle( $idListView ) ; Subclass ListView to handle messages related to ComboBox ; ComboBox open and close events $idComboOpen = GUICtrlCreateDummy() $idComboClose = GUICtrlCreateDummy() GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) ; Subclass callback functions $pListViewCallback= DllCallbackGetPtr( DllCallbackRegister( "ListViewCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) $pEditCallback = DllCallbackGetPtr( DllCallbackRegister( "EditCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) $pListCommand = DllCallbackGetPtr( DllCallbackRegister( "ListCommand", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) $pGuiCallback = DllCallbackGetPtr( DllCallbackRegister( "GuiCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) _WinAPI_SetWindowSubclass( $hListView, $pListViewCallback, 9998, 0 ) ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $Button3 GuiSetState(@SW_LOCK, $hGui) nCheckDB("bigtable.sqlite" ,"SELECT * FROM hugetable;",$idListView ) GuiSetState(@SW_UNLOCK, $hGui) Case $Button1 GuiSetState(@SW_LOCK, $hGui) For $i = 0 To _GUICtrlListView_GetColumnCount($idListView)-1 _GUICtrlListView_SetColumnWidth ( $hListView, $i, $LVSCW_AUTOSIZE_USEHEADER ) ;$LVSCW_AUTOSIZE Next GuiSetState(@SW_UNLOCK, $hGui) #cs Local $S_PH = "C:\\Users\\achis\\Desktop\\PP2C 24.11.2015_OK\\Prod.sqlite" Local $SSQLi ="UPDATE sumbomLVL_Static Set part='10000611' WHERE rowid=1 ;" Local $hDLL = DllOpen("libSlqiteFaster.dll") Local $Arrx = DllCall($hDLL,"STR" ,"SqliteExec", "struct*", __SQLite_StringToUtf8Struct($S_PH) ,"struct*" ,__SQLite_StringToUtf8Struct($SSQLi) ) MsgBox ( 0,"",$Arrx[0]) DllClose($hDLL) #ce Case $idComboOpen If $bComboOpen Then ; If another ComboBox is open then delete it _WinAPI_RemoveWindowSubclass( $hEdit, $pEditCallback, 9999 ) ;_WinAPI_RemoveWindowSubclass( $hListView, $pListCommand, 9999 ) _WinAPI_RemoveWindowSubclass( $hGui, $pGuiCallback, 9999 ) _GUICtrlEdit_Destroy( $hEdit ) EndIf $hEdit = _GUICtrlEdit_Create( $hListView,_GUICtrlListView_GetItemText( $hListView, $iItem, $iSubItem ), $aRect[0], $aRect[1], $aRect[2] - $aRect[0],20,$ES_AUTOHSCROLL ) _GUICtrlEdit_SetSel( $hEdit, 0, -1 ) ; Create subclasses to handle Windows messages _WinAPI_SetWindowSubclass( $hEdit, $pEditCallback, 9999, 0 ) ; Messages from the Edit control of the ComboBox ;_WinAPI_SetWindowSubclass( $hListView, $pListCommand, 9999, 0 ) ; WM_COMMAND messages from Listbox part of ComboBox _WinAPI_SetWindowSubclass( $hGui, $pGuiCallback, 9999, 0 ) ; Handle GUI messages related to ComboBox control ; Set focus to ComboBox ; Subclasses are used only when ComboBox is open _WinAPI_SetFocus( $hEdit ) $bComboOpen = True Case $idComboClose If Not $bComboOpen Then ContinueLoop If GUICtrlRead( $idComboClose ) Then Local $c_item = StringSplit($RowsArray[$iItem+2],$TabSep)[$iSubItem+1] Local $T = StringSplit( $RowsArray[$iItem+2],$TabSep) $T[$iSubItem] =_GUICtrlEdit_GetText( $hEdit ) $RowsArray[$iItem+2]=_ArrayToString($T,$TabSep) _WinAPI_SetFocus( $hListView ) ; Set focus to ListView EndIf ; Delete ComboBox control _WinAPI_RemoveWindowSubclass( $hEdit, $pEditCallback, 9999 ) ;_WinAPI_RemoveWindowSubclass( $hListView, $pListCommand, 9999 ) _WinAPI_RemoveWindowSubclass( $hGui, $pGuiCallback, 9999 ) _GUICtrlEdit_Destroy( $hEdit ) $bComboOpen = False Case $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_SECONDARYDOWN If Not $bComboOpen Then ContinueLoop ; Clicks in Listbox part of ComboBox should not delete it If $bListboxOpen Then ContinueLoop ; Clicks in Edit part of ComboBox should not delete it Local $aPos = MouseGetWindowPos( $hListView ) If Not ( $aPos[0] > $aRect[0] And $aPos[0] < $aRect[2] And $aPos[1] > $aRect[1] And $aPos[1] < $aRect[1] + 20 ) Then GUICtrlSendToDummy( $idComboClose ) ; Delete ComboBox Local $aSize = WinGetPos( $hListView ) If $aPos[0] > 0 And $aPos[1] > 0 And $aPos[0] < $aSize[2] And $aPos[1] < $aSize[3] Then _ _WinAPI_SetFocus( $hListView ) ; Set focus to ListView if mouse click is inside ListView EndIf Case $GUI_EVENT_CLOSE Exit If Not $bEditEscape Then ExitLoop $bEditEscape = False EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam ) Local Static $bNotXP = Not ( @OSVersion = "WIN_XP" ) Local Static $tRect = DllStructCreate( $tagRECT ) Local Static $hBrush = _WinAPI_CreateSolidBrush( 0xFFFF00 ) Local Static $tText = DllStructCreate( "wchar[50]" ) Local Static $pText = DllStructGetPtr( $tText ) Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Local $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_GETDISPINFOW Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) ; $LV_DISPINFO *lpdi = ($LV_DISPINFO *)$lParam; If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" ) Local $Subindex = DllStructGetData($tNMLVDISPINFO,"SubItem") Local $sItem = StringSplit($RowsArray[$iIndex+2],$TabSep)[$Subindex+1] ; $aResult[$iIndex][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) EndIf Case $NM_CUSTOMDRAW Local $tNMLVCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Specifies the drawing stage ; Stage 1 Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Stage 2 will be carried out ; Stage 2 Case $CDDS_ITEMPREPAINT ; Before an item is painted If Not _GUICtrlListView_GetItemState( $hListView, DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ), $LVIS_FOCUSED ) Then Return $CDRF_NEWFONT ; Default drawing of item $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) Return $CDRF_NOTIFYSUBITEMDRAW ; Stage 3 will be carried out ; Stage 3 Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before a subitem is painted Return $CDRF_NOTIFYPOSTPAINT ; Stage 4 will be carried out ; Stage 4 Case BitOR( $CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM ) ; After a subitem has been painted If DllStructGetData( $tNMLVCustomDraw, "iSubItem" ) = $iSubItem Then Local $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" ) ; Device context $aRect = _GUICtrlListView_GetSubItemRect( $hListView, $iItem, $iSubItem ) ; Subitem rectangle $aRect[2] = $aRect[0] + _GUICtrlListView_GetColumnWidth( $hListView, $iSubItem ) DllStructSetData( $tRect, "Left", $aRect[0]+4 ) DllStructSetData( $tRect, "Top", $aRect[1] ) DllStructSetData( $tRect, "Right", $aRect[2] ) DllStructSetData( $tRect, "Bottom", $aRect[3] ) _WinAPI_FillRect( $hDC, $tRect, $hBrush ) ; Fill subitem background _WinAPI_SetTextColor( $hDC, 0x000000 ) ; Set black text color DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + 2 ) ; Adjust rectangle If $bNotXP Then DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 2 ) _WinAPI_DrawText( $hDC, StringSplit($RowsArray[$iItem+2],$TabSep)[$iSubItem+1], $tRect, $DT_WORD_ELLIPSIS ) ; Draw text EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch Case $NM_CLICK If Not $bComboDoNotOpen And Not $bComboOpenOnDoubleClick And $iItem > -1 And $iSubItem > -1 Then _ GUICtrlSendToDummy( $idComboOpen ) ; Send message to open ComboBox Case $NM_DBLCLK If $bComboOpenOnDoubleClick And $iItem > -1 And $iSubItem > -1 Then _ GUICtrlSendToDummy( $idComboOpen ) ; Send message to open ComboBox EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ; Handle ListView messages related to ComboBox Func ListViewCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) Switch $iMsg ; Open ComboBox on Enter key Case $WM_GETDLGCODE Switch $wParam Case $VK_RETURN If Not $bComboDoNotOpen And $bComboOpenOnEnter And $iItem > -1 And $iSubItem > -1 Then _GUICtrlListView_SetItemSelected( $hListView, -1, False ) _GUICtrlListView_SetItemSelected( $hListView, $iItem ) GUICtrlSendToDummy( $idComboOpen ) EndIf EndSwitch ; Manage multiple selections ; Prevent ComboBox from opening ; Manage keyboard events Case $WM_KEYDOWN Switch $wParam Case $VK_SHIFT, $VK_CONTROL $bComboDoNotOpen = True ; Manage keyboard events Case $VK_LEFT If Not $bComboDoNotOpen And $iSubItem > 0 Then $iSubItem -= 1 _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem ) Case $VK_RIGHT If Not $bComboDoNotOpen And $iSubItem < _GUICtrlListView_GetColumnCount( $hListView ) - 1 Then $iSubItem += 1 _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem ) Case $VK_SPACE If Not $bComboDoNotOpen And $bComboOpenOnSpace And $iItem > -1 And $iSubItem > -1 Then _GUICtrlListView_SetItemSelected( $hListView, -1, False ) GUICtrlSendToDummy( $idComboOpen ) EndIf EndSwitch Case $WM_KEYUP Switch $wParam Case $VK_SHIFT, $VK_CONTROL $bComboDoNotOpen = False EndSwitch ; Left click in ListView ; Sent on single and double click ; Determines item/subitem of the cell that's clicked Case $WM_LBUTTONDOWN Local $aHit = _GUICtrlListView_SubItemHitTest( $hListView ) If $bComboOpen Then ; If another ComboBox is open then delete it _GUICtrlEDIT_Destroy( $hEdit ) GUICtrlSendToDummy( $idComboClose ) _WinAPI_SetFocus( $hListView ) EndIf If $aHit[0] > -1 And $aHit[1] > -1 Then $iItem = $aHit[0] $iSubItem = $aHit[1] _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem ) EndIf ; Delete ComboBox on right click in ListView and on left ; or right click in non-client ListView area (Scrollbars). Case $WM_RBUTTONDOWN, $WM_NCLBUTTONDOWN, $WM_NCRBUTTONDOWN _GUICtrlEDIT_Destroy( $hEdit ) GUICtrlSendToDummy( $idComboClose ) _WinAPI_SetFocus( $hListView ) EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc ; Messages from the Edit control of the ComboBox Func EditCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) Switch $iMsg ; Dialog codes Case $WM_GETDLGCODE Switch $wParam Case $VK_TAB ; Close GUICtrlSendToDummy( $idComboClose, True ) Case $VK_RETURN ; Accept and close GUICtrlSendToDummy( $idComboClose, True ) Case $VK_ESCAPE ; Close GUICtrlSendToDummy( $idComboClose, True ) _WinAPI_SetFocus( $hListView ) $bEditEscape = True EndSwitch ; Double click in Edit part of ComboBox Case $WM_LBUTTONDBLCLK Local $aPos = MouseGetWindowPos( $hListView ) If $aPos[0] > $aRect[0] And $aPos[0] < $aRect[2] And $aPos[1] > $aRect[1] And $aPos[1] < $aRect[1] + 20 Then _ GUICtrlSendToDummy( $idComboClose, True ) ; Accept and close EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc ; Handle GUI messages related to ComboBox control Func GuiCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData ) Switch $iMsg ; Delete ComboBox on left or right mouse click in non-client GUI area and on GUI deactivate Case $WM_NCLBUTTONDOWN, $WM_NCRBUTTONDOWN, $WM_ACTIVATE _GUICtrlEDIT_Destroy( $hEdit ) GUICtrlSendToDummy( $idComboClose ) EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] #forceref $iSubclassId, $pData EndFunc ; Get mouse pos relative to window Func MouseGetWindowPos( $hWindow ) Local $aPos = MouseGetPos() Local $tPoint = DllStructCreate( "int X;int Y" ) DllStructSetData( $tPoint, "X", $aPos[0] ) DllStructSetData( $tPoint, "Y", $aPos[1] ) _WinAPI_ScreenToClient( $hWindow, $tPoint ) $aPos[0] = DllStructGetData( $tPoint, "X" ) $aPos[1] = DllStructGetData( $tPoint, "Y" ) Return $aPos EndFunc  
       
       
       
      OnefolderWorking.zip