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