I am getting the above error when trying to compile..

main.cpp

#include <windows.h>
#include <string>
#include "resource.h"

#define GETITEM(item) GetDlgItem(hWndDlg, item)

static bool keeprunning = true;
static bool keeprunning1 = true;
static bool keeprunning2 = true;
static void run();
static void breakrun();
static void lunchrun();
static void end();
static void breakend();
static void lunchend();
static DWORD WINAPI ThreadTime(LPVOID lpParam);
static DWORD WINAPI ThreadBreak(LPVOID lpParam);
static DWORD WINAPI ThreadLunch(LPVOID lpParam);
static HANDLE hThread = NULL;

LPCTSTR Caption = "Time for Aux!"; // Set the Captoin for all Msg boxes

// Global Variables
char CurrentTime[15], MeetingTime[15], StartTime[15], Break1Start[15], 
     LunchStart[15], Break2Start[15], LeaveTime[15], LateBreak[15], Time[15],
     Tmp[0], FileString[120];

int Contains = 0;

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
 switch(Msg)
 {
  case WM_INITDIALOG:
       // Initiate what loads when the application starts
       run(); // Start thread for showing current thread
       
       // Open Times.txt file and save to FileString
       HANDLE fh;
       DWORD dwRead;
       DWORD dwFileSize;
       fh = CreateFile("Times.txt", GENERIC_READ, FILE_SHARE_READ, NULL,
                        OPEN_EXISTING, 0, NULL);
       dwFileSize = GetFileSize(fh, NULL);
       ReadFile(fh, FileString, dwFileSize, &dwRead, NULL);
       CloseHandle(fh);
       
       //Split FileString into its respective strings
       strncpy(StartTime, FileString, 11);
       strncpy(Break1Start, FileString + 13, 11);
       strncpy(LunchStart, FileString + 26, 11);
       strncpy(Break2Start, FileString + 39, 11);
       strncpy(LeaveTime, FileString + 52, 11);
       strcpy(FileString, "");
       
       // Load the Windows with the saved string values
       SetWindowText(GetDlgItem(hWndDlg, IDC_MEETING_TIME), "");
       SetWindowText(GetDlgItem(hWndDlg, IDC_START_TIME), StartTime);
       SetWindowText(GetDlgItem(hWndDlg, IDC_BREAK1), Break1Start);
       SetWindowText(GetDlgItem(hWndDlg, IDC_LUNCH), LunchStart);
       SetWindowText(GetDlgItem(hWndDlg, IDC_BREAK2), Break2Start);
       SetWindowText(GetDlgItem(hWndDlg, IDC_LEAVE_TIME), LeaveTime);      
  return TRUE;
  
  case WM_COMMAND:
       switch(LOWORD(wParam))
       {
        case IDC_LATE_BREAK_BTN:
             Sleep(900000); // Start a 15 minute timer
             MessageBox(NULL, "Time to return from your late break.", Caption, 
                         MB_OK);
        return TRUE;
        
        case IDCANCEL:
             // Stop the Current Timer Thread
             end();
             
             // Save current user entered times to string values
             GetWindowText(GETITEM(IDC_START_TIME), StartTime, 15);
             GetWindowText(GETITEM(IDC_BREAK1), Break1Start, 15);
             GetWindowText(GETITEM(IDC_LUNCH), LunchStart, 15);             
             GetWindowText(GETITEM(IDC_BREAK2), Break2Start, 15);
             GetWindowText(GETITEM(IDC_LEAVE_TIME), LeaveTime, 15);
             
             // Merge user entered times into comma delimeted line
             if (strcmp(StartTime, Tmp) == 0)
             {
               strcpy(FileString, "          ");
             }
             else
             {
               strcpy(FileString, StartTime);
             }
             strcat(FileString, ", ");
             
             if (strcmp(Break1Start, Tmp) == 0)
             {
               strcat(FileString, "          ");
             }
             else
             {
               strcat(FileString, Break1Start);
             }
             strcat(FileString, ", ");
             
             if (strcmp(LunchStart, Tmp) == 0)
             {
               strcat(FileString, "          ");
             }
             else
             {
               strcat(FileString, LunchStart);
             }
             strcat(FileString, ", ");
             
             if (strcmp(Break2Start, Tmp) == 0)
             {
               strcat(FileString, "          ");
             }
             else
             {
               strcat(FileString, Break2Start);
             }
             strcat(FileString, ", ");
               
             if (strcmp(LeaveTime, Tmp) == 0)
             {
               strcat(FileString, "          ");
             }
             else
             {
               strcat(FileString, LeaveTime);
             }
             
             // 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); 
        return TRUE;
       }
  break;
  }
 return FALSE; 
}

// Current Time Thread
static void run()
{
 DWORD dummy;
 hThread = CreateThread(NULL, 0, ThreadTime, NULL, 0, &dummy);
}

static void end()
{
 keeprunning = false;
}

