File:  [OS/2 SDKs] / pmsdk / samples / btntest / btntest.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:28:13 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: pmsdk-1988, HEAD
Microsoft OS/2 SDK PM 08-08-1988

/*      btntest.c  - List box control test application          */
/*      Created by Microsoft Corp., 1988                        */
/*                                                              */

#define  INCL_PM
#include <os2.h>
#include "btntest.h"

/************* GLOBAL VARIABLES         */

char szBtntestClass[] = "Btntest";
char szAppName[] = "Btntest Application";

HAB    habBtntest;
HMQ    hmqBtntest;
HWND   hwndBtntest;
HWND   hwndBtntestFrame;

INT fOwnerDraw;
INT cyText;

void FAR PASCAL WinExitWindows(PCH);

/************* PROCEDURE DECLARATIONS   */

MRESULT FAR PASCAL BtnDlgProc(HWND, USHORT, MPARAM, MPARAM);
MRESULT FAR PASCAL StyleDlgProc(HWND, USHORT, MPARAM, MPARAM);


BOOL BtntestInit()
{
    /*
     * Initialize the HAB
     * (just usSet to -1L for now until we get WinInitialize()
     */
    habBtntest = WinInitialize(NULL);
    hmqBtntest = WinCreateMsgQueue(habBtntest, 0);

    return(TRUE);
}

int cdecl main(argc, argv)
int argc;
char *argv[];
{
    QMSG qmsg;
    USHORT wResult;
    WRECT rc;

    if (!BtntestInit())
        return(0);

    wResult = WinDlgBox(HWND_DESKTOP, (HWND)NULL, (PFNWP)BtnDlgProc, 
            (HMODULE)NULL, IDD_BTNTEST, (PCH)NULL);

    WinDestroyMsgQueue(hmqBtntest);

    WinTerminate(habBtntest);
    DosExit(EXIT_PROCESS, 0);
}

USHORT seed;
INT   cPushed;

