I have a problem I'm trying to write to a list box but everytime I do the program states :
Unhandled exception at 0x5c560a97 (msvcr90d.dll) in Dialog_Box.exe: 0xC0000005: Access violation reading location 0x00070000.
when I take out SetWindowText(); the program is fine. here is a copy of my code:
#include <windows.h>
#include "Resource.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//---------------------------------------------------------------------------
wchar_t *ComboBoxItems = L"Time not Set"; //holds the text
wchar_t *ComboBoxItems1 = L"None"; //holds the text
wchar_t *ComboBoxItems2 = L"None"; //holds the text
wchar_t *ComboBoxItems3 = L"None"; //holds the text
string Combo;
string temp;
HWND Handle = NULL; // Specify a handle as null
HWND hTimer;
HWND hWnd; //specify another handle this will be used in the dialog box
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); //Function
//which handles requests for the dialog box
ifstream file;
int input_position = 0;
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
ofstream file2("Gui_display.txt");
file2<<"No Class"<<endl;
file2<<"No Class"<<endl;
file2<<"No Message"<<endl;
file2.close();
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),
hWnd, reinterpret_cast<DLGPROC>(DlgProc));
return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
SetTimer(hWndDlg, IDC_CHECKTIME, 2000, NULL);
HWND hWndPrincipal;
HWND hWndPrincipal2;
HWND hWndPrincipal3;
HWND hWndPrincipal4;
hWndPrincipal = GetDlgItem(hWndDlg, IDC_EDIT1);
hWndPrincipal2 = GetDlgItem(hWndDlg, IDC_EDIT2);
hWndPrincipal3 = GetDlgItem(hWndDlg, IDC_EDIT3);
hWndPrincipal4 = GetDlgItem(hWndDlg, IDC_EDIT5);
string class1;
string class2;
string message;
switch(Msg)
{
case WM_INITDIALOG:
SetWindowText(hWndPrincipal, L"No Time");
SetWindowText(hWndPrincipal2, L"No Class");
SetWindowText(hWndPrincipal3, L"No Class");
SetWindowText(hWndPrincipal4, L"No Message");
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDQUIT:
EndDialog(hWndDlg, 0);
return TRUE;
case IDTK:
ShellExecute(Handle,L"open",L"Time_keeper.exe",
NULL,NULL,SW_SHOWDEFAULT);
return TRUE;
case IDOCS:
ShellExecute(Handle,L"open",L"input.txt",
NULL,NULL,SW_SHOWDEFAULT);
return TRUE;
case IDOML:
ShellExecute(Handle,L"open",L"command.txt",
NULL,NULL,SW_SHOWDEFAULT);
return TRUE;
}
case WM_TIMER:
file.open("Gui_display.txt");
input_position = file.tellg();
file.close();
file.open("Gui_display.txt");
file.seekg(input_position);
getline(file, class1);
getline(file, class2);
getline(file, message);
file.close();
//hWndPrincipal = GetDlgItem(hWndDlg, IDC_EDIT1);
//hWndPrincipal2 = GetDlgItem(hWndDlg, IDC_EDIT2);
//hWndPrincipal3 = GetDlgItem(hWndDlg, IDC_EDIT3);
//hWndPrincipal4 = GetDlgItem(hWndDlg, IDC_EDIT5);
[B][U]SetWindowText(hWndPrincipal, L"Hello");[/U][/B]
return TRUE;
break;
}
return FALSE;
}
//---------------------------------------------------------------------------