Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/28/2018 in all areas

  1. In Fast subclassing through compiled code a WM_NOTIFY message handler is implemented in C/C++. Is it possible to implement the entire window procedure (main message handler) in compiled code and thus avoid the overhead associated with the subclassing technique? AutoIt code This is a slightly modified version of _WinAPI_RegisterClassEx example, and a listview is created in the window (ListView0.au3): #include <WinAPIRes.au3> #include <WinAPISys.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $bExit = False Global $iRows = 100, $iCols = 8 Example() Func Example() Local Const $sClass = "MyWindowClass" Local Const $sName = "Ordinary ListView" ; Get module handle for the current process Local $hInstance = _WinAPI_GetModuleHandle( 0 ) ; Create a class cursor Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW ; Create a class icons (large and small) Local $tIcons = DllStructCreate( "ptr;ptr" ) _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 ) Local $hIcon = DllStructGetData( $tIcons, 1 ) Local $hIconSm = DllStructGetData( $tIcons, 2 ) ; Create DLL callback function (window procedure) Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) ) ; Create and fill $tagWNDCLASSEX structure Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" ) DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) ) DllStructSetData( $tWCEX, "Style", 0 ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) DllStructSetData( $tWCEX, "ClsExtra", 0 ) DllStructSetData( $tWCEX, "WndExtra", 0 ) DllStructSetData( $tWCEX, "hInstance", $hInstance ) DllStructSetData( $tWCEX, "hIcon", $hIcon ) DllStructSetData( $tWCEX, "hCursor", $hCursor ) DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) ) DllStructSetData( $tWCEX, "MenuName", 0 ) DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) ) DllStructSetData( $tWCEX, "hIconSm", $hIconSm ) DllStructSetData( $tWCEX, "szClassName", $sClass ) ; Register a window class _WinAPI_RegisterClassEx( $tWCEX ) ; Create a window Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 ) ; Create listview Local $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 _GUICtrlListView_AddItem( $hListView, "Row " & $i ) For $j = 1 To $iCols - 1 _GUICtrlListView_AddSubItem( $hListView, $i, "Col " & $j, $j ) Next Next ; Main loop While Sleep(10) If $bExit Then ExitLoop WEnd ; Unregister window class and release unnecessary resources _WinAPI_UnregisterClass( $sClass, $hInstance ) _WinAPI_DestroyCursor( $hCursor ) _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DestroyIcon( $hIconSm ) EndFunc Func WinProc( $hWnd, $iMsg, $wParam, $lParam ) Switch $iMsg Case $WM_CLOSE $bExit = True EndSwitch Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam ) EndFunc It's left for Windows to handle all listview messages. No new code is added to WinProc() function. In the next example the listview is replaced by a virtual and custom drawn listview. Now it's necessary to handle LVN_GETDISPINFO and NM_CUSTOMDRAW notifications in WinProc() function (ListView1.au3): ; Create listview $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT+$LVS_OWNERDATA-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aItems[$i][$j] = $i & "/" & $j Next Next ; ListView colors Local $aLVColors = [ 0xCCCCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFFCC, 0xFFCCCC, 0xFFCCFF ] ; BGR For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aColors[$i][$j] = $aLVColors[Random( 0,5,1 )] Next Next ; Set number of rows in virtual ListView DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_SETITEMCOUNT, "wparam", $iRows, "lparam", 0 ) WinProc() function: Func WinProc( $hWnd, $iMsg, $wParam, $lParam ) Local Static $tText = DllStructCreate( "wchar[100]" ), $pText = DllStructGetPtr( $tText ) Local Static $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ) Switch $iMsg Case $WM_NOTIFY Switch DllStructGetData( DllStructCreate( $tagNMHDR, $lParam ), "Code" ) Case $LVN_GETDISPINFOW ; Fill virtual listview Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam ) If Not BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then Return Local $sItem = $aItems[DllStructGetData($tNMLVDISPINFO,"Item")][DllStructGetData($tNMLVDISPINFO,"SubItem")] DllStructSetData( $tText, 1, $sItem ) DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) ) DllStructSetData( $tNMLVDISPINFO, "Text", $pText ) Return Case $NM_CUSTOMDRAW ; Draw back colors Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ), $iItem Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any subitem-related drawing operations Case $CDDS_ITEMPREPAINT + $CDDS_SUBITEM ; Before painting a subitem $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) If DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_GETITEMSTATE, "wparam", $iItem, "lparam", $LVIS_SELECTED )[0] Then Return $CDRF_NOTIFYPOSTPAINT ; Selected item DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", $aColors[$iItem][DllStructGetData($tNMLVCUSTOMDRAW,"iSubItem")] ) ; Normal item Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors Case $CDDS_ITEMPOSTPAINT + $CDDS_SUBITEM ; After painting a subitem Local $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" ) ; Subitem rectangle $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) Local $iSubItem = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem" ) DllStructSetData( $tRect, "Left", $LVIR_LABEL ) DllStructSetData( $tRect, "Top", $iSubItem ) DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_GETSUBITEMRECT, "wparam", $iItem, "lparam", $pRect ) DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + 2 ) DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 1 ) DllStructSetData( $tRect, "Right", DllStructGetData( $tRect, "Right" ) - 2 ) DllStructSetData( $tRect, "Bottom", DllStructGetData( $tRect, "Bottom" ) - 1 ) ; Subitem back color Local $hBrush = DllCall( "gdi32.dll", "handle", "CreateSolidBrush", "int", $aColors[$iItem][$iSubItem] )[0] ; _WinAPI_CreateSolidBrush DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrush ) ; _WinAPI_FillRect DllCall( "gdi32.dll", "bool", "DeleteObject", "handle", $hBrush ) ; _WinAPI_DeleteObject ; Draw subitem text DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 1 ) DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int", 0 ) ; _WinAPI_SetTextColor DllCall( "gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT ) ; _WinAPI_SetBkMode DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aItems[$iItem][$iSubItem], "int", -1, "struct*", $tRect, "uint", $DT_CENTER ) ; _WinAPI_DrawText Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Case $WM_CLOSE $bExit = True EndSwitch Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam ) EndFunc Also in this example there is a problem with the speed of the WM_NOTIFY code. You can provoke an error this way: Click a row in the listview (not one of the very top rows). Press Shift+Down arrow to select multiple rows. The problem will arise after just a few rows. Press Ctrl+Break in SciTE to stop the code. Note that since the window isn't created with GUICreate(), it's not possible to use any of the native functions in the GUI Management section of the help file. But all the UDFs in the GUI Reference section can be used. C/C++ code The window procedure above is defined this way: ; Create DLL callback function (window procedure) Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) The C/C++ definition of a window procedure in a dll-file looks like this: LRESULT CALLBACK __stdcall WinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) We can get a pointer to the window procedure this way: Local $hModule = _WinAPI_LoadLibrary( "WinProc.dll" ) Local $pWinProc = _WinAPI_GetProcAddress( $hModule, "WinProc" ) Now we can use this pointer in $tWCEX struct. We also need to pass $aItems and $aColors arrays to the compiled code in the dll-file. But we already know how to do that. Note that because $pWinProc is used directly in $tWCEX struct, we can avoid both the DllCall and DllCallAddress commands. Thus, we avoid a severe overhead in relation to these commands (that the AutoIt code interpreter should interpret a code line for each message (for a huge number of messages), and that DllCall and DllCallAddress are complicated and time-consuming commands). AutoIt code in ListView2.au3: #include <WinAPIRes.au3> #include <WinAPISys.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include "AccArrays.au3" Global $aData[3] ; $psaItems, $psaColors, $pExit Example() Func Example() Local Const $sClass = "MyWindowClass", $sName = "Virtual and Custom Drawn ListView" Local $iRows = 10000, $iCols = 8, $aItems[$iRows][$iCols], $aColors[$iRows][$iCols] ; Get module handle for the current process Local $hInstance = _WinAPI_GetModuleHandle( 0 ) ; Create a class cursor Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW ; Create a class icons (large and small) Local $tIcons = DllStructCreate( "ptr;ptr" ) _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 ) Local $hIcon = DllStructGetData( $tIcons, 1 ) Local $hIconSm = DllStructGetData( $tIcons, 2 ) ; Create DLL callback function (window procedure) Local $hModule = _WinAPI_LoadLibrary( @AutoItX64 ? "WinProc_x64.dll" : "WinProc.dll" ) Local $pWinProc = _WinAPI_GetProcAddress( $hModule, "WinProc" ) ; Create and fill $tagWNDCLASSEX structure Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" ) DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) ) DllStructSetData( $tWCEX, "Style", 0 ) DllStructSetData( $tWCEX, "hWndProc", $pWinProc ) DllStructSetData( $tWCEX, "ClsExtra", 0 ) DllStructSetData( $tWCEX, "WndExtra", 0 ) DllStructSetData( $tWCEX, "hInstance", $hInstance ) DllStructSetData( $tWCEX, "hIcon", $hIcon ) DllStructSetData( $tWCEX, "hCursor", $hCursor ) DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) ) DllStructSetData( $tWCEX, "MenuName", 0 ) DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) ) DllStructSetData( $tWCEX, "hIconSm", $hIconSm ) DllStructSetData( $tWCEX, "szClassName", $sClass ) ; Register a window class _WinAPI_RegisterClassEx( $tWCEX ) ; Create a window Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 ) ; Create listview Local $hListView = _GUICtrlListView_Create( $hWnd, "", 10, 10, 800, 538, $LVS_DEFAULT+$LVS_OWNERDATA-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $hListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) ; Add columns For $i = 0 To $iCols - 1 _GUICtrlListView_AddColumn( $hListView, "Col " & $i, 96, 2 ) ; 2 = Centered text Next ; ListView items For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aItems[$i][$j] = $i & "/" & $j Next Next ; ListView colors Local $aLVColors = [ 0xCCCCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFFCC, 0xFFCCCC, 0xFFCCFF ] ; BGR For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $aColors[$i][$j] = $aLVColors[Random( 0,5,1 )] Next Next ; Load dll-file Local $hDll = DllOpen( @AutoItX64 ? "WinProc_x64.dll" : "WinProc.dll" ) ; $aItems, $aColors and $bExit Local $psaItemsData, $psaColorsData, $bExit = False $aData[2] = DllStructGetPtr( DllStructCreate( $tagVARIANT ) ) AccArrays03( Copy, $aItems, $aColors, $bExit ) SafeArrayAccessData( $aData[0], $psaItemsData ) SafeArrayAccessData( $aData[1], $psaColorsData ) ; Pass data to compiled code DllCall( $hDll, "none", "PassData", "hwnd", $hListView, "int", $iCols, "ptr", $psaItemsData, "ptr", $psaColorsData, "ptr", $aData[2] ) ; Set number of rows in virtual ListView DllCall( "user32.dll", "lresult", "SendMessageW", "hwnd", $hListView, "uint", $LVM_SETITEMCOUNT, "wparam", $iRows, "lparam", 0 ) ; Main loop While Sleep(10) If DllStructGetData( DllStructCreate( "short", $aData[2] + 8 ), 1 ) Then ExitLoop WEnd ; Unregister window class and release unnecessary resources _WinAPI_UnregisterClass( $sClass, $hInstance ) _WinAPI_DestroyCursor( $hCursor ) _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DestroyIcon( $hIconSm ) SafeArrayUnaccessData( $aData[0] ) SafeArrayUnaccessData( $aData[1] ) _WinAPI_FreeLibrary( $hModule ) DllClose( $hDLL ) EndFunc ; Copy internal AutoIt variants (variables) to real Windows ; variants, that can be accessed from both AutoIt and C/C++. Func Copy( $pvItems, $pvColors, $pvExit ) SafeArrayCopy( DllStructGetData( DllStructCreate( "ptr", $pvItems + 8 ), 1 ), $aData[0] ) SafeArrayCopy( DllStructGetData( DllStructCreate( "ptr", $pvColors + 8 ), 1 ), $aData[1] ) VariantCopy( $aData[2], $pvExit ) EndFunc C/C++ code: #include <Windows.h> #include <CommCtrl.h> #include <OleAuto.h> // Globals HWND g_hListView; int g_iColumns; VARIANT* g_psaItems; VARIANT* g_psaColors; VARIANT* g_pExit; void __stdcall PassData( HWND hListView, int iColumns, VARIANT* psaItems, VARIANT* psaColors, VARIANT* pExit ) { g_hListView = hListView; g_iColumns = iColumns; g_psaItems = psaItems; g_psaColors = psaColors; g_pExit = pExit; } LRESULT CALLBACK __stdcall WinProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { NMLVDISPINFOW* plvdi; NMLVCUSTOMDRAW* plvcd; BSTR pBstr; DWORD_PTR iItem; RECT r; HBRUSH hBrush; switch ( uMsg ) { case WM_NOTIFY: switch ( ((LPNMHDR)lParam)->code ) { case LVN_GETDISPINFOW: // Fill virtual listview plvdi = (NMLVDISPINFOW*)lParam; if ( ( plvdi->item.mask & LVIF_TEXT ) == 0 ) return TRUE; pBstr = g_psaItems[plvdi->item.iItem*g_iColumns+plvdi->item.iSubItem].bstrVal; plvdi->item.pszText = pBstr; plvdi->item.cchTextMax = SysStringLen( pBstr ); return TRUE; case NM_CUSTOMDRAW: // Draw back colors plvcd = (NMLVCUSTOMDRAW*)lParam; switch ( plvcd->nmcd.dwDrawStage ) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: iItem = plvcd->nmcd.dwItemSpec; if ( SendMessageW( g_hListView, LVM_GETITEMSTATE, iItem, LVIS_SELECTED ) ) return CDRF_NOTIFYPOSTPAINT; plvcd->clrTextBk = g_psaColors[iItem*g_iColumns+plvcd->iSubItem].intVal; return CDRF_NEWFONT; case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Subitem rectangle iItem = plvcd->nmcd.dwItemSpec; r.left = LVIR_LABEL; r.top = plvcd->iSubItem; SendMessageW( g_hListView, LVM_GETSUBITEMRECT, iItem, (LPARAM)&r ); r.left += 2; r.right -= 2; r.top += 1; r.bottom -= 1; // Subitem back color hBrush = CreateSolidBrush( g_psaColors[iItem*g_iColumns+plvcd->iSubItem].intVal ); FillRect( plvcd->nmcd.hdc, &r, hBrush ); DeleteObject( hBrush ); // Draw subitem text SetTextColor( plvcd->nmcd.hdc, 0 ); SetBkMode( plvcd->nmcd.hdc, TRANSPARENT ); pBstr = g_psaItems[iItem*g_iColumns+plvcd->iSubItem].bstrVal; r.top += 1; DrawTextW( plvcd->nmcd.hdc, pBstr, SysStringLen( pBstr ), &r, DT_CENTER ); return CDRF_NEWFONT; } default: return DefWindowProcW( hWnd, uMsg, wParam, lParam ); } case WM_CLOSE: g_pExit->boolVal = 1; default: return DefWindowProcW( hWnd, uMsg, wParam, lParam ); } return 0; } Zip-file ListView0.au3 and ListView1.au3 is pure AutoIt code. In ListView2.au3 the window procedure is replaced with compiled code. Note that the zip-file contains two small dll-files. If you are using Microsoft SmartScreen or Microsoft Windows Defender, there is a likelihood of fake virus detection, even if the dll-files are created with Microsoft Visual Studio. Most other antivirus products will not detect fake viruses. You need AutoIt 3.3.12 or later. Tested on Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. WinProc.7z
    2 points
  2. water

    PowerPoint UDF

    Version 1.5.0.0

    1,391 downloads

    Extensive library to control and manipulate Microsoft PowerPoint. Threads: Help & Support, Wiki BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort
    1 point
  3. This started from the Uten's Scintilla example, but I added some functionality to it. Now it looks like Notepad. And the most important - it has SYNTAX HIGHLIGHTING for: *.au3,*.bat;*.cmd;*.html;*.htm;*.php;*.properties;*.ini;*.inf;*.reg;*.url;*.cfg;*.cnf;*.aut.... more are comming.... - you can define your own styles for the highlighter - shows Line numbers - has Code folding - find/replace with regular expressions The SciLexer.dll MUST be in the PATH or in the script dir. You can download it from The latest version is here http://scintilla.sourceforge.net/ Screenshots: INI Highlighter, AU3 Highlighter, PHP Highlighter Here is the script: Update 07.02.2007:sciteit.au3(previous downloads: 66) - completed the find/replace functions (regular expressions are supported) This file is also required:scintilla.h.au3 (this is Scintilla.h converted to au3 format) The highlighters style definitions: highlighter.au3.txt - for AU3 files highlighter.bat.txt - for BAT files highlighter.html.txt - for HTML/PHP files (It is not fully complete, but works for PHP/HTML) highlighter.ini.txt - for INI/INF/CFG/PROPERTIES files highlighter.txt.txt - for plain text
    1 point
  4. _PPT_SlideShow returns a SlideShow object. You could then query the State in a loop until the SlideShow has finished (untested): $oSlideShow = _PPT_SlideShow(...) Global Const $ppSlideShowDone = 5 ; Done While $oSlideShow.View.State <> $ppSlideShowDone Sleep(1000) ; check every second WEnd ; Exit or shutdown here Or the Application.SlideShowEnd event should be used.
    1 point
  5. Jos

    autoit-v3-setup.exe problem

    Yea right .... let me see in the company directory where the hell that IP department is and will notify them. Seriously, what the hell do you really expect when 1 out of the 66 check returns a positive? Just inform them instead of us. Jos
    1 point
  6. Shoot.. sorry about that, no idea where I copied that from but I have now copied the correct file to Dev. Thanks for letting me know.
    1 point
  7. Hi AlienStar Execute() should do it : $eq_inp = "5+1" $equation = Execute($eq_inp) Msgbox(0, "", $equation) ; displays 6
    1 point
  8. Made this some time ago, for shutdown. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Resources\Clock.ico #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Res_Icon_Add=Resources\Clock.ico #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> Opt("TrayAutoPause", 0) Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Time4Shutdown", 395, 32, 250, 475, -1, $WS_EX_DLGMODALFRAME) GUISetOnEvent($GUI_EVENT_CLOSE, "Close") $settime = GUICtrlCreateInput("", 168, 5, 49, 21) $Label1 = GUICtrlCreateLabel("Set time for shutdown in minutes", 8, 8, 156, 17) $Button1 = GUICtrlCreateButton("Start", 234, 3, 75, 25) GUICtrlSetOnEvent($Button1, "Start") $Button2 = GUICtrlCreateButton("Reboot", 314, 3, 75, 25) GUICtrlSetOnEvent($Button2, "Reboot") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func Start() GUISetState(@SW_HIDE) $time = GUICtrlRead($settime, 1) $timetosleep = $time * 60 Do ToolTip($timetosleep & ' Seconds Remanining', 300, 0) Sleep(995) $timetosleep -= 1 Until $timetosleep <= 0 ToolTip("") Shutdown(13) Exit EndFunc ;==>Start Func Reboot() Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(4164, "Notice", "Do you really want to reboot?") Select Case $iMsgBoxAnswer = 6 ;Yes Case $iMsgBoxAnswer = 7 ;No EndSelect If $iMsgBoxAnswer = 6 Then MsgBox(4096, "Notice", "Clicked Yes! Going to reboot") Shutdown(6) ElseIf $iMsgBoxAnswer = 7 Then MsgBox(4096, "Notice", "Clicked No! Aborting reboot") EndIf EndFunc ;==>Reboot Func Close() Exit EndFunc ;==>Close Do Sleep(100) Until $Form1 = $GUI_EVENT_CLOSE
    1 point
  9. TheDcoder

    Backup file modify

    For VHD (specification) you can just backup the first 512 bytes (copy of footer) and 1024 bytes (header) of the file and any sane program would not accept it as a proper VHD I imagine you could do something similar with VHDX too but I haven't looked into it
    1 point
  10. Not in bad mood but it seems I need glasses I was under the impression that the OP of the thread I referred to started a new one with the same content. That's what happens when you "hijack" a thread. You should have opened a new one in the first place The only help I can offer at the moment is: Do not wait for the IE object to load but for a DOM element in your frames. The help file gives a bit more detail about this.
    1 point
  11. ProgAndy

    Threaded Dll Sample

    You can create threads with Autoit, so you don't need a DLl to do that. You just mustn't use an AutoIt-Function with DLLCallbackRegister as the Thread-Functions. (The thread runs, but AutoIt crahses after a few secs) So yo have to use just one func in the DLL which wil be the ThreadProc. For Messageboxes you could use the MessageBoxIndirect from user32.dll. Example at the end of script: Global Const $STATUS_PENDING = 0x103 Global Const $STILL_ACTIVE = $STATUS_PENDING ; ThreadID is @extended ;=============================================================================== ; ; Function Name: _Thread_Create ; Description:: Creates a thread ; Parameter(s): see MSDN (lpThreadId is removed) ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; @extended will be ThreadID ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Create($lpThreadAttributes, $dwStackSize, $lpStartAddress, $lpParameter, $dwCreationFlags) Local $result = DllCall("kernel32.dll","ptr","CreateThread", "ptr", $lpThreadAttributes, "dword", $dwStackSize, "ptr", $lpStartAddress, "ptr", $lpParameter, "dword", $dwCreationFlags, "dword*", 0) Return SetError($result[0]=0,$result[6],$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_Terminate ; Description:: Terminates a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Terminate($hThread,$dwExitCode) Local $result = DllCall("Kernel32.dll","int","TerminateThread","ptr",$hThread,"dword",$dwExitCode) Return SetError($result[0]=0,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_Exits ; Description:: Exits the current thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): none ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Exit($dwExitCode) DllCall("Kernel32.dll","none","ExitThread","dword",$dwExitCode) EndFunc ;=============================================================================== ; ; Function Name: _Thread_GetExitCode ; Description:: retrieves ExitCode of a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_GetExitCode($hThread) Local $result = DllCall("Kernel32.dll","int","GetExitCodeThread","ptr",$hThread,"dword*",0) Return SetError($result[0]=0,0,$result[2]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_GetID ; Description:: retrieves ThreadID of a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_GetID($hThread) Local $result = DllCall("Kernel32.dll","dword","GetThreadId","ptr",$hThread) Return SetError($result[0]=0,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_GetPriority ; Description:: retrieves priority of a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_GetPriority($hThread) Local $result = DllCall("Kernel32.dll","int","GetThreadPriority","ptr",$hThread) Return SetError($result[0]=0,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_SetPriority ; Description:: sets priority of a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_SetPriority($hThread,$nPriority) Local $result = DllCall("Kernel32.dll","int","SetThreadPriority","ptr",$hThread,"int",$nPriority) Return SetError($result[0]=0,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_Suspend ; Description:: suspends a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Suspend($hThread) Local $result = DllCall("Kernel32.dll","int","SuspendThread","ptr",$hThread) Return SetError($result[0]=-1,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_Resume ; Description:: resumes a thread ; Parameter(s): see MSDN ; Requirement(s): minimum Win2000 ; Return Value(s): see MSDN ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Resume($hThread) Local $result = DllCall("Kernel32.dll","int","ResumeThread","ptr",$hThread) Return SetError($result[0]=-1,0,$result[0]) EndFunc ;=============================================================================== ; ; Function Name: _Thread_Wait ; Description:: Waits for a thread to terminate ; Parameter(s): $hThread - Handle of thread ; $nTimeOut - [optional] Timeout (default: 0xFFFFFFFF => INFINTE) ; Requirement(s): minimum Win2000 ; Return Value(s): Success: true ; on TimeOut, @eeor will be set to -1 ; On error, @error will be set to 1 ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _Thread_Wait($hThread,$nTimeout=0xFFFFFFFF) Local $result = DllCall("Kernel32.dll", "dword", "WaitForSingleObject", "ptr", $hThread, "int", $nTimeout) If @error Then Return SetError(2,0,0) Switch $result[0] Case -1, 0xFFFFFFFF Return SetError(1,0,0) Case 0x00000102 Return SetError(-1,0,1) Case Else Return 1 EndSwitch EndFunc #include <WinAPI.au3> $tagMSGBOXPARAMS = _ "UINT cbSize;" & _ "HWND hwndOwner;" & _ "ptr hInstance;" & _ "ptr lpszText;" & _ "ptr lpszCaption;" & _ "DWORD dwStyle;" & _ "ptr lpszIcon;" & _ "UINT_PTR dwContextHelpId;" & _ "ptr lpfnMsgBoxCallback;" & _ "DWORD dwLanguageId;" ; creates a struct for an Unicode-String Func _UnicodeStruct($text) ; Prog@ndy Local $s = DllStructCreate("wchar[" & StringLen($text)+1 & "]") DllStructSetData($s,1,$text) Return $s EndFunc ; retrieves Address of a function Func _Thread_GetProcAddress($hModule,$sProcname) ; Prog@ndy Local $result = DllCall("kernel32.dll","ptr","GetProcAddress","hwnd",$hModule,"str",$sProcname) Return $result[0] EndFunc ; Struct to send to the Thread ; in this case the MsgBox-Params $MSGBOXPARAMS = DllStructCreate($tagMSGBOXPARAMS) DllStructSetData($MSGBOXPARAMS,"cbSize",DllStructGetSize($MSGBOXPARAMS)) $stText = _UnicodeStruct("The messageBox in a separate thead!") DllStructSetData($MSGBOXPARAMS,"lpszText",DllStructGetPtr($stText)) $stCaption = _UnicodeStruct("Caption") DllStructSetData($MSGBOXPARAMS,"lpszCaption",DllStructGetPtr($stCaption)) DllStructSetData($MSGBOXPARAMS,"dwStyle",17) ; msgBox-style ; Use MessageBoxIndirect Unicode as ThreadProc ; normal MessageBox doesn't work, since CreateThread just has one possible parameter. Local $hThreadProc = _Thread_GetProcAddress(_WinAPI_GetModuleHandle("user32.dll"),"MessageBoxIndirectW") $hThread = _Thread_Create(0 ,0, $hThreadProc, DllStructGetPtr($MSGBOXPARAMS), 0) $ThreadID = @extended While MsgBox(69, "main", "Main script is not blocked" )=4 WEnd MsgBox(0, "Thread-Info", "Handle: " & $hThread & @CRLF & "Thread-ID: " & $ThreadID) _Thread_Wait($hThread) $code = _Thread_GetExitCode($hThread) MsgBox(0, 'Thread ended', "Threaded MsgBox returned: " & $code)
    1 point
  12. Greenseed

    I Love AutoIT

    ThX to everyone who support the autoit user. And THX to Jonathan Bennett & AutoIt Team. I LOve Autoit! i very do! my life and the life of 1000 people around me have the life easier. Greenseed --------------- MCSE, CCNA, AutoIT ;-) _______________________ aleajecta@aleajecta.com
    1 point
×
×
  • Create New...