Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  WINAPI
Language: C/C++
Code:
#include<windows.h>

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

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR lpCmdLine, int nCmdShow)
{
     const char* lpszClassName = TEXT("WINAPI");
     WNDCLASS wc;
     HWND hWnd;
     MSG msg;

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

     if(!RegisterClass(&wc))
     {
          MessageBox(NULL, TEXT("Requires Windows NT or later!"), TEXT("Error"), MB_OK);
          return EXIT_FAILURE;
     }

     hWnd = CreateWindow(
          lpszClassName,
          lpszClassName,
          WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, CW_USEDEFAULT,
          CW_USEDEFAULT, CW_USEDEFAULT,
          NULL, NULL,
          hInst, NULL);
     
     if(NULL == hWnd)
     {
          MessageBox(NULL, TEXT("Can't create window!"), TEXT("Error"), MB_OK);
          return EXIT_FAILURE;
     }

     ShowWindow(hWnd, SW_SHOW);
     UpdateWindow(hWnd);

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

     return msg.wParam;
}

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

     switch(uMsg)
     {
     case WM_DESTROY:
          PostQuitMessage(0);
          return 0;
     case WM_PAINT:
          hdc = BeginPaint(hWnd, &ps);
          EndPaint(hWnd, &ps);
          return 0;
     default:
          return DefWindowProc(hWnd, uMsg, wParam, lParam);
     }
}
          
Comments: