Changeset 337


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

Add winhStoreWindowPos. Bug 458.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/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
     
    673673    BOOL XWPENTRY winhRestoreWindowPos(HWND hwnd, HINI hIni, const char *pcszApp, const char *pcszKey, ULONG fl);
    674674
     675    // V1.0.6 (2006-10-28) [pr]
     676
     677    /*
     678     *@@ STOREPOS:
     679     *
     680     */
     681
     682    #pragma pack(2)
     683    typedef struct _STOREPOS
     684    {
     685        USHORT      usMagic;          // Always 0x7B6A (???)
     686        ULONG       ulFlags;
     687        USHORT      usXPos;
     688        USHORT      usYPos;
     689        USHORT      usWidth;
     690        USHORT      usHeight;
     691        ULONG       ulRes1;           // Always 1 (???)
     692        USHORT      usRestoreXPos;
     693        USHORT      usRestoreYPos;
     694        USHORT      usRestoreWidth;
     695        USHORT      usRestoreHeight;
     696        ULONG       ulRes2;           // Always 1 (???)
     697        USHORT      usMinXPos;
     698        USHORT      usMinYPos;
     699        ULONG       ulRes3;           // Always 0x0400 (???)
     700        ULONG       ulRes4;           // Always 0x0300 (???)
     701        ULONG       ulRes5;           // Always 0xFFFFFFFF (???)
     702        ULONG       ulRes6;           // Always 0xFFFFFFFF (???)
     703        ULONG       ulPPLen;          // Presentation Parameters length
     704    } STOREPOS, *PSTOREPOS;
     705    #pragma pack()
     706
     707    #pragma import(WinGetFrameTreePPSize, , "PMWIN", 972)
     708    #pragma import(WinGetFrameTreePPs, , "PMWIN", 973)
     709
     710    ULONG APIENTRY WinGetFrameTreePPSize(HWND hwnd);
     711    ULONG APIENTRY WinGetFrameTreePPs(HWND hwnd, ULONG cchMax, PCH pch);
     712
     713    BOOL XWPENTRY winhStoreWindowPos(HWND hwnd, HINI hIni, const char *pcszApp, const char *pcszKey);
     714
    675715    #define XAC_MOVEX       0x0001
    676716    #define XAC_MOVEY       0x0002
  • branches/branch-1-0/src/helpers/winh.c

    r336 r337  
    24702470
    24712471/*
     2472 *@@ winhStoreWindowPos:
     2473 *      saves the position of a certain window in the same format
     2474 *      as the barely documented WinStoreWindowPos API.
     2475 *      This uses the completely undocumented calls
     2476 *      WinGetFrameTreePPSize and WinGetFrameTreePPs imported
     2477 *      from PMWIN.DLL ordinals 972 and 973.
     2478 *
     2479 *      The window should still be visible on the screen
     2480 *      when calling this function. Do not call it in WM_DESTROY,
     2481 *      because then the SWP data is no longer valid.
     2482 *
     2483 *      This returns TRUE if saving was successful.
     2484 *
     2485 *@@added XWP V1.0.6 (2006-10-31) [pr]: @@fixes 458
     2486 */
     2487
     2488BOOL winhStoreWindowPos(HWND hwnd,   // in: window to save
     2489                        HINI hIni,   // in: INI file (or HINI_USER/SYSTEM)
     2490                        const char *pcszApp,  // in: INI application name
     2491                        const char *pcszKey)  // in: INI key name
     2492{
     2493    BOOL brc = FALSE;
     2494    SWP swp;
     2495
     2496    if (WinQueryWindowPos(hwnd, &swp))
     2497    {
     2498        ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
     2499        ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
     2500        PSTOREPOS pStorePos;
     2501
     2502        if ((pStorePos = malloc(ulSize)))
     2503        {
     2504            // This first bit is all guesswork as I don't know what it all means,
     2505            // but it always seems to be the same everywhere I've looked.
     2506            pStorePos->usMagic = 0x7B6A;
     2507            pStorePos->ulRes1 = 1;
     2508            pStorePos->ulRes2 = 1;
     2509            pStorePos->ulRes3 = 0x0400;
     2510            pStorePos->ulRes4 = 0x0300;
     2511            pStorePos->ulRes5 = 0xFFFFFFFF;
     2512            pStorePos->ulRes6 = 0xFFFFFFFF;
     2513
     2514            pStorePos->ulFlags = swp.fl;
     2515            pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
     2516            pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
     2517            pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
     2518            pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
     2519            if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
     2520            {
     2521                pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
     2522                pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
     2523                pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
     2524                pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
     2525            }
     2526
     2527            pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
     2528            pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
     2529            pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, pStorePos + 1);
     2530            ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
     2531            brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
     2532            free(pStorePos);
     2533        }
     2534    }
     2535    return brc;
     2536}
     2537
     2538/*
    24722539 *@@ winhAdjustControls:
    24732540 *      helper function for dynamically adjusting a window's
  • 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.