GUI Part II Midterm - FAQ

Q: How many programs am I writing?

Q: I have a resource conflict between the dialog in the first program, and the same dialog in the second program. Why?

Q: I get linking errors. What on earth caused that?

Q: Uh, how do I work with the registry again?

Q: Ok, I see how to work with the registry. But, whats the best way to store the registry setting in the view class, so that I can give it to the CCaseEdit object when I need to?

Q: How can I set the CCaseEdit conversion setting in InitInstance, when InitInstance doesn't have a CCaseEdit to work with?

 

Q: How many programs am I writing?

A: Two. You will need to create a project/program, to create the dialog and the CCaseEdit class. You will be testing them both in this first program. Once you have this program working succesfully, you are to create another program which is called the Test Program in the hand out.

You may note that this second program, the Test Program, looks and operates nearly identical to the first program. This is normal. This portion of the midterm is designed to introduce you to the Component Gallery, and re-using the classes you created in the previous program. With the second program, you should wind up writing much less code than you did in the first one.

As an example, the code you wrote in the first program, in the CCaseEdit class to convert the case of a string. In your test program, when you add the CCaseEdit class from the component gallery it should bring that fundtion in with it, and that function should be called automatically (i.e., you have to write zero lines of code to use).


Q: I have a resource conflict between the dialog in the first program, and the same dialog in the second program. Why?

A: You should have no conflicts, because you should not re-create the login dialog in your second test program. When you add the dialog class from the Component Gallery, it will also add the resource for the dialog. In other words, let Component Gallery do the work for you.


Q: I get linking errors. What on earth caused that?

A: Without knowing exactly what the link error is, it is hard to tell. But, my guess is that you forgot to declare the static variables from the CCaseEdit class, and thats what is causing the link error. Don't forget that static variables must be declared inside the class, and again seperately outside the class definition, like in a .cpp file. For example:

// In a .h file:
class Boo {
   static int Foo;
};
// In a .cpp file:
int Boo::Foo;


Q: Uh, how do I work with the registry again?

A: In your CWinApp-derived application class, you can call the GetProfileString function (which is a member of the CWinApp class) to retrieve the value of the registry setting for your program and 'setting'. I would recommend doing this in the InitInstance function.

For simplicity, in your menu handler in the second Test program, I would suggest that in the 'Do Conversion' menu handler (which should be in your view class), you save the new conversion setting back to the registry at that point, using WriteProfileString (a member function of the CWinApp class).

The problem here is that the view class is not derived from CWinApp, and WriteProfileString is therefore not a member function. So, you need a CWinApp-derived object in order to call it. To get one, you can call the AfxGetApp function. This is a global Afx function that will return to your current CWinApp-derived object, via pointer. Note: This function can also be used from DLL functions in the future.

To use the AfxGetApp function, you can do the following:

CWinApp* pApp = AfxGetApp();

Now, you can use pApp to call the WriteProfileString function to write your value back to the registry:

pApp->WriteProfileString(....);


Q: Ok, I see how to work with the registry. But, whats the best way to store the registry setting in the view class, so that I can give it to the CCaseEdit object when I need to? or How can I set the CCaseEdit conversion setting in InitInstance, when InitInstance doesn't have a CCaseEdit to work with?

A: You don't need a CCaseEdit object to work with, or any other variable to store the 'status' of the conversion flag for CCaseEdit. Since the flag is a static variable, and the interface functions are also static, you can call them without instantiating a CCaseEdit object. For example:

CCaseEdit::SetConversion( TRUE );

or:

if( CCaseEdit::GetConversion() )
    // do something - like maybe check a menu item