C   23

menyy

Guest on 20th July 2022 07:02:03 AM

  1.  
  2. #include <windows.h>
  3. define ID_MENU 501
  4.  
  5. #define IDM_FILENEW         200
  6. #define IDM_FILEOPEN        201
  7. #define IDM_FILESAVE        202
  8. #define IDM_FILESAVEAS      203
  9. #define IDM_FILEPRINT       204
  10. #define IDM_FILEPAGESETUP   205
  11. #define IDM_FILEPRINTSETUP  206
  12. #define IDM_FILEEXIT        207
  13.  
  14. #define IDM_EDITUNDO        210
  15. #define IDM_EDITCUT         211
  16. #define IDM_EDITCOPY        212
  17. #define IDM_EDITPASTE       213
  18. #define IDM_EDITDELETE      214
  19.  
  20. #define IDM_HELPCONTENTS    215
  21. #define IDM_HELPSEARCH      216
  22. #define IDM_HELPHELP        217
  23. #define IDM_HELPABOUT       218
  24.  
  25. /* Declare WindowsProcedure */
  26. LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
  27. /* Make the classname into a global variable */
  28. char szClassName[] = "Windows Example";
  29. HINSTANCE hThisInstance;
  30.  
  31. int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  32.  
  33. {
  34.     HWND hwnd;               /* This is the handle for our window */
  35.     MSG messages;            /* Here messages to the application is saved */
  36.     WNDCLASSEX wincl;        /* Datastructure for the windowclass */
  37.     HMENU menu;              /* Handle of the menu */
  38.  
  39.     /* The Window structure */
  40.     wincl.hInstance = hThisInstance;
  41.     wincl.lpszClassName = szClassName;
  42.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  43.     wincl.style = CS_DBLCLKS;                 /* Ctach double-clicks */
  44.     wincl.cbSize = sizeof(WNDCLASSEX);
  45.  
  46.     /* Use default icon and mousepointer */
  47.     wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  48.     wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  49.     wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
  50.     wincl.lpszMenuName = NULL; /* No menu */
  51.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  52.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  53.     /* Use lightgray as the background of the window */
  54.     wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
  55.  
  56.     /* Register the window class, if fail quit the program */
  57.     if(!RegisterClassEx(&wincl)) return 0;
  58.  
  59.     /* The class is registered, lets create the program*/
  60.     hwnd = CreateWindowEx(
  61.            0,                   /* Extended possibilites for variation */
  62.            szClassName,         /* Classname */
  63.            "Windows Example",         /* Title Text */
  64.            WS_OVERLAPPEDWINDOW, /* defaultwindow */
  65.            CW_USEDEFAULT,       /* Windows decides the position */
  66.            CW_USEDEFAULT,       /* where the window end up on the screen */
  67.            544,                 /* The programs width */
  68.            375,                 /* and height in pixels */
  69.            HWND_DESKTOP,        /* The window is a childwindow to desktop */
  70.            NULL,                /* No menu */
  71.            hThisInstance,       /* Program Instance handler */
  72.            NULL                 /* No Window Creation data */
  73.            );
  74.  
  75.     /* Make the window visible on the screen */
  76.     ShowWindow(hwnd, nFunsterStil);
  77.  
  78.     menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
  79.     SetMenu(hwnd, menu);
  80.  
  81.     /* Run the nessageloop. It will run until GetMessage( ) returns 0 */
  82.     while(GetMessage(&messages, NULL, 0, 0))
  83.     {
  84.            /* Send message to WindowProcedure */
  85.            DispatchMessage(&messages);
  86.     }
  87.  
  88.     /* The program returvalue is 0 - The value that PostQuitMessage( ) gave */
  89.     return messages.wParam;
  90. }
  91.  
  92. /* This function is called by the Windowsfunction DispatchMessage( ) */
  93. LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  94. {
  95.     switch (message)                  /* handle the messages */
  96.     {
  97.        case WM_COMMAND:
  98.            switch( wParam )
  99.            {
  100.              case IDM_FILENEW:
  101.              case IDM_FILEOPEN:
  102.              case IDM_FILESAVE:
  103.              case IDM_FILESAVEAS:
  104.              case IDM_FILEPRINT:
  105.              case IDM_FILEPAGESETUP:
  106.              case IDM_FILEPRINTSETUP:
  107.  
  108.              case IDM_EDITUNDO:
  109.              case IDM_EDITCUT:
  110.              case IDM_EDITCOPY:
  111.              case IDM_EDITPASTE:
  112.              case IDM_EDITDELETE:
  113.                   MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
  114.                               (LPSTR) szClassName,
  115.                               MB_ICONINFORMATION | MB_OK );
  116.                   return 0;
  117.  
  118.              case IDM_HELPCONTENTS:
  119.                   WinHelp( hwnd, (LPSTR) "HELPFILE.HLP",
  120.                            HELP_CONTENTS, 0L );
  121.                   return 0;
  122.  
  123.              case IDM_HELPSEARCH:
  124.                   WinHelp( hwnd, (LPSTR) "HELPFILE.HLP",
  125.                            HELP_PARTIALKEY, 0L );
  126.                   return 0;
  127.  
  128.              case IDM_HELPHELP:
  129.                   WinHelp( hwnd, (LPSTR) "HELPFILE.HLP",
  130.                            HELP_HELPONHELP, 0L );
  131.                   return 0;
  132.  
  133.              case IDM_FILEEXIT:
  134.                   SendMessage( hwnd, WM_CLOSE, 0, 0L );
  135.                   return 0;
  136.  
  137.              case IDM_HELPABOUT:
  138.                   MessageBox (NULL, "About..." , "Windows example version 0.01", 1);
  139.                   return 0;
  140.  
  141.            }
  142.            break;
  143.  
  144.       case WM_CLOSE:
  145.            DestroyWindow( hwnd );
  146.            return 0;
  147.  
  148.       case WM_DESTROY:
  149.            PostQuitMessage (0);
  150.            return 0;
  151.  
  152.       break;
  153.       default:                   /* for messages that we don't deal with */
  154.       return DefWindowProc(hwnd, message, wParam, lParam);
  155.    }
  156.   return 0;
  157. }

Raw Paste


Login or Register to edit or fork this paste. It's free.