TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Gary Chambers
from: Peter Fitzsimmons
date: 1996-01-10 16:04:36
subject: SpinButton Quandary

GC>     /* This works as expected /*
                                  ^^^^
This is not a valid comment.


Your big error was processing WM_CONTROL for all controls,  not just the
spinbutton --- no WM_CONTROL was ever ending up in WinDefWindowProc.

I made several changes...I'll just repost the whole thing.

 #define INCL_WIN

 #include 
 #include 
 #include 
 #include 

 MRESULT EXPENTRY ClientWndProc(HWND, ULONG, MPARAM, MPARAM);

 #define ID_SPINBUTTON 99

 int main(void)
 {
     HAB   hab;
     HMQ   hmq;
     HWND  hwndFrame, hwndClient, hwndSpin;
     QMSG  qmsg;
     RECTL rcl;
     int   InitNum = 25, MinRange = 0, MaxRange = 100;
     char  szClassName[] = "SpinTest1";
     char  szWindowTitle[] = "Spin Test";

     /* No external resources */
     ULONG flFrameOpts = (FCF_STANDARD &
                         ~FCF_ICON &
                         ~FCF_MENU &
                         ~FCF_ACCELTABLE);

     ULONG ulSpinStyle = SPBS_MASTER      |
                         SPBS_NUMERICONLY |
                         SPBS_JUSTRIGHT   |
                         SPBS_FASTSPIN;

     hab = WinInitialize(0);
     hmq = WinCreateMsgQueue(hab, 0);

     WinRegisterClass(hab, szClassName, ClientWndProc, CS_SIZEREDRAW, 0);

     hwndFrame = WinCreateStdWindow(HWND_DESKTOP, WS_VISIBLE,
                                    &flFrameOpts, szClassName,
                                    szWindowTitle, 0L, 0, 0, &hwndClient);

     hwndSpin = WinCreateWindow(hwndClient, WC_SPINBUTTON, NULL, ulSpinStyle,
                                5, 100, 60, 50,
                                hwndClient, HWND_TOP,
                                ID_SPINBUTTON, NULL, NULL);

     /* This works as expected !!!!!!!!!!!!!!!!!!*/
     WinSendMsg(hwndSpin, SPBM_SETLIMITS, (MPARAM)MaxRange, (MPARAM)MinRange);
     WinSendMsg(hwndSpin, SPBM_SETCURRENTVALUE, (MPARAM)InitNum, (MPARAM)NULL);
     WinShowWindow(hwndSpin, TRUE);

     while (WinGetMsg(hab, &qmsg, 0, 0, 0))
         WinDispatchMsg(hab, &qmsg);

     WinDestroyWindow(hwndFrame);
     WinDestroyMsgQueue(hmq);
     WinTerminate(hab);
     return 0;
 }

 MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 {
    HPS   hps;
    RECTL rcl;
    CHAR  Prefix[] = "Spin Button value is now ";
    CHAR  szStr[80], _num[10];
    static ULONG num = 25;
    HWND  spinID;

    switch (msg)
    {
        case WM_CREATE:
             /* Not sure if this is the correct way of getting the handle */
             spinID = WinWindowFromID(hwnd, ID_SPINBUTTON);

             /* Method different from WM_CONTROL because I was testing */
             WinSendMsg(spinID, SPBM_QUERYVALUE, MPFROMSHORT(&num),
                        MPFROM2SHORT(SPBQ_ALWAYSUPDATE, 0));
             return 0;

        /* I'm getting the WM_CONTROL message (tested with DosBeep), */
        /* but after that, nothing. */
        case WM_CONTROL:
             if(SHORT1FROMMP(mp1) == ID_SPINBUTTON){
                 if(SHORT2FROMMP(mp1) == SPBN_CHANGE){
                     WinSendMsg(HWNDFROMMP(mp2), SPBM_QUERYVALUE,
                                &num, MPFROM2SHORT(0, SPBQ_UPDATEIFVALID));
                     WinInvalidateRect(hwnd, NULL, TRUE);
                     WinAlarm(HWND_DESKTOP, WA_NOTE);
                     return 0;
                 }
             }
             break;
        case WM_PAINT:
             hps = WinBeginPaint(hwnd, 0, NULL);
             WinQueryWindowRect(hwnd, &rcl);
             WinFillRect(hps, &rcl, CLR_BACKGROUND);
             rcl.xLeft += 5; rcl.yTop -= 5;
             strcpy(szStr, Prefix);
             itoa(num, _num, 10);
             strcat(szStr, _num);
             WinDrawText(hps, -1, szStr, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
                         DT_ERASERECT);
             WinEndPaint(hps);
             return 0;

    } /* switch */

    return WinDefWindowProc(hwnd, msg, mp1, mp2);
 }



--- Maximus/2 3.00
* Origin: Sol 3 * Toronto * V.32 * (905)858-8488 (1:259/414)
SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/99 3615/50 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.