LOGFONT struct & Registry :: MFC

This is a discussion on LOGFONT struct & Registry :: MFC within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I would like to save properties of a LOGFONT object in the registry so I can log the exact ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    LOGFONT struct & Registry :: MFC

    Hi.

    I would like to save properties of a LOGFONT object in the registry so I can log the exact settings back at program startup. LOGFONT contains about eight to ten individual settings like height, weight, etc. I have never used the store by binary using MFC. Do I have to store the LOGFONT object as a binary in the registry? Will it fit?

    What is the best way to save/restore a LOGFONT object in into the registry?

    Thanks,
    Kuphryn

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Do I have to store the LOGFONT object as a binary in the registry?<<

    You can store it as you please. Obviously if you are going to save it as a string then you would have to break the LOGFONT parameters up into individual string values. Probably best to save it as binary.

    >>Will it fit?<<

    Easily.
    Last edited by Ken Fitlike; 05-27-2002 at 06:22 PM.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thank guys.

    I am using the WriteProfileBinary() and GetProfileBinary() functions. The program seems to save and read data to and from the registry without any errors. However, the data that it reads back is not the same as what it writes, or maybe it is not writing data correctly. Anywhere, here are the two functions I use to write and read the LOGFONT object to and from the registry.

    // Write to registry
    -----
    LOGFONT mLogFont;
    memset(&mLogFont, 0, sizeof(LOGFONT));
    mLogFont = pView->GetLogFont();
    theApp.WriteProfileBinary(version, _T("Font"), reinterpret_cast<LPBYTE>(&mLogFont), sizeof(LOGFONT));
    -----

    // Read from registry
    -----
    UINT mRead = 0;
    LOGFONT mLogFont;
    memset(&mLogFont, 0, sizeof(LOGFONT));
    theApp.GetProfileBinary(version, _T("Font"), reinterpret_cast<LPBYTE *>(&mLogFont), &mRead);
    pView->SetLogFont(&mLogFont);
    -----

    I am not sure if the problem is that the program is not saving the LOGFONT object correctly, or is it that it is not reading it back correctly. Please post if you see any possible problems with the algorithm.

    Thanks,
    Kuphryn

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. The problem was in the algorithm to read the data back from the registry. Here is an algorithm that does work.

    // Read from registry
    -----
    UINT mRead = 0;
    LOGFONT mLogFont;
    theApp.GetProfileBinary(version, _T("Font"), reinterpret_cast<LPBYTE *>(&mLogFont), &mRead);
    pView->SetLogFont(&mLogFont);
    -----

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  2. Help please im stuck
    By ItsMeHere in forum C Programming
    Replies: 7
    Last Post: 06-15-2006, 05:07 AM
  3. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  4. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 03:56 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21