1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340:
| /*----------------------------------------------- PCMCIASample Programm zur Demonstration der Programmierung des SOUNDLIGHT USB->DMX Interfaces für Windows
Ansi C ohne Ressourcen-Einbindung -----------------------------------------------*/ #include <windows.h> #include <stdio.h>
#define DHC_OPEN 1 #define DHC_DMXOUT 4 #define DHC_CLOSE 2 // // Callback-Funktinonen deklarieren // // Windows-Prozedur // Prozedur, die die Ausführung der Kommandos der Scrollbars übernimmt // LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; LRESULT CALLBACK ScrollProc (HWND, UINT, WPARAM, LPARAM) ;
int idFocus ; WNDPROC OldScroll[6] ;
// //Jetzt wird's DMX'ig // char dmx_level[511];
// // Das ist für die DLL-Importierung // int (APIENTRY *pfnDasHardCommand) (int, int, unsigned char *); HMODULE dllHandle;
// // und los geht's // int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "USBSample" ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ;
wndclass.style = 0 ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = CreateSolidBrush (0) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; int interface_open;//Für die Initialisierung des Adapters
// //Fensterklasse anmelden // if (!RegisterClass (&wndclass)) { MessageBox (NULL, "Programm nicht startbar", szAppName, MB_ICONERROR) ; return 0 ; }
// //Handle des Fensters ermitteln, Eigenschaften des Fensters definieren //Das Fenster hat ein "Schliessen-Feld (sysmenu) ist aber nicht skalierbar(border) // hwnd = CreateWindow (szAppName, "USB2DMXSample", WS_SYSMENU |WS_BORDER , CW_USEDEFAULT, CW_USEDEFAULT, 230, 450, NULL, NULL, hInstance, NULL) ;
// //DLL-Funktion importieren WICHTIG! In der DLL ist die Funktion, die die Kommunikation mit dem Adapter regelt! // dllHandle = LoadLibrary("dashard.dll");
if (dllHandle == NULL) { MessageBox (hwnd, "dashard.dll konnte nicht gefunden werden.", "Fehler", 0) ; exit (0); }
pfnDasHardCommand = (int (APIENTRY *)(int, int, unsigned char *)) GetProcAddress (dllHandle, "DasHardCommand"); if (pfnDasHardCommand == NULL) { MessageBox (hwnd, "Falsche DLL?", "Fehler", 0) ; exit (0); }
// // Testen, ob DMX-Adapter da, wenn ja: initialisieren des Adapters, wenn nein:exit // interface_open = pfnDasHardCommand(DHC_OPEN, 0, 0); if (interface_open <= 0) { MessageBox (hwnd, "Kein Adapter gefunden, Programm wird abgebrochen", "Achtung", 0) ; exit (0); }
// //Fenster darstellen // ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ;
// //Messages verwalten // while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
static HWND hwndScroll[6], hwndLabel[6], hwndValue[6], hwndRect, hwndC; static int intensity[6], cyChar ; // In intensity [] wird der Helligkeitswert eines Reglers abgelegt, allerdings "verkehrt herrum": 0=hell static char * szTextLabel[] = { "1", "2", "3", "4", "5", "6"} ; HINSTANCE hInstance ; int i, cxClient, cyClient ; char szBuffer[10] ;
switch (message) {
// // Hier wird die Bedienoberfläche vorbereitet // case WM_CREATE :
hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;
// Ein weißes Rechteck als Hintergrund für die Bildlaufleisten; // die ID dieses Child-Fensters ist 18. hwndRect = CreateWindow ("static", NULL, WS_CHILD | WS_VISIBLE | SS_WHITERECT, 0, 0, 0, 0, hwnd, (HMENU) 18, hInstance, NULL) ;
// Ein (c) -Vermerk, ID 19 hwndC = CreateWindow ("static", "(c) 2002 S. Ahrens", WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 0, 0, hwnd, (HMENU) 19, hInstance, NULL) ;
for (i = 0 ; i < 6 ; i++) {
// Die sechs Bildlaufleisten mit IDs von 0 bis 5 und einem Bereich von 0 bis 255 hwndScroll[i] = CreateWindow ("scrollbar", NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | SBS_VERT, 0, 0, 0, 0, hwnd, (HMENU) i, hInstance, NULL) ;
SetScrollRange (hwndScroll[i], SB_CTL, 0, 255, FALSE) ; // Position 255 heisst: ganz unten, also "gefühltes Null" SetScrollPos (hwndScroll[i], SB_CTL, 255, FALSE) ;
intensity[i]=255;
// Sechs Beschriftungen dazu (IDs 6 - 11) mit den Texten // "1", "2", "3"... hwndLabel [i] = CreateWindow ("static", szTextLabel[i], WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 0, 0, hwnd, (HMENU) (i + 6), hInstance, NULL) ;
// Drei statische Textfelder (IDs 12 - 17) für die Positionen // der Bildlaufleisten; Startwert ist in allen drei Fällen "0" hwndValue [i] = CreateWindow ("static", "0", WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, 0, 0, hwnd, (HMENU) (i + 12), hInstance, NULL) ;
OldScroll[i] = (WNDPROC) SetWindowLong (hwndScroll[i], GWL_WNDPROC, (LONG) ScrollProc) ; }
cyChar = HIWORD (GetDialogBaseUnits ()) ;
return 0 ;
case WM_SIZE :
cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ;
// // Alle Bedienelemente positionieren und darstellen // MoveWindow (hwndRect, 0, 0, cxClient, cyClient, TRUE) ; MoveWindow (hwndC, 10,cyClient-23,cxClient - 20, 20, TRUE);
for (i = 0 ; i < 6 ; i++) { MoveWindow (hwndScroll[i], ((2 * i + 1) * cxClient / 14) + 8, 2 * cyChar +10, cxClient / 14, (cyClient - 4 * cyChar) -30, TRUE) ;
MoveWindow (hwndLabel[i], ((4 * i + 2) * cxClient / 28) + 8, cyChar / 2 +10, cxClient / 14, cyChar, TRUE) ;
MoveWindow (hwndValue[i], ((4 * i + 2) * cxClient / 28) + 4, cyClient -20 -3 * cyChar / 2, cxClient / 14 + 8 , cyChar, TRUE) ; } SetFocus (hwnd) ; return 0 ;
case WM_CTLCOLORSTATIC: //Farben der Texte einstellen if (!(GetWindowLong((HWND) lParam, GWL_ID) >= 12 && GetWindowLong((HWND) lParam, GWL_ID) <= 17))//nicht die DMX-Werte { SetTextColor((HDC)wParam,RGB(0,0,0));//schwarz SetBkMode((HDC)wParam,TRANSPARENT);//farblos return (LRESULT)GetStockObject(NULL_BRUSH); } break;
case WM_SETFOCUS : SetFocus (hwndScroll[idFocus]) ; return 0 ;
case WM_VSCROLL :
// //Hier passiert das scrollen //
i = GetWindowLong ((HWND) lParam, GWL_ID) ;
switch (LOWORD (wParam)) { case SB_PAGEDOWN : intensity[i] += 9 ;
case SB_LINEDOWN : intensity[i] = min (255, intensity[i] + 1) ; break ;
case SB_PAGEUP : intensity[i] -= 9 ;
case SB_LINEUP : intensity[i] = max (0, intensity[i] - 1) ; break ;
case SB_TOP : intensity[i] = 0 ; break ;
case SB_BOTTOM : intensity[i] = 255 ; break ;
case SB_THUMBPOSITION : case SB_THUMBTRACK : intensity[i] = HIWORD (wParam) ; break ;
default : break ; }
// //Anzeigen der veränderten Werte nach dem scrollen // SetScrollPos (hwndScroll[i], SB_CTL, intensity[i], TRUE) ; //Ausgabe als Text sprintf (szBuffer, "%i", 255-intensity[i]) ; SetWindowText (hwndValue[i], szBuffer) ;
// //Übertragen des neu "erscrollten" Wertes in das Interface // dmx_level[i]=255-intensity[i]; pfnDasHardCommand (DHC_DMXOUT, 512, dmx_level);
return 0 ;
case WM_DESTROY : pfnDasHardCommand(DHC_CLOSE,0,0); FreeLibrary (dllHandle); PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
LRESULT CALLBACK ScrollProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { int id = GetWindowLong (hwnd, GWL_ID) ;
// // Hier werden Benutzereingaben verwaltet, wenn die Scrollbars den Fokus haben // insbesondere TAB und SHIFT-TAB zum Verändern des Fokus // switch (message) { case WM_KEYDOWN : if (wParam == VK_TAB) SetFocus (GetDlgItem (GetParent (hwnd), (id + (GetKeyState (VK_SHIFT) < 0 ? 5 : 1)) % 6)) ; break ;
case WM_SETFOCUS : idFocus = id ; break ; } return CallWindowProc (OldScroll[id], hwnd, message, wParam, lParam) ; } |