Creating CProperty Page in a Static Lib 
Author Message
 Creating CProperty Page in a Static Lib

Hi,

I'm just searching on archives but could not find any answer yet...
Basically, I have a Win32 Static Lib project that supports MFC. And I
want to create CPropertyPage based object ... I just could not add some
resources in static lib.. It's possible using MFC Dll Project..

Is there something like MFX Lib projhect... Ot how can I add resourses
into my Lib.. Or How can I create CPropertyPage based object without
resources...

Thx for any help...

Ozgur.



Mon, 28 Jun 2004 19:39:20 GMT  
 Creating CProperty Page in a Static Lib

Quote:
>... I just could not add some resources in static lib..

static libraries can't have resources. If you need a resource you need
a DLL.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Mon, 28 Jun 2004 21:23:52 GMT  
 Creating CProperty Page in a Static Lib

Quote:
> Hi,

> I'm just searching on archives but could not find any answer yet...
> Basically, I have a Win32 Static Lib project that supports MFC. And I
> want to create CPropertyPage based object ... I just could not add some
> resources in static lib.. It's possible using MFC Dll Project..

> Is there something like MFX Lib projhect... Ot how can I add resourses
> into my Lib.. Or How can I create CPropertyPage based object without
> resources...

> Thx for any help...

> Ozgur.

I really don't know if it's a good idea or not, but after you've finished developing your
CPropertyPage using the resource editor, you could provide the perfected template as a byte array
and use the PSP_DLGINDIRECT flag. For example...

    class CPageTwoTempl : public CPageTwo
    {
    public:
        CPageTwoTempl() : CPageTwo()
        {
            m_lpszTemplateName = NULL;
            m_psp.dwFlags |= PSP_DLGINDIRECT;
            m_psp.pResource = GetTemplate();
        }

        UINT GetTemplateSize() const
        {
            return 126;
        }

        LPCDLGTEMPLATE GetTemplate() const
        {
            static const BYTE templ[126] = {
                0x40, 0x00, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00,
                0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBA, 0x00,
                0x5F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00,
                0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x20, 0x00,
                0x54, 0x00, 0x77, 0x00, 0x6F, 0x00, 0x00, 0x00,
                0x08, 0x00, 0x4D, 0x00, 0x53, 0x00, 0x20, 0x00,
                0x53, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00,
                0x20, 0x00, 0x53, 0x00, 0x65, 0x00, 0x72, 0x00,
                0x69, 0x00, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x02, 0x01, 0x21, 0x50, 0x00, 0x00, 0x00, 0x00,
                0x0D, 0x00, 0x0D, 0x00, 0x3F, 0x00, 0x44, 0x00,
                0xEC, 0x03, 0xFF, 0xFF, 0x85, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xA1, 0x50,
                0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x0E, 0x00,
                0x48, 0x00, 0x41, 0x00, 0xE8, 0x03, 0xFF, 0xFF,
                0x81, 0x00, 0x00, 0x00, 0x00, 0x00
            };
            return (LPCDLGTEMPLATE)templ;
        }
    };

...derives from the resource-based CPropertyPage class, but reimplements the template in memory. It
does work in a quick test of the concept.

Anyway, if that sounds like it would work, here's a helper function that will load the specified
DLGTEMPLATE resource and generate something like the above, by dumping it to the IDE output window
during a debug session (I haven't tested it in a UNICODE build BTW)...

    BOOL DebugOutputDlgTemplate(LPCTSTR lpszClassName, LPCTSTR lpszResName)
    {
        ASSERT(AfxIsValidString(lpszClassName));
        ASSERT(HIWORD(lpszResName) == 0 || AfxIsValidString(lpszResName));

        HRSRC hRes = FindResource(NULL, lpszResName, RT_DIALOG);
        CString strBuf;
        LPSTR pBuf;
        INT n = 0;

        if (!hRes)
            return FALSE;

        INT nSize = (INT)SizeofResource(NULL, hRes);

        if (!nSize)
            return FALSE;

        try
        {
            pBuf = strBuf.GetBufferSetLength((6*nSize));
        }
        catch(CMemoryException* e)
        {
            e->Delete();
            return FALSE;
        }

        if (!pBuf)
            return FALSE;

        HGLOBAL hg = LoadResource(NULL, hRes);

        if (!hg)
            return FALSE;

        CHAR* p = (CHAR*)LockResource(hg);

        if (!p)
            return FALSE;

        DLGTEMPLATE* pTmpl = (DLGTEMPLATE*)p;

        for (INT i = 0; i < nSize; i++)
            n += sprintf(&pBuf[n], _T("0x%02X, "), (BYTE)p[i]);

        strBuf.ReleaseBuffer(n-2);
        UnlockResource(hg);

        if (strBuf.IsEmpty())
            return FALSE;

        TRACE(_T("\nclass %sTempl : public %s"), lpszClassName, lpszClassName);
        TRACE(_T("\n{\npublic:\n\t%sTempl() : %s()"), lpszClassName, lpszClassName);
        TRACE(_T("\n\t{\n\t\tm_lpszTemplateName = NULL;"));
        TRACE(_T("\n\t\tm_psp.dwFlags |= PSP_DLGINDIRECT;"));
        TRACE(_T("\n\t\tm_psp.pResource = GetTemplate();\n\t}\n"));
        TRACE(_T("\n\tUINT GetTemplateSize() const\n\t{"));
        TRACE(_T("\n\t\treturn %d;\n\t}\n"), nSize);
        TRACE(_T("\n\tLPCDLGTEMPLATE GetTemplate() const\n\t{"));
        TRACE(_T("\n\t\tstatic const BYTE templ[%d] = {\n"), nSize);

        try
        {
            for (INT i = 0; i < n; i += 48)
                TRACE("\t\t\t%s\n", (LPCTSTR)strBuf.Mid(i, 47));
        }
        catch(CMemoryException* e)
        {
            e->Delete();
            return FALSE;
        }

        TRACE(_T("\t\t};\n\t\treturn (LPCDLGTEMPLATE)templ;\n\t}\n};\n\n"));
        return TRUE;
    }

And in your resource-based project, you could add a menu item to invoke it something like this...

    void CResourceBasedApp::OnMenuDumpPageTwo()
    {
        DebugOutputDlgTemplate(_T("CPageTwo"), MAKEINTRESOURCE(IDD_PAGE_TWO));
    }

...and then just copy and paste it into your static lib project. Your CPropertySheet class will have
to instantiate CPageXXXTempl classes, of course.

HTH,

Jeff...
--
Please post all follow-ups to the newsgroup only.



Tue, 29 Jun 2004 11:05:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Cproperty page how to question

2. Populating Combo Boxes on Separate CProperty Pages

3. Changing CProperty pages at runtime.

4. Placing a CSplitterWnd inside a CProperty Page

5. CProperty Page Fonts

6. CProperty Page - Edit Controls - highlighted text

7. Creating a Static Lib

8. Creating static .lib and dynamic .dll

9. Creating a static lib with inline functions?

10. create static lib wth mfc classes

11. Creating static lib which is dependent on other static lib?

12. Differentiate LIB file for static library and LIB file for DLL

 

 
Powered by phpBB® Forum Software