generic.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 3k
Development Platform:

C++ Builder

  1. #include <windows.h>
  2. #include "generic.h"
  3. #if defined (win32)
  4.    #define IS_WIN32 TRUE
  5. #else
  6.    #define IS_WIN32 FALSE
  7. #endif
  8. HINSTANCE hInst;        // current instance
  9. LPCTSTR lpszAppName = "Generic";
  10. LPCTSTR lpszTitle =   "Generic Application";
  11. BOOL RegisterWin95(CONST WNDCLASS* lpwc);
  12. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  13.  {
  14.    MSG msg;
  15.    HWND hWnd;
  16.    WNDCLASS wc;
  17.    wc.style          = CS_HREDRAW | CS_VREDRAW;
  18.    wc.lpfnWndProc    = (WNDPROC)WndProc;
  19.    wc.cbClsExtra     = 0;
  20.    wc.cbWndExtra     = 0;
  21.    wc.hInstance      = 0;
  22.    wc.hIcon          = LoadIcon(hInstance, lpszAppName);
  23.    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  24.    wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  25.    wc.lpszMenuName   = lpszAppName;
  26.    wc.lpszClassName  = lpszAppName;
  27.    if(!RegisterWin95(&wc))
  28.       return false;
  29.    hInst = hInstance;
  30.    hWnd = CreateWindow (lpszAppName,
  31.                         lpszTitle,
  32.                         WS_OVERLAPPEDWINDOW,
  33.                         CW_USEDEFAULT, 0,
  34.                         CW_USEDEFAULT, 0,
  35.                         NULL,
  36.                         NULL,
  37.                         hInstance,
  38.                         NULL
  39.                        );
  40.    if(!hWnd)
  41.       return false;
  42.    ShowWindow(hWnd, nCmdShow);
  43.    UpdateWindow(hWnd);
  44.    while(GetMessage(&msg, NULL, 0,0))
  45.     {
  46.       TranslateMessage(&msg);
  47.       DispatchMessage(&msg);
  48.     }
  49.    return(msg.wParam);
  50.  }
  51. BOOL RegisterWin95(CONST WNDCLASS* lpwc)
  52.  {
  53.    WNDCLASSEX wcex;
  54.    wcex.style           = lpwc->style;
  55.    wcex.lpfnWndProc     = lpwc->lpfnWndProc;
  56.    wcex.cbClsExtra      = lpwc->cbClsExtra;
  57.    wcex.cbWndExtra      = lpwc->cbWndExtra;
  58.    wcex.hInstance       = lpwc->hInstance;
  59.    wcex.hIcon           = lpwc->hIcon;
  60.    wcex.hCursor         = lpwc->hCursor;
  61.    wcex.hbrBackground   = lpwc->hbrBackground;
  62.    wcex.lpszMenuName    = lpwc->lpszMenuName;
  63.    wcex.lpszClassName   = lpwc->lpszClassName;
  64.    wcex.cbSize          = sizeof(WNDCLASSEX);
  65.    wcex.hIconSm         = LoadIcon(wcex.hInstance, "SMALL");
  66.    return RegisterClassEx(&wcex);
  67.  }
  68. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  69.  {
  70.    switch(uMsg)
  71.     {
  72.       case WM_COMMAND:
  73.          switch(LOWORD(wParam))
  74.           {
  75.             case IDM_TEST :
  76.                break;
  77.             case IDM_EXIT :
  78.                DestroyWindow(hWnd);
  79.                break;
  80.           }
  81.          break;
  82.       case WM_DESTROY :
  83.          PostQuitMessage(0);
  84.          break;
  85.       default:
  86.          return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  87.     }
  88.    return(0L);
  89.  }