Problem mit MSDN Beispiel: Positioning Objects on a Multiple Display Setup



  • Hallo ich habe folgenden Code,
    in meine Testapplication eingebaut.
    Bin leider noch kein Vollprofi, vielleicht könnt ihr mir helfen. 😞

    #include <windows.h>
    #include "multimon.h"    
    
    #define MONITOR_CENTER     0x0001        // center rect to monitor
    #define MONITOR_CLIP     0x0000        // clip rect to monitor
    #define MONITOR_WORKAREA 0x0002        // use monitor work area
    #define MONITOR_AREA     0x0000        // use monitor entire area
    
    //
    //  ClipOrCenterRectToMonitor
    //
    //  The most common problem apps have when running on a
    //  multimonitor system is that they "clip" or "pin" windows
    //  based on the SM_CXSCREEN and SM_CYSCREEN system metrics.
    //  Because of app compatibility reasons these system metrics
    //  return the size of the primary monitor.
    //
    //  This shows how you use the multi-monitor functions
    //  to do the same thing.
    //
    void ClipOrCenterRectToMonitor(LPRECT prc, UINT flags)
    {
        HMONITOR hMonitor;
        MONITORINFO mi;
        RECT        rc;
        int         w = prc->right  - prc->left;
        int         h = prc->bottom - prc->top;
    
        //
        // get the nearest monitor to the passed rect.
        //
        hMonitor = MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST);
    
        //
        // get the work area or entire monitor rect.
        //
        mi.cbSize = sizeof(mi);
        GetMonitorInfo(hMonitor, &mi);
    
        if (flags & MONITOR_WORKAREA)
            rc = mi.rcWork;
        else
            rc = mi.rcMonitor;
    
        //
        // center or clip the passed rect to the monitor rect
        //
        if (flags & MONITOR_CENTER)
        {
            prc->left   = rc.left + (rc.right  - rc.left - w) / 2;
            prc->top    = rc.top  + (rc.bottom - rc.top  - h) / 2;
            prc->right  = prc->left + w;
            prc->bottom = prc->top  + h;
        }
        else
        {
            prc->left   = max(rc.left, min(rc.right-w,  prc->left));
            prc->top    = max(rc.top,  min(rc.bottom-h, prc->top));
            prc->right  = prc->left + w;
            prc->bottom = prc->top  + h;
        }
    }
    
    void ClipOrCenterWindowToMonitor(HWND hwnd, UINT flags)
    {
        RECT rc;
        GetWindowRect(hwnd, &rc);
        ClipOrCenterRectToMonitor(&rc, flags);
        SetWindowPos(hwnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
    }
    

    und möchte ihn bei mir implementieren, leider bekomme ich immer diese Fehlermeldungen:

    diagtestDlg.obj : error LNK2001: unresolved external symbol _xGetMonitorInfo@8
    diagtestDlg.obj : error LNK2001: unresolved external symbol _xMonitorFromRect@8
    Debug/diagtest.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    


  • OK, ich war ein volldepp.
    Kann mir vielleicht jmd helfen wie ich einen HAndle auf den Monitor setze ?

    HMONITOR hMonitor, // handle to display monitor ?

    Danke schonmal Patrick



  • Schau mal in der Hilfe nach EnumDisplayMonitors(), dort gibt es ein Beispiel, wie man eine Aufzählung der vorhandenen Monitore bekommt.


Anmelden zum Antworten