InvalidateRect Function Error/Question

Every time I call this function like this:

InvalidateRect (hWnd, NULL, TRUE);

It always deletes the existing text.

.Exe file download, use the features drop down, go to mips helper, enter "add" as the command, and then click the Learn button to see what I mean:

Note: This also has the full source code.

http://www.sendspace.com/file/hihibh

I am calling this function on line 71 of the file WindowProcedures.h and my class, that paints text for me, is in the file "OOP.h"

What I need:
For the function to NOT delete any existing text.

Any help would be great ! :D
Last edited on
I was going to download, but check the invalidateRect function... I think the TRUE you are sending is deleting the image... try that first...
There are some ussues with array boundary overflows, and the WM_PAINT setup wasn't working
well.
I made some changes as follows:

The globals.h file now looks like this:
1
2
3
4
5
6
7
8
9
10
//Globals.h
using namespace std;
HWND hWnd;
HWND hWndChild [11];
HINSTANCE hInstance = GetModuleHandle (NULL);
int iLoopCounter = 0;
namespace nsMIPSHelper {
    char *cpYouTube = "http://www.youtube.com/user/LeetGamer4L";
    char *cpaInfo [5];//Changed here
}


The oop.h file now looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//oop.h
class CPaintClass {
    public:
    PAINTSTRUCT ps;
    HDC hDC;
    HWND hParent;
    CPaintClass (HWND hWnd  ) 
    {
        hParent = hWnd;
        hDC = BeginPaint (hParent, &ps);
    }
        void DoText( int iX, int iY, char *cpaText [])
        {
            for (iLoopCounter = 0; strlen(cpaText [iLoopCounter]) != 0; iLoopCounter++, iY += 20)
            {
                TextOut (hDC, iX, iY, cpaText [iLoopCounter], strlen (cpaText [iLoopCounter]));

            }
        }
    ~CPaintClass () {
        EndPaint (hParent, &ps);
    }
};


The windows procedure file has also changed slightly, I'll post that in a minute (too long to fit in this post)

The windowprocedures.h file now look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//windowsprocedures.h

namespace nsWindowProcedures
{
    namespace nsCWP
    {
        LRESULT CALLBACK CWP_1 (HWND hWnd, unsigned int uiMsg, WPARAM wParam, LPARAM lParam)
        {
            switch (uiMsg)
            {
            case WM_CLOSE:
                ShowWindow (hWnd, SW_HIDE);
                return 0;
                break;
            case WM_PAINT:
            {
                char *cpaText [] =
                {
                    "Welcome to -LeetGamer-'s PSP All In One v1!",
                    "This program will help any PSP user, who has a CFW, with a number of different things!",
                    "If you find a bug, or have an idea for a future version, use the \"Contact me\" drop down.",
                    "If you want to use the features that this program has, then use the \"Features\" drop down.",
                    "Also make note that there are options at File>Options.",
                    "This program was made in the C++ programming language, and is open source.",
                    "Enjoy!",
                    '\0'
                };
                CPaintClass qPaint (hWnd); //changes here
                qPaint.DoText(5,5,cpaText);//changes here
                return 0;//changes here
            }
            break;
            }
            return DefWindowProc (hWnd, uiMsg, wParam, lParam);
        }


