Changeset 337 for trunk


Ignore:
Timestamp:
Oct 31, 2006, 3:11:11 AM (19 years ago)
Author:
pr
Message:

Add winhStoreWindowPos. Bug 458.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/winh.h

    r276 r337  
    1515 */
    1616
    17 /*      Copyright (C) 1997-2000 Ulrich M”ller.
     17/*      Copyright (C) 1997-2006 Ulrich M”ller.
    1818 *      This file is part of the "XWorkplace helpers" source package.
    1919 *      This is free software; you can redistribute it and/or modify
     
    763763    BOOL XWPENTRY winhRestoreWindowPos(HWND hwnd, HINI hIni, const char *pcszApp, const char *pcszKey, ULONG fl);
    764764
     765    // V1.0.6 (2006-10-28) [pr]
     766
     767    /*
     768     *@@ STOREPOS:
     769     *
     770     */
     771
     772    #pragma pack(2)
     773    typedef struct _STOREPOS
     774    {
     775        USHORT      usMagic;          // Always 0x7B6A (???)
     776        ULONG       ulFlags;
     777        USHORT      usXPos;
     778        USHORT      usYPos;
     779        USHORT      usWidth;
     780        USHORT      usHeight;
     781        ULONG       ulRes1;           // Always 1 (???)
     782        USHORT      usRestoreXPos;
     783        USHORT      usRestoreYPos;
     784        USHORT      usRestoreWidth;
     785        USHORT      usRestoreHeight;
     786        ULONG       ulRes2;           // Always 1 (???)
     787        USHORT      usMinXPos;
     788        USHORT      usMinYPos;
     789        ULONG       ulRes3;           // Always 0x0400 (???)
     790        ULONG       ulRes4;           // Always 0x0300 (???)
     791        ULONG       ulRes5;           // Always 0xFFFFFFFF (???)
     792        ULONG       ulRes6;           // Always 0xFFFFFFFF (???)
     793        ULONG       ulPPLen;          // Presentation Parameters length
     794    } STOREPOS, *PSTOREPOS;
     795    #pragma pack()
     796
     797    #pragma import(WinGetFrameTreePPSize, , "PMWIN", 972)
     798    #pragma import(WinGetFrameTreePPs, , "PMWIN", 973)
     799
     800    ULONG APIENTRY WinGetFrameTreePPSize(HWND hwnd);
     801    ULONG APIENTRY WinGetFrameTreePPs(HWND hwnd, ULONG cchMax, PCH pch);
     802
     803    BOOL XWPENTRY winhStoreWindowPos(HWND hwnd, HINI hIni, const char *pcszApp, const char *pcszKey);
     804
    765805    #define XAC_MOVEX       0x0001
    766806    #define XAC_MOVEY       0x0002
  • trunk/src/helpers/winh.c

    r336 r337  
    26482648
    26492649/*
     2650 *@@ winhStoreWindowPos:
     2651 *      saves the position of a certain window in the same format
     2652 *      as the barely documented WinStoreWindowPos API.
     2653 *      This uses the completely undocumented calls
     2654 *      WinGetFrameTreePPSize and WinGetFrameTreePPs imported
     2655 *      from PMWIN.DLL ordinals 972 and 973.
     2656 *
     2657 *      The window should still be visible on the screen
     2658 *      when calling this function. Do not call it in WM_DESTROY,
     2659 *      because then the SWP data is no longer valid.
     2660 *
     2661 *      This returns TRUE if saving was successful.
     2662 *
     2663 *@@added XWP V1.0.6 (2006-10-31) [pr]: @@fixes 458
     2664 */
     2665
     2666BOOL winhStoreWindowPos(HWND hwnd,   // in: window to save
     2667                        HINI hIni,   // in: INI file (or HINI_USER/SYSTEM)
     2668                        const char *pcszApp,  // in: INI application name
     2669                        const char *pcszKey)  // in: INI key name
     2670{
     2671    BOOL brc = FALSE;
     2672    SWP swp;
     2673
     2674    if (WinQueryWindowPos(hwnd, &swp))
     2675    {
     2676        ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
     2677        ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
     2678        PSTOREPOS pStorePos;
     2679
     2680        if ((pStorePos = malloc(ulSize)))
     2681        {
     2682            // This first bit is all guesswork as I don't know what it all means,
     2683            // but it always seems to be the same everywhere I've looked.
     2684            pStorePos->usMagic = 0x7B6A;
     2685            pStorePos->ulRes1 = 1;
     2686            pStorePos->ulRes2 = 1;
     2687            pStorePos->ulRes3 = 0x0400;
     2688            pStorePos->ulRes4 = 0x0300;
     2689            pStorePos->ulRes5 = 0xFFFFFFFF;
     2690            pStorePos->ulRes6 = 0xFFFFFFFF;
     2691
     2692            pStorePos->ulFlags = swp.fl;
     2693            pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
     2694            pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
     2695            pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
     2696            pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
     2697            if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
     2698            {
     2699                pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
     2700                pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
     2701                pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
     2702                pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
     2703            }
     2704
     2705            pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
     2706            pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
     2707            pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, pStorePos + 1);
     2708            ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
     2709            brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
     2710            free(pStorePos);
     2711        }
     2712    }
     2713    return brc;
     2714}
     2715
     2716/*
    26502717 *@@ winhAdjustControls:
    26512718 *      helper function for dynamically adjusting a window's
Note: See TracChangeset for help on using the changeset viewer.