Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: setting window active

  1. #11

    Default

    Not sure... Havent had that problem but if your looking for more win32 functions.. http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx msdn is always a must there may be a different function to use to fix this on there..
    Last edited by clint; June 27th, 2010 at 10:46 AM.

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

    Default

    So just an update I figured out what was causing the prog to crash. It was this line of code
    PHP Code:
    SetWindowLong(myDialogDWL_DLGPROC, (long)myProc); 
    One strange thing though is that I can't seem to get any keystrokes to be acknowledged for that static dialog window. I tried using getasynckeystate and even switch(message) using events like WM_CLOSE WM_DESTROY, VK_ESCAPE... I don't know why it doesn't work hmm...

  3. #13
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    Try to use this:

    http://msdn.microsoft.com/en-us/libr...65(VS.85).aspx

    DialogBoxParam, make your window in Resource Editor, add the resources to project. Then this function will load this window and whats more, you can specify the function for this window that will handle all the messages that go to this window.

    and modal means that it won't go off, behind any window, until user won't close it.

  4. #14

    Default

    Quote Originally Posted by James View Post
    So just an update I figured out what was causing the prog to crash. It was this line of code
    PHP Code:
    SetWindowLong(myDialogDWL_DLGPROC, (long)myProc); 
    One strange thing though is that I can't seem to get any keystrokes to be acknowledged for that static dialog window. I tried using getasynckeystate and even switch(message) using events like WM_CLOSE WM_DESTROY, VK_ESCAPE... I don't know why it doesn't work hmm...
    you have to save the return value from setwinlong, and use that with CallWindowProc in your function myProc

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

    Default

    I updated the code and cleaned it up. I now have this. Still requires some tweaking, but I'm getting there. And thanks for all the input, I'm trying to take as much input as I can, but some of it is just a bit beyond my skill level. Anywho, here is what I currently have:

    PHP Code:
    // shoreTel.cpp : Defines the entry point for the application.
    //
    #include "stdafx.h"
    #include "shoreTel.h"
    #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
    // Forward declarations of functions included in this code module:
    ATOM    MyRegisterClass(HINSTANCE hInstance);
    BOOL    InitInstance(HINSTANCEint);
    LRESULT CALLBACK  WndProc(HWNDUINTWPARAMLPARAM);
    BOOL    staticDlg(HINSTANCE int );
    bool minimized false;
    bool maximized true;
    bool msgHide false;
    bool msgShow false;
    HWND myDialog CreateWindowEx(0,WC_DIALOG,"Testing..."WS_VISIBLE|WS_OVERLAPPEDWINDOW400,100,800,600,NULL,NULL,NULL,NULL);
    HWND myBox CreateWindowEx(0"STATIC",""SS_CENTERIMAGE SS_REALSIZEIMAGE SS_BITMAP WS_CHILD WS_VISIBLE00800600myDialog, (HMENU)-1NULLNULL );
    HWND myButton CreateWindowEx0"BUTTON""Def Push Button"WS_CHILD WS_VISIBLE BS_DEFPUSHBUTTON200200 100 100100myDialog, (HMENU)ID_BUTTON1NULLNULL );
     
    /* These functions allow to find the correct Window & Class Name */
    struct result_stru 
    {
        
    chartext;
        
    UINT (__stdcall*GET)(HWND,LPSTR,UINT);
        
    HWND hRet;
    };
    BOOL WINAPI StruEnumProcHWND hwndresult_strustru )
    {
        
    char loc_buf[128];
        
    stru->GEThwndloc_buf127 );
        if( 
    strstrloc_bufstru->text ) ) 
     {
            
    stru->hRet hwnd;
            return 
    FALSE;
        }
        return 
    TRUE;
    }
    //case sensitive!
    HWND FindWindowTitleContainschartext )
    {
        
    result_stru res = { text, (UINT (__stdcall *)(HWND,LPSTR,UINT))GetWindowTextA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }
    //case sensitive!
    HWND FindWindowClassContainschartext )
    {
        
    result_stru res = { textRealGetWindowClassA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }
    int APIENTRY _tWinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPTSTR lpCmdLineint nCmdShow)
    {
      
    // TODO: Place code here.
     
    MSG msg;
     
    HACCEL hAccelTable;
     
    // Initialize global strings
     
    MyRegisterClass(hInstance);
     
    // Perform application initialization:
     
    if (!InitInstance (hInstancenCmdShow)) 
     {
      return 
    FALSE;
     }
     
    hAccelTable LoadAccelerators(hInstance, (LPCTSTR)IDC_SHORETEL);
     
    // Main message loop:
     
    while (GetMessage(&msgNULL00)) 
     {
      if (!
    TranslateAccelerator(msg.hwndhAccelTable, &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(NULLIDC_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 hwndUINT messageWPARAM wParamLPARAM lParam
    {
     switch (
    message
     {
      case 
    WM_CLOSE:
       
    PostQuitMessage(0);
      break;
      case 
    WM_INITDIALOG:
       
    //** Set timers
       
    SetTimer(hwndTOGGABLE_KEYS1NULL);
      break;
      case 
    WM_TIMER:
      {
       
    HINSTANCE hInst;
       
    int nCmdShow;
       
    //Get the Class Name
       
    HWND hWnd1 FindWindowClassContains"Afx:00400000:b:0001" );
       
    //Get the Title Name
       
    HWND hWnd2 FindWindowTitleContains"ShoreWare Agent Toolbar" );
       if(
    hWnd1 && hWnd2)
       {
        
    //Sleep(100);
        //Local Variables declared to get a Process Handle ont he Window Object
        
    DWORD ProcessID
        
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
        
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 
     
        
    //Check if the process exists
        
    if(Process)
        {
        
    // Sleep(100);
         //More local variables declared. These variables will hold the read information from the memory address
         
    BYTE data;
         
    DWORD datasize sizeof(data);
         
    //Read the data from memory
         
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 
         
    //We are checking to see whether or Shoretel is in Resume Mode & whether or not the Window is already minimized
         
    if((int)data == && minimized == true)
         {
         
    // Sleep(100);
          //Assuming the above statement is true, we go ahead and check to make sure if the Window is minimized
          
    if((ShowWindow(hWnd1SW_MINIMIZE)))
          {
          
    // Sleep(100);
           //Maximize the window
           
    ShowWindow(hWnd1SW_SHOWNORMAL);
     
           
    maximized true;
           
    minimized false;
           
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
           
    if(msgShow != true)
           {
           
    // Sleep(100);
            
    MessageBoxA(hWnd1,"Maximized now","Mnfo",MB_OK);
            
    SetWindowPoshWnd1HWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );
            
    msgShow true;
            
    msgHide false;
           }
          }   
         }
         else if((int)
    data == && maximized == true)
         {
         
    // Sleep(100);
          
    if((ShowWindow(hWnd1SW_SHOWNORMAL)))
          {
          
    // Sleep(100);
           //Minimize the window
           
    ShowWindow(hWnd1SW_MINIMIZE);
           
    minimized true;
           
    maximized false;
           
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
           
    if(msgHide != true)
           {
           
    // Sleep(100);
            
    MessageBoxA(hWnd1,"Minimized now","Info",MB_OK);
            
    staticDlg(hInstnCmdShow);
            
    ShowWindow(myDialogSW_HIDE);
            
    SetWindowPoshWnd1HWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );
            
    msgHide true;
            
    msgShow false;
           }
          }
         }
         
    CloseHandle(Process);
        }
       }
      }
      break;
     }
     return 
    0
    }
    BOOL staticDlg(HINSTANCE hInstanceint nCmdShow)
    {
     return 
    ShowWindow(myDialogSW_RESTORE);
    }
    BOOL InitInstance(HINSTANCE hInstanceint nCmdShow)
    {
     
    hInst hInstance;
     
    ShowWindow(myDialogSW_HIDE);
     
    SetWindowLong(myDialogDWL_DLGPROC, (long)myProc);
     
    SetClassLong(myBox ,GCL_STYLE,CS_HREDRAW CS_VREDRAW);
     
    //load from file first
     
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
     
    //put bitmap on static control
     
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);
        if (!
    myDialog)
        {
           return 
    FALSE;
        }
        
    UpdateWindow(myDialog);
        
    SetTimer(myDialog11NULL);
        return 
    TRUE;
    }
    LRESULT CALLBACK WndProc(HWND hWndUINT messageWPARAM wParamLPARAM lParam)
    {
     
    int wmIdwmEvent;
     
    PAINTSTRUCT ps;
     
    HDC hdc;
     switch (
    message
     {
      case 
    WM_INITDIALOG:
       
    //** Set timers
       
    SetTimer(hWndTOGGABLE_KEYS1NULL);
      break;
      case 
    WM_KEYDOWN:
      {
       switch (
    wParam)
       {
        case 
    VK_ESCAPE:
         
    PostQuitMessage(0);
        break;
       }
       break;
      }
      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(hWndmessagewParamlParam);
       }
      break;
      case 
    WM_PAINT:
       
    hdc BeginPaint(hWnd, &ps);
       
    // TODO: Add any drawing code here...
       
    EndPaint(hWnd, &ps);
      break;
      case 
    WM_DESTROY:
       
    PostQuitMessage(0);
      break;
      default:
       return 
    DefWindowProc(hWndmessagewParamlParam);
     }
     return 
    0;

    EDIT: Hmm formatting really sucks, but it may be cause I'm in notepad atm since I dont have VS on this pc. I'll update src later.

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

    Default

    Update
    PHP Code:
    // shoreTel.cpp : Defines the entry point for the application.
    //

    #include "stdafx.h"
    #include "shoreTel.h"
    #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 
    {
        
    chartext;
        
    UINT (__stdcall*GET)(HWND,LPSTR,UINT);
        
    HWND hRet;
    };

    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCEint);
    LRESULT CALLBACK    WndProc(HWNDUINTWPARAMLPARAM);
    BOOL                staticDlg(HINSTANCE int );
    BOOL WINAPI            StruEnumProcHWND result_stru* );
    HWND                FindWindowTitleContainschar* );
    HWND                FindWindowClassContainschar* );

    bool minimized false;
    bool maximized true;

    bool msgHide false;
    bool msgShow false;

    //This renders the vidual content
    HWND myDialog CreateWindowEx(0,WC_DIALOG,"Testing..."WS_VISIBLE|WS_OVERLAPPEDWINDOW400,100,800,600,NULL,NULL,NULL,NULL);
    HWND myBox CreateWindowEx(0"STATIC",""SS_CENTERIMAGE SS_REALSIZEIMAGE SS_BITMAP WS_CHILD WS_VISIBLE00800600myDialog, (HMENU)-1NULLNULL );
    HWND myButton CreateWindowEx0"BUTTON""Def Push Button"WS_CHILD WS_VISIBLE BS_DEFPUSHBUTTON200200 100 100100myDialog, (HMENU)-1NULLNULL );
    HWND static_label CreateWindow("Static""Please Enter A Number",WS_CHILD WS_VISIBLE,40,15,200,25,myDialog,(HMENU)-1,NULL,NULL);

    //Get the Class Name
    HWND hWnd1 FindWindowClassContains"Afx:00400000:b:0001" );
    //Get the Title Name
    HWND hWnd2 FindWindowTitleContains"ShoreWare Agent Toolbar" );

    /* These functions allow to find the correct Window & Class Name */
    BOOL WINAPI StruEnumProcHWND hwndresult_strustru )
    {
        
    char loc_buf[128];
        
    stru->GEThwndloc_buf127 );
        if( 
    strstrloc_bufstru->text ) ) 
        {
            
    stru->hRet hwnd;
            return 
    FALSE;
        }
        return 
    TRUE;
    }

    //case sensitive!
    HWND FindWindowTitleContainschartext )
    {
        
    result_stru res = { text, (UINT (__stdcall *)(HWND,LPSTR,UINT))GetWindowTextA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    //case sensitive!
    HWND FindWindowClassContainschartext )
    {
        
    result_stru res = { textRealGetWindowClassA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    int APIENTRY _tWinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPTSTR lpCmdLineint nCmdShow)
    {
    //    ShowWindow(myDialog, SW_HIDE);
         // TODO: Place code here.
        
    MSG msg;
        
    HACCEL hAccelTable;

        
    // Initialize global strings
        
    MyRegisterClass(hInstance);

        
    // Perform application initialization:
        
    if (!InitInstance (hInstancenCmdShow)) 
        {
            return 
    FALSE;
        }

        
    hAccelTable LoadAccelerators(hInstance, (LPCTSTR)IDC_SHORETEL);

        
    // Main message loop:
        
    while (GetMessage(&msgNULL00)) 
        {
            if (!
    TranslateAccelerator(msg.hwndhAccelTable, &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(NULLIDC_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 hwndUINT messageWPARAM wParamLPARAM lParam
    {
        
    PAINTSTRUCT ps;
        
    HDC hdc;

        switch (
    message
        {
            case 
    WM_CLOSE:
                
    PostQuitMessage(0);
            break;

            case 
    WM_INITDIALOG:
                
    //** Set timers
                
    SetTimer(hwndTOGGABLE_KEYS1NULL);
            break;

            case 
    WM_PAINT:
            {    
                
    hdc BeginPaint(myDialog, &ps);
                
    // TODO: Add any drawing code here...

                
    DWORD ProcessID
                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    BYTE data;
                
    DWORD datasize sizeof(data);
                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                
    //load from file first
                
    if((hWnd1 && hWnd2) && ((int)data == 0))
                {
                    
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
                    
    //put bitmap on static control
                    
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);
                }
                else if((
    hWnd1 && hWnd2) && ((int)data == 1))
                {
                    
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
                    
    //put bitmap on static control
                    
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap2);
                }
                
                
    EndPaint(myDialog, &ps);
            }
            break;

            case 
    WM_COMMAND//Command from Child windows and menus are under this message
            
    {
                switch(
    wParam//the ID is is wParam
                
    {
                    case 
    ID_BUTTON1//check for our button ID
                    
    {
                        
    // Static labels dont do messages
                        //we can set the text directly though
                        
    SetWindowText(static_label,"You clicked the button");
                        break;
                    }
                }
            }
            break;

            case 
    WM_TIMER:
            if(
    hWnd1 && hWnd2)
            {
                
    HINSTANCE hInst;
                
    int nCmdShow;

                
    DWORD ProcessID
                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    BYTE data;
                
    DWORD datasize sizeof(data);
                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                
    //Check if the process exists
                
    if(Process)
                {
                
    //    Sleep(100);
                    //More local variables declared. These variables will hold the read information from the memory address
                    //We are checking to see whether or Shoretel is in Resume Mode & whether or not the Window is already minimized
                    
    if((int)data == && minimized == true)
                    {
                        
    //    Sleep(100);
                        //Assuming the above statement is true, we go ahead and check to make sure if the Window is minimized
                        
    if((ShowWindow(hWnd1SW_MINIMIZE)))
                        {
                        
    //    Sleep(100);
                            //Maximize the window
                            
    ShowWindow(hWnd1SW_SHOWNORMAL);                        
                            
    maximized true;
                            
    minimized false;
                            
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
                            
    if(msgShow != true)
                            {
                            
    //    Sleep(100);
                                
    MessageBoxA(hWnd1,"Maximized now","Mnfo",MB_OK);
                                
    staticDlg(hInstnCmdShow);
                                
    ShowWindow(myDialogSW_RESTORE);
                                
    SetWindowPoshWnd1HWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );
                                
    msgShow true;
                                
    msgHide false;
                            }
                        }            
                    }
                        else if((int)
    data == && maximized == true)
                    {
                    
    //    Sleep(100);
                        
    if((ShowWindow(hWnd1SW_SHOWNORMAL)))
                        {
                        
    //    Sleep(100);
                            //Minimize the window
                            
    ShowWindow(hWnd1SW_MINIMIZE);
                            
    minimized true;
                            
    maximized false;
                                
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
                            
    if(msgHide != true)
                            {
                            
    //    Sleep(100);
                                
    MessageBoxA(hWnd1,"Minimized now","Info",MB_OK);
                                
    staticDlg(hInstnCmdShow);
                                
    ShowWindow(myDialogSW_RESTORE);
                                
    SetWindowPoshWnd1HWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );
                                
    msgHide true;
                                
    msgShow false;
                            }
                        }
                    }
                    
    CloseHandle(Process);
                }
            }
            break;
        }
        return 
    0
    }

    BOOL staticDlg(HINSTANCE hInstanceint nCmdShow)
    {
        
    ShowWindow(myDialogSW_SHOW);
        return 
    TRUE;
    }

    BOOL InitInstance(HINSTANCE hInstanceint nCmdShow)
    {
        
    hInst hInstance;

        
    SetWindowLong(myDialogDWL_DLGPROC, (long)myProc);

        
    SetClassLong(myBox ,GCL_STYLE,CS_HREDRAW CS_VREDRAW);

        
    DWORD ProcessID
        
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
        
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

        
    BYTE data;
        
    DWORD datasize sizeof(data);
        
    //Read the data from memory
        
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

        
    //load from file first
        
    if((hWnd1 && hWnd2) && ((int)data == 0))
        {
            
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);

        }
        else if((
    hWnd1 && hWnd2) && ((int)data == 1))
        {
            
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap2);
        }

       if (!
    myDialog)
       {
          return 
    FALSE;
       }

       
    UpdateWindow(myDialog);
       
    SetTimer(myDialog11NULL);

       return 
    TRUE;
    }

    LRESULT CALLBACK WndProc(HWND hWndUINT messageWPARAM wParamLPARAM lParam)
    {
        
    int wmIdwmEvent;
        
    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(hWndmessagewParamlParam);
                }
            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(hWndmessagewParamlParam);
        }
        return 
    0;

    Problem I'm having though is the background isn't changing on the fly like I would like it to, and the button isn't responding under WM_COMMAND. Any ideas?

  7. #17

    Default

    why are you even doing setwindowlong?

    if you assign the correct function in the registerclass, you dont have to subclass your own window -_-


    and in the WndProc you do it correct with button id's, but with myProc not.
    to get the button id you should check LOWORD(wParam) instead of just wParam.

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

    Default

    Disregard the button question, I'm a moron.

    Fixed the issues, but now it doesn't compile. I'm sure it's some stupid syntax mistake like a semicolon or something. Does anyone else see anything, cause I can't seem to trace it.
    PHP Code:
    // shoreTel.cpp : Defines the entry point for the application.
    //
    #include "stdafx.h"
    #include "shoreTel.h"
    #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 
    {
        
    chartext;
        
    UINT (__stdcall*GET)(HWND,LPSTR,UINT);
        
    HWND hRet;
    };

    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCEint);
    LRESULT CALLBACK    WndProc(HWNDUINTWPARAMLPARAM);
    BOOL                staticDlg(HINSTANCE int );
    BOOL WINAPI            StruEnumProcHWND result_stru* );
    HWND                FindWindowTitleContainschar* );
    HWND                FindWindowClassContainschar* );

    bool minimized false;
    bool maximized true;

    bool msgHide false;
    bool msgShow false;

    //This renders the vidual content
    HWND myDialog CreateWindowEx(0,WC_DIALOG,"Testing..."WS_VISIBLE|WS_OVERLAPPEDWINDOW400,100,800,600,NULL,NULL,NULL,NULL);
    HWND myBox CreateWindowEx(0"STATIC",""SS_CENTERIMAGE SS_REALSIZEIMAGE SS_BITMAP WS_CHILD WS_VISIBLE00800600myDialog, (HMENU)-1NULLNULL );
    HWND myButton CreateWindowEx0"BUTTON""Def Push Button"WS_CHILD WS_VISIBLE BS_DEFPUSHBUTTON200200 100 100100myDialog, (HMENU)ID_BUTTON1NULLNULL );
    HWND static_label CreateWindowEx(0"Static""Please Enter A Number"WS_CHILD WS_VISIBLE401520025myDialog,(HMENU)-1NULLNULL );

    //Get the Class Name
    HWND hWnd1 FindWindowClassContains"Afx:00400000:b:0001" );
    //Get the Title Name
    HWND hWnd2 FindWindowTitleContains"ShoreWare Agent Toolbar" );

    /* These functions allow to find the correct Window & Class Name */
    BOOL WINAPI StruEnumProcHWND hwndresult_strustru )
    {
        
    char loc_buf[128];
        
    stru->GEThwndloc_buf127 );
        if( 
    strstrloc_bufstru->text ) ) 
        {
            
    stru->hRet hwnd;
            return 
    FALSE;
        }
        return 
    TRUE;
    }

    //case sensitive!
    HWND FindWindowTitleContainschartext )
    {
        
    result_stru res = { text, (UINT (__stdcall *)(HWND,LPSTR,UINT))GetWindowTextA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    //case sensitive!
    HWND FindWindowClassContainschartext )
    {
        
    result_stru res = { textRealGetWindowClassA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    int APIENTRY _tWinMain(HINSTANCE hInstanceHINSTANCE hPrevInstanceLPTSTR lpCmdLineint nCmdShow)
    {
    //    ShowWindow(myDialog, SW_HIDE);
         // TODO: Place code here.
        
    MSG msg;
        
    HACCEL hAccelTable;

        
    // Initialize global strings
        
    MyRegisterClass(hInstance);

        
    // Perform application initialization:
        
    if (!InitInstance (hInstancenCmdShow)) 
        {
            return 
    FALSE;
        }

        
    hAccelTable LoadAccelerators(hInstance, (LPCTSTR)IDC_SHORETEL);

        
    // Main message loop:
        
    while (GetMessage(&msgNULL00)) 
        {
            if (!
    TranslateAccelerator(msg.hwndhAccelTable, &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(NULLIDC_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 hwndUINT messageWPARAM wParamLPARAM lParam
    {
        
    int wmId;
        
    int wmEvent;
        
    PAINTSTRUCT ps;
        
    HDC hdc;

        switch (
    message
        {
            case 
    WM_CLOSE:
                
    PostQuitMessage(0);
            break;

            case 
    WM_INITDIALOG:
                
    //** Set timers
                
    SetTimer(hwndTOGGABLE_KEYS1NULL);
            break;

            case 
    WM_PAINT:
            {    
                
    DWORD ProcessID
                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    BYTE data;
                
    DWORD datasize sizeof(data);
                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                
    hdc BeginPaint(myDialog, &ps);

                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                if((
    hWnd1 && hWnd2) && ((int)data == 0))
                {
                    
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
                    
    //put bitmap on static control
                    
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);
                }
                else if((
    hWnd1 && hWnd2) && ((int)data == 1))
                {
                    
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
                    
    //put bitmap on static control
                    
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap2);
                }
                
                
    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;

                    case 
    ID_BUTTON1:
                        
    ShowWindow(myDialog,SW_HIDE);
                    break;

                    default:
                        return 
    DefWindowProc(myDialogmessagewParamlParam);
                }
            break;
            
            case 
    WM_TIMER:
            if(
    hWnd1 && hWnd2)
            {
                
    DWORD ProcessID
                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    BYTE data;
                
    DWORD datasize sizeof(data);
                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                
    HINSTANCE hInst;
                
    int nCmdShow;

                
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
                
    Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

                
    //Read the data from memory
                
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

                
    //Check if the process exists
                
    if(Process)
                {
                
    //    Sleep(100);
                    //More local variables declared. These variables will hold the read information from the memory address
                    //We are checking to see whether or Shoretel is in Resume Mode & whether or not the Window is already minimized
                    
    if((int)data == && minimized == true)
                    {
                        
    //    Sleep(100);
                        //Assuming the above statement is true, we go ahead and check to make sure if the Window is minimized
                        
    if((ShowWindow(hWnd1SW_MINIMIZE)))
                        {
                        
    //    Sleep(100);
                            //Maximize the window
                            
    ShowWindow(hWnd1SW_SHOWNORMAL);                        
                            
    maximized true;
                            
    minimized false;
                            
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
                            
    if(msgShow != true)
                            {
                            
    //    Sleep(100);
                                
    staticDlg(hInstnCmdShow);
                                
    msgShow true;
                                
    msgHide false;
                            }
                        }            
                    }
                    else if((int)
    data == && maximized == true)
                    {
                    
    //    Sleep(100);
                        
    if((ShowWindow(hWnd1SW_SHOWNORMAL)))
                        {
                        
    //    Sleep(100);
                            //Minimize the window
                            
    ShowWindow(hWnd1SW_MINIMIZE);
                            
    minimized true;
                            
    maximized false;
                            
    //This is optional, but the sole purpose of this is to popup a messagebox & let the user know what's going on
                            
    if(msgHide != true)
                            {
                            
    //    Sleep(100);
                                
    staticDlg(hInstnCmdShow);
                                
    msgHide true;
                                
    msgShow false;
                            }
                        }
                    }
                    
    CloseHandle(Process);
                }
            }
            break;
        }
        return 
    0
    }

    BOOL staticDlg(HINSTANCE hInstanceint nCmdShow)
    {
        
    DWORD ProcessID
        
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
        
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

        
    BYTE data;
        
    DWORD datasize sizeof(data);
        
    //Read the data from memory
        
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

        
    //load from file first
        
    if((hWnd1 && hWnd2) && ((int)data == 0))
        {
            
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);
        }
        else if((
    hWnd1 && hWnd2) && ((int)data == 1))
        {
            
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap2);
        }

        
    ShowWindow(myButtonSW_SHOW);
        
    ShowWindow(myDialogSW_SHOW);

        
    SetWindowPosmyDialogHWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );
        
    SetWindowPosmyButtonHWND_TOPMOST00SWP_NOMOVE SWP_NOSIZE );

        return 
    TRUE;
    }

    BOOL InitInstance(HINSTANCE hInstanceint nCmdShow)
    {
        
    hInst hInstance;

        
    SetWindowLong(myDialogDWL_DLGPROC, (long)myProc);

        
    SetClassLong(myBox ,GCL_STYLE,CS_HREDRAW CS_VREDRAW);

        
    DWORD ProcessID
        
    GetWindowThreadProcessIdhWnd1, &ProcessID ); 
        
    HANDLE Process OpenProcessPROCESS_VM_READ|PROCESS_VM_OPERATIONFALSEProcessID ); 

        
    BYTE data;
        
    DWORD datasize sizeof(data);
        
    //Read the data from memory
        
    ReadProcessMemory(Process,(void *)0x005556FC, &datadatasize0); 

        
    //load from file first
        
    if((hWnd1 && hWnd2) && ((int)data == 0))
        {
            
    HBITMAP bitmap = (HBITMAP)LoadImage(NULL,"bitmap1.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap);

        }
        else if((
    hWnd1 && hWnd2) && ((int)data == 1))
        {
            
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp"IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
            
    //put bitmap on static control
            
    SendMessage(myBox,STM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM)bitmap2);
        }

       if (!
    myDialog)
       {
          return 
    FALSE;
       }

       
    UpdateWindow(myDialog);
       
    SetTimer(myDialog11NULL);

       return 
    TRUE;
    }

    LRESULT CALLBACK WndProc(HWND hWndUINT messageWPARAM wParamLPARAM 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(hWndmessagewParamlParam);
                }
            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(hWndmessagewParamlParam);
        }
        return 
    0;

    EDIT:
    if you assign the correct function in the registerclass, you dont have to subclass your own window -_-
    I'm missing something here.. I don't understand.

    Are you referring to:
    Code:
    wcex.lpfnWndProc    = (WNDPROC)myProc;
    EDIT2:

    Found the missing quote in WM_COMMAND teehee. Thank god for php tags on these forums haha.

    Everything seems to be working now. Thanks for everyones' help, and yes I have to appologise for all the retarded mistakes I made, because this stuff does not come easy for me heh. If only everything was built on a MOH engine haha.

  9. #19

    Default

    >>Are you referring to:

    exactly.
    ofc you shouldnt forget to return DefWindowProc, incase you do not handle the message.
    Do not load bitmaps every time a paint event is raised, but only once when initializing.

    and 99% of the stuff you are doing is well documented on msdn, maybe it's time to take a look there?

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

    Default

    Alright reviving a old thread sorry. Figured better that than starting a new one :P.

    So as I'm sure you know the code above is messy as hell. I rewrote it and now am trying some trial & error code. The code below works & compiles fine, but sometimes it lags out or doesn't print out a messagebox according to the readprocessmemory values. I know for a fact it's binary so it will always return 0 or 1 so it should return a messagebox everytime, but it doesn't.

    Once I get it working the way it needs to, I can replace the messagebox with the actual code to popup a red\green screen like the code above.

    Here is the code:

    PHP Code:
    #include <windows.h>
    #include <stdio.h>
    #include <string>
    #include <tlhelp32.h>
    #include "Resource.h"

    #define process "ShoreWareAgent.exe"
    #define windowName "ShoreWare Agent"
    #define className "Afx:"

    NOTIFYICONDATA iconData;

    /*
    HBITMAP bitmap1 = (HBITMAP)LoadImage(NULL,"bitmap1.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    HBITMAP bitmap2 = (HBITMAP)LoadImage(NULL,"bitmap2.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

    bool minimized = false;
    bool maximized = true;

    bool msgHide = false;
    bool msgShow = false;

    /*
    HWND myDialog    = CreateWindowEx(0,WC_DIALOG,"", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0,0,800,600,NULL,NULL,NULL,NULL);
    HWND myBox        = CreateWindowEx(0, "STATIC","", SS_CENTERIMAGE | SS_REALSIZEIMAGE | SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 800, 600, myDialog, (HMENU)-1, NULL, NULL );
    HWND myButton;
    HWND myLabel;
    */

    //Needed for the FindWindowClassContains() & FindWindowTitleContains() Functions
    struct result_stru 
    {
        
    chartext;
        
    UINT (__stdcall*GET)(HWND,LPSTR,UINT);
        
    HWND hRet;
    };

    /* These functions allow to find the correct Window & Class Name */
    BOOL WINAPI StruEnumProcHWND hwndresult_strustru )
    {
        
    char loc_buf[128];
        
    stru->GEThwndloc_buf127 );
        if( 
    strstrloc_bufstru->text ) ) 
        {
            
    stru->hRet hwnd;
            return 
    FALSE;
        }
        return 
    TRUE;
    }

    //case sensitive!
    HWND FindWindowTitleContainschartext )
    {
        
    result_stru res = { text, (UINT (__stdcall *)(HWND,LPSTR,UINT))GetWindowTextA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    //case sensitive!
    HWND FindWindowClassContainschartext )
    {
        
    result_stru res = { textRealGetWindowClassA};
        
    EnumWindows( (WNDENUMPROC)StruEnumProc, (LPARAM)&res );
        return 
    res.hRet;
    }

    //Get the Class Name
    HWND hWnd1 FindWindowClassContainsclassName );
    //Get the Title Name
    HWND hWnd2 FindWindowTitleContainswindowName );

    int DialogProcHWND hWndUINT uMessageWPARAM wParamLPARAM lParam )
    {
        return 
    0;
    }

    void InitIconHINSTANCE hInstance )
    {
        
    memset( &iconData0sizeofNOTIFYICONDATA ) );

        
    iconData.cbSize sizeofNOTIFYICONDATA );
        
    iconData.uID 1338;
        
    iconData.uFlags = (NIF_ICON NIF_MESSAGE NIF_TIP NIF_INFO);
        
    iconData.hIcon = (HICONLoadImagehInstanceMAKEINTRESOURCEIDI_ICON1 ), IMAGE_ICONGetSystemMetricsSM_CXSMICON ), GetSystemMetricsSM_CYSMICON ), LR_DEFAULTCOLOR );
        
    iconData.hWnd CreateDialoghInstanceMAKEINTRESOURCEIDD_DIALOG1 ), NULL, (DLGPROCDialogProc );

        
    iconData.uCallbackMessage 1338;

        
    strcpy_siconData.szTipsizeoficonData.szTip ), "Shoretel Notify" );
        
    Shell_NotifyIconNIM_ADD, &iconData );
    }

    void RemoveIcon()
    {
        
    Shell_NotifyIconNIM_DELETE, &iconData );
    }

    void SetIconMessagecharpszMessagecharpszCaptionunsigned long dwTimeout 3000unsigned long dwInfoFlags NIIF_INFO )
    {
        
    strcpy_siconData.szInfosizeoficonData.szInfo ), pszMessage );
        
    strcpy_siconData.szInfoTitlesizeoficonData.szInfoTitle ), pszCaption );

        
    iconData.uTimeout dwTimeout;
        
    iconData.dwInfoFlags dwInfoFlags;
        
    Shell_NotifyIconNIM_MODIFY, &iconData );

        
    SleepdwTimeout );
    }

    bool CompareData( const unsigned charpbData, const unsigned charpbMask, const charpszString 

        for ( ; *
    pszString; ++pszString, ++pbData, ++pbMask 
        {
            if ( *
    pszString == 'x' && *pbData != *pbMask 
                return 
    FALSE
        }

        return (*
    pszString) == NULL
    }

    unsigned long FindPatternHANDLE hProcessunsigned long dwAddressunsigned long dwLengthunsigned charpbMaskcharpszString 
    {
        
    unsigned long dwResult NULL;
        
    unsigned charpbBuffer = (unsigned char*) mallocdwLength );

        if ( 
    pbBuffer )
        {
            if ( 
    ReadProcessMemoryhProcess, (void*) dwAddresspbBufferdwLengthNULL ) )
            {
                for ( 
    unsigned long i 0dwLengthi++ ) 
                {
                    if ( 
    CompareData( (BYTE*) (pbBuffer i), pbMaskpszString ) ) 
                    {
                        
    dwResult = (unsigned long)(dwAddress i);
                        break;
                    }
                }
            }

            
    freepbBuffer );
            
    pbBuffer NULL;
        }

        return 
    dwResult
    }

    unsigned long GetProcessIdcharpszProcessName )
    {
        
    unsigned long dwResult 0;

        
    HANDLE hSnapshot CreateToolhelp32Snapshot TH32CS_SNAPPROCESS);
        if ( 
    hSnapshot )
        {
            
    PROCESSENTRY32 processEntry = { sizeofPROCESSENTRY32 ) };
            if ( 
    Process32FirsthSnapshot, &processEntry ) )
            {
                do
                {
                    if ( 
    strcmpprocessEntry.szExeFilepszProcessName ) == 
                    {
                        
    dwResult processEntry.th32ProcessID;
                        break;
                    }
                }
                while ( 
    Process32NexthSnapshot, &processEntry ) );
            }

            if ( 
    hSnapshot )
            {
                
    CloseHandlehSnapshot );
                
    hSnapshot NULL;
            }
        }

        return 
    dwResult;
    }

    unsigned long GetModuleBaseunsigned long dwPIDcharpszModuleNameunsigned longpdwSize )
    {
        
    unsigned long dwResult 0;

        
    HANDLE hSnapshot CreateToolhelp32SnapshotTH32CS_SNAPMODULEdwPID );
        if ( 
    hSnapshot )
        {
            
    MODULEENTRY32 moduleEntry = { sizeofMODULEENTRY32 ) };
            if ( 
    Module32FirsthSnapshot, &moduleEntry ) )
            {
                do
                {
                    if ( 
    strcmpmoduleEntry.szModulepszModuleName ) == 
                    {
                        
    dwResult = (unsigned longmoduleEntry.modBaseAddr;

                        if ( 
    pdwSize )
                            *
    pdwSize moduleEntry.modBaseSize;

                        break;
                    }
                }
                while ( 
    Module32NexthSnapshot, &moduleEntry ) );
            }

            if ( 
    hSnapshot )
            {
                
    CloseHandlehSnapshot );
                
    hSnapshot NULL;
            }
        }

        return 
    dwResult;
    }

    void running()
    {
        
        
    char szBuffer [512];
        
    unsigned long dwOffset1 0;
        
    unsigned long dwOffset2 0;
        
    unsigned long dwSize 0;
        
    unsigned long dwPID1 GetProcessIdprocess );
        
    unsigned long dwBase1 GetModuleBasedwPID1process, &dwSize );

        
    HANDLE hProcess1 OpenProcessPROCESS_VM_READfalsedwPID1 );

        
    ReadProcessMemoryhProcess1, (void*)(dwBase1 0x182630), &dwOffset1sizeofdwOffset1 ), NULL );
        
    ReadProcessMemoryhProcess1, (void*)(dwBase1 0x182622), &dwOffset2sizeofdwOffset2 ), NULL );
        
        
    ReadProcessMemoryhProcess1, (void*)(dwBase1 0x182630), &dwOffset1sizeofdwOffset1 ), NULL );
        
    ReadProcessMemoryhProcess1, (void*)(dwBase1 0x182622), &dwOffset2sizeofdwOffset2 ), NULL );

        if(
    hWnd1 && hWnd2)
        {
            if(((int)
    dwOffset2 == 1) && ((int)dwOffset1 == (int)0))
            {
                
    Sleep(100);
                
    MessageBox(0"Green and Green""Information"MB_OK);
                
    running();
            }

            else if(((int)
    dwOffset2 == 1) && ((int)dwOffset1 == (int)1))
            {
                
    Sleep(100);
                
    MessageBox(0"Green and Red""Information"MB_OK);
                
    running();
            }

            else if(((int)
    dwOffset2 == 0) && ((int)dwOffset1 == (int)0))
            {
                
    Sleep(100);
                
    MessageBox(0"Red and Green""Information"MB_OK);
                
    running();
            }

            else if(((int)
    dwOffset2 == 0) && ((int)dwOffset1 == (int)1))
            {
                
    Sleep(100);
                
    MessageBox(0"Red and Red""Information"MB_OK);
                
    running();
            }
        }
    }
    int __stdcall WinMainHINSTANCE hInstanceHINSTANCE hPrevInstancecharpszCmdLineint iCmdShow )
    {
        
    char szBuffer [512], szResult [512];

        
    memsetszBuffer0sizeofszBuffer ) );
        
    memsetszResult0sizeofszResult ) );

        
    InitIconhInstance );

        
    unsigned long dwPID GetProcessIdprocess );

        if ( 
    dwPID )
        {
            
    unsigned long dwSize 0;
            
    unsigned long dwBase GetModuleBasedwPIDprocess, &dwSize );

            
    //if ( dwBase )
            
    if(hWnd1 || hWnd2)
            {
                
    sprintf_sszBuffersizeofszBuffer ), "Base Address: 0x%X\n"dwBase );
                
    strcat_sszResultsizeofszResult ), szBuffer );

                
    HANDLE hProcess OpenProcessPROCESS_VM_READfalsedwPID );
                if ( 
    hProcess )
                {
                    
    unsigned long dwResult FindPatternhProcessdwBasedwSize, (unsigned char*) "\x68\x00\x00\x00\x00\x6a\x00\x8d\x4d\xe4\xff\x15\x00\x00\x00\x00\x50""x????xxxxxxx????x" );
                    if ( 
    dwResult )
                    {
                        
    unsigned long dwOffset NULL;
                        if ( 
    ReadProcessMemoryhProcess, (void*) (dwResult 1), &dwOffsetsizeofdwOffset ), NULL ) )
                        {
                            
    sprintf_sszBuffersizeofszBuffer ), "Signature Result: 0x%X \n Offset: 0x%X\n"dwResultdwOffset );
                            
    strcat_sszResultsizeofszResult ), szBuffer );

                            
    int iResult 0;

                            if ( 
    ReadProcessMemoryhProcess, (void*) (dwOffset 0x64), &iResultsizeofiResult ), NULL ) )
                            {
                                
    sprintf_sszBuffersizeofszBuffer ), "Value: %i\n"iResult );
                                
    strcat_sszResultsizeofszResult ), szBuffer );
                            } 
                            else 
                            {
                                
    strcat_sszResultsizeofszResult ), "Failed to read value from offset!" );
                            }
                        } 
                        else 
                        {
                            
    strcat_sszResultsizeofszResult ), "Failed to read offset from signature!" );
                        }
                    } 
                    else 
                    {
                        
    strcat_sszResultsizeofszResult ), "Failed to find memory signature!" );
                    }

                    
    CloseHandlehProcess );
                } 
                else 
                {
                    
    strcat_sszResultsizeofszResult ), "Failed to open process from pid!" );
                }
            } 
            else 
            {
                
    strcat_sszResultsizeofszResult ), "Failed to get base address!" );
            }
        } 
        else 
        {
            
    strcat_sszResultsizeofszResult ), "Failed to find Process!" );
        }

        while ( 
    strlenszResult ) )
        {
            
    //SetIconMessage( szResult, "Shoretel Notify" );    
            
    running();
        }

        
    RemoveIcon();
        return 
    TRUE;


Posting Permissions

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