File: winmain.cpp

package info (click to toggle)
audacity 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 129,312 kB
  • sloc: ansic: 373,350; cpp: 276,880; sh: 56,060; python: 18,922; makefile: 10,309; lisp: 8,365; xml: 1,888; perl: 1,798; java: 1,551; asm: 545; pascal: 395; sed: 58; awk: 35
file content (657 lines) | stat: -rw-r--r-- 24,134 bytes parent folder | download | duplicates (13)
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
#include "windows.h"            /* required for all Windows applications */
#include "cppext.h"
#include "longque.h"
#include "button.h"
#include "slider.h"
#include "winmain.h"            /* specific to this program          */
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "textio.h"
#include "mmsystem.h"
#include <crtdbg.h>
#include <mapiwin.h>        // for Sleep()
#include "stdio.h"
#include "resource.h"
#include "typein.h"
#include "xlispfns.h"
#include "winfun.h"

//#define THUMBTRACK        // tries to get continuous scrollbars with SB_THUMBTRACK messages.
                            // doesn't work -- zone 1 doesn't seem to wake up until the button-up.

//#include "saudio.h"

//#define D if(0) 

HWND buttons[NUMBUTTONS];
HWND sliders[NUMSLIDERS];

HWND textinput;
HWND textoutput;
HFONT hfont;

HWND alt_win;
WNDPROC alt_proc;


extern "C" {
    HINSTANCE hInst;            /* current instance */
    HWND hMainWindow;           /* main window handle */
}
/* HINSTANCE hInst;            /* current instance */
/* HWND hMainWindow;           /* main window handle */


int quit_value; // return value from WinMain
int abort_flag = 0;


// there's some state here:
// when we get a message from the input queue, it is an entire
// string. We save the string and a pointer to the next char
//
char *get_ascii_string = NULL;
char *next_ascii = NULL;

//asciiwait -- wait for ascii input
char wait_ascii()
{
    if (next_ascii && *next_ascii) {
        char c = *next_ascii++;
        if (c == '\r') c = '\n';
        _RPT1(_CRT_WARN, "|%c|", c);
        return c;
    }
    if (get_ascii_string) {
        _RPT2(_CRT_WARN, "free get_ascii_string %x %s\n", 
              get_ascii_string, get_ascii_string);
        free(get_ascii_string);
        get_ascii_string = NULL;
        next_ascii = NULL;
    }
    // no input, so look for Windows messages
    while (typein::queue.emptyp() && !abort_flag) {
        process_win_events(USE_GET);
    }
    if (abort_flag == ABORT_LEVEL) return ABORT_CHAR;
    if (abort_flag == BREAK_LEVEL) return BREAK_CHAR;
    get_ascii_string = (char *) typein::queue.remove();
    _RPT2(_CRT_WARN, "removed %x: %s\n", get_ascii_string, get_ascii_string);
    edit_append(get_ascii_string);
    next_ascii = get_ascii_string;
    return wait_ascii();
}


//process_win_events -- receive and handle windows by either:
//  USE_PEEK: non-blocking 
//  USE_GET: blocks
void process_win_events(int method)
{
    MSG msg;
    edit_append(""); // flush the output
    if (method == USE_GET) {
        //blocks until at least a message arrives
        if (GetMessage(&msg,    //msg stored here
                NULL,           //receive ALL application messages
                NULL,NULL))     //no msg filtering
        {
            //standard windows loop
            TranslateMessage(&msg); //posts another msg if there is a virtual to WM_CHAR mapping
            DispatchMessage(&msg);  //calls object's receive function
        } else {
            //is this ever entered???
            quit_value = msg.wParam;
            abort_flag = ABORT_CHAR;
            exit(0);
        }
    } else {
        //default: process all messges that already exist (non-blocking)
        while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE | PM_NOYIELD)) 
        {
            TranslateMessage(&msg);    
            DispatchMessage(&msg);     
        }
    }
}

//STUFF TO PROVIDE CONSOLE-------------------------------------------------
//terminate strings and strip out LF
int lf2crlf(char *dest, char *src)
{
    char *d = dest;
    while (*src) {
        if (*src == '\n') {
            *dest++ = '\r';
        }
        *dest++ = *src++;
    }
    *dest = EOS;
    return dest - d; /* string length */
}

#define EDIT_HIGH_WATER 10000
#define EDIT_LOW_WATER 9000

#define EABUFFMAX 110
static char eabuff[EABUFFMAX]; /* edit_append buffer */
static char eabuffx = 0;

static void edit_append2(char *txt2);

