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
|
string Getuser()
{
char delUser[50];
GetWindowText(Username,delUser,50);
string name(delUser);
return name;
}
//-----------------------------MALL PROCEDURE---------------------------------------------------------------//
LRESULT CALLBACK windowProcedure2(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_COMMAND:
switch(wp)
{
case BUTTON_LOGOUT:
//delete from file
const char* filename = "Session.txt";
const char* tempname = "temp.txt";
string cname=Getuser();
ifstream testing(filename);
if (!testing)
{
MessageBoxW(hWnd, L"Cannot open the file", L"Error", MB_OK| MB_ICONEXCLAMATION);
}
ofstream temp("temp.txt", ios::out|ios::trunc);
if (!temp)
{
MessageBoxW(hWnd, L"Cannot open the file", L"Error", MB_OK| MB_ICONEXCLAMATION);
}
string line;
while(getline(testing, line))
{
if (line!=cname)
{
temp<<line;
temp<<"\n";
}
}
testing.close();
temp.close();
remove(filename);
rename(tempname, filename);
MessageBoxW(hWnd, L"Successfully Log out", MB_OK,MB_ICONINFORMATION);
ShowWindow(hLoginWindow,SW_HIDE);
ShowWindow(hMainWindow,SW_SHOW);
| |