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

C++ Builder

  1. #include <windows.h>
  2. #if defined (WIN32)
  3. #define IS_WIN32 TRUE
  4. #else
  5. #define IS_WIN32 FALSE
  6. #endif
  7. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  8. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  9. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  10. HINSTANCE hInst;   // current instance
  11. LPCTSTR lpszAppName  = "MyApp";
  12. LPCTSTR lpszTitle    = "My Application"; 
  13. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  14. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  15.                       LPTSTR lpCmdLine, int nCmdShow)
  16. {
  17.    MSG      msg;
  18.    HWND     hWnd; 
  19.    WNDCLASS wc;
  20.    // Register the main application window class.
  21.    //............................................
  22.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  23.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  24.    wc.cbClsExtra    = 0;
  25.    wc.cbWndExtra    = 0;                      
  26.    wc.hInstance     = hInstance;              
  27.    wc.hIcon         = LoadIcon( hInstance, lpszAppName ); 
  28.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  29.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  30.    wc.lpszMenuName  = lpszAppName;              
  31.    wc.lpszClassName = lpszAppName;              
  32.    if ( IS_WIN95 )
  33.    {
  34.       if ( !RegisterWin95( &wc ) )
  35.          return( FALSE );
  36.    }
  37.    else if ( !RegisterClass( &wc ) )
  38.       return( FALSE );
  39.    hInst = hInstance; 
  40.    // Create the main application window.
  41.    //....................................
  42.    hWnd = CreateWindow( lpszAppName, 
  43.                         lpszTitle,    
  44.                         WS_OVERLAPPEDWINDOW, 
  45.                         CW_USEDEFAULT, 0, 
  46.                         CW_USEDEFAULT, 0,  
  47.                         NULL,              
  48.                         NULL,              
  49.                         hInstance,
  50.                         NULL               
  51.                       );
  52.    if ( !hWnd ) 
  53.       return( FALSE );
  54.    ShowWindow( hWnd, nCmdShow ); 
  55.    UpdateWindow( hWnd );         
  56.    while( GetMessage( &msg, NULL, 0, 0) )   
  57.    {
  58.       TranslateMessage( &msg ); 
  59.       DispatchMessage( &msg );  
  60.    }
  61.    return( msg.wParam ); 
  62. }
  63. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  64. {
  65.    WNDCLASSEX wcex;
  66.    wcex.style         = lpwc->style;
  67.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  68.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  69.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  70.    wcex.hInstance     = lpwc->hInstance;
  71.    wcex.hIcon         = lpwc->hIcon;
  72.    wcex.hCursor       = lpwc->hCursor;
  73.    wcex.hbrBackground = lpwc->hbrBackground;
  74.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  75.    wcex.lpszClassName = lpwc->lpszClassName;
  76.    // Added elements for Windows 95.
  77.    //...............................
  78.    wcex.cbSize = sizeof(WNDCLASSEX);
  79.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  80.                             IMAGE_ICON, 16, 16,
  81.                             LR_DEFAULTCOLOR );
  82.    return RegisterClassEx( &wcex );
  83. }
  84. LRESULT CALLBACK About( HWND hDlg,
  85.                         UINT message,
  86.                         WPARAM wParam,
  87.                         LPARAM lParam)
  88. {
  89.    switch (message)
  90.    {
  91.        case WM_INITDIALOG:
  92.                return (TRUE);
  93.        case WM_COMMAND:                              
  94.                if (   LOWORD(wParam) == IDOK         
  95.                    || LOWORD(wParam) == IDCANCEL)    
  96.                {
  97.                        EndDialog(hDlg, TRUE);        
  98.                        return (TRUE);
  99.                }
  100.                break;
  101.    }
  102.    return (FALSE); 
  103. }