|
|
1.1 ! root 1: /*----------------------------------------- ! 2: BUTTONS1.C -- Push Button Demonstration ! 3: -----------------------------------------*/ ! 4: ! 5: #define INCL_WIN ! 6: #define INCL_GPI ! 7: #include <os2.h> ! 8: ! 9: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ; ! 10: ! 11: int main (void) ! 12: { ! 13: static CHAR szClientClass[] = "Buttons1" ; ! 14: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | ! 15: FCF_SIZEBORDER | FCF_MINMAX | ! 16: FCF_SHELLPOSITION | FCF_TASKLIST ; ! 17: HAB hab ; ! 18: HMQ hmq ; ! 19: HWND hwndFrame, hwndClient ; ! 20: QMSG qmsg ; ! 21: ! 22: hab = WinInitialize (0) ; ! 23: hmq = WinCreateMsgQueue (hab, 0) ; ! 24: ! 25: WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ; ! 26: ! 27: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE, ! 28: &flFrameFlags, szClientClass, NULL, ! 29: 0L, NULL, 0, &hwndClient) ; ! 30: ! 31: WinSendMsg (hwndFrame, WM_SETICON, ! 32: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE), ! 33: NULL) ; ! 34: ! 35: while (WinGetMsg (hab, &qmsg, NULL, 0, 0)) ! 36: WinDispatchMsg (hab, &qmsg) ; ! 37: ! 38: WinDestroyWindow (hwndFrame) ; ! 39: WinDestroyMsgQueue (hmq) ; ! 40: WinTerminate (hab) ; ! 41: return 0 ; ! 42: } ! 43: ! 44: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2) ! 45: { ! 46: static CHAR *szButtonLabel[] = { "Smaller", "Larger" } ; ! 47: static HWND hwndFrame, hwndButton[2] ; ! 48: static SHORT cxClient, cyClient, cxChar, cyChar ; ! 49: FONTMETRICS fm ; ! 50: HPS hps ; ! 51: SHORT id ; ! 52: RECTL rcl ; ! 53: ! 54: switch (msg) ! 55: { ! 56: case WM_CREATE : ! 57: hwndFrame = WinQueryWindow (hwnd, QW_PARENT, FALSE) ; ! 58: ! 59: hps = WinGetPS (hwnd) ; ! 60: GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ; ! 61: cxChar = (SHORT) fm.lAveCharWidth ; ! 62: cyChar = (SHORT) fm.lMaxBaselineExt ; ! 63: WinReleasePS (hps) ; ! 64: ! 65: for (id = 0 ; id < 2 ; id++) ! 66: hwndButton[id] = WinCreateWindow ( ! 67: hwnd, // Parent ! 68: WC_BUTTON, // Class ! 69: szButtonLabel[id], // Text ! 70: WS_VISIBLE | // Style ! 71: BS_PUSHBUTTON, ! 72: 0, 0, // Position ! 73: 12 * cxChar, // Width ! 74: 2 * cyChar, // Height ! 75: hwnd, // Owner ! 76: HWND_BOTTOM, // Placement ! 77: id, // ID ! 78: NULL, // Ctrl Data ! 79: NULL) ; // Pres Params ! 80: return 0 ; ! 81: ! 82: case WM_SIZE : ! 83: cxClient = SHORT1FROMMP (mp2) ; ! 84: cyClient = SHORT2FROMMP (mp2) ; ! 85: ! 86: for (id = 0 ; id < 2 ; id++) ! 87: WinSetWindowPos (hwndButton[id], NULL, ! 88: cxClient / 2 + (14 * id - 13) * cxChar, ! 89: (cyClient - 2 * cyChar) / 2, ! 90: 0, 0, SWP_MOVE) ; ! 91: return 0 ; ! 92: ! 93: case WM_COMMAND: ! 94: WinQueryWindowRect (hwnd, &rcl) ; ! 95: WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2) ; ! 96: ! 97: switch (COMMANDMSG(&msg)->cmd) // Child ID ! 98: { ! 99: case 0: // "Smaller" ! 100: rcl.xLeft += cxClient / 20 ; ! 101: rcl.xRight -= cxClient / 20 ; ! 102: rcl.yBottom += cyClient / 20 ; ! 103: rcl.yTop -= cyClient / 20 ; ! 104: break ; ! 105: ! 106: case 1: // "Larger" ! 107: rcl.xLeft -= cxClient / 20 ; ! 108: rcl.xRight += cxClient / 20 ; ! 109: rcl.yBottom -= cyClient / 20 ; ! 110: rcl.yTop += cyClient / 20 ; ! 111: break ; ! 112: } ! 113: WinCalcFrameRect (hwndFrame, &rcl, FALSE) ; ! 114: ! 115: WinSetWindowPos (hwndFrame, NULL, ! 116: (SHORT) rcl.xLeft, (SHORT) rcl.yBottom, ! 117: (SHORT) rcl.xRight - (SHORT) rcl.xLeft, ! 118: (SHORT) rcl.yTop - (SHORT) rcl.yBottom, ! 119: SWP_MOVE | SWP_SIZE) ; ! 120: return 0 ; ! 121: ! 122: case WM_ERASEBACKGROUND: ! 123: return 1 ; ! 124: } ! 125: return WinDefWindowProc (hwnd, msg, mp1, mp2) ; ! 126: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.