4 Replies - 891 Views - Last Post: 29 April 2009 - 04:34 PM Rate Topic: -----

#1 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Call a Case Statement from Another Case Statement

Post icon  Posted 29 April 2009 - 01:48 PM

I want to be able to reuse some code but I do not know how to call a case statement from another case statement.

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  switch(Msg)
  {
	case WM_DESTROY: // command for the close option at top right of screen
			// Call IDM_FILEEXIT code
	break;

	case IDM_FILE_EXIT:
			 // Stop the Current Timer Thread
			 end();
			 
			 // Save current user entered times to string values
			 GetWindowText(GETITEM(IDC_START_TIME), StartTime, 10);
			 GetWindowText(GETITEM(IDC_BREAK1), Break1Start, 10);
			 GetWindowText(GETITEM(IDC_LUNCH), LunchStart, 10);			 
			 GetWindowText(GETITEM(IDC_BREAK2), Break2Start, 10);
			 GetWindowText(GETITEM(IDC_LEAVE_TIME), LeaveTime, 10);
	
			 // Save the string values to a file
			 HANDLE fh;
			 DWORD dwWritten = 120;
			 DWORD dwFileSize = strlen(FileString);
			 fh = CreateFile("Times.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
							  FILE_ATTRIBUTE_NORMAL, NULL);
			 WriteFile(fh, FileString, dwFileSize, &dwWritten, NULL);
			 CloseHandle(fh);

			 // Terminates the window
			 EndDialog(hWndDlg, 0); 
		break;
	   }
  break;
  }
 return FALSE; 
}



Is This A Good Question/Topic? 0
  • +

Replies To: Call a Case Statement from Another Case Statement

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,513
  • Joined: 23-August 08

Re: Call a Case Statement from Another Case Statement

Posted 29 April 2009 - 03:27 PM

You may have to explain what you're trying to do more clearly, but I think what you want to do is send the IDM_FILE_EXIT message to the window with SendMessage(), like:
SendMessage(hWndDlg, IDM_FILE_EXIT, 0, 0);

Was This Post Helpful? 0
  • +
  • -

#3 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Re: Call a Case Statement from Another Case Statement

Posted 29 April 2009 - 03:46 PM

I want ot have...

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  switch(Msg)
  {
	case WM_DESTROY: // command for the close option at top right of screen
						 // Stop the Current Timer Thread
			 end();
			 
			 // Save current user entered times to string values
			 GetWindowText(GETITEM(IDC_START_TIME), StartTime, 10);
			 GetWindowText(GETITEM(IDC_BREAK1), Break1Start, 10);
			 GetWindowText(GETITEM(IDC_LUNCH), LunchStart, 10);			 
			 GetWindowText(GETITEM(IDC_BREAK2), Break2Start, 10);
			 GetWindowText(GETITEM(IDC_LEAVE_TIME), LeaveTime, 10);
	
			 // Save the string values to a file
			 HANDLE fh;
			 DWORD dwWritten = 120;
			 DWORD dwFileSize = strlen(FileString);
			 fh = CreateFile("Times.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
							  FILE_ATTRIBUTE_NORMAL, NULL);
			 WriteFile(fh, FileString, dwFileSize, &dwWritten, NULL);
			 CloseHandle(fh);

			 // Terminates the window
			 EndDialog(hWndDlg, 0); 
	break;

	case IDM_FILE_EXIT:
			 // Stop the Current Timer Thread
			 end();
			 
			 // Save current user entered times to string values
			 GetWindowText(GETITEM(IDC_START_TIME), StartTime, 10);
			 GetWindowText(GETITEM(IDC_BREAK1), Break1Start, 10);
			 GetWindowText(GETITEM(IDC_LUNCH), LunchStart, 10);			 
			 GetWindowText(GETITEM(IDC_BREAK2), Break2Start, 10);
			 GetWindowText(GETITEM(IDC_LEAVE_TIME), LeaveTime, 10);
	
			 // Save the string values to a file
			 HANDLE fh;
			 DWORD dwWritten = 120;
			 DWORD dwFileSize = strlen(FileString);
			 fh = CreateFile("Times.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
							  FILE_ATTRIBUTE_NORMAL, NULL);
			 WriteFile(fh, FileString, dwFileSize, &dwWritten, NULL);
			 CloseHandle(fh);

			 // Terminates the window
			 EndDialog(hWndDlg, 0); 
		break;
	   }
  break;
  }
return FALSE; 
}



But without having to reuse all that code in the WM_DESTROY case.

This post has been edited by mcamardo: 29 April 2009 - 03:47 PM

Was This Post Helpful? 0
  • +
  • -

#4 stayscrisp  Icon User is online

  • フカユ
  • member icon

Reputation: 999
  • View blog
  • Posts: 4,176
  • Joined: 14-February 08

Re: Call a Case Statement from Another Case Statement

Posted 29 April 2009 - 03:52 PM

Could you not make the code you want to reuse into a function?

Seems the best way :^:
Was This Post Helpful? 1
  • +
  • -

#5 mcamardo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 48
  • Joined: 29-June 08

Re: Call a Case Statement from Another Case Statement

Posted 29 April 2009 - 04:34 PM

Yup.. that did it..

<-- Bangs head against desk.. Been working on this to long.. even the simplist thing just eluded me.. Time to step away for today.. Thanks..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1