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

  • Home
  • SEARCH
  • 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 8581907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:09:49+00:00 2026-06-11T21:09:49+00:00

<pre> #include<Windows.h> #include<process.h> LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam); HWND hwnd; int clientx,clienty;

  • 0
<pre>
#include<Windows.h>
#include<process.h>

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
HWND hwnd;
int clientx,clienty;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
    static TCHAR szAppName[]=TEXT("hello");
    MSG msg;
    WNDCLASS wndclass;

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

    if(!RegisterClass(&wndclass))
    {
        MessageBox(NULL,TEXT("this program requires windows NT"),TEXT("wrong"),MB_ICONERROR);
        return 0;
    }
    hwnd=CreateWindow(szAppName,TEXT("random rectangles"),
        WS_OVERLAPPEDWINDOW,
        100,100,800,600,
        NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,iCmdShow);
    UpdateWindow(hwnd);
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

VOID Thread(PVOID pvoid)
{
    HBRUSH hbrush;
    HDC hdc;
    int xleft,xright,ytop,ybottom,ired,igreen,iblue;
    while(TRUE)
    {
        if(clientx!=0||clienty!=0)
        {
            xleft=rand()%clientx;
            xright=rand()%clientx;
            ytop=rand()%clienty;
            ybottom=rand()%clienty;
            ired=rand()%255;
            igreen=rand()%255;
            iblue=rand()%255;

            hdc=GetDC(hwnd);
            hbrush=CreateSolidBrush(RGB(ired,igreen,iblue));
            SelectObject(hdc,hbrush);

            Rectangle(hdc,min(xleft,xright),min(ytop,ybottom),max(xleft,xright),max(ytop,ybottom));
            ReleaseDC(hwnd,hdc);
            DeleteObject(hbrush);
        }
    }//while
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
    switch(message)
    {
    case WM_CREATE:
        _beginthread(Thread,0,NULL);
        return 0;
    case WM_SIZE:
        clientx=LOWORD(lParam);
        clienty=HIWORD(lParam);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd,message,wParam,lParam);
}
<code>

I do not know how the variable clientx and clienty at the top of the program get their value s when the program runs…Because I didn’t see any value assignments in the program ….I used to debug it in my visual studio 2010, when it ran to “ShowWindow(hwnd,iCmdShow);”in the WinMain(),the clientx and clienty got their values (735 and 654 random…).But before that the clientx and clienty both were “0”. I was confused~~ Thanks a lot~~~ 🙂

  • 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-11T21:09:50+00:00Added an answer on June 11, 2026 at 9:09 pm

    I think you are asking why clientx and clienty both have value zero when they are not explicitly initialised to zero.

    A global variable, as clientx and clienty, has static storage duration. If a variable with static storage duration is not explicitly initialised (from section 6.7.8 Initialization of C99 standard):

    • if it has pointer type, it is initialized to a null pointer;
    • if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    • if it is an aggregate, every member is initialized (recursively) according to these rules;
    • if it is a union, the first named member is initialized (recursively) according to these
      rules.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder how a can include an pre-compiled binary in an iPhone application. I
The only pre-process directive that I know about in VBScript / Classic ASP is
I'm in the process of cross-compiling GTK+ 3.4.4 for Windows. I have already cross-compiled
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
solution is developed for x86 platform and framework 3.5... i need to include pre-request
I am using <pre> tags to preserve long strings of text that include user-entered
Pre-compiled headers seem like they can save a lot of time in large projects,
In the pre ARC era, I could override retain and release and log the
I'm trying to pre-populate create defect popup and I'm not clear on what key/values
I've added a pre-build action for an ASP.NET web control (server control) project, that

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.