MRESULT FAR PASCAL BtnDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
    HWND hwnd1, hwnd2;
    CHAR rgch[256];
    ULONG flStyle;
    BOOL fParse;
    HPS hps;
    INT result;
    ULONG lseed;
    WRECT rc;

    hwnd2 = WinWindowFromID(hwnd, 11);      /* Input/output edit control */
    hwnd1 = WinWindowFromID(hwnd, 10);      /* button control */

    switch (msg) {
    case WM_COMMAND:
        switch (LOUSHORT(mp1)) {
        case DID_OK:
            WinDismissDlg(hwnd, 1234);
            break;
        case 14: /* click */
            WinSendMsg(hwnd1, BM_CLICK, (MPARAM)TRUE, 0L);
            break;
        case 15: /* querycheckindex */
            result = (INT)WinSendMsg(hwnd1, BM_QUERYCHECKINDEX, 0L, 0L);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 16: /* queryhilite */
            result = (INT)WinSendMsg(hwnd1, BM_QUERYHILITE, 0L, 0L);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 17: /* sethilite */
            WinQueryDlgItemShort(hwnd, 31, (PSHORT)&result, FALSE);
            WinSendMsg(hwnd1, BM_SETHILITE, (MPARAM)result, 0L);
            break;
        case 18: /* querycheck */
            result = (INT)WinSendMsg(hwnd1, BM_QUERYCHECK, 0L, 0L);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 19: /* setcheck */
            WinQueryDlgItemShort(hwnd, 31, (PSHORT)&result, FALSE);
            WinSendMsg(hwnd1, BM_SETCHECK, (MPARAM)result, 0L);
            break;
        case 20: /* querydlgcode */
            result = (INT)WinSendMsg(hwnd1, WM_QUERYDLGCODE, 0L, 0L);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 21: /* querytext */
            result = WinQueryWindowText(hwnd1, 255, (PSZ)rgch);
            WinSetWindowText(hwnd2, (PSZ)rgch);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 22: /* querytextlength */
            result = WinQueryWindowTextLength(hwnd1);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 23: /* settext */
            result = WinQueryWindowText(hwnd2, 255, (PSZ)rgch);
            result = WinSetWindowText(hwnd1, (PSZ)rgch);
            WinSetDlgItemShort(hwnd, 31, result, TRUE);
            break;
        case 25: /* Change flStyle */
            flStyle = WinQueryWindowULong(hwnd1, QWL_STYLE);
            result = WinDlgBox(HWND_DESKTOP, hwnd, (PFNWP)StyleDlgProc, 
                                                (HMODULE)NULL, 2, (PCH)&flStyle);
            flStyle = (flStyle & 0xffff0000) + result;

            if (WinSendDlgItemMsg(hwnd, 26, BM_QUERYCHECK, 0L, 0L))
                flStyle |= BS_HELP;
            if (WinSendDlgItemMsg(hwnd, 27, BM_QUERYCHECK, 0L, 0L))
                flStyle |= BS_NOPOINTERFOCUS;
            if (WinSendDlgItemMsg(hwnd, 28, BM_QUERYCHECK, 0L, 0L))
                flStyle |= BS_NOBORDER;

            WinSetWindowULong(hwnd1, QWL_STYLE, flStyle);
            WinInvalidateRect(hwnd1, (PWRECT)NULL, TRUE);
            break;
        default:
            break;
        }
        break;
    case WM_CONTROL:
        switch(LOUSHORT(mp1)) {
        case 10:
            WinSetDlgItemShort(hwnd, 33, HIUSHORT(mp1), FALSE);
            switch (HIUSHORT(mp1)) {
            case BN_CLICKED:
                break;
            case BN_PAINT:
                WinQueryWindowRect(hwnd1, (PRECTL)&rc);
                seed = ((seed * 23) + 15) & 0xffff;
                lseed = -(long)(seed % SYSCLR_CSYSCOLORS + 10);
                hps = WinGetPS(hwnd1);
                WinFillRect(hps, (PRECTL)&rc, lseed);
                WinReleasePS(hps);
                break;
            default:
                break;
            }
            break;
        case 24:
            fParse = (BOOL)WinSendMsg(WinWindowFromID(hwnd, 24), BM_QUERYCHECK,
                    0L, 0L);
            WinEnableWindow(hwnd1, !fParse);
            break;
        case 26:
            fParse = (BOOL)WinSendDlgItemMsg(hwnd, 26, BM_QUERYCHECK, 0L, 0L);
            flStyle = WinQueryWindowULong(hwnd1, QWL_STYLE);
            if (fParse)
                flStyle |= BS_HELP;
            else
                flStyle &= ~BS_HELP;
            WinSetWindowULong(hwnd1, QWL_STYLE, flStyle);
            WinInvalidateRect(hwnd1, (PWRECT)NULL, TRUE);
            break;
        case 27:
            fParse = (BOOL)WinSendDlgItemMsg(hwnd, 27, BM_QUERYCHECK, 0L, 0L);
            flStyle = WinQueryWindowULong(hwnd1, QWL_STYLE);
            if (fParse)
                flStyle |= BS_NOPOINTERFOCUS;
            else
                flStyle &= ~BS_NOPOINTERFOCUS;
            WinSetWindowULong(hwnd1, QWL_STYLE, flStyle);
            break;
        case 28:
            fParse = (BOOL)WinSendDlgItemMsg(hwnd, 28, BM_QUERYCHECK, 0L, 0L);
            flStyle = WinQueryWindowULong(hwnd1, QWL_STYLE);
            if (fParse)
                flStyle |= BS_NOBORDER;
            else
                flStyle &= ~BS_NOBORDER;
            WinSetWindowULong(hwnd1, QWL_STYLE, flStyle);
            WinInvalidateRect(hwnd1, (PWRECT)NULL, TRUE);
            break;
        }
        break;
    case WM_INITDLG:
        /* Set up user button redraws */
        seed = 12345;
        cPushed = 0;
        WinSetFocus(HWND_DESKTOP, hwnd1);
        return((ULONG)TRUE);
        break;
    default:
        return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        break;
    }
    return 0L;
}

MRESULT FAR PASCAL StyleDlgProc(hwnd, msg, mp1, mp2)
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
    ULONG flStyle;
    INT result;

    switch (msg) {
    case WM_COMMAND:
        if (LOUSHORT(mp1) == DID_OK) {
            result = (INT)WinSendDlgItemMsg(hwnd, 3, BM_QUERYCHECKINDEX, 0L, 0L);
            WinDismissDlg(hwnd, result);
        }
        break;
    case WM_INITDLG:
        flStyle = *((ULONG FAR *)mp2);
        WinSendDlgItemMsg(hwnd, 3 + LOUSHORT(flStyle), BM_SETCHECK,
                (MPARAM)TRUE, 0L);
        break;
    default:
        return(WinDefDlgProc(hwnd, msg, mp1, mp2));
        break;
    }
    return (FALSE);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.