|
|
1.1 root 1: /*-----------------------------------------------------------
2: WELCOME3.C -- Creates a Top-Level Window and Two Children
3: -----------------------------------------------------------*/
4:
5: #define INCL_WIN
6: #include <os2.h>
7:
8: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
9: MRESULT EXPENTRY ChildWndProc (HWND, USHORT, MPARAM, MPARAM) ;
10:
11: int main (void)
12: {
1.1.1.2 ! root 13: static CHAR szClientClass [] = "Welcome3",
! 14: szChildClass [] = "Welcome3.Child" ;
! 15: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
! 16: FCF_SIZEBORDER | FCF_MINMAX |
! 17: FCF_SHELLPOSITION | FCF_TASKLIST ;
! 18: HAB hab ;
! 19: HMQ hmq ;
! 20: HWND hwndFrame, hwndChildFrame1, hwndChildFrame2,
! 21: hwndClient, hwndChildClient1, hwndChildClient2 ;
! 22: QMSG qmsg ;
1.1 root 23:
24: hab = WinInitialize (0) ;
25: hmq = WinCreateMsgQueue (hab, 0) ;
26:
27: WinRegisterClass (
1.1.1.2 ! root 28: hab, // Anchor block handle
! 29: szClientClass, // Name of class being registered
! 30: ClientWndProc, // Window procedure for class
! 31: CS_SIZEREDRAW, // Class style
! 32: 0) ; // Extra bytes to reserve
1.1 root 33:
34: WinRegisterClass (
1.1.1.2 ! root 35: hab, // Anchor block handle
! 36: szChildClass, // Name of class being registered
! 37: ChildWndProc, // Window procedure for class
! 38: CS_SIZEREDRAW, // Class style
! 39: sizeof (PVOID)) ; // Extra bytes to reserve
1.1 root 40:
41: /*-------------------------
42: Create top-level window
43: -------------------------*/
44:
45: hwndFrame = WinCreateStdWindow (
1.1.1.2 ! root 46: HWND_DESKTOP, // Parent window handle
! 47: WS_VISIBLE, // Style of frame window
! 48: &flFrameFlags, // Pointer to control data
! 49: szClientClass, // Client window class name
! 50: NULL, // Title bar text
! 51: 0L, // Style of client window
! 52: NULL, // Module handle for resources
! 53: 0, // ID of resources
! 54: &hwndClient) ; // Pointer to client window handle
! 55:
! 56: WinSendMsg (hwndFrame, WM_SETICON,
! 57: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
! 58: NULL) ;
1.1 root 59:
60: /*--------------------------
61: Create two child windows
62: --------------------------*/
63:
1.1.1.2 ! root 64: flFrameFlags &= ~FCF_TASKLIST ;
! 65:
1.1 root 66: hwndChildFrame1 = WinCreateStdWindow (
1.1.1.2 ! root 67: hwndClient, // Parent window handle
! 68: WS_VISIBLE, // Style of frame window
! 69: &flFrameFlags, // Pointer to control data
! 70: szChildClass, // Client window class name
! 71: "Child No. 1", // Title bar text
! 72: 0L, // Style of client window
! 73: NULL, // Module handle for resources
! 74: 0, // ID of resources
! 75: &hwndChildClient1) ;// Pointer to client window handle
1.1 root 76:
77: hwndChildFrame2 = WinCreateStdWindow (
1.1.1.2 ! root 78: hwndClient, // Parent window handle
! 79: WS_VISIBLE, // Style of frame window
! 80: &flFrameFlags, // Pointer to control data
! 81: szChildClass, // Client window class name
! 82: "Child No. 2", // Title bar text
! 83: 0L, // Style of client window
! 84: NULL, // Module handle for resources
! 85: 0, // ID of resources
! 86: &hwndChildClient2) ;// Pointer to client window handle
! 87:
! 88: WinSendMsg (hwndChildFrame1, WM_SETICON,
! 89: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
! 90: NULL) ;
! 91:
! 92: WinSendMsg (hwndChildFrame2, WM_SETICON,
! 93: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
! 94: NULL) ;
1.1 root 95:
96: /*-----------------------------------------------------
97: Set reserved area of window to text string pointers
98: -----------------------------------------------------*/
99:
100: WinSetWindowPtr (hwndChildClient1, QWL_USER, "I'm a child ...") ;
101: WinSetWindowPtr (hwndChildClient2, QWL_USER, "... Me too!") ;
102:
103: while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
104: WinDispatchMsg (hab, &qmsg) ;
105:
106: WinDestroyWindow (hwndFrame) ;
107: WinDestroyMsgQueue (hmq) ;
108: WinTerminate (hab) ;
109: return 0 ;
110: }
111:
112: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
113: {
114: static CHAR szText [] = "I'm the parent of two children" ;
115: HPS hps ;
116: RECTL rcl ;
117:
118: switch (msg)
119: {
120: case WM_PAINT:
121: hps = WinBeginPaint (hwnd, NULL, NULL) ;
122:
123: WinQueryWindowRect (hwnd, &rcl) ;
124:
1.1.1.2 ! root 125: WinDrawText (hps, -1, szText, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
1.1 root 126: DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
127:
128: WinEndPaint (hps) ;
129: return 0 ;
130: }
131: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
132: }
133:
134: MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
135: {
1.1.1.2 ! root 136: HPS hps ;
! 137: RECTL rcl ;
1.1 root 138:
139: switch (msg)
140: {
141: case WM_PAINT:
142: hps = WinBeginPaint (hwnd, NULL, NULL) ;
143:
144: WinQueryWindowRect (hwnd, &rcl) ;
145:
146: WinDrawText (hps, -1, WinQueryWindowPtr (hwnd, QWL_USER), &rcl,
147: CLR_NEUTRAL, CLR_BACKGROUND,
148: DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
149:
150: WinEndPaint (hps) ;
151: return 0 ;
152:
153: case WM_CLOSE:
154: WinDestroyWindow (WinQueryWindow (hwnd, QW_PARENT, FALSE)) ;
155: return 0 ;
156: }
157: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
158: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.