Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:11:31+00:00 2026-06-13T08:11:31+00:00

I have 3 windows that have to interact with each other using events. windows

  • 0

I have 3 windows that have to interact with each other using events.
windows 1 and 2 are identical; each only have one button in them.

Basically, I the main window(program 3) to not show up until one of the other two windows buttons
is clicked; this is how it was describes in the lab:

You need to use synchronization to control the processes (starting Program3 via Program1 or 2, ending Program1 or 2 via closing Program3). Note: Program1 and Program2 must have had their button clicked in order for them to receive the signal to die

I’ve been looking around and got this so far for code:

Main window(program 3):

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

#include <stdio.h>
#include <tchar.h>
#include <conio.h>
#pragma comment(lib, "winmm.lib")


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("RACE") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;
     HANDLE hEvents[2];
     hEvents[0] = "btn2";
     hEvents[1] = "btn3";
     DWORD count = 2;

     HBRUSH brush;
     brush = CreateSolidBrush(RGB(255,0,0));

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0;
     wndclass.cbWndExtra    = 0;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = brush;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     TCHAR* name;

     //WAIT FOR SIGNAL
     DWORD result = WaitForMultipleObjects(count,hEvents,FALSE,INFINITE);//work on this
     if(result == WAIT_OBJECT_0)
     {
        name = TEXT("Program 1");       
     }
     else if(result == WAIT_OBJECT_0 + 1)
     {
        name = TEXT("Program 2");
     }

    hwnd = CreateWindow (szAppName,                  // window class name
                          name, // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          0,              // initial x position
                          0,              // initial y position
                          600,              // initial x size
                          600,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL);                     // creation parameters



     ShowWindow (hwnd, iCmdShow) ;//DON'T SHOW UNTIL ANOTHER WINDOW'S BUTTON IS PUSHED.
     UpdateWindow (hwnd) ;

     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;


     TCHAR* carNames[5] = {TEXT("Red Car"), TEXT("Blue Car"), TEXT("Black Car"), TEXT("Green Car"), TEXT("Orange Car")};
     switch (message)
     {
     case WM_CREATE:
         HWND hwndButton;

         for(int i = 0; i < 5; i++)
         {
         hwndButton = CreateWindow ( TEXT("button"),//type of child window 
                                   carNames[i],//text displayed on button
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,//type of button
                                   20, (20*i*5+10),
                                   85, 25,
                                   hwnd, //parent handle i.e. main window handle
                                    (HMENU) i,//child ID – any number
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL);
         }



         break;


          return 0 ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;



          EndPaint (hwnd, &ps) ;
          return 0 ;

    /* case WM_CLOSE:

          c--;
          DestroyWindow(hwnd);
          return 0 ;*/

     case WM_DESTROY:

          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

window 2(program2):

    #include <windows.h>
    #include<string.h>
    #pragma comment(lib, "winmm.lib")

    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("Part 2") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;


         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0;
         wndclass.cbWndExtra    = 0;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;

         if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }

         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("Part 2"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              0,              // initial x position
                              0,              // initial y position
                              300,              // initial x size
                              200,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                             NULL) ;                     // creation parameters



         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;


         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }

    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         HDC         hdc ;
         PAINTSTRUCT ps ;
         HANDLE hEvent;


         switch (message)
         {
         case WM_CREATE:
             HWND hwndButton2;
               hwndButton2 = CreateWindow ( TEXT("button"),//type of child window 
                                       TEXT("PRESS ME!"),//text displayed on button
                                       WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,//type of button
                                       20, 20,
                                       200, 25,
                                       hwnd, //parent handle i.e. main window handle
                                        (HMENU) 45,//child ID – any number
                                       ((LPCREATESTRUCT) lParam)->hInstance, NULL);

               hEvent = CreateEvent(NULL, //no security attributes
                FALSE, //auto-reset event object
                FALSE, //initial state is nonsignaled
                L"btn2"); //unnamed object



              return 0 ;

         case WM_PAINT:
              hdc = BeginPaint (hwnd, &ps) ;



              EndPaint (hwnd, &ps) ;
              return 0 ;

         case WM_COMMAND:


             SetEvent("btn2");

             return 0;

         case WM_DESTROY:

              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }

and window 3 (program 3): which is pretty much identical to window 2

#include <windows.h>
#include<string.h>
#pragma comment(lib, "winmm.lib")

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("Part 3") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;


     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0;
     wndclass.cbWndExtra    = 0;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }

     hwnd = CreateWindow (szAppName,                  // window class name
                          TEXT ("Part 3"), // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          0,              // initial x position
                          0,              // initial y position
                          300,              // initial x size
                          200,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                         NULL) ;                     // creation parameters



     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;


     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;
     HANDLE hEvent1;

     switch (message)
     {
     case WM_CREATE:
           HWND hwndButton3;
           hwndButton3 = CreateWindow ( TEXT("button"),//type of child window 
                                   TEXT("PRESS ME!"),//text displayed on button
                                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,//type of button
                                   20, 20,
                                   200, 25,
                                   hwnd, //parent handle i.e. main window handle
                                    (HMENU) 95,//child ID – any number
                                   ((LPCREATESTRUCT) lParam)->hInstance, NULL);

           hEvent1 = CreateEvent(NULL, //no security attributes
            FALSE, //auto-reset event object
            FALSE, //initial state is nonsignaled
            L"btn3"); //unnamed object


          return 0 ;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;



          EndPaint (hwnd, &ps) ;
          return 0 ;

          case WM_COMMAND:

         SetEvent("btn3");

         return 0;


     case WM_DESTROY:

          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

These are all in the same solution; but in different projects(multiple project in one solution).

The problem right now is that I can’t seem to get the main window to open when I click
either one of the buttons. I’ve tried many different things, but none seem to be working.

Any and all help is appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:11:32+00:00Added an answer on June 13, 2026 at 8:11 am
     HANDLE hEvents[2];
     hEvents[0] = "btn2";
     hEvents[1] = "btn3";
    

    That’s not right. You’ll have to call the CreateEvent function just like you do in the other two programs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows service that does some intensive work every one minute (actually
I have a Windows application that has 2 Forms . From one form I
I have an application consisting of two windows, one communicates to the other and
I have a windows phone app that allows the user to interact with it.
This is nuts. I have an ASP.NET MVC application using Windows authentication that, amongst
I have a Windows service that writes messages to the Event Log. I also
I have a Windows process that runs in the background and periodically backs up
i have a windows form that contains a bunch of textboxes. I need a
I have a Windows server that is intermittently losing the ability to lookup DNS
I have a Windows server that is intermittently losing the ability to lookup DNS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.