/* edit_append -- optimizes output by buffering 
 *
 * call with empty string to flush buffer 
 */
void edit_append(char *txt)
{
    /* new algorithm to deal with long strings on input:
     *  if input is longer than 50, insert a zero and 
     *  call recursively; then undo the zero and continue.
     */
    char txt2[100];
    while (strlen(txt) > 50) {
        char temp = txt[50];
        txt[50] = 0;
        edit_append(txt); /* strlen(txt) == 50 */
        txt = txt + 50;
        txt[0] = temp;
    }
    int len = lf2crlf(txt2, txt);
    if ((eabuffx + len + 1 > EABUFFMAX) || ((len == 0) && eabuffx)) {
        edit_append2(eabuff);
        eabuffx = 0;
    }
    strcpy(eabuff + eabuffx, txt2);
    eabuffx += len;
}


static void edit_append2(char *txt2)
{
    int len;
    int lines;
    if (*txt2 == '\b') { // special case: erase last character
        long len = SendMessage(textoutput, WM_GETTEXTLENGTH, (WPARAM) 0, (LPARAM) 0);
        if (len > 0) {
            // select the last character:
            SendMessage(textoutput, EM_SETSEL, (WPARAM) len - 1, (LPARAM) -1);
            // delete the last character:
            SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) ""));
        }
        return;
    }
    // to put insertion point at the end, first select
    // everything ...
    //wparam is UINT ; lparam is LONG
    SendMessage(textoutput, EM_SETSEL, (WPARAM) 0, (LPARAM) -1); 
    // then remove selection, leaving cursor at the end:
    SendMessage(textoutput, EM_SETSEL, (WPARAM) -1, (LPARAM) -1);
    // now, replacement actually appends to the buffer:
    SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) txt2));
    // if the number of characters exceeds EDIT_HIGH_WATER, then
    // trim the number of characters to EDIT_LOW_WATER by deleting
    // all lines up to the one containing total-EDIT_LOW_WATER
    lines = (int) SendMessage(textoutput, EM_GETLINECOUNT, (WPARAM) 0, (LPARAM) 0);
    len = (int) SendMessage(textoutput, EM_LINEINDEX, (WPARAM)(lines - 1), (LPARAM) 0);
    len += (int) SendMessage(textoutput, EM_LINELENGTH, (WPARAM)(lines - 1), (LPARAM) 0);
    if (len > EDIT_HIGH_WATER) {
        //these SendMessages operate to completion
        lines = (int) SendMessage(textoutput, EM_LINEFROMCHAR, 
                        (WPARAM)(len - EDIT_LOW_WATER), (LPARAM) 0);
        len = (int) SendMessage(textoutput, EM_LINEINDEX, (WPARAM)(lines), (LPARAM) 0);
        SendMessage(textoutput, EM_SETSEL, (WPARAM) 0, (LPARAM)(len));
        SendMessage(textoutput, EM_REPLACESEL, (WPARAM) 0, (LPARAM) ((LPSTR) ""));
    } 
}

//THE STUFF REQUIRED BY WINDOWS APPLICATIONS----------------------------------


// we will subclass the textinput window with a window procedure that detects
// the Enter key (hex 0x0d) and sets a flag. Then in the main window proc, 
// when an EN_CHANGE message is received, we will know the user typed Enter,
// so we can transfer the text to XLISP.
// 
// This would be a good place also to add editing characters to scroll through
// previous entries.
//
WNDPROC DefaultEditWndProc = NULL;
#define ENTER_KEY 0x0d
bool enter_flag = false;


long CALLBACK EditWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    if (message == WM_CHAR) {
        if (wParam == ENTER_KEY) enter_flag = true;
        _RPT1(_CRT_WARN, "wm_char is %x\n", wParam);
    }
    return CallWindowProc(DefaultEditWndProc, hWnd, message, wParam, lParam);
}



//All applications need to register
BOOL InitApplication(HINSTANCE hInstance /* current instance */)
{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */
    wc.style = NULL;                    /* Class style(s).                    */
    wc.lpfnWndProc = MainWndProc;       /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NYCON));
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "MAINMENU";   /* Name of menu resource in .RC file. */
    wc.lpszClassName = "CMTWClass"; /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */
    return (RegisterClass(&wc));

}


static char *button_names[NUMBUTTONS] = { "Load File", "Reload File", 
    "Replay Sound", "Break", "Top", "Up", "Info", "F1", "F2", "F3", "F4" };