        LRESULT CALLBACK CWP_2 (HWND hWnd, unsigned int uiMsg, WPARAM wParam, LPARAM lParam)
        {
            //Changes here The initial/default text - 
            static char *cpaText [] =
            {
                "Enter a MIPS command, and then click a button",
                "Name: ",
                "Information: ",
                "Syntax: ",
                "Syntax Explained: ",
                "Example: ",
                "Enter value for t0: ",
                "Enter value for t1: ",
                "Result: ",
                "\0"//terminator = empty line
            };

            //this will point to which text we want to print
            //It will initially point to the default text array above
            
            static char **pText = NULL;//and we will pass this to the CPaintClass
            

            switch (uiMsg)
            {
            case WM_CLOSE:
                ShowWindow (hWnd, SW_HIDE);
                return 0;
                break;

            case WM_CREATE:
                CreateWindow ("edit", "Command Here", WS_CHILD_WINDOW, 5, 5, 130, 30, hWnd, (HMENU) MIPS_HELPER_COMMAND, hInstance, NULL);
                CreateWindow ("button", "Learn", WS_CHILD_WINDOW, 140, 5, 50, 30, hWnd, (HMENU) MIPS_HELPER_LEARN, hInstance, NULL);
                CreateWindow ("button", "YouTube Tutorial", WS_CHILD_WINDOW, 200, 5, 130, 30, hWnd, (HMENU) MIPS_HELPER_YOUTUBE, hInstance, NULL);
                CreateWindow ("edit", "", WS_CHILD_WINDOW, 130, 160, 100, 20, hWnd, (HMENU) MIPS_HELPER_INPUT_ONE, hInstance, NULL);
                CreateWindow ("edit", "", WS_CHILD_WINDOW, 130, 180, 100, 20, hWnd, (HMENU) MIPS_HELPER_INPUT_TWO, hInstance, NULL);
                break;
            case WM_PAINT: //changes here
            {
                CPaintClass qPaint (hWnd);
                qPaint.DoText(5,40,cpaText);
                if (pText != NULL)
                {
                    qPaint.DoText(135,60, pText);
                }
            }
            return 0;

            case WM_COMMAND:
                switch (LOWORD (wParam))
                {
                case MIPS_HELPER_LEARN:
                {
                    TCHAR tcaCommand [256]={0};
                    pText = NULL;

                    GetWindowText (GetDlgItem (hWnd, MIPS_HELPER_COMMAND), tcaCommand, 256);
                    using namespace nsMIPSHelper;
                    if (CompareCommand ("add"))
                    {
                        cpaInfo [0] = "Add - Add";
                        cpaInfo [1] = "Adds the value in two registers and puts the result into another register";
                        cpaInfo [2] = "Add t2 t0 t1";
                        cpaInfo [3] = "The above is saying add the values in t0 and t1 and put the reuslt into another register";
                        cpaInfo[4]="\0";//terminator = empty line
                        cpYouTube = "http://www.youtube.com/user/LeetGamer4L#p/c/C1ADEAA098E7B652/6/39KfxEIMr-s";
                    }
                    else
                    {
                        ErrorMessageBox (hWnd, "Unknown/Invalid Command");
                        break;
                    }

                //set our text  pointer
                    pText = cpaInfo;
                   InvalidateRect (hWnd, NULL, FALSE);//cause a repaint
                   UpdateWindow(hWnd);
                  return 0;

                }
                break;
                case MIPS_HELPER_YOUTUBE:
                    using namespace nsMIPSHelper;
                    if (MessageBox (hWnd, "You are about to connect to the internet and open http://Youtube.com\nDo you want to continue?", "Internet Connection Confirm:", MB_YESNO) == 6)
                    {
                        ShellExecute (NULL, "open", cpYouTube, NULL, NULL, SW_SHOW);
                        cpYouTube = "http://www.youtube.com/user/LeetGamer4L";
                    }
                    break;
                }
                break;
            }
            return DefWindowProc (hWnd, uiMsg, wParam, lParam);
        }
    };
    LRESULT CALLBACK MainWindowProcedure (HWND hWnd, unsigned int uiMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uiMsg)
        {
        case WM_CLOSE:
            if (CheckOption (EXIT_MESSAGE))
            {
                if (MessageBox (hWnd, "Are you sure you want to exit the program? All text in this program will be lost.", "Exit Message:", MB_YESNO) == 6)
                {
                    DestroyWindow (hWnd);
                }
                else return 0;
            }
            else DestroyWindow (hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage (0);
            break;
        case WM_COMMAND:
            switch (wParam)
            {
            case ID_MENU_FILE_CLOSE:
                SendMessage (hWnd, WM_CLOSE, wParam, lParam);
                break;
            case ID_MENU_FILE_OPTIONS_HIDE_CHILD_WINDOWS_ON:
                SetOption (HIDE_CHILD_WINDOWS, true);
                break;
            case ID_MENU_FILE_OPTIONS_HIDE_CHILD_WINDOWS_OFF:
                SetOption (HIDE_CHILD_WINDOWS, false);
                break;
            case ID_MENU_FILE_OPTIONS_DYNAMIC_BG_COLOR_ON:
                SetOption (DYNAMIC_BG_COLOR, true);
                break;
            case ID_MENU_FILE_OPTIONS_DYNAMIC_BG_COLOR_OFF:
                SetOption (DYNAMIC_BG_COLOR, false);
                break;
            case ID_MENU_FILE_OPTIONS_EXIT_MESSAGE_ON:
                SetOption (EXIT_MESSAGE, true);
                break;
            case ID_MENU_FILE_OPTIONS_EXIT_MESSAGE_OFF:
                SetOption (EXIT_MESSAGE, false);
                break;
            case ID_MENU_FEATURES_WELCOME:
                if (CheckOption (HIDE_CHILD_WINDOWS)) HideAllChildWindows ();
                ShowWindow (hWndChild [0], SW_SHOW);
                break;
            case ID_MENU_FEATURES_MIPS_HELPER:
                if (CheckOption (HIDE_CHILD_WINDOWS)) HideAllChildWindows ();
                ShowWindow (hWndChild [1], SW_SHOW);
                break;
            }
            break;
        }
        return DefWindowProc (hWnd, uiMsg, wParam, lParam);
    }
};
Topic archived. No new replies allowed.