TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: All
from: Gary Chambers
date: 1996-01-08 15:44:24
subject: SpinButton Quandary

Hi All...

I apologize for the lengthy code segment, but I'm not sure what's *NOT*
needed.  I'm having a difficult time (thinking it would be easy) with
SpinButton controls.  My desire is, simply, to have a small string
displayed in a window as the button is changed (in any way).  I cannot seem
to grasp the use of SPBM_QUERYVALUE.  My code will illustrate the method
I'm using now.  Any help will be greatly appreciated.  Here's the code:

/***** Cut Here *****/

#define INCL_WIN

#include 
#include 
#include 
#include 

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

#define ID_SPINBUTTON 1

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];
   ULONG num;
   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:
            switch (SHORT1FROMMP(mp1))
            {
                /* I want to intercept *ANY* SpinButton message */
                case SPBN_CHANGE:
                case SPBN_UPARROW:
                case SPBN_DOWNARROW:
                case SPBN_ENDSPIN:
                case SPBN_SETFOCUS:
                case SPBN_KILLFOCUS:
                     WinSendMsg(HWNDFROMMP(mp2), SPBM_QUERYVALUE,
                                mp1, MPFROM2SHORT(&num, 0));
                     num = (ULONG)mp1;
                     WinQueryWindowRect(hwnd, &rcl);
                     WinInvalidateRect(hwnd, &rcl, TRUE);
                     break;
            }
            return 0;

       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);
}

/***** Cut Here *****/

GeeCee/2
gchambers{at}maine.com

... Topsham, ME 43 57.0'N 69 57.0'W 
--- 
* Origin: Mystic Seaport Inn OiS/2 - USR DS V.34+ - (207)721-3258 (1:326/426)
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: 326/426 411 400 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™.