Hirdetés

Új hozzászólás Aktív témák

  • pmonitor

    aktív tag

    válasz sztanozs #16528 üzenetére

    Készítettem tesztprogramot C-ben, csak nem tudom, hogy mikor tudom hosszasan futtatni. pidtesztA:
    #include <windows.h>

    HINSTANCE hInstance = NULL;
    char* AppName = "PID teszt \"A\"";
    char* WindowClassName = "pidtesztA";
    HWND AppHwnd = NULL;

    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

    int main()
    {
    WNDCLASSEX wc;
    MSG msg;
    hInstance = GetModuleHandle(NULL);
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hbrBackground = COLOR_BTNFACE + 1;
    wc.hInstance = hInstance;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = WindowClassName;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    RegisterClassEx(&wc);
    AppHwnd = CreateWindowEx(0, WindowClassName, AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1200, 900, 0, 0, hInstance, 0);
    ShowWindow(AppHwnd, SW_SHOWDEFAULT);
    UpdateWindow(AppHwnd);
    while (GetMessage(&msg, 0, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_CREATE:
    ShowWindow(AppHwnd, SW_NORMAL);
    break;
    case WM_COMMAND:
    break;
    case WM_SIZE:
    {
    break;
    }
    case WM_SHOWWINDOW:
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
    break;
    }

    }

    pidtesztB:
    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>

    STARTUPINFOA SI;
    PROCESS_INFORMATION PI;
    HWND Pids[400000000];
    int PidsP = 0;
    int waitmsec = 500;

    int appStart(char name[])
    {
    if (!CreateProcessA(NULL, name, NULL, NULL, FALSE, 0, NULL, NULL, &SI, &PI))
    {
    printf("A %s file-t nem lehet megnyitni...\n", name);
    return -1;
    }
    WaitForSingleObject(PI.hProcess, waitmsec);
    return 0;
    }



    int main(int argc, char* argv[])
    {
    DWORD procid = 0, hwndid;
    ZeroMemory(&SI, sizeof(SI));
    SI.cb = sizeof(SI);
    ZeroMemory(&PI, sizeof(PI));
    if (argc == 3) waitmsec = atoi(argv[2]);
    char appA[50] = "pidtesztA.exe";
    char appAClass[50] = "pidtesztA";
    if (!appStart(appA))
    {
    HWND hwnd = FindWindowExA(NULL, NULL, appAClass, NULL);
    while (hwnd)
    {
    int pidact = 0;
    int tid = GetWindowThreadProcessId(hwnd, &pidact);
    Pids[PidsP] = pidact;
    PidsP++;
    hwnd = FindWindowExA(NULL, hwnd, appAClass, NULL);
    }
    TerminateProcess(PI.hProcess, 0);
    }
    HWND prochwnd;
    int i, out = 0, imax = 500;
    if (argc >= 2) imax = atoi(argv[1]);
    for (i = 0; i < imax; i++)
    {
    ZeroMemory(&SI, sizeof(SI));
    SI.cb = sizeof(SI);
    ZeroMemory(&PI, sizeof(PI));
    if (!appStart(appA))
    {
    HWND hwnd = FindWindowExA(NULL, NULL, appAClass, NULL);
    while (hwnd)
    {
    int pidact = 0;
    int tid = GetWindowThreadProcessId(hwnd, &pidact);
    int j = 0;
    while (j < PidsP)
    {
    if (Pids[j] == pidact)
    {
    printf("Pid egyezik!\n");
    out = 1;
    break;
    }
    j++;
    }
    if (out) break;
    Pids[PidsP] = pidact;
    PidsP++;
    hwnd = FindWindowExA(NULL, hwnd, appAClass, NULL);
    }
    TerminateProcess(PI.hProcess, 0);
    if (out) break;
    }
    }
    printf("i: %d\n", i);
    return 0;
    }

    Mint látható az "A" egy standard window. A "B" console. Az indítási intervallum, és a waitforsingleobject() ideje is alapból 500, de parancssorból változtatható, mint az a kódból is látható. A szám adatok validitását nem ellenőriztem le, csak egyből konvertál(legalábbis megpróbál :) ).
    Még nem tudtam hosszan futtatni. Ha vki. működésbeli hibát vesz észre, Ő kérem jelezze.

Új hozzászólás Aktív témák

Hirdetés