Leaderboard
Popular Content
Showing content with the highest reputation on 07/11/2017 in all areas
-
I wanted to start using SDL2 libraries in C++. This is a Hello World project that covers some of the essentials of programming with SDL2. I will use it when I forget how to create an SDL2 project. Loads a scrolling background image for world. Mouse position, left click, and double click example. Hotkeys and cooldown timers to prevent hotkey spam. Plays background music. (ALT + P) Plays sound effects changing sprite type. (numpad: /, *, -, +) Features a Player class for multiplayer. Player collision detection. Uses a Window class from Lazyfoo for maximize button, fullscreen ext.. Built using MSVS 2013 (free). All dlls and libraries included and linked (for MSVS) using relative paths. You can probably run the SDL2_HelloWorld.sln without setting up any libraries. Note SDL_Net is setup but not used. Delta time used to create consistent frame rate across machines. Player animation sprite sheet: Demo: Slimy's First Kiss Download Source and project: http://songersoft.com/programming/sdl2_helloworld/sdl2_helloworld_about.phtml This isn't meant to be amazing. It's just to help get started with SDL2. I will consider any criticism. main.cpp // This example HelloWorld followed this video: // https://www.youtube.com/watch?v=M4Jgz0wEQxY // Turned into this // https://www.youtube.com/watch?v=yRpen8jOa08&list=PL77-op_SRaiEuC0YC43ZAUJJwL_G_C2z8&index=15 // Window class was copied from Lazyfoo // http://lazyfoo.net/tutorials/SDL/35_window_events/index.php #include <iostream> #include <string> #include "SDL.h" #include "SDL_image.h" #include "SDL_ttf.h" #include "SDL_mixer.h" #include "SDL_net.h" #include "Player.h" #include "Window.h" using namespace std; // Prototypes SDL_Texture *LoadTexture(string filepath, SDL_Renderer *renderTarget); void logSDLError(const string); SDL_Rect sdlrect(int, int, int, int); SDL_Surface *OptimizedSurface(string filepath, SDL_Surface *windowSurface); // if(okAlt) either Alt key is pressed OrKeyALT #define okAlt (k[SDL_SCANCODE_RALT] || k[SDL_SCANCODE_LALT]) int main(int argc, char *argv[]) { // Needed for the initialize block Window window; SDL_Renderer *renderTarget = nullptr; // Initialize SDL2 if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { logSDLError("SDL_Init "); } // Initialize SDL_image if (!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) { cout << "Could not initialize SDL_image: " << IMG_GetError() << std::endl; SDL_Delay(5500); } // Initialize TTF if (TTF_Init() < 0) cout << "TTF_Init " << TTF_GetError() << endl; //Create window if (!window.init("SDL2 Hello World", 640, 480, "../../Graphics/iconbmp.bmp")) { printf("Window could not be created! SDL Error: %s\n", SDL_GetError()); } else { //Create renderer for window renderTarget = window.createRenderer(); if (renderTarget == NULL) { printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError()); } } // Audio if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) { cout << "Mix_OpenAudio: " << Mix_GetError() << endl; } // Load sounds: Run chunk if less than 10 sec, music if greater (generally) //Mix_Music *bgm = Mix_LoadMUS("../../Sounds/overworld.mid"); // Can't Pause MIDI Mix_Music *bgm = Mix_LoadMUS("../../Sounds/bensound-goinghigher.mp3"); cout << Mix_GetError() << endl; // Font and text SDL_Texture *text_texture = nullptr; SDL_Color textColor = { 144, 77, 255, 255 }; TTF_Font *font = TTF_OpenFont("../../Graphics/Fonts/VCR_OSD_MONO.ttf", 20); if (font) { SDL_Surface *textSurf = TTF_RenderText_Solid(font, "Hello world", textColor); text_texture = SDL_CreateTextureFromSurface(renderTarget, textSurf); SDL_FreeSurface(textSurf); } else cout << TTF_GetError() << endl; SDL_Rect textRect = { 0, 0, 0, 0 };// Position of text on window // Get the size of the text_texture SDL_QueryTexture(text_texture, NULL, NULL, &textRect.w, &textRect.h); const int playerMax = 8; int players = 2; float prevTime = 0, currentTime = 0, deltaTime = 0; bool fullscreen_toggle = 0; int i = 0, ii = 0; int redraw = 1; bool done = 0; // Load player sprite sheet and background texture SDL_Texture *spritesheet_texture = LoadTexture("../../Graphics/DW3_Char_SpriteSheet.png", renderTarget); SDL_Texture *bg_texture = LoadTexture("../../Graphics/dw3-over.png", renderTarget); int bg_texture_w = 0, bg_texture_h = 0; // Point k to Keyboard state (only needs done here, not in main loop) const Uint8 *k = SDL_GetKeyboardState(NULL); SDL_Event windowEvent; // Stop keys spamming (like music ON / OFF) float key_cooldown_timer_max = 500.0f, key_cooldown_timer = 0; SDL_Rect cameraRect = { 0, 0, window.getWidth(), window.getHeight()}; // Construct default players Player player[playerMax]; // Customize players (texture and position) for (i = 0; i < players; i++)//(sprite texture, position x, position y) player[i].Player_new(spritesheet_texture, window.getWidth() / 2 + i * 16, window.getHeight() / 2); // Get the size of bg_texture SDL_QueryTexture(bg_texture, NULL, NULL, &bg_texture_w, &bg_texture_h); // Main message loop while (!done) { prevTime = currentTime; currentTime = SDL_GetTicks(); deltaTime = (currentTime - prevTime) / 1000.0f; while (SDL_PollEvent(&windowEvent) != 0) { // Check for events if (windowEvent.type == SDL_QUIT) { // Window Exit done = 1; } else if(windowEvent.type == SDL_MOUSEBUTTONDOWN) { // Mouse buttons if (windowEvent.button.clicks == 2) { // Double left click redraw = 1; } else if (windowEvent.button.button == SDL_BUTTON_LEFT) { // Single left click redraw = 1; } // Output mouse position cout << "Mouse: " << windowEvent.button.x << " " << windowEvent.button.y << endl; } }// if(SDL_PollEvent(&windowEvent)) if (okAlt) { // Either ALT key if (k[SDL_SCANCODE_RETURN]) { // ALT + ENTER, toggle fullscreen // Consider matching current window resolution to closest preset array of valid full screen resolutions. fullscreen_toggle = 1; } if (k[SDL_SCANCODE_P]) { if (SDL_GetTicks() - key_cooldown_timer > key_cooldown_timer_max) { // Action cooldown timer is ready. Avoids ON / OFF flicker // Play Music if (!Mix_PlayingMusic()) { cout << "PLAY"; Mix_PlayMusic(bgm, -1); } else if (Mix_PausedMusic()) { cout << "RESUME"; Mix_ResumeMusic(); } else { cout << "PAUSE"; Mix_PauseMusic(); } key_cooldown_timer = SDL_GetTicks(); } }// SDL_SCANCODE_P if (k[SDL_SCANCODE_S]) { // Stop Music Mix_HaltMusic(); } }// okAlt //Handle window events fullscreen_toggle = window.handleEvent(windowEvent, renderTarget, fullscreen_toggle); // Player Update and IntersectsWith for (i = 0; i < players; i++) { player[i].Update(deltaTime, k); for (ii = 0; ii < players; ii++) { if(i != ii)// Not self player[i].IntersectsWith(player[ii]); } } // Camera cameraRect.x = player[0].GetOriginX() - window.getWidth() / 2; cameraRect.y = player[0].GetOriginY() - window.getHeight() / 2; // Normalize if (cameraRect.x < 0) cameraRect.x = 0; if (cameraRect.y < 0) cameraRect.y = 0; if (cameraRect.x + cameraRect.w >= bg_texture_w) cameraRect.x = bg_texture_w - window.getWidth(); if (cameraRect.y + cameraRect.h >= bg_texture_h) cameraRect.y = bg_texture_h - window.getHeight(); redraw = 1; // Don't judge me if (redraw) { // Redraw should definatly pretty much be at the end of loop // Clear window SDL_RenderClear(renderTarget); // Copy camera from bg_texture SDL_RenderCopy(renderTarget, bg_texture, &cameraRect, NULL); // Draw players for (i = 0; i < players; i++) player[i].Draw(renderTarget, cameraRect); // Print text SDL_RenderCopy(renderTarget, text_texture, NULL, &textRect); // Show the rendered content SDL_RenderPresent(renderTarget); redraw = 0; }// if(redraw) }// while(true) // Free windows window.free(); SDL_DestroyTexture(bg_texture); SDL_DestroyTexture(spritesheet_texture); SDL_DestroyTexture(text_texture); TTF_CloseFont(font); // Free Renderers SDL_DestroyRenderer(renderTarget); // Free music Mix_FreeMusic(bgm); // Close systems Mix_Quit(); TTF_Quit(); IMG_Quit(); SDL_Quit(); return EXIT_SUCCESS; }// main() SDL_Texture *LoadTexture(string filepath, SDL_Renderer *renderTarget) { // Create texture SDL_Texture *texture = nullptr; // Load surface SDL_Surface *surface = IMG_Load(filepath.c_str()); if (surface == NULL) { // surface didn't load logSDLError("LoadTexture surface "); } else { SDL_SetColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 0, 0, 0)); texture = SDL_CreateTextureFromSurface(renderTarget, surface); //SDL_SetTextureColorMod(texture, 120, 150, 140); if (texture == NULL) logSDLError("LoadTexture texture "); } SDL_FreeSurface(surface); return texture; } void logSDLError(const string msg){ cout << msg << " Error: " << SDL_GetError() << endl; SDL_Delay(4000); } SDL_Rect sdlrect(int x, int y, int w, int h) { SDL_Rect rect = {x, y, w, h}; return rect; } SDL_Surface *OptimizedSurface(string filepath, SDL_Surface *windowSurface) { SDL_Surface *optimizedSurf = nullptr; SDL_Surface *surface = IMG_Load(filepath.c_str()); if (surface == NULL) { cout << "Error: " << endl; } else { optimizedSurf = SDL_ConvertSurface(surface, windowSurface->format, 0); if (optimizedSurf == NULL) cout << "Error: " << endl; } SDL_FreeSurface(surface); return optimizedSurf; } Player.h #pragma once #include <iostream> #include "SDL.h" #include <String> #include "SDL_mixer.h" using namespace std; enum player_control { ePlayer_control_up, ePlayer_control_down, ePlayer_control_left, ePlayer_control_right, ePlayer_control_type_minus, ePlayer_control_type_plus }; class Player { private: SDL_Rect cropRect; SDL_Texture *texture; int spritesheet_texture_w, spritesheet_texture_h;//size of spritesheet texture bool isActive;//animation timer SDL_Scancode keys[6]; int frame_w, frame_h;//16, 16 float frameTimerMax; float frameTimer;//0..frameTimerMax int frame;//0..1 int frameMax;//2 int way;//0..3 int classType;//0..53 float moveSpeed; float cast_cooldown_max; Mix_Chunk *soundEffect; int originX, originY; int radius; Uint32 key_cooldown_timer; string name; public: void Player_new(SDL_Texture *spritesheet_texture, int x, int y); Player(); ~Player(); void Update(float delta, const Uint8 *keyState); void Draw(SDL_Renderer *renderTarget, SDL_Rect cameraRect); bool IntersectsWith(Player &p); int GetOriginX(); int GetOriginY(); int GetRadius(); SDL_Rect positionRect; }; Player.cpp #pragma once #include "Player.h" #include "SDL_image.h" #include "SDL_mixer.h" #include <iostream> #include <String> #include <cmath> using namespace std; Player::Player() { cropRect = {0, 0, 16, 16}; texture = nullptr; spritesheet_texture_w = spritesheet_texture_h = 0;//size of spritesheet texture isActive = false;//animation timer keys[6]; frame_w = frame_h = 16;//16, 16 frameTimerMax = 0.5f; frameTimer = 0;//0..frameTimerMax frame = 0;//0..1 frameMax = 2;//2 way = 0;//0..3 classType = 0;//0..53 moveSpeed = 200.0f; radius = frame_w / 2; soundEffect = nullptr; key_cooldown_timer = 0; cast_cooldown_max = 190.0f; static int playerNumber = 0; playerNumber++; name = "Player:" + to_string(playerNumber); // Setup keys for player 1 // ** I see the enum didn't exist when this was written ** if (playerNumber == 1) { keys[0] = SDL_SCANCODE_W; keys[1] = SDL_SCANCODE_S; keys[2] = SDL_SCANCODE_A; keys[3] = SDL_SCANCODE_D; keys[4] = SDL_SCANCODE_KP_MINUS; keys[5] = SDL_SCANCODE_KP_PLUS; } else { // Setup keys all other players (not 1) keys[0] = SDL_SCANCODE_UP; keys[1] = SDL_SCANCODE_DOWN; keys[2] = SDL_SCANCODE_LEFT; keys[3] = SDL_SCANCODE_RIGHT; keys[4] = SDL_SCANCODE_KP_DIVIDE; keys[5] = SDL_SCANCODE_KP_MULTIPLY; } }//Player::Player() void Player::Player_new(SDL_Texture *spritesheet_texture, int x, int y) { // This is new player isActive = false; // Read size of spritesheet texture SDL_QueryTexture(spritesheet_texture, NULL, NULL, &spritesheet_texture_w, &spritesheet_texture_h); texture = spritesheet_texture; // spritesheet rect cropRect = { 0, 0, 16, 16 }; // player screen position positionRect = { x, y, 16, 16 }; // Defaults moveSpeed = 200.0f; radius = frame_w / 2; frameTimer = 0; frame = 0; frameMax = 2; way = 0; classType = 0; originX = frame_w / 2; originY = frame_h / 2; soundEffect = Mix_LoadWAV("../../Sounds/whipcrack1.wav"); cout << "Name: " << name << endl; }//Player::Player_new() void Player::Update(float delta, const Uint8 *keyState) { isActive = true; if (keyState[keys[ePlayer_control_up]]) { way = 0; positionRect.y -= moveSpeed * delta; cropRect.x = (way * cropRect.w * frameMax) + (frame * cropRect.w); } if (keyState[keys[ePlayer_control_down]]) { way = 1; positionRect.y += moveSpeed * delta; cropRect.x = (way * cropRect.w * frameMax) + (frame * cropRect.w); } if (keyState[keys[ePlayer_control_left]]) { way = 3; positionRect.x -= moveSpeed * delta; cropRect.x = (way * cropRect.w * frameMax) + (frame * cropRect.w); } if (keyState[keys[ePlayer_control_right]]) { way = 2; positionRect.x += moveSpeed * delta; cropRect.x = (way * cropRect.w * frameMax) + (frame * cropRect.w); } if (keyState[keys[ePlayer_control_type_minus]]) { if (SDL_GetTicks() - key_cooldown_timer > cast_cooldown_max) { key_cooldown_timer = SDL_GetTicks(); Mix_PlayChannel(-1, soundEffect, 0); classType--; if (classType < 0) classType = spritesheet_texture_h / cropRect.h - 1; cropRect.y = classType * cropRect.h; } } if (keyState[keys[ePlayer_control_type_plus]]) { if (SDL_GetTicks() - key_cooldown_timer > cast_cooldown_max) { key_cooldown_timer = SDL_GetTicks(); Mix_PlayChannel(-1, soundEffect, 0); classType++; if (classType >= spritesheet_texture_h / cropRect.h) classType = 0; cropRect.y = classType * cropRect.h; } } if (isActive) { frameTimer += delta; if (frameTimer >= frameTimerMax){ frameTimer = 0; cropRect.x = (way * cropRect.w * frameMax) + (frame * cropRect.w); if (frame >= frameMax - 1) frame = 0; else frame++; } } else { frameTimer = 0; } }//Player::Update() void Player::Draw(SDL_Renderer *renderTarget, SDL_Rect cameraRect) { SDL_Rect drawingRect = { positionRect.x - cameraRect.x, positionRect.y - cameraRect.y, positionRect.w, positionRect.h }; SDL_RenderCopy(renderTarget, texture, &cropRect, &drawingRect); } bool Player::IntersectsWith(Player &p){ if (sqrt(pow(GetOriginX() - p.GetOriginX(), 2) + pow(GetOriginY() - p.GetOriginY(), 2)) >= radius + p.GetRadius()) { SDL_SetTextureColorMod(texture, 255, 255, 255); return false; } SDL_SetTextureColorMod(texture, 255, 0, 0); return true; } Player::~Player() { SDL_DestroyTexture(texture); Mix_FreeChunk(soundEffect); } int Player::GetOriginX() { return positionRect.x + originX; } int Player::GetOriginY() { return positionRect.y + originY; } int Player::GetRadius() { return radius; }2 points
-
zLib (Deflate/Inflate/GZIP) UDF
ducln456789 reacted to Ward for a topic
To use zLib in AutoIt, the easiest way is download the DLL, and then just use it by DllCall, or warp it by my But now I convert zLib to machine code version UDF, because "just for fun", or because I can. There is another good reason: to minimize the UDF size (because there are some functions I don't need in the DLL file). The best thing of this library is that it can compress/decompress the gzip format. So this is also a "GZIP UDF" in pure script. Example: ; ----------------------------------------------------------------------------- ; Zlib Compression Library (Deflate/Inflate) Machine Code UDF Example ; Purpose: Provide The Machine Code Version of Zlib Library In AutoIt ; Author: Ward ; Zlib Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler ; ----------------------------------------------------------------------------- #Include "ZLIB.au3" ; Test _ZLIB_Compress And _ZLIB_Uncompress Dim $Original = BinaryFileRead(@AutoItExe) Dim $Compressed = _ZLIB_Compress($Original, 9) Dim $Decompressed = _ZLIB_Uncompress($Compressed) Dim $Result = 'Original Size: ' & BinaryLen($Original) & @CRLF $Result &= 'Compressed Size: ' & BinaryLen($Compressed) & @CRLF $Result &= 'Decompress Succeed: ' & ($Decompressed = $Original) MsgBox(0,'Deflate/Inflate Test', $Result) ; Test _ZLIB_GZCompress And _ZLIB_GZUncompress Dim $Original = BinaryFileRead(@AutoItExe) Dim $Compressed = _ZLIB_GZCompress($Original, 9) Dim $Decompressed = _ZLIB_GZUncompress($Compressed) Dim $Result = 'Original Size: ' & BinaryLen($Original) & @CRLF $Result &= 'Compressed Size: ' & BinaryLen($Compressed) & @CRLF $Result &= 'Decompress Succeed: ' & ($Decompressed = $Original) MsgBox(0,'Gzip Test', $Result) ; Test _ZLIB_FileCompress And _ZLIB_FileUncompress Dim $OriginalPath = @AutoItExe Dim $CompressedPath = @TempDir & "\test.z" Dim $DecompressedPath = @TempDir & "\test.unz" _ZLIB_FileCompress($OriginalPath, $CompressedPath, 9) _ZLIB_FileUncompress($CompressedPath, $DecompressedPath) Dim $Result = 'Original Size: ' & FileGetSize($OriginalPath) & @CRLF $Result &= 'Compressed Size: ' & FileGetSize($CompressedPath) & @CRLF $Result &= 'Decompress Succeed: ' & (BinaryFileRead($DecompressedPath) = BinaryFileRead($OriginalPath)) FileDelete($CompressedPath) FileDelete($DecompressedPath) MsgBox(0,'Deflate/Inflate File Test', $Result) ; Test _ZLIB_GZFileCompress And _ZLIB_GZFileUncompress Dim $OriginalPath = @AutoItExe Dim $CompressedPath = @TempDir & "\test.gz" Dim $DecompressedPath = @TempDir & "\test.ungz" _ZLIB_GZFileCompress($OriginalPath, $CompressedPath, 9) _ZLIB_GZFileUncompress($CompressedPath, $DecompressedPath) Dim $Result = 'Original Size: ' & FileGetSize($OriginalPath) & @CRLF $Result &= 'Compressed Size: ' & FileGetSize($CompressedPath) & @CRLF $Result &= 'Decompress Succeed: ' & (BinaryFileRead($DecompressedPath) = BinaryFileRead($OriginalPath)) FileDelete($CompressedPath) FileDelete($DecompressedPath) MsgBox(0,'Gzip File Test', $Result) Exit Func BinaryFileRead($Path) Local $File = FileOpen($Path, 16) Local $Data = FileRead($File) FileClose($File) Return $Data EndFunc For other compression method, see my " ZLIB.zip1 point -
Hi to all, I only am accustomed pas has posted on the forum (coz, I'm french). But I use it a lot. So first of all, thank you all to participate in the evolution of this wonderful product. Today is not one day like any other, I myself am decide has posted a UDF that I myself create and developed (there may be some bug) for some months. So here it is: This UDF allows to use the SSH protocol very easily in your code. It uses the syntax as the TCPxxx() function. Your code will be easier to convert :-). excused my English, I'm French. Example: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.4.0 Author: Joseph Barone 2010-2015 Script Function: Modele pour l'utilisation de la fonction ssh (plink). #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include #include #include #include #include #include "SSH_udf.au3" _SSHStartup() Global $butt[6] $Gui = GUICreate("SSH Console",550,400) $label1 = GUICtrlCreateLabel("Adresse IP:",10,10,150,20) ; ip $input1 = GUICtrlCreateInput("",10,25,150,20) ; ip $label2 = GUICtrlCreateLabel("Tcp port:",170,10,150,20) ; port $input2 = GUICtrlCreateInput("",170,25,60,20) ; port $label6 = GUICtrlCreateLabel("Protocol:",240,10,40,20) ; port $input6 = GUICtrlCreateInput("ssh",240,25,60,20) ; port $butt[0] = GUICtrlCreateButton("Connect0",310,5,80,20,$BS_DEFPUSHBUTTON) $butt[1] = GUICtrlCreateButton("Connect1",390,5,80,20) $butt[2] = GUICtrlCreateButton("Connect2",470,5,80,20) $butt[3] = GUICtrlCreateButton("Connect3",310,25,80,20) $butt[4] = GUICtrlCreateButton("Connect4",390,25,80,20) $butt[5] = GUICtrlCreateButton("Connect5",470,25,80,20) $Checkbox = GUICtrlCreateCheckbox("RSA, Fingerprint, Alert AutoValidate", 330, 45, 205, 25) $label4 = GUICtrlCreateLabel("Login:",10,45,150,20) ; login $input4 = GUICtrlCreateInput("",10,60,150,20) ; login $label5 = GUICtrlCreateLabel("Mot de passe:",170,45,150,20) ; password $input5 = GUICtrlCreateInput("",170,60,150,20,$ES_PASSWORD) ; password $label3 = GUICtrlCreateLabel("Commande a envoyer:",10,85,150,20) ; send command $input3 = GUICtrlCreateInput("",10,100,310,20) ; send commande vers l'hote $butt2 = GUICtrlCreateButton("Send",330,100,80,20,$BS_DEFPUSHBUTTON) GUICtrlSetState($butt2,$GUI_DISABLE) $edit = GUICtrlCreateEdit("",10,130,530,260,$WS_VSCROLL);,$WS_DISABLED)) GUISetState() Global $ConnectedSocket[6] = [-1,-1,-1,-1,-1,-1] Global $msg, $recv, $ret ; GUI Message Loop ;============================================== While 1 $nmsg = GUIGetMsg() If $nmsg = $GUI_EVENT_CLOSE Then ExitLoop ;;; connect part: $b = 0 While 1 If $nMsg = $butt[$b] Then If GUICtrlRead($butt[$b]) = "Connect"&$b Then _SSHParametreSet("yesall",GUICtrlRead($Checkbox)) _SSHParametreSet("protocol",GUICtrlRead($input6)) _SSHParametreSet("login",GUICtrlRead($input4)) _SSHParametreSet("passwd",GUICtrlRead($input5)) $ConnectedSocket[$b] = _SSHConnect(GUICtrlRead($input1),GUICtrlRead($input2)) If $ConnectedSocket[$b] = 0 Then MsgBox(0,"Erreur", "Impossible de ce connecter!!") Else GUICtrlSetData($butt[$b],"Close"&$b GUICtrlSetState($butt2,$GUI_ENABLE) EndIf DisplayArray($_config) ConsoleWrite("nb config:"&$_nbconf&@CRLF) Else _SSHCloseSocket($ConnectedSocket[$b]) GUICtrlSetData($butt[$b],"Connect"&$b GUICtrlSetState($butt2,$GUI_DISABLE) DisplayArray($_config) ConsoleWrite("nb config:"&$_nbconf&@CRLF) EndIf EndIf ;;; send part: If $nMsg = $butt2 Then $ret = _SSHSend( $ConnectedSocket[$b] , GUICtrlRead($input3)&@crlf) GUICtrlSetData($input3,"") GUICtrlSetState($input3,$GUI_FOCUS) EndIf ;;; receive part: $recv = _SSHRecv( $ConnectedSocket[$b]) If $recv <> "" Then GUICtrlSetData($edit, GUICtrlRead($edit) & $recv ) EndIf GUICtrlSendMsg($edit, $EM_SCROLL, $SB_PAGEDOWN, 0) $b += 1 If $b = UBound($butt) Then ExitLoop WEnd WEnd _SSHCloseSocket($ConnectedSocket) _SSHShutdown() Exit Func DisplayArray($array) $i = 0 $j = 0 if UBound($array,1) = 0 Then Return While 1 ConsoleWrite("(["&UBound($array,1)&"]["&UBound($array,2)&"]) ") While 1 ConsoleWrite("["&$j&"]"&$array[$i][$j]&" ") $j += 1 if UBound($array,2)<=$j Then ExitLoop WEnd ConsoleWrite(@CRLF) $i += 1 $j = 0 if UBound($array,1)<=$i Then ExitLoop WEnd EndFunc I join with UDF version of modified putty myself. 🙂 LoL but, it is not used with the UDF, it is included in the UDF. putty-04012015- 92453+lic.zip ssh_udf.zip New version (contains the latest version of plink (0.74) edited by http://jakub.kotrla.net/putty/) ssh_udf-v2.zip Same as the v2 but supports all putty/plink settings ssh_udf-v2.1.zip1 point
-
Rotate animation
Parsix reacted to haijie1223 for a topic
#NoTrayIcon #RequireAdmin #My QQ No: 29535065 #QQ group: 477266297 #include <GDIPlus.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $iSleepTime = 80 Global $hGUI = GUICreate("GDI+旋转动画", 400, 280) Global $Pic_Animation = GUICtrlCreatePic('', 5, 5, 256, 256) Global $Btn_Type1 = GUICtrlCreateButton('旋转方式一', 275, 35, 100, 30) Global $Btn_Type2 = GUICtrlCreateButton('旋转方式二', 275, 85, 100, 30) Global $Btn_Type3 = GUICtrlCreateButton('旋转方式三', 275, 135, 100, 30) Global $Slider_Time = GUICtrlCreateSlider(275, 185, 100, 45) GUICtrlSetLimit($Slider_Time, 500, 50) GUISetState() GUISetIcon('shell32.dll',322,$hGUI) GUISetOnEvent(-3, '_GuiEvent') GUICtrlSetOnEvent($Btn_Type1, '_GuiEvent') GUICtrlSetOnEvent($Btn_Type2, '_GuiEvent') GUICtrlSetOnEvent($Btn_Type3, '_GuiEvent') GUICtrlSetOnEvent($Slider_Time, '_GuiEvent') _AnimationInit(ControlGetHandle($hGUI, '', $Pic_Animation), 1) _GDIPlus_Startup() ; While 1 Sleep($iSleepTime) _NextFlash() WEnd Func _GuiEvent() Switch @GUI_CtrlId Case -3 _DeleteCache() Exit Case $Btn_Type1 _ResetAniType(1, 2) Case $Btn_Type2 _ResetAniType(2, 0) Case $Btn_Type3 _ResetAniType(3, 0) Case $Slider_Time $iSleepTime=GUICtrlRead($Slider_Time) EndSwitch EndFunc ;==>_GuiEvent Func _AnimationInit($hHwd, $SpaceSec) Global $m_hWnd = $hHwd Global $m_nWidth, $m_nHeight Global $m_AnimationIndex = 0, $m_AnimationType = 0, $m_AnimationCount = 12 Global $m_ItemSize, $m_MarginAngle Global $m_hCacheDC, $m_hCacheBitmap, $m_hCacheOldBitmap Global $m_Rect = DllStructCreate($tagRECT) Global $m_ColorBack = _WinAPI_GetSysColor($COLOR_BTNFACE) Global $m_ColorBasic[2] = [0x808080, 0xC0C0C0] Global $m_ColorFore1 = [0x1FF4FB, 0x07F98C, 0x91A804, 0xCC9302, 0xAF5801, 0x9C426B, 0x9744A7, 0x9841E4, 0x241BEE, 0x2472F5, 0x2190F4, 0x12C2FF] Global $m_ColorFore2 = [0x34F5FF, 0x3CFDA3, 0xA5B833, 0xD8A733, 0xB67636, 0xAD6988, 0xAD68B9, 0xAC66E9, 0x514AEF, 0x4E8DF5, 0x4BA5FA, 0x3ECEFE] Global $m_AnimationArray[$m_AnimationCount] Local $i For $i = 0 To $m_AnimationCount - 1 $m_AnimationArray[$i] = _AnimationItem() DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorBasic[0], 255)) DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorBasic[1], 255)) Next _Resize() _ResetAniType($m_AnimationType, $SpaceSec) EndFunc ;==>_AnimationInit Func _RGB2ARGB($RGBColor, $Alpha) Return BitOR(Binary('0x' & Hex($RGBColor, 6)), BitShift($Alpha, -24)) EndFunc ;==>_RGB2ARGB Func _Resize() _DeleteCache() Local $rc = _WinAPI_GetClientRect($m_hWnd) $m_nWidth = DllStructGetData($rc, 3) - DllStructGetData($rc, 1) $m_nHeight = DllStructGetData($rc, 4) - DllStructGetData($rc, 2) If $m_nWidth > $m_nHeight Then DllStructSetData($m_Rect, 3, ($m_nHeight - 10)) Else DllStructSetData($m_Rect, 3, ($m_nWidth - 10)) EndIf ;~ DllStructSetData($m_Rect, 3, ($m_nWidth > $m_nHeight) ? ($m_nHeight - 10) : ($m_nWidth - 10)) DllStructSetData($m_Rect, 4, DllStructGetData($m_Rect, 3)) DllStructSetData($m_Rect, 1, ($m_nWidth - DllStructGetData($m_Rect, 3)) / 2) DllStructSetData($m_Rect, 2, ($m_nHeight - DllStructGetData($m_Rect, 4)) / 2) $m_ItemSize = 20 EndFunc ;==>_Resize Func _ResetAniType($AniType, $SpaceSec = 0) Local $i $m_AnimationIndex = 0 Switch $AniType Case 0 $m_AnimationType = 0 Case 1 $m_AnimationType = 1 Case 2 $m_AnimationType = 2 For $i = 0 To $m_AnimationCount - 1 DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255)) DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255)) Next Case 3 $m_AnimationType = 3 For $i = 0 To $m_AnimationCount - 1 DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255)) DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255)) Next Case Else _ResetAniType(0) Return EndSwitch $m_MarginAngle = $SpaceSec If $m_MarginAngle > 10 Then $m_MarginAngle = 10 If $m_MarginAngle < 0 Then $m_MarginAngle = 0 EndFunc ;==>_ResetAniType Func _NextFlash() Local $i Switch $m_AnimationType Case 0 For $i = 0 To $m_AnimationIndex - 1 DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorFore1[$i], 255)) DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorFore2[$i], 255)) Next $m_AnimationIndex += 1 If ($m_AnimationIndex > $m_AnimationCount) Then $m_AnimationType = 1 $m_AnimationIndex = 0 EndIf Case 1 For $i = 0 To $m_AnimationIndex - 1 DllStructSetData($m_AnimationArray[$i], 1, _RGB2ARGB($m_ColorBasic[0], 255)) DllStructSetData($m_AnimationArray[$i], 2, _RGB2ARGB($m_ColorBasic[1], 255)) Next $m_AnimationIndex += 1 If ($m_AnimationIndex > $m_AnimationCount) Then $m_AnimationType = 0 $m_AnimationIndex = 0 EndIf Case 2 local $item=$m_AnimationArray[11] For $i = 0 To $m_AnimationCount - 2 $m_AnimationArray[$m_AnimationCount - $i - 1] = $m_AnimationArray[$m_AnimationCount - $i - 2] Next $m_AnimationArray[0] = $item Case 3 $m_AnimationIndex = $m_AnimationIndex + 1 If ($m_AnimationIndex > $m_AnimationCount) Then $m_AnimationIndex = 0 EndSwitch _Draw() EndFunc ;==>_NextFlash Func _Draw() Local $hDC = _WinAPI_GetDC($m_hWnd) If $m_hCacheDC = 0 Then $m_hCacheDC = _WinAPI_CreateCompatibleDC($hDC) $m_hCacheBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $m_nWidth, $m_nHeight) $m_hCacheOldBitmap = _WinAPI_SelectObject($m_hCacheDC, $m_hCacheBitmap) EndIf _FillSolidRect($m_hCacheDC, _CRect(0, 0, $m_nWidth, $m_nHeight), $m_ColorBack) _DrawPie($m_hCacheDC) _WinAPI_BitBlt($hDC, 0, 0, $m_nWidth, $m_nHeight, $m_hCacheDC, 0, 0, 0x00CC0020) _WinAPI_ReleaseDC($m_hWnd, $hDC) EndFunc ;==>_Draw Func _CRect($Left, $Top, $Right, $Bottom) Local $Rect = DllStructCreate($tagRECT) DllStructSetData($Rect, 1, $Left) DllStructSetData($Rect, 2, $Top) DllStructSetData($Rect, 3, $Right) DllStructSetData($Rect, 4, $Bottom) Return $Rect EndFunc ;==>_CRect Func _FillSolidRect($hDC, $lpRect, $clr) _WinAPI_SetBkColor($hDC, $clr) _ExtTextOut($hDC, 0, 0, 2, $lpRect, Chr(0), 0, 0) EndFunc ;==>_FillSolidRect Func _DrawPie($hDC) Local $i Local $nStartAngle Local $nSweepAngle Local $pGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC) _GDIPlus_GraphicsSetSmoothingMode($pGraphics, 4) Local $pBrush = _GDIPlus_BrushCreateSolid(_RGB2ARGB(0, 255)) Local $rcOut = DllStructCreate($tagRECT) DllStructSetData($rcOut, 1, DllStructGetData($m_Rect, 1)) DllStructSetData($rcOut, 2, DllStructGetData($m_Rect, 2)) DllStructSetData($rcOut, 3, DllStructGetData($m_Rect, 3)) DllStructSetData($rcOut, 4, DllStructGetData($m_Rect, 4)) Local $rcIn = DllStructCreate($tagRECT) DllStructSetData($rcIn, 1, DllStructGetData($rcOut, 1)) DllStructSetData($rcIn, 2, DllStructGetData($rcOut, 2)) DllStructSetData($rcIn, 3, DllStructGetData($rcOut, 3)) DllStructSetData($rcIn, 4, DllStructGetData($rcOut, 4)) _InflateRectF($rcIn, -1 * $m_ItemSize) $nSweepAngle = 360 / $m_AnimationCount $nStartAngle = -90 For $i = 0 To $m_AnimationCount - 1 _GDIPlus_BrushSetSolidColor($pBrush, DllStructGetData($m_AnimationArray[$i], 1)) _GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcOut, 1), DllStructGetData($rcOut, 2), DllStructGetData($rcOut, 3), DllStructGetData($rcOut, 4), _ $nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush) $nStartAngle += $nSweepAngle Next $nSweepAngle = 360 / $m_AnimationCount $nStartAngle = -90 For $i = 0 To $m_AnimationCount - 1 _GDIPlus_BrushSetSolidColor($pBrush, DllStructGetData($m_AnimationArray[$i], 2)) _GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcIn, 1), DllStructGetData($rcIn, 2), DllStructGetData($rcIn, 3), DllStructGetData($rcIn, 4), _ $nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush) $nStartAngle += $nSweepAngle Next If ($m_AnimationType = 3) Then If $m_AnimationIndex > 0 Then $nStartAngle = -90 $nStartAngle = $nStartAngle + $m_AnimationIndex * $nSweepAngle _GDIPlus_BrushSetSolidColor($pBrush, _RGB2ARGB(0xFFFFFF, 150)) _GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcOut, 1), DllStructGetData($rcOut, 2), DllStructGetData($rcOut, 3), DllStructGetData($rcOut, 4), _ $nStartAngle, $nSweepAngle - $m_MarginAngle, $pBrush) EndIf EndIf _InflateRectF($rcIn, -1 * $m_ItemSize) _GDIPlus_BrushSetSolidColor($pBrush, _RGB2ARGB($m_ColorBack, 255)) _GDIPlus_GraphicsFillPie($pGraphics, DllStructGetData($rcIn, 1), DllStructGetData($rcIn, 2), DllStructGetData($rcIn, 3), DllStructGetData($rcIn, 4), 0, 360, $pBrush) _GDIPlus_BrushDispose($pBrush) _GDIPlus_GraphicsDispose($pGraphics) EndFunc ;==>_DrawPie Func _InflateRectF($rc, $dx, $dy = 0) If $dy = 0 Then $dy = $dx DllStructSetData($rc, 1, DllStructGetData($rc, 1) - $dx) DllStructSetData($rc, 2, DllStructGetData($rc, 2) - $dy) DllStructSetData($rc, 3, DllStructGetData($rc, 3) + $dx * 2) DllStructSetData($rc, 4, DllStructGetData($rc, 4) + $dy * 2) EndFunc ;==>_InflateRectF Func _DeleteCache() If $m_hCacheDC <> 0 Then _WinAPI_SelectObject($m_hCacheDC, $m_hCacheOldBitmap) _WinAPI_DeleteObject($m_hCacheBitmap) _WinAPI_DeleteDC($m_hCacheDC) _GDIPlus_Shutdown() $m_hCacheDC = 0 $m_hCacheBitmap = 0 $m_hCacheOldBitmap = 0 EndIf EndFunc ;==>_DeleteCache Func _ExtTextOut($hDC, $x, $y, $wOptions, $lpRect, $lpString, $nCount, $lpDx) If Not IsPtr($lpRect) Then $lpRect=DllStructGetPtr($lpRect) Local $Ret = DllCall('GDI32.dll', 'BOOL', 'ExtTextOutW', 'HANDLE', $hDC, 'INT', $x, 'INT', $y, 'UINT', $wOptions, 'PTR', $lpRect, 'WSTR', $lpString, 'UINT', $nCount, 'INT', $lpDx) If @error Then Return SetError(@error, 0, 0) Return $Ret[0] EndFunc ;==>_ExtTextOut Func _AnimationItem() Return DllStructCreate('INT;INT;') EndFunc ;==>_AnimationItem1 point -
_FileReadToArray() fails. Most of the time
DynastyQin reacted to jchd for a topic
A .csv file must adhere to the RFC standard or desist from calling itself .csv1 point -
fopetesl, The 2D _FileReadToArray function was written (by me) to split "square" csv files - i.e. those with the same number of elements on each line. This is a design decision to warn if the array is not "square" as would be expected for the majority of csv files. If you want to read files like yours with different numbers of elements on each line then you need to do some work yourself: #include <Array.au3> #include <File.au3> $sCSV = "ZZj2_Test.Won.Two.csv" Global $aLines _FileReadToArray($sCSV, $aLines) ;_ArrayDisplay($aLines, "", Default, 8) Global $aLines2D[$aLines[0]][1] For $i = 1 To $aLines[0] $aSplit = StringSplit($aLines[$i], ",") If $aSplit[0] > UBound($aLines2D, 2) Then ReDim $aLines2D[UBound($aLines2D)][$aSplit[0]] EndIf ;_ArrayDisplay($aSplit, "", Default, 8) For $j = 1 To $aSplit[0] $aLines2D[$i - 1][$j - 1] = $aSplit[$j] Next ;_ArrayDisplay($aLines2D, "", Default, 8) Next _ArrayDisplay($aLines2D, "", Default, 8) As to "I did try $FRTA_INTARRAYS but the eventual 1D array just showed 630+ times 1{array} with no data, i.e. didn't seem to split each row" - that is exactly what the Help file tells you will happen - each element of the array is another array split on the delimiter. Once again it is up to you get these elements into a 2D array, using logic not dissimilar to that in the example above. M231 point
-
Unable to use backspace in controls with embedded IE ActiveX
tarretarretarre reacted to Danp2 for a topic
Don't know how to fix this. However, I noticed that Control+H can be used as the equivalent to backspace. Also found this: https://www.autoitscript.com/trac/autoit/ticket/1101 point -
Here is a method to center text in a combo control. #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> ; Ref: https://www.autoitscript.com/forum/topic/119009-combo-and-format-issue-aligning-text/?do=findComment&comment=827534 Local $data[20] Local $iComboWidth = 249 Local $gui = GUICreate('', 260, 410) Local $test = GUICtrlCreateCombo('', 0, 0, $iComboWidth, 400, $WS_VSCROLL) GUICtrlSetFont(-1, 10, Default, Default, "Consolas") ; <<<<<<<<<<<<<<<< From above https reference thread. GUISetState() ; ---- Generate data --------- For $i = 0 To UBound($data) - 1 For $j = 0 To Random(2, 10) $data[$i] &= Random(1, 10, 1) Next Next ; ---- End of Generate data --------- _CentreData($iComboWidth, $data) ; Set data to the control. For $i = 0 To UBound($data) - 1 GUICtrlSetData($test, $data[$i]) Next While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then MsgBox(0, "", "Selected: " & StringStripWS(GUICtrlRead($test), 3), 4) ; $STR_STRIPLEADING (1) = strip leading white space plus $STR_STRIPTRAILING (2) = strip trailing white space ExitLoop EndIf WEnd ; Centre each item in the $aData array, relative to the $iComboWidth. Func _CentreData($iComboWidth, ByRef $aData) Local $strintest = Int(($iComboWidth / 8.3) / 2) ; Find centre of combo window width 8.3 pixels per character ; Add spaces to each item to Centre text. For $i = 0 To UBound($aData) - 1 While Int(StringLen($aData[$i]) / 2) < $strintest $aData[$i] = ' ' & $aData[$i] & ' ' WEnd Next EndFunc ;==>_CentreData1 point
-
I tidied the code from a post made by KaFu. The code is fully working in both x32 & x64. I also used _CmdLineRaw() to parse $CmdLineRaw to an Array. Function: Version 11 (20/07/2014) #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;' & _ 'dword cbData;' & _ 'ptr lpData' Global $IPC_GUID = 'E23D443E-F0E1-11E3-9E5C-90580B9E45A7' Global Enum $IPC_AUTOITID, _ $IPC_CLIENTWND, $IPC_CLIENTID, _ $IPC_GLOBALID, _ $IPC_ID, $IPC_ISMONITORING, _ $IPC_MONITORID, _ $IPC_SERVERWND, $IPC_SERVERID, _ $IPC_MAX Global Enum $IPC_CONTROLID, _ $IPC_RECEIVEDDATA, $IPC_RECEIVEDWND, $IPC_RECEIVEDMSG, _ $IPC__MAX Global $IPC[$IPC__MAX] ; Internal array for the interprocess communication functions. $IPC[$IPC_CONTROLID] = 0 #Region Example ; Display only if compiled. If @Compiled Then Example() Else MsgBox($MB_SYSTEMMODAL, '', 'Please compile the example before running.') EndIf Func Example() Local $hIPC = _InterProcess('F23B0E88-ED9F-11E3-8179-82ADECBA0006', Default) ; Start the interprocess communication. _InterProcess_Monitor($hIPC) If _InterProcess_IsServerExists($hIPC) And Not _InterProcess_SendToServer($hIPC, 'This is a sample string') Then ; Send a sample string if there is a main process already running. MsgBox($MB_SYSTEMMODAL, 'Second Instance: ' & @AutoItPID, _ 'Seems there was an error sending the IPC message, but more than likely the string was blank.') EndIf Local $hWnd = 0, _ $iMsg = 0, _ $sMsg = '' Local Const $SERVER_CLOSE_PROCESS = 1001 While 1 Switch GUIGetMsg() Case _InterProcess_GetMonitorID($hIPC) ; The monitoring id used to notify when an IPC message is received. ; If the process is an server i.e. the first instance, then read the data sent by a client and ; respond that the IPC message was received If _InterProcess_IsThisServer($hIPC) Then If _InterProcess_GetData($hIPC, $hWnd, $sMsg, $iMsg) Then MsgBox($MB_SYSTEMMODAL, 'First Instance: ' & @AutoItPID, _ 'hWnd: ' & $hWnd & @CRLF & _ 'Data: ' & $sMsg & @CRLF & _ 'Message: ' & $iMsg & @CRLF) ; Parse the relevant handle and data from the message. If $iMsg = $SERVER_CLOSE_PROCESS Then ; Check the $iMsg parameter doesn't contain the message to close this instance. ExitLoop ; If the $iMsg parameter is equal to $IPC_CLOSE_PROCESS (1001) the close the first instance. Else _InterProcess_SendToClient($hIPC, $hWnd, 'The data was successfully received by the first instance (server). This second instance (client) will now close. Thanks.') EndIf EndIf ; If the process is not the first instance also known as a client, then wait for the server to send a reply that it ; successfully recived the IPC message. ElseIf _InterProcess_IsThisClient($hIPC) Then If _InterProcess_GetData($hIPC, $hWnd, $sMsg, $iMsg) Then MsgBox($MB_SYSTEMMODAL, 'Second Instance: ' & @AutoItPID, _ 'hWnd: ' & $hWnd & @CRLF & _ 'Data: ' & $sMsg & @CRLF & _ 'Message: ' & $iMsg & @CRLF) ; Parse the relevant handle and data from the message. _InterProcess_SendToServer($hIPC, 'The second instance (client) recieved the message to close their instance so this instance (server) will close too.', $SERVER_CLOSE_PROCESS) ExitLoop EndIf EndIf EndSwitch WEnd _InterProcess_Destroy($hIPC) EndFunc ;==>Example #EndRegion Example Func _InterProcess($sGUID, $hWnd) Local $aIPC[$IPC_MAX] $aIPC[$IPC_ID] = $IPC_GUID $aIPC[$IPC_AUTOITID] = AutoItWinGetTitle() $aIPC[$IPC_ISMONITORING] = False If StringRegExp($sGUID, '^(?:\{){0,1}[[:xdigit:]]{8}-(?:[[:xdigit:]]{4}-){3}[[:xdigit:]]{12}(?:\}){0,1}$') Then ; Is GUID. $aIPC[$IPC_GLOBALID] = StringUpper($sGUID) Else $aIPC[$IPC_GLOBALID] = 'IPC_' & $IPC_GUID EndIf $aIPC[$IPC_CLIENTWND] = $hWnd $aIPC[$IPC_CLIENTID] = $aIPC[$IPC_GLOBALID] & '_CLIENT' $aIPC[$IPC_SERVERWND] = 0 $aIPC[$IPC_SERVERID] = $aIPC[$IPC_GLOBALID] & '_SERVER' $hWnd = WinGetHandle($aIPC[$IPC_SERVERID]) If @error Or Not $hWnd Then ; No interprocess communication server exists. $aIPC[$IPC_SERVERWND] = 0 Else Local Const $hControl = ControlGetHandle($hWnd, '', 'Edit1') $aIPC[$IPC_SERVERWND] = HWnd( _ StringRegExp('|' & ControlGetText($hWnd, '', $hControl) & '|IPC_WND:0x00000000|', _ '\|IPC_WND:(0[xX][[:xdigit:]]+)\|', _ $STR_REGEXPARRAYGLOBALMATCH)[0] _ ) ; Retrieve the server communication handle. EndIf Return $aIPC EndFunc ;==>_InterProcess Func _InterProcess_Destroy(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) Then $bReturn = True Local $hAutoItWnd = 0 If _InterProcess_IsThisServer($aIPC) Then $hAutoItWnd = WinGetHandle($aIPC[$IPC_SERVERID]) ElseIf _InterProcess_IsThisClient($aIPC) And _InterProcess_IsClientExists($aIPC) Then $hAutoItWnd = WinGetHandle($aIPC[$IPC_CLIENTID]) EndIf If IsHWnd($hAutoItWnd) Then Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, _ StringRegExpReplace(ControlGetText($hAutoItWnd, '', $hControl), _ '(?<=\n)\|IPC_(?:WND|PID):\V+\R', _ '')) ; Destroy the communication handle and PID. ; Destroy the associated GUI. GUIRegisterMsg($WM_COPYDATA, '') If $aIPC[$IPC_MONITORID] > 0 Then GUICtrlDelete($aIPC[$IPC_MONITORID]) EndIf If IsHWnd($aIPC[$IPC_CLIENTWND]) Then GUIDelete($aIPC[$IPC_CLIENTWND]) EndIf EndIf _InterProcess_Destroy_Monitor($aIPC) AutoItWinSetTitle($aIPC[$IPC_AUTOITID]) EndIf $aIPC = Null ; Destroy the contents of the API. Return $bReturn EndFunc ;==>_InterProcess_Destroy Func _InterProcess_Destroy_Monitor(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) And $aIPC[$IPC_ISMONITORING] Then $IPC[$IPC_CONTROLID] = 0 $aIPC[$IPC_ISMONITORING] = False $bReturn = True EndIf Return $bReturn EndFunc ;==>_InterProcess_Destroy_Monitor Func _InterProcess_GetClientID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_CLIENTID] : Null EndFunc ;==>_InterProcess_GetClientID Func _InterProcess_GetGlobalID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_GLOBALID] : Null EndFunc ;==>_InterProcess_GetGlobalID Func _InterProcess_GetMonitorID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_MONITORID] : 0 EndFunc ;==>_InterProcess_GetMonitorID Func _InterProcess_GetServerID(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_SERVERID] : Null EndFunc ;==>_InterProcess_GetServerID Func _InterProcess_GetData(ByRef $aIPC, ByRef $hWnd, ByRef $sMsg, ByRef $iMsg) $hWnd = 0 $iMsg = 0 $sMsg = '' Local $bReturn = False If __InterProcess_IsAPI($aIPC) And ($IPC[$IPC_RECEIVEDDATA] Or $IPC[$IPC_RECEIVEDMSG]) Then $bReturn = True $hWnd = (IsHWnd($IPC[$IPC_RECEIVEDWND]) ? $IPC[$IPC_RECEIVEDWND] : Null) ; hWnd. $iMsg = Int($IPC[$IPC_RECEIVEDMSG]) $sMsg = $IPC[$IPC_RECEIVEDDATA] ; Data EndIf $IPC[$IPC_RECEIVEDDATA] = '' $IPC[$IPC_RECEIVEDWND] = 0 $IPC[$IPC_RECEIVEDMSG] = 0 Return $bReturn EndFunc ;==>_InterProcess_GetData Func _InterProcess_GetClientWnd(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? $aIPC[$IPC_CLIENTWND] : Null EndFunc ;==>_InterProcess_GetClientWnd Func _InterProcess_GetServerWnd(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) ? (_InterProcess_IsThisServer($aIPC) ? $aIPC[$IPC_CLIENTWND] : $aIPC[$IPC_SERVERWND]) : Null EndFunc ;==>_InterProcess_GetServerWnd Func _InterProcess_IsClientExists(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And IsHWnd($aIPC[$IPC_CLIENTWND]) And $aIPC[$IPC_MONITORID] > 0 EndFunc ;==>_InterProcess_IsClientExists Func _InterProcess_IsMonitoring(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And $aIPC[$IPC_ISMONITORING] EndFunc ;==>_InterProcess_IsMonitoring Func _InterProcess_IsServerExists(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And IsHWnd($aIPC[$IPC_SERVERWND]) EndFunc ;==>_InterProcess_IsServerExists Func _InterProcess_IsThisServer(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And Not IsHWnd($aIPC[$IPC_SERVERWND]) EndFunc ;==>_InterProcess_IsThisServer Func _InterProcess_IsThisClient(ByRef $aIPC) Return __InterProcess_IsAPI($aIPC) And Not _InterProcess_IsThisServer($aIPC) EndFunc ;==>_InterProcess_IsThisClient Func _InterProcess_Monitor(ByRef $aIPC) Local $bReturn = False If __InterProcess_IsAPI($aIPC) And Not $aIPC[$IPC_ISMONITORING] Then $aIPC[$IPC_ISMONITORING] = True If _InterProcess_IsThisServer($aIPC) And Not _InterProcess_IsClientExists($aIPC) Then __InterProcess_Create($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_MONITORID], $aIPC[$IPC_SERVERID]) ElseIf _InterProcess_IsThisClient($aIPC) And Not _InterProcess_IsClientExists($aIPC) Then __InterProcess_Create($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_MONITORID], $aIPC[$IPC_CLIENTID]) EndIf $IPC[$IPC_CONTROLID] = $aIPC[$IPC_MONITORID] $bReturn = True EndIf Return $bReturn EndFunc ;==>_InterProcess_Monitor Func _InterProcess_SendToServer(ByRef $aIPC, $sMsg, $iMsg = Default) Return __InterProcess_IsAPI($aIPC) And __InterProcess_Send($aIPC[$IPC_CLIENTWND], $aIPC[$IPC_SERVERWND], $iMsg, $sMsg) EndFunc ;==>_InterProcess_SendToServer Func _InterProcess_SendToClient(ByRef $aIPC, $hWnd, $sMsg, $iMsg = Default) Return __InterProcess_IsAPI($aIPC) And __InterProcess_Send($aIPC[$IPC_CLIENTWND], $hWnd, $iMsg, $sMsg) EndFunc ;==>_InterProcess_SendToClient Func _InterProcess_SetGUID($sGUID) $IPC_GUID = $sGUID Return True EndFunc ;==>_InterProcess_SetGUID Func __InterProcess_Create(ByRef $hWnd, ByRef $iControl, $sID) If Not IsHWnd($hWnd) Or $hWnd = Default Then $hWnd = GUICreate('', 0, 0, -99, -99, $GUI_SS_DEFAULT_GUI, $WS_EX_TOOLWINDOW) GUISetState(@SW_SHOWNOACTIVATE, $hWnd) EndIf If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hWnd, $WM_COPYDATA, $MSGFLT_ALLOW) EndIf If Not $iControl Then $iControl = GUICtrlCreateDummy() EndIf GUIRegisterMsg($WM_COPYDATA, WM_COPYDATA) AutoItWinSetTitle($sID) Local Const $hAutoItWnd = WinGetHandle($sID) Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, ControlGetText($hAutoItWnd, '', $hControl) & @CRLF & _ '|IPC_WND:' & $hWnd & '|IPC_PID:' & @AutoItPID & @CRLF) ; Set the communication handle and PID. Return True EndFunc ;==>__InterProcess_Create Func __InterProcess_IsAPI(ByRef $aIPC) Return UBound($aIPC) = $IPC_MAX And $aIPC[$IPC_ID] = $IPC_GUID EndFunc ;==>__InterProcess_IsAPI Func __InterProcess_Send($hSender, $hReciever, $iMsg, $sMsg) If Not IsHWnd($hReciever) Then Return SetError(1, 0, False) EndIf If StringStripWS($sMsg, $STR_STRIPALL) = '' Then Return SetError(2, 0, False) EndIf If Not IsInt($iMsg) Then $iMsg = 0 EndIf $sMsg = $IPC_GUID & $sMsg Local Const $tBuffer = DllStructCreate('wchar cdata[' & StringLen($sMsg) + 1 & ']') DllStructSetData($tBuffer, 'cdata', $sMsg) Local Const $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT) DllStructSetData($tCOPYDATASTRUCT, 'dwData', $iMsg) DllStructSetData($tCOPYDATASTRUCT, 'cbData', DllStructGetSize($tBuffer)) DllStructSetData($tCOPYDATASTRUCT, 'lpData', DllStructGetPtr($tBuffer)) _SendMessage($hReciever, _ $WM_COPYDATA, _ $hSender, _ DllStructGetPtr($tCOPYDATASTRUCT)) Return Not @error EndFunc ;==>__InterProcess_Send Func WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local Const $tCOPYDATASTRUCT = DllStructCreate($tagCOPYDATASTRUCT, $lParam) Local Const $tBuffer = DllStructCreate('wchar cdata[' & DllStructGetData($tCOPYDATASTRUCT, 'cbData') / 2 & ']', DllStructGetData($tCOPYDATASTRUCT, 'lpData')) $IPC[$IPC_RECEIVEDDATA] = StringRegExpReplace(DllStructGetData($tBuffer, 'cdata'), '^' & $IPC_GUID, '') ; Data. If @extended > 0 Then $IPC[$IPC_RECEIVEDWND] = $wParam ; hWnd. $IPC[$IPC_RECEIVEDMSG] = DllStructGetData($tCOPYDATASTRUCT, 'dwData') ; Message. If $IPC[$IPC_CONTROLID] > 0 Then GUICtrlSendToDummy($IPC[$IPC_CONTROLID]) ; Send to the control. EndIf Else $IPC[$IPC_RECEIVEDDATA] = '' EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_COPYDATA1 point
-
To resurrect an old thread, which was the first I found when looking for the answer, I made the following to deactivate the saver on Win8.1. Maybe useful for others... #include <File.au3> func KillScreenSaver() local $szDrive, $szDir, $szFName, $szExt $sspath=RegRead("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") if @error<>0 then return 0 _PathSplit($sspath, $szDrive, $szDir, $szFName, $szExt ) $SCRproc=$szFName & $szExt if ProcessExists($SCRproc) Then processclose($SCRproc) ProcessWaitClose($SCRproc,1) EndIf EndFunc1 point
-
This is possible without automating any user interface. If this is only your second project, then you won't have been exposed yet to the monstrosity that is the Windows API (shortened to WinAPI). The WinAPI dlls give you control over nearly everything on the system, but with great power comes great big confusing documentation pages, on a site called MSDN. With great power also comes great ability to get your computer completely FUBAR. So with that warning in place, here is the code to rotate the screen directly with the winapi. Hopefully this shows you just how powerful programming can be, and why it is a great skill to learn #include <APIGdiConstants.au3> #include <WinAPIGdi.au3> Local $i = 0, $aData $aData = _WinAPI_EnumDisplaySettings('', $ENUM_CURRENT_SETTINGS) ConsoleWrite('Current settings: ' & $aData[0] & ' x ' & $aData[1] & ' x ' & $aData[2] & ' bit, ' & $aData[3] & ' hz' & @CRLF) ; Store the current settings $tDM = _WinAPI_EnumDisplaySettingsEx("", $ENUM_CURRENT_SETTINGS) ; Get the settings to change $tDM2 = _WinAPI_EnumDisplaySettingsEx("", $ENUM_CURRENT_SETTINGS) ; Flip orientation, but also switch width/height. $tDM2.Fields = BitOR($tDM2.Fields, $DM_DISPLAYORIENTATION) $tDM2.DisplayOrientation = $DMDO_90 $v = $tDM2.PelsWidth $tDM2.PelsWidth = $tDM2.PelsHeight $tDM2.PelsHeight = $v ; Change the display settings $ret = _WinAPI_ChangeDisplaySettings($tDM2, 0) ; Wait for the user to click ok, will also timeout after 10 seconds just in case I've messed the display up. MsgBox(0, $ret, "H" & @LF & "e" & @LF & "l" & @LF & "l" & @LF & "o", 10) _WinAPI_ChangeDisplaySettings($tDM, 0) MsgBox(0, @error, "Back to normal") Func _WinAPI_ChangeDisplaySettings($tDevMode, $dwFlags) Local $aRet = DllCall("user32.dll", "LONG", "ChangeDisplaySettingsW", "ptr", DllStructGetPtr($tDevMode), "DWORD", $dwFlags) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc ;==>_WinAPI_ChangeDisplaySettings ; #FUNCTION# ==================================================================================================================== ; Author.........: Yashied ; Modified.......: jpm, Mat ; =============================================================================================================================== Func _WinAPI_EnumDisplaySettingsEx($sDevice, $iMode) Local $sTypeOfDevice = 'wstr' If Not StringStripWS($sDevice, $STR_STRIPLEADING + $STR_STRIPTRAILING) Then $sTypeOfDevice = 'ptr' $sDevice = 0 EndIf Local $tDevMode = DllStructCreate($tagDEVMODE_DISPLAY) DllStructSetData($tDevMode, 'Size', DllStructGetSize($tDevMode)) DllStructSetData($tDevMode, 'DriverExtra', 0) Local $aRet = DllCall('user32.dll', 'bool', 'EnumDisplaySettingsW', $sTypeOfDevice, $sDevice, 'dword', $iMode, _ 'struct*', $tDevMode) If @error Or Not $aRet[0] Then Return SetError(@error + 10, @extended, 0) Return $tDevMode EndFunc ;==>_WinAPI_EnumDisplaySettingsEx1 point