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 8540117
In Process

The Archive Base Latest Questions

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

To start, here is the description from the document I was given. NOTE: all

  • 0

To start, here is the description from the document I was given.
NOTE: all I had to do was change existing code to meet these requirements

Change the code to create 4 windows organized as shown in the demo.
When the user closes a window, if there are other windows still open
it does NOT kill the program. The user must close ALL of them to stop program,

You will need to keep track of the number of windows opened (and subtract
when they are closed). NO GLOBALS ALLOWED. NO STATICS ALLOWED.

In addition your program must initialize the count using the lParam and CREATESTRUCT.

Possible functions and structs:

SetWindowLong()
GetWindowLong()
SetClassLong()
GetClassLong()
CREATESTRUCT

Ok now, here is what I ended with. I could open the 4 required windows, and had it so closing one window (sending the WM_DESTROY Message) did not end the entire program. What I am confused about is the passing of an lParam and using the CREATESTRUCT.

Here is my wndproc.c:

 LRESULT CALLBACK HelloWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
    HDC     hdc;
    PAINTSTRUCT ps;
    RECT    rect;
    int number = GetClassLongPtr(hwnd, 0);

    switch (message){
        case WM_CREATE:
            if(number == 0){
                SetClassLongPtr(hwnd, 0, (LONG)((CREATESTRUCT*)lParam)->lpCreateParams);
            }
            number++;
            return 0;

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

            GetClientRect(hwnd, &rect);
            DrawText(hdc, TEXT("Unique yet the same!"), -1, &rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER);

            EndPaint(hwnd, &ps);
            return 0;

        case WM_DESTROY:
            number--;
            if(number == 0){
                PostQuitMessage(0);
            }
            return 0;
    }
    return DefWindowProc(hwnd, message, wParam, lParam);

I’m trying to get the variable, which I pass as the lParam of the first window that is created, to be set as the Class Extra. Does that make sense? Here is my main.c:

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCMLine, int iCmdShow){
static TCHAR szAppName[] = TEXT (“HelloApplication”);
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
LONG* count;

wndclass.style      = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = HelloWndProc;
wndclass.cbClsExtra = 5;
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 95/98/NT"),
                szAppName, MB_ICONERROR);
    return 0;
}

hwnd = CreateWindow(szAppName,      
                    TEXT("Hello World for Windows"), 
                    WS_OVERLAPPEDWINDOW,    
                    100,        
                    50,     
                    400,        
                    300,        
                    NULL,               
                    NULL,           
                    hInstance,          
                    count = 0);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);

Any help would be appreciated; I’ve already been quizzed on this info in my class and did not understand it. I’m posting this question for my own understanding only.

Thanks.

  • 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-11T11:31:34+00:00Added an answer on June 11, 2026 at 11:31 am

    As you have to count the number of windows (instances) of the same window class, the counter needed can be seen as a static data member of the window class.

    So the goal is to add some extra data (here an integer counter) to the window class. To do so, one needs to tell windows to allocate this extra data. This can be achieved by passing the right values to RegisterClass(). For the counter needed, set the member cbClsExtra of the structure of type WNDCLASS, which’s reference is passed to the RegisterClass(), to the size of the integer counter.

    To access the windows class’ static data (and with it the integer counter) in the message dispatcher’s callback method use GetClassLongPtr().

    As I assume this is homework I leave the rest of the game as an exercise … 😉

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

Sidebar

Related Questions

Ok here is my problem : Before i start the description, let me to
Here I have 2 requirements: Need a batch file to start a process on
here is the code: http://jsfiddle.net/VW8V5/1/ When hover it should start looping but end of
Here is the code: <?php //Starting session session_start(); //Includes mass includes containing all the
Here is te code: <?php //Starting session session_start(); //Includes mass includes containing all the
Here is MySQL prepared statement SELECT ag.`attendance_type`, ag.`description`, COUNT(a.`attendance`) attendance_count FROM `ems_attendance` a RIGHT
To start off, here is the JSON response that I've been working on: {
So I decided to start using prototype and here's my first question. I'm trying
here is the code <?php session_start(); if(!isset($_SESSION['user_name'])) { header('Location: login.php'); } $conn = mysql_connect(localhost,
Here's the scenario: I'm an SSIS virgin, but I found an excuse to start

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.