home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
mag&info
/
msjv7_6.zip
/
TOPTEN.ARJ
/
PASSMSG.ARJ
/
PASSMSG.C
< prev
next >
Wrap
Text File
|
1992-10-01
|
8KB
|
278 lines
#include <windows.h>
#include "basedefs.h"
#include "passmsg.h"
WINPROC WndProc ( WINDOWS_PARAMS );
WINPROC FormWndProc ( WINDOWS_PARAMS );
/**************************************************************
* *
* Global Variables *
* *
**************************************************************/
HANDLE ghInst;
HWND ghWnd;
HWND ghWndChild;
char szNullString[] = "";
char szAppName[] = "BASE1";
char szChildName[] = "Ben";
char szMoveMe[] = "Move Me!";
/**************************************************************
* *
* WinMain *
* *
**************************************************************/
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
MSG msg ;
WNDCLASS wndclass ;
int dx ;
HBRUSH hFormBrush ;
HBITMAP hFormBM ;
dx = 24;
while ((!SetMessageQueue(dx)) && (dx >= 8)) dx--;
hFormBM = LoadBitmap ( hInstance, "FORM" );
hFormBrush = CreatePatternBrush ( hFormBM );
DeleteObject ( hFormBM );
if (!hPrevInstance)
{
// Register the Parent Window
wndclass.style = CS_BYTEALIGNCLIENT;
wndclass.lpfnWndProc = (WNDPROC)WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = hFormBrush;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
return FALSE;
// Register the Child Window
wndclass.style = CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)FormWndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor (hInstance, "HAND" );
wndclass.hbrBackground = GetStockObject ( LTGRAY_BRUSH ) ;
wndclass.lpszMenuName = (LPSTR)NULL;
wndclass.lpszClassName = szChildName ;
if (!RegisterClass (&wndclass))
return FALSE;
}
ghInst = hInstance;
ghWnd = CreateWindow (szAppName, "PASSMSG Sample",
WS_OVERLAPPEDWINDOW,
GetSystemMetrics ( SM_CXSCREEN ) /4,
GetSystemMetrics ( SM_CYSCREEN ) /4,
GetSystemMetrics ( SM_CXSCREEN ) /2,
GetSystemMetrics ( SM_CYSCREEN ) /2,
NULL, NULL, hInstance, NULL) ;
ghWndChild = CreateWindow (szChildName, szNullString,
WS_CHILD | WS_BORDER | WS_THICKFRAME | WS_VISIBLE,
10, 10,
100, 100,
ghWnd, NULL, hInstance, NULL) ;
ShowWindow ( ghWnd, nCmdShow );
UpdateWindow ( ghWnd );
while (GetMessage((LPMSG)&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeleteObject ( hFormBrush );
return msg.wParam ;
}
/*********************************************************************
* *
* WndProc: Main Message Translator *
* *
*********************************************************************/
WINPROC WndProc ( WINDOWS_PARAMS )
{
static BOOL bDragging;
static POINT ptLastPos;
switch ( msg )
{
case WM_LBUTTONDOWN:
ptLastPos.x = LOWORD ( lParam);
ptLastPos.y = HIWORD ( lParam);
ptLastPos.x = LOWORD ( lParam ) - LOWORD ( lParam )%8;
ptLastPos.y = HIWORD ( lParam ) - HIWORD ( lParam )%8;
if (ChildWindowFromPoint(hWnd, ptLastPos) != hWnd) // must be the child!
{
SetCapture ( hWnd );
bDragging = TRUE;
}
break;
case WM_LBUTTONUP:
if (bDragging)
{
InvalidateRect ( ghWndChild, NULL, TRUE );
ReleaseCapture ( );
bDragging = FALSE;
}
break;
case WM_MOUSEMOVE:
if (bDragging)
{
POINT ptNew;
ptNew.x = LOWORD ( lParam ) - LOWORD ( lParam )%8;
ptNew.y = HIWORD ( lParam ) - HIWORD ( lParam )%8;
if (
( ptNew.x != ptLastPos.x )
||
( ptNew.y != ptLastPos.y )
)
{
POINT ptTopLeft;
// Figure out current position of Child window
ptTopLeft.x = 0 - GetSystemMetrics ( SM_CXFRAME );
ptTopLeft.y = 0 - GetSystemMetrics ( SM_CYFRAME );
ClientToScreen ( ghWndChild, &ptTopLeft );
ScreenToClient ( hWnd, &ptTopLeft );
// Move child Window to new spot
SetWindowPos (ghWndChild,
NULL,
ptTopLeft.x + (ptNew.x-ptLastPos.x),
ptTopLeft.y + (ptNew.y-ptLastPos.y),
NULL,
NULL,
SWP_NOSIZE | SWP_NOZORDER
);
InvalidateRect (ghWndChild, NULL, TRUE );
UpdateWindow (ghWndChild);
ptLastPos = ptNew;
}
}
break;
case WM_CREATE :
break;
case WM_DESTROY :
PostQuitMessage (0) ;
break ;
default :
return DefWindowProc ( hWnd, msg, wParam, lParam );
}
return 0L ;
}
/*********************************************************************
* *
* *
* *
*********************************************************************/
WINPROC FormWndProc ( WINDOWS_PARAMS )
{
POINT pt;
HDC hDC;
PAINTSTRUCT ps;
RECT rc;
switch ( msg )
{
case WM_ERASEBKGND: // Eat this message to avoid flicker
break;
case WM_CREATE :
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
// Pass all mouse messages on through to parent, in parent coordinates
pt.x = LOWORD ( lParam );
pt.y = HIWORD ( lParam );
ClientToScreen ( hWnd, &pt );
ScreenToClient ( GetParent(hWnd), &pt );
PostMessage ( ghWnd, msg, wParam, MAKELONG (pt.x, pt.y ));
break;
case WM_PAINT:
// Just draw a simple little something centered in the window with nice
hDC = BeginPaint ( hWnd, &ps );
GetClientRect ( hWnd, &rc );
SetBkColor ( hDC, RGB ( 0, 0, 128 ));
SetTextColor ( hDC, RGB ( 255, 255, 0 ));
pt.x = (rc.right - LOWORD (GetTextExtent ( hDC, szMoveMe, lstrlen(szMoveMe))))/2;
pt.y = (rc.bottom - HIWORD (GetTextExtent ( hDC, szMoveMe, lstrlen(szMoveMe))))/2;
ExtTextOut ( hDC, pt.x, pt.y, ETO_OPAQUE, &rc, szMoveMe, lstrlen (szMoveMe), NULL );
EndPaint ( hWnd, &ps );
break;
default :
return DefWindowProc ( hWnd, msg, wParam, lParam );
}
return 0L ;
}