home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Pier Shareware 6
/
The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso
/
046
/
dosq1194.exe
/
WINPOST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-01
|
5KB
|
169 lines
/*
* WinPost demonstrates how a Windows app can receive and process messages
* from an MS-DOS app running in another VM.
*/
#include <windows.h>
#include <memory.h>
#include <dos.h>
#define Device_ID 0x4321
long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
void FAR PASCAL CallbackProc (HWND, WORD, WORD, LONG);
//
// The following statement places the callback procedure in the segment
// named CALLBACKSEG, which is defined as fixed and nondiscardable in the
// program's module definition file.
//
#pragma alloc_text (CALLBACKSEG, CallbackProc)
/*
* Function WinMain.
*/
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
static char szAppName[] = "WinPost";
WNDCLASS wc;
HWND hwnd;
MSG msg;
if (!hPrevInstance) {
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
RegisterClass (&wc);
}
hwnd = CreateWindow (szAppName, szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_DESKTOP, NULL, hInstance, NULL);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
/*
* WndProc processes messages to the main window.
*/
long FAR PASCAL WndProc (HWND hwnd, WORD msg, WORD wParam, LONG lParam)
{
RECT rect;
static HWND hwndListbox;
static FARPROC fpVxd;
struct _SREGS sregs;
union _REGS regs;
char szBuffer[64];
DWORD dwCallback;
switch (msg) {
case WM_CREATE:
//
// Make sure we're in 386 enhanced mode.
//
if (GetWinFlags () & WF_ENHANCED == 0) {
MessageBox (hwnd, "This application must be run in 386 "\
"enhanced mode", "Error", MB_OK);
return -1;
}
//
// Get the protected mode entry point address and fail the
// application if the POSTMSG VxD is not loaded.
//
memset (&sregs, 0, sizeof (sregs));
regs.x.ax = 0x1684;
regs.x.bx = Device_ID;
_int86x (0x2F, ®s, ®s, &sregs);
_FP_SEG (fpVxd) = sregs.es;
_FP_OFF (fpVxd) = regs.x.di;
if (!fpVxd) {
MessageBox (hwnd, "The POSTMSG VxD is not loaded",
"Error", MB_OK);
return -1;
}
//
// Register this application with the POSTMSG VxD.
//
dwCallback = (DWORD) CallbackProc;
__asm mov ax, hwnd
__asm mov bx, word ptr [dwCallback + 0]
__asm mov cx, word ptr [dwCallback + 2]
(*fpVxd) ();
//
// Create a list box that fills the window's client area.
//
GetClientRect (hwnd, &rect);
hwndListbox = CreateWindow ("listbox", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NOINTEGRALHEIGHT,
0, 0, rect.right, rect.bottom, hwnd, 100,
(HINSTANCE) (((LPCREATESTRUCT) lParam)->hInstance), NULL);
return 0;
case WM_SIZE:
//
// Resize the list box when the main window is resized.
//
if ((wParam == SIZE_RESTORED) || (wParam == SIZE_MAXIMIZED)){
MoveWindow (hwndListbox, 0, 0, LOWORD (lParam),
HIWORD (lParam), TRUE);
return 0;
}
break;
case WM_USER + 0x100:
//
// Display the message parameters in the list box.
//
wsprintf (szBuffer, "msg=%u, wParam=%u, lParam=%lu",
msg, wParam, lParam);
SendMessage (hwndListbox, LB_ADDSTRING, 0,
(LPARAM) (LPCSTR) szBuffer);
return 0;
case WM_DESTROY:
//
// Terminate the application.
//
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, msg, wParam, lParam);
}
/*
* CallbackProc gets called by the POSTMSG VxD, and in turn calls
* PostMessage to post a message to WndProc.
*/
void FAR PASCAL CallbackProc (HWND hwnd, WORD msg, WORD wParam, LONG lParam)
{
PostMessage (hwnd, msg, wParam, lParam);
}