Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CRgn::GetRegionData

Posted on 1998-10-29
10
Medium Priority
?
414 Views
Last Modified: 2013-11-20
I'm looking to find the proper syntax to retrieve the region data from CRgn::GetRegionData and how to make use of that data with CRgn::CreateFromData. I have tried this suppling the proper parameter but the variable LPRGNDATA needs to be carefully "nurtured", I'm not sure how to initialize and handle this structure.

I will give an A to whomever supplys the answer that also stores and retrieves the data from a file.
0
Comment
Question by:mite51
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1324017
I think that it`s must work:

void StoreRegion(CRgn& rgn)
{
RGNDATA* pData = NULL;
BYTE* pBytes = NULL;
int nBytes = rgn.GetRegionData(NULL, 0);

nBytes += sizeof[RGNDATA]; // I`m not shure (?!), but for safety...
pBytes = new BYTE[nBytes ];

if (!pBytes) // not enough memory!
  return;
pData  = (RGNDATA*)pBytes;

if (rgn.GetRegionData(pData, nBytes) == ERROR)
  {
   delete[] pBytes;
   return; // something wrong
  }
// ok we have data now
// store data
StoreRegionData(pData, nBytes);
delete[] pBytes;
return;
}

BOOL CreateRegionFromFile(CRgn& rgn)
{
RGNDATA* pData = NULL;
int nBytes = ReadRegionData(&pData);
if (!nBytes || !pData)
  return FALSE;

BOOL bRes = rgn.CreateFromData( NULL, nBytes, pData );
BYTE* pBytes = (BYTES*)pData;
delete[] pBytes;
return TRUE;
}

void StoreRegionData(RGNDATA* pData, int nBytes)
{
CFile myFile;
if (myFile.Open("Test.rgn", CFile::modeCreate|CFile::modeWrite|CFile::typeBinary))
 {
  // write mark that Region data stored here!
    char szBuffer[4] = "rgn";
    myFile.Write(szBuffer, sizeof(szBuffer));
    // store number of bytes
    myFile.Write((LPSTR)&nBytes, sizeof(nBytes));
   // and data
    myFile.Write( pData, nBytes);
 }
myFile.Close();
}

int ReadRegionData(RGNDATA** pData)
{
CFile myFile;
*pData = NULL;

if (myFile.Open("Test.rgn", CFile::modeRead|CFile::typeBinary))
 {
  // write mark that Region data stored here!
    char szBuffer[4] = "";
    myFile.Read(szBuffer, sizeof(szBuffer));
    if (!lstrcmp(szBuffer, "rgn"))
       {
        int nBytes = 0;
        myFile.Read((LPSTR)&nBytes, sizeof(nBytes));
        *pData = new BYTE[nBytes];
        if (*pData)
          {
            myFile.Read( pData, nBytes);
            myFile.Close();
            return nBytes;
          }
       }
 }
myFile.Close();
return 0;
}


0
 
LVL 1

Author Comment

by:mite51
ID: 1324018
That was good, but it didn't seem to work (i had to fix some syntax to get it to compile). I don't think its too much to ask for you to debug it. I have the program I'm using this on my web site. In that program the main window class is CTestDlg, the function SetupBk sets up a CRgn for the window based on a color.
It should load the CRgn data from a file, if the file does not exist then it creates the file. If you get it to work I will give you the points and post your name for the work you did.

Jason
the site -- http://www.geocities.com/ResearchTriangle/Lab/5376/Spells/TransDialog/index.html
0
 
LVL 1

Author Comment

by:mite51
ID: 1324019
hello?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:migel
ID: 1324020
Excuse me. I am not compile my examples (I give only idea, not worked program), so ... ;-).
What you mean when say: <...if the file does not exist then it creates the file...>? What region must  be created (simple or more complex)?
0
 
LVL 1

Author Comment

by:mite51
ID: 1324021
I could make psuedo code too. The reason I posted this question for 400 points was because I couldn't get the proper systax, I'm not looking for theory, I need a working example. I'm sorry, but if you can't get the above code to work I can't give you the points.
0
 
LVL 1

Author Comment

by:mite51
ID: 1324022
I'm not sure exactly what wrong but it seems to have a problem allocating the memory and the region is pretty complex so I think may be a source or problems.
0
 
LVL 1

Author Comment

by:mite51
ID: 1324023
I got it to work after screwing with it for a while. I'm going to post the code on my site if you want to take a look. Incase you want to know, it didn't like assiging the memory to a double pointer, so I made it global (ya ya) so I never had to pass the double pointer. I'll make it into a CRgn derived class later.
0
 
LVL 1

Author Comment

by:mite51
ID: 1324024
you can reanswer the question and I'll give you the points
0
 
LVL 12

Accepted Solution

by:
migel earned 1600 total points
ID: 1324025
Hi! Sorry, I had a problem with internet connection, so i can`t send checked code for you.
(I think that global pointer is not good idea, but if it`s work...)
Here is my checked code:

#include "stdafx.h"

void StoreRegionData(RGNDATA* pData, int nBytes);
int ReadRegionData(RGNDATA** pData);

void StoreRegion(CRgn& rgn)
     {
     RGNDATA* pData = NULL;
     BYTE* pBytes = NULL;
     int nBytes = rgn.GetRegionData(NULL, 0);

     nBytes += sizeof(RGNDATA); // I`m not shure (?!), but for safety...
     pBytes = new BYTE[nBytes ];

     if (!pBytes) // not enough memory!
       return;
     pData  = (RGNDATA*)pBytes;

     if (rgn.GetRegionData(pData, nBytes) == ERROR)
       {
        delete[] pBytes;
        return; // something wrong
       }
     // ok we have data now
     // store data
     StoreRegionData(pData, nBytes);
     delete[] pBytes;
     return;
     }

BOOL CreateRegionFromFile(CRgn& rgn)
     {
     RGNDATA* pData = NULL;
     int nBytes = ReadRegionData(&pData);
     if (!nBytes || !pData)
       return FALSE;

     BOOL bRes = rgn.CreateFromData( NULL, nBytes, pData );
     BYTE* pBytes = (BYTE*) pData;
     delete[] pBytes;
     return TRUE;
     }

     void StoreRegionData(RGNDATA* pData, int nBytes)
     {
     CFile myFile;
     if (myFile.Open("Test.rgn", CFile::modeCreate|CFile::modeWrite|CFile::typeBinary))
      {
       // write mark that Region data stored here!
         char szBuffer[4] = "rgn";
         myFile.Write(szBuffer, sizeof(szBuffer));
         // store number of bytes
         myFile.Write((LPSTR)&nBytes, sizeof(nBytes));
        // and data
         myFile.Write( pData, nBytes);
      }
     myFile.Close();
     }

int ReadRegionData(RGNDATA** pData)
     {
     CFile myFile;
     *pData = NULL;

     if (myFile.Open("Test.rgn", CFile::modeRead|CFile::typeBinary))
      {
       // write mark that Region data stored here!
         char szBuffer[4] = "";
         myFile.Read(szBuffer, sizeof(szBuffer));
         if (!lstrcmp(szBuffer, "rgn"))
            {
             int nBytes = 0;
             myFile.Read((LPSTR)&nBytes, sizeof(nBytes));
             *pData = (RGNDATA*)new BYTE[nBytes];
             if (*pData)
               {
                 myFile.Read( pData, nBytes);
                 myFile.Close();
                 return nBytes;
               }
            }
      }
     myFile.Close();
     return 0;
     }
0
 
LVL 1

Author Comment

by:mite51
ID: 1324026
You get lots of points now :)


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question