Jump to content

HOw to make this C++ script work in AutoIt


Recommended Posts

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <math.h>
#include "commctrl.h"

#define TIMER_ELAPSE        50
#define ICON_HFWIDTH        35
#define ICON_HFHEIGHT       35
#define MAX_LEN         65

// get currrent list view
HWND GetLstView(POINT * pt /*= NULL*/)
{
    const char * strLstVClass = "SysListView32";
    char ClassName[MAX_LEN];
    if(NULL == pt) return NULL;
    HWND hDeskView = WindowFromPoint(*pt);
    GetClassName(hDeskView, ClassName, 64);
    if(0 == strcmp(ClassName,strLstVClass))
        return hDeskView;
    return NULL;
}

// get icon's position
void GetItemPos(HWND hLstView, int i, POINT * ppt)
{
    DWORD dwProcessId;
    GetWindowThreadProcessId(hLstView,&dwProcessId);
    HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, dwProcessId);
    PVOID vpt = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);
    ListView_GetItemPosition(hLstView,i,vpt);
    ReadProcessMemory(hProcess, vpt, ppt, sizeof(POINT), NULL);
    VirtualFreeEx(hProcess, vpt, NULL, MEM_RELEASE);
    CloseHandle(hProcess);
}

// icons esacpe
void Escape(int iRadius)
{
    int i, iCount;
    POINT ptCur;
    RECT rctLst, rctUpdate;
    HWND hLstView;
    //get listview
    GetCursorPos(&ptCur);
    if(NULL == (hLstView = GetLstView(&ptCur))) return;
    //show my name, pls remain it
    GetClientRect(hLstView, &rctLst);
    rctUpdate = rctLst;
    rctUpdate.left = rctLst.right - 130;
    rctUpdate.top = rctLst.bottom - 40;
    InvalidateRect(hLstView, &rctUpdate,true);
    HDC hdc = GetDC(hLstView);
    COLORREF crPre = SetTextColor(hdc,RGB(0,255,0));
    int iBk = SetBkMode(hdc,TRANSPARENT);
    TextOut(hdc, rctLst.right - 120, rctLst.bottom - 30, "Caohai 12/31/04", 15);
    SetTextColor(hdc,crPre);
    SetBkMode(hdc, iBk);
    ReleaseDC(hLstView,hdc);
    //set listview to icon style
    DWORD dwStyle = GetWindowLong(hLstView,GWL_STYLE);
    dwStyle = dwStyle & ~LVS_AUTOARRANGE & ~LVS_SMALLICON & ~LVS_LIST & ~LVS_REPORT;
    SetWindowLong(hLstView, GWL_STYLE, dwStyle);
    //escape
    iCount = ListView_GetItemCount(hLstView);
    ScreenToClient(hLstView,&ptCur);
    for(i=0; i<iCount; i++)
    {
        POINT ptIcon, ptIC;
        GetItemPos(hLstView,i,&ptIcon);
        ptIC.x = ptIcon.x + ICON_HFWIDTH;
        ptIC.y = ptIcon.y + ICON_HFHEIGHT;
        float fDistance = sqrt((float)(ptIC.y - ptCur.y) * (ptIC.y - ptCur.y) + (ptIC.x - ptCur.x) * (ptIC.x - ptCur.x));
        if(fDistance < (float)iRadius && (ptIC.x != ptCur.x) && ((fDistance > 0.0) ||(fDistance < 0.0))) 
        {//move
            ptIcon.x = ptCur.x + (LONG)((iRadius * (ptIC.x - ptCur.x)) / fDistance) - ICON_HFWIDTH;
            ptIcon.y = ptCur.y + (LONG)((iRadius * (ptIC.y - ptCur.y)) / fDistance) - ICON_HFHEIGHT;
            if(ptIcon.x < 2 * ICON_HFWIDTH || ptIcon.x > rctLst.right - 2 * ICON_HFWIDTH)
            {
                srand((int)ptIcon.x * i);
                ptIcon.x = (rand() % rctLst.right);
            }
            if(ptIcon.y < 2 * ICON_HFHEIGHT || ptIcon.y > rctLst.bottom - 2 * ICON_HFHEIGHT)
            {
                srand((int)ptIcon.y * i);
                ptIcon.y = (rand() % rctLst.bottom);
            }
            ListView_SetItemPosition(hLstView, i, ptIcon.x, ptIcon.y);
        }
    }
}

// win main
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    if(hPrevInstance != NULL)
        return FALSE;
    SetTimer(NULL,1,TIMER_ELAPSE,NULL);
    while(GetMessage(&msg, NULL, WM_TIMER, WM_TIMER)) 
        Escape(100);
    KillTimer(NULL,1);
    return (int) msg.wParam;
}

only make this C++ script work in AutoIt

//set listview to icon style
    DWORD dwStyle = GetWindowLong(hLstView,GWL_STYLE);
    dwStyle = dwStyle & ~LVS_AUTOARRANGE & ~LVS_SMALLICON & ~LVS_LIST & ~LVS_REPORT;
    SetWindowLong(hLstView, GWL_STYLE, dwStyle);

我不懂英文啊。。只是想知道怎么取消桌面图标的自动排列

Link to comment
Share on other sites

C++ code

I've no idea. :)

Maybe if you said what you wanted to do it would be easier to start from scratch. ;)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Most of that code has already been done in autoit... check the example scripts forum.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...