home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
PMHINTS1.ZIP
/
HINTS.C
< prev
next >
Wrap
Text File
|
1991-05-03
|
11KB
|
331 lines
#define INCL_WIN
#include <os2.h>
#include <string.h>
#include <stdlib.h>
#include "hints.h"
PFNWP OldFrameProc;
MRESULT EXPENTRY MainWndProc (HWND, USHORT, MPARAM, MPARAM);
MRESULT EXPENTRY ChildWndProc (HWND, USHORT, MPARAM, MPARAM);
MRESULT EXPENTRY NewFrame (HWND, USHORT, MPARAM, MPARAM);
/****************************************************************************/
VOID cdecl main (void)
{
HAB hab;
HMQ hmq;
static HWND hwndEntry,
hwndClient,
hwndChild,
hwndFrame,
hwndChildFrame;
QMSG qmsg;
ULONG flFrameFlags,
flCFrameFlags,
DataLength;
CHAR Title[80],
CTitle[80];
SWCNTRL PgmEntry;
SWP swp;
/****************************************************************************/
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
WinRegisterClass(hab,
"Hints",
MainWndProc,
CS_SIZEREDRAW,
0);
WinRegisterClass(hab,
"Hints2",
ChildWndProc,
CS_SIZEREDRAW,
0);
WinLoadString( hab, NULL, ID_TITLE, sizeof(Title), Title );
WinLoadString( hab, NULL, ID_CTITLE, sizeof(CTitle), CTitle );
flCFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_NOBYTEALIGN |
FCF_SIZEBORDER | FCF_MINMAX;
flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU |
FCF_SIZEBORDER | FCF_MINMAX | FCF_ACCELTABLE |
FCF_NOBYTEALIGN;
hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
0L,
&flFrameFlags,
"Hints",
(PSZ)Title,
0L,
NULL,
ID_MAINWND,
&hwndClient);
OldFrameProc = WinSubclassWindow(hwndFrame, (PFNWP)NewFrame);
DataLength = sizeof(swp);
if (!PrfQueryProfileData(HINI_USERPROFILE, "Hints", "Size",
&swp, &DataLength))
{
swp.x = 100;
swp.y = 100;
swp.cx = 200;
swp.cy = 200;
/*-------------------------------------------------------------*/
/* For full screen - */
/* */
/* swp.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); */
/* swp.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); */
/*-------------------------------------------------------------*/
}
WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
hwndChildFrame = WinCreateStdWindow(HWND_DESKTOP,
0L,
&flCFrameFlags,
"Hints2",
(PSZ)CTitle,
0L,
NULL,
0,
&hwndChild);
WinSetOwner(hwndChildFrame, hwndFrame);
WinSetWindowPos(hwndChildFrame, HWND_TOP, 350, 100, 200, 200,
SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
PgmEntry.hwnd = hwndFrame;
PgmEntry.hwndIcon = NULL;
PgmEntry.hprog = NULL;
PgmEntry.idProcess = NULL;
PgmEntry.idSession = NULL;
PgmEntry.uchVisibility = SWL_VISIBLE;
PgmEntry.fbJump = SWL_JUMPABLE;
strcpy(PgmEntry.szSwtitle, Title);
hwndEntry = WinAddSwitchEntry(&PgmEntry);
WinStartTimer( hab, hwndClient, 1, 500 );
WinSendMsg(hwndFrame, WM_SETICON,
WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE), NULL);
WinSendMsg(hwndChildFrame, WM_SETICON,
WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE), NULL);
while(WinGetMsg(hab, &qmsg, NULL, 0, 0))
WinDispatchMsg(hab, &qmsg);
WinStopTimer( hab, hwndClient, 1);
WinDestroyWindow(hwndFrame);
WinRemoveSwitchEntry(hwndEntry);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
}
/****************************************************************************/
MRESULT EXPENTRY MainWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
RECTL rc;
SWP swp;
HPS hps;
HWND hwndActiveWin,
hwndFrame;
PID pid;
TID tid;
CHAR szText[20],
szPid[6];
switch (msg)
{
case WM_PAINT:
hwndActiveWin = WinQueryActiveWindow(HWND_DESKTOP, FALSE);
WinQueryWindowProcess(hwndActiveWin, &pid, &tid);
strcpy(szText, "Process ID = ");
strcat(szText, itoa(pid, szPid, 10));
WinQueryWindowRect(hwnd, &rc);
/*------------------------------------------------------------------*/
/* WinMapWindowPoints(hwnd, WinQueryWindow(hwnd, QW_PARENT, FALSE), */
/* (PPOINTL)&rc, 2); */
/*------------------------------------------------------------------*/
hps = WinBeginPaint(hwnd, NULL, &rc);
WinDrawText (hps, strlen(szText), szText, &rc, SYSCLR_WINDOWTEXT,
SYSCLR_WINDOW, DT_LEFT | DT_ERASERECT);
WinEndPaint(hps);
break;
case WM_TIMER:
hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
WinInvalidateRect(hwnd, NULL, TRUE); /* Cause PID to be displayed */
break;
case WM_BUTTON1DOWN:
hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
WinSetWindowText(hwndFrame, "Hints - Size and Position Fixed");
WinEnableWindow (WinWindowFromID (hwndFrame, FID_TITLEBAR), FALSE);
WinEnableWindow (WinWindowFromID (hwndFrame, FID_MINMAX), FALSE);
WinSetWindowBits(hwndFrame, QWL_STYLE,
(~FS_SIZEBORDER | FS_DLGBORDER),
( FS_SIZEBORDER | FS_DLGBORDER));
/*-----------------------------------------------------------------*/
/* WinSetWindowULong(hwndFrame, QWL_STYLE, */
/* (WinQueryWindowULong(hwndFrame, QWL_STYLE) & */
/* ~FS_SIZEBORDER | FS_DLGBORDER)); */
/*-----------------------------------------------------------------*/
WinInvalidateRect(hwndFrame, NULL, TRUE);
break;
case WM_BUTTON2DOWN:
hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
WinSetWindowText(hwndFrame, "Hints");
WinEnableWindow (WinWindowFromID (hwndFrame, FID_TITLEBAR), TRUE);
WinEnableWindow (WinWindowFromID (hwndFrame, FID_MINMAX), TRUE);
WinSetWindowBits(hwndFrame, QWL_STYLE,
(FS_SIZEBORDER | ~FS_DLGBORDER),
(FS_SIZEBORDER | FS_DLGBORDER));
/*-----------------------------------------------------------------*/
/* WinSetWindowULong(hwndFrame, QWL_STYLE, */
/* (WinQueryWindowULong(hwndFrame, QWL_STYLE) & */
/* ~FS_DLGBORDER | FS_SIZEBORDER)); */
/*-----------------------------------------------------------------*/
WinInvalidateRect(hwndFrame, NULL, TRUE);
break;
case WM_MINMAXFRAME:
hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
if (((PSWP)mp1)->fs & SWP_MINIMIZE)
{
DosBeep(100, 100);
}
else
if (((PSWP)mp1)->fs & SWP_MAXIMIZE)
{
DosBeep(1000, 100);
}
else
if (((PSWP)mp1)->fs & SWP_RESTORE)
{
DosBeep(500, 100);
}
WinSetWindowUShort(hwndFrame, QWS_XRESTORE, 100);
WinSetWindowUShort(hwndFrame, QWS_YRESTORE, 100);
WinSetWindowUShort(hwndFrame, QWS_CXRESTORE, 200);
WinSetWindowUShort(hwndFrame, QWS_CYRESTORE, 200);
break;
case WM_SAVEAPPLICATION:
WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT, FALSE), &swp);
PrfWriteProfileData(HINI_USERPROFILE, "Hints", "Size",
&swp, (ULONG)sizeof(swp));
return NULL;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1))
{
case MI_MIN:
hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
WinSetWindowPos(hwndFrame, NULL, 0, 0, 0, 0, SWP_MINIMIZE);
break;
case MI_EXIT:
WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
break;
}
case WM_ERASEBACKGROUND:
return (MRESULT)TRUE;
}
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
/****************************************************************************/
MRESULT EXPENTRY NewFrame(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
PTRACKINFO ptrack;
switch(msg)
{
case WM_QUERYTRACKINFO:
/*----------------------------------------------------------*/
/* Invoke the default frame window procedure first in order */
/* to update the tracking rectangle to the new position. */
/*----------------------------------------------------------*/
OldFrameProc(hwnd, msg, mp1, mp2);
ptrack = (PTRACKINFO)mp2;
ptrack->ptlMinTrackSize.x = 25;
ptrack->ptlMinTrackSize.y = 25;
return((MRESULT)TRUE);
break;
default:
return(OldFrameProc(hwnd, msg, mp1, mp2));
break;
}
return((MRESULT)NULL);
}
/****************************************************************************/
MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{
RECTL rc;
HPS hps;
CHAR szText[22];
HWND hwndChildFrame;
switch(msg)
{
case WM_PAINT:
strcpy(szText, "I am a child of Hints");
WinQueryWindowRect(hwnd, &rc);
hps = WinBeginPaint(hwnd, NULL, &rc);
WinDrawText (hps, strlen(szText), szText, &rc, SYSCLR_WINDOWTEXT,
SYSCLR_WINDOW, DT_LEFT | DT_ERASERECT);
WinEndPaint(hps);
break;
case WM_ERASEBACKGROUND:
return (MRESULT)TRUE;
case WM_CLOSE:
hwndChildFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
WinDestroyWindow(hwndChildFrame);
break;
}
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}