static DWORD WINAPI ThreadTime(LPVOID lpParam)
{
 while (keeprunning)
 {
  time_t rawtime;
  struct tm * timeinfo;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  strftime(CurrentTime,20,"%I:%M:%S %p", timeinfo);
  SetWindowText(GetDlgItem(hWndDlg, IDC_CURRENT_TIME), CurrentTime);
  Sleep(1000);
  GetWindowText(GetDlgItem(hWndDlg, IDC_MEETING_TIME), MeetingTime, 15);
  GetWindowText(GetDlgItem(hWndDlg, IDC_START_TIME), StartTime, 15);
  GetWindowText(GetDlgItem(hWndDlg, IDC_BREAK1), Break1Start, 15);
  GetWindowText(GetDlgItem(hWndDlg, IDC_LUNCH), LunchStart, 15);
  GetWindowText(GetDlgItem(hWndDlg, IDC_BREAK2), Break2Start, 15);
  GetWindowText(GetDlgItem(hWndDlg, IDC_LEAVE_TIME), LeaveTime, 15);
  if (strcmp(MeetingTime, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time for your Meeting.", Caption, MB_OK);
  }
  else if (strcmp(StartTime, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time to login and start your day.", Caption, MB_OK);
  }
  else if (strcmp(Break1Start, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time to start your first break.", Caption, MB_OK);
    breakrun();
  }
  else if (strcmp(LunchStart, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time to go eat your lunch.", Caption, MB_OK);
    lunchrun();
  }
  else if (strcmp(Break2Start, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time to start your last break.", Caption, MB_OK);
    breakrun();
  }
  else if (strcmp(LeaveTime, CurrentTime) == 0)
  {
    MessageBox(NULL, "Time to ACD and get ready to go home.", Caption, MB_OK);
  }
 }
 return 0;
}

// Break Thread
static void breakrun()
{
 DWORD dummy;
 hThread = CreateThread(NULL, 0, ThreadBreak, NULL, 0, &dummy);
}

static void breakend()
{
 keeprunning1 = false;
}

static DWORD WINAPI ThreadBreak(LPVOID lpParam)
{
 while(keeprunning1)
 {
  Sleep(900000);
  MessageBox(NULL, "Time to login from your break.", Caption, MB_OK);
  breakend();
 }
 return 0;
}

// Lunch Thread
static void lunchend()
{
  DWORD dummy;
  hThread = CreateThread(NULL, 0, ThreadLunch, NULL, 0, &dummy);
}

static void lunchend()
{
 keeprunning2 = false;
}

static DWORD WINAPI ThreadLunch(LPVOID lpParam)
{
 while(keeprunning2)
 {
  Sleep(1800000);
  MessageBox(NULL, "Time to return from lunch.", Caption, MB_OK);
  lunchend();
 }
 return 0;
}

int APIENTRY WinMain (HINSTANCE hInst, HINSTANCE unused, LPSTR cmdLine, int cmdShow)
{
 DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG), 0, (DLGPROC)(DlgProc));
 return 0;
}

GUI.rc

#include "resource.h"
#include <afxres.h>

IDD_CONTROLS_DLG DIALOG DISCARDABLE  0, 0, 132, 180
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "HSBC Break Clock"
FONT 8, "MS Sans Serif"
MENU IDR_MAIN_MENU
BEGIN
    LTEXT           "Current Time is: ",-1,10,10,55,12
    LTEXT           "Meeting Time: ",-1,10,30,45,12
    LTEXT           "Start Time: ",-1,10,50,45,12
    LTEXT           "Break 1 Start: ",-1,10,70,45,12
    LTEXT           "Lunch Start: ",-1,10,90,45,12
    LTEXT           "Break 2 Start: ",-1,10,110,45,12
    LTEXT           "End Time: ",-1,10,130,45,12
    EDITTEXT        IDC_CURRENT_TIME,80,10,45,12, ES_AUTOHSCROLL
    EDITTEXT        IDC_MEETING_TIME,80,30,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_START_TIME,80,50,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_BREAK1,80,70,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_LUNCH,80,90,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_BREAK2,80,110,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_LEAVE_TIME,80,130,45,12,ES_RIGHT | ES_AUTOHSCROLL
    PUSHBUTTON      "Late Break",IDC_LATE_BREAK_BTN,20,150,40,18
    PUSHBUTTON      "Quit",IDCANCEL,70,150,40,18
END

IDR_MAIN_MENU MENU 
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "Se&lect a Sound",             IDM_FILE_SOUND
        MENUITEM "E&xit",                       IDM_FILE_EXIT
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About...\tF1",               IDM_HELP_ABOUT
    END
END

resource.h

#define IDD_CONTROLS_DLG                101
#define IDR_MAIN_MENU                   102
#define IDR_POPUP                       103
#define IDC_CURRENT_TIME                1002
#define IDC_MEETING_TIME                1003
#define IDC_START_TIME                  1004
#define IDC_BREAK1                      1005
#define IDC_LUNCH                       1006
#define IDC_BREAK2                      1007
#define IDC_LEAVE_TIME                  1008
#define IDC_LATE_BREAK_BTN              1009
#define IDM_FILE_SOUND                  2001
#define IDM_FILE_EXIT                   2002
#define IDM_HELP_ABOUT                  2003

what line number does that error occur on ?

ThreadTime does not have access to hWndDlg. You need to either make it global (DlgProc would set the global var in WM_INITDIALOG)or pass it as a parameter to ThreadTime.

ThreadTime does not have access to hWndDlg. You need to either make it global (DlgProc would set the global var in WM_INITDIALOG)or pass it as a parameter to ThreadTime.

How would I set it as a Global variable or pass it as a parameter?

> How would I set it as a Global variable

This question suggests that you may not be ready for WinAPI programming. You should master the programming language with console programs.

To make it global: First put HWND gHWndDlg; at the top of the program (say, just before the definition of keeprunning). Then under case WM_INITDIALOG: put the line gHWndDlg = hWndDlg; . Then in ThreadProc change all hWndDlg to gHWndDlg.

OK.. I understand most of it.. I really don't learn unless I do it. I was putting something similar at the top but not declaring it in WM_INITDIALOG:. This is my second Win32 API program so it is a learning experience.. Thank you again Nucleon for the help..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.