Results 1 to 3 of 3

Thread: Clear cache

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default Clear cache

    Soooo I wrote 2 apps. One using win32 API (which I prefer using, but it doesn't work.)
    The 2nd method is console based, which works, but it lacks optimization. Any help would be appreciated.

    Code:
    // shoreTel.cpp : Defines the entry point for the application.
    //
    #include "stdafx.h"
    #include "shoreTel.h"
    #include <shellapi.h>
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <cstdlib>
    #define  MAX_LOADSTRING 100
    #define  TOGGABLE_KEYS 10002
    #define  IDT_TIMER  WM_USER + 200
    
    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    
    //This renders the vidual content
    HWND myDialog = CreateWindowEx(0,WC_DIALOG,"", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0,0,1,1,NULL,NULL,NULL,NULL);
    
    //Cache Maintenance Window
    HWND hWnd1 = FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
    //Purge Maintenance Window
    HWND hWnd2 = FindWindow("TfrmConfirmPurgeProcess","Confirmation");
    
    DWORD dwLastError = GetLastError();
    
    char* MakeLower( char* strLower )
    {
        int size = strlen(strLower);
        char *newstr = (char*)malloc(size);
    
        for(int loop = 0; loop < strlen(newstr); loop++)
        {
            newstr[loop] = tolower(strLower[loop]);
        }
    
        return newstr;
    }
    
    int CheckProcess( char* ProcessName )
    {
        int n_PId=0;
    
        HANDLE n_NewSnapshot;
        PROCESSENTRY32 procA;
        n_NewSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
            
        if (n_NewSnapshot==INVALID_HANDLE_VALUE) 
        {
            CloseHandle(n_NewSnapshot);
            return 0;
        }
    
        procA.dwSize = sizeof(procA);
    
        while (Process32Next(n_NewSnapshot,&procA)) 
        {
            if(strcmp(MakeLower(procA.szExeFile), MakeLower(ProcessName)) == 0) 
            {
                n_PId = procA.th32ProcessID;
            }
        }
    
        CloseHandle(n_NewSnapshot);
            return n_PId;
    }
    
    int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
    {
        //This checks if the process is already running so you don't have multiple instances running.
        HANDLE handle = CreateMutex(NULL, true, "MHC-CM");
        if(GetLastError() != ERROR_SUCCESS)
        {
        //    MessageBox(0, "Process is already running", "Warning", MB_ICONWARNING);
            return false;
        }
        ShowWindow(myDialog, SW_HIDE);
         // TODO: Place code here.
        MSG msg;
        HACCEL hAccelTable;
    
        // Initialize global strings
        MyRegisterClass(hInstance);
    
        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow)) 
        {
            return FALSE;
        }
    
        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SHORETEL);
    
        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0)) 
        {
                DWORD ProcessID1; 
        GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
        HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
        DWORD ProcessID2; 
        GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
        HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                if(hWnd1)
                { 
                    MessageBox(0, "window1 is already running", "Warning", MB_ICONWARNING);
                    if(Process1)
                    {
                        MessageBox(0, "Process1 is already running", "Warning", MB_ICONWARNING);
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    MessageBox(0, "window2 is already running", "Warning", MB_ICONWARNING);
                    if(Process2)
                    {
                        MessageBox(0, "Process2 is already running", "Warning", MB_ICONWARNING);
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
    
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        return (int) msg.wParam;
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
        WNDCLASSEX wcex;
    
        wcex.cbSize = sizeof(WNDCLASSEX); 
    
        wcex.style            = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc    = (WNDPROC)WndProc;
        wcex.cbClsExtra        = 0;
        wcex.cbWndExtra        = 0;
        wcex.hInstance        = hInstance;
        wcex.hIcon            = LoadIcon(hInstance, (LPCTSTR)IDI_SHORETEL);
        wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName    = (LPCTSTR)IDC_SHORETEL;
    //    wcex.lpszClassName    = szWindowClass;
        wcex.hIconSm        = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
    
        return RegisterClassEx(&wcex);
    }
    
    LRESULT WINAPI myProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
    {
        int wmId;
        int wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;
        switch (message) 
        {
            case WM_CLOSE:
                PostQuitMessage(0);
            break;
    
            case WM_INITDIALOG:
                //** Set timers
                SetTimer(hwnd, TOGGABLE_KEYS, 1, NULL);
            break;
    
            case WM_PAINT:
            {    
                hdc = BeginPaint(myDialog, &ps);
    
                if(hWnd1)
                { 
                    //Cache Maintenance Window
                    DWORD ProcessID1; 
                    GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
                    HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
                    if(Process1)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    //Cache Maintenance Window
                    DWORD ProcessID2; 
                    GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
                    HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                    if(Process2)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
                
                EndPaint(myDialog, &ps);
            }
            break;
    
            case WM_COMMAND:
            {
                wmId    = LOWORD(wParam); 
                wmEvent = HIWORD(wParam); 
                // Parse the menu selections:
                switch (wmId)
                {
                    case IDM_EXIT:
                        DestroyWindow(myDialog);
                    break;
    
                    default:
                        return DefWindowProc(myDialog, message, wParam, lParam);
                }
            }
            break;
            
            case WM_TIMER:
                /*
            if(hWnd1 || hWnd2)
            {
                Sleep(100);
                DWORD ProcessID; 
                GetWindowThreadProcessId( hWnd1, &ProcessID ); 
                HANDLE Process = OpenProcess( PROCESS_VM_READ|PROCESS_VM_OPERATION, FALSE, ProcessID ); 
    
                DWORD ProcessID2; 
                GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
                HANDLE Process2 = OpenProcess( PROCESS_VM_READ|PROCESS_VM_OPERATION, FALSE, ProcessID2 ); 
    
                if((hWnd1 || hWnd2) && (ProcessID || ProcessID2))
                {
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
                }
    
                CloseHandle(Process);
                CloseHandle(Process2);
            }
            */
                if(hWnd1)
                { 
                    //Cache Maintenance Window
                    DWORD ProcessID1; 
                    GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
                    HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
                    if(Process1)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    //Cache Maintenance Window
                    DWORD ProcessID2; 
                    GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
                    HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                    if(Process2)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
    
            break;
            /*
            NOTE: If you comment the below, this will allow the user to move or close out the window (may not be a good idea)
                  This way the code below stops all user interaction unless they press the "Close Dialog" button.
            */
            default:
                return DefWindowProc(myDialog, message, wParam, lParam);
        }
        return 0; 
    }
    
    BOOL staticDlg(HINSTANCE hInstance, int nCmdShow)
    {
        DWORD ProcessID1; 
        GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
        HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
        DWORD ProcessID2; 
        GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
        HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                if(hWnd1)
                { 
                    if(Process1)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    if(Process2)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
    
    
        ShowWindow(myDialog, SW_HIDE);
    
        SetWindowPos( myDialog, HWND_TOPMOST, 0, 0 , 0 , 0, SWP_NOMOVE | SWP_NOSIZE );
    
        return TRUE;
    }
    
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
        DWORD ProcessID1; 
        GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
        HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
        DWORD ProcessID2; 
        GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
        HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                if(hWnd1)
                { 
                    if(Process1)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    if(Process2)
                    {
                        Sleep(50);
                        //Emulated keypresses
                        keybd_event(VK_RIGHT, NULL, NULL, NULL);
                        keybd_event(VK_RIGHT, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
    
       if (!myDialog)
       {
          return FALSE;
       }
    
       UpdateWindow(myDialog);
       SetTimer(myDialog, 1, 1, NULL);
    
       return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        int wmId;
        int wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;
    
        switch (message) 
        {
            case WM_CLOSE:
                PostQuitMessage(0);
            break;
    
            case WM_COMMAND:
                wmId    = LOWORD(wParam); 
                wmEvent = HIWORD(wParam); 
                // Parse the menu selections:
                switch (wmId)
                {
                    case IDM_EXIT:
                        DestroyWindow(hWnd);
                    break;
    
                    default:
                        return DefWindowProc(hWnd, message, wParam, lParam);
                }
            break;
    
            case WM_PAINT:
                hdc = BeginPaint(myDialog, &ps);
                // TODO: Add any drawing code here...
                EndPaint(myDialog, &ps);
            break;
    
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
    
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }
    Code:
    // MHC-CM.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <cstdlib>
    
    char* MakeLower( char* strLower )
    {
        int size = strlen(strLower);
        char *newstr = (char*)malloc(size);
    
        for(int loop = 0; loop < strlen(newstr); loop++)
        {
            newstr[loop] = tolower(strLower[loop]);
        }
    
        return newstr;
    }
    
    int CheckProcess( char* ProcessName )
    {
        int n_PId=0;
    
        HANDLE n_NewSnapshot;
        PROCESSENTRY32 procA;
        n_NewSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
            
        if (n_NewSnapshot==INVALID_HANDLE_VALUE) 
        {
            CloseHandle(n_NewSnapshot);
            return 0;
        }
    
        procA.dwSize = sizeof(procA);
    
        while (Process32Next(n_NewSnapshot,&procA)) 
        {
            if(strcmp(MakeLower(procA.szExeFile), MakeLower(ProcessName)) == 0) 
            {
                n_PId = procA.th32ProcessID;
            }
        }
    
        CloseHandle(n_NewSnapshot);
            return n_PId;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        bool run = true;
    
        // Stealth mode so we don't see the command prompt window
        HWND stealth = FindWindowA("ConsoleWindowClass",NULL);
        FreeConsole();
    
    
        while(1 && run == true)
        {
            Sleep(100);
    
            //Check to make sure Allscripts is running. 
            if(!CheckProcess("MHC.exe"))
            {
                Sleep(100);
                run = false;
                return 0;
            }
    
            //Cache Maintenance Window
            HWND hWnd1 = FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
            //Purge Maintenance Window
            HWND hWnd2 = FindWindow("TfrmConfirmPurgeProcess","Confirmation");
            Sleep(100);
    
            //This portion checks for the Cache Maintenance Message Box
            if(hWnd1)
            { 
                //Cache Maintenance Window
                DWORD ProcessID1; 
                GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
                HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
                if(Process1)
                {
                    //Emulated keypresses
                    keybd_event(VK_RETURN, NULL, NULL, NULL);
                    keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
                    run = true;
    
                    CloseHandle(Process1);
                }
            }
                
            //This portion checks for the Purge Maintenance Message Box
            else if(hWnd2)
            { 
                //Purge Maintenance Window
                DWORD ProcessID2; 
                GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
                HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                if(Process2)
                {
                    //Emulated keypresses
                    keybd_event(VK_RETURN, NULL, NULL, NULL);
                    keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
    
                    run = true;
                    CloseHandle(Process2);
                }
            }
            Sleep(100);
            run = true;
        }
        run = false;
        return 0;
    }

  2. #2

    Default

    There is a memory leak in MakeLower and you are trying to use a Window Class without initializing it first.

    Did you learn programming in Java?


    MakeLower is not needed at all,
    instead of strcmp(MakeLower(procA.szExeFile), MakeLower(ProcessName)
    use stricmp.

    Create the window in InitInstance (after the class is registered).
    And assign the window in both the Register and Create call a unique classname.

  3. #3
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Did you learn programming in Java?
    Yes, and I despised it.

    Alright I made these changes, but it doesn't trigger on hWnd1 & 2 :S
    Code:
    // shoreTel.cpp : Defines the entry point for the application.
    //
    #include "stdafx.h"
    #include "shoreTel.h"
    #include <shellapi.h>
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <cstdlib>
    #define  MAX_LOADSTRING 100
    #define  TOGGABLE_KEYS 10002
    #define  IDT_TIMER  WM_USER + 200
    
    // Global Variables:
    HINSTANCE hInst;                                // current instance
    TCHAR szTitle[MAX_LOADSTRING];                    // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
    
    //Needed for the FindWindowClassContains() & FindWindowTitleContains() Functions
    struct result_stru 
    {
        char* text;
        UINT (__stdcall*GET)(HWND,LPSTR,UINT);
        HWND hRet;
    };
    
    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    BOOL WINAPI            StruEnumProc( HWND , result_stru* );
    
    //Cache Maintenance Window
    HWND hWnd1 = FindWindow("TfrmConfirmCacheMaintenance","Confirmation");
    //Purge Maintenance Window
    HWND hWnd2 = FindWindow("TfrmConfirmPurgeProcess","Confirmation");
    
    DWORD dwLastError = GetLastError();
    
    /* These functions allow to find the correct Window & Class Name */
    BOOL WINAPI StruEnumProc( HWND hwnd, result_stru* stru )
    {
        char loc_buf[128];
        stru->GET( hwnd, loc_buf, 127 );
        if( strstr( loc_buf, stru->text ) ) 
        {
            stru->hRet = hwnd;
            return FALSE;
        }
        return TRUE;
    }
    
    char* MakeLower( char* strLower )
    {
        int size = strlen(strLower);
        char *newstr = (char*)malloc(size);
    
        for(int loop = 0; loop < strlen(newstr); loop++)
        {
            newstr[loop] = tolower(strLower[loop]);
        }
    
        return newstr;
    }
    
    int CheckProcess( char* ProcessName )
    {
        int n_PId=0;
    
        HANDLE n_NewSnapshot;
        PROCESSENTRY32 procA;
        n_NewSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,NULL);
            
        if (n_NewSnapshot==INVALID_HANDLE_VALUE) 
        {
            CloseHandle(n_NewSnapshot);
            return 0;
        }
    
        procA.dwSize = sizeof(procA);
    
        while (Process32Next(n_NewSnapshot,&procA)) 
        {
            //if(strcmp(MakeLower(procA.szExeFile), MakeLower(ProcessName)) == 0)
            if(stricmp(MakeLower(procA.szExeFile), MakeLower(ProcessName)) == 0)
            {
                n_PId = procA.th32ProcessID;
            }
        }
    
        CloseHandle(n_NewSnapshot);
            return n_PId;
    }
    
    int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
    {
        //This checks if the process is already running so you don't have multiple instances running.
        HANDLE handle = CreateMutex(NULL, true, "MHC-CM");
        if(GetLastError() != ERROR_SUCCESS)
        {
        //    MessageBox(0, "Process is already running", "Warning", MB_ICONWARNING);
            return false;
        }
    
        // TODO: Place code here.
        MSG msg;
        HACCEL hAccelTable;
    
        // Initialize global strings
        MyRegisterClass(hInstance);
    
        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow)) 
        {
            return FALSE;
        }
    
        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0)) 
        {
            if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        return (int) msg.wParam;
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
        WNDCLASSEX wcex;
    
        wcex.cbSize = sizeof(WNDCLASSEX); 
    
        wcex.style            = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc    = (WNDPROC)WndProc;
        wcex.cbClsExtra        = 0;
        wcex.cbWndExtra        = 0;
        wcex.hInstance        = hInstance;
        wcex.hIcon            = LoadIcon(NULL , IDI_ASTERISK);
        wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName    = NULL ;
        wcex.lpszClassName    = szWindowClass;
        wcex.hIconSm        = LoadIcon(NULL , IDI_ERROR);
    
        return RegisterClassEx(&wcex);
    }
    
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
        HWND myDialog;
        hInst = hInstance;
    
        //This renders the visual content
        myDialog = CreateWindowEx(0,WC_DIALOG,"", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0,0,1,1,NULL,NULL,hInstance,NULL);
    
       if (!myDialog)
       {
          return FALSE;
       }
    
       SetTimer(myDialog, 1, 1, NULL);
    
       ShowWindow(myDialog,SW_HIDE);
       UpdateWindow(myDialog);
    
       return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        int wmId;
        int wmEvent;
    //    PAINTSTRUCT ps;
    //    HDC hdc;
    
        switch (message) 
        {
            case WM_CLOSE:
                PostQuitMessage(0);
            break;
    
            case WM_COMMAND:
            {
                wmId    = LOWORD(wParam); 
                wmEvent = HIWORD(wParam); 
                // Parse the menu selections:
                switch (wmId)
                {
                    case IDM_EXIT:
                        DestroyWindow(hWnd);
                    break;
    
                    default:
                        return DefWindowProc(hWnd, message, wParam, lParam);
                }
            }
            break;
    /*
            case WM_PAINT:
            {
                hdc = BeginPaint(myDialog, &ps);
                // TODO: Add any drawing code here...
                EndPaint(myDialog, &ps);
            }
            break;
    */
            case WM_TIMER:
            {
                DWORD ProcessID1; 
                GetWindowThreadProcessId( hWnd1, &ProcessID1 ); 
                HANDLE Process1 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID1 ); 
    
                DWORD ProcessID2; 
                GetWindowThreadProcessId( hWnd2, &ProcessID2 ); 
                HANDLE Process2 = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID2 ); 
    
                if(hWnd1)
                { 
                    MessageBox( NULL , "Window1" , "Info" , MB_OK);
                    if(Process1)
                    {
                        Sleep(50);
                        MessageBox( NULL , "Process1" , "Info" , MB_OK);
                        //Emulated keypresses
                        //keybd_event(VK_RETURN, NULL, NULL, NULL);
                        //keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
                        CloseHandle(Process1);
                    }
                }
    
                else if(hWnd2)
                { 
                    MessageBox( NULL , "Window2" , "Info" , MB_OK);
                    if(Process2)
                    {
                        Sleep(50);
                        MessageBox( NULL , "Process2" , "Info" , MB_OK);
                        //Emulated keypresses
                        //keybd_event(VK_RETURN, NULL, NULL, NULL);
                        //keybd_event(VK_RETURN, NULL, KEYEVENTF_KEYUP, NULL);
    
                        CloseHandle(Process2);
                    }
                }
            }
            break ;
    
            case WM_DESTROY:
                PostQuitMessage(0);
            break;
    
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •