home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
power.zip
/
TEST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-09
|
26KB
|
522 lines
/*______________________________________________________________________
| PowerThread (c) 1994 Greg Ratajik |
|-----------------------------------------------------------------------|
| Description: This module allows testing of the PowerThread function |
| calls. See POWER.C or POWER.DOC for more information. |
| |
| ***************************************************************** |
| *DISCLAIMER OF WARRANTIES. The following code is * |
| * sample code created by Greg Ratajik. The code is provided * |
| *"AS IS", without warranty of any kind. Greg Ratatjik shall not* |
| *be liable for any damages arising out of your use of the sample* |
| *code. * |
| ***************************************************************** |
|_____________________________________________________________________*/
#define INCL_PM /* PM Support */
#define INCL_DOSPROCESS /* Process and thread support */
#define INCL_DOSMODULEMGR /* Support DosLoad DosGetProgAddr */
/*______________________________________________________________________
| |
| System Includes |
|_____________________________________________________________________*/
#define _MT
#include <os2.h> /* Base OS/2 Include */
#include <string.h> /* Standard C functions */
#include <stdlib.h> /* malloc and free */
#include <process.h> /* _beginthread support */
/*______________________________________________________________________
| |
| Application Specific Includes & Defines |
|_____________________________________________________________________*/
#include "test.rch" /* RC info for the DLG */
#include "power.h" /* Prototypes for PowerCalls */
#define DYNOHELP_DYNAMIC_LINK
#include "DynoHelp.h"
/*______________________________________________________________________
| |
| Gobal Local Variables |
|_____________________________________________________________________*/
HAB hAB;
/*____________________________________________________________________
| |
| Function Prototypes. |
|____________________________________________________________________*/
MRESULT EXPENTRY AppWndProc(HWND hwndClient,ULONG ulMsg,MPARAM mpParm1, MPARAM mpParm2);
INT _System ProcessTest ( USHORT *);
HSWITCH AddTask (HWND hWndDlg, CHAR *szSwitchTitle, USHORT usID);
BOOL LoadDLLS( VOID );
/*___________________________________________________________________________
| |
| Function: Main |
| |
| Description: Main function |
| |
| Return: SHORT |
| |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| C H A N G E L O G |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| |
| PRG. DATE DESCRIPTION |
| ---- ---------- --------------------------------------------------- |
| RATAJIK 10-01-1994 Initial Developement |
|___________________________________________________________________________*/
main(int argc, char *argv[])
{
HMQ hMQ;
hAB = WinInitialize(0); /* Init the process for PM */
hMQ = WinCreateMsgQueue(hAB, 0); /* Create a Message queue */
/*____________________________________
| |
| Start the test DLG. |
| |
|____________________________________*/
WinDlgBox(HWND_DESKTOP,
HWND_DESKTOP,
AppWndProc,
0,
DLG_APP_TEST,
(PVOID)NULL);
return(0);
}
/*___________________________________________________________________________
| |
| Function: AppWndProc |
| |
| Description: Test window proc to test PowerThreads |
| |
| Return: SHORT |
| |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| C H A N G E L O G |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| |
| PRG. DATE DESCRIPTION |
| ---- ---------- --------------------------------------------------- |
| RATAJIK 10-01-1994 Initial Developement |
|___________________________________________________________________________*/
MRESULT EXPENTRY AppWndProc(HWND hWndDlg, ULONG msg, MPARAM mp1, MPARAM mp2)
{
USHORT usTotal;
CHAR szTmp[250];
switch (msg)
{
case WM_INITDLG:
/*____________________________________
| |
| NOTE: This version of Dynohelp is |
| pre-BETA. I will be releasing a |
| toolkit of this, among other things |
| at a later time. THING WILL CHANGE |
| BETWEEN THIS VERSION AND THE NEXT! |
| (So use at your own risk... |
|____________________________________*/
/*____________________________________
| |
| Try and load the DYNOHELP DLL, and |
| resolve the address. If we can't, |
| it's okay, just don't use dynohelp..|
|____________________________________*/
if(LoadDLLS())
{
/*____________________________________
| |
| Set up the dynamic help for |
| everything. |
|____________________________________*/
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, PB_THREAD_1 ), HTX_PB_THREAD_1 , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, hWndDlg , HTX_DLG_APP_TEST , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, PB_THREAD_2 ), HTX_PB_THREAD_2 , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, PB_THREAD_3 ), HTX_PB_THREAD_3 , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, PB_NO_THREAD ), HTX_PB_NO_THREAD , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, EF_NUMBER ), HTX_EF_NUMBER , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_INFO ), HTX_TX_INFO , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_APP_NAME ), HTX_TX_APP_NAME , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_COPYRIGHT ), HTX_TX_COPYRIGHT , TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_CONTACT_INFO1), HTX_TX_CONTACT_INFO, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_CONTACT_INFO2), HTX_TX_CONTACT_INFO, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_CONTACT_INFO3), HTX_TX_CONTACT_INFO, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, TX_CONTACT_INFO4), HTX_TX_CONTACT_INFO, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, FID_SYSMENU ), HTX_FID_SYSMENU, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, FID_TITLEBAR), HTX_FID_TITLEBAR, TX_HELP, TRUE);
DynoCreateHelp(hWndDlg, WinWindowFromID(hWndDlg, FID_MINMAX ), HTX_FID_MINMAX, TX_HELP, TRUE);
}
AddTask(hWndDlg, "PowerThreads Test", DLG_APP_TEST);
WinSetDlgItemText(hWndDlg, TX_INFO, POWER_INFO);
WinSetDlgItemText(hWndDlg, EF_NUMBER, "5");
break;
case WM_CLOSE:
/*____________________________________
| |
| Remove help from all of the controls|
| (Dynohelp is Dynamic, so it won't |
| cause a problem if the control is |
| still visible after the help has |
| been removed. |
|____________________________________*/
WinSendMsg(hWndDlg, WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_1 ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_2 ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_3 ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, PB_NO_THREAD ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, EF_NUMBER ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_INFO ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_APP_NAME ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_COPYRIGHT ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_CONTACT_INFO1), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_CONTACT_INFO2), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_CONTACT_INFO3), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, TX_CONTACT_INFO4), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, FID_SYSMENU ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, FID_TITLEBAR ), WM_DYNO_DELETE, 0, 0);
WinSendMsg(WinWindowFromID(hWndDlg, FID_MINMAX ), WM_DYNO_DELETE, 0, 0);
WinDismissDlg(hWndDlg, TRUE);
break;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1))
{
case PB_THREAD_1:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, (PSHORT)&usTotal, FALSE);
/*____________________________________
| |
| Show what DynoHelp can do... (Change|
| text of help item, before thread, |
| and then change it back when it's |
| done.) |
|____________________________________*/
strcpy(szTmp, HTX_PB_THREAD_1);
strcat(szTmp, " (again)");
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_1 ), WM_DYNO_CHANGE, (MPARAM)szTmp, 0);
/*____________________________________
| |
| Call the ProcessTest function, |
| using usTotal as the parm, via |
| the PowerHABCall. This function call|
| will not return until PocessTest |
| is finished. |
|____________________________________*/
PowerHABCall(hAB, ProcessTest, (PVOID)&usTotal);
WinMessageBox(HWND_DESKTOP,
hWndDlg,
"The thread has finished processing.",
"Thread - Type 1",
0,
MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
/*____________________________________
| |
| Change the help text back to what |
| it was. |
|____________________________________*/
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_1 ), WM_DYNO_CHANGE, (MPARAM)HTX_PB_THREAD_1, 0);
return (MPARAM)(TRUE);
break;
case PB_THREAD_2:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, (PSHORT)&usTotal, FALSE);
/*____________________________________
| |
| Show what DynoHelp can do... (Change|
| text of help item, before thread, |
| and then change it back when it's |
| done.) |
|____________________________________*/
strcpy(szTmp, HTX_PB_THREAD_2);
strcat(szTmp, " (again)");
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_2 ), WM_DYNO_CHANGE, (MPARAM)szTmp, 0);
/*____________________________________
| |
| Call the ProcessTest function, |
| using usTotal as the parm, via |
| the PowerCall. This function call |
| will not return until PocessTest |
| is finished. |
|____________________________________*/
PowerCall(ProcessTest, (PVOID)&usTotal);
WinMessageBox(HWND_DESKTOP,
hWndDlg,
"The thread has finished processing.",
"Thread - Type 2",
0,
MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
/*____________________________________
| |
| Change the help text back to what |
| it was. |
|____________________________________*/
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_2 ), WM_DYNO_CHANGE, (MPARAM)HTX_PB_THREAD_2, 0);
return (MPARAM)(TRUE);
break;
case PB_THREAD_3:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, (PSHORT)&usTotal, FALSE);
/*____________________________________
| |
| Show what DynoHelp can do... (Change|
| text of help item, before thread, |
| and then change it back when it's |
| done.) |
|____________________________________*/
strcpy(szTmp, HTX_PB_THREAD_3);
strcat(szTmp, " (again)");
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_3 ), WM_DYNO_CHANGE, (MPARAM)szTmp, 0);
/*____________________________________
| |
| Call the ProcessTest function, |
| using usTotal as the parm, via |
| the PowerCall. This function call |
| will not return until PocessTest |
| is finished. |
|____________________________________*/
PowerCall2(ProcessTest, (PVOID)&usTotal);
WinMessageBox(HWND_DESKTOP,
hWndDlg,
"The thread has finished processing.",
"Thread - Type 3",
0,
MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
/*____________________________________
| |
| Change the help text back to what |
| it was. |
|____________________________________*/
WinSendMsg(WinWindowFromID(hWndDlg, PB_THREAD_3 ), WM_DYNO_CHANGE, (MPARAM)HTX_PB_THREAD_3, 0);
return (MPARAM)(TRUE);
break;
case PB_NO_THREAD:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, (PSHORT)&usTotal, FALSE);
/*____________________________________
| |
| Call the ProcessTest function, |
| using usTotal as the parm. It will |
| lock up the desktop, until it |
| returns. |
|____________________________________*/
ProcessTest(&usTotal);
WinMessageBox(HWND_DESKTOP,
hWndDlg,
"The function call has finished processing.",
"No Thread",
0,
MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
return (MPARAM)(TRUE);
break;
case DID_CANCEL:
WinDismissDlg(hWndDlg, TRUE);
break;
}
break;
}
return WinDefDlgProc(hWndDlg,
msg,
mp1,
mp2);
}
/*__________________________________________________________________________
| |
| Function: ProcessTest |
| |
| Description: Stub function to demo the differct threaded/no-threading |
| calls. The function you pass to the threading calls should |
| be define as: |
| |
| <Ret Value> pascal <FunctionName>(<Parm List>) |
| |
| When calling though the PowerThread, you can do just |
| about anything you can do when it's non-threaded. Remember, |
| if you want to do any WinSendMsg (or any other Win calls, |
| excluding WinPostMsg), you'll need to create a message |
| queue for this thread. |
| |
| Return: SHORT |
| |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| C H A N G E L O G |
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| |
| PRG. DATE DESCRIPTION |
| ---- ---------- --------------------------------------------------- |
| RATAJIK 10-01-1994 Initial Developement |
|__________________________________________________________________________*/
INT _System ProcessTest(USHORT *pusTest)
{
INT j = *pusTest;
/*____________________________________
| |
| Loop through j times, sleeping and |
| beeping. When called directly, this|
| function will lock PM up. When |
| called through the threads, it |
| won't! (How cool!) |
|____________________________________*/
while(j)
{
j--;
DosSleep(1500L);
DosBeep(101,1);
}
}
HSWITCH AddTask(HWND hWndDlg, CHAR *szSwitchTitle, USHORT usID)
{
SWCNTRL swctlSwitchList;
PID pid;
WinQueryWindowProcess(hWndDlg, &pid, NULL);
strcpy(swctlSwitchList.szSwtitle, szSwitchTitle);
swctlSwitchList.hwnd = hWndDlg;
swctlSwitchList.hwndIcon = (HWND)usID;
swctlSwitchList.hprog = (ULONG)NULL;
swctlSwitchList.idProcess = pid;
swctlSwitchList.idSession = (USHORT)0;
swctlSwitchList.uchVisibility = SWL_VISIBLE;
swctlSwitchList.fbJump = SWL_JUMPABLE;
return(WinAddSwitchEntry(&swctlSwitchList));
}
/*__________________________________________________________________________
| |
| Function: Dynamically Load the PM-superset stuff |
| |
| Decription: |
| |
|Creation Date: 8-18-94 Written By: Greg Ratajik |
| |
| Notes: |
| |
|__________________________________________________________________________*/
BOOL LoadDLLS( VOID )
{
APIRET apiRet;
CHAR szFailName[CCHMAXPATH];
CHAR szError[CCHMAXPATH];
CHAR szTmp[CCHMAXPATH];
HMODULE hmodDyno;
USHORT usVersion;
DynoCreateHelp = NULL;
memset(szError, 0, sizeof(szError));
if((apiRet = DosLoadModule( szFailName, /* failure name buffer */
sizeof( szFailName ), /* size of failure name buffer */
DYNO_MODULE_NAME, /* module name */
&hmodDyno))) /* address of handle */
{
strcpy(szTmp, DYNO_MODULE_NAME);
sprintf(szTmp, "(Load Error code #%u) %s, \n", apiRet, szFailName);
strcat(szError, szTmp);
}
else
{
if((apiRet = DosQueryProcAddr(hmodDyno,
0,
DYNO_VERSION_NAME,
&DynoGetVersion)))
{
sprintf(szTmp, "(Get Function Error code #%u) %s, \n", apiRet, DYNO_VERSION_NAME);
strcat(szError, szTmp);
}
else
{
usVersion = DynoGetVersion();
if(usVersion != DYNO_MAJOR_VERSION)
{
sprintf(szTmp, "(Version Mismatch on DLL) DYNOHELP.DLL Version = %u, EasyCD uses Version %u, \n", usVersion, DYNO_MAJOR_VERSION);
strcat(szError, szTmp);
}
else
{
if((apiRet = DosQueryProcAddr(hmodDyno,
0,
DYNO_CREATE_NAME,
&DynoCreateHelp)))
{
sprintf(szTmp, "(Get Function Error code #%u) %s, \n", apiRet, DYNO_CREATE_NAME);
strcat(szError, szTmp);
}
}
}
}
if(szError[0] != 0)
{
PCHAR tmp;
CHAR szTmp[600];
if(tmp = strrchr(szError, ','))
*tmp = '.';
strcat(szError, "\n");
strcpy(szTmp, "PowerCalls TEST was unable to load a DLL. ");
strcat(szTmp, "The errors returned while loading/initilizing where:\n\n");
strcat(szTmp, szError);
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
szTmp,
"Load Error",
0,
MB_OK|MB_ICONEXCLAMATION);
return(FALSE);
}
return(TRUE);
}