Thread: Puzzled by this code

  1. #1
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149

    Puzzled by this code

    i got this sample of creating a window on borland cbuilderx

    Code:
    #include<windows.h>
    #include<windows.h>
    #ifdef _BORLANDC_
    #pragma argsused
    #endif
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,WPARAM wParam,LPARAM lParam);
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
    lpCmdLine,int nCmdShow)
    {
    HWND WinForm;
    MSG WinMsg;
    const char *Clsname="Win32Test";
    const char *Wndname="GS Application";
    HINSTANCE WinIns;
    WinIns=hInstance;
    
    WNDCLASSEX WndRegist;
            WndRegist.cbSize        = sizeof(WNDCLASSEX);
            WndRegist.style         = CS_HREDRAW | CS_VREDRAW;
            WndRegist.lpfnWndProc   = WndProcedure;
            WndRegist.cbClsExtra    = 0;
            WndRegist.cbWndExtra    = 0;
            WndRegist.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
            WndRegist.hCursor       = LoadCursor(NULL, IDC_ARROW);
            WndRegist.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
            WndRegist.lpszMenuName  = NULL;
            WndRegist.lpszClassName = Clsname;
            WndRegist.hInstance     = WinIns;
            WndRegist.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    RegisterClassEx(&WndRegist);
    
    
    WinForm=CreateWindow(Clsname,Wndname,WS_OVERLAPPEDWINDOW,100,100,500,300,NULL,NULL,WinIns,NULL);
      if(WinForm)
              {MessageBox(NULL,"Window successful created.","SystemMessage",MB_OK|MB_ICONINFORMATION);}
      else
              {MessageBox(NULL,"Error: Something happend,something bad ...","SystemMessage",MB_OK|MB_ICONWARNING);return 0;}
    
    ShowWindow(WinForm,SW_SHOWNORMAL);
    UpdateWindow(WinForm);
    while( GetMessage(&WinMsg, NULL, 0, 0) )
           {
                TranslateMessage(&WinMsg);
                DispatchMessage(&WinMsg);
           }
    
    return Msg.wParam;
    }
    
    
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        case WM_CREATE:
            return 0;
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
        default:
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        return 0;
    }

    and i have these question :
    1.what is this for?
    Code:
    #ifdef _BORLANDC_
    #pragma argsused
    #endif
    2.what is the meaning of this 'classname'?
    Code:
    const char *Clsname="Win32Test";
    3.what do these codes do? set some basic attribute of the window?
    Code:
    WNDCLASSEX WndRegist;
            WndRegist.cbSize        = sizeof(WNDCLASSEX);
            WndRegist.style         = CS_HREDRAW | CS_VREDRAW;
            WndRegist.lpfnWndProc   = WndProcedure;
            WndRegist.cbClsExtra    = 0;
            WndRegist.cbWndExtra    = 0;
            WndRegist.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
            WndRegist.hCursor       = LoadCursor(NULL, IDC_ARROW);
            WndRegist.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
            WndRegist.lpszMenuName  = NULL;
            WndRegist.lpszClassName = Clsname;
            WndRegist.hInstance     = WinIns;
            WndRegist.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    RegisterClassEx(&WndRegist);
    4.does this function receive all the messages that sent by system? please tell me more details.
    Code:
    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
        case WM_CREATE:
            return 0;
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
        default:
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        return 0;
    }
    any help would be great appreciated ....

    blow me ... ...

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

  3. #3
    Never Exist Hermitsky's Avatar
    Join Date
    Jul 2004
    Posts
    149
    thanks, it is really helpful !!!

    blow me ... ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM