home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pwr16.zip
/
TEST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-07
|
12KB
|
248 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 */
/*______________________________________________________________________
| |
| System Includes |
|_____________________________________________________________________*/
#define _MT
#include <os2.h> /* Base OS/2 Include */
#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 */
/*______________________________________________________________________
| |
| Gobal Local Variables |
|_____________________________________________________________________*/
HAB hAB;
/*____________________________________________________________________
| |
| Function Prototypes. |
|____________________________________________________________________*/
MRESULT EXPENTRY AppWndProc(HWND hwndClient,USHORT ulMsg,MPARAM mpParm1, MPARAM mpParm2);
VOID _pascal far ProcessTest ( USHORT *);
/*___________________________________________________________________________
| |
| 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 |
|___________________________________________________________________________*/
SHORT cdecl 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, USHORT msg, MPARAM mp1, MPARAM mp2)
{
USHORT usTotal;
switch (msg)
{
case WM_INITDLG:
WinSetDlgItemText(hWndDlg, TX_INFO, POWER_INFO);
WinSetDlgItemText(hWndDlg, EF_NUMBER, "5");
break;
case WM_CLOSE:
WinDismissDlg(hWndDlg, TRUE);
break;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1))
{
case PB_THREAD_1:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, &usTotal, FALSE);
/*____________________________________
| |
| 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);
return (MPARAM)(TRUE);
break;
case PB_THREAD_2:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, &usTotal, FALSE);
/*____________________________________
| |
| 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);
return (MPARAM)(TRUE);
break;
case PB_NO_THREAD:
WinQueryDlgItemShort(hWndDlg, EF_NUMBER, &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 far <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 |
|__________________________________________________________________________*/
VOID pascal far 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);
}
}