File doesn't appear.

I am writing a program that creates/updates a file with some predefined text and input from various edit controls. I currently have the file writing with the predefined text but when I try and add the input from one textbox the file isn't created. I even tried taking out the predefined text and it still wouldn't display. I tried a message box to intercept the variable and see if it was getting anything and it was. I am now thoroughly stumped. I'll post my code and see what you make of it. Also please don't be too harsh on any of my coding errors aa I AM ONLY 13 and am still picking this up although I did write this program from scratch.

Thank you in advance :)

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

//The header file
#include "resource.h"

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    //The combobox items
    HWND cboGame;
    const char *Game[] = { "Death Match", "Team Death Match", "Capture The Flag", "Assault" };
    
    //File dialog variable
    char szFileName[MAX_PATH] = "";

	switch(Message)
	{
		case WM_INITDIALOG:
			// Default values
			SetDlgItemText(hwnd, IDC_TEXT, "Press the browse button and choose your map file...");
			SetDlgItemText(hwnd, IDC_TEXT1, "Type the full name of your map here...");
			
			
            //Add items to combobox                                            
            cboGame = GetDlgItem(hwnd, IDC_COMBO);
            
            for(int Count = 0; Count < 4; Count++)
            {
                SendMessage(cboGame, CB_ADDSTRING, 0, (LPARAM) Game[Count]);

            }
            return TRUE;
		break;
		
		case WM_COMMAND:
             switch(LOWORD(wParam))
			{
                case IDC_ADD:
                     {
                        //The open file dialog
                        OPENFILENAME ofn;
   
                        ZeroMemory(&ofn, sizeof(ofn));
   
                        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
                        ofn.hwndOwner = hwnd;
                        ofn.lpstrFilter = "Map Files (*.ctm)\0*.ctm\0All Files (*.*)\0*.*\0";
                        ofn.nMaxFile = MAX_PATH;
                        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
                        ofn.lpstrDefExt = "ctm";
                        ofn.lpstrFileTitle = szFileName;
                        ofn.nMaxFileTitle = 100;
                                              
                        if(GetOpenFileName(&ofn))
                        {
                            SetDlgItemText(hwnd, IDC_TEXT, szFileName);
                        }
                     }
                     break;
                case IDC_ABOUT:
                     {
                            //About dialog box setup
                            int ret = DialogBox(GetModuleHandle(NULL), 
                            MAKEINTRESOURCE(IDD_ABOUT), hwnd, DlgProc);
						       
					        if(ret == -1)
                            {
						           MessageBox(hwnd, "Error, Dialog failed to initialise!", "Error",
					           	MB_OK | MB_ICONINFORMATION);
                            }
                     }
                break;
                
                case IDC_UPDATE:
                     {      
                            //Update the file
                            //CURRENTLY NOT WORKING WITH THE UPDATE FROM THE TEXTBOX                                                  
                            if (MessageBox(hwnd, "Are you happy with your settings?", "Attention!", MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
                            {                                            
                               HANDLE hFile = CreateFile("xmaplist.int", GENERIC_READ|GENERIC_WRITE,
                               0,0,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

                               if( hFile != INVALID_HANDLE_VALUE)
                               {
                               char text[] = "Map+=(FileName=\"";
                               char upd_txt[1000];
                               
                               GetDlgItemText(hwnd, IDC_TEXT, upd_txt, 1000);
                               
                               DWORD dwBytesWritten = 0;
                               SetFilePointer(hFile, 0, 0, FILE_END);
                               WriteFile(hFile, text, strlen(text), &dwBytesWritten, 0);
                               WriteFile(hFile, upd_txt, strlen(upd_txt), &dwBytesWritten, 0);
                               CloseHandle(hFile);
                                                              
                               MessageBox(hwnd, "Your map list was updated successfully!", "Success!", MB_OK | MB_ICONEXCLAMATION); 
                               }                      
                            }
                            else
                            {
                            }
                     }
                     break;
            }
        break;
        case WM_CLOSE:
            //CLose program
			EndDialog(hwnd, 0);
		break;
		default:
			return FALSE;
	}
	return TRUE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}
Please, I really need help with this.
Topic archived. No new replies allowed.