Announcement

Collapse
No announcement yet.

Brauche dringend Hilfe WndProc registrieren für Office

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Brauche dringend Hilfe WndProc registrieren für Office

    Hallo,

    Ich möchte eine Windows Procedure (WndProc) für eine externe Windows Klasse registrieren, für eine Office Applikation. Ich hole mir das Handle auf das Windows von Office und registriere über WNDCLASSEX ein WndProc dafür. Das Problem ist nur ich bekomme im Message Loop keine Message für das Windows. So das ich auch nicht in meine WndProc komme.

    Was mache ich falsch, brauche schnell Hilfe bin langsam am Verzweifeln!!

    Thomas

    LPCWSTR gc_szAppName;

    /////////////////////////////////////////////////////////
    //
    // RegisterWindowClass
    //
    // The RegisterWindowClass function registers a window class for
    // subsequent use in calls to the CreateWindow or CreateWindowEx function.
    //
    // Parameters:
    // HINSTANCE hInstance : [in] Handle to the instance that
    // contains the window procedure for the class.
    //
    // Return Values:
    // TRUE : Success
    // FALSE : Failure to register the class
    //
    /////////////////////////////////////////////////////////
    BOOL RegisterWindowClass(HINSTANCE hInstance)
    {
    WNDCLASSEX WndClassEx;

    WndClassEx.cbSize = sizeof(WndClassEx);
    WndClassEx.style = CS_HREDRAW | CS_VREDRAW;
    WndClassEx.lpfnWndProc = WndProc;
    WndClassEx.cbClsExtra = 0;
    WndClassEx.cbWndExtra = 0;
    WndClassEx.hInstance = hInstance;
    WndClassEx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
    WndClassEx.hIconSm = WndClassEx.hIcon;
    WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClassEx.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
    WndClassEx.lpszClassName = gc_szAppName;

    if (!RegisterClassEx(&WndClassEx))
    {
    MessageBox(NULL, TEXT("Failed to register window class!"),
    gc_szAppName, MB_ICONERROR);
    return false;
    }

    return true;
    }

    /////////////////////////////////////////////////////////
    //
    // WinMain
    //
    // The WinMain function is called by the system as the
    // initial entry point for a Win32-based application.
    // It contains typical boilerplate code to create and
    // show the main window, and pump messages.
    //
    // Parameters:
    // HINSTANCE hInstance, : [in] handle to current instance
    // HINSTANCE hPrevInstance, : [in] handle to previous instance
    // LPSTR lpCmdLine, : [in] command line
    // int nCmdShow : [in] show state
    //
    // Return Values:
    // 0 : The function terminated before entering the message loop.
    // non zero: Value of the wParam when receiving the WM_QUIT message
    //
    /////////////////////////////////////////////////////////
    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {

    string commandLineInput = "";
    int i;
    for(i= 0; i<=sizeof (lpCmdLine); *lpCmdLine++)
    {
    if(*lpCmdLine == 0)
    {
    break;
    }
    //strcat(commandLineInput, lpCmdLine);
    commandLineInput += *lpCmdLine;
    }
    int lenght = commandLineInput.length();
    int index = commandLineInput.find(' ');
    string applicationName = commandLineInput.substr(0, index);
    string path = commandLineInput.substr(index +1,lenght);

    //Get the Window Class Name

    if(applicationName == "outlook"){
    windowClass = (LPCTSTR)L"rctrl_renwnd32";
    gc_szAppName = L"rctrl_renwnd32";
    }else
    if(applicationName == "word"){
    windowClass = (LPCTSTR)L"OpusApp";
    gc_szAppName = L"OpusApp";
    }else
    if(applicationName == "excel"){
    windowClass = (LPCTSTR)L"XLMAIN";
    gc_szAppName = L"XLMAIN";
    }else
    if(applicationName == "powerPoint"){
    windowClass = (LPCTSTR)L"PP9FRMECLASS";
    gc_szAppName = L"PP9FRMECLASS";
    }

    if (!RegisterWindowClass(hInstance))
    return 0;

    CoInitialize(NULL);

    //LPCTSTR windowName = commandLineInput.GetBuffer();



    //HWND hWnd = FindWindow (NULL, windowName);
    HWND hWnd = FindWindow (windowClass, NULL);

    if (NULL == hWnd)
    {
    MessageBox(NULL, TEXT("Error creating the window"), TEXT("Error"),
    MB_OK | MB_ICONINFORMATION);
    return 0;
    }

    // Show the main window
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    // Start the boilerplate message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    CleanUp();
    CoUninitialize();

    return msg.wParam;
    }

  • #2
    Hallo,

    wenn ich dich richtig verstehe, willst du die WNDPROC einer Office-Applikation "anzapfen"?

    Wenn dem so ist, versuchs mal mit

    GetWindowLongPtr() (HWND von FindWindow(), GWLP_WNDPROC
    als Index);

    Die Funktion gibt dir die Addresse der WNDPROC von Office zurück, die du in einer Member-Variablen abspeichern solltest!

    Dann:

    SetWindowLongPtr()

    Hier übergibst du die Addresse deiner eigenen WNDPROC in der du, wenn deine eigene Verabeitung abgeschlossen ist, UNBEDINGT die Orginal-WNDPROC mit dem Function-Pointer von GetWindowLongPtr() aufrufen musst!

    Wenn deine Applikation terminiert, solltest du den Originalzustand mit SetWindowLongPtr() wiederherstellen.

    So müsste es eigentlich hinhauen.

    Gruss

    Reine

    Comment

    Working...
    X