//each time this application is run, the following program must be run
BOOL InitInstance(
    HINSTANCE       hInstance,          /* Current instance identifier.       */
    int             nCmdShow)           /* Param for first ShowWindow() call. */
{
    int i;
    RECT rect;
    LRESULT rslt;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequent calls from this application to Windows.            */

    hInst = hInstance;

    /* Create a main window for this application instance.  */

    hMainWindow = CreateWindow(
        "CMTWClass",                    /* See RegisterClass() call.          */
        "Nyquist",                      /* Text for window title bar.         */
        WS_OVERLAPPEDWINDOW,            /* Window style.                      */
        CW_USEDEFAULT,                  /* Default horizontal position.       */
        CW_USEDEFAULT,                  /* Default vertical position.         */
        CW_USEDEFAULT,                  /* Default width.                     */
        CW_USEDEFAULT,                  /* Default height.                    */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer not needed.                */
    );

    /* If window could not be created, return "failure" */

    if (!hMainWindow)
        return (FALSE);
        
    GetClientRect(hMainWindow, (LPRECT) &rect);

    /* Make the window visible; update its client area; and return "success" */

    const int button_y = 25;        // size in pixels
    const int slider_x = 20;
    const int slider_gap = 1;
    const int input_height = 48;   // how high is input type-in edit control
    int slider_xsum = slider_x * NUMSLIDERS;
    int button_ysum = button_y * NUMBUTTONS_VERT;


    ShowWindow(hMainWindow, nCmdShow);  /* Show the window                        */
    UpdateWindow(hMainWindow);          /* Sends WM_PAINT message                 */
    for (i = 0; i < NUMBUTTONS; i++) {
        int x = 0;
        int y = i * button_y;
        int width = slider_xsum;
        if (i > 2) {
            y = (3  + (i - 3) / 2) * button_y;
            width = width / 2;
            if ((i & 1) == 0) x = width;
        }
        buttons[i] = CreateWindow("Button",         //lpszClassName
                                    button_names[i],//windowName
                                    BS_PUSHBUTTON | //Style: 1) PB
                                        WS_CHILD |  //  2) must reside w/in parent
                                        WS_VISIBLE, //  3) initially visible
                                    x, y, width, button_y,
                                    hMainWindow,    //owner window
                                    (HMENU)(IDC_BUTTON+i),
                                    //&buttonsH[i], //child window Id
                                    hInstance,      //application instance 
                                    NULL);          //WM_CREATE argument

        //activate current window & display w/current size and position
        ShowWindow(buttons[i], SW_SHOW);
        //update (nonempty) client area via WM_PAINT
        UpdateWindow(buttons[i]);
    }

    for (i=0; i<NUMSLIDERS; ++i)  {
        char name[5];
        sprintf(name, "%d", i);
        sliders[i] = CreateWindow("Scrollbar", name, WS_CHILD | WS_VISIBLE | SBS_VERT /*| WS_BORDER */,
                                  slider_x * i + slider_gap, button_ysum, slider_x - slider_gap, (rect.bottom - rect.top) - button_ysum, 
                                  hMainWindow, (HMENU)(IDC_SLIDER+i), hInstance, NULL);     // (was IDC_BUTTON)
        SetScrollRange(sliders[i], SB_CTL, 0, 127, 1);
        ShowWindow(sliders[i], SW_SHOW);
        UpdateWindow(sliders[i]); 
    }
    


    textinput = CreateWindow("Edit", NULL,
                          WS_CHILD | WS_VISIBLE | ES_MULTILINE | 
                            WS_VSCROLL | ES_AUTOVSCROLL | WS_BORDER,
                          slider_xsum, 0, 
                          (rect.right - rect.left) - slider_xsum, 
                          input_height,
                          hMainWindow, (HMENU)(IDC_EDIT_INPUT), hInstance, NULL);
    // subclass the input window so we can catch the Enter key
    DefaultEditWndProc = (WNDPROC) SetWindowLong(textinput, GWL_WNDPROC, (long) EditWndProc);

    textoutput = CreateWindow("Edit", NULL,
                          WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_READONLY |
                            WS_VSCROLL | ES_AUTOVSCROLL | WS_BORDER,
                          slider_xsum, input_height - 1, 
                          (rect.right - rect.left) - slider_xsum, 
                          (rect.bottom - rect.top) - input_height,
                          hMainWindow, (HMENU)(IDC_EDIT), hInstance, NULL);

    hfont = CreateFont(0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
                       ANSI_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS,
                       DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE,
                       "Courier");


    rslt = SendMessage(textoutput, WM_SETFONT, (WPARAM) hfont,
                               MAKELPARAM(TRUE, 0));
 
    ShowWindow(textoutput, SW_SHOW);
    UpdateWindow(textoutput); 

    rslt = SendMessage(textinput, WM_SETFONT, (WPARAM) hfont,
                               MAKELPARAM(TRUE, 0));
 
    ShowWindow(textinput, SW_SHOW);
    UpdateWindow(textinput); 

    return (TRUE);               /* Returns the value from PostQuitMessage */

}

//this is the hook called where any windows application starts up
extern "C" int WINAPI WinMain(
  HINSTANCE hInstance,              /* current instance         */
  HINSTANCE hPrevInstance,          /* previous instance        */
  LPSTR lpCmdLine,                 /* command line             */
  int nCmdShow)                    /* show-window type (open/icon) */
{
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW);      // EUB

#if defined(_DEBUG) && 0
    int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
    flags |= _CRTDBG_CHECK_ALWAYS_DF;       // do expensive memory checking     -eub
    flags |= _CRTDBG_LEAK_CHECK_DF;         // check for leaks at termination
    _CrtSetDbgFlag(flags);
    _CrtCheckMemory();
#endif

    typein::init();
    
    if (!hPrevInstance)          /* Other instances of app running? */
    if (!InitApplication(hInstance)) /* Initialize shared things */
        return (FALSE);      /* Exits if unable to initialize     */

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow)) return (FALSE);

    run_xlisp();

    return quit_value;
}


char *button_msgs[] = {
    "(ny:load-file)\n",
    "(ny:reload-file)\n",
    "(r)\n",
    "\002",
    "\003",
    "\007",
    "\024",
    "(F1)\n",
    "(F2)\n",
    "(F3)\n",
    "(F4)\n" };


static void type_this(char *ptr)
{
    char *s = (char *) malloc(strlen(ptr) + 1);
    _RPT1(_CRT_WARN, "type_this mallocs %x\n", s);
    strcpy(s, ptr);
    typein::handler(s);
}



//This is the Main Window Receive Function
long CALLBACK MainWndProc(
  HWND hWnd,                      /* window handle */
  UINT message,                   /* type of message */
  WPARAM wParam,                  /* additional information */
  LPARAM lParam)                  /* additional information */
{
   switch (message) {
        case WM_CHAR: {
            //message: character code is posted via Translate Message
            TCHAR c = (TCHAR) wParam;
            //lKeyData = lParam;    extended, ctrl, etc keys are ignored!!!
            // typein::handler(c);
            break;
        }
        case WM_COMMAND: {      
            //message: command from application menu
            short int code = HIWORD(wParam);
            int wid = LOWORD(wParam);
            HWND hwndCtrl = (HWND) lParam;
            if (code == 0 && wid == IDM_ABOUT) {
                DialogBox(hInst, /*current inst*/ "ABOUTBOX", /*resource to use*/
                    hWnd, /* parent*/ (DLGPROC) About /*About() instance address*/);
            } else if (code == 0 && wid == ID_FILE_LOAD) {
                type_this(button_msgs[0]);
            } else if (code == 0 && wid == ID_FILE_RELOAD) {
                type_this(button_msgs[1]);
            } else if (code == 0 && wid == ID_FILE_EXIT) {
                type_this("(exit)\n");
            } else if (wid >= IDC_BUTTON && wid < IDC_BUTTON + NUMBUTTONS) {
                SetFocus(textinput); /* get focus back */
                type_this(button_msgs[wid - IDC_BUTTON]);
            } else if (wid == IDC_EDIT_INPUT) {
                if (code == EN_CHANGE) {
                    if (enter_flag) {
                        enter_flag = false;
                        long len = SendMessage(hwndCtrl, WM_GETTEXTLENGTH, 0, 0);
                        len++; // allow for terminating null character
                        char *buffer = (char *) malloc(len);
                        SendMessage(hwndCtrl, WM_GETTEXT, (WPARAM) len, (LPARAM) buffer);
                        _RPT2(_CRT_WARN, "inserting %x: %s\n", buffer, buffer);
                        typein::handler(buffer);
                        SendMessage(hwndCtrl, WM_SETTEXT, (WPARAM) 0, (LPARAM) "");
                    }
                }
            } else if (wid == IDC_EDIT) { 
                if (code == EN_CHANGE) {
                } else {
                }
            } else {
                /*Let Windows process it*/
                printf("unhandled: message %d\n", message);
                return (DefWindowProc(hWnd, message, wParam, lParam));
            }
            break;
        }
        case WM_DESTROY:          
            //message: window being destroyed 
            PostQuitMessage(0);
            break;
#ifdef MOUSEBUTTON_INPUT
        case WM_LBUTTONDOWN: {
            //message: left mouse button pressed while cursor in client area
            //never used, need SetCaputure???
            int /*???*/ xPos LOWORD(lParam);
            int /*???*/ yPos HIWORD(lParam);
            //int /*???*/ fwKeys; virtual keys not used!!!
            buffer[0] = '<';
            _itoa(xPos,buffer+1,10/*radix*/);
            i = strlen(buffer);
            buffer[i++] = ',';
            _itoa(yPos,buffer+i,10/*radix*/);
            i = strlen(buffer);
            buffer[i++] = '>';
            buffer[i] = 0;
            edit_append(buffer);
            break;
#endif
#ifdef DEBUGINPUT
        //WM_USER msg codes are from the callbacks-------------------------
        case WM_USER_TIMEOUT: {
            //dummy message just unblocks GetMessage 
            break;
        }
        //remaining wMsg codes generated elsewhere------------------------------------
        case WM_KILLFOCUS: {
            //message: this window's loosing focus, focus must be set to new window
            HWND newFocus = (HWND) wParam;
            if (newFocus == textoutput) {
                //why not also set buttons, sliders...???
                SetFocus(hWnd);
            }
            break;
        }
        case WM_VSCROLL: {
            //message: control bar scroll I/O
            //where is window scroll bar handled???
            //why is this not also a WM_COMMAND???
            HWND hwndCtrl = (HWND) lParam;
            short int nPos = HIWORD(wParam);
            int code = LOWORD(wParam);
            int i;
            for (i = 0; i < NUMSLIDERS; i++) {
                if (sliders[i] == hwndCtrl) {
                    int pos = GetScrollPos(hwndCtrl /*parent*/, SB_CTL /*control*/);
                    switch (code) {
                      case SB_LINEUP:   pos--;      break;
                      case SB_LINEDOWN: pos++;      break;
                      case SB_PAGEUP:   pos -= 10;  break;
                      case SB_PAGEDOWN: pos += 10;  break;
                      case SB_ENDSCROLL:            
                          break;    //why not continue???
                      case SB_THUMBTRACK:       
#ifdef THUMBTRACK
                                        pos = nPos; 
                                                    break;
#else
                                                    continue;       // no silly multiple messages
#endif
                                                    //break;
                      case SB_THUMBPOSITION: 
#ifndef THUMBTRACK
                                        pos = nPos;
#endif
                                        break;
                      case SB_TOP:      pos = 0;    break;
                      case SB_BOTTOM:   pos = 127;  break;
                      default: continue;    //avoid SetScrollPos
                    }
                    // SetScrollRange() set the range to 0-127, but clip just to make sure:
                    if (pos < 0) pos = 0; 
                    if (pos > 127) pos = 127;
                    if (code != SB_ENDSCROLL
#ifdef THUMBTRACK
                        && code != SB_THUMBTRACK
#endif
                       ) {
                        //ctrlevents.insert(CTRLEVENT(IDC_SLIDER + i, 127 - pos));    
                    }
                    SetScrollPos(hwndCtrl /*parent*/, SB_CTL /*control sb*/, pos /*new position*/, TRUE /*redraw*/);
                    break;
                }
            }
            break;
        }
#endif
        default:                  
            //Pass on all unproccessed messages
            return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (NULL);  //all messages currently return this...
}


/****************************************************************************

    FUNCTION: About(HWND, unsigned, WORD, LONG)

    PURPOSE:  Processes messages for "About" dialog box

    MESSAGES:

    WM_INITDIALOG - initialize dialog box
    WM_COMMAND    - Input received

    COMMENTS:

    No initialization is needed for this particular dialog box, but TRUE
    must be returned to Windows.

    Wait for user to click on "Ok" button, then close the dialog box.

****************************************************************************/

extern "C" BOOL CALLBACK About(
  HWND hDlg,               /* window handle of the dialog box */
  unsigned message,        /* type of message                 */
  WORD wParam,             /* message-specific information    */
  LONG lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:            /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:               /* message: received a command */
            if (wParam == IDOK         /* "OK" box selected?          */
                || wParam == IDCANCEL) /* System menu close command?  */
            {
                EndDialog(hDlg, TRUE); /* Exits the dialog box        */
                return TRUE;
            }
            break;
    }
    return FALSE;               /* Didn't process a message    */
}


/* Load File support */

extern "C" 

void RegisterWindow(HWND w, WNDPROC p) {
    alt_win = w;
    alt_proc = p;
}