Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Event Constants */
  2. #define REDRAW_EVENT 1
  3. #define KEY_EVENT    2
  4. #define BUTTON_EVENT 3
  5.  
  6. /* Window Style Constants */
  7. #define WS_SKINNED_FIXED 0x4000000
  8. #define WS_COORD_CLIENT  0x20000000
  9. #define WS_CAPTION       0x10000000
  10.  
  11. /* Caption Style Constants */
  12. #define CS_MOVABLE 0
  13.  
  14. /* Charset specifiers for DrawText */
  15. #define DT_CP866_8X16 0x10000000
  16.  
  17. /* Fill styles for DrawText */
  18. #define DT_FILL_OPAQUE 0x40000000
  19.  
  20. /* Draw zero terminated string for DrawText */
  21. #define DT_ZSTRING 0x80000000
  22.  
  23. /* Button identifiesrs */
  24. #define BUTTON_CLOSE 1
  25.  
  26. /* Key code values */
  27. #define KEY_CODE_ENTER 13
  28.  
  29. #pragma pack(1)
  30.  
  31. struct TButtonInput{
  32.   union{
  33.     struct{
  34.       unsigned char MouseButton;
  35.       unsigned short ID;
  36.       unsigned char HiID;
  37.     };
  38.     unsigned long Value;
  39.   };
  40. };
  41.  
  42. struct TKeyboardInput{
  43.   union{
  44.     struct{
  45.       unsigned char Flag;
  46.       char Code;
  47.       union{
  48.         char Scan;
  49.         unsigned short Control;
  50.       };
  51.     };
  52.     unsigned long Value;
  53.   };
  54. };
  55.  
  56. struct TSize{
  57.   union{
  58.     struct{
  59.       unsigned short Height;
  60.       unsigned short Width;
  61.     };
  62.     unsigned long Value;
  63.   };
  64. };
  65.  
  66. struct TRect{
  67.   long Left;
  68.   long Top;
  69.   long Right;
  70.   long Bottom;
  71. };
  72.  
  73. extern struct TButtonInput   __stdcall GetButton(void);
  74. extern struct TKeyboardInput __stdcall GetKey(void);
  75. extern struct TSize          __stdcall GetScreenSize(void);
  76. extern unsigned long         __stdcall WaitEvent(void);
  77. extern void                  __stdcall BeginDraw(void);
  78. extern void                  __stdcall EndDraw(void);
  79. extern void                  __stdcall ThreadTerminate(void);
  80. extern void                  __stdcall DrawWindow(long          Left,
  81.                                                   long          Top,
  82.                                                   long          Right,
  83.                                                   long          Bottom,
  84.                                                   char*         Caption,
  85.                                                   unsigned long BackColor,
  86.                                                   unsigned long Style,
  87.                                                   unsigned long CapStyle);
  88. extern void                  __stdcall DrawText(long X,
  89.                                                 long Y,
  90.                                                 char* Text,
  91.                                                 unsigned long ForeColor,
  92.                                                 unsigned long BackColor,
  93.                                                 unsigned long Flags,
  94.                                                 unsigned long Count);
  95.  
  96. struct TSize Screen;
  97. struct TRect Window;
  98.  
  99. void Main(){
  100.   Screen = GetScreenSize();
  101.   Window.Right  = Screen.Width / 3;
  102.   Window.Bottom = Screen.Height / 3;
  103.   Window.Left   = (Screen.Width  - Window.Right)  / 2;
  104.   Window.Top    = (Screen.Height - Window.Bottom) / 2;
  105.   while(1){
  106.     switch (WaitEvent()){
  107.     case BUTTON_EVENT:
  108.       if (GetButton().ID == BUTTON_CLOSE) ThreadTerminate();
  109.       break;
  110.     case KEY_EVENT:
  111.       if (GetKey().Code == KEY_CODE_ENTER) ThreadTerminate();
  112.       break;
  113.     case REDRAW_EVENT:
  114.       BeginDraw();
  115.       DrawWindow(Window.Right, Window.Bottom, Window.Left, Window.Top, "C with KolibriOS.lib", 0x00C0DDEE, WS_SKINNED_FIXED | WS_COORD_CLIENT | WS_CAPTION, CS_MOVABLE);
  116.       DrawText( 8, 25, "Press Enter to quit", 0, 0x00FFFFFF, DT_CP866_8X16 | DT_FILL_OPAQUE | DT_ZSTRING, 0);
  117.       EndDraw();
  118.       break;
  119.     }
  120.   }
  121. }
  122.