|
|
1.1 ! root 1: /******************************************************************************\ ! 2: * ! 3: * PROGRAM: SPINTEST.C ! 4: * ! 5: * PURPOSE: Demonstrates the use of the SPINCUBE custom control. ! 6: * ! 7: * FUNCTIONS: WinMain - standard stuff; also loads the ! 8: * SPINCUBE.DLL and creates a couple ! 9: * of spincube controls. ! 10: * MainWndProc - generic window procedure. ! 11: * SpintestDlgProc- generic dialog procedure. ! 12: * AboutDlgProc - processes about dialog messages ! 13: * ! 14: * Dan Knudson ! 15: * Microsoft Developer Support ! 16: * Copyright (c) 1992, 1993 Microsoft Corporation ! 17: * ! 18: \******************************************************************************/ ! 19: ! 20: #include <windows.h> ! 21: #include <stdio.h> ! 22: #include "spintest.h" ! 23: ! 24: // ! 25: // The exported variables from SPINCUBE.C. ! 26: // ! 27: // NOTE: Pointers to these vars are actually exported, ! 28: // *** NOT the variables themselves ***. ! 29: // ! 30: ! 31: extern int *giNumSpincubesThisProcess; ! 32: extern int *giNumSpincubesAllProcesses; ! 33: ! 34: ! 35: ! 36: /******************************************************************************\ ! 37: * ! 38: * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) ! 39: * ! 40: \******************************************************************************/ ! 41: ! 42: int WINAPI WinMain (HANDLE hInstance,HANDLE hPrevInstance, LPSTR lpCmdLine, ! 43: int nCmdShow) ! 44: { ! 45: WNDCLASS wc; ! 46: HWND hwnd; ! 47: MSG msg; ! 48: RECT rect; ! 49: WORD i; ! 50: ! 51: wc.style = 0; ! 52: wc.lpfnWndProc = (WNDPROC) MainWndProc; ! 53: wc.cbClsExtra = 0; ! 54: wc.cbWndExtra = 0; ! 55: wc.hInstance = hInstance; ! 56: wc.hIcon = LoadIcon (hInstance, "spintesticon"); ! 57: wc.hCursor = LoadCursor (NULL, IDC_ARROW); ! 58: wc.hbrBackground = GetStockObject (WHITE_BRUSH); ! 59: wc.lpszMenuName = (LPSTR) "Menu"; ! 60: wc.lpszClassName = (LPSTR) "Main"; ! 61: ! 62: if (!RegisterClass (&wc)) ! 63: { ! 64: MessageBox (NULL, "WinMain(): RegisterClass() failed", ! 65: "Err! - SPINTEST", MB_OK | MB_ICONEXCLAMATION); ! 66: return(FALSE); ! 67: } ! 68: ! 69: ghInst = hInstance; ! 70: if (!(hwnd = CreateWindow ("Main", "spintest Sample Application", ! 71: WS_OVERLAPPEDWINDOW, ! 72: CW_USEDEFAULT, CW_USEDEFAULT, ! 73: CW_USEDEFAULT, CW_USEDEFAULT, ! 74: NULL, NULL, ghInst, NULL))) ! 75: return 0; ! 76: ! 77: ! 78: // ! 79: // Create a couple of SpinCube custom controls, we'll size them later in ! 80: // the WM_SIZE message handler ! 81: // ! 82: ! 83: for (i = 0; i < 4; i++) ! 84: ! 85: gahwndSpin[i] = CreateWindow ("Spincube", "", ! 86: WS_VISIBLE | WS_CHILD | ! 87: SS_INMOTION | SS_ERASE, ! 88: 0, 0, 0, 0, hwnd, NULL, NULL, NULL); ! 89: ! 90: ! 91: // ! 92: // Delete the SS_ERASE to the 1st & 4th controls so we get the ! 93: // trailing cubes effect. ! 94: // ! 95: ! 96: SetWindowLong (gahwndSpin[0], GWL_STYLE, ! 97: GetWindowLong (gahwndSpin[0], GWL_STYLE) & ~ SS_ERASE); ! 98: SetWindowLong (gahwndSpin[3], GWL_STYLE, ! 99: GetWindowLong (gahwndSpin[3], GWL_STYLE) & ~ SS_ERASE); ! 100: ! 101: ! 102: // ! 103: // Send ourself a WM_SIZE so the controls will get sized appropriately ! 104: // ! 105: ! 106: GetClientRect (hwnd, &rect); ! 107: SendMessage (hwnd, WM_SIZE, 0, ! 108: MAKELONG((WORD)rect.right,(WORD)rect.bottom)); ! 109: ! 110: ShowWindow (hwnd, nCmdShow); ! 111: ! 112: while (GetMessage (&msg, NULL, 0, 0)) ! 113: { ! 114: TranslateMessage (&msg); ! 115: DispatchMessage (&msg); ! 116: } ! 117: ! 118: return (msg.wParam); ! 119: } ! 120: ! 121: ! 122: ! 123: /******************************************************************************\ ! 124: * ! 125: * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) ! 126: * ! 127: \******************************************************************************/ ! 128: ! 129: LRESULT CALLBACK MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ! 130: { ! 131: switch (msg) ! 132: { ! 133: case WM_COMMAND: ! 134: ! 135: switch (LOWORD(wParam)) ! 136: { ! 137: case IDM_DLGEDITDIALOG: ! 138: ! 139: DialogBox (ghInst, (LPCTSTR) "SpintestDlg", hwnd, (DLGPROC) DlgProc); ! 140: break; ! 141: ! 142: case IDM_SPINTESTSTATS: ! 143: ! 144: DialogBox (ghInst, (LPCTSTR) "Stats", hwnd, (DLGPROC) DlgProc); ! 145: break; ! 146: ! 147: case IDM_ABOUT: ! 148: ! 149: DialogBox (ghInst, (LPCTSTR)"About", hwnd, (DLGPROC) DlgProc); ! 150: break; ! 151: ! 152: } ! 153: break; ! 154: ! 155: case WM_SIZE: ! 156: { ! 157: // ! 158: // Resize the controls such that each cover half the client area ! 159: // (plus a little border). ! 160: // ! 161: ! 162: int width = (int) LOWORD(lParam); ! 163: int height = (int) HIWORD(lParam); ! 164: ! 165: SetWindowPos (gahwndSpin[0], NULL, ! 166: BORDER, BORDER, ! 167: width/2 - BORDER, height/2 - BORDER, ! 168: SWP_SHOWWINDOW); ! 169: SetWindowPos (gahwndSpin[1], NULL, ! 170: width/2 + BORDER, BORDER, ! 171: width/2 - 2*BORDER, height/2 - BORDER, ! 172: SWP_SHOWWINDOW); ! 173: SetWindowPos (gahwndSpin[2], NULL, ! 174: BORDER, height/2 + BORDER, ! 175: width/2 - BORDER, height/2 - 2*BORDER, ! 176: SWP_SHOWWINDOW); ! 177: SetWindowPos (gahwndSpin[3], NULL, ! 178: width/2 + BORDER, height/2 + BORDER, ! 179: width/2 - 2*BORDER, height/2 - 2*BORDER, ! 180: SWP_SHOWWINDOW); ! 181: break; ! 182: } ! 183: ! 184: case WM_DESTROY: ! 185: ! 186: PostQuitMessage (0); ! 187: break; ! 188: ! 189: default: ! 190: ! 191: return (DefWindowProc (hwnd, msg, wParam, lParam)); ! 192: } ! 193: return 0; ! 194: } ! 195: ! 196: ! 197: ! 198: /******************************************************************************\ ! 199: * ! 200: * FUNCTION: DlgProc (standard dialog procedure INPUTS/RETURNS) ! 201: * ! 202: * COMMENTS: Our common dlg proc (why have 3 that do the same thing???) ! 203: * ! 204: \******************************************************************************/ ! 205: ! 206: LRESULT CALLBACK DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ! 207: { ! 208: switch (message) ! 209: { ! 210: case WM_INITDIALOG: ! 211: ! 212: // ! 213: // If this dlg the "Stats" dlg fill in the appropriate fields. ! 214: // If not these calls will just fail. ! 215: // ! 216: // If the references to the giNum* vars are commented out & ! 217: // the program gets rebuilt don't be surprised if no spincubes ! 218: // appear- since no references to spincube.lib the linker will ! 219: // infer that it is not needed, & will not cause it to get ! 220: // loaded. You'll need to make a call to LoadLibrary ("SPINCUBE.DLL") ! 221: // prior to calling CreateWindow ("SPINCUBE"...). ! 222: // ! 223: ! 224: SetDlgItemInt (hwnd, 500, *giNumSpincubesThisProcess, TRUE); ! 225: SetDlgItemInt (hwnd, 501, *giNumSpincubesAllProcesses, TRUE); ! 226: return (TRUE); ! 227: ! 228: case WM_COMMAND: ! 229: ! 230: if (LOWORD(wParam) == IDOK) ! 231: ! 232: EndDialog (hwnd, TRUE); ! 233: ! 234: return (TRUE); ! 235: } ! 236: return (FALSE); ! 237: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.