I have a problem on writing MFC program

I have a test2.h file to save CString b;
my purpose is write the value get from the edit control to String b
void Cdlg001::OnBnClickedButton1()
{

CString value;
seat2.GetWindowText(value);
MessageBox(_T("11111"));
((Ctest2App *)AfxGetApp())->b= "0000";
if( ((Ctest2App *)AfxGetApp())->b == "0000")
MessageBox(_T("00000"));

// TODO: Add your control notification handler code here
}
I can compile the program but the program stops at((Ctest2App *)AfxGetApp())->b= "0000";
I would like to know why the program stops at
((Ctest2App *)AfxGetApp())->b= "0000";
million thanks!
How can I make it work again?
Last edited on
1. Can you use the code formatting tag to format your code.
2. Can you post your CWinApp derived class' header file.
2. Can you post your CWinApp derived class' header file.This is the headder file code.

// test2.h : main header file for the PROJECT_NAME application
//

#pragma once

#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif

#ifdef POCKETPC2003_UI_MODEL
#include "resourceppc.h"
#endif
#ifdef SMARTPHONE2003_UI_MODEL
#include "resourcesp.h"
#endif

// Ctest2App:
// See test2.cpp for the implementation of this class
//

class Ctest2App : public CWinApp
{
public:
Ctest2App();

// Overrides
public:
virtual BOOL InitInstance();

// Implementation

DECLARE_MESSAGE_MAP()

public:
int g_n_filmID;
int g_n_location;
int g_n_time;
int a;
CString b;
// This is the most useful part
};

extern Ctest2App theApp;




1. Can you use the code formatting tag to format your code. what do you mean by that?
thz
closed account (z05DSL3A)
Can you use the code formatting tag to format your code. what do you mean by that?


put [code] at the start of your code and [/code] at the end.

for example:

[code]
class Ctest2App : public CWinApp
{
public:
Ctest2App();

// Overrides
public:
virtual BOOL InitInstance();
[/code]

is displayed as

1
2
3
4
5
6
7
8
class Ctest2App : public CWinApp
{
public:
Ctest2App();

// Overrides
public:
virtual BOOL InitInstance();

There's nothing obviously wrong with what you've posted.

I should point out that using public data is almost always bad. Having said that, try:
1
2
3
4
void Cdlg001::OnBnClickedButton1()
{
    seat2.GetWindowText(theApp.b);
}
I just cannot pass the string to a public CString let say b
theApp.b is a public CString. That means the rest of the program has unfettered access to it.
Topic archived. No new replies allowed.