home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / BPASCAL.700 / D12 / WINDEMOS.ZIP / WPOPUP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-01  |  5.4 KB  |  175 lines

  1. {************************************************}
  2. {                                                }
  3. {   Demo Program                                 }
  4. {   Copyright (c) 1991 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. program WPopUp;
  9.  
  10. { This is a small example of creating child and pop up windows with out }
  11. { using the class 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.  
  27.   begin
  28.     case iMessage of
  29.       WM_Paint: 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: begin
  55.                     if Wnd=PopUp then
  56.               EnableMenuItem(GetMenu(Parent), 101, MF_Enabled)
  57.                     else if Wnd=PopUpNo then
  58.                           EnableMenuItem(GetMenu(Parent), 102, MF_Enabled)
  59.                     else if Wnd=Child then
  60.               EnableMenuItem(GetMenu(Parent), 103, MF_Enabled);
  61.                   end;
  62.     else
  63.       Window1:=DefWindowProc(Wnd, iMessage, wParam, lParam);
  64.     end;
  65.   end;
  66.  
  67. procedure Register(P: Pointer; Name: PChar; Menu: PChar);
  68.   var
  69.     WndClas: TWndClass;
  70.   begin
  71.     if hPrevInst <> 0 then
  72.       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. function AboutProc(Dlg: hWnd; iMessage, wParam: Word; lParam: LongInt): Bool; Export;
  119.   begin
  120.     AboutProc:=false;
  121.     case iMessage of
  122.       WM_Create: AboutProc:=true;
  123.       WM_Command: if (wParam = IDOK) or (wParam = IDCancel) then
  124.             begin
  125.               AboutProc:=true;
  126.               EndDialog(Dlg, 0);
  127.             end;
  128.     end;
  129.   end;
  130.  
  131. function WindowSetup(Wnd: hWnd; iMessage, wParam:Word; lParam: LongInt): LongInt; export;
  132.   var
  133.     DC: hDC;
  134.     ProcInst: Pointer;
  135.   begin
  136.     case iMessage of
  137.       WM_Command: Case wParam of
  138.             101:begin
  139.               PopUp:=Create('PopUp With Parent', WS_PopUp or WS_OverLappedWindow, 40, 60, 300, 150, Parent);
  140.               InvalidateWindow(PopUp);
  141.               EnableMenuItem(GetMenu(Wnd), 101, MF_Grayed);
  142.             end;
  143.             102:begin
  144.               PopUpNo:=Create('PopUp No Parent', WS_PopUp or WS_OverLappedWindow, 60, 80, 300, 150, 0);
  145.               InvalidateWindow(PopUpNo);
  146.               EnableMenuItem(GetMenu(Wnd), 102, MF_Grayed);
  147.             end;
  148.             103:begin
  149.               Child:=Create('Child Window', WS_Child or WS_OverLappedWindow, 20, 0, 300, 100, Parent);
  150.               InvalidateWindow(Child);
  151.               EnableMenuItem(GetMenu(Wnd), 103, MF_Grayed);
  152.             end;
  153.             104: begin
  154.                ProcInst:=MakeProcInstance(@AboutProc, hInstance);
  155.                DialogBox(hInstance, 'About', Wnd, ProcInst);
  156.                FreeProcInstance(ProcInst);
  157.              end;
  158.           else
  159.             WindowSetUp:=DefWindowProc(Wnd, iMessage, wParam, lParam);
  160.           end;
  161.       WM_Destroy:   PostQuitMessage(0);
  162.     else
  163.       WindowSetUp:=DefWindowProc(Wnd, iMessage, wParam, lParam);
  164.     end;
  165.   end;
  166.  
  167. begin
  168.   Register(@WindowSetUp, 'Parent Window', 'Menu');
  169.   Parent:=Create('Parent Window', WS_OverLappedWindow, 0, 0, 400, 200, 0);
  170.   Register(@Window1, 'Child Window', '');
  171.   Register(@Window1, 'PopUp No Parent', '');
  172.   Register(@Window1, 'PopUp With Parent', '');
  173.   Loop;
  174. end.
  175.