home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WINDEMOS.ZIP / WPOPUP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  5.2 KB  |  182 lines

  1. {************************************************}
  2. {                                                }
  3. {   Demo Program                                 }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program WPopUp;
  9.  
  10. { This is a small example of creating child and pop up windows without  }
  11. { using the ObjectWindows library.                                      }
  12.  
  13. {$R WPopUp}
  14.  
  15. uses WinTypes, WinProcs, Strings;
  16.  
  17. var
  18.   Parent, PopUp, PopUpNo, Child: hWnd;
  19.  
  20. function Window1(Wnd: hWnd; iMessage, wParam: Word; lParam: LongInt): LongInt; export;
  21. var
  22.   PaintStruct: TPaintStruct;
  23.   DC: hDC;
  24.   S: String;
  25.   R: TRect;
  26. begin
  27.   case iMessage of
  28.     WM_Paint:
  29.       begin
  30.     DC:=BeginPaint(Wnd, PaintStruct);
  31.     S:='';
  32.     if Wnd = PopUp then
  33.       S := 'PopUp windows can be moved outside the Parent Window. '+
  34.       'A PopUp with a Parent will always stay on top even when the '+
  35.       'focus is put on the underlying Parent Window.  Try this '+
  36.       'by clicking on the Parent Window.  When Minimized, PopUp '+
  37.       'icons reside on the desktop.'
  38.     else if Wnd = PopUpNo then
  39.       S := 'PopUp windows can be moved outside the Parent Window. '+
  40.       'A PopUp with no Parent allows the focused Parent window to be '+
  41.       'brought to the front (Try this by clicking on the Parent '+
  42.       'Window).  When Minimized, PopUp icons reside on the desktop.'
  43.     else if Wnd = Child then
  44.       S := 'Child Window always lives within the Parent Window.  It cannot '+
  45.       'be moved outside the Parent Window.  When Minimized, the icon '+
  46.       'also resides within the Parent Window.';
  47.     if Length(S) <> 0 then
  48.     begin
  49.       GetClientRect(Wnd, R);
  50.       DrawText(DC, @S[1], Length(S), R, DT_WordBreak);
  51.     end;
  52.     EndPaint(Wnd, PaintStruct);
  53.       end;
  54.       WM_Destroy:
  55.         begin
  56.           if Wnd = PopUp then
  57.         EnableMenuItem(GetMenu(Parent), 101, MF_Enabled)
  58.           else if Wnd = PopUpNo then
  59.             EnableMenuItem(GetMenu(Parent), 102, MF_Enabled)
  60.           else if Wnd = Child then
  61.         EnableMenuItem(GetMenu(Parent), 103, MF_Enabled);
  62.         end;
  63.     else
  64.       Window1 := DefWindowProc(Wnd, iMessage, wParam, lParam);
  65.   end;
  66. end;
  67.  
  68. procedure Register(P: Pointer; Name: PChar; Menu: PChar);
  69. var
  70.   WndClas: TWndClass;
  71. begin
  72.   if hPrevInst <> 0 then Exit;
  73.   WndClas.Style := CS_HReDraw or CS_VReDraw;
  74.   WndClas.lpfnWndProc:= P;
  75.   WndClas.cbClsExtra := 0;
  76.   WndClas.cbWndExtra := 0;
  77.   WndClas.hInstance := HInstance;
  78.   WndClas.hIcon := LoadIcon(0, Idi_Application);
  79.   WndClas.hCursor := LoadCursor(0, Idc_Arrow);
  80.   WndClas.hbrBackground := GetStockObject(White_Brush);
  81.   WndClas.lpszMenuName := Menu;
  82.   WndClas.lpszClassName := Name;
  83.   if not RegisterClass(WndClas) then
  84.   begin
  85.     MessageBox(GetFocus, 'Can not Register Class', 'Error ', MB_OK);
  86.     Halt;
  87.   end;
  88. end;
  89.  
  90. function Create(Name: PChar; Style: Longint; X1,Y1,X2,Y2: Integer; Parent: Word): Word;
  91. var
  92.   Wnd: Word;
  93. begin
  94.   Wnd := CreateWindow(Name, Name, Style, X1, Y1, X2, Y2, Parent, 0, hInstance, nil);
  95.   ShowWindow(Wnd, SW_ShowNormal);
  96.   UpDateWindow(Wnd);
  97.   Create := Wnd;
  98. end;
  99.  
  100. procedure Loop;
  101. var
  102.   Msg: TMsg;
  103. begin
  104.   while GetMessage(Msg, 0, 0, 0) do
  105.   begin
  106.     TranslateMessage(msg);
  107.     DispatchMessage(msg);
  108.   end;
  109. end;
  110.  
  111. procedure InvalidateWindow(Wnd: hWnd);
  112. var
  113.   R: TRect;
  114. begin
  115.   GetClientRect(Wnd, R);
  116.   InvalidateRect(Wnd, @R, false);
  117. end;
  118.  
  119. function AboutProc(Dlg: hWnd; iMessage, wParam: Word; lParam: LongInt): Bool; Export;
  120. begin
  121.   AboutProc:=false;
  122.   case iMessage of
  123.     WM_Create: AboutProc := True;
  124.     WM_Command:
  125.       if (wParam = IDOK) or (wParam = IDCancel) then
  126.       begin
  127.     AboutProc := True;
  128.     EndDialog(Dlg, 0);
  129.       end;
  130.   end;
  131. end;
  132.  
  133. function WindowSetup(Wnd: hWnd; iMessage, wParam:Word; lParam: LongInt): LongInt; export;
  134. var
  135.   ProcInst: Pointer;
  136. begin
  137.   case iMessage of
  138.     WM_Command:
  139.       case wParam of
  140.         101:
  141.           begin
  142.         PopUp := Create('PopUp With Parent', WS_PopUp or WS_OverLappedWindow, 40, 60, 300, 150, Parent);
  143.         InvalidateWindow(PopUp);
  144.         EnableMenuItem(GetMenu(Wnd), 101, MF_Grayed);
  145.       end;
  146.     102:
  147.           begin
  148.         PopUpNo := Create('PopUp No Parent', WS_PopUp or WS_OverLappedWindow, 60, 80, 300, 150, 0);
  149.         InvalidateWindow(PopUpNo);
  150.         EnableMenuItem(GetMenu(Wnd), 102, MF_Grayed);
  151.       end;
  152.     103:
  153.           begin
  154.         Child := Create('Child Window', WS_Child or WS_OverLappedWindow, 20, 0, 300, 100, Parent);
  155.         InvalidateWindow(Child);
  156.         EnableMenuItem(GetMenu(Wnd), 103, MF_Grayed);
  157.       end;
  158.     104:
  159.           begin
  160.         ProcInst := MakeProcInstance(@AboutProc, hInstance);
  161.         DialogBox(hInstance, 'About', Wnd, ProcInst);
  162.         FreeProcInstance(ProcInst);
  163.       end;
  164.     else
  165.       WindowSetUp:=DefWindowProc(Wnd, iMessage, wParam, lParam);
  166.       end;
  167.     WM_Destroy:
  168.       PostQuitMessage(0);
  169.   else
  170.     WindowSetUp := DefWindowProc(Wnd, iMessage, wParam, lParam);
  171.   end;
  172. end;
  173.  
  174. begin
  175.   Register(@WindowSetUp, 'Parent Window', 'Menu');
  176.   Parent:=Create('Parent Window', WS_OverLappedWindow, 0, 0, 400, 200, 0);
  177.   Register(@Window1, 'Child Window', '');
  178.   Register(@Window1, 'PopUp No Parent', '');
  179.   Register(@Window1, 'PopUp With Parent', '');
  180.   Loop;
  181. end.
  182.