WinNT-Templates: Data Structures

  • Main Page
  • Data Structures
  • Files
  • Directories
  • Data Structures
  • Data Structure Index
  • Data Fields

Data Structures

Here are the data structures with brief descriptions:
_CMD
_CMDI
_DISK_RESOURCES_CONNECTABLE
_ENUMLISTOBJECT
_ENUMNODE
_ENUMOBJECT
_ENUMSYNC
_MSD
_MSDI
_MYHOOKDATA
_PerWndInfo
_TLSOBJECT
CHAINLIST
EVENTHEADER_STRUCT
GLOBAL_STRUCT
growmemory
memory
RGNSTRUCT
tagApplets
tagControlText
tagCOPYDATASTRUCT
tagExtraBytes
tagLookupEntry
tagMYREC
tagSUBTABLE
tagTABLE
tagTHREADPBLOCK
tagTrackObject
tagWIN32SINFO
TRACKRECTSTRUCT
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _CMD Struct Reference

  • Directories
  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_CMD Struct Reference

#include "GLOBALS.H"

Data Fields

PFNCMD pfncmd
WORD wCommand

Detailed Description

Definition at line 216 of file GLOBALS.H.

Field Documentation

PFNCMD pfncmd

Definition at line 219 of file GLOBALS.H.

WORD wCommand

Definition at line 218 of file GLOBALS.H.

The documentation for this struct was generated from the following files:
  • NETDDE/GLOBALS.H
  • SERVENUM/DEMO/GLOBALS.H
  • SERVENUM/DLL/DLLDISP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _CMDI Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_CMDI Struct Reference

#include "GLOBALS.H"

Data Fields

int ccmd
EDWP edwp
CMD * rgcmd

Detailed Description

Definition at line 225 of file GLOBALS.H.

Field Documentation

int ccmd

Definition at line 227 of file GLOBALS.H.

EDWP edwp

Definition at line 229 of file GLOBALS.H.

CMD * rgcmd

Definition at line 228 of file GLOBALS.H.

The documentation for this struct was generated from the following files:
  • NETDDE/GLOBALS.H
  • SERVENUM/DEMO/GLOBALS.H
  • SERVENUM/DLL/DLLDISP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _DISK_RESOURCES_CONNECTABLE Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_DISK_RESOURCES_CONNECTABLE Struct Reference

Data Fields

LPTSTR | lpComment
LPTSTR | lpProvider
LPTSTR | lpRemoteName

Detailed Description

Definition at line 133 of file WINNET.C.

Field Documentation

LPTSTR lpComment

Definition at line 136 of file WINNET.C.

LPTSTR lpProvider

Definition at line 137 of file WINNET.C.

LPTSTR lpRemoteName

Definition at line 135 of file WINNET.C.

The documentation for this struct was generated from the following file:
  • WINNET/WINNET.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _ENUMLISTOBJECT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_ENUMLISTOBJECT Struct Reference

#include "ENUMUTIL.H"

Data Fields

UINT nItem
ENUMOBJECT Object

Detailed Description

Definition at line 64 of file ENUMUTIL.H.

Field Documentation

UINT nItem

Definition at line 66 of file ENUMUTIL.H.

ENUMOBJECT Object

Definition at line 67 of file ENUMUTIL.H.

The documentation for this struct was generated from the following file:
  • SERVENUM/DLL/ENUMUTIL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _ENUMNODE Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_ENUMNODE Struct Reference

#include "ENUMUTIL.H"

Data Fields

DWORD cChild
struct _ENUMNODE * | lpChild
LPNETRESOURCE | lpNet
UINT | ndxBmp

Detailed Description

Definition at line 37 of file ENUMUTIL.H.

Field Documentation

DWORD cChild

Definition at line 41 of file ENUMUTIL.H.

struct _ENUMNODE* lpChild

Definition at line 42 of file ENUMUTIL.H.

LPNETRESOURCE lpNet

Definition at line 40 of file ENUMUTIL.H.

UINT ndxBmp

Definition at line 39 of file ENUMUTIL.H.

The documentation for this struct was generated from the following file:
  • SERVENUM/DLL/ENUMUTIL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _ENUMOBJECT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_ENUMOBJECT Struct Reference

#include "ENUMUTIL.H"

Data Fields

LPENUMNODE lpNode
LPENUMSYNC lpSync

Detailed Description

Definition at line 57 of file ENUMUTIL.H.

Field Documentation

LPENUMNODE lpNode

Definition at line 60 of file ENUMUTIL.H.

LPENUMSYNC lpSync

Definition at line 59 of file ENUMUTIL.H.

The documentation for this struct was generated from the following file:
  • SERVENUM/DLL/ENUMUTIL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _ENUMSYNC Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_ENUMSYNC Struct Reference

#include "ENUMUTIL.H"

Data Fields

DWORD cNetBuf
CRITICAL_SECTION | cs
DWORD cThread
HANDLE | hwnd
LPNETRESOURCE * | lplpnetBuf
LPENUMNODE lpRoot

Detailed Description

Definition at line 46 of file ENUMUTIL.H.

Field Documentation

DWORD cNetBuf

Definition at line 50 of file ENUMUTIL.H.

CRITICAL_SECTION cs

Definition at line 53 of file ENUMUTIL.H.

DWORD cThread

Definition at line 49 of file ENUMUTIL.H.

HANDLE hwnd

Definition at line 48 of file ENUMUTIL.H.

LPNETRESOURCE* lplpnetBuf

Definition at line 51 of file ENUMUTIL.H.

LPENUMNODE lpRoot

Definition at line 52 of file ENUMUTIL.H.

The documentation for this struct was generated from the following file:
  • SERVENUM/DLL/ENUMUTIL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _MSD Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_MSD Struct Reference

#include "GLOBALS.H"

Data Fields

PFNMSG pfnmsg
UINT uMessage

Detailed Description

Definition at line 199 of file GLOBALS.H.

Field Documentation

PFNMSG pfnmsg

Definition at line 202 of file GLOBALS.H.

UINT uMessage

Definition at line 201 of file GLOBALS.H.

The documentation for this struct was generated from the following files:
  • NETDDE/GLOBALS.H
  • SERVENUM/DEMO/GLOBALS.H
  • SERVENUM/DLL/DLLDISP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _MSDI Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_MSDI Struct Reference

#include "GLOBALS.H"

Data Fields

int cmsd
EDWP edwp
MSD * rgmsd

Detailed Description

Definition at line 208 of file GLOBALS.H.

Field Documentation

int cmsd

Definition at line 210 of file GLOBALS.H.

EDWP edwp

Definition at line 212 of file GLOBALS.H.

MSD * rgmsd

Definition at line 211 of file GLOBALS.H.

The documentation for this struct was generated from the following files:
  • NETDDE/GLOBALS.H
  • SERVENUM/DEMO/GLOBALS.H
  • SERVENUM/DLL/DLLDISP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _MYHOOKDATA Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_MYHOOKDATA Struct Reference

Data Fields

HHOOK | hhook
HOOKPROC | hkprc
int | nType

Detailed Description

Definition at line 21 of file HOOKTEST.C.

Field Documentation

HHOOK hhook

Definition at line 24 of file HOOKTEST.C.

HOOKPROC hkprc

Definition at line 23 of file HOOKTEST.C.

int nType

Definition at line 22 of file HOOKTEST.C.

The documentation for this struct was generated from the following file:
  • HOOKS/HOOKTEST.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _PerWndInfo Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_PerWndInfo Struct Reference

#include "MDITYPES.H"

Data Fields

BOOL | bClrCycle
BOOL | bDrawing
BOOL | bMandel
BOOL | bSetDIBsToDevice
BOOL | bStretch
double | c1
double | c2
char | CaptionBarText [SIZEOFCAPTIONTEXT]
DWORD dwElapsed
DWORD dwThreadId
HBITMAP | hBmpSaved
HPALETTE | hHTPal
HPALETTE | hPal
HWND | hParent
HWND | hTextWnd
HANDLE | hThrd
HWND | hwnd
int | iIteration
INT | iPen
int | iStep
int | iStretchMode
LONG | lc1
LONG | lc2
LONG | lxFrom
LONG | lxTo
LONG | lyFrom
LONG | lyTo
PVOID * | prghPen
RECT | rcClient
char | szSavef [MAXPATHLEN]
double | xFrom
double | xTo
double | yFrom
double | yTo

Detailed Description

Definition at line 43 of file MDI.C.

Field Documentation

BOOL bClrCycle

Definition at line 81 of file FRACTAL.H.

BOOL bDrawing

Definition at line 54 of file FRACTAL.H.

BOOL bMandel

Definition at line 70 of file FRACTAL.H.

BOOL bSetDIBsToDevice

Definition at line 75 of file FRACTAL.H.

BOOL bStretch

Definition at line 73 of file FRACTAL.H.

double c1

Definition at line 61 of file FRACTAL.H.

double c2

Definition at line 62 of file FRACTAL.H.

char CaptionBarText

Definition at line 47 of file MDI.C.

DWORD dwElapsed

Definition at line 56 of file FRACTAL.H.

DWORD dwThreadId

Definition at line 55 of file FRACTAL.H.

HBITMAP hBmpSaved

Definition at line 69 of file FRACTAL.H.

HPALETTE hHTPal

Definition at line 77 of file FRACTAL.H.

HPALETTE hPal

Definition at line 76 of file FRACTAL.H.

HWND hParent

Definition at line 44 of file MDI.C.

HWND hTextWnd

Definition at line 45 of file MDI.C.

HANDLE hThrd

Definition at line 53 of file FRACTAL.H.

HWND hwnd

Definition at line 52 of file FRACTAL.H.

int iIteration

Definition at line 71 of file FRACTAL.H.

INT iPen

Definition at line 79 of file FRACTAL.H.

int iStep

Definition at line 72 of file FRACTAL.H.

int iStretchMode

Definition at line 74 of file FRACTAL.H.

LONG lc1

Definition at line 67 of file FRACTAL.H.

LONG lc2

Definition at line 68 of file FRACTAL.H.

LONG lxFrom

Definition at line 63 of file FRACTAL.H.

LONG lxTo

Definition at line 64 of file FRACTAL.H.

LONG lyFrom

Definition at line 65 of file FRACTAL.H.

LONG lyTo

Definition at line 66 of file FRACTAL.H.

PVOID* prghPen

Definition at line 78 of file FRACTAL.H.

RECT rcClient

Definition at line 46 of file MDI.C.

char szSavef[MAXPATHLEN]

Definition at line 80 of file FRACTAL.H.

double xFrom

Definition at line 57 of file FRACTAL.H.

double xTo

Definition at line 58 of file FRACTAL.H.

double yFrom

Definition at line 59 of file FRACTAL.H.

double yTo

Definition at line 60 of file FRACTAL.H.

The documentation for this struct was generated from the following files:
  • MDI_/MDI.C
  • MDI_/MDITYPES.H
  • NTSD/MDI.C
  • NTSD/MDITYPES.H
  • SCRNSAVE/FRACTAL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: _TLSOBJECT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

_TLSOBJECT Struct Reference

#include "ENUMUTIL.H"

Data Fields

HBITMAP | hbmpArray [HIGHLIGHT_NDX *2]
HBRUSH | hbrushHL
HFONT | hfont
LPDWORD | lpcchServer
FARPROC lpfnHelpProc
WNDPROC | lpfnListProc
LPENUMSYNC lpSync
LPWSTR | lpszServer
TEXTMETRIC | tm

Detailed Description

Definition at line 71 of file ENUMUTIL.H.

Field Documentation

HBITMAP hbmpArray[HIGHLIGHT_NDX *2]

Definition at line 75 of file ENUMUTIL.H.

HBRUSH hbrushHL

Definition at line 77 of file ENUMUTIL.H.

HFONT hfont

Definition at line 76 of file ENUMUTIL.H.

LPDWORD lpcchServer

Definition at line 84 of file ENUMUTIL.H.

FARPROC lpfnHelpProc

Definition at line 85 of file ENUMUTIL.H.

WNDPROC lpfnListProc

Definition at line 81 of file ENUMUTIL.H.

LPENUMSYNC lpSync

Definition at line 73 of file ENUMUTIL.H.

LPWSTR lpszServer

Definition at line 83 of file ENUMUTIL.H.

TEXTMETRIC tm

Definition at line 79 of file ENUMUTIL.H.

The documentation for this struct was generated from the following file:
  • SERVENUM/DLL/ENUMUTIL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CHAINLIST Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Public Member Functions | Data Fields

CHAINLIST Struct Reference

#include "SHRSTUFF.H"

Public Member Functions

struct CHAINLIST | __based (clBasePt)*clNext

Data Fields

int | iElement

Detailed Description

Definition at line 22 of file SHRSTUFF.H.

Member Function Documentation

struct CHAINLIST __based ( clBasePt ) [read]

Field Documentation

int iElement

Definition at line 23 of file SHRSTUFF.H.

The documentation for this struct was generated from the following file:
  • BPOINTER/SHRSTUFF.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: EVENTHEADER_STRUCT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

EVENTHEADER_STRUCT Struct Reference

Data Fields

DWORD BaseMsgTime
UINT | RecordedMsgCount
CHAR | Signature [7]

Detailed Description

Definition at line 37 of file RECHOOK.C.

Field Documentation

DWORD BaseMsgTime

Definition at line 40 of file RECHOOK.C.

UINT RecordedMsgCount

Definition at line 39 of file RECHOOK.C.

CHAR Signature[7]

Definition at line 38 of file RECHOOK.C.

The documentation for this struct was generated from the following file:
  • MINREC/RECHOOK.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLOBAL_STRUCT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

GLOBAL_STRUCT Struct Reference

Data Fields

DWORD BaseMsgTime
EVENTMSG | EventMsg
BOOL | fPlaying
BOOL | fRecording
BOOL | fStopPlaying
BOOL | fStopRecording
HWND | hDlgMain
HANDLE | hFile
HHOOK | hHookGetMsg
HHOOK | hHookPlayback
HHOOK | hHookRecord
HINSTANCE | hInstance
HANDLE | hMutex
DWORD LastMsgTime
LPCTSTR | lpszApiFailedMsg
UINT | PlayedMsgCount
UINT | RecordedMsgCount

Detailed Description

Definition at line 29 of file MINREC.C.

Field Documentation

DWORD BaseMsgTime

Definition at line 51 of file RECHOOK.C.

EVENTMSG EventMsg

Definition at line 54 of file RECHOOK.C.

BOOL fPlaying

Definition at line 46 of file RECHOOK.C.

BOOL fRecording

Definition at line 45 of file RECHOOK.C.

BOOL fStopPlaying

Definition at line 48 of file RECHOOK.C.

BOOL fStopRecording

Definition at line 47 of file RECHOOK.C.

HWND hDlgMain

Definition at line 27 of file MINREC.C.

HANDLE hFile

Definition at line 53 of file RECHOOK.C.

HHOOK hHookGetMsg

Definition at line 57 of file RECHOOK.C.

HHOOK hHookPlayback

Definition at line 56 of file RECHOOK.C.

HHOOK hHookRecord

Definition at line 55 of file RECHOOK.C.

HINSTANCE hInstance

Definition at line 28 of file MINREC.C.

HANDLE hMutex

Definition at line 29 of file MINREC.C.

DWORD LastMsgTime

Definition at line 52 of file RECHOOK.C.

LPCTSTR lpszApiFailedMsg

Definition at line 30 of file MINREC.C.

UINT PlayedMsgCount

Definition at line 49 of file RECHOOK.C.

UINT RecordedMsgCount

Definition at line 50 of file RECHOOK.C.

The documentation for this struct was generated from the following files:
  • MINREC/MINREC.C
  • MINREC/RECHOOK.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: growmemory Class Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Public Member Functions | Private Attributes

growmemory Class Reference

#include "GUIGREP.H"

Public Member Functions

growmemory (int iInitSize, int iInc)
~growmemory (void)
BOOL | add (LPSTR lpSource, int iSize)
HANDLE | GetHandle (void)

Private Attributes

CRITICAL_SECTION | csAllocGuard
HANDLE | hCurrentBlock
int | iCurrentPt
int | iCurrentSize
int | iIncrement
int | ilpszCRLF
LPSTR lpStartPt
char | lpszCRLF [3]

Detailed Description

Definition at line 122 of file GUIGREP.H.

Constructor & Destructor Documentation

growmemory | ( | int | iInitSize,
 |  | int | iInc
 | ) |  |

Definition at line 163 of file GUIGREP.H.

       { iIncrement=iInc;
         iCurrentPt=0;
         iCurrentSize=iInitSize;
         hCurrentBlock = LocalAlloc(LMEM_MOVEABLE,iCurrentSize);
         InitializeCriticalSection(&csAllocGuard);
         strcpy(lpszCRLF,"\r\n");
         ilpszCRLF=strlen(lpszCRLF);
       }

~growmemory ( void )

Definition at line 172 of file GUIGREP.H.

       {DeleteCriticalSection(&csAllocGuard);
        LocalFree(hCurrentBlock);
       }

Member Function Documentation

BOOL add | ( | LPSTR | lpSource,
 |  | int | iSize |
 | ) |  |  | [inline]

Definition at line 133 of file GUIGREP.H.

                 : We assume that the requested size is never bigger than
   the increment. This is safe with the hardcoded values but may fail in
   the general case. */

       { int iSizeOld = iSize;
         EnterCriticalSection(&csAllocGuard);
/* adjust the size for the line feed to follow */
           iSize+=ilpszCRLF;
         if (iCurrentPt+iSize > iCurrentSize)
          {iCurrentSize+=iIncrement;
       hCurrentBlock = LocalReAlloc(hCurrentBlock,iCurrentSize,LMEM_MOVEABLE);
          };
          lpStartPt = (LPSTR)LocalLock(hCurrentBlock);
          if (!lpStartPt)
           { MessageBeep(0);
             return(FALSE);     };
          strncpy(&lpStartPt[iCurrentPt],lpSource,iSizeOld);
/* add the CRLF at the end. */
          strncpy(&lpStartPt[iCurrentPt+iSizeOld],lpszCRLF,ilpszCRLF);
          LocalUnlock(hCurrentBlock);
          iCurrentPt+=iSize;
          LeaveCriticalSection(&csAllocGuard);
          return(TRUE);
          };

HANDLE GetHandle ( void ) [inline]

Definition at line 158 of file GUIGREP.H.

      { return (hCurrentBlock);
      };

Field Documentation

CRITICAL_SECTION csAllocGuard [private]

Definition at line 127 of file GUIGREP.H.

HANDLE hCurrentBlock [private]

Definition at line 125 of file GUIGREP.H.

int iCurrentPt [private]

Definition at line 124 of file GUIGREP.H.

int iCurrentSize [private]

Definition at line 124 of file GUIGREP.H.

int iIncrement [private]

Definition at line 124 of file GUIGREP.H.

int ilpszCRLF [private]

Definition at line 129 of file GUIGREP.H.

LPSTR lpStartPt [private]

Definition at line 126 of file GUIGREP.H.

char lpszCRLF[3] [private]

Definition at line 128 of file GUIGREP.H.

The documentation for this class was generated from the following file:
  • GUIGREP/GUIGREP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: memory Class Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Public Member Functions | Private Attributes

memory Class Reference

#include "GUIGREP.H"

Public Member Functions

memory (int)
~memory (void)
LPSTR | Alloc (int iSize)
void | Free (LPSTR lpBlockPt)
void | Reset ()

Private Attributes

CRITICAL_SECTION | csAllocGuard
HANDLE | hBlock
int | iActualBlockSize
int | iCurrentPointer
LPSTR lpBasePointer
LPSTR lpCurrentPointer
LPSTR lpReturnPointer

Detailed Description

Definition at line 54 of file GUIGREP.H.

Constructor & Destructor Documentation

memory ( int iSize )

Definition at line 98 of file GUIGREP.H.

{
  hBlock = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,iSize);
  lpBasePointer = (LPSTR) LocalLock(hBlock);
  lpCurrentPointer = lpBasePointer;
  iActualBlockSize = iSize;
  iCurrentPointer = 0;
  InitializeCriticalSection(&csAllocGuard);
}

~memory ( void )

Definition at line 108 of file GUIGREP.H.

{ LocalUnlock(hBlock);
  LocalFree(hBlock);
  DeleteCriticalSection(&csAllocGuard);
}

Member Function Documentation

LPSTR Alloc ( int iSize ) [inline]

Definition at line 65 of file GUIGREP.H.

    {      EnterCriticalSection(&csAllocGuard);
#ifdef MIPS
  /* MIPS requires all DWORDs to be aligned on DWORD boundaries.
     That's why under MIPS, we round up all alignments to
     multiples of sizeof(DWORD).   */
     if (iSize != (int)((iSize / sizeof (DWORD)) * sizeof (DWORD)))
        iSize = (1 + (iSize / sizeof (DWORD))) * sizeof (DWORD);
#endif
       if (iSize + iCurrentPointer > iActualBlockSize)
    {               MessageBox(GetFocus(),"No memory left",
          "Grepper",MB_OK);
            return((LPSTR)0);
    };
    iCurrentPointer+= iSize;
    lpReturnPointer = lpCurrentPointer;
  _try {
    lpCurrentPointer = &lpCurrentPointer[iSize];
    }
    _except (EXCEPTION_EXECUTE_HANDLER) {
     MessageBox(GetFocus(),"Access Violation","Memory Allocator",MB_OK);
    };
    LeaveCriticalSection(&csAllocGuard);
    return (lpReturnPointer);
     };

void Free ( LPSTR lpBlockPt ) [inline]

Definition at line 94 of file GUIGREP.H.

     {};

void Reset ( ) [inline]

Definition at line 90 of file GUIGREP.H.

     {lpCurrentPointer = lpBasePointer;
      iCurrentPointer = 0;
     };

Field Documentation

CRITICAL_SECTION csAllocGuard [private]

Definition at line 62 of file GUIGREP.H.

HANDLE hBlock [private]

Definition at line 61 of file GUIGREP.H.

int iActualBlockSize [private]

Definition at line 60 of file GUIGREP.H.

int iCurrentPointer [private]

Definition at line 59 of file GUIGREP.H.

LPSTR lpBasePointer [private]

Definition at line 56 of file GUIGREP.H.

LPSTR lpCurrentPointer [private]

Definition at line 57 of file GUIGREP.H.

LPSTR lpReturnPointer [private]

Definition at line 58 of file GUIGREP.H.

The documentation for this class was generated from the following file:
  • GUIGREP/GUIGREP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RGNSTRUCT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

RGNSTRUCT Struct Reference

#include "REGIONS.H"

Data Fields

HRGN | hrgn
WORD | type

Detailed Description

Definition at line 68 of file REGIONS.H.

Field Documentation

HRGN hrgn

Definition at line 70 of file REGIONS.H.

WORD type

Definition at line 71 of file REGIONS.H.

The documentation for this struct was generated from the following file:
  • REGIONS/REGIONS.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagApplets Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagApplets Struct Reference

Data Fields

int | descstring
DLGPROC | dlgfn
int | dlgtemplate
int | icon
int | namestring

Detailed Description

Definition at line 35 of file STEREO.C.

Field Documentation

int descstring

Definition at line 37 of file STEREO.C.

DLGPROC dlgfn

Definition at line 39 of file STEREO.C.

int dlgtemplate

Definition at line 38 of file STEREO.C.

int icon

Definition at line 35 of file STEREO.C.

int namestring

Definition at line 36 of file STEREO.C.

The documentation for this struct was generated from the following file:
  • CPL/STEREO.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagControlText Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagControlText Struct Reference

#include "BOB.H"

Data Fields

UINT | cbTitle
HBITMAP | hDefaultButton
HBITMAP | hSelectButton
POINT | ptPosition
PTCHAR | szTitle

Detailed Description

Definition at line 1 of file BOB.H.

Field Documentation

UINT cbTitle

Definition at line 4 of file BOB.H.

HBITMAP hDefaultButton

Definition at line 5 of file BOB.H.

HBITMAP hSelectButton

Definition at line 6 of file BOB.H.

POINT ptPosition

Definition at line 2 of file BOB.H.

PTCHAR szTitle

Definition at line 3 of file BOB.H.

The documentation for this struct was generated from the following file:
  • BOB/BOB.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagCOPYDATASTRUCT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagCOPYDATASTRUCT Struct Reference

Data Fields

DWORD cbData
DWORD dwData
VOID FAR * lpData

Detailed Description

Definition at line 39 of file APP16.C.

Field Documentation

DWORD cbData

Definition at line 38 of file APP16.C.

DWORD dwData

Definition at line 37 of file APP16.C.

VOID FAR* lpData

Definition at line 39 of file APP16.C.

The documentation for this struct was generated from the following file:
  • INTEROP/APP16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagExtraBytes Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagExtraBytes Struct Reference

#include "SUBCLASS.H"

Data Fields

int | Action
WNDPROC | pfnOldProc
RECT | rect

Detailed Description

Definition at line 58 of file SUBCLASS.H.

Field Documentation

int Action

Definition at line 61 of file SUBCLASS.H.

WNDPROC pfnOldProc

Definition at line 59 of file SUBCLASS.H.

RECT rect

Definition at line 60 of file SUBCLASS.H.

The documentation for this struct was generated from the following file:
  • SUBCLASS/SUBCLASS.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagLookupEntry Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagLookupEntry Struct Reference

#include "GETDEV.H"

Data Fields

USHORT | end
USHORT | start
char | String [100]
TCHAR | String [MAXTCHAR]
int | Value

Detailed Description

Definition at line 33 of file GETDEV.H.

Field Documentation

USHORT end

Definition at line 15 of file DISPLAY.H.

USHORT start

Definition at line 14 of file DISPLAY.H.

TCHAR String

Definition at line 35 of file GETDEV.H.

TCHAR String[32]

Definition at line 40 of file LOCALE.H.

int Value

Definition at line 34 of file GETDEV.H.

The documentation for this struct was generated from the following files:
  • GETDEV/GETDEV.H
  • GETSYS/GETSYS.H
  • LOCALE/LOCALE.H
  • MASKBLT/MASKBLT.H
  • STREBLT/STREBLT.H
  • UNIPUT/DISPLAY.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagMYREC Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagMYREC Struct Reference

Data Fields

DWORD n
char | s1 [80]
char | s2 [80]

Detailed Description

Definition at line 48 of file APP16.C.

Field Documentation

DWORD n

Definition at line 52 of file APP16.C.

char s1

Definition at line 50 of file APP16.C.

char s2

Definition at line 51 of file APP16.C.

The documentation for this struct was generated from the following files:
  • INTEROP/APP16.C
  • INTEROP/DISP32.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagSUBTABLE Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagSUBTABLE Struct Reference

Data Fields

USHORT | entrySelector
USHORT | format
USHORT | length
USHORT | rangeShift
USHORT | searchRange
USHORT | segCountX2
USHORT | version

Detailed Description

Definition at line 749 of file DISPLAY.C.

Field Documentation

USHORT entrySelector

Definition at line 755 of file DISPLAY.C.

USHORT format

Definition at line 750 of file DISPLAY.C.

USHORT length

Definition at line 751 of file DISPLAY.C.

USHORT rangeShift

Definition at line 756 of file DISPLAY.C.

USHORT searchRange

Definition at line 754 of file DISPLAY.C.

USHORT segCountX2

Definition at line 753 of file DISPLAY.C.

USHORT version

Definition at line 752 of file DISPLAY.C.

The documentation for this struct was generated from the following file:
  • UNIPUT/DISPLAY.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagTABLE Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagTABLE Struct Reference

Data Fields

USHORT | encodingID
ULONG | offset
USHORT | platformID

Detailed Description

Definition at line 743 of file DISPLAY.C.

Field Documentation

USHORT encodingID

Definition at line 745 of file DISPLAY.C.

ULONG offset

Definition at line 746 of file DISPLAY.C.

USHORT platformID

Definition at line 744 of file DISPLAY.C.

The documentation for this struct was generated from the following file:
  • UNIPUT/DISPLAY.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagTHREADPBLOCK Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagTHREADPBLOCK Struct Reference

#include "GUIGREP.H"

Data Fields

HWND | hWndFileBox
HWND | hWndGlobal
int | iLoop

Detailed Description

Definition at line 32 of file GUIGREP.H.

Field Documentation

HWND hWndFileBox

Definition at line 36 of file GUIGREP.H.

HWND hWndGlobal

Definition at line 35 of file GUIGREP.H.

int iLoop

Definition at line 34 of file GUIGREP.H.

The documentation for this struct was generated from the following file:
  • GUIGREP/GUIGREP.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagTrackObject Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagTrackObject Struct Reference

#include "TRACK.H"

Data Fields

int | allowedModes
HDC | hdc
int | Mode
struct tagTrackObject * | Next
RECT | rect
RECT | rectClip
XFORM | xfmChange
XFORM | xfmDown

Detailed Description

Definition at line 36 of file TRACK.H.

Field Documentation

int allowedModes

Definition at line 42 of file TRACK.H.

HDC hdc

Definition at line 40 of file TRACK.H.

int Mode

Definition at line 41 of file TRACK.H.

struct tagTrackObject * Next

Definition at line 44 of file TRACK.H.

RECT rect

Definition at line 37 of file TRACK.H.

RECT rectClip

Definition at line 43 of file TRACK.H.

XFORM xfmChange

Definition at line 38 of file TRACK.H.

XFORM xfmDown

Definition at line 39 of file TRACK.H.

The documentation for this struct was generated from the following files:
  • MASKBLT/TRACK.H
  • STREBLT/TRACK.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: tagWIN32SINFO Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

tagWIN32SINFO Struct Reference

Data Fields

BYTE | bMajor
BYTE | bMinor
BOOL | fDebug
WORD | wBuildNumber

Detailed Description

Definition at line 27 of file DLL16.C.

Field Documentation

BYTE bMajor

Definition at line 29 of file DLL16.C.

BYTE bMinor

Definition at line 30 of file DLL16.C.

BOOL fDebug

Definition at line 32 of file DLL16.C.

WORD wBuildNumber

Definition at line 31 of file DLL16.C.

The documentation for this struct was generated from the following file:
  • INTEROP/DLL16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TRACKRECTSTRUCT Struct Reference

  • Data Structures
  • Data Structure Index
  • Data Fields
Data Fields

TRACKRECTSTRUCT Struct Reference

#include "REGIONS.H"

Data Fields

RECT | clientRect
HDC | hdc
RECT | trackRect
WORD | xOrigin
WORD | yOrigin

Detailed Description

Definition at line 75 of file REGIONS.H.

Field Documentation

RECT clientRect

Definition at line 78 of file REGIONS.H.

HDC hdc

Definition at line 79 of file REGIONS.H.

RECT trackRect

Definition at line 78 of file REGIONS.H.

WORD xOrigin

Definition at line 77 of file REGIONS.H.

WORD yOrigin

Definition at line 77 of file REGIONS.H.

The documentation for this struct was generated from the following file:
  • REGIONS/REGIONS.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • Data Structures
  • Data Structure Index
  • Data Fields
  • All
  • Functions
  • Variables
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
  • ~
Here is a list of all struct and union fields with links to the structures/unions they belong to:

- _ -

  • __based() : CHAINLIST

- a -

  • Action : tagExtraBytes
  • add() : growmemory
  • Alloc() : memory
  • allowedModes : tagTrackObject

- b -

  • BaseMsgTime : EVENTHEADER_STRUCT , GLOBAL_STRUCT
  • bClrCycle : _PerWndInfo
  • bDrawing : _PerWndInfo
  • bMajor : tagWIN32SINFO
  • bMandel : _PerWndInfo
  • bMinor : tagWIN32SINFO
  • bSetDIBsToDevice : _PerWndInfo
  • bStretch : _PerWndInfo

- c -

  • c1 : _PerWndInfo
  • c2 : _PerWndInfo
  • CaptionBarText : _PerWndInfo
  • cbData : tagCOPYDATASTRUCT
  • cbTitle : tagControlText
  • cChild : _ENUMNODE
  • ccmd : _CMDI
  • clientRect : TRACKRECTSTRUCT
  • cmsd : _MSDI
  • cNetBuf : _ENUMSYNC
  • cs : _ENUMSYNC
  • csAllocGuard : growmemory , memory
  • cThread : _ENUMSYNC

- d -

  • descstring : tagApplets
  • dlgfn : tagApplets
  • dlgtemplate : tagApplets
  • dwData : tagCOPYDATASTRUCT
  • dwElapsed : _PerWndInfo
  • dwThreadId : _PerWndInfo

- e -

  • edwp : _MSDI , _CMDI
  • encodingID : tagTABLE
  • end : tagLookupEntry
  • entrySelector : tagSUBTABLE
  • EventMsg : GLOBAL_STRUCT

- f -

  • fDebug : tagWIN32SINFO
  • format : tagSUBTABLE
  • fPlaying : GLOBAL_STRUCT
  • fRecording : GLOBAL_STRUCT
  • Free() : memory
  • fStopPlaying : GLOBAL_STRUCT
  • fStopRecording : GLOBAL_STRUCT

- g -

  • GetHandle() : growmemory
  • growmemory() : growmemory

- h -

  • hBlock : memory
  • hbmpArray : _TLSOBJECT
  • hBmpSaved : _PerWndInfo
  • hbrushHL : _TLSOBJECT
  • hCurrentBlock : growmemory
  • hdc : tagTrackObject , TRACKRECTSTRUCT
  • hDefaultButton : tagControlText
  • hDlgMain : GLOBAL_STRUCT
  • hFile : GLOBAL_STRUCT
  • hfont : _TLSOBJECT
  • hhook : _MYHOOKDATA
  • hHookGetMsg : GLOBAL_STRUCT
  • hHookPlayback : GLOBAL_STRUCT
  • hHookRecord : GLOBAL_STRUCT
  • hHTPal : _PerWndInfo
  • hInstance : GLOBAL_STRUCT
  • hkprc : _MYHOOKDATA
  • hMutex : GLOBAL_STRUCT
  • hPal : _PerWndInfo
  • hParent : _PerWndInfo
  • hrgn : RGNSTRUCT
  • hSelectButton : tagControlText
  • hTextWnd : _PerWndInfo
  • hThrd : _PerWndInfo
  • hwnd : _ENUMSYNC , _PerWndInfo
  • hWndFileBox : tagTHREADPBLOCK
  • hWndGlobal : tagTHREADPBLOCK

- i -

  • iActualBlockSize : memory
  • icon : tagApplets
  • iCurrentPointer : memory
  • iCurrentPt : growmemory
  • iCurrentSize : growmemory
  • iElement : CHAINLIST
  • iIncrement : growmemory
  • iIteration : _PerWndInfo
  • iLoop : tagTHREADPBLOCK
  • ilpszCRLF : growmemory
  • iPen : _PerWndInfo
  • iStep : _PerWndInfo
  • iStretchMode : _PerWndInfo

- l -

  • LastMsgTime : GLOBAL_STRUCT
  • lc1 : _PerWndInfo
  • lc2 : _PerWndInfo
  • length : tagSUBTABLE
  • lpBasePointer : memory
  • lpcchServer : _TLSOBJECT
  • lpChild : _ENUMNODE
  • lpComment : _DISK_RESOURCES_CONNECTABLE
  • lpCurrentPointer : memory
  • lpData : tagCOPYDATASTRUCT
  • lpfnHelpProc : _TLSOBJECT
  • lpfnListProc : _TLSOBJECT
  • lplpnetBuf : _ENUMSYNC
  • lpNet : _ENUMNODE
  • lpNode : _ENUMOBJECT
  • lpProvider : _DISK_RESOURCES_CONNECTABLE
  • lpRemoteName : _DISK_RESOURCES_CONNECTABLE
  • lpReturnPointer : memory
  • lpRoot : _ENUMSYNC
  • lpStartPt : growmemory
  • lpSync : _TLSOBJECT , _ENUMOBJECT
  • lpszApiFailedMsg : GLOBAL_STRUCT
  • lpszCRLF : growmemory
  • lpszServer : _TLSOBJECT
  • lxFrom : _PerWndInfo
  • lxTo : _PerWndInfo
  • lyFrom : _PerWndInfo
  • lyTo : _PerWndInfo

- m -

  • memory() : memory
  • Mode : tagTrackObject

- n -

  • n : tagMYREC
  • namestring : tagApplets
  • ndxBmp : _ENUMNODE
  • Next : tagTrackObject
  • nItem : _ENUMLISTOBJECT
  • nType : _MYHOOKDATA

- o -

  • Object : _ENUMLISTOBJECT
  • offset : tagTABLE

- p -

  • pfncmd : _CMD
  • pfnmsg : _MSD
  • pfnOldProc : tagExtraBytes
  • platformID : tagTABLE
  • PlayedMsgCount : GLOBAL_STRUCT
  • prghPen : _PerWndInfo
  • ptPosition : tagControlText

- r -

  • rangeShift : tagSUBTABLE
  • rcClient : _PerWndInfo
  • RecordedMsgCount : GLOBAL_STRUCT , EVENTHEADER_STRUCT
  • rect : tagTrackObject , tagExtraBytes
  • rectClip : tagTrackObject
  • Reset() : memory
  • rgcmd : _CMDI
  • rgmsd : _MSDI

- s -

  • s1 : tagMYREC
  • s2 : tagMYREC
  • searchRange : tagSUBTABLE
  • segCountX2 : tagSUBTABLE
  • Signature : EVENTHEADER_STRUCT
  • start : tagLookupEntry
  • String : tagLookupEntry
  • szSavef : _PerWndInfo
  • szTitle : tagControlText

- t -

  • tm : _TLSOBJECT
  • trackRect : TRACKRECTSTRUCT
  • type : RGNSTRUCT

- u -

  • uMessage : _MSD

- v -

  • Value : tagLookupEntry
  • version : tagSUBTABLE

- w -

  • wBuildNumber : tagWIN32SINFO
  • wCommand : _CMD

- x -

  • xfmChange : tagTrackObject
  • xfmDown : tagTrackObject
  • xFrom : _PerWndInfo
  • xOrigin : TRACKRECTSTRUCT
  • xTo : _PerWndInfo

- y -

  • yFrom : _PerWndInfo
  • yOrigin : TRACKRECTSTRUCT
  • yTo : _PerWndInfo

- ~ -

  • ~growmemory() : growmemory
  • ~memory() : memory
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: File Index

  • File List
  • Globals

File List

Here is a list of all files with brief descriptions:
ASYN_IO/ASYN_IO.C [code]
BNDBUF/BNDBUF.IDL [code]
BNDBUF/BNDBUFC.C [code]
BNDBUF/BNDBUFP.C [code]
BNDBUF/BNDBUFS.C [code]
BNDBUF/COMMON.H [code]
BOB/BOB.C [code]
BOB/BOB.H [code]
BPOINTER/CHGDATA.C [code]
BPOINTER/READDATA.C [code]
BPOINTER/SHRSTUFF.H [code]
CLIPTEXT/CLIPTEXT.C [code]
CLIPTEXT/CLIPTEXT.H [code]
CMNDLG/CDERR.H [code]
CMNDLG/CMNDLG.C [code]
CMNDLG/CMNDLG.H [code]
CONSOLEC/COLOR.C [code]
CONSOLEC/COLOR.H [code]
CPL/STEREO.C [code]
CPL/STEREO.H [code]
CURSOR/CURSOR.C [code]
CURSOR/CURSOR.H [code]
DRIVES/DRIVES.C [code]
DRIVES/DRIVES.H [code]
EVENT/ASYN_IO.C [code]
GETDEV/GETDEV.C [code]
GETDEV/GETDEV.H [code]
GETSYS/GETSYS.C [code]
GETSYS/GETSYS.H [code]
GLTHREAD/GLOS.H [code]
GLTHREAD/GLTHREAD.C [code]
GLTHREAD/GLTHREAD.H [code]
GLTHREAD/RESOURCE.H [code]
GLTHREAD/THREADS.C [code]
GUIGREP/GUIGREP.C [code]
GUIGREP/GUIGREP.H [code]
GUIGREP/NTGREP.C [code]
GUIGREP/NTGREP.H [code]
HOOKS/HOOKTEST.C [code]
HOOKS/HOOKTEST.H [code]
INHERIT/CHILD.C [code]
INHERIT/INHERIT.C [code]
INTEROP/APP16.C [code]
INTEROP/APP16.H [code]
INTEROP/DISP32.C [code]
INTEROP/DLL16.C [code]
INTEROP/DLL32.C [code]
INTEROP/MYUT.H [code]
INTEROP/STUB32.C [code]
INTEROP/UTDLL32.C [code]
INTEROP/W32SUT.H [code]
IOCOMP/IOCOMP.C [code]
LOCALE/LOCALE.C [code]
LOCALE/LOCALE.H [code]
LOGGING/LOG.C [code]
MASKBLT/BITMAP.C [code]
MASKBLT/BITMAP.H [code]
MASKBLT/MASKBLT.C [code]
MASKBLT/MASKBLT.H [code]
MASKBLT/TRACK.C [code]
MASKBLT/TRACK.H [code]
MDI_/MDI.C [code]
MDI_/MDI.H [code]
MDI_/MDITYPES.H [code]
MENU/MENU.C [code]
MENU/MENU.H [code]
MINREC/MINREC.C [code]
MINREC/MINREC.H [code]
MINREC/RECHOOK.C [code]
MINREC/RECHOOK.H [code]
NETDDE/ABOUT.C [code]
NETDDE/CONNECT.C [code]
NETDDE/CONNECT.H [code]
NETDDE/DDECBACK.C [code]
NETDDE/DDECBACK.H [code]
NETDDE/DISPATCH.C [code]
NETDDE/GLOBALS.H [code]
NETDDE/INIT.C [code]
NETDDE/MEM.C [code]
NETDDE/MEM.H [code]
NETDDE/MISC.C [code]
NETDDE/NDDECHAT.C [code]
NETDDE/NDDEUTIL.C [code]
NETDDE/NDDEUTIL.H [code]
NETDDE/WIN16EXT.H [code]
NETDDE/WINMAIN.C [code]
NTSD/DEBUG.C [code]
NTSD/MDI.C [code]
NTSD/MDI.H [code]
NTSD/MDITYPES.H [code]
OTHRPROC/OTHRPROC.C [code]
OTHRPROC/OTHRPROC.H [code]
OVCOMM/OVCOMM.C [code]
OVCOMM/OVCOMM.H [code]
OWNCOMBO/OWNCOMBO.C [code]
OWNCOMBO/OWNCOMBO.H [code]
PATHS/PATHS.C [code]
PATHS/PATHS.H [code]
PLATFORM/PLATFORM.C [code]
PLATFORM/PLATFORM.H [code]
POLYDRAW/POLYDRAW.C [code]
POLYDRAW/POLYDRAW.H [code]
READWRIT/DATABASE.C [code]
READWRIT/DATABASE.H [code]
READWRIT/READWRIT.C [code]
REBOOT/REBOOT.C [code]
REGIONS/REGIONS.C [code]
REGIONS/REGIONS.H [code]
RESDLL/MAIN.C [code]
RESDLL/MAIN.H [code]
RESDLL/THE_DLL.H [code]
SCRNSAVE/FRACTAL.C [code]
SCRNSAVE/FRACTAL.H [code]
SEMAPHOR/SEMA.C [code]
SEMAPHOR/SEMA.H [code]
SERVENUM/DEMO/BROWSE.C [code]
SERVENUM/DEMO/DISPATCH.C [code]
SERVENUM/DEMO/GLOBALS.H [code]
SERVENUM/DEMO/INIT.C [code]
SERVENUM/DEMO/MISC.C [code]
SERVENUM/DEMO/SERVENUM.H [code]
SERVENUM/DEMO/WINMAIN.C [code]
SERVENUM/DLL/DLLDISP.C [code]
SERVENUM/DLL/DLLDISP.H [code]
SERVENUM/DLL/ENUMDLG.C [code]
SERVENUM/DLL/ENUMDLG.H [code]
SERVENUM/DLL/ENUMTHRD.C [code]
SERVENUM/DLL/ENUMTHRD.H [code]
SERVENUM/DLL/ENUMUTIL.C [code]
SERVENUM/DLL/ENUMUTIL.H [code]
SERVENUM/DLL/MACROS.H [code]
SERVENUM/DLL/MEM.C [code]
SERVENUM/DLL/MEM.H [code]
SERVENUM/DLL/MISCUTIL.C [code]
SERVENUM/DLL/MISCUTIL.H [code]
SERVENUM/DLL/SERVENUM.C [code]
SERVENUM/DLL/SERVENUM.H [code]
SERVENUM/DLL/THRDUTIL.C [code]
SERVENUM/DLL/THRDUTIL.H [code]
SETINFO/SETINFO.C [code]
SETINFO/SETINFO.H [code]
SHAREMEM/SHAREMEM.C [code]
SHAREMEM/SHAREMEM.H [code]
SIMPLDLL/LINKTEST.C [code]
SIMPLDLL/LINKTEST.H [code]
SIMPLDLL/LOADTEST.C [code]
SIMPLDLL/LOADTEST.H [code]
SIMPLDLL/THE_DLL.C [code]
SIMPLDLL/THE_DLL.H [code]
STARTP/STARTP.C [code]
STREBLT/BITMAP.C [code]
STREBLT/BITMAP.H [code]
STREBLT/STREBLT.C [code]
STREBLT/STREBLT.H [code]
STREBLT/TRACK.C [code]
STREBLT/TRACK.H [code]
SUBCLASS/SUBCLASS.C [code]
SUBCLASS/SUBCLASS.H [code]
TERMPROC/TERMPROC.C [code]
THREADS/THREADS.C [code]
THREADS/THREADS.H [code]
TIMERS/TIMERS.C [code]
TIMERS/TIMERS.H [code]
TLS/TLSCALL.C [code]
TLS/TLSDLL.C [code]
TLS/TLSDLL.H [code]
UNIPUT/DISPLAY.C [code]
UNIPUT/DISPLAY.H [code]
UNIPUT/STATUS.C [code]
UNIPUT/UNIPUT.C [code]
UNIPUT/UNIPUT.H [code]
VIRTMEM/VIRTMEM.C [code]
VIRTMEM/VIRTMEM.H [code]
WALK/WALK.C [code]
WALK/WALK.H [code]
WINNET/WINNET.C [code]
WORLD/WORLD.C [code]
WORLD/WORLD.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: ASYN_IO/ASYN_IO.C File Reference

  • ASYN_IO
Defines | Functions

ASYN_IO.C File Reference

#include <windows.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define | SECTOR_SIZE 1024

Functions

VOID | Do_BackgroundTask (VOID)
VOID | ErrorMsg (LPCTSTR psz)
VOID | main (int argc, char *argv[])

Define Documentation

#define SECTOR_SIZE 1024

Definition at line 38 of file ASYN_IO.C.

Function Documentation

VOID Do_BackgroundTask ( VOID )

Definition at line 278 of file ASYN_IO.C.

{
  Sleep (5000L) ;
}

VOID ErrorMsg ( LPCTSTR psz )

Definition at line 297 of file ASYN_IO.C.

{
  LPVOID lpvMessageBuffer;

  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
            NULL, GetLastError(),
            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
            (LPTSTR)&lpvMessageBuffer, 0, NULL);

  //... now display this string
  printf("ERROR: API        = %s.\n", psz);
  printf("       error code = %d.\n", GetLastError());
  printf("       message    = %s.\n", (LPTSTR)lpvMessageBuffer);

  // Free the buffer allocated by the system
  LocalFree(lpvMessageBuffer);

  ExitProcess(EXIT_FAILURE);
}

void main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 43 of file ASYN_IO.C.

{
  BOOL       bSuccess ;          // return code of last API called

  CHAR       buf[SECTOR_SIZE] ;  // Buffer used by either
                                   // ReadFile() or WriteFile()

  DWORD      cbBytesRead,        // count of bytes read by ReadFile()
                                   // When asynchonous I/O is performed
                                   // one must check how many bytes were
                                   // read by calling GetOverLappedResults().

               cbBytesWritten,     // count of bytes written by WriteFile()

               cbBytesTransfered ; // this value is returned by
                                   // GetOverLappedResults() represents the
                                   // count of bytes transfered asynchronous

  DWORD      dwStatus,           // value returned by GetLastError()
               dwSuccess ;         // return code of last API called

    HANDLE     hInfile,            // Handle to the file to read
               hOutfile;           // Handle to the file to write to

    HANDLE     hEvent ;            // Handle to the synchronization Event

    OVERLAPPED OverLapped ;        // The operating system does not automatically
                                   // track the current file position of a file
                                   // open for asynchroous I/O. Instead one must
                                   // manually track this by updating the OVERLAPPED
                                   // structure. To update this structure one uses
                                   // the result returned by GetOverLappedResults().

/////////////////////////////////////////////////////////////////////////////
//
//  This block of code initalizes all the necessary variables needed to do
//  asynchronous IO. Specfically it opens the files and initializes the
//  synchronization EVENT and OVERLAPPED structure needed to keep track
//  of asynchronous file I/O
//
/////////////////////////////////////////////////////////////////////////////

  // check if running on Windows NT, if not, display notice and terminate
  if (GetVersion() & 0x80000000)
      {
      MessageBox(NULL,
                   "This sample application can only be run on Windows NT.\n"
                   "This application will now terminate.",
                   "Event",
                   MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return;
      }

    if (argc != 3)
      {
        printf ("\nUsage: ASYN_IO input_file output_file\n");
        ExitProcess(1L);
      }

  // Open file which will be copying.  Note we are opening this
  // asynchronously

    hInfile = CreateFile(argv[1],              // File to read
                         GENERIC_READ,         // Open file for reading only
                         FILE_SHARE_READ,      // Allow others to read file
                         NULL,                 // No security
                         OPEN_EXISTING,        // Fail if file doesn't exit
                         FILE_FLAG_OVERLAPPED, // Async I/o
                         NULL);

  if (hInfile == INVALID_HANDLE_VALUE)
      {
        printf("Error opening %s.\n", argv[1]);
        ErrorMsg("CreateFile");
      }

  // Create the file to write to; here we have opened it for synchronous IO.

  hOutfile = CreateFile(argv[2],                 // File to write to
                          GENERIC_WRITE,           // Open file only to write to
                          0,                       // No sharing allowed
                          NULL,                    // No security
                          CREATE_NEW,              // Fail if file exists
                          FILE_ATTRIBUTE_NORMAL,   // No attributes
                          NULL);

    if (hOutfile == INVALID_HANDLE_VALUE)
      {
      printf("Error opening %s.\n", argv[2]);
        ErrorMsg("CreateFile") ;
      }

  // Create Synchronizing Event

    hEvent = CreateEvent(NULL,    // No security
                         TRUE,    // Manual reset
                         FALSE,   // Initially Event set to non-signaled state
                         NULL);   // No name
    if (hEvent == NULL)
    ErrorMsg("CreateEvent") ;

  //
    // Intialize OverLapped structure. We will be using an Event instead
    // of the file handle for synchronizing I/O. One reason to use a unique
    // event instead of the file handle would be a so multi-threaded app
  // would know which thread to unblock when the handle is set to the
  // signaled state.
  //

    memset(&OverLapped, 0, sizeof(OVERLAPPED));
    OverLapped.hEvent = hEvent ;

    bSuccess = TRUE ;

  /***************************************************************************\
  **                                                                         **
  ** This is the main function of this program. Here we loop until the file  **
  ** has been copied. Notice that even though we are using asynchronous I/O  **
  ** ReadFile() may still return sychronously if it can be done fast enough  **
  **                                                                         **
  \***************************************************************************/

    while (bSuccess)
      {

    // Read file asynchronously

        bSuccess = ReadFile(hInfile,        // Handle of file to read
                      buf,            // Buffer to store input
                      SECTOR_SIZE,    // Number of bytes to read
                      &cbBytesRead,   // Number of bytes read. See note]
                                      // above in delcaration
                      &OverLapped);   // Used for asynchronous I/O

    // Check whether ReadFile() has completed yet

        if (!bSuccess && ((dwStatus = GetLastError()) == ERROR_IO_PENDING))
          {
          printf("\nIO Pending");

      // Read not complete yet first execute the background task then check
      // to the if event "hEvent" set to the signaled state. If the event is
      // not set signaled state then loop through again - run the background
      // task and check the event.

          Do_BackgroundTask();

          dwSuccess = WaitForSingleObject(hEvent, 0);

          if (dwSuccess == WAIT_FAILED)
        {
              ErrorMsg("WaitForSingleObject");
            }
          else if (dwSuccess == WAIT_OBJECT_0)
            {
              bSuccess = GetOverlappedResult(hInfile,
                                             &OverLapped,
                                             &cbBytesTransfered,
                                             FALSE);
              if (!bSuccess)
                  ErrorMsg("GetOverLappedResult");
              else
                {
                  // Read has completed now find out how many bytes have been read
                  printf ("\nNumber of bytes transfered is %d\n", cbBytesTransfered);
                  OverLapped.Offset += cbBytesTransfered ;
                  cbBytesRead = cbBytesTransfered ;
                }
            }
          else if (dwSuccess == WAIT_TIMEOUT)
              {
              Do_BackgroundTask () ;
            }
          }

    // ReadFile() read file synchronously; update Overlapped structure

    else if (bSuccess  && cbBytesRead != 0)
          {
          printf ( "\nNumber of bytes transfered is %d\n", cbBytesRead ) ;
          OverLapped.Offset += cbBytesRead ;
          }

    // ReadFile() has found the end of the file; exit loop

        else if (!bSuccess  && GetLastError() == ERROR_HANDLE_EOF)
          {
          printf("\nEnd of file read\n");
          break ;
          }
        else
      {

      // An error occured while reading, print out status and exit loop.

          ErrorMsg ("ReadFile");
      }

  // Write to file synchronously

  bSuccess = WriteFile(hOutfile,             // Handle of file to write to
                     buf,                  // Data to write to file
                     cbBytesRead,          // Number of bytes to write
                     &cbBytesWritten,      // Number of bytes written
                     NULL);                // Only need for asynchonous output

  if (!bSuccess)
      ErrorMsg("WriteFile");

   } // End of WHILE loop

   CloseHandle(hInfile);        // Close handle to input file
   FlushFileBuffers(hOutfile);  // Make sure all data written to file first
   CloseHandle (hOutfile);      // Close handle to output file
   ExitProcess(0L);

}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUF.IDL File Reference

  • BNDBUF

BNDBUF.IDL File Reference

Go to the source code of this file.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFC.C File Reference

  • BNDBUF
Functions | Variables

BNDBUFC.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <rpc.h>
#include "common.h"
#include "bndbuf.h"

Go to the source code of this file.

Functions

void | consumer ()
void | main (int argc, char *argv[])
void __RPC_FAR *__RPC_API | MIDL_user_allocate (size_t len)
void __RPC_API | MIDL_user_free (void __RPC_FAR *ptr)
void | produce_item (char *string)
void | producer ()

Variables

HANDLE | hConThrd
HANDLE | hMainThrd
HANDLE | hProdThrd
LONG | lConThreadId
LONG | lProdThreadId
DWORD retCode

Function Documentation

void consumer ( )

Definition at line 149 of file BNDBUFC.C.

{
    char item[20];

    while (TRUE)
    {

    // RPC guarded statements

    RpcTryExcept
    {
        remove_buffer(item);        // Take item from buffer
        printf("\nconsume   ---> %s", item);
    }

    RpcExcept(1)
    {
        printf("The RPC runtime library raised exception %lx.\n", RpcExceptionCode());
        printf("Please verify that the server application and \n");
        printf("the locator service have been started.");
    }
    RpcEndExcept

    // End RPC guarded statements

    }

}

void main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 46 of file BNDBUFC.C.

{

  // check if Win32s, if so, display notice and terminate
      if( GetVersion() & 0x80000000 )
      {
        MessageBox( NULL,
           "This application cannot run on Windows 3.1 or Windows 95.\n"
           "This application will now terminate.",
           "BndBuf",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return;
      }

    // Create Consumer Thread

    hConThrd = CreateThread(NULL,
                0,
                (LPTHREAD_START_ROUTINE)consumer,
                NULL,
                0,
                (LPDWORD) &lConThreadId );

    // Create producer thread

    hProdThrd = CreateThread(NULL,
                 0,
                 (LPTHREAD_START_ROUTINE)producer,
                 NULL,
                 0,
                 (LPDWORD) &lProdThreadId );

    // Suspend the main thread

    hMainThrd = GetCurrentThread();

    if (SuspendThread(hMainThrd) == -1)
    {
        retCode = GetLastError();
        printf("\nSuspendThread returns %d\n", retCode);
        ExitProcess(0);
    }

}

void __RPC_FAR* __RPC_API MIDL_user_allocate ( size_t len )

Definition at line 211 of file BNDBUFC.C.

{
    return(malloc(len));
}

void __RPC_API MIDL_user_free ( void __RPC_FAR * ptr )

Definition at line 216 of file BNDBUFC.C.

{
    free(ptr);
}

void produce_item ( char * string )

Definition at line 189 of file BNDBUFC.C.

{
    char *tmp;
    int i;

    tmp = string;

    for (i = MAX_SIZE; i > 1; i--)
    {
        *tmp = (rand() % 26) + 'A';
        tmp++;
    }
    strcpy(tmp, "\0");

}

void producer ( )

Definition at line 106 of file BNDBUFC.C.

{
    char item[MAX_SIZE];

    // Delay for awhile before starting
    Sleep(200);

    while (TRUE)
    {
    produce_item(item);     // Produce random string

    // RPC guarded statements

    RpcTryExcept
    {
        insert_buffer(item);    // Put item in buffer
        printf("\nproduce   ---> %s", item);
    }
    RpcExcept(1)
    {
        printf("The RPC runtime library raised exception 0x%lx.\n", RpcExceptionCode());
        printf("Please verify that the server application and \n");
        printf("the locator service have been started.");
    }
    RpcEndExcept

    // End RPC guarded statements

    }
}

Variable Documentation

HANDLE hConThrd

Definition at line 31 of file BNDBUFC.C.

HANDLE hMainThrd

Definition at line 30 of file BNDBUFC.C.

HANDLE hProdThrd

Definition at line 32 of file BNDBUFC.C.

LONG lConThreadId

Definition at line 33 of file BNDBUFC.C.

LONG lProdThreadId

Definition at line 34 of file BNDBUFC.C.

DWORD retCode

Definition at line 35 of file BNDBUFC.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFP.C File Reference

  • BNDBUF
Functions | Variables

BNDBUFP.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <rpc.h>
#include "common.h"
#include "bndbuf.h"

Go to the source code of this file.

Functions

void | enter_item (char *input)
void | insert_buffer (unsigned char *item)
void | remove_buffer (unsigned char *item)
void | remove_item (char *output)

Variables

char | buffer [MAX_ITEM][MAX_SIZE]
int | con_buf_pos
HANDLE | hEmptySem
HANDLE | hFullSem
HANDLE | hMutex
int | pro_buf_pos

Function Documentation

void enter_item ( char * input )

Definition at line 103 of file BNDBUFP.C.

{

    strncpy(buffer[pro_buf_pos], input, MAX_SIZE);
    printf("\nproduce    ---> %s", buffer[pro_buf_pos]);
    pro_buf_pos = ((++pro_buf_pos) % MAX_ITEM);
}

void insert_buffer ( unsigned char * item )

Definition at line 46 of file BNDBUFP.C.

{

    WaitForSingleObject(hEmptySem, INFINITE);     // Decrease empty count
    WaitForSingleObject(hMutex, INFINITE);      // Acquire Mutex
    enter_item(item);           // Put item in buffer
    ReleaseMutex(hMutex);         // Release Mutex
    ReleaseSemaphore(hFullSem, 1, NULL);      // Increment full count

}

void remove_buffer ( unsigned char * item )

Definition at line 67 of file BNDBUFP.C.

{

    WaitForSingleObject(hFullSem, INFINITE);      // Decrease full count
    WaitForSingleObject(hMutex, INFINITE);      // Acquire Mutex
    remove_item(item);            // Take item from buffer
    ReleaseMutex(hMutex);         // Release Mutex
    ReleaseSemaphore(hEmptySem, 1, NULL);     // Increment full count

}

void remove_item ( char * output )

Definition at line 120 of file BNDBUFP.C.

{

    strncpy(output, buffer[con_buf_pos], 20);
    printf("\nconsume    ---> %s", output);
    con_buf_pos = ((++con_buf_pos) % MAX_ITEM);

}

Variable Documentation

char buffer[MAX_ITEM][MAX_SIZE]

Definition at line 20 of file COMMON.H.

int con_buf_pos

Definition at line 26 of file COMMON.H.

HANDLE hEmptySem

Definition at line 14 of file COMMON.H.

HANDLE hFullSem

Definition at line 15 of file COMMON.H.

HANDLE hMutex

Definition at line 13 of file COMMON.H.

int pro_buf_pos

Definition at line 25 of file COMMON.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFS.C File Reference

  • BNDBUF
Functions | Variables

BNDBUFS.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <rpc.h>
#include "common.h"
#include "bndbuf.h"

Go to the source code of this file.

Functions

void | main (int argc, char *argv[])
void __RPC_FAR *__RPC_API | MIDL_user_allocate (size_t len)
void __RPC_API | MIDL_user_free (void __RPC_FAR *ptr)
void | Usage (char *pszProgramName)

Variables

char | buffer [MAX_ITEM][MAX_SIZE]
HANDLE | hEmptySem
HANDLE | hFullSem
HANDLE | hMutex
DWORD retCode

Function Documentation

void main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 67 of file BNDBUFS.C.

{

    RPC_STATUS status;
    RPC_BINDING_VECTOR * pBindingVector;

    unsigned char * pszEndpoint         = "\\pipe\\boundbuf";
    unsigned char * pszProtocolSequence     = "ncacn_np";

    int i;

    // This program only runs on Windows NT
    if (GetVersion() & 0x80000000)
    {
        MessageBox(NULL,
            "This application cannot run on Windows 3.1 or Windows 95\n"
            "This application will now terminate.",
            "BndBuf",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
        return;
    }

    // allow the user to override settings with command line switches
    for (i = 1; i < argc; i++)
    {
    if ((*argv[i] == '-') || (*argv[i] == '/'))
    {
        switch (tolower(*(argv[i]+1)))
        {
        case 'p':  // protocol sequence
            pszProtocolSequence = argv[++i];
            break;
        case 'e':
            pszEndpoint = argv[++i];
            break;
        case 'h':
        case '?':
        default:
            Usage(argv[0]);
        }
     }

        else
        Usage(argv[0]);
    }

    // Create semaphores and mutex for synchronization

    hMutex = CreateMutex(NULL,
             FALSE,
             "Buffer_Mutex");

    if (hMutex == NULL)
    {
        retCode = GetLastError();
        printf("\nCreateMutex returns error %d\n", retCode);
        ExitProcess(0);
    }

    if ((hEmptySem = CreateSemaphore(NULL,
                    MAX_ITEM,
                    MAX_ITEM,
                    "Empty_Sem")) == NULL)

    {
        retCode = GetLastError();
        printf("\nCreateSemaphore for empty returns error %d\n", retCode);
        ExitProcess(0);
    }

    if ((hFullSem = CreateSemaphore(NULL,
                    0,
                    MAX_ITEM,
                    "Full_Sem")) == NULL)

    {
        retCode = GetLastError();
        printf("\nCreateSemaphore for full returns error %d\n", retCode);
        ExitProcess(0);
    }

// Initialize RPC Interface server

    status = RpcServerUseProtseqEp((unsigned char *)pszProtocolSequence,
                   MAXCALLS,
                   pszEndpoint,
                   0);
    printf("RpcServerUseProtseqEp returned %d\n", status);
    if (status)
    ExitProcess(2);

    status = RpcServerRegisterIf(bndbufh_ServerIfHandle,
                 0,
                 0);
    printf("RpcServerRegisterIf returned %d\n", status);
    if (status)
    ExitProcess(2);

    status = RpcServerInqBindings(&pBindingVector);
    printf("RpcServerInqBindings returned %d\n", status);
    if (status)
    ExitProcess(2);

    status = RpcNsBindingExport(RPC_C_NS_SYNTAX_DEFAULT,    /* name syntax */
                "/.:/Boundbuf_sample",      /* name */
                bndbufh_ServerIfHandle,
                pBindingVector,
                NULL);
    printf("RpcNsBindingExport returned %d\n", status);
    if (status)
    ExitProcess(2);

    printf("Calling RpcServerListen\n");
    status = RpcServerListen(1,
                 MAXCALLS,
                 0);
    printf("RpcServerListen returned %d\n", status);
    if (status)
    ExitProcess(2);

}

void __RPC_FAR* __RPC_API MIDL_user_allocate ( size_t len )

Definition at line 207 of file BNDBUFS.C.

{
    return(malloc(len));
}

void __RPC_API MIDL_user_free ( void __RPC_FAR * ptr )

Definition at line 212 of file BNDBUFS.C.

{
    free(ptr);
}

void Usage ( char * pszProgramName )

Definition at line 46 of file BNDBUFS.C.

{
    fprintf(stderr, "Usage:  %s\n", pszProgramName);
    fprintf(stderr, " -p protocol_sequence\n");
    fprintf(stderr, " -e endpoint\n");
    ExitProcess(1);
}

Variable Documentation

char buffer[MAX_ITEM][MAX_SIZE]

Definition at line 20 of file COMMON.H.

HANDLE hEmptySem

Definition at line 14 of file COMMON.H.

HANDLE hFullSem

Definition at line 15 of file COMMON.H.

HANDLE hMutex

Definition at line 13 of file COMMON.H.

DWORD retCode

Definition at line 35 of file BNDBUFS.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/COMMON.H File Reference

  • BNDBUF
Defines | Variables

COMMON.H File Reference

Go to the source code of this file.

Defines

#define | FAILURE 0
#define | MAX_ITEM 10
#define | MAX_SIZE 20
#define | MAXCALLS 20
#define | SUCCESS 1

Variables

char | buffer [MAX_ITEM][MAX_SIZE]
int | con_buf_pos
HANDLE | hEmptySem
HANDLE | hFullSem
HANDLE | hMutex
int | pro_buf_pos

Define Documentation

#define FAILURE 0

Definition at line 5 of file COMMON.H.

#define MAX_ITEM 10

Definition at line 1 of file COMMON.H.

#define MAX_SIZE 20

Definition at line 2 of file COMMON.H.

#define MAXCALLS 20

Definition at line 8 of file COMMON.H.

#define SUCCESS 1

Definition at line 4 of file COMMON.H.

Variable Documentation

char buffer[MAX_ITEM][MAX_SIZE]

Definition at line 20 of file COMMON.H.

int con_buf_pos

Definition at line 26 of file COMMON.H.

HANDLE hEmptySem

Definition at line 14 of file COMMON.H.

HANDLE hFullSem

Definition at line 15 of file COMMON.H.

HANDLE hMutex

Definition at line 13 of file COMMON.H.

int pro_buf_pos

Definition at line 25 of file COMMON.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BOB/BOB.C File Reference

  • BOB
Defines | Functions | Variables

BOB.C File Reference

#include <stddef.h>
#include <stdlib.h>
#include "windows.h"
#include "BOB.H"

Go to the source code of this file.

Defines

#define | OEMRESOURCE
#define | STRICT
#define | WIN32S 0x80000000l

Functions

BOOL CALLBACK | About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | ButtonProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
void | DrawBitmap (HDC hDC, RECT rect, HBITMAP hBitmap, DWORD rop)
void | HandleFocusState (LPDRAWITEMSTRUCT lpdisCtrl, LPRECT lpFocusRect, LPRECT lpSelectRect)
void | HandleSelectedState (LPDRAWITEMSTRUCT lpdisCtrl, LPCONTROLTEXT lpCtlText)
BOOL | InitApplication (HANDLE hInstance)
BOOL | InitInstance (HANDLE hInstance, int nCmdShow)
LRESULT CALLBACK | MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HINSTANCE | ghInst
HWND | ghWnd
WNDPROC | OldButtonProc

Define Documentation

#define OEMRESOURCE

Definition at line 40 of file BOB.C.

#define STRICT

Definition at line 34 of file BOB.C.

#define WIN32S 0x80000000l

Definition at line 32 of file BOB.C.

Function Documentation

LRESULT CALLBACK About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 497 of file BOB.C.

{
    switch (message) {
        case WM_INITDIALOG:           /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command?  */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

LRESULT CALLBACK ButtonProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 640 of file BOB.C.

{

   switch ( message )
   {
       case WM_CHAR:
          OutputDebugString("ButtonProc: WM_CHAR received\r\n");
          SendMessage( ghWnd, WM_COMMAND, MAKEWPARAM(BOB,BN_CLICKED),
                       (LPARAM)(hWnd));

       default:
          return CallWindowProc( OldButtonProc, hWnd, message, wParam, lParam );

   }

   return ( 0 );
}

void DrawBitmap | ( | HDC | hDC,
 |  | RECT | rect,
 |  | HBITMAP | hBitmap,
 |  | DWORD | rop
 | ) |  |

Definition at line 621 of file BOB.C.

{
    HDC           hMemDC;
    BITMAP        bm;
    hMemDC = CreateCompatibleDC(hDC);
    SelectObject(hMemDC, hBitmap);
//    BitBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, hMemDC, 0, 0, rop);
    GetObject(hBitmap, sizeof (BITMAP), (LPVOID) &bm);
    StretchBlt( hDC, rect.left, rect.top, rect.right, rect.bottom,
                hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, rop);
    DeleteDC(hMemDC);
}

void HandleFocusState | ( | LPDRAWITEMSTRUCT | lpdisCtrl,
 |  | LPRECT | lpFocusRect,
 |  | LPRECT | lpSelectRect
 | ) |  |

Definition at line 583 of file BOB.C.

{
    // if focus state, draw a dashed rect around text
    if (lpdisCtrl->itemState & ODS_FOCUS)
    {
        // if selected, shift focus rect right and down 2 pixels around text
        if (lpdisCtrl->itemState & ODS_SELECTED) {
        OutputDebugString("HandleFocusState: State is ODS_SELECTED\r\n");
            DrawFocusRect(lpdisCtrl->hDC, lpSelectRect);
        }
        // else text centered, so focus rect will be too
        else {
            DrawFocusRect(lpdisCtrl->hDC, lpFocusRect);
            OutputDebugString("HandleFocusState: State is ODS_FOCUS\r\n");
        }

    }
    else
        if (lpdisCtrl->itemState & ODS_SELECTED)
            OutputDebugString(
                "Error HandleFocusState: State is ODS_SELECTED\r\n");
        else {
            char buffer[80];
            wsprintf(buffer,
                "HandleFocusState:  lpdisCtrl->itemState is %#x\r\n",
                lpdisCtrl->itemState );
            OutputDebugString(buffer);
        }
}

void HandleSelectedState | ( | LPDRAWITEMSTRUCT | lpdisCtrl,
 |  | LPCONTROLTEXT | lpCtlText
 | ) |  |

Definition at line 531 of file BOB.C.

{

    int nOldBkMode;

    // handle button pressed down select state -- button down bitmap
    //   text is right & down 2 pixels
    if (lpdisCtrl->itemState & ODS_SELECTED)
    {
        DrawBitmap(lpdisCtrl->hDC,
           lpdisCtrl->rcItem,
           lpCtlText->hSelectButton,
                   SRCCOPY);

        // put text 2 pixels right and down of center of bitmap
        nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);

        TextOut( lpdisCtrl->hDC,
                 lpCtlText->ptPosition.x+2,
                 lpCtlText->ptPosition.y+2,
                 lpCtlText->szTitle,
                 lpCtlText->cbTitle );

        SetBkMode(lpdisCtrl->hDC,nOldBkMode);
    }
    // not selected -- button up; text is in normal position
    else
    {
        DrawBitmap(lpdisCtrl->hDC,
           lpdisCtrl->rcItem,
           lpCtlText->hDefaultButton,
                   SRCCOPY);

        // center text in bitmap
        nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);
        TextOut( lpdisCtrl->hDC,
                 lpCtlText->ptPosition.x,
                 lpCtlText->ptPosition.y,
                 lpCtlText->szTitle,
                 lpCtlText->cbTitle );

        SetBkMode(lpdisCtrl->hDC,nOldBkMode);
    }
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 71 of file BOB.C.

{
    MSG msg;                            /* message              */

    if (!hPrevInstance)                 /* Other instances of app running? */
    if (!InitApplication(hInstance))    /* Initialize shared things */
        return (FALSE);                 /* Exits if unable to initialize */

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,    /* message structure                      */
        NULL,                  /* handle of window receiving the message */
        0,                     /* lowest message to examine              */
        0))                    /* highest message to examine             */
    {
        TranslateMessage(&msg);    /* Translates virtual key codes       */
        DispatchMessage(&msg);     /* Dispatches message to window       */

    }
    return (msg.wParam);       /* Returns the value from PostQuitMessage */
UNREFERENCED_PARAMETER(lpCmdLine);
}

Variable Documentation

HINSTANCE ghInst

Definition at line 45 of file BOB.C.

HWND ghWnd

Definition at line 46 of file BOB.C.

WNDPROC OldButtonProc

Definition at line 47 of file BOB.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BOB/BOB.H File Reference

  • BOB
Data Structures | Defines | Typedefs | Functions

BOB.H File Reference

Go to the source code of this file.

Data Structures

struct | tagControlText

Defines

#define | BOB 10
#define | DEFAULTBUTTON 1
#define | SELECTEDBUTTON 2
#define | SubclassWindow(hwnd, lpfn) ((WNDPROC)SetWindowLong((hwnd), GWL_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))

Typedefs

typedef struct tagControlText | CONTROLTEXT
typedef struct tagControlText * | LPCONTROLTEXT

Functions

BOOL CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | ButtonProc (HWND, UINT, WPARAM, LPARAM)
void | DrawBitmap (HDC hDC, RECT rect, HBITMAP hBitmap, DWORD rop)
void | HandleFocusState (LPDRAWITEMSTRUCT lpdis, LPRECT lpFocusRect, LPRECT lpSelectRect)
void | HandleSelectedState (LPDRAWITEMSTRUCT lpdisCtrl, LPCONTROLTEXT lpCtlText)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
int PASCAL | WinMain (HINSTANCE, HINSTANCE, LPSTR, int)

Define Documentation

#define BOB 10

Definition at line 20 of file BOB.H.

#define DEFAULTBUTTON 1

Definition at line 21 of file BOB.H.

#define SELECTEDBUTTON 2

Definition at line 22 of file BOB.H.

#define SubclassWindow | ( | hwnd,
 |  | lpfn |
 | ) |  | ((WNDPROC)SetWindowLong((hwnd), GWL_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))

Definition at line 24 of file BOB.H.

Typedef Documentation

typedef struct tagControlText CONTROLTEXT
typedef struct tagControlText* LPCONTROLTEXT

Function Documentation

BOOL CALLBACK About | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 497 of file BOB.C.

{
    switch (message) {
        case WM_INITDIALOG:           /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command?  */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

LRESULT CALLBACK ButtonProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 640 of file BOB.C.

{

   switch ( message )
   {
       case WM_CHAR:
          OutputDebugString("ButtonProc: WM_CHAR received\r\n");
          SendMessage( ghWnd, WM_COMMAND, MAKEWPARAM(BOB,BN_CLICKED),
                       (LPARAM)(hWnd));

       default:
          return CallWindowProc( OldButtonProc, hWnd, message, wParam, lParam );

   }

   return ( 0 );
}

void DrawBitmap | ( | HDC | hDC,
 |  | RECT | rect,
 |  | HBITMAP | hBitmap,
 |  | DWORD | rop
 | ) |  |

Definition at line 621 of file BOB.C.

{
    HDC           hMemDC;
    BITMAP        bm;
    hMemDC = CreateCompatibleDC(hDC);
    SelectObject(hMemDC, hBitmap);
//    BitBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, hMemDC, 0, 0, rop);
    GetObject(hBitmap, sizeof (BITMAP), (LPVOID) &bm);
    StretchBlt( hDC, rect.left, rect.top, rect.right, rect.bottom,
                hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, rop);
    DeleteDC(hMemDC);
}

void HandleFocusState | ( | LPDRAWITEMSTRUCT | lpdis,
 |  | LPRECT | lpFocusRect,
 |  | LPRECT | lpSelectRect
 | ) |  |

Definition at line 583 of file BOB.C.

{
    // if focus state, draw a dashed rect around text
    if (lpdisCtrl->itemState & ODS_FOCUS)
    {
        // if selected, shift focus rect right and down 2 pixels around text
        if (lpdisCtrl->itemState & ODS_SELECTED) {
        OutputDebugString("HandleFocusState: State is ODS_SELECTED\r\n");
            DrawFocusRect(lpdisCtrl->hDC, lpSelectRect);
        }
        // else text centered, so focus rect will be too
        else {
            DrawFocusRect(lpdisCtrl->hDC, lpFocusRect);
            OutputDebugString("HandleFocusState: State is ODS_FOCUS\r\n");
        }

    }
    else
        if (lpdisCtrl->itemState & ODS_SELECTED)
            OutputDebugString(
                "Error HandleFocusState: State is ODS_SELECTED\r\n");
        else {
            char buffer[80];
            wsprintf(buffer,
                "HandleFocusState:  lpdisCtrl->itemState is %#x\r\n",
                lpdisCtrl->itemState );
            OutputDebugString(buffer);
        }
}

void HandleSelectedState | ( | LPDRAWITEMSTRUCT | lpdisCtrl,
 |  | LPCONTROLTEXT | lpCtlText
 | ) |  |

Definition at line 531 of file BOB.C.

{

    int nOldBkMode;

    // handle button pressed down select state -- button down bitmap
    //   text is right & down 2 pixels
    if (lpdisCtrl->itemState & ODS_SELECTED)
    {
        DrawBitmap(lpdisCtrl->hDC,
           lpdisCtrl->rcItem,
           lpCtlText->hSelectButton,
                   SRCCOPY);

        // put text 2 pixels right and down of center of bitmap
        nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);

        TextOut( lpdisCtrl->hDC,
                 lpCtlText->ptPosition.x+2,
                 lpCtlText->ptPosition.y+2,
                 lpCtlText->szTitle,
                 lpCtlText->cbTitle );

        SetBkMode(lpdisCtrl->hDC,nOldBkMode);
    }
    // not selected -- button up; text is in normal position
    else
    {
        DrawBitmap(lpdisCtrl->hDC,
           lpdisCtrl->rcItem,
           lpCtlText->hDefaultButton,
                   SRCCOPY);

        // center text in bitmap
        nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);
        TextOut( lpdisCtrl->hDC,
                 lpCtlText->ptPosition.x,
                 lpCtlText->ptPosition.y,
                 lpCtlText->szTitle,
                 lpCtlText->cbTitle );

        SetBkMode(lpdisCtrl->hDC,nOldBkMode);
    }
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | int |
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

int PASCAL WinMain | ( | HINSTANCE | ,
 |  | HINSTANCE | ,
 |  | LPSTR | ,
 |  | int |
 | ) |  |

Definition at line 71 of file BOB.C.

{
    MSG msg;                            /* message              */

    if (!hPrevInstance)                 /* Other instances of app running? */
    if (!InitApplication(hInstance))    /* Initialize shared things */
        return (FALSE);                 /* Exits if unable to initialize */

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,    /* message structure                      */
        NULL,                  /* handle of window receiving the message */
        0,                     /* lowest message to examine              */
        0))                    /* highest message to examine             */
    {
        TranslateMessage(&msg);    /* Translates virtual key codes       */
        DispatchMessage(&msg);     /* Dispatches message to window       */

    }
    return (msg.wParam);       /* Returns the value from PostQuitMessage */
UNREFERENCED_PARAMETER(lpCmdLine);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/CHGDATA.C File Reference

  • BPOINTER
Functions

CHGDATA.C File Reference

#include <windows.h>
#include <stdio.h>
#include "shrstuff.h"

Go to the source code of this file.

Functions

void | InsertElement (int iValue)
int | main (void)

Function Documentation

void InsertElement ( int iValue )

Definition at line 24 of file CHGDATA.C.

{
  clRunning->iElement = iValue;
  clRunning->clNext = clRunning + 1;
  clRunning += 1;
}

int main ( void )

Definition at line 32 of file CHGDATA.C.

{   HANDLE hFileMapping;
    DWORD dwVersion;
    int iCounter;
    int iNextElement;
    int iInternalCounter = 0;

// check if running on Win32s, if so, display notice and terminate

    dwVersion = GetVersion();
    if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
        MessageBox( NULL,
            "This sample application will not run on Windows 3.1.\n"
            "This application will now terminate.",
            "ChgData",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

// Set up the shared memory.
// In this process, the file mapping must not yet exist.

    hFileMapping = CreateFileMapping( (HANDLE)0xffffffff,
                                      NULL,
                                      PAGE_READWRITE,
                                      0,4096,
                                      "FM_DemoMapObject");

    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {   printf("Please close ReadData before running this application!");
        CloseHandle(hFileMapping);
        return 0;
    }

    if (!hFileMapping)
    {   printf ("Error %d: CreateFileMapping failed.", GetLastError());
        return 0;
    }

// MapViewOfFile is used here to get the file mapping mapped into
// this processe's address space.  There is no guarantee about which address
// will be chosen for this process.  The address used by another
// process could be different.  That is why we need based pointers.
// The pointers in this process are based on whatever address is used
// by this process. For another process, the pointers will be based on some
// other address.

    clBasePt = (CHAINLIST *)MapViewOfFile( hFileMapping,
                                           FILE_MAP_ALL_ACCESS,
                                           0,0,
                                           0);

    if (clBasePt == NULL)
    {   printf("Error %d: MapViewOfFileEx failed.\n", GetLastError());
        CloseHandle(hFileMapping);
        return 0;
    }

// Now the memory is set up. The following loops and prompts the user for new
// elements until a 0 is hit. The memory is displayed so that we see that
// the offsets are entered into the link fields, ignoring the based
// pointers.

    printf("Address of file mapping in this process: 0x%08x\n", (int)clBasePt);
    printf("Enter element to insert; 0 terminates: ");
    scanf("%d",&iNextElement);
    while (iNextElement != 0)
    {
        InsertElement(iNextElement);
        iInternalCounter += (sizeof(CHAINLIST)/sizeof(DWORD));
        printf ("Now displaying raw data at address: 0x%x\n", (int)clBasePt);
        printf ("You might want to run readdata.exe now.\n");
        for (iCounter = 0; iCounter <= iInternalCounter; iCounter += 2)
            printf("%p: %08x %08x\n", (LPVOID)((DWORD *)clBasePt+iCounter),
                                     ((DWORD *)clBasePt)[iCounter],
                                     ((DWORD *)clBasePt)[iCounter+1]);
        printf("\nEnter next element to insert; 0 terminates: ");
        scanf("%d", &iNextElement);
    }

// user has entered 0 -- now clean up.

    UnmapViewOfFile(clBasePt);
    CloseHandle(hFileMapping);

    return(0);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/READDATA.C File Reference

  • BPOINTER
Functions

READDATA.C File Reference

#include <windows.h>
#include <stdio.h>
#include "shrstuff.h"

Go to the source code of this file.

Functions

int main (void)

Function Documentation

int main ( void )

Definition at line 23 of file READDATA.C.

{   HANDLE hFileMapping;
    DWORD dwVersion;
    char cInput;

// check if running on Win32s, if so, display notice and terminate

    dwVersion = GetVersion();
    if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
        MessageBox(NULL,
            "This sample application cannot be run on Windows 3.1.\n"
            "This application will now terminate.",
            "ReadData",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

// Set up the shared memory.
// In this process, the mapped file must already exist.

    hFileMapping = OpenFileMapping( FILE_MAP_READ, FALSE, "FM_DemoMapObject");

    if (!hFileMapping)
    {   printf("Error %d: OpenFileMapping failed.  ", GetLastError());
        printf("Make sure ChgData is running first.\n");
        return(0);
    }

// MapViewOfFile is used here to get the file mapping mapped into
// this processe's address space.  There is no guarantee about which address
// will be chosen for this process.  The address used by another
// process could be different.  That is why we need based pointers.
// The pointers in this process are based on whatever address is used
// by this process. For another process, the pointers will be based on some
// other address.

    clBasePt = (CHAINLIST *)MapViewOfFile(hFileMapping,
                                          FILE_MAP_READ,
                                          0,0,
                                          0);

    if (clBasePt == NULL)
    {   printf("Error in MapViewOfFile: %d",GetLastError());
        CloseHandle(hFileMapping);
        return(0);
    }

// This loop continuously traverses the linked list, dereferencing the
// link pointers through the base implicitly.

    printf("Press q to quit, or <enter> to display list: ");
    scanf("%c",&cInput);
    while (cInput != 'q')
    {
        clRunning = 0;
        printf("Address of file mapping in this process: 0x%08x\n",(int)clBasePt);
        while (clRunning->clNext != 0)
        {
            printf ("Next Element in chain: %d\n",clRunning->iElement);
            clRunning = clRunning->clNext;
        }

        printf("Press q to quit, anything else to continue: ");
        scanf("%c",&cInput);
    }

// user didn't want any more dumps, so clean up.

    UnmapViewOfFile(clBasePt);
    CloseHandle(hFileMapping);
    return(0);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/SHRSTUFF.H File Reference

  • BPOINTER
Data Structures | Typedefs | Functions

SHRSTUFF.H File Reference

Go to the source code of this file.

Data Structures

struct | CHAINLIST

Typedefs

typedef struct CHAINLIST | CHAINLIST
typedef typedef struct CHAINLIST * | clBasePt

Functions

struct CHAINLIST | __based (clBasePt)*clRunning

Typedef Documentation

typedef struct CHAINLIST CHAINLIST
typedef typedef struct CHAINLIST* clBasePt

Definition at line 19 of file SHRSTUFF.H.

Function Documentation

struct CHAINLIST __based ( clBasePt ) [read]
Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CLIPTEXT/CLIPTEXT.C File Reference

  • CLIPTEXT
Functions | Variables

CLIPTEXT.C File Reference

#include "cliptext.h"
#include <string.h>

Go to the source code of this file.

Functions

BOOL APIENTRY | About (HWND, UINT, UINT, LONG)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, INT)
LONG APIENTRY | MainWndProc (HWND, UINT, UINT, LONG)
VOID | OutOfMemory ()
VOID | OutOfMemory (VOID)
int APIENTRY | WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hAccTable
HANDLE | hClipData
HANDLE | hData
HANDLE | hInst
HANDLE | hText = NULL
HWND | hwnd
LPSTR lpClipData
LPSTR lpData
CHAR | szInitialClientAreaText [] = "application so that you can watch the data exchanges take place. "

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 103 of file CLIPTEXT.C.

{
    WNDCLASS  wc;

    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC) MainWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "CliptextMenu";
    wc.lpszClassName = "CliptextWClass";

    return (RegisterClass(&wc));
}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | INT | nCmdShow
 | ) |  |

Definition at line 130 of file CLIPTEXT.C.

{
    LPSTR           lpszText;

    hInst = hInstance;

    hAccTable = LoadAccelerators(hInst, "ClipTextAcc");

    if (!(hText
          = GlobalAlloc(GMEM_MOVEABLE,(DWORD)sizeof(szInitialClientAreaText)))) {
        OutOfMemory();
        return (FALSE);
    }

    if (!(lpszText = GlobalLock(hText))) {
        OutOfMemory();
        return (FALSE);
    }

    strcpy(lpszText, szInitialClientAreaText);
    GlobalUnlock(hText);

    hwnd = CreateWindow(
        "CliptextWClass",
        "Cliptext Sample Application",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!hwnd)
        return (FALSE);

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    return (TRUE);

}

LONG APIENTRY MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

VOID OutOfMemory ( )

Definition at line 433 of file CLIPTEXT.C.

{
    MessageBox(
        GetFocus(),
        "Out of Memory",
        NULL,
        MB_ICONHAND | MB_SYSTEMMODAL);
    return;
}

VOID OutOfMemory ( VOID )
int APIENTRY WinMain | ( | HANDLE | hInstance,
 |  | HANDLE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 64 of file CLIPTEXT.C.

{
    MSG msg;

    UNREFERENCED_PARAMETER( lpCmdLine );

    if (!hPrevInstance)
        if (!InitApplication(hInstance))
            return (FALSE);

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    while (GetMessage(&msg, NULL, 0, 0)) {

    /* Only translate message if it is not an accelerator message */

        if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return (msg.wParam);
}

Variable Documentation

HANDLE hAccTable

Definition at line 33 of file CLIPTEXT.C.

HANDLE hClipData

Definition at line 46 of file CLIPTEXT.C.

HANDLE hData

Definition at line 46 of file CLIPTEXT.C.

HANDLE hInst

Definition at line 32 of file CLIPTEXT.C.

HANDLE hText = NULL

Definition at line 36 of file CLIPTEXT.C.

HWND hwnd

Definition at line 34 of file CLIPTEXT.C.

LPSTR lpClipData

Definition at line 47 of file CLIPTEXT.C.

LPSTR lpData

Definition at line 47 of file CLIPTEXT.C.

CHAR szInitialClientAreaText[] = "application so that you can watch the data exchanges take place. "

Definition at line 38 of file CLIPTEXT.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CLIPTEXT/CLIPTEXT.H File Reference

  • CLIPTEXT
Defines

CLIPTEXT.H File Reference

#include "windows.h"

Go to the source code of this file.

Defines

#define | IDM_ABOUT 100
#define | IDM_CLEAR 204
#define | IDM_COPY 202
#define | IDM_CUT 201
#define | IDM_EXIT 106
#define | IDM_NEW 101
#define | IDM_OPEN 102
#define | IDM_PASTE 203
#define | IDM_PRINT 105
#define | IDM_SAVE 103
#define | IDM_SAVEAS 104
#define | IDM_UNDO 200

Define Documentation

#define IDM_ABOUT 100

Definition at line 15 of file CLIPTEXT.H.

#define IDM_CLEAR 204

Definition at line 32 of file CLIPTEXT.H.

#define IDM_COPY 202

Definition at line 30 of file CLIPTEXT.H.

#define IDM_CUT 201

Definition at line 29 of file CLIPTEXT.H.

#define IDM_EXIT 106

Definition at line 24 of file CLIPTEXT.H.

#define IDM_NEW 101

Definition at line 19 of file CLIPTEXT.H.

#define IDM_OPEN 102

Definition at line 20 of file CLIPTEXT.H.

#define IDM_PASTE 203

Definition at line 31 of file CLIPTEXT.H.

#define IDM_PRINT 105

Definition at line 23 of file CLIPTEXT.H.

#define IDM_SAVE 103

Definition at line 21 of file CLIPTEXT.H.

#define IDM_SAVEAS 104

Definition at line 22 of file CLIPTEXT.H.

#define IDM_UNDO 200

Definition at line 28 of file CLIPTEXT.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CDERR.H File Reference

  • CMNDLG
Defines

CDERR.H File Reference

Go to the source code of this file.

Defines

#define | CCERR_CHOOSECOLORCODES 0x5000
#define | CDERR_DIALOGFAILURE 0xFFFF
#define | CDERR_FINDRESFAILURE 0x0006
#define | CDERR_GENERALCODES 0x0000
#define | CDERR_INITIALIZATION 0x0002
#define | CDERR_LOADRESFAILURE 0x0007
#define | CDERR_LOADSTRFAILURE 0x0005
#define | CDERR_LOCKRESFAILURE 0x0008
#define | CDERR_MEMALLOCFAILURE 0x0009
#define | CDERR_MEMLOCKFAILURE 0x000A
#define | CDERR_NOHINSTANCE 0x0004
#define | CDERR_NOHOOK 0x000B
#define | CDERR_NOTEMPLATE 0x0003
#define | CDERR_STRUCTSIZE 0x0001
#define | CFERR_CHOOSEFONTCODES 0x2000
#define | CFERR_NOFONTS 0x2001
#define | FNERR_BUFFERTOOSMALL 0x3003
#define | FNERR_FILENAMECODES 0x3000
#define | FNERR_INVALIDFILENAME 0x3002
#define | FNERR_SUBCLASSFAILURE 0x3001
#define | FRERR_FINDREPLACECODES 0x4000
#define | PDERR_CREATEICFAILURE 0x100A
#define | PDERR_DNDMMISMATCH 0x1009
#define | PDERR_GETDEVMODEFAIL 0x1005
#define | PDERR_INITFAILURE 0x1006
#define | PDERR_LOADDRVFAILURE 0x1004
#define | PDERR_NODEFAULTPRN 0x1008
#define | PDERR_NODEVICES 0x1007
#define | PDERR_PARSEFAILURE 0x1002
#define | PDERR_PRINTERCODES 0x1000
#define | PDERR_PRINTERNOTFOUND 0x100B
#define | PDERR_RETDEFFAILURE 0x1003
#define | PDERR_SETUPFAILURE 0x1001

Define Documentation

#define CCERR_CHOOSECOLORCODES 0x5000

Definition at line 49 of file CDERR.H.

#define CDERR_DIALOGFAILURE 0xFFFF

Definition at line 12 of file CDERR.H.

#define CDERR_FINDRESFAILURE 0x0006

Definition at line 20 of file CDERR.H.

#define CDERR_GENERALCODES 0x0000

Definition at line 14 of file CDERR.H.

#define CDERR_INITIALIZATION 0x0002

Definition at line 16 of file CDERR.H.

#define CDERR_LOADRESFAILURE 0x0007

Definition at line 21 of file CDERR.H.

#define CDERR_LOADSTRFAILURE 0x0005

Definition at line 19 of file CDERR.H.

#define CDERR_LOCKRESFAILURE 0x0008

Definition at line 22 of file CDERR.H.

#define CDERR_MEMALLOCFAILURE 0x0009

Definition at line 23 of file CDERR.H.

#define CDERR_MEMLOCKFAILURE 0x000A

Definition at line 24 of file CDERR.H.

#define CDERR_NOHINSTANCE 0x0004

Definition at line 18 of file CDERR.H.

#define CDERR_NOHOOK 0x000B

Definition at line 25 of file CDERR.H.

#define CDERR_NOTEMPLATE 0x0003

Definition at line 17 of file CDERR.H.

#define CDERR_STRUCTSIZE 0x0001

Definition at line 15 of file CDERR.H.

#define CFERR_CHOOSEFONTCODES 0x2000

Definition at line 40 of file CDERR.H.

#define CFERR_NOFONTS 0x2001

Definition at line 41 of file CDERR.H.

#define FNERR_BUFFERTOOSMALL 0x3003

Definition at line 46 of file CDERR.H.

#define FNERR_FILENAMECODES 0x3000

Definition at line 43 of file CDERR.H.

#define FNERR_INVALIDFILENAME 0x3002

Definition at line 45 of file CDERR.H.

#define FNERR_SUBCLASSFAILURE 0x3001

Definition at line 44 of file CDERR.H.

#define FRERR_FINDREPLACECODES 0x4000

Definition at line 48 of file CDERR.H.

#define PDERR_CREATEICFAILURE 0x100A

Definition at line 37 of file CDERR.H.

#define PDERR_DNDMMISMATCH 0x1009

Definition at line 36 of file CDERR.H.

#define PDERR_GETDEVMODEFAIL 0x1005

Definition at line 32 of file CDERR.H.

#define PDERR_INITFAILURE 0x1006

Definition at line 33 of file CDERR.H.

#define PDERR_LOADDRVFAILURE 0x1004

Definition at line 31 of file CDERR.H.

#define PDERR_NODEFAULTPRN 0x1008

Definition at line 35 of file CDERR.H.

#define PDERR_NODEVICES 0x1007

Definition at line 34 of file CDERR.H.

#define PDERR_PARSEFAILURE 0x1002

Definition at line 29 of file CDERR.H.

#define PDERR_PRINTERCODES 0x1000

Definition at line 27 of file CDERR.H.

#define PDERR_PRINTERNOTFOUND 0x100B

Definition at line 38 of file CDERR.H.

#define PDERR_RETDEFFAILURE 0x1003

Definition at line 30 of file CDERR.H.

#define PDERR_SETUPFAILURE 0x1001

Definition at line 28 of file CDERR.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CMNDLG.C File Reference

  • CMNDLG
Functions | Variables

CMNDLG.C File Reference

#include <windows.h>
#include <commdlg.h>
#include <dlgs.h>
#include <stdio.h>
#include <string.h>
#include <cderr.h>
#include "cmndlg.h"

Go to the source code of this file.

Functions

BOOL WINAPI | About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
void | CallFindText (HWND hWnd)
void | CallReplaceText (HWND hWnd)
BOOL CALLBACK | ChooseColorHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK | ChooseFontHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | ChooseNewColor (HWND hWnd)
BOOL | ChooseNewFont (HWND hWnd)
BOOL CALLBACK | EnterNew (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK | FileOpenHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK | FileSaveHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL CALLBACK | FindTextHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | InitApplication (HANDLE hInstance)
BOOL | InitInstance (HANDLE hInstance, int nCmdShow)
LRESULT CALLBACK | MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | OpenNewFile (HWND hWnd)
BOOL CALLBACK | PrintDlgHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
void | PrintFile (HWND hWnd)
BOOL CALLBACK | PrintSetupHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
void | ProcessCDError (DWORD dwErrorCode, HWND hWnd)
BOOL CALLBACK | ReplaceTextHookProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | SaveAs (HWND hWnd)
BOOL | SaveToFile (HWND hWnd)
void | SearchFile (LPFINDREPLACE lpFR)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

CHOOSEFONT | chf
CHOOSECOLOR | chsclr
COLORREF | crColor
DWORD dwFileSize
CHAR | FileBuf [FILE_LEN]
UINT | FindReplaceMsg
FINDREPLACE | frText
HWND | hDlgFR = NULL
HANDLE | hInst
LOGFONT | lf
CHAR * | lpBufPtr = FileBuf
LPFINDREPLACE | lpFR
OPENFILENAME | OpenFileName
PRINTDLG | pd
CHAR | szDirName [256] = ""
CHAR | szFile [256] = "\0"
CHAR | szFileTitle [256]
CHAR | szFilter [] = "Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0"
CHAR | szFindString [64] = ""
CHAR | szReplaceString [64] = ""
WORD | wMode = IDM_STANDARD

Function Documentation

BOOL WINAPI About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 531 of file CMNDLG.C.

{
    switch (message)
    {
        case WM_INITDIALOG:                /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (LOWORD(wParam) == IDOK          /* "OK" box selected?        */
                || LOWORD(wParam) == IDCANCEL) {        /* System menu close command? */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */

    // avoid compiler warnings at W3
    lParam;
}

void CallFindText ( HWND hWnd )

Definition at line 1517 of file CMNDLG.C.

{

    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = (LPSTR)NULL;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = 0;
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags =  FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                 FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FINDDLGORD);
            break;
    }

    if ((hDlgFR = FindText(&frText)) == NULL)
        ProcessCDError(CommDlgExtendedError(), hWnd );

}

void CallReplaceText ( HWND hWnd )

Definition at line 1576 of file CMNDLG.C.

{
    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = szReplaceString;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = sizeof( szReplaceString );
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(REPLACEDLGORD);
            break;
    }

    if ( (hDlgFR = ReplaceText( &frText )) == NULL )
            ProcessCDError(CommDlgExtendedError(), hWnd );

}

BOOL CALLBACK ChooseColorHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 964 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to change the color?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK ChooseFontHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 1084 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (chf.Flags & CF_ENABLETEMPLATE)
            {
                ShowWindow(GetDlgItem(hDlg, stc4), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, cmb4), SW_HIDE);
            }
            break;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to change the font?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL ChooseNewColor ( HWND hWnd )

Definition at line 1009 of file CMNDLG.C.

{

    DWORD dwColor;
    DWORD dwCustClrs[16];
    BOOL fSetColor = FALSE;
    int i;

    for (i=0; i < 15; i++)
        dwCustClrs[i] = RGB( 255, 255, 255);

    dwColor = RGB( 0, 0, 0 );

    chsclr.lStructSize = sizeof(CHOOSECOLOR);
    chsclr.hwndOwner = hWnd;
    chsclr.hInstance = (HANDLE)hInst;
    chsclr.rgbResult = dwColor;
    chsclr.lpCustColors = (LPDWORD)dwCustClrs;
    chsclr.lCustData = 0L;

    switch( wMode )
    {
        case IDM_HOOK:
        case IDM_CUSTOM:
            chsclr.Flags = CC_PREVENTFULLOPEN | CC_ENABLEHOOK;
            chsclr.lpfnHook = (LPCCHOOKPROC)MakeProcInstance(ChooseColorHookProc, NULL);
            chsclr.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_STANDARD:
            chsclr.Flags = CC_PREVENTFULLOPEN;
            chsclr.lpfnHook = (LPCCHOOKPROC)(FARPROC)NULL;
            chsclr.lpTemplateName = (LPSTR)NULL;
            break;

   }

   if ( fSetColor = ChooseColor( &chsclr ))
   {
       crColor = chsclr.rgbResult;
       return (TRUE);
   }
   else
   {
       ProcessCDError(CommDlgExtendedError(), hWnd );
       return FALSE;
   }
}

BOOL ChooseNewFont ( HWND hWnd )

Definition at line 1137 of file CMNDLG.C.

{

   HDC hDC;

   hDC = GetDC( hWnd );
   chf.hDC = CreateCompatibleDC( hDC );
   ReleaseDC( hWnd, hDC );
   chf.lStructSize = sizeof(CHOOSEFONT);
   chf.hwndOwner = hWnd;
   chf.lpLogFont = &lf;
   chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
   chf.rgbColors = RGB(0, 255, 255);
   chf.lCustData = 0;
   chf.hInstance = (HANDLE)hInst;
   chf.lpszStyle = (LPSTR)NULL;
   chf.nFontType = SCREEN_FONTTYPE;
   chf.nSizeMin = 0;
   chf.nSizeMax = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
            chf.lpfnHook = (LPCFHOOKPROC)(FARPROC)NULL;
            chf.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK;
            chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
            chf.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK |
              CF_ENABLETEMPLATE;
            chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
            chf.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FORMATDLGORD31);
            break;
   }

   if( ChooseFont( &chf ) == FALSE )
   {
        DeleteDC( hDC );
        ProcessCDError(CommDlgExtendedError(), hWnd );
        return FALSE;
   }

   DeleteDC( hDC );

   return (TRUE);
}

BOOL CALLBACK EnterNew | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 479 of file CMNDLG.C.

{
    CHAR Buf[FILE_LEN-1];

    switch (message)
    {
        case WM_INITDIALOG:                /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, IDEDIT, Buf, FILE_LEN-1);
                strcpy( FileBuf, Buf);
                lpBufPtr = FileBuf;
                dwFileSize = strlen(FileBuf);
                EndDialog( hDlg, TRUE );
                return (TRUE);
            }
            else if (LOWORD(wParam) == IDCANCEL)
            {   /* System menu close command? */
                EndDialog(hDlg, FALSE);       /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */

    // avoid compiler warnings at W3
    lParam;
}

BOOL CALLBACK FileOpenHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 578 of file CMNDLG.C.

{

    int hFile;
    CHAR szTempText[256];
    CHAR szString[256];
    OFSTRUCT OfStruct;

    switch (message)
    {

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, edt1, szTempText,
                        sizeof( szTempText ) - 1);

                if ( OpenFileName.Flags & OFN_PATHMUSTEXIST )
                {
                    sprintf( szString, "Are you sure you want to open %s?",
                        szTempText);
                    if ( MessageBox( hDlg, szString, "Information",
                        MB_YESNO ) == IDYES )

                        break;
                    return (TRUE);
                }

                // check to see if the Create File box has been checked
                if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
                    BM_GETCHECK, 0, 0L )) == TRUE )
                {
                    // if so, create the file
                    if ((hFile = OpenFile(szTempText,
                        &OfStruct,
                        OF_CREATE)) == -1)
                    {
                        MessageBox( hDlg,
                            "Directory could not be created.",
                            NULL,
                            MB_OK );
                        return (FALSE);
                    }

                    strcpy(FileBuf, "Empty");
                    lpBufPtr = FileBuf;
                    dwFileSize = strlen(FileBuf);
                    if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
                        MessageBox( hDlg, "Error writing file.", NULL, MB_OK );

                    // close the file
                    _lclose( hFile );
                }

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK FileSaveHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 824 of file CMNDLG.C.

{
    CHAR szTempText[256];
    CHAR szString[256];

    switch (message)
    {
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, edt1, szTempText,
                    sizeof( szTempText ) - 1);
                if ( OpenFileName.Flags & OFN_ENABLETEMPLATE )
                {
                    // check to see if the Create File box has been checked
                    if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
                        BM_GETCHECK, 0, 0L )) == FALSE )
                        OpenFileName.Flags |= OFN_FILEMUSTEXIST;
                    break;

                }
                else
                {
                    sprintf( szString, "Are you sure you want to save %s?",
                        szTempText);
                    if ( MessageBox( hDlg, szString, "Information",
                        MB_YESNO ) == IDYES )
                        break;
                    return(TRUE);
                }

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK FindTextHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 1465 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (frText.Flags & FR_ENABLETEMPLATE )
            {
                ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad2), SW_HIDE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        default:
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 168 of file CMNDLG.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).                    */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "CmnDlgMenu";   /* Name of menu resource in .RC file. */
    wc.lpszClassName = "CmnDlgWClass"; /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 207 of file CMNDLG.C.

{
    HWND            hWnd;               /* Main window handle.                */

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    hInst = hInstance;

    /* Create a main window for this application instance.  */

    hWnd = CreateWindow(
        "CmnDlgWClass",                 /* See RegisterClass() call.          */
        "Common Dialogs Sample Application",   /* Text for window title bar.         */
        WS_OVERLAPPEDWINDOW,            /* Window style.                      */
        CW_USEDEFAULT,                  /* Default horizontal position.       */
        CW_USEDEFAULT,                  /* Default vertical position.         */
        CW_USEDEFAULT,                  /* Default width.                     */
        CW_USEDEFAULT,                  /* Default height.                    */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer not needed.                */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    /* Make the window visible; update its client area; and return "success" */

    ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */
    return (TRUE);               /* Returns the value from PostQuitMessage */

}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 264 of file CMNDLG.C.

{
    FARPROC lpProcAbout;          /* pointer to the "About" function */
    FARPROC lpProcEnterNew;       /* pointer to the "EnterNew" function */
    HDC hDC;
    PAINTSTRUCT ps;
    INT nDrawX;
    INT nDrawY;
    HFONT hFont;
    HANDLE Handle;
    static BOOL NewFont;

    switch (message) {

        case WM_CREATE:
            //initialize the output on the screen
            strcpy( FileBuf, "Hello World!");
            lpBufPtr = FileBuf;
            dwFileSize = strlen(FileBuf);
            crColor = 0;
            NewFont = FALSE;
            break;

        case WM_PAINT:
            /* Set up a display context to begin painting */
            hDC = BeginPaint (hWnd, &ps);

            /* Initialize drawing position to 1/4 inch from the top  */
            /* and from the left of the top, left corner of the      */
            /* client area of the main windows.                      */
            nDrawX = GetDeviceCaps(hDC, LOGPIXELSX) / 4;   /* 1/4 inch */
            nDrawY = GetDeviceCaps(hDC, LOGPIXELSY) / 4;   /* 1/4 inch */

            if ( NewFont == TRUE )
            {
                hFont = CreateFontIndirect( &lf );
                Handle = SelectObject( hDC, hFont );
            }

            SetTextColor( hDC, crColor );
            TextOut (hDC, nDrawX, nDrawY, (LPSTR)&FileBuf[0], dwFileSize);

            // end painting and release hDC
            EndPaint( hWnd, &ps );
            break;

        case WM_COMMAND:           /* message: command from application menu */

            switch( LOWORD( wParam ))
            {
                case IDM_OPENFILE:
                    if ( OpenNewFile( hWnd ) == TRUE )
                    {
                        // enable the Save As and Print menu items
                        EnableMenuItem( GetMenu( hWnd ), IDM_SAVEFILE,
                            MF_BYCOMMAND | MF_ENABLED );
                        EnableMenuItem( GetMenu( hWnd ), IDM_PRINT,
                            MF_BYCOMMAND | MF_ENABLED );
                        DrawMenuBar( hWnd);
                        // reset the title in the title bar to reflect the
                        // new open file
                        SetWindowText( hWnd, OpenFileName.lpstrFile );
                        // reset the current color and current font to the
                        // default
                        crColor = 0;
                        NewFont = FALSE;
                        InvalidateRect( hWnd, NULL, TRUE );
                    }
                    break;

                case IDM_SAVEFILE:
                    OpenFileName.Flags = 0L;
                    SaveToFile( hWnd );
                    break;

                case IDM_SAVEFILEAS:
                    if ( SaveAs( hWnd ) == TRUE )
                    {
                        EnableMenuItem( GetMenu( hWnd ), IDM_SAVEFILE,
                            MF_BYCOMMAND | MF_ENABLED );
                        SetWindowText( hWnd, OpenFileName.lpstrFile );
                        DrawMenuBar( hWnd );
                    }
                    break;

                case IDM_EXIT:
                    PostQuitMessage(0);
                    break;

                case IDM_PRINT:
                    PrintFile( hWnd );
                    break;

                case IDM_CHOOSECOLOR:
                    if (ChooseNewColor( hWnd ))
                        InvalidateRect( hWnd, NULL, TRUE );
                    break;

                case IDM_CHOOSEFONT:
                    if (NewFont = ChooseNewFont( hWnd ))
                        InvalidateRect( hWnd, NULL, TRUE );

                    break;

                case IDM_FINDTEXT:
                    CallFindText( hWnd );
                    break;

                case IDM_REPLACETEXT:
                    CallReplaceText( hWnd );
                    break;

                case IDM_STANDARD:
                  // enable the ChooseColor() option
                    EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR,
                            MF_BYCOMMAND | MF_ENABLED );
                    // uncheck previous selection
                    CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
                    //reset mode
                    wMode = LOWORD(wParam);
                    //check new selection
                    CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
                    DrawMenuBar( hWnd);
                    break;
                case IDM_HOOK:
                case IDM_CUSTOM:
                    // disable the ChooseColor() option
                    EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR,
                            MF_BYCOMMAND | MF_GRAYED );
                     // uncheck previous selection
                    CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
                    //reset mode
                    wMode = LOWORD(wParam);
                    //check new selection
                    CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
                    DrawMenuBar( hWnd);
                    break;

                case IDM_ENTERNEW:
                    lpProcEnterNew = MakeProcInstance((FARPROC)EnterNew, hInst);

                    if (DialogBox(hInst,                 /* current instance         */
                        "EnterNewBox",           /* resource to use          */
                        hWnd,                    /* parent handle            */
                        (DLGPROC)lpProcEnterNew) == TRUE)

                        InvalidateRect( hWnd, NULL, TRUE );

                    FreeProcInstance(lpProcEnterNew);
                    break;

                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);

                    DialogBox(hInst,             /* current instance         */
                        "AboutBox",                      /* resource to use          */
                        hWnd,                    /* parent handle            */
                        (DLGPROC)lpProcAbout);           /* About() instance address */

                    FreeProcInstance(lpProcAbout);
                    break;

                default:
                    return (DefWindowProc(hWnd, message, wParam, lParam));

            }
            break;

        case WM_DESTROY:                  /* message: window being destroyed */
            PostQuitMessage(0);
            break;

        default:
            // Handle the special findreplace message (FindReplaceMsg) which
            // was registered at initialization time.
            if ( message == FindReplaceMsg )
            {
                if ( lpFR = (LPFINDREPLACE) lParam )
                    {
                    if (lpFR->Flags & FR_DIALOGTERM )  // terminating dialog
                        return (0);
                    SearchFile( lpFR );
                    InvalidateRect( hWnd, NULL, TRUE );
                    }
                return (0);
            }

            return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

HANDLE OpenNewFile ( HWND hWnd )

Definition at line 664 of file CMNDLG.C.

{
   int hFile;
   int cBufLen;
   OFSTRUCT OfStruct;
   WORD wStyle;

   strcpy( szFile, "");
   strcpy( szFileTitle, "");

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.hwndOwner         = hWnd;
   OpenFileName.hInstance         = (HANDLE) hInst;
   OpenFileName.lpstrFilter       = szFilter;
   OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
   OpenFileName.nMaxCustFilter    = 0L;
   OpenFileName.nFilterIndex      = 1L;
   OpenFileName.lpstrFile         = szFile;
   OpenFileName.nMaxFile          = sizeof(szFile);
   OpenFileName.lpstrFileTitle    = szFileTitle;
   OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = "Open a File";
   OpenFileName.nFileOffset       = 0;
   OpenFileName.nFileExtension    = 0;
   OpenFileName.lpstrDefExt       = "*.txt";
   OpenFileName.lCustData         = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
                OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            break;

        case IDM_HOOK:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
                OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
            break;

        case IDM_CUSTOM:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_ENABLEHOOK |
                OFN_HIDEREADONLY | OFN_ENABLETEMPLATE;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
            break;
   }

   if (GetOpenFileName(&OpenFileName))
   {
      if (OpenFileName.Flags & OFN_READONLY )
        wStyle = OF_READ;
      else
        wStyle = OF_READWRITE;

      // open the file
      hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct, wStyle );
      if (hFile == -1)
      {
         MessageBox( hWnd, "File open failed.", NULL, MB_OK );
         return FALSE;
      }
      // read it's contents into a buffer
      cBufLen = _lread( hFile, FileBuf, FILE_LEN );
      lpBufPtr = FileBuf;

      if (cBufLen == -1)
      {
         MessageBox( hWnd, "Zero bytes read.", NULL, MB_OK );
         return FALSE;
      }
      // close the file
      _lclose( hFile );

      dwFileSize = cBufLen;
    }
    else
    {
      ProcessCDError(CommDlgExtendedError(), hWnd );
      return FALSE;
    }
    return TRUE;
}

BOOL CALLBACK PrintDlgHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 1264 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLEPRINTTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to print?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

void PrintFile ( HWND hWnd )

Definition at line 1327 of file CMNDLG.C.

{

    // initialize PRINTDLG structure
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.hDevMode = (HANDLE)NULL;
    pd.hDevNames = (HANDLE)NULL;
    pd.nFromPage = 0;
    pd.nToPage = 0;
    pd.nMinPage = 0;
    pd.nMaxPage = 0;
    pd.nCopies = 0;
    pd.hInstance = (HANDLE)hInst;

    switch( wMode )
    {
        case IDM_STANDARD:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL;
            pd.lpSetupTemplateName = (LPSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL;
            pd.lpPrintTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
            pd.lpSetupTemplateName = (LPSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
            pd.lpPrintTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
                PD_ENABLESETUPHOOK | PD_ENABLESETUPTEMPLATE | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
            pd.lpSetupTemplateName = (LPSTR)MAKEINTRESOURCE(PRNSETUPDLGORD);
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
            pd.lpPrintTemplateName = (LPSTR)MAKEINTRESOURCE(PRINTDLGORD);
            break;

    }

    //print a test page if successful
    if (PrintDlg(&pd) == TRUE)
    {
        Escape(pd.hDC, STARTDOC, 8, "Test-Doc", NULL);

        //Print text
        TextOut(pd.hDC, 5, 5, FileBuf, strlen(FileBuf));

        Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
        Escape(pd.hDC, ENDDOC, 0, NULL, NULL );
        DeleteDC(pd.hDC);
        if (pd.hDevMode)
            GlobalFree(pd.hDevMode);
        if (pd.hDevNames)
            GlobalFree(pd.hDevNames);
    }
   else
        ProcessCDError(CommDlgExtendedError(), hWnd );
}

BOOL CALLBACK PrintSetupHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 1213 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLESETUPTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

void ProcessCDError | ( | DWORD | dwErrorCode,
 |  | HWND | hWnd
 | ) |  |

Definition at line 1735 of file CMNDLG.C.

{
   WORD  wStringID;
   CHAR  buf[256];

   switch(dwErrorCode)
      {
         case CDERR_DIALOGFAILURE:   wStringID=IDS_DIALOGFAILURE;   break;
         case CDERR_STRUCTSIZE:      wStringID=IDS_STRUCTSIZE;      break;
         case CDERR_INITIALIZATION:  wStringID=IDS_INITIALIZATION;  break;
         case CDERR_NOTEMPLATE:      wStringID=IDS_NOTEMPLATE;      break;
         case CDERR_NOHINSTANCE:     wStringID=IDS_NOHINSTANCE;     break;
         case CDERR_LOADSTRFAILURE:  wStringID=IDS_LOADSTRFAILURE;  break;
         case CDERR_FINDRESFAILURE:  wStringID=IDS_FINDRESFAILURE;  break;
         case CDERR_LOADRESFAILURE:  wStringID=IDS_LOADRESFAILURE;  break;
         case CDERR_LOCKRESFAILURE:  wStringID=IDS_LOCKRESFAILURE;  break;
         case CDERR_MEMALLOCFAILURE: wStringID=IDS_MEMALLOCFAILURE; break;
         case CDERR_MEMLOCKFAILURE:  wStringID=IDS_MEMLOCKFAILURE;  break;
         case CDERR_NOHOOK:          wStringID=IDS_NOHOOK;          break;
         case PDERR_SETUPFAILURE:    wStringID=IDS_SETUPFAILURE;    break;
         case PDERR_PARSEFAILURE:    wStringID=IDS_PARSEFAILURE;    break;
         case PDERR_RETDEFFAILURE:   wStringID=IDS_RETDEFFAILURE;   break;
         case PDERR_LOADDRVFAILURE:  wStringID=IDS_LOADDRVFAILURE;  break;
         case PDERR_GETDEVMODEFAIL:  wStringID=IDS_GETDEVMODEFAIL;  break;
         case PDERR_INITFAILURE:     wStringID=IDS_INITFAILURE;     break;
         case PDERR_NODEVICES:       wStringID=IDS_NODEVICES;       break;
         case PDERR_NODEFAULTPRN:    wStringID=IDS_NODEFAULTPRN;    break;
         case PDERR_DNDMMISMATCH:    wStringID=IDS_DNDMMISMATCH;    break;
         case PDERR_CREATEICFAILURE: wStringID=IDS_CREATEICFAILURE; break;
         case PDERR_PRINTERNOTFOUND: wStringID=IDS_PRINTERNOTFOUND; break;
         case CFERR_NOFONTS:         wStringID=IDS_NOFONTS;         break;
         case FNERR_SUBCLASSFAILURE: wStringID=IDS_SUBCLASSFAILURE; break;
         case FNERR_INVALIDFILENAME: wStringID=IDS_INVALIDFILENAME; break;
         case FNERR_BUFFERTOOSMALL:  wStringID=IDS_BUFFERTOOSMALL;  break;

         case 0:   //User may have hit CANCEL or we got a *very* random error
            return;

         default:
            wStringID=IDS_UNKNOWNERROR;
      }

   LoadString(NULL, wStringID, buf, sizeof(buf));
   MessageBox(hWnd, buf, NULL, MB_OK);
   return;
}

BOOL CALLBACK ReplaceTextHookProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 1415 of file CMNDLG.C.

{
    switch (message)
    {
        case WM_INITDIALOG:
            if (frText.Flags & FR_ENABLETEMPLATE )
                {
                    ShowWindow( GetDlgItem(hDlg, psh2), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        default:
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

BOOL SaveAs ( HWND hWnd )

Definition at line 887 of file CMNDLG.C.

{

   strcpy( szFile, "");
   strcpy( szFileTitle, "");

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.hwndOwner         = hWnd;
   OpenFileName.hInstance         = (HANDLE) hInst;
   OpenFileName.lpstrFilter       = szFilter;
   OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
   OpenFileName.nMaxCustFilter    = 0L;
   OpenFileName.nFilterIndex      = 1L;
   OpenFileName.lpstrFile         = szFile;
   OpenFileName.nMaxFile          = sizeof(szFile);
   OpenFileName.lpstrFileTitle    = szFileTitle;
   OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = "Save File As";
   OpenFileName.nFileOffset       = 0;
   OpenFileName.nFileExtension    = 0;
   OpenFileName.lpstrDefExt       = "txt";
   OpenFileName.lCustData         = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            OpenFileName.Flags = 0L;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)(FARPROC)NULL;
            OpenFileName.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            OpenFileName.Flags = OFN_ENABLEHOOK;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            OpenFileName.Flags = OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
            break;
   }

   if ( GetSaveFileName( &OpenFileName ))
        return(SaveToFile( hWnd ));
   else
   {
        ProcessCDError(CommDlgExtendedError(), hWnd );
        return FALSE;
   }

   return (FALSE);
}

BOOL SaveToFile ( HWND hWnd )

Definition at line 765 of file CMNDLG.C.

{
   int hFile;
   OFSTRUCT OfStruct;
   WORD wStyle;
   CHAR buf[256];

   if (OpenFileName.Flags | OFN_FILEMUSTEXIST)
        wStyle = OF_READWRITE;
   else
        wStyle = OF_READWRITE | OF_CREATE;

   if ((hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct,
         wStyle)) == -1)
   {
      sprintf( buf, "Could not create file %s", OpenFileName.lpstrFile );
      MessageBox( hWnd, buf, NULL, MB_OK );
      return FALSE;
   }
   // write it's contents into a file
   if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
   {
      MessageBox( hWnd, "Error writing file.", NULL, MB_OK );
      return FALSE;
   }

   // close the file
   _lclose( hFile );

   sprintf( buf, "%s", OpenFileName.lpstrFile );
   MessageBox( hWnd, buf, "File Saved", MB_OK );
   return TRUE;
}

void SearchFile ( LPFINDREPLACE lpFR )

Definition at line 1634 of file CMNDLG.C.

{

    CHAR Buf[FILE_LEN];
    CHAR *pStr;
    int count, newcount;
    static BOOL bFoundLast = FALSE;

if ( lpFR->Flags & ( FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL ) )
    {
    memset(Buf, '\0', FILE_LEN -1);
    if ( bFoundLast )
        {
        if ( (lpBufPtr != FileBuf) && (lpFR->Flags & FR_FINDNEXT) )
            lpBufPtr++;
        bFoundLast = FALSE;
        }

    if (!*lpBufPtr || !(pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) )
        {
        sprintf( Buf, "'%s' not found!", lpFR->lpstrFindWhat );
        lpBufPtr = FileBuf;
        MessageBox( lpFR->hwndOwner, Buf, "No luck", MB_OK | MB_TASKMODAL);
        }
    else
        {
        if ( lpFR->Flags & FR_FINDNEXT )
            {
            sprintf( Buf, "Found Next '%s'!\nSubstring: '%.10s'",
                     lpFR->lpstrFindWhat, pStr );
            lpBufPtr = pStr;
            bFoundLast = TRUE;
            MessageBox( lpFR->hwndOwner, Buf, "Success!", MB_OK | MB_TASKMODAL );
            }
        else if ( lpFR->Flags & FR_REPLACE )
            {
            // replace string specified in the replace with found string
            // copy up to found string into new buffer
            for( count=0;
                 *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
                 count++);
                strncpy( Buf, lpBufPtr, count );
            // concatenate new string
            strcat( Buf, lpFR->lpstrReplaceWith );
            // copy rest of string (less the found string)
            newcount = count + strlen(lpFR->lpstrFindWhat);
            strcat( Buf, lpBufPtr+newcount);
            strcpy( lpBufPtr, Buf );
            lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
            dwFileSize = strlen(FileBuf);
            MessageBox( lpFR->hwndOwner, FileBuf, "Success!", MB_OK | MB_TASKMODAL );
            }
        else if ( lpFR->Flags & FR_REPLACEALL)
            {
            do
                {
                // replace string specified in the replace with found string
                // copy up to found string into new buffer
                memset(Buf, '\0', FILE_LEN -1);
                for( count=0;
                     *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
                     count++);
                     strncpy( Buf, lpBufPtr, count );
                // concatenate new string
                strcat( Buf, lpFR->lpstrReplaceWith );
                // copy rest of string (less the found string)
                newcount = count + strlen(lpFR->lpstrFindWhat);
                strcat( Buf, lpBufPtr + newcount);
                strcpy( lpBufPtr, Buf );
                lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
                }
            while ( *lpBufPtr &&
                    (pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) );
            dwFileSize = strlen(FileBuf);
            lpBufPtr = FileBuf;
            MessageBox( lpFR->hwndOwner, FileBuf,
                        "Success!", MB_OK | MB_TASKMODAL );
            }

        }
    }
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 112 of file CMNDLG.C.

{

    MSG msg;                         /* message                      */

    if (!hPrevInstance)                  /* Other instances of app running? */
        if (!InitApplication(hInstance)) /* Initialize shared things */
            return (FALSE);              /* Exits if unable to initialize     */

    hInst = hInstance;

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    // register window message for FindText() and ReplaceText() hook procs
    FindReplaceMsg = RegisterWindowMessage( (LPSTR) FINDMSGSTRING );

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,        /* message structure                      */
            NULL,                  /* handle of window receiving the message */
            0,                     /* lowest message to examine              */
            0))                    /* highest message to examine             */
        if ( !hDlgFR || !IsWindow(hDlgFR) || !IsDialogMessage( hDlgFR, &msg ) )
            {
            TranslateMessage(&msg);    /* Translates virtual key codes */
            DispatchMessage(&msg);     /* Dispatches message to window */
            }
    return (msg.wParam);           /* Returns the value from PostQuitMessage */

    // avoid compiler warnings at W3
    lpCmdLine;
}

Variable Documentation

CHOOSEFONT chf

Definition at line 93 of file CMNDLG.C.

CHOOSECOLOR chsclr

Definition at line 94 of file CMNDLG.C.

COLORREF crColor

Definition at line 95 of file CMNDLG.C.

DWORD dwFileSize

Definition at line 86 of file CMNDLG.C.

CHAR FileBuf[FILE_LEN]

Definition at line 85 of file CMNDLG.C.

UINT FindReplaceMsg

Definition at line 87 of file CMNDLG.C.

FINDREPLACE frText

Definition at line 90 of file CMNDLG.C.

HWND hDlgFR = NULL

Definition at line 98 of file CMNDLG.C.

HANDLE hInst

Definition at line 73 of file CMNDLG.C.

LOGFONT lf

Definition at line 96 of file CMNDLG.C.

CHAR* lpBufPtr = FileBuf

Definition at line 92 of file CMNDLG.C.

LPFINDREPLACE lpFR

Definition at line 91 of file CMNDLG.C.

OPENFILENAME OpenFileName

Definition at line 74 of file CMNDLG.C.

PRINTDLG pd

Definition at line 99 of file CMNDLG.C.

CHAR szDirName[256] = ""

Definition at line 75 of file CMNDLG.C.

CHAR szFile[256] = "\0"

Definition at line 76 of file CMNDLG.C.

CHAR szFileTitle[256]

Definition at line 77 of file CMNDLG.C.

CHAR szFilter[] = "Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0"

Definition at line 83 of file CMNDLG.C.

CHAR szFindString[64] = ""

Definition at line 88 of file CMNDLG.C.

CHAR szReplaceString[64] = ""

Definition at line 89 of file CMNDLG.C.

WORD wMode = IDM_STANDARD

Definition at line 97 of file CMNDLG.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CMNDLG.H File Reference

  • CMNDLG
Defines | Functions

CMNDLG.H File Reference

Go to the source code of this file.

Defines

#define | FILE_LEN 80
#define | IDEDIT 500
#define | IDM_ABOUT 300
#define | IDM_CHOOSECOLOR 201
#define | IDM_CHOOSEFONT 202
#define | IDM_CUSTOM 207
#define | IDM_ENTERNEW 200
#define | IDM_EXIT 104
#define | IDM_FINDTEXT 203
#define | IDM_HOOK 206
#define | IDM_OPENFILE 100
#define | IDM_PRINT 103
#define | IDM_REPLACETEXT 204
#define | IDM_SAVEFILE 101
#define | IDM_SAVEFILEAS 102
#define | IDM_STANDARD 205
#define | IDS_BUFFERTOOSMALL 27
#define | IDS_CREATEICFAILURE 22
#define | IDS_DIALOGFAILURE 1
#define | IDS_DNDMMISMATCH 21
#define | IDS_FILTERSTRING 28
#define | IDS_FINDRESFAILURE 7
#define | IDS_GETDEVMODEFAIL 17
#define | IDS_INITFAILURE 18
#define | IDS_INITIALIZATION 3
#define | IDS_INVALIDFILENAME 26
#define | IDS_LOADDRVFAILURE 16
#define | IDS_LOADRESFAILURE 8
#define | IDS_LOADSTRFAILURE 6
#define | IDS_LOCKRESFAILURE 9
#define | IDS_MEMALLOCFAILURE 10
#define | IDS_MEMLOCKFAILURE 11
#define | IDS_NODEFAULTPRN 20
#define | IDS_NODEVICES 19
#define | IDS_NOFONTS 24
#define | IDS_NOHINSTANCE 5
#define | IDS_NOHOOK 12
#define | IDS_NOTEMPLATE 4
#define | IDS_PARSEFAILURE 14
#define | IDS_PRINTERNOTFOUND 23
#define | IDS_RETDEFFAILURE 15
#define | IDS_SETUPFAILURE 13
#define | IDS_STRUCTSIZE 2
#define | IDS_SUBCLASSFAILURE 25
#define | IDS_UNKNOWNERROR 29

Functions

BOOL CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
void | CallFindText (HWND)
void | CallReplaceText (HWND)
BOOL CALLBACK | ChooseColorHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL CALLBACK | ChooseFontHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL | ChooseNewColor (HWND)
BOOL | ChooseNewFont (HWND)
BOOL CALLBACK | EnterNew (HWND, UINT, WPARAM, LPARAM)
BOOL CALLBACK | FileOpenHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL CALLBACK | FileSaveHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL CALLBACK | FindTextHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
BOOL | OpenNewFile (HWND)
BOOL CALLBACK | PrintDlgHookProc (HWND, UINT, WPARAM, LPARAM)
void | PrintFile (HWND)
BOOL CALLBACK | PrintSetupHookProc (HWND, UINT, WPARAM, LPARAM)
void | ProcessCDError (DWORD, HWND)
BOOL CALLBACK | ReplaceTextHookProc (HWND, UINT, WPARAM, LPARAM)
BOOL | SaveAs (HWND)
BOOL | SaveToFile (HWND)
void | SearchFile (LPFINDREPLACE)

Define Documentation

#define FILE_LEN 80

Definition at line 73 of file CMNDLG.H.

#define IDEDIT 500

Definition at line 37 of file CMNDLG.H.

#define IDM_ABOUT 300

Definition at line 33 of file CMNDLG.H.

#define IDM_CHOOSECOLOR 201

Definition at line 24 of file CMNDLG.H.

#define IDM_CHOOSEFONT 202

Definition at line 25 of file CMNDLG.H.

#define IDM_CUSTOM 207

Definition at line 30 of file CMNDLG.H.

#define IDM_ENTERNEW 200

Definition at line 23 of file CMNDLG.H.

#define IDM_EXIT 104

Definition at line 20 of file CMNDLG.H.

#define IDM_FINDTEXT 203

Definition at line 26 of file CMNDLG.H.

#define IDM_HOOK 206

Definition at line 29 of file CMNDLG.H.

#define IDM_OPENFILE 100

Definition at line 16 of file CMNDLG.H.

#define IDM_PRINT 103

Definition at line 19 of file CMNDLG.H.

#define IDM_REPLACETEXT 204

Definition at line 27 of file CMNDLG.H.

#define IDM_SAVEFILE 101

Definition at line 17 of file CMNDLG.H.

#define IDM_SAVEFILEAS 102

Definition at line 18 of file CMNDLG.H.

#define IDM_STANDARD 205

Definition at line 28 of file CMNDLG.H.

#define IDS_BUFFERTOOSMALL 27

Definition at line 67 of file CMNDLG.H.

#define IDS_CREATEICFAILURE 22

Definition at line 62 of file CMNDLG.H.

#define IDS_DIALOGFAILURE 1

Definition at line 41 of file CMNDLG.H.

#define IDS_DNDMMISMATCH 21

Definition at line 61 of file CMNDLG.H.

#define IDS_FILTERSTRING 28

Definition at line 68 of file CMNDLG.H.

#define IDS_FINDRESFAILURE 7

Definition at line 47 of file CMNDLG.H.

#define IDS_GETDEVMODEFAIL 17

Definition at line 57 of file CMNDLG.H.

#define IDS_INITFAILURE 18

Definition at line 58 of file CMNDLG.H.

#define IDS_INITIALIZATION 3

Definition at line 43 of file CMNDLG.H.

#define IDS_INVALIDFILENAME 26

Definition at line 66 of file CMNDLG.H.

#define IDS_LOADDRVFAILURE 16

Definition at line 56 of file CMNDLG.H.

#define IDS_LOADRESFAILURE 8

Definition at line 48 of file CMNDLG.H.

#define IDS_LOADSTRFAILURE 6

Definition at line 46 of file CMNDLG.H.

#define IDS_LOCKRESFAILURE 9

Definition at line 49 of file CMNDLG.H.

#define IDS_MEMALLOCFAILURE 10

Definition at line 50 of file CMNDLG.H.

#define IDS_MEMLOCKFAILURE 11

Definition at line 51 of file CMNDLG.H.

#define IDS_NODEFAULTPRN 20

Definition at line 60 of file CMNDLG.H.

#define IDS_NODEVICES 19

Definition at line 59 of file CMNDLG.H.

#define IDS_NOFONTS 24

Definition at line 64 of file CMNDLG.H.

#define IDS_NOHINSTANCE 5

Definition at line 45 of file CMNDLG.H.

#define IDS_NOHOOK 12

Definition at line 52 of file CMNDLG.H.

#define IDS_NOTEMPLATE 4

Definition at line 44 of file CMNDLG.H.

#define IDS_PARSEFAILURE 14

Definition at line 54 of file CMNDLG.H.

#define IDS_PRINTERNOTFOUND 23

Definition at line 63 of file CMNDLG.H.

#define IDS_RETDEFFAILURE 15

Definition at line 55 of file CMNDLG.H.

#define IDS_SETUPFAILURE 13

Definition at line 53 of file CMNDLG.H.

#define IDS_STRUCTSIZE 2

Definition at line 42 of file CMNDLG.H.

#define IDS_SUBCLASSFAILURE 25

Definition at line 65 of file CMNDLG.H.

#define IDS_UNKNOWNERROR 29

Definition at line 69 of file CMNDLG.H.

Function Documentation

BOOL CALLBACK About | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 497 of file BOB.C.

{
    switch (message) {
        case WM_INITDIALOG:           /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command?  */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

void CallFindText ( HWND )

Definition at line 1517 of file CMNDLG.C.

{

    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = (LPSTR)NULL;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = 0;
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags =  FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                 FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FINDDLGORD);
            break;
    }

    if ((hDlgFR = FindText(&frText)) == NULL)
        ProcessCDError(CommDlgExtendedError(), hWnd );

}

void CallReplaceText ( HWND )

Definition at line 1576 of file CMNDLG.C.

{
    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = szReplaceString;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = sizeof( szReplaceString );
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
            frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(REPLACEDLGORD);
            break;
    }

    if ( (hDlgFR = ReplaceText( &frText )) == NULL )
            ProcessCDError(CommDlgExtendedError(), hWnd );

}

BOOL CALLBACK ChooseColorHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 964 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to change the color?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK ChooseFontHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 1084 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (chf.Flags & CF_ENABLETEMPLATE)
            {
                ShowWindow(GetDlgItem(hDlg, stc4), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, cmb4), SW_HIDE);
            }
            break;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to change the font?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL ChooseNewColor ( HWND )

Definition at line 1009 of file CMNDLG.C.

{

    DWORD dwColor;
    DWORD dwCustClrs[16];
    BOOL fSetColor = FALSE;
    int i;

    for (i=0; i < 15; i++)
        dwCustClrs[i] = RGB( 255, 255, 255);

    dwColor = RGB( 0, 0, 0 );

    chsclr.lStructSize = sizeof(CHOOSECOLOR);
    chsclr.hwndOwner = hWnd;
    chsclr.hInstance = (HANDLE)hInst;
    chsclr.rgbResult = dwColor;
    chsclr.lpCustColors = (LPDWORD)dwCustClrs;
    chsclr.lCustData = 0L;

    switch( wMode )
    {
        case IDM_HOOK:
        case IDM_CUSTOM:
            chsclr.Flags = CC_PREVENTFULLOPEN | CC_ENABLEHOOK;
            chsclr.lpfnHook = (LPCCHOOKPROC)MakeProcInstance(ChooseColorHookProc, NULL);
            chsclr.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_STANDARD:
            chsclr.Flags = CC_PREVENTFULLOPEN;
            chsclr.lpfnHook = (LPCCHOOKPROC)(FARPROC)NULL;
            chsclr.lpTemplateName = (LPSTR)NULL;
            break;

   }

   if ( fSetColor = ChooseColor( &chsclr ))
   {
       crColor = chsclr.rgbResult;
       return (TRUE);
   }
   else
   {
       ProcessCDError(CommDlgExtendedError(), hWnd );
       return FALSE;
   }
}

BOOL ChooseNewFont ( HWND )

Definition at line 1137 of file CMNDLG.C.

{

   HDC hDC;

   hDC = GetDC( hWnd );
   chf.hDC = CreateCompatibleDC( hDC );
   ReleaseDC( hWnd, hDC );
   chf.lStructSize = sizeof(CHOOSEFONT);
   chf.hwndOwner = hWnd;
   chf.lpLogFont = &lf;
   chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
   chf.rgbColors = RGB(0, 255, 255);
   chf.lCustData = 0;
   chf.hInstance = (HANDLE)hInst;
   chf.lpszStyle = (LPSTR)NULL;
   chf.nFontType = SCREEN_FONTTYPE;
   chf.nSizeMin = 0;
   chf.nSizeMax = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
            chf.lpfnHook = (LPCFHOOKPROC)(FARPROC)NULL;
            chf.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK;
            chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
            chf.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK |
              CF_ENABLETEMPLATE;
            chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
            chf.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FORMATDLGORD31);
            break;
   }

   if( ChooseFont( &chf ) == FALSE )
   {
        DeleteDC( hDC );
        ProcessCDError(CommDlgExtendedError(), hWnd );
        return FALSE;
   }

   DeleteDC( hDC );

   return (TRUE);
}

BOOL CALLBACK EnterNew | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 479 of file CMNDLG.C.

{
    CHAR Buf[FILE_LEN-1];

    switch (message)
    {
        case WM_INITDIALOG:                /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, IDEDIT, Buf, FILE_LEN-1);
                strcpy( FileBuf, Buf);
                lpBufPtr = FileBuf;
                dwFileSize = strlen(FileBuf);
                EndDialog( hDlg, TRUE );
                return (TRUE);
            }
            else if (LOWORD(wParam) == IDCANCEL)
            {   /* System menu close command? */
                EndDialog(hDlg, FALSE);       /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */

    // avoid compiler warnings at W3
    lParam;
}

BOOL CALLBACK FileOpenHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 578 of file CMNDLG.C.

{

    int hFile;
    CHAR szTempText[256];
    CHAR szString[256];
    OFSTRUCT OfStruct;

    switch (message)
    {

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, edt1, szTempText,
                        sizeof( szTempText ) - 1);

                if ( OpenFileName.Flags & OFN_PATHMUSTEXIST )
                {
                    sprintf( szString, "Are you sure you want to open %s?",
                        szTempText);
                    if ( MessageBox( hDlg, szString, "Information",
                        MB_YESNO ) == IDYES )

                        break;
                    return (TRUE);
                }

                // check to see if the Create File box has been checked
                if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
                    BM_GETCHECK, 0, 0L )) == TRUE )
                {
                    // if so, create the file
                    if ((hFile = OpenFile(szTempText,
                        &OfStruct,
                        OF_CREATE)) == -1)
                    {
                        MessageBox( hDlg,
                            "Directory could not be created.",
                            NULL,
                            MB_OK );
                        return (FALSE);
                    }

                    strcpy(FileBuf, "Empty");
                    lpBufPtr = FileBuf;
                    dwFileSize = strlen(FileBuf);
                    if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
                        MessageBox( hDlg, "Error writing file.", NULL, MB_OK );

                    // close the file
                    _lclose( hFile );
                }

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK FileSaveHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 824 of file CMNDLG.C.

{
    CHAR szTempText[256];
    CHAR szString[256];

    switch (message)
    {
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                GetDlgItemText( hDlg, edt1, szTempText,
                    sizeof( szTempText ) - 1);
                if ( OpenFileName.Flags & OFN_ENABLETEMPLATE )
                {
                    // check to see if the Create File box has been checked
                    if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
                        BM_GETCHECK, 0, 0L )) == FALSE )
                        OpenFileName.Flags |= OFN_FILEMUSTEXIST;
                    break;

                }
                else
                {
                    sprintf( szString, "Are you sure you want to save %s?",
                        szTempText);
                    if ( MessageBox( hDlg, szString, "Information",
                        MB_YESNO ) == IDYES )
                        break;
                    return(TRUE);
                }

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

BOOL CALLBACK FindTextHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 1465 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (frText.Flags & FR_ENABLETEMPLATE )
            {
                ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad2), SW_HIDE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        default:
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | int |
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

BOOL OpenNewFile ( HWND )

Definition at line 664 of file CMNDLG.C.

{
   int hFile;
   int cBufLen;
   OFSTRUCT OfStruct;
   WORD wStyle;

   strcpy( szFile, "");
   strcpy( szFileTitle, "");

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.hwndOwner         = hWnd;
   OpenFileName.hInstance         = (HANDLE) hInst;
   OpenFileName.lpstrFilter       = szFilter;
   OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
   OpenFileName.nMaxCustFilter    = 0L;
   OpenFileName.nFilterIndex      = 1L;
   OpenFileName.lpstrFile         = szFile;
   OpenFileName.nMaxFile          = sizeof(szFile);
   OpenFileName.lpstrFileTitle    = szFileTitle;
   OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = "Open a File";
   OpenFileName.nFileOffset       = 0;
   OpenFileName.nFileExtension    = 0;
   OpenFileName.lpstrDefExt       = "*.txt";
   OpenFileName.lCustData         = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
                OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            break;

        case IDM_HOOK:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
                OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
            break;

        case IDM_CUSTOM:
            OpenFileName.Flags = OFN_SHOWHELP | OFN_ENABLEHOOK |
                OFN_HIDEREADONLY | OFN_ENABLETEMPLATE;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
            break;
   }

   if (GetOpenFileName(&OpenFileName))
   {
      if (OpenFileName.Flags & OFN_READONLY )
        wStyle = OF_READ;
      else
        wStyle = OF_READWRITE;

      // open the file
      hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct, wStyle );
      if (hFile == -1)
      {
         MessageBox( hWnd, "File open failed.", NULL, MB_OK );
         return FALSE;
      }
      // read it's contents into a buffer
      cBufLen = _lread( hFile, FileBuf, FILE_LEN );
      lpBufPtr = FileBuf;

      if (cBufLen == -1)
      {
         MessageBox( hWnd, "Zero bytes read.", NULL, MB_OK );
         return FALSE;
      }
      // close the file
      _lclose( hFile );

      dwFileSize = cBufLen;
    }
    else
    {
      ProcessCDError(CommDlgExtendedError(), hWnd );
      return FALSE;
    }
    return TRUE;
}

BOOL CALLBACK PrintDlgHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 1264 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLEPRINTTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to print?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}

void PrintFile ( HWND )

Definition at line 1327 of file CMNDLG.C.

{

    // initialize PRINTDLG structure
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.hDevMode = (HANDLE)NULL;
    pd.hDevNames = (HANDLE)NULL;
    pd.nFromPage = 0;
    pd.nToPage = 0;
    pd.nMinPage = 0;
    pd.nMaxPage = 0;
    pd.nCopies = 0;
    pd.hInstance = (HANDLE)hInst;

    switch( wMode )
    {
        case IDM_STANDARD:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL;
            pd.lpSetupTemplateName = (LPSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL;
            pd.lpPrintTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
            pd.lpSetupTemplateName = (LPSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
            pd.lpPrintTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
                PD_ENABLESETUPHOOK | PD_ENABLESETUPTEMPLATE | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
            pd.lpSetupTemplateName = (LPSTR)MAKEINTRESOURCE(PRNSETUPDLGORD);
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
            pd.lpPrintTemplateName = (LPSTR)MAKEINTRESOURCE(PRINTDLGORD);
            break;

    }

    //print a test page if successful
    if (PrintDlg(&pd) == TRUE)
    {
        Escape(pd.hDC, STARTDOC, 8, "Test-Doc", NULL);

        //Print text
        TextOut(pd.hDC, 5, 5, FileBuf, strlen(FileBuf));

        Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
        Escape(pd.hDC, ENDDOC, 0, NULL, NULL );
        DeleteDC(pd.hDC);
        if (pd.hDevMode)
            GlobalFree(pd.hDevMode);
        if (pd.hDevNames)
            GlobalFree(pd.hDevNames);
    }
   else
        ProcessCDError(CommDlgExtendedError(), hWnd );
}

BOOL CALLBACK PrintSetupHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 1213 of file CMNDLG.C.

{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLESETUPTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

void ProcessCDError | ( | DWORD | ,
 |  | HWND |
 | ) |  |

Definition at line 1735 of file CMNDLG.C.

{
   WORD  wStringID;
   CHAR  buf[256];

   switch(dwErrorCode)
      {
         case CDERR_DIALOGFAILURE:   wStringID=IDS_DIALOGFAILURE;   break;
         case CDERR_STRUCTSIZE:      wStringID=IDS_STRUCTSIZE;      break;
         case CDERR_INITIALIZATION:  wStringID=IDS_INITIALIZATION;  break;
         case CDERR_NOTEMPLATE:      wStringID=IDS_NOTEMPLATE;      break;
         case CDERR_NOHINSTANCE:     wStringID=IDS_NOHINSTANCE;     break;
         case CDERR_LOADSTRFAILURE:  wStringID=IDS_LOADSTRFAILURE;  break;
         case CDERR_FINDRESFAILURE:  wStringID=IDS_FINDRESFAILURE;  break;
         case CDERR_LOADRESFAILURE:  wStringID=IDS_LOADRESFAILURE;  break;
         case CDERR_LOCKRESFAILURE:  wStringID=IDS_LOCKRESFAILURE;  break;
         case CDERR_MEMALLOCFAILURE: wStringID=IDS_MEMALLOCFAILURE; break;
         case CDERR_MEMLOCKFAILURE:  wStringID=IDS_MEMLOCKFAILURE;  break;
         case CDERR_NOHOOK:          wStringID=IDS_NOHOOK;          break;
         case PDERR_SETUPFAILURE:    wStringID=IDS_SETUPFAILURE;    break;
         case PDERR_PARSEFAILURE:    wStringID=IDS_PARSEFAILURE;    break;
         case PDERR_RETDEFFAILURE:   wStringID=IDS_RETDEFFAILURE;   break;
         case PDERR_LOADDRVFAILURE:  wStringID=IDS_LOADDRVFAILURE;  break;
         case PDERR_GETDEVMODEFAIL:  wStringID=IDS_GETDEVMODEFAIL;  break;
         case PDERR_INITFAILURE:     wStringID=IDS_INITFAILURE;     break;
         case PDERR_NODEVICES:       wStringID=IDS_NODEVICES;       break;
         case PDERR_NODEFAULTPRN:    wStringID=IDS_NODEFAULTPRN;    break;
         case PDERR_DNDMMISMATCH:    wStringID=IDS_DNDMMISMATCH;    break;
         case PDERR_CREATEICFAILURE: wStringID=IDS_CREATEICFAILURE; break;
         case PDERR_PRINTERNOTFOUND: wStringID=IDS_PRINTERNOTFOUND; break;
         case CFERR_NOFONTS:         wStringID=IDS_NOFONTS;         break;
         case FNERR_SUBCLASSFAILURE: wStringID=IDS_SUBCLASSFAILURE; break;
         case FNERR_INVALIDFILENAME: wStringID=IDS_INVALIDFILENAME; break;
         case FNERR_BUFFERTOOSMALL:  wStringID=IDS_BUFFERTOOSMALL;  break;

         case 0:   //User may have hit CANCEL or we got a *very* random error
            return;

         default:
            wStringID=IDS_UNKNOWNERROR;
      }

   LoadString(NULL, wStringID, buf, sizeof(buf));
   MessageBox(hWnd, buf, NULL, MB_OK);
   return;
}

BOOL CALLBACK ReplaceTextHookProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 1415 of file CMNDLG.C.

{
    switch (message)
    {
        case WM_INITDIALOG:
            if (frText.Flags & FR_ENABLETEMPLATE )
                {
                    ShowWindow( GetDlgItem(hDlg, psh2), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        default:
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}

BOOL SaveAs ( HWND )

Definition at line 887 of file CMNDLG.C.

{

   strcpy( szFile, "");
   strcpy( szFileTitle, "");

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.hwndOwner         = hWnd;
   OpenFileName.hInstance         = (HANDLE) hInst;
   OpenFileName.lpstrFilter       = szFilter;
   OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
   OpenFileName.nMaxCustFilter    = 0L;
   OpenFileName.nFilterIndex      = 1L;
   OpenFileName.lpstrFile         = szFile;
   OpenFileName.nMaxFile          = sizeof(szFile);
   OpenFileName.lpstrFileTitle    = szFileTitle;
   OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = "Save File As";
   OpenFileName.nFileOffset       = 0;
   OpenFileName.nFileExtension    = 0;
   OpenFileName.lpstrDefExt       = "txt";
   OpenFileName.lCustData         = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            OpenFileName.Flags = 0L;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)(FARPROC)NULL;
            OpenFileName.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_HOOK:
            OpenFileName.Flags = OFN_ENABLEHOOK;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)NULL;
            break;

        case IDM_CUSTOM:
            OpenFileName.Flags = OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
            OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
            OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
            break;
   }

   if ( GetSaveFileName( &OpenFileName ))
        return(SaveToFile( hWnd ));
   else
   {
        ProcessCDError(CommDlgExtendedError(), hWnd );
        return FALSE;
   }

   return (FALSE);
}

BOOL SaveToFile ( HWND )

Definition at line 765 of file CMNDLG.C.

{
   int hFile;
   OFSTRUCT OfStruct;
   WORD wStyle;
   CHAR buf[256];

   if (OpenFileName.Flags | OFN_FILEMUSTEXIST)
        wStyle = OF_READWRITE;
   else
        wStyle = OF_READWRITE | OF_CREATE;

   if ((hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct,
         wStyle)) == -1)
   {
      sprintf( buf, "Could not create file %s", OpenFileName.lpstrFile );
      MessageBox( hWnd, buf, NULL, MB_OK );
      return FALSE;
   }
   // write it's contents into a file
   if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
   {
      MessageBox( hWnd, "Error writing file.", NULL, MB_OK );
      return FALSE;
   }

   // close the file
   _lclose( hFile );

   sprintf( buf, "%s", OpenFileName.lpstrFile );
   MessageBox( hWnd, buf, "File Saved", MB_OK );
   return TRUE;
}

void SearchFile ( LPFINDREPLACE )

Definition at line 1634 of file CMNDLG.C.

{

    CHAR Buf[FILE_LEN];
    CHAR *pStr;
    int count, newcount;
    static BOOL bFoundLast = FALSE;

if ( lpFR->Flags & ( FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL ) )
    {
    memset(Buf, '\0', FILE_LEN -1);
    if ( bFoundLast )
        {
        if ( (lpBufPtr != FileBuf) && (lpFR->Flags & FR_FINDNEXT) )
            lpBufPtr++;
        bFoundLast = FALSE;
        }

    if (!*lpBufPtr || !(pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) )
        {
        sprintf( Buf, "'%s' not found!", lpFR->lpstrFindWhat );
        lpBufPtr = FileBuf;
        MessageBox( lpFR->hwndOwner, Buf, "No luck", MB_OK | MB_TASKMODAL);
        }
    else
        {
        if ( lpFR->Flags & FR_FINDNEXT )
            {
            sprintf( Buf, "Found Next '%s'!\nSubstring: '%.10s'",
                     lpFR->lpstrFindWhat, pStr );
            lpBufPtr = pStr;
            bFoundLast = TRUE;
            MessageBox( lpFR->hwndOwner, Buf, "Success!", MB_OK | MB_TASKMODAL );
            }
        else if ( lpFR->Flags & FR_REPLACE )
            {
            // replace string specified in the replace with found string
            // copy up to found string into new buffer
            for( count=0;
                 *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
                 count++);
                strncpy( Buf, lpBufPtr, count );
            // concatenate new string
            strcat( Buf, lpFR->lpstrReplaceWith );
            // copy rest of string (less the found string)
            newcount = count + strlen(lpFR->lpstrFindWhat);
            strcat( Buf, lpBufPtr+newcount);
            strcpy( lpBufPtr, Buf );
            lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
            dwFileSize = strlen(FileBuf);
            MessageBox( lpFR->hwndOwner, FileBuf, "Success!", MB_OK | MB_TASKMODAL );
            }
        else if ( lpFR->Flags & FR_REPLACEALL)
            {
            do
                {
                // replace string specified in the replace with found string
                // copy up to found string into new buffer
                memset(Buf, '\0', FILE_LEN -1);
                for( count=0;
                     *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
                     count++);
                     strncpy( Buf, lpBufPtr, count );
                // concatenate new string
                strcat( Buf, lpFR->lpstrReplaceWith );
                // copy rest of string (less the found string)
                newcount = count + strlen(lpFR->lpstrFindWhat);
                strcat( Buf, lpBufPtr + newcount);
                strcpy( lpBufPtr, Buf );
                lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
                }
            while ( *lpBufPtr &&
                    (pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) );
            dwFileSize = strlen(FileBuf);
            lpBufPtr = FileBuf;
            MessageBox( lpFR->hwndOwner, FileBuf,
                        "Success!", MB_OK | MB_TASKMODAL );
            }

        }
    }
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CONSOLEC/COLOR.C File Reference

  • CONSOLEC
Functions

COLOR.C File Reference

#include <Windows.H>
#include <StdIO.H>
#include <StdLib.H>
#include <ConIO.H>
#include <String.H>
#include "Color.H"

Go to the source code of this file.

Functions

WORD | GetConsoleTextAttribute (HANDLE hConsole)
int | main (int __argc, char **__argv)
void | PrintBanner ()
BOOL | Syntax (HANDLE hConsole)

Function Documentation

WORD GetConsoleTextAttribute ( HANDLE hConsole )

Definition at line 251 of file COLOR.C.

{
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  GetConsoleScreenBufferInfo( hConsole, &csbi );
  return( csbi.wAttributes );
}

int main | ( | int | __argc,
 |  | char ** | __argv
 | ) |  |

Definition at line 66 of file COLOR.C.

{
  WORD          ForeColor;
  WORD          BackColor;
  int           ColorIndex;
  size_t        StrLen;
  HANDLE        hConsole;
  char          ForeGround[8];
  char          BackGround[8];
  BOOL          WIN95 = FALSE;
  OSVERSIONINFO os;

  PrintBanner();

  // check if Win32s, if so, display notice and terminate
  os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

  if( GetVersionEx(&os) )
  {
    if ( os.dwPlatformId != VER_PLATFORM_WIN32_NT)
    {
        if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
        {
            WIN95 = TRUE;
            printf("\n\nChanges to the text attibutes are not persistant in Windows 95.");
        }
        else
        {
            MessageBoxA( NULL,
              "This application cannot run on Windows 3.1.\n"
              "This application will now terminate.",
              "Color",
              MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
              return( 1 );
        }
    }
  }
  else
      return( 1 );

  /**********************************************************************\
   * Open the current console input buffer
  \**********************************************************************/
  if( ( hConsole = CreateFile(
                     "CONOUT$", GENERIC_WRITE | GENERIC_READ,
                     FILE_SHARE_READ | FILE_SHARE_WRITE,
                     0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L) )
       == INVALID_HANDLE_VALUE ) {
    printf("\nError: Unable to open console.\n");
    return( -1 );
  }

  ForeColor = MAXCOLORS;
  BackColor = MAXCOLORS;

  if( __argc < 2 || WIN95 ) {
    Syntax( hConsole );
  }
  else {

      /**********************************************************************\
       * Get the first argument; the foreground text color
      \**********************************************************************/
      if( __argc > 1 ) {
        sprintf( ForeGround, "%s", __argv[1] );
        StrLen = strlen( ForeGround );
        for( ColorIndex = 0; ColorIndex < MAXCOLORS; ColorIndex++ ) {
          if( strnicmp( ForeGround, Color[ColorIndex], StrLen ) == 0 ) {
            ForeColor = (WORD) ColorIndex;
            break;
          }
        }
      }
      /**********************************************************************\
       * Get the second (optional) argument; the background text color
      \**********************************************************************/
      if( __argc > 2 ) {
        sprintf( BackGround, "%s", __argv[2] );
        StrLen = strlen( BackGround );
        for( ColorIndex = 0; ColorIndex < MAXCOLORS; ColorIndex++ ) {
          if( strnicmp( BackGround, Color[ColorIndex], StrLen ) == 0 ) {
            BackColor = (WORD) ColorIndex;
            break;
          }
        }
      }
      else
        BackColor = (WORD) (( GetConsoleTextAttribute(hConsole) & BACKGROUND_COLOR ) >> 4);

      /**********************************************************************\
       * Check if foreground and backgroud colors are the same; issue a error
       * and exit if they are
      \**********************************************************************/
      if( BackColor == MAXCOLORS || ForeColor == MAXCOLORS || BackColor == ForeColor) {
        printf("\n\nError: %s", BackColor == ForeColor ?
            "Foreground and background color cannot be the same." :
            "Invalid color specified.");

        Syntax( hConsole );
      }
      else
        /**********************************************************************\
         * Set the new console text colors
        \**********************************************************************/
        SetConsoleTextAttribute( hConsole, (WORD) (ForeColor | (BackColor << 4) ) );

  }

  CloseHandle(hConsole);
  return( 0 );
}

void PrintBanner ( )

Definition at line 272 of file COLOR.C.

{
  printf("Console Window Text Color Setter, Version 1.10");
  printf("\nMicrosoft Developer Support");
  printf("\nCopyright (c) 1992-1996 Microsoft Corp.");
}

BOOL Syntax ( HANDLE hConsole )

Definition at line 199 of file COLOR.C.

{
  WORD ForeColor;
  WORD BackColor;
  WORD wAttributesOld;

  printf("\n\nSyntax: COLOR FOREGROUND [BACKGROUND]");
  printf("\n\nAvailable colors are:");
  printf("\n");

  wAttributesOld = GetConsoleTextAttribute( hConsole );

  printf("%36s BACKGROUND\n", " ");
  printf("FOREGROUND  ");
  for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
    printf("%-8s", Color[BackColor] );
  }
  printf("\n");

  for( ForeColor = 0; ForeColor < MAXCOLORS; ForeColor++ ) {
    printf( "%-10s ",  Color[ForeColor] );

    for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
      SetConsoleTextAttribute( hConsole, (WORD) ( (BackColor << 4) | ForeColor) );
      printf(" XxXxXx ");
    }
    SetConsoleTextAttribute( hConsole, wAttributesOld );
    printf("\n");
  }

  SetConsoleTextAttribute( hConsole, wAttributesOld );

  return( TRUE );
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CONSOLEC/COLOR.H File Reference

  • CONSOLEC
Defines | Functions | Variables

COLOR.H File Reference

Go to the source code of this file.

Defines

#define | BACKGROUND_COLOR 0x00F0
#define | MAXCOLORS 8

Functions

WORD | GetConsoleTextAttribute (HANDLE hConsole)
void | PrintBanner ()
BOOL | Syntax (HANDLE hConsole)

Variables

char * | Color [MAXCOLORS]

Define Documentation

#define BACKGROUND_COLOR 0x00F0

Definition at line 18 of file COLOR.H.

#define MAXCOLORS 8

Definition at line 17 of file COLOR.H.

Function Documentation

WORD GetConsoleTextAttribute ( HANDLE hConsole )

Definition at line 251 of file COLOR.C.

{
  CONSOLE_SCREEN_BUFFER_INFO csbi;

  GetConsoleScreenBufferInfo( hConsole, &csbi );
  return( csbi.wAttributes );
}

void PrintBanner ( )

Definition at line 272 of file COLOR.C.

{
  printf("Console Window Text Color Setter, Version 1.10");
  printf("\nMicrosoft Developer Support");
  printf("\nCopyright (c) 1992-1996 Microsoft Corp.");
}

BOOL Syntax ( HANDLE hConsole )

Definition at line 199 of file COLOR.C.

{
  WORD ForeColor;
  WORD BackColor;
  WORD wAttributesOld;

  printf("\n\nSyntax: COLOR FOREGROUND [BACKGROUND]");
  printf("\n\nAvailable colors are:");
  printf("\n");

  wAttributesOld = GetConsoleTextAttribute( hConsole );

  printf("%36s BACKGROUND\n", " ");
  printf("FOREGROUND  ");
  for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
    printf("%-8s", Color[BackColor] );
  }
  printf("\n");

  for( ForeColor = 0; ForeColor < MAXCOLORS; ForeColor++ ) {
    printf( "%-10s ",  Color[ForeColor] );

    for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
      SetConsoleTextAttribute( hConsole, (WORD) ( (BackColor << 4) | ForeColor) );
      printf(" XxXxXx ");
    }
    SetConsoleTextAttribute( hConsole, wAttributesOld );
    printf("\n");
  }

  SetConsoleTextAttribute( hConsole, wAttributesOld );

  return( TRUE );
}

Variable Documentation

char* Color[MAXCOLORS]
Initial value:
 {
  "BLACK",
  "BLUE",
  "GREEN",
  "CYAN",
  "RED",
  "MAGENTA",
  "YELLOW",
  "GREY",
}

Definition at line 24 of file COLOR.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CPL/STEREO.C File Reference

  • CPL
Data Structures | Defines | Typedefs | Functions | Variables

STEREO.C File Reference

#include <windows.h>
#include <cpl.h>
#include "stereo.h"

Go to the source code of this file.

Data Structures

struct | tagApplets

Defines

#define | NUM_APPLETS (sizeof(StereoApplets)/sizeof(StereoApplets[0]))

Typedefs

typedef struct tagApplets | APPLETS

Functions

BOOL APIENTRY | AmpDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
LONG CALLBACK | CPlApplet (HWND hwndCPL, UINT uMsg, LONG lParam1, LONG lParam2)
BOOL WINAPI | DllMain (IN PVOID hmod, IN ULONG ulReason, IN PCONTEXT pctx OPTIONAL)
BOOL | InitStereoApplet (HWND hwndParent)
BOOL APIENTRY | TapeDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
void | TermStereoApplet ()
BOOL APIENTRY | TunerDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)

Variables

HANDLE | hModule = NULL
APPLETS StereoApplets []
char | szCtlPanel [30]

Define Documentation

#define NUM_APPLETS (sizeof(StereoApplets)/sizeof(StereoApplets[0]))

Definition at line 52 of file STEREO.C.

Typedef Documentation

typedef struct tagApplets APPLETS

Function Documentation

BOOL APIENTRY AmpDlgProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 223 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

LONG CALLBACK CPlApplet | ( | HWND | hwndCPL,
 |  | UINT | uMsg,
 |  | LONG | lParam1,
 |  | LONG | lParam2
 | ) |  |

Definition at line 139 of file STEREO.C.

{
    int iApplet;
    LPNEWCPLINFO lpNewCPlInfo;
    static iInitCount = 0;

    switch (uMsg) {
        case CPL_INIT:              // first message, sent once
            if (!iInitCount)
            {
                if (!InitStereoApplet(hwndCPL))
                    return FALSE;
            }
            iInitCount++;
            return TRUE;

        case CPL_GETCOUNT:          // second message, sent once
            return (LONG)NUM_APPLETS;
            break;

        case CPL_NEWINQUIRE:        // third message, sent once per app
            lpNewCPlInfo = (LPNEWCPLINFO) lParam2;

            iApplet = (int)(LONG)lParam1;
            lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
            lpNewCPlInfo->dwFlags = 0;
            lpNewCPlInfo->dwHelpContext = 0;
            lpNewCPlInfo->lData = 0;
            lpNewCPlInfo->hIcon = LoadIcon (hModule,
                (LPCTSTR) MAKEINTRESOURCE(StereoApplets[iApplet].icon));
            lpNewCPlInfo->szHelpFile[0] = '\0';

            LoadString (hModule, StereoApplets[iApplet].namestring,
                        lpNewCPlInfo->szName, 32);

            LoadString (hModule, StereoApplets[iApplet].descstring,
                        lpNewCPlInfo->szInfo, 64);
            break;

        case CPL_SELECT:            // application icon selected
            break;

        case CPL_DBLCLK:            // application icon double-clicked
            iApplet = (int)(LONG)lParam1;
            MessageBeep (MB_ICONEXCLAMATION);

            DialogBox (hModule,
                       MAKEINTRESOURCE(StereoApplets[iApplet].dlgtemplate),
                       hwndCPL,
                       StereoApplets[iApplet].dlgfn);
            break;

         case CPL_STOP:              // sent once per app. before CPL_EXIT
            break;

         case CPL_EXIT:              // sent once before FreeLibrary called
            iInitCount--;
            if (!iInitCount)
                TermStereoApplet();
            break;

         default:
            break;
    }
    return 0;
}

BOOL WINAPI DllMain | ( | IN PVOID | hmod,
 |  | IN ULONG | ulReason,
 |  | IN PCONTEXT pctx | OPTIONAL
 | ) |  |

Definition at line 70 of file STEREO.C.

{
    if (ulReason != DLL_PROCESS_ATTACH)
    {
        return TRUE;
    }
    else
    {
        hModule = hmod;
    }

    return TRUE;

    UNREFERENCED_PARAMETER(pctx);
}

BOOL InitStereoApplet ( HWND hwndParent )

Definition at line 101 of file STEREO.C.

{
    LoadString (hModule, CPCAPTION, szCtlPanel, sizeof(szCtlPanel));

    return TRUE;

    UNREFERENCED_PARAMETER(hwndParent);
}

BOOL APIENTRY TapeDlgProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 283 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

void TermStereoApplet ( )

Definition at line 122 of file STEREO.C.

{
    return;
}

BOOL APIENTRY TunerDlgProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 253 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

Variable Documentation

HANDLE hModule = NULL

Definition at line 55 of file STEREO.C.

APPLETS StereoApplets[]
Initial value:
{
    AMP_ICON, AMP_NAME, AMP_DESC, AMP_DLG, AmpDlgProc,
    TUNER_ICON, TUNER_NAME, TUNER_DESC, TUNER_DLG, TunerDlgProc,
    TAPE_ICON, TAPE_NAME, TAPE_DESC, TAPE_DLG, TapeDlgProc,

}

Definition at line 44 of file STEREO.C.

char szCtlPanel[30]

Definition at line 57 of file STEREO.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CPL/STEREO.H File Reference

  • CPL
Defines | Functions

STEREO.H File Reference

Go to the source code of this file.

Defines

#define | AMP_DESC 102
#define | AMP_DLG 103
#define | AMP_ICON 100
#define | AMP_NAME 101
#define | CPCAPTION 1
#define | TAPE_DESC 302
#define | TAPE_DLG 303
#define | TAPE_ICON 300
#define | TAPE_NAME 301
#define | TUNER_DESC 202
#define | TUNER_DLG 203
#define | TUNER_ICON 200
#define | TUNER_NAME 201

Functions

BOOL APIENTRY | AmpDlgProc (HWND, UINT, UINT, LONG)
LONG CALLBACK | CPlApplet (HWND, UINT, LONG, LONG)
BOOL APIENTRY | TapeDlgProc (HWND, UINT, UINT, LONG)
BOOL APIENTRY | TunerDlgProc (HWND, UINT, UINT, LONG)

Define Documentation

#define AMP_DESC 102

Definition at line 5 of file STEREO.H.

#define AMP_DLG 103

Definition at line 6 of file STEREO.H.

#define AMP_ICON 100

Definition at line 3 of file STEREO.H.

#define AMP_NAME 101

Definition at line 4 of file STEREO.H.

#define CPCAPTION 1

Definition at line 1 of file STEREO.H.

#define TAPE_DESC 302

Definition at line 15 of file STEREO.H.

#define TAPE_DLG 303

Definition at line 16 of file STEREO.H.

#define TAPE_ICON 300

Definition at line 13 of file STEREO.H.

#define TAPE_NAME 301

Definition at line 14 of file STEREO.H.

#define TUNER_DESC 202

Definition at line 10 of file STEREO.H.

#define TUNER_DLG 203

Definition at line 11 of file STEREO.H.

#define TUNER_ICON 200

Definition at line 8 of file STEREO.H.

#define TUNER_NAME 201

Definition at line 9 of file STEREO.H.

Function Documentation

BOOL APIENTRY AmpDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 223 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

LONG CALLBACK CPlApplet | ( | HWND | ,
 |  | UINT | ,
 |  | LONG | ,
 |  | LONG |
 | ) |  |

Definition at line 139 of file STEREO.C.

{
    int iApplet;
    LPNEWCPLINFO lpNewCPlInfo;
    static iInitCount = 0;

    switch (uMsg) {
        case CPL_INIT:              // first message, sent once
            if (!iInitCount)
            {
                if (!InitStereoApplet(hwndCPL))
                    return FALSE;
            }
            iInitCount++;
            return TRUE;

        case CPL_GETCOUNT:          // second message, sent once
            return (LONG)NUM_APPLETS;
            break;

        case CPL_NEWINQUIRE:        // third message, sent once per app
            lpNewCPlInfo = (LPNEWCPLINFO) lParam2;

            iApplet = (int)(LONG)lParam1;
            lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
            lpNewCPlInfo->dwFlags = 0;
            lpNewCPlInfo->dwHelpContext = 0;
            lpNewCPlInfo->lData = 0;
            lpNewCPlInfo->hIcon = LoadIcon (hModule,
                (LPCTSTR) MAKEINTRESOURCE(StereoApplets[iApplet].icon));
            lpNewCPlInfo->szHelpFile[0] = '\0';

            LoadString (hModule, StereoApplets[iApplet].namestring,
                        lpNewCPlInfo->szName, 32);

            LoadString (hModule, StereoApplets[iApplet].descstring,
                        lpNewCPlInfo->szInfo, 64);
            break;

        case CPL_SELECT:            // application icon selected
            break;

        case CPL_DBLCLK:            // application icon double-clicked
            iApplet = (int)(LONG)lParam1;
            MessageBeep (MB_ICONEXCLAMATION);

            DialogBox (hModule,
                       MAKEINTRESOURCE(StereoApplets[iApplet].dlgtemplate),
                       hwndCPL,
                       StereoApplets[iApplet].dlgfn);
            break;

         case CPL_STOP:              // sent once per app. before CPL_EXIT
            break;

         case CPL_EXIT:              // sent once before FreeLibrary called
            iInitCount--;
            if (!iInitCount)
                TermStereoApplet();
            break;

         default:
            break;
    }
    return 0;
}

BOOL APIENTRY TapeDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 283 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

BOOL APIENTRY TunerDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 253 of file STEREO.C.

{
    switch (message)
    {
      case WM_INITDIALOG:
          return (TRUE);

      case WM_COMMAND:
            if (LOWORD(wParam))
            {
            EndDialog(hDlg, TRUE);
            return (TRUE);
          }
          break;
    }
    return (FALSE);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CURSOR/CURSOR.C File Reference

  • CURSOR
Defines | Functions | Variables

CURSOR.C File Reference

#include <windows.h>
#include <string.h>
#include "cursor.h"

Go to the source code of this file.

Defines

#define | NITER 20
#define | SIZE 8190

Functions

BOOL APIENTRY | About (HWND hDlg, UINT message, UINT wParam, LONG lParam)
BOOL | InitApplication (HANDLE hInstance)
BOOL | InitInstance (HANDLE hInstance, INT nCmdShow)
LONG APIENTRY | MainWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)
INT | sieve ()
int APIENTRY | WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

BOOL | bTrack = FALSE
CHAR | flags [SIZE+1] = { 0}
HCURSOR | hHourGlass
HANDLE | hInst
HCURSOR | hSaveCursor
INT | OrgX = 0
INT | OrgY = 0
INT | PrevX = 0
INT | PrevY = 0
MPOINT ptCursor
RECT | Rect
INT | repeat = 1
CHAR | str [255]
INT | X = 0
INT | Y = 0

Define Documentation

#define NITER 20

Definition at line 472 of file CURSOR.C.

#define SIZE 8190

Definition at line 473 of file CURSOR.C.

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 435 of file CURSOR.C.

{
    switch (message) {
        case WM_INITDIALOG:
            return (TRUE);

        case WM_COMMAND:
            // LOWORD added for portability
            if (LOWORD(wParam) == IDOK
                || LOWORD(wParam) == IDCANCEL) {
                EndDialog(hDlg, TRUE);
                return (TRUE);
            }
            break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 100 of file CURSOR.C.

{
    WNDCLASS  wc;

    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC) MainWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(hInstance, "bullseye");
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "CursorMenu";
    wc.lpszClassName = "CursorWClass";

    return (RegisterClass(&wc));
}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | INT | nCmdShow
 | ) |  |

Definition at line 127 of file CURSOR.C.

{
    HWND            hWnd;

    hInst = hInstance;

    strcpy(str,"");

    hHourGlass = LoadCursor(NULL, IDC_WAIT);

    hWnd = CreateWindow(
        "CursorWClass",
        "Cursor Sample Application",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    return (TRUE);

}

LONG APIENTRY MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 197 of file CURSOR.C.

{
    FARPROC lpProcAbout;
    POINT pt;
    HDC hDC;

    switch (message) {
        case WM_COMMAND:
            // LOWORD added for portability
            if (LOWORD(wParam) == IDM_ABOUT) {
                lpProcAbout = MakeProcInstance((FARPROC)About, hInst);

                DialogBox(hInst,
                    "AboutBox",
                    hWnd,
                    lpProcAbout);

                FreeProcInstance(lpProcAbout);
                break;
            }
            else
                return (DefWindowProc(hWnd, message, wParam, lParam));

        case WM_CHAR:
            if (wParam == '\r') {
                SetCapture(hWnd);

                /* Set the cursor to an hourglass */

                hSaveCursor = SetCursor(hHourGlass);

                strcpy (str, "Calculating prime numbers...");
                InvalidateRect (hWnd, NULL, TRUE);
                UpdateWindow (hWnd);
                wsprintf(str, "Calculated %d primes.       ", sieve());
                InvalidateRect (hWnd, NULL, TRUE);
                UpdateWindow (hWnd);

                SetCursor(hSaveCursor);          /* Restores previous cursor */
                ReleaseCapture();
            }
            break;

        case WM_LBUTTONDOWN:
            bTrack = TRUE;
            strcpy (str, "");
            PrevX = LOWORD(lParam);
            PrevY = HIWORD(lParam);
            if (!(wParam & MK_SHIFT)) {       /* If shift key is not pressed */
                OrgX = LOWORD(lParam);
                OrgY = HIWORD(lParam);
            }
            InvalidateRect (hWnd, NULL, TRUE);
            UpdateWindow (hWnd);

            /* Capture all input even if the mouse goes outside of window */

            SetCapture(hWnd);
            break;

        case WM_MOUSEMOVE:
            {
                RECT        rectClient;
                INT         NextX;
                INT         NextY;

                if (bTrack) {
                    NextX = (SHORT)LOWORD(lParam);
                    NextY = (SHORT)HIWORD(lParam);

                    /* Do not draw outside the window's client area */

                    GetClientRect (hWnd, &rectClient);
                    if (NextX < rectClient.left) {
                        NextX = rectClient.left;
                    } else if (NextX >= rectClient.right) {
                        NextX = rectClient.right - 1;
                    }
                    if (NextY < rectClient.top) {
                        NextY = rectClient.top;
                    } else if (NextY >= rectClient.bottom) {
                        NextY = rectClient.bottom - 1;
                    }

                    /* If the mouse position has changed, then clear the */
                    /* previous rectangle and draw the new one.          */

                    if ((NextX != PrevX) || (NextY != PrevY)) {
                        hDC = GetDC(hWnd);
                        SetROP2(hDC, R2_NOT);          /* Erases the previous box */
                        MoveToEx(hDC, OrgX, OrgY, NULL);
                        LineTo(hDC, OrgX, PrevY);
                        LineTo(hDC, PrevX, PrevY);
                        LineTo(hDC, PrevX, OrgY);
                        LineTo(hDC, OrgX, OrgY);

                        /* Get the current mouse position */

                        PrevX = NextX;
                        PrevY = NextY;
                        MoveToEx(hDC, OrgX, OrgY, NULL); /* Draws the new box */
                        LineTo(hDC, OrgX, PrevY);
                        LineTo(hDC, PrevX, PrevY);
                        LineTo(hDC, PrevX, OrgY);
                        LineTo(hDC, OrgX, OrgY);
                        ReleaseDC(hWnd, hDC);
                    }
                }
            }
            break;

        case WM_LBUTTONUP:
            bTrack = FALSE;                 /* No longer creating a selection */
            ReleaseCapture();               /* Releases hold on mouse input */

            X = LOWORD(lParam);             /* Saves the current value      */
            Y = HIWORD(lParam);
            break;

        case WM_KEYDOWN:
            if (wParam != VK_LEFT && wParam != VK_RIGHT
                    && wParam != VK_UP && wParam != VK_DOWN)
                break;

            MPOINT2POINT(ptCursor, pt);
            GetCursorPos(&pt);

            /* Convert screen coordinates to client coordinates */

            ScreenToClient(hWnd, &pt);
            POINT2MPOINT(pt, ptCursor);
            repeat++;                           /* Increases the repeat rate */

            switch (wParam) {

            /* Adjust cursor position according to which key was pressed. */

                case VK_LEFT:
                    ptCursor.x -= repeat;
                    break;

                case VK_RIGHT:
                    ptCursor.x += repeat;
                    break;

                case VK_UP:
                    ptCursor.y -= repeat;
                    break;

                case VK_DOWN:
                    ptCursor.y += repeat;
                    break;

            }

            /* Get the client boundaries */

            GetClientRect(hWnd, &Rect);

            /* Do not draw outside the window's client area */

            MPOINT2POINT(ptCursor, pt);
            if (pt.x >= Rect.right)
                pt.x = Rect.right - 1;
            else if (pt.x < Rect.left)
                pt.x = Rect.left;
            if (pt.y >= Rect.bottom)
                pt.y = Rect.bottom - 1;
            else if (pt.y < Rect.top)
                pt.y = Rect.top;

            /* Convert the coordinates to screen coordinates */

            ClientToScreen(hWnd, &pt);
            SetCursorPos(pt.x, pt.y);
            break;

        case WM_KEYUP:
            repeat = 1;                          /* Clears the repeat count. */
            break;

        case WM_ACTIVATE:
            if (!GetSystemMetrics(SM_MOUSEPRESENT)) {
                if (!HIWORD(wParam)) {
                    // LOWORD added for portability
                    if (LOWORD(wParam)) {
                        SetCursor(LoadCursor(hInst, "bullseye"));
                        pt.x = X;
                        pt.y = Y;
                        ClientToScreen(hWnd, &pt);
                        SetCursorPos(pt.x, pt.y);
                    }
                    ShowCursor(wParam);
                }
            }
            break;

        case WM_PAINT:
            {
                PAINTSTRUCT     ps;

                hDC = BeginPaint (hWnd, &ps);
                if (OrgX != PrevX || OrgY != PrevY) {
                    MoveToEx(hDC, OrgX, OrgY, NULL);
                    LineTo(hDC, OrgX, PrevY);
                    LineTo(hDC, PrevX, PrevY);
                    LineTo(hDC, PrevX, OrgY);
                    LineTo(hDC, OrgX, OrgY);
                }
                TextOut (hDC, 1, 1, str, strlen (str));
                EndPaint (hWnd, &ps);
            }
            break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;

        default:
            return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

INT sieve ( )

Definition at line 477 of file CURSOR.C.

            {
    INT i,k;
    INT iter, count;

    for (iter = 1; iter <= NITER; iter++) {      /* Does sieve NITER times */
        count = 0;
        for (i = 0; i <= SIZE; i++)              /* Sets all flags TRUE    */
            flags[i] = TRUE;

        for (i = 2; i <= SIZE; i++) {
            if (flags[i] ) {                        /* Found a prime?       */
                for (k = i + i; k <= SIZE; k += i)
                    flags[k] = FALSE;              /* Cancelsits multiples */
                count++;
            }
        }
    }
    return (count);
}

int APIENTRY WinMain | ( | HANDLE | hInstance,
 |  | HANDLE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 57 of file CURSOR.C.

{
    MSG msg;                                 /* message                      */

    UNREFERENCED_PARAMETER( lpCmdLine );

    if (!hPrevInstance)
        if (!InitApplication(hInstance))
            return (FALSE);

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    MessageBox (
          GetFocus ()
        , "Use the mouse button in this program for an example of graphics "
                        "selection, or the <Enter> key for an example of "
                        "using a special cursor to reflect a program state."
        , "Cursor Sample Application"
        , MB_ICONASTERISK | MB_OK
    );

    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return (msg.wParam);
}

Variable Documentation

BOOL bTrack = FALSE

Definition at line 40 of file CURSOR.C.

CHAR flags[SIZE+1] = { 0}

Definition at line 475 of file CURSOR.C.

HCURSOR hHourGlass

Definition at line 38 of file CURSOR.C.

HANDLE hInst

Definition at line 33 of file CURSOR.C.

HCURSOR hSaveCursor

Definition at line 37 of file CURSOR.C.

INT OrgX = 0

Definition at line 41 of file CURSOR.C.

INT OrgY = 0

Definition at line 41 of file CURSOR.C.

INT PrevX = 0

Definition at line 42 of file CURSOR.C.

INT PrevY = 0

Definition at line 42 of file CURSOR.C.

MPOINT ptCursor

Definition at line 46 of file CURSOR.C.

RECT Rect

Definition at line 44 of file CURSOR.C.

INT repeat = 1

Definition at line 47 of file CURSOR.C.

CHAR str[255]

Definition at line 35 of file CURSOR.C.

INT X = 0

Definition at line 43 of file CURSOR.C.

INT Y = 0

Definition at line 43 of file CURSOR.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CURSOR/CURSOR.H File Reference

  • CURSOR
Defines | Typedefs | Functions

CURSOR.H File Reference

Go to the source code of this file.

Defines

#define | IDM_ABOUT 100
#define | MPOINT2POINT(mpt, pt) ((pt).x = (mpt).x, (pt).y = (mpt).y)
#define | POINT2MPOINT(pt, mpt) ((mpt).x = (SHORT)(pt).x, (mpt).y = (SHORT)(pt).y)

Typedefs

typedef POINTS | MPOINT

Functions

BOOL APIENTRY | About (HWND, UINT, UINT, LONG)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, INT)
LONG APIENTRY | MainWndProc (HWND, UINT, UINT, LONG)
INT | sieve (VOID)

Define Documentation

#define IDM_ABOUT 100

Definition at line 12 of file CURSOR.H.

#define MPOINT2POINT | ( | mpt,
 |  | pt |
 | ) |  | ((pt).x = (mpt).x, (pt).y = (mpt).y)

Definition at line 15 of file CURSOR.H.

#define POINT2MPOINT | ( | pt,
 |  | mpt |
 | ) |  | ((mpt).x = (SHORT)(pt).x, (mpt).y = (SHORT)(pt).y)

Definition at line 16 of file CURSOR.H.

Typedef Documentation

typedef POINTS MPOINT

Definition at line 14 of file CURSOR.H.

Function Documentation

BOOL APIENTRY About | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | INT |
 | ) |  |

Definition at line 130 of file CLIPTEXT.C.

{
    LPSTR           lpszText;

    hInst = hInstance;

    hAccTable = LoadAccelerators(hInst, "ClipTextAcc");

    if (!(hText
          = GlobalAlloc(GMEM_MOVEABLE,(DWORD)sizeof(szInitialClientAreaText)))) {
        OutOfMemory();
        return (FALSE);
    }

    if (!(lpszText = GlobalLock(hText))) {
        OutOfMemory();
        return (FALSE);
    }

    strcpy(lpszText, szInitialClientAreaText);
    GlobalUnlock(hText);

    hwnd = CreateWindow(
        "CliptextWClass",
        "Cliptext Sample Application",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
    );

    if (!hwnd)
        return (FALSE);

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    return (TRUE);

}

LONG APIENTRY MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

INT sieve ( VOID )
Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: DRIVES/DRIVES.C File Reference

  • DRIVES
Defines | Functions | Variables

DRIVES.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "drives.h"

Go to the source code of this file.

Defines

#define | BUFSIZE 2048

Functions

BOOL | CheckRM (LPTSTR lpszDriveName)
VOID | GVI (LPTSTR lpszDriveName, LPTSTR lpszSystemName, DWORD nSystemNameSize)
VOID | main (VOID)
LPTSTR | UpdateBuffer (LPTSTR lpszString)

Variables

CHAR | chBuffer [BUFSIZE]

Define Documentation

#define BUFSIZE 2048

Definition at line 36 of file DRIVES.C.

Function Documentation

BOOL CheckRM ( LPTSTR lpszDriveName )

Definition at line 66 of file DRIVES.C.

{
  int      iRC;
  LPTSTR   lpszFileName="         ";
  OFSTRUCT ofstruct;
  WORD     wStyle=OF_EXIST;

  SetErrorMode(1);
  strcpy(lpszFileName,lpszDriveName);
  strcat(lpszFileName,".");
  iRC=OpenFile(lpszFileName,&ofstruct,wStyle);
  SetErrorMode(0);
  if (iRC==-1)
    return (FALSE);
  _lclose(iRC);
  return (TRUE);
}

VOID GVI | ( | LPTSTR | lpszDriveName,
 |  | LPTSTR | lpszSystemName,
 |  | DWORD | nSystemNameSize
 | ) |  |

Definition at line 106 of file DRIVES.C.

{
  BOOL     bRC;

  lstrcpy( lpszSystemName, "Unknown Media Type" );
  bRC=GetVolumeInformation(lpszDriveName,
                           NULL,
                           0,
                           NULL,
                           NULL,
                           NULL,
                           lpszSystemName,
                           nSystemNameSize);
  printf("File system = %s",lpszSystemName);
}

VOID main ( VOID )

Definition at line 177 of file DRIVES.C.

{
  DWORD     dwDriveMask;
  DWORD     dwRC;
  DWORD     dwTemp;
  DWORD     cbDriveStringBufferSize=BUFSIZE;
  LPTSTR    lpszDriveStringBuffer=chBuffer;
  LPTSTR    lpszRootPathName="?:\\";
  LPTSTR    lpszFileSystemNameBuffer="                              ";
  DWORD     nFileSystemNameSize=sizeof("                              ");
  DWORD     dwVersion;
//yg Modified to check for windows 95

  // check if running on Windows NT or Windows 95, if not, display notice and terminate

  dwVersion = GetVersion();
  if ((dwVersion & 0x80000000) && (LOBYTE(LOWORD(dwVersion))< 4))
  {
     MessageBox( NULL,
       "This sample application can only be run on Windows NT or Windows 95.\n"
       "This application will now terminate.",
       "Drives",
       MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
       return;
  }

  dwDriveMask=GetLogicalDrives();
  dwRC=GetLogicalDriveStrings(cbDriveStringBufferSize,lpszDriveStringBuffer);
  printf("%08X %s\n", dwDriveMask, lpszDriveStringBuffer);
  for (*lpszRootPathName='a';*lpszRootPathName<='z';(*lpszRootPathName)++)
    {
    dwTemp=dwDriveMask & 1;
    dwDriveMask >>= 1;
    if (dwTemp)
      {
      dwRC=GetDriveType(lpszRootPathName);
      printf("The drive type for %s is ",lpszDriveStringBuffer);
      lpszDriveStringBuffer=UpdateBuffer(lpszDriveStringBuffer);
      switch (dwRC)
        {
        case DRIVE_REMOVEABLE :
            printf("removeable. ");
            if (CheckRM(lpszRootPathName))
              GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            else
              printf("File system = INDETERMINATE");
            break;
        case DRIVE_FIXED      :
            printf("fixed.      ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_REMOTE     :
            printf("remote.     ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_CDROM      :
            printf("CD-ROM.     ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_RAMDISK    :
            printf("RAM disk.   ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        default               :
            break;
        }
      printf("\n");
      }
    }
}

LPTSTR UpdateBuffer ( LPTSTR lpszString )

Definition at line 138 of file DRIVES.C.

{
  return (lpszString+strlen(lpszString)+1);
}

Variable Documentation

CHAR chBuffer[BUFSIZE]

Definition at line 38 of file DRIVES.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: DRIVES/DRIVES.H File Reference

  • DRIVES
Defines | Functions

DRIVES.H File Reference

Go to the source code of this file.

Defines

#define | DRIVE_CDROM 5
#define | DRIVE_FIXED 3
#define | DRIVE_RAMDISK 6
#define | DRIVE_REMOTE 4
#define | DRIVE_REMOVEABLE 2

Functions

BOOL | CheckRM (LPTSTR)
VOID | GVI (LPTSTR, LPTSTR, DWORD)
VOID | main (VOID)
LPTSTR | UpdateBuffer (LPTSTR)

Define Documentation

#define DRIVE_CDROM 5

Definition at line 17 of file DRIVES.H.

#define DRIVE_FIXED 3

Definition at line 15 of file DRIVES.H.

#define DRIVE_RAMDISK 6

Definition at line 18 of file DRIVES.H.

#define DRIVE_REMOTE 4

Definition at line 16 of file DRIVES.H.

#define DRIVE_REMOVEABLE 2

Definition at line 14 of file DRIVES.H.

Function Documentation

BOOL CheckRM ( LPTSTR )

Definition at line 66 of file DRIVES.C.

{
  int      iRC;
  LPTSTR   lpszFileName="         ";
  OFSTRUCT ofstruct;
  WORD     wStyle=OF_EXIST;

  SetErrorMode(1);
  strcpy(lpszFileName,lpszDriveName);
  strcat(lpszFileName,".");
  iRC=OpenFile(lpszFileName,&ofstruct,wStyle);
  SetErrorMode(0);
  if (iRC==-1)
    return (FALSE);
  _lclose(iRC);
  return (TRUE);
}

VOID GVI | ( | LPTSTR | ,
 |  | LPTSTR | ,
 |  | DWORD |
 | ) |  |

Definition at line 106 of file DRIVES.C.

{
  BOOL     bRC;

  lstrcpy( lpszSystemName, "Unknown Media Type" );
  bRC=GetVolumeInformation(lpszDriveName,
                           NULL,
                           0,
                           NULL,
                           NULL,
                           NULL,
                           lpszSystemName,
                           nSystemNameSize);
  printf("File system = %s",lpszSystemName);
}

VOID main ( VOID )

Definition at line 177 of file DRIVES.C.

{
  DWORD     dwDriveMask;
  DWORD     dwRC;
  DWORD     dwTemp;
  DWORD     cbDriveStringBufferSize=BUFSIZE;
  LPTSTR    lpszDriveStringBuffer=chBuffer;
  LPTSTR    lpszRootPathName="?:\\";
  LPTSTR    lpszFileSystemNameBuffer="                              ";
  DWORD     nFileSystemNameSize=sizeof("                              ");
  DWORD     dwVersion;
//yg Modified to check for windows 95

  // check if running on Windows NT or Windows 95, if not, display notice and terminate

  dwVersion = GetVersion();
  if ((dwVersion & 0x80000000) && (LOBYTE(LOWORD(dwVersion))< 4))
  {
     MessageBox( NULL,
       "This sample application can only be run on Windows NT or Windows 95.\n"
       "This application will now terminate.",
       "Drives",
       MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
       return;
  }

  dwDriveMask=GetLogicalDrives();
  dwRC=GetLogicalDriveStrings(cbDriveStringBufferSize,lpszDriveStringBuffer);
  printf("%08X %s\n", dwDriveMask, lpszDriveStringBuffer);
  for (*lpszRootPathName='a';*lpszRootPathName<='z';(*lpszRootPathName)++)
    {
    dwTemp=dwDriveMask & 1;
    dwDriveMask >>= 1;
    if (dwTemp)
      {
      dwRC=GetDriveType(lpszRootPathName);
      printf("The drive type for %s is ",lpszDriveStringBuffer);
      lpszDriveStringBuffer=UpdateBuffer(lpszDriveStringBuffer);
      switch (dwRC)
        {
        case DRIVE_REMOVEABLE :
            printf("removeable. ");
            if (CheckRM(lpszRootPathName))
              GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            else
              printf("File system = INDETERMINATE");
            break;
        case DRIVE_FIXED      :
            printf("fixed.      ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_REMOTE     :
            printf("remote.     ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_CDROM      :
            printf("CD-ROM.     ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        case DRIVE_RAMDISK    :
            printf("RAM disk.   ");
            GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
            break;
        default               :
            break;
        }
      printf("\n");
      }
    }
}

LPTSTR UpdateBuffer ( LPTSTR )

Definition at line 138 of file DRIVES.C.

{
  return (lpszString+strlen(lpszString)+1);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: EVENT/ASYN_IO.C File Reference

  • EVENT
Defines | Typedefs | Functions

ASYN_IO.C File Reference

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <string.h>

Go to the source code of this file.

Defines

#define | DEFAULT 0L
#define | IO_ERROR (HANDLE)0xFFFFFFFF
#define | NOMINMAX
#define | RETURN_IMEDIATELY 0L
#define | SECTOR_SIZE 1024
#define | STRICT
#define | SUCCESS 0L
#define | WAIT_ERROR 0xFFFFFFFF

Typedefs

typedef HANDLE | HEVENT
typedef HANDLE | HFILEEX

Functions

VOID | Do_BackgroundTask (VOID)
VOID | ErrorMsg (PSZ psz)
void | main (int argc, char *argv[])

Define Documentation

#define DEFAULT 0L

Definition at line 47 of file ASYN_IO.C.

#define IO_ERROR (HANDLE)0xFFFFFFFF

Definition at line 49 of file ASYN_IO.C.

#define NOMINMAX

Definition at line 39 of file ASYN_IO.C.

#define RETURN_IMEDIATELY 0L

Definition at line 52 of file ASYN_IO.C.

#define SECTOR_SIZE 1024

Definition at line 51 of file ASYN_IO.C.

#define STRICT

Definition at line 38 of file ASYN_IO.C.

#define SUCCESS 0L

Definition at line 48 of file ASYN_IO.C.

#define WAIT_ERROR 0xFFFFFFFF

Definition at line 50 of file ASYN_IO.C.

Typedef Documentation

typedef HANDLE HEVENT

Definition at line 55 of file ASYN_IO.C.

typedef HANDLE HFILEEX

Definition at line 59 of file ASYN_IO.C.

Function Documentation

VOID Do_BackgroundTask ( VOID )

Definition at line 373 of file ASYN_IO.C.

{
  Sleep ( 5000L ) ;
}

VOID ErrorMsg ( PSZ psz )

Definition at line 349 of file ASYN_IO.C.

{

  printf ("\n%s: return code = %d\n", psz, GetLastError()) ;
  exit ( EXIT_FAILURE ) ;
}

void main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 67 of file ASYN_IO.C.

{

   HFILEEX    hInfile,  // Handle to the file to read
            hOutfile; // Handle to the file to write to

   HEVENT   hEvent ;  // Handle to the synchronization Event

   OVERLAPPED
            OverLapped ; // The operating system does not automatically
                         // track the current file position of a file
                         // open for asynchroous I/O. Instead one must
                         // manually track this by updating the OVERLAPPED
                         // structure. To update this structure one uses
                         // the result returned by GetOverLappedResults().

   CHAR     buf[SECTOR_SIZE] ; // Buffer used by either
                               // ReadFile() or WriteFile()

   DWORD    cbBytesRead,         // count of bytes read by ReadFile()
                                 // When asynchonous I/O is performed
                                 // one must check how many bytes were
                                 // read by calling GetOverLappedResults().

            cbBytesWritten,      // count of bytes written by WriteFile()

            cbBytesTransfered ;  // this value is returned by
                                 // GetOverLappedResults() represents the
                                 // count of bytes transfered asynchronous

   DWORD    dwStatus,            // value returned by GetLastError()
            dwSuccess ;          // return code of last API called

   BOOL     bSuccess ;           // return code of last API called

   CHAR     buffer[80] ;

/***************************************************************************\
**                                                                         **
**  This block of code initalizes all the necessary variables needed to do **
**  asynchronous IO. Specfically it opens the files and initializes the    **
**  synchronization EVENT and OVERLAPPED structure needed to keep track    **
**  of asynchronous file I/O                                               **
**                                                                         **
\***************************************************************************/

// check if running on Windows NT, if not, display notice and terminate
    if( GetVersion() & 0x80000000 )
    {
       MessageBox( NULL,
         "This sample application can only be run on Windows NT.\n"
         "This application will now terminate.",
         "Event",
         MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
      return;
   }

   if ( argc != 3 )
   {
      printf ( "\nUsage: ASYN_IO input_file output_file\n" ) ;
      exit ( EXIT_FAILURE ) ;
   }

/*
 * Open file which we will be copying. Note we are opening this
 * asynchronously.
 */

   hInfile = CreateFile
                  (
                     argv[1]              // File to read
                    ,GENERIC_READ         // Open file for reading only
                    ,FILE_SHARE_READ      // Allow others to read file
                    ,NULL                 // No security
                    ,OPEN_EXISTING        // Fail if file doesn't exit
                    ,FILE_FLAG_OVERLAPPED // Async I/o
                    ,DEFAULT
                  ) ;

   if ( hInfile == IO_ERROR )
   {
      strcpy ( buffer, "Error opening" ) ;
      strcat ( buffer, argv[1] ) ;
      ErrorMsg ( buffer ) ;
   }

/*
 * Create the file to write to; here we have opened it for synchronous IO.
 */

   hOutfile = CreateFile
                  (
                     argv[2]                 // File to write to
                    ,GENERIC_WRITE           // Open file only to write to
                    ,DEFAULT                 // No sharing allowed
                    ,NULL                    // No security
                    ,CREATE_NEW              // Fail if file exists
                    ,FILE_ATTRIBUTE_NORMAL   // No attributes
                    ,DEFAULT
                  ) ;

   if ( hOutfile == IO_ERROR )
   {
      strcpy ( buffer, "Error opening" ) ;
      strcat ( buffer, argv[1] ) ;
      ErrorMsg ( buffer ) ;
   }

/*
 * Create Synchronoizing Event
 */

   hEvent = CreateEvent
                    (
                      NULL    // No security
                     ,TRUE    // Manual reset
                     ,FALSE   // Initially Event set to non-signaled state
                     ,NULL    // No name
                    ) ;
   if ( !hEvent )
      ErrorMsg ( "Error creating Event" ) ;

/*
 * Intialize OverLapped structure. We will be using an Event instead
 * of the file handle for synchronizing I/O. One reason to use a unique
 * event instead of the file handle would be a so multi-threaded app
 * would know which thread to unblock when the handle is set to the
 * signaled state.
 */

   memset ( &OverLapped, 0, sizeof ( OVERLAPPED ) ) ;
   OverLapped.hEvent = hEvent ;

   bSuccess = TRUE ;

/***************************************************************************\
**                                                                         **
** This is the main function of this program. Here we loop until the file  **
** has been copied. Notice that even though we are using asynchronous I/O  **
** ReadFile() may still return sychronously if it can be done fast enough  **
**                                                                         **
\***************************************************************************/

   while ( bSuccess )
   {

/*
 * Read file asynchronously
 */

      bSuccess = ReadFile
            (
               hInfile        // Handle of file to read
              ,buf            // Buffer to store input
              ,SECTOR_SIZE    // Number of bytes to read
              ,&cbBytesRead   // Number of bytes read. See note]
                              // above in delcaration
              ,&OverLapped    // Used for asynchronous I/O
            ) ;

/*
 * Check whether ReadFile() has completed yet
 */
      if ( !bSuccess && (( dwStatus = GetLastError ()) == ERROR_IO_PENDING ) )
      {
        printf ( "\nIO Pending" ) ;
/*
 * Read not complete yet first execute the background task then check
 * to the if event "hEvent" set to the signaled state. If the event is
 * not set signaled state then loop through again - run the background
 * task and check the event.
 *
 */

        Do_BackgroundTask () ;

        dwSuccess = WaitForSingleObject ( hEvent, RETURN_IMEDIATELY ) ;

        if ( dwSuccess == WAIT_ERROR )
            ErrorMsg("Error in WaitForSingleObject") ;
        else if ( dwSuccess == SUCCESS )
        {

            bSuccess = GetOverlappedResult(
                            hInfile, &OverLapped, &cbBytesTransfered, FALSE) ;
            if ( !bSuccess )
                ErrorMsg ( "Error in GetOverLappedResult" ) ;
            else
            {
                // Read has completed now find out how many bytes have been read

                printf ( "\nNumber of bytes transfered is %d\n", cbBytesTransfered ) ;
                OverLapped.Offset += cbBytesTransfered ;
                cbBytesRead = cbBytesTransfered ;
            }
        }
        else if ( dwSuccess == WAIT_TIMEOUT )
            Do_BackgroundTask () ;
      }
/*
 * ReadFile() read file synchronously; update Overlapped structure
 */
      else if ( bSuccess  && cbBytesRead != 0 )
      {
         printf ( "\nNumber of bytes transfered is %d\n", cbBytesRead ) ;
         OverLapped.Offset += cbBytesRead ;
      }
/*
 * ReadFile() has found the end of the file; exit loop
 */
      else if ( bSuccess  && cbBytesRead == 0 )
      {
         printf ( "End of file read\n" ) ;
         break ;
      }
/*
 * An error occured while reading, print out status and exit loop.
 */
      else
         ErrorMsg ( "Error reading to file" ) ;

/*
 * Write to file synchronously
 */
      bSuccess = WriteFile
            (
               hOutfile             // Handle of file to write to
              ,buf                  // Data to write to file
              ,cbBytesRead          // Number of bytes to write
              ,&cbBytesWritten      // Number of bytes written
              ,NULL                 // Only need for asynchonous output
            ) ;

      if ( !bSuccess )
         ErrorMsg ( "Error writing to file" ) ;

   } // End of WHILE loop

   CloseHandle ( hInfile ) ;        // Close handle to input file
   FlushFileBuffers ( hOutfile ) ;  // Make sure all data written to file first
   CloseHandle ( hOutfile ) ;       // Close handle to output file
   exit ( EXIT_SUCCESS ) ;

}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETDEV/GETDEV.C File Reference

  • GETDEV
Functions

GETDEV.C File Reference

#include <windows.h>
#include "getdev.h"

Go to the source code of this file.

Functions

VOID | ExpandInfo (HWND hwnd, int index, int value)
LONG APIENTRY | MainDlgProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

VOID ExpandInfo | ( | HWND | hwnd,
 |  | int | index,
 |  | int | value
 | ) |  |

Definition at line 132 of file GETDEV.C.

{
  int i;

  switch (index) {

    case TECHNOLOGY   :
      for (i = 0 ; i< NDevice ; i++) {
        if (value == Device[i].Value) {
          wsprintf (buffer,space, Device[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case CURVECAPS    :
      for (i = 0 ; i< NCurveCaps ; i++) {
        if (value & CurveCaps[i].Value) {
          wsprintf (buffer,space, CurveCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case LINECAPS     :
      for (i = 0 ; i< NLineCaps ; i++) {
        if (value & LineCaps[i].Value) {
          wsprintf (buffer,space, LineCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case POLYGONALCAPS:
      for (i = 0 ; i< NPolygonalCaps ; i++) {
        if (value & PolygonalCaps[i].Value) {
          wsprintf (buffer,space, PolygonalCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case TEXTCAPS     :
      for (i = 0 ; i< NTextCaps ; i++) {
        if (value & TextCaps[i].Value) {
          wsprintf (buffer,space, TextCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case CLIPCAPS     :
      for (i = 0 ; i< NClipCaps ; i++) {
        if (value & ClipCaps[i].Value) {
          wsprintf (buffer,space, ClipCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case RASTERCAPS   :
      for (i = 0 ; i< NRasterCaps ; i++) {
        if (value & RasterCaps[i].Value) {
          wsprintf (buffer,space, RasterCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    default:
    break;

  } /* end switch */
}

LONG APIENTRY MainDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 64 of file GETDEV.C.

{
  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    case WM_INITDIALOG: {
      int i;
      int value;
      HDC hdc;

      hdc = GetDC (hwnd);

      for (i = 0; i < NINDEX ; i++) {
        value = GetDeviceCaps (hdc , DevCaps[i].Value);
        wsprintf (buffer,"%s %8d", DevCaps[i].String, value);
        SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        ExpandInfo (hwnd, DevCaps[i].Value, value);
      }

      ReleaseDC (hwnd,hdc);
    } break;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    default: return FALSE;
  } /* end switch(message) */
  return 0;
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 39 of file GETDEV.C.

{
int ret;

    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nCmdShow);

    ret = DialogBox (hInstance, "getdevDlg", NULL, (DLGPROC)MainDlgProc);
    return ret;
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETDEV/GETDEV.H File Reference

  • GETDEV
Data Structures | Defines | Typedefs | Functions | Variables

GETDEV.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | DID_LISTBOX 0x006B
#define | NClipCaps 2
#define | NCurveCaps 9
#define | NDevice 7
#define | NINDEX 28
#define | NLineCaps 8
#define | NPolygonalCaps 10
#define | NRasterCaps 12
#define | NTextCaps 16

Typedefs

typedef struct tagLookupEntry | LookupEntry

Functions

VOID | ExpandInfo (HWND, int, int)
long FAR PASCAL | MainDlgProc (HWND, UINT, UINT, LONG)

Variables

char | buffer [100]
LookupEntry | ClipCaps [NClipCaps]
LookupEntry | CurveCaps [NCurveCaps]
LookupEntry | DevCaps [NINDEX]
LookupEntry | Device [NDevice]
LookupEntry | LineCaps [NLineCaps]
LookupEntry | PolygonalCaps [NPolygonalCaps]
LookupEntry | RasterCaps [NRasterCaps]
char | space [] = " %s"
LookupEntry | TextCaps [NTextCaps]

Define Documentation

#define DID_LISTBOX 0x006B

Definition at line 29 of file GETDEV.H.

#define NClipCaps 2

Definition at line 130 of file GETDEV.H.

#define NCurveCaps 9

Definition at line 88 of file GETDEV.H.

#define NDevice 7

Definition at line 76 of file GETDEV.H.

#define NINDEX 28

Definition at line 41 of file GETDEV.H.

#define NLineCaps 8

Definition at line 102 of file GETDEV.H.

#define NPolygonalCaps 10

Definition at line 115 of file GETDEV.H.

#define NRasterCaps 12

Definition at line 158 of file GETDEV.H.

#define NTextCaps 16

Definition at line 137 of file GETDEV.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Function Documentation

VOID ExpandInfo | ( | HWND | ,
 |  | int | ,
 |  | int |
 | ) |  |

Definition at line 132 of file GETDEV.C.

{
  int i;

  switch (index) {

    case TECHNOLOGY   :
      for (i = 0 ; i< NDevice ; i++) {
        if (value == Device[i].Value) {
          wsprintf (buffer,space, Device[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case CURVECAPS    :
      for (i = 0 ; i< NCurveCaps ; i++) {
        if (value & CurveCaps[i].Value) {
          wsprintf (buffer,space, CurveCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case LINECAPS     :
      for (i = 0 ; i< NLineCaps ; i++) {
        if (value & LineCaps[i].Value) {
          wsprintf (buffer,space, LineCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case POLYGONALCAPS:
      for (i = 0 ; i< NPolygonalCaps ; i++) {
        if (value & PolygonalCaps[i].Value) {
          wsprintf (buffer,space, PolygonalCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case TEXTCAPS     :
      for (i = 0 ; i< NTextCaps ; i++) {
        if (value & TextCaps[i].Value) {
          wsprintf (buffer,space, TextCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case CLIPCAPS     :
      for (i = 0 ; i< NClipCaps ; i++) {
        if (value & ClipCaps[i].Value) {
          wsprintf (buffer,space, ClipCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    case RASTERCAPS   :
      for (i = 0 ; i< NRasterCaps ; i++) {
        if (value & RasterCaps[i].Value) {
          wsprintf (buffer,space, RasterCaps[i].String);
          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
        }
      }
    break;

    default:
    break;

  } /* end switch */
}

long FAR PASCAL MainDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 64 of file GETDEV.C.

{
  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    case WM_INITDIALOG: {
      int i;
      int value;
      HDC hdc;

      hdc = GetDC (hwnd);

      for (i = 0; i < NINDEX ; i++) {
        value = GetDeviceCaps (hdc , DevCaps[i].Value);
        wsprintf (buffer,"%s %8d", DevCaps[i].String, value);
        SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
        ExpandInfo (hwnd, DevCaps[i].Value, value);
      }

      ReleaseDC (hwnd,hdc);
    } break;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    default: return FALSE;
  } /* end switch(message) */
  return 0;
}

Variable Documentation

char buffer[100]

Definition at line 23 of file GETDEV.H.

LookupEntry ClipCaps[NClipCaps]
Initial value:
    {{ 0   , "CP_NONE     "},
     { 1   , "CP_RECTANGLE"}}

Definition at line 131 of file GETDEV.H.

LookupEntry CurveCaps[NCurveCaps]
Initial value:
    {{ 0   , "CC_NONE      "},
     { 1   , "CC_CIRCLES   "},
     { 2   , "CC_PIE       "},
     { 4   , "CC_CHORD     "},
     { 8   , "CC_ELLIPSES  "},
     { 16  , "CC_WIDE      "},
     { 32  , "CC_STYLED    "},
     { 64  , "CC_WIDESTYLED"},
     { 128 , "CC_INTERIORS "}}

Definition at line 89 of file GETDEV.H.

LookupEntry DevCaps[NINDEX]
Initial value:
    {{  0 , "DRIVERVERSION "},
     {  2 , "TECHNOLOGY    "},
     {  4 , "HORZSIZE      "},
     {  6 , "VERTSIZE      "},
     {  8 , "HORZRES       "},
     {  10, "VERTRES       "},
     {  12, "BITSPIXEL     "},
     {  14, "PLANES        "},
     {  16, "NUMBRUSHES    "},
     {  18, "NUMPENS       "},
     {  20, "NUMMARKERS    "},
     {  22, "NUMFONTS      "},
     {  24, "NUMCOLORS     "},
     {  26, "PDEVICESIZE   "},
     {  28, "CURVECAPS     "},
     {  30, "LINECAPS      "},
     {  32, "POLYGONALCAPS "},
     {  34, "TEXTCAPS      "},
     {  36, "CLIPCAPS      "},
     {  38, "RASTERCAPS    "},
     {  40, "ASPECTX       "},
     {  42, "ASPECTY       "},
     {  44, "ASPECTXY      "},
     {  88, "LOGPIXELSX    "},
     {  90, "LOGPIXELSY    "},
     { 104, "SIZEPALETTE   "},
     { 106, "NUMRESERVED   "},
     { 108, "COLORRES      "}}

Definition at line 42 of file GETDEV.H.

LookupEntry Device[NDevice]
Initial value:
    {{ 0 , "DT_PLOTTER   "},
     { 1 , "DT_RASDISPLAY"},
     { 2 , "DT_RASPRINTER"},
     { 3 , "DT_RASCAMERA "},
     { 4 , "DT_CHARSTREAM"},
     { 5 , "DT_METAFILE  "},
     { 6 , "DT_DISPFILE  "}}

Definition at line 77 of file GETDEV.H.

LookupEntry LineCaps[NLineCaps]
Initial value:
    {{ 0   , "LC_NONE       "},
     { 2   , "LC_POLYLINE   "},
     { 4   , "LC_MARKER     "},
     { 8   , "LC_POLYMARKER "},
     { 16  , "LC_WIDE       "},
     { 32  , "LC_STYLED     "},
     { 64  , "LC_WIDESTYLED "},
     { 128 , "LC_INTERIORS  "}}

Definition at line 103 of file GETDEV.H.

LookupEntry PolygonalCaps[NPolygonalCaps]
Initial value:
    {{ 0   , "PC_NONE       "},
     { 1   , "PC_POLYGON    "},
     { 2   , "PC_RECTANGLE  "},
     { 4   , "PC_WINDPOLYGON"},
     { 4   , "PC_TRAPEZOID  "},
     { 8   , "PC_SCANLINE   "},
     { 16  , "PC_WIDE       "},
     { 32  , "PC_STYLED     "},
     { 64  , "PC_WIDESTYLED "},
     { 128 , "PC_INTERIORS  "}}

Definition at line 116 of file GETDEV.H.

LookupEntry RasterCaps[NRasterCaps]
Initial value:
    {{  1     , "RC_BITBLT       "},
     {  2     , "RC_BANDING      "},
     {  4     , "RC_SCALING      "},
     {  8     , "RC_BITMAP64     "},
     {  0x0010, "RC_GDI20_OUTPUT "},
     {  0x0080, "RC_DI_BITMAP    "},
     {  0x0100, "RC_PALETTE      "},
     {  0x0200, "RC_DIBTODEV     "},
     {  0x0400, "RC_BIGFONT      "},
     {  0x0800, "RC_STRETCHBLT   "},
     {  0x1000, "RC_FLOODFILL    "},
     {  0x2000, "RC_STRETCHDIB   "}}

Definition at line 159 of file GETDEV.H.

char space[] = " %s"

Definition at line 24 of file GETDEV.H.

LookupEntry TextCaps[NTextCaps]
Initial value:
    {{ 0x0001 , "TC_OP_CHARACTER"},
     { 0x0002 , "TC_OP_STROKE   "},
     { 0x0004 , "TC_CP_STROKE   "},
     { 0x0008 , "TC_CR_90       "},
     { 0x0010 , "TC_CR_ANY      "},
     { 0x0020 , "TC_SF_X_YINDEP "},
     { 0x0040 , "TC_SA_DOUBLE   "},
     { 0x0080 , "TC_SA_INTEGER  "},
     { 0x0100 , "TC_SA_CONTIN   "},
     { 0x0200 , "TC_EA_DOUBLE   "},
     { 0x0400 , "TC_IA_ABLE     "},
     { 0x0800 , "TC_UA_ABLE     "},
     { 0x1000 , "TC_SO_ABLE     "},
     { 0x2000 , "TC_RA_ABLE     "},
     { 0x4000 , "TC_VA_ABLE     "},
     { 0x8000 , "TC_RESERVED    "}}

Definition at line 138 of file GETDEV.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETSYS/GETSYS.C File Reference

  • GETSYS
Functions

GETSYS.C File Reference

#include <windows.h>
#include "getsys.h"

Go to the source code of this file.

Functions

VOID | doDirectory (HWND hwnd)
VOID | doInfo (HWND hwnd)
VOID | doLocalTime (HWND hwnd)
VOID | doMetrics (HWND hwnd)
VOID | doPalette (HWND hwnd)
VOID | doSysColors (HWND hwnd)
VOID | doTime (HWND hwnd)
VOID | doVersionEx (HWND hwnd)
LRESULT CALLBACK | MainDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

VOID doDirectory ( HWND hwnd )

Definition at line 172 of file GETSYS.C.

{
char buffer[MAX_PATH];

  SetDlgItemText (hwnd, DID_TEXT, "System Directory");

  /*******************************************************/
  /*******************************************************/
  GetSystemDirectory (buffer, MAX_PATH);
  /*******************************************************/
  /*******************************************************/

  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

  return;
}

VOID doInfo ( HWND hwnd )

Definition at line 190 of file GETSYS.C.

{
SYSTEM_INFO  si;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEM_INFO");

  /*******************************************************/
  /*******************************************************/
  GetSystemInfo (&si);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wProcessorArchitecture      %d", (int) si.wProcessorArchitecture    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wReserved                   %d", (int) si.wReserved                 );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwPageSize                  %d",  (int) si.dwPageSize                 );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "lpMinimumApplicationAddress %08lx", (LONG)si.lpMinimumApplicationAddress );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "lpMaximumApplicationAddress %08lx", (LONG)si.lpMaximumApplicationAddress );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwActiveProcessorMask       %d",  (int) si.dwActiveProcessorMask      );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwNumberOfProcessors        %d",  (int) si.dwNumberOfProcessors       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwProcessorType             %d",  (int) si.dwProcessorType            );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwAllocationGranularity     %d",  (int) si.dwAllocationGranularity    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wProcessorLevel             %d",  (int) si.wProcessorLevel            );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wProcessorRevision          %d",  (int) si.wProcessorRevision         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

  return;
}

VOID doLocalTime ( HWND hwnd )

Definition at line 300 of file GETSYS.C.

{
SYSTEMTIME  st;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");

  /*******************************************************/
  /*******************************************************/
  GetLocalTime (&st);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  return;
}

VOID doMetrics ( HWND hwnd )

Definition at line 230 of file GETSYS.C.

{
int  i;
int  answer;

  SetDlgItemText (hwnd, DID_TEXT, "System Metrics");

  for (i = 0; i<sizeof(SystemMetrics)/sizeof(LookupEntry); i++) {

    /*******************************************************/
    /*******************************************************/
    answer = GetSystemMetrics (SystemMetrics[i].Value);
    /*******************************************************/
    /*******************************************************/

    wsprintf (buffer, SystemMetrics[i].String, (int)answer);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }

  return;
}

VOID doPalette ( HWND hwnd )

Definition at line 254 of file GETSYS.C.

{
int nEntries;
HDC hdc;
int i;
LPPALETTEENTRY  lpp;

  SetDlgItemText (hwnd, DID_TEXT, "System Palette");

  /* this function is slightly different because the amount of information
   * is not known until run time.  First find the number of entries in the
   * palette (16 for VGA, but 256 for 8514, ...), then allocate enough
   * space to hold all of them, query the information, put it in the list
   * box, and then free up the memory allocated.
   */
  hdc = GetDC (hwnd);
  nEntries = GetSystemPaletteEntries (hdc, 0,0, NULL);
  lpp = (LPPALETTEENTRY)LocalAlloc (LPTR,
                           (DWORD) (nEntries* sizeof (PALETTEENTRY)));

  if (lpp == NULL) {
    MessageBox (hwnd, "Memory allocation failed.", "Warning", MB_ICONSTOP | MB_OK);
    return;
  }

  /*******************************************************/
  /*******************************************************/
  nEntries = GetSystemPaletteEntries (hdc, 0,nEntries, lpp);
  /*******************************************************/
  /*******************************************************/

  ReleaseDC (hwnd, hdc);

  for (i = 0; i<nEntries; i++) {
    wsprintf (buffer, "%d) \t%02x \t%02x \t%02x \t%02x", i,
              lpp[i].peRed, lpp[i].peGreen, lpp[i].peBlue, lpp[i].peFlags);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }

  LocalFree (LocalHandle ((LPSTR)lpp));
  return;
}

VOID doSysColors ( HWND hwnd )

Definition at line 149 of file GETSYS.C.

{
int i;
DWORD answer;

  SetDlgItemText (hwnd, DID_TEXT, "System Colors");

  for (i = 0; i<NSYSCOLORS; i++) {

    /*******************************************************/
    /*******************************************************/
    answer = GetSysColor (SysColors[i].Value);
    /*******************************************************/
    /*******************************************************/

    wsprintf (buffer, SysColors[i].String, (int)answer);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }
  return;
}

VOID doTime ( HWND hwnd )

Definition at line 333 of file GETSYS.C.

{
SYSTEMTIME  st;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");

  /*******************************************************/
  /*******************************************************/
  GetSystemTime (&st);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  return;
}

VOID doVersionEx ( HWND hwnd )

Definition at line 368 of file GETSYS.C.

{
OSVERSIONINFO osvi;

  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  SetDlgItemText (hwnd, DID_TEXT, "OSVERSIONINFO");

  /*******************************************************/
  /*******************************************************/
  GetVersionEx (&osvi);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "dwOSVersionInfoSize %d",  (int)osvi.dwOSVersionInfoSize );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwMajorVersion      %d",  (int)osvi.dwMajorVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwMinorVersion      %d",  (int)osvi.dwMinorVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwBuildNumber       %d",  (int)osvi.dwBuildNumber );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwPlatformId        %d",  (int)osvi.dwPlatformId );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "szCSDVersion:       %s",  (LPTSTR) osvi.szCSDVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

#ifdef GETVERSION
  wsprintf (buffer, "GetVersion(): 0x%08x",  GetVersion () );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
#endif

  return;
}

BOOL CALLBACK MainDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 57 of file GETSYS.C.

{
  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    /********************************************************************\
    * WM_INITDIALOG
    *
    * Set a monospaced font into the listbox so columns line up nicely.
    \********************************************************************/
    case WM_INITDIALOG:
      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT,
        (WPARAM) GetStockObject (SYSTEM_FIXED_FONT), (LPARAM) 0 );
    break;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    /********************************************************************\
    * WM_COMMAND
    *
    * When the different buttons are hit, clear the list box, disable
    *  updating to it, call the function which will fill it, reenable
    *  updating, and then force a repaint.
    *
    \********************************************************************/
    case WM_COMMAND:

      /* if the list box sends back messages, return.  Otherwise we will
       *  clear it out, and that is not what we want to do at this point.
       */
      if (LOWORD(wParam)==DID_LISTBOX) return TRUE;

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW,    FALSE, 0);
      SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0,     0);

      /* switch on the control ID of the button that is pressed. */
      switch (LOWORD(wParam)) {
        case DID_SYSCOLORS : doSysColors (hwnd); break;
        case DID_DIRECTORY : doDirectory (hwnd); break;
        case DID_INFO      : doInfo      (hwnd); break;
        case DID_METRICS   : doMetrics   (hwnd); break;
        case DID_PALETTE   : doPalette   (hwnd); break;
        case DID_LOCALTIME : doLocalTime (hwnd); break;
        case DID_TIME      : doTime      (hwnd); break;
        case DID_VERSIONEX : doVersionEx (hwnd); break;
      } /* end switch (LOWORD()) */

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
      InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
      return TRUE;
    break; /* end WM_COMMAND */

    default: return FALSE;
  } /* end switch(message) */
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 35 of file GETSYS.C.

{
int ret;

    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nCmdShow);

    ret = DialogBox (hInstance, "getsysDlg", NULL, (DLGPROC)MainDlgProc);
    return ret;
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETSYS/GETSYS.H File Reference

  • GETSYS
Data Structures | Defines | Typedefs | Functions | Variables

GETSYS.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | DID_DIRECTORY 62
#define | DID_INFO 63
#define | DID_LISTBOX 70
#define | DID_LOCALTIME 66
#define | DID_METRICS 64
#define | DID_PALETTE 65
#define | DID_SYSCOLORS 61
#define | DID_TEXT 71
#define | DID_TIME 67
#define | DID_VERSIONEX 68
#define | NSYSCOLORS COLOR_BTNHIGHLIGHT+1

Typedefs

typedef struct tagLookupEntry | LookupEntry

Functions

VOID | doDirectory (HWND)
VOID | doInfo (HWND)
VOID | doLocalTime (HWND)
VOID | doMetrics (HWND)
VOID | doPalette (HWND)
VOID | doSysColors (HWND)
VOID | doTime (HWND)
VOID | doVersionEx (HWND)
LRESULT CALLBACK | MainDlgProc (HWND, UINT, WPARAM, LPARAM)

Variables

char | buffer [256]
LookupEntry | SysColors [NSYSCOLORS]
LookupEntry SystemMetrics []

Define Documentation

#define DID_DIRECTORY 62

Definition at line 35 of file GETSYS.H.

#define DID_INFO 63

Definition at line 36 of file GETSYS.H.

#define DID_LISTBOX 70

Definition at line 43 of file GETSYS.H.

#define DID_LOCALTIME 66

Definition at line 39 of file GETSYS.H.

#define DID_METRICS 64

Definition at line 37 of file GETSYS.H.

#define DID_PALETTE 65

Definition at line 38 of file GETSYS.H.

#define DID_SYSCOLORS 61

Definition at line 34 of file GETSYS.H.

#define DID_TEXT 71

Definition at line 44 of file GETSYS.H.

#define DID_TIME 67

Definition at line 40 of file GETSYS.H.

#define DID_VERSIONEX 68

Definition at line 41 of file GETSYS.H.

#define NSYSCOLORS COLOR_BTNHIGHLIGHT+1

Definition at line 55 of file GETSYS.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Function Documentation

VOID doDirectory ( HWND )

Definition at line 172 of file GETSYS.C.

{
char buffer[MAX_PATH];

  SetDlgItemText (hwnd, DID_TEXT, "System Directory");

  /*******************************************************/
  /*******************************************************/
  GetSystemDirectory (buffer, MAX_PATH);
  /*******************************************************/
  /*******************************************************/

  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

  return;
}

VOID doInfo ( HWND )

Definition at line 190 of file GETSYS.C.

{
SYSTEM_INFO  si;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEM_INFO");

  /*******************************************************/
  /*******************************************************/
  GetSystemInfo (&si);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wProcessorArchitecture      %d", (int) si.wProcessorArchitecture    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wReserved                   %d", (int) si.wReserved                 );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwPageSize                  %d",  (int) si.dwPageSize                 );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "lpMinimumApplicationAddress %08lx", (LONG)si.lpMinimumApplicationAddress );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "lpMaximumApplicationAddress %08lx", (LONG)si.lpMaximumApplicationAddress );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwActiveProcessorMask       %d",  (int) si.dwActiveProcessorMask      );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwNumberOfProcessors        %d",  (int) si.dwNumberOfProcessors       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwProcessorType             %d",  (int) si.dwProcessorType            );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwAllocationGranularity     %d",  (int) si.dwAllocationGranularity    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wProcessorLevel             %d",  (int) si.wProcessorLevel            );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wProcessorRevision          %d",  (int) si.wProcessorRevision         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

  return;
}

VOID doLocalTime ( HWND )

Definition at line 300 of file GETSYS.C.

{
SYSTEMTIME  st;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");

  /*******************************************************/
  /*******************************************************/
  GetLocalTime (&st);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  return;
}

VOID doMetrics ( HWND )

Definition at line 230 of file GETSYS.C.

{
int  i;
int  answer;

  SetDlgItemText (hwnd, DID_TEXT, "System Metrics");

  for (i = 0; i<sizeof(SystemMetrics)/sizeof(LookupEntry); i++) {

    /*******************************************************/
    /*******************************************************/
    answer = GetSystemMetrics (SystemMetrics[i].Value);
    /*******************************************************/
    /*******************************************************/

    wsprintf (buffer, SystemMetrics[i].String, (int)answer);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }

  return;
}

VOID doPalette ( HWND )

Definition at line 254 of file GETSYS.C.

{
int nEntries;
HDC hdc;
int i;
LPPALETTEENTRY  lpp;

  SetDlgItemText (hwnd, DID_TEXT, "System Palette");

  /* this function is slightly different because the amount of information
   * is not known until run time.  First find the number of entries in the
   * palette (16 for VGA, but 256 for 8514, ...), then allocate enough
   * space to hold all of them, query the information, put it in the list
   * box, and then free up the memory allocated.
   */
  hdc = GetDC (hwnd);
  nEntries = GetSystemPaletteEntries (hdc, 0,0, NULL);
  lpp = (LPPALETTEENTRY)LocalAlloc (LPTR,
                           (DWORD) (nEntries* sizeof (PALETTEENTRY)));

  if (lpp == NULL) {
    MessageBox (hwnd, "Memory allocation failed.", "Warning", MB_ICONSTOP | MB_OK);
    return;
  }

  /*******************************************************/
  /*******************************************************/
  nEntries = GetSystemPaletteEntries (hdc, 0,nEntries, lpp);
  /*******************************************************/
  /*******************************************************/

  ReleaseDC (hwnd, hdc);

  for (i = 0; i<nEntries; i++) {
    wsprintf (buffer, "%d) \t%02x \t%02x \t%02x \t%02x", i,
              lpp[i].peRed, lpp[i].peGreen, lpp[i].peBlue, lpp[i].peFlags);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }

  LocalFree (LocalHandle ((LPSTR)lpp));
  return;
}

VOID doSysColors ( HWND )

Definition at line 149 of file GETSYS.C.

{
int i;
DWORD answer;

  SetDlgItemText (hwnd, DID_TEXT, "System Colors");

  for (i = 0; i<NSYSCOLORS; i++) {

    /*******************************************************/
    /*******************************************************/
    answer = GetSysColor (SysColors[i].Value);
    /*******************************************************/
    /*******************************************************/

    wsprintf (buffer, SysColors[i].String, (int)answer);
    SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  }
  return;
}

VOID doTime ( HWND )

Definition at line 333 of file GETSYS.C.

{
SYSTEMTIME  st;

  SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");

  /*******************************************************/
  /*******************************************************/
  GetSystemTime (&st);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  return;
}

VOID doVersionEx ( HWND )

Definition at line 368 of file GETSYS.C.

{
OSVERSIONINFO osvi;

  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  SetDlgItemText (hwnd, DID_TEXT, "OSVERSIONINFO");

  /*******************************************************/
  /*******************************************************/
  GetVersionEx (&osvi);
  /*******************************************************/
  /*******************************************************/

  wsprintf (buffer, "dwOSVersionInfoSize %d",  (int)osvi.dwOSVersionInfoSize );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwMajorVersion      %d",  (int)osvi.dwMajorVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwMinorVersion      %d",  (int)osvi.dwMinorVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwBuildNumber       %d",  (int)osvi.dwBuildNumber );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "dwPlatformId        %d",  (int)osvi.dwPlatformId );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
  wsprintf (buffer, "szCSDVersion:       %s",  (LPTSTR) osvi.szCSDVersion );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);

#ifdef GETVERSION
  wsprintf (buffer, "GetVersion(): 0x%08x",  GetVersion () );
  SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
#endif

  return;
}

LRESULT CALLBACK MainDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 57 of file GETSYS.C.

{
  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    /********************************************************************\
    * WM_INITDIALOG
    *
    * Set a monospaced font into the listbox so columns line up nicely.
    \********************************************************************/
    case WM_INITDIALOG:
      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT,
        (WPARAM) GetStockObject (SYSTEM_FIXED_FONT), (LPARAM) 0 );
    break;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    /********************************************************************\
    * WM_COMMAND
    *
    * When the different buttons are hit, clear the list box, disable
    *  updating to it, call the function which will fill it, reenable
    *  updating, and then force a repaint.
    *
    \********************************************************************/
    case WM_COMMAND:

      /* if the list box sends back messages, return.  Otherwise we will
       *  clear it out, and that is not what we want to do at this point.
       */
      if (LOWORD(wParam)==DID_LISTBOX) return TRUE;

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW,    FALSE, 0);
      SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0,     0);

      /* switch on the control ID of the button that is pressed. */
      switch (LOWORD(wParam)) {
        case DID_SYSCOLORS : doSysColors (hwnd); break;
        case DID_DIRECTORY : doDirectory (hwnd); break;
        case DID_INFO      : doInfo      (hwnd); break;
        case DID_METRICS   : doMetrics   (hwnd); break;
        case DID_PALETTE   : doPalette   (hwnd); break;
        case DID_LOCALTIME : doLocalTime (hwnd); break;
        case DID_TIME      : doTime      (hwnd); break;
        case DID_VERSIONEX : doVersionEx (hwnd); break;
      } /* end switch (LOWORD()) */

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
      InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
      return TRUE;
    break; /* end WM_COMMAND */

    default: return FALSE;
  } /* end switch(message) */
}

Variable Documentation

char buffer[256]

Definition at line 29 of file GETSYS.H.

LookupEntry SysColors[NSYSCOLORS]
Initial value:
    {{ COLOR_SCROLLBAR          , "COLOR_SCROLLBAR           %06lx"},
     { COLOR_BACKGROUND         , "COLOR_BACKGROUND          %06lx"},
     { COLOR_ACTIVECAPTION      , "COLOR_ACTIVECAPTION       %06lx"},
     { COLOR_INACTIVECAPTION    , "COLOR_INACTIVECAPTION     %06lx"},
     { COLOR_MENU               , "COLOR_MENU                %06lx"},
     { COLOR_WINDOW             , "COLOR_WINDOW              %06lx"},
     { COLOR_WINDOWFRAME        , "COLOR_WINDOWFRAME         %06lx"},
     { COLOR_MENUTEXT           , "COLOR_MENUTEXT            %06lx"},
     { COLOR_WINDOWTEXT         , "COLOR_WINDOWTEXT          %06lx"},
     { COLOR_CAPTIONTEXT        , "COLOR_CAPTIONTEXT         %06lx"},
     { COLOR_ACTIVEBORDER       , "COLOR_ACTIVEBORDER        %06lx"},
     { COLOR_INACTIVEBORDER     , "COLOR_INACTIVEBORDER      %06lx"},
     { COLOR_APPWORKSPACE       , "COLOR_APPWORKSPACE        %06lx"},
     { COLOR_HIGHLIGHT          , "COLOR_HIGHLIGHT           %06lx"},
     { COLOR_HIGHLIGHTTEXT      , "COLOR_HIGHLIGHTTEXT       %06lx"},
     { COLOR_BTNFACE            , "COLOR_BTNFACE             %06lx"},
     { COLOR_BTNSHADOW          , "COLOR_BTNSHADOW           %06lx"},
     { COLOR_GRAYTEXT           , "COLOR_GRAYTEXT            %06lx"},
     { COLOR_BTNTEXT            , "COLOR_BTNTEXT             %06lx"},
     { COLOR_INACTIVECAPTIONTEXT, "COLOR_INACTIVECAPTIONTEXT %06lx"},
     { COLOR_BTNHIGHLIGHT       , "COLOR_BTNHIGHLIGHT        %06lx"}}

Definition at line 56 of file GETSYS.H.

LookupEntry SystemMetrics[]

Definition at line 82 of file GETSYS.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLOS.H File Reference

  • GLTHREAD

GLOS.H File Reference

#include <windows.h>

Go to the source code of this file.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLTHREAD.C File Reference

  • GLTHREAD
Functions | Variables

GLTHREAD.C File Reference

#include "glthread.h"

Go to the source code of this file.

Functions

LONG WINAPI | CommandHandler (HWND, WPARAM, LPARAM)
HWND WINAPI | InitializeWindow (HINSTANCE, int)
LONG WINAPI | MainWndProc (HWND, UINT, WPARAM, LPARAM)
int WINAPI | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HPALETTE | ghPalette
HPALETTE | ghpalOld
HWND | ghWnd
HGLRC | hRC
CHAR | szAppName [] = "GLThreads"

Function Documentation

LONG WINAPI CommandHandler | ( | HWND | hWnd,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 312 of file GLTHREAD.C.

{
    switch (LOWORD(wParam))
    {
      case IDM_EXIT:
            /* exit application */
            PostMessage (hWnd, WM_CLOSE, 0, 0L);
          break;

      case ID_DRAWWAVES:
        draw_scene(hWnd);
          break;

      default:
            return FALSE;
    }
    return TRUE;
}

HWND WINAPI InitializeWindow | ( | HINSTANCE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 101 of file GLTHREAD.C.

    {
    WNDCLASS   wc;
    HWND       hWnd;

    /* Register the frame class */
    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon (hInstance, szAppName);
    wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = szAppName;
    wc.lpszClassName = szAppName;

    if (!RegisterClass (&wc) )
        return FALSE;

    /* Create the frame */
    ghWnd = hWnd = CreateWindow (szAppName,
      "Generic OpenGL Sample",
      WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      NULL,
      NULL,
      hInstance,
      NULL);

    /* make sure window was created */
    if (!hWnd)
        return FALSE;

    /* show and update main window */
    ShowWindow (hWnd, nCmdShow);

    UpdateWindow (hWnd);

    return hWnd;
}

LONG WINAPI MainWndProc | ( | HWND | hWnd,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 166 of file GLTHREAD.C.

{
    LONG    lRet = 1;

    switch (uMsg)
    {
      case WM_SIZE:
          resize(hWnd);
            break;

        // The WM_QUERYNEWPALETTE message informs a window that it is about to
        // receive input focus. In response, the window receiving focus should
        // realize its palette as a foreground palette and update its client
        // area. If the window realizes its palette, it should return TRUE;
        // otherwise, it should return FALSE.

        case WM_QUERYNEWPALETTE:
        {
            HDC     hDC;

            if(ghPalette)
            {
                hDC = GetDC(hWnd);

                // Select and realize the palette

                ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
                RealizePalette(hDC);

                // Redraw the client area

                InvalidateRect(hWnd, NULL, TRUE);
                UpdateWindow(hWnd);

                if(ghpalOld)
                    SelectPalette(hDC, ghpalOld, FALSE);

                ReleaseDC(hWnd, hDC);

                return TRUE;
            }

            return FALSE;
        }

        // The WM_PALETTECHANGED message informs all windows that the window
        // with input focus has realized its logical palette, thereby changing
        // the system palette. This message allows a window without input focus
        // that uses a color palette to realize its logical palettes and update
        // its client area.
        //
        // This message is sent to all windows, including the one that changed
        // the system palette and caused this message to be sent. The wParam of
        // this message contains the handle of the window that caused the system
        // palette to change. To avoid an infinite loop, care must be taken to
        // check that the wParam of this message does not match the window's
        // handle.

        case WM_PALETTECHANGED:
        {
            HDC         hDC;

            // Before processing this message, make sure we
            // are indeed using a palette

            if (ghPalette)
            {
                // If this application did not change the palette, select
                // and realize this application's palette

                if (wParam != (WPARAM)hWnd)
                {
                    // Need the window's DC for SelectPalette/RealizePalette

                    hDC = GetDC(hWnd);

                    // Select and realize our palette

                    ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
                    RealizePalette(hDC);

                    // WHen updating the colors for an inactive window,
                    // UpdateColors can be called because it is faster than
                    // redrawing the client area (even though the results are
                    // not as good)

                    UpdateColors(hDC);

                    // Clean up

                    if (ghpalOld)
                       SelectPalette(hDC, ghpalOld, FALSE);

                    ReleaseDC(hWnd, hDC);
                }
            }
            break;
        }

      case WM_COMMAND:
            lRet = CommandHandler (hWnd, wParam, lParam);
            break;

        case WM_CLOSE:
            /* call destroy window to cleanup and go away */
            DestroyWindow (hWnd);
          break;

        case WM_DESTROY:
            PostQuitMessage (0);
          break;

      default:
            /* pass all unhandled messages to DefWindowProc */
            lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
          break;
    }

    /* return 1 if handled message, 0 if not */
    return lRet;
}

int WINAPI WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 58 of file GLTHREAD.C.

{
    MSG        msg;
    HWND       hWnd;

    /* previous instances do not exist in Win32 */
    if (hPrevInstance)
        return 0;

    if (!(hWnd = InitializeWindow (hInstance, nCmdShow)))
        return FALSE;

    /* main window message loop */
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    /* return success of application */
    return TRUE;
}

Variable Documentation

HPALETTE ghPalette

Definition at line 23 of file THREADS.C.

HPALETTE ghpalOld

Definition at line 23 of file THREADS.C.

HWND ghWnd

Definition at line 28 of file GLTHREAD.C.

HGLRC hRC

Definition at line 26 of file GLTHREAD.C.

CHAR szAppName[] = "GLThreads"

Definition at line 24 of file GLTHREAD.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLTHREAD.H File Reference

  • GLTHREAD
Functions

GLTHREAD.H File Reference

#include "glos.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include "resource.h"

Go to the source code of this file.

Functions

BOOL | bSetupPixelFormat (HDC)
GLvoid | CalculateVectorNormal (GLfloat fVert1[], GLfloat fVert2[], GLfloat fVert3[], GLfloat *fNormalX, GLfloat *fNormalY, GLfloat *fNormalZ)
GLvoid | draw_scene (HWND)
GLvoid | DrawWave (GLfloat fHeight, GLfloat fWidth, GLfloat fHorizon)
GLvoid | initialize (HWND)
GLvoid | resize (HWND)
GLfloat | solve (GLfloat x, GLfloat z, GLfloat h, GLfloat w)
GLvoid | ThreadFunc1 (void)
GLvoid | ThreadFunc2 (void)

Function Documentation

BOOL bSetupPixelFormat ( HDC )

Definition at line 157 of file THREADS.C.

{
    static PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
        1,                              // version number
        PFD_DRAW_TO_WINDOW |            // support window
        PFD_SUPPORT_OPENGL,             // support OpenGL
        PFD_TYPE_RGBA,                  // RGBA type
        24,                             // 24-bit color depth
        0, 0, 0, 0, 0, 0,               // color bits ignored
        0,                              // no alpha buffer
        0,                              // shift bit ignored
        0,                              // no accumulation buffer
        0, 0, 0, 0,                     // accum bits ignored
        32,                             // 32-bit z-buffer
        0,                              // no stencil buffer
        0,                              // no auxiliary buffer
        PFD_MAIN_PLANE,                 // main layer
        0,                              // reserved
        0, 0, 0                         // layer masks ignored
    };
    int pixelformat;

    if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
    {
        MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
        return FALSE;
    }

    if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE)
    {
        MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
        return FALSE;
    }

    CreateRGBPalette(hDC);

    return TRUE;
}

GLvoid CalculateVectorNormal | ( | GLfloat | fVert1[],
 |  | GLfloat | fVert2[],
 |  | GLfloat | fVert3[],
 |  | GLfloat * | fNormalX,
 |  | GLfloat * | fNormalY,
 |  | GLfloat * | fNormalZ
 | ) |  |

Definition at line 527 of file THREADS.C.

{
    GLfloat Qx, Qy, Qz, Px, Py, Pz;

    Qx = fVert2[0]-fVert1[0];
    Qy = fVert2[1]-fVert1[1];
    Qz = fVert2[2]-fVert1[2];
    Px = fVert3[0]-fVert1[0];
    Py = fVert3[1]-fVert1[1];
    Pz = fVert3[2]-fVert1[2];

    *fNormalX = Py*Qz - Pz*Qy;
    *fNormalY = Pz*Qx - Px*Qz;
    *fNormalZ = Px*Qy - Py*Qx;
}

GLvoid draw_scene ( HWND )

Definition at line 374 of file THREADS.C.

{
    DWORD dwThread1ID;
    DWORD dwThread2ID;

    hThreads[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc1,
                               NULL, 0, &dwThread1ID);

    // Create this thread suspended so it will wait until the window has been
    // cleared before drawing.
    hThreads[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc2,
                               NULL, CREATE_SUSPENDED,&dwThread2ID);

    // Wait for both threads to finish.
    WaitForMultipleObjects(2, hThreads, TRUE, 10000);
    CloseHandle(hThreads[0]);
    CloseHandle(hThreads[1]);
}

GLvoid DrawWave | ( | GLfloat | fHeight,
 |  | GLfloat | fWidth,
 |  | GLfloat | fHorizon
 | ) |  |

Definition at line 432 of file THREADS.C.

{
    GLfloat x;
    GLfloat z;
    GLfloat step;

    step = 0.11;
    for (z=3.5;z >= -12.0;z-=step)
    {
        for (x= -2.0 + fHorizon; x <= (2.0 + 0.01 + fHorizon); x += step)
        {
            GLfloat fNormalX, fNormalY, fNormalZ;
            GLfloat fVert1[3];
            GLfloat fVert2[3];
            GLfloat fVert3[3];
            GLfloat fVert4[3];

            glBegin(GL_POLYGON);
            fVert1[0] = x;
            fVert1[1] = solve(x,z,fHeight,fWidth);
            fVert1[2] = z;
            glVertex3fv(fVert1);
            fVert2[0] = x;
            fVert2[1] = solve(x,z-step,fHeight,fWidth);
            fVert2[2] = z-step;
            glVertex3fv(fVert2);
            fVert3[0] = x+step;
            fVert3[1] = solve(x+step,z-step,fHeight,fWidth);
            fVert3[2] = z-step;
            glVertex3fv(fVert3);
            fVert4[0] = x+step;
            fVert4[1] = solve(x+step,z,fHeight,fWidth);
            fVert4[2] = z;
            glVertex3fv(fVert4);

            // Calculate the vector normal coming out of the 3D polygon.
            CalculateVectorNormal(fVert1, fVert2, fVert3, &fNormalX, &fNormalY,
                                  &fNormalZ);
            // Set the normal vector for the polygon
            glNormal3f(fNormalX, fNormalY, fNormalZ);
            glEnd();
        }
    }
}

GLvoid initialize ( HWND )

Definition at line 215 of file THREADS.C.

{
    GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    /*  light_position is NOT default value */
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
    GLfloat maxObjectSize, aspect;
    GLdouble near_plane, far_plane;

    GetClientRect(hWnd, &oldrect);
    glClearColor( 0.0, 0.0, 0.0, 1.0 );
    glClearDepth( 70.0 );

    glEnable(GL_DEPTH_TEST);

    // Make it so our normal vectors are automatically changed to "unit" length
    glEnable(GL_NORMALIZE);

    glMatrixMode( GL_PROJECTION );
    aspect = (GLfloat) oldrect.right / oldrect.bottom;;
    gluPerspective( 45.0, aspect, 3.0, 70.0 );
    glMatrixMode( GL_MODELVIEW );

    // Set up lighting
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);

    near_plane = 3.0;
    far_plane = 70.0;
    maxObjectSize = 3.0;
    radius = near_plane + maxObjectSize/2.0;
}

GLvoid resize ( HWND )

Definition at line 401 of file THREADS.C.

{
    RECT    rect;

    GetClientRect(hWnd, &rect);

    glViewport(0, 0, rect.right, rect.bottom);

    oldrect.right = rect.right;
    oldrect.bottom = rect.bottom;
}

GLfloat solve | ( | GLfloat | x,
 |  | GLfloat | z,
 |  | GLfloat | h,
 |  | GLfloat | w
 | ) |  |

Definition at line 497 of file THREADS.C.

{
    GLfloat y;
    y = cos(x/w)*h+cos(z/w)*h;
    return y;
}

GLvoid ThreadFunc1 ( void )

Definition at line 275 of file THREADS.C.

{
    HDC   hDC;
    HGLRC hRC;

    // Get a DC for the main window
    hDC = GetDC(ghWnd);
    bSetupPixelFormat(hDC);
    hRC = wglCreateContext( hDC );
    wglMakeCurrent( hDC, hRC );
    initialize(ghWnd);

    // Clear the main window.  Only _one_ thread should be doing this.
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    // Now, it's safe for the other thread to start drawing.
    ResumeThread(hThreads[1]);

    glPushMatrix();
    glTranslatef(0.0, 0.0, -radius);

    // Define our point of reference
    gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
    DrawWave(0.6, 0.7, -2.5);
    glPopMatrix();
    glFinish();

    wglMakeCurrent(NULL, NULL);
    if (hRC)
        wglDeleteContext(hRC);
    if (hDC)
        ReleaseDC(ghWnd, hDC);
}

GLvoid ThreadFunc2 ( void )

Definition at line 326 of file THREADS.C.

{
    HDC   hDC;
    HGLRC hRC;

    // Get a DC for the main window
    hDC = GetDC(ghWnd);
    bSetupPixelFormat(hDC);
    hRC = wglCreateContext( hDC );
    wglMakeCurrent( hDC, hRC );
    initialize(ghWnd);

    glPushMatrix();
    glTranslatef(0.0, 0.0, -radius);

    // Define our point of reference
    gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
    DrawWave(0.2, 0.3, 2.5);
    glPopMatrix();
    glFinish();

    wglMakeCurrent(NULL, NULL);
    if (hRC)
        wglDeleteContext(hRC);
    if (hDC)
        ReleaseDC(ghWnd, hDC);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/RESOURCE.H File Reference

  • GLTHREAD
Defines

RESOURCE.H File Reference

Go to the source code of this file.

Defines

#define | ID_DRAWWAVES 40004
#define | IDM_EXIT 40001

Define Documentation

#define ID_DRAWWAVES 40004

Definition at line 6 of file RESOURCE.H.

#define IDM_EXIT 40001

Definition at line 5 of file RESOURCE.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/THREADS.C File Reference

  • GLTHREAD
Functions | Variables

THREADS.C File Reference

#include "glthread.h"
#include <math.h>

Go to the source code of this file.

Functions

BOOL | bSetupPixelFormat (HDC hDC)
GLvoid | CalculateVectorNormal (GLfloat fVert1[], GLfloat fVert2[], GLfloat fVert3[], GLfloat *fNormalX, GLfloat *fNormalY, GLfloat *fNormalZ)
unsigned char | ComponentFromIndex (int i, UINT nbits, UINT shift)
void | CreateRGBPalette (HDC hDC)
GLvoid | draw_scene (HWND hWnd)
GLvoid | DrawWave (GLfloat fHeight, GLfloat fWidth, GLfloat fHorizon)
GLvoid | initialize (HWND hWnd)
GLvoid | resize (HWND hWnd)
GLfloat | solve (GLfloat x, GLfloat z, GLfloat h, GLfloat w)
GLvoid | ThreadFunc1 (void)
GLvoid | ThreadFunc2 (void)

Variables

HPALETTE | ghPalette = (HPALETTE) 0
HPALETTE | ghpalOld
HWND | ghWnd
HANDLE | hThreads [2]
RECT | oldrect
unsigned char | oneto8 [2]
GLfloat | radius
unsigned char | threeto8 [8]
unsigned char | twoto8 [4]

Function Documentation

BOOL bSetupPixelFormat ( HDC hDC )

Definition at line 157 of file THREADS.C.

{
    static PIXELFORMATDESCRIPTOR pfd = {
        sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
        1,                              // version number
        PFD_DRAW_TO_WINDOW |            // support window
        PFD_SUPPORT_OPENGL,             // support OpenGL
        PFD_TYPE_RGBA,                  // RGBA type
        24,                             // 24-bit color depth
        0, 0, 0, 0, 0, 0,               // color bits ignored
        0,                              // no alpha buffer
        0,                              // shift bit ignored
        0,                              // no accumulation buffer
        0, 0, 0, 0,                     // accum bits ignored
        32,                             // 32-bit z-buffer
        0,                              // no stencil buffer
        0,                              // no auxiliary buffer
        PFD_MAIN_PLANE,                 // main layer
        0,                              // reserved
        0, 0, 0                         // layer masks ignored
    };
    int pixelformat;

    if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
    {
        MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
        return FALSE;
    }

    if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE)
    {
        MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
        return FALSE;
    }

    CreateRGBPalette(hDC);

    return TRUE;
}

GLvoid CalculateVectorNormal | ( | GLfloat | fVert1[],
 |  | GLfloat | fVert2[],
 |  | GLfloat | fVert3[],
 |  | GLfloat * | fNormalX,
 |  | GLfloat * | fNormalY,
 |  | GLfloat * | fNormalZ
 | ) |  |

Definition at line 527 of file THREADS.C.

{
    GLfloat Qx, Qy, Qz, Px, Py, Pz;

    Qx = fVert2[0]-fVert1[0];
    Qy = fVert2[1]-fVert1[1];
    Qz = fVert2[2]-fVert1[2];
    Px = fVert3[0]-fVert1[0];
    Py = fVert3[1]-fVert1[1];
    Pz = fVert3[2]-fVert1[2];

    *fNormalX = Py*Qz - Pz*Qy;
    *fNormalY = Pz*Qx - Px*Qz;
    *fNormalZ = Px*Qy - Py*Qx;
}

unsigned char ComponentFromIndex | ( | int | i,
 |  | UINT | nbits,
 |  | UINT | shift
 | ) |  |

Definition at line 75 of file THREADS.C.

{
    unsigned char val;

    val = (unsigned char) (i >> shift);
    switch (nbits)
    {
        case 1:
            val &= 0x1;
            return oneto8[val];

        case 2:
            val &= 0x3;
            return twoto8[val];

        case 3:
            val &= 0x7;
            return threeto8[val];

        default:
            return 0;
    }
}

void CreateRGBPalette ( HDC hDC )

Definition at line 106 of file THREADS.C.

{
    PIXELFORMATDESCRIPTOR pfd;
    LOGPALETTE *pPal;
    int n, i;

    n = GetPixelFormat(hDC);
    DescribePixelFormat(hDC, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    if (pfd.dwFlags & PFD_NEED_PALETTE) {
        n = 1 << pfd.cColorBits;
        pPal = (PLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
               n * sizeof(PALETTEENTRY));
        pPal->palVersion = 0x300;
        pPal->palNumEntries = n;
        for (i=0; i<n; i++)
        {
            pPal->palPalEntry[i].peRed =
                    ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift);
            pPal->palPalEntry[i].peGreen =
                    ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift);
            pPal->palPalEntry[i].peBlue =
                    ComponentFromIndex(i, pfd.cBlueBits, pfd.cBlueShift);
            pPal->palPalEntry[i].peFlags = 0;
        }

        /* fix up the palette to include the default GDI palette */
        if ((pfd.cColorBits == 8)                           &&
            (pfd.cRedBits   == 3) && (pfd.cRedShift   == 0) &&
            (pfd.cGreenBits == 3) && (pfd.cGreenShift == 3) &&
            (pfd.cBlueBits  == 2) && (pfd.cBlueShift  == 6))
        {
            for (i = 1 ; i <= 12 ; i++)
                pPal->palPalEntry[defaultOverride[i]] = defaultPalEntry[i];
        }

        ghPalette = CreatePalette(pPal);
        LocalFree(pPal);

        ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
        n = RealizePalette(hDC);
    }
}

GLvoid draw_scene ( HWND hWnd )

Definition at line 374 of file THREADS.C.

{
    DWORD dwThread1ID;
    DWORD dwThread2ID;

    hThreads[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc1,
                               NULL, 0, &dwThread1ID);

    // Create this thread suspended so it will wait until the window has been
    // cleared before drawing.
    hThreads[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc2,
                               NULL, CREATE_SUSPENDED,&dwThread2ID);

    // Wait for both threads to finish.
    WaitForMultipleObjects(2, hThreads, TRUE, 10000);
    CloseHandle(hThreads[0]);
    CloseHandle(hThreads[1]);
}

GLvoid DrawWave | ( | GLfloat | fHeight,
 |  | GLfloat | fWidth,
 |  | GLfloat | fHorizon
 | ) |  |

Definition at line 432 of file THREADS.C.

{
    GLfloat x;
    GLfloat z;
    GLfloat step;

    step = 0.11;
    for (z=3.5;z >= -12.0;z-=step)
    {
        for (x= -2.0 + fHorizon; x <= (2.0 + 0.01 + fHorizon); x += step)
        {
            GLfloat fNormalX, fNormalY, fNormalZ;
            GLfloat fVert1[3];
            GLfloat fVert2[3];
            GLfloat fVert3[3];
            GLfloat fVert4[3];

            glBegin(GL_POLYGON);
            fVert1[0] = x;
            fVert1[1] = solve(x,z,fHeight,fWidth);
            fVert1[2] = z;
            glVertex3fv(fVert1);
            fVert2[0] = x;
            fVert2[1] = solve(x,z-step,fHeight,fWidth);
            fVert2[2] = z-step;
            glVertex3fv(fVert2);
            fVert3[0] = x+step;
            fVert3[1] = solve(x+step,z-step,fHeight,fWidth);
            fVert3[2] = z-step;
            glVertex3fv(fVert3);
            fVert4[0] = x+step;
            fVert4[1] = solve(x+step,z,fHeight,fWidth);
            fVert4[2] = z;
            glVertex3fv(fVert4);

            // Calculate the vector normal coming out of the 3D polygon.
            CalculateVectorNormal(fVert1, fVert2, fVert3, &fNormalX, &fNormalY,
                                  &fNormalZ);
            // Set the normal vector for the polygon
            glNormal3f(fNormalX, fNormalY, fNormalZ);
            glEnd();
        }
    }
}

GLvoid initialize ( HWND hWnd )

Definition at line 215 of file THREADS.C.

{
    GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    /*  light_position is NOT default value */
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
    GLfloat maxObjectSize, aspect;
    GLdouble near_plane, far_plane;

    GetClientRect(hWnd, &oldrect);
    glClearColor( 0.0, 0.0, 0.0, 1.0 );
    glClearDepth( 70.0 );

    glEnable(GL_DEPTH_TEST);

    // Make it so our normal vectors are automatically changed to "unit" length
    glEnable(GL_NORMALIZE);

    glMatrixMode( GL_PROJECTION );
    aspect = (GLfloat) oldrect.right / oldrect.bottom;;
    gluPerspective( 45.0, aspect, 3.0, 70.0 );
    glMatrixMode( GL_MODELVIEW );

    // Set up lighting
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);

    near_plane = 3.0;
    far_plane = 70.0;
    maxObjectSize = 3.0;
    radius = near_plane + maxObjectSize/2.0;
}

GLvoid resize ( HWND hWnd )

Definition at line 401 of file THREADS.C.

{
    RECT    rect;

    GetClientRect(hWnd, &rect);

    glViewport(0, 0, rect.right, rect.bottom);

    oldrect.right = rect.right;
    oldrect.bottom = rect.bottom;
}

GLfloat solve | ( | GLfloat | x,
 |  | GLfloat | z,
 |  | GLfloat | h,
 |  | GLfloat | w
 | ) |  |

Definition at line 497 of file THREADS.C.

{
    GLfloat y;
    y = cos(x/w)*h+cos(z/w)*h;
    return y;
}

GLvoid ThreadFunc1 ( void )

Definition at line 275 of file THREADS.C.

{
    HDC   hDC;
    HGLRC hRC;

    // Get a DC for the main window
    hDC = GetDC(ghWnd);
    bSetupPixelFormat(hDC);
    hRC = wglCreateContext( hDC );
    wglMakeCurrent( hDC, hRC );
    initialize(ghWnd);

    // Clear the main window.  Only _one_ thread should be doing this.
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    // Now, it's safe for the other thread to start drawing.
    ResumeThread(hThreads[1]);

    glPushMatrix();
    glTranslatef(0.0, 0.0, -radius);

    // Define our point of reference
    gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
    DrawWave(0.6, 0.7, -2.5);
    glPopMatrix();
    glFinish();

    wglMakeCurrent(NULL, NULL);
    if (hRC)
        wglDeleteContext(hRC);
    if (hDC)
        ReleaseDC(ghWnd, hDC);
}

GLvoid ThreadFunc2 ( void )

Definition at line 326 of file THREADS.C.

{
    HDC   hDC;
    HGLRC hRC;

    // Get a DC for the main window
    hDC = GetDC(ghWnd);
    bSetupPixelFormat(hDC);
    hRC = wglCreateContext( hDC );
    wglMakeCurrent( hDC, hRC );
    initialize(ghWnd);

    glPushMatrix();
    glTranslatef(0.0, 0.0, -radius);

    // Define our point of reference
    gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
    DrawWave(0.2, 0.3, 2.5);
    glPopMatrix();
    glFinish();

    wglMakeCurrent(NULL, NULL);
    if (hRC)
        wglDeleteContext(hRC);
    if (hDC)
        ReleaseDC(ghWnd, hDC);
}

Variable Documentation

HPALETTE ghPalette = (HPALETTE) 0

Definition at line 23 of file THREADS.C.

HPALETTE ghpalOld

Definition at line 23 of file THREADS.C.

HWND ghWnd

Definition at line 46 of file BOB.C.

HANDLE hThreads[2]

Definition at line 19 of file THREADS.C.

RECT oldrect

Definition at line 25 of file THREADS.C.

unsigned char oneto8[2]
Initial value:
 {
    0, 255
}

Definition at line 35 of file THREADS.C.

GLfloat radius

Definition at line 24 of file THREADS.C.

unsigned char threeto8[8]
Initial value:
 {
    0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
}

Definition at line 27 of file THREADS.C.

unsigned char twoto8[4]
Initial value:
 {
    0, 0x55, 0xaa, 0xff
}

Definition at line 31 of file THREADS.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/GUIGREP.C File Reference

  • GUIGREP
Defines | Functions | Variables

GUIGREP.C File Reference

#include <windows.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "guigrep.h"
#include "wfext.h"

Go to the source code of this file.

Defines

#define | lpTB ((LPFMS_TOOLBARLOAD) lParam)
#define | WNDCLASSNAME "SearchWndClass"

Functions

BOOL APIENTRY | About (HWND hDlg, UINT message, UINT wParam, LONG lParam)
BOOL APIENTRY | About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
LONG APIENTRY | ColorWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)
BOOL WINAPI | DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
LONG WINAPI | FMExtensionProc (HWND hWndFileMan, WORD wMsg, LONG lParam)
long | Poll_On_Threads (LONG lParam)
long | ProcessFileCommonCode (LPTHREADPBLOCK tpArgs)
BOOL APIENTRY | StringProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
long | TraverseFileCaseInsens (HANDLE hFile, LPSTR lpFilNam, LPSTR lpFileView)
long | TraverseFileCaseSens (HANDLE hFile, LPSTR lpFilNam, LPSTR lpFileView)

Variables

BOOL | bCaseInsens = FALSE
BOOL | bObjectExists = FALSE
HINSTANCE | hOurselves
HWND | hWndGlobal
int | iFinishedFiles
unsigned int | iGlobalSStLen
int | iHitCount = 0
int | ilpszCRLF = strlen("\r\n")
WNDPROC | lpfnOldEditProc
char | lpszCRLF [] = "\r\n"
memory * MasterBlock
growmemory * ResultBlock
char | szGlobalSearchString [MAXLINELEN]

Define Documentation

#define lpTB ((LPFMS_TOOLBARLOAD) lParam)
#define WNDCLASSNAME "SearchWndClass"

Definition at line 70 of file GUIGREP.C.

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 182 of file GUIGREP.C.

{
    switch (message) {
  case WM_INITDIALOG:
      return (TRUE);

  case WM_COMMAND:
      if (LOWORD(wParam) == IDOK
    || LOWORD(wParam) == IDCANCEL) {
    EndDialog(hDlg, TRUE);
    return (TRUE);
      }
      break;
    }
    return (FALSE);
  UNREFERENCED_PARAMETER(lParam);
}

LONG APIENTRY ColorWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 98 of file GUIGREP.C.

{
    static char szBuf[13];
    static char szPathName[MAX_PATH];

    RECT   rcClient;
  static HWND hWndHitBox,hWndFileMan;
  HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
    switch (message) {
  case WM_CREATE:
      AppendMenu(GetSystemMenu(hWnd,FALSE),MF_STRING, IDM_ABOUT, "About...");
      hWndHitBox = CreateWindow("EDIT","",WS_CHILD | WS_VISIBLE | ES_WANTRETURN | ES_AUTOHSCROLL |
                 DS_LOCALEDIT|ES_MULTILINE | WS_BORDER|WS_VSCROLL|WS_HSCROLL,
             0,0,1,1,hWnd, NULL, hInst,
             NULL);
    if (!hWndHitBox)
       {MessageBox(hWnd,"Unable to create Child Window!","Browse Extension",MB_OK);
        return(-1);
       };

      CloseHandle((HANDLE)SendMessage(hWndHitBox,EM_GETHANDLE,0,0));
    ShowWindow(hWndHitBox,SW_SHOWNORMAL);
      break;
  case WM_SIZE:
      GetClientRect(hWnd,&rcClient);
      MoveWindow(hWndHitBox,rcClient.left,rcClient.top,
           rcClient.right, rcClient.bottom, TRUE);
      break;
  case WM_LAUNCH:
    hWndFileMan = (HWND)lParam;
       { static THREADPBLOCK tpbParms;
         int iPollThreadID;
         tpbParms.hWndGlobal = hWnd;
         tpbParms.hWndFileBox = hWndFileMan;
         SendMessage(hWndHitBox,LB_RESETCONTENT,0,0);
         ResultBlock = new growmemory(4*4096,4096);
         bObjectExists=TRUE;
         HANDLE hNewThread=CreateThread(NULL,0,
           (LPTHREAD_START_ROUTINE)Poll_On_Threads,(LPVOID)&tpbParms,0,(LPDWORD)&iPollThreadID);
     };
       break;
  case WM_ADDITEM:
    { char szBuf[40];
      wsprintf(szBuf,"Finished %d File(s)",(int)lParam);
     SetWindowText(hWnd,szBuf);
    };
    break;
    case WM_FREEAGAIN:
    SendMessage(hWndHitBox,EM_SETHANDLE,(WPARAM)ResultBlock->GetHandle(),0);
    InvalidateRect(hWndHitBox,NULL,FALSE);
    break;

  case WM_SYSCOMMAND:
    if (wParam == IDM_ABOUT)
       DialogBox(hOurselves,
           "AboutBox",
           hWnd,
           (DLGPROC)About);
       else
      return (DefWindowProc(hWnd, message, wParam, lParam));
    break;

  case WM_DESTROY:
   bObjectExists=FALSE;
   delete(ResultBlock);
   break;
  default:
      return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (NULL);
}

BOOL WINAPI DllMain | ( | HINSTANCE | hDLL,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 214 of file GUIGREP.C.

{
  switch (dwReason)
  {
    case DLL_PROCESS_ATTACH:
    {
    WNDCLASS  wc;
    hOurselves=hDLL;

    wc.style = NULL;
    wc.lpfnWndProc = (WNDPROC)ColorWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = (HINSTANCE)GetCurrentProcess();
    wc.hIcon = LoadIcon(hDLL, "GrepIcon");
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  NULL;
    wc.lpszClassName = WNDCLASSNAME;

    if (!RegisterClass(&wc))
    {
    MessageBox(GetFocus(),"Unable to create class",
     "Browse extension",MB_OK);
    return(NULL);
    }
    };
   };
   return( TRUE );
}

LONG WINAPI FMExtensionProc | ( | HWND | hWndFileMan,
 |  | WORD | wMsg,
 |  | LONG | lParam
 | ) |  |

Definition at line 613 of file GUIGREP.C.

{
  static HMENU hSubMenu;
  static UINT wDelta;
  static HWND hWnd;
 switch (wMsg)
 {

/* this message is sent to the extension proc to update its toolbar to
   add custom buttons as accelarators for the extension menu. */

  case FMEVENT_TOOLBARLOAD:
   {
     static EXT_BUTTON ExtButtons[1] =
     { { IDM_STARTGREP-100, 0 , 0} };   /* This must correspond to the wMsg parameter passed to the extension proc */

#define lpTB ((LPFMS_TOOLBARLOAD) lParam)

  lpTB->dwSize = sizeof(FMS_TOOLBARLOAD);
  lpTB->lpButtons = (LPEXT_BUTTON) &ExtButtons;
  lpTB->cButtons = 1;
  lpTB->cBitmaps = 1;
  lpTB->idBitmap = IDM_STARTGREP;       /* Must correspond to the bitmap identifier */
  return(TRUE);
   };

/* this message is sent to the extension proc to associate a help string with
   a menu item. */

  case FMEVENT_HELPSTRING:
   strcpy(((LPFMS_HELPSTRING)lParam)->szHelp,"Search for a string in multiple files");
   return (TRUE);

  case FMEVENT_LOAD:
   if (!hOurselves)
    return(NULL);

     hSubMenu = LoadMenu(hOurselves,"FileManMenu");
     wDelta = ((LPFMS_LOAD)lParam)->wMenuDelta;
     ((LPFMS_LOAD)lParam)->dwSize= sizeof(FMS_LOAD);
     strcpy(((LPFMS_LOAD)lParam)->szMenuName,"S&earch");
     ((LPFMS_LOAD)lParam)->hMenu = hSubMenu;

     return (LONG) hSubMenu;
  default:
       switch (wMsg+100)
       {
        case IDM_DEFGREP:
       DialogBox(hOurselves,
           "StringDialog",
           hWndFileMan,
           (DLGPROC)StringProc);
       break;

    case IDM_STARTGREP:
    if (strlen(szGlobalSearchString) == 0)
       if (!DialogBox(hOurselves,
           "StringDialog",
           hWndFileMan,
           (DLGPROC)StringProc))
        break;
  if (IsWindow(hWndGlobal))
   {MessageBox(GetFocus(),"No more than one window supported","Close hit window",MB_OK);
    break;
   };
    hWnd = CreateWindow(
  WNDCLASSNAME,
  "Windows NT File Search Extension",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  (HINSTANCE)GetCurrentProcess(),
  NULL
    );
  SendMessage(hWnd,WM_LAUNCH,0,(LONG)hWndFileMan);
    ShowWindow(hWnd, SW_SHOWNORMAL);
    UpdateWindow(hWnd);
    break;
    default:
    break;
    };
  return(0);
 };
}

long Poll_On_Threads ( LONG lParam )

Definition at line 551 of file GUIGREP.C.

{ int iLoop, iEndLoop,iThread,iArrayIndex;
  char tempFilBuf[80];
  static HANDLE aThreads[MAX_CONCURRENT_THREADS];
  HWND hWndFileBox;
  LPTHREADPBLOCK lpTB = (LPTHREADPBLOCK)lParam;
  iHitCount = 0;
  iFinishedFiles = 0;
  iGlobalSStLen = strlen(szGlobalSearchString);
  hWndFileBox = lpTB->hWndFileBox;
  hWndGlobal =  lpTB->hWndGlobal;
  MasterBlock = new memory(150000);
  iEndLoop = SendMessage(hWndFileBox,FM_GETSELCOUNT,0,0);
  if (iEndLoop == 0)
   { MessageBox(hWndFileBox,"No files selected","Browser extension",MB_OK);
     return(0);
   };
  for (iLoop = 0; iLoop < iEndLoop; iLoop++)
  {HANDLE hNewThread;

    if (iLoop < MAX_CONCURRENT_THREADS)
             iArrayIndex = iLoop;
    else
      {
       iArrayIndex = WaitForMultipleObjects(
           MAX_CONCURRENT_THREADS,aThreads,FALSE,INFINITE);
       if (iArrayIndex == -1)
        {MessageBeep(0);
            return(-1);
         };

       CloseHandle(aThreads[iArrayIndex]);
      };
    lpTB = (LPTHREADPBLOCK)MasterBlock->Alloc(sizeof(THREADPBLOCK));
    lpTB->hWndFileBox=hWndFileBox;
  lpTB->iLoop = iLoop;
      hNewThread = CreateThread(NULL,0,
    (LPTHREAD_START_ROUTINE) ProcessFileCommonCode,
         (LPVOID)lpTB,0,(LPDWORD)&iThread);
  if (!hNewThread)
     MessageBox(GetFocus(),"Failed","CreateThread",MB_OK);
    aThreads[iArrayIndex] = hNewThread;

   };
/* We are now processing the last few threads. Clean up. */
  iEndLoop = min(iEndLoop,MAX_CONCURRENT_THREADS);
  WaitForMultipleObjects(iEndLoop, aThreads,TRUE,INFINITE);
  for (iLoop = 0; iLoop < iEndLoop ; iLoop++)
    if (!CloseHandle(aThreads[iLoop]))
      MessageBox(GetFocus(),"Can't delete thread!","",MB_OK);
  wsprintf(tempFilBuf,"Total Hits: %d",iHitCount);
  SetWindowText(hWndGlobal,tempFilBuf);
  delete (MasterBlock);
  SendMessage(hWndGlobal,WM_FREEAGAIN,0,0);
    return(0);
}

long ProcessFileCommonCode ( LPTHREADPBLOCK tpArgs )

Definition at line 479 of file GUIGREP.C.

{ FMS_GETFILESEL gfsSelection;
  LPSTR lpFilNam;
  HANDLE hFile, hMappedFile;
  LPSTR lpFileView;
  unsigned int iLineCt = 0;
/**************************************************************************/
/*    Set up file mapping etc.                                            */
/**************************************************************************/
  SendMessage(tpArgs->hWndFileBox,FM_GETFILESEL,tpArgs->iLoop,(LPARAM)&gfsSelection);
  lpFilNam = MasterBlock->Alloc(1+strlen(gfsSelection.szName));
    strcpy(lpFilNam,gfsSelection.szName);

  if ((hFile = CreateFile(lpFilNam, GENERIC_READ, FILE_SHARE_READ, NULL,
        OPEN_ALWAYS, FILE_ATTRIBUTE_READONLY, NULL))
      == INVALID_HANDLE_VALUE)
       return(FALSE);
  if (!(hMappedFile = CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,0)))
       {MessageBox(GetFocus(),"Could not open file mapping!",lpFilNam,MB_OK);
  return(FALSE);
       };
  if (!(lpFileView = (LPSTR)MapViewOfFile(hMappedFile,FILE_MAP_READ,0,0,0)))
       {MessageBox(GetFocus(),"Could not map file view",lpFilNam,MB_OK);
  return(FALSE);
       };
/**************************************************************************/
/*    Now traverse file                                                   */
/**************************************************************************/
  if (bCaseInsens)
    TraverseFileCaseInsens(hFile,lpFilNam,lpFileView);
  else
    TraverseFileCaseSens(hFile,lpFilNam,lpFileView);

/**************************************************************************/
/*    Clean up.                                                   */
/**************************************************************************/

  if (!UnmapViewOfFile(lpFileView))
   MessageBox(GetFocus(),"UnmapViewOfFile Failure",lpFilNam,MB_OK);
  if (!CloseHandle(hMappedFile))
   MessageBox(GetFocus(),"CloseHandle Failure...",lpFilNam,MB_OK);
  if (!CloseHandle(hFile))
   MessageBox(GetFocus(),"CloseHandle Failure...",lpFilNam,MB_OK);

iFinishedFiles++;
SendMessage(hWndGlobal,WM_ADDITEM,(WPARAM)iHitCount,iFinishedFiles);
  return(1);

}

BOOL APIENTRY StringProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 254 of file GUIGREP.C.

{   HWND hEditControl;
    switch (message)
      {
  case WM_INITDIALOG:
      hEditControl = GetDlgItem(hDlg, IDM_STRINGEDIT);
      SetWindowText(hEditControl,szGlobalSearchString);
    SendMessage(GetDlgItem(hDlg,IDM_CASESENS),BM_SETCHECK,bCaseInsens,0);
      return (TRUE);

  case WM_COMMAND:
    switch (LOWORD(wParam))
     {
     case IDM_CANCEL:
       EndDialog(hDlg,FALSE);
       return(TRUE);
       break;
       case IDM_TERMBOX:
      {int iLoopVar, iLen;
         bCaseInsens = SendMessage(GetDlgItem(hDlg,IDM_CASESENS),BM_GETCHECK,0,0);
         hEditControl = GetDlgItem(hDlg,IDM_STRINGEDIT);
         GetWindowText(hEditControl,szGlobalSearchString,MAXLINELEN);
       if (bCaseInsens)
        { iLen = strlen(szGlobalSearchString);
        for (iLoopVar = 0; iLoopVar < iLen;iLoopVar++)
       if (IsCharUpper(szGlobalSearchString[iLoopVar]))
       szGlobalSearchString[iLoopVar] = (char)_tolower((int)szGlobalSearchString[iLoopVar]);
      };
       EndDialog(hDlg, TRUE);
      }
         break;

      }
      break;
    }
    return (FALSE);
  UNREFERENCED_PARAMETER(lParam);
}

long TraverseFileCaseInsens | ( | HANDLE | hFile,
 |  | LPSTR | lpFilNam,
 |  | LPSTR | lpFileView
 | ) |  |

Definition at line 298 of file GUIGREP.C.

{
  unsigned int iGlobalSearchString, iCurrentBuffPt, iPrefixLength;
  BOOL bMatch;
  LPSTR lpLineBuff;
  unsigned int iLineCt = 0;
  DWORD dwFileSize, dwCurrentFilePt;

  dwFileSize = GetFileSize(hFile,NULL);
  lpLineBuff = MasterBlock->Alloc(MAXLINELEN);
  if (!lpLineBuff)
   {
   MessageBox(GetFocus(),lpFilNam,"Out of memory processing:",MB_OK);
   return (-1);
   };
/**************************************************************************/
/*    Initialize variables:                                               */
/*    lpLineBuff contains the buffer in which we store the whole line.    */
/*    If the line doesn't match, we "recycle" the buffer by using it      */
/*    for the next line; if it does, we send it off.                      */
/*    iCurrentBuff is the length of the line we currently work on,        */
/*    and iGlobalSearchString describes how far in the global search      */
/*    string we have progreesed so far matching.                          */
/**************************************************************************/

  strcpy(lpLineBuff,lpFilNam);
  strcat(lpLineBuff," <    >: ");
  iPrefixLength = strlen(lpLineBuff);
  iCurrentBuffPt = iPrefixLength-1;
  iGlobalSearchString = 0;
  bMatch = FALSE;
/**************************************************************************/
/*    Now go through the mapping character by character                   */
/**************************************************************************/

  for (dwCurrentFilePt=0;
       dwCurrentFilePt<dwFileSize;
       dwCurrentFilePt++)

    { if (iCurrentBuffPt >= MAXLINELEN)
    {MessageBox(GetFocus(),"File not readable!",lpFilNam,MB_OK);
     return(-1);
    };

      iCurrentBuffPt++;
      lpLineBuff[iCurrentBuffPt]= lpFileView[dwCurrentFilePt];
     if (lpLineBuff[iCurrentBuffPt] == '\n')
  {

   iLineCt++;
       if (bMatch)
         {
/**************************************************************************/
/*    A match has occurred!                                               */
/*    At this point, lpLineBuff points to the string that contains the    */
/*    matching line; iCurrentBuffPt its length.                           */
/**************************************************************************/

    OemToChar(lpLineBuff,lpLineBuff);
    wsprintf(&lpLineBuff[strlen(lpFilNam)+2],"%4d",iLineCt);
    lpLineBuff[strlen(lpFilNam)+6] = '>';
    iHitCount++;
        ResultBlock->add(lpLineBuff,iCurrentBuffPt-1);
    strcpy(lpLineBuff, lpFilNam);
    wsprintf(&lpLineBuff[strlen(lpFilNam)]," <    >: ");

         };
/**************************************************************************/
/*    The FOR-logic will increment the pointer,                           */
/*    so we reduce it by one because we use it in the NEXT iteration.     */
/**************************************************************************/

  iCurrentBuffPt = iPrefixLength -1;
  iGlobalSearchString = 0;
  bMatch = FALSE;
  }
     else

  { if (iGlobalSearchString < iGlobalSStLen)
      if ( /* This is the only difference to case-sensitive... */
      (IsCharUpper(lpLineBuff[iCurrentBuffPt]) ? (char)_tolower(lpLineBuff[iCurrentBuffPt])
        : lpLineBuff[iCurrentBuffPt]) == szGlobalSearchString[iGlobalSearchString])
         { iGlobalSearchString++;
     bMatch = TRUE;
         }
      else
         { bMatch = FALSE;
     iGlobalSearchString = 0;

         };

   };

   };
return(TRUE);
}

long TraverseFileCaseSens | ( | HANDLE | hFile,
 |  | LPSTR | lpFilNam,
 |  | LPSTR | lpFileView
 | ) |  |

Definition at line 404 of file GUIGREP.C.

{
  unsigned int iGlobalSearchString, iCurrentBuffPt, iPrefixLength;
  BOOL bMatch;
  LPSTR lpLineBuff;
  unsigned int iLineCt = 0;
  DWORD dwFileSize, dwCurrentFilePt;

  dwFileSize = GetFileSize(hFile,NULL);
  lpLineBuff = MasterBlock->Alloc(MAXLINELEN);
  if (!lpLineBuff)
   {
   MessageBox(GetFocus(),lpFilNam,"Out of memory processing:",MB_OK);
   return (-1);
   };

  strcpy(lpLineBuff,lpFilNam);
  strcat(lpLineBuff," <    >: ");
  iPrefixLength = strlen(lpLineBuff);
  iCurrentBuffPt = iPrefixLength-1;
  iGlobalSearchString = 0;
  bMatch = FALSE;
  for (dwCurrentFilePt=0;
       dwCurrentFilePt<dwFileSize;
       dwCurrentFilePt++)

    { if (iCurrentBuffPt >= MAXLINELEN)
    {MessageBox(GetFocus(),"File not readable!",lpFilNam,MB_OK);
     return(-1);
    };

      iCurrentBuffPt++;
      lpLineBuff[iCurrentBuffPt]= lpFileView[dwCurrentFilePt];
     if (lpLineBuff[iCurrentBuffPt] == '\n')
  {

   iLineCt++;
       if (bMatch)
         {
    OemToChar(lpLineBuff,lpLineBuff);
    wsprintf(&lpLineBuff[strlen(lpFilNam)+2],"%4d",iLineCt);
    lpLineBuff[strlen(lpFilNam)+6] = '>';
    iHitCount++;
    ResultBlock->add(lpLineBuff,iCurrentBuffPt-1);
    strcpy(lpLineBuff, lpFilNam);
    wsprintf(&lpLineBuff[strlen(lpFilNam)]," <    >: ");

         };
  iCurrentBuffPt = iPrefixLength -1;
  iGlobalSearchString = 0;
  bMatch = FALSE;
  }
     else

  { if (iGlobalSearchString < iGlobalSStLen)
      if (lpLineBuff[iCurrentBuffPt] == szGlobalSearchString[iGlobalSearchString])
         { iGlobalSearchString++;
     bMatch = TRUE;
         }
      else
         { bMatch = FALSE;
     iGlobalSearchString = 0;

         };

   };

   };

return(TRUE);
}

Variable Documentation

BOOL bCaseInsens = FALSE

Definition at line 57 of file GUIGREP.C.

BOOL bObjectExists = FALSE

Definition at line 62 of file GUIGREP.C.

HINSTANCE hOurselves

Definition at line 58 of file GUIGREP.C.

HWND hWndGlobal

Definition at line 52 of file GUIGREP.C.

int iFinishedFiles

Definition at line 56 of file GUIGREP.C.

unsigned int iGlobalSStLen

Definition at line 55 of file GUIGREP.C.

int iHitCount = 0

Definition at line 53 of file GUIGREP.C.

int ilpszCRLF = strlen("\r\n")

Definition at line 61 of file GUIGREP.C.

WNDPROC lpfnOldEditProc

Definition at line 59 of file GUIGREP.C.

char lpszCRLF[] = "\r\n"

Definition at line 60 of file GUIGREP.C.

memory* MasterBlock

Definition at line 50 of file GUIGREP.C.

growmemory* ResultBlock

Definition at line 51 of file GUIGREP.C.

char szGlobalSearchString[MAXLINELEN]

Definition at line 54 of file GUIGREP.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/GUIGREP.H File Reference

  • GUIGREP
Data Structures | Defines | Typedefs | Functions

GUIGREP.H File Reference

Go to the source code of this file.

Data Structures

class | growmemory
class | memory
struct | tagTHREADPBLOCK

Defines

#define | FILBUFSIZE 16384
#define | IDM_ABOUT 100
#define | IDM_CANCEL 109
#define | IDM_CASESENS 108
#define | IDM_DEFGREP 101
#define | IDM_INSTALL 102
#define | IDM_SORTBOX 107
#define | IDM_STARTGREP 105
#define | IDM_STRINGEDIT 103
#define | IDM_TERMBOX 104
#define | IDM_UNINSTALL 106
#define | MAX_CONCURRENT_THREADS 30
#define | MAXLINELEN 256
#define | WM_ADDITEM WM_USER+0xc004
#define | WM_FREEAGAIN WM_USER+0xc003
#define | WM_INQUIREFILES WM_USER+0xc001
#define | WM_LAUNCH WM_USER+0xc002
#define | WM_STARTSYNC WM_USER+0xc006
#define | WM_TELLHANDLE WM_USER+0xc005

Typedefs

typedef struct tagTHREADPBLOCK * | LPTHREADPBLOCK
typedef struct tagTHREADPBLOCK | THREADPBLOCK

Functions

BOOL FAR PASCAL | About (HWND, UINT, UINT, LONG)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, int)
long FAR PASCAL | MainWndProc (HWND, UINT, UINT, LONG)

Define Documentation

#define FILBUFSIZE 16384

Definition at line 22 of file GUIGREP.H.

#define IDM_ABOUT 100

Definition at line 2 of file GUIGREP.H.

#define IDM_CANCEL 109

Definition at line 11 of file GUIGREP.H.

#define IDM_CASESENS 108

Definition at line 10 of file GUIGREP.H.

#define IDM_DEFGREP 101

Definition at line 3 of file GUIGREP.H.

#define IDM_INSTALL 102

Definition at line 4 of file GUIGREP.H.

#define IDM_SORTBOX 107

Definition at line 9 of file GUIGREP.H.

#define IDM_STARTGREP 105

Definition at line 7 of file GUIGREP.H.

#define IDM_STRINGEDIT 103

Definition at line 5 of file GUIGREP.H.

#define IDM_TERMBOX 104

Definition at line 6 of file GUIGREP.H.

#define IDM_UNINSTALL 106

Definition at line 8 of file GUIGREP.H.

#define MAX_CONCURRENT_THREADS 30

Definition at line 23 of file GUIGREP.H.

#define MAXLINELEN 256

Definition at line 21 of file GUIGREP.H.

#define WM_ADDITEM WM_USER+0xc004

Definition at line 16 of file GUIGREP.H.

#define WM_FREEAGAIN WM_USER+0xc003

Definition at line 15 of file GUIGREP.H.

#define WM_INQUIREFILES WM_USER+0xc001

Definition at line 13 of file GUIGREP.H.

#define WM_LAUNCH WM_USER+0xc002

Definition at line 14 of file GUIGREP.H.

#define WM_STARTSYNC WM_USER+0xc006

Definition at line 18 of file GUIGREP.H.

#define WM_TELLHANDLE WM_USER+0xc005

Definition at line 17 of file GUIGREP.H.

Typedef Documentation

typedef struct tagTHREADPBLOCK * LPTHREADPBLOCK
typedef struct tagTHREADPBLOCK THREADPBLOCK

Function Documentation

BOOL FAR PASCAL About | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | int |
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

long FAR PASCAL MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/NTGREP.C File Reference

  • GUIGREP
Defines | Functions | Variables

NTGREP.C File Reference

#include <windows.h>
#include <string.h>
#include "ntgrep.h"

Go to the source code of this file.

Defines

#define | INITCLASSNAME "SearchInitClass"

Functions

BOOL APIENTRY | About (HWND hDlg, UINT message, UINT wParam, LONG lParam)
BOOL APIENTRY | About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | InitApplication (HINSTANCE hInstance)
BOOL | InitInstance (HINSTANCE hInstance, int nCmdShow)
LONG APIENTRY | MainWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HINSTANCE | hInst

Define Documentation

#define INITCLASSNAME "SearchInitClass"

Definition at line 19 of file NTGREP.C.

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 186 of file NTGREP.C.

{
    switch (message) {
  case WM_INITDIALOG:
      return (TRUE);

  case WM_COMMAND:
      if (LOWORD(wParam) == IDOK
    || LOWORD(wParam) == IDCANCEL) {
    EndDialog(hDlg, TRUE);
    return (TRUE);
      }
      break;
    }
    return (FALSE);
  UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HINSTANCE hInstance )

Definition at line 86 of file NTGREP.C.

{
    WNDCLASS  wc;
    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC)MainWndProc;

    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "GrepMenu";
    wc.lpszClassName = INITCLASSNAME;

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HINSTANCE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 106 of file NTGREP.C.

{
    HWND            hWnd;

    hInst = hInstance;

    hWnd = CreateWindow(
  INITCLASSNAME,
  "File Search Installer",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL
    );

    if (!hWnd)
  return (FALSE);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    return (TRUE);

}

LONG APIENTRY MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 140 of file NTGREP.C.

{

    switch (message) {
  case WM_COMMAND:
      switch (LOWORD(wParam))
      { static char szDirBuff[MAX_PATH+12];
        case IDM_INSTALL:
       GetSystemDirectory(szDirBuff,MAX_PATH);
       strcat(szDirBuff,"\\guigrep.dll");
       if (!CopyFile("guigrep.dll",szDirBuff,FALSE))
        { MessageBox(hWnd,"Error copying file to system directory",
            "Grep setup",MB_OK);
        break;
      };
      WritePrivateProfileString("AddOns","File Grepper",
              "guigrep.dll","winfile.ini");
     DialogBox(hInst,"ExplainBox",hWnd,(DLGPROC)About);
      /* Fall through... (vanity) */
        case IDM_ABOUT:
       DialogBox(hInst,"AboutBox",hWnd,(DLGPROC)About);
       break;
      case IDM_UNINSTALL:
      WritePrivateProfileString("AddOns","File Grepper",
              "","winfile.ini");
      break;

      default:
        return (DefWindowProc(hWnd, message, wParam, lParam));
      };
      break;
  case WM_DESTROY:
      PostQuitMessage(0);
      break;

  default:
      return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 40 of file NTGREP.C.

{

    MSG msg;
    DWORD dwVersion;

    UNREFERENCED_PARAMETER( lpCmdLine );

    /* Get the version we're running on to make sure it's NT */
    dwVersion = GetVersion();
    if (dwVersion & 0x80000000)
    {
        /* This is not NT.  Display an error message and exit. */
        MessageBox( NULL,
            "This sample application can only be run on Windows NT.\n"
            "This application will now terminate.",
            "GUIGrep",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

    if (!hPrevInstance)
  if (!InitApplication((HINSTANCE)hInstance))
      return (FALSE);

    if (!InitInstance((HINSTANCE)hInstance, nCmdShow))
  return (FALSE);

    while (GetMessage(&msg,NULL,0,0))
  {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
    }
    return (msg.wParam);
}

Variable Documentation

HINSTANCE hInst

Definition at line 16 of file NTGREP.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/NTGREP.H File Reference

  • GUIGREP
Defines

NTGREP.H File Reference

Go to the source code of this file.

Defines

#define | IDM_ABOUT 100
#define | IDM_CANCEL 109
#define | IDM_CASESENS 108
#define | IDM_DEFGREP 101
#define | IDM_INSTALL 102
#define | IDM_SORTBOX 107
#define | IDM_STARTGREP 105
#define | IDM_STRINGEDIT 103
#define | IDM_TERMBOX 104
#define | IDM_UNINSTALL 106

Define Documentation

#define IDM_ABOUT 100

Definition at line 1 of file NTGREP.H.

#define IDM_CANCEL 109

Definition at line 10 of file NTGREP.H.

#define IDM_CASESENS 108

Definition at line 9 of file NTGREP.H.

#define IDM_DEFGREP 101

Definition at line 2 of file NTGREP.H.

#define IDM_INSTALL 102

Definition at line 3 of file NTGREP.H.

#define IDM_SORTBOX 107

Definition at line 8 of file NTGREP.H.

#define IDM_STARTGREP 105

Definition at line 6 of file NTGREP.H.

#define IDM_STRINGEDIT 103

Definition at line 4 of file NTGREP.H.

#define IDM_TERMBOX 104

Definition at line 5 of file NTGREP.H.

#define IDM_UNINSTALL 106

Definition at line 7 of file NTGREP.H.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: HOOKS/HOOKTEST.C File Reference

  • HOOKS
Data Structures | Defines | Typedefs | Functions | Variables

HOOKTEST.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include "hooktest.h"

Go to the source code of this file.

Data Structures

struct | _MYHOOKDATA

Defines

#define | NUMHOOKS 7

Typedefs

typedef struct _MYHOOKDATA | MYHOOKDATA

Functions

LRESULT CALLBACK | CallWndProc (int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | CBTProc (int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | DebugProc (int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | GetMsgProc (int nCode, WPARAM wParam, LPARAM lParam)
BOOL | InitApplication (HANDLE hInstance)
BOOL | InitInstance (HANDLE hInstance, int nCmdShow)
LRESULT CALLBACK | KeyboardProc (int nCode, WPARAM wParam, LPARAM lParam)
LONG APIENTRY | MainWndProc (HWND hwndMain, UINT uMsg, UINT wParam, LONG lParam)
LRESULT CALLBACK | MessageProc (int nCode, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | MouseProc (int nCode, WPARAM wParam, LPARAM lParam)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hInst
HWND | hwndMain
MYHOOKDATA | myhookdata [NUMHOOKS]

Define Documentation

#define NUMHOOKS 7

Definition at line 17 of file HOOKTEST.C.

Typedef Documentation

typedef struct _MYHOOKDATA MYHOOKDATA

Function Documentation

LRESULT CALLBACK CallWndProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 319 of file HOOKTEST.C.

{
    CHAR szCWPBuf[256];
    HDC hdc;

    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
                wParam, lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HC_ACTION:
            cch = wsprintf(szCWPBuf,
               "CALLWNDPROC - tsk: %ld, msg: %d, %d times %20s",
                wParam, nCode, c++, "" );
            TextOut(hdc, 2, 15, szCWPBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
        wParam, lParam);
}

LRESULT CALLBACK CBTProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 448 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    CHAR szCode[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
            lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HCBT_ACTIVATE:
            lstrcpy(szCode, "HCBT_ACTIVATE");
            break;

        case HCBT_CLICKSKIPPED:
            lstrcpy(szCode, "HCBT_CLICKSKIPPED");
            break;

        case HCBT_CREATEWND:
            lstrcpy(szCode, "HCBT_CREATEWND");
            break;

        case HCBT_DESTROYWND:
            lstrcpy(szCode, "HCBT_DESTROYWND");
            break;

        case HCBT_KEYSKIPPED:
            lstrcpy(szCode, "HCBT_KEYSKIPPED");
            break;

        case HCBT_MINMAX:
            lstrcpy(szCode, "HCBT_MINMAX");
            break;

        case HCBT_MOVESIZE:
            lstrcpy(szCode, "HCBT_MOVESIZE");
            break;

        case HCBT_QS:
            lstrcpy(szCode, "HCBT_QS");
            break;

        case HCBT_SETFOCUS:
            lstrcpy(szCode, "HCBT_SETFOCUS");
            break;

        case HCBT_SYSCOMMAND:

            lstrcpy(szCode, "HCBT_SYSCOMMAND");
            break;

        default:
            lstrcpy(szCode, "Unknown");
            break;
    }

    cch = wsprintf(szBuf, "CBT - nCode: %s, tsk: %ld, %d times %20s",
        szCode, wParam, c++, "");
    TextOut(hdc, 2, 75, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
        lParam);
}

LRESULT CALLBACK DebugProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 410 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HC_ACTION:
            cch = wsprintf(szBuf,
                "DEBUG - nCode: %d, tsk: %ld, %d times %20s",
                nCode,wParam, c++, "");
            TextOut(hdc, 2, 55, szBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode, wParam,
        lParam);
}

LRESULT CALLBACK GetMsgProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 357 of file HOOKTEST.C.

{
    CHAR szMSGBuf[256];
    CHAR szRem[16];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0) /* do not process message */
        return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
            wParam, lParam);

    switch (nCode) {
        case HC_ACTION:
            switch (wParam) {
                case PM_REMOVE:
                    lstrcpy(szRem, "PM_REMOVE");
                    break;

                case PM_NOREMOVE:
                    lstrcpy(szRem, "PM_NOREMOVE");
                    break;

                default:
                    lstrcpy(szRem, "Unknown");
                    break;
            }

            hdc = GetDC(hwndMain);

            cch = wsprintf(szMSGBuf,
                "GETMESSAGE - wParam: %s, msg: %d, %d times %20s",
                szRem, nCode, c++, "");
            TextOut(hdc, 2, 35, szMSGBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
        wParam, lParam);
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 97 of file HOOKTEST.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).                    */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "HookMenu";   /* Name of menu resource in .RC file. */
    wc.lpszClassName = "HookWClass"; /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 136 of file HOOKTEST.C.

{

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    hInst = hInstance;

    /* Create a main window for this application instance.  */

    hwndMain = CreateWindow(
        "HookWClass",                 /* See RegisterClass() call.          */
        "Hooks Sample Application",   /* Text for window title bar.         */
        WS_OVERLAPPEDWINDOW,            /* Window style.                      */
        CW_USEDEFAULT,                  /* Default horizontal position.       */
        CW_USEDEFAULT,                  /* Default vertical position.         */
        CW_USEDEFAULT,                  /* Default width.                     */
        CW_USEDEFAULT,                  /* Default height.                    */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer not needed.                */
    );

    /* If window could not be created, return "failure" */

    if (!hwndMain)
        return (FALSE);

    /* Make the window visible; update its client area; and return "success" */

    ShowWindow(hwndMain, nCmdShow);  /* Show the window                        */
    UpdateWindow(hwndMain);          /* Sends WM_PAINT message                 */
    return (TRUE);               /* Returns the value from PostQuitMessage */

}

LRESULT CALLBACK KeyboardProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 560 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

    cch = wsprintf(szBuf, "KEYBOARD - nCode: %d, vk: %d, %d times %20s",
        nCode, wParam, c++, "" );
    TextOut(hdc, 2, 115, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode, wParam,
        lParam);
}

LONG APIENTRY MainWndProc | ( | HWND | hwndMain,
 |  | UINT | uMsg,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 194 of file HOOKTEST.C.

{
    static BOOL aHooks[NUMHOOKS];
    int index;
    static HMENU hmenu;

    switch (uMsg) {
        case WM_CREATE:

            /* Save the menu handle. */

            hmenu = GetMenu(hwndMain);

            /*
             * Initialize structures with hook data. The menu-item
             * identifiers are defined as 0 through 6 in the
             * header file. They can be used to identify array
             * elements both here and during the WM_COMMAND
             * message.
             */

            myhookdata[IDM_CALLWNDPROC].nType = WH_CALLWNDPROC;
            myhookdata[IDM_CALLWNDPROC].hkprc = CallWndProc;

            myhookdata[IDM_CBT].nType = WH_CBT;
            myhookdata[IDM_CBT].hkprc = CBTProc;
            myhookdata[IDM_DEBUG].nType = WH_DEBUG;
            myhookdata[IDM_DEBUG].hkprc = DebugProc;
            myhookdata[IDM_GETMESSAGE].nType = WH_GETMESSAGE;
            myhookdata[IDM_GETMESSAGE].hkprc = GetMsgProc;
            myhookdata[IDM_KEYBOARD].nType = WH_KEYBOARD;

            myhookdata[IDM_KEYBOARD].hkprc = KeyboardProc;
            myhookdata[IDM_MOUSE].nType = WH_MOUSE;
            myhookdata[IDM_MOUSE].hkprc = MouseProc;
            myhookdata[IDM_MSGFILTER].nType = WH_MSGFILTER;
            myhookdata[IDM_MSGFILTER].hkprc = MessageProc;

            /* Initialize all flags in the array to FALSE. */
            memset(aHooks, FALSE, sizeof(aHooks));

            return 0;

        case WM_COMMAND:

            switch (LOWORD(wParam)) {

                case IDM_EXIT:
                    PostQuitMessage(0);
                    break;

                /*
                 * The user selected a hook command from the menu.
                 */

                case IDM_CALLWNDPROC:
                case IDM_CBT:
                case IDM_DEBUG:
                case IDM_GETMESSAGE:
                case IDM_KEYBOARD:
                case IDM_MOUSE:
                case IDM_MSGFILTER:

                    /*
                     * Use the menu-item identifier as an index
                     * into the array of structures with hook data.

                     */

                    index = LOWORD(wParam);

                    /*
                     * If the selected type of hook procedure isn't
                     * installed yet, install it and check the
                     * associated menu item.
                     */

                    if (!aHooks[index]) {
                        myhookdata[index].hhook = SetWindowsHookEx(
                            myhookdata[index].nType,
                            myhookdata[index].hkprc,
                            (HINSTANCE) NULL, GetCurrentThreadId());
                        CheckMenuItem(hmenu, index,
                            MF_BYCOMMAND | MF_CHECKED);
                        aHooks[index] = TRUE;
                    }

                    /*
                     * If the selected type of hook procedure is
                     * already installed, remove it and remove the
                     * check mark from the associated menu item.
                     */

                    else {
                        UnhookWindowsHookEx(myhookdata[index].hhook);
                        CheckMenuItem(hmenu, index,
                            MF_BYCOMMAND | MF_UNCHECKED);
                        aHooks[index] = FALSE;
                        InvalidateRect(hwndMain, NULL, TRUE);
                        UpdateWindow(hwndMain);
                    }

           }
            break;

             case WM_DESTROY:
                 PostQuitMessage(0);
                 break;

        default:
            return DefWindowProc(hwndMain, uMsg, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK MessageProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 588 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    CHAR szCode[32];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
            wParam, lParam);

    switch (nCode) {
        case MSGF_DIALOGBOX:
            lstrcpy(szCode, "MSGF_DIALOGBOX");
            break;

        case MSGF_MENU:
            lstrcpy(szCode, "MSGF_MENU");
            break;

        case MSGF_SCROLLBAR:
            lstrcpy(szCode, "MSGF_SCROLLBAR");
            break;

        case MSGF_NEXTWINDOW:
            lstrcpy(szCode, "MSGF_NEXTWINDOW");
            break;

        default:
            wsprintf(szCode, "Unknown: %d", nCode);
            break;
    }

    hdc = GetDC(hwndMain);
    cch = wsprintf(szBuf,
        "MSGFILTER  nCode: %s, msg: %d, %d times %20s",
        szCode, nCode, c++, "" );
    TextOut(hdc, 2, 135, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
        wParam, lParam);
}

LRESULT CALLBACK MouseProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 526 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;
  LPMOUSEHOOKSTRUCT lpMouseHookStruct;

    if (nCode < 0)  /* do not process the message */
        return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

  lpMouseHookStruct = (LPMOUSEHOOKSTRUCT)lParam;
    cch = wsprintf(szBuf,
        "MOUSE - nCode: %d, msg: %d, x: %d, y: %d, %d times %20s",
        nCode, wParam, lpMouseHookStruct->pt.x, lpMouseHookStruct->pt.y,
        c++, "" );
    TextOut(hdc, 2, 95, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode, wParam,

        lParam);
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 44 of file HOOKTEST.C.

{

    MSG msg;                         /* message                      */

        if (!InitApplication(hInstance)) /* Initialize shared things */
            return (FALSE);              /* Exits if unable to initialize     */

    hInst = hInstance;

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    // register window message for FindText() and ReplaceText() hook procs
    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,        /* message structure                      */
            NULL,                  /* handle of window receiving the message */
            0,                     /* lowest message to examine              */
            0))                    /* highest message to examine             */
        {
        TranslateMessage(&msg);    /* Translates virtual key codes           */
        DispatchMessage(&msg);     /* Dispatches message to window           */
    }
    return (msg.wParam);           /* Returns the value from PostQuitMessage */

    // avoid compiler warnings at W3
    lpCmdLine;
    hPrevInstance;
}

Variable Documentation

HANDLE hInst

Definition at line 30 of file HOOKTEST.C.

HWND hwndMain

Definition at line 29 of file HOOKTEST.C.

MYHOOKDATA myhookdata[NUMHOOKS]

Definition at line 27 of file HOOKTEST.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: HOOKS/HOOKTEST.H File Reference

  • HOOKS
Defines | Functions

HOOKTEST.H File Reference

Go to the source code of this file.

Defines

#define | IDM_CALLWNDPROC 0
#define | IDM_CBT 1
#define | IDM_DEBUG 2
#define | IDM_EXIT 100
#define | IDM_GETMESSAGE 3
#define | IDM_KEYBOARD 4
#define | IDM_MOUSE 5
#define | IDM_MSGFILTER 6

Functions

LRESULT CALLBACK | CallWndProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | CBTProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | DebugProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | GetMsgProc (int, WPARAM, LPARAM)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, int)
LRESULT CALLBACK | KeyboardProc (int, WPARAM, LPARAM)
long APIENTRY | MainWndProc (HWND, UINT, UINT, LONG)
LRESULT CALLBACK | MessageProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | MouseProc (int, WPARAM, LPARAM)

Define Documentation

#define IDM_CALLWNDPROC 0

Definition at line 14 of file HOOKTEST.H.

#define IDM_CBT 1

Definition at line 15 of file HOOKTEST.H.

#define IDM_DEBUG 2

Definition at line 16 of file HOOKTEST.H.

#define IDM_EXIT 100

Definition at line 21 of file HOOKTEST.H.

#define IDM_GETMESSAGE 3

Definition at line 17 of file HOOKTEST.H.

#define IDM_KEYBOARD 4

Definition at line 18 of file HOOKTEST.H.

#define IDM_MOUSE 5

Definition at line 19 of file HOOKTEST.H.

#define IDM_MSGFILTER 6

Definition at line 20 of file HOOKTEST.H.

Function Documentation

LRESULT CALLBACK CallWndProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 319 of file HOOKTEST.C.

{
    CHAR szCWPBuf[256];
    HDC hdc;

    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
                wParam, lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HC_ACTION:
            cch = wsprintf(szCWPBuf,
               "CALLWNDPROC - tsk: %ld, msg: %d, %d times %20s",
                wParam, nCode, c++, "" );
            TextOut(hdc, 2, 15, szCWPBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
        wParam, lParam);
}

LRESULT CALLBACK CBTProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 448 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    CHAR szCode[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
            lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HCBT_ACTIVATE:
            lstrcpy(szCode, "HCBT_ACTIVATE");
            break;

        case HCBT_CLICKSKIPPED:
            lstrcpy(szCode, "HCBT_CLICKSKIPPED");
            break;

        case HCBT_CREATEWND:
            lstrcpy(szCode, "HCBT_CREATEWND");
            break;

        case HCBT_DESTROYWND:
            lstrcpy(szCode, "HCBT_DESTROYWND");
            break;

        case HCBT_KEYSKIPPED:
            lstrcpy(szCode, "HCBT_KEYSKIPPED");
            break;

        case HCBT_MINMAX:
            lstrcpy(szCode, "HCBT_MINMAX");
            break;

        case HCBT_MOVESIZE:
            lstrcpy(szCode, "HCBT_MOVESIZE");
            break;

        case HCBT_QS:
            lstrcpy(szCode, "HCBT_QS");
            break;

        case HCBT_SETFOCUS:
            lstrcpy(szCode, "HCBT_SETFOCUS");
            break;

        case HCBT_SYSCOMMAND:

            lstrcpy(szCode, "HCBT_SYSCOMMAND");
            break;

        default:
            lstrcpy(szCode, "Unknown");
            break;
    }

    cch = wsprintf(szBuf, "CBT - nCode: %s, tsk: %ld, %d times %20s",
        szCode, wParam, c++, "");
    TextOut(hdc, 2, 75, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
        lParam);
}

LRESULT CALLBACK DebugProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 410 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

    switch (nCode) {
        case HC_ACTION:
            cch = wsprintf(szBuf,
                "DEBUG - nCode: %d, tsk: %ld, %d times %20s",
                nCode,wParam, c++, "");
            TextOut(hdc, 2, 55, szBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode, wParam,
        lParam);
}

LRESULT CALLBACK GetMsgProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 357 of file HOOKTEST.C.

{
    CHAR szMSGBuf[256];
    CHAR szRem[16];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0) /* do not process message */
        return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
            wParam, lParam);

    switch (nCode) {
        case HC_ACTION:
            switch (wParam) {
                case PM_REMOVE:
                    lstrcpy(szRem, "PM_REMOVE");
                    break;

                case PM_NOREMOVE:
                    lstrcpy(szRem, "PM_NOREMOVE");
                    break;

                default:
                    lstrcpy(szRem, "Unknown");
                    break;
            }

            hdc = GetDC(hwndMain);

            cch = wsprintf(szMSGBuf,
                "GETMESSAGE - wParam: %s, msg: %d, %d times %20s",
                szRem, nCode, c++, "");
            TextOut(hdc, 2, 35, szMSGBuf, cch);
            break;

        default:
            break;
    }

    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
        wParam, lParam);
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | int |
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

LRESULT CALLBACK KeyboardProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 560 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

    cch = wsprintf(szBuf, "KEYBOARD - nCode: %d, vk: %d, %d times %20s",
        nCode, wParam, c++, "" );
    TextOut(hdc, 2, 115, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode, wParam,
        lParam);
}

long APIENTRY MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

LRESULT CALLBACK MessageProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 588 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    CHAR szCode[32];
    HDC hdc;
    static int c = 0;
    int cch;

    if (nCode < 0)  /* do not process message */
        return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
            wParam, lParam);

    switch (nCode) {
        case MSGF_DIALOGBOX:
            lstrcpy(szCode, "MSGF_DIALOGBOX");
            break;

        case MSGF_MENU:
            lstrcpy(szCode, "MSGF_MENU");
            break;

        case MSGF_SCROLLBAR:
            lstrcpy(szCode, "MSGF_SCROLLBAR");
            break;

        case MSGF_NEXTWINDOW:
            lstrcpy(szCode, "MSGF_NEXTWINDOW");
            break;

        default:
            wsprintf(szCode, "Unknown: %d", nCode);
            break;
    }

    hdc = GetDC(hwndMain);
    cch = wsprintf(szBuf,
        "MSGFILTER  nCode: %s, msg: %d, %d times %20s",
        szCode, nCode, c++, "" );
    TextOut(hdc, 2, 135, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
        wParam, lParam);
}

LRESULT CALLBACK MouseProc | ( | int | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 526 of file HOOKTEST.C.

{
    CHAR szBuf[128];
    HDC hdc;
    static int c = 0;
    int cch;
  LPMOUSEHOOKSTRUCT lpMouseHookStruct;

    if (nCode < 0)  /* do not process the message */
        return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode,
            wParam, lParam);

    hdc = GetDC(hwndMain);

  lpMouseHookStruct = (LPMOUSEHOOKSTRUCT)lParam;
    cch = wsprintf(szBuf,
        "MOUSE - nCode: %d, msg: %d, x: %d, y: %d, %d times %20s",
        nCode, wParam, lpMouseHookStruct->pt.x, lpMouseHookStruct->pt.y,
        c++, "" );
    TextOut(hdc, 2, 95, szBuf, cch);
    ReleaseDC(hwndMain, hdc);
    return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode, wParam,

        lParam);
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INHERIT/CHILD.C File Reference

  • INHERIT
Functions

CHILD.C File Reference

#include <stdio.h>
#include <io.h>
#include <string.h>
#include <windows.h>

Go to the source code of this file.

Functions

int | main ()
void | myError (HANDLE h, char *api, int line)

Function Documentation

int main ( void )

Definition at line 50 of file CHILD.C.

{
  DWORD cBytesWritten;
  HANDLE hStdErr, hStdOut, hConout;
  BOOL fSuccess;
  char *stdErrMsg = "Hello from child to standard error!\n";
  char *stdOutMsg = "Hello from child to standard output!\n";

  hConout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL, NULL);
  if ((int) hConout == -1)
    Beep(5000,500); /* no reliable way of reporting errors to the console */
                    /* if we can't open a console handle */
  hStdErr = GetStdHandle(STD_ERROR_HANDLE);
  if (hStdErr == INVALID_HANDLE_VALUE)
    myError(hConout, "GetStdHandle", __LINE__);
  hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  if (hStdOut == INVALID_HANDLE_VALUE)
    myError(hConout, "GetStdHandle", __LINE__);
  fSuccess = WriteFile(hStdErr, stdErrMsg, strlen(stdErrMsg),
      &cBytesWritten, NULL);
  if (!fSuccess)
    myError(hConout, "WriteFile", __LINE__);
  fSuccess = WriteFile(hStdOut, stdOutMsg, strlen(stdOutMsg),
      &cBytesWritten, NULL);
  if (!fSuccess)
    myError(hConout, "WriteFile", __LINE__);
  CloseHandle(hConout);
  return(0);
}

void myError | ( | HANDLE | h,
 |  | char * | api,
 |  | int | line
 | ) |  |

Definition at line 24 of file CHILD.C.

{
  char buf[512];
  BOOL fSuccess;
  DWORD cBytesWritten;
  HANDLE hConout;

  sprintf(buf, "%s: Error %d from %s on line %d\n", __FILE__, GetLastError(),
      api, line);
  fSuccess = WriteFile(h, buf, strlen(buf), &cBytesWritten, NULL);
  if (!fSuccess)
    {
    hConout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL, NULL);
    sprintf(buf, "%s: Error %d from %s on line %d\n", __FILE__,
      GetLastError(), api, line);
    WriteFile(hConout, buf, strlen(buf), &cBytesWritten, NULL);
    CloseHandle(hConout);
    }
  return;
}

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INHERIT/INHERIT.C File Reference

  • INHERIT
Defines | Functions

INHERIT.C File Reference

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define | USESTDHANDLES

Functions

int | main (int argc, char *argv[])
void | PERR (BOOL bSuccess, char *api)

Define Documentation

#define USESTDHANDLES

Definition at line 58 of file INHERIT.C.

Function Documentation

int main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 66 of file INHERIT.C.

{
  char chReadBuffer[64];  /* pipe read buffer */
  BOOL bSuccess;  /* BOOL return code for APIs */
  int j;
  HANDLE hOutFile;  /* handle to log file */
  /* handles to the anonymous pipe */
  HANDLE hReadPipe, hWritePipe, hWritePipe2;
  char szArgs[256];  /* child process argument buffer */
  char *p;  /* temporary pointer into szArgs */
  DWORD cchReadBuffer;  /* number of bytes read or to be written */
  STARTUPINFO si;  /* for CreateProcess call */
  PROCESS_INFORMATION pi;  /* for CreateProcess call */
  SECURITY_ATTRIBUTES saPipe;  /* security for anonymous pipe */
  OSVERSIONINFO os; /* operating system specs */

  os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // required assignment

  // check if running on Windows NT, if not, display notice and terminate
  if ( GetVersionEx(&os) )
  {
      if( os.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS &&
          os.dwPlatformId != VER_PLATFORM_WIN32_NT  )
      {
           MessageBox( NULL,
           "This sample application can only run on Windows NT and Windows 95.\n"
           "This application will now terminate.",
           "Inherit",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );

           return( 1 );
      }
  }
  else
  {
       MessageBox( NULL,
       "Unable to test for OS version.",
       "Inherit Error",
       MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );

       return( 1 );
  }

  if (argc < 3)
    {
    puts("format: inherit <trace file> <command to execute>");
    puts("trace file is the name of the file where the stdout");
    puts("and stderr of command will be redirected\n");
    puts("command to execute is command line of the function");
    puts("you wish to perform.\n");
    puts("Examples:\n");
    puts("  inherit trace.txt chkdsk d:");
    puts("  inherit trace.txt nmake /f foo.mak");
    return(1);
    }

  /* create the log file where we will save all output from child */
  hOutFile = CreateFile(argv[1],  /* file to open */
      GENERIC_WRITE,  /* access mode */
      FILE_SHARE_READ,  /* share mode */
      NULL,  /* security attributes */
      CREATE_ALWAYS,  /* creation flags - trash existing file */
      FILE_ATTRIBUTE_NORMAL,  /* file attributes */
      NULL);
  PERR(hOutFile != INVALID_HANDLE_VALUE, "CreateFile");

  /* set up the security attributes for the anonymous pipe */
  saPipe.nLength = sizeof(SECURITY_ATTRIBUTES);
  saPipe.lpSecurityDescriptor = NULL;
  /* In order for the child to be able to write to the pipe, the handle */
  /* must be marked as inheritable by setting this flag: */
  saPipe.bInheritHandle = TRUE;

  /* create the anonymous pipe */
  bSuccess = CreatePipe(&hReadPipe,  /* read handle */
      &hWritePipe,  /* write handle, used as stdout by child */
      &saPipe,  /* security descriptor */
      0);  /* pipe buffer size */
  PERR(bSuccess, "CreatePipe");

  /* Now we need to change the inheritable property for the readable
  end of the pipe so that the child will not inherit that handle as
  a "garbage" handle. This will keep us from having extra,
  unclosable handles to the pipe. Alternatively, we could have
  opened the pipe with saPipe.bInheritHandle = FALSE and changed the
  inherit property on the *write* handle of the pipe to TRUE. */

  bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
      hReadPipe, /* handle to duplicate */
      GetCurrentProcess(), /* destination process */
      NULL, /* new handle - don't want one, change original handle */
      0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
      FALSE, /* make it *not* inheritable */
      DUPLICATE_SAME_ACCESS);
  PERR(bSuccess, "DuplicateHandle");

  /* I most cases you can get away with using the same anonymous
  pipe write handle for both the child's standard output and
  standard error, but this may cause problems if the child app
  explicitly closes one of its standard output or error handles. If
  that happens, the anonymous pipe will close, since the child's
  standard output and error handles are really the same handle. The
  child won't be able to write to the other write handle since the
  pipe is now gone, and parent reads from the pipe will return
  ERROR_BROKEN_PIPE and child output will be lost. To solve this
  problem, simply duplicate the write end of the pipe to create
  another distinct, separate handle to the write end of the pipe.
  One pipe write handle will serve as standard out, the other as
  standard error. Now *both* write handles must be closed before the
  write end of the pipe actually closes. */

  bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
      hWritePipe, /* handle to duplicate */
      GetCurrentProcess(), /* destination process */
      &hWritePipe2, /* new handle, used as stderr by child */
      0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
      TRUE, /* it's inheritable */
      DUPLICATE_SAME_ACCESS);
  PERR(bSuccess, "DuplicateHandle");

  /* Set up the STARTUPINFO structure for the CreateProcess() call */
  memset(&si, 0, sizeof(si));
  si.cb = sizeof(si);

  /* Set up the command-line buffer for the child for CreateProcess() */
  memset(szArgs, 0, sizeof(szArgs));
  strcpy(szArgs, argv[2]);
  if (strchr(szArgs, '.') == NULL)  /* does it have a '.'? */
    strcat(szArgs, ".exe");  /* if not, assume it's an .exe */
  strcat(szArgs, " ");
  p = strchr(szArgs, 0);  /* point to the terminating null */
  for (j = 3; j < argc; j++)
    {
    strcat(p, argv[j]);
    /* the program and parameters are delimited by spaces */
    strcat(p, " ");
    }

#ifdef USESTDHANDLES
  /* If using the STARTUPINFO STARTF_USESTDHANDLES flag, be sure to
  set the CreateProcess fInheritHandles parameter too TRUE so that
  the file handles specified in the STARTUPINFO structure will be
  inheritied by the child. Note that we don't specify a standard
  input handle; the child will not inherit a valid input handle, so
  if it reads from stdin, it will encounter errors. */

  si.hStdInput = hWritePipe2; /* hStdInput needs a valid handle in case it is checked by the child */
  si.hStdOutput = hWritePipe; /* write end of the pipe */
  si.hStdError = hWritePipe2; /* duplicate of write end of the pipe */
  si.dwFlags = STARTF_USESTDHANDLES;
#else
  /* If we're not using the STARTF_USESTDHANDLES flag, set the
  standard output and error handles to the end of the pipe we want
  the child to inherit with SetStdHandle(). For this program, we
  don't want standard input inherited so we'll also change the
  handle inheritance property of standard input so that it is not
  inherited */
  bSuccess = SetStdHandle(STD_INPUT_HANDLE, hWritePipe2);
  PERR(bSuccess, "SetStdHandle");
  bSuccess = SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe);
  PERR(bSuccess, "SetStdHandle");
  bSuccess = SetStdHandle(STD_ERROR_HANDLE, hWritePipe2);
  PERR(bSuccess, "SetStdHandle");
  bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
      GetStdHandle(STD_INPUT_HANDLE), /* handle to duplicate */
      GetCurrentProcess(), /* destination process */
      NULL, /* new handle - don't want one, change original handle */
      0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
      FALSE, /* it's *not* inheritable */
      DUPLICATE_SAME_ACCESS);
  PERR(bSuccess, "DuplicateHandle");
#endif

  /* Now create the child process, inheriting handles */

  bSuccess = CreateProcess(NULL,  /* filename */
      szArgs,  /* full command line for child */
      NULL,  /* process security descriptor */
      NULL,  /* thread security descriptor */
      TRUE,  /* inherit handles? Also use if STARTF_USESTDHANDLES */
      0,  /* creation flags */
      NULL,  /* inherited environment address */
      NULL,  /* startup dir; NULL = start in current */
      &si,  /* pointer to startup info (input) */
      &pi);  /* pointer to process info (output) */
  PERR(bSuccess, "CreateProcess");

  /* We can close the returned child process handle and thread
  handle as we won't be needing them; you could, however, wait on
  the process handle to wait until the child process terminates. */

  CloseHandle(pi.hThread);
  CloseHandle(pi.hProcess);

  /* We need to close our instances of the inheritable pipe write
  handle now that it's been inherited so that all open handles to
  the pipe are closed when the child process ends and closes its
  handles to the pipe. */

  bSuccess = CloseHandle(hWritePipe);
  PERR(bSuccess, "CloseHandle");
  bSuccess = CloseHandle(hWritePipe2);
  PERR(bSuccess, "CloseHandle");

  /* read from the pipe until we get an ERROR_BROKEN_PIPE */
  for (;;)
    {
    bSuccess = ReadFile(hReadPipe,  /* read handle */
        chReadBuffer,  /* buffer for incoming data */
        sizeof(chReadBuffer),  /* number of bytes to read */
        &cchReadBuffer,  /* number of bytes actually read */
        NULL);  /* no overlapped reading */
    if (!bSuccess && (GetLastError() == ERROR_BROKEN_PIPE))
        break;  /* child has died */

    PERR(bSuccess, "ReadFile");
    if (bSuccess && cchReadBuffer)
      {
      /* write the data from the child to the file */
      bSuccess = WriteFile(hOutFile,  /* write handle */
          chReadBuffer,  /* buffer to write */
          cchReadBuffer,  /* number of bytes to write */
          &cchReadBuffer,  /* number of bytes actually written */
          NULL);  /* no overlapped writing */
      PERR(bSuccess, "WriteFile");

      /* write buffer (of specified length) to console */
      printf("%.*s", cchReadBuffer, chReadBuffer);
      }
    }
  /* close the trace file, pipe handles */
  CloseHandle(hOutFile);
  CloseHandle(hReadPipe);
  return(0);
}

void PERR | ( | BOOL | bSuccess,
 |  | char * | api
 | ) |  |

Definition at line 302 of file INHERIT.C.

{
    DWORD       dwError;
    TCHAR       szMsgBuf[500];

    if (!(bSuccess))
    {
        dwError = GetLastError();
        printf("\nFile:%s\nError occured in %s on line %d\n", __FILE__, api, __LINE__);

      FormatMessage(
          FORMAT_MESSAGE_FROM_SYSTEM,
          NULL,                               // ignored
          dwError,                     // message id
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),   // message language
          szMsgBuf,                   // address of buffer pointer
          500,                                  // minimum buffer size
          NULL );                              // no other arguments

        printf("\nError:(%ld)%s ", dwError, szMsgBuf);
     }
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/APP16.C File Reference

  • INTEROP
Data Structures | Defines | Typedefs | Functions | Variables

APP16.C File Reference

#include <windows.h>
#include <stdlib.h>
#include "app16.h"
#include "myut.h"

Go to the source code of this file.

Data Structures

struct | tagCOPYDATASTRUCT
struct | tagMYREC

Defines

#define | WM_COPYDATA 0x004A

Typedefs

typedef struct tagCOPYDATASTRUCT | COPYDATASTRUCT
typedef struct tagCOPYDATASTRUCT * | LPCOPYDATASTRUCT
typedef struct tagMYREC | MYREC

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
BOOL CALLBACK | InfoDlgProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
void WINAPI | MyPrint (LPSTR, LPSTR, DWORD)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)

Variables

HINSTANCE | ghInstance
HANDLE | ghWnd
DWORD nAge
char | szFirstName [80]
char | szLastName [80]

Define Documentation

#define WM_COPYDATA 0x004A

Definition at line 46 of file APP16.C.

Typedef Documentation

typedef struct tagCOPYDATASTRUCT COPYDATASTRUCT
typedef struct tagCOPYDATASTRUCT* LPCOPYDATASTRUCT
typedef struct tagMYREC MYREC

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hDlg,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 288 of file APP16.C.

{
   switch( uMsg ) {
      case WM_INITDIALOG:
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;
   }
   return FALSE;
}

BOOL CALLBACK InfoDlgProc | ( | HWND | hDlg,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 245 of file APP16.C.

{
   char szAge[5];

   switch( uMsg ) {
      case WM_INITDIALOG:
         szFirstName[0] = '\0';
         szLastName[0] = '\0';
         nAge = 0;
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case ID_OK:
               SendMessage( GetDlgItem(hDlg, IDC_FIRSTNAME), WM_GETTEXT,
                  sizeof(szFirstName), (LPARAM) ((LPSTR) szFirstName) );
               SendMessage( GetDlgItem(hDlg, IDC_LASTNAME), WM_GETTEXT,
                  sizeof(szLastName), (LPARAM) ((LPSTR) szLastName) );
               SendMessage( GetDlgItem(hDlg, IDC_AGE), WM_GETTEXT,
                  sizeof(szAge), (LPARAM) ((LPSTR) szAge) );
               nAge = atoi( szAge );
               EndDialog( hDlg, TRUE );
               return TRUE;
            case ID_CANCEL:
               EndDialog( hDlg, FALSE );
               return TRUE;
         }
      break;
   }
   return FALSE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | msg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 145 of file APP16.C.

{
   COPYDATASTRUCT MyCDS;
   MYREC MyRec;
   HWND hwDispatch;

   switch( msg ) {

/**************************************************************\
*     WM_COMMAND: Process menu commands                        *
\**************************************************************/

      case WM_COMMAND:
         switch( wParam ) {
            case IDM_THUNK:

            /* Get data from user (stored in globals) */

               DialogBox( ghInstance, "InfoDlg", hWnd, (DLGPROC)
                             InfoDlgProc );

            /* Call routine (through thunk) */

               MyPrint( (LPSTR) szFirstName,
                        (LPSTR) szLastName,
                        (DWORD) nAge );
               break;

            case IDM_COPYDATA:

            /* Get data from user (stored in globals) */

               DialogBox( ghInstance, "InfoDlg", hWnd, (DLGPROC)
                             InfoDlgProc );

            /* Copy data into structure to be passed via WM_COPYDATA */

               lstrcpy( MyRec.s1, szFirstName );
               lstrcpy( MyRec.s2, szLastName );
               MyRec.n = nAge;

            /* Fill the COPYDATA structure */

               MyCDS.dwData = MYPRINT;          // function identifier
               MyCDS.cbData = sizeof( MyRec );  // size of data
               MyCDS.lpData = &MyRec;           // data structure

            /* Call function through identifier, passing data in &MyCDS */

               hwDispatch = FindWindow( "Disp32Class", "Hidden Window" );
               if( hwDispatch != NULL )
                  SendMessage( hwDispatch,
                               WM_COPYDATA,
                               (WPARAM)(HWND) hWnd,
                               (LPARAM) (VOID FAR *) &MyCDS );
               else
                  MessageBox( hWnd, "Can't send WM_COPYDATA", "app16",
                              MB_OK );
               break;
            case IDM_EXIT:
               SendMessage( hWnd, WM_CLOSE, 0, 0 );
               break;
            case IDM_ABOUT:
               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                             AboutDlgProc );
               break;
         }
         break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

void WINAPI MyPrint | ( | LPSTR | ,
 |  | LPSTR | ,
 |  | DWORD |
 | ) |  |

Definition at line 147 of file DLL16.C.

{
   DWORD Args[3];
   LPVOID TransList[3];

   /*
      The arguments are packed into the Args array to be passed through
      the thunk. The TransList contains any pointers which must be
      translated. We wish to pass dwValue by value, so it is not placed
      in the translation list. The last entry in the translation list
      must be NULL.
   */

   if( fWin32s )
   {
      Args[0] = (DWORD) lpString1;
      Args[1] = (DWORD) lpString2;
      Args[2] = dwValue;

      TransList[0] = &Args[0];
      TransList[1] = &Args[1];
      TransList[2] = NULL;

      (*gpUTCBack)( Args, MYPRINT, TransList );
   }

   /*
      CallProc32W() takes a variable number of parameters. The last
      parameter here indicates that the first three arguments are to
      be passed through the thunk. The next parameter specifies Proc
      as the address of the function to be called. The second to the
      last parameter is a mask that indicates which parameters are
      addresses which should be translated. Note that the mask is
      specified in the opposite order that the parameters are listed,
      so 6 = 0110, indicating that lpString1 and lpString2 should be
      translated.
   */

   else
   {
      Proc = (MYPROC) GetProcAddress32W( ghLib, "MyPrint" );
      CallProc32W( (DWORD) lpString1, (DWORD) lpString2,
         (DWORD) dwValue, Proc, 6, 3 );
   }
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpszCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 82 of file APP16.C.

{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;

   if( !hPrevInstance ) {
      wc.lpszClassName = "App16Class";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( hInstance, "App16Icon" );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = "App16Menu";
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   hWnd = CreateWindow( "App16Class",
                        "App16",
                        WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
                        0,
                        0,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        NULL,
                        NULL,
                        hInstance,
                        NULL
          );

   ghWnd = hWnd;
   ghInstance = hInstance;

   ShowWindow( hWnd, nCmdShow );

   while( GetMessage( &msg, NULL, 0, 0 ) ) {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }

   return msg.wParam;
}

Variable Documentation

HINSTANCE ghInstance

Definition at line 58 of file APP16.C.

HANDLE ghWnd

Definition at line 57 of file APP16.C.

DWORD nAge

Definition at line 62 of file APP16.C.

char szFirstName[80]

Definition at line 60 of file APP16.C.

char szLastName[80]

Definition at line 61 of file APP16.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/APP16.H File Reference

  • INTEROP
Defines

APP16.H File Reference

Go to the source code of this file.

Defines

#define | ID_CANCEL 209
#define | ID_OK 208
#define | IDC_AGE 204
#define | IDC_FIRSTNAME 202
#define | IDC_LASTNAME 203
#define | IDM_ABOUT 104
#define | IDM_COPYDATA 102
#define | IDM_EXIT 103
#define | IDM_THUNK 101

Define Documentation

#define ID_CANCEL 209

Definition at line 11 of file APP16.H.

#define ID_OK 208

Definition at line 10 of file APP16.H.

#define IDC_AGE 204

Definition at line 9 of file APP16.H.

#define IDC_FIRSTNAME 202

Definition at line 7 of file APP16.H.

#define IDC_LASTNAME 203

Definition at line 8 of file APP16.H.

#define IDM_ABOUT 104

Definition at line 5 of file APP16.H.

#define IDM_COPYDATA 102

Definition at line 3 of file APP16.H.

#define IDM_EXIT 103

Definition at line 4 of file APP16.H.

#define IDM_THUNK 101

Definition at line 2 of file APP16.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DISP32.C File Reference

  • INTEROP
Data Structures | Typedefs | Functions

DISP32.C File Reference

#include <windows.h>
#include "myut.h"

Go to the source code of this file.

Data Structures

struct | tagMYREC

Typedefs

typedef struct tagMYREC | MYREC

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
void WINAPI | MyPrint (LPSTR, LPSTR, DWORD)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)

Typedef Documentation

typedef struct tagMYREC MYREC

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | msg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 105 of file DISP32.C.

{
   PCOPYDATASTRUCT pMyCDS;

   switch( msg ) {

/**************************************************************\
*     WM_COPYDATA: Dispatch calls to dll32.dll. The switch     *
*        statement is not strictly necessary here, since there *
*        is only one function thunked, but it is used to       *
*        demonstrate how you would dispatch more than one      *
*        function call.                                        *
\**************************************************************/

      case WM_COPYDATA:
         pMyCDS = (PCOPYDATASTRUCT) lParam;

         switch( pMyCDS->dwData )
         {
            case MYPRINT:
               MyPrint( (LPSTR) ((MYREC *)(pMyCDS->lpData))->s1,
                        (LPSTR) ((MYREC *)(pMyCDS->lpData))->s2,
                        (DWORD) ((MYREC *)(pMyCDS->lpData))->n );
         }
         break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

void WINAPI MyPrint | ( | LPSTR | ,
 |  | LPSTR | ,
 |  | DWORD |
 | ) |  |

Definition at line 147 of file DLL16.C.

{
   DWORD Args[3];
   LPVOID TransList[3];

   /*
      The arguments are packed into the Args array to be passed through
      the thunk. The TransList contains any pointers which must be
      translated. We wish to pass dwValue by value, so it is not placed
      in the translation list. The last entry in the translation list
      must be NULL.
   */

   if( fWin32s )
   {
      Args[0] = (DWORD) lpString1;
      Args[1] = (DWORD) lpString2;
      Args[2] = dwValue;

      TransList[0] = &Args[0];
      TransList[1] = &Args[1];
      TransList[2] = NULL;

      (*gpUTCBack)( Args, MYPRINT, TransList );
   }

   /*
      CallProc32W() takes a variable number of parameters. The last
      parameter here indicates that the first three arguments are to
      be passed through the thunk. The next parameter specifies Proc
      as the address of the function to be called. The second to the
      last parameter is a mask that indicates which parameters are
      addresses which should be translated. Note that the mask is
      specified in the opposite order that the parameters are listed,
      so 6 = 0110, indicating that lpString1 and lpString2 should be
      translated.
   */

   else
   {
      Proc = (MYPROC) GetProcAddress32W( ghLib, "MyPrint" );
      CallProc32W( (DWORD) lpString1, (DWORD) lpString2,
         (DWORD) dwValue, Proc, 6, 3 );
   }
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpszCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 44 of file DISP32.C.

{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;

   if( !hPrevInstance ) {
      wc.lpszClassName = "Disp32Class";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      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.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   hWnd = CreateWindow( "Disp32Class",
                        "Hidden Window",
                        WS_OVERLAPPEDWINDOW,
                        0,
                        0,
                        GetSystemMetrics(SM_CXMIN),
                        GetSystemMetrics(SM_CYMIN),
                        NULL,
                        NULL,
                        hInstance,
                        NULL
          );

   ShowWindow( hWnd, SW_HIDE );

   while( GetMessage( &msg, NULL, 0, 0 ) ) {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }

   return msg.wParam;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DLL16.C File Reference

  • INTEROP
Data Structures | Defines | Typedefs | Functions | Variables

DLL16.C File Reference

#include <windows.h>
#include "w32sut.h"
#include "myut.h"

Go to the source code of this file.

Data Structures

struct | tagWIN32SINFO

Defines

#define | W32SUT_16

Typedefs

typedef struct tagWIN32SINFO * | LPWIN32SINFO
typedef struct tagWIN32SINFO | WIN32SINFO

Functions

BOOL FAR PASCAL | IsWin32sLoaded (void)
int FAR PASCAL | LibMain (HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine)
void WINAPI | MyPrint (LPSTR lpString1, LPSTR lpString2, DWORD dwValue)
DWORD FAR PASCAL | UTInit (UT16CBPROC pfnUT16CallBack, LPVOID lpBuff)
DWORD FAR PASCAL | UTProc (LPVOID lpBuff, DWORD dwFunc)
typedef | void (FAR PASCAL *MYPROC)(LPSTR
int FAR PASCAL | WEP (int nParam)

Variables

typedef | DWORD
BOOL | fWin32s = FALSE
HINSTANCE | ghInst
DWORD ghLib
HWND | ghWnd = NULL
UT16CBPROC | gpUTCBack = NULL
typedef | LPSTR
MYPROC | Proc

Define Documentation

#define W32SUT_16

Definition at line 17 of file DLL16.C.

Typedef Documentation

typedef struct tagWIN32SINFO* LPWIN32SINFO
typedef struct tagWIN32SINFO WIN32SINFO

Function Documentation

BOOL FAR PASCAL IsWin32sLoaded ( void )

Definition at line 204 of file DLL16.C.

{
   BOOL       fWin32sLoaded = FALSE;
   HANDLE     hWin32sys;
   FARPROC    pfnInfo;
   WIN32SINFO Info;

   hWin32sys = LoadLibrary( "w32sys.dll" );

   if( hWin32sys > HINSTANCE_ERROR )
   {
      pfnInfo = GetProcAddress( hWin32sys, "GETWIN32SINFO" );
      if( pfnInfo )
      {
         if(!(*pfnInfo)((LPWIN32SINFO) &Info))
            fWin32sLoaded = TRUE;
         else fWin32sLoaded = FALSE;
      }
      else fWin32sLoaded = TRUE;
      FreeLibrary( hWin32sys );
   }

   return fWin32sLoaded;
}

int FAR PASCAL LibMain | ( | HINSTANCE | hInst,
 |  | WORD | wDataSeg,
 |  | WORD | cbHeapSize,
 |  | LPSTR | lpszCmdLine
 | ) |  |

Definition at line 60 of file DLL16.C.

{
   DWORD dwVersion;

   ghInst = hInst;

   WinExec( "disp32.exe", SW_SHOW );

   /* Check to see what version we're running on */
   dwVersion = GetVersion();
   if(( GetWinFlags() & WF_WINNT ) || ( HIBYTE(LOWORD(dwVersion)) == 95 ))
   {
      /* This is either Windows NT or Windows 95 */
      OutputDebugString( "This is either Windows NT or Windows 95\r\n" );
      ghLib = LoadLibraryEx32W( "dll32.dll", NULL, 0 );
   }
   else
   {
      fWin32s = IsWin32sLoaded( );
      if( fWin32s )
         WinExec( "stub32.exe", SW_SHOW );
      else
         return FALSE;
   }
   return TRUE;
}

void WINAPI MyPrint | ( | LPSTR | lpString1,
 |  | LPSTR | lpString2,
 |  | DWORD | dwValue
 | ) |  |

Definition at line 147 of file DLL16.C.

{
   DWORD Args[3];
   LPVOID TransList[3];

   /*
      The arguments are packed into the Args array to be passed through
      the thunk. The TransList contains any pointers which must be
      translated. We wish to pass dwValue by value, so it is not placed
      in the translation list. The last entry in the translation list
      must be NULL.
   */

   if( fWin32s )
   {
      Args[0] = (DWORD) lpString1;
      Args[1] = (DWORD) lpString2;
      Args[2] = dwValue;

      TransList[0] = &Args[0];
      TransList[1] = &Args[1];
      TransList[2] = NULL;

      (*gpUTCBack)( Args, MYPRINT, TransList );
   }

   /*
      CallProc32W() takes a variable number of parameters. The last
      parameter here indicates that the first three arguments are to
      be passed through the thunk. The next parameter specifies Proc
      as the address of the function to be called. The second to the
      last parameter is a mask that indicates which parameters are
      addresses which should be translated. Note that the mask is
      specified in the opposite order that the parameters are listed,
      so 6 = 0110, indicating that lpString1 and lpString2 should be
      translated.
   */

   else
   {
      Proc = (MYPROC) GetProcAddress32W( ghLib, "MyPrint" );
      CallProc32W( (DWORD) lpString1, (DWORD) lpString2,
         (DWORD) dwValue, Proc, 6, 3 );
   }
}

DWORD FAR PASCAL UTInit | ( | UT16CBPROC | pfnUT16CallBack,
 |  | LPVOID | lpBuff
 | ) |  |

Definition at line 103 of file DLL16.C.

{
   gpUTCBack = pfnUT16CallBack;

   ghWnd = (HWND) (*gpUTCBack)( NULL, GETHWND, NULL );

   FreeLibrary( ghInst );

   return TRUE;
}

DWORD FAR PASCAL UTProc | ( | LPVOID | lpBuff,
 |  | DWORD | dwFunc
 | ) |  |

Definition at line 124 of file DLL16.C.

{
   return FALSE;
}

typedef void ( FAR PASCAL * MYPROC )
int FAR PASCAL WEP ( int nParam )

Definition at line 242 of file DLL16.C.

{
   SendMessage( FindWindow("Disp32Class", "Hidden Window"),
                WM_CLOSE, 0, 0 );

   if( fWin32s )
   {
      PostMessage( ghWnd, WM_CLOSE, 0, 0 );
   }
   else
   {
      FreeLibrary32W( ghLib );
   }
   return TRUE;
}

Variable Documentation

typedef DWORD

Definition at line 25 of file DLL16.C.

BOOL fWin32s = FALSE

Definition at line 37 of file DLL16.C.

HINSTANCE ghInst

Definition at line 44 of file DLL16.C.

DWORD ghLib

Definition at line 41 of file DLL16.C.

HWND ghWnd = NULL

Definition at line 43 of file DLL16.C.

UT16CBPROC gpUTCBack = NULL

Definition at line 38 of file DLL16.C.

typedef LPSTR

Definition at line 25 of file DLL16.C.

MYPROC Proc

Definition at line 40 of file DLL16.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DLL32.C File Reference

  • INTEROP
Functions

DLL32.C File Reference

#include <windows.h>
#include <stdio.h>

Go to the source code of this file.

Functions

BOOL WINAPI | DllMain (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
void WINAPI | MyPrint (LPSTR lpString1, LPSTR lpString2, DWORD dwValue)

Function Documentation

BOOL WINAPI DllMain | ( | HANDLE | hDLL,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 28 of file DLL32.C.

{
   switch (dwReason)
   {
      case DLL_PROCESS_ATTACH:
         break;

      case DLL_THREAD_ATTACH:
         break;

      case DLL_THREAD_DETACH:
         break;

      case DLL_PROCESS_DETACH:
         break;
   }

   return TRUE;
}

void WINAPI MyPrint | ( | LPSTR | lpString1,
 |  | LPSTR | lpString2,
 |  | DWORD | dwValue
 | ) |  |

Definition at line 60 of file DLL32.C.

{
   char buf[200];

   wsprintf( buf, "Data received:\n\n%s\n%s\n%d\n", lpString1, lpString2,
                 dwValue );
   MessageBox( NULL, buf, "Dll32", MB_OK|MB_SETFOREGROUND );
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/MYUT.H File Reference

  • INTEROP
Defines | Functions

MYUT.H File Reference

Go to the source code of this file.

Defines

#define | GETHWND 2
#define | MYPRINT 1
#define | WF_WINNT 0x4000

Functions

DWORD FAR PASCAL | CallProc32W (DWORD, DWORD, DWORD, LPVOID, DWORD, DWORD)
BOOL FAR PASCAL | FreeLibrary32W (DWORD)
DWORD FAR PASCAL | GetProcAddress32W (DWORD, LPCSTR)
DWORD FAR PASCAL | LoadLibraryEx32W (LPCSTR, DWORD, DWORD)

Define Documentation

#define GETHWND 2

Definition at line 3 of file MYUT.H.

#define MYPRINT 1

Definition at line 2 of file MYUT.H.

#define WF_WINNT 0x4000

Definition at line 5 of file MYUT.H.

Function Documentation

DWORD FAR PASCAL CallProc32W | ( | DWORD | ,
 |  | DWORD | ,
 |  | DWORD | ,
 |  | LPVOID | ,
 |  | DWORD | ,
 |  | DWORD |
 | ) |  |
BOOL FAR PASCAL FreeLibrary32W ( DWORD )
DWORD FAR PASCAL GetProcAddress32W | ( | DWORD | ,
 |  | LPCSTR |
 | ) |  |
DWORD FAR PASCAL LoadLibraryEx32W | ( | LPCSTR | ,
 |  | DWORD | ,
 |  | DWORD |
 | ) |  |
Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/STUB32.C File Reference

  • INTEROP
Functions | Variables

STUB32.C File Reference

#include <windows.h>
#include "myut.h"

Go to the source code of this file.

Functions

void WINAPI | InitThunk (HWND)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)

Variables

BOOL | fWin32s
HINSTANCE | ghDLL

Function Documentation

void WINAPI InitThunk ( HWND )

Definition at line 103 of file UTDLL32.C.

{
   ghWnd = hWnd;

   if( !(*pUTRegister)( ghDLL,
      "dll16.dll",
      "UTInit",
      "UTProc",
      &pfnUTProc,
      UTCBProc,
      NULL )
     )
   MessageBox( NULL, "UTRegister() failed", "UTDLL32", MB_OK );
}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | msg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 103 of file STUB32.C.

{
   switch( msg ) {

/**************************************************************\
*     WM_CREATE: Let the 32-bit UT DLL initialize the thunk    *
\**************************************************************/

      case WM_CREATE:
         InitThunk( hWnd );
   break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
   PostQuitMessage( 0 );
   break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
   return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpszCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 41 of file STUB32.C.

{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;

   if( !hPrevInstance ) {
      wc.lpszClassName = "Stub32Class";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      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.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   hWnd = CreateWindow( "Stub32Class",
      "Hidden Window",
      WS_OVERLAPPEDWINDOW,
      0,
      0,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      NULL,
      NULL,
      hInstance,
      NULL
          );

   ShowWindow( hWnd, SW_HIDE );

   while( GetMessage( &msg, NULL, 0, 0 ) ) {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }

   return msg.wParam;
}

Variable Documentation

BOOL fWin32s

Definition at line 20 of file STUB32.C.

HINSTANCE ghDLL

Definition at line 21 of file STUB32.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/UTDLL32.C File Reference

  • INTEROP
Defines | Typedefs | Functions | Variables

UTDLL32.C File Reference

#include <windows.h>
#include "w32sut.h"
#include "myut.h"

Go to the source code of this file.

Defines

#define | W32SUT_32

Typedefs

typedef UT32PROC | FARPROC
typedef UT32PROC | LPVOID

Functions

typedef | BOOL (WINAPI *PUTREGISTER)(HANDLE
BOOL WINAPI | DllMain (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved)
void WINAPI | InitThunk (HWND hWnd)
void WINAPI | MyPrint (LPSTR, LPSTR, DWORD)
DWORD WINAPI | UTCBProc (LPVOID, DWORD)
typedef | VOID (WINAPI *PUTUNREGISTER)(HANDLE)

Variables

HANDLE | ghDLL
HWND | ghWnd
HANDLE | hKernel32 = 0
typedef | LPCSTR
UT32PROC | pfnUTProc = NULL
PUTREGISTER | pUTRegister = NULL
PUTUNREGISTER | pUTUnRegister = NULL

Define Documentation

#define W32SUT_32

Definition at line 15 of file UTDLL32.C.

Typedef Documentation

typedef UT32PROC FARPROC

Definition at line 24 of file UTDLL32.C.

typedef UT32PROC LPVOID

Definition at line 24 of file UTDLL32.C.

Function Documentation

typedef BOOL ( WINAPI * PUTREGISTER )
BOOL WINAPI DllMain | ( | HANDLE | hDLL,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 58 of file UTDLL32.C.

{
   static int cAttached = 0;

   switch (dwReason)
   {
      case DLL_PROCESS_ATTACH:
   if( !cAttached ) {
      hKernel32 = LoadLibrary( "Kernel32.Dll" );
      pUTRegister = (PUTREGISTER) GetProcAddress(hKernel32, "UTRegister");
      pUTUnRegister = (PUTUNREGISTER) GetProcAddress(hKernel32, "UTUnRegister");
      ghDLL = hDLL;
   }
         cAttached++;
         break;

      case DLL_THREAD_ATTACH:
         break;

      case DLL_THREAD_DETACH:
         break;

      case DLL_PROCESS_DETACH:
         --cAttached;
         if( !cAttached ) {
      (*pUTUnRegister)( hDLL );
         }
         break;
   }

   return TRUE;
}

void WINAPI InitThunk ( HWND hWnd )

Definition at line 103 of file UTDLL32.C.

{
   ghWnd = hWnd;

   if( !(*pUTRegister)( ghDLL,
      "dll16.dll",
      "UTInit",
      "UTProc",
      &pfnUTProc,
      UTCBProc,
      NULL )
     )
   MessageBox( NULL, "UTRegister() failed", "UTDLL32", MB_OK );
}

void WINAPI MyPrint | ( | LPSTR | ,
 |  | LPSTR | ,
 |  | DWORD |
 | ) |  |

Definition at line 147 of file DLL16.C.

{
   DWORD Args[3];
   LPVOID TransList[3];

   /*
      The arguments are packed into the Args array to be passed through
      the thunk. The TransList contains any pointers which must be
      translated. We wish to pass dwValue by value, so it is not placed
      in the translation list. The last entry in the translation list
      must be NULL.
   */

   if( fWin32s )
   {
      Args[0] = (DWORD) lpString1;
      Args[1] = (DWORD) lpString2;
      Args[2] = dwValue;

      TransList[0] = &Args[0];
      TransList[1] = &Args[1];
      TransList[2] = NULL;

      (*gpUTCBack)( Args, MYPRINT, TransList );
   }

   /*
      CallProc32W() takes a variable number of parameters. The last
      parameter here indicates that the first three arguments are to
      be passed through the thunk. The next parameter specifies Proc
      as the address of the function to be called. The second to the
      last parameter is a mask that indicates which parameters are
      addresses which should be translated. Note that the mask is
      specified in the opposite order that the parameters are listed,
      so 6 = 0110, indicating that lpString1 and lpString2 should be
      translated.
   */

   else
   {
      Proc = (MYPROC) GetProcAddress32W( ghLib, "MyPrint" );
      CallProc32W( (DWORD) lpString1, (DWORD) lpString2,
         (DWORD) dwValue, Proc, 6, 3 );
   }
}

DWORD WINAPI UTCBProc | ( | LPVOID | lpBuf,
 |  | DWORD | dwFunc
 | ) |  |

Definition at line 132 of file UTDLL32.C.

{
   switch( dwFunc )
   {
      case MYPRINT:
         MyPrint( (LPSTR) ((LPDWORD)lpBuf)[0], (LPSTR) ((LPDWORD)lpBuf)[1],
            ((LPDWORD)lpBuf)[2] );
         break;

   /*
      Return window handle so that app16.exe can force stub32.exe
      to terminate via SendMessage( ... WM_CLOSE ... )
   */

      case GETHWND:
         return (DWORD) ghWnd;
         break;

      default:
         MessageBox( NULL, "Unsupported routine called", "utdll32", MB_OK );
   }
   return TRUE;
}

typedef VOID ( WINAPI * PUTUNREGISTER )

Variable Documentation

HANDLE ghDLL

Definition at line 36 of file UTDLL32.C.

HWND ghWnd

Definition at line 35 of file UTDLL32.C.

HANDLE hKernel32 = 0

Definition at line 36 of file UTDLL32.C.

typedef LPCSTR

Definition at line 24 of file UTDLL32.C.

UT32PROC pfnUTProc = NULL

Definition at line 37 of file UTDLL32.C.

PUTREGISTER pUTRegister = NULL

Definition at line 38 of file UTDLL32.C.

PUTUNREGISTER pUTUnRegister = NULL

Definition at line 39 of file UTDLL32.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/W32SUT.H File Reference

  • INTEROP

W32SUT.H File Reference

Go to the source code of this file.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: IOCOMP/IOCOMP.C File Reference

  • IOCOMP
Defines | Functions | Variables

IOCOMP.C File Reference

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

Go to the source code of this file.

Defines

#define | BUFFER_SIZE (64*1024)
#define | NUMBER_OF_WRITES (320*1)
#define | TEST_REPEAT_COUNT 10

Functions

int _CRTAPI1 | main (int argc, char *argv[], char *envp)
VOID | ParseSwitch (CHAR chSwitch, int *pArgc, char **pArgv[])
VOID | ShowUsage (VOID)

Variables

char * | Buffer
int | BufferSize
BOOL | fBufferdIo
LPSTR FileName
BOOL | fSequentialNew
int | NumberOfWrites

Define Documentation

#define BUFFER_SIZE (64*1024)

Definition at line 28 of file IOCOMP.C.

#define NUMBER_OF_WRITES (320*1)

Definition at line 29 of file IOCOMP.C.

#define TEST_REPEAT_COUNT 10

Definition at line 22 of file IOCOMP.C.

Function Documentation

int _CRTAPI1 main | ( | int | argc,
 |  | char * | argv[],
 |  | char * | envp
 | ) |  |

Definition at line 55 of file IOCOMP.C.

{
    DWORD Start[TEST_REPEAT_COUNT];
    DWORD End[TEST_REPEAT_COUNT];
    DWORD Diff;
    double fDiff, fSec, fKb, fSumKbs;
    int TestNumber;
    HANDLE hFile, hPort;
    OVERLAPPED ov;
    LPOVERLAPPED ov2;
    int WriteCount;
    DWORD n,n2,key;
    BOOL b;
    int PendingIoCount;
    DWORD Version;
    DWORD FileFlags;
    char chChar, *pchChar;

    Version = GetVersion() >> 16;

    FileName = "unbufw.dat";
    fSequentialNew = FALSE;
    fBufferdIo = FALSE;

    BufferSize = BUFFER_SIZE;
    NumberOfWrites = ( (20*(1024*1024)) / BufferSize);

    while (--argc) {
  pchChar = *++argv;
  if (*pchChar == '/' || *pchChar == '-') {
      while (chChar = *++pchChar) {
    ParseSwitch( chChar, &argc, &argv );
    }
      }
  }

    if ( argc > 1 ) {
  FileName = argv[1];
  }
    else {
  }

    fSumKbs = 0.0;

    Buffer = VirtualAlloc(NULL,BUFFER_SIZE,MEM_COMMIT,PAGE_READONLY);
    if ( !Buffer ) {
  printf("Error allocating buffer %d\n",GetLastError());
  return 99;
  }

    FileFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED;

    if ( !fBufferdIo ) {
  FileFlags |= FILE_FLAG_NO_BUFFERING;
  }

    DeleteFile(FileName);

    for (TestNumber = 0; TestNumber < TEST_REPEAT_COUNT; TestNumber++ ) {

  hFile = CreateFile(
        FileName,
        GENERIC_READ | GENERIC_WRITE,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        NULL,
        OPEN_ALWAYS,
        FileFlags,
        NULL
        );
  if ( hFile == INVALID_HANDLE_VALUE ) {
      printf("Error opening file %s %d\n",FileName,GetLastError());
      return 99;
      }

  hPort = CreateIoCompletionPort(
        hFile,
        NULL,
        (DWORD)hFile,
        0
        );
  if ( !hPort ) {
      printf("Error creating completion port %d\n",FileName,GetLastError());
      return 99;
      }

  ZeroMemory(&ov,sizeof(ov));

  if ( TestNumber == 0 && fSequentialNew == FALSE) {

      Start[TestNumber] = GetTickCount();

      //
      // Make sure the file is written out to the end...
      //
      ov.Offset = (NUMBER_OF_WRITES * BUFFER_SIZE) - 1024;

      b = WriteFile(hFile,Buffer,1024,&n,&ov);
      if ( !b && GetLastError() != ERROR_IO_PENDING ) {
    printf("Error in pre-write %d\n",GetLastError());
    return 99;
    }
      b = GetQueuedCompletionStatus(
        hPort,
        &n2,
        &key,
        &ov2,
        (DWORD)-1
        );
      if ( !b ) {
    printf("Error picking up completion pre-write %d\n",GetLastError());
    return 99;
    }

      End[TestNumber] = GetTickCount();

      Diff = End[TestNumber] - Start[TestNumber];

      fDiff = Diff;
      fSec = fDiff/1000.0;
      fKb = ( (NumberOfWrites * BufferSize) / 1024 );

      printf("First Write %2dMb Written in %3.3fs I/O Rate %4.3f Kb/S\n\n",
    (NumberOfWrites * BufferSize) / ( 1024 * 1024),
    fSec,
    fKb / fSec
    );
      }

  ov.Offset = 0;

  PendingIoCount = 0;

  Start[TestNumber] = GetTickCount();

  //
  // Issue the writes
  //

  for (WriteCount = 0; WriteCount < NumberOfWrites; WriteCount++){
reissuewrite:
      b = WriteFile(hFile,Buffer,BufferSize,&n,&ov);
      if ( !b && GetLastError() != ERROR_IO_PENDING ) {

    //
    // we reached our limit on outstanding I/Os
    //

    if ( GetLastError() == ERROR_INVALID_USER_BUFFER ||
         GetLastError() == ERROR_NOT_ENOUGH_QUOTA ||
         GetLastError() == ERROR_NOT_ENOUGH_MEMORY ) {

        //
        // wait for an outstanding I/O to complete and then go again
        //
        b = GetQueuedCompletionStatus(
          hPort,
          &n2,
          &key,
          &ov2,
          (DWORD)-1
          );
        if ( !b ) {
      printf("Error picking up completion write %d\n",GetLastError());
      return 99;
      }

        PendingIoCount--;
        goto reissuewrite;
        }
    else {
        printf("Error in write %d\n",GetLastError());
        return 99;
        }
    }
      PendingIoCount++;
      ov.Offset += BufferSize;
      }

  //
  // Pick up the I/O completion
  //

  for (WriteCount = 0; WriteCount < PendingIoCount; WriteCount++){
      b = GetQueuedCompletionStatus(
        hPort,
        &n2,
        &key,
        &ov2,
        (DWORD)-1
        );
      if ( !b ) {
    printf("Error picking up completion write %d\n",GetLastError());
    return 99;
    }
      }

  End[TestNumber] = GetTickCount();

  CloseHandle(hFile);

  if ( Version > 613 ) {
      CloseHandle(hPort);
      }

  //
  // Dump the results
  //

  Diff = End[TestNumber] - Start[TestNumber];

  fDiff = Diff;
  fSec = fDiff/1000.0;
  fKb = ( (NumberOfWrites * BufferSize) / 1024 );

  printf("Test %2d %2dMb Written in %3.3fs I/O Rate %4.3f Kb/S\n",
      TestNumber,
      (NumberOfWrites * BufferSize) / ( 1024 * 1024),
      fSec,
      fKb / fSec
      );

  fSumKbs += (fKb / fSec);

  if ( fSequentialNew ) {
      DeleteFile(FileName);
      }

  }

    DeleteFile(FileName);

    //
    // Average
    //

    printf("\n Average Throughput %4.3f\n\n",
      fSumKbs/TEST_REPEAT_COUNT
      );
}

VOID ParseSwitch | ( | CHAR | chSwitch,
 |  | int * | pArgc,
 |  | char ** | pArgv[]
 | ) |  |

Definition at line 305 of file IOCOMP.C.

{
    int bs;
    switch (toupper( chSwitch )) {

  case '?':
      ShowUsage();
      break;

  case 'F':
      if (!--(*pArgc)) {
    ShowUsage();
    }
      (*pArgv)++;
      FileName =  *(*pArgv);
      break;

  case 'K':
      if (!--(*pArgc)) {
    ShowUsage();
    }
      (*pArgv)++;
      bs = strtoul( *(*pArgv), NULL, 10 );
      bs *= 1024;
      if ( bs > BUFFER_SIZE ) {
    ShowUsage();
    }

      BufferSize = bs;
      NumberOfWrites = ( (20*(1024*1024)) / BufferSize);

      break;

  case 'S':
      fSequentialNew = TRUE;
      break;

  case 'B':
      fBufferdIo = TRUE;
      break;

  default:
      fprintf( stderr, "UNBUFW: Invalid switch - /%c\n", chSwitch );
      ShowUsage();
      break;

  }
}

VOID ShowUsage ( VOID )

Definition at line 362 of file IOCOMP.C.

{
    fputs( "usage: IOCOMP [switches]\n"
     "              [-f filename] supplies the output filename\n"
     "              [-s] write sequentially without pre-allocating the file\n"
     "              [-b] use buffered I/O instead of unbuffered I/O\n"
     "              [-k write-size] use write-size k as write-size (64 is max)\n",
     stderr );

    exit( 1 );
}

Variable Documentation

char* Buffer

Definition at line 34 of file IOCOMP.C.

int BufferSize

Definition at line 31 of file IOCOMP.C.

BOOL fBufferdIo

Definition at line 37 of file IOCOMP.C.

LPSTR FileName

Definition at line 38 of file IOCOMP.C.

BOOL fSequentialNew

Definition at line 36 of file IOCOMP.C.

int NumberOfWrites

Definition at line 32 of file IOCOMP.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOCALE/LOCALE.C File Reference

  • LOCALE
Defines | Functions

LOCALE.C File Reference

#include <windows.h>
#include "locale.h"

Go to the source code of this file.

Defines

#define | UNICODE

Functions

LRESULT CALLBACK | MainDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Define Documentation

#define UNICODE

Definition at line 24 of file LOCALE.C.

Function Documentation

LRESULT CALLBACK MainDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 71 of file LOCALE.C.

{
  int i;
  TCHAR buffer[MAXTCHAR];

  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    /********************************************************************\
    * WM_INITDIALOG
    *
    * Fill the combobox with the language, sublanguage pairs.
    *
    \********************************************************************/
    case WM_INITDIALOG:

      /* fill up the combobox with the possible input values to
       *  GetLocaleInfoW().  The strings are in a lookup table
       *  in the file locale.h
       */
      for (i = 0; i < NLANG; i++) {

        SendDlgItemMessage (hwnd, DID_COMBOBOX, CB_ADDSTRING, 0,
            (LPARAM)langstrings[i].String);
      }

      /* Attempt to create a unicode font for the listbox with the
       *  same size as the default system font.  This will work well
       *  if the uclucida.ttf font was installed with the control panel.
       *  If not, then some of the characters in the strings returned
       *  by GetLocaleInfoW() will be displayed as the 'missing' font glyph.
       */
      { HFONT   hfont;
        LOGFONT  logfont;

        GetObject (GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &logfont);
        logfont.lfCharSet = UNICODE_CHARSET;
        wsprintf (logfont.lfFaceName, TEXT("Lucida Sans Unicode"));
        hfont = CreateFontIndirect (&logfont);
        SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT, (WPARAM) hfont, 0);
      }
    return 0;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    /********************************************************************\
    * WM_COMMAND
    *
    * When the different languages are selected, clear the list box,
    *  then fill it up again with the new information.
    *
    \********************************************************************/
    case WM_COMMAND:
      if ((HIWORD(wParam) == CBN_SELCHANGE) && (LOWORD(wParam) == DID_COMBOBOX)) {
        int iSel;
        TCHAR linfo[MAXTCHAR];

        iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
        SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0, 0);

        for (i = 0; i < NLOCALEENTRIES; i++) {
          linfo[0] = 0;
          GetLocaleInfoW (MAKELCID( langstrings[iSel].Value, 0 ),
                  localeentry[i].Value, linfo, MAXTCHAR);

          wsprintf (buffer, TEXT("%s \t %s"), localeentry[i].String, linfo);

          SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)buffer);
        }

      }
    break; /* end WM_COMMAND */

    default: return FALSE;
  } /* end switch(message) */
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 38 of file LOCALE.C.

{
int ret;

    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nCmdShow);

// check if running on Windows NT, if not, display notice and terminate
    if( GetVersion() & 0x80000000 )
    {
       MessageBoxA( NULL,
           "This sample application can only be run on Windows NT.\n"
           "This application will now terminate.",
           "Locale",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

    ret = DialogBox (hInstance, TEXT("localeDlg"), NULL, (DLGPROC)MainDlgProc);
    return ret;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOCALE/LOCALE.H File Reference

  • LOCALE
Data Structures | Defines | Typedefs | Functions | Variables

LOCALE.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | DID_COMBOBOX 101
#define | DID_LISTBOX 100
#define | DID_TEXT 102
#define | MAXTCHAR 100
#define | NLANG 39
#define | NLOCALEENTRIES 89
#define | UNICODE_CHARSET 1

Typedefs

typedef struct tagLookupEntry | LookupEntry

Functions

LRESULT CALLBACK | MainDlgProc (HWND, UINT, WPARAM, LPARAM)

Variables

LookupEntry | langstrings [NLANG]
LookupEntry | localeentry [NLOCALEENTRIES]

Define Documentation

#define DID_COMBOBOX 101

Definition at line 24 of file LOCALE.H.

#define DID_LISTBOX 100

Definition at line 23 of file LOCALE.H.

#define DID_TEXT 102

Definition at line 25 of file LOCALE.H.

#define MAXTCHAR 100

Definition at line 19 of file LOCALE.H.

#define NLANG 39

Definition at line 46 of file LOCALE.H.

#define NLOCALEENTRIES 89

Definition at line 90 of file LOCALE.H.

#define UNICODE_CHARSET 1

Definition at line 34 of file LOCALE.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Function Documentation

LRESULT CALLBACK MainDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 57 of file GETSYS.C.

{
  UNREFERENCED_PARAMETER(lParam);

  switch (message) {

    /********************************************************************\
    * WM_INITDIALOG
    *
    * Set a monospaced font into the listbox so columns line up nicely.
    \********************************************************************/
    case WM_INITDIALOG:
      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT,
        (WPARAM) GetStockObject (SYSTEM_FIXED_FONT), (LPARAM) 0 );
    break;

    /********************************************************************\
    * WM_SYSCOMMAND
    *
    * ignore all syscommand messages, except for SC_CLOSE.
    *  on this one, call EndDialog().
    \********************************************************************/
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE) {
        EndDialog (hwnd, TRUE);
        return TRUE;
      } else
        return FALSE;
    break;

    /********************************************************************\
    * WM_COMMAND
    *
    * When the different buttons are hit, clear the list box, disable
    *  updating to it, call the function which will fill it, reenable
    *  updating, and then force a repaint.
    *
    \********************************************************************/
    case WM_COMMAND:

      /* if the list box sends back messages, return.  Otherwise we will
       *  clear it out, and that is not what we want to do at this point.
       */
      if (LOWORD(wParam)==DID_LISTBOX) return TRUE;

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW,    FALSE, 0);
      SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0,     0);

      /* switch on the control ID of the button that is pressed. */
      switch (LOWORD(wParam)) {
        case DID_SYSCOLORS : doSysColors (hwnd); break;
        case DID_DIRECTORY : doDirectory (hwnd); break;
        case DID_INFO      : doInfo      (hwnd); break;
        case DID_METRICS   : doMetrics   (hwnd); break;
        case DID_PALETTE   : doPalette   (hwnd); break;
        case DID_LOCALTIME : doLocalTime (hwnd); break;
        case DID_TIME      : doTime      (hwnd); break;
        case DID_VERSIONEX : doVersionEx (hwnd); break;
      } /* end switch (LOWORD()) */

      SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
      InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
      return TRUE;
    break; /* end WM_COMMAND */

    default: return FALSE;
  } /* end switch(message) */
}

Variable Documentation

LookupEntry langstrings[NLANG]

Definition at line 47 of file LOCALE.H.

LookupEntry localeentry[NLOCALEENTRIES]

Definition at line 91 of file LOCALE.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOGGING/LOG.C File Reference

  • LOGGING
Defines | Functions

LOG.C File Reference

#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include "messages.h"

Go to the source code of this file.

Defines

#define | LOGNAME "Application"
#define | LOGSOURCE "LogSample"
#define | MACHINE NULL
#define | MAX_MSG_LENGTH 1024
#define | MSG_ID_MASK 0x0000FFFF
#define | PARAM_SIZE (16)
#define | PERR(bSuccess, api) {if (!(bSuccess)) printf("\n%s: Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
#define | REG_ERR(lRegError, api) {if (lRegError!=ERROR_SUCCESS) printf("%s: \ Error %d from %s on line %d\n", __FILE__, lRegError, api, __LINE__);}
#define | REMOTE_MSG_DLL_PATH "\\\\ericsa2\\d$\\ntwork\\eventlog"
#define | SID_BUF_SIZE 1024

Functions

void | addSourceToRegistry (LPSTR pszLogName, LPSTR pszSrcName, LPSTR pszMsgDLL)
PTCHAR | insertMsgString (HKEY hk, PTCHAR szMsg, WORD wNumStrings, PTCHAR szInsStrings)
PTCHAR | lookupStringFromMsgDll (HKEY hk, DWORD dwEventID, WORD wNumStrings, PTCHAR szStrings, PTCHAR szMsgDllPath)
int | main (int argc, char *argv[])
void | notifyChange (LPCTSTR logSource)
void | queryEventLog (HANDLE hEventLog, LPCTSTR pszLogName, LPCTSTR pszSourceName)
void | reportAnEvent (LPSTR pszSrcName, DWORD dwIdEvent, WORD wCategory, WORD cStrings, LPTSTR *pszStrings)
void | usage ()

Define Documentation

#define LOGNAME "Application"

Definition at line 695 of file LOG.C.

#define LOGSOURCE "LogSample"

Definition at line 696 of file LOG.C.

#define MACHINE NULL

Definition at line 43 of file LOG.C.

#define MAX_MSG_LENGTH 1024

Definition at line 39 of file LOG.C.

#define MSG_ID_MASK 0x0000FFFF

Definition at line 40 of file LOG.C.

#define PARAM_SIZE (16)

Definition at line 221 of file LOG.C.

#define PERR | ( | bSuccess,
 |  | api |
 | ) |  | {if (!(bSuccess)) printf("\n%s: Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

Definition at line 33 of file LOG.C.

#define REG_ERR | ( | lRegError,
 |  | api |
 | ) |  | {if (lRegError!=ERROR_SUCCESS) printf("%s: \ Error %d from %s on line %d\n", __FILE__, lRegError, api, __LINE__);}

Definition at line 36 of file LOG.C.

#define REMOTE_MSG_DLL_PATH "\\\\ericsa2\\d$\\ntwork\\eventlog"

Definition at line 47 of file LOG.C.

#define SID_BUF_SIZE 1024

Function Documentation

void addSourceToRegistry | ( | LPSTR | pszLogName,
 |  | LPSTR | pszSrcName,
 |  | LPSTR | pszMsgDLL
 | ) |  |

Definition at line 62 of file LOG.C.

{
  HKEY hk, hklm;          // registry key handle
  DWORD dwData;
  TCHAR szTemp[MAX_PATH];
  LONG lRegError;         // return value from registry APIs

  /* connect to remote registry (or local if MACHINE == NULL) */
  lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
  REG_ERR(lRegError, "RegConnectRegistry");
  /* When a process uses the RegisterEventSource or OpenEventLog function to
     get a handle of an event log, the event logging service searches for the
     specified source name in the registry. You can add a new source name to
     the registry by opening a new registry subkey under the EventLog key and
     adding registry values to the new subkey. */
  // Create a new key for our source
  sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
      pszLogName, pszSrcName);
  lRegError = RegCreateKey(hklm, szTemp, &hk);
  REG_ERR(lRegError, "RegCreateKey");
  RegCloseKey(hklm);
  // Add the Event-ID message-file name to the subkey.
  lRegError = RegSetValueEx(hk,  // subkey handle
      "EventMessageFile",        // value name
      0,                         // must be zero
      REG_EXPAND_SZ,             // value type
      (LPBYTE) pszMsgDLL,        // address of value data
      strlen(pszMsgDLL) + 1);    // length of value data
  REG_ERR(lRegError, "RegSetValueEx");

  /* Add the Category message-file name to the subkey. These category strings
     correspond to the fwCategory parameter passed into ReportEvent(). */
  lRegError = RegSetValueEx(hk,  // subkey handle
      "CategoryMessageFile",     // value name
      0,                         // must be zero
      REG_EXPAND_SZ,             // value type
      (LPBYTE) pszMsgDLL,        // address of value data
      strlen(pszMsgDLL) + 1);    // length of value data
  REG_ERR(lRegError, "RegSetValueEx");

  /* Add the replaceable parameter message-file name to the subkey. This is
     used to replace %%nnn values in messages with the appropriate string */
  lRegError = RegSetValueEx(hk,  // subkey handle
      "ParameterMessageFile",    // value name
      0,                         // must be zero
      REG_EXPAND_SZ,             // value type
      (LPBYTE) pszMsgDLL,        // address of value data
      strlen(pszMsgDLL) + 1);    // length of value data
  REG_ERR(lRegError, "RegSetValueEx");

  // Set the supported types flags and add it to the subkey.
  dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
    EVENTLOG_INFORMATION_TYPE;
  lRegError = RegSetValueEx(hk,  // subkey handle
      "TypesSupported",          // value name
      0,                         // must be zero
      REG_DWORD,                 // value type
      (LPBYTE) &dwData,          // address of value data
      sizeof(DWORD));            // length of value data
  REG_ERR(lRegError, "RegSetValueEx");

  // Set the number of categories supported
  dwData = 3;
  lRegError = RegSetValueEx(hk,  // subkey handle
      "CategoryCount",           // value name
      0,                         // must be zero
      REG_DWORD,                 // value type
      (LPBYTE) &dwData,          // address of value data
      sizeof(DWORD));            // length of value data
  REG_ERR(lRegError, "RegSetValueEx");
  RegCloseKey(hk);
  return;
} // addSourceToRegistry

PTCHAR insertMsgString | ( | HKEY | hk,
 |  | PTCHAR | szMsg,
 |  | WORD | wNumStrings,
 |  | PTCHAR | szInsStrings
 | ) |  |

Definition at line 223 of file LOG.C.

{
  BOOL bSuccess;
  DWORD dwType;    // for RegQueryValueEx
  LONG lRegError;  // return value from registry APIs
  // paths to ParameterMessageFile
  TCHAR szParamMsgPath[MAX_PATH], szTemp[MAX_PATH];
  DWORD dwcbData;
  HINSTANCE hLib;   // handle to DLL containing ParameterMessageFile
  DWORD dwID;       // message ID
  LPTSTR msgBuf;
  PTCHAR szTempMsg;  // the message with replaced "%" or "%%" insert strings
  PTCHAR p1 = szMsg, p2 = szMsg; // temp pointers to walk the string
  PTCHAR szInsStr;   // point to insert strings in the EVENTLOGRECORD struct
  DWORD cchDest;
  int i;

  szTempMsg = malloc(MAX_MSG_LENGTH);
  szTempMsg[0] = 0;
  while (p2)
  {
    p2 = strchr(p1, '%');
    if (!p2)  // "%" not found, just copy the rest of the string and quit
    {
      strcat(szTempMsg, p1);
      continue;
    }
    strncat(szTempMsg, p1, p2 - p1);  // copy up to "%"
    /* is this a special "%%" string? If so, replace with language-dependant
       insert string from the ParameterMessageFile from registry. If it's not
       a "%%" string, skip down to else clause to replace as normal insert
       strings from the EVENTLOGRECORD structure */
    if (p2[1] == '%') // yup, it's a "%%" parameter string
    {
      p2 += 2;          // point to number, past the "%%"
      dwID = atoi(p2);  // get the message ID following the "%%"
      if (!dwID)        // it's not a number, copy "%%" as-is
      {
        strcat(szTempMsg, "%%");
        p1 = p2;
        continue;
      }
      else
        p1 = p2 + strspn(p2, "0123456789"); // point past number

      /* now look up the string corresponding to the message ID and append
         it into our temp string */
      dwcbData = MAX_PATH;
      lRegError = RegQueryValueEx(hk,  // handle of key to query
          "ParameterMessageFile",      // value name
          NULL,                        // must be NULL
          &dwType,                     // address of type value
          szTemp,                      // path to replaceable parameter message file
          &dwcbData);                  // length of value data
      REG_ERR(lRegError, "RegQueryValueEx");

      /* Expand environment variable strings in the message DLL path name, in
         case any are there */
      cchDest = ExpandEnvironmentStrings(szTemp, szParamMsgPath, MAX_PATH);
      PERR(cchDest != 0, "ExpandEnvironmentStrings");
      PERR(cchDest < MAX_PATH, "ExpandEnvironmentStrings");

      hLib = LoadLibraryEx(szParamMsgPath, NULL, DONT_RESOLVE_DLL_REFERENCES);
      PERR(hLib != NULL, "LoadLibraryEx");
      bSuccess = FormatMessage(
          FORMAT_MESSAGE_FROM_HMODULE |     // get the message from the DLL
          FORMAT_MESSAGE_ALLOCATE_BUFFER |  // allocate the msg buffer
          FORMAT_MESSAGE_ARGUMENT_ARRAY |   // lpArgs is an array of pointers
          FORMAT_MESSAGE_IGNORE_INSERTS |   // don't do any formatting
          70,                     // line length for the mesages
          hLib,                   // the messagetable DLL handle
          dwID,                   // message ID
          LANG_USER_DEFAULT,      // language ID
          (LPTSTR) &msgBuf,       // address of pointer to buffer for message
          PARAM_SIZE,             // maximum size of the message buffer
          NULL);                  // array of insert strings for the message
      PERR(bSuccess, "FormatMessage");
      FreeLibrary(hLib);
      strcat(szTempMsg, msgBuf);
      LocalFree((HLOCAL) msgBuf);
    }
    else //a normal insert string, look up in EVENTLOGRECORD structure
    {
      p2++;            // point to number, past the "%"
      dwID = atoi(p2);  // get the message ID following the "%"
      if (!dwID)        // it's not a number, copy "%" as-is
      {
        strcat(szTempMsg, "%");
        p1 = p2;
        continue;
      }
      else
        p1 = p2 + strspn(p2, "0123456789"); // point past number
      szInsStr = szInsStrings;
      for (i = 1; i < (int) dwID; i++) // find string number dwID
      {
        if (i > wNumStrings) // handle bogus string number
        {
          puts("**Error! Insert string ID too large");
          continue;
        }
        szInsStr += (strlen(szInsStr) + 1); // point to next string
      }
      strcat(szTempMsg, szInsStr);
    } //else
  } //while
  return (szTempMsg);  // caller must free()!
} // insertMsgString

PTCHAR lookupStringFromMsgDll | ( | HKEY | hk,
 |  | DWORD | dwEventID,
 |  | WORD | wNumStrings,
 |  | PTCHAR | szStrings,
 |  | PTCHAR | szMsgDllPath
 | ) |  |

Definition at line 349 of file LOG.C.

{
  DWORD cchDest;
  PTCHAR pMsgDll;   // one of the message DLLs in the list
  PTCHAR pNextDll;  // pointer to next DLL in the list
  HINSTANCE hLib;  // handle to the messagetable DLL
  LPTSTR msgBuf;   // hold text of the error message that we build
  PTCHAR p;
  TCHAR szTempMsg[MAX_MSG_LENGTH];
  BOOL bSuccess;
  TCHAR szMsgDllPathEx[MAX_PATH];  // after environment string expansion

  /* Expand environment variable strings in the message DLL path name, in
     case any are there, such as %systemroot% */
  cchDest = ExpandEnvironmentStrings(szMsgDllPath, szMsgDllPathEx, MAX_PATH);
  PERR(cchDest != 0, "ExpandEnvironmentStrings");
  PERR(cchDest < MAX_PATH, "ExpandEnvironmentStrings");

  // The list is delimited by ';' chars, check each DLL for the message
  pMsgDll = szMsgDllPathEx;  // point to beginning of DLL list
  while (pMsgDll)
  {
    pNextDll = strchr(szMsgDllPathEx, ';');
    if (pNextDll)
    {
      *pNextDll = 0;  // replace ';' with 0 to null terminate the name
      pNextDll++;     // point to the next name in the list
    }

    // Now we've got a message DLL name, load the DLL.
    hLib = LoadLibraryEx(pMsgDll, NULL, DONT_RESOLVE_DLL_REFERENCES);
    PERR(hLib != NULL, "LoadLibraryEx");
    if (!hLib)
      continue;

    /* retrieve the message from the messagetable DLL. For the language
    identifier, use the values we defined in the LanguageNames statements in
    the .mc file. If no LanguageNames values were defined in the .mc file, as
    in this case, use the LANG_USER_DEFAULT macro defined in winnt.h */
    bSuccess = FormatMessage(
        FORMAT_MESSAGE_FROM_HMODULE |     // get the message from the DLL
        FORMAT_MESSAGE_ALLOCATE_BUFFER |  // allocate the msg buffer for us
        FORMAT_MESSAGE_ARGUMENT_ARRAY |   // lpArgs is an array of pointers
        FORMAT_MESSAGE_IGNORE_INSERTS |   // just get the message
        70,                 // line length for the mesages
        hLib,               // the messagetable DLL handle
        dwEventID,          // message ID
        LANG_USER_DEFAULT,  // language ID
        (LPTSTR) &msgBuf,   // address of pointer to buffer for message
        MAX_MSG_LENGTH,     // maximum size of the message buffer
        NULL);              // array of insert strings for the message
    // if the message was not found, try the next DLL in the list
    if (!bSuccess && GetLastError() == ERROR_MR_MID_NOT_FOUND && pNextDll)
    {
      FreeLibrary(hLib);
      pMsgDll = pNextDll;  // point to next DLL in list (or NULL if no more)
      continue;            /* if the msg doesn't exist, and we have more
                              DLL's to check, continue down the list */
    }
    PERR(bSuccess, "FormatMessage");

    // if everything is ok, continue on, otherwise proceed to next event
    if (bSuccess)
    {
      /* process insert strings. Call twice - insert strings may contain
         special "%%" language-dependant replaceable parameter strings */
      strcpy(szTempMsg, msgBuf);
      LocalFree((HLOCAL) msgBuf);
      p = insertMsgString(hk, szTempMsg, wNumStrings, szStrings);
      strcpy(szTempMsg, p);
      free(p);  // free buffer allocated by insertParamString()
      p = insertMsgString(hk, szTempMsg, wNumStrings, szStrings);
      strcpy(szTempMsg, p);
      //don't free p again, it will be returned to the caller to free.
    } // if
    else
      p = NULL;
    pMsgDll = pNextDll;  // point to next DLL in list (or NULL if no more)
    // free the message DLL since we don't know if we'll need it again
    FreeLibrary(hLib);
  } // while
  return(p);  // p will be freed by our caller
} // lookupStringFromMsgDll

int main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 698 of file LOG.C.

{
  TCHAR szMsgPath[MAX_PATH];
  PTCHAR aInsertStrs[16];  // array of pointers to insert strings
  TCHAR szTemp[MAX_PATH];
  BOOL bSuccess;
  HANDLE hEventLog;
  OSVERSIONINFO osv;

  // Check to make sure we are running on Windows NT
  osv.dwOSVersionInfoSize = sizeof(osv);
  bSuccess = GetVersionEx(&osv);
  if (osv.dwPlatformId != VER_PLATFORM_WIN32_NT)
  {
    MessageBox(NULL, "Sorry, this application requires Windows NT.\n"
        "This application will now terminate.",
        "Error", MB_OK);
    return (1);
  }

  if (argc == 1)  // no args, use default defines
  {
    /* set up a notification event thread that will print a message when the
       first message is added to LOGSOURCE. This will only work for local
       logging. */
    if (MACHINE == NULL)
      _beginthread(notifyChange, 0, LOGSOURCE);

    /* Set the Event-ID message-file name. For local logging, we assume that
       the message DLL is in the same directory as this application. For
       remote logging, this sample will access the message DLL over the net
       via a UNC name for simplicity. This will be very slow when reading a
       large number of events from the eventlog. */
    if (MACHINE == NULL)
      GetCurrentDirectory(sizeof(szMsgPath), szMsgPath);
    else
      strcpy(szMsgPath, REMOTE_MSG_DLL_PATH);
    strcat(szMsgPath, "\\messages.dll");
    addSourceToRegistry(LOGNAME, LOGSOURCE, szMsgPath);

    // clear the event log
    hEventLog = OpenEventLog(MACHINE,  // open on machine defined elsewhere
        LOGSOURCE);                 // event log source name
    PERR(hEventLog, "OpenEventLog");
    bSuccess = ClearEventLog(hEventLog, NULL);
    PERR(bSuccess, "ClearEventLog");
    // can't use the log handle now that it's been cleared, we must close it
    bSuccess = CloseEventLog(hEventLog);
    PERR(bSuccess, "CloseEventLog");

    // Set up our array of insert strings for our error message
    reportAnEvent(LOGSOURCE,  // source name
        MSG_BAD_COMMAND,      // the message to log
        CAT_1,                // category
        0,                    // number of insert strings
        aInsertStrs);         // the array of insert strings
    reportAnEvent(LOGSOURCE,  // source name
        MSG_BAD_PARM1,        // the message to log
        CAT_3,                // category
        0,                    // number of insert strings
        aInsertStrs);         // the array of insert strings
    reportAnEvent(LOGSOURCE,  // source name
        MSG_STRIKE_ANY_KEY,   // the message to log
        CAT_2,                // category
        0,                    // number of insert strings
        aInsertStrs);         // the array of insert strings
    aInsertStrs[0] = "2,567";
    aInsertStrs[1] = "10";
    reportAnEvent(LOGSOURCE,  // source name
        MSG_RETRYS,           // the message to log
        CAT_1,                // category
        2,                    // number of insert strings
        aInsertStrs);         // the array of insert strings
    strcpy(szTemp, "%%");
    itoa(SPROCKETS, szTemp + 2, 10);  // concatenate the value
    aInsertStrs[0] = "foo.dat";
    aInsertStrs[1] = szTemp;
    reportAnEvent(LOGSOURCE,    // source name
        MSG_FILE_BAD_CONTENTS,  // the message to log
        CAT_1,                  // category
        2,                      // number of insert strings
        aInsertStrs);           // the array of insert strings
    aInsertStrs[0] = "a:";
    reportAnEvent(LOGSOURCE,    // source name
        MSG_INSERT_DISK,        // the message to log
        CAT_1,                  // category
        1,                      // number of insert strings
        aInsertStrs);           // the array of insert strings
    queryEventLog(NULL, LOGNAME, LOGSOURCE);  // query the log
  }
  else
  {  // we've got parameters
    if (argc > 1 && !strcmpi(argv[1], "Application") ||
        !strcmpi(argv[1], "Security") || !strcmpi(argv[1], "System"))
    {
      if (argc > 2)  // got a backup log name
      {
        hEventLog = OpenBackupEventLog(NULL, argv[2]); // must be local
        if (hEventLog)
        {
          queryEventLog(hEventLog, argv[1], NULL);  // dump the backup log
          bSuccess = CloseEventLog(hEventLog);
          PERR(bSuccess, "CloseEventLog");
        }
        else
        {  // 2nd arg was bad
          printf("can't open backup eventlog %s\n", argv[2]);
          PERR(hEventLog, "OpenBackupEventLog");
          usage();
        }
      }
      else
      {  // only got logname, dump it
        HKEY hk, hklm;
        FILETIME ft;
        LONG lRegError;
        DWORD cchName = sizeof(szTemp);

        // get arbitrary subkey of param to be used to open event log
        sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s",
            argv[1]);
        lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
        REG_ERR(lRegError, "RegConnectRegistry");
        lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
        REG_ERR(lRegError, "RegOpenKeyEx");
        RegCloseKey(hklm);
        lRegError = RegEnumKeyEx(hk, 0, szTemp, &cchName, NULL,
            NULL, NULL, &ft);
        REG_ERR(lRegError, "RegEnumKeyEx");
        queryEventLog(NULL, argv[1], szTemp);  // query the log
      }
    }
    else  // first arg was bad
      usage();
  }  // else
  return (0);
}

void notifyChange ( LPCTSTR logSource )

Definition at line 669 of file LOG.C.

{
  BOOL bSuccess;
  HANDLE hEventLog, hEvent;
  DWORD dwWaitResult;

  hEvent = CreateEvent(NULL,    // address of security attributes
      FALSE,                    // no manual reset
      FALSE,                    // create as not signaled
      NULL);                    // event name
  hEventLog = OpenEventLog(MACHINE,  // open on machine defined elsewhere
      logSource);                 // event log source name
  PERR(hEventLog, "OpenEventLog");
  bSuccess = NotifyChangeEventLog(hEventLog,
      hEvent);
  PERR(bSuccess, "NotifyChangeEventLog");
  dwWaitResult = WaitForSingleObject(hEvent, INFINITE);
  if (dwWaitResult != WAIT_FAILED)
    printf("**Notification: %s has changed\n", logSource);
  else
    PERR(dwWaitResult == WAIT_FAILED, "EventLogNotifyProc");
  CloseHandle(hEvent);
  CloseHandle(hEventLog);
  return;
} // notifyChange

void queryEventLog | ( | HANDLE | hEventLog,
 |  | LPCTSTR | pszLogName,
 |  | LPCTSTR | pszSourceName
 | ) |  |

Definition at line 452 of file LOG.C.

{
  EVENTLOGRECORD *pevlr;
  BYTE bBuffer[1024 * 64];    // hold the event log record raw data
  DWORD dwRead, dwNeeded, dwThisRecord = 0;
  HANDLE hLog;                // handle to the log
  BOOL bSuccess;
  DWORD cRecords;             // number of event records in the log
  LONG lRegError;
  DWORD dwType;
  DWORD dwcbData;
  HKEY hklm, hk;
  TCHAR szTemp[MAX_PATH];
  TCHAR szPrimaryMsgFile[64];  // name of primary (default) message file
  PTCHAR p;

  if (!hEventLog)
  {
    hLog = OpenEventLog(NULL,  // use local machine
        pszSourceName);        // source name - assumed to be valid
    PERR(hLog, "OpenEventLog");
  }
  else
    hLog = hEventLog;

  // Get the number of records in the log.
  bSuccess = GetNumberOfEventLogRecords(hLog, &cRecords);
  PERR(bSuccess, "GetNumberOfEventLogRecords");
  printf("There are %d records in the %s log.\n", cRecords, pszLogName);

  /* If the eventlog key contains a PrimaryModule value, get the default
     messagefile from it. This is the default EventMessageFile if an
     EventMessageFile value doesn't exist for a given source. */
  sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s",
      pszLogName);
  lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
  REG_ERR(lRegError, "RegConnectRegistry");
  lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
  REG_ERR(lRegError, "RegOpenKeyEx");
  RegCloseKey(hklm);
  dwcbData = MAX_PATH;
  lRegError = RegQueryValueEx(hk,  // handle of key to query
      "PrimaryModule",             // value name
      NULL,                        // must be NULL
      &dwType,                     // address of type value
      szPrimaryMsgFile,            // path to primary (default) message DLL
      &dwcbData);                  // length of value data
  if (lRegError == ERROR_FILE_NOT_FOUND)  // the key doesn't exist
    szPrimaryMsgFile[0] = 0;       // so we can test for it later
  else
    REG_ERR(lRegError, "RegQueryValueEx");
  RegCloseKey(hk);
  /* if the key exists, get the default EventMessageFile from the specified
     subkey */
  if (lRegError == ERROR_SUCCESS)
  {
    strcat(szTemp, "\\");
    strcat(szTemp, szPrimaryMsgFile);
    lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
    REG_ERR(lRegError, "RegConnectRegistry");
    lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
    REG_ERR(lRegError, "RegOpenKeyEx");
    RegCloseKey(hklm);
    dwcbData = MAX_PATH;
    lRegError = RegQueryValueEx(hk,  // handle of key to query
        "EventMessageFile",          // value name
        NULL,                        // must be NULL
        &dwType,                     // address of type value
        szPrimaryMsgFile,            // path(s) to message DLL
        &dwcbData);                  // length of value data
    REG_ERR(lRegError, "RegQueryValueEx");
    RegCloseKey(hk);
  }

  pevlr = (EVENTLOGRECORD *) &bBuffer;
  /* Opening the log positions the file pointer for this handle at the
     beginning of the log. Read records sequentially until there are no more
     records. */
  while (bSuccess = ReadEventLog(hLog,  // event-log handle
          EVENTLOG_FORWARDS_READ |      // read forward
          EVENTLOG_SEQUENTIAL_READ,     // sequential read
          0,                            // ignored for sequential reads
          bBuffer,                      // address of buffer
          sizeof(bBuffer),              // size of buffer
          &dwRead,                      // count of bytes read
          &dwNeeded))                   // bytes in next record
  {
    while (dwRead > 0)
    {
      /* Print the event ID, type, source name, and category. The source name
         is just past the end of the formal structure. */
      printf("\n%03d  Event ID: 0x%08X  EventType: ", dwThisRecord++,
          pevlr->EventID);
      switch (pevlr->EventType)
      {
        case EVENTLOG_ERROR_TYPE:
          printf("EVENTLOG_ERROR_TYPE");
          break;
        case EVENTLOG_WARNING_TYPE:
          printf("EVENTLOG_WARNING_TYPE");
          break;
        case EVENTLOG_INFORMATION_TYPE:
          printf("EVENTLOG_INFORMATION_TYPE");
          break;
        case EVENTLOG_AUDIT_SUCCESS:
          printf("EVENTLOG_AUDIT_SUCCESS");
          break;
        case EVENTLOG_AUDIT_FAILURE:
          printf("EVENTLOG_AUDIT_FAILURE");
          break;
        default:
          printf("UNKNOWN");
          break;
      }

      printf("\nSource: %s", (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)));
      // mask off the actual message number and show it
      printf("  Message ID: %d", pevlr->EventID & MSG_ID_MASK);

      /* From the event log source name, we know the name of the registry key
         to look under for the list of the message DLLs that may contain the
         message we need to extract with FormatMessage. Get the event log
         source name list... */
      // The source name follows the EVENTLOGRECORD structure
      sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
          pszLogName, (PTCHAR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)));
      /* Now open this key and get the EventMessageFile value, which is the
         list of the message DLLs for that source */
      lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
      REG_ERR(lRegError, "RegConnectRegistry");
      lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
      REG_ERR(lRegError, "RegOpenKeyEx");
      RegCloseKey(hklm);
      // first, look up the path(s) to the category message DLL
      dwcbData = MAX_PATH;
      lRegError = RegQueryValueEx(hk,  // handle of key to query
          "CategoryMessageFile",       // value name
          NULL,                        // must be NULL
          &dwType,                     // address of type value
          szTemp,                      // path to category message DLL
          &dwcbData);                  // length of value data
        REG_ERR(lRegError, "RegQueryValueEx");

      // get the string from the category DLL
      p = lookupStringFromMsgDll(hk, pevlr->EventCategory, 0, NULL, szTemp);
      printf("  Category: %s", p);

      // print out the user's account name if the SID was logged in the record
      if (pevlr->UserSidLength)
      {
        UCHAR szAccountName[64], szDomainName[64];
        DWORD cbAccountSize, cbDomainSize;
        SID_NAME_USE snu;
        PSID psid;

        /* get the user name associated with the Security identifier (SID)
           in the event log record */
        psid = (PSID)((LPBYTE) pevlr + pevlr->UserSidOffset);
        cbAccountSize = sizeof(szAccountName);
        cbDomainSize = sizeof(szDomainName);
        bSuccess = LookupAccountSid(NULL, psid, szAccountName, &cbAccountSize,
            szDomainName, &cbDomainSize, &snu);
        PERR(bSuccess, "LookupAccountSid");
        printf("  User: %s", bSuccess ? szAccountName : "NA");
      }

      // now look up the path(s) to the message DLL to get the message text
      dwcbData = MAX_PATH;
      lRegError = RegQueryValueEx(hk,  // handle of key to query
          "EventMessageFile",          // value name
          NULL,                        // must be NULL
          &dwType,                     // address of type value
          szTemp,                      // path(s) to message DLL
          &dwcbData);                  // length of value data
      // if the message file isn't there, and a default exists, use default
      if (lRegError == ERROR_FILE_NOT_FOUND && szPrimaryMsgFile[0])
        strcpy(szTemp, szPrimaryMsgFile);
      else
        REG_ERR(lRegError, "RegQueryValueEx");

      /* get the message from the message DLL, replacing parameters and
         replaceable parameter strings as appropriate */
      p = lookupStringFromMsgDll(hk, pevlr->EventID, pevlr->NumStrings,
          (PTCHAR) ((LPBYTE) pevlr + pevlr->StringOffset), szTemp);
      printf("\nMessage: %s\n", p);

      // Subtract the size of the event log record we just read
      dwRead -= pevlr->Length;
      // Point to the next event log record in the buffer
      pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length);
      RegCloseKey(hk);  // close key for this event source
    } // while
    /* reset our event log record pointer back to the beginning of the buffer
       in preparation for reading the next record. */
    pevlr = (EVENTLOGRECORD *) &bBuffer;
  } // while
  if (GetLastError() != ERROR_HANDLE_EOF)
    PERR(bSuccess, "ReadEventLog");
  RegCloseKey(hk);
  if (!hEventLog)  // if we had to open the event log, close it
  {
    bSuccess = CloseEventLog(hLog);
    PERR(bSuccess, "CloseEventLog");
  }
  return;
} // queryEventLog

void reportAnEvent | ( | LPSTR | pszSrcName,
 |  | DWORD | dwIdEvent,
 |  | WORD | wCategory,
 |  | WORD | cStrings,
 |  | LPTSTR * | pszStrings
 | ) |  |

Definition at line 150 of file LOG.C.

{
  #define SID_BUF_SIZE 1024
  HANDLE hLog;
  HANDLE hAccessToken;
  PTOKEN_USER ptgUser;
  BYTE UserBuf[SID_BUF_SIZE];
  DWORD cbUserBufSize = SID_BUF_SIZE;
  BOOL bSuccess;

  // get the current process access token
  bSuccess = OpenProcessToken(
            GetCurrentProcess(),
            TOKEN_QUERY,
            &hAccessToken);
  PERR(bSuccess, "OpenProcessToken");

  ptgUser = (PTOKEN_USER) UserBuf;

  // get the TOKEN_USER structure from the access token, which contains
  // the Sid representing the caller
  bSuccess = GetTokenInformation(
            hAccessToken,
            TokenUser,
            ptgUser,
            cbUserBufSize,
            &cbUserBufSize
            );
  PERR(bSuccess, "GetTokenInformation");

  CloseHandle(hAccessToken);

  // Get a handle to the event log
  hLog = RegisterEventSource(MACHINE,  // use machine defined elsewhere
      pszSrcName);                  // source name
  PERR(hLog, "RegisterEventSource");

  // Now report the event, which will add this event to the event log
  bSuccess = ReportEvent(hLog,  // event-log handle
      EVENTLOG_ERROR_TYPE,      // event type
      wCategory,                // category
      dwIdEvent,                // event ID
      ptgUser->User.Sid,        // Sid representing caller
      cStrings,                 // number of substitution strings
      0,                        // no binary data
      pszStrings,               // string array
      NULL);                    // address of data
  PERR(bSuccess, "ReportEvent");

  DeregisterEventSource(hLog);

  return;
} // reportAnEvent

void usage ( )

Definition at line 659 of file LOG.C.

{
  puts("log [logname] [backuplog]>");
  puts("[logname] is an optional eventlog category such as Application, Security,"
      " or System."
      "[backuplog] is the filename of a backup log file to view. If this\n"
      "parameter is specified, [logname] must be given as well.");
  return;
} // usage()

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/BITMAP.C File Reference

  • MASKBLT
Functions

BITMAP.C File Reference

#include <windows.h>
#include <commdlg.h>

Go to the source code of this file.

Functions

VOID | DrawBitmap (HDC hdc, HBITMAP hbm)
HBITMAP | GetBitmap (HDC hdc, HANDLE hInst, BOOL monochrome)

Function Documentation

VOID DrawBitmap | ( | HDC | hdc,
 |  | HBITMAP | hbm
 | ) |  |

Definition at line 33 of file BITMAP.C.

{
    BOOL f;
    HDC hdcBits;
    BITMAP bm;

    hdcBits = CreateCompatibleDC(hdc);
    GetObject (hbm, sizeof(BITMAP), &bm);
    SelectObject(hdcBits,hbm);
    f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
    DeleteDC(hdcBits);
}

HBITMAP GetBitmap | ( | HDC | hdc,
 |  | HANDLE | hInst,
 |  | BOOL | monochrome
 | ) |  |

Definition at line 63 of file BITMAP.C.

{
    HBITMAP hbm;
    PBITMAPFILEHEADER pbmfh;
    PBITMAPINFOHEADER pbmih;
    PBYTE             pBits;
    int fh;
    int bfOffBits;
    int nbytes;
    OPENFILENAME  of;
    char buffer [MAX_PATH];

    buffer[0] = 0;

    /* set up the OPENFILE structure,
     *  then use the appropriate common dialog
     */
    of.lStructSize       = sizeof (OPENFILENAME);
    of.hwndOwner         = NULL;
    of.hInstance         = hInst;
    of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter    = 0;
    of.nFilterIndex      = 0;
    of.lpstrFile         = buffer;
    of.nMaxFile          = MAX_PATH;
    of.lpstrFileTitle    = NULL;
    of.nMaxFileTitle     = 0;
    of.lpstrInitialDir   = "c:\\nt\\windows";
    of.lpstrTitle        = NULL;
    of.Flags             = OFN_HIDEREADONLY;
    of.nFileOffset       = 0;
    of.nFileExtension    = 0;
    of.lpstrDefExt       = NULL;
    of.lCustData         = 0;
    of.lpfnHook          = NULL;
    of.lpTemplateName    = NULL;
    if (!GetOpenFileName (&of)) return NULL;

    /* Try to open the file.  If successful, then allocate space for it,
     *  and read in all of the bytes.
     */
    fh = _lopen (buffer, OF_READ);
    if (fh == -1) return NULL;
    nbytes = GetFileSize ((HANDLE) fh, NULL);

    /* The contents of the file are read in here in three parts.  First
     *  the bitmap file header is read, then the bitmap header along with
     *  the color table, then finally the actual bit data.  I.e. from
     *  a total of nbytes...
     *    1.  sizeof (BITMAPFILEHEADER)
     *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
     *    3.  (nbytes - bfOffBits)
     */

    /* read in the bitmap file header.  save the offset to bits. */
    if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
    bfOffBits=pbmfh->bfOffBits;

    /* read in the bitmap info header and the color table right after it.
     * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
     */
    if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));

    /* finally read in the bit data. */
    if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
    _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));

    /* in the case of desiring a monochrome bitmap (input parameter),
     *  verify that is what we got.  If it is, then use CreateBitmap,
     *  else use a device independent bitmap.
     */
    if (monochrome) {
      if (pbmih->biBitCount != 1) {
        MessageBox (NULL, "Mask must be monochrome bitmap.",
                    "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
        hbm = NULL;
      } else {
      hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
                          pbmih->biPlanes, pbmih->biBitCount,
                          pBits);
      }
    } else  /* bitmap is NOT monochrome, use DIB. */
      hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
                          pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);

    /* hbm is set... free up memory, and return */
    LocalFree (LocalHandle ((LPSTR)pBits));
    LocalFree (LocalHandle ((LPSTR)pbmih));
    LocalFree (LocalHandle ((LPSTR)pbmfh));
    _lclose (fh);

    return hbm;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/BITMAP.H File Reference

  • MASKBLT
Functions

BITMAP.H File Reference

Go to the source code of this file.

Functions

VOID | DrawBitmap (HDC, HBITMAP)
HBITMAP | GetBitmap (HDC, HANDLE, BOOL)

Function Documentation

VOID DrawBitmap | ( | HDC | ,
 |  | HBITMAP |
 | ) |  |

Definition at line 33 of file BITMAP.C.

{
    BOOL f;
    HDC hdcBits;
    BITMAP bm;

    hdcBits = CreateCompatibleDC(hdc);
    GetObject (hbm, sizeof(BITMAP), &bm);
    SelectObject(hdcBits,hbm);
    f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
    DeleteDC(hdcBits);
}

HBITMAP GetBitmap | ( | HDC | ,
 |  | HANDLE | ,
 |  | BOOL |
 | ) |  |

Definition at line 63 of file BITMAP.C.

{
    HBITMAP hbm;
    PBITMAPFILEHEADER pbmfh;
    PBITMAPINFOHEADER pbmih;
    PBYTE             pBits;
    int fh;
    int bfOffBits;
    int nbytes;
    OPENFILENAME  of;
    char buffer [MAX_PATH];

    buffer[0] = 0;

    /* set up the OPENFILE structure,
     *  then use the appropriate common dialog
     */
    of.lStructSize       = sizeof (OPENFILENAME);
    of.hwndOwner         = NULL;
    of.hInstance         = hInst;
    of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter    = 0;
    of.nFilterIndex      = 0;
    of.lpstrFile         = buffer;
    of.nMaxFile          = MAX_PATH;
    of.lpstrFileTitle    = NULL;
    of.nMaxFileTitle     = 0;
    of.lpstrInitialDir   = "c:\\nt\\windows";
    of.lpstrTitle        = NULL;
    of.Flags             = OFN_HIDEREADONLY;
    of.nFileOffset       = 0;
    of.nFileExtension    = 0;
    of.lpstrDefExt       = NULL;
    of.lCustData         = 0;
    of.lpfnHook          = NULL;
    of.lpTemplateName    = NULL;
    if (!GetOpenFileName (&of)) return NULL;

    /* Try to open the file.  If successful, then allocate space for it,
     *  and read in all of the bytes.
     */
    fh = _lopen (buffer, OF_READ);
    if (fh == -1) return NULL;
    nbytes = GetFileSize ((HANDLE) fh, NULL);

    /* The contents of the file are read in here in three parts.  First
     *  the bitmap file header is read, then the bitmap header along with
     *  the color table, then finally the actual bit data.  I.e. from
     *  a total of nbytes...
     *    1.  sizeof (BITMAPFILEHEADER)
     *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
     *    3.  (nbytes - bfOffBits)
     */

    /* read in the bitmap file header.  save the offset to bits. */
    if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
    bfOffBits=pbmfh->bfOffBits;

    /* read in the bitmap info header and the color table right after it.
     * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
     */
    if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));

    /* finally read in the bit data. */
    if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
    _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));

    /* in the case of desiring a monochrome bitmap (input parameter),
     *  verify that is what we got.  If it is, then use CreateBitmap,
     *  else use a device independent bitmap.
     */
    if (monochrome) {
      if (pbmih->biBitCount != 1) {
        MessageBox (NULL, "Mask must be monochrome bitmap.",
                    "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
        hbm = NULL;
      } else {
      hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
                          pbmih->biPlanes, pbmih->biBitCount,
                          pBits);
      }
    } else  /* bitmap is NOT monochrome, use DIB. */
      hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
                          pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);

    /* hbm is set... free up memory, and return */
    LocalFree (LocalHandle ((LPSTR)pBits));
    LocalFree (LocalHandle ((LPSTR)pbmih));
    LocalFree (LocalHandle ((LPSTR)pbmfh));
    _lclose (fh);

    return hbm;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/MASKBLT.C File Reference

  • MASKBLT
Defines | Functions | Variables

MASKBLT.C File Reference

#include <windows.h>
#include <commdlg.h>
#include <math.h>
#include <stdio.h>
#include "maskblt.h"
#include "track.h"
#include "bitmap.h"

Go to the source code of this file.

Defines

#define | NONE -1
#define | TICKSPACE 20

Functions

BOOL CALLBACK | DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | DrawGrids (HDC hdc, int width, int height)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HBITMAP | hbmMask = NULL
HBITMAP | hbmSrc = NULL
HDC | hdcDest
HDC | hdcMask
HDC | hdcSrc
HANDLE | hInst
HWND | hwndDlg
HWND | hwndMain
int | iPatternBrush = NONE
PTrackObject ptoDest
PTrackObject | ptoMask = NULL
PTrackObject ptoSrc

Define Documentation

#define NONE -1

Definition at line 45 of file MASKBLT.C.

#define TICKSPACE 20

Definition at line 818 of file MASKBLT.C.

Function Documentation

BOOL CALLBACK DlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 572 of file MASKBLT.C.

{
  char buffer[MAXCHARS];
  HBITMAP hbm;

  switch (message) {
    /**********************************************************************\
    *  WM_INITDIALOG
    *
    * Fill the entry fields with sensible original values.
    \**********************************************************************/
    case WM_INITDIALOG: {
      int i;

      for (i = DID_X; i<=  DID_YMASK; i++)
        SetDlgItemText(hwnd, i, "0");

      /* these are the three bytes from SRCCOPY */
      SetDlgItemText(hwnd, DID_ROP0  , "00");
      SetDlgItemText(hwnd, DID_ROP1  , "cc");
      SetDlgItemText(hwnd, DID_ROP2  , "00");
      SetDlgItemText(hwnd, DID_ROP3  , "20");

      for (i = 0; i< NROPS; i++)
        SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)StandardROPs[i].String);

      for (i = 0; i< NPATTERNS; i++)
        SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)Patterns[i].String);

    } return TRUE;

    /**********************************************************************\
    *  WM_PUTUPDESTRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the destination rectangle points.
    *  Conditionally change <x,y> or <width,height> depending on tracking mode.
    \**********************************************************************/
    case WM_PUTUPDESTRECT: {
        POINT p1,p2, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p2.x = pto->rect.right;
        p2.y = pto->rect.bottom;
        LPtoDP (pto->hdc, &p2, 1);
        p2.x -= p1.x; p2.y -= p1.y;

        p1.x -= origin.x; p1.y -= origin.y;

        if (!(pto->Mode & TMSIZEXY)) {
          SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
          SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
        }

        if (!(pto->Mode & TMMOVE)) {
          SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
          SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
        }
    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPSRCRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the source location point.
    \**********************************************************************/
    case WM_PUTUPSRCRECT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);

    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPMASKPT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the mask location point.
    \**********************************************************************/
    case WM_PUTUPMASKPT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);
        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XMASK, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YMASK, p1.y, TRUE);

    } return FALSE;

    case WM_COMMAND:
      switch (LOWORD(wParam)) {

        /******************************************************************\
        *  WM_COMMAND, DID_DRAW
        *
        * Draw button hit - send main window message to call MaskBlt().
        \******************************************************************/
        case DID_DRAW:
          SendMessage (hwndMain, WM_MASKBLT, 0,0);
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWSRC
        *
        * Try to get a new source bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWSRC:
          if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
            DeleteObject (hbmSrc);
            hbmSrc = hbm;
            InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWMASK
        *
        * Try to get a new mask bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWMASK:
          if ( hbm = GetBitmap (hdcMask, hInst, TRUE)) {
            DeleteObject (hbmMask);
            hbmMask = hbm;
            InvalidateRect (hwndMain, &ptoMask->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_ROPS
        *
        * A new standard rop entry was selected.  Lookup the value,
        *  then break it into four parts, convert to hex, and put
        *  it in the proper entry fields.
        \******************************************************************/
        case DID_CB_ROPS:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel, rop;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            rop = StandardROPs[iSel].Value;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP3, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP2, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP1, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP0, buffer);

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_PATTERN
        *
        * A new pattern brush was selected.  Look up the value, store it
        *  in a global variable (iPatternBrush), then force a new StretchBlt
        \******************************************************************/
        case DID_CB_PATTERN:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            iPatternBrush = Patterns[iSel].Value;

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

      } return FALSE; /* end WM_COMMAND switch*/

  } /* end switch */
  return 0;
}

VOID DrawGrids | ( | HDC | hdc,
 |  | int | width,
 |  | int | height
 | ) |  |

Definition at line 831 of file MASKBLT.C.

{
    int i;

    /* Draw vertical lines. Double at the axis */
    for (i = 0; i<= width; i+=TICKSPACE){
      MoveToEx (hdc, i, 0, NULL);
      LineTo (hdc, i, height);
    }
    MoveToEx (hdc, 1, 0, NULL);
    LineTo (hdc, 1, height);

    /* Draw horizontal lines. Double at the axis */
    for (i = 0; i<= height; i+=TICKSPACE){
      MoveToEx (hdc, 0,i, NULL);
      LineTo (hdc, width,i);
    }
    MoveToEx (hdc, 0, 1, NULL);
    LineTo (hdc, width,1);

  return;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 167 of file MASKBLT.C.

{
static int miniWidth;
static RECT rect;
static HANDLE hPenGrid, hPenSeparator;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Get three new HDCs, then create three new track objects.
    *  Each track object has different allowed tracking modes.
    *  Finally create two pens for drawing later on.
    \**********************************************************************/
    case WM_CREATE:
        hdcSrc  = GetDC (hwnd);
        hdcDest = GetDC (hwnd);
        hdcMask = GetDC (hwnd);

        ptoDest = doTrackObject (NULL, TROB_NEW, hwnd,0);
        ptoDest->allowedModes = TMMOVE | TMSIZEXY;
        ptoSrc  = doTrackObject (NULL, TROB_NEW, hwnd,0);
        ptoSrc->allowedModes = TMMOVE;
        ptoMask = doTrackObject (NULL, TROB_NEW, hwnd,0);
        ptoMask->allowedModes = TMMOVE;

        hPenGrid      = CreatePen (PS_SOLID, 1, GRIDCOLOR);
        hPenSeparator = CreatePen (PS_SOLID, 2*SEPARATORWIDTH, (COLORREF) 0x01000000);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Complement of WM_CREATE.  Free up all of the HDCs, send all of the
    *  track objects their delete messages, delete the pens,
    *  then call PostQuitMessage.
    \**********************************************************************/
    case WM_DESTROY:
        ReleaseDC (hwnd, hdcSrc );
        ReleaseDC (hwnd, hdcDest);
        ReleaseDC (hwnd, hdcMask);
        doTrackObject (ptoDest, TROB_DELETE, hwnd,0);
        doTrackObject (ptoSrc , TROB_DELETE, hwnd,0);
        doTrackObject (ptoMask, TROB_DELETE, hwnd,0);

        DeleteObject(hPenGrid);
        DeleteObject(hPenSeparator);

        PostQuitMessage(0);
    break;

    /**********************************************************************\
    *  WM_SIZE
    *
    * Stretch the top dialog to fill the width of the main window.
    * Adjust the viewport origins of the 6 HDCs.
    * Set the clip regions of the 6 HDCs.
    \**********************************************************************/
    case WM_SIZE: {
        HRGN hrgn;

        SetWindowPos (hwndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);

        GetClientRect (hwndMain, &rect);
        miniWidth = rect.right/3;

        SetViewportOrgEx (hdcDest,      0,           DIALOGHEIGHT, NULL);
        SetViewportOrgEx (ptoDest->hdc, 0,           DIALOGHEIGHT, NULL);
        SetViewportOrgEx (hdcSrc,       miniWidth,   DIALOGHEIGHT, NULL);
        SetViewportOrgEx (ptoSrc->hdc,  miniWidth,   DIALOGHEIGHT, NULL);
        SetViewportOrgEx (hdcMask,      2*miniWidth, DIALOGHEIGHT, NULL);
        SetViewportOrgEx (ptoMask->hdc, 2*miniWidth, DIALOGHEIGHT, NULL);

        ptoDest->rectClip.left    = 0;
        ptoDest->rectClip.top     = DIALOGHEIGHT;
        ptoDest->rectClip.right   = miniWidth-2*SEPARATORWIDTH;
        ptoDest->rectClip.bottom  = rect.bottom;
        hrgn = CreateRectRgnIndirect (&ptoDest->rectClip);
        SelectClipRgn (hdcDest,      hrgn);
        SelectClipRgn (ptoDest->hdc, hrgn);
        DeleteObject (hrgn);

        ptoSrc->rectClip.left    = miniWidth;
        ptoSrc->rectClip.top     = DIALOGHEIGHT;
        ptoSrc->rectClip.right   = 2*miniWidth-2*SEPARATORWIDTH;
        ptoSrc->rectClip.bottom  = rect.bottom;
        hrgn = CreateRectRgnIndirect (&ptoSrc->rectClip);
        SelectClipRgn (hdcSrc,       hrgn);
        SelectClipRgn (ptoSrc->hdc,  hrgn);
        DeleteObject (hrgn);

        ptoMask->rectClip.left    = 2*miniWidth;
        ptoMask->rectClip.top     = DIALOGHEIGHT;
        ptoMask->rectClip.right   = 3*miniWidth;
        ptoMask->rectClip.bottom  = rect.bottom;
        hrgn = CreateRectRgnIndirect (&ptoMask->rectClip);
        SelectClipRgn (hdcMask,      hrgn);
        SelectClipRgn (ptoMask->hdc, hrgn);
        DeleteObject (hrgn);

        SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD)hdcDest, (LONG)ptoDest);
        SendMessage (hwndDlg, WM_PUTUPSRCRECT,  (DWORD)hdcSrc,  (LONG)ptoSrc);
        SendMessage (hwndDlg, WM_PUTUPMASKPT,   (DWORD)hdcMask, (LONG)ptoMask);

        /* repaint the whole window. */
        InvalidateRect (hwnd, NULL, TRUE);
    } break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * miniWidth, rect -- set by WM_SIZE message.
    *
    * First shift the viewport origin down so that 0,0 is the top left
    *  most visible point (out from underneath the top dialog).  Second,
    *  draw the grid with wider lines on the axes.  Finally, read the
    *  values out of the top dialog, do elementary validation, and then
    *  try to call MaskBlt() with the values.
    \**********************************************************************/
     case WM_PAINT: {
        HDC hdc;
        PAINTSTRUCT ps;

        hdc = BeginPaint(hwnd, &ps);

        /* Draw Separator lines for the three miniareas */
        SelectObject(hdc, hPenSeparator);
        MoveToEx (hdc,   miniWidth-SEPARATORWIDTH,0, NULL);
        LineTo   (hdc,   miniWidth-SEPARATORWIDTH, rect.bottom);
        MoveToEx (hdc, 2*miniWidth-SEPARATORWIDTH,0, NULL);
        LineTo   (hdc, 2*miniWidth-SEPARATORWIDTH, rect.bottom);

        /* Grid the HDCs */
        SelectObject(hdcSrc, hPenGrid);
        DrawGrids (hdcSrc, miniWidth, rect.bottom);
        SelectObject(hdcMask, hPenGrid);
        DrawGrids (hdcMask, miniWidth, rect.bottom);

        /* Draw bitmaps if any, then draw track objects over them. */
        if (hbmSrc)  DrawBitmap (hdcSrc, hbmSrc);
        if (hbmMask) DrawBitmap (hdcMask, hbmMask);
        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
        doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);

        /* paint the left third of the window. */
        SendMessage (hwnd, WM_MASKBLT, 0,0);

        EndPaint (hwnd, &ps);
    } return FALSE;

    /**********************************************************************\
    *  WM_MASKBLT
    *
    * WM_USER message.  This paints the left third of the window.  It
    *  is called on the WM_PAINT message.  It is separated out here because
    *  it is common for just the MaskBlt() to need to be called and not the
    *  whole window painted.
    \**********************************************************************/
    case WM_MASKBLT: {
        int X, Y, nWidth, nHeight;
        int XSrc, YSrc, XMask, YMask;
        DWORD rop, ropByte;
        char buffer[MAXCHARS];

        BOOL success;
        RECT cliprect;

        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
        doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);

        GetClipBox (hdcDest, &cliprect);
        FillRect (hdcDest, &cliprect,
                  (HBRUSH) GetClassLong (hwnd, GCL_HBRBACKGROUND));
        SelectObject(hdcDest, hPenGrid);

        DrawGrids (hdcDest, miniWidth, rect.bottom);
        if (IsWindow(hwndDlg)) {

          /* Grab points out of the dialog entry fields. */
          X =      GetDlgItemInt(hwndDlg, DID_X,      &success, TRUE);
          Y =      GetDlgItemInt(hwndDlg, DID_Y,      &success, TRUE);
          nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH,  &success, TRUE);
          nHeight= GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);

          XSrc =   GetDlgItemInt(hwndDlg, DID_XSRC,   &success, TRUE);
          YSrc =   GetDlgItemInt(hwndDlg, DID_YSRC,   &success, TRUE);
          XMask =  GetDlgItemInt(hwndDlg, DID_XMASK,  &success, TRUE);
          YMask =  GetDlgItemInt(hwndDlg, DID_YMASK,  &success, TRUE);

          /* get high order ROP byte and shift left by two bytes. */
          GetDlgItemText(hwndDlg, DID_ROP0, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop = ropByte * 256 * 256 * 256;

          /* get the next ROP byte and shift left by one byte. */
          GetDlgItemText(hwndDlg, DID_ROP1, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop += ropByte * 256 * 256;

          /* get the next ROP byte and shift left by one byte. */
          GetDlgItemText(hwndDlg, DID_ROP2, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop += ropByte * 256;

          /* finally, get the low order ROP byte. */
          GetDlgItemText(hwndDlg, DID_ROP3, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop += ropByte;

          /* select the pattern brush.  (user selects via combo box.) */
          if (iPatternBrush != NONE)
            SelectObject (hdcDest, GetStockObject (iPatternBrush));

          /**********************************************************/
          /**********************************************************/
          MaskBlt (hdcDest, X, Y, nWidth, nHeight,
                  hdcSrc, XSrc, YSrc,
                  hbmMask, XMask, YMask, rop);
          /**********************************************************/
          /**********************************************************/
        }
        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
        doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);
    } break;

    /**********************************************************************\
    *  WM_LBUTTONDOWN & WM_RBUTTONDOWN
    * On button down messages, hittest on the track object, and if
    *  it returns true, then send these messages to the track object.
    \**********************************************************************/
    case WM_RBUTTONDOWN:
    case WM_LBUTTONDOWN:
      if (doTrackObject(ptoDest, TROB_HITTEST, hwnd, lParam))
         doTrackObject(ptoDest, message, hwnd, lParam);
      else if (doTrackObject(ptoSrc, TROB_HITTEST, hwnd, lParam))
         doTrackObject(ptoSrc, message, hwnd, lParam);
      else if (doTrackObject(ptoMask, TROB_HITTEST, hwnd, lParam))
         doTrackObject(ptoMask, message, hwnd, lParam);
    break;

    /**********************************************************************\
    *  WM_LBUTTONUP & WM_RBUTTONDOWN & MW_MOUSEMOVE
    * If the track object is in a "tracking mode" then send it these messages.
    *  If the transform dialog is not minimized, fill it with numbers.
    *  If the mouse dialog is not minimized, fill it with numbers.
    \**********************************************************************/
    case WM_RBUTTONUP:
    case WM_LBUTTONUP:
      /* user action complete.  Force MaskBlt() update. */
      PostMessage (hwndMain, WM_MASKBLT, 0,0);
    case WM_MOUSEMOVE:
      if (ptoDest->Mode) {
        doTrackObject(ptoDest, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
      }
      if (ptoSrc->Mode) {
        doTrackObject(ptoSrc, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
      }

      if (ptoMask->Mode) {
        doTrackObject(ptoMask, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPMASKPT, (DWORD) hdcMask, (LONG) ptoMask);
      }

    break;

    /**********************************************************************\
    *  Accelerator & clipboard support.
    *
    * Certain key strokes (c.f. *.rc) will cause the following WM_COMMAND
    *  messages.  In response the app will copy a bitmap into the clipboard
    *  or paste down from it.  In both cases, it is necessary to create a
    *  new bitmap since a bitmap in the clipboard belongs to the clipboard
    *  and not to the application.
    \**********************************************************************/
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        HBITMAP hbmCompat, hbmOld;
        HDC hdcCompat;

        /******************************************************************\
        *  WM_COMMAND, AID_COPY
        *
        * Create a new bitmap, copy the destination HDC bits into it,
        *  and send the new bitmap to the clipboard.
        \******************************************************************/
        case AID_COPY: {
          int X,Y, nWidth, nHeight;
          BOOL success;

          X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
          Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
          nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
          nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);

          hdcCompat = CreateCompatibleDC(hdcDest);
          hbmCompat = CreateCompatibleBitmap (hdcDest, nWidth, nHeight);
          hbmOld = SelectObject(hdcCompat,hbmCompat);

          BitBlt (hdcCompat, 0,0,nWidth, nHeight, hdcDest, X,Y, SRCCOPY );

          SelectObject(hdcCompat,hbmOld);
          DeleteDC(hdcCompat);

          OpenClipboard (hwnd);
          SetClipboardData (CF_BITMAP,hbmCompat);
          CloseClipboard ();

          DeleteObject (hbmCompat);

        } break;

        /******************************************************************\
        *  WM_COMMAND, AID_PASTE
        *
        * Get bitmap handle from clipboard, create a new bitmap, draw
        *  the clipboard bitmap into the new one, and store the new
        *  handle in the global hbmSrc.
        \******************************************************************/
        case AID_PASTE: {
          HBITMAP hbm;
          BITMAP bm;

          OpenClipboard (hwnd);
          if ( hbm = GetClipboardData (CF_BITMAP)) {
            DeleteObject (hbmSrc);

            GetObject (hbm, sizeof(BITMAP), &bm);

            hdcCompat = CreateCompatibleDC(hdcDest);
            hbmCompat = CreateCompatibleBitmap (hdcDest, bm.bmWidth, bm.bmHeight);
            hbmOld = SelectObject(hdcCompat,hbmCompat);

            DrawBitmap (hdcCompat, hbm);

            SelectObject(hdcCompat,hbmOld);
            DeleteDC(hdcCompat);

            hbmSrc = hbmCompat;

            InvalidateRect (hwnd, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwnd, &ptoDest->rectClip, TRUE);
          }
          CloseClipboard ();
        } break;

        /******************************************************************\
        *  WM_COMMAND, AID_CYCLE
        *
        * Post a COPY and PASTE command message to this window so that with
        *  one key stroke the user can copy the DEST image into the clipboard,
        *  paste it down into the SRC hdc and cause the blt.
        \******************************************************************/
        case AID_CYCLE:
          PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_COPY , 1), 0);
          PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_PASTE, 1), 0);
        break;
      }  /* end switch */

    break;  /* end wm_command */

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 57 of file MASKBLT.C.

{
    MSG   msg;
    RECT rect;
    HANDLE haccel;

    UNREFERENCED_PARAMETER( lpCmdLine );

    // check if running on Windows NT, if not, display notice and terminate
    if( GetVersion() & 0x80000000 )
    {
       MessageBoxA( NULL,
           "This sample application can only be run on Windows NT.\n"
           "This application will now terminate.",
           "MaskBlt",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
     }

    /* Check for previous instance.  If none, then register class. */
    if (!hPrevInstance) {
        WNDCLASS  wc;

        wc.style = 0;
        wc.lpfnWndProc = (WNDPROC)MainWndProc;

        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, "MaskBltIcon");
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "MaskBlt";

        if (!RegisterClass(&wc)) return (FALSE);
    }  /* class registered o.k. */

    /* Create the main window.  Return false if CreateWindow() fails */
    hInst = hInstance;

    hwndMain = CreateWindow(
        "MaskBlt",
        "MaskBlt",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    if (!hwndMain) return (FALSE);

    /* create the top dialog as a child of the main window. */
    hwndDlg = CreateDialog (hInst, "maskbltDlg", hwndMain, (DLGPROC)DlgProc);

    /* Send main window a WM_SIZE message so that it will size the top
     *  dialog correctly.
     */
    GetClientRect (hwndMain, &rect);
    SendMessage (hwndMain, WM_SIZE, 0, (rect.right - rect.left));
    ShowWindow (hwndDlg, SW_SHOW);
    ShowWindow(hwndMain, nCmdShow);

    /* Load the accelerator table that provides clipboard support. */
    haccel = LoadAccelerators (hInst, "bltAccel");

    /* Loop getting messages and dispatching them. */
    while (GetMessage(&msg,NULL, 0,0)) {
      if (!TranslateAccelerator(hwndMain, haccel, &msg))
      if (!IsDialogMessage (hwndDlg, &msg)){
        DispatchMessage(&msg);
      }
    }

    /* Return the value from PostQuitMessage */
    return (msg.wParam);
}

Variable Documentation

HBITMAP hbmMask = NULL

Definition at line 43 of file MASKBLT.C.

HBITMAP hbmSrc = NULL

Definition at line 42 of file MASKBLT.C.

HDC hdcDest

Definition at line 41 of file MASKBLT.C.

HDC hdcMask

Definition at line 41 of file MASKBLT.C.

HDC hdcSrc

Definition at line 41 of file MASKBLT.C.

HANDLE hInst

Definition at line 37 of file MASKBLT.C.

HWND hwndDlg

Definition at line 38 of file MASKBLT.C.

HWND hwndMain

Definition at line 38 of file MASKBLT.C.

int iPatternBrush = NONE

Definition at line 46 of file MASKBLT.C.

PTrackObject ptoDest

Definition at line 40 of file MASKBLT.C.

PTrackObject ptoMask = NULL

Definition at line 40 of file MASKBLT.C.

PTrackObject ptoSrc

Definition at line 40 of file MASKBLT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/MASKBLT.H File Reference

  • MASKBLT
Data Structures | Defines | Typedefs | Functions | Variables

MASKBLT.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | AID_COPY 56
#define | AID_CYCLE 57
#define | AID_PASTE 55
#define | DIALOGHEIGHT 90
#define | DID_CB_MODE 150
#define | DID_CB_PATTERN 151
#define | DID_CB_ROPS 152
#define | DID_DRAW 302
#define | DID_HEIGHT 103
#define | DID_NEWMASK 301
#define | DID_NEWSRC 300
#define | DID_ROP0 110
#define | DID_ROP1 111
#define | DID_ROP2 112
#define | DID_ROP3 113
#define | DID_WIDTH 102
#define | DID_X 100
#define | DID_XMASK 106
#define | DID_XSRC 104
#define | DID_Y 101
#define | DID_YMASK 107
#define | DID_YSRC 105
#define | GRIDCOLOR (COLORREF) 0x01000006
#define | INC 5
#define | MAXCHARS 32
#define | NPATTERNS 6
#define | NROPS 17
#define | SEPARATORWIDTH 4
#define | WM_MASKBLT WM_USER+23
#define | WM_PUTUPDESTRECT WM_USER+20
#define | WM_PUTUPMASKPT WM_USER+22
#define | WM_PUTUPSRCRECT WM_USER+21

Typedefs

typedef struct tagLookupEntry | LookupEntry

Functions

BOOL CALLBACK | DlgProc (HWND, UINT, WPARAM, LPARAM)
VOID | DrawGrids (HDC, int, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)

Variables

LookupEntry | Patterns [NPATTERNS]
LookupEntry | StandardROPs [NROPS]

Define Documentation

#define AID_COPY 56

Definition at line 50 of file MASKBLT.H.

#define AID_CYCLE 57

Definition at line 51 of file MASKBLT.H.

#define AID_PASTE 55

Definition at line 49 of file MASKBLT.H.

#define DIALOGHEIGHT 90

Definition at line 57 of file MASKBLT.H.

#define DID_CB_MODE 150

Definition at line 42 of file MASKBLT.H.

#define DID_CB_PATTERN 151

Definition at line 43 of file MASKBLT.H.

#define DID_CB_ROPS 152

Definition at line 44 of file MASKBLT.H.

#define DID_DRAW 302

Definition at line 40 of file MASKBLT.H.

#define DID_HEIGHT 103

Definition at line 26 of file MASKBLT.H.

#define DID_NEWMASK 301

Definition at line 38 of file MASKBLT.H.

#define DID_NEWSRC 300

Definition at line 37 of file MASKBLT.H.

#define DID_ROP0 110

Definition at line 32 of file MASKBLT.H.

#define DID_ROP1 111

Definition at line 33 of file MASKBLT.H.

#define DID_ROP2 112

Definition at line 34 of file MASKBLT.H.

#define DID_ROP3 113

Definition at line 35 of file MASKBLT.H.

#define DID_WIDTH 102

Definition at line 25 of file MASKBLT.H.

#define DID_X 100

Definition at line 23 of file MASKBLT.H.

#define DID_XMASK 106

Definition at line 29 of file MASKBLT.H.

#define DID_XSRC 104

Definition at line 27 of file MASKBLT.H.

#define DID_Y 101

Definition at line 24 of file MASKBLT.H.

#define DID_YMASK 107

Definition at line 30 of file MASKBLT.H.

#define DID_YSRC 105

Definition at line 28 of file MASKBLT.H.

#define GRIDCOLOR (COLORREF) 0x01000006

Definition at line 56 of file MASKBLT.H.

#define INC 5

Definition at line 60 of file MASKBLT.H.

#define MAXCHARS 32

Definition at line 59 of file MASKBLT.H.

#define NPATTERNS 6

Definition at line 100 of file MASKBLT.H.

#define NROPS 17

Definition at line 79 of file MASKBLT.H.

#define SEPARATORWIDTH 4

Definition at line 58 of file MASKBLT.H.

#define WM_MASKBLT WM_USER+23

Definition at line 68 of file MASKBLT.H.

#define WM_PUTUPDESTRECT WM_USER+20

Definition at line 65 of file MASKBLT.H.

#define WM_PUTUPMASKPT WM_USER+22

Definition at line 67 of file MASKBLT.H.

#define WM_PUTUPSRCRECT WM_USER+21

Definition at line 66 of file MASKBLT.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Function Documentation

BOOL CALLBACK DlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 572 of file MASKBLT.C.

{
  char buffer[MAXCHARS];
  HBITMAP hbm;

  switch (message) {
    /**********************************************************************\
    *  WM_INITDIALOG
    *
    * Fill the entry fields with sensible original values.
    \**********************************************************************/
    case WM_INITDIALOG: {
      int i;

      for (i = DID_X; i<=  DID_YMASK; i++)
        SetDlgItemText(hwnd, i, "0");

      /* these are the three bytes from SRCCOPY */
      SetDlgItemText(hwnd, DID_ROP0  , "00");
      SetDlgItemText(hwnd, DID_ROP1  , "cc");
      SetDlgItemText(hwnd, DID_ROP2  , "00");
      SetDlgItemText(hwnd, DID_ROP3  , "20");

      for (i = 0; i< NROPS; i++)
        SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)StandardROPs[i].String);

      for (i = 0; i< NPATTERNS; i++)
        SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)Patterns[i].String);

    } return TRUE;

    /**********************************************************************\
    *  WM_PUTUPDESTRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the destination rectangle points.
    *  Conditionally change <x,y> or <width,height> depending on tracking mode.
    \**********************************************************************/
    case WM_PUTUPDESTRECT: {
        POINT p1,p2, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p2.x = pto->rect.right;
        p2.y = pto->rect.bottom;
        LPtoDP (pto->hdc, &p2, 1);
        p2.x -= p1.x; p2.y -= p1.y;

        p1.x -= origin.x; p1.y -= origin.y;

        if (!(pto->Mode & TMSIZEXY)) {
          SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
          SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
        }

        if (!(pto->Mode & TMMOVE)) {
          SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
          SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
        }
    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPSRCRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the source location point.
    \**********************************************************************/
    case WM_PUTUPSRCRECT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);

    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPMASKPT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the mask location point.
    \**********************************************************************/
    case WM_PUTUPMASKPT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);
        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XMASK, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YMASK, p1.y, TRUE);

    } return FALSE;

    case WM_COMMAND:
      switch (LOWORD(wParam)) {

        /******************************************************************\
        *  WM_COMMAND, DID_DRAW
        *
        * Draw button hit - send main window message to call MaskBlt().
        \******************************************************************/
        case DID_DRAW:
          SendMessage (hwndMain, WM_MASKBLT, 0,0);
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWSRC
        *
        * Try to get a new source bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWSRC:
          if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
            DeleteObject (hbmSrc);
            hbmSrc = hbm;
            InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWMASK
        *
        * Try to get a new mask bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWMASK:
          if ( hbm = GetBitmap (hdcMask, hInst, TRUE)) {
            DeleteObject (hbmMask);
            hbmMask = hbm;
            InvalidateRect (hwndMain, &ptoMask->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_ROPS
        *
        * A new standard rop entry was selected.  Lookup the value,
        *  then break it into four parts, convert to hex, and put
        *  it in the proper entry fields.
        \******************************************************************/
        case DID_CB_ROPS:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel, rop;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            rop = StandardROPs[iSel].Value;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP3, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP2, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP1, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP0, buffer);

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_PATTERN
        *
        * A new pattern brush was selected.  Look up the value, store it
        *  in a global variable (iPatternBrush), then force a new StretchBlt
        \******************************************************************/
        case DID_CB_PATTERN:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            iPatternBrush = Patterns[iSel].Value;

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

      } return FALSE; /* end WM_COMMAND switch*/

  } /* end switch */
  return 0;
}

VOID DrawGrids | ( | HDC | ,
 |  | int | ,
 |  | int |
 | ) |  |

Definition at line 831 of file MASKBLT.C.

{
    int i;

    /* Draw vertical lines. Double at the axis */
    for (i = 0; i<= width; i+=TICKSPACE){
      MoveToEx (hdc, i, 0, NULL);
      LineTo (hdc, i, height);
    }
    MoveToEx (hdc, 1, 0, NULL);
    LineTo (hdc, 1, height);

    /* Draw horizontal lines. Double at the axis */
    for (i = 0; i<= height; i+=TICKSPACE){
      MoveToEx (hdc, 0,i, NULL);
      LineTo (hdc, width,i);
    }
    MoveToEx (hdc, 0, 1, NULL);
    LineTo (hdc, width,1);

  return;
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

Variable Documentation

LookupEntry Patterns[NPATTERNS]
Initial value:
    {{  0, "WHITE_BRUSH "},
     {  1, "LTGRAY_BRUSH"},
     {  2, "GRAY_BRUSH  "},
     {  3, "DKGRAY_BRUSH"},
     {  4, "BLACK_BRUSH "},
     {  5, "NULL_BRUSH  "}}

Definition at line 101 of file MASKBLT.H.

LookupEntry StandardROPs[NROPS]
Initial value:
    {{ SRCCOPY     , "SRCCOPY"    },
     { SRCPAINT    , "SRCPAINT"   },
     { SRCAND      , "SRCAND"     },
     { SRCINVERT   , "SRCINVERT"  },
     { SRCERASE    , "SRCERASE"   },
     { NOTSRCCOPY  , "NOTSRCCOPY" },
     { NOTSRCERASE , "NOTSRCERASE"},
     { MERGECOPY   , "MERGECOPY"  },
     { MERGEPAINT  , "MERGEPAINT" },
     { PATCOPY     , "PATCOPY"    },
     { PATPAINT    , "PATPAINT"   },
     { PATINVERT   , "PATINVERT"  },
     { DSTINVERT   , "DSTINVERT"  },
     { BLACKNESS   , "BLACKNESS"  },
     { WHITENESS   , "WHITENESS"  },
     { 0xccaa0000  , "Transparent1"  },
     { 0xaacc0000  , "Transparent2"  }}

Definition at line 80 of file MASKBLT.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/TRACK.C File Reference

  • MASKBLT
Defines | Functions

TRACK.C File Reference

#include <windows.h>
#include <math.h>
#include "track.h"

Go to the source code of this file.

Defines

#define | EPSILON (float) 0.0001
#define | RECTSIZE 60

Functions

PTrackObject | doTrackObject (PTrackObject pto, int msg, HWND hwnd, LONG lParam)
VOID | MouseMove (PTrackObject pto, int msg, HWND hwnd, LONG lParam)

Define Documentation

#define EPSILON (float) 0.0001

Definition at line 20 of file TRACK.C.

#define RECTSIZE 60

Definition at line 21 of file TRACK.C.

Function Documentation

PTrackObject doTrackObject | ( | PTrackObject | pto,
 |  | int | msg,
 |  | HWND | hwnd,
 |  | LONG | lParam
 | ) |  |

Definition at line 54 of file TRACK.C.

{
  if ((pto == NULL) && (msg != TROB_NEW))  return NULL;

  switch (msg) {

    /**********************************************************************\
    *  TROB_NEW
    *
    * Allocate new PTrackObject structure.  Fill in default values
    *  for the fields of the structure.  Set up the HDC correctly.
    * return - pointer to the new object.
    \**********************************************************************/
    case  TROB_NEW: {
        PTrackObject  pto;

        /* with LPTR returned value is a pointer. */
        pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));

        /* initialize the HDC and other fields. */
        pto->hdc = GetDC (hwnd);
        SetGraphicsMode (pto->hdc, GM_ADVANCED);
        SetROP2(pto->hdc, R2_NOT);
        SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
        pto->Mode = TMNONE;
        pto->allowedModes = TMMOVE | TMSIZEXY;

        GetWorldTransform (pto->hdc, &(pto->xfmChange));

        /* initialize the size. */
        pto->rect.top = pto->rect.left = 0;
        pto->rect.bottom = pto->rect.right = RECTSIZE;

        return (pto);
    }

    /**********************************************************************\
    *  TROB_DELETE
    *
    * Complement of TROB_NEW.  Free up the memory allocated for the object.
    \**********************************************************************/
    case  TROB_DELETE:
        doTrackObject (pto, TROB_PAINT, hwnd, lParam);
        ReleaseDC (hwnd, pto->hdc);
        LocalFree (LocalHandle ((LPSTR)pto));
    return NULL;

    /**********************************************************************\
    *  TROB_PAINT
    *
    * Paint the object into its hdc.  Called half the time to erase
    *  the object, and half the time to redraw it.
    \**********************************************************************/
    case TROB_PAINT: {
        MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);

        if (pto->allowedModes & TMSIZEXY) {
          LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
          LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
        }

        if (pto->allowedModes & TMROTATE) {
          MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
          AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
                 (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
        }

    } return NULL;

    /**********************************************************************\
    *  TROB_HITTEST
    *
    * Check the point sent in in the lParam to see if it lays within
    *  the bounds of the objects defining rectangle.
    * return - pointer to the object iff the point is in rectangle,
    *  otherwise return NULL.
    \**********************************************************************/
    case TROB_HITTEST:{
        POINT  mouWorld;
        mouWorld.x = LOWORD(lParam);
        mouWorld.y = HIWORD(lParam);

        DPtoLP (pto->hdc, &mouWorld, 1);

        if (PtInRect (&pto->rect, mouWorld))  return pto;
        else  return NULL;
    }

    /**********************************************************************\
    *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
    *
    * Capture the mouse, set the tracking mode depending on the mouse
    *  location in world coordinates, reset the mouse position.
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN: {
      POINT  newmouScreen;
      POINT  mouWorld;

      mouWorld.x = LOWORD(lParam);
      mouWorld.y = HIWORD(lParam);
      DPtoLP (pto->hdc, &mouWorld, 1);

      /* upper left hand corner. right button is no-op. */
      if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {
          if (msg == WM_RBUTTONDOWN) return NULL;
          pto->Mode = TMMOVE;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.top;

      /* lower left hand corner */
      } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.bottom;

      /* upper right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.top;

      /* lower right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.bottom;
      }

      if (! (pto->Mode & pto->allowedModes)) {
        pto->Mode = TMNONE;
        return NULL;
      }

      SetCapture(hwnd);
      LPtoDP (pto->hdc, &newmouScreen, 1);
      ClientToScreen (hwnd, &newmouScreen);
      SetCursorPos (newmouScreen.x,newmouScreen.y);

      GetWorldTransform (pto->hdc, &pto->xfmDown);
    } return NULL;

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * this is where almost all of the interesting calculation is done.
    *  First clip the mouse location to be in rectClip, then
    *  call MouseMove() to handle the different tracking modes.
    \**********************************************************************/
    case WM_MOUSEMOVE: {
      if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
        lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));

      if (LOWORD(lParam) > (WORD)pto->rectClip.right)
        lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));

      if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
        lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);

      if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
        lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);

      MouseMove (pto, msg, hwnd, lParam);

    } return NULL;

    /**********************************************************************\
    *  WM_RBUTTONUP & WM_LBUTTONUP
    *
    * simply release the mouse capture, and set the mode to TMNONE.
    \**********************************************************************/
    case WM_RBUTTONUP:
    case WM_LBUTTONUP: {
      if (pto->Mode) {
         ReleaseCapture();
         pto->Mode = TMNONE;
      }
    } return NULL;

  }  /* end switch(msg) */
}

VOID MouseMove | ( | PTrackObject | pto,
 |  | int | msg,
 |  | HWND | hwnd,
 |  | LONG | lParam
 | ) |  |

Definition at line 296 of file TRACK.C.

{
POINT  mouWorld, mouDevice, orgDevice;

    UNREFERENCED_PARAMETER(msg);

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);
    mouDevice.x = mouWorld.x = LOWORD(lParam);
    mouDevice.y = mouWorld.y = HIWORD(lParam);

    SetWorldTransform(pto->hdc, &pto->xfmDown);
    DPtoLP (pto->hdc, &mouWorld, 1);

    /* offset the mouse device point for the viewport's origin. */
    GetViewportOrgEx (pto->hdc, &orgDevice);
    mouDevice.x -= orgDevice.x;
    mouDevice.y -= orgDevice.y;

    GetWorldTransform(pto->hdc, &pto->xfmChange);

    switch (pto->Mode) {
      /*******************************************************\
      *    (     1         xShear       0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSHEARX: {
        pto->xfmChange.eM12 = (float) mouDevice.y;
        pto->xfmChange.eM12 -=pto->xfmChange.eDy;
        pto->xfmChange.eM12 /=(float) pto->rect.right ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (   yShear        1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSHEARY: {
        pto->xfmChange.eM21 = (float) mouDevice.x;
        pto->xfmChange.eM21 -=pto->xfmChange.eDx;
        pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

      } break;

      /*******************************************************\
      *    (   cos(a)      -sin(a)      0   )
      *    (   sin(a)       cos(a)      0   )
      *    (     0           0          1   )
      *
      * a == rotation angle.  Since mouse in in lower right,
      *  we need to shift this back 45 degrees (assuming that
      *  straight down is 0 degrees).  Thus we actually compute
      *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
      *  where b is angle from the origin to the mouse (x,y)
      *  cos(45) = sin(45) ~= 0.707107
      *  cos(b) = y/r    sin(b) = x/r
      *
      \*******************************************************/
      case TMROTATE: {
        float r;

        /* translate back to the origin. */
        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

        /* rotate about the origin. */
        r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
                          (double)(mouWorld.y * mouWorld.y));

        pto->xfmChange.eM11 = (float) mouWorld.y / r;
        pto->xfmChange.eM11 += (float) mouWorld.x / r;
        pto->xfmChange.eM11 *= (float) 0.707107;
        pto->xfmChange.eM22 = pto->xfmChange.eM11;

        pto->xfmChange.eM12 = (float) mouWorld.y / r;
        pto->xfmChange.eM12 -= (float) mouWorld.x / r;
        pto->xfmChange.eM12 *= (float) 0.707107;
        pto->xfmChange.eM21 = -pto->xfmChange.eM12;

        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;

        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);

        /* translate back to the original offset. */
        pto->xfmChange.eM11 =
        pto->xfmChange.eM22 = (float) 1.0;
        pto->xfmChange.eM12 =
        pto->xfmChange.eM21 = (float) 0.0;

        pto->xfmChange.eDx = pto->xfmDown.eDx;
        pto->xfmChange.eDy = pto->xfmDown.eDy;
        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
        GetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      \*******************************************************/
      case TMSIZEXY: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSIZEX: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSIZEY: {
        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0           1          0   )
      *    (   Move x      Move y       1   )
      *
      * xWorld = rect.left == 0;
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMMOVE: {
        pto->xfmChange.eDx = (float) mouDevice.x ;
        pto->xfmChange.eDy = (float) mouDevice.y ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;
    } /* end switch */

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);

    return;
 }

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/TRACK.H File Reference

  • MASKBLT
Data Structures | Defines | Typedefs | Functions

TRACK.H File Reference

Go to the source code of this file.

Data Structures

struct | tagTrackObject

Defines

#define | TMALL 0x00ff
#define | TMMOVE 0x0001
#define | TMNONE 0x0000
#define | TMROTATE 0x0008
#define | TMSHEARX 0x0010
#define | TMSHEARY 0x0020
#define | TMSIZEX 0x0002
#define | TMSIZEXY 0x0006
#define | TMSIZEY 0x0004
#define | TROB_DELETE WM_USER+2
#define | TROB_HITTEST WM_USER+5
#define | TROB_NEW WM_USER+1
#define | TROB_PAINT WM_USER+3

Typedefs

typedef struct tagTrackObject * | PTrackObject
typedef struct tagTrackObject | TrackObject

Functions

PTrackObject | doTrackObject (PTrackObject, int, HWND, LONG)
VOID | MouseMove (PTrackObject, int, HWND, LONG)

Define Documentation

#define TMALL 0x00ff

Definition at line 31 of file TRACK.H.

#define TMMOVE 0x0001

Definition at line 24 of file TRACK.H.

#define TMNONE 0x0000

Definition at line 23 of file TRACK.H.

#define TMROTATE 0x0008

Definition at line 30 of file TRACK.H.

#define TMSHEARX 0x0010

Definition at line 28 of file TRACK.H.

#define TMSHEARY 0x0020

Definition at line 29 of file TRACK.H.

#define TMSIZEX 0x0002

Definition at line 25 of file TRACK.H.

#define TMSIZEXY 0x0006

Definition at line 27 of file TRACK.H.

#define TMSIZEY 0x0004

Definition at line 26 of file TRACK.H.

#define TROB_DELETE WM_USER+2

Definition at line 17 of file TRACK.H.

#define TROB_HITTEST WM_USER+5

Definition at line 19 of file TRACK.H.

#define TROB_NEW WM_USER+1

Definition at line 16 of file TRACK.H.

#define TROB_PAINT WM_USER+3

Definition at line 18 of file TRACK.H.

Typedef Documentation

typedef struct tagTrackObject * PTrackObject
typedef struct tagTrackObject TrackObject

Function Documentation

PTrackObject doTrackObject | ( | PTrackObject | ,
 |  | int | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |

Definition at line 54 of file TRACK.C.

{
  if ((pto == NULL) && (msg != TROB_NEW))  return NULL;

  switch (msg) {

    /**********************************************************************\
    *  TROB_NEW
    *
    * Allocate new PTrackObject structure.  Fill in default values
    *  for the fields of the structure.  Set up the HDC correctly.
    * return - pointer to the new object.
    \**********************************************************************/
    case  TROB_NEW: {
        PTrackObject  pto;

        /* with LPTR returned value is a pointer. */
        pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));

        /* initialize the HDC and other fields. */
        pto->hdc = GetDC (hwnd);
        SetGraphicsMode (pto->hdc, GM_ADVANCED);
        SetROP2(pto->hdc, R2_NOT);
        SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
        pto->Mode = TMNONE;
        pto->allowedModes = TMMOVE | TMSIZEXY;

        GetWorldTransform (pto->hdc, &(pto->xfmChange));

        /* initialize the size. */
        pto->rect.top = pto->rect.left = 0;
        pto->rect.bottom = pto->rect.right = RECTSIZE;

        return (pto);
    }

    /**********************************************************************\
    *  TROB_DELETE
    *
    * Complement of TROB_NEW.  Free up the memory allocated for the object.
    \**********************************************************************/
    case  TROB_DELETE:
        doTrackObject (pto, TROB_PAINT, hwnd, lParam);
        ReleaseDC (hwnd, pto->hdc);
        LocalFree (LocalHandle ((LPSTR)pto));
    return NULL;

    /**********************************************************************\
    *  TROB_PAINT
    *
    * Paint the object into its hdc.  Called half the time to erase
    *  the object, and half the time to redraw it.
    \**********************************************************************/
    case TROB_PAINT: {
        MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);

        if (pto->allowedModes & TMSIZEXY) {
          LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
          LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
        }

        if (pto->allowedModes & TMROTATE) {
          MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
          AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
                 (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
        }

    } return NULL;

    /**********************************************************************\
    *  TROB_HITTEST
    *
    * Check the point sent in in the lParam to see if it lays within
    *  the bounds of the objects defining rectangle.
    * return - pointer to the object iff the point is in rectangle,
    *  otherwise return NULL.
    \**********************************************************************/
    case TROB_HITTEST:{
        POINT  mouWorld;
        mouWorld.x = LOWORD(lParam);
        mouWorld.y = HIWORD(lParam);

        DPtoLP (pto->hdc, &mouWorld, 1);

        if (PtInRect (&pto->rect, mouWorld))  return pto;
        else  return NULL;
    }

    /**********************************************************************\
    *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
    *
    * Capture the mouse, set the tracking mode depending on the mouse
    *  location in world coordinates, reset the mouse position.
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN: {
      POINT  newmouScreen;
      POINT  mouWorld;

      mouWorld.x = LOWORD(lParam);
      mouWorld.y = HIWORD(lParam);
      DPtoLP (pto->hdc, &mouWorld, 1);

      /* upper left hand corner. right button is no-op. */
      if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {
          if (msg == WM_RBUTTONDOWN) return NULL;
          pto->Mode = TMMOVE;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.top;

      /* lower left hand corner */
      } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.bottom;

      /* upper right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.top;

      /* lower right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.bottom;
      }

      if (! (pto->Mode & pto->allowedModes)) {
        pto->Mode = TMNONE;
        return NULL;
      }

      SetCapture(hwnd);
      LPtoDP (pto->hdc, &newmouScreen, 1);
      ClientToScreen (hwnd, &newmouScreen);
      SetCursorPos (newmouScreen.x,newmouScreen.y);

      GetWorldTransform (pto->hdc, &pto->xfmDown);
    } return NULL;

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * this is where almost all of the interesting calculation is done.
    *  First clip the mouse location to be in rectClip, then
    *  call MouseMove() to handle the different tracking modes.
    \**********************************************************************/
    case WM_MOUSEMOVE: {
      if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
        lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));

      if (LOWORD(lParam) > (WORD)pto->rectClip.right)
        lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));

      if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
        lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);

      if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
        lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);

      MouseMove (pto, msg, hwnd, lParam);

    } return NULL;

    /**********************************************************************\
    *  WM_RBUTTONUP & WM_LBUTTONUP
    *
    * simply release the mouse capture, and set the mode to TMNONE.
    \**********************************************************************/
    case WM_RBUTTONUP:
    case WM_LBUTTONUP: {
      if (pto->Mode) {
         ReleaseCapture();
         pto->Mode = TMNONE;
      }
    } return NULL;

  }  /* end switch(msg) */
}

VOID MouseMove | ( | PTrackObject | ,
 |  | int | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |

Definition at line 296 of file TRACK.C.

{
POINT  mouWorld, mouDevice, orgDevice;

    UNREFERENCED_PARAMETER(msg);

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);
    mouDevice.x = mouWorld.x = LOWORD(lParam);
    mouDevice.y = mouWorld.y = HIWORD(lParam);

    SetWorldTransform(pto->hdc, &pto->xfmDown);
    DPtoLP (pto->hdc, &mouWorld, 1);

    /* offset the mouse device point for the viewport's origin. */
    GetViewportOrgEx (pto->hdc, &orgDevice);
    mouDevice.x -= orgDevice.x;
    mouDevice.y -= orgDevice.y;

    GetWorldTransform(pto->hdc, &pto->xfmChange);

    switch (pto->Mode) {
      /*******************************************************\
      *    (     1         xShear       0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSHEARX: {
        pto->xfmChange.eM12 = (float) mouDevice.y;
        pto->xfmChange.eM12 -=pto->xfmChange.eDy;
        pto->xfmChange.eM12 /=(float) pto->rect.right ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (   yShear        1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSHEARY: {
        pto->xfmChange.eM21 = (float) mouDevice.x;
        pto->xfmChange.eM21 -=pto->xfmChange.eDx;
        pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

      } break;

      /*******************************************************\
      *    (   cos(a)      -sin(a)      0   )
      *    (   sin(a)       cos(a)      0   )
      *    (     0           0          1   )
      *
      * a == rotation angle.  Since mouse in in lower right,
      *  we need to shift this back 45 degrees (assuming that
      *  straight down is 0 degrees).  Thus we actually compute
      *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
      *  where b is angle from the origin to the mouse (x,y)
      *  cos(45) = sin(45) ~= 0.707107
      *  cos(b) = y/r    sin(b) = x/r
      *
      \*******************************************************/
      case TMROTATE: {
        float r;

        /* translate back to the origin. */
        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

        /* rotate about the origin. */
        r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
                          (double)(mouWorld.y * mouWorld.y));

        pto->xfmChange.eM11 = (float) mouWorld.y / r;
        pto->xfmChange.eM11 += (float) mouWorld.x / r;
        pto->xfmChange.eM11 *= (float) 0.707107;
        pto->xfmChange.eM22 = pto->xfmChange.eM11;

        pto->xfmChange.eM12 = (float) mouWorld.y / r;
        pto->xfmChange.eM12 -= (float) mouWorld.x / r;
        pto->xfmChange.eM12 *= (float) 0.707107;
        pto->xfmChange.eM21 = -pto->xfmChange.eM12;

        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;

        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);

        /* translate back to the original offset. */
        pto->xfmChange.eM11 =
        pto->xfmChange.eM22 = (float) 1.0;
        pto->xfmChange.eM12 =
        pto->xfmChange.eM21 = (float) 0.0;

        pto->xfmChange.eDx = pto->xfmDown.eDx;
        pto->xfmChange.eDy = pto->xfmDown.eDy;
        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
        GetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      \*******************************************************/
      case TMSIZEXY: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSIZEX: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSIZEY: {
        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0           1          0   )
      *    (   Move x      Move y       1   )
      *
      * xWorld = rect.left == 0;
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMMOVE: {
        pto->xfmChange.eDx = (float) mouDevice.x ;
        pto->xfmChange.eDy = (float) mouDevice.y ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;
    } /* end switch */

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);

    return;
 }

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDI.C File Reference

  • MDI_
Data Structures | Defines | Typedefs | Functions | Variables

MDI.C File Reference

#include <stdlib.h>
#include "mdi.h"
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct | _PerWndInfo

Defines

#define | STRICT

Typedefs

typedef struct _PerWndInfo | INFO
typedef struct _PerWndInfo * | PINFO

Functions

BOOL CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
BOOL | InitializeApp (void)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MDIWndProc (HWND, UINT, WPARAM, LPARAM)
LONG APIENTRY | TextWndProc (HWND, UINT, DWORD, LONG)
VOID | vTest (PINFO)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

Variables

HANDLE | ghModule
HWND | ghwndClient = NULL
HWND | ghwndMain = NULL
CHAR | gszFile [20]
CHAR | gszMapName [20]
HMENU | hChildMenu
HMENU | hChildMenuWindow
HMENU | hMenu
HMENU | hMenuWindow

Define Documentation

#define STRICT

Definition at line 25 of file MDI.C.

Typedef Documentation

typedef struct _PerWndInfo INFO
typedef struct _PerWndInfo * PINFO

Function Documentation

BOOL CALLBACK About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 516 of file MDI.C.

{
    switch (message) {
    case WM_INITDIALOG:
        return TRUE;

    case WM_COMMAND:
        if (wParam == IDOK)
            EndDialog(hDlg, wParam);
        break;
    }

    return FALSE;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(hDlg);
}

BOOL InitializeApp ( void )

Definition at line 114 of file MDI.C.

{
    WNDCLASS wc;

    wc.style            = CS_OWNDC;
    wc.lpfnWndProc      = (WNDPROC) MainWndProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = sizeof(LONG);
    wc.hInstance        = ghModule;
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE);
    wc.lpszMenuName     = "MainMenu";
    wc.lpszClassName    = "MDIDemoClass";

    if (!RegisterClass(&wc))
        return FALSE;

    wc.lpfnWndProc      = (WNDPROC) MDIWndProc;
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = "MDIClass";

    if (!RegisterClass(&wc))
        return FALSE;

    wc.style            = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc      = (WNDPROC) TextWndProc;
    wc.hIcon            = NULL;
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = (HBRUSH)(COLOR_BTNSHADOW);
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = "Text";

    if (!RegisterClass(&wc))
            return FALSE;

    hMenu       = LoadMenu(ghModule, "MainMenu");
    hChildMenu  = LoadMenu(ghModule, "ChildMenu");
    hMenuWindow      = GetSubMenu(hMenu, 1);
    hChildMenuWindow = GetSubMenu(hChildMenu, 2);

    ghwndMain = CreateWindowEx(0L, "MDIDemoClass", "MDI Demonstration",
            WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
            WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
            WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
            80, 70, 400, 300,
            NULL, hMenu, ghModule, NULL);

    if (ghwndMain == NULL)
        return FALSE;

    SetWindowLong(ghwndMain, GWL_USERDATA, 0L);

    SetFocus(ghwndMain);    /* set initial focus */

    return TRUE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 185 of file MDI.C.

{
    static int         iMDICount=1;
    CLIENTCREATESTRUCT clientcreate;
    HWND               hwndChildWindow;

    switch (message) {

      case WM_CREATE:
        SetWindowLong(hwnd, 0, (LONG)NULL);

        clientcreate.hWindowMenu  = hMenuWindow;
        clientcreate.idFirstChild = 1;

        ghwndClient = CreateWindow("MDICLIENT", NULL,
                                    WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
                                    0,0,0,0,
                                    hwnd, NULL, ghModule, (LPVOID)&clientcreate);
        return 0L;

      case WM_DESTROY: {
        PostQuitMessage(0);
        return 0L;
      }

      case WM_COMMAND:

        switch (LOWORD(wParam)) {
            //
            // Getting default MDI functionalities...
            //
            case IDM_TILE:
                SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
                return 0L;
            case IDM_CASCADE:
                SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
                return 0L;
            case IDM_ARRANGE:
                SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
                return 0L;

            //
            // Creates MDI child
            //
            case MM_MDI: {
                HANDLE hInfo;
                PINFO  pInfo;
                MDICREATESTRUCT mdicreate;

                //
                // Allocating memory for INFO to be associated with the
                //  new child
                //
                hInfo = LocalAlloc(LHND, (WORD) sizeof(INFO));
                if (hInfo) {
                    if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
                        MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

                    wsprintf((LPSTR) &(pInfo->CaptionBarText),
                             "MDI %d", iMDICount);
                    pInfo->hParent    = ghwndClient;

                    mdicreate.szClass = "MDIClass";
                    mdicreate.szTitle = (LPTSTR)&(pInfo->CaptionBarText);
                    mdicreate.hOwner  = ghModule;
                    mdicreate.x       =
                    mdicreate.y       =
                    mdicreate.cx      =
                    mdicreate.cy      = CW_USEDEFAULT;
                    mdicreate.style   = 0L;
                    //
                    // passing the handle of the per MDI child INFO to the
                    //  child MDI window for storage
                    //
                    mdicreate.lParam  = (LONG) hInfo;

                    /*Create Child Window*/
                    hwndChildWindow =
                        (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
                                    0L,
                                    (LONG)(LPMDICREATESTRUCT)&mdicreate);

                    if (hwndChildWindow == NULL) {
                        MessageBox(ghwndMain, "Failed in Creating Child Window", "Error", MB_OK);
                        return 0L;
                    }

                    iMDICount++;

                    LocalUnlock(hInfo);
                } else {
                            MessageBox(ghwndMain, "Failed to Allocate INFO data!", "Error", MB_OK);
                }
                return 0L;
            }

            case MM_ABOUT:
                if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
                        MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
                return 0L;

            //
            // Passes these WM_COMMAND messages to the appropriate active child
            //  window proc for processing
            //
            case MM_OPT_1:
            case MM_OPT_2:
            case MM_OPT_3:
            case MM_OPT_4:
            case MM_OPT_5:
            case MM_OPT_6:
            case MM_OPT_7:
            case MM_OPT_8: {
                HWND hActiveChild;

                hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L);
                if (hActiveChild)
                    SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
                return 0L;
            }

            default:
                return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
        }

    default:

        return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
    }
}

LRESULT CALLBACK MDIWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 332 of file MDI.C.

{

    switch (message) {
        case WM_COMMAND: {
          HANDLE      hInfo;
          PINFO       pInfo;
          HWND        hTextWnd;

          //
          // Retrieving this child window's INFO data for displaying
          //    messages in the text window
          //
          hInfo = (HANDLE) GetWindowLong(hwnd, 0);
          if (hInfo) {
              if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
                  MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

              hTextWnd = pInfo->hTextWnd;
              vTest(pInfo);
              LocalUnlock(hInfo);
          } else {
              MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
          }

          switch (LOWORD(wParam)) {
            case MM_OPT_1: {
               SetWindowText(hTextWnd, "MM_OPT_1");
               return 0L;
            }

            case MM_OPT_2: {
               SetWindowText(hTextWnd, "MM_OPT_2");
               return 0L;
            }

            case MM_OPT_3: {
               SetWindowText(hTextWnd, "MM_OPT_3");
               return 0L;
            }

            case MM_OPT_4: {
               SetWindowText(hTextWnd, "MM_OPT_4");
               return 0L;
            }
            default:
               return 0L;

          }

        }
        case WM_SETFOCUS:
            break;

        //
        // Potentially, you can set different menu for different MDI
        //  child which is currently being active.
        //
        case WM_MDIACTIVATE:
            if ((HWND) lParam == hwnd) {
                SendMessage(GetParent(hwnd), WM_MDISETMENU,
                            (DWORD)  hChildMenu,
                            (LONG)   hChildMenuWindow) ;
                DrawMenuBar(GetParent(GetParent(hwnd))) ;
            }
            return 0L;

        //
        // Whenever the MDI child window is resized, its children has to be
        //  resized accordingly.
        //
        case WM_SIZE: {
            HANDLE      hInfo;
            PINFO       pInfo;
            HWND        hTextWnd;

            //
            // First, get the text window's handle from the per MDI child
            //  INFO data structure
            //
            hInfo = (HANDLE) GetWindowLong(hwnd, 0);
            if (hInfo) {
                if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
                    MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

                hTextWnd = pInfo->hTextWnd;
                LocalUnlock(hInfo);
            } else {
                MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
            }

            //
            // Always, put the text window at the bottom of the MDI window
            //
            MoveWindow(hTextWnd,
                       0,
                       HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
                       LOWORD(lParam),
                       HIWORD(lParam), TRUE);
            break;
        }

        //
        // Creates the text window for this MDI child and saves its handle
        //  in the per MDI child INFO data structure.
        //
        case WM_CREATE: {
            PINFO           pInfo;
            HANDLE          hInfo;
            HWND            hTextWnd;

            hTextWnd = CreateWindow("Text", NULL,
                                    WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
                                    0, 0, 0, 0,
                                    hwnd,
                                    (HMENU) 2,
                                    ghModule,
                                    NULL);

            SetWindowText(hTextWnd, "Select 'Option' menu items");
            //
            // INFO was allocated in the MDIWndProc at MM_MDI time and is
            //  passed to us at WM_CREATE time...
            //
            hInfo = (HANDLE) ((LPMDICREATESTRUCT) ((LPCREATESTRUCT) lParam)->lpCreateParams)->lParam ;
            if (hInfo) {
                if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
                    MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

                if (!GetClientRect(hwnd, &pInfo->rcClient))
                    MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);

                pInfo->hTextWnd = hTextWnd;
                //
                // Save the handle to INFO in our window structure
                //
                SetWindowLong(hwnd, 0, (LONG) hInfo);
                LocalUnlock(hInfo);
            } else {
                MessageBox(ghwndMain, "Can't allocate hInfo!", "Error", MB_OK);
            }

            break;
        }

        //
        // Free the INFO data that associates with this window
        //  also, reset the menu.
        //
        case WM_CLOSE: {
            HANDLE           hInfo;

            SendMessage(GetParent(hwnd), WM_MDISETMENU,
                            (DWORD) hMenu,
                            (LONG)  hMenuWindow) ;
            DrawMenuBar(GetParent(GetParent(hwnd))) ;

            hInfo = (HANDLE) GetWindowLong(hwnd, 0);
            LocalFree(hInfo);
            break;
        }

        default:
            return DefMDIChildProc(hwnd, message, wParam, lParam);

    } //switch
    return DefMDIChildProc(hwnd, message, wParam, lParam);
}

LONG APIENTRY TextWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | DWORD | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 550 of file MDI.C.

{
    static HFONT hFont = (HFONT) NULL;

    switch (message)
    {
    case WM_CREATE:
        {
            LOGFONT    lf;
            HDC        hDC;
            HFONT      hOldFont;
            TEXTMETRIC tm;
            RECT       rect;
            LONG       lHeight;

            SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);

            hDC = GetDC(hwnd);
            // this is the height for 8 point size font in pixels
            lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;

            hFont = CreateFontIndirect(&lf);
            hOldFont = SelectObject(hDC, hFont);
            GetTextMetrics(hDC, &tm);
            GetClientRect(GetParent(hwnd), &rect);

            // base the height of the window on size of text
            lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
            // saved the height for later reference
            SetWindowLong(hwnd, GWL_USERDATA, lHeight);
            SetWindowPos(hwnd, NULL,
                    0,
                    rect.bottom-lHeight,
                    rect.right-rect.left,
                    lHeight,
                    SWP_NOZORDER | SWP_NOMOVE);

            ReleaseDC(hwnd, hDC);
            break;
        }

    case WM_DESTROY:
            if (hFont)
                DeleteObject(hFont);
            break;

    case WM_SETTEXT:
            DefWindowProc(hwnd, message, wParam, lParam);
            InvalidateRect(hwnd,NULL,FALSE);
            UpdateWindow(hwnd);
            return 0L;

    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            RECT   rc;
            char   ach[128];
            int    len, nxBorder, nyBorder;
            HFONT  hOldFont = NULL;

            BeginPaint(hwnd, &ps);

            GetClientRect(hwnd,&rc);

            nxBorder = GetSystemMetrics(SM_CXBORDER);
            rc.left  += 9*nxBorder;
            rc.right -= 9*nxBorder;

            nyBorder = GetSystemMetrics(SM_CYBORDER);
            rc.top    += 3*nyBorder;
            rc.bottom -= 3*nyBorder;

            // 3D Text
            len = GetWindowText(hwnd, ach, sizeof(ach));
            SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));

            SetBkMode(ps.hdc, TRANSPARENT);
            SetTextColor(ps.hdc, RGB(64,96,96));
            if (hFont)
                hOldFont = SelectObject(ps.hdc, hFont);
            ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
                        &rc, ach, len, NULL);

            SetTextColor(ps.hdc, RGB(128,128,128));
            if (hFont)
                hOldFont = SelectObject(ps.hdc, hFont);
            ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
                        &rc, ach, len, NULL);

            SetTextColor(ps.hdc, RGB(255,255,255));
            if (hFont)
                hOldFont = SelectObject(ps.hdc, hFont);
            ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
                        &rc, ach, len, NULL);

            SetBkMode(ps.hdc, OPAQUE);

            if (hOldFont)
                SelectObject(ps.hdc, hOldFont);

            EndPaint(hwnd, &ps);
            return 0L;
        }
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

VOID vTest ( PINFO pInfo )

Definition at line 657 of file MDI.C.

{
    OutputDebugString("Inside vTest()\n");

    UNREFERENCED_PARAMETER(pInfo);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nShowCmd
 | ) |  |

Definition at line 69 of file MDI.C.

{
    MSG    msg;
    HANDLE hAccel;

    ghModule = GetModuleHandle(NULL);
    if (!InitializeApp()) {
        MessageBox(ghwndMain, "MDI: InitializeApp failure!", "Error", MB_OK);
        return 0;
    }

    if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
        MessageBox(ghwndMain, "MDI: Load Accel failure!", "Error", MB_OK);

    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!TranslateAccelerator( ghwndMain, hAccel, &msg) &&
            !TranslateMDISysAccel(  ghwndClient, &msg)          ) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return 1;

    UNREFERENCED_PARAMETER(lpCmdLine);
    UNREFERENCED_PARAMETER(nShowCmd);
    UNREFERENCED_PARAMETER(hInstance);
    UNREFERENCED_PARAMETER(hPrevInstance);
}

Variable Documentation

HANDLE ghModule

Definition at line 30 of file MDI.C.

HWND ghwndClient = NULL

Definition at line 32 of file MDI.C.

HWND ghwndMain = NULL

Definition at line 31 of file MDI.C.

CHAR gszFile[20]

Definition at line 37 of file MDI.C.

CHAR gszMapName[20]

Definition at line 38 of file MDI.C.

HMENU hChildMenu

Definition at line 35 of file MDI.C.

HMENU hChildMenuWindow

Definition at line 35 of file MDI.C.

HMENU hMenu

Definition at line 34 of file MDI.C.

HMENU hMenuWindow

Definition at line 34 of file MDI.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDI.H File Reference

  • MDI_
Defines

MDI.H File Reference

#include <windows.h>
#include <string.h>

Go to the source code of this file.

Defines

#define | ACCEL_ID 100
#define | IDM_ARRANGE 32
#define | IDM_CASCADE 30
#define | IDM_CLOSEALL 33
#define | IDM_TILE 31
#define | MM_ABOUT 8000
#define | MM_MDI 8001
#define | MM_OPT_1 7001
#define | MM_OPT_2 7002
#define | MM_OPT_3 7003
#define | MM_OPT_4 7004
#define | MM_OPT_5 7005
#define | MM_OPT_6 7006
#define | MM_OPT_7 7007
#define | MM_OPT_8 7008
#define | MM_RESERVE1 8002
#define | MM_RESERVE2 8003
#define | SIZEOFCAPTIONTEXT 20

Define Documentation

#define ACCEL_ID 100

Definition at line 40 of file MDI.H.

#define IDM_ARRANGE 32

Definition at line 35 of file MDI.H.

#define IDM_CASCADE 30

Definition at line 33 of file MDI.H.

#define IDM_CLOSEALL 33

Definition at line 36 of file MDI.H.

#define IDM_TILE 31

Definition at line 34 of file MDI.H.

#define MM_ABOUT 8000

Definition at line 19 of file MDI.H.

#define MM_MDI 8001

Definition at line 20 of file MDI.H.

#define MM_OPT_1 7001

Definition at line 24 of file MDI.H.

#define MM_OPT_2 7002

Definition at line 25 of file MDI.H.

#define MM_OPT_3 7003

Definition at line 26 of file MDI.H.

#define MM_OPT_4 7004

Definition at line 27 of file MDI.H.

#define MM_OPT_5 7005

Definition at line 28 of file MDI.H.

#define MM_OPT_6 7006

Definition at line 29 of file MDI.H.

#define MM_OPT_7 7007

Definition at line 30 of file MDI.H.

#define MM_OPT_8 7008

Definition at line 31 of file MDI.H.

#define MM_RESERVE1 8002

Definition at line 21 of file MDI.H.

#define MM_RESERVE2 8003

Definition at line 22 of file MDI.H.

#define SIZEOFCAPTIONTEXT 20

Definition at line 38 of file MDI.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDITYPES.H File Reference

  • MDI_
Data Structures | Typedefs

MDITYPES.H File Reference

#include "mdi.h"

Go to the source code of this file.

Data Structures

struct | _PerWndInfo

Typedefs

typedef struct _PerWndInfo | INFO
typedef struct _PerWndInfo * | PINFO

Typedef Documentation

typedef struct _PerWndInfo INFO
typedef struct _PerWndInfo * PINFO
Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MENU/MENU.C File Reference

  • MENU
Functions | Variables

MENU.C File Reference

#include "windows.h"
#include "menu.h"

Go to the source code of this file.

Functions

BOOL APIENTRY | About (HWND hDlg, UINT message, UINT wParam, LONG lParam)
VOID APIENTRY | HandleChangeColors (HWND hwnd)
VOID APIENTRY | HandleCreate (HWND hwnd)
VOID APIENTRY | HandleDrawItem (HWND hwnd, LPDRAWITEMSTRUCT lpdis)
VOID APIENTRY | HandlePaint (HWND hwnd)
VOID APIENTRY | HandlePopupMenu (HWND hwnd, POINT point)
BOOL NEAR PASCAL | MenuInit (HANDLE hInstance)
LONG APIENTRY | MenuWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)
HBITMAP APIENTRY | ShrinkBitmap (HWND hwnd, HBITMAP hbm)
int APIENTRY | WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HMENU | hBigMenu
HBITMAP | hbmCheckOff
HBITMAP | hbmCheckOn
HANDLE | hInst

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 166 of file MENU.C.

{
    switch (message){
        case WM_INITDIALOG:
            return(TRUE);

        case WM_COMMAND:
            // LOWORD added for portability
            if (LOWORD(wParam) == IDOK){
                EndDialog(hDlg,0);
                return(TRUE);
            }
            break;
    }
    return(FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

VOID APIENTRY HandleChangeColors ( HWND hwnd )

Definition at line 342 of file MENU.C.

{
    HMENU hMenu;
    BOOL  fOwnerDraw;

    /* Get a handle to the Colors menu. This is at position 1. */
    hMenu = GetSubMenu (GetMenu (hwnd), IDCOLORS_POS);

    /* Get the current state of the item */
    fOwnerDraw = GetMenuState ( hMenu,
                                IDM_COLOROWNERDR, MF_BYCOMMAND) & MF_CHECKED;

    /* Toggle the state of the item. */
    CheckMenuItem ( hMenu,
                    IDM_COLOROWNERDR,
                    MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED));

    if (!fOwnerDraw){
        /* Change the items to owner-draw items. Pass the RGB value for the
         * color as the application-supplied data. This makes it easier for
         * us to draw the items.
         */
        ModifyMenu(hMenu,
                   IDM_BLACK,
                   MF_OWNERDRAW | MF_BYCOMMAND,
                   IDM_BLACK,
                   (LPSTR)RGB (0,0,0));

        ModifyMenu(hMenu,
                   IDM_BLUE,
                   MF_OWNERDRAW | MF_BYCOMMAND,
                   IDM_BLUE,
                   (LPSTR)RGB (0,0,255));

        ModifyMenu(hMenu,
                   IDM_RED,
                   MF_OWNERDRAW | MF_BYCOMMAND,
                   IDM_RED,
                   (LPSTR)RGB (255,0,0));

        ModifyMenu(hMenu,
                   IDM_GREEN,
                   MF_OWNERDRAW | MF_BYCOMMAND,
                   IDM_GREEN,
                   (LPSTR)RGB (0,255,0));
    }
    else {
        /* Change the items to normal text items. */
        ModifyMenu(hMenu, IDM_BLACK, MF_BYCOMMAND, IDM_BLACK, "Black");

        ModifyMenu(hMenu, IDM_BLUE, MF_BYCOMMAND, IDM_BLUE, "Blue");

        ModifyMenu(hMenu, IDM_RED, MF_BYCOMMAND, IDM_RED, "Red");

        ModifyMenu(hMenu, IDM_GREEN, MF_BYCOMMAND, IDM_GREEN, "Green");
    }
}

VOID APIENTRY HandleCreate ( HWND hwnd )

Definition at line 267 of file MENU.C.

{
    HMENU   hMenu;
    HMENU   hWndMenu;

    /* Create a new menu into the menubar on the fly */
    hMenu = CreateMenu ();
    if (!hMenu)
        return;

    /* Append the state menu items to it */
    AppendMenu (hMenu, MF_STRING, IDM_STATE1, "South Dakota");
    AppendMenu (hMenu, MF_STRING, IDM_STATE2, "Washington");
    AppendMenu (hMenu, MF_STRING, IDM_STATE3, "California");
    if (!AppendMenu (hMenu, MF_STRING, IDM_STATE4, "Oregon")){
        /* It is unlikely the other appends will fail and this will succeed.
         * So just check this one. And if it fails, Destroy the menu for
         * good measure and return.
         */
        DestroyMenu(hMenu);
        return;
    }
    hbmCheckOn  = ShrinkBitmap (hwnd, LoadBitmap (hInst, "checkon"));
    hbmCheckOff = ShrinkBitmap (hwnd, LoadBitmap (hInst, "checkoff"));

    /* Set up the user-defined check marks */
    SetMenuItemBitmaps (hMenu, 0, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
    SetMenuItemBitmaps (hMenu, 1, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
    SetMenuItemBitmaps (hMenu, 2, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
    SetMenuItemBitmaps (hMenu, 3, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);

    /* Now insert the menu into the main menu bar. */
    hWndMenu = GetMenu (hwnd);
    InsertMenu (hWndMenu, 2, MF_POPUP|MF_BYPOSITION, (DWORD)hMenu, "States");

    return;
}

VOID APIENTRY HandleDrawItem | ( | HWND | hwnd,
 |  | LPDRAWITEMSTRUCT | lpdis
 | ) |  |

Definition at line 412 of file MENU.C.

{
    HDC     hdcBitmap;
    HBITMAP hbmSave;
    HBRUSH  hbr;
    RECT    rc;
    LONG    checkMarkSize;
    DWORD   textColorSave;
    DWORD   bkColorSave;

    /* Get the size of the checkmark so we can leave room for it since we
     * want to be able to check the selected color.
     */
    checkMarkSize = GetMenuCheckMarkDimensions ();

    if (lpdis->itemAction == ODA_SELECT ||
        lpdis->itemAction == ODA_DRAWENTIRE){

        CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
        InflateRect ((LPRECT)&rc, (-2 - LOWORD(checkMarkSize)), -2);

        if (lpdis->itemState & ODS_SELECTED)
        {
            /* Item has been selected -- hilite with a gray frame */
            hbr = GetStockObject (GRAY_BRUSH);
            FrameRect (lpdis->hDC, (LPRECT)&rc, hbr);
        }
        else if (lpdis->itemAction == ODA_SELECT)
        {
            /* Item has been de-selected -- remove gray frame */
            hbr = CreateSolidBrush (GetSysColor (COLOR_MENU));
            FrameRect (lpdis->hDC, (LPRECT)&rc, hbr);
            DeleteObject (hbr);
        }
    }

    if (lpdis->itemAction == ODA_DRAWENTIRE){

        /* Paint the color item in the color requested. */
        hbr = CreateSolidBrush (lpdis->itemData);
        CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
        InflateRect ((LPRECT)&rc, -10-LOWORD(checkMarkSize), -10);
        FillRect (lpdis->hDC, (LPRECT)&rc, hbr);
        DeleteObject (hbr);

        if (lpdis->itemState & ODS_CHECKED){
            /* Draw the check mark if the item is checked. */
            hdcBitmap = CreateCompatibleDC (lpdis->hDC);
            hbmSave = SelectObject (hdcBitmap, hbmCheckOn);

            textColorSave = SetTextColor (lpdis->hDC, 0x00000000L);
            bkColorSave   = SetBkColor (lpdis->hDC, 0x00FFFFFFL);

            /* Use Magic bitblt op so that monochrome bitmaps preserve
               background and foreground colors. */
            BitBlt (lpdis->hDC,
                    lpdis->rcItem.left,
                    lpdis->rcItem.top+
                           (MEASUREITEMHEIGHT - HIWORD (checkMarkSize)) / 2,
                    LOWORD (checkMarkSize),
                    HIWORD (checkMarkSize),
                    hdcBitmap,
                    0,
                    0,
                    ROP_PSDPxax);

            /* Restore colors and bitmap and clean up */
            SetTextColor (lpdis->hDC, textColorSave);
            SetBkColor (lpdis->hDC, bkColorSave);
            SelectObject (hdcBitmap, hbmSave);
            DeleteDC (hdcBitmap);

        }
    }
        UNREFERENCED_PARAMETER(hwnd);
}

VOID APIENTRY HandlePaint ( HWND hwnd )

Definition at line 312 of file MENU.C.

{
    HDC         hdc;
    PAINTSTRUCT ps;
    RECT        rc;

    hdc = BeginPaint (hwnd, (LPPAINTSTRUCT)&ps);

    /* Center the text in the client area */
    GetClientRect (hwnd, (LPRECT)&rc);
    DrawText (hdc,
              "Down click in the window for a popup menu",
               41,
               (LPRECT)&rc,
               DT_CENTER | DT_WORDBREAK);
    EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
}

VOID APIENTRY HandlePopupMenu | ( | HWND | hwnd,
 |  | POINT | point
 | ) |  |

Definition at line 500 of file MENU.C.

{
    HMENU hMenu;
    HMENU hMenuTrackPopup;

    /* Get the menu for the popup from the resource file. */
    hMenu = LoadMenu (hInst, "PopupMenu");
    if (!hMenu)
        return;

    /* Get the first menu in it which we will use for the call to
     * TrackPopup(). This could also have been created on the fly using
     * CreatePopupMenu and then we could have used InsertMenu() or
     * AppendMenu.
     */
    hMenuTrackPopup = GetSubMenu (hMenu, 0);

    /* Convert the mouse point to screen coordinates since that is what
     * TrackPopup expects.
     */
    ClientToScreen (hwnd, (LPPOINT)&point);

    /* Draw and track the "floating" popup */
    TrackPopupMenu (hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL);

    /* Destroy the menu since were are done with it. */
    DestroyMenu (hMenu);
}

BOOL NEAR PASCAL MenuInit ( HANDLE hInstance )

Definition at line 127 of file MENU.C.

{
    HANDLE    hMemory;
    PWNDCLASS pWndClass;
    BOOL      bSuccess;

    /* Initialize the menu window class */
    hMemory   = LocalAlloc(LPTR, sizeof(WNDCLASS));
    if(!hMemory){
        MessageBox(NULL, "<MenuInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
        return(FALSE);
    }

    pWndClass = (PWNDCLASS) LocalLock(hMemory);

    pWndClass->style         = 0;
    pWndClass->lpfnWndProc   = (WNDPROC) MenuWndProc;
    pWndClass->hInstance     = hInstance;
    pWndClass->hIcon         = LoadIcon (hInstance, "menu");
    pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
    pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
    pWndClass->lpszMenuName  = (LPSTR) "MenuMenu",
    pWndClass->lpszClassName = (LPSTR) "menu";

    bSuccess = RegisterClass (pWndClass);
    LocalUnlock (hMemory);
    LocalFree (hMemory);

    return bSuccess;
}

LONG APIENTRY MenuWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 540 of file MENU.C.

{
    FARPROC lpProc;
    HMENU hMenu;
    RECT rc;
    POINT pt;

    switch (message){
        case WM_SYSCOMMAND:
            /* Show the About ... dialog */
            if (wParam == ID_ABOUT){
                lpProc = MakeProcInstance ((FARPROC)About, hInst);
                DialogBox (hInst,
                           "AboutBox",
                           hWnd,
                           lpProc);

                FreeProcInstance (lpProc);
                break;
            }
            else
              return DefWindowProc (hWnd, message, wParam, lParam);

        case WM_COMMAND:
            // LOWORD added for portability
            switch (LOWORD(wParam)){
                 case IDM_EXIT:
                   DestroyWindow (hWnd);
                   break;

                 case IDM_ABOUT:
                   /* Bring up the About.. dialog box */
                   lpProc = MakeProcInstance ((FARPROC)About, hInst);
                   DialogBox (hInst,
                              "AboutBox",
                              hWnd,
                              lpProc);

                   FreeProcInstance (lpProc);
                   break;

                 case IDM_COLOROWNERDR:
                     /* Change colors in color menu depending on state of this
                        menu item. */
                     HandleChangeColors (hWnd);
                     break;

                 case IDM_STATE1:
                 case IDM_STATE2:
                 case IDM_STATE3:
                 case IDM_STATE4:
                      /* Get a handle to the states menu... */
                      hMenu = GetSubMenu (GetMenu (hWnd), IDSTATES_POS);

                      /* Uncheck all the items. */
                      CheckMenuItem (hMenu, IDM_STATE1,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE2,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE3,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE4,
                                     MF_BYCOMMAND | MF_UNCHECKED);

                      /* ...and just check the selected one.*/
                      CheckMenuItem (hMenu, (WORD)wParam,
                                     MF_BYCOMMAND | MF_CHECKED);
                     break;

                 case IDM_BLACK:
                 case IDM_RED:
                 case IDM_BLUE:
                 case IDM_GREEN:
                      /* Get a handle to the Colors menu. */
                      hMenu = GetSubMenu (GetMenu (hWnd),IDCOLORS_POS);

                      /* Uncheck all the items. */
                      CheckMenuItem (hMenu, IDM_BLACK,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_RED,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_BLUE,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_GREEN,
                                     MF_BYCOMMAND | MF_UNCHECKED);

                      /* ...and just check the selected one.*/
                      CheckMenuItem (hMenu, (WORD)wParam,
                                     MF_BYCOMMAND | MF_CHECKED);
                      break;

                 case IDM_FONT:
                      /* Messages sent to us from TrackPopupMenu when
                       * items are selected from the "floating" popups
                       */
                      MessageBox (hWnd,
                                  "A font was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;

                 case IDM_SIZE:
                      MessageBox (hWnd,
                                  "A size was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;

                 case IDM_STYLE:
                      MessageBox (hWnd,
                                  "A style was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;
            }
            break;

        case WM_SIZE:
            if (lParam){
                /* If window is being sized to a non zero value...
                 * invalidate it's client area.
                 */
                InvalidateRect (hWnd, NULL, TRUE);
            }
            break;

        case WM_PAINT:
            HandlePaint (hWnd);
            break;

        case WM_MEASUREITEM:
            /* Use the same width for all items. We could examine the item id
               and use different widths/heights for each item. */
            ((LPMEASUREITEMSTRUCT)lParam)->itemWidth  = MEASUREITEMWIDTH;
            ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = MEASUREITEMHEIGHT;
            return TRUE;

        case WM_DRAWITEM:
            /* Redraw the "colors" menu in normal/ownerdrawmode */
            HandleDrawItem (hWnd,(LPDRAWITEMSTRUCT)lParam);
            return TRUE;
            break;

        case WM_CREATE:
            /* Create the menu */
            HandleCreate (hWnd);
            break;

        case WM_DESTROY:
            /* Delete the on/off bitmaps so that they don't waste memory. */
            DeleteObject (hbmCheckOn);
            DeleteObject (hbmCheckOff);

            PostQuitMessage (0);
            break;

        case WM_LBUTTONDOWN:
            /* Draw the "floating" popup in the app's client area */
            GetClientRect (hWnd, (LPRECT)&rc);

            // Temporary porting macro
            LONG2POINT(lParam, pt);
            if (PtInRect ((LPRECT)&rc, pt))
                HandlePopupMenu (hWnd, pt);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return(0);
}

HBITMAP APIENTRY ShrinkBitmap | ( | HWND | hwnd,
 |  | HBITMAP | hbm
 | ) |  |

Definition at line 201 of file MENU.C.

{
    HDC     hdc;
    HDC     hmemorydcNew;
    HDC     hmemorydcOld;
    LONG    checkMarkSize;
    HBITMAP hCheckBitmap;
    HBITMAP hOldBitmapSave;
    HBITMAP hNewBitmapSave;

    hdc = GetDC (hwnd);

    /* Create DCs for the source (old) and target (new) bitmaps */
    hmemorydcNew = CreateCompatibleDC (hdc);
    hmemorydcOld = CreateCompatibleDC (hdc);

    /* Determine the dimensions of the default menu checkmark and
     * create a target bitmap of the same dimensions
     */
    checkMarkSize = GetMenuCheckMarkDimensions ();
    hCheckBitmap  = CreateCompatibleBitmap (hdc,
                                            LOWORD (checkMarkSize),
                                            HIWORD (checkMarkSize));

    /* Select the source bitmap and the target bitmap into their
     * respective DCs.
     */
    hOldBitmapSave = SelectObject (hmemorydcNew, hCheckBitmap);
    hNewBitmapSave = SelectObject (hmemorydcOld, hbm);

    /* Shrink the source bitmap into the target DC */
    StretchBlt (hmemorydcNew,
                0,
                0,
                LOWORD(checkMarkSize),
                HIWORD(checkMarkSize),
                hmemorydcOld,
                0,
                0,
                64,
                64,
                SRCCOPY);

    /* De-select the bitmaps and clean up .. */
    SelectObject (hmemorydcNew, hOldBitmapSave);
    SelectObject (hmemorydcOld, hNewBitmapSave);
    DeleteDC (hmemorydcNew);
    DeleteDC (hmemorydcOld);
    ReleaseDC (hwnd, hdc);

    /* .. and return a handle to the target bitmap */
    return hCheckBitmap;
}

int APIENTRY WinMain | ( | HANDLE | hInstance,
 |  | HANDLE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 67 of file MENU.C.

{

    HWND  hWnd;
    MSG msg;                                 /* message                      */

    UNREFERENCED_PARAMETER( lpCmdLine );

    /* Register main window class if this is the first instance of the app. */
    if (!hPrevInstance)
        if (!MenuInit (hInstance))
            return 0;

    hInst = hInstance;

    /* Create the app. window */
    hWnd = CreateWindow ("menu",
                         "Menu Example",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         (HWND) NULL,
                         NULL,
                         hInstance,
                         (LPSTR) NULL);

    if (!hWnd)
        return 0;

    ShowWindow (hWnd, nCmdShow);
    UpdateWindow (hWnd);

    while (GetMessage (&msg, NULL, 0, 0)){
        /* Since we have no accelerators, no need to call
         * TranslateAccelerator here.
         */
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }
    return(msg.wParam);
}

Variable Documentation

HMENU hBigMenu

Definition at line 55 of file MENU.C.

HBITMAP hbmCheckOff

Definition at line 57 of file MENU.C.

HBITMAP hbmCheckOn

Definition at line 56 of file MENU.C.

HANDLE hInst

Definition at line 54 of file MENU.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MENU/MENU.H File Reference

  • MENU
Defines | Functions

MENU.H File Reference

Go to the source code of this file.

Defines

#define | ID_ABOUT 100
#define | IDCOLORS_POS 1
#define | IDFILE_POS 0
#define | IDHELP_POS 3
#define | IDM_ABOUT 203
#define | IDM_BLACK 501
#define | IDM_BLUE 502
#define | IDM_COLOROWNERDR 500
#define | IDM_EXIT 202
#define | IDM_FONT 600
#define | IDM_GREEN 504
#define | IDM_RED 503
#define | IDM_SIZE 601
#define | IDM_STATE1 610
#define | IDM_STATE2 611
#define | IDM_STATE3 612
#define | IDM_STATE4 613
#define | IDM_STYLE 602
#define | IDSTATES_POS 2
#define | LONG2POINT(l, pt) ((pt).x = (INT)LOWORD(l), (pt).y = (INT)HIWORD(l))
#define | MEASUREITEMHEIGHT 40
#define | MEASUREITEMWIDTH 40
#define | ROP_PSDPxax 0x00B8074AL

Functions

BOOL APIENTRY | About (HWND, UINT, UINT, LONG)
BOOL NEAR PASCAL | MenuInit (HANDLE)
LONG APIENTRY | MenuWndProc (HWND, UINT, UINT, LONG)

Define Documentation

#define ID_ABOUT 100

Definition at line 29 of file MENU.H.

#define IDCOLORS_POS 1

Definition at line 21 of file MENU.H.

#define IDFILE_POS 0

Definition at line 20 of file MENU.H.

#define IDHELP_POS 3

Definition at line 23 of file MENU.H.

#define IDM_ABOUT 203

Definition at line 33 of file MENU.H.

#define IDM_BLACK 501

Definition at line 37 of file MENU.H.

#define IDM_BLUE 502

Definition at line 38 of file MENU.H.

#define IDM_COLOROWNERDR 500

Definition at line 36 of file MENU.H.

#define IDM_EXIT 202

Definition at line 32 of file MENU.H.

#define IDM_FONT 600

Definition at line 43 of file MENU.H.

#define IDM_GREEN 504

Definition at line 40 of file MENU.H.

#define IDM_RED 503

Definition at line 39 of file MENU.H.

#define IDM_SIZE 601

Definition at line 44 of file MENU.H.

#define IDM_STATE1 610

Definition at line 48 of file MENU.H.

#define IDM_STATE2 611

Definition at line 49 of file MENU.H.

#define IDM_STATE3 612

Definition at line 50 of file MENU.H.

#define IDM_STATE4 613

Definition at line 51 of file MENU.H.

#define IDM_STYLE 602

Definition at line 45 of file MENU.H.

#define IDSTATES_POS 2

Definition at line 22 of file MENU.H.

#define LONG2POINT | ( | l,
 |  | pt |
 | ) |  | ((pt).x = (INT)LOWORD(l), (pt).y = (INT)HIWORD(l))

Definition at line 16 of file MENU.H.

#define MEASUREITEMHEIGHT 40

Definition at line 26 of file MENU.H.

#define MEASUREITEMWIDTH 40

Definition at line 25 of file MENU.H.

#define ROP_PSDPxax 0x00B8074AL

Definition at line 54 of file MENU.H.

Function Documentation

BOOL APIENTRY About | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL NEAR PASCAL MenuInit ( HANDLE )

Definition at line 127 of file MENU.C.

{
    HANDLE    hMemory;
    PWNDCLASS pWndClass;
    BOOL      bSuccess;

    /* Initialize the menu window class */
    hMemory   = LocalAlloc(LPTR, sizeof(WNDCLASS));
    if(!hMemory){
        MessageBox(NULL, "<MenuInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
        return(FALSE);
    }

    pWndClass = (PWNDCLASS) LocalLock(hMemory);

    pWndClass->style         = 0;
    pWndClass->lpfnWndProc   = (WNDPROC) MenuWndProc;
    pWndClass->hInstance     = hInstance;
    pWndClass->hIcon         = LoadIcon (hInstance, "menu");
    pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
    pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
    pWndClass->lpszMenuName  = (LPSTR) "MenuMenu",
    pWndClass->lpszClassName = (LPSTR) "menu";

    bSuccess = RegisterClass (pWndClass);
    LocalUnlock (hMemory);
    LocalFree (hMemory);

    return bSuccess;
}

LONG APIENTRY MenuWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 540 of file MENU.C.

{
    FARPROC lpProc;
    HMENU hMenu;
    RECT rc;
    POINT pt;

    switch (message){
        case WM_SYSCOMMAND:
            /* Show the About ... dialog */
            if (wParam == ID_ABOUT){
                lpProc = MakeProcInstance ((FARPROC)About, hInst);
                DialogBox (hInst,
                           "AboutBox",
                           hWnd,
                           lpProc);

                FreeProcInstance (lpProc);
                break;
            }
            else
              return DefWindowProc (hWnd, message, wParam, lParam);

        case WM_COMMAND:
            // LOWORD added for portability
            switch (LOWORD(wParam)){
                 case IDM_EXIT:
                   DestroyWindow (hWnd);
                   break;

                 case IDM_ABOUT:
                   /* Bring up the About.. dialog box */
                   lpProc = MakeProcInstance ((FARPROC)About, hInst);
                   DialogBox (hInst,
                              "AboutBox",
                              hWnd,
                              lpProc);

                   FreeProcInstance (lpProc);
                   break;

                 case IDM_COLOROWNERDR:
                     /* Change colors in color menu depending on state of this
                        menu item. */
                     HandleChangeColors (hWnd);
                     break;

                 case IDM_STATE1:
                 case IDM_STATE2:
                 case IDM_STATE3:
                 case IDM_STATE4:
                      /* Get a handle to the states menu... */
                      hMenu = GetSubMenu (GetMenu (hWnd), IDSTATES_POS);

                      /* Uncheck all the items. */
                      CheckMenuItem (hMenu, IDM_STATE1,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE2,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE3,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_STATE4,
                                     MF_BYCOMMAND | MF_UNCHECKED);

                      /* ...and just check the selected one.*/
                      CheckMenuItem (hMenu, (WORD)wParam,
                                     MF_BYCOMMAND | MF_CHECKED);
                     break;

                 case IDM_BLACK:
                 case IDM_RED:
                 case IDM_BLUE:
                 case IDM_GREEN:
                      /* Get a handle to the Colors menu. */
                      hMenu = GetSubMenu (GetMenu (hWnd),IDCOLORS_POS);

                      /* Uncheck all the items. */
                      CheckMenuItem (hMenu, IDM_BLACK,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_RED,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_BLUE,
                                     MF_BYCOMMAND | MF_UNCHECKED);
                      CheckMenuItem (hMenu, IDM_GREEN,
                                     MF_BYCOMMAND | MF_UNCHECKED);

                      /* ...and just check the selected one.*/
                      CheckMenuItem (hMenu, (WORD)wParam,
                                     MF_BYCOMMAND | MF_CHECKED);
                      break;

                 case IDM_FONT:
                      /* Messages sent to us from TrackPopupMenu when
                       * items are selected from the "floating" popups
                       */
                      MessageBox (hWnd,
                                  "A font was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;

                 case IDM_SIZE:
                      MessageBox (hWnd,
                                  "A size was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;

                 case IDM_STYLE:
                      MessageBox (hWnd,
                                  "A style was selected",
                                  "Popup Menu Alert",
                                  MB_APPLMODAL|MB_OK);
                      break;
            }
            break;

        case WM_SIZE:
            if (lParam){
                /* If window is being sized to a non zero value...
                 * invalidate it's client area.
                 */
                InvalidateRect (hWnd, NULL, TRUE);
            }
            break;

        case WM_PAINT:
            HandlePaint (hWnd);
            break;

        case WM_MEASUREITEM:
            /* Use the same width for all items. We could examine the item id
               and use different widths/heights for each item. */
            ((LPMEASUREITEMSTRUCT)lParam)->itemWidth  = MEASUREITEMWIDTH;
            ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = MEASUREITEMHEIGHT;
            return TRUE;

        case WM_DRAWITEM:
            /* Redraw the "colors" menu in normal/ownerdrawmode */
            HandleDrawItem (hWnd,(LPDRAWITEMSTRUCT)lParam);
            return TRUE;
            break;

        case WM_CREATE:
            /* Create the menu */
            HandleCreate (hWnd);
            break;

        case WM_DESTROY:
            /* Delete the on/off bitmaps so that they don't waste memory. */
            DeleteObject (hbmCheckOn);
            DeleteObject (hbmCheckOff);

            PostQuitMessage (0);
            break;

        case WM_LBUTTONDOWN:
            /* Draw the "floating" popup in the app's client area */
            GetClientRect (hWnd, (LPRECT)&rc);

            // Temporary porting macro
            LONG2POINT(lParam, pt);
            if (PtInRect ((LPRECT)&rc, pt))
                HandlePopupMenu (hWnd, pt);
            break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return(0);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/MINREC.C File Reference

  • MINREC
Data Structures | Defines | Typedefs | Functions

MINREC.C File Reference

#include <Windows.H>
#include "MinRec.H"
#include "RecHook.H"

Go to the source code of this file.

Data Structures

struct | GLOBAL_STRUCT

Defines

#define | ERROR_BUFFER_SIZE 512
#define | STRICT

Typedefs

typedef struct GLOBAL_STRUCT | GLOBAL
typedef struct GLOBAL_STRUCT * | PGLOBAL

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
BOOL | ErrorMessageBox (LPCTSTR, LPCTSTR, LPCTSTR, INT)
BOOL CALLBACK | MainDlgProc (HWND, UINT, WPARAM, LPARAM)
INT PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT nCmdShow)

Define Documentation

#define ERROR_BUFFER_SIZE 512
#define STRICT

Definition at line 15 of file MINREC.C.

Typedef Documentation

typedef struct GLOBAL_STRUCT GLOBAL
typedef struct GLOBAL_STRUCT * PGLOBAL

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hDlg,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 262 of file MINREC.C.

{
  switch( uMsg ) {

    case WM_COMMAND:
      switch( LOWORD(wParam) ) {

        case IDOK:
          EndDialog( hDlg, TRUE );
          return( TRUE );

        case IDCANCEL:
          EndDialog( hDlg, FALSE );
          return( TRUE );
      }
      break;

    case WM_INITDIALOG:
      return( TRUE );

    case WM_CLOSE:
      return( TRUE );

  }

  return( FALSE );
  UNREFERENCED_PARAMETER( lParam );
}

BOOL ErrorMessageBox | ( | LPCTSTR | lpszText,
 |  | LPCTSTR | lpszTitle,
 |  | LPCTSTR | lpszFile,
 |  | INT | Line
 | ) |  |

Definition at line 301 of file MINREC.C.

{
  #define ERROR_BUFFER_SIZE 512

  static TCHAR szMessageFormat[] =
    TEXT( "%s\n"                                           )
    TEXT( "\n"                                             )
    TEXT( "-- Error Information --\n"                      )
    TEXT( "File : %s\n"                                    )
    TEXT( "Line : %d\n"                                    )
    TEXT( "Error Number : %d\n"                            )
    TEXT( "Error Message : %s\n"                           )
    TEXT( "\n"                                             )
    TEXT( "Press OK to terminate this application.\n"      )
    TEXT( "Press Cancel to ignore the error and continue." );

  LPTSTR lpFormatMessageBuffer;
  DWORD  dwFormatMessage;
  DWORD  dwGetLastError;
  HLOCAL hMessageBoxBuffer;
  LPVOID lpMessageBoxBuffer;

  // get the system error
  dwGetLastError = GetLastError();

  // perform a simple check on the needed buffer size
  if( lstrlen(lpszText) > (ERROR_BUFFER_SIZE - lstrlen(szMessageFormat)) )
    return( FALSE );

  // allocate the message box buffer
  hMessageBoxBuffer  = LocalAlloc( LMEM_MOVEABLE, ERROR_BUFFER_SIZE );
  lpMessageBoxBuffer = LocalLock( hMessageBoxBuffer );

  // get the system error message
  dwFormatMessage = FormatMessage(
                      FORMAT_MESSAGE_ALLOCATE_BUFFER
                      | FORMAT_MESSAGE_FROM_SYSTEM,
                      NULL, dwGetLastError, LANG_NEUTRAL,
                      (LPTSTR) &lpFormatMessageBuffer, 0, NULL );
  if( !dwFormatMessage )
    lpFormatMessageBuffer = TEXT("FormatMessage() failed!");

  // format the error messge box string
  wsprintf( lpMessageBoxBuffer, szMessageFormat, lpszText, lpszFile,
    Line, dwGetLastError, lpFormatMessageBuffer );

  // -- display the error and allow the user to terminate or continue
  if( MessageBox( NULL, lpMessageBoxBuffer, lpszTitle,
        MB_APPLMODAL | MB_ICONSTOP | MB_OKCANCEL | MB_SETFOREGROUND ) == IDOK )
    ExitProcess( 0 );

  // free all buffers
  if( dwFormatMessage )
    LocalFree( (HLOCAL) lpFormatMessageBuffer );
  LocalFree( (HLOCAL) hMessageBoxBuffer );

  return( TRUE );
}

BOOL CALLBACK MainDlgProc | ( | HWND | hWnd,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 176 of file MINREC.C.

{
  switch( uMsg ) {

    case WM_CREATE:
      // Register the Playback (Ctrl+P) and Record (Ctrl+R) hot keys
      RegisterHotKey( hWnd, IDM_MACRO_PLAYBACK, MOD_CONTROL, 'P' );
      RegisterHotKey( hWnd, IDM_MACRO_RECORD, MOD_CONTROL, 'R' );
      return( TRUE );

    case WM_COMMAND:
      switch( LOWORD(wParam) ) {

        case IDM_FILE_EXIT:
          PostMessage( hWnd, WM_CLOSE, (WPARAM) 0, (LPARAM) 0 );
          return( TRUE );

        case IDM_MACRO_PLAYBACK:
          StartJournalPlayback();
          return( TRUE );

        case IDM_MACRO_RECORD:
          StartJournalRecord();
          return( TRUE );

        case IDM_MACRO_STOP:
          StopAllJournalling();
          return( TRUE );

        case IDM_HELP_ABOUT:
          if( DialogBox( Global.hInstance, TEXT( "AboutDlgBox" ),
                hWnd, AboutDlgProc ) == -1 ) {
            ErrorMessageBox( TEXT("DialogBox()"),
              Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
          }
          return( TRUE );

      }
      break;

    case WM_SYSCOMMAND:
      switch( LOWORD(wParam) ) {
        // return a nonzero value to disable the screen saver
        case SC_SCREENSAVE:
          return( TRUE );
      }
      break;

    case WM_HOTKEY:
      PostMessage( hWnd, WM_COMMAND, wParam, lParam );
      return( TRUE );

    case WM_CLOSE:
      // Unregister the Playback (Ctrl+P) and Record (Ctrl+R) hot keys
      if( !UnregisterHotKey( hWnd, IDM_MACRO_PLAYBACK ) ) {
        ErrorMessageBox( TEXT("UnregisterHotKey()"),
          Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
      }
      if( !UnregisterHotKey( hWnd, IDM_MACRO_RECORD ) ) {
        ErrorMessageBox( TEXT("UnregisterHotKey()"),
          Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
      }
      DestroyWindow( Global.hDlgMain );
      Global.hDlgMain = NULL;
      PostQuitMessage( FALSE );
      return( TRUE );
  }

  return( DefDlgProc( hWnd, uMsg, wParam, lParam )  );
}

INT PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpszCmdLine,
 |  | INT | nCmdShow
 | ) |  |

Definition at line 53 of file MINREC.C.

{
  MSG     Msg;
  HACCEL  hAccel;
  LPCTSTR lpszClassName   = TEXT( "MinRecClass" );
  LPCTSTR lpszMenuName    = TEXT( "MinRecMenu"  );
  LPCTSTR lpszIconName    = TEXT( "MinRecIcon"  );
  LPCTSTR lpszAccelName   = TEXT( "MinRecAccel" );

  // Check to see if this is running on Windows 95 or Windows NT.  If not
  // display a message and exit.
  if( (GetVersion() >= 0x80000000) && (LOBYTE(LOWORD(GetVersion())) < 4) )
  {
      MessageBoxA( NULL,
      "This sample application cannot be run on Windows 3.1.\n"
      "This application will now terminate.",
      "MinRec",
      MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
    return( 1 );
  }

  Global.hInstance        = hInstance;
  Global.lpszApiFailedMsg = TEXT( "A Windows API Failed" );

  // allow only one instance of MinRec to be active
  // (especially since this makes handling of hot keys easier)
  Global.hMutex = CreateMutex( NULL, TRUE, TEXT("MinRec") );
  switch( GetLastError() ) {

    case ERROR_ALREADY_EXISTS: {
      MessageBox( NULL,
        TEXT( "Sorry, only one instance of MinRec\n"   )
        TEXT( "can be running at any given time.\n"    )
        TEXT( "This application will now terminate."   ),
        TEXT( "MinRec - Multiple Instances Detected!!" ),
        MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
      return( 1 );
    }

    case NO_ERROR:
      break;

    default:
      ErrorMessageBox( TEXT("CreateMutex()"),
        Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );

  }

  // register the window class
  {
    WNDCLASS WndClass;

    WndClass.style         = (UINT) NULL;
    WndClass.lpfnWndProc   = (WNDPROC) MainDlgProc;
    WndClass.cbClsExtra    = (int) NULL;
    WndClass.cbWndExtra    = DLGWINDOWEXTRA;
    WndClass.hInstance     = hInstance;
    WndClass.hIcon         = LoadIcon( Global.hInstance, lpszIconName );
    WndClass.hCursor       = LoadCursor( NULL, IDC_ARROW );
    WndClass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
    WndClass.lpszMenuName  = lpszMenuName;
    WndClass.lpszClassName = lpszClassName;

    if( !RegisterClass(&WndClass) ) {
      ErrorMessageBox( TEXT("RegisterClass()"),
        Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
    }
  }

  // Create a main dialog window for this application instance
  Global.hDlgMain = CreateDialog( Global.hInstance, TEXT("MainDlgBox"),
                      NULL, NULL );

  // If window could not be created, return "failure"
  if( !Global.hDlgMain ) {
    ErrorMessageBox( TEXT("CreateDialog()"),
      Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
  }

  // Load main menu accelerators
  if( !(hAccel = LoadAccelerators( Global.hInstance, lpszAccelName) ) ) {
    ErrorMessageBox( TEXT("LoadAccelerators()"),
      Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
  }

  // Make the window visible; update its client area; and return "success"
  ShowWindow( Global.hDlgMain, SW_SHOWDEFAULT );  // Show the window

  // Acquire and dispatch messages until a WM_QUIT message is received.
  while( GetMessage( &Msg, NULL, 0, 0 ) ) {
    if( !TranslateAccelerator( Global.hDlgMain, hAccel, &Msg ) ) {
      if( !IsDialogMessage( Global.hDlgMain, &Msg ) ) {
        TranslateMessage( &Msg );     // Translates virtual key codes
        DispatchMessage( &Msg );      // Dispatches message to window
      }
    }
  }

  // close the mutex handle
  if( !CloseHandle( Global.hMutex ) ) {
    ErrorMessageBox( TEXT("CloseHandle()"),
      Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
  }

  return( Msg.wParam );           // Returns the value from PostQuitMessage
  UNREFERENCED_PARAMETER( lpszCmdLine );  // avoid the warning
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/MINREC.H File Reference

  • MINREC
Defines

MINREC.H File Reference

Go to the source code of this file.

Defines

#define | IDM_FILE_EXIT 199
#define | IDM_HELP_ABOUT 205
#define | IDM_MACRO_PLAYBACK 801
#define | IDM_MACRO_RECORD 802
#define | IDM_MACRO_STOP 803
#define | IDS_APPNAME 1000
#define | IDS_SHORT_APPNAME 1001

Define Documentation

#define IDM_FILE_EXIT 199

Definition at line 12 of file MINREC.H.

#define IDM_HELP_ABOUT 205

Definition at line 18 of file MINREC.H.

#define IDM_MACRO_PLAYBACK 801

Definition at line 14 of file MINREC.H.

#define IDM_MACRO_RECORD 802

Definition at line 15 of file MINREC.H.

#define IDM_MACRO_STOP 803

Definition at line 16 of file MINREC.H.

#define IDS_APPNAME 1000

Definition at line 21 of file MINREC.H.

#define IDS_SHORT_APPNAME 1001

Definition at line 22 of file MINREC.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/RECHOOK.C File Reference

  • MINREC
Data Structures | Defines | Typedefs | Functions

RECHOOK.C File Reference

#include <Windows.H>
#include "RecHook.H"
#include "MinRec.H"

Go to the source code of this file.

Data Structures

struct | EVENTHEADER_STRUCT
struct | GLOBAL_STRUCT

Defines

#define | MINREC_FILENAME TEXT("MinRec.Rec")
#define | MINREC_SIGNATURE "MinRec\0"
#define | STRICT

Typedefs

typedef struct EVENTHEADER_STRUCT | EVENTHEADER
typedef struct GLOBAL_STRUCT | GLOBAL
typedef struct EVENTHEADER_STRUCT * | PEVENTHEADER
typedef struct GLOBAL_STRUCT * | PGLOBAL

Functions

BOOL WINAPI | DllMain (HINSTANCE hInstanceDll, DWORD dwReason, LPVOID lpvReserved)
LRESULT CALLBACK | GetMsgProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | JournalPlaybackProc (int, WPARAM, LPARAM)
LRESULT CALLBACK | JournalRecordProc (int, WPARAM, LPARAM)
BOOL | StartJournalPlayback ()
BOOL | StartJournalRecord ()
BOOL | StopAllJournalling ()
BOOL | StopJournalPlayback ()
BOOL | StopJournalRecord ()

Define Documentation

#define MINREC_FILENAME TEXT("MinRec.Rec")

Definition at line 33 of file RECHOOK.C.

#define MINREC_SIGNATURE "MinRec\0"

Definition at line 34 of file RECHOOK.C.

#define STRICT

Definition at line 19 of file RECHOOK.C.

Typedef Documentation

typedef struct EVENTHEADER_STRUCT EVENTHEADER
typedef struct GLOBAL_STRUCT GLOBAL
typedef struct EVENTHEADER_STRUCT * PEVENTHEADER
typedef struct GLOBAL_STRUCT * PGLOBAL

Function Documentation

BOOL WINAPI DllMain | ( | HINSTANCE | hInstanceDll,
 |  | DWORD | dwReason,
 |  | LPVOID | lpvReserved
 | ) |  |

Definition at line 80 of file RECHOOK.C.

{
  switch( dwReason ) {

    case DLL_PROCESS_ATTACH:
      Global.fRecording    = FALSE;
      Global.fPlaying      = FALSE;
      Global.hInstance     = hInstanceDll;
      break;

  }

  return( TRUE );
  UNREFERENCED_PARAMETER( lpvReserved );
}

LRESULT CALLBACK GetMsgProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 472 of file RECHOOK.C.

{
  // if nCode < 0 we must immediately return the result of CallNextHookEx.
  if( nCode < 0  )
    return( CallNextHookEx( Global.hHookGetMsg, nCode, wParam, lParam ) );

  switch( ((LPMSG)lParam)->message ) {

    // user pressed Ctrl+Esc, Alt+Esc or Ctrl+Alt+Del, the system will
    // automatically stop all journalling.  Thus we display a message that
    // this has resulted in the termination of the Jorunalling since the
    // user may not expect this to occur with these key events.
    case WM_CANCELJOURNAL:
      StopAllJournalling();
      MessageBox( NULL,
        TEXT( "The user has pressed either\n"            )
        TEXT( "Ctrl+Esc, Alt+Esc or Ctrl+Alt+Del\n"      )
        TEXT( "and thus the system has automatically\n"  )
        TEXT( "canceled all journalling.\n"              ),
        TEXT( "MinRec - Notice!"                         ),
        MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
      break;

  }

  return( CallNextHookEx( Global.hHookGetMsg, nCode, wParam, lParam ) );
  UNREFERENCED_PARAMETER( wParam );
}

LRESULT CALLBACK JournalPlaybackProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 341 of file RECHOOK.C.

{
  // if nCode < 0 or is set Global.fStopPlaying we must immediately return
  // the result of CallNextHookEx.
  if( nCode < 0 || Global.fStopPlaying )
    return( CallNextHookEx( Global.hHookPlayback, nCode, wParam, lParam ) );

  switch( nCode ) {

    // HC_GETNEXT occurs when Windows requests the next system message
    // queue message.  If we return 0 it will place the message found in
    // lParam into the system message queue otherwise it will sleep
    // for the specified number of milliseconds returned and then later
    // call JournalPlaybackProc with nCode set, again, to HC_GETNEXT.
    case HC_GETNEXT: {
      LRESULT SleepTime;

      // determine the amount of time Windows must sleep before
      // it should place this message into the system message queue.
      SleepTime = Global.EventMsg.time - Global.LastMsgTime;

      // copy the current ready system message to lParam
      CopyMemory( (PVOID) lParam, (CONST VOID*) &(Global.EventMsg),
        sizeof(EVENTMSG) );

      // store the value of the next system message post time so we can
      // use this value to set SleepTime to 0 on the next HC_GETNEXT
      Global.LastMsgTime = Global.EventMsg.time;

      return( SleepTime );
    }

    // HC_SKIP occurs only after Windows has processed a HC_GETNEXT
    // condition that returned 0.  We can use this to prepare the next
    // ready system message to be posted or deterimine of there are no
    // remaining system messages to post and thus stop the playback.
    case HC_SKIP: {
      if( ++Global.PlayedMsgCount > Global.RecordedMsgCount ) {
        StopJournalPlayback();
        break;
        // return( (LRESULT) 0L );
      }
      else {
        DWORD dwBytesRead;

        // Get the next ready message from the file and store it
        // in the global buffer for the next HC_GETNEXT
        ReadFile( Global.hFile, (LPVOID) &(Global.EventMsg), sizeof(EVENTMSG),
          &dwBytesRead, NULL );
        // fall through and call CallNextHookEx
        // return( (LRESULT) 0L );
        break;

      }
    }

    // A system-modal dialog box is being displayed. Until the dialog box
    // is destroyed, the hook procedure must stop playing back messages.
    case HC_SYSMODALON:
      Global.fStopPlaying = TRUE;
      break;

    // A system-modal dialog box has been destroyed. The hook
    // procedure must resume playing back the messages.
    case HC_SYSMODALOFF:
      Global.fStopPlaying = FALSE;
      break;

  }

  return( CallNextHookEx( Global.hHookPlayback, nCode, wParam, lParam ) );
  UNREFERENCED_PARAMETER( wParam );
}

LRESULT CALLBACK JournalRecordProc | ( | int | nCode,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 142 of file RECHOOK.C.

{
  // if nCode < 0 or is set Global.fStopRecording we must immediately return
  // the result of CallNextHookEx.
  if( nCode < 0 || Global.fStopRecording )
    return( CallNextHookEx( Global.hHookRecord, nCode, wParam, lParam ) );

  switch( nCode ) {

    // The lParam parameter points to an EVENTMSG structure
    // containing information about a message removed from the system
    // queue.  The hook procedure must record the contents of the structure
    // by copying them to the Recorded Journal file.
    case HC_ACTION: {
      LPEVENTMSG lpEventMsg;
      DWORD      dwBytesWritten;

      lpEventMsg = (LPEVENTMSG) lParam;

      // user pressed Ctrl+Break.  We use this as a request to cancel
      // journal recording.  We wont display a message to the user here
      // since this is an action the user choose to do.
      if( (lpEventMsg->message == WM_KEYDOWN)
           && (LOBYTE(lpEventMsg->paramL) == VK_CANCEL) ) {
        StopAllJournalling();
      }
      else {
        // write the event message to the Recorded Journal file
        WriteFile( Global.hFile, (LPCSTR) lParam, sizeof(EVENTMSG),
          &dwBytesWritten, NULL );
        if( ++Global.RecordedMsgCount == 1)
          Global.BaseMsgTime = lpEventMsg->time;
      }
      break;
    }

    // A system-modal dialog box is being displayed. Until the dialog box
    // is destroyed, the hook procedure must stop recording.
    case HC_SYSMODALON:
      Global.fStopRecording = TRUE;
      break;

    // A system-modal dialog box has been destroyed. The hook
    // procedure must resume recording.
    case HC_SYSMODALOFF:
      Global.fStopRecording = FALSE;
      break;

  }

  return( CallNextHookEx( Global.hHookRecord, nCode, wParam, lParam ) );
  UNREFERENCED_PARAMETER( wParam );
}

BOOL StartJournalPlayback ( )

Definition at line 243 of file RECHOOK.C.

{
  EVENTHEADER EventHeader;
  DWORD       dwBytesRead;

  // Allow infinite playback loop
  if( Global.fRecording ) {
    StopJournalRecord();
    MessageBox( NULL,
      TEXT( "Infinite playback\n" )
      TEXT( "loop recorded!"      ),
      TEXT( "MinRec - Notice!"    ),
      MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
    return( FALSE );
  }

  if( Global.fPlaying ) {
    StopJournalPlayback();
  }

  // Open Recorded Journal file
  Global.hFile = CreateFile( (LPCTSTR) MINREC_FILENAME, GENERIC_READ,
                       0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  if( Global.hFile == INVALID_HANDLE_VALUE ) {
    MessageBox( NULL,
      TEXT( "The default Journal Record File\n" )
      TEXT( "MINREC.REC could not be found.\n"  ),
      TEXT( "MinRec - Error!"                   ),
      MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
    return( FALSE );
  }

  // Quick check, file size should be at least the length of the header
  if( GetFileSize( Global.hFile, NULL ) < sizeof(EVENTHEADER) ) {
    MessageBox( NULL,
      TEXT( "The file MINREC.REC is not a \n"     )
      TEXT( "valid MinRec Journal Record file.\n" ),
      TEXT( "MinRec - Error!"                     ),
      MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
    return( FALSE );
  }

  // Read Recorded Journal file header
  SetFilePointer( Global.hFile, 0L, NULL, FILE_BEGIN );
  ReadFile( Global.hFile, (LPVOID) &EventHeader, sizeof(EVENTHEADER),
        &dwBytesRead, NULL );

  // Quick check, the signature of the file must be "MinRec"
  if( lstrcmpA( EventHeader.Signature, MINREC_SIGNATURE ) != 0 ) {
    MessageBox( NULL,
      TEXT( "The file MINREC.REC does not\n"    )
      TEXT( "contain a valid MinRec signature." ),
      TEXT( "MinRec - Error!"                   ),
      MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
     return( FALSE );
  }

  // Store the header values
  Global.RecordedMsgCount = EventHeader.RecordedMsgCount;
  Global.BaseMsgTime      = EventHeader.BaseMsgTime;
  Global.LastMsgTime      = EventHeader.BaseMsgTime;

  // If no messages were recorded, none to play back.
  if( Global.RecordedMsgCount == 0 ) {
    MessageBox( NULL,
      TEXT( "Sorry, nothing was recorded, so\n")
      TEXT( "there is nothing to playback."    ),
      TEXT( "MinRec - Notice!"                 ),
      MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
     return( FALSE );
  }

  // Initialize the played message count to zero and set the play flag
  Global.PlayedMsgCount = 0;
  Global.fPlaying       = TRUE;

  // Get the first recorded message from the file and store it
  ReadFile( Global.hFile, (LPVOID) &(Global.EventMsg), sizeof(EVENTMSG),
        &dwBytesRead, NULL );

  // Set the GetMsg hook to trap Ctrl+Break, Ctrl+Esc and Ctrl+Alt+Del.
  Global.hHookGetMsg = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
                         Global.hInstance, 0 );

  // Set the Journal Playback hook
  Global.hHookPlayback = SetWindowsHookEx( WH_JOURNALPLAYBACK,
                           JournalPlaybackProc, Global.hInstance, 0 );

  return( TRUE );
}

BOOL StartJournalRecord ( )

Definition at line 102 of file RECHOOK.C.

{
  // Do not allow recording while playing back
  if( Global.fPlaying ) {
    MessageBox( NULL,
      TEXT( "Sorry, recording while\n" )
      TEXT( "playing is not allowed."  ),
      TEXT( "MinRec - Notice!"         ),
      MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
    return( FALSE );
  }

  // Create and open the journal record file and set the file pointer to
  //  just past the journal record file header
  Global.hFile = CreateFile( (LPCTSTR) MINREC_FILENAME, GENERIC_WRITE,
                       0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  SetFilePointer( Global.hFile, (LONG) sizeof(EVENTHEADER), NULL, FILE_BEGIN );

  // Initialize the recorded message count to zero and set recording flag
  Global.RecordedMsgCount = 0;
  Global.fRecording       = TRUE;

  // Set the GetMsg hook to trap Ctrl+Esc, Alt+Esc and Ctrl+Alt+Del.
  Global.hHookGetMsg = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
                         Global.hInstance, 0 );

  // Set the Journal Record hook.
  Global.hHookRecord = SetWindowsHookEx( WH_JOURNALRECORD, JournalRecordProc,
                         Global.hInstance, 0 );

  return( TRUE );
}

BOOL StopAllJournalling ( )

Definition at line 449 of file RECHOOK.C.

{
  if( Global.fRecording )
    StopJournalRecord();
  if( Global.fPlaying )
    StopJournalPlayback();

  return( TRUE );
}

BOOL StopJournalPlayback ( )

Definition at line 421 of file RECHOOK.C.

{
  // Remove the Playback Journal hook if playing
  if( Global.fPlaying ) {

    // remove the playback hook
    UnhookWindowsHookEx( Global.hHookPlayback );

    // remove the get message hook
    UnhookWindowsHookEx( Global.hHookGetMsg );

    // close the journal record file
    CloseHandle( Global.hFile );

    // Clear playback flag
    Global.fPlaying = FALSE;
  }

  return( TRUE );
}

BOOL StopJournalRecord ( )

Definition at line 203 of file RECHOOK.C.

{
  EVENTHEADER EventHeader;

  // Remove the Journal Record hook if recording
  if( Global.fRecording ) {
    DWORD dwBytesWritten;

    // remove the record hook
    UnhookWindowsHookEx( Global.hHookRecord );

    // remove the get message hook
    UnhookWindowsHookEx( Global.hHookGetMsg );

    // Copy Recorded Journal header data to temporary buffer
    lstrcpyA( EventHeader.Signature, MINREC_SIGNATURE );
    EventHeader.RecordedMsgCount = Global.RecordedMsgCount;
    EventHeader.BaseMsgTime      = Global.BaseMsgTime;

    // Open Recorded Journal file and update the file header and close
    //  the file
    SetFilePointer( Global.hFile, 0, NULL, FILE_BEGIN );
    WriteFile( Global.hFile, (LPCSTR) &EventHeader, sizeof(EVENTHEADER),
      &dwBytesWritten, NULL );
    CloseHandle( Global.hFile );

    // Clear recording flag
    Global.fRecording = FALSE;
  }

  return( TRUE );
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/RECHOOK.H File Reference

  • MINREC
Functions

RECHOOK.H File Reference

Go to the source code of this file.

Functions

BOOL | StartJournalPlayback (VOID)
BOOL | StartJournalRecord (VOID)
BOOL | StopAllJournalling (VOID)
BOOL | StopJournalPlayback (VOID)
BOOL | StopJournalRecord (VOID)

Function Documentation

BOOL StartJournalPlayback ( VOID )
BOOL StartJournalRecord ( VOID )
BOOL StopAllJournalling ( VOID )
BOOL StopJournalPlayback ( VOID )
BOOL StopJournalRecord ( VOID )
Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/ABOUT.C File Reference

  • NETDDE
Defines | Functions | Variables

ABOUT.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"

Go to the source code of this file.

Defines

#define | POINTSIZE 8

Functions

LRESULT CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
LRESULT | CmdAbout (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdAboutDone (HWND, WORD, WORD, HWND)
LRESULT | MsgAboutCommand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgAboutInit (HWND, UINT, WPARAM, LPARAM)

Variables

CMDI cmdiAbout
HFONT | hFontCopyright
MSDI msdiAbout
CMD rgcmdAbout []
MSD rgmsdAbout []

Define Documentation

#define POINTSIZE 8

Function Documentation

LRESULT CALLBACK About | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 126 of file ABOUT.C.

{
    return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
}

LRESULT CmdAbout | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 96 of file ABOUT.C.

{
    DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
    return 0;
}

LRESULT CmdAboutDone | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 273 of file ABOUT.C.

{
    if (hFontCopyright)
       DeleteObject(hFontCopyright);

    EndDialog(hdlg, TRUE);          // Exit the dialog
    return TRUE;
}

LRESULT MsgAboutCommand | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 247 of file ABOUT.C.

{
    return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
}

LRESULT MsgAboutInit | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 151 of file ABOUT.C.

{
    #define POINTSIZE 8

    char  szFullPath[256];
    DWORD dwVerHnd;
    DWORD dwVerInfoSize;
    HDC   hDC;
    int   iLogPixelsY, iPointSize;

    // Center the dialog over the application window
    CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));

    // Set the copyright font to something smaller than default
    hDC = GetDC(hdlg);
    iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
    ReleaseDC(hdlg, hDC);
    iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
    iPointSize *= -1;

    hFontCopyright = CreateFont(iPointSize,
                                0, 0, 0,
                                FW_BOLD,
                                0, 0, 0, 0,
                                0, 0, 0, 0,
                                "Arial");

    SendDlgItemMessage(hdlg,
                       IDD_VERLAST,
                       WM_SETFONT,
                       (WPARAM)hFontCopyright,
                       0L);

    // Get version information from the application
    GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
    dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
    if (dwVerInfoSize)
    {
        // If we were able to get the information, process it:
        HANDLE  hMem;
        LPVOID  lpvMem;
        char    szGetName[256];
        int     cchRoot;
        int     i;

        hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
        lpvMem = GlobalLock(hMem);
        GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
        lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
        cchRoot = lstrlen(szGetName);

        // Walk through the dialog items that we want to replace:
        for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
        {
            BOOL  fRet;
            UINT  cchVer = 0;
            LPSTR lszVer = NULL;
            char  szResult[256];

            GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
            lstrcpy(&szGetName[cchRoot], szResult);
            fRet = VerQueryValue(lpvMem, szGetName, &lszVer, &cchVer);

            if (fRet && cchVer && lszVer)
            {
                // Replace dialog item text with version info
                lstrcpy(szResult, lszVer);
                SetDlgItemText(hdlg, i, szResult);
            }
        }
        GlobalUnlock(hMem);
        GlobalFree(hMem);
    }
    return TRUE;
}

Variable Documentation

CMDI cmdiAbout
Initial value:
{
    sizeof(rgcmdAbout) / sizeof(CMD),
    rgcmdAbout,
    edwpNone
}

Definition at line 65 of file ABOUT.C.

HFONT hFontCopyright

Definition at line 75 of file ABOUT.C.

MSDI msdiAbout
Initial value:
{
    sizeof(rgmsdAbout) / sizeof(MSD),
    rgmsdAbout,
    edwpNone
}

Definition at line 51 of file ABOUT.C.

CMD rgcmdAbout[]
Initial value:
{
    {IDOK,     CmdAboutDone},
    {IDCANCEL, CmdAboutDone}
}

Definition at line 59 of file ABOUT.C.

MSD rgmsdAbout[]
Initial value:
{
    {WM_COMMAND,    MsgAboutCommand},
    {WM_INITDIALOG, MsgAboutInit}
}

Definition at line 45 of file ABOUT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/CONNECT.C File Reference

  • NETDDE
Functions | Variables

CONNECT.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"
#include "connect.h"

Go to the source code of this file.

Functions

LRESULT | CmdConnectDlgCancel (HWND, WORD, WORD, HWND)
LRESULT | CmdConnectDlgOK (HWND, WORD, WORD, HWND)
LRESULT CALLBACK | ConnectDlg (HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgConnectDlgCommand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgConnectDlgInit (HWND, UINT, WPARAM, LPARAM)

Variables

CMDI cmdiConnectDlg
MSDI msdiConnectDlg
CMD rgcmdConnectDlg []
MSD rgmsdConnectDlg []

Function Documentation

LRESULT CmdConnectDlgCancel | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 216 of file CONNECT.C.

{
    EndDialog(hdlg, FALSE);          // Exit the dialog
    return TRUE;
}

LRESULT CmdConnectDlgOK | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 172 of file CONNECT.C.

{
    char szServer[MAX_COMPUTERNAME_LENGTH+5] = "\\\\";
    LPSTR psz = (LPSTR)szServer+ 2L;

    GetDlgItemText( hdlg, IDE_SERVERNAME, psz, MAX_COMPUTERNAME_LENGTH+3 );

    if ( *psz == '\0' ) // no server name, so same as cancelled
    {
        EndDialog(hdlg, FALSE);
    }
    else
    {
        if ( *psz != '\\' ) // if the name does not begin with a '\', we make
        {                   // it begin with '\\' by ajusting the pointer
            psz = (LPSTR) szServer;
            psz[MAX_COMPUTERNAME_LENGTH+2] = '\0';
        }

        lstrcpy( (LPSTR)g_szServer, psz );
        EndDialog(hdlg, TRUE);
    }
    return TRUE;

}

LRESULT CALLBACK ConnectDlg | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 89 of file CONNECT.C.

{
    return DispMessage(&msdiConnectDlg, hdlg, uMessage, wparam, lparam);
}

LRESULT MsgConnectDlgCommand | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 146 of file CONNECT.C.

{
    return DispCommand(&cmdiConnectDlg, hwnd, wparam, lparam);
}

LRESULT MsgConnectDlgInit | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 114 of file CONNECT.C.

{
    // Set text limits on edit controls
    SendDlgItemMessage(hdlg, IDE_SERVERNAME, EM_LIMITTEXT, (WPARAM) MAX_COMPUTERNAME_LENGTH+2, 0L );

    // Center the dialog over the application window
    CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));

    return TRUE;
}

Variable Documentation

CMDI cmdiConnectDlg
Initial value:
{
    sizeof(rgcmdConnectDlg) / sizeof(CMD),
    rgcmdConnectDlg,
    edwpNone
}

Definition at line 60 of file CONNECT.C.

MSDI msdiConnectDlg
Initial value:
{
    sizeof(rgmsdConnectDlg) / sizeof(MSD),
    rgmsdConnectDlg,
    edwpNone
}

Definition at line 46 of file CONNECT.C.

CMD rgcmdConnectDlg[]
Initial value:
{
    {IDOK,     CmdConnectDlgOK},
    {IDCANCEL, CmdConnectDlgCancel}
}

Definition at line 54 of file CONNECT.C.

MSD rgmsdConnectDlg[]
Initial value:
{
    {WM_COMMAND,      MsgConnectDlgCommand},
    {WM_INITDIALOG,   MsgConnectDlgInit}
}

Definition at line 40 of file CONNECT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/CONNECT.H File Reference

  • NETDDE
Defines | Functions

CONNECT.H File Reference

Go to the source code of this file.

Defines

#define | IDE_SERVERNAME 100

Functions

LRESULT CALLBACK | ConnectDlg (HWND, UINT, WPARAM, LPARAM)

Define Documentation

#define IDE_SERVERNAME 100

Definition at line 19 of file CONNECT.H.

Function Documentation

LRESULT CALLBACK ConnectDlg | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 89 of file CONNECT.C.

{
    return DispMessage(&msdiConnectDlg, hdlg, uMessage, wparam, lparam);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DDECBACK.C File Reference

  • NETDDE
Functions

DDECBACK.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"
#include "mem.h"
#include "ddecback.h"

Go to the source code of this file.

Functions

HDDEDATA CALLBACK DdeCallback (UINT iType, UINT iFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2)

Function Documentation

HDDEDATA CALLBACK DdeCallback | ( | UINT | iType,
 |  | UINT | iFmt,
 |  | HCONV | hConv,
 |  | HSZ | hsz1,
 |  | HSZ | hsz2,
 |  | HDDEDATA | hData,
 |  | DWORD | dwData1,
 |  | DWORD | dwData2
 | ) |  |

Definition at line 45 of file DDECBACK.C.

{
    char szBuffer[128];
    LPSTR psz;
    DWORD cbBytes;

    switch (iType)
    {

        //** DDEML messages handled by client side of the conversation **//
        case XTYP_ADVDATA:
            // Check for matching format and data item
            if (iFmt != CF_TEXT)
                return (HDDEDATA) DDE_FNOTPROCESSED ;

            if ( g_fState == STATE_PENDING )
            {
                PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
                return (HDDEDATA) DDE_FACK ;
            }

            // get data being advised
            cbBytes = DdeGetData (hData, NULL, 0, 0) ;
            if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
            {
                DdeGetData( hData, psz, cbBytes, 0 );
                PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM)cbBytes, (LPARAM)psz );
            }
            return (HDDEDATA) DDE_FACK ;
            break;

        //** DDEML messages handled by both sides of the conversation **//
        case XTYP_DISCONNECT:
            PostMessage( g_hwnd, WM_DISCONNECT, 0L, (LPARAM)hConv );
            return (HDDEDATA) TRUE ;
            break;

        //** DDEML messages handled by server side of the conversation **//
        case XTYP_CONNECT:
            // hsz1 = topic, hsz2 = service
            if ( g_fState  != STATE_UNCONN)
                return (HDDEDATA) FALSE;

            // validate service for connection
            DdeQueryString (g_idInst, hsz2, (LPSTR)szBuffer, 128, 0) ;

            if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)szAppName))
                return (HDDEDATA) FALSE ;

            // validate topic for connection
            DdeQueryString (g_idInst, hsz1, (LPSTR)szBuffer, 128, 0) ;

            if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)g_szTopic))
                return (HDDEDATA) FALSE ;

            g_fState = STATE_SERVER;
            return (HDDEDATA) TRUE;
            break;

        case XTYP_CONNECT_CONFIRM:
            PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
            return (HDDEDATA) TRUE;
            break;

        case XTYP_POKE:
            if (iFmt != CF_TEXT)
                return (HDDEDATA) DDE_FNOTPROCESSED;

            // get data being poked
            cbBytes = DdeGetData (hData, NULL, 0, 0) ;
            if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
            {
                DdeGetData( hData, psz, cbBytes, 0 );

                if ( STR_DWORD(psz) == (DWORD) -1 ) // computer name poked
                {
                    wsprintf( (LPSTR)g_szServer, psz );
                    PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM)hConv );
                }
                else
                    PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM) cbBytes, (LPARAM)psz );

                return (HDDEDATA) DDE_FACK;
            }
            break;

        case XTYP_ADVSTART:
#ifdef WIN16
            PostMessage( g_hwnd, WM_COMMAND, (WPARAM) IDE_SEND, MAKELONG( hwndSend, EN_CHANGE ) );
#else
            PostMessage( g_hwnd, WM_COMMAND, MAKELONG( IDE_SEND, EN_CHANGE ), (LPARAM) hwndSend );
#endif
            return (HDDEDATA) TRUE;
            break;

        case XTYP_ADVREQ:  // send data
            return GetDataToTrans();
            break;

        case XTYP_ADVSTOP:  // stop advising client
            return (HDDEDATA) TRUE ;
            break;

     }

     return (HDDEDATA) 0 ;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DDECBACK.H File Reference

  • NETDDE
Defines | Functions

DDECBACK.H File Reference

Go to the source code of this file.

Defines

#define | IDE_SERVERNAME 100

Functions

HDDEDATA CALLBACK | DdeCallback (UINT iType, UINT iFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, DWORD dwData1, DWORD dwData2)

Define Documentation

#define IDE_SERVERNAME 100

Definition at line 16 of file DDECBACK.H.

Function Documentation

HDDEDATA CALLBACK DdeCallback | ( | UINT | iType,
 |  | UINT | iFmt,
 |  | HCONV | hConv,
 |  | HSZ | hsz1,
 |  | HSZ | hsz2,
 |  | HDDEDATA | hData,
 |  | DWORD | dwData1,
 |  | DWORD | dwData2
 | ) |  |

Definition at line 45 of file DDECBACK.C.

{
    char szBuffer[128];
    LPSTR psz;
    DWORD cbBytes;

    switch (iType)
    {

        //** DDEML messages handled by client side of the conversation **//
        case XTYP_ADVDATA:
            // Check for matching format and data item
            if (iFmt != CF_TEXT)
                return (HDDEDATA) DDE_FNOTPROCESSED ;

            if ( g_fState == STATE_PENDING )
            {
                PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
                return (HDDEDATA) DDE_FACK ;
            }

            // get data being advised
            cbBytes = DdeGetData (hData, NULL, 0, 0) ;
            if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
            {
                DdeGetData( hData, psz, cbBytes, 0 );
                PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM)cbBytes, (LPARAM)psz );
            }
            return (HDDEDATA) DDE_FACK ;
            break;

        //** DDEML messages handled by both sides of the conversation **//
        case XTYP_DISCONNECT:
            PostMessage( g_hwnd, WM_DISCONNECT, 0L, (LPARAM)hConv );
            return (HDDEDATA) TRUE ;
            break;

        //** DDEML messages handled by server side of the conversation **//
        case XTYP_CONNECT:
            // hsz1 = topic, hsz2 = service
            if ( g_fState  != STATE_UNCONN)
                return (HDDEDATA) FALSE;

            // validate service for connection
            DdeQueryString (g_idInst, hsz2, (LPSTR)szBuffer, 128, 0) ;

            if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)szAppName))
                return (HDDEDATA) FALSE ;

            // validate topic for connection
            DdeQueryString (g_idInst, hsz1, (LPSTR)szBuffer, 128, 0) ;

            if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)g_szTopic))
                return (HDDEDATA) FALSE ;

            g_fState = STATE_SERVER;
            return (HDDEDATA) TRUE;
            break;

        case XTYP_CONNECT_CONFIRM:
            PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
            return (HDDEDATA) TRUE;
            break;

        case XTYP_POKE:
            if (iFmt != CF_TEXT)
                return (HDDEDATA) DDE_FNOTPROCESSED;

            // get data being poked
            cbBytes = DdeGetData (hData, NULL, 0, 0) ;
            if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
            {
                DdeGetData( hData, psz, cbBytes, 0 );

                if ( STR_DWORD(psz) == (DWORD) -1 ) // computer name poked
                {
                    wsprintf( (LPSTR)g_szServer, psz );
                    PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM)hConv );
                }
                else
                    PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM) cbBytes, (LPARAM)psz );

                return (HDDEDATA) DDE_FACK;
            }
            break;

        case XTYP_ADVSTART:
#ifdef WIN16
            PostMessage( g_hwnd, WM_COMMAND, (WPARAM) IDE_SEND, MAKELONG( hwndSend, EN_CHANGE ) );
#else
            PostMessage( g_hwnd, WM_COMMAND, MAKELONG( IDE_SEND, EN_CHANGE ), (LPARAM) hwndSend );
#endif
            return (HDDEDATA) TRUE;
            break;

        case XTYP_ADVREQ:  // send data
            return GetDataToTrans();
            break;

        case XTYP_ADVSTOP:  // stop advising client
            return (HDDEDATA) TRUE ;
            break;

     }

     return (HDDEDATA) 0 ;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DISPATCH.C File Reference

  • NETDDE
Functions

DISPATCH.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"

Go to the source code of this file.

Functions

LRESULT | DispCommand (LPCMDI lpcmdi, HWND hwnd, WPARAM wparam, LPARAM lparam)
LRESULT | DispDefault (EDWP, HWND, UINT, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI lpmsdi, HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)

Function Documentation

LRESULT DispCommand | ( | LPCMDI | lpcmdi,
 |  | HWND | hwnd,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 100 of file DISPATCH.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispDefault | ( | EDWP | edwp,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 151 of file DISPATCH.C.

{
    switch (edwp)
    {
        case edwpNone:
            return 0;
        case edwpWindow:
            return DefWindowProc(hwnd, uMessage, wparam, lparam);
        case edwpDialog:
            return DefDlgProc(hwnd, uMessage, wparam, lparam);
        case edwpMDIFrame:
            return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
        case edwpMDIChild:
            return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
    }
    return 0;
}

LRESULT DispMessage | ( | LPMSDI | lpmsdi,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 54 of file DISPATCH.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/GLOBALS.H File Reference

  • NETDDE
Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

GLOBALS.H File Reference

Go to the source code of this file.

Data Structures

struct | _CMD
struct | _CMDI
struct | _MSD
struct | _MSDI

Defines

#define | APPNAME nddechat
#define | hwndMDIClient NULL
#define | ICONFILE nddechat.ico
#define | IDC_STATIC -1
#define | IDD_VERFIRST 200
#define | IDD_VERLAST 204
#define | IDE_RECV 101
#define | IDE_SEND 100
#define | IDM_ABOUT 1200
#define | IDM_CONNECT 1001
#define | IDM_DISCONNECT 1002
#define | IDM_EXIT 1000
#define | IDS_APPNAME 1
#define | IDS_DESCRIPTION 2
#define | IDS_ITEM 5
#define | IDS_SHARENAME 3
#define | IDS_TOPIC 4
#define | STATE_CLIENT 3
#define | STATE_PENDING 1
#define | STATE_SERVER 2
#define | STATE_UNCONN 0
#define | STR_DWORD(x) (*((UNALIGNED DWORD FAR*)(x+lstrlen(x)+1)))
#define | SZABOUT "About NetDDE Chat"
#define | SZAPPNAME "nddechat"
#define | SZDESCRIPTION "NetDDE Chat Sample"
#define | SZRAPPNAME "InternalName"
#define | SZRCOMPANYNAME "CompanyName"
#define | SZRCOPYRIGHT "LegalCopyright"
#define | SZRDESCRIPTION "FileDescription"
#define | SZRPRODNAME "ProductName"
#define | SZRPRODVER "ProuctVersion"
#define | SZRTRADEMARK "LegalTrademarks"
#define | SZRVERSION "FileVersion"
#define | SZVERSION "Version 1.0"
#define | WM_CONNECT WM_USER+100
#define | WM_DISCONNECT WM_USER+101
#define | WM_RECEIVE_TEXT WM_USER+102

Typedefs

typedef struct _CMD | CMD
typedef struct _CMDI | CMDI
typedef struct _CMDI * | LPCMDI
typedef struct _MSDI * | LPMSDI
typedef struct _MSD | MSD
typedef struct _MSDI | MSDI
typedef LRESULT(* | PFNCMD )(HWND, WORD, WORD, HWND)
typedef LRESULT(* | PFNMSG )(HWND, UINT, WPARAM, LPARAM)

Enumerations

enum EDWP {
edwpNone, edwpWindow, edwpDialog, edwpMDIChild,
edwpMDIFrame, edwpNone, edwpWindow, edwpDialog,
edwpMDIChild, edwpMDIFrame, edwpNone, edwpWindow,
edwpDialog, edwpMDIChild, edwpMDIFrame
}

Functions

BOOL | CenterWindow (HWND, HWND)
LRESULT | CmdAbout (HWND, WORD, WORD, HWND)
LRESULT | CmdConnectDlg (HWND, WORD, WORD, HWND)
LRESULT | CmdDisconnect (HWND, WORD, WORD, HWND)
LRESULT | CmdExit (HWND, WORD, WORD, HWND)
LRESULT | CmdSendNotify (HWND, WORD, WORD, HWND)
LRESULT | DispCommand (LPCMDI, HWND, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI, HWND, UINT, WPARAM, LPARAM)
HDDEDATA | GetDataToTrans (VOID)
BOOL | InitApplication (HINSTANCE)
BOOL | InitInstance (HINSTANCE, int)
LRESULT | MsgCommand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgConnect (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgCreate (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgDestroy (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgDisconnect (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgReceiveText (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgSetFocus (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgSize (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | WndProc (HWND, UINT, WPARAM, LPARAM)

Variables

CMDI cmdiMain
BOOL | g_fState
HINSTANCE | g_hInstNetDde
HWND | g_hwnd
DWORD g_idInst
char | g_szServer []
char | g_szTopic []
HINSTANCE | hInst
HWND | hwndSend
MSDI msdiMain
char | szAppName []
char | szTitle []

Define Documentation

#define APPNAME nddechat

Definition at line 18 of file GLOBALS.H.

#define hwndMDIClient NULL

Definition at line 170 of file GLOBALS.H.

#define ICONFILE nddechat.ico

Definition at line 19 of file GLOBALS.H.

#define IDC_STATIC -1

Definition at line 131 of file GLOBALS.H.

#define IDD_VERFIRST 200

Definition at line 147 of file GLOBALS.H.

#define IDD_VERLAST 204

Definition at line 148 of file GLOBALS.H.

#define IDE_RECV 101

Definition at line 130 of file GLOBALS.H.

#define IDE_SEND 100

Definition at line 129 of file GLOBALS.H.

#define IDM_ABOUT 1200

Definition at line 115 of file GLOBALS.H.

#define IDM_CONNECT 1001

Definition at line 111 of file GLOBALS.H.

#define IDM_DISCONNECT 1002

Definition at line 112 of file GLOBALS.H.

#define IDM_EXIT 1000

Definition at line 110 of file GLOBALS.H.

#define IDS_APPNAME 1

Definition at line 120 of file GLOBALS.H.

#define IDS_DESCRIPTION 2

Definition at line 121 of file GLOBALS.H.

#define IDS_ITEM 5

Definition at line 124 of file GLOBALS.H.

#define IDS_SHARENAME 3

Definition at line 122 of file GLOBALS.H.

#define IDS_TOPIC 4

Definition at line 123 of file GLOBALS.H.

#define STATE_CLIENT 3

Definition at line 142 of file GLOBALS.H.

#define STATE_PENDING 1

Definition at line 140 of file GLOBALS.H.

#define STATE_SERVER 2

Definition at line 141 of file GLOBALS.H.

#define STATE_UNCONN 0

Definition at line 139 of file GLOBALS.H.

#define STR_DWORD ( x ) (*((UNALIGNED DWORD FAR*)(x+lstrlen(x)+1)))

Definition at line 137 of file GLOBALS.H.

#define SZABOUT "About NetDDE Chat"

Definition at line 22 of file GLOBALS.H.

#define SZAPPNAME "nddechat"

Definition at line 20 of file GLOBALS.H.

#define SZDESCRIPTION "NetDDE Chat Sample"

Definition at line 21 of file GLOBALS.H.

#define SZRAPPNAME "InternalName"

Definition at line 251 of file GLOBALS.H.

#define SZRCOMPANYNAME "CompanyName"

Definition at line 248 of file GLOBALS.H.

#define SZRCOPYRIGHT "LegalCopyright"

Definition at line 252 of file GLOBALS.H.

#define SZRDESCRIPTION "FileDescription"

Definition at line 249 of file GLOBALS.H.

#define SZRPRODNAME "ProductName"

Definition at line 254 of file GLOBALS.H.

#define SZRPRODVER "ProuctVersion"

Definition at line 255 of file GLOBALS.H.

#define SZRTRADEMARK "LegalTrademarks"

Definition at line 253 of file GLOBALS.H.

#define SZRVERSION "FileVersion"

Definition at line 250 of file GLOBALS.H.

#define SZVERSION "Version 1.0"

Definition at line 23 of file GLOBALS.H.

#define WM_CONNECT WM_USER+100

Definition at line 133 of file GLOBALS.H.

#define WM_DISCONNECT WM_USER+101

Definition at line 134 of file GLOBALS.H.

#define WM_RECEIVE_TEXT WM_USER+102

Definition at line 135 of file GLOBALS.H.

Typedef Documentation

typedef struct _CMD CMD
typedef struct _CMDI CMDI
typedef struct _CMDI* LPCMDI
typedef struct _MSDI* LPMSDI
typedef struct _MSD MSD
typedef struct _MSDI MSDI
typedef LRESULT(* PFNCMD)(HWND, WORD, WORD, HWND)

Definition at line 183 of file GLOBALS.H.

typedef LRESULT(* PFNMSG)(HWND, UINT, WPARAM, LPARAM)

Definition at line 180 of file GLOBALS.H.

Enumeration Type Documentation

enum EDWP
Enumerator:
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame

Definition at line 188 of file GLOBALS.H.

{
   edwpNone,            // Do not call any default procedure.
   edwpWindow,          // Call DefWindowProc.
   edwpDialog,          // Call DefDlgProc (This should be used only for
                        // custom dialogs - standard dialog use edwpNone).
   edwpMDIChild,        // Call DefMDIChildProc.
   edwpMDIFrame         // Call DefFrameProc.
} EDWP;                // Enumeration for Default Window Procedures

Function Documentation

BOOL CenterWindow | ( | HWND | ,
 |  | HWND |
 | ) |  |

Definition at line 50 of file MISC.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

LRESULT CmdAbout | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 96 of file ABOUT.C.

{
    DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
    return 0;
}

LRESULT CmdConnectDlg | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 476 of file NDDECHAT.C.

{

    char szBuffer[128];
    char szService[MAX_COMPUTERNAME_LENGTH+9];  // extra for \\%s\NDDE$
    HSZ hszService;
    HSZ hszShare;
    HSZ hszItem;

    *g_szServer = '\0';

    if ( DialogBox(hInst, "ConnectDlgBox", hwnd, (DLGPROC)ConnectDlg) )
    {
        wsprintf( (LPSTR) szService, "%s\\NDDE$", (LPSTR) g_szServer );

        hszService = DdeCreateStringHandle (g_idInst, (LPSTR) szService, 0) ;
        hszShare   = DdeCreateStringHandle (g_idInst, (LPSTR) szShareName,   0) ;

        hconv = DdeConnect (g_idInst, hszService, hszShare, NULL) ;

        DdeFreeStringHandle (g_idInst, hszService) ;
        DdeFreeStringHandle (g_idInst, hszShare) ;

        if (!hconv)
        {
            MessageBox (hwnd, (LPSTR)"Cannot connect to server.",
                        (LPSTR)szAppName, MB_ICONEXCLAMATION | MB_OK) ;

            return 0 ;
        }

        // Request notification of item
        hszItem = DdeCreateStringHandle (g_idInst, szItem, 0) ;

        DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
                              XTYP_ADVSTART | XTYPF_ACKREQ,
                              (DWORD )TIMEOUT_ASYNC, NULL) ;

        DdeFreeStringHandle (g_idInst, hszItem) ;

        g_fState = STATE_PENDING;
        wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connecting to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
        SetWindowText( hwnd, (LPSTR)szBuffer );

        EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );
        EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
    }

    return 0;
}

LRESULT CmdDisconnect | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 547 of file NDDECHAT.C.

{
    HSZ hszItem;

    if ( g_fState == STATE_CLIENT )
    {
        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);

        DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
                              XTYP_ADVSTOP, (DWORD)TIMEOUT_ASYNC, NULL) ;

        DdeFreeStringHandle (g_idInst, hszItem) ;
    }

    // Disconnect the conversation
    DdeDisconnect (hconv) ;

    PostMessage( hwnd, WM_DISCONNECT, 0, 0 );

    return 0;
}

LRESULT CmdExit | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 636 of file NDDECHAT.C.

{
    DestroyWindow(hwnd);
    return 0;
}

LRESULT CmdSendNotify | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 589 of file NDDECHAT.C.

{
    HSZ hszTopic;
    HSZ hszItem;
    HDDEDATA hdata;

    if ( wNotify == EN_CHANGE )
    {
        hszTopic = DdeCreateStringHandle (g_idInst, (LPSTR)g_szTopic, 0);
        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);

        if ( g_fState == STATE_SERVER )
            DdePostAdvise (g_idInst, hszTopic, hszItem) ;
        else
        {
            if ( (hdata = GetDataToTrans()) != 0 )
            {
                DdeClientTransaction( (LPBYTE) hdata, (DWORD) -1, hconv,
                                      hszItem, CF_TEXT, XTYP_POKE,
                                      (DWORD)TIMEOUT_ASYNC, NULL);
            }
        }

        DdeFreeStringHandle (g_idInst, hszItem) ;
        DdeFreeStringHandle (g_idInst, hszTopic) ;

    }
    return 0;
}

LRESULT DispCommand | ( | LPCMDI | ,
 |  | HWND | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 100 of file DISPATCH.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispMessage | ( | LPMSDI | ,
 |  | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 54 of file DISPATCH.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

HDDEDATA GetDataToTrans ( VOID )

Definition at line 658 of file NDDECHAT.C.

{
    HDDEDATA hdata;
    HSZ hszItem;
    LPSTR pszNew;
    LPSTR pszN;
    LPSTR pszL;
    DWORD cbBytes = GetWindowTextLength( hwndSend );

    if ( MallocMem( (LPVOID *) &pszNew, cbBytes+1+sizeof(DWORD) ) == ERROR_SUCCESS )
    {
        GetWindowText( hwndSend, pszNew, (int)cbBytes+1 );

        pszN = pszNew;
        pszL = pszLast;

        // increment pointed while ...
        // 1) not at end of Last string
        // 2) not at end of New string
        // 3) New char is equal to Last char

        // compute the insertion point of changed text
        if( !(*pszL) || !(*pszN) )
            STR_DWORD(pszNew) = 0;
        else
        {
            while ( *pszN++ == *pszL++ ) ;
            pszN--;
            STR_DWORD(pszNew) = (DWORD) ( pszL - 1 - pszLast );
        }

        hszItem = DdeCreateStringHandle (g_idInst, szItem, 0);
        hdata = DdeCreateDataHandle (g_idInst, pszN, cbBytes+1+sizeof(DWORD)-STR_DWORD(pszNew),
                                     0, hszItem, CF_TEXT, 0);
        DdeFreeStringHandle (g_idInst, hszItem) ;

        FreeMem( &pszLast );
        pszLast = pszNew;
    }

    return hdata;
}

BOOL InitApplication ( HINSTANCE )

Definition at line 86 of file NTGREP.C.

{
    WNDCLASS  wc;
    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC)MainWndProc;

    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "GrepMenu";
    wc.lpszClassName = INITCLASSNAME;

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HINSTANCE | ,
 |  | int |
 | ) |  |

Definition at line 106 of file NTGREP.C.

{
    HWND            hWnd;

    hInst = hInstance;

    hWnd = CreateWindow(
  INITCLASSNAME,
  "File Search Installer",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL
    );

    if (!hWnd)
  return (FALSE);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    return (TRUE);

}

LRESULT MsgCommand | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 418 of file NDDECHAT.C.

{
    return DispCommand(&cmdiMain, hwnd, wparam, lparam);
}

LRESULT MsgConnect | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 270 of file NDDECHAT.C.

{
    char szBuffer[128];
    DWORD cbBytes = 128;
    HSZ hszItem;

    if ( g_fState == STATE_PENDING ) // only clients pend
    {
        // get the name of the local ( client ) computer to poke to server
#ifdef WIN16
        NDdeGetNodeName( (LPSTR)szBuffer, cbBytes );
#else
        GetComputerName( (LPSTR)szBuffer, &cbBytes );
#endif
        // -1 signals computer name
        STR_DWORD((LPSTR)szBuffer) = (DWORD) -1;

        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0) ;
        DdeClientTransaction( (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer)+1+sizeof(DWORD),
                              hconv, hszItem, CF_TEXT, XTYP_POKE,
                              (DWORD) TIMEOUT_ASYNC, NULL);

        DdeFreeStringHandle (g_idInst, hszItem) ;

        g_fState = STATE_CLIENT;

    }

    // save conversation handle for disconnect
    hconv = (HCONV) lparam;

    // set user interface
    if ( *g_szServer != '\0' )
    {
        wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connected to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
        SetWindowText( hwnd, (LPSTR)szBuffer );
    }

    *pszLast = '\0';

    SetWindowText( hwndRecv, (LPSTR)"" );
    SetWindowText( hwndSend, (LPSTR)"" );
    EnableMenuItem( GetMenu( g_hwnd ), IDM_DISCONNECT, MF_ENABLED );
    EnableMenuItem( GetMenu( g_hwnd ), IDM_CONNECT, MF_GRAYED );

    SetFocus( hwndSend );

    return 0;
}

LRESULT MsgCreate | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 151 of file NDDECHAT.C.

{
    RECT rc;
    HSZ  hszService;

    g_hwnd = hwnd;
    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
    EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );

    // setup NetDDE Share ( require if acting as a server )
    LoadString(hInst, IDS_SHARENAME, (LPSTR)szShareName, MAX_NDDESHARENAME);
    LoadString(hInst, IDS_TOPIC, (LPSTR)g_szTopic, MAX_TOPICNAME);
    LoadString(hInst, IDS_ITEM, (LPSTR)szItem, MAX_ITEMNAME);

    if ( !SetupNDDEShare(hwnd, (LPSTR)szShareName, (LPSTR)szAppName, (LPSTR)g_szTopic) )
    {
        MessageBox( hwnd, (LPSTR)"Unable to create NetDDE Share.",
                    (LPSTR)szAppName, MB_ICONSTOP | MB_OK );
        return 0;
    }

    // Initialize DDEML conversation
    if (DdeInitialize (&g_idInst, (PFNCALLBACK) DdeCallback,
                       APPCLASS_STANDARD | CBF_FAIL_EXECUTES
                       | CBF_FAIL_REQUESTS | CBF_FAIL_SELFCONNECTIONS, 0L))
    {
        MessageBox (hwnd, (LPSTR)"Unable to initialize DDEML.",
                      szAppName, MB_ICONSTOP | MB_OK) ;
        return 0;
    }

    hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0) ;
    DdeNameService (g_idInst, hszService, 0, DNS_REGISTER) ;
    DdeFreeStringHandle (g_idInst, hszService) ;

    // Initialize user interface
    GetClientRect( hwnd, &rc );

    hwndSend  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_WANTRETURN,
                             0,
                             0,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_SEND,
                             hInst,
                             NULL );

    hwndRecv  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_READONLY | ES_WANTRETURN,
                             0,
                             rc.bottom/2,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_RECV,
                             hInst,
                             NULL );

    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_ENABLED );

    // initialize variable for last contents of send data
    MallocMem( (LPVOID *) &pszLast, 1 );
    *pszLast = '\0';

    return 0;
}

LRESULT MsgDestroy | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 443 of file NDDECHAT.C.

{
    HSZ hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0);
    DdeNameService (g_idInst, hszService, 0, DNS_UNREGISTER);
    DdeFreeStringHandle (g_idInst, hszService);

    if ( pszLast )
        FreeMem( (LPVOID *) &pszLast );

    PostQuitMessage(0);
    return 0;
}

LRESULT MsgDisconnect | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 340 of file NDDECHAT.C.

{
    char szBuffer[128];

    wsprintf( (LPSTR)szBuffer, (LPSTR)"Conversation with %s disconnected", (LPSTR) g_szServer );
    g_fState = STATE_UNCONN;
    *g_szServer = '\0';
    SetWindowText(hwnd, SZDESCRIPTION );

    // reset menus
    EnableMenuItem(GetMenu(g_hwnd), IDM_CONNECT, MF_ENABLED );
    EnableMenuItem(GetMenu(g_hwnd), IDM_DISCONNECT, MF_GRAYED );

    MessageBox( hwnd, szBuffer, szAppName, MB_OK );
    return 0;
}

LRESULT MsgReceiveText | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 378 of file NDDECHAT.C.

{
    DWORD ndx = GetWindowTextLength( hwndRecv );

#ifdef WIN16
    SendMessage( hwndRecv, EM_SETSEL, 1, MAKELONG((WORD)STR_DWORD((LPSTR)lparam), ndx) );
#else
    SendMessage( hwndRecv, EM_SETSEL, (INT)STR_DWORD((LPSTR)lparam), (LPARAM)-1 );
#endif

    SendMessage( hwndRecv, EM_REPLACESEL, 0, lparam );

    FreeMem( (LPVOID *) &lparam );
    return 0;
}

LRESULT MsgSetFocus | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |
LRESULT MsgSize | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 244 of file NDDECHAT.C.

{
    MoveWindow(hwndSend, 0, 0, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
    MoveWindow(hwndRecv, 0, HIWORD(lparam)/2, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
    return 0;
}

LRESULT CALLBACK WndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 121 of file NDDECHAT.C.

{
    return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}

Variable Documentation

CMDI cmdiMain

Definition at line 70 of file NDDECHAT.C.

BOOL g_fState

Definition at line 81 of file NDDECHAT.C.

HINSTANCE g_hInstNetDde

Definition at line 28 of file WINMAIN.C.

HWND g_hwnd

Definition at line 78 of file NDDECHAT.C.

DWORD g_idInst

Definition at line 82 of file NDDECHAT.C.

char g_szServer[]

Definition at line 79 of file NDDECHAT.C.

char g_szTopic[]

Definition at line 80 of file NDDECHAT.C.

HINSTANCE hInst

Definition at line 32 of file CLIPTEXT.C.

HWND hwndSend

Definition at line 95 of file NDDECHAT.C.

MSDI msdiMain

Definition at line 54 of file NDDECHAT.C.

char szAppName[]

Definition at line 24 of file GLTHREAD.C.

char szTitle[]

Definition at line 28 of file INIT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/INIT.C File Reference

  • NETDDE
Functions | Variables

INIT.C File Reference

#include <windows.h>
#include "globals.h"

Go to the source code of this file.

Functions

BOOL | InitApplication (HINSTANCE hInstance)
BOOL | InitInstance (HINSTANCE hInstance, int nCmdShow)

Variables

HINSTANCE | hInst
char | szAppName [9]
char | szTitle [40]

Function Documentation

BOOL InitApplication ( HINSTANCE hInstance )

Definition at line 57 of file INIT.C.

{
    WNDCLASS  wc;

    // Load the application name and description strings.

    LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
    LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));

    // Fill in window class structure with parameters that describe the
    // main window.

    wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
    wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
    wc.cbClsExtra    = 0;                       // No per-class extra data.
    wc.cbWndExtra    = 0;                       // No per-window extra data.
    wc.hInstance     = hInstance;               // Owner of this class
    wc.hIcon         = LoadIcon(hInstance, szAppName); // Icon name from .RC
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
    wc.lpszMenuName  = szAppName;               // Menu name from .RC
    wc.lpszClassName = szAppName;               // Name to register as

    // Register the window class and return FALSE if unsuccesful.

    if (!RegisterClass(&wc))
    {
        return FALSE;
    }
    //
    // **TODO** Call module specific application initialization functions here.
    //

    return TRUE;
}

BOOL InitInstance | ( | HINSTANCE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 117 of file INIT.C.

{
    HWND    hwnd; // Main window handle.

    // Save the instance handle in static variable, which will be used in
    // many subsequence calls from this application to Windows.

    hInst = hInstance; // Store instance handle in our global variable

    // Create a main window for this application instance.
    hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
                        szTitle,             // Text for window title bar.
                        WS_OVERLAPPEDWINDOW, // Window style.
                        CW_USEDEFAULT, 0,    // Use default positioning
                        CW_USEDEFAULT, 0,    // Use default size
                        NULL,                // Overlapped has no parent.
                        NULL,                // Use the window class menu.
                        hInstance,
                        NULL);

    // If window could not be created, return "failure"
    if (!hwnd)
        return FALSE;

    //
    // **TODO** Call module specific instance initialization functions here.
    //

    // Make the window visible; update its client area; and return "success"
    ShowWindow(hwnd, nCmdShow); // Show the window
    UpdateWindow(hwnd);         // Sends WM_PAINT message

    return TRUE;                // We succeeded...
}

Variable Documentation

HINSTANCE hInst

Definition at line 25 of file INIT.C.

char szAppName[9]

Definition at line 27 of file INIT.C.

char szTitle[40]

Definition at line 28 of file INIT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MEM.C File Reference

  • NETDDE
Functions

MEM.C File Reference

#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <malloc.h>
#include "mem.h"

Go to the source code of this file.

Functions

VOID | FreeMem (LPVOID *lplpv)
DWORD | MallocMem (LPVOID *lplpv, DWORD dwSize)
DWORD | ReallocMem (LPVOID *lplpv, DWORD dwSize)

Function Documentation

VOID FreeMem ( LPVOID * lplpv )

Definition at line 119 of file MEM.C.

{
    _ffree( *lplpv );
    *lplpv = NULL;
#ifdef _DEBUG
#ifdef WIN16
    dwAlloc--;
#else
    InterlockedDecrement(&dwAlloc);
#endif
#endif

}

DWORD MallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 44 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _fmalloc( (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

    *lplpv = lpTemp;

#ifdef _DEBUG
#ifdef WIN16
    dwAlloc++;
#else
    InterlockedIncrement(&dwAlloc);
#endif
#endif

    return ERROR_SUCCESS;

}

DWORD ReallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 80 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _frealloc( *lplpv, (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

#ifdef _DEBUG
    if ( dwSize == 0 )
#ifdef WIN16
        dwAlloc--;
#else
        InterlockedDecrement(&dwAlloc);
#endif
    else if ( *lplpv == NULL )
#ifdef WIN16
        dwAlloc++;
#else
        InterlockedIncrement(&dwAlloc);
#endif
#endif

    *lplpv = lpTemp;

    return ERROR_SUCCESS;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MEM.H File Reference

  • NETDDE
Defines | Functions

MEM.H File Reference

Go to the source code of this file.

Defines

#define | ERROR_NOT_ENOUGH_MEMORY 8
#define | ERROR_SUCCESS 0

Functions

VOID | FreeMem (LPVOID *lplpv)
DWORD | MallocMem (LPVOID *lplpv, DWORD dwSize)
DWORD | ReallocMem (LPVOID *lplpv, DWORD dwSize)

Define Documentation

#define ERROR_NOT_ENOUGH_MEMORY 8

Definition at line 18 of file MEM.H.

#define ERROR_SUCCESS 0

Definition at line 22 of file MEM.H.

Function Documentation

VOID FreeMem ( LPVOID * lplpv )

Definition at line 119 of file MEM.C.

{
    _ffree( *lplpv );
    *lplpv = NULL;
#ifdef _DEBUG
#ifdef WIN16
    dwAlloc--;
#else
    InterlockedDecrement(&dwAlloc);
#endif
#endif

}

DWORD MallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 44 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _fmalloc( (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

    *lplpv = lpTemp;

#ifdef _DEBUG
#ifdef WIN16
    dwAlloc++;
#else
    InterlockedIncrement(&dwAlloc);
#endif
#endif

    return ERROR_SUCCESS;

}

DWORD ReallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 80 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _frealloc( *lplpv, (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

#ifdef _DEBUG
    if ( dwSize == 0 )
#ifdef WIN16
        dwAlloc--;
#else
        InterlockedDecrement(&dwAlloc);
#endif
    else if ( *lplpv == NULL )
#ifdef WIN16
        dwAlloc++;
#else
        InterlockedIncrement(&dwAlloc);
#endif
#endif

    *lplpv = lpTemp;

    return ERROR_SUCCESS;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MISC.C File Reference

  • NETDDE
Functions

MISC.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"

Go to the source code of this file.

Functions

BOOL CenterWindow (HWND hwndChild, HWND hwndParent)

Function Documentation

BOOL CenterWindow | ( | HWND | hwndChild,
 |  | HWND | hwndParent
 | ) |  |

Definition at line 50 of file MISC.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDECHAT.C File Reference

  • NETDDE
Functions | Variables

NDDECHAT.C File Reference

#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <nddeapi.h>
#include "globals.h"
#include "nddeutil.h"
#include "mem.h"
#include "connect.h"
#include "ddecback.h"

Go to the source code of this file.

Functions

LRESULT | CmdConnectDlg (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdDisconnect (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdExit (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdSendNotify (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
HDDEDATA | GetDataToTrans (VOID)
LRESULT | MsgCommand (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgConnect (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgCreate (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgDestroy (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgDisconnect (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgReceiveText (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgSize (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT CALLBACK | WndProc (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)

Variables

CMDI cmdiMain
BOOL | g_fState = STATE_UNCONN
HWND | g_hwnd
DWORD | g_idInst = 0
char | g_szServer [MAX_COMPUTERNAME_LENGTH+3]
char | g_szTopic [MAX_TOPICNAME+1]
HCONV | hconv = 0
HWND | hwndRecv
HWND | hwndSend
MSDI msdiMain
LPSTR | pszLast = NULL
CMD rgcmd []
MSD rgmsd []
char | szItem [MAX_ITEMNAME+1]
char | szShareName [MAX_NDDESHARENAME+1]

Function Documentation

LRESULT CmdConnectDlg | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 476 of file NDDECHAT.C.

{

    char szBuffer[128];
    char szService[MAX_COMPUTERNAME_LENGTH+9];  // extra for \\%s\NDDE$
    HSZ hszService;
    HSZ hszShare;
    HSZ hszItem;

    *g_szServer = '\0';

    if ( DialogBox(hInst, "ConnectDlgBox", hwnd, (DLGPROC)ConnectDlg) )
    {
        wsprintf( (LPSTR) szService, "%s\\NDDE$", (LPSTR) g_szServer );

        hszService = DdeCreateStringHandle (g_idInst, (LPSTR) szService, 0) ;
        hszShare   = DdeCreateStringHandle (g_idInst, (LPSTR) szShareName,   0) ;

        hconv = DdeConnect (g_idInst, hszService, hszShare, NULL) ;

        DdeFreeStringHandle (g_idInst, hszService) ;
        DdeFreeStringHandle (g_idInst, hszShare) ;

        if (!hconv)
        {
            MessageBox (hwnd, (LPSTR)"Cannot connect to server.",
                        (LPSTR)szAppName, MB_ICONEXCLAMATION | MB_OK) ;

            return 0 ;
        }

        // Request notification of item
        hszItem = DdeCreateStringHandle (g_idInst, szItem, 0) ;

        DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
                              XTYP_ADVSTART | XTYPF_ACKREQ,
                              (DWORD )TIMEOUT_ASYNC, NULL) ;

        DdeFreeStringHandle (g_idInst, hszItem) ;

        g_fState = STATE_PENDING;
        wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connecting to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
        SetWindowText( hwnd, (LPSTR)szBuffer );

        EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );
        EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
    }

    return 0;
}

LRESULT CmdDisconnect | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 547 of file NDDECHAT.C.

{
    HSZ hszItem;

    if ( g_fState == STATE_CLIENT )
    {
        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);

        DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
                              XTYP_ADVSTOP, (DWORD)TIMEOUT_ASYNC, NULL) ;

        DdeFreeStringHandle (g_idInst, hszItem) ;
    }

    // Disconnect the conversation
    DdeDisconnect (hconv) ;

    PostMessage( hwnd, WM_DISCONNECT, 0, 0 );

    return 0;
}

LRESULT CmdExit | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 636 of file NDDECHAT.C.

{
    DestroyWindow(hwnd);
    return 0;
}

LRESULT CmdSendNotify | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 589 of file NDDECHAT.C.

{
    HSZ hszTopic;
    HSZ hszItem;
    HDDEDATA hdata;

    if ( wNotify == EN_CHANGE )
    {
        hszTopic = DdeCreateStringHandle (g_idInst, (LPSTR)g_szTopic, 0);
        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);

        if ( g_fState == STATE_SERVER )
            DdePostAdvise (g_idInst, hszTopic, hszItem) ;
        else
        {
            if ( (hdata = GetDataToTrans()) != 0 )
            {
                DdeClientTransaction( (LPBYTE) hdata, (DWORD) -1, hconv,
                                      hszItem, CF_TEXT, XTYP_POKE,
                                      (DWORD)TIMEOUT_ASYNC, NULL);
            }
        }

        DdeFreeStringHandle (g_idInst, hszItem) ;
        DdeFreeStringHandle (g_idInst, hszTopic) ;

    }
    return 0;
}

HDDEDATA GetDataToTrans ( VOID )

Definition at line 658 of file NDDECHAT.C.

{
    HDDEDATA hdata;
    HSZ hszItem;
    LPSTR pszNew;
    LPSTR pszN;
    LPSTR pszL;
    DWORD cbBytes = GetWindowTextLength( hwndSend );

    if ( MallocMem( (LPVOID *) &pszNew, cbBytes+1+sizeof(DWORD) ) == ERROR_SUCCESS )
    {
        GetWindowText( hwndSend, pszNew, (int)cbBytes+1 );

        pszN = pszNew;
        pszL = pszLast;

        // increment pointed while ...
        // 1) not at end of Last string
        // 2) not at end of New string
        // 3) New char is equal to Last char

        // compute the insertion point of changed text
        if( !(*pszL) || !(*pszN) )
            STR_DWORD(pszNew) = 0;
        else
        {
            while ( *pszN++ == *pszL++ ) ;
            pszN--;
            STR_DWORD(pszNew) = (DWORD) ( pszL - 1 - pszLast );
        }

        hszItem = DdeCreateStringHandle (g_idInst, szItem, 0);
        hdata = DdeCreateDataHandle (g_idInst, pszN, cbBytes+1+sizeof(DWORD)-STR_DWORD(pszNew),
                                     0, hszItem, CF_TEXT, 0);
        DdeFreeStringHandle (g_idInst, hszItem) ;

        FreeMem( &pszLast );
        pszLast = pszNew;
    }

    return hdata;
}

LRESULT MsgCommand | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 418 of file NDDECHAT.C.

{
    return DispCommand(&cmdiMain, hwnd, wparam, lparam);
}

LRESULT MsgConnect | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 270 of file NDDECHAT.C.

{
    char szBuffer[128];
    DWORD cbBytes = 128;
    HSZ hszItem;

    if ( g_fState == STATE_PENDING ) // only clients pend
    {
        // get the name of the local ( client ) computer to poke to server
#ifdef WIN16
        NDdeGetNodeName( (LPSTR)szBuffer, cbBytes );
#else
        GetComputerName( (LPSTR)szBuffer, &cbBytes );
#endif
        // -1 signals computer name
        STR_DWORD((LPSTR)szBuffer) = (DWORD) -1;

        hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0) ;
        DdeClientTransaction( (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer)+1+sizeof(DWORD),
                              hconv, hszItem, CF_TEXT, XTYP_POKE,
                              (DWORD) TIMEOUT_ASYNC, NULL);

        DdeFreeStringHandle (g_idInst, hszItem) ;

        g_fState = STATE_CLIENT;

    }

    // save conversation handle for disconnect
    hconv = (HCONV) lparam;

    // set user interface
    if ( *g_szServer != '\0' )
    {
        wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connected to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
        SetWindowText( hwnd, (LPSTR)szBuffer );
    }

    *pszLast = '\0';

    SetWindowText( hwndRecv, (LPSTR)"" );
    SetWindowText( hwndSend, (LPSTR)"" );
    EnableMenuItem( GetMenu( g_hwnd ), IDM_DISCONNECT, MF_ENABLED );
    EnableMenuItem( GetMenu( g_hwnd ), IDM_CONNECT, MF_GRAYED );

    SetFocus( hwndSend );

    return 0;
}

LRESULT MsgCreate | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 151 of file NDDECHAT.C.

{
    RECT rc;
    HSZ  hszService;

    g_hwnd = hwnd;
    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
    EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );

    // setup NetDDE Share ( require if acting as a server )
    LoadString(hInst, IDS_SHARENAME, (LPSTR)szShareName, MAX_NDDESHARENAME);
    LoadString(hInst, IDS_TOPIC, (LPSTR)g_szTopic, MAX_TOPICNAME);
    LoadString(hInst, IDS_ITEM, (LPSTR)szItem, MAX_ITEMNAME);

    if ( !SetupNDDEShare(hwnd, (LPSTR)szShareName, (LPSTR)szAppName, (LPSTR)g_szTopic) )
    {
        MessageBox( hwnd, (LPSTR)"Unable to create NetDDE Share.",
                    (LPSTR)szAppName, MB_ICONSTOP | MB_OK );
        return 0;
    }

    // Initialize DDEML conversation
    if (DdeInitialize (&g_idInst, (PFNCALLBACK) DdeCallback,
                       APPCLASS_STANDARD | CBF_FAIL_EXECUTES
                       | CBF_FAIL_REQUESTS | CBF_FAIL_SELFCONNECTIONS, 0L))
    {
        MessageBox (hwnd, (LPSTR)"Unable to initialize DDEML.",
                      szAppName, MB_ICONSTOP | MB_OK) ;
        return 0;
    }

    hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0) ;
    DdeNameService (g_idInst, hszService, 0, DNS_REGISTER) ;
    DdeFreeStringHandle (g_idInst, hszService) ;

    // Initialize user interface
    GetClientRect( hwnd, &rc );

    hwndSend  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_WANTRETURN,
                             0,
                             0,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_SEND,
                             hInst,
                             NULL );

    hwndRecv  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_READONLY | ES_WANTRETURN,
                             0,
                             rc.bottom/2,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_RECV,
                             hInst,
                             NULL );

    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_ENABLED );

    // initialize variable for last contents of send data
    MallocMem( (LPVOID *) &pszLast, 1 );
    *pszLast = '\0';

    return 0;
}

LRESULT MsgDestroy | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 443 of file NDDECHAT.C.

{
    HSZ hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0);
    DdeNameService (g_idInst, hszService, 0, DNS_UNREGISTER);
    DdeFreeStringHandle (g_idInst, hszService);

    if ( pszLast )
        FreeMem( (LPVOID *) &pszLast );

    PostQuitMessage(0);
    return 0;
}

LRESULT MsgDisconnect | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 340 of file NDDECHAT.C.

{
    char szBuffer[128];

    wsprintf( (LPSTR)szBuffer, (LPSTR)"Conversation with %s disconnected", (LPSTR) g_szServer );
    g_fState = STATE_UNCONN;
    *g_szServer = '\0';
    SetWindowText(hwnd, SZDESCRIPTION );

    // reset menus
    EnableMenuItem(GetMenu(g_hwnd), IDM_CONNECT, MF_ENABLED );
    EnableMenuItem(GetMenu(g_hwnd), IDM_DISCONNECT, MF_GRAYED );

    MessageBox( hwnd, szBuffer, szAppName, MB_OK );
    return 0;
}

LRESULT MsgReceiveText | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 378 of file NDDECHAT.C.

{
    DWORD ndx = GetWindowTextLength( hwndRecv );

#ifdef WIN16
    SendMessage( hwndRecv, EM_SETSEL, 1, MAKELONG((WORD)STR_DWORD((LPSTR)lparam), ndx) );
#else
    SendMessage( hwndRecv, EM_SETSEL, (INT)STR_DWORD((LPSTR)lparam), (LPARAM)-1 );
#endif

    SendMessage( hwndRecv, EM_REPLACESEL, 0, lparam );

    FreeMem( (LPVOID *) &lparam );
    return 0;
}

LRESULT MsgSize | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 244 of file NDDECHAT.C.

{
    MoveWindow(hwndSend, 0, 0, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
    MoveWindow(hwndRecv, 0, HIWORD(lparam)/2, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
    return 0;
}

LRESULT CALLBACK WndProc | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 121 of file NDDECHAT.C.

{
    return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}

Variable Documentation

CMDI cmdiMain
Initial value:
{
    sizeof(rgcmd) / sizeof(CMD),
    rgcmd,
    edwpWindow
}

Definition at line 70 of file NDDECHAT.C.

BOOL g_fState = STATE_UNCONN

Definition at line 81 of file NDDECHAT.C.

HWND g_hwnd

Definition at line 78 of file NDDECHAT.C.

DWORD g_idInst = 0

Definition at line 82 of file NDDECHAT.C.

char g_szServer[MAX_COMPUTERNAME_LENGTH+3]

Definition at line 79 of file NDDECHAT.C.

char g_szTopic[MAX_TOPICNAME+1]

Definition at line 80 of file NDDECHAT.C.

HCONV hconv = 0

Definition at line 92 of file NDDECHAT.C.

HWND hwndRecv

Definition at line 94 of file NDDECHAT.C.

HWND hwndSend

Definition at line 95 of file NDDECHAT.C.

MSDI msdiMain
Initial value:
{
    sizeof(rgmsd) / sizeof(MSD),
    rgmsd,
    edwpWindow
}

Definition at line 54 of file NDDECHAT.C.

LPSTR pszLast = NULL

Definition at line 87 of file NDDECHAT.C.

CMD rgcmd[]
Initial value:
{
    {IDM_CONNECT,    CmdConnectDlg},
    {IDM_DISCONNECT, CmdDisconnect},
    {IDE_SEND,       CmdSendNotify},
    {IDM_EXIT,       CmdExit},
    {IDM_ABOUT,      CmdAbout}
}

Definition at line 61 of file NDDECHAT.C.

MSD rgmsd[]
Initial value:
{
    {WM_CREATE,       MsgCreate},
    {WM_SIZE,         MsgSize},
    {WM_CONNECT,      MsgConnect},
    {WM_DISCONNECT,   MsgDisconnect},
    {WM_RECEIVE_TEXT, MsgReceiveText},
    {WM_COMMAND,      MsgCommand},
    {WM_DESTROY,      MsgDestroy}
}

Definition at line 43 of file NDDECHAT.C.

char szItem[MAX_ITEMNAME+1]

Definition at line 90 of file NDDECHAT.C.

char szShareName[MAX_NDDESHARENAME+1]

Definition at line 89 of file NDDECHAT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDEUTIL.C File Reference

  • NETDDE
Functions

NDDEUTIL.C File Reference

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include "globals.h"
#include <nddeapi.h>
#include "nddeutil.h"

Go to the source code of this file.

Functions

BOOL | SetupNDDEShare (HWND hwnd, LPSTR lpszShareName, LPSTR lpszApp, LPSTR lpszTopic)
VOID | ShowNDDEErrMsg (HWND hwnd, LPSTR lpstr, UINT uCode)

Function Documentation

BOOL SetupNDDEShare | ( | HWND | hwnd,
 |  | LPSTR | lpszShareName,
 |  | LPSTR | lpszApp,
 |  | LPSTR | lpszTopic
 | ) |  |

Definition at line 57 of file NDDEUTIL.C.

{

#ifdef WIN16 // Win16 bimplementation
    UINT uRet = 0;
    NDDESHAREINFO ndsiInfo;

    lstrcpy( ndsiInfo.szShareName, lpszShareName );
    ndsiInfo.lpszTargetApp  = lpszApp;
    ndsiInfo.lpszTargetTopic= lpszTopic;
    ndsiInfo.lpbPassword1   = "";
    ndsiInfo.cbPassword1    = 0;
    ndsiInfo.dwPermissions1 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
    ndsiInfo.lpbPassword2   = "";
    ndsiInfo.cbPassword2    = 0;
    ndsiInfo.dwPermissions2 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
    ndsiInfo.lpszItem       = NULL;
    ndsiInfo.cAddItems      = 0;
    ndsiInfo.lpNDdeShareItemInfo = NULL;

    NDdeShareDel ( NULL, lpszShareName, 0 );

    uRet = NDdeShareAdd(NULL, 2, (LPBYTE) &ndsiInfo, sizeof(NDDESHAREINFO));

    if (uRet != NDDE_NO_ERROR )
    {
        ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
        return FALSE;
    }

    return TRUE;

#else  // Win32 implementation
    FARPROC lpfn = NULL;
    BOOL bRet = TRUE;
    UINT uRet = 0;
    NDDESHAREINFO ndsiInfo;
    PSECURITY_DESCRIPTOR pSD = NULL;
    long lShareType = 0;
    long len = 0;
    char szAppTopicList[3*(MAX_APPNAME+MAX_TOPICNAME+2)+1];
    // create app / topic list - this is 3 null terminated strings
    // terminated by another null

    wsprintf(szAppTopicList,
            "%s|%s",
            lpszApp,
            lpszTopic );

    len = lstrlen(szAppTopicList)+1;  // include NULL charater

    wsprintf(szAppTopicList+len,
            "%s|%s",
            lpszApp,
            lpszTopic );

    wsprintf(szAppTopicList+len*2,
            "%s|%s",
            lpszApp,
            lpszTopic );

    szAppTopicList[len*3] = 0;        // terminate with double null

    lShareType = SHARE_TYPE_OLD | SHARE_TYPE_NEW | SHARE_TYPE_STATIC;

    // Get a pointer to the NDdeIsValidAppTopicList() API
    lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeIsValidAppTopicListA"));
    if (!lpfn)
    {
        MessageBox(NULL, TEXT("Error calling NetDDE API"), TEXT("NDDECHAT"),
                   MB_OK);
        return (FALSE);
    }

    if( (lpfn)(szAppTopicList)) {

        ndsiInfo.lRevision = 1;
        ndsiInfo.lpszShareName = lpszShareName;
        ndsiInfo.lShareType = lShareType;
        ndsiInfo.lpszAppTopicList = szAppTopicList;
        ndsiInfo.fSharedFlag = TRUE;
        ndsiInfo.fService = FALSE;
        ndsiInfo.fStartAppFlag = TRUE;
        ndsiInfo.nCmdShow = SW_SHOWNORMAL;
        ndsiInfo.cNumItems = 0;
        ndsiInfo.lpszItemList = "";

        // Delete possible old share
        lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareDelA"));
        (lpfn)( NULL, lpszShareName, 0 );

        // Create a Security descriptor which allows write access
        // This enables pokes from client ( ie writes )

        // Allocate memory for the security descriptor.
        pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
                                        SECURITY_DESCRIPTOR_MIN_LENGTH);

        // Initialize the new security descriptor.
        InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION);

        // Add a NULL descriptor ACL to the security descriptor.
        SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE);

        // create the new share
        lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareAddA"));
        uRet = (lpfn)( NULL, 2, pSD, (LPBYTE)&ndsiInfo, sizeof(NDDESHAREINFO) );
        if ( uRet == NDDE_NO_ERROR )
        {
            // trust the new share to allow remote access
            lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeSetTrustedShareA"));
            uRet = (lpfn)( NULL, lpszShareName,
                           NDDE_TRUST_SHARE_INIT | NDDE_TRUST_SHARE_START);
            if ( uRet != NDDE_NO_ERROR )
            {
                ShowNDDEErrMsg ( hwnd, "Error Trusting Share", uRet );
                bRet = FALSE;
            }
        }
        else
        {
            ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
            bRet = FALSE;
        }

        // free security descriptor
        LocalFree( pSD );
    }
    else
    {
        MessageBox ( hwnd, "Invalid Topic List", szAppName, MB_ICONEXCLAMATION | MB_OK );
        bRet = FALSE;
    }

    return bRet;
#endif  // Win32

}

VOID ShowNDDEErrMsg | ( | HWND | hwnd,
 |  | LPSTR | lpstr,
 |  | UINT | uCode
 | ) |  |

Definition at line 219 of file NDDEUTIL.C.

{
    char szBuf[256];
    FARPROC lpfn;

    if ( uCode == NDDE_NO_ERROR )
        return;

    MessageBeep(MB_ICONEXCLAMATION);

    wsprintf( (LPSTR)szBuf, "%s\n", lpstr );
    lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeGetErrorStringA"));
    if ( (lpfn) ( uCode,
                  (LPSTR)szBuf+lstrlen((LPSTR)szBuf),
                  255-lstrlen((LPSTR)szBuf) ) == NDDE_NO_ERROR )
    {
        MessageBox (hwnd, szBuf, szAppName, MB_ICONEXCLAMATION | MB_OK );
    }
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDEUTIL.H File Reference

  • NETDDE
Functions

NDDEUTIL.H File Reference

Go to the source code of this file.

Functions

BOOL | SetupNDDEShare (HWND hwnd, LPSTR pszShareName, LPSTR pszApp, LPSTR pszTopic)
VOID | ShowNDDEErrMsg (HWND hwnd, LPSTR lpstr, UINT uCode)

Function Documentation

BOOL SetupNDDEShare | ( | HWND | hwnd,
 |  | LPSTR | pszShareName,
 |  | LPSTR | pszApp,
 |  | LPSTR | pszTopic
 | ) |  |

Definition at line 57 of file NDDEUTIL.C.

{

#ifdef WIN16 // Win16 bimplementation
    UINT uRet = 0;
    NDDESHAREINFO ndsiInfo;

    lstrcpy( ndsiInfo.szShareName, lpszShareName );
    ndsiInfo.lpszTargetApp  = lpszApp;
    ndsiInfo.lpszTargetTopic= lpszTopic;
    ndsiInfo.lpbPassword1   = "";
    ndsiInfo.cbPassword1    = 0;
    ndsiInfo.dwPermissions1 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
    ndsiInfo.lpbPassword2   = "";
    ndsiInfo.cbPassword2    = 0;
    ndsiInfo.dwPermissions2 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
    ndsiInfo.lpszItem       = NULL;
    ndsiInfo.cAddItems      = 0;
    ndsiInfo.lpNDdeShareItemInfo = NULL;

    NDdeShareDel ( NULL, lpszShareName, 0 );

    uRet = NDdeShareAdd(NULL, 2, (LPBYTE) &ndsiInfo, sizeof(NDDESHAREINFO));

    if (uRet != NDDE_NO_ERROR )
    {
        ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
        return FALSE;
    }

    return TRUE;

#else  // Win32 implementation
    FARPROC lpfn = NULL;
    BOOL bRet = TRUE;
    UINT uRet = 0;
    NDDESHAREINFO ndsiInfo;
    PSECURITY_DESCRIPTOR pSD = NULL;
    long lShareType = 0;
    long len = 0;
    char szAppTopicList[3*(MAX_APPNAME+MAX_TOPICNAME+2)+1];
    // create app / topic list - this is 3 null terminated strings
    // terminated by another null

    wsprintf(szAppTopicList,
            "%s|%s",
            lpszApp,
            lpszTopic );

    len = lstrlen(szAppTopicList)+1;  // include NULL charater

    wsprintf(szAppTopicList+len,
            "%s|%s",
            lpszApp,
            lpszTopic );

    wsprintf(szAppTopicList+len*2,
            "%s|%s",
            lpszApp,
            lpszTopic );

    szAppTopicList[len*3] = 0;        // terminate with double null

    lShareType = SHARE_TYPE_OLD | SHARE_TYPE_NEW | SHARE_TYPE_STATIC;

    // Get a pointer to the NDdeIsValidAppTopicList() API
    lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeIsValidAppTopicListA"));
    if (!lpfn)
    {
        MessageBox(NULL, TEXT("Error calling NetDDE API"), TEXT("NDDECHAT"),
                   MB_OK);
        return (FALSE);
    }

    if( (lpfn)(szAppTopicList)) {

        ndsiInfo.lRevision = 1;
        ndsiInfo.lpszShareName = lpszShareName;
        ndsiInfo.lShareType = lShareType;
        ndsiInfo.lpszAppTopicList = szAppTopicList;
        ndsiInfo.fSharedFlag = TRUE;
        ndsiInfo.fService = FALSE;
        ndsiInfo.fStartAppFlag = TRUE;
        ndsiInfo.nCmdShow = SW_SHOWNORMAL;
        ndsiInfo.cNumItems = 0;
        ndsiInfo.lpszItemList = "";

        // Delete possible old share
        lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareDelA"));
        (lpfn)( NULL, lpszShareName, 0 );

        // Create a Security descriptor which allows write access
        // This enables pokes from client ( ie writes )

        // Allocate memory for the security descriptor.
        pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
                                        SECURITY_DESCRIPTOR_MIN_LENGTH);

        // Initialize the new security descriptor.
        InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION);

        // Add a NULL descriptor ACL to the security descriptor.
        SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE);

        // create the new share
        lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareAddA"));
        uRet = (lpfn)( NULL, 2, pSD, (LPBYTE)&ndsiInfo, sizeof(NDDESHAREINFO) );
        if ( uRet == NDDE_NO_ERROR )
        {
            // trust the new share to allow remote access
            lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeSetTrustedShareA"));
            uRet = (lpfn)( NULL, lpszShareName,
                           NDDE_TRUST_SHARE_INIT | NDDE_TRUST_SHARE_START);
            if ( uRet != NDDE_NO_ERROR )
            {
                ShowNDDEErrMsg ( hwnd, "Error Trusting Share", uRet );
                bRet = FALSE;
            }
        }
        else
        {
            ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
            bRet = FALSE;
        }

        // free security descriptor
        LocalFree( pSD );
    }
    else
    {
        MessageBox ( hwnd, "Invalid Topic List", szAppName, MB_ICONEXCLAMATION | MB_OK );
        bRet = FALSE;
    }

    return bRet;
#endif  // Win32

}

VOID ShowNDDEErrMsg | ( | HWND | hwnd,
 |  | LPSTR | lpstr,
 |  | UINT | uCode
 | ) |  |

Definition at line 219 of file NDDEUTIL.C.

{
    char szBuf[256];
    FARPROC lpfn;

    if ( uCode == NDDE_NO_ERROR )
        return;

    MessageBeep(MB_ICONEXCLAMATION);

    wsprintf( (LPSTR)szBuf, "%s\n", lpstr );
    lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeGetErrorStringA"));
    if ( (lpfn) ( uCode,
                  (LPSTR)szBuf+lstrlen((LPSTR)szBuf),
                  255-lstrlen((LPSTR)szBuf) ) == NDDE_NO_ERROR )
    {
        MessageBox (hwnd, szBuf, szAppName, MB_ICONEXCLAMATION | MB_OK );
    }
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/WIN16EXT.H File Reference

  • NETDDE
Defines

WIN16EXT.H File Reference

#include <ver.h>

Go to the source code of this file.

Defines

#define | APIENTRY far pascal
#define | DLGPROC FARPROC
#define | GET_WM_COMMAND_CMD(w, l) HIWORD(l)
#define | GET_WM_COMMAND_HWND(w, l) LOWORD(l)
#define | GET_WM_COMMAND_ID(w, l) (w)

Define Documentation

#define APIENTRY far pascal

Definition at line 14 of file WIN16EXT.H.

#define DLGPROC FARPROC

Definition at line 17 of file WIN16EXT.H.

#define GET_WM_COMMAND_CMD | ( | w,
 |  | l |
 | ) |  | HIWORD(l)

Definition at line 21 of file WIN16EXT.H.

#define GET_WM_COMMAND_HWND | ( | w,
 |  | l |
 | ) |  | LOWORD(l)

Definition at line 22 of file WIN16EXT.H.

#define GET_WM_COMMAND_ID | ( | w,
 |  | l |
 | ) |  | (w)

Definition at line 20 of file WIN16EXT.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/WINMAIN.C File Reference

  • NETDDE
Functions | Variables

WINMAIN.C File Reference

#include <windows.h>
#include "globals.h"

Go to the source code of this file.

Functions

int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HINSTANCE | g_hInstNetDde

Function Documentation

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 72 of file WINMAIN.C.

{
    MSG msg;
    HANDLE hAccelTable;
    DWORD dwVersion;

    // First check to see if we're running on Win95
    dwVersion = GetVersion();
    if (!(dwVersion < 0x8000000))
    {
        MessageBox(NULL,
                   TEXT("This application cannot run on Windows 95 or Win32s"),
                   TEXT("NDdeChat"), MB_OK | MB_ICONHAND);
        return (FALSE);
    }

    // Other instances of app running?
    if (!hPrevInstance)
    {
        // Initialize shared things
        if (!InitApplication(hInstance))
        {
            return FALSE;               // Exits if unable to initialize
        }
    }

    // Attempt to load the NDDEAPI.DLL.  If this is Win95 it will fail.
    g_hInstNetDde = LoadLibrary(TEXT("NDDEAPI.DLL"));
    if (!g_hInstNetDde)
    {
        MessageBox(NULL, TEXT("Could not load NDDEAPI.DLL."), TEXT("NDDECHAT"), MB_OK);
        return (FALSE);
    }

    // Perform initializations that apply to a specific instance
    if (!InitInstance(hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, szAppName);

    // Acquire and dispatch messages until a WM_QUIT message is received.
    while (GetMessage(&msg, NULL, 0, 0))
    {
        //
        // **TODO** Add other Translation functions (for modeless dialogs
        //  and/or MDI windows) here.
        //

        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    //
    // **TODO** Call module specific instance free/delete functions here.
    //
    if (g_hInstNetDde)
        FreeLibrary(g_hInstNetDde);

    // Returns the value from PostQuitMessage
    return msg.wParam;
}

Variable Documentation

HINSTANCE g_hInstNetDde

Definition at line 28 of file WINMAIN.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/DEBUG.C File Reference

  • NTSD
Defines | Typedefs | Functions

DEBUG.C File Reference

#include <stdarg.h>
#include <stdio.h>
#include <stddef.h>
#include <windows.h>
#include <winerror.h>
#include <excpt.h>
#include <ntsdexts.h>
#include "mditypes.h"

Go to the source code of this file.

Defines

#define | move(dst, src)

Typedefs

typedef LARGE_INTEGER | PHYSICAL_ADDRESS
typedef LARGE_INTEGER * | PPHYSICAL_ADDRESS

Functions

void | dinfo (HANDLE hCurrentProcess, HANDLE hCurrentThread, HANDLE dwCurrentPc, PNTSD_EXTENSION_APIS lpExtensionApis, LPSTR lpArgumentString)
BOOL WINAPI | DllMain (HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)

Define Documentation

#define move | ( | dst,
 |  | src
 | ) |
Value:
try {\
    ReadProcessMemory(hCurrentProcess, (LPVOID)(src), &(dst), sizeof(dst), NULL);\
} except (EXCEPTION_EXECUTE_HANDLER) {\
    return;\
}

Definition at line 54 of file DEBUG.C.

Typedef Documentation

typedef LARGE_INTEGER PHYSICAL_ADDRESS

Definition at line 32 of file DEBUG.C.

typedef LARGE_INTEGER * PPHYSICAL_ADDRESS

Definition at line 32 of file DEBUG.C.

Function Documentation

void dinfo | ( | HANDLE | hCurrentProcess,
 |  | HANDLE | hCurrentThread,
 |  | HANDLE | dwCurrentPc,
 |  | PNTSD_EXTENSION_APIS | lpExtensionApis,
 |  | LPSTR | lpArgumentString
 | ) |  |

Definition at line 107 of file DEBUG.C.

{
    PNTSD_OUTPUT_ROUTINE Print;
    PNTSD_GET_EXPRESSION EvalExpression;
    PNTSD_GET_SYMBOL GetSymbol;

    PINFO   pInfo;
    INFO    info;

    Print = lpExtensionApis->lpOutputRoutine;
    EvalExpression = lpExtensionApis->lpGetExpressionRoutine;
    GetSymbol = lpExtensionApis->lpGetSymbolRoutine;

    pInfo = (PINFO)EvalExpression(lpArgumentString);
    move(info, pInfo);
    Print(info.CaptionBarText);
    Print("\n");
    Print("hParent             = %x\n", info.hParent         );
    Print("hTextWnd            = %x\n", info.hTextWnd        );
    Print("rcClient(l,t,r,b)   = (%d,%d,%d,%d)\n",
                                 info.rcClient.left,  info.rcClient.top,
                                 info.rcClient.right, info.rcClient.bottom );
    return;
}

BOOL WINAPI DllMain | ( | HANDLE | hInst,
 |  | DWORD | ul_reason_being_called,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 78 of file DEBUG.C.

{
    return 1;
  UNREFERENCED_PARAMETER(hInst);
  UNREFERENCED_PARAMETER(ul_reason_being_called);
  UNREFERENCED_PARAMETER(lpReserved);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDI.C File Reference

  • NTSD
Data Structures | Defines | Typedefs | Functions | Variables

MDI.C File Reference

#include <stdlib.h>
#include "mdi.h"
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct | _PerWndInfo

Defines

#define | STRICT

Typedefs

typedef struct _PerWndInfo | INFO
typedef struct _PerWndInfo * | PINFO

Functions

BOOL CALLBACK | About (HWND, UINT, DWORD, LONG)
BOOL | InitializeApp (void)
LONG APIENTRY | MainWndProc (HWND, UINT, DWORD, LONG)
LONG APIENTRY | MDIWndProc (HWND, UINT, DWORD, LONG)
LONG APIENTRY | TextWndProc (HWND, UINT, DWORD, LONG)
VOID | vTest (PINFO)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

Variables

HANDLE | ghModule
HWND | ghwndClient = NULL
HWND | ghwndMain = NULL
CHAR | gszFile [20]
CHAR | gszMapName [20]
HMENU | hChildMenu
HMENU | hChildMenuWindow
HMENU | hMenu
HMENU | hMenuWindow

Define Documentation

#define STRICT

Definition at line 19 of file MDI.C.

Typedef Documentation

typedef struct _PerWndInfo INFO
typedef struct _PerWndInfo * PINFO

Function Documentation

BOOL CALLBACK About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | DWORD | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 510 of file MDI.C.

{
    switch (message) {
    case WM_INITDIALOG:
  return TRUE;

    case WM_COMMAND:
  if (wParam == IDOK)
      EndDialog(hDlg, wParam);
  break;
    }

    return FALSE;

    UNREFERENCED_PARAMETER(lParam);
    UNREFERENCED_PARAMETER(hDlg);
}

BOOL InitializeApp ( void )

Definition at line 108 of file MDI.C.

{
    WNDCLASS wc;

    wc.style            = CS_OWNDC;
    wc.lpfnWndProc      = (WNDPROC) MainWndProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = sizeof(LONG);
    wc.hInstance        = ghModule;
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE);
    wc.lpszMenuName     = "MainMenu";
    wc.lpszClassName    = "MDIDemoClass";

    if (!RegisterClass(&wc))
  return FALSE;

    wc.lpfnWndProc      = (WNDPROC) MDIWndProc;
    wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = "MDIClass";

    if (!RegisterClass(&wc))
  return FALSE;

    wc.style            = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc      = (WNDPROC) TextWndProc;
    wc.hIcon            = NULL;
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground    = (HBRUSH)(COLOR_BTNSHADOW);
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = "Text";

    if (!RegisterClass(&wc))
      return FALSE;

    hMenu       = LoadMenu(ghModule, "MainMenu");
    hChildMenu  = LoadMenu(ghModule, "ChildMenu");
    hMenuWindow      = GetSubMenu(hMenu, 1);
    hChildMenuWindow = GetSubMenu(hChildMenu, 2);

    ghwndMain = CreateWindowEx(0L, "MDIDemoClass", "MDI Demonstration",
      WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
      WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
      WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
      80, 70, 400, 300,
      NULL, hMenu, ghModule, NULL);

    if (ghwndMain == NULL)
  return FALSE;

    SetWindowLong(ghwndMain, GWL_USERDATA, 0L);

    SetFocus(ghwndMain);    /* set initial focus */

    return TRUE;
}

long APIENTRY MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | DWORD | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 179 of file MDI.C.

{
    static int         iMDICount=1;
    CLIENTCREATESTRUCT clientcreate;
    HWND               hwndChildWindow;

    switch (message) {

      case WM_CREATE:
  SetWindowLong(hwnd, 0, (LONG)NULL);

  clientcreate.hWindowMenu  = hMenuWindow;
  clientcreate.idFirstChild = 1;

  ghwndClient = CreateWindow("MDICLIENT", NULL,
            WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
            0,0,0,0,
            hwnd, NULL, ghModule, (LPVOID)&clientcreate);
  return 0L;

      case WM_DESTROY: {
  PostQuitMessage(0);
  return 0L;
      }

      case WM_COMMAND:

  switch (LOWORD(wParam)) {
      //
      // Getting default MDI functionalities...
      //
      case IDM_TILE:
    SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
    return 0L;
      case IDM_CASCADE:
    SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
    return 0L;
      case IDM_ARRANGE:
    SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
    return 0L;

      //
      // Creates MDI child
      //
      case MM_MDI: {
    HANDLE hInfo;
    PINFO  pInfo;
    MDICREATESTRUCT mdicreate;

    //
    // Allocating memory for INFO to be associated with the
    //  new child
    //
    hInfo = LocalAlloc(LHND, (WORD) sizeof(INFO));
    if (hInfo) {
        if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
      MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

        wsprintf((LPSTR) &(pInfo->CaptionBarText),
           "MDI %d", iMDICount);
        pInfo->hParent    = ghwndClient;

        mdicreate.szClass = "MDIClass";
        mdicreate.szTitle = (LPTSTR)&(pInfo->CaptionBarText);
        mdicreate.hOwner  = ghModule;
        mdicreate.x       =
        mdicreate.y       =
        mdicreate.cx      =
        mdicreate.cy      = CW_USEDEFAULT;
        mdicreate.style   = 0L;
        //
        // passing the handle of the per MDI child INFO to the
        //  child MDI window for storage
        //
        mdicreate.lParam  = (LONG) hInfo;

        /*Create Child Window*/
        hwndChildWindow =
      (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
            0L,
            (LONG)(LPMDICREATESTRUCT)&mdicreate);

        if (hwndChildWindow == NULL) {
      MessageBox(ghwndMain, "Failed in Creating Child Window", "Error", MB_OK);
      return 0L;
        }

        iMDICount++;

        LocalUnlock(hInfo);
    } else {
          MessageBox(ghwndMain, "Failed to Allocate INFO data!", "Error", MB_OK);
    }
    return 0L;
      }

      case MM_ABOUT:
    if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
      MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
    return 0L;

      //
      // Passes these WM_COMMAND messages to the appropriate active child
      //  window proc for processing
      //
      case MM_OPT_1:
      case MM_OPT_2:
      case MM_OPT_3:
      case MM_OPT_4:
      case MM_OPT_5:
      case MM_OPT_6:
      case MM_OPT_7:
      case MM_OPT_8: {
    HWND hActiveChild;

    hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L);
    if (hActiveChild)
        SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
    return 0L;
      }

      default:
    return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
  }

    default:

  return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
    }
}

long APIENTRY MDIWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | DWORD | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 326 of file MDI.C.

{

    switch (message) {
  case WM_COMMAND: {
    HANDLE      hInfo;
    PINFO       pInfo;
    HWND        hTextWnd;

    //
    // Retrieving this child window's INFO data for displaying
    //    messages in the text window
    //
    hInfo = (HANDLE) GetWindowLong(hwnd, 0);
    if (hInfo) {
        if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
      MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

        hTextWnd = pInfo->hTextWnd;
        vTest(pInfo);
        LocalUnlock(hInfo);
    } else {
        MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
    }

    switch (LOWORD(wParam)) {
      case MM_OPT_1: {
         SetWindowText(hTextWnd, "MM_OPT_1");
         return 0L;
      }

      case MM_OPT_2: {
         SetWindowText(hTextWnd, "MM_OPT_2");
         return 0L;
      }

      case MM_OPT_3: {
         SetWindowText(hTextWnd, "MM_OPT_3");
         return 0L;
      }

      case MM_OPT_4: {
         SetWindowText(hTextWnd, "MM_OPT_4");
         return 0L;
      }
      default:
         return 0L;

    }

  }
  case WM_SETFOCUS:
      break;

  //
  // Potentially, you can set different menu for different MDI
  //  child which is currently being active.
  //
  case WM_MDIACTIVATE:
      if ((HWND) lParam == hwnd) {
    SendMessage(GetParent(hwnd), WM_MDISETMENU,
          (DWORD)  hChildMenu,
          (LONG)   hChildMenuWindow) ;
    DrawMenuBar(GetParent(GetParent(hwnd))) ;
      }
      return 0L;

  //
  // Whenever the MDI child window is resized, its children has to be
  //  resized accordingly.
  //
  case WM_SIZE: {
      HANDLE      hInfo;
      PINFO       pInfo;
      HWND        hTextWnd;

      //
      // First, get the text window's handle from the per MDI child
      //  INFO data structure
      //
      hInfo = (HANDLE) GetWindowLong(hwnd, 0);
      if (hInfo) {
    if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
        MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

    hTextWnd = pInfo->hTextWnd;
    LocalUnlock(hInfo);
      } else {
    MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
      }

      //
      // Always, put the text window at the bottom of the MDI window
      //
      MoveWindow(hTextWnd,
           0,
           HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
           LOWORD(lParam),
           HIWORD(lParam), TRUE);
      break;
  }

  //
  // Creates the text window for this MDI child and saves its handle
  //  in the per MDI child INFO data structure.
  //
  case WM_CREATE: {
      PINFO           pInfo;
      HANDLE          hInfo;
      HWND            hTextWnd;

      hTextWnd = CreateWindow("Text", NULL,
            WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
            0, 0, 0, 0,
            hwnd,
            (HMENU) 2,
            ghModule,
            NULL);

      SetWindowText(hTextWnd, "Select 'Option' menu items");
      //
      // INFO was allocated in the MDIWndProc at MM_MDI time and is
      //  passed to us at WM_CREATE time...
      //
      hInfo = (HANDLE) ((LPMDICREATESTRUCT) ((LPCREATESTRUCT) lParam)->lpCreateParams)->lParam ;
      if (hInfo) {
    if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
        MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);

    if (!GetClientRect(hwnd, &pInfo->rcClient))
        MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);

    pInfo->hTextWnd = hTextWnd;
    //
    // Save the handle to INFO in our window structure
    //
    SetWindowLong(hwnd, 0, (LONG) hInfo);
    LocalUnlock(hInfo);
      } else {
    MessageBox(ghwndMain, "Can't allocate hInfo!", "Error", MB_OK);
      }

      break;
  }

  //
  // Free the INFO data that associates with this window
  //  also, reset the menu.
  //
  case WM_CLOSE: {
      HANDLE           hInfo;

      SendMessage(GetParent(hwnd), WM_MDISETMENU,
          (DWORD) hMenu,
          (LONG)  hMenuWindow) ;
      DrawMenuBar(GetParent(GetParent(hwnd))) ;

      hInfo = (HANDLE) GetWindowLong(hwnd, 0);
      LocalFree(hInfo);
      break;
  }

  default:
      return DefMDIChildProc(hwnd, message, wParam, lParam);

    } //switch
    return DefMDIChildProc(hwnd, message, wParam, lParam);
}

LONG APIENTRY TextWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | DWORD | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 544 of file MDI.C.

{
    static HFONT hFont = (HFONT) NULL;

    switch (message)
    {
    case WM_CREATE:
  {
      LOGFONT    lf;
      HDC        hDC;
      HFONT      hOldFont;
      TEXTMETRIC tm;
      RECT       rect;
      LONG       lHeight;

      SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);

      hDC = GetDC(hwnd);
      // this is the height for 8 point size font in pixels
      lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;

      hFont = CreateFontIndirect(&lf);
      hOldFont = SelectObject(hDC, hFont);
      GetTextMetrics(hDC, &tm);
      GetClientRect(GetParent(hwnd), &rect);

      // base the height of the window on size of text
      lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
      // saved the height for later reference
      SetWindowLong(hwnd, GWL_USERDATA, lHeight);
      SetWindowPos(hwnd, NULL,
        0,
        rect.bottom-lHeight,
        rect.right-rect.left,
        lHeight,
        SWP_NOZORDER | SWP_NOMOVE);

      ReleaseDC(hwnd, hDC);
      break;
  }

    case WM_DESTROY:
      if (hFont)
    DeleteObject(hFont);
      break;

    case WM_SETTEXT:
      DefWindowProc(hwnd, message, wParam, lParam);
      InvalidateRect(hwnd,NULL,FALSE);
      UpdateWindow(hwnd);
      return 0L;

    case WM_PAINT:
  {
      PAINTSTRUCT ps;
      RECT   rc;
      char   ach[128];
      int    len, nxBorder, nyBorder;
      HFONT  hOldFont = NULL;

      BeginPaint(hwnd, &ps);

      GetClientRect(hwnd,&rc);

      nxBorder = GetSystemMetrics(SM_CXBORDER);
      rc.left  += 9*nxBorder;
      rc.right -= 9*nxBorder;

      nyBorder = GetSystemMetrics(SM_CYBORDER);
      rc.top    += 3*nyBorder;
      rc.bottom -= 3*nyBorder;

      // 3D Text
      len = GetWindowText(hwnd, ach, sizeof(ach));
      SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));

      SetBkMode(ps.hdc, TRANSPARENT);
      SetTextColor(ps.hdc, RGB(64,96,96));
      if (hFont)
    hOldFont = SelectObject(ps.hdc, hFont);
      ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
      &rc, ach, len, NULL);

      SetTextColor(ps.hdc, RGB(128,128,128));
      if (hFont)
    hOldFont = SelectObject(ps.hdc, hFont);
      ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
      &rc, ach, len, NULL);

      SetTextColor(ps.hdc, RGB(255,255,255));
      if (hFont)
    hOldFont = SelectObject(ps.hdc, hFont);
      ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
      &rc, ach, len, NULL);

      SetBkMode(ps.hdc, OPAQUE);

      if (hOldFont)
    SelectObject(ps.hdc, hOldFont);

      EndPaint(hwnd, &ps);
      return 0L;
  }
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

VOID vTest ( PINFO pInfo )

Definition at line 651 of file MDI.C.

{
    OutputDebugString("Inside vTest()\n");

    UNREFERENCED_PARAMETER(pInfo);
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nShowCmd
 | ) |  |

Definition at line 63 of file MDI.C.

{
    MSG    msg;
    HANDLE hAccel;

    ghModule = GetModuleHandle(NULL);
    if (!InitializeApp()) {
  MessageBox(ghwndMain, "MDI: InitializeApp failure!", "Error", MB_OK);
  return 0;
    }

    if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
  MessageBox(ghwndMain, "MDI: Load Accel failure!", "Error", MB_OK);

    while (GetMessage(&msg, NULL, 0, 0)) {
  if (!TranslateAccelerator( ghwndMain, hAccel, &msg) &&
      !TranslateMDISysAccel(  ghwndClient, &msg)          ) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }
    }

    return 1;

    UNREFERENCED_PARAMETER(lpCmdLine);
    UNREFERENCED_PARAMETER(nShowCmd);
    UNREFERENCED_PARAMETER(hInstance);
    UNREFERENCED_PARAMETER(hPrevInstance);
}

Variable Documentation

HANDLE ghModule

Definition at line 24 of file MDI.C.

HWND ghwndClient = NULL

Definition at line 26 of file MDI.C.

HWND ghwndMain = NULL

Definition at line 25 of file MDI.C.

CHAR gszFile[20]

Definition at line 31 of file MDI.C.

CHAR gszMapName[20]

Definition at line 32 of file MDI.C.

HMENU hChildMenu

Definition at line 29 of file MDI.C.

HMENU hChildMenuWindow

Definition at line 29 of file MDI.C.

HMENU hMenu

Definition at line 28 of file MDI.C.

HMENU hMenuWindow

Definition at line 28 of file MDI.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDI.H File Reference

  • NTSD
Defines

MDI.H File Reference

#include <windows.h>
#include <string.h>

Go to the source code of this file.

Defines

#define | ACCEL_ID 100
#define | IDM_ARRANGE 32
#define | IDM_CASCADE 30
#define | IDM_CLOSEALL 33
#define | IDM_TILE 31
#define | MM_ABOUT 8000
#define | MM_MDI 8001
#define | MM_OPT_1 7001
#define | MM_OPT_2 7002
#define | MM_OPT_3 7003
#define | MM_OPT_4 7004
#define | MM_OPT_5 7005
#define | MM_OPT_6 7006
#define | MM_OPT_7 7007
#define | MM_OPT_8 7008
#define | MM_RESERVE1 8002
#define | MM_RESERVE2 8003
#define | SIZEOFCAPTIONTEXT 20

Define Documentation

#define ACCEL_ID 100

Definition at line 47 of file MDI.H.

#define IDM_ARRANGE 32

Definition at line 42 of file MDI.H.

#define IDM_CASCADE 30

Definition at line 40 of file MDI.H.

#define IDM_CLOSEALL 33

Definition at line 43 of file MDI.H.

#define IDM_TILE 31

Definition at line 41 of file MDI.H.

#define MM_ABOUT 8000

Definition at line 26 of file MDI.H.

#define MM_MDI 8001

Definition at line 27 of file MDI.H.

#define MM_OPT_1 7001

Definition at line 31 of file MDI.H.

#define MM_OPT_2 7002

Definition at line 32 of file MDI.H.

#define MM_OPT_3 7003

Definition at line 33 of file MDI.H.

#define MM_OPT_4 7004

Definition at line 34 of file MDI.H.

#define MM_OPT_5 7005

Definition at line 35 of file MDI.H.

#define MM_OPT_6 7006

Definition at line 36 of file MDI.H.

#define MM_OPT_7 7007

Definition at line 37 of file MDI.H.

#define MM_OPT_8 7008

Definition at line 38 of file MDI.H.

#define MM_RESERVE1 8002

Definition at line 28 of file MDI.H.

#define MM_RESERVE2 8003

Definition at line 29 of file MDI.H.

#define SIZEOFCAPTIONTEXT 20

Definition at line 45 of file MDI.H.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDITYPES.H File Reference

  • NTSD
Data Structures | Typedefs

MDITYPES.H File Reference

#include "mdi.h"

Go to the source code of this file.

Data Structures

struct | _PerWndInfo

Typedefs

typedef struct _PerWndInfo | INFO
typedef struct _PerWndInfo * | PINFO

Typedef Documentation

typedef struct _PerWndInfo INFO
typedef struct _PerWndInfo * PINFO
Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OTHRPROC/OTHRPROC.C File Reference

  • OTHRPROC
Defines | Functions | Variables

OTHRPROC.C File Reference

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "othrproc.h"

Go to the source code of this file.

Defines

#define | WERR(who, where)

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | ReadProc (VOID)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

CHAR | Buf [80]
CHAR | Buf2 [80]
HANDLE | hInst
HANDLE | hMapObject
HANDLE | hThread
HWND | hWnd
HWND | hWndDlg
LONG * | MapView

Define Documentation

#define WERR | ( | who,
 |  | where
 | ) |
Value:
{sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
                            sprintf(Buf2,"From within %s", where);\
                            MessageBox(hwnd, Buf, Buf2, MB_OK);}

Definition at line 68 of file OTHRPROC.C.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 198 of file OTHRPROC.C.

{
    DWORD ThreadID;

    switch (message)
    {
        case WM_CREATE:
            hMapObject = OpenFileMapping (FILE_MAP_READ,
                                          FALSE,
                                          "shared_memory");
            if (!hMapObject)
            {
                WERR("OpenFileMapping","WM_CREATE");
                PostQuitMessage (0);
                return (0);
            }

            (LPVOID)MapView = MapViewOfFile (hMapObject,
                                             FILE_MAP_READ,
                                             0, 0, 0);
            if (!MapView)
            {
                MessageBox (hwnd, "ERROR: MapViewOfFile was not successful.",
                            "From within WM_CREATE", MB_OK);
                PostQuitMessage (0);
                return (0);
            }

            hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReadProc,
                                   NULL, 0, &ThreadID);
            if (!hThread)
            {
                WERR("CreateThread", "WM_CREATE");
                PostQuitMessage(0);
            }

            return (0);

        case WM_SIZE :
            SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
            return (0);

        case WM_DESTROY :
            CloseHandle (hMapObject);
            CloseHandle (hThread);
            PostQuitMessage (0);
            return (0);

    }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

VOID ReadProc ( VOID )

Definition at line 298 of file OTHRPROC.C.

{
    HBITMAP hCrossHair;
    LONG lParam, oldParam = 0;
    HDC hDC, hDCMem;
    int X, Y;
    HANDLE hBrush;
    RECT Rect;
    BITMAP bm;
    POINT ptSize, ptOrg;

    _try
    {
        lParam = MapView[0];
    }
    _except(EXCEPTION_EXECUTE_HANDLER)
    {
        MessageBox(hWnd, "Trying to read shared memory caused an exception.",
                   "From within WM_MOUSEMOVE", MB_OK);
        PostMessage(hWnd, WM_DESTROY, 0, 0);
    }

    hBrush = GetStockObject(WHITE_BRUSH);
    X = LOWORD(lParam);
    Y = HIWORD(lParam);

    hCrossHair = LoadBitmap(hInst, "CrossHair");

    while (1)
    {
        lParam = MapView[0];

        if (lParam != oldParam)
        {
            hDC = GetDC(hWnd);

            Rect.top = Y; Rect.left = X; Rect.bottom = Y+16; Rect.right = X+16;
            FillRect(hDC, &Rect, hBrush);

            X = LOWORD(lParam);
            Y = HIWORD(lParam);

            hDCMem = CreateCompatibleDC(hDC);
            SelectObject(hDCMem, hCrossHair);
            SetMapMode(hDCMem, GetMapMode(hDC));

            GetObject(hCrossHair, sizeof(BITMAP), &bm);

            ptSize.x = bm.bmWidth;
            ptSize.y = bm.bmHeight;
            DPtoLP (hDC, &ptSize, 1);

            ptOrg.x = 0;
            ptOrg.y = 0;
            DPtoLP (hDCMem, &ptOrg, 1);

            BitBlt(hDC, X, Y, ptSize.x, ptSize.y,
                   hDCMem, ptOrg.x, ptOrg.y, SRCCOPY);

            oldParam = lParam;
            SetDlgItemInt (hWndDlg, IDE_XCOORD, X, FALSE);
            SetDlgItemInt (hWndDlg, IDE_YCOORD, Y, FALSE);
            ReleaseDC(hWnd, hDC);
            DeleteDC(hDCMem);

            Sleep(100);
        }
    }
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 95 of file OTHRPROC.C.

{

    MSG  msg;
    WNDCLASS wc;
    RECT rect;
    DWORD dwVersion = GetVersion();

    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( hPrevInstance );

    // check if running on Windows NT, if not, display notice and terminate
    if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
        MessageBoxA(NULL,
                    "This sample application cannot run on Win32s.\n"
                    "This application will now terminate.",
                    "OthrProc",
                    MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

    hInst = hInstance;

    wc.style = 0;                          // Replaces CS_SIZEREDRAW.
    wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
    wc.cbClsExtra = 0;                     // No room reserved for extra data.
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName = "";
    wc.lpszClassName = "OthrProcWClass";

    RegisterClass(&wc);

    hWnd = CreateWindow ("OthrProcWClass",
                         "Other Procedure",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         NULL,
                         NULL,
                         hInstance,
                         NULL);

    hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, NULL);

    GetClientRect (hWnd, &rect);
    SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
    ShowWindow  (hWndDlg,  SW_SHOW);
    ShowWindow  (hWnd, nCmdShow);

    while (GetMessage (&msg, NULL, 0, 0))
    if (!IsDialogMessage (hWndDlg, &msg))
    {
        DispatchMessage (&msg);    // Dispatch message to window.
    }

    return (msg.wParam);           // Returns value from PostQuitMessage.
}

Variable Documentation

CHAR Buf[80]

Definition at line 72 of file OTHRPROC.C.

CHAR Buf2[80]

Definition at line 73 of file OTHRPROC.C.

HANDLE hInst

Definition at line 75 of file OTHRPROC.C.

HANDLE hMapObject

Definition at line 76 of file OTHRPROC.C.

HANDLE hThread

Definition at line 78 of file OTHRPROC.C.

HWND hWnd

Definition at line 77 of file OTHRPROC.C.

HWND hWndDlg

Definition at line 77 of file OTHRPROC.C.

LONG* MapView

Definition at line 79 of file OTHRPROC.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OTHRPROC/OTHRPROC.H File Reference

  • OTHRPROC
Defines | Functions

OTHRPROC.H File Reference

Go to the source code of this file.

Defines

#define | DIALOGHEIGHT 45
#define | IDE_XCOORD 101
#define | IDE_YCOORD 102

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | ReadProc (VOID)
BOOL CALLBACK | StatusDlgProc (HWND, UINT, WPARAM, LPARAM)

Define Documentation

#define DIALOGHEIGHT 45

Definition at line 16 of file OTHRPROC.H.

#define IDE_XCOORD 101

Definition at line 12 of file OTHRPROC.H.

#define IDE_YCOORD 102

Definition at line 13 of file OTHRPROC.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID ReadProc ( VOID )

Definition at line 298 of file OTHRPROC.C.

{
    HBITMAP hCrossHair;
    LONG lParam, oldParam = 0;
    HDC hDC, hDCMem;
    int X, Y;
    HANDLE hBrush;
    RECT Rect;
    BITMAP bm;
    POINT ptSize, ptOrg;

    _try
    {
        lParam = MapView[0];
    }
    _except(EXCEPTION_EXECUTE_HANDLER)
    {
        MessageBox(hWnd, "Trying to read shared memory caused an exception.",
                   "From within WM_MOUSEMOVE", MB_OK);
        PostMessage(hWnd, WM_DESTROY, 0, 0);
    }

    hBrush = GetStockObject(WHITE_BRUSH);
    X = LOWORD(lParam);
    Y = HIWORD(lParam);

    hCrossHair = LoadBitmap(hInst, "CrossHair");

    while (1)
    {
        lParam = MapView[0];

        if (lParam != oldParam)
        {
            hDC = GetDC(hWnd);

            Rect.top = Y; Rect.left = X; Rect.bottom = Y+16; Rect.right = X+16;
            FillRect(hDC, &Rect, hBrush);

            X = LOWORD(lParam);
            Y = HIWORD(lParam);

            hDCMem = CreateCompatibleDC(hDC);
            SelectObject(hDCMem, hCrossHair);
            SetMapMode(hDCMem, GetMapMode(hDC));

            GetObject(hCrossHair, sizeof(BITMAP), &bm);

            ptSize.x = bm.bmWidth;
            ptSize.y = bm.bmHeight;
            DPtoLP (hDC, &ptSize, 1);

            ptOrg.x = 0;
            ptOrg.y = 0;
            DPtoLP (hDCMem, &ptOrg, 1);

            BitBlt(hDC, X, Y, ptSize.x, ptSize.y,
                   hDCMem, ptOrg.x, ptOrg.y, SRCCOPY);

            oldParam = lParam;
            SetDlgItemInt (hWndDlg, IDE_XCOORD, X, FALSE);
            SetDlgItemInt (hWndDlg, IDE_YCOORD, Y, FALSE);
            ReleaseDC(hWnd, hDC);
            DeleteDC(hDCMem);

            Sleep(100);
        }
    }
}

BOOL CALLBACK StatusDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |
Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OVCOMM/OVCOMM.C File Reference

  • OVCOMM
Functions

OVCOMM.C File Reference

#include <windows.h>
#include <stdio.h>
#include "OvComm.h"

Go to the source code of this file.

Functions

void | BreakDownCommPort (void)
void | CheckModemStatus (void)
BOOL WINAPI | ControlHandlerProc (DWORD dwCtrlType)
void | ErrorHandler (char *szMessage)
void | ErrorInComm (char *szMessage)
void | ErrorReporter (char *szMessage)
int | main (int argc, char *argv[])
void | OutputABuffer (HANDLE hOut, char *lpBuf, DWORD dwBufLen)
void | ProcessIO (HANDLE hIn, HANDLE hOut)
DWORD WINAPI | ReaderProc (LPVOID lpV)
void | ReportCommError (void)
void | ReportModemStatus (DWORD dwModemStatus)
void | ReportStatusEvent (DWORD dwStatus)
BOOL | SetupCommandLineOptions (int cArgs, char *argv[])
HANDLE | SetupCommPort (void)
DWORD WINAPI | StatusProc (LPVOID lpV)
DWORD WINAPI | WriterProc (LPVOID lpV)

Function Documentation

void BreakDownCommPort ( void )

Definition at line 211 of file OVCOMM.C.

{
    // lower DTR
  if (!EscapeCommFunction(comHandle, CLRDTR))
    ErrorReporter("EscapeCommFunction(CLRDTR)");

    // restore original comm timeouts
    if (!SetCommTimeouts(comHandle, &g_timeouts))
        ErrorReporter("SetCommTimeouts (Restoration to original)");

  if (!PurgeComm(comHandle, PURGE_FLAGS))
        ErrorReporter("PurgeComm");

    CloseHandle(comHandle);
}

void CheckModemStatus ( void )

Definition at line 269 of file OVCOMM.C.

{
  static DWORD dwOldStatus = 0;
  DWORD dwNewModemStatus;

  if (!GetCommModemStatus(comHandle, &dwNewModemStatus))
    ErrorReporter("GetCommModemStatus");

  if (dwNewModemStatus != dwOldStatus) {  // status changed?
        ReportModemStatus(dwNewModemStatus);
        dwOldStatus = dwNewModemStatus;
    }

    return;
}

BOOL WINAPI ControlHandlerProc ( DWORD dwCtrlType )

Definition at line 802 of file OVCOMM.C.

{
    // we can clean up here
    OutputDebugString("Control Event Handled\n\rExiting\n\r");
    printf("\n\n\rExiting...");
    bDone = TRUE;

    return TRUE;   // don't call default handler
}

void ErrorHandler ( char * szMessage )

Definition at line 102 of file OVCOMM.C.

{
    ErrorReporter(szMessage);
  exit(0);
}

void ErrorInComm ( char * szMessage )

Definition at line 118 of file OVCOMM.C.

{
  ErrorReporter(szMessage);
    BreakDownCommPort();
    exit(0);
}

void ErrorReporter ( char * szMessage )

Definition at line 67 of file OVCOMM.C.

{
  DWORD dwErr;
  char * szTemp;
    char * szFormat = "Error %d: %s.\n\r";

    dwErr = GetLastError();

  // allocate a temporary buffer
  szTemp = malloc(strlen(szMessage) + 20);

  if (szTemp == NULL) // if no buffer, then printf message
    printf(szFormat, dwErr, szMessage);
  else {
    wsprintf(szTemp, szFormat, dwErr, szMessage);
    printf(szTemp);           // printf message on console
    OutputDebugString(szTemp);  // and debugger
    free(szTemp);         // free buffer
  }

    return;
}

int main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 824 of file OVCOMM.C.

{
  DWORD dwOldMode, dwNewMode, dwVersion;
  HANDLE hStdOut, hStdIn;

    // check if running on Win32s, if so, display notice and terminate

    dwVersion = GetVersion();
    if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) ) {
        MessageBoxA( NULL,
            "This sample application will not run on Windows 3.1.\n"
            "This application will now terminate.",
            "OvComm",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return 1 ;
    }

    // parse command line
    if (!SetupCommandLineOptions(argc, argv)) {
        printf("Usage: comm <port identifier> <serial spec string>\n");
        printf("\n   example:  comm com1 9600,N,8,1\n");
        printf("     The serial spec string cannot contain spaces\n");
        printf("     The serial spec string follows the same guidelines\n");
        printf("       as the MS-DOS 'mode' command\n");
        return 0;
    }

    // setup console mode and std handles
    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  hStdIn = GetStdHandle(STD_INPUT_HANDLE);

  if (hStdOut == hStdIn)
    ErrorHandler("GetStdHandle");

  if (!GetConsoleMode(hStdIn, &dwOldMode))
    ErrorHandler("GetConsoleMode (old)");

    // turn off echo and CR & ctrl-c handling; I'll do it myself.
  dwNewMode = dwOldMode
              & ~ENABLE_LINE_INPUT
              & ~ENABLE_ECHO_INPUT
              & ~ENABLE_PROCESSED_INPUT;

  if (!SetConsoleMode(hStdIn, dwNewMode))
    ErrorHandler("SetConsoleMode (new)");

    if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)ControlHandlerProc, TRUE))
        ErrorHandler("SetConsoleCtrlHandler");

  ProcessIO(hStdIn, hStdOut);

    // restore console mode
  if (!SetConsoleMode(hStdIn, dwOldMode))
    ErrorReporter("SetConsoleMode (old)");

  return 0;
}

void OutputABuffer | ( | HANDLE | hOut,
 |  | char * | lpBuf,
 |  | DWORD | dwBufLen
 | ) |  |

Definition at line 502 of file OVCOMM.C.

{
  DWORD dwWritten;

  if (dwBufLen != 0) {
    if (!WriteFile(hOut, lpBuf, dwBufLen, &dwWritten, NULL))
      ErrorReporter("WriteFile (console) in Reader");
  }
    else
        OutputDebugString("Attempt to write empty buffer\n\r");
  return;
}

void ProcessIO | ( | HANDLE | hIn,
 |  | HANDLE | hOut
 | ) |  |

Definition at line 660 of file OVCOMM.C.

{
  DWORD dwReaderId, dwWriterId, dwStatusId, dwRes;
  HANDLE hReader, hWriter, hStatus;
    HANDLE hThreads[3];

  // setup comm port
  SetupCommPort();

    // create all threads (suspended)
  hReader = CreateThread( NULL,
                          0,
                          (LPTHREAD_START_ROUTINE) ReaderProc,
                          (LPVOID) hOut,
                          CREATE_SUSPENDED,
                          &dwReaderId);
  if (hReader == NULL)
    ErrorInComm("CreateThread (Reader)");

  hWriter = CreateThread( NULL,
                          0,
                          (LPTHREAD_START_ROUTINE) WriterProc,
                          (LPVOID) hIn,
                          CREATE_SUSPENDED,
                          &dwWriterId);
  if (hWriter == NULL)
    ErrorInComm("CreateThread (Writer)");

  hStatus = CreateThread( NULL,
                          0,
                          (LPTHREAD_START_ROUTINE) StatusProc,
                          (LPVOID) NULL,
                          CREATE_SUSPENDED,
                          &dwStatusId);
  if (hStatus == NULL)
    ErrorInComm("CreateThread (Status)");

  // start status monitoring thread
  ResumeThread(hStatus);

    // Comm event mask has been initialized and initial modem status reported
    // when hSetupEvent has been signalled.
    if (WaitForSingleObject(hSetupEvent, 1000) != WAIT_OBJECT_0)
    OutputDebugString("Setup event not set.  Proceeding anyway.\n\r");

    CloseHandle(hSetupEvent);

    // start reader/writer threads
  ResumeThread(hReader);
  ResumeThread(hWriter);

    hThreads[0] = hStatus;
    hThreads[1] = hReader;
    hThreads[2] = hWriter;

  // wait for threads to exit
  for (;;) {
        dwRes = WaitForMultipleObjects(3, hThreads, TRUE, 5000);
    if (dwRes == WAIT_OBJECT_0)
      break;

    if (dwRes == WAIT_FAILED)
      ErrorInComm("WaitForMultipleObjects");

        if (bDone && dwRes == WAIT_TIMEOUT) {
            if (WaitForSingleObject(hStatus, 0) == WAIT_TIMEOUT)
                OutputDebugString("Status Thread didn't exit.\n\r");

            if (WaitForSingleObject(hReader, 0) == WAIT_TIMEOUT)
                OutputDebugString("Reader Thread didn't exit.\n\r");

            if (WaitForSingleObject(hWriter, 0) == WAIT_TIMEOUT)
                OutputDebugString("Writer Thread didn't exit.\n\r");

            break;
        }
  }

    BreakDownCommPort();

  // clean up handles

  CloseHandle(hReader);
  CloseHandle(hWriter);
  CloseHandle(hStatus);

  OutputDebugString("ProcessIO Exiting\n");
}

DWORD WINAPI ReaderProc ( LPVOID lpV )

Definition at line 525 of file OVCOMM.C.

{
  BOOL     bWaitingOnRead = FALSE;
  char     lpBuf[MAX_READ_BUFFER];
  DWORD      dwRead, dwRes;
  HANDLE     hReadEvent;
  OVERLAPPED ov = {0};
  HANDLE     hOut;  // std output

  hOut = (HANDLE) lpV;

  hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  if (hReadEvent == NULL)
    ErrorInComm("CreateEvent (ReadEvent)");

  ov.hEvent = hReadEvent;

  while (!bDone)
  {
    if (bWaitingOnRead) {
        // wait for read to finish
      dwRes = WaitForSingleObject(hReadEvent, READ_TIMEOUT);
      switch(dwRes)
      {
        case WAIT_TIMEOUT:      // read timed out
                    // timeouts are not reported because they happen too often
                    // take comments out of next line to report read timeouts
                    // OutputDebugString("Read timeout\n\r");
          break;

        case WAIT_OBJECT_0:     // read completed
          if (!GetOverlappedResult(comHandle, &ov, &dwRead, TRUE)) {
                        if (GetLastError() == ERROR_OPERATION_ABORTED)
                            OutputDebugString("Read aborted\n\r");
                        else
                          ErrorInComm("GetOverlappedResult (in Reader)");
                    }
          else {
            // read completed successfully
            bWaitingOnRead = FALSE;
            OutputABuffer(hOut, lpBuf, dwRead);
            ResetEvent(hReadEvent);   // reset event for next read
          }

          break;

        default:          // wait on event failed
            ErrorReporter("WaitForSingleObject(hReadEvent)");
            break;
      }
    }

    if (!bWaitingOnRead) {
            // issue read
      if (!ReadFile(comHandle, lpBuf, MAX_READ_BUFFER, &dwRead, &ov)) {
          // read failed
        if (GetLastError() != ERROR_IO_PENDING)   // read not delayed?
          ErrorInComm("ReadFile (comHandle) in Reader");

        bWaitingOnRead = TRUE;
      }
      else {    // read completed immediately
        if (dwRead != 0)
          OutputABuffer(hOut, lpBuf, dwRead);
                else
                    OutputDebugString("Read 0 bytes and didn't overlap.\n\r");
      }
    }
  }

    CloseHandle(hReadEvent);
  OutputDebugString("Reader Thread Exiting\n");

  return 1;
}

void ReportCommError ( void )

Definition at line 295 of file OVCOMM.C.

{
    COMSTAT comStat;
    DWORD   dwErrors;
    char    szMessage[100];
    BOOL    bBREAK, bDNS, bFRAME, bIOE, bMODE;
    BOOL    bOOP, bOVERRUN, bPTO, bRXOVER, bRXPARITY, bTXFULL;

    if (!ClearCommError(comHandle, &dwErrors, &comStat))
        ErrorInComm("ClearCommError");

    bDNS = dwErrors & CE_DNS;
    bIOE = dwErrors & CE_IOE;
    bOOP = dwErrors & CE_OOP;
    bPTO = dwErrors & CE_PTO;
    bMODE = dwErrors & CE_MODE;
    bBREAK = dwErrors & CE_BREAK;
    bFRAME = dwErrors & CE_FRAME;
    bRXOVER = dwErrors & CE_RXOVER;
    bTXFULL = dwErrors & CE_TXFULL;
    bOVERRUN = dwErrors & CE_OVERRUN;
    bRXPARITY = dwErrors & CE_RXPARITY;

    strcpy(szMessage, "ERROR: ");
    strcat(szMessage, bDNS ? "DNS " : "");
    strcat(szMessage, bIOE ? "IOE " : "");
    strcat(szMessage, bOOP ? "OOP " : "");
    strcat(szMessage, bPTO ? "PTO " : "");
    strcat(szMessage, bMODE ? "MODE " : "");
    strcat(szMessage, bBREAK ? "BREAK " : "");
    strcat(szMessage, bFRAME ? "FRAME " : "");
    strcat(szMessage, bRXOVER ? "RXOVER " : "");
    strcat(szMessage, bTXFULL ? "TXFULL " : "");
    strcat(szMessage, bOVERRUN ? "OVERRUN " : "");
    strcat(szMessage, bRXPARITY ? "RXPARITY " : "");
    strcat(szMessage, "\n\r");

    OutputDebugString(szMessage);

    if (comStat.fCtsHold)
        OutputDebugString("Tx waiting for CTS signal\n\r");

    if (comStat.fDsrHold)
        OutputDebugString("Tx waiting for DSR signal\n\r");

    if (comStat.fRlsdHold)
        OutputDebugString("Tx waiting for RLSD signal\n\r");

    if (comStat.fXoffHold)
        OutputDebugString("Tx waiting, XOFF char rec'd\n\r");

    if (comStat.fXoffSent)
        OutputDebugString("Tx waiting, XOFF char sent\n\r");

    if (comStat.fEof)
        OutputDebugString("EOF character received\n\r");

    if (comStat.fTxim)
        OutputDebugString("Character waiting for Tx\n\r");

    if (comStat.cbInQue) {
        sprintf(szMessage, "%d bytes in input buffer\n\r", comStat.cbInQue);
        OutputDebugString(szMessage);
    }

    if (comStat.cbOutQue) {
        sprintf(szMessage, "%d bytes in output buffer\n\r", comStat.cbOutQue);
        OutputDebugString(szMessage);
    }

    return;
}

void ReportModemStatus ( DWORD dwModemStatus )

Definition at line 237 of file OVCOMM.C.

{
  BOOL bCTS, bDSR, bRING, bRLSD;
    char szMessage[35];

  bCTS = MS_CTS_ON & dwModemStatus;
  bDSR = MS_DSR_ON & dwModemStatus;
  bRING = MS_RING_ON & dwModemStatus;
  bRLSD = MS_RLSD_ON & dwModemStatus;

    strcpy(szMessage, "MODEM STATUS: ");
    strcat(szMessage, bCTS ? "CTS " : "cts ");
  strcat(szMessage, bDSR ? "DSR " : "dsr ");
  strcat(szMessage, bRING ? "RING " : "ring ");
  strcat(szMessage, bRLSD ? "RLSD " : "rlsd ");
    strcat(szMessage,"\n\r");

    OutputDebugString(szMessage);

    return;
}

void ReportStatusEvent ( DWORD dwStatus )

Definition at line 377 of file OVCOMM.C.

{
  BOOL bBREAK, bCTS, bDSR, bERR;
  BOOL bRING, bRLSD, bRXCHAR, bRXFLAG, bTXEMPTY;
    char szMessage[70];

  bCTS = EV_CTS & dwStatus;
  bDSR = EV_DSR & dwStatus;
  bERR = EV_ERR & dwStatus;
  bRING = EV_RING & dwStatus;
  bRLSD = EV_RLSD & dwStatus;
  bBREAK = EV_BREAK & dwStatus;
  bRXCHAR = EV_RXCHAR & dwStatus;
    bRXFLAG = EV_RXFLAG & dwStatus;
  bTXEMPTY = EV_TXEMPTY & dwStatus;

    strcpy(szMessage, "EVENT: ");
    strcat(szMessage, bCTS ? "CTS " : "");
  strcat(szMessage, bDSR ? "DSR " : "");
  strcat(szMessage, bERR ? "ERR " : "");
  strcat(szMessage, bRING ? "RING " : "");
  strcat(szMessage, bRLSD ? "RLSD " : "");
  strcat(szMessage, bBREAK ? "BREAK " : "");
    strcat(szMessage, bRXFLAG ? "RXFLAG " : "");
  strcat(szMessage, bRXCHAR ? "RXCHAR " : "");
  strcat(szMessage, bTXEMPTY ? "TXEMPTY " : "");
    strcat(szMessage, "\n\r");

    OutputDebugString(szMessage);

    if (bERR)
        ReportCommError();

  CheckModemStatus();

  return;
}

BOOL SetupCommandLineOptions | ( | int | cArgs,
 |  | char * | argv[]
 | ) |  |

Definition at line 760 of file OVCOMM.C.

{
    int i;

    for ( i = 0; i < cArgs; i++) {
        if (strchr(argv[i], '?'))
            return FALSE;
    }

    switch(cArgs)
    {
        case 1:
                strcpy(lpszPort, "COM1");   // default port
                strcpy(lpszSerialSpec, "9600,n,8,1"); // default serial spec
                break;

        case 2:
                strcpy(lpszPort, argv[1]);
                strcpy(lpszSerialSpec, "9600,n,8,1");
                break;

        case 3:
                strcpy(lpszPort, argv[1]);
                strcpy(lpszSerialSpec, argv[2]);
                break;

        default:
                return FALSE;
    }

    return TRUE;
}

HANDLE SetupCommPort ( void )

Definition at line 135 of file OVCOMM.C.

{
  COMMTIMEOUTS timeouts;
  DCB dcb;

  // sync event for controlling thread startup
  hSetupEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  if (hSetupEvent == NULL)
    ErrorHandler("CreateEvent(Setup Event)");

  // communication handle
  comHandle = CreateFile( lpszPort,
                          GENERIC_READ | GENERIC_WRITE,
                          0,
                          0,
                          OPEN_EXISTING,
              FILE_FLAG_OVERLAPPED,
              0);

  if (comHandle == INVALID_HANDLE_VALUE) {
        printf("Problem opening port: %s\n", lpszPort);
    ErrorHandler("CreateFile");
    }

    FillMemory(&dcb, sizeof(dcb), 0);
    dcb.DCBlength = sizeof(dcb);
    if (!BuildCommDCB(lpszSerialSpec, &dcb)) {
        printf("Problem with serial spec line: %s\n", lpszSerialSpec);
        ErrorInComm("BuildCommDCB");
    }

    dcb.EvtChar = EVT_CHAR;

  if (!SetCommState(comHandle, &dcb))
    ErrorInComm("SetCommState");

    // Save original comm timeouts and set new ones
    if (!GetCommTimeouts(comHandle, &g_timeouts))
        ErrorInComm("GetCommTimeouts");

    // Need ReadIntervalTimeout here to cause the read operations
    // that we do to actually timeout and become overlapped.
    // Specifying 1 here causes ReadFile to return very quickly
    // so that our reader thread will continue execution after a ReadFile
    // is overlapped.
    // Specifying MAXDWORD here causes ReadFile to return immediately
    // without overlapping.
    timeouts.ReadIntervalTimeout = 1;
  timeouts.ReadTotalTimeoutMultiplier = 0;
  timeouts.ReadTotalTimeoutConstant = 0;
  timeouts.WriteTotalTimeoutMultiplier = 0;
  timeouts.WriteTotalTimeoutConstant = 0;

  if (!SetCommTimeouts(comHandle, &timeouts))
    ErrorInComm("SetCommTimeouts");

    // raise DTR
  if (!EscapeCommFunction(comHandle, SETDTR))
    ErrorInComm("EscapeCommFunction (SETDTR)");

    // set initial thread state: NOT DONE
  bDone = FALSE;

  return comHandle;
}

DWORD WINAPI StatusProc ( LPVOID lpV )

Definition at line 430 of file OVCOMM.C.

{
  DWORD    dwWaitResult, dwCommEvent;
  HANDLE     hEvent;
  BOOL     bWaitingOnStatusHandle = FALSE;
  OVERLAPPED os = {0};

  hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  if (hEvent == NULL)
    ErrorInComm("CreateEvent(Status)");

  os.hEvent = hEvent;

  if (!SetCommMask(comHandle, EVENT_FLAGS))
    ErrorInComm("SetCommMask");

    // initial check before everything else gets going
    CheckModemStatus();

    // This event signals that the comm mask has been setup and initial
    // modem status reported.
    // This prevents any reads/writes until the program is ready to
    // start reporting events.
    if (!SetEvent(hSetupEvent))
    ErrorInComm("SetEvent (Setup Event)");

  // wait for status changes to occur and report them every so often
  for ( ; !bDone ; Sleep(STATUS_CHECK_TIMEOUT))
  {
    // check and possibly report modem status
    CheckModemStatus();

    // check and report event status
    if (bWaitingOnStatusHandle) {     // waiting on previous WaitCommEvent
      dwWaitResult = WaitForSingleObject(hEvent, 0);  // check event
      if (dwWaitResult == WAIT_OBJECT_0) {            //  event signalled
                ReportStatusEvent(dwCommEvent);
                bWaitingOnStatusHandle = FALSE;
                ResetEvent(hEvent);
            }
        }

        if (!bWaitingOnStatusHandle) {    // previous event isn't pending?
          // wait for another (or first) event
            if (!WaitCommEvent(comHandle, &dwCommEvent, &os)) {
                if (GetLastError() != ERROR_IO_PENDING) // is Wait pending?
                    ErrorInComm("WaitCommEvent");

                bWaitingOnStatusHandle = TRUE;
            }
            else
                // WaitCommEvent returned immediately
                ReportStatusEvent(dwCommEvent);
        }
    }

    CloseHandle(hEvent);
    OutputDebugString("Status Thread Exiting\n\r");

    return 1;
}

DWORD WINAPI WriterProc ( LPVOID lpV )

Definition at line 611 of file OVCOMM.C.

{
  HANDLE     hIn;
  char       chRead;
  DWORD      dwRead, dwWritten;
  OVERLAPPED ov = {0};

  hIn = (HANDLE) lpV;

  while (!bDone)
  {
    // block the console read until a character key is pressed
    if (!ReadFile(hIn, &chRead, 1, &dwRead, NULL))
      ErrorInComm("ReadFile (std in) in Writer Thread");

    // if char is actually read from the keyboard
    if (dwRead == 1) {
            // send character out comm port
      if (!WriteFile(comHandle, &chRead, 1, &dwWritten, &ov)) {
        if (GetLastError() == ERROR_IO_PENDING) {  // write is delayed
          // check write status and wait til complete.
          // can't do another write until the first one finishes.
          if (!GetOverlappedResult(comHandle, &ov, &dwWritten, TRUE))
            ErrorInComm("GetOverlappedResult(in Writer)");
        }
        else
          ErrorInComm("WriteFile (comHandle)");
      }

      if (dwWritten != 1)
        OutputDebugString("Error writing character to port.\n\r");
    }
  }

  OutputDebugString("Writer Thread Exiting\n");

  return 1;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OVCOMM/OVCOMM.H File Reference

  • OVCOMM
Defines | Functions | Variables

OVCOMM.H File Reference

Go to the source code of this file.

Defines

#define | EVENT_FLAGS EV_RING | EV_ERR
#define | EVT_CHAR (char) 0x0A
#define | MAX_READ_BUFFER 80
#define | MAX_WRITE_BUFFER 1024
#define | PURGE_FLAGS PURGE_RXABORT | PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR
#define | READ_TIMEOUT 1000
#define | STATUS_CHECK_TIMEOUT 500

Functions

void | BreakDownCommPort ()

Variables

BOOL | bDone
HANDLE | comHandle
COMMTIMEOUTS | g_timeouts
HANDLE | hSetupEvent
char | lpszPort [100]
char | lpszSerialSpec [100]

Define Documentation

#define EVENT_FLAGS EV_RING | EV_ERR

Definition at line 10 of file OVCOMM.H.

#define EVT_CHAR (char) 0x0A

Definition at line 12 of file OVCOMM.H.

#define MAX_READ_BUFFER 80

Definition at line 6 of file OVCOMM.H.

#define MAX_WRITE_BUFFER 1024

Definition at line 7 of file OVCOMM.H.

#define PURGE_FLAGS PURGE_RXABORT | PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR

Definition at line 8 of file OVCOMM.H.

#define READ_TIMEOUT 1000

Definition at line 5 of file OVCOMM.H.

#define STATUS_CHECK_TIMEOUT 500

Definition at line 4 of file OVCOMM.H.

Function Documentation

void BreakDownCommPort ( )

Definition at line 211 of file OVCOMM.C.

{
    // lower DTR
  if (!EscapeCommFunction(comHandle, CLRDTR))
    ErrorReporter("EscapeCommFunction(CLRDTR)");

    // restore original comm timeouts
    if (!SetCommTimeouts(comHandle, &g_timeouts))
        ErrorReporter("SetCommTimeouts (Restoration to original)");

  if (!PurgeComm(comHandle, PURGE_FLAGS))
        ErrorReporter("PurgeComm");

    CloseHandle(comHandle);
}

Variable Documentation

BOOL bDone

Definition at line 17 of file OVCOMM.H.

HANDLE comHandle

Definition at line 16 of file OVCOMM.H.

COMMTIMEOUTS g_timeouts

Definition at line 20 of file OVCOMM.H.

HANDLE hSetupEvent

Definition at line 16 of file OVCOMM.H.

char lpszPort[100]

Definition at line 18 of file OVCOMM.H.

char lpszSerialSpec[100]

Definition at line 19 of file OVCOMM.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OWNCOMBO/OWNCOMBO.C File Reference

  • OWNCOMBO
Functions | Variables

OWNCOMBO.C File Reference

#include "windows.h"
#include "owncombo.h"

Go to the source code of this file.

Functions

BOOL APIENTRY | About (HWND hDlg, UINT message, UINT wParam, LONG lParam)
BOOL APIENTRY | ComboBoxExample (HWND hDlg, UINT message, UINT wParam, LONG lParam)
VOID APIENTRY | DrawEntireItem (LPDRAWITEMSTRUCT lpdis, INT inflate)
VOID APIENTRY | HandleFocusState (LPDRAWITEMSTRUCT lpdis, INT inflate)
VOID APIENTRY | HandleSelectionState (LPDRAWITEMSTRUCT lpdis, INT inflate)
BOOL APIENTRY | ListBoxExample (HWND hDlg, UINT message, UINT wParam, LONG lParam)
BOOL NEAR PASCAL | OwnComboInit (HANDLE hInstance)
LONG APIENTRY | OwnComboWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)
BOOL APIENTRY | OwnerComboBoxExample (HWND hDlg, UINT message, UINT wParam, LONG lParam)
int APIENTRY | WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hInst

Function Documentation

BOOL APIENTRY About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 160 of file OWNCOMBO.C.

{

        UNREFERENCED_PARAMETER(lParam);
    switch (message){
        case WM_INITDIALOG:
            return(TRUE);

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK){
                EndDialog (hDlg,0);
                return(FALSE);
            }
            break;

        default:
            break;
    }
  return(FALSE);
}

BOOL APIENTRY ComboBoxExample | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 521 of file OWNCOMBO.C.

{

    HWND hWndCombo;                  /* Handle to the combo box control */
                                     /* in the dialog box window        */
    HWND hWndCheckBox;               /* Handle to the Auto Check Box    */
    CHAR strSingleEditLine[255];     /* Single line edit control input  */
    INT  wIndex, wCount;

    /* Get handles to the Combo box and the Check box */
    hWndCombo     = GetDlgItem(hDlg, ID_COMBOBOX);
    hWndCheckBox  = GetDlgItem(hDlg, ID_STEPSBOX);

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                    EndDialog (hDlg,0);
                    return(TRUE);

                case ID_UNSLBUTTON:
                    /* Selecting this button unselects any selection in the
                     * combo box.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage( hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (wIndex == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else
                        SendMessage (hWndCombo, CB_SETCURSEL, (WPARAM)-1, 0L);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_NUMSELBUTTON:
                    /* An integer value is taken from the edit control and an
                     * attempt is made to select a combo box entry having this
                     * index.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
                    wIndex = (INT) GetDlgItemInt (hDlg, ID_SINGLEEDIT, NULL, TRUE);
                    if (wIndex >= wCount)
                        MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    else
                        SendMessage(hWndCombo, CB_SETCURSEL, wIndex, 0L);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_TXTSELBUTTON:
                    /* A text string is taken from the edit control and an
                     * attempt is made to select a combo box entry having the
                     * string as a prefix.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg, ID_SINGLEEDIT,
                                 (LPSTR)strSingleEditLine, 255);
                    wIndex = (WORD) SendMessage (hWndCombo,
                                                CB_SELECTSTRING,
                                                (WPARAM)-1,
                                                (LONG)(LPSTR)strSingleEditLine);
                    if (wIndex == CB_ERR)
                      MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_FNDSELBUTTON:
                    /* Searches for the text specified in the list of combo
                     * entries and returns the index (in combo box) of the
                     * first match. The index is displayed in the "Text1"
                     * field of the dialog.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg,
                                    ID_SINGLEEDIT,
                                    (LPSTR)strSingleEditLine,
                                    255);
                    wIndex = (WORD)SendMessage (hWndCombo,
                                               CB_FINDSTRING,(WPARAM)-1,
                                               (LONG)(LPSTR)strSingleEditLine);
                    if (wIndex == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    else
                        SetDlgItemInt (hDlg, ID_TEXT1, wIndex, FALSE);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CLRBUTTON:
                    /* Clears the combo box of all it's entries */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
                    if (!wCount)
                        MessageBox (hDlg, (LPSTR)"Already clear", NULL, MB_OK);
                    else{
                        SetDlgItemInt (hDlg, ID_TEXT1, wCount, TRUE);
                        SetDlgItemText (hDlg, ID_TEXT2, "Items cleared");
                        SendMessage (hWndCombo,CB_RESETCONTENT, 0, 0L);
                    }
                    SetFocus (GetDlgItem (hDlg,ID_SINGLEEDIT));
                    break;

                case ID_ADDBUTTON:
                    /* Takes the string specified in the edit control and
                     * adds it to the combo box.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg, ID_SINGLEEDIT, strSingleEditLine, 255);
                    SendMessage (hWndCombo,
                                 CB_ADDSTRING,
                                 0,
                                 (LONG)(LPSTR) strSingleEditLine);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_DELETEBUTTON:
                    /* Delete the currently selected item from the combo box. */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (SendMessage (hWndCombo, CB_DELETESTRING, wIndex, 0L) == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else{
                        SetDlgItemText (hDlg, ID_TEXT1, "deleted index #");
                        SetDlgItemInt  (hDlg, ID_TEXT2, wIndex, TRUE);
                    }
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CBDIRBUTTON:
                    /* Appends a directory listing of the current directory
                     * to the combo box entries.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD)SendMessage (hWndCombo,
                                               CB_DIR,
                                               0x10|0x4000,
                                               (LONG)(LPSTR)"*.*");
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CPYBUTTON:
                    /* Copies the currently selected item in the combo box to
                     * the edit control.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (wIndex == CB_ERR)
                        MessageBox(hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else{
                        wCount = SendMessage (hWndCombo, CB_GETLBTEXTLEN, wIndex, 0L);
                        SendMessage (hWndCombo,
                                     CB_GETLBTEXT,
                                     wIndex,
                                     (LONG)(LPSTR)strSingleEditLine);
                        SetDlgItemText(hDlg, ID_SINGLEEDIT,
                                       (LPSTR)strSingleEditLine);
                        SetDlgItemText(hDlg, ID_TEXT1, "copied index #");
                        SetDlgItemInt(hDlg, ID_TEXT2, wIndex, TRUE);
                    }
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                /* When the combo notification box is checked, a message box
                 * is flashed showing what notification codes the combo box is
                 * returning to the app. in response to the messages sent by
                 * the buttons.
                 */
                case ID_COMBOBOX:
                    if (SendMessage (hWndCheckBox, BM_GETCHECK, 0, 0L)){
                        switch (HIWORD(lParam)){
                            case (WORD)CBN_ERRSPACE:
                              MessageBox (hDlg, (LPSTR)"CB Out of Space",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_SELCHANGE:
                              MessageBox (hDlg, (LPSTR)"CB Sel Change",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_DBLCLK:
                              MessageBox(hDlg, (LPSTR)"CB Double Click",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_SETFOCUS:
                              SetDlgItemText(hDlg, ID_TEXT1, "CB SetFocus");
                              break;

                            case CBN_KILLFOCUS:
                              SetDlgItemText(hDlg, ID_TEXT1, "CB KillFocus");
                              break;
                        }
                    }
                    break;

                default:
                    return(FALSE);
            }
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }
    return(TRUE);
}

VOID APIENTRY DrawEntireItem | ( | LPDRAWITEMSTRUCT | lpdis,
 |  | INT | inflate
 | ) |  |

Definition at line 359 of file OWNCOMBO.C.

{
        RECT    rc;
        HBRUSH  hbr;

        /* Resize rectangle to leave space for frames */
        CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
        InflateRect ((LPRECT)&rc, inflate, inflate);

        /* Create a brush using the value in the item data field (this value
         * was initialized when we added the item to the list/combo box using
         * LB_ADDSTRING/CB_ADDSTRING) and draw the color in the list/combo box.
         */
        hbr = CreateSolidBrush (lpdis->itemData);
        FillRect (lpdis->hDC, (LPRECT)&rc, hbr);
        DeleteObject (hbr);

        /* Draw or erase appropriate frames */
        HandleSelectionState(lpdis, inflate + 4);
        HandleFocusState(lpdis, inflate + 2);
}

VOID APIENTRY HandleFocusState | ( | LPDRAWITEMSTRUCT | lpdis,
 |  | INT | inflate
 | ) |  |

Definition at line 324 of file OWNCOMBO.C.

{
        RECT    rc;
        HBRUSH  hbr;

        /* Resize rectangle to place focus frame between the selection
         * frame and the item.
         */
        CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
        InflateRect ((LPRECT)&rc, inflate, inflate);

        if (lpdis->itemState & ODS_FOCUS)
        {
                /* gaining input focus -- paint a gray frame */
                hbr = GetStockObject(GRAY_BRUSH);
        }
        else
        {
                /* losing input focus -- remove (paint over) frame */
                hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
        }
        FrameRect(lpdis->hDC, (LPRECT)&rc, hbr);
        DeleteObject (hbr);
}

VOID APIENTRY HandleSelectionState | ( | LPDRAWITEMSTRUCT | lpdis,
 |  | INT | inflate
 | ) |  |

Definition at line 284 of file OWNCOMBO.C.

{
        RECT    rc;
        HBRUSH  hbr;

        /* Resize rectangle to place selection frame outside of the focus
         * frame and the item.
         */
        CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
        InflateRect ((LPRECT)&rc, inflate, inflate);

        if (lpdis->itemState & ODS_SELECTED)
        {
                /* selecting item -- paint a black frame */
                hbr = GetStockObject(BLACK_BRUSH);
        }
        else
        {
                /* de-selecting item -- remove frame */
                hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
        }
        FrameRect(lpdis->hDC, (LPRECT)&rc, hbr);
        DeleteObject (hbr);
}

BOOL APIENTRY ListBoxExample | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 393 of file OWNCOMBO.C.

{
    LPDRAWITEMSTRUCT    lpdis;
    LPMEASUREITEMSTRUCT lpmis;

    /* Vars for WM_DRAWITEM */

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                   EndDialog (hDlg, 0);
                   return (TRUE);
                   break;

                /* Clicking any of these buttons adds the corresponding color
                 * to the list box. The application-supplied data is the RGB
                 * value for the color to be drawn in the listbox.
                 */
                case ID_BLACK:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,0,0));
                    return(TRUE);
                    break;
                case ID_RED:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (255,0,0));
                    return(TRUE);
                    break;

                case ID_BLUE:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,0,255));
                    return(TRUE);
                    break;

                case ID_GREEN:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,255,0));
                    return(TRUE);
                    break;

                default:
                    return(FALSE);
                    break;
            }

        case WM_DRAWITEM:
            /* Get pointer to the DRAWITEMSTRUCT */
            lpdis = (LPDRAWITEMSTRUCT)lParam;

            if (lpdis->itemID == -1)
            {
                /* We have a request to draw an item in the list box, yet there
                 * are no list box items. This is sent when the user TABS into
                 * an empty list box or an empty list box gets the focus. We
                 * have to indicate (somehow) that this owner-draw list box has
                 * the focus. We do it in response to this message. Note that
                 * lpdis->itemData field would be invalid in this instance so
                 * we can't allow it to fall into our standard routines.
                 */
                HandleFocusState(lpdis, -5);
            }
            else
            {
                switch (lpdis->itemAction)
                {
                        case ODA_DRAWENTIRE:
                                DrawEntireItem(lpdis, -7);
                                break;

                        case ODA_SELECT:
                                HandleSelectionState(lpdis, -3);
                                break;

                        case ODA_FOCUS:
                                HandleFocusState(lpdis, -5);
                                break;
                }
            }

            /* Return TRUE meaning that we processed this message. */
            return(TRUE);
            break;

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT)lParam;

            /* All the items are the same height since the list box style is
             * LBS_OWNERDRAWFIXED
             */
            lpmis->itemHeight = 30;
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }

    return(TRUE);
}

BOOL NEAR PASCAL OwnComboInit ( HANDLE hInstance )

Definition at line 122 of file OWNCOMBO.C.

{
    HANDLE     hMemory;
    PWNDCLASS  pWndClass;
    BOOL       bSuccess;

    /* Allocate for and fill class structure. */
    hMemory = LocalAlloc (LPTR, sizeof (WNDCLASS));
    if(!hMemory){
        MessageBox(NULL, "<OwnComboInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
        return(FALSE);
    }

    pWndClass = (PWNDCLASS) LocalLock (hMemory);

    pWndClass->style         = 0;
    pWndClass->lpfnWndProc   = (WNDPROC) OwnComboWndProc;
    pWndClass->hInstance    = hInstance;
    pWndClass->hIcon         = LoadIcon (hInstance, "owncombo");
    pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
    pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
    pWndClass->lpszMenuName  = (LPSTR) "OwnComboMenu",
    pWndClass->lpszClassName = (LPSTR) "owncombo";

    bSuccess = RegisterClass (pWndClass);
    LocalUnlock (hMemory);
    LocalFree (hMemory);

    return (bSuccess);
}

LONG APIENTRY OwnComboWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 194 of file OWNCOMBO.C.

{
    FARPROC          lpProc;

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDM_EXIT:
                    DestroyWindow (hWnd);
                    break;

                case IDM_ABOUT:
                    /* Bring up the about box */
                    lpProc = MakeProcInstance ((FARPROC)About, hInst);
                    DialogBox (hInst,
                               "AboutBox",
                               hWnd,
                               lpProc);

                    FreeProcInstance (lpProc);
                    break;

                case IDM_LISTBOX:
                    /* Bring up the list box example */
                    lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
                    DialogBox (hInst,
                               "ListBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_MULTILISTBOX:
                    /* Bring up the multiple selection list box example */
                    lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
                    DialogBox (hInst,
                               "MultiListBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_COMBOBOX:
                    /* Bring up the combo box example */
                    lpProc = MakeProcInstance ((FARPROC)ComboBoxExample, hInst);
                    DialogBox (hInst,
                               "ComboBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_OWNERCOMBOBOX:
                    /* Bring up the owner-draw dropdown list box example */
                    lpProc = MakeProcInstance ((FARPROC)OwnerComboBoxExample, hInst);
                    DialogBox (hInst,
                               "OwnerComboBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;
            }
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return(DefWindowProc(hWnd, message, wParam, lParam));
    }
    return(0);
}

BOOL APIENTRY OwnerComboBoxExample | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 754 of file OWNCOMBO.C.

{
    LPDRAWITEMSTRUCT    lpdis;
    LPMEASUREITEMSTRUCT lpmis;

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                   EndDialog (hDlg, 0);
                   return(TRUE);
                   break;

                /* Clicking any of these buttons adds the corresponding color
                 * to the combo box. The application-supplied data is the RGB
                 * value for the color to be drawn in the listbox.
                 */
                case ID_BLACK:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,0,0));
                   return(TRUE);
                   break;

                case ID_RED:
                   SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (255,0,0));
                   return(TRUE);
                   break;

                case ID_BLUE:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,0,255));
                   return(TRUE);
                   break;

                case ID_GREEN:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,255,0));
                   return(TRUE);
                   break;

                default:
                   return(TRUE);
                   break;
            }

        case WM_DRAWITEM:
            /* Get pointer to the DRAWITEMSTRUCT */
            lpdis = (LPDRAWITEMSTRUCT)lParam;

            if (lpdis->itemID == -1){
                /* We have a request to draw an item in the combo box, yet there
                 * are no combo box items. This is sent when the user TABS into
                 * an empty combo box or an empty combo box gets the focus. We
                 * have to indicate (somehow) that this owner-draw combo box has
                 * the focus. We do it in response to this message. Note that
                 * lpdis->itemData field would be invalid in this instance so
                 * we can't allow it to fall into our standard routines.
                 */
                HandleFocusState(lpdis, -2);
            }
            else
            {
                switch (lpdis->itemAction)
                {
                        case ODA_DRAWENTIRE:
                                DrawEntireItem(lpdis, -4);
                                break;

                        case ODA_SELECT:
                                HandleSelectionState(lpdis, 0);
                                break;

                        case ODA_FOCUS:
                                HandleFocusState(lpdis, -2);
                                break;
                }
            }

            /* Return TRUE meaning that we processed this message. */
            return(TRUE);
            break;

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT)lParam;

            /* All the items are the same height since the combo box is
             * CBS_OWNERDRAWFIXED
             */
            if (lpmis->itemID == -1){
                /* If -1 for item, then we are setting the height of the
                 * always visible static item part of the dropdown combo box.
                 */
                lpmis->itemHeight = 25;
                return(TRUE);
            }
            lpmis->itemHeight = 30;
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }
    return(TRUE);
}

int APIENTRY WinMain | ( | HANDLE | hInstance,
 |  | HANDLE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 66 of file OWNCOMBO.C.

{

    HWND  hWnd;
    MSG   msg;

    UNREFERENCED_PARAMETER( lpCmdLine );

    if (!hPrevInstance)
        if (!OwnComboInit (hInstance))
            return (0);

    hInst = hInstance;

    /* Create the app. window */
    hWnd = CreateWindow ("owncombo",
                         "Owner-draw & Combo Box Example",
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         (HWND) NULL,
                         NULL,
                         hInstance,
                         (LPSTR) NULL);

    if (!hWnd)
        return (0);

    ShowWindow (hWnd, nCmdShow);

    while (GetMessage (&msg, NULL, 0, 0)){
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return(msg.wParam);
}

Variable Documentation

HANDLE hInst

Definition at line 56 of file OWNCOMBO.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OWNCOMBO/OWNCOMBO.H File Reference

  • OWNCOMBO
Defines | Functions

OWNCOMBO.H File Reference

Go to the source code of this file.

Defines

#define | ID_ADDBUTTON 1010
#define | ID_BLACK 1003
#define | ID_BLUE 1006
#define | ID_CBDIRBUTTON 1013
#define | ID_CLRBUTTON 1009
#define | ID_COMBOBOX 1000
#define | ID_CPYBUTTON 1012
#define | ID_DELETEBUTTON 1011
#define | ID_FNDSELBUTTON 1008
#define | ID_GREEN 1007
#define | ID_LISTBOX 1000
#define | ID_NUMSELBUTTON 1006
#define | ID_RED 1005
#define | ID_SINGLEEDIT 1001
#define | ID_STEPSBOX 1004
#define | ID_TEXT1 1002
#define | ID_TEXT2 1003
#define | ID_TXTSELBUTTON 1007
#define | ID_UNSLBUTTON 1005
#define | ID_WHITE 1004
#define | IDM_ABOUT 202
#define | IDM_COMBOBOX 302
#define | IDM_EXIT 201
#define | IDM_HELP 400
#define | IDM_LISTBOX 300
#define | IDM_MULTILISTBOX 301
#define | IDM_OWNERCOMBOBOX 303

Functions

BOOL FAR PASCAL | About (HWND, UINT, UINT, LONG)
BOOL FAR PASCAL | ComboBoxExample (HWND, UINT, UINT, LONG)
BOOL FAR PASCAL | ListBoxExample (HWND, UINT, UINT, LONG)
BOOL NEAR PASCAL | OwnComboInit (HANDLE)
LONG FAR PASCAL | OwnComboWndProc (HWND, UINT, UINT, LONG)
BOOL FAR PASCAL | OwnerComboBoxExample (HWND, UINT, UINT, LONG)

Define Documentation

#define ID_ADDBUTTON 1010

Definition at line 42 of file OWNCOMBO.H.

#define ID_BLACK 1003

Definition at line 25 of file OWNCOMBO.H.

#define ID_BLUE 1006

Definition at line 28 of file OWNCOMBO.H.

#define ID_CBDIRBUTTON 1013

Definition at line 45 of file OWNCOMBO.H.

#define ID_CLRBUTTON 1009

Definition at line 41 of file OWNCOMBO.H.

#define ID_COMBOBOX 1000

Definition at line 32 of file OWNCOMBO.H.

#define ID_CPYBUTTON 1012

Definition at line 44 of file OWNCOMBO.H.

#define ID_DELETEBUTTON 1011

Definition at line 43 of file OWNCOMBO.H.

#define ID_FNDSELBUTTON 1008

Definition at line 40 of file OWNCOMBO.H.

#define ID_GREEN 1007

Definition at line 29 of file OWNCOMBO.H.

#define ID_LISTBOX 1000

Definition at line 24 of file OWNCOMBO.H.

#define ID_NUMSELBUTTON 1006

Definition at line 38 of file OWNCOMBO.H.

#define ID_RED 1005

Definition at line 27 of file OWNCOMBO.H.

#define ID_SINGLEEDIT 1001

Definition at line 33 of file OWNCOMBO.H.

#define ID_STEPSBOX 1004

Definition at line 36 of file OWNCOMBO.H.

#define ID_TEXT1 1002

Definition at line 34 of file OWNCOMBO.H.

#define ID_TEXT2 1003

Definition at line 35 of file OWNCOMBO.H.

#define ID_TXTSELBUTTON 1007

Definition at line 39 of file OWNCOMBO.H.

#define ID_UNSLBUTTON 1005

Definition at line 37 of file OWNCOMBO.H.

#define ID_WHITE 1004

Definition at line 26 of file OWNCOMBO.H.

#define IDM_ABOUT 202

Definition at line 14 of file OWNCOMBO.H.

#define IDM_COMBOBOX 302

Definition at line 18 of file OWNCOMBO.H.

#define IDM_EXIT 201

Definition at line 13 of file OWNCOMBO.H.

#define IDM_HELP 400

Definition at line 21 of file OWNCOMBO.H.

#define IDM_LISTBOX 300

Definition at line 16 of file OWNCOMBO.H.

#define IDM_MULTILISTBOX 301

Definition at line 17 of file OWNCOMBO.H.

#define IDM_OWNERCOMBOBOX 303

Definition at line 19 of file OWNCOMBO.H.

Function Documentation

BOOL FAR PASCAL About | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 406 of file CLIPTEXT.C.

{
    switch (message) {
            case WM_INITDIALOG:
                return (TRUE);

            case WM_COMMAND:
                if (LOWORD(wParam) == IDOK
                       || LOWORD(wParam) == IDCANCEL) {

                        EndDialog(hDlg, TRUE);
                        return (TRUE);
            }
                break;
    }
    return (FALSE);
        UNREFERENCED_PARAMETER(lParam);
}

BOOL FAR PASCAL ComboBoxExample | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 521 of file OWNCOMBO.C.

{

    HWND hWndCombo;                  /* Handle to the combo box control */
                                     /* in the dialog box window        */
    HWND hWndCheckBox;               /* Handle to the Auto Check Box    */
    CHAR strSingleEditLine[255];     /* Single line edit control input  */
    INT  wIndex, wCount;

    /* Get handles to the Combo box and the Check box */
    hWndCombo     = GetDlgItem(hDlg, ID_COMBOBOX);
    hWndCheckBox  = GetDlgItem(hDlg, ID_STEPSBOX);

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                    EndDialog (hDlg,0);
                    return(TRUE);

                case ID_UNSLBUTTON:
                    /* Selecting this button unselects any selection in the
                     * combo box.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage( hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (wIndex == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else
                        SendMessage (hWndCombo, CB_SETCURSEL, (WPARAM)-1, 0L);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_NUMSELBUTTON:
                    /* An integer value is taken from the edit control and an
                     * attempt is made to select a combo box entry having this
                     * index.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
                    wIndex = (INT) GetDlgItemInt (hDlg, ID_SINGLEEDIT, NULL, TRUE);
                    if (wIndex >= wCount)
                        MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    else
                        SendMessage(hWndCombo, CB_SETCURSEL, wIndex, 0L);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_TXTSELBUTTON:
                    /* A text string is taken from the edit control and an
                     * attempt is made to select a combo box entry having the
                     * string as a prefix.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg, ID_SINGLEEDIT,
                                 (LPSTR)strSingleEditLine, 255);
                    wIndex = (WORD) SendMessage (hWndCombo,
                                                CB_SELECTSTRING,
                                                (WPARAM)-1,
                                                (LONG)(LPSTR)strSingleEditLine);
                    if (wIndex == CB_ERR)
                      MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_FNDSELBUTTON:
                    /* Searches for the text specified in the list of combo
                     * entries and returns the index (in combo box) of the
                     * first match. The index is displayed in the "Text1"
                     * field of the dialog.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg,
                                    ID_SINGLEEDIT,
                                    (LPSTR)strSingleEditLine,
                                    255);
                    wIndex = (WORD)SendMessage (hWndCombo,
                                               CB_FINDSTRING,(WPARAM)-1,
                                               (LONG)(LPSTR)strSingleEditLine);
                    if (wIndex == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
                    else
                        SetDlgItemInt (hDlg, ID_TEXT1, wIndex, FALSE);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CLRBUTTON:
                    /* Clears the combo box of all it's entries */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
                    if (!wCount)
                        MessageBox (hDlg, (LPSTR)"Already clear", NULL, MB_OK);
                    else{
                        SetDlgItemInt (hDlg, ID_TEXT1, wCount, TRUE);
                        SetDlgItemText (hDlg, ID_TEXT2, "Items cleared");
                        SendMessage (hWndCombo,CB_RESETCONTENT, 0, 0L);
                    }
                    SetFocus (GetDlgItem (hDlg,ID_SINGLEEDIT));
                    break;

                case ID_ADDBUTTON:
                    /* Takes the string specified in the edit control and
                     * adds it to the combo box.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    GetDlgItemText (hDlg, ID_SINGLEEDIT, strSingleEditLine, 255);
                    SendMessage (hWndCombo,
                                 CB_ADDSTRING,
                                 0,
                                 (LONG)(LPSTR) strSingleEditLine);
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_DELETEBUTTON:
                    /* Delete the currently selected item from the combo box. */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (SendMessage (hWndCombo, CB_DELETESTRING, wIndex, 0L) == CB_ERR)
                        MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else{
                        SetDlgItemText (hDlg, ID_TEXT1, "deleted index #");
                        SetDlgItemInt  (hDlg, ID_TEXT2, wIndex, TRUE);
                    }
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CBDIRBUTTON:
                    /* Appends a directory listing of the current directory
                     * to the combo box entries.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD)SendMessage (hWndCombo,
                                               CB_DIR,
                                               0x10|0x4000,
                                               (LONG)(LPSTR)"*.*");
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                case ID_CPYBUTTON:
                    /* Copies the currently selected item in the combo box to
                     * the edit control.
                     */
                    SetDlgItemText (hDlg, ID_TEXT1, "");
                    SetDlgItemText (hDlg, ID_TEXT2, "");
                    wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
                    if (wIndex == CB_ERR)
                        MessageBox(hDlg, (LPSTR)"No Selection", NULL, MB_OK);
                    else{
                        wCount = SendMessage (hWndCombo, CB_GETLBTEXTLEN, wIndex, 0L);
                        SendMessage (hWndCombo,
                                     CB_GETLBTEXT,
                                     wIndex,
                                     (LONG)(LPSTR)strSingleEditLine);
                        SetDlgItemText(hDlg, ID_SINGLEEDIT,
                                       (LPSTR)strSingleEditLine);
                        SetDlgItemText(hDlg, ID_TEXT1, "copied index #");
                        SetDlgItemInt(hDlg, ID_TEXT2, wIndex, TRUE);
                    }
                    SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
                    break;

                /* When the combo notification box is checked, a message box
                 * is flashed showing what notification codes the combo box is
                 * returning to the app. in response to the messages sent by
                 * the buttons.
                 */
                case ID_COMBOBOX:
                    if (SendMessage (hWndCheckBox, BM_GETCHECK, 0, 0L)){
                        switch (HIWORD(lParam)){
                            case (WORD)CBN_ERRSPACE:
                              MessageBox (hDlg, (LPSTR)"CB Out of Space",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_SELCHANGE:
                              MessageBox (hDlg, (LPSTR)"CB Sel Change",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_DBLCLK:
                              MessageBox(hDlg, (LPSTR)"CB Double Click",
                                         "CB MSG", MB_OK);
                              break;

                            case CBN_SETFOCUS:
                              SetDlgItemText(hDlg, ID_TEXT1, "CB SetFocus");
                              break;

                            case CBN_KILLFOCUS:
                              SetDlgItemText(hDlg, ID_TEXT1, "CB KillFocus");
                              break;
                        }
                    }
                    break;

                default:
                    return(FALSE);
            }
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }
    return(TRUE);
}

BOOL FAR PASCAL ListBoxExample | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 393 of file OWNCOMBO.C.

{
    LPDRAWITEMSTRUCT    lpdis;
    LPMEASUREITEMSTRUCT lpmis;

    /* Vars for WM_DRAWITEM */

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                   EndDialog (hDlg, 0);
                   return (TRUE);
                   break;

                /* Clicking any of these buttons adds the corresponding color
                 * to the list box. The application-supplied data is the RGB
                 * value for the color to be drawn in the listbox.
                 */
                case ID_BLACK:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,0,0));
                    return(TRUE);
                    break;
                case ID_RED:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (255,0,0));
                    return(TRUE);
                    break;

                case ID_BLUE:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,0,255));
                    return(TRUE);
                    break;

                case ID_GREEN:
                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                 LB_ADDSTRING,
                                 0,
                                 RGB (0,255,0));
                    return(TRUE);
                    break;

                default:
                    return(FALSE);
                    break;
            }

        case WM_DRAWITEM:
            /* Get pointer to the DRAWITEMSTRUCT */
            lpdis = (LPDRAWITEMSTRUCT)lParam;

            if (lpdis->itemID == -1)
            {
                /* We have a request to draw an item in the list box, yet there
                 * are no list box items. This is sent when the user TABS into
                 * an empty list box or an empty list box gets the focus. We
                 * have to indicate (somehow) that this owner-draw list box has
                 * the focus. We do it in response to this message. Note that
                 * lpdis->itemData field would be invalid in this instance so
                 * we can't allow it to fall into our standard routines.
                 */
                HandleFocusState(lpdis, -5);
            }
            else
            {
                switch (lpdis->itemAction)
                {
                        case ODA_DRAWENTIRE:
                                DrawEntireItem(lpdis, -7);
                                break;

                        case ODA_SELECT:
                                HandleSelectionState(lpdis, -3);
                                break;

                        case ODA_FOCUS:
                                HandleFocusState(lpdis, -5);
                                break;
                }
            }

            /* Return TRUE meaning that we processed this message. */
            return(TRUE);
            break;

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT)lParam;

            /* All the items are the same height since the list box style is
             * LBS_OWNERDRAWFIXED
             */
            lpmis->itemHeight = 30;
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }

    return(TRUE);
}

BOOL NEAR PASCAL OwnComboInit ( HANDLE )

Definition at line 122 of file OWNCOMBO.C.

{
    HANDLE     hMemory;
    PWNDCLASS  pWndClass;
    BOOL       bSuccess;

    /* Allocate for and fill class structure. */
    hMemory = LocalAlloc (LPTR, sizeof (WNDCLASS));
    if(!hMemory){
        MessageBox(NULL, "<OwnComboInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
        return(FALSE);
    }

    pWndClass = (PWNDCLASS) LocalLock (hMemory);

    pWndClass->style         = 0;
    pWndClass->lpfnWndProc   = (WNDPROC) OwnComboWndProc;
    pWndClass->hInstance    = hInstance;
    pWndClass->hIcon         = LoadIcon (hInstance, "owncombo");
    pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
    pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
    pWndClass->lpszMenuName  = (LPSTR) "OwnComboMenu",
    pWndClass->lpszClassName = (LPSTR) "owncombo";

    bSuccess = RegisterClass (pWndClass);
    LocalUnlock (hMemory);
    LocalFree (hMemory);

    return (bSuccess);
}

LONG FAR PASCAL OwnComboWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 194 of file OWNCOMBO.C.

{
    FARPROC          lpProc;

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDM_EXIT:
                    DestroyWindow (hWnd);
                    break;

                case IDM_ABOUT:
                    /* Bring up the about box */
                    lpProc = MakeProcInstance ((FARPROC)About, hInst);
                    DialogBox (hInst,
                               "AboutBox",
                               hWnd,
                               lpProc);

                    FreeProcInstance (lpProc);
                    break;

                case IDM_LISTBOX:
                    /* Bring up the list box example */
                    lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
                    DialogBox (hInst,
                               "ListBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_MULTILISTBOX:
                    /* Bring up the multiple selection list box example */
                    lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
                    DialogBox (hInst,
                               "MultiListBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_COMBOBOX:
                    /* Bring up the combo box example */
                    lpProc = MakeProcInstance ((FARPROC)ComboBoxExample, hInst);
                    DialogBox (hInst,
                               "ComboBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;

                case IDM_OWNERCOMBOBOX:
                    /* Bring up the owner-draw dropdown list box example */
                    lpProc = MakeProcInstance ((FARPROC)OwnerComboBoxExample, hInst);
                    DialogBox (hInst,
                               "OwnerComboBoxDialog",
                               hWnd,
                               lpProc);
                    FreeProcInstance (lpProc);
                    break;
            }
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return(DefWindowProc(hWnd, message, wParam, lParam));
    }
    return(0);
}

BOOL FAR PASCAL OwnerComboBoxExample | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 754 of file OWNCOMBO.C.

{
    LPDRAWITEMSTRUCT    lpdis;
    LPMEASUREITEMSTRUCT lpmis;

    switch (message){
        case WM_COMMAND:
            switch (LOWORD(wParam)){
                case IDOK:
                   EndDialog (hDlg, 0);
                   return(TRUE);
                   break;

                /* Clicking any of these buttons adds the corresponding color
                 * to the combo box. The application-supplied data is the RGB
                 * value for the color to be drawn in the listbox.
                 */
                case ID_BLACK:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,0,0));
                   return(TRUE);
                   break;

                case ID_RED:
                   SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (255,0,0));
                   return(TRUE);
                   break;

                case ID_BLUE:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,0,255));
                   return(TRUE);
                   break;

                case ID_GREEN:
                   SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
                                CB_ADDSTRING,
                                0,
                                RGB (0,255,0));
                   return(TRUE);
                   break;

                default:
                   return(TRUE);
                   break;
            }

        case WM_DRAWITEM:
            /* Get pointer to the DRAWITEMSTRUCT */
            lpdis = (LPDRAWITEMSTRUCT)lParam;

            if (lpdis->itemID == -1){
                /* We have a request to draw an item in the combo box, yet there
                 * are no combo box items. This is sent when the user TABS into
                 * an empty combo box or an empty combo box gets the focus. We
                 * have to indicate (somehow) that this owner-draw combo box has
                 * the focus. We do it in response to this message. Note that
                 * lpdis->itemData field would be invalid in this instance so
                 * we can't allow it to fall into our standard routines.
                 */
                HandleFocusState(lpdis, -2);
            }
            else
            {
                switch (lpdis->itemAction)
                {
                        case ODA_DRAWENTIRE:
                                DrawEntireItem(lpdis, -4);
                                break;

                        case ODA_SELECT:
                                HandleSelectionState(lpdis, 0);
                                break;

                        case ODA_FOCUS:
                                HandleFocusState(lpdis, -2);
                                break;
                }
            }

            /* Return TRUE meaning that we processed this message. */
            return(TRUE);
            break;

        case WM_MEASUREITEM:
            lpmis = (LPMEASUREITEMSTRUCT)lParam;

            /* All the items are the same height since the combo box is
             * CBS_OWNERDRAWFIXED
             */
            if (lpmis->itemID == -1){
                /* If -1 for item, then we are setting the height of the
                 * always visible static item part of the dropdown combo box.
                 */
                lpmis->itemHeight = 25;
                return(TRUE);
            }
            lpmis->itemHeight = 30;
            break;

        case WM_CLOSE:
            EndDialog(hDlg, 0);
            return(TRUE);
            break;

        default:
            return(FALSE);
    }
    return(TRUE);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PATHS/PATHS.C File Reference

  • PATHS
Defines | Functions

PATHS.C File Reference

#include <windows.h>
#include <string.h>
#include <math.h>
#include "paths.h"

Go to the source code of this file.

Defines

#define | TWO_PI 6.2831853f

Functions

void | DrawPath (HDC hdc, PRECT prect)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | NewAngleArc (HDC hdc, int X, int Y, DWORD dwRadius, float fStartDegrees, float fEndDegrees)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Define Documentation

#define TWO_PI 6.2831853f

Definition at line 312 of file PATHS.C.

Function Documentation

void DrawPath | ( | HDC | hdc,
 |  | PRECT | prect
 | ) |  |

Definition at line 249 of file PATHS.C.

{
    RECT destRect;
    POINT ptRect[4];
    DWORD dwError;
    BOOL fRet;

    /* make a copy that we can modify with impunity. */
    CopyRect (&destRect, prect);

    BeginPath (hdc);

    InflateRect (&destRect, ((destRect.left- destRect.right)/5),
                        ((destRect.top- destRect.bottom)/5));

//    Rectangle (hdc, destRect.left, destRect.top,
//                    destRect.right, destRect.bottom);
    ptRect[0].x = destRect.left; ptRect[0].y = destRect.top;
    ptRect[1].x = destRect.left; ptRect[1].y = destRect.bottom;
    ptRect[2].x = destRect.right; ptRect[2].y = destRect.bottom;
    ptRect[3].x = destRect.right; ptRect[3].y = destRect.top;
    fRet = Polygon (hdc, ptRect, 4);
    if (!fRet)
        dwError = GetLastError();

    InflateRect (&destRect, ((destRect.left- destRect.right)/4),
                        ((destRect.top- destRect.bottom)/4));

//    Ellipse (hdc, destRect.left, destRect.top,
//                  destRect.right, destRect.bottom);
    ptRect[0].x = destRect.left; ptRect[0].y = destRect.top;
    ptRect[1].x = destRect.left; ptRect[1].y = destRect.bottom;
    ptRect[2].x = destRect.right; ptRect[2].y = destRect.bottom;
    ptRect[3].x = destRect.right; ptRect[3].y = destRect.top;
    fRet = Polygon (hdc, ptRect, 4);
    if (!fRet)
        dwError = GetLastError();

    EndPath (hdc);
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 117 of file PATHS.C.

{
  static HANDLE hPenFill, hPenPath;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Create three pens for drawing with later.
    \**********************************************************************/
    case WM_CREATE:
        hPenPath   = CreatePen (PS_SOLID, 2, (COLORREF) 0x01000005);
        hPenFill   = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000002);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Complement of the WM_CREATE message.  Delete the pens that were
    *  created and then call postquitmessage.
    \**********************************************************************/
    case WM_DESTROY:
      DeleteObject (hPenFill);
      DeleteObject (hPenPath);

      PostQuitMessage(0);
    break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * Query the client rectangle.  Divide it into six sub rectangles
    *  (only actually compute the top left sixth).  Now, set the origin
    *  for each one of these, write text describing the operation, and
    *  then stroke or fill or whatever the path.
    \**********************************************************************/
    case WM_PAINT: {
      HDC  hdc;
      PAINTSTRUCT ps;
      RECT rect;
      HRGN hrgn;
      int  i;

      hdc = BeginPaint(hwnd, &ps);
      SetBkMode (hdc, TRANSPARENT);

      GetClientRect (hwnd, &rect);
      rect.bottom /= 2;
      rect.right /= 3;
      SelectObject(hdc, hPenPath);

      /* 1. Just stroke the path */
      SetViewportOrgEx (hdc, 0, 0, NULL);
      TextOut (hdc, 2, 10, STROKEPATH, sizeof (STROKEPATH)-1);
      DrawPath(hdc, &rect);
      StrokePath (hdc);

      /* 2. Fill the path */
      SetViewportOrgEx (hdc, 0, rect.bottom, NULL);
      TextOut (hdc, 2, 10, FILLPATH, sizeof (FILLPATH)-1);
      DrawPath(hdc, &rect);
      FillPath (hdc);

      /* 3. Stroke and fill the path */
      SetViewportOrgEx (hdc,rect.right, 0, NULL);
      SetPolyFillMode (hdc, WINDING);
      TextOut (hdc, 2, 10, STROKEANDFILLWIND, sizeof (STROKEANDFILLWIND)-1);
      DrawPath(hdc, &rect);
      StrokeAndFillPath (hdc);

      /* 4. Stroke and fill it again, but with different mode. */
      SetViewportOrgEx (hdc,rect.right, rect.bottom, NULL);
      SetPolyFillMode (hdc, ALTERNATE);
      TextOut (hdc, 2, 10, STROKEANDFILLALT, sizeof (STROKEANDFILLALT)-1);
      DrawPath(hdc, &rect);
      StrokeAndFillPath (hdc);

      /* 5. Set the clipping region based on the path. */
      SetViewportOrgEx (hdc,rect.right*2, 0, NULL);
      SetPolyFillMode (hdc, WINDING);
      TextOut (hdc, 2, 10, CLIPPATHWIND, sizeof (CLIPPATHWIND)-1);
      SelectObject(hdc, hPenFill);
      DrawPath(hdc, &rect);
      hrgn = PathToRegion(hdc);
      SelectClipRgn (hdc, hrgn);
      DeleteObject (hrgn);
      MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL);
      for (i = 0; i < (rect.right/2); i += 5)
        NewAngleArc (hdc, rect.right/2, rect.bottom/2, i,
                     (FLOAT)0.0, (FLOAT)360.0);

      /* 6. Set the clipping region based on the path, with different mode. */
      SetViewportOrgEx (hdc,rect.right*2, rect.bottom, NULL);
      SetPolyFillMode (hdc, ALTERNATE);
      /* clear the clip region so that TextOut() shows up. */
      ExtSelectClipRgn (hdc, NULL, RGN_COPY);
      TextOut (hdc, 2, 10, CLIPPATHALT, sizeof (CLIPPATHALT)-1);
      DrawPath(hdc, &rect);
      hrgn = PathToRegion(hdc);
      SelectClipRgn (hdc, hrgn);
      DeleteObject (hrgn);
      MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL);
      for (i = 0; i < (rect.right/2); i += 5)
        NewAngleArc (hdc, rect.right/2, rect.bottom/2, i,
                     (FLOAT)0.0, (FLOAT)360.0);

      EndPaint (hwnd, &ps);

    } return 0;

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

BOOL NewAngleArc | ( | HDC | hdc,
 |  | int | X,
 |  | int | Y,
 |  | DWORD | dwRadius,
 |  | float | fStartDegrees,
 |  | float | fEndDegrees
 | ) |  |

Definition at line 313 of file PATHS.C.

{
    float fCurrentAngle, fStepAngle = 0.03f;
    float fx, fy;
    float fStart, fEnd;

    /* Use NT version if we are on NT else do it ourselves*/
    if (GetVersion() & 0x80000000)
    {
        /* Not NT, so we draw it the hard way */

        /* Convert degrees to radians */
        /* radians = (deg / 360) * 2pi */
        fStart = (fStartDegrees / 360.0f) * TWO_PI;
        fEnd = (fEndDegrees / 360.0f) * TWO_PI;

        /* Calculate and move to starting point for sweep */
        fx = (float)dwRadius * (float)cos(fStart);
        fy = (float)dwRadius * (float)sin(fStart);
        MoveToEx(hdc, (int)fx + X, Y - (int)fy, NULL);

        /* Calculate and draw the sweep */
        for (fCurrentAngle = fStart; fCurrentAngle <= fEnd;
             fCurrentAngle += fStepAngle)
        {
            /* Convert from polar to cartesian coordinate */
            fx = (float)dwRadius * (float)cos(fCurrentAngle);
            fy = (float)dwRadius * (float)sin(fCurrentAngle);

            /* Draw the segment */
            LineTo(hdc, (int)fx + X, Y - (int)fy);
        }
    }
    else
        /* This is NT, so use the API */
        return AngleArc(hdc, X, Y, dwRadius, fStartDegrees, fEndDegrees);

    return TRUE;
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 30 of file PATHS.C.

{
    HANDLE hInst;
    HWND   hwndMain;
    MSG    msg;

    UNREFERENCED_PARAMETER( lpCmdLine );

#if 0
     // check if running on Windows NT, if not, display notice and terminate
        if( GetVersion() & 0x80000000 )
        {
          MessageBoxA( NULL,
           "This sample application can only be run on Windows NT.\n"
             "This application will now terminate.",
             "Paths",
             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
          return( 1 );
        }
#endif

    /* Check for previous instance.  If none, then register class. */
    if (!hPrevInstance) {
        WNDCLASS  wc;

        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = (WNDPROC)MainWndProc;

        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, "pathsIcon");
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "paths";

        if (!RegisterClass(&wc)) return (FALSE);
    }  /* class registered o.k. */

    /* Create the main window.  Return false if CreateWindow() fails */
    hInst = hInstance;

    hwndMain = CreateWindow(
        "paths",
        "Paths",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    if (!hwndMain) return (FALSE);
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    /* Loop getting messages and dispatching them. */
    while (GetMessage(&msg,NULL, 0,0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }

    return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PATHS/PATHS.H File Reference

  • PATHS
Defines | Functions

PATHS.H File Reference

Go to the source code of this file.

Defines

#define | CLIPPATHALT "ClipPath, Alternate"
#define | CLIPPATHWIND "ClipPath, Winding"
#define | FILLPATH "FillPath"
#define | STROKEANDFILLALT "StrokeAndFill, Alternate"
#define | STROKEANDFILLWIND "StrokeAndFill, Winding"
#define | STROKEPATH "StrokePath"

Functions

void | DrawPath (HDC, LPRECT)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
BOOL | NewAngleArc (HDC, int, int, DWORD, float, float)

Define Documentation

#define CLIPPATHALT "ClipPath, Alternate"

Definition at line 27 of file PATHS.H.

#define CLIPPATHWIND "ClipPath, Winding"

Definition at line 26 of file PATHS.H.

#define FILLPATH "FillPath"

Definition at line 23 of file PATHS.H.

#define STROKEANDFILLALT "StrokeAndFill, Alternate"

Definition at line 25 of file PATHS.H.

#define STROKEANDFILLWIND "StrokeAndFill, Winding"

Definition at line 24 of file PATHS.H.

#define STROKEPATH "StrokePath"

Definition at line 22 of file PATHS.H.

Function Documentation

void DrawPath | ( | HDC | ,
 |  | LPRECT |
 | ) |  |
LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

BOOL NewAngleArc | ( | HDC | ,
 |  | int | ,
 |  | int | ,
 |  | DWORD | ,
 |  | float | ,
 |  | float |
 | ) |  |

Definition at line 313 of file PATHS.C.

{
    float fCurrentAngle, fStepAngle = 0.03f;
    float fx, fy;
    float fStart, fEnd;

    /* Use NT version if we are on NT else do it ourselves*/
    if (GetVersion() & 0x80000000)
    {
        /* Not NT, so we draw it the hard way */

        /* Convert degrees to radians */
        /* radians = (deg / 360) * 2pi */
        fStart = (fStartDegrees / 360.0f) * TWO_PI;
        fEnd = (fEndDegrees / 360.0f) * TWO_PI;

        /* Calculate and move to starting point for sweep */
        fx = (float)dwRadius * (float)cos(fStart);
        fy = (float)dwRadius * (float)sin(fStart);
        MoveToEx(hdc, (int)fx + X, Y - (int)fy, NULL);

        /* Calculate and draw the sweep */
        for (fCurrentAngle = fStart; fCurrentAngle <= fEnd;
             fCurrentAngle += fStepAngle)
        {
            /* Convert from polar to cartesian coordinate */
            fx = (float)dwRadius * (float)cos(fCurrentAngle);
            fy = (float)dwRadius * (float)sin(fCurrentAngle);

            /* Draw the segment */
            LineTo(hdc, (int)fx + X, Y - (int)fy);
        }
    }
    else
        /* This is NT, so use the API */
        return AngleArc(hdc, X, Y, dwRadius, fStartDegrees, fEndDegrees);

    return TRUE;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PLATFORM/PLATFORM.C File Reference

  • PLATFORM
Defines | Functions | Variables

PLATFORM.C File Reference

#include <stddef.h>
#include "windows.h"
#include "Platform.h"

Go to the source code of this file.

Defines

#define | LPTSTR LPSTR
#define | STRICT
#define | TCHAR char
#define | TEXT(x) x
#define | UNREFERENCED_PARAMETER(x) x;
#define | WF1_WINNT 0x40
#define | WINAPI FAR PASCAL

Functions

BOOL CALLBACK | About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
BOOL | InitApplication (HANDLE hInstance)
BOOL | InitInstance (HANDLE hInstance, int nCmdShow)
LRESULT CALLBACK | MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HINSTANCE | hInst

Define Documentation

#define LPTSTR LPSTR

Definition at line 45 of file PLATFORM.C.

#define STRICT

Definition at line 34 of file PLATFORM.C.

#define TCHAR char

Definition at line 44 of file PLATFORM.C.

#define TEXT ( x ) x

Definition at line 47 of file PLATFORM.C.

#define UNREFERENCED_PARAMETER ( x ) x;

Definition at line 46 of file PLATFORM.C.

#define WF1_WINNT 0x40

Definition at line 49 of file PLATFORM.C.

#define WINAPI FAR PASCAL

Definition at line 43 of file PLATFORM.C.

Function Documentation

BOOL CALLBACK About | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 345 of file PLATFORM.C.

{
    switch (message) {
        case WM_INITDIALOG:                /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command? */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE hInstance )

Definition at line 147 of file PLATFORM.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                        /* Class style(s).                    */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "PlatformMenu";   /* Name of menu resource in .RC file. */
    wc.lpszClassName = "PlatformWClass"; /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HANDLE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 190 of file PLATFORM.C.

{
    HWND            hWnd;               /* Main window handle.                */

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    hInst = hInstance;

    /* Create a main window for this application instance.  */

    hWnd = CreateWindow(
        "PlatformWClass",                /* See RegisterClass() call.          */
        "Platform Sample Application",   /* Text for window title bar.         */
        WS_OVERLAPPEDWINDOW,            /* Window style.                      */
        10,                  /* Default horizontal position.       */
        10,                  /* Default vertical position.         */
        600,                  /* Default width.                     */
        400,                  /* Default height.                    */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer not needed.                */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    /* Make the window visible; update its client area; and return "success" */

    ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */
    return (TRUE);               /* Returns the value from PostQuitMessage */

}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 250 of file PLATFORM.C.

{
    DLGPROC lpProcAbout;
    DWORD   version, flags;
    char    buf[80];

    switch (message) {

        case WM_COMMAND:           /* message: command from application menu */
            if (LOWORD(wParam) == IDM_ABOUT) {
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, hInst );

                DialogBox(hInst,                 /* current instance         */
                    "AboutBox",                  /* resource to use          */
                    hWnd,                        /* parent handle            */
                    lpProcAbout);       /* About() instance address */

                FreeProcInstance((FARPROC)lpProcAbout);
                break;
            }
            else if ( LOWORD(wParam) == IDM_PLATFORM ) {
                version = GetVersion();
                wsprintf( buf, "The version of Windows that you are running is %d.%d",
                          LOBYTE(LOWORD(version)), HIBYTE(LOWORD(version)) );

                MessageBox( hWnd, buf, "Platform", MB_OK );
#if defined(_WIN32) || defined(WIN32)
/*
 * bugbug Currently HIWORD of version is 500. The highbit is not set
 */

                if (version < 0x80000000)
                    wsprintf( buf, "This is running on Win32/NT" );
                else
                    if (LOBYTE(LOWORD(version)) < 4)
                        wsprintf( buf, "This is running on Win32s" );
                    else
                        wsprintf( buf, "This is running on Windows 95" );

                UNREFERENCED_PARAMETER(flags);
#else
                flags = GetWinFlags();
                wsprintf ( buf, "flags are %#lx", flags );
//                MessageBox ( hWnd, buf, NULL, MB_OK );

                if ( flags & WF1_WINNT )
                    wsprintf ( buf, "This is running in the WOW layer" );
                else
                    if (HIBYTE(LOWORD(version)) == 95)
                        wsprintf( buf, "This is running on Windows 95" );
                    else
                        wsprintf( buf, "The version of MS-DOS you're running is %d.%d",
                            HIBYTE(HIWORD(version)), LOBYTE(HIWORD(version)) );
#endif
                MessageBox( hWnd, buf, "Platform", MB_OK );
            }
            else                            /* Lets Windows process it       */
                return (DefWindowProc(hWnd, message, wParam, lParam));

            break;

        case WM_DESTROY:                  /* message: window being destroyed */
            PostQuitMessage(0);
            break;

        default:                          /* Passes it on if unproccessed    */
            return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 94 of file PLATFORM.C.

{
    MSG msg;                                 /* message                      */

    if (!hPrevInstance)                  /* Other instances of app running? */
        if (!InitApplication(hInstance)) /* Initialize shared things */
            return (FALSE);              /* Exits if unable to initialize     */

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,        /* message structure                      */
            NULL,                  /* handle of window receiving the message */
            0,                     /* lowest message to examine              */
            0))                    /* highest message to examine             */
    {
            TranslateMessage(&msg);    /* Translates virtual key codes           */
            DispatchMessage(&msg);     /* Dispatches message to window           */
    }

    return (msg.wParam);           /* Returns the value from PostQuitMessage */
UNREFERENCED_PARAMETER(lpCmdLine);
}

Variable Documentation

HINSTANCE hInst

Definition at line 69 of file PLATFORM.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PLATFORM/PLATFORM.H File Reference

  • PLATFORM
Defines | Functions

PLATFORM.H File Reference

Go to the source code of this file.

Defines

#define | IDM_ABOUT 100
#define | IDM_PLATFORM 200

Functions

BOOL CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
BOOL | InitApplication (HANDLE)
BOOL | InitInstance (HANDLE, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
int PASCAL | WinMain (HINSTANCE, HINSTANCE, LPSTR, int)

Define Documentation

#define IDM_ABOUT 100

Definition at line 12 of file PLATFORM.H.

#define IDM_PLATFORM 200

Definition at line 13 of file PLATFORM.H.

Function Documentation

BOOL CALLBACK About | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 497 of file BOB.C.

{
    switch (message) {
        case WM_INITDIALOG:           /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command?  */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

BOOL InitApplication ( HANDLE )

Definition at line 124 of file BOB.C.

{
    WNDCLASS  wc;

    /* Fill in window class structure with parameters that describe the       */
    /* main window.                                                           */

    wc.style = 0;                       /* Class style(s).            */
    wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
                                        /* windows of this class.             */
    wc.cbClsExtra = 0;                  /* No per-class extra data.           */
    wc.cbWndExtra = 0;                  /* No per-window extra data.          */
    wc.hInstance = hInstance;           /* Application that owns the class.   */
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
    wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */

    /* Register the window class and return success/failure code. */

    if ( !RegisterClass(&wc) )
        return( FALSE );

}

BOOL InitInstance | ( | HANDLE | ,
 |  | int |
 | ) |  |

Definition at line 170 of file BOB.C.

{
    HWND      hWnd;                 /* Main window handle.                */
    HWND      hWndDeskTop;
    RECT      rcDeskTop;

    /* Save the instance handle in static variable, which will be used in  */
    /* many subsequence calls from this application to Windows.            */

    ghInst = hInstance;

    /* Create a main window for this application instance.  */

    hWndDeskTop = GetDesktopWindow();
    GetWindowRect( hWndDeskTop, &rcDeskTop );

    hWnd = CreateWindow(
        "BOBWClass",                    /* See RegisterClass() call.          */
        "BOB",                          /* Text for window title bar.         */
        WS_OVERLAPPED,                  /* Window style.                      */
        rcDeskTop.left+50,              /* horizontal position.               */
        rcDeskTop.bottom-200,           /* vertical position.                 */
        150,                            /* width.                             */
        100,                            /* height.                            */
        NULL,                           /* Overlapped windows have no parent. */
        NULL,                           /* Use the window class menu.         */
        hInstance,                      /* This instance owns this window.    */
        NULL                            /* Pointer to Createion Parameters    */
    );

    /* If window could not be created, return "failure" */

    if (!hWnd)
        return (FALSE);

    ShowWindow(hWnd, nCmdShow);  /* Show the window                */
    UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
    ghWnd = hWnd;

}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

int PASCAL WinMain | ( | HINSTANCE | ,
 |  | HINSTANCE | ,
 |  | LPSTR | ,
 |  | int |
 | ) |  |

Definition at line 71 of file BOB.C.

{
    MSG msg;                            /* message              */

    if (!hPrevInstance)                 /* Other instances of app running? */
    if (!InitApplication(hInstance))    /* Initialize shared things */
        return (FALSE);                 /* Exits if unable to initialize */

    /* Perform initializations that apply to a specific instance */

    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while (GetMessage(&msg,    /* message structure                      */
        NULL,                  /* handle of window receiving the message */
        0,                     /* lowest message to examine              */
        0))                    /* highest message to examine             */
    {
        TranslateMessage(&msg);    /* Translates virtual key codes       */
        DispatchMessage(&msg);     /* Dispatches message to window       */

    }
    return (msg.wParam);       /* Returns the value from PostQuitMessage */
UNREFERENCED_PARAMETER(lpCmdLine);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: POLYDRAW/POLYDRAW.C File Reference

  • POLYDRAW
Functions

POLYDRAW.C File Reference

#include <windows.h>
#include "polydraw.h"

Go to the source code of this file.

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 118 of file POLYDRAW.C.

{
static HANDLE hPenGrey, hPenLine, hPenpolydraw;
static POINT svPoints [MAXPOINTS];
static BYTE  svTypes  [MAXPOINTS];
static int   svNumDown;
static int   svIndex;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Initialize the static variables.
    *  Then create three pens for drawing with later.
    \**********************************************************************/
    case WM_CREATE:
        svNumDown = NONE;
        svIndex = NONE;
        hPenLine     = CreatePen (PS_SOLID, 1, (COLORREF) 0x0100000f);
        hPenpolydraw = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000005);
        hPenGrey     = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000007);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Complement of the WM_CREATE message.  Delete the pens that were
    *  created and then call postquitmessage.
    \**********************************************************************/
    case WM_DESTROY:
      DeleteObject (hPenLine);
      DeleteObject (hPenpolydraw);
      DeleteObject (hPenGrey);

      PostQuitMessage(0);
    break;

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    *
    * Hittest to see if the user is selecting an existing point.
    *  If not, check for point overflow.
    *  If o.k. then add a new point to the current list.
    \**********************************************************************/
    case WM_LBUTTONDOWN: {
      int i;
      RECT rectNear;

      /* Construct a rectangle around the mouse point. */
      rectNear.left   = LOWORD(lParam) - HITSIZE;
      rectNear.right  = LOWORD(lParam) + HITSIZE;
      rectNear.top    = HIWORD(lParam) - HITSIZE;
      rectNear.bottom = HIWORD(lParam) + HITSIZE;

      /* step through all points so far.  hittest mouse location against
       *  each one.  If we hit one, set index, capture mouse and exit
       *  window procedure.
       */
      for (i = 0; i<= svNumDown; i++) {
        if (PtInRect (&rectNear, svPoints[i])) {
          svIndex = i;
          SetCapture (hwnd);
          return 0;
        }
      }

      /* we did not hit an old point, watch for overflow. */
      if (svNumDown == (MAXPOINTS-1)) {
        MessageBox (hwnd,
                    "Points may be dragged with left mouse button.",
                    "No more points allowed",
                    MB_OK | MB_ICONSTOP);
        return 0;
      }

      /* don't have old point, still room for more.  Put down one more. */
      if (GetCapture() != hwnd) {
        svNumDown++;
        svPoints[svNumDown].x = LOWORD(lParam);
        svPoints[svNumDown].y = HIWORD(lParam);

        /* set the type value in the array dependent upon keyboard state. */
        if (wParam & MK_SHIFT)        svTypes [svNumDown] = PT_MOVETO;
        else if (wParam & MK_CONTROL) svTypes [svNumDown] = PT_BEZIERTO;
        else                          svTypes [svNumDown] = PT_LINETO;

        InvalidateRect (hwnd, NULL, TRUE);
      }

    }break;

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * If the curve is tracking the mouse, the erase the old curve by drawing
    *  over it with the grey pen.  Redraw the new curves with the proper pens.
    \**********************************************************************/
    case WM_MOUSEMOVE: {
      if (GetCapture() == hwnd) {
        HDC hdc;

        hdc = GetDC (hwnd);
        MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);

        /* Erase the old lines and curves. */
        SelectObject(hdc, hPenGrey);
        Polyline (hdc, svPoints, svNumDown+1);
        PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);

        /* Change the point to match the new mouse position. */
        svPoints[svIndex].x = (int)(short)LOWORD(lParam);
        svPoints[svIndex].y = (int)(short)HIWORD(lParam);

        MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);
        SelectObject(hdc, hPenLine);
        Polyline (hdc, svPoints, svNumDown+1);
        SelectObject(hdc, hPenpolydraw);
        PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);

        ReleaseDC (hwnd, hdc);
      }
    }break;

    /**********************************************************************\
    *  WM_LBUTTONUP
    *
    * Finished tracking.  Release the mouse capture, and force repaint.
    \**********************************************************************/
    case WM_LBUTTONUP:
      if (GetCapture() == hwnd) {
        SetCapture (NULL);
        InvalidateRect (hwnd, NULL, FALSE);
      }
    break;

    /**********************************************************************\
    *  WM_RBUTTONDOWN
    *
    * Re-Initialize the static variables, and force a repaint
    \**********************************************************************/
    case WM_RBUTTONDOWN:
      svNumDown = NONE;
      svIndex = NONE;
      InvalidateRect (hwnd, NULL, TRUE);
    break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * Write the instructions at the bottom of the window.  (Note that these
    *  lines may be erased by user MOUSEMOVE actions.)  Draw the polyline
    *  then draw the PolyDraw.
    \**********************************************************************/
    case WM_PAINT: {
      HDC hdc;
      PAINTSTRUCT ps;
      RECT  rect;
      int   height,x,y;

      hdc = BeginPaint(hwnd, &ps);

      /* set the background mode, the write out the 4 instruction strings. */
      SetBkMode (hdc, TRANSPARENT);
      height = GetSystemMetrics (SM_CYCAPTION);
      GetClientRect (hwnd, &rect);
      x = rect.left + 10;
      y = rect.bottom - 4*height;
      TextOut (hdc, x,y, instructions0,sizeof(instructions0)-1);
      y = rect.bottom - 3*height;
      TextOut (hdc, x,y, instructions1,sizeof(instructions1)-1);
      y = rect.bottom - 2*height;
      TextOut (hdc, x,y, instructions2,sizeof(instructions2)-1);
      y = rect.bottom - 1*height;
      TextOut (hdc, x,y, instructions3,sizeof(instructions3)-1);

      /* Move to the first point in the array and then call polydraw */
      MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);

      SelectObject(hdc, hPenLine);
      Polyline (hdc, svPoints, svNumDown+1);
      SelectObject(hdc, hPenpolydraw);
      PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);

      EndPaint (hwnd, &ps);
    } return FALSE;

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 32 of file POLYDRAW.C.

{
    HANDLE hInst;
    HWND   hwndMain;
    MSG   msg;

    UNREFERENCED_PARAMETER( lpCmdLine );

    /* Check for previous instance.  If none, then register class. */
    if (!hPrevInstance) {
        WNDCLASS  wc;

        wc.style = CS_VREDRAW;
        wc.lpfnWndProc = (WNDPROC)MainWndProc;

        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, "polydrawIcon");
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "polydraw";

        if (!RegisterClass(&wc)) return (FALSE);
    }  /* class registered o.k. */

    /* Create the main window.  Return false if CreateWindow() fails */
    hInst = hInstance;

    hwndMain = CreateWindow(
        "polydraw",
        "PolyDraw",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    if (!hwndMain) return (FALSE);
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    /* Loop getting messages and dispatching them. */
    while (GetMessage(&msg,NULL, 0,0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: POLYDRAW/POLYDRAW.H File Reference

  • POLYDRAW
Defines | Functions | Variables

POLYDRAW.H File Reference

Go to the source code of this file.

Defines

#define | HITSIZE 10
#define | MAXPOINTS 16
#define | NONE -1

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)

Variables

char | instructions0 [] = "Left mouse button places or moves points. Right button erases."
char | instructions1 [] = " default -- PT_LINETO "
char | instructions2 [] = " <shift> -- PT_MOVETO "
char | instructions3 [] = " <ctrl> -- PT_BEZIERTO"

Define Documentation

#define HITSIZE 10

Definition at line 20 of file POLYDRAW.H.

#define MAXPOINTS 16

Definition at line 18 of file POLYDRAW.H.

#define NONE -1

Definition at line 19 of file POLYDRAW.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

Variable Documentation

char instructions0[] = "Left mouse button places or moves points. Right button erases."

Definition at line 23 of file POLYDRAW.H.

char instructions1[] = " default -- PT_LINETO "

Definition at line 25 of file POLYDRAW.H.

char instructions2[] = " <shift> -- PT_MOVETO "

Definition at line 26 of file POLYDRAW.H.

char instructions3[] = " <ctrl> -- PT_BEZIERTO"

Definition at line 27 of file POLYDRAW.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/DATABASE.C File Reference

  • READWRIT
Defines | Typedefs | Functions | Variables

DATABASE.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define | EVENT1 "event1"
#define | EVENT2 "event2"
#define | EVENT3 "evnet3"
#define | EVENT4 "event4"
#define | MAX 10
#define | MUTX1 "mutx1"
#define | NOMINMAX
#define | SEM1 "semph1"
#define | SIGNALED 0
#define | STRICT
#define | WAIT_ERROR 0xFFFFFFFF

Typedefs

typedef HANDLE | HEVENT
typedef HANDLE | HMUTEX
typedef HANDLE | HSEM

Functions

BOOL | CleanupApp (VOID)
BOOL | CleanupSubsystem (VOID)
BOOL | CloseDataBase (VOID)
VOID | DebugMsg (PSZ psz)
BOOL WINAPI | DllMain (HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
VOID | ErrorMsg (PSZ psz)
BOOL | GetData (PSZ psz)
BOOL | InitApp (VOID)
BOOL | InitializeDataBase (VOID)
BOOL | InitializeSubsystem (VOID)
BOOL | PutData (PSZ psz)
BOOL WINAPI | ReadDataBase (PSZ psz1, PSZ psz2)
BOOL WINAPI | WriteDataBase (PSZ psz1, PSZ psz2)

Variables

UINT | cRead
UINT | cReadQueue
UINT | cReadQueueEx
UINT | cWrite
UINT | cWriteQueue
char * | DataBase [MAX]
HMUTEX ghMutex
HEVENT ghReadEvent1
HEVENT ghReadEvent2
HSEM ghSemaphore
HEVENT ghWriteEvent1
HEVENT ghWriteEvent2
int | gUserCount = 0
BOOL | InWrite

Define Documentation

#define EVENT1 "event1"

Definition at line 67 of file DATABASE.C.

#define EVENT2 "event2"

Definition at line 68 of file DATABASE.C.

#define EVENT3 "evnet3"

Definition at line 69 of file DATABASE.C.

#define EVENT4 "event4"

Definition at line 70 of file DATABASE.C.

#define MAX 10

Definition at line 72 of file DATABASE.C.

#define MUTX1 "mutx1"

Definition at line 66 of file DATABASE.C.

#define NOMINMAX

Definition at line 53 of file DATABASE.C.

#define SEM1 "semph1"

Definition at line 65 of file DATABASE.C.

#define SIGNALED 0

Definition at line 74 of file DATABASE.C.

#define STRICT

Definition at line 52 of file DATABASE.C.

#define WAIT_ERROR 0xFFFFFFFF

Definition at line 75 of file DATABASE.C.

Typedef Documentation

typedef HANDLE HEVENT

Definition at line 62 of file DATABASE.C.

typedef HANDLE HMUTEX

Definition at line 60 of file DATABASE.C.

typedef HANDLE HSEM

Definition at line 61 of file DATABASE.C.

Function Documentation

BOOL CleanupApp ( VOID )

Definition at line 486 of file DATABASE.C.

{
    DebugMsg ( "CleanupApp\n" ) ;

    if ( !CloseHandle ( ghSemaphore ) )
        ErrorMsg ( "Error Closing Semaphore" ) ;

    if ( !CloseHandle ( ghMutex ) )
        ErrorMsg ( "Error Closing Mutex" ) ;

    if ( !CloseHandle ( ghReadEvent1 ) )
        ErrorMsg ( "Error Closing Event" ) ;

    if ( !CloseHandle ( ghWriteEvent1 ) )
        ErrorMsg ( "Error Closing Event" ) ;

    return ( TRUE ) ;
}

BOOL CleanupSubsystem ( VOID )

Definition at line 451 of file DATABASE.C.

{
    DebugMsg ( "CleanupSubsystem\n" ) ;

    if ( !CloseHandle ( ghSemaphore ) )
        ErrorMsg ( "Error Closing Semaphore" ) ;

    if ( !CloseHandle ( ghMutex ) )
        ErrorMsg ( "Error Closing Mutex" ) ;

    if ( !CloseHandle ( ghReadEvent1 ) )
        ErrorMsg ( "Error Closing Event" ) ;

    if ( !CloseHandle ( ghWriteEvent1 ) )
        ErrorMsg ( "Error Closing Event" ) ;

    CloseDataBase ( ) ;

    return ( TRUE ) ;
}

BOOL CloseDataBase ( VOID )

Definition at line 545 of file DATABASE.C.

{
    DebugMsg ( "Closing database\n" ) ;
    return ( TRUE ) ;
}

VOID DebugMsg ( PSZ psz )

Definition at line 169 of file DATABASE.C.

{
    printf ( psz ) ;
}

BOOL WINAPI DllMain | ( | HINSTANCE | hModule,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 198 of file DATABASE.C.

{

    BOOL bSuccess ;
    UNREFERENCED_PARAMETER ( hModule ) ;
    UNREFERENCED_PARAMETER ( lpReserved ) ;

    if ( dwReason == DLL_PROCESS_ATTACH ) {

        gUserCount++ ;

        printf ( "\nNumber of clients currently using this are %d\n", gUserCount ) ;

        if ( gUserCount == 1 )
            bSuccess = InitializeSubsystem ( ) ;
        else
            bSuccess = InitApp ( ) ;
    }

    else if ( dwReason == DLL_PROCESS_DETACH ) {

        printf ( "\nCleaning up subsystem ...\n" ) ;
        printf ( "Number of clients currently using this are %d\n", gUserCount ) ;

        if ( gUserCount ==  1 )
            bSuccess = CleanupSubsystem ( ) ;
        else
            bSuccess = CleanupApp ( ) ;

        gUserCount-- ;

    }

    return ( bSuccess ) ;
}

VOID ErrorMsg ( PSZ psz )

Definition at line 150 of file DATABASE.C.

{
    printf ("\n%s: return code = %d\n", psz, GetLastError()) ;
}

BOOL GetData ( PSZ psz )

Definition at line 913 of file DATABASE.C.

{
    static UINT i = 0 ;

    strcpy ( psz, DataBase[i++ % MAX] ) ;
    return ( TRUE ) ;
}

BOOL InitApp ( VOID )

Definition at line 377 of file DATABASE.C.

{

    DebugMsg ( "InitApp\n" ) ;

    ghSemaphore = OpenSemaphore ( SEMAPHORE_ALL_ACCESS,  //
                                 FALSE,                  // No inheritance
                                 SEM1 ) ;                // No name

    if ( !ghSemaphore )
    {
        ErrorMsg ( "Error Opening semaphore" ) ;
        return ( FALSE ) ;
    }

    ghMutex = OpenMutex  ( MUTEX_ALL_ACCESS,    //
                           FALSE,               // No inheritance
                           MUTX1 ) ;            // No name
    if ( !ghMutex )
    {
        ErrorMsg ( "Error Opening Mutex" ) ;
        return ( FALSE ) ;
    }

    ghReadEvent1 = OpenEvent ( EVENT_ALL_ACCESS, //
                              FALSE,            // No inheritance
                              EVENT1 ) ;        //

    if ( !ghReadEvent1 )
    {
        ErrorMsg ( "Error Opening ghReadEvent1" ) ;
        return ( FALSE ) ;
    }

    ghWriteEvent1 = OpenEvent ( EVENT_ALL_ACCESS, //
                               FALSE,            // No inheritance
                               EVENT2 ) ;        //

    if ( !ghWriteEvent1 )
    {
        ErrorMsg ( "Error Opening ghWriteEvent1" ) ;
        return ( FALSE ) ;
    }

    ghReadEvent2 = OpenEvent ( EVENT_ALL_ACCESS, //
                              FALSE,            // No inheritance
                              EVENT3 ) ;        //

    if ( !ghReadEvent2 )
    {
        ErrorMsg ( "Error Opening ghReadEvent2" ) ;
        return ( FALSE ) ;
    }

    ghWriteEvent2 = OpenEvent ( EVENT_ALL_ACCESS, //
                               FALSE,            // No inheritance
                               EVENT4 ) ;        //

    if ( !ghWriteEvent2 )
    {
        ErrorMsg ( "Error Opening ghWriteEvent2" ) ;
        return ( FALSE ) ;
    }

    return ( TRUE ) ;
}

BOOL InitializeDataBase ( VOID )

Definition at line 519 of file DATABASE.C.

{
    UINT i ;

    DebugMsg ( "Initializing database\n" ) ;

    for ( i=0; i< MAX; i++ )
        PutData ( "Unintialized" ) ;

    return ( TRUE ) ;
}

BOOL InitializeSubsystem ( VOID )

Definition at line 251 of file DATABASE.C.

{
    LONG cSemMax = 5;
    BOOL bSuccess ;

    DebugMsg ( "InitializeSubsystem\n" ) ;

    ghSemaphore = CreateSemaphore ( NULL,       // No security descriptor

                                   0,           // Initial count of zero so
                                                // access to database is blocked
                                                // till initialization completed
                                   cSemMax,
                                                // Maximun threads allowed to
                                                // access the database at one time
                                   SEM1) ;      // No name

    if ( !ghSemaphore )
    {
        ErrorMsg ( "Error Creating semaphore" ) ;
        return ( FALSE ) ;
    }

    ghMutex = CreateMutex ( NULL,               // No security descriptor
                            TRUE,               // Block access till database
                                                // is setup
                            MUTX1 ) ;           // No name
    if ( !ghMutex )
    {
        ErrorMsg ( "Error Creating Mutex" ) ;
        return ( FALSE ) ;
    }

    ghReadEvent1 = CreateEvent ( NULL,           // No security descriptor
                                FALSE,          // Use manual reset so all
                                                // waiting threads get signaled
                                FALSE,          // Set to non-signaled state
                                EVENT1 ) ;

    if ( !ghReadEvent1 )
    {
        ErrorMsg ( "Error Creating ghReadEvent1" ) ;
        return ( FALSE ) ;
    }

    ghWriteEvent1 = CreateEvent ( NULL,           // No security descriptor
                                FALSE,          // Use manual reset so all
                                                // waiting threads get signaled
                                FALSE,          // Set to non-signaled state
                                EVENT2 ) ;

    if ( !ghWriteEvent1 )
    {
        ErrorMsg ( "Error Creating ghWriteEvent1" ) ;
        return ( FALSE ) ;
    }

    ghReadEvent2 = CreateEvent ( NULL,           // No security descriptor
                                FALSE,          // Use manual reset so all
                                                // waiting threads get signaled
                                FALSE,          // Set to non-signaled state
                                EVENT3 ) ;

    if ( !ghReadEvent2 )
    {
        ErrorMsg ( "Error Creating ghReadEvent2" ) ;
        return ( FALSE ) ;
    }

    ghWriteEvent2 = CreateEvent ( NULL,           // No security descriptor
                                FALSE,          // Use manual reset so all
                                                // waiting threads get signaled
                                FALSE,          // Set to non-signaled state
                                EVENT4 ) ;

    if ( !ghWriteEvent2 )
    {
        ErrorMsg ( "Error Creating ghWriteEvent2" ) ;
        return ( FALSE ) ;
    }

    bSuccess = InitializeDataBase () ;

    /*
     * Now that all the initialization is done it's save to
     * release the semaphore and mutex.
     *
     */

    if ( !ReleaseSemaphore ( ghSemaphore,       // Handle to semaphore
                       cSemMax,                 // Size to increment
                       NULL ) )                 // Don't care about previous value
        {
            ErrorMsg ( "Error releasing semaphore" ) ;
            return ( FALSE ) ;
        }

    if ( !ReleaseMutex ( ghMutex ) )            // Handle to semaphore
        {
            ErrorMsg ( "Error releasing mutex" ) ;
            return ( FALSE ) ;
        }

    return ( bSuccess ) ;
}

BOOL PutData ( PSZ psz )

Definition at line 922 of file DATABASE.C.

{
    static UINT i = 0 ;

    i++ ;
    DataBase[i % MAX] = strdup ( psz ) ;
    return ( TRUE ) ;
}

BOOL WINAPI ReadDataBase | ( | PSZ | psz1,
 |  | PSZ | psz2
 | ) |  |

Definition at line 576 of file DATABASE.C.

{
   BOOL bSuccess ;
   DWORD dwSuccess ;
   UNREFERENCED_PARAMETER ( psz2 ) ;

//   DebugMsg ("In ReadDataBase\n" ) ;

   cReadQueueEx++ ;
   dwSuccess = SIGNALED ;

   if ( cWriteQueue )                               // Block if Writer waiting
         dwSuccess = WaitForSingleObject ( ghReadEvent1, 0xFFFFFFFF ) ;
//       dwSuccess = WaitForSingleObject ( ghReadEvent1, 5000 ) ;

   cReadQueue++ ;                                   // Reader entering queue
   cReadQueueEx-- ;

   if ( dwSuccess != SIGNALED )
   {
      ErrorMsg ( "ReadDatabase: Error Waiting for ghReadEvent1" ) ;
      bSuccess = FALSE ;
   }
   else
   {
   /*
    * Only let N readers in the queue at one time
    */
      switch ( WaitForSingleObject ( ghSemaphore, 0xFFFFFFFF ) )
//      switch ( WaitForSingleObject ( ghSemaphore, 3000 ) )
      {
          case SIGNALED:
              __try {
                   if ( InWrite )               // Block if Writer in database
                      dwSuccess = WaitForSingleObject ( ghReadEvent2, 0xFFFFFFFF ) ;
//                    dwSuccess = WaitForSingleObject ( ghReadEvent2, 1500 ) ;

                   cRead++ ;                    // Number readers in database
                   cReadQueue-- ;               // Reader leaving queue

                   /*
                    * Signal Writer if no Reader waiting
                    *
                    */
                   if ( !cReadQueue )
                      bSuccess = SetEvent ( ghWriteEvent1 ) ;

                   if ( dwSuccess == SIGNALED )
                   {
                      bSuccess = GetData ( psz1 ) ;   // Read data
                      cRead-- ;
                      /*
                       * Signal Writer if no Reader in database
                       *
                       */

                      if ( !cRead )
                         bSuccess = SetEvent ( ghWriteEvent2 ) ;

                      ReleaseSemaphore ( ghSemaphore, // Let next waiting
                                          1,          // reader in the queue
                                          NULL ) ;
                   }
                   else
                   {
                      cRead-- ;
                      /*
                       * Signal Writer if no Reader in database
                       *
                       */

                      if ( !cRead )
                         bSuccess = SetEvent ( ghWriteEvent2 ) ;

                      bSuccess = FALSE ;
                      DebugMsg ( "ReadDataBase: Error Waiting for ghReadEvent2\n" ) ;
                   }
              }
              __finally {
                 // what if these is already decremented above????
                   cRead-- ;
                   /*
                    * Signal Writer if no Reader in database
                    *
                    */

                   if ( !cRead )
                      bSuccess = SetEvent ( ghWriteEvent2 ) ;

                   /*
                    * Signal Writer if no Reader in queue
                    *
                    */
                   if ( !cReadQueue )
                      bSuccess = SetEvent ( ghWriteEvent1 ) ;

                   bSuccess = FALSE ;
                   ReleaseSemaphore ( ghSemaphore,     // Let next waiting
                                  1,                   // reader in the queue
                                  NULL ) ;
              }

              break ;

          case WAIT_TIMEOUT:
              DebugMsg ( "ReadDataBase: Error WAIT_TIMEOUT ghSemaphore\n" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;

          case WAIT_ERROR:
              ErrorMsg ( "ReadDataBase: Error WAIT_ERROR ghSemaphore" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;

          default:
              DebugMsg ( "ReadDataBase: Dropped through switch\n" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;
      }
   } // END IF

   return ( bSuccess ) ;
}

BOOL WINAPI WriteDataBase | ( | PSZ | psz1,
 |  | PSZ | psz2
 | ) |  |

Definition at line 758 of file DATABASE.C.

{
   BOOL bSuccess ;
   DWORD dwSuccess ;
   UNREFERENCED_PARAMETER ( psz2 ) ;

//   DebugMsg ( "In WriteDataBase\n" ) ;

   cWriteQueue++ ;                             // Writer entering queue
   dwSuccess = SIGNALED ;

                   // should the same event be used twice ???

   if ( cReadQueue )                           // Block if Reader waiting
      dwSuccess = WaitForSingleObject ( ghWriteEvent1, 0xFFFFFFFF ) ;
//      dwSuccess = WaitForSingleObject ( ghWriteEvent1, 5000 ) ;

   if ( dwSuccess != SIGNALED )
   {
      DebugMsg ( "WriteDataBase: Error Waiting for ghWriteEvent1\n" ) ;
      bSuccess = FALSE ;
   }
   else
   {
   /*
    * Only allow 1 writer at a time in the database
    *
    */
      switch ( WaitForSingleObject ( ghMutex, 0xFFFFFFFF ) ) {
//      switch ( WaitForSingleObject ( ghMutex, 3000 ) ) {
         case SIGNALED:
            __try {
               InWrite = TRUE ;
               cWriteQueue-- ;

               /*
                * Signal Reader if any waiting
                *
                */
               if ( cReadQueueEx )
                  bSuccess = SetEvent ( ghReadEvent1 ) ;

                               // Writer leaving queue
               if ( cRead )               // Block if Reader in database
                  dwSuccess = WaitForSingleObject ( ghWriteEvent2, 0xFFFFFFFF ) ;
//                dwSuccess = WaitForSingleObject ( ghWriteEvent2, 1500 ) ;

               if ( dwSuccess == SIGNALED )
               {
                  bSuccess = PutData ( psz1 ) ;
                  InWrite = FALSE ;
                  /*
                   * Signal Reader when no Writer waiting
                   *
                   */
                  bSuccess = SetEvent ( ghReadEvent2 ) ;
                  ReleaseMutex ( ghMutex ) ;    // Let next waiting writer in the queue
               }
               else
               {
                  bSuccess = FALSE ;
                  InWrite = FALSE ;
                  /*
                   * Signal Reader when no Writer waiting
                   *
                   */
                  bSuccess = SetEvent ( ghReadEvent2 ) ;
                  DebugMsg ( "WriteDataBase: Error Waiting on ghWriteEvent2\n" ) ;
               }
            }
            __finally {
               InWrite = FALSE ;
               /*
                * Signal Reader after leaving database
                *
                */
               bSuccess = SetEvent ( ghReadEvent2 ) ;

               /*
                * Signal Reader if no Writer in queue
                *
                */
               if ( !cWriteQueue )
                  bSuccess = SetEvent ( ghReadEvent1 ) ;

               bSuccess = FALSE ;
               ReleaseMutex ( ghMutex ) ;
            }
            break ;

         case WAIT_TIMEOUT:
            DebugMsg ( "WriteDataBase: Error WAIT_TIMEOUT ghMutex\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         case WAIT_ABANDONED:
            DebugMsg ( "WriteDataBase: Error WAIT_ABANDONED ghMutex\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         case WAIT_ERROR:
            ErrorMsg ( "WriteDataBase: Error WAIT_ERROR ghMutex" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         default:
            DebugMsg ( "WriteDataBase: Dropped through switch\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;
      }
   } // END IF

   if ( cReadQueue )
       bSuccess = SetEvent ( ghReadEvent1 ) ;          // Signal Reader
   else
       bSuccess = SetEvent ( ghWriteEvent1 ) ;         // Signal Writer

   return ( bSuccess ) ;
}

Variable Documentation

UINT cRead

Definition at line 98 of file DATABASE.C.

UINT cReadQueue

Definition at line 97 of file DATABASE.C.

UINT cReadQueueEx

Definition at line 97 of file DATABASE.C.

UINT cWrite

Definition at line 98 of file DATABASE.C.

UINT cWriteQueue

Definition at line 97 of file DATABASE.C.

char* DataBase[MAX]

Definition at line 106 of file DATABASE.C.

HMUTEX ghMutex

Definition at line 94 of file DATABASE.C.

HEVENT ghReadEvent1

Definition at line 96 of file DATABASE.C.

HEVENT ghReadEvent2

Definition at line 96 of file DATABASE.C.

HSEM ghSemaphore

Definition at line 95 of file DATABASE.C.

HEVENT ghWriteEvent1

Definition at line 96 of file DATABASE.C.

HEVENT ghWriteEvent2

Definition at line 96 of file DATABASE.C.

int gUserCount = 0

Definition at line 87 of file DATABASE.C.

BOOL InWrite

Definition at line 99 of file DATABASE.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/DATABASE.H File Reference

  • READWRIT
Functions

DATABASE.H File Reference

Go to the source code of this file.

Functions

BOOL WINAPI | ReadDataBase (PSZ, PSZ)
BOOL WINAPI | WriteDataBase (PSZ, PSZ)

Function Documentation

BOOL WINAPI ReadDataBase | ( | PSZ | ,
 |  | PSZ |
 | ) |  |

Definition at line 576 of file DATABASE.C.

{
   BOOL bSuccess ;
   DWORD dwSuccess ;
   UNREFERENCED_PARAMETER ( psz2 ) ;

//   DebugMsg ("In ReadDataBase\n" ) ;

   cReadQueueEx++ ;
   dwSuccess = SIGNALED ;

   if ( cWriteQueue )                               // Block if Writer waiting
         dwSuccess = WaitForSingleObject ( ghReadEvent1, 0xFFFFFFFF ) ;
//       dwSuccess = WaitForSingleObject ( ghReadEvent1, 5000 ) ;

   cReadQueue++ ;                                   // Reader entering queue
   cReadQueueEx-- ;

   if ( dwSuccess != SIGNALED )
   {
      ErrorMsg ( "ReadDatabase: Error Waiting for ghReadEvent1" ) ;
      bSuccess = FALSE ;
   }
   else
   {
   /*
    * Only let N readers in the queue at one time
    */
      switch ( WaitForSingleObject ( ghSemaphore, 0xFFFFFFFF ) )
//      switch ( WaitForSingleObject ( ghSemaphore, 3000 ) )
      {
          case SIGNALED:
              __try {
                   if ( InWrite )               // Block if Writer in database
                      dwSuccess = WaitForSingleObject ( ghReadEvent2, 0xFFFFFFFF ) ;
//                    dwSuccess = WaitForSingleObject ( ghReadEvent2, 1500 ) ;

                   cRead++ ;                    // Number readers in database
                   cReadQueue-- ;               // Reader leaving queue

                   /*
                    * Signal Writer if no Reader waiting
                    *
                    */
                   if ( !cReadQueue )
                      bSuccess = SetEvent ( ghWriteEvent1 ) ;

                   if ( dwSuccess == SIGNALED )
                   {
                      bSuccess = GetData ( psz1 ) ;   // Read data
                      cRead-- ;
                      /*
                       * Signal Writer if no Reader in database
                       *
                       */

                      if ( !cRead )
                         bSuccess = SetEvent ( ghWriteEvent2 ) ;

                      ReleaseSemaphore ( ghSemaphore, // Let next waiting
                                          1,          // reader in the queue
                                          NULL ) ;
                   }
                   else
                   {
                      cRead-- ;
                      /*
                       * Signal Writer if no Reader in database
                       *
                       */

                      if ( !cRead )
                         bSuccess = SetEvent ( ghWriteEvent2 ) ;

                      bSuccess = FALSE ;
                      DebugMsg ( "ReadDataBase: Error Waiting for ghReadEvent2\n" ) ;
                   }
              }
              __finally {
                 // what if these is already decremented above????
                   cRead-- ;
                   /*
                    * Signal Writer if no Reader in database
                    *
                    */

                   if ( !cRead )
                      bSuccess = SetEvent ( ghWriteEvent2 ) ;

                   /*
                    * Signal Writer if no Reader in queue
                    *
                    */
                   if ( !cReadQueue )
                      bSuccess = SetEvent ( ghWriteEvent1 ) ;

                   bSuccess = FALSE ;
                   ReleaseSemaphore ( ghSemaphore,     // Let next waiting
                                  1,                   // reader in the queue
                                  NULL ) ;
              }

              break ;

          case WAIT_TIMEOUT:
              DebugMsg ( "ReadDataBase: Error WAIT_TIMEOUT ghSemaphore\n" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;

          case WAIT_ERROR:
              ErrorMsg ( "ReadDataBase: Error WAIT_ERROR ghSemaphore" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;

          default:
              DebugMsg ( "ReadDataBase: Dropped through switch\n" ) ;

              //where to put this?
              cReadQueue-- ;            // Reader leaving queue
              /*
               * Signal Writer if no Reader waiting
               *
               */
              if ( !cReadQueue )
                 bSuccess = SetEvent ( ghWriteEvent1 ) ;

              bSuccess = FALSE ;
              break ;
      }
   } // END IF

   return ( bSuccess ) ;
}

BOOL WINAPI WriteDataBase | ( | PSZ | ,
 |  | PSZ |
 | ) |  |

Definition at line 758 of file DATABASE.C.

{
   BOOL bSuccess ;
   DWORD dwSuccess ;
   UNREFERENCED_PARAMETER ( psz2 ) ;

//   DebugMsg ( "In WriteDataBase\n" ) ;

   cWriteQueue++ ;                             // Writer entering queue
   dwSuccess = SIGNALED ;

                   // should the same event be used twice ???

   if ( cReadQueue )                           // Block if Reader waiting
      dwSuccess = WaitForSingleObject ( ghWriteEvent1, 0xFFFFFFFF ) ;
//      dwSuccess = WaitForSingleObject ( ghWriteEvent1, 5000 ) ;

   if ( dwSuccess != SIGNALED )
   {
      DebugMsg ( "WriteDataBase: Error Waiting for ghWriteEvent1\n" ) ;
      bSuccess = FALSE ;
   }
   else
   {
   /*
    * Only allow 1 writer at a time in the database
    *
    */
      switch ( WaitForSingleObject ( ghMutex, 0xFFFFFFFF ) ) {
//      switch ( WaitForSingleObject ( ghMutex, 3000 ) ) {
         case SIGNALED:
            __try {
               InWrite = TRUE ;
               cWriteQueue-- ;

               /*
                * Signal Reader if any waiting
                *
                */
               if ( cReadQueueEx )
                  bSuccess = SetEvent ( ghReadEvent1 ) ;

                               // Writer leaving queue
               if ( cRead )               // Block if Reader in database
                  dwSuccess = WaitForSingleObject ( ghWriteEvent2, 0xFFFFFFFF ) ;
//                dwSuccess = WaitForSingleObject ( ghWriteEvent2, 1500 ) ;

               if ( dwSuccess == SIGNALED )
               {
                  bSuccess = PutData ( psz1 ) ;
                  InWrite = FALSE ;
                  /*
                   * Signal Reader when no Writer waiting
                   *
                   */
                  bSuccess = SetEvent ( ghReadEvent2 ) ;
                  ReleaseMutex ( ghMutex ) ;    // Let next waiting writer in the queue
               }
               else
               {
                  bSuccess = FALSE ;
                  InWrite = FALSE ;
                  /*
                   * Signal Reader when no Writer waiting
                   *
                   */
                  bSuccess = SetEvent ( ghReadEvent2 ) ;
                  DebugMsg ( "WriteDataBase: Error Waiting on ghWriteEvent2\n" ) ;
               }
            }
            __finally {
               InWrite = FALSE ;
               /*
                * Signal Reader after leaving database
                *
                */
               bSuccess = SetEvent ( ghReadEvent2 ) ;

               /*
                * Signal Reader if no Writer in queue
                *
                */
               if ( !cWriteQueue )
                  bSuccess = SetEvent ( ghReadEvent1 ) ;

               bSuccess = FALSE ;
               ReleaseMutex ( ghMutex ) ;
            }
            break ;

         case WAIT_TIMEOUT:
            DebugMsg ( "WriteDataBase: Error WAIT_TIMEOUT ghMutex\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         case WAIT_ABANDONED:
            DebugMsg ( "WriteDataBase: Error WAIT_ABANDONED ghMutex\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         case WAIT_ERROR:
            ErrorMsg ( "WriteDataBase: Error WAIT_ERROR ghMutex" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;

         default:
            DebugMsg ( "WriteDataBase: Dropped through switch\n" ) ;
            cWriteQueue-- ;
            /*
             * Signal Reader if no Writer waiting
             *
             */
            if ( !cWriteQueue )
               bSuccess = SetEvent ( ghReadEvent1 ) ;

            bSuccess = FALSE ;
            break ;
      }
   } // END IF

   if ( cReadQueue )
       bSuccess = SetEvent ( ghReadEvent1 ) ;          // Signal Reader
   else
       bSuccess = SetEvent ( ghWriteEvent1 ) ;         // Signal Writer

   return ( bSuccess ) ;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/READWRIT.C File Reference

  • READWRIT
Defines | Functions

READWRIT.C File Reference

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "DataBase.h"

Go to the source code of this file.

Defines

#define | MAX 100
#define | NOMINMAX
#define | STRICT

Functions

void | main (void)
VOID | Read (PSZ psz)
VOID | Write (PSZ psz)

Define Documentation

#define MAX 100

Definition at line 43 of file READWRIT.C.

#define NOMINMAX

Definition at line 32 of file READWRIT.C.

#define STRICT

Definition at line 31 of file READWRIT.C.

Function Documentation

void main ( void )

Definition at line 54 of file READWRIT.C.

{
    char psz[20], psztmp[10] ;
    int  i ;
    DWORD idThread ;
    DWORD dwVersion = GetVersion();

  // check if Win32s, if so, display notice and terminate
   if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
        {
          MessageBox( NULL,
             "This application cannot run on Windows 3.1.\n"
             "This application will now terminate.",
             "ReadWrit",
             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
          return;
        }

    printf ( "\nStart of program\n" ) ;

/*
 * Create the reader/writers to stress the database
 *
 */

    for ( i=1; i<=MAX; i++ )
    {
        strcat (strcpy ( psz,"In Thread #" ),itoa( i,psztmp, 10)) ;
        CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE)Write,psz, 0,
                 &idThread ) ;

        CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE)Read, psz, 0,
                 &idThread ) ;

        Sleep( 0 ) ;                        // Relinquish timeslice
        printf ( "psz = %s\n", psz ) ;      // Print result of the test
    }

    printf ( "\nEnd of program\n" ) ;

    exit ( EXIT_SUCCESS ) ;
}

VOID Read ( PSZ psz )

Definition at line 98 of file READWRIT.C.

{
  ReadDataBase ( psz, NULL ) ;
}

VOID Write ( PSZ psz )

Definition at line 103 of file READWRIT.C.

{

  WriteDataBase ( psz, NULL ) ;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REBOOT/REBOOT.C File Reference

  • REBOOT
Defines | Functions

REBOOT.C File Reference

#include <windows.h>
#include <stdio.h>

Go to the source code of this file.

Defines

#define | MYMAIN main
#define | STRICT

Functions

void | DisplayError (LPSTR)
int _cdecl | MYMAIN (int argc, LPTSTR argv[])
BOOL | SetCurrentPrivilege (LPTSTR MachineName, LPCTSTR Privilege, BOOL bEnablePrivilege)

Define Documentation

#define MYMAIN main

Definition at line 25 of file REBOOT.C.

#define STRICT

Definition at line 16 of file REBOOT.C.

Function Documentation

void DisplayError ( LPSTR szAPI )

Definition at line 204 of file REBOOT.C.

{
    LPSTR MessageBuffer;
    DWORD dwBufferLength;

    fprintf(stderr,"%s error!\n", szAPI);

    if(dwBufferLength=FormatMessageA(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM,
                NULL,
                GetLastError(),
                GetUserDefaultLangID(),
                (LPSTR) &MessageBuffer,
                0,
                NULL
                ))
    {
        DWORD dwBytesWritten;

        //
        // Output message string on stderr
        //
        WriteFile(
                GetStdHandle(STD_ERROR_HANDLE),
                MessageBuffer,
                dwBufferLength,
                &dwBytesWritten,
                NULL
                );

        //
        // free the buffer allocated by the system
        //
        LocalFree(MessageBuffer);
    }
}

int _cdecl MYMAIN | ( | int | argc,
 |  | LPTSTR | argv[]
 | ) |  |

Definition at line 51 of file REBOOT.C.

{
    LPTSTR lpPrivilege;
    int iReturnValue;   // return value from main()

    // if Win32s or Windows 95, display notice and terminate
    if(GetVersion() & 0x80000000) {
        MessageBoxA(
            NULL,
            "This application cannot run on Windows 3.1 or Windows 95.\n"
            "This application will now terminate.",
            "REBOOT",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND
            );

        return 1;
    }

    if(argc != 2) {
        printf("Reboot Program, Version 1.1\n");
        printf("Copyright (c) 1992-1996 Microsoft Corp.\n");

        printf("\nSyntax: reboot \\\\MachineName OR . for local machine\n");
        return 1;
    }

    lpPrivilege = SE_SHUTDOWN_NAME;

    //
    // enable the appropriate privilege
    //
    if(!SetCurrentPrivilege(argv[1], lpPrivilege, TRUE)) {
        DisplayError("SetCurrentPrivilege");
        return 2;
    }

    printf("Attempting to shutdown %s\n", argv[1]);

    //
    // attempt to shutdown the target machine
    // since we use a non-zero shutdown timeout, we could abort the shutdown
    // via the Win32 AbortSystemShutdown() API
    //
    if(!InitiateSystemShutdown(
        argv[1], // machine name
        NULL,    // dialog box message
        10,      // shutdown timeout
        TRUE,    // force apps closed
        TRUE     // reboot
        )) {

        DisplayError("InitiateSystemShutdown");
        iReturnValue = 2; // error
    }
    else {
        printf( "InitiateSystemShutdown successful.\n");
        iReturnValue = 0; // success
    }

    //
    // disable the privilege
    //
    SetCurrentPrivilege(argv[1], lpPrivilege, FALSE);

    return iReturnValue;
}

BOOL SetCurrentPrivilege | ( | LPTSTR | MachineName,
 |  | LPCTSTR | Privilege,
 |  | BOOL | bEnablePrivilege
 | ) |  |

Definition at line 125 of file REBOOT.C.

{
    HANDLE hToken;
    TOKEN_PRIVILEGES tp;
    LUID luid;
    TOKEN_PRIVILEGES tpPrevious;
    DWORD cbPrevious=sizeof(TOKEN_PRIVILEGES);
    BOOL bSuccess=FALSE; // assume this function will fail

    //
    // obtain the Luid of the privilege from the target computer
    //
    if(!LookupPrivilegeValue(MachineName, Privilege, &luid)) return FALSE;

    //
    // open our access token, which we read and modify later
    //
    if(!OpenProcessToken(
            GetCurrentProcess(),
            TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
            &hToken
            )) return FALSE;

    //
    // first pass.  get current privilege setting
    //
    tp.PrivilegeCount           = 1;
    tp.Privileges[0].Luid       = luid;
    tp.Privileges[0].Attributes = 0;

    AdjustTokenPrivileges(
            hToken,
            FALSE,
            &tp,
            sizeof(TOKEN_PRIVILEGES),
            &tpPrevious,
            &cbPrevious
            );

    if(GetLastError() == ERROR_SUCCESS) {
        //
        // second pass.  set privilege based on previous setting
        //
        tpPrevious.PrivilegeCount     = 1;
        tpPrevious.Privileges[0].Luid = luid;

        if(bEnablePrivilege)
            tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
        else
            tpPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED &
                tpPrevious.Privileges[0].Attributes);

        AdjustTokenPrivileges(
                hToken,
                FALSE,
                &tpPrevious,
                cbPrevious,
                NULL,
                NULL
                );

        if (GetLastError() == ERROR_SUCCESS) bSuccess=TRUE;
    }

    CloseHandle(hToken);

    return bSuccess;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REGIONS/REGIONS.C File Reference

  • REGIONS
Functions

REGIONS.C File Reference

#include <windows.h>
#include "regions.h"

Go to the source code of this file.

Functions

BOOL CALLBACK | AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
void | MyCombineRgn (int fnCombineMode)
void | MyCreateRgn (WORD rgnStyle)
void | Reset (WORD action)
BOOL CALLBACK | RgnBoxDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
PTRACKRECTSTRUCT | TrackRect (PTRACKRECTSTRUCT ptr, int action, HWND hWnd, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 464 of file REGIONS.C.

{ switch (message)
  {
    case WM_COMMAND:

      if (LOWORD(wParam) == IDOK)
      {
        EndDialog(hwnd, TRUE);
        return (TRUE);
      }
      return (TRUE);
  }
  return (FALSE);
}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 147 of file REGIONS.C.

{
  static RECT             rect;
  static PTRACKRECTSTRUCT ptr;
  static BOOL             bOffsetRgnFlag = FALSE;
  static WORD             lButtonFlag = 0;
         int              i;
         HDC              hdc;

  switch (message)
  {
    case WM_CREATE:

      hMenu   = GetMenu (hWnd);
      currRgn = -1;
      Reset (RESET_ALL);
      break;

    case WM_COMMAND:

      switch (LOWORD(wParam))
      {
        case IDM_ERASE:
          Reset (RESET_ALL);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_OFFSETRGN:

          //
          // Offset rgnArray[currRgn].hrgn either down & right, or up &
          //   left (depending on bOffsetRgnFlag). Toggle bOffsetRgnFlag.
          //

          if (bOffsetRgnFlag)

            OffsetRgn (rgnArray[currRgn].hrgn, 15, 10);

          else

            OffsetRgn (rgnArray[currRgn].hrgn, -15, -10);

          bOffsetRgnFlag = ~bOffsetRgnFlag;
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_INVERTRGN:

          hdc = GetDC (hWnd);
          InvertRgn (hdc, rgnArray[currRgn].hrgn);
          ReleaseDC (hWnd, hdc);
          break;

        case IDM_FRAMERGN:

          hdc = GetDC (hWnd);

          FrameRgn (hdc, rgnArray[currRgn].hrgn,
                    GetStockObject (LTGRAY_BRUSH), 2, 2);
          ReleaseDC (hWnd, hdc);
          break;

        case IDM_PTINRGN:

          //
          // Uncheck "RectInRgn" menu item, toggle "PtInRgn" menu item,
          //   toggle lButtonFlag
          //

          if (lButtonFlag == IDM_RECTINRGN)
            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
                            MF_UNCHECKED | MF_BYCOMMAND);
          if (lButtonFlag == IDM_PTINRGN)
          {
            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
                            MF_UNCHECKED | MF_BYCOMMAND);
            lButtonFlag = 0;
          }
          else
          {
            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
                            MF_CHECKED | MF_BYCOMMAND);
            lButtonFlag = IDM_PTINRGN;
          }
          break;

        case IDM_RECTINRGN:

          //
          // Uncheck "PtInRgn" menu item, toggle "RectInRgn" menu item,
          //   toggle lButtonFlag
          //

          if (lButtonFlag == IDM_PTINRGN)

            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
                            MF_UNCHECKED | MF_BYCOMMAND);

          if (lButtonFlag == IDM_RECTINRGN)
          {
            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
                            MF_UNCHECKED | MF_BYCOMMAND);
            lButtonFlag = 0;
          }
          else
          {
            CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
                            MF_CHECKED | MF_BYCOMMAND);
            lButtonFlag = IDM_RECTINRGN;
          }
          break;

        case IDM_SETRECTRGN:

          //
          // Reset rgnArray[currRgn].hrgn to be the rectangle which
          //   currently bounds it.
          //

          GetRgnBox  (rgnArray[currRgn].hrgn, &rect);
          SetRectRgn (rgnArray[currRgn].hrgn, (int) rect.left,
                      (int) rect.top, (int) rect.right,
                      (int) rect.bottom);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_GETRGNBOX: // put up dlg which call GetRgnBox

          DialogBox (hInst, (LPCTSTR) "RgnBox", hWnd, (DLGPROC)RgnBoxDlgProc);
          break;

        case IDM_ELLIPSE: // create an elliptic region

          MyCreateRgn (ELLIPTIC_RGN);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_POLYPOLYGON: // create a polyPolygon region

          MyCreateRgn (POLYPOLYGON_RGN);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_RECT: // create a rectangular rgn

          MyCreateRgn (RECT_RGN);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_AND:  // combine previous 2 rgns

          MyCombineRgn (RGN_AND);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_COPY: // combine previous 2 rgns

          MyCombineRgn (RGN_COPY);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_DIFF: // combine previous 2 rgns

          MyCombineRgn (RGN_DIFF);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_OR: // combine previous 2 rgns

          MyCombineRgn (RGN_OR);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_XOR: // combine previous 2 rgns

          MyCombineRgn (RGN_XOR);
          InvalidateRect (hWnd, NULL, TRUE);
          break;

        case IDM_ABOUT:  // put up About dialog box

          DialogBox (hInst, (LPCTSTR) "About", hWnd, (DLGPROC)AboutDlgProc);
          break;
      }
      return (0);

    case WM_LBUTTONDOWN:
    {
      //
      // if the "PtInRgn" menu item is checked, then see if the point at
      //   which this event happened is within currRgn, MessageBeep if so.
      //
      // else if the "RectInRgn" menu items are checked, then start
      //   tracking rectangle mode
      //

      if (lButtonFlag == IDM_PTINRGN)
      {
        if (currRgn > -1)

          if (PtInRegion (rgnArray[currRgn].hrgn, (int) LOWORD(lParam),
                          (int) HIWORD(lParam)))
            MessageBeep (0);
      }
      else if (lButtonFlag == IDM_RECTINRGN)

        if ((ptr = TrackRect (NULL, TRECT_NEW, hWnd, lParam)) == NULL)

        //
        // If TrackRect failed to LocalAlloc, then disable the
        //   IDM_RECTINRGN opion.
        //

          EnableMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
                          MF_DISABLED | MF_GRAYED | MF_BYCOMMAND);

      return (0);
    }
    case WM_MOUSEMOVE:

      //
      // if in tracking rectangle mode call TrackRect
      //

      if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd)

        TrackRect (ptr, TRECT_PAINT, hWnd, lParam);

      return (0);

    case WM_LBUTTONUP:

      //
      // if in tracking rectangle mode call TrackRect, check out the final
      //   rectangle, and see if it intersects currRgn
      //

      if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd)
      {
        //
        // call TrackRect with TRECT_PAINT so it updates the rectangle
        //   for the last time, then again with TRECT_DELETE so it frees
        //   up the TRACKRECTSTRUCT it allocated
        //

        TrackRect (ptr, TRECT_PAINT, hWnd, lParam);
        rect = ptr->trackRect;
        TrackRect (ptr, TRECT_DELETE, hWnd, lParam);
        if (RectInRegion (rgnArray[currRgn].hrgn, &rect))

          MessageBeep (0);
      }
      return (0);

    case WM_PAINT:
    {
      PAINTSTRUCT ps;
      COLORREF    crColor;
      HBRUSH      hBrush;

      hdc = BeginPaint (hWnd, &ps);

      //
      // For each rgn we created determine appropriate color & draw it
      //

      for (i = 0; i <= currRgn; i++)
      {
        if (rgnArray[i].hrgn != NULL)
        {
          crColor = 0x000000;
          if (rgnArray[i].type & ELLIPTIC_RGN)    // add some red

            crColor |= 0x0000ff;

          if (rgnArray[i].type & POLYPOLYGON_RGN) // add some green

            crColor |= 0x00ff00;

          if (rgnArray[i].type & RECT_RGN)        // add some blue

            crColor |= 0xff0000;

          hBrush = CreateSolidBrush (crColor);

          //
          // Alternately, the following would work:
          //    SelectObject (hdc, hBrush);
          //    FillRgn (hdc, rgnArray[i].hrgn);
          //

          FillRgn (hdc, rgnArray[i].hrgn, hBrush);
          DeleteObject (hBrush);
        }
      }
      EndPaint (hWnd, &ps);
      return (0);
    }
    case WM_DESTROY:

      PostQuitMessage(0);
      return (0);
  }
  return (DefWindowProc(hWnd, message, wParam, lParam));
}

void MyCombineRgn ( int fnCombineMode )

Definition at line 655 of file REGIONS.C.

{
  if (currRgn >= 1) // only if two or more regions have been created
  {
    CombineRgn (rgnArray[currRgn-1].hrgn, rgnArray[currRgn-1].hrgn,
                rgnArray[currRgn].hrgn, fnCombineMode);

    rgnArray[currRgn-1].type |= rgnArray[currRgn].type;

    //
    // Delete the second of the two regions after combining
    //

    DeleteObject (rgnArray[currRgn--].hrgn);

    if (currRgn == 0)

      Reset (DISABLE_COMBINERGN);
  }
}

void MyCreateRgn ( WORD rgnStyle )

Definition at line 571 of file REGIONS.C.

{
  if (++currRgn == 0)         // if this is 1st region enable options menu

    Reset (ENABLE_OPTIONS);

  else if (currRgn == 1)      // if this is 2nd region enable combine menu

    Reset (ENABLE_COMBINERGN);

  rgnArray[currRgn].type = rgnStyle;

  switch (rgnStyle)
  {
    case ELLIPTIC_RGN:

      //
      //  The following will also work here:
      //     CreateEllipticRgn ((int) ellipseRect.left,
      //                        (int) ellipseRect.top,
      //                        (int) ellipseRect.right,
      //                        (int) ellipseRect.bottom);
      //

      rgnArray[currRgn].hrgn = CreateEllipticRgnIndirect (&ellipseRect);

      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_ELLIPSE,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;

    case POLYPOLYGON_RGN:

      //
      // Alternately, several calls to CreatePolygonRgn could be made.
      //

      rgnArray[currRgn].hrgn = CreatePolyPolygonRgn (polyPolygonPoints,
                                                     polyPolygonCounts,
                                                     POLYPOLYGONCOUNT,
                                                     WINDING);
      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_POLYPOLYGON,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;

    case RECT_RGN:

      //
      // Alternately, a call to CreatePolygonRgn could be made.
      //

      rgnArray[currRgn].hrgn = CreateRectRgn (rectRect.left,
                                              rectRect.top,
                                              rectRect.right,
                                              rectRect.bottom);

      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_RECT,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;
  }
}

void Reset ( WORD action )

Definition at line 697 of file REGIONS.C.

{
  UINT i;

  switch (action)
  {
    case RESET_ALL:
      if (currRgn > 0)

        for (i = 0; i <= (UINT) currRgn; i++)

          DeleteObject (rgnArray[i].hrgn);

      currRgn = -1;
      for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)

        EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      for (i = IDM_ELLIPSE; i <= IDM_RECT; i++)

        EnableMenuItem (GetSubMenu (hMenu, 1), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      break;

   case ENABLE_OPTIONS:

      for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)

        EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      break;

   case ENABLE_COMBINERGN:

      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      break;

   case DISABLE_COMBINERGN:

      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      break;
  }
}

BOOL CALLBACK RgnBoxDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 497 of file REGIONS.C.

{
  switch (message)
  {
    case WM_INITDIALOG:
    {
      RECT rect;
      char buf[15];

      //
      // get the bounding rect of currRgn, fill in the dlg controls
      //   with text string describing the bounding rect.
      //

      if (GetRgnBox (rgnArray[currRgn].hrgn, &rect) == SIMPLEREGION)

        SetDlgItemText (hwnd, 102, "SIMPLEREGION");

      else

        SetDlgItemText (hwnd, 102, "COMPLEXREGION");

      wsprintf (buf, "%ld", rect.left);
      SetDlgItemText (hwnd, 107, buf);
      wsprintf (buf, "%ld", rect.top);
      SetDlgItemText (hwnd, 108, buf);
      wsprintf (buf, "%ld", rect.right);
      SetDlgItemText (hwnd, 109, buf);
      wsprintf (buf, "%ld", rect.bottom);
      SetDlgItemText (hwnd, 110, buf);

      return (TRUE);
    }

    case WM_COMMAND:

      if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
      {
        EndDialog(hwnd, TRUE);
        return (TRUE);
      }
      return (TRUE);
  }
  return (FALSE);
}

PTRACKRECTSTRUCT TrackRect | ( | PTRACKRECTSTRUCT | ptr,
 |  | int | action,
 |  | HWND | hWnd,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 771 of file REGIONS.C.

{
  if ((ptr == NULL) && (action != TRECT_NEW))  return NULL;

  switch (action)
  {
    //
    // TRECT_NEW: Allocate new PTRACKRECTSTRUCT. Fill in initial values
    //            for the fields of the structure. Set up the HDC
    //            correctly.
    //
    // return - pointer to the new object.
    //

    case TRECT_NEW:
    {
      PTRACKRECTSTRUCT ptr;

      if ((ptr = LocalAlloc (LPTR, sizeof (TRACKRECTSTRUCT))) == NULL)
      {
        MessageBox (hWnd, (LPCTSTR) "REGIONS: LocalAlloc() failed", "Err!",
                    MB_OK | MB_ICONEXCLAMATION);
        return NULL;
      }

      //
      // initialize the HDC and other fields.
      //

      ptr->hdc = GetDC(hWnd);
      SetROP2(ptr->hdc, R2_NOT);
      SelectObject (ptr->hdc, GetStockObject (NULL_BRUSH));
      SelectObject (ptr->hdc, CreatePen (PS_SOLID, 2,
                   (COLORREF) 0x01000009));

      //
      // initialize the size
      //

      ptr->trackRect.left = ptr->trackRect.right =
                            (LONG) (ptr->xOrigin = LOWORD (lParam));
      ptr->trackRect.top = ptr->trackRect.bottom =
                            (LONG) (ptr->yOrigin = HIWORD (lParam));

      SetCapture (hWnd);
      GetClientRect (hWnd, &(ptr->clientRect));
      return (ptr);
    }

    //
    // TRECT_DELETE: Free up the memory allocated for the tracking rect.
    //               Also, erase the last rectangle we drew.
    //

    case  TRECT_DELETE:

      Rectangle (ptr->hdc, (int) ptr->trackRect.left,
                           (int) ptr->trackRect.top,
                           (int) ptr->trackRect.right,
                           (int) ptr->trackRect.bottom);
      ReleaseDC (hWnd, ptr->hdc);
      LocalFree (LocalHandle ((LPSTR)ptr));
      ReleaseCapture ();
      return NULL;

    //
    // TRECT_PAINT: Draw the tracking rectangle (involves erasing last
    //              rectangle at old coordinates, and drawing new rect
    //              at new coordinates).
    //

    case TRECT_PAINT:

      //
      // Remove the last rectangle we painted by painting over it again
      //

      Rectangle (ptr->hdc, (int) ptr->trackRect.left,
                           (int) ptr->trackRect.top,
                           (int) ptr->trackRect.right,
                           (int) ptr->trackRect.bottom);

      //
      // We want to restrict our Rectangle() calls to paint within the
      //   client area, so do a bounds check on lParam and reset any
      //   values which fall outside the client area (eg. <1,
      //   >clientRect.left, >clientRect.top).
      //

      if ((SHORT)LOWORD(lParam) < 1)

        lParam &= 0xffff0000;

      else if (LOWORD(lParam) > (WORD) (ptr->clientRect.right- 1))

        lParam = MAKELONG ((WORD) ptr->clientRect.right - 1,
                           HIWORD(lParam));

      if ((SHORT)HIWORD(lParam) < 1)

        lParam &= 0x0000ffff;

      else if (HIWORD(lParam) > (WORD) (ptr->clientRect.bottom - 1))

        lParam = MAKELONG (LOWORD(lParam),
                           (WORD) ptr->clientRect.bottom - 1);

      ptr->trackRect.left   = (LONG) (ptr->xOrigin > LOWORD(lParam)
                               ? LOWORD(lParam) : ptr->xOrigin);
      ptr->trackRect.right  = (LONG) (ptr->xOrigin > LOWORD(lParam)
                               ? ptr->xOrigin : LOWORD(lParam));
      ptr->trackRect.top    = (LONG) (ptr->yOrigin > HIWORD(lParam)
                               ? HIWORD(lParam) : ptr->yOrigin);
      ptr->trackRect.bottom = (LONG) (ptr->yOrigin > HIWORD(lParam)
                               ? ptr->yOrigin : HIWORD(lParam));

      //
      // Redraw the tracking rectangle
      //

      Rectangle (ptr->hdc, (int) ptr->trackRect.left,
                           (int) ptr->trackRect.top,
                           (int) ptr->trackRect.right,
                           (int) ptr->trackRect.bottom);
      return NULL;
  }
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 74 of file REGIONS.C.

{ HWND hwnd;
  MSG  msg;

  if (!hPrevInstance)
  {
    WNDCLASS wc;

    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (DKGRAY_BRUSH);
    wc.lpszMenuName  = (LPCTSTR) "Menu";
    wc.lpszClassName = (LPCTSTR) "Main";

    if (!RegisterClass (&wc))
    {
      MessageBox (NULL, (LPCTSTR) "RegisterClass() failed",
                  (LPCTSTR) "Err! - REGIONS", MB_OK | MB_ICONEXCLAMATION);
      return(FALSE);
    }
  }
  hInst = hInstance;
  if (!(hwnd  = CreateWindow ("Main", "Regions API Sample",
                              WS_OVERLAPPED | WS_CAPTION |
                              WS_SYSMENU | WS_MINIMIZEBOX,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              220, 280, NULL, NULL, hInstance, NULL)))
    return (0);

  ShowWindow   (hwnd, nCmdShow);

  while (GetMessage (&msg, NULL, 0,0))
  {
    TranslateMessage (&msg);
    DispatchMessage  (&msg);
  }

  return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REGIONS/REGIONS.H File Reference

  • REGIONS
Data Structures | Defines | Typedefs | Functions | Variables

REGIONS.H File Reference

Go to the source code of this file.

Data Structures

struct | RGNSTRUCT
struct | TRACKRECTSTRUCT

Defines

#define | DISABLE_COMBINERGN 3
#define | ELLIPTIC_RGN 0X0001
#define | ENABLE_COMBINERGN 2
#define | ENABLE_OPTIONS 1
#define | IDM_ABOUT 109
#define | IDM_AND 301
#define | IDM_COPY 302
#define | IDM_DIFF 303
#define | IDM_ELLIPSE 201
#define | IDM_ERASE 101
#define | IDM_FRAMERGN 104
#define | IDM_GETRGNBOX 108
#define | IDM_INVERTRGN 103
#define | IDM_OFFSETRGN 102
#define | IDM_OR 304
#define | IDM_POLYPOLYGON 202
#define | IDM_PTINRGN 105
#define | IDM_RECT 203
#define | IDM_RECTINRGN 106
#define | IDM_SETRECTRGN 107
#define | IDM_XOR 305
#define | MAXRGNSTRUCTS 3
#define | POLYPOLYGON_RGN 0X0002
#define | POLYPOLYGONCOUNT 3
#define | RECT_RGN 0X0004
#define | RESET_ALL 0
#define | TRECT_DELETE 2
#define | TRECT_NEW 1
#define | TRECT_PAINT 3

Typedefs

typedef struct TRACKRECTSTRUCT * | PTRACKRECTSTRUCT

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | MyCombineRgn (int)
VOID | MyCreateRgn (WORD)
VOID | Reset (WORD)
BOOL CALLBACK | RgnBoxDlgProc (HWND, UINT, WPARAM, LPARAM)
PTRACKRECTSTRUCT | TrackRect (PTRACKRECTSTRUCT, int, HWND, LONG)

Variables

int | currRgn
RECT | ellipseRect = {40, 40, 180, 160}
HANDLE | hInst
HMENU | hMenu
int | polyPolygonCounts [] = {4,3,3}
POINT | polyPolygonPoints []
RECT | rectRect = {20, 100, 120, 200}
RGNSTRUCT | rgnArray [MAXRGNSTRUCTS]

Define Documentation

#define DISABLE_COMBINERGN 3

Definition at line 60 of file REGIONS.H.

#define ELLIPTIC_RGN 0X0001

Definition at line 44 of file REGIONS.H.

#define ENABLE_COMBINERGN 2

Definition at line 59 of file REGIONS.H.

#define ENABLE_OPTIONS 1

Definition at line 58 of file REGIONS.H.

#define IDM_ABOUT 109

Definition at line 32 of file REGIONS.H.

#define IDM_AND 301

Definition at line 38 of file REGIONS.H.

#define IDM_COPY 302

Definition at line 39 of file REGIONS.H.

#define IDM_DIFF 303

Definition at line 40 of file REGIONS.H.

#define IDM_ELLIPSE 201

Definition at line 34 of file REGIONS.H.

#define IDM_ERASE 101

Definition at line 24 of file REGIONS.H.

#define IDM_FRAMERGN 104

Definition at line 27 of file REGIONS.H.

#define IDM_GETRGNBOX 108

Definition at line 31 of file REGIONS.H.

#define IDM_INVERTRGN 103

Definition at line 26 of file REGIONS.H.

#define IDM_OFFSETRGN 102

Definition at line 25 of file REGIONS.H.

#define IDM_OR 304

Definition at line 41 of file REGIONS.H.

#define IDM_POLYPOLYGON 202

Definition at line 35 of file REGIONS.H.

#define IDM_PTINRGN 105

Definition at line 28 of file REGIONS.H.

#define IDM_RECT 203

Definition at line 36 of file REGIONS.H.

#define IDM_RECTINRGN 106

Definition at line 29 of file REGIONS.H.

#define IDM_SETRECTRGN 107

Definition at line 30 of file REGIONS.H.

#define IDM_XOR 305

Definition at line 42 of file REGIONS.H.

#define MAXRGNSTRUCTS 3

Definition at line 48 of file REGIONS.H.

#define POLYPOLYGON_RGN 0X0002

Definition at line 45 of file REGIONS.H.

#define POLYPOLYGONCOUNT 3

Definition at line 50 of file REGIONS.H.

#define RECT_RGN 0X0004

Definition at line 46 of file REGIONS.H.

#define RESET_ALL 0

Definition at line 57 of file REGIONS.H.

#define TRECT_DELETE 2

Definition at line 54 of file REGIONS.H.

#define TRECT_NEW 1

Definition at line 53 of file REGIONS.H.

#define TRECT_PAINT 3

Definition at line 55 of file REGIONS.H.

Typedef Documentation

typedef struct TRACKRECTSTRUCT * PTRACKRECTSTRUCT

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 288 of file APP16.C.

{
   switch( uMsg ) {
      case WM_INITDIALOG:
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;
   }
   return FALSE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID MyCombineRgn ( int )

Definition at line 655 of file REGIONS.C.

{
  if (currRgn >= 1) // only if two or more regions have been created
  {
    CombineRgn (rgnArray[currRgn-1].hrgn, rgnArray[currRgn-1].hrgn,
                rgnArray[currRgn].hrgn, fnCombineMode);

    rgnArray[currRgn-1].type |= rgnArray[currRgn].type;

    //
    // Delete the second of the two regions after combining
    //

    DeleteObject (rgnArray[currRgn--].hrgn);

    if (currRgn == 0)

      Reset (DISABLE_COMBINERGN);
  }
}

VOID MyCreateRgn ( WORD )

Definition at line 571 of file REGIONS.C.

{
  if (++currRgn == 0)         // if this is 1st region enable options menu

    Reset (ENABLE_OPTIONS);

  else if (currRgn == 1)      // if this is 2nd region enable combine menu

    Reset (ENABLE_COMBINERGN);

  rgnArray[currRgn].type = rgnStyle;

  switch (rgnStyle)
  {
    case ELLIPTIC_RGN:

      //
      //  The following will also work here:
      //     CreateEllipticRgn ((int) ellipseRect.left,
      //                        (int) ellipseRect.top,
      //                        (int) ellipseRect.right,
      //                        (int) ellipseRect.bottom);
      //

      rgnArray[currRgn].hrgn = CreateEllipticRgnIndirect (&ellipseRect);

      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_ELLIPSE,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;

    case POLYPOLYGON_RGN:

      //
      // Alternately, several calls to CreatePolygonRgn could be made.
      //

      rgnArray[currRgn].hrgn = CreatePolyPolygonRgn (polyPolygonPoints,
                                                     polyPolygonCounts,
                                                     POLYPOLYGONCOUNT,
                                                     WINDING);
      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_POLYPOLYGON,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;

    case RECT_RGN:

      //
      // Alternately, a call to CreatePolygonRgn could be made.
      //

      rgnArray[currRgn].hrgn = CreateRectRgn (rectRect.left,
                                              rectRect.top,
                                              rectRect.right,
                                              rectRect.bottom);

      EnableMenuItem (GetSubMenu (hMenu, 1), IDM_RECT,
                      MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
      break;
  }
}

VOID Reset ( WORD )

Definition at line 697 of file REGIONS.C.

{
  UINT i;

  switch (action)
  {
    case RESET_ALL:
      if (currRgn > 0)

        for (i = 0; i <= (UINT) currRgn; i++)

          DeleteObject (rgnArray[i].hrgn);

      currRgn = -1;
      for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)

        EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      for (i = IDM_ELLIPSE; i <= IDM_RECT; i++)

        EnableMenuItem (GetSubMenu (hMenu, 1), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      break;

   case ENABLE_OPTIONS:

      for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)

        EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      break;

   case ENABLE_COMBINERGN:

      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_ENABLED |
                                                  MF_BYCOMMAND);
      break;

   case DISABLE_COMBINERGN:

      for (i = IDM_AND; i <= IDM_XOR; i++)

        EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
                                                  | MF_BYCOMMAND);
      break;
  }
}

BOOL CALLBACK RgnBoxDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 497 of file REGIONS.C.

{
  switch (message)
  {
    case WM_INITDIALOG:
    {
      RECT rect;
      char buf[15];

      //
      // get the bounding rect of currRgn, fill in the dlg controls
      //   with text string describing the bounding rect.
      //

      if (GetRgnBox (rgnArray[currRgn].hrgn, &rect) == SIMPLEREGION)

        SetDlgItemText (hwnd, 102, "SIMPLEREGION");

      else

        SetDlgItemText (hwnd, 102, "COMPLEXREGION");

      wsprintf (buf, "%ld", rect.left);
      SetDlgItemText (hwnd, 107, buf);
      wsprintf (buf, "%ld", rect.top);
      SetDlgItemText (hwnd, 108, buf);
      wsprintf (buf, "%ld", rect.right);
      SetDlgItemText (hwnd, 109, buf);
      wsprintf (buf, "%ld", rect.bottom);
      SetDlgItemText (hwnd, 110, buf);

      return (TRUE);
    }

    case WM_COMMAND:

      if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
      {
        EndDialog(hwnd, TRUE);
        return (TRUE);
      }
      return (TRUE);
  }
  return (FALSE);
}

PTRACKRECTSTRUCT TrackRect | ( | PTRACKRECTSTRUCT | ,
 |  | int | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |

Variable Documentation

int currRgn

Definition at line 90 of file REGIONS.H.

RECT ellipseRect = {40, 40, 180, 160}

Definition at line 93 of file REGIONS.H.

HANDLE hInst

Definition at line 88 of file REGIONS.H.

HMENU hMenu

Definition at line 91 of file REGIONS.H.

int polyPolygonCounts[] = {4,3,3}

Definition at line 99 of file REGIONS.H.

POINT polyPolygonPoints[]
Initial value:
 {{120, 20}, {200, 20}, {200, 80},
                                                       { 80,140},
                                 { 20, 20}, { 80, 20}, { 20, 80},
                                 {200,120}, {200,200}, {160,200}}

Definition at line 94 of file REGIONS.H.

RECT rectRect = {20, 100, 120, 200}

Definition at line 100 of file REGIONS.H.

RGNSTRUCT rgnArray[MAXRGNSTRUCTS]

Definition at line 89 of file REGIONS.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/MAIN.C File Reference

  • RESDLL
Functions

MAIN.C File Reference

#include <windows.h>
#include "Main.h"
#include "the_dll.h"

Go to the source code of this file.

Functions

void | DrawBitmap (HDC hdc, HBITMAP hbm, int xStart, int yStart)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

void DrawBitmap | ( | HDC | hdc,
 |  | HBITMAP | hbm,
 |  | int | xStart,
 |  | int | yStart
 | ) |  |

Definition at line 171 of file MAIN.C.

{
  BITMAP bm;
  HDC    hdcMem;

  hdcMem = CreateCompatibleDC (hdc);
  SelectObject (hdcMem, hbm);
  SetMapMode (hdcMem, GetMapMode(hdc));

  GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm);
  BitBlt (hdc, xStart, yStart, bm.bmWidth, bm.bmHeight,
          hdcMem, 0, 0, SRCCOPY);

  DeleteDC(hdcMem);
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 106 of file MAIN.C.

{
  static HBITMAP hbm;

  switch (message)
  {
    case WM_CREATE:

      hbm = LoadBitmap (ghLib, TEXT( "dllbitmap"));
      break;

    case WM_PAINT:
    {
      RECT        rect;
      PAINTSTRUCT ps;

      GetClientRect (hwnd, &rect);
      BeginPaint (hwnd, &ps);

      //
      // draw the dllbitmap centered in middle of our client rect
      //

      DrawBitmap (ps.hdc, hbm,
                  rect.right/2 - DLLBITMAP_WIDTH/2,
                  rect.bottom/2 - DLLBITMAP_HEIGHT/2);
      EndPaint (hwnd, &ps);
      return 0;
    }

    case WM_DESTROY:

      DeleteObject ((HANDLE) hbm);
      PostQuitMessage (0);
      break;

    default:

      return (DefWindowProc(hwnd, message, wParam, lParam));
  }
  return (0);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 39 of file MAIN.C.

{
  HWND hwnd;
  MSG msg;

  if ((ghLib = LoadLibrary (TEXT("the_dll.dll"))) == NULL)
  {
    MessageBox (NULL, TEXT( "WinMain(): LoadLibrary() failed"),
                TEXT( "Err! - RESDLL"), MB_OK | MB_ICONEXCLAMATION);
    return 0;
  }

  if (!hPrevInstance)
  {
    WNDCLASS wc;

    wc.style         = CS_HREDRAW | CS_VREDRAW;;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon (ghLib, TEXT("dllicon"));
    wc.hCursor       = LoadCursor (ghLib, TEXT("dllcursor"));
    wc.hbrBackground = GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = TEXT( "RESDLL");

    if (!RegisterClass (&wc))
    {
      MessageBox (NULL, TEXT( "WinMain(): RegisterClass() failed"),
                  TEXT( "Err! - MAIN"), MB_OK | MB_ICONEXCLAMATION);
      return(FALSE);
    }
  }

  if (!(hwnd = CreateWindow (TEXT("RESDLL"), TEXT("RESDLL Sample Application"),
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             NULL, NULL, hInstance, NULL)))
    return (0);

  ShowWindow (hwnd, nCmdShow);

  while (GetMessage (&msg, NULL, 0,0))
  {
    TranslateMessage (&msg);
    DispatchMessage  (&msg);
  }
  FreeLibrary (ghLib);
  return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/MAIN.H File Reference

  • RESDLL
Functions | Variables

MAIN.H File Reference

Go to the source code of this file.

Functions

void | DrawBitmap (HDC, HBITMAP, int, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)

Variables

HANDLE | ghLib

Function Documentation

void DrawBitmap | ( | HDC | ,
 |  | HBITMAP | ,
 |  | int | ,
 |  | int |
 | ) |  |

Definition at line 171 of file MAIN.C.

{
  BITMAP bm;
  HDC    hdcMem;

  hdcMem = CreateCompatibleDC (hdc);
  SelectObject (hdcMem, hbm);
  SetMapMode (hdcMem, GetMapMode(hdc));

  GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm);
  BitBlt (hdc, xStart, yStart, bm.bmWidth, bm.bmHeight,
          hdcMem, 0, 0, SRCCOPY);

  DeleteDC(hdcMem);
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

Variable Documentation

HANDLE ghLib

Definition at line 13 of file MAIN.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/THE_DLL.H File Reference

  • RESDLL
Defines

THE_DLL.H File Reference

Go to the source code of this file.

Defines

#define | DLLBITMAP_HEIGHT 64
#define | DLLBITMAP_WIDTH 128

Define Documentation

#define DLLBITMAP_HEIGHT 64

Definition at line 14 of file THE_DLL.H.

#define DLLBITMAP_WIDTH 128

Definition at line 13 of file THE_DLL.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SCRNSAVE/FRACTAL.C File Reference

  • SCRNSAVE
Functions

FRACTAL.C File Reference

#include <windows.h>
#include <scrnsave.h>
#include <stdio.h>
#include <math.h>
#include <commdlg.h>
#include "fractal.h"

Go to the source code of this file.

Functions

BOOL | bColorCycle (HDC, PINFO)
BOOL | bGetPPStr (char szXFr[MAXDOUBLELEN], char szYFr[MAXDOUBLELEN], char szX2[MAXDOUBLELEN], char szY2[MAXDOUBLELEN], char szSavef[MAXFILELEN], char szIter[MAXDOUBLELEN])
BOOL | bGetPPStr (char szXFr[MAXDOUBLELEN], char szYFr[MAXDOUBLELEN], char szX2[MAXDOUBLELEN], char szY2[MAXDOUBLELEN], char szSavef[MAXPATHLEN], char szIter[MAXDOUBLELEN])
BOOL | bInitDlgItems (HWND)
BOOL | bInitInfo (PINFO)
void | ErrorOut (char errstring[30])
INT | iCreatePenFrPal (HDC, PVOID *, INT, HPALETTE *)
BOOL WINAPI | RegisterDialogClasses (HANDLE)
BOOL | SaveBitmapFile (HDC, HBITMAP, PSTR)
BOOL APIENTRY | ScreenSaverConfigureDialog (HWND, UINT, WPARAM, LPARAM)
LONG APIENTRY | ScreenSaverProc (HWND, UINT, WPARAM, LPARAM)
BOOL | StartMandelbrot (PINFO)
void | vLoadStrings (VOID)

Function Documentation

BOOL bColorCycle | ( | HDC | hDC,
 |  | PINFO | pInfo
 | ) |  |

Definition at line 993 of file FRACTAL.C.

{
    INT             iEntry, i, iNumClr;
    PLOGPALETTE     plogPat;
    ULONG           ulSize;
    BOOL            bSuccess;
    HPALETTE        hPal, hPalOld;
    PALETTEENTRY    peTemp;
    BOOL            bQuit;

UINT uRC;

    bSuccess = TRUE;
    iEntry = 1<<GetDeviceCaps(hDC, BITSPIXEL);
    iNumClr = 236;          // 256 minus 20 reserved colors
    ulSize = sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*256;

    if ((plogPat = (PLOGPALETTE) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, ulSize)) == NULL) {
        MessageBox(hMainWindow, "Failed in Memory Allocation for plogPat!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit1;
    }

    plogPat->palVersion = 0x300;
    plogPat->palNumEntries = (WORD) 256;
    {
    int     iFirst, iSecond, iInc;

        iFirst = iNumClr/3;
        iSecond = iFirst * 2;
        iInc = (iNumClr <= 256) ? 3 : 1;

        for (i = 0; i < iNumClr; i++) {
            if (i < iFirst) {
                plogPat->palPalEntry[i+10].peBlue   = 255-(i+1)*iInc;
                plogPat->palPalEntry[i+10].peGreen  = 0;
                plogPat->palPalEntry[i+10].peRed    = (i+1)*iInc;
                plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
                continue;
            }
            if (i < iSecond) {
                plogPat->palPalEntry[i+10].peBlue   = 0;
                plogPat->palPalEntry[i+10].peGreen  = (i+1-iFirst)*iInc;
                plogPat->palPalEntry[i+10].peRed    = 255-(i+1-iFirst)*iInc;
                plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
                continue;
            }
            plogPat->palPalEntry[i+10].peBlue   = (i+1-iSecond)*iInc;
            plogPat->palPalEntry[i+10].peGreen  = 255-(i+1-iSecond)*iInc;
            plogPat->palPalEntry[i+10].peRed    = 0;
            plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
        }
    }

    if ((hPal = CreatePalette(plogPat)) == (HPALETTE) NULL) {
        MessageBox(hMainWindow, "Failed in creating palette!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit2;
    }

    hPalOld = SelectPalette(hDC, hPal, FALSE);
    RealizePalette(hDC);
    //SelectPalette(hDC, hPalOld, FALSE);

    bQuit = FALSE;
    while (TRUE && !bQuit) {
        if (!pInfo->bClrCycle) {
            //sprintf( gtext,"NOT to animate palette\n");
            //OutputDebugString( gtext );
            bQuit = TRUE;
        }

        if (!bQuit) {
            //sprintf( gtext,"About to animate palette\n");
            //OutputDebugString( gtext );

            peTemp = plogPat->palPalEntry[10];
            for (i = 0; i < iNumClr; i++) {
                plogPat->palPalEntry[i+10] = plogPat->palPalEntry[i+10+1];
            }
            plogPat->palPalEntry[i+10] = peTemp;

            Sleep(25);

            if (!AnimatePalette(hPal, 0, 256, plogPat->palPalEntry)) {
                sprintf( gtext,"Anmiate palette failed\n");
                OutputDebugString( gtext );
            }

            if ((uRC = RealizePalette(hDC)) == -1) {
                sprintf( gtext,"Realize palette failed\n");
                OutputDebugString( gtext );
            }

            if (!UpdateColors(hDC)) {
                sprintf( gtext,"Update Colors failed\n");
                OutputDebugString( gtext );
            }

        }

    }

    SelectPalette(hDC, hPalOld, 0);
    DeleteObject(hPal);
ErrExit2:
    GlobalFree(plogPat);
ErrExit1:
    return bSuccess;

}

BOOL bGetPPStr | ( | char | szXFr[MAXDOUBLELEN],
 |  | char | szYFr[MAXDOUBLELEN],
 |  | char | szX2[MAXDOUBLELEN],
 |  | char | szY2[MAXDOUBLELEN],
 |  | char | szSavef[MAXFILELEN],
 |  | char | szIter[MAXDOUBLELEN]
 | ) |  |
BOOL bGetPPStr | ( | char | szXFr[MAXDOUBLELEN],
 |  | char | szYFr[MAXDOUBLELEN],
 |  | char | szX2[MAXDOUBLELEN],
 |  | char | szY2[MAXDOUBLELEN],
 |  | char | szSavef[MAXPATHLEN],
 |  | char | szIter[MAXDOUBLELEN]
 | ) |  |

Definition at line 948 of file FRACTAL.C.

{
    char    szDefXFr[MAXDOUBLELEN];
    char    szDefYFr[MAXDOUBLELEN];
    char    szDefX2[MAXDOUBLELEN];
    char    szDefY2[MAXDOUBLELEN];
    char    szDefSavef[MAXPATHLEN];
    char    szDefIter[MAXDOUBLELEN];

    sprintf(szDefXFr, "-2.00");
    sprintf(szDefYFr, "1.00");
    sprintf(szDefX2,  "1.00");
    sprintf(szDefY2,  "-1.00");
    sprintf(szDefSavef, "c:\\fractal.bmp");
    sprintf(szDefIter, "500");
    GetPrivateProfileString(szAppName, szXFrom, szDefXFr, szXFr, MAXDOUBLELEN, szIniFile);
    GetPrivateProfileString(szAppName, szYFrom, szDefYFr, szYFr, MAXDOUBLELEN, szIniFile);
    GetPrivateProfileString(szAppName, szXTo, szDefX2, szX2, MAXDOUBLELEN, szIniFile);
    GetPrivateProfileString(szAppName, szYTo, szDefY2, szY2, MAXDOUBLELEN, szIniFile);
    GetPrivateProfileString(szAppName, szSaveFile, szDefSavef, szSavef, MAXPATHLEN, szIniFile);
    GetPrivateProfileString(szAppName, szIteration, szDefIter, szIter, MAXDOUBLELEN, szIniFile);
    return TRUE;
}

BOOL bInitDlgItems ( HWND hDlg )

Definition at line 918 of file FRACTAL.C.

{
    char    szXFr[MAXDOUBLELEN], szYFr[MAXDOUBLELEN], szX2[MAXDOUBLELEN],
            szY2[MAXDOUBLELEN], szSavef[MAXPATHLEN], szIter[MAXDOUBLELEN];
    BOOL    bSuccess;

    bSuccess = bGetPPStr(szXFr, szYFr, szX2, szY2, szSavef, szIter);
    SetDlgItemText(hDlg, ID_XFROM, szXFr);
    SetDlgItemText(hDlg, ID_YFROM, szYFr);
    SetDlgItemText(hDlg, ID_XTO, szX2);
    SetDlgItemText(hDlg, ID_YTO, szY2);
    SetDlgItemText(hDlg, ID_ITERATION, szIter);

    return bSuccess;
}

BOOL bInitInfo ( PINFO pInfo )

Definition at line 651 of file FRACTAL.C.

{
    char    szXFr[MAXDOUBLELEN], szYFr[MAXDOUBLELEN], szX2[MAXDOUBLELEN],
            szY2[MAXDOUBLELEN], szSavef[MAXPATHLEN], szIter[MAXDOUBLELEN];

    bGetPPStr(szXFr, szYFr, szX2, szY2, szSavef, szIter);
    pInfo->xFrom        = atof(szXFr);
    pInfo->xTo          = atof(szX2);
    pInfo->yFrom        = atof(szYFr);
    pInfo->yTo          = atof(szY2);
    pInfo->lxFrom       = -4096;                // 20.11 fix point
    pInfo->lxTo         = 4096;                 // representation of
    pInfo->lyFrom       = 4096;                 // -2, 2, 2, and -2
    pInfo->lyTo         = -4096;                //
    pInfo->iIteration   = (INT) atof(szIter);
    pInfo->iStep        = gStep;
    pInfo->bStretch     = gbStretch;
    pInfo->iStretchMode = giStretchMode;
    pInfo->hwnd         = NULL;
    pInfo->hThrd        = NULL;
    pInfo->bDrawing     = FALSE;
    pInfo->dwThreadId   = 0;
    pInfo->dwElapsed    = 0L;
    pInfo->c1           = 0.0;
    pInfo->c2           = 0.0;
    pInfo->lc1          = 0L;
    pInfo->lc2          = 0L;
    pInfo->hBmpSaved    = NULL;
    pInfo->bMandel      = TRUE;
    pInfo->bSetDIBsToDevice = FALSE;
    pInfo->hPal         = NULL;
    pInfo->prghPen      = NULL;
    pInfo->iPen         = 0;
    pInfo->bClrCycle    = FALSE;
    wsprintf((LPSTR) &(pInfo->szSavef), szSavef);
    return TRUE;
}

void ErrorOut ( char errstring[30] )

Definition at line 908 of file FRACTAL.C.

{
DWORD Error;
CHAR  str[80];

Error= GetLastError();
wsprintf((LPSTR) str, "Error on %s = %d\n", errstring, Error);
MessageBox(GetFocus(), (LPSTR)str, "Error", MB_OK);
}

INT iCreatePenFrPal | ( | HDC | hDC,
 |  | PVOID * | prghPen,
 |  | INT | iWidth,
 |  | HPALETTE * | phPal
 | ) |  |

Definition at line 451 of file FRACTAL.C.

{
    INT             iNumClr, iResult, i, iEntry;
    PLOGPALETTE     plogPat;
    ULONG           ulSize;

    iResult = 0;

    if (!((GetDeviceCaps(hDC, RASTERCAPS)) & RC_PALETTE)) {

        if (iNumClr = GetSystemPaletteEntries(hDC, 0, 0, NULL)) {
            if (prghPen == NULL) {
                return (iNumClr);
            }

            if (iWidth < 0) {
                MessageBox(GetFocus(), "Invalid pen width!", "Error", MB_OK);
                return 0L;
            }

            for (i = 0; i < iNumClr; i++) {
                prghPen[i] =
                     (PVOID) CreatePen(PS_SOLID, iWidth, PALETTEINDEX(i));
                iResult = i;
#if 0
                SelectObject(hDC, (HPEN)prghPen[i]);
                MoveToEx(hDC, i*iWidth, 0, NULL);
                LineTo(hDC, i*iWidth, 300);
#endif
            }
            return iResult;
        }

        // GetPaletteEntries returns 0
        iNumClr = 1 << GetDeviceCaps(hDC, BITSPIXEL);

        if (iNumClr <= 16) {
            sprintf( gtext,"Assertion failed: iCreatePenFrPal() \n");
            OutputDebugString( gtext);
            sprintf( gtext,"iNumClr <= 16! iNumClr = %d\n", iNumClr);
            OutputDebugString( gtext);
            return (iNumClr);
        }

        // Assuming at least 16 bit device
        //
        iNumClr = 768;      // COLORREF format: 0x00bbggrr r,g,b=[0,255]

        if (prghPen == NULL) {
            return (iNumClr);
        }

        if (iWidth < 0) {
            MessageBox(GetFocus(), "Invalid pen width!", "Error", MB_OK);
            return 0L;
        }

        for (i = 0; i < iNumClr; i++) {
            if (i < 256) {
                prghPen[i] =
                    (PVOID) CreatePen(PS_SOLID, iWidth, RGB(i,0,255-i));
                iResult = i;
#if 0
                SelectObject(hDC, (HPEN)prghPen[i]);
                MoveToEx(hDC, i*iWidth, 0, NULL);
                LineTo(hDC, i*iWidth, 300);
#endif
                continue;
            }

            if (i < 512) {
                prghPen[i] =
                    (PVOID) CreatePen(PS_SOLID, iWidth, RGB(511-i,i-256,0));
                iResult = i;
#if 0
                SelectObject(hDC, (HPEN)prghPen[i]);
                MoveToEx(hDC, i*iWidth, 0, NULL);
                LineTo(hDC, i*iWidth, 300);
#endif
                continue;
            }

            prghPen[i] =
                (PVOID) CreatePen(PS_SOLID, iWidth, RGB(0,767-i,i-512));
            iResult = i;
#if 0
            SelectObject(hDC, (HPEN)prghPen[i]);
            MoveToEx(hDC, i*iWidth, 0, NULL);
            LineTo(hDC, i*iWidth, 300);
#endif
        }

        return iResult;
    }

    //
    // Palette managed device
    //
    iEntry = iNumClr = 1 << GetDeviceCaps(hDC, BITSPIXEL);

    if (iNumClr > 256) {
        sprintf( gtext,"Assertion failed: iCreatePenFrPal() \n");
        OutputDebugString( gtext);
        sprintf( gtext,"iNumClr > 256! iNumClr = %d\n", iNumClr);
        OutputDebugString( gtext);
        iEntry=iNumClr = 256;
    }

    ulSize = sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*iNumClr;

    iNumClr -= GetDeviceCaps(hDC, NUMRESERVED);

    if (prghPen == NULL)
        return iNumClr;

    if ((plogPat = (PLOGPALETTE) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, ulSize)) == NULL) {
        MessageBox(GetFocus(), "Failed in Memory Allocation for plogPat!", "Error", MB_OK);
        goto ErrExit1;
    }

    plogPat->palVersion = 0x300;
    plogPat->palNumEntries = (WORD) iEntry;

    {
    int     iFirst, iSecond, iInc;

        iFirst = iNumClr/3;
        iSecond = iFirst * 2;
        iInc = (iNumClr <= 256) ? 3 : 1;

        for (i = 0; i < iNumClr; i++) {
            if (i < iFirst) {
                plogPat->palPalEntry[i+10].peBlue   = 255-(i+1)*iInc;
                plogPat->palPalEntry[i+10].peGreen  = 0;
                plogPat->palPalEntry[i+10].peRed    = (i+1)*iInc;
                plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
                continue;
            }
            if (i < iSecond) {
                plogPat->palPalEntry[i+10].peBlue   = 0;
                plogPat->palPalEntry[i+10].peGreen  = (i+1-iFirst)*iInc;
                plogPat->palPalEntry[i+10].peRed    = 255-(i+1-iFirst)*iInc;
                plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
                continue;
            }
            plogPat->palPalEntry[i+10].peBlue   = (i+1-iSecond)*iInc;
            plogPat->palPalEntry[i+10].peGreen  = 255-(i+1-iSecond)*iInc;
            plogPat->palPalEntry[i+10].peRed    = 0;
            plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
        }
    }

    DeleteObject(*phPal);

    if ((*phPal = CreatePalette(plogPat)) == (HPALETTE) NULL) {
        MessageBox(GetFocus(), "Failed in creating palette!", "Error", MB_OK);
        goto ErrExit2;
    }
    if (*phPal) {
       SelectPalette(hDC, *phPal, FALSE);
       RealizePalette(hDC);
    }

    for (i = 0; i < iNumClr; i++) {
        HPEN    hPen;

        hPen = CreatePen(PS_SOLID, iWidth, PALETTEINDEX(i+10));
        prghPen[i] = (PVOID) hPen;
        iResult = i;
#if 0
        SelectObject(hDC, hPen);
        MoveToEx(hDC, i*iWidth, 0, NULL);
        LineTo(hDC, i*iWidth, 300);
#endif
    }

ErrExit2:
    GlobalFree(plogPat);
ErrExit1:
    return iResult;

}

BOOL WINAPI RegisterDialogClasses ( HANDLE hInst )

Definition at line 215 of file FRACTAL.C.

{
    return TRUE;
}

BOOL SaveBitmapFile | ( | HDC | hDC,
 |  | HBITMAP | hBmp,
 |  | PSTR | pszFileName
 | ) |  |

Definition at line 737 of file FRACTAL.C.

{
    int         hFile;
    OFSTRUCT    ofReOpenBuff;
    HBITMAP     hTmpBmp, hBmpOld;
    BOOL        bSuccess;
    BITMAPFILEHEADER    bfh;
    PBITMAPINFO pbmi;
    PBYTE       pBits;
    BITMAPINFO  bmi;
    PBYTE pjTmp, pjTmpBmi;
    ULONG sizBMI;

    bSuccess = TRUE;
    if (!hBmp) {
        MessageBox(GetFocus(), "There's no Bitmap to save!", "Error", MB_OK);
        return FALSE;
    }

    //
    // Let the graphics engine to retrieve the dimension of the bitmap for us
    // GetDIBits uses the size to determine if it's BITMAPCOREINFO or BITMAPINFO
    // if BitCount != 0, color table will be retrieved
    //
    bmi.bmiHeader.biSize = 0x28;              // GDI need this to work
    bmi.bmiHeader.biBitCount = 0;             // don't get the color table
    if ((GetDIBits(hDC, hBmp, 0, 0, (LPSTR)NULL, &bmi, DIB_RGB_COLORS)) == 0) {
        MessageBox(GetFocus(), "GetDIBits failed!", "Error", MB_OK);
        return FALSE;
    }

    //
    // Now that we know the size of the image, alloc enough memory to retrieve
    // the actual bits
    //
    if ((pBits = (PBYTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
                bmi.bmiHeader.biSizeImage)) == NULL) {
        MessageBox(GetFocus(), "Failed in Memory Allocation for pBits!", "Error", MB_OK);
        return FALSE;
    }

    //
    // Note: 24 bits per pixel has no color table.  So, we don't have to
    // allocate memory for retrieving that.  Otherwise, we do.
    //
    pbmi = &bmi;                                      // assume no color table
    if (bmi.bmiHeader.biBitCount != 24) {             // has color table
        sizBMI = sizeof(BITMAPINFO)+sizeof(RGBQUAD)*(1<<bmi.bmiHeader.biBitCount);
        //
        // I need more memory for the color table
        //
        if ((pbmi = (PBITMAPINFO)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizBMI )) == NULL) {
            MessageBox(GetFocus(), "Failed in Memory Allocation for pbmi!", "Error", MB_OK);
            bSuccess = FALSE;
            goto ErrExit1;
        }
        //
        // Now that we've a bigger chunk of memory, let's copy the Bitmap
        // info header data over
        //
        pjTmp = (PBYTE)pbmi;
        pjTmpBmi = (PBYTE)&bmi;
        sizBMI = sizeof(BITMAPINFOHEADER);

        while(sizBMI--)
        {
            *(((PBYTE)pjTmp)++) = *((pjTmpBmi)++);
        }

    }

    //
    // Let's open the file and get ready for writing
    //
    if ((hFile = OpenFile(pszFileName, (LPOFSTRUCT)&ofReOpenBuff,
                 OF_CREATE | OF_WRITE)) == -1) {
        MessageBox(GetFocus(), "Failed in OpenFile!", "Error", MB_OK);
        ErrorOut("OpenFile");
        goto ErrExit2;
    }

    //
    // But first, fill in the info for the BitmapFileHeader
    //
    bfh.bfType = 0x4D42;                            // 'BM'
    bfh.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*
        ((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1<<pbmi->bmiHeader.biBitCount))+
        pbmi->bmiHeader.biSizeImage;
    bfh.bfReserved1 =
    bfh.bfReserved2 = 0;
    bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+
        sizeof(RGBQUAD)*((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1<<pbmi->bmiHeader.biBitCount));

    //
    // Write out the file header now
    //
    if (_lwrite(hFile, (LPSTR)&bfh, sizeof(BITMAPFILEHEADER)) == -1) {
        MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit3;
    }

    //
    // Bitmap can't be selected into a DC when calling GetDIBits
    // Assume that the hDC is the DC where the bitmap would have been selected
    // if indeed it has been selected
    //
    if (hTmpBmp = CreateCompatibleBitmap(hDC, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight)) {
        hBmpOld = SelectObject(hDC, hTmpBmp);
        if ((GetDIBits(hDC, hBmp, 0, pbmi->bmiHeader.biHeight, (LPSTR)pBits, pbmi, DIB_RGB_COLORS))==0){
            MessageBox(GetFocus(), "Failed in GetDIBits!", "Error", MB_OK);
            bSuccess = FALSE;
            goto ErrExit4;
        }
    } else {
        MessageBox(GetFocus(), "Failed in creating bitmap!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit3;
    }

    //
    // Now write out the BitmapInfoHeader and color table, if any
    //
    if (_lwrite(hFile, (LPSTR)pbmi, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) *
        ((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1 << pbmi->bmiHeader.biBitCount))) == -1) {
        MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit4;
    }

    //
    // write the bits also
    //
    if (_lwrite(hFile, (LPSTR)pBits, pbmi->bmiHeader.biSizeImage) == -1) {
        MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
        bSuccess = FALSE;
        goto ErrExit4;
    }

ErrExit4:
    SelectObject(hDC, hBmpOld);
    DeleteObject(hTmpBmp);
ErrExit3:
    _lclose(hFile);
ErrExit2:
    GlobalFree(pbmi);
ErrExit1:
    GlobalFree(pBits);
    return bSuccess;
}

BOOL APIENTRY ScreenSaverConfigureDialog | ( | HWND | hDlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 117 of file FRACTAL.C.

{
    switch(message)
    {
        case WM_INITDIALOG: {
            vLoadStrings();
            bInitDlgItems(hDlg);
            return TRUE;
        }
        case WM_COMMAND:

            switch(LOWORD(wParam))
            {
                static char         szFile[MAXPATHLEN];
                static BOOL         bSave2DiffFile = FALSE;

                case ID_SAVEAS: {
                    OPENFILENAME ofn;
                    char         szDirName[MAXPATHLEN];
                    char         szFileTitle[256];
                    static char  *szFilter;

                    szFilter = "DIB files (*.bmp)\0\0";

                    GetSystemDirectory((LPSTR) szDirName, MAXPATHLEN);
                    strcpy(szFile, "*.bmp\0");
                    ofn.lStructSize = sizeof(OPENFILENAME);
                    ofn.hwndOwner = hDlg;
                    ofn.lpstrFilter = szFilter;
                    ofn.lpstrCustomFilter = (LPSTR) NULL;
                    ofn.nMaxCustFilter = 0L;
                    ofn.nFilterIndex = 0L;
                    ofn.lpstrFile = szFile;
                    ofn.nMaxFile = sizeof(szFile);
                    ofn.lpstrFileTitle = szFileTitle;
                    ofn.nMaxFileTitle = sizeof(szFileTitle);
                    ofn.lpstrInitialDir = szDirName;
                    ofn.lpstrTitle = "Save Bitmap As";
                    ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
                    ofn.nFileOffset = 0;
                    ofn.nFileExtension = 0;
                    ofn.lpstrDefExt = (LPSTR)NULL;

                    if (GetSaveFileName(&ofn))
                        bSave2DiffFile = TRUE;

                    break;
                }
                case IDOK: {
                    char    szXFr[MAXDOUBLELEN];
                    char    szYFr[MAXDOUBLELEN];
                    char    szX2[MAXDOUBLELEN];
                    char    szY2[MAXDOUBLELEN];
                    char    szIter[MAXDOUBLELEN];

                    if (bSave2DiffFile)
                        WritePrivateProfileString(szAppName, szSaveFile, szFile, szIniFile);

                    //
                    // Saves new configuartion...
                    //
                    GetDlgItemText(hDlg, ID_XFROM, szXFr, MAXDOUBLELEN);
                    GetDlgItemText(hDlg, ID_YFROM, szYFr, MAXDOUBLELEN);
                    GetDlgItemText(hDlg, ID_XTO,   szX2,  MAXDOUBLELEN);
                    GetDlgItemText(hDlg, ID_YTO,   szY2,  MAXDOUBLELEN);
                    GetDlgItemText(hDlg, ID_ITERATION, szIter, MAXDOUBLELEN);
                    WritePrivateProfileString(szAppName, szXFrom, szXFr, szIniFile);
                    WritePrivateProfileString(szAppName, szYFrom, szYFr, szIniFile);
                    WritePrivateProfileString(szAppName, szXTo,    szX2,  szIniFile);
                    WritePrivateProfileString(szAppName, szYTo,    szY2,  szIniFile);
                    WritePrivateProfileString(szAppName, szIteration, szIter,  szIniFile);
                }
                case IDCANCEL:
                    bSave2DiffFile = FALSE;
                    EndDialog(hDlg,LOWORD(wParam) == IDOK);
                    return TRUE;
                default:
                    break;
            }
        default:
            break;
    }
    return FALSE;
}

LONG APIENTRY ScreenSaverProc | ( | HWND | hWnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 54 of file FRACTAL.C.

{
    static HBRUSH hBkBr;

    switch(message)
    {
        case WM_CREATE:
            hBkBr = GetStockObject(BLACK_BRUSH);
            hpnRed     = CreatePen(PS_SOLID, 0, RGB(0xFF, 0,    0));
            hpnGreen   = CreatePen(PS_SOLID, 0, RGB(0,    0xFF, 0));
            hpnBlack   = CreatePen(PS_SOLID, 0, RGB(0,    0,    0));

            vLoadStrings();
            bInitInfo(&gInfo);
            break;

        case WM_ERASEBKGND: {
            RECT    rc;

            GetClientRect(hWnd, &rc);
            FillRect((HDC)wParam, &rc, hBkBr);
            gInfo.bMandel = TRUE;
            gInfo.hwnd = hWnd;
            gInfo.hHTPal = CreateHalftonePalette((HDC)wParam);
            gInfo.hThrd = CreateThread(NULL, 0,
                                 (LPTHREAD_START_ROUTINE)StartMandelbrot,
                                 &gInfo,
                                 STANDARD_RIGHTS_REQUIRED,
                                 &gInfo.dwThreadId );

            if (gInfo.hThrd) {
                SetThreadPriority(gInfo.hThrd, THREAD_PRIORITY_BELOW_NORMAL);
            }

            return 0L;
        }
        case WM_DESTROY:
            DeleteObject(hBkBr);
            DeleteObject(hpnRed);
            DeleteObject(hpnGreen);
            DeleteObject(hpnBlack);
            TerminateThread(gInfo.hThrd, (DWORD)0L);
            break;
    }
    return (DefScreenSaverProc(hWnd,message,wParam,lParam));
}

BOOL StartMandelbrot ( PINFO pInfo )

Definition at line 237 of file FRACTAL.C.

{
   DWORD       dwTick1;
   HDC         hDC;
   RECT        rc;
   int         m, n, i, iPrev;
   int         xCurr, yCurr;
   int         iPen;

#ifndef THRDONE
   INT      iNumClr;
   char     text[256];
#endif

   double c1, c2;
   double x1, y1, x, y, r;

   HDC          hDCMem;
   HBITMAP      hBitmap, hOldBitmap;

   pInfo->bMandel = TRUE;
   pInfo->bDrawing = TRUE;
   hDC = GetDC(pInfo->hwnd);

#ifndef THRDONE
    if ((iNumClr = iCreatePenFrPal(hDC, NULL, 0, &(pInfo->hPal))) != 0) {
        sprintf( gtext,"iNumClr = %d\n", iNumClr);
        OutputDebugString( gtext);

        if ((pInfo->prghPen = (PVOID*) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(HPEN)*iNumClr)) == NULL) {
            MessageBox(GetFocus(), "Failed in Memory Allocation for pInfo->prghPen!", "Error", MB_OK);
        } else {
            if ((pInfo->iPen = iCreatePenFrPal(hDC, pInfo->prghPen, 1, &(pInfo->hPal))) == 0)
                MessageBox(GetFocus(), "Failed in creating pen!", "Error", MB_OK);
        }
    }

   hDCMem = CreateCompatibleDC(hDC);

   if (pInfo->hPal) {
    SelectPalette(hDCMem, pInfo->hPal, FALSE);
    RealizePalette(hDCMem);
   }
   iPen = pInfo->iPen + 1;
   wsprintf(text, "iPen = %d\n", iPen);
   //MessageBox(GetFocus(), text, "Error", MB_OK);
#endif

   GetClientRect(pInfo->hwnd, &rc);

   hBitmap = CreateCompatibleBitmap(hDC, (int)rc.right, (int)rc.bottom);
   hOldBitmap = SelectObject(hDCMem, hBitmap);

//#if 0
 {
   int iWidth, i, j;

   iWidth = (((iWidth = rc.right/iNumClr) == 0) ? 1 : iWidth);
   sprintf( gtext,"iWidth = %d\n", iWidth);
   OutputDebugString( gtext);

   for (i = 0; i < iNumClr; i++) {
   //for (i = 0; i < 256; i++) {
       //sprintf( gtext,"i mod iNumClr = %d\n", i % iNumClr);
       //OutputDebugString( gtext);
       if ((SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iNumClr])) == NULL) {
            sprintf( gtext,"Select Pen failed\n");
            OutputDebugString( gtext);
       }
       SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[i % iNumClr]);
       for (j = 0; j < iWidth; j++) {
            MoveToEx(hDC, i*iWidth+j, 0, NULL);
            LineTo(hDC, i*iWidth+j, rc.bottom);
            MoveToEx(hDCMem, i*iWidth+j, 0, NULL);
            LineTo(hDCMem, i*iWidth+j, rc.bottom);
       }

   }
 }
//#endif

   dwTick1 = GetTickCount();

   sprintf( gtext,"Start Drawing\n");
   OutputDebugString( gtext);
   yCurr = rc.top;
   for (n=rc.top; n<=rc.bottom; n+=pInfo->iStep, yCurr+=pInfo->iStep, iPrev = FIRST_PIXEL) {
       xCurr = rc.left;                   // since LineTo excludes last point
       MoveToEx(hDC, 0, yCurr, NULL);
       MoveToEx(hDCMem, 0, yCurr, NULL);
       c2 = Xform((double) n, 0.0, (double) rc.bottom, pInfo->yFrom, pInfo->yTo);

       for (m=rc.left; m<=rc.right; m++, xCurr++) {
           c1 = Xform((double) m, 0.0, (double) rc.right, pInfo->xFrom, pInfo->xTo);
     x = c1;
     y = c2;

     for (i=1; i<=pInfo->iIteration; i++) {
               x1 = (x - y) * (x + y) + c1;
               y1 = 2 * x * y + c2;
         r = x1 * x1 + y1 * y1;
         x = x1;
         y = y1;
         if (r > 4.0) {
                   break;
               }
           }

           if (i != iPrev) {
               if (iPrev != FIRST_PIXEL) {
                 switch(iPrev) {
                   case 1: SelectObject(hDC, (HPEN)(pInfo->prghPen)[0]);
                           SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[0]);
                    break;
                   default:
                       if (iPrev >= pInfo->iIteration) {
                            SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPen/3]);
                            SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPen/3]);
                            break;
                       }
                       SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPrev % iPen]);
                       SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPrev % iPen]);
                       //SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPrev % iNumClr]);
                       break;
                 }
                 iPrev = i;
                 LineTo(hDC, xCurr, yCurr);
                 LineTo(hDCMem, xCurr, yCurr);
               }
               else
      iPrev = i;  // remember the color for the first pixel
           }
       }

            switch(i)
    {
                   case 1: SelectObject(hDC, (HPEN)(pInfo->prghPen)[0]);
                           SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[0]);
                    break;
                   default:
                       if (i >= pInfo->iIteration) {
                            SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPen/3]);
                            SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPen/3]);
                            break;
                       }
                       SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iPen]);
                       SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[i % iPen]);
                       //SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iNumClr]);
                       break;
    }

     LineTo(hDC,xCurr,yCurr);
                 LineTo(hDCMem,xCurr,yCurr);

   }

   pInfo->dwElapsed = GetTickCount() - dwTick1;

   if (pInfo->hBmpSaved)
       DeleteObject(pInfo->hBmpSaved);

   pInfo->hBmpSaved = SelectObject(hDCMem, hOldBitmap);
   pInfo->bDrawing = FALSE;
   SaveBitmapFile(hDC, pInfo->hBmpSaved, pInfo->szSavef);
   pInfo->bClrCycle = TRUE;
   if (pInfo->hPal)
      bColorCycle(hDC, pInfo);
   ReleaseDC(pInfo->hwnd, hDC);

#ifndef THRDONE
   if (pInfo->prghPen != NULL) {
       for (i = 0; i <= pInfo->iPen; i++) {
           DeleteObject((HPEN) (pInfo->prghPen)[i]);
       }
       GlobalFree(pInfo->prghPen);
   }
#endif

   DeleteDC(hDCMem);

   ExitThread(0);
   if (!CloseHandle(pInfo->hThrd))
       MessageBox(GetFocus(), "Failed in CloseHandle!", "Error", MB_OK);

   return TRUE;
}

void vLoadStrings ( VOID )

Definition at line 705 of file FRACTAL.C.

{
    LoadString(hMainInstance, idsAppName, szAppName, APPNAMEBUFFERLEN);
    LoadString(hMainInstance, idsName, szName, TITLEBARNAMELEN);
    LoadString(hMainInstance, idsIniFile, szIniFile, MAXFILELEN);
    LoadString(hMainInstance, idsScreenSaver, szScreenSaver, 22);
    LoadString(hMainInstance, idsHelpFile, szHelpFile, MAXFILELEN);
    LoadString(hMainInstance, idsNoHelpMemory, szNoHelpMemory, BUFFLEN);
    LoadString(hMainInstance, idsXFrom, szXFrom, MAXDOUBLELEN);
    LoadString(hMainInstance, idsYFrom, szYFrom, MAXDOUBLELEN);
    LoadString(hMainInstance, idsXTo, szXTo, MAXDOUBLELEN);
    LoadString(hMainInstance, idsYTo, szYTo, MAXDOUBLELEN);
    LoadString(hMainInstance, idsSaveAs, szSaveFile, MAXPATHLEN);
    LoadString(hMainInstance, idsIteration, szIteration, MAXDOUBLELEN);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SCRNSAVE/FRACTAL.H File Reference

  • SCRNSAVE
Data Structures | Defines | Typedefs | Variables

FRACTAL.H File Reference

Go to the source code of this file.

Data Structures

struct | _PerWndInfo

Defines

#define | FIRST_PIXEL 429496796
#define | ID_ITERATION 2005
#define | ID_SAVEAS 2004
#define | ID_XFROM 2000
#define | ID_XTO 2001
#define | ID_YFROM 2002
#define | ID_YTO 2003
#define | idsIteration 9006
#define | idsName 100
#define | idsSaveAs 9005
#define | idsXFrom 9001
#define | idsXTo 9003
#define | idsYFrom 9002
#define | idsYTo 9004
#define | MAXDOUBLELEN 22
#define | MAXPATHLEN 256
#define | Xform(Pt, SrcFrom, SrcTo, DestFrom, DestTo) (((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom))+DestFrom)
#define | Xform2(Pt, SrcFrom, SrcTo, DestFrom, DestTo) ((int) ((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom)+DestFrom))
#define | XformFix(Pt, SrcFrom, SrcTo, DestFrom, DestTo) (lMul(lDiv(Pt-SrcFrom,SrcTo-SrcFrom), DestTo-DestFrom)+DestFrom)

Typedefs

typedef struct _PerWndInfo | INFO
typedef struct _PerWndInfo * | PINFO

Variables

BOOL | gbStretch = TRUE
BOOL | gFloat = TRUE
INT | giDmOrient = DMORIENT_PORTRAIT
INFO gInfo
INT | giNPrinters = 0
INT | giPen = 0
INT | giStretchMode = COLORONCOLOR
LONG | gIteration = 500
LONG | gStep = 1
CHAR | gtext [128]
HPEN | hpnBlack
HPEN | hpnGreen
HPEN | hpnRed
UINT | MyHelpMessage
TCHAR | szAppName [APPNAMEBUFFERLEN]
TCHAR | szHelpFile [MAXFILELEN]
TCHAR | szIniFile [MAXFILELEN]
TCHAR | szIteration [MAXDOUBLELEN]
TCHAR | szName [TITLEBARNAMELEN]
TCHAR | szNoHelpMemory [BUFFLEN]
TCHAR | szSaveFile [MAXPATHLEN]
TCHAR | szScreenSaver [22]
TCHAR | szXFrom [MAXDOUBLELEN]
TCHAR | szXTo [MAXDOUBLELEN]
TCHAR | szYFrom [MAXDOUBLELEN]
TCHAR | szYTo [MAXDOUBLELEN]

Define Documentation

#define FIRST_PIXEL 429496796

Definition at line 9 of file FRACTAL.H.

#define ID_ITERATION 2005

Definition at line 18 of file FRACTAL.H.

#define ID_SAVEAS 2004

Definition at line 17 of file FRACTAL.H.

#define ID_XFROM 2000

Definition at line 13 of file FRACTAL.H.

#define ID_XTO 2001

Definition at line 14 of file FRACTAL.H.

#define ID_YFROM 2002

Definition at line 15 of file FRACTAL.H.

#define ID_YTO 2003

Definition at line 16 of file FRACTAL.H.

#define idsIteration 9006

Definition at line 7 of file FRACTAL.H.

#define idsName 100

Definition at line 1 of file FRACTAL.H.

#define idsSaveAs 9005

Definition at line 6 of file FRACTAL.H.

#define idsXFrom 9001

Definition at line 2 of file FRACTAL.H.

#define idsXTo 9003

Definition at line 4 of file FRACTAL.H.

#define idsYFrom 9002

Definition at line 3 of file FRACTAL.H.

#define idsYTo 9004

Definition at line 5 of file FRACTAL.H.

#define MAXDOUBLELEN 22

Definition at line 10 of file FRACTAL.H.

#define MAXPATHLEN 256

Definition at line 11 of file FRACTAL.H.

#define Xform | ( | Pt,
 |  | SrcFrom,
 |  | SrcTo,
 |  | DestFrom,
 |  | DestTo |
 | ) |  | (((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom))+DestFrom)

Definition at line 90 of file FRACTAL.H.

#define Xform2 | ( | Pt,
 |  | SrcFrom,
 |  | SrcTo,
 |  | DestFrom,
 |  | DestTo |
 | ) |  | ((int) ((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom)+DestFrom))

Definition at line 92 of file FRACTAL.H.

#define XformFix | ( | Pt,
 |  | SrcFrom,
 |  | SrcTo,
 |  | DestFrom,
 |  | DestTo |
 | ) |  | (lMul(lDiv(Pt-SrcFrom,SrcTo-SrcFrom), DestTo-DestFrom)+DestFrom)

Definition at line 94 of file FRACTAL.H.

Typedef Documentation

typedef struct _PerWndInfo INFO
typedef struct _PerWndInfo * PINFO

Variable Documentation

BOOL gbStretch = TRUE

Definition at line 46 of file FRACTAL.H.

BOOL gFloat = TRUE

Definition at line 43 of file FRACTAL.H.

INT giDmOrient = DMORIENT_PORTRAIT

Definition at line 48 of file FRACTAL.H.

INFO gInfo

Definition at line 84 of file FRACTAL.H.

INT giNPrinters = 0

Definition at line 49 of file FRACTAL.H.

INT giPen = 0

Definition at line 41 of file FRACTAL.H.

INT giStretchMode = COLORONCOLOR

Definition at line 47 of file FRACTAL.H.

LONG gIteration = 500

Definition at line 45 of file FRACTAL.H.

LONG gStep = 1

Definition at line 44 of file FRACTAL.H.

CHAR gtext[128]

Definition at line 34 of file FRACTAL.H.

HPEN hpnBlack

Definition at line 36 of file FRACTAL.H.

HPEN hpnGreen

Definition at line 37 of file FRACTAL.H.

HPEN hpnRed

Definition at line 35 of file FRACTAL.H.

UINT MyHelpMessage
TCHAR szAppName[APPNAMEBUFFERLEN]

Definition at line 24 of file GLTHREAD.C.

TCHAR szHelpFile[MAXFILELEN]
TCHAR szIniFile[MAXFILELEN]
TCHAR szIteration[MAXDOUBLELEN]

Definition at line 28 of file FRACTAL.H.

TCHAR szName[TITLEBARNAMELEN]
TCHAR szNoHelpMemory[BUFFLEN]
TCHAR szSaveFile[MAXPATHLEN]

Definition at line 26 of file FRACTAL.H.

TCHAR szScreenSaver[22]
TCHAR szXFrom[MAXDOUBLELEN]

Definition at line 22 of file FRACTAL.H.

TCHAR szXTo[MAXDOUBLELEN]

Definition at line 23 of file FRACTAL.H.

TCHAR szYFrom[MAXDOUBLELEN]

Definition at line 24 of file FRACTAL.H.

TCHAR szYTo[MAXDOUBLELEN]

Definition at line 25 of file FRACTAL.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SEMAPHOR/SEMA.C File Reference

  • SEMAPHOR
Functions | Variables

SEMA.C File Reference

#include <windows.h>
#include <stdlib.h>
#include "sema.h"

Go to the source code of this file.

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | ThreadProc (LPVOID *Color)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hInst
HANDLE | hSemaphore
HANDLE | hWnd

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 205 of file SEMA.C.

{
  DWORD  ThreadID1, ThreadID2, ThreadID3, ThreadID4;
  RECT   rect;
  DWORD  Col1, Col2, Col3, Row1, Row2, Row3, width, height;
  HDC    hDC;
  HANDLE hBrush;
  PAINTSTRUCT Paint;
  static HANDLE hThread1, hThread2, hThread3, hThread4;
  static DWORD  *pColor1,  *pColor2,  *pColor3,  *pColor4;
  CHAR Buf[80];

  switch (message)
      {

        case WM_PAINT:
          hDC = BeginPaint (hwnd, &Paint);
          GetClientRect( hWnd, &rect);       // Get window rectangle.

          width =  rect.right / 4;           // Calculate static rectangle's
          height = rect.bottom / 4;          // width and height.

          Col1 = (rect.right / 16)  * 1;     // Calculate x positions.
          Col2 = (rect.right / 16)  * 6;
          Col3 = (rect.right / 16)  * 11;
                                             // Calculate y positions.
          Row1 = (rect.bottom / 16) * 1;
          Row2 = (rect.bottom / 16) * 6;
          Row3 = (rect.bottom / 16) * 11;

          hBrush = CreateSolidBrush((COLORREF)RED);
          SelectObject (hDC, hBrush);
          Rectangle (hDC, Col2, Row1, Col2+width, Row1+height);
          DeleteObject (hBrush);
                                             // Draw the Blue rectangle.
          hBrush = CreateSolidBrush((COLORREF)BLUE);
          SelectObject (hDC, hBrush);
          Rectangle (hDC, Col1, Row2, Col1+width, Row2+height);
          DeleteObject (hBrush);
                                             // Draw the Green rectangle.
          hBrush = CreateSolidBrush((COLORREF)GREEN);
          SelectObject (hDC, hBrush);
          Rectangle (hDC, Col2, Row3, Col2+width, Row3+height);
          DeleteObject (hBrush);
                                             // Draw the Gray rectangle.
          hBrush = CreateSolidBrush((COLORREF)GRAY);
          SelectObject (hDC, hBrush);
          Rectangle (hDC, Col3, Row2, Col3+width, Row2+height);
          DeleteObject (hBrush);

          EndPaint (hwnd, &Paint);
          return (0);

        case WM_CREATE :
                                             // Create the semaphore.
          hSemaphore = CreateSemaphore (NULL, 0, 1, NULL);

          if (!hSemaphore)
            {
             wsprintf (Buf, "CreateSemaphore() Error = %d",
                       GetLastError());
             MessageBox(hwnd, Buf, "WM_CREATE", MB_OK);
             return (0);
            }

          pColor1  = malloc(sizeof(DWORD));
          *pColor1 = GREEN;                  // Create the Green thread.
          hThread1 = CreateThread ( NULL,
                                    0,
                                    (LPTHREAD_START_ROUTINE)ThreadProc,
                            (LPVOID)pColor1,
                            0,
                                    &ThreadID1);

          pColor2  = malloc(sizeof(DWORD));
          *pColor2 = RED;                    // Create the Red thread.
          hThread2 = CreateThread ( NULL,
                                    0,
                                    (LPTHREAD_START_ROUTINE)ThreadProc,
                            (LPVOID)pColor2,
                            0,
                                    &ThreadID2);

          pColor3  = malloc(sizeof(DWORD));
          *pColor3 = BLUE;                   // Create the Blue thread.
          hThread3 = CreateThread ( NULL,
                                    0,
                                    (LPTHREAD_START_ROUTINE)ThreadProc,
                            (LPVOID)pColor3,
                            0,
                                    &ThreadID3);

          pColor4  = malloc(sizeof(DWORD));
          *pColor4 = GRAY;                   // Create the Gray thread.
          hThread4 = CreateThread ( NULL,
                                    0,
                                    (LPTHREAD_START_ROUTINE)ThreadProc,
                            (LPVOID)pColor4,
                            0,
                                    &ThreadID4);

          ReleaseSemaphore (hSemaphore, 1, NULL);

          return (0);

        case WM_DESTROY :                    // Terminate the threads and
            TerminateThread(hThread1, 0);    // clean up.
            TerminateThread(hThread2, 0);
            TerminateThread(hThread3, 0);
            TerminateThread(hThread4, 0);
            free (pColor1);
            free (pColor2);
            free (pColor3);
            free (pColor4);

            PostQuitMessage (0);
            return (0);

       }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

VOID ThreadProc ( LPVOID * Color )

Definition at line 363 of file SEMA.C.

{
  RECT   rect;
  HDC    hDC;
  HANDLE hBrush;
  DWORD  width, height, Col, Row;

  hBrush = CreateSolidBrush((COLORREF)*Color);

  while (TRUE)
  {
      WaitForSingleObject (hSemaphore, INFINITE);
      GetClientRect( hWnd, &rect);

      width  =  rect.right / 4;
      height = rect.bottom / 4;
      Col = (rect.right / 16)  * 6;
      Row = (rect.bottom / 16) * 6;

      hDC = GetDC(hWnd);
      SelectObject( hDC, hBrush);
      Rectangle (hDC, Col, Row, Col + width, Row + height);
      ReleaseDC(hWnd, hDC);
      Sleep (500);
      ReleaseSemaphore (hSemaphore, 1, NULL);
  }

  return;
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 82 of file SEMA.C.

{
  MSG  msg;
  WNDCLASS wc;
  DWORD dwVersion = GetVersion();

  UNREFERENCED_PARAMETER( lpCmdLine );
  UNREFERENCED_PARAMETER( hPrevInstance );

  // check if Win32s, if so, display notice and terminate
      if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
      {
        MessageBox( NULL,
           "This application cannot run on Windows 3.1.\n"
           "This application will now terminate.",
           "Semaphor",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
      }

  hInst = hInstance;

  wc.style         = CS_VREDRAW | CS_HREDRAW;
  wc.lpfnWndProc   = (WNDPROC)MainWndProc;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.hInstance     = hInstance;
  wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName  = "";
  wc.lpszClassName = "SemaWClass";

  RegisterClass(&wc);

  hWnd = CreateWindow ("SemaWClass",
                       "Semaphore Sample",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);

  ShowWindow(hWnd, nCmdShow);
  while (GetMessage (&msg, NULL, 0, 0))
      DispatchMessage (&msg);    // Dispatch message to window.

  return (msg.wParam);           // Returns value from PostQuitMessage.

}

Variable Documentation

HANDLE hInst

Definition at line 69 of file SEMA.C.

HANDLE hSemaphore

Definition at line 71 of file SEMA.C.

HANDLE hWnd

Definition at line 70 of file SEMA.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SEMAPHOR/SEMA.H File Reference

  • SEMAPHOR
Defines | Functions

SEMA.H File Reference

Go to the source code of this file.

Defines

#define | BLUE 0x007F0000
#define | GRAY 0x007F7F7F
#define | GREEN 0x00007F00
#define | RED 0x0000007F

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | ThreadProc (LPVOID *)

Define Documentation

#define BLUE 0x007F0000

Definition at line 4 of file SEMA.H.

#define GRAY 0x007F7F7F

Definition at line 3 of file SEMA.H.

#define GREEN 0x00007F00

Definition at line 1 of file SEMA.H.

#define RED 0x0000007F

Definition at line 2 of file SEMA.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID ThreadProc ( LPVOID * )

Definition at line 363 of file SEMA.C.

{
  RECT   rect;
  HDC    hDC;
  HANDLE hBrush;
  DWORD  width, height, Col, Row;

  hBrush = CreateSolidBrush((COLORREF)*Color);

  while (TRUE)
  {
      WaitForSingleObject (hSemaphore, INFINITE);
      GetClientRect( hWnd, &rect);

      width  =  rect.right / 4;
      height = rect.bottom / 4;
      Col = (rect.right / 16)  * 6;
      Row = (rect.bottom / 16) * 6;

      hDC = GetDC(hWnd);
      SelectObject( hDC, hBrush);
      Rectangle (hDC, Col, Row, Col + width, Row + height);
      ReleaseDC(hWnd, hDC);
      Sleep (500);
      ReleaseSemaphore (hSemaphore, 1, NULL);
  }

  return;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/BROWSE.C File Reference

  • SERVENUM
  • DEMO
Typedefs | Functions | Variables

BROWSE.C File Reference

#include <windows.h>
#include <windowsx.h>
#include <stdlib.h>
#include <malloc.h>
#include <tchar.h>
#include "globals.h"
#include "servenum.h"

Go to the source code of this file.

Typedefs

typedef DWORD(* | FPSERVENUMDLG )(HWND, LPTSTR, LPDWORD, FARPROC)

Functions

LRESULT | CmdEnumDlg (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdEnumHelpDlg (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
LRESULT | CmdExit (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
int | HelpProc (VOID)
LRESULT | MsgCommand (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgCreate (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgDestroy (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT CALLBACK | WndProc (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)

Variables

CMDI cmdiMain
HINSTANCE | g_hLibrary
HWND | g_hwnd
FPSERVENUMDLG g_lpfnServEnumDlg
MSDI msdiMain
CMD rgcmd []
MSD rgmsd []

Typedef Documentation

typedef DWORD(* FPSERVENUMDLG)(HWND, LPTSTR, LPDWORD, FARPROC)

Definition at line 40 of file BROWSE.C.

Function Documentation

LRESULT CmdEnumDlg | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 280 of file BROWSE.C.

{
    TCHAR szBuf[64];
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
    DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
    DWORD dwRet;

    dwRet = g_lpfnServEnumDlg( hwnd, szServer, &cchServer, NULL );

    if ( dwRet == ERROR_SUCCESS )
        wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );

    else if ( dwRet == ERROR_CANCELLED )
        _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );

    else
        wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );

    MessageBox( hwnd, szBuf, szAppName, MB_OK );

    return 0;
}

LRESULT CmdEnumHelpDlg | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 321 of file BROWSE.C.

{
    TCHAR szBuf[64];
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
    DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
    DWORD dwRet;

    dwRet = g_lpfnServEnumDlg(hwnd, szServer, &cchServer, (FARPROC) HelpProc);

    if ( dwRet == ERROR_SUCCESS )
        wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );

    else if ( dwRet == ERROR_CANCELLED )
        _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );

    else
        wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );

    MessageBox( hwnd, szBuf, szAppName, MB_OK );

    return 0;
}

LRESULT CmdExit | ( | HWND | hwnd,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 255 of file BROWSE.C.

{
    DestroyWindow(hwnd);
    return 0;
}

int HelpProc ( VOID )

Definition at line 358 of file BROWSE.C.

{
    MessageBox( g_hwnd, TEXT("Help Procedure Called"), szAppName, MB_OK );
    return 0;
}

LRESULT MsgCommand | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 202 of file BROWSE.C.

{
    return DispCommand(&cmdiMain, hwnd, wparam, lparam);
}

LRESULT MsgCreate | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 136 of file BROWSE.C.

{
    DWORD dwError;
    TCHAR szError[128];

    // Store the main window handle
    g_hwnd = hwnd;

    // Attempt to dynamically load the servenum.dll
    g_hLibrary = LoadLibrary(TEXT("servenum.dll"));
    if (!g_hLibrary)
    {
        dwError = GetLastError();
        wsprintf(szError, TEXT("Error loading SERVENUM.DLL.  ")
                 TEXT("GetLastError() == %d."), dwError);
        MessageBox(hwnd, szError, TEXT("Server Enum"), MB_ICONEXCLAMATION | MB_OK);
        return(-1);
    }

    // The DLL is loaded, get a pointer to the exported function
#ifdef UNICODE
    g_lpfnServEnumDlg = (FPSERVENUMDLG) GetProcAddress(g_hLibrary,
            "ServerEnumDialogW");
#else
    g_lpfnServEnumDlg = (FPSERVENUMDLG) GetProcAddress(g_hLibrary,
            "ServerEnumDialogA");
#endif

    if (!g_lpfnServEnumDlg)
    {
        dwError = GetLastError();
        wsprintf(szError, TEXT("Error loading SERVENUM.DLL.  ")
                 TEXT("GetLastError() == %d."), dwError);
        MessageBox(hwnd, szError, TEXT("Server Enum"), MB_ICONEXCLAMATION | MB_OK);
        return(-1);
    }

    return 0;
}

LRESULT MsgDestroy | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 228 of file BROWSE.C.

{

    PostQuitMessage(0);
    return 0;
}

LRESULT CALLBACK WndProc | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 106 of file BROWSE.C.

{
    return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}

Variable Documentation

CMDI cmdiMain
Initial value:
{
    sizeof(rgcmd) / sizeof(CMD),
    rgcmd,
    edwpWindow
}

Definition at line 68 of file BROWSE.C.

HINSTANCE g_hLibrary

Definition at line 81 of file BROWSE.C.

HWND g_hwnd

Definition at line 80 of file BROWSE.C.

FPSERVENUMDLG g_lpfnServEnumDlg

Definition at line 82 of file BROWSE.C.

MSDI msdiMain
Initial value:
{
    sizeof(rgmsd) / sizeof(MSD),
    rgmsd,
    edwpWindow
}

Definition at line 52 of file BROWSE.C.

CMD rgcmd[]
Initial value:
{
    {IDM_ENUM, CmdEnumDlg},
    {IDM_ENUMHELP, CmdEnumHelpDlg},
    {IDM_EXIT, CmdExit},
}

Definition at line 61 of file BROWSE.C.

MSD rgmsd[]
Initial value:
{
    {WM_CREATE,   MsgCreate},
    {WM_COMMAND,  MsgCommand},
    {WM_DESTROY,  MsgDestroy}
}

Definition at line 45 of file BROWSE.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/DISPATCH.C File Reference

  • SERVENUM
  • DEMO
Functions

DISPATCH.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"

Go to the source code of this file.

Functions

LRESULT | DispCommand (LPCMDI lpcmdi, HWND hwnd, WPARAM wparam, LPARAM lparam)
LRESULT | DispDefault (EDWP, HWND, UINT, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI lpmsdi, HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)

Function Documentation

LRESULT DispCommand | ( | LPCMDI | lpcmdi,
 |  | HWND | hwnd,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 97 of file DISPATCH.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispDefault | ( | EDWP | edwp,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 148 of file DISPATCH.C.

{
    switch (edwp)
    {
        case edwpNone:
            return 0;
        case edwpWindow:
            return DefWindowProc(hwnd, uMessage, wparam, lparam);
        case edwpDialog:
            return DefDlgProc(hwnd, uMessage, wparam, lparam);
        case edwpMDIFrame:
            return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
        case edwpMDIChild:
            return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
    }
    return 0;
}

LRESULT DispMessage | ( | LPMSDI | lpmsdi,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 51 of file DISPATCH.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/GLOBALS.H File Reference

  • SERVENUM
  • DEMO
Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

GLOBALS.H File Reference

Go to the source code of this file.

Data Structures

struct | _CMD
struct | _CMDI
struct | _MSD
struct | _MSDI

Defines

#define | APPNAME browse
#define | hwndMDIClient NULL
#define | ICONFILE browse.ico
#define | IDM_ENUM 1001
#define | IDM_ENUMHELP 1002
#define | IDM_EXIT 1000
#define | IDS_APPNAME 1
#define | IDS_DESCRIPTION 2
#define | SZABOUT "About Browse"
#define | SZAPPNAME "Browse"
#define | SZDESCRIPTION "ServerEnumDialog Sample"
#define | SZVERSION "Version 1.0"

Typedefs

typedef struct _CMD | CMD
typedef struct _CMDI | CMDI
typedef struct _CMDI * | LPCMDI
typedef struct _MSDI * | LPMSDI
typedef struct _MSD | MSD
typedef struct _MSDI | MSDI
typedef LRESULT(* | PFNCMD )(HWND, WORD, WORD, HWND)
typedef LRESULT(* | PFNMSG )(HWND, UINT, WPARAM, LPARAM)

Enumerations

enum EDWP {
edwpNone, edwpWindow, edwpDialog, edwpMDIChild,
edwpMDIFrame, edwpNone, edwpWindow, edwpDialog,
edwpMDIChild, edwpMDIFrame, edwpNone, edwpWindow,
edwpDialog, edwpMDIChild, edwpMDIFrame
}

Functions

BOOL | CenterWindow (HWND, HWND)
LRESULT | CmdEnumDlg (HWND, WORD, WORD, HWND)
LRESULT | CmdEnumHelpDlg (HWND, WORD, WORD, HWND)
LRESULT | CmdExit (HWND, WORD, WORD, HWND)
LRESULT | DispCommand (LPCMDI, HWND, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI, HWND, UINT, WPARAM, LPARAM)
BOOL | InitApplication (HINSTANCE)
BOOL | InitInstance (HINSTANCE, int)
LRESULT | MsgCommand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgCreate (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgDestroy (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | WndProc (HWND, UINT, WPARAM, LPARAM)

Variables

CMDI cmdiMain
HINSTANCE | hInst
MSDI msdiMain
TCHAR | szAppName []
TCHAR | szTitle []

Define Documentation

#define APPNAME browse

Definition at line 16 of file GLOBALS.H.

#define hwndMDIClient NULL

Definition at line 102 of file GLOBALS.H.

#define ICONFILE browse.ico

Definition at line 17 of file GLOBALS.H.

#define IDM_ENUM 1001

Definition at line 75 of file GLOBALS.H.

#define IDM_ENUMHELP 1002

Definition at line 76 of file GLOBALS.H.

#define IDM_EXIT 1000

Definition at line 74 of file GLOBALS.H.

#define IDS_APPNAME 1

Definition at line 83 of file GLOBALS.H.

#define IDS_DESCRIPTION 2

Definition at line 84 of file GLOBALS.H.

#define SZABOUT "About Browse"

Definition at line 20 of file GLOBALS.H.

#define SZAPPNAME "Browse"

Definition at line 18 of file GLOBALS.H.

#define SZDESCRIPTION "ServerEnumDialog Sample"

Definition at line 19 of file GLOBALS.H.

#define SZVERSION "Version 1.0"

Definition at line 21 of file GLOBALS.H.

Typedef Documentation

typedef struct _CMD CMD
typedef struct _CMDI CMDI
typedef struct _CMDI* LPCMDI
typedef struct _MSDI* LPMSDI
typedef struct _MSD MSD
typedef struct _MSDI MSDI
typedef LRESULT(* PFNCMD)(HWND, WORD, WORD, HWND)

Definition at line 115 of file GLOBALS.H.

typedef LRESULT(* PFNMSG)(HWND, UINT, WPARAM, LPARAM)

Definition at line 112 of file GLOBALS.H.

Enumeration Type Documentation

enum EDWP
Enumerator:
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame

Definition at line 120 of file GLOBALS.H.

{
   edwpNone,            // Do not call any default procedure.
   edwpWindow,          // Call DefWindowProc.
   edwpDialog,          // Call DefDlgProc (This should be used only for
                        // custom dialogs - standard dialog use edwpNone).
   edwpMDIChild,        // Call DefMDIChildProc.
   edwpMDIFrame         // Call DefFrameProc.
} EDWP;                // Enumeration for Default Window Procedures

Function Documentation

BOOL CenterWindow | ( | HWND | ,
 |  | HWND |
 | ) |  |

Definition at line 50 of file MISC.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

LRESULT CmdEnumDlg | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 280 of file BROWSE.C.

{
    TCHAR szBuf[64];
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
    DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
    DWORD dwRet;

    dwRet = g_lpfnServEnumDlg( hwnd, szServer, &cchServer, NULL );

    if ( dwRet == ERROR_SUCCESS )
        wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );

    else if ( dwRet == ERROR_CANCELLED )
        _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );

    else
        wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );

    MessageBox( hwnd, szBuf, szAppName, MB_OK );

    return 0;
}

LRESULT CmdEnumHelpDlg | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 321 of file BROWSE.C.

{
    TCHAR szBuf[64];
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
    DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
    DWORD dwRet;

    dwRet = g_lpfnServEnumDlg(hwnd, szServer, &cchServer, (FARPROC) HelpProc);

    if ( dwRet == ERROR_SUCCESS )
        wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );

    else if ( dwRet == ERROR_CANCELLED )
        _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );

    else
        wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );

    MessageBox( hwnd, szBuf, szAppName, MB_OK );

    return 0;
}

LRESULT CmdExit | ( | HWND | ,
 |  | WORD | ,
 |  | WORD | ,
 |  | HWND |
 | ) |  |

Definition at line 636 of file NDDECHAT.C.

{
    DestroyWindow(hwnd);
    return 0;
}

LRESULT DispCommand | ( | LPCMDI | ,
 |  | HWND | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 100 of file DISPATCH.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispMessage | ( | LPMSDI | ,
 |  | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 54 of file DISPATCH.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

BOOL InitApplication ( HINSTANCE )

Definition at line 86 of file NTGREP.C.

{
    WNDCLASS  wc;
    wc.style = 0;
    wc.lpfnWndProc = (WNDPROC)MainWndProc;

    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName =  "GrepMenu";
    wc.lpszClassName = INITCLASSNAME;

    return (RegisterClass(&wc));

}

BOOL InitInstance | ( | HINSTANCE | ,
 |  | int |
 | ) |  |

Definition at line 106 of file NTGREP.C.

{
    HWND            hWnd;

    hInst = hInstance;

    hWnd = CreateWindow(
  INITCLASSNAME,
  "File Search Installer",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL
    );

    if (!hWnd)
  return (FALSE);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    return (TRUE);

}

LRESULT MsgCommand | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 418 of file NDDECHAT.C.

{
    return DispCommand(&cmdiMain, hwnd, wparam, lparam);
}

LRESULT MsgCreate | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 151 of file NDDECHAT.C.

{
    RECT rc;
    HSZ  hszService;

    g_hwnd = hwnd;
    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
    EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );

    // setup NetDDE Share ( require if acting as a server )
    LoadString(hInst, IDS_SHARENAME, (LPSTR)szShareName, MAX_NDDESHARENAME);
    LoadString(hInst, IDS_TOPIC, (LPSTR)g_szTopic, MAX_TOPICNAME);
    LoadString(hInst, IDS_ITEM, (LPSTR)szItem, MAX_ITEMNAME);

    if ( !SetupNDDEShare(hwnd, (LPSTR)szShareName, (LPSTR)szAppName, (LPSTR)g_szTopic) )
    {
        MessageBox( hwnd, (LPSTR)"Unable to create NetDDE Share.",
                    (LPSTR)szAppName, MB_ICONSTOP | MB_OK );
        return 0;
    }

    // Initialize DDEML conversation
    if (DdeInitialize (&g_idInst, (PFNCALLBACK) DdeCallback,
                       APPCLASS_STANDARD | CBF_FAIL_EXECUTES
                       | CBF_FAIL_REQUESTS | CBF_FAIL_SELFCONNECTIONS, 0L))
    {
        MessageBox (hwnd, (LPSTR)"Unable to initialize DDEML.",
                      szAppName, MB_ICONSTOP | MB_OK) ;
        return 0;
    }

    hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0) ;
    DdeNameService (g_idInst, hszService, 0, DNS_REGISTER) ;
    DdeFreeStringHandle (g_idInst, hszService) ;

    // Initialize user interface
    GetClientRect( hwnd, &rc );

    hwndSend  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_WANTRETURN,
                             0,
                             0,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_SEND,
                             hInst,
                             NULL );

    hwndRecv  = CreateWindow("EDIT",
                             NULL,
                             WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
                              | ES_LEFT | ES_MULTILINE | ES_READONLY | ES_WANTRETURN,
                             0,
                             rc.bottom/2,
                             rc.right,
                             rc.bottom/2,
                             hwnd,
                             (HMENU) IDE_RECV,
                             hInst,
                             NULL );

    EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_ENABLED );

    // initialize variable for last contents of send data
    MallocMem( (LPVOID *) &pszLast, 1 );
    *pszLast = '\0';

    return 0;
}

LRESULT MsgDestroy | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 443 of file NDDECHAT.C.

{
    HSZ hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0);
    DdeNameService (g_idInst, hszService, 0, DNS_UNREGISTER);
    DdeFreeStringHandle (g_idInst, hszService);

    if ( pszLast )
        FreeMem( (LPVOID *) &pszLast );

    PostQuitMessage(0);
    return 0;
}

LRESULT CALLBACK WndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 121 of file NDDECHAT.C.

{
    return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}

Variable Documentation

CMDI cmdiMain

Definition at line 70 of file NDDECHAT.C.

HINSTANCE hInst

Definition at line 32 of file CLIPTEXT.C.

MSDI msdiMain

Definition at line 54 of file NDDECHAT.C.

TCHAR szAppName[]

Definition at line 24 of file GLTHREAD.C.

TCHAR szTitle[]

Definition at line 28 of file INIT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/INIT.C File Reference

  • SERVENUM
  • DEMO
Functions | Variables

INIT.C File Reference

#include <windows.h>
#include "globals.h"

Go to the source code of this file.

Functions

BOOL | InitApplication (HINSTANCE hInstance)
BOOL | InitInstance (HINSTANCE hInstance, int nCmdShow)

Variables

HINSTANCE | hInst
TCHAR | szAppName [9]
TCHAR | szTitle [40]

Function Documentation

BOOL InitApplication ( HINSTANCE hInstance )

Definition at line 54 of file INIT.C.

{
    WNDCLASS  wc;

    // Load the application name and description strings.

    LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
    LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));

    // Fill in window class structure with parameters that describe the
    // main window.

    wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
    wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
    wc.cbClsExtra    = 0;                       // No per-class extra data.
    wc.cbWndExtra    = 0;                       // No per-window extra data.
    wc.hInstance     = hInstance;               // Owner of this class
    wc.hIcon         = LoadIcon(hInstance, szAppName); // Icon name from .RC
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
    wc.lpszMenuName  = szAppName;               // Menu name from .RC
    wc.lpszClassName = szAppName;               // Name to register as

    // Register the window class and return FALSE if unsuccesful.

    if (!RegisterClass(&wc))
    {
        return FALSE;
    }
    //
    // **TODO** Call module specific application initialization functions here.
    //

    return TRUE;
}

BOOL InitInstance | ( | HINSTANCE | hInstance,
 |  | int | nCmdShow
 | ) |  |

Definition at line 114 of file INIT.C.

{
    HWND    hwnd; // Main window handle.

    // Save the instance handle in static variable, which will be used in
    // many subsequence calls from this application to Windows.

    hInst = hInstance; // Store instance handle in our global variable

    // Create a main window for this application instance.
    hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
                        szTitle,             // Text for window title bar.
                        WS_OVERLAPPEDWINDOW, // Window style.
                        CW_USEDEFAULT, 0,    // Use default positioning
                        CW_USEDEFAULT, 0,    // Use default size
                        NULL,                // Overlapped has no parent.
                        NULL,                // Use the window class menu.
                        hInstance,
                        NULL);

    // If window could not be created, return "failure"
    if (!hwnd)
        return FALSE;

    //
    // **TODO** Call module specific instance initialization functions here.
    //

    // Make the window visible; update its client area; and return "success"
    ShowWindow(hwnd, nCmdShow); // Show the window
    UpdateWindow(hwnd);         // Sends WM_PAINT message

    return TRUE;                // We succeeded...
}

Variable Documentation

HINSTANCE hInst

Definition at line 22 of file INIT.C.

TCHAR szAppName[9]

Definition at line 24 of file INIT.C.

TCHAR szTitle[40]

Definition at line 25 of file INIT.C.

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/MISC.C File Reference

  • SERVENUM
  • DEMO
Functions

MISC.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "globals.h"

Go to the source code of this file.

Functions

BOOL CenterWindow (HWND hwndChild, HWND hwndParent)

Function Documentation

BOOL CenterWindow | ( | HWND | hwndChild,
 |  | HWND | hwndParent
 | ) |  |

Definition at line 47 of file MISC.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/SERVENUM.H File Reference

  • SERVENUM
  • DEMO
Defines | Functions

SERVENUM.H File Reference

Go to the source code of this file.

Defines

#define | ERROR_CANCELLED 1223L
#define | ServerEnumDialog ServerEnumDialogA

Functions

DWORD | ServerEnumDialogA (HWND hwnd, LPSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)
DWORD | ServerEnumDialogW (HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)

Define Documentation

#define ERROR_CANCELLED 1223L

Definition at line 17 of file SERVENUM.H.

#define ServerEnumDialog ServerEnumDialogA

Definition at line 64 of file SERVENUM.H.

Function Documentation

DWORD ServerEnumDialogA | ( | HWND | hwnd,
 |  | LPSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 161 of file SERVENUM.C.

{
    DWORD dwRet;
    WCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];

    if ( ERROR_SUCCESS == ( dwRet = ServerEnumDialogW( hwnd, szServer, lpcchServer, lpfnHelpProc ) ) )
        WideCharToMultiByte( CP_ACP, 0, szServer, *lpcchServer, lpszServer, *lpcchServer, NULL, NULL );
    return dwRet;
}

DWORD ServerEnumDialogW | ( | HWND | hwnd,
 |  | LPWSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 104 of file SERVENUM.C.

{
    HDC hdc;
    HFONT hfontOld;
    DWORD dwRet = ERROR_SUCCESS;
    LPTLSOBJECT lpTls;

    if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpTls, sizeof(TLSOBJECT) ) ) )
    {
        TlsSetValue( ndxTls, (LPVOID) lpTls );

        lpTls->lpszServer = lpszServer;
        lpTls->lpcchServer = lpcchServer;
        lpTls->lpfnHelpProc = lpfnHelpProc;

        lpTls->hfont = CreateStdFont( hwnd, 8 );
        hdc = GetDC( hwnd );
        hfontOld = SelectObject( hdc, lpTls->hfont );
        GetTextMetrics(hdc, &(lpTls->tm) );
        SelectObject( hdc, hfontOld );
        ReleaseDC( hwnd, hdc );

        dwRet = DialogBox(g_hMod, TEXT("EnumDlgBox"), hwnd, (DLGPROC)EnumDlg);

        DeleteObject( lpTls->hfont );

        FreeMem( &lpTls );
    }

    RefreshOutstanding(); // try cleaning up any outstanding threads

    return dwRet;

}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/WINMAIN.C File Reference

  • SERVENUM
  • DEMO
Functions

WINMAIN.C File Reference

#include <windows.h>
#include "globals.h"

Go to the source code of this file.

Functions

int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 67 of file WINMAIN.C.

{
    MSG msg;
    HANDLE hAccelTable;

    // Check to see if this is Win95 or Windows NT.  This sample uses some
    // unicode and some other API's that aren't available in Win95 at least
    // in the BETA 2 release.  If it's not Win NT we'll gracefully exit.
    if (GetVersion() & 0x80000000)
    {
        MessageBox(NULL, TEXT("This program can only be run on Windows NT"),
                TEXT("Server Enum Sample"), MB_ICONEXCLAMATION | MB_OK);
        return(0);
    }

    // Other instances of app running?
    if (!hPrevInstance)
    {
        // Initialize shared things
        if (!InitApplication(hInstance))
        {
            return FALSE;               // Exits if unable to initialize
        }
    }

    // Perform initializations that apply to a specific instance
    if (!InitInstance(hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, szAppName);

    // Acquire and dispatch messages until a WM_QUIT message is received.
    while (GetMessage(&msg, NULL, 0, 0))
    {
        //
        // **TODO** Add other Translation functions (for modeless dialogs
        //  and/or MDI windows) here.
        //

        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    //
    // **TODO** Call module specific instance free/delete functions here.
    //

    // Returns the value from PostQuitMessage
    return msg.wParam;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/DLLDISP.C File Reference

  • SERVENUM
  • DLL
Functions

DLLDISP.C File Reference

#include <windows.h>
#include <windowsx.h>
#include "dlldisp.h"

Go to the source code of this file.

Functions

LRESULT | DispCommand (LPCMDI lpcmdi, HWND hwnd, WPARAM wparam, LPARAM lparam)
LRESULT | DispDefault (EDWP, HWND, UINT, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI lpmsdi, HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)

Function Documentation

LRESULT DispCommand | ( | LPCMDI | lpcmdi,
 |  | HWND | hwnd,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 97 of file DLLDISP.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispDefault | ( | EDWP | edwp,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 148 of file DLLDISP.C.

{
    switch (edwp)
    {
        case edwpNone:
            return 0;
        case edwpWindow:
            return DefWindowProc(hwnd, uMessage, wparam, lparam);
        case edwpDialog:
            return DefDlgProc(hwnd, uMessage, wparam, lparam);
        case edwpMDIFrame:
            return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
        case edwpMDIChild:
            return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
    }
    return 0;
}

LRESULT DispMessage | ( | LPMSDI | lpmsdi,
 |  | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 51 of file DLLDISP.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/DLLDISP.H File Reference

  • SERVENUM
  • DLL
Data Structures | Defines | Typedefs | Enumerations | Functions

DLLDISP.H File Reference

Go to the source code of this file.

Data Structures

struct | _CMD
struct | _CMDI
struct | _MSD
struct | _MSDI

Defines

#define | hwndMDIClient NULL

Typedefs

typedef struct _CMD | CMD
typedef struct _CMDI | CMDI
typedef struct _CMDI * | LPCMDI
typedef struct _MSDI * | LPMSDI
typedef struct _MSD | MSD
typedef struct _MSDI | MSDI
typedef LRESULT(* | PFNCMD )(HWND, WORD, WORD, HWND)
typedef LRESULT(* | PFNMSG )(HWND, UINT, WPARAM, LPARAM)

Enumerations

enum EDWP {
edwpNone, edwpWindow, edwpDialog, edwpMDIChild,
edwpMDIFrame, edwpNone, edwpWindow, edwpDialog,
edwpMDIChild, edwpMDIFrame, edwpNone, edwpWindow,
edwpDialog, edwpMDIChild, edwpMDIFrame
}

Functions

LRESULT | DispCommand (LPCMDI, HWND, WPARAM, LPARAM)
LRESULT | DispMessage (LPMSDI, HWND, UINT, WPARAM, LPARAM)

Define Documentation

#define hwndMDIClient NULL

Definition at line 19 of file DLLDISP.H.

Typedef Documentation

typedef struct _CMD CMD
typedef struct _CMDI CMDI
typedef struct _CMDI* LPCMDI
typedef struct _MSDI* LPMSDI
typedef struct _MSD MSD
typedef struct _MSDI MSDI
typedef LRESULT(* PFNCMD)(HWND, WORD, WORD, HWND)

Definition at line 31 of file DLLDISP.H.

typedef LRESULT(* PFNMSG)(HWND, UINT, WPARAM, LPARAM)

Definition at line 28 of file DLLDISP.H.

Enumeration Type Documentation

enum EDWP
Enumerator:
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame
edwpNone
edwpWindow
edwpDialog
edwpMDIChild
edwpMDIFrame

Definition at line 36 of file DLLDISP.H.

{
   edwpNone,            // Do not call any default procedure.
   edwpWindow,          // Call DefWindowProc.
   edwpDialog,          // Call DefDlgProc (This should be used only for
                        // custom dialogs - standard dialog use edwpNone).
   edwpMDIChild,        // Call DefMDIChildProc.
   edwpMDIFrame         // Call DefFrameProc.
} EDWP;                // Enumeration for Default Window Procedures

Function Documentation

LRESULT DispCommand | ( | LPCMDI | ,
 |  | HWND | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 100 of file DISPATCH.C.

{
    LRESULT lRet = 0;
    WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
    int     icmd;

    CMD    *rgcmd = lpcmdi->rgcmd;
    int     ccmd  = lpcmdi->ccmd;

    // Message packing of wparam and lparam have changed for Win32,
    // so use the GET_WM_COMMAND macro to unpack the commnad

    for (icmd = 0; icmd < ccmd; icmd++)
    {
        if (rgcmd[icmd].wCommand == wCommand)
        {
            return rgcmd[icmd].pfncmd(hwnd,
                                      wCommand,
                                      GET_WM_COMMAND_CMD(wparam, lparam),
                                      GET_WM_COMMAND_HWND(wparam, lparam));
        }
    }

    return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}

LRESULT DispMessage | ( | LPMSDI | ,
 |  | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 54 of file DISPATCH.C.

{
    int  imsd = 0;

    MSD *rgmsd = lpmsdi->rgmsd;
    int  cmsd  = lpmsdi->cmsd;

    for (imsd = 0; imsd < cmsd; imsd++)
    {
        if (rgmsd[imsd].uMessage == uMessage)
            return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
    }

    return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMDLG.C File Reference

  • SERVENUM
  • DLL
Defines | Functions | Variables

ENUMDLG.C File Reference

#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include "dlldisp.h"
#include "enumdlg.h"
#include "enumutil.h"
#include "enumthrd.h"
#include "thrdutil.h"
#include "miscutil.h"
#include "mem.h"
#include "macros.h"

Go to the source code of this file.

Defines

#define | ERROR_CANCELLED 1223L

Functions

LRESULT | CmdEnumDlgBrowse (HWND, WORD, WORD, HWND)
LRESULT | CmdEnumDlgCancel (HWND, WORD, WORD, HWND)
LRESULT | CmdEnumDlgHelp (HWND, WORD, WORD, HWND)
LRESULT | CmdEnumDlgOK (HWND, WORD, WORD, HWND)
LRESULT CALLBACK | EnumDlg (HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT APIENTRY | ListSubProc (HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgEnumDlgCharToItem (HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
LRESULT | MsgEnumDlgCommand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgDestroy (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgDrawItem (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgEnumExpand (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgInit (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgInitEnum (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgMeasureItem (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgSetCursor (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgSysColor (HWND, UINT, WPARAM, LPARAM)
LRESULT | MsgEnumDlgVKeyToItem (HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)

Variables

CMDI cmdiEnumDlg
MSDI msdiEnumDlg
DWORD ndxTls
CMD rgcmdEnumDlg []
MSD rgmsdEnumDlg []

Define Documentation

#define ERROR_CANCELLED 1223L

Definition at line 52 of file ENUMDLG.C.

Function Documentation

LRESULT CmdEnumDlgBrowse | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 941 of file ENUMDLG.C.

{
    LPENUMNODE lpNode;
    UINT ndx;
    HWND hwndBrowse;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    if ( lpTls->lpSync->cThread == 1 )
    {

        hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
        ndx = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
        SendMessage( hwndBrowse, LB_GETTEXT, (WPARAM) ndx, (LPARAM) &lpNode );

        switch( wNotify )
        {
            case LBN_DBLCLK:  // expanding and collapsing nodes
                switch( lpNode->ndxBmp )
                {
                    case PROV_NDX:
                        lpNode->ndxBmp = PROVEX_NDX;
                        EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );
                        EnumListExpand( hwndBrowse, lpTls->lpSync, lpNode, ndx );
                        break;

                    case DOM_NDX:
                        lpNode->ndxBmp = DOMEX_NDX;
                        EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );
                        EnumListExpand( hwndBrowse, lpTls->lpSync, lpNode, ndx );
                        break;

                    case PROVEX_NDX:
                        lpNode->ndxBmp = PROV_NDX;
                        EnumListCollapse( hwndBrowse, lpNode, ndx );
                        break;

                    case DOMEX_NDX:
                        lpNode->ndxBmp = DOM_NDX;
                        EnumListCollapse( hwndBrowse, lpNode, ndx );
                        break;

                    case SERV_NDX:
                        SendMessage( hdlg, WM_COMMAND, (WPARAM) IDOK, 0 );
                        break;
                }
                return TRUE;
        }
    }
    return FALSE;
}

LRESULT CmdEnumDlgCancel | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 891 of file ENUMDLG.C.

{
    EndDialog(hdlg, ERROR_CANCELLED);          // Exit the dialog
    return TRUE;
}

LRESULT CmdEnumDlgHelp | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 915 of file ENUMDLG.C.

{
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    (*(lpTls->lpfnHelpProc))();
    return TRUE;
}

LRESULT CmdEnumDlgOK | ( | HWND | hdlg,
 |  | WORD | wCommand,
 |  | WORD | wNotify,
 |  | HWND | hwndCtrl
 | ) |  |

Definition at line 835 of file ENUMDLG.C.

{
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+5] = TEXT("\\\\");
    LPTSTR psz = szServer+2;
    DWORD cchServer = 0;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    SendDlgItemMessage( hdlg, IDE_SERVER, WM_GETTEXT, (WPARAM)(MAX_COMPUTERNAME_LENGTH+3), (LPARAM)psz );

    if ( *psz == TEXT('\0') ) // no server name, so same as cancelled
    {
        EndDialog(hdlg, ERROR_CANCELLED);
    }
    else
    {
        if ( *psz != TEXT('\\') ) // if the name does not begin with a '\', we make
        {                         // it begin with '\\' by ajusting the pointer
            psz = szServer;
            psz[MAX_COMPUTERNAME_LENGTH+2] = TEXT('\0');
        }
        cchServer = _tcslen( psz )+1;

        if ( ( cchServer > *(lpTls->lpcchServer) ) ||
             ( lpTls->lpszServer == NULL ) )
        {
            *(lpTls->lpcchServer) = cchServer;
            EndDialog(hdlg, ERROR_MORE_DATA);
        }
        else
        {
            _tcscpy( lpTls->lpszServer, psz );
            *(lpTls->lpcchServer) = cchServer;
            EndDialog(hdlg, ERROR_SUCCESS);
        }
    }
    return TRUE;
}

LRESULT CALLBACK EnumDlg | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 133 of file ENUMDLG.C.

{
    return DispMessage(&msdiEnumDlg, hdlg, uMessage, wparam, lparam);
}

LRESULT APIENTRY ListSubProc | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 994 of file ENUMDLG.C.

{
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    switch (uMessage)
    {
        case WM_SETCURSOR:
            SendMessage( GetParent(hwnd), WM_SETCURSOR, (WPARAM) hwnd, MAKELONG( HTCLIENT, 0 ) );
            break;

        case WM_GETDLGCODE:
            return DLGC_WANTALLKEYS | CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);

        default:
            return CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);
    }
    return (0);
}

LRESULT MsgEnumDlgCharToItem | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 621 of file ENUMDLG.C.

{
    int nCur;
    int nCount;
    int ndx;
    LPENUMNODE lpNode  = NULL;
    TCHAR w_key[2];
    CHAR key = (CHAR) LOWORD(wparam);
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );

    if ( (HWND)lparam == hwndBrowse )  // handle message for this listbox
    {
        if ( (UINT)key == 0xD )  // enter key is the same as a double click
        {
            SendMessage( hdlg, WM_COMMAND, MAKELONG(IDL_BROWSE, LBN_DBLCLK), (LPARAM) hwndBrowse );
            return -2;
        }

        nCur = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
        nCount = SendMessage( hwndBrowse, LB_GETCOUNT, 0, 0 );

        if ( nCount > 0 )
        {
            if ( MultiByteToWideChar( CP_ACP, 0, &key, 1, w_key, 2 ) )
            {
                for( ndx = nCur+1; ndx != nCur; ndx++ )
                {
                     if ( ndx >= nCount )
                     {
                         ndx = -1;
                         continue;
                     }

                     if ( LB_ERR != SendMessage( hwndBrowse, LB_GETTEXT, ndx, (LPARAM) &lpNode) )
                     {
                         if ( _totupper(*w_key) == _totupper(*lpNode->lpNet->lpRemoteName) )
                         {
                             SendMessage( hwndBrowse, LB_SETCURSEL, ndx, 0 );
                             return -2;
                         }
                     }
                }
            }
        }
    }
    return -1;
}

LRESULT MsgEnumDlgCommand | ( | HWND | hwnd,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 763 of file ENUMDLG.C.

{
    return DispCommand(&cmdiEnumDlg, hwnd, wparam, lparam);
}

LRESULT MsgEnumDlgDestroy | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 788 of file ENUMDLG.C.

{
    UINT ndx = HIGHLIGHT_NDX*2;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );

    if ( lpTls->hbmpArray[0] )
    {
        while( ndx-- )
            DeleteObject( lpTls->hbmpArray[ndx] );
    }

    if ( lpTls->hbrushHL )
        DeleteObject( lpTls->hbrushHL );

    if ( lpTls->lpfnListProc )
        SetWindowLong( hwndBrowse, GWL_WNDPROC, (LONG) lpTls->lpfnListProc );

    if ( lpTls->lpSync )
        FreeEnumSync( &(lpTls->lpSync) );

    return TRUE;
}

LRESULT MsgEnumDlgDrawItem | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 384 of file ENUMDLG.C.

{
    LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lparam;
    LPENUMNODE lpNode = (LPENUMNODE) lpdis->itemData;
    HBITMAP hbmpOld = NULL;
    HDC hdcMem = NULL;
    HBRUSH hbrush;
    COLORREF crefOldText;
    COLORREF crefOldBk;
    UINT nTop;
    UINT nIndent = 0;
    TCHAR szWorking[] = TEXT("Working...");
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];
    UINT nHighlight = 0;
    LPTLSOBJECT lpTls;

    // If this isn't the correct dialog item, skip this message
    if ( (UINT) wparam != IDL_BROWSE )
        return FALSE;

    // If there are no list box items, skip this message.
    if (lpdis->itemID == -1)
        return FALSE;

    switch (lpdis->itemAction)
    {
        case ODA_SELECT:
        case ODA_DRAWENTIRE:

            // if we're still doing the initial enumeration
            if ( (LONG) lpNode == WORKING )
            {
                TextOut(lpdis->hDC, 2, 2, szWorking, _tcslen(szWorking) );
            }
            else
            {
                lpTls = TlsGetValue(ndxTls);

                // compute indent for list item
                switch( lpNode->lpNet->dwDisplayType )
                {
                    case RESOURCEDISPLAYTYPE_GENERIC:
                        nIndent = 0;
                        break;

                    case RESOURCEDISPLAYTYPE_DOMAIN:
                        nIndent = BITMAP_WIDTH;
                        break;

                    case RESOURCEDISPLAYTYPE_SERVER:
                        nIndent = 2 * BITMAP_WIDTH;
                        break;
                }

                // Create MemDC for bitmap
                hdcMem = CreateCompatibleDC(lpdis->hDC);

                // Is the item selected?
                if (lpdis->itemState & ODS_SELECTED)
                {
                    hbmpOld = SelectObject(hdcMem, lpTls->hbmpArray[lpNode->ndxBmp+HIGHLIGHT_NDX]);
                    hbrush = lpTls->hbrushHL;
                    crefOldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT) );
                    crefOldBk = SetBkColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT) );
                }
                else
                {
                    hbmpOld = SelectObject(hdcMem, lpTls->hbmpArray[lpNode->ndxBmp]);
                    hbrush = GetStockObject( WHITE_BRUSH );
                    crefOldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT) );
                    crefOldBk = SetBkColor( lpdis->hDC, GetSysColor(COLOR_WINDOW) );
                }

                // Draw background
                FillRect( lpdis->hDC,
                          &(lpdis->rcItem),
                          hbrush );

                // Display bitmap
                nTop = (lpdis->rcItem.bottom + lpdis->rcItem.top - BITMAP_HEIGHT) / 2;
                BitBlt(lpdis->hDC,
                       lpdis->rcItem.left+nIndent,
                       nTop,
                       lpdis->rcItem.right - lpdis->rcItem.left,
                       lpdis->rcItem.bottom - lpdis->rcItem.top,
                       hdcMem, 0, 0, SRCCOPY);

                // Display the text associated with the item. */
                nTop = (lpdis->rcItem.bottom + lpdis->rcItem.top - lpTls->tm.tmHeight) / 2;
                TextOut(lpdis->hDC,
                    BITMAP_WIDTH + nIndent + 4,
                    nTop,
                    lpNode->lpNet->lpRemoteName,
                    _tcslen(lpNode->lpNet->lpRemoteName) );

                // Display comment if there is one
                if ( lpNode->lpNet->lpComment )
                {
                    TextOut(lpdis->hDC,
                        lpdis->rcItem.right/2,
                        nTop,
                        lpNode->lpNet->lpComment,
                        _tcslen(lpNode->lpNet->lpComment) );
                }

                SetBkColor( lpdis->hDC, crefOldBk );
                SetTextColor( lpdis->hDC, crefOldText );
                SelectObject(hdcMem, hbmpOld);

                DeleteDC(hdcMem);
            }
            break;

        case ODA_FOCUS: // taks appropriate measures if item has focus
            if ( (LONG) lpNode != WORKING )
            {
                DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );

                if (lpdis->itemState & ODS_FOCUS)
                {
                    if ( lpNode->lpNet->dwDisplayType == RESOURCEDISPLAYTYPE_SERVER )
                    {
                        _tcscpy( szServer, TEXT("\\\\") );
                        _tcscat( szServer, lpNode->lpNet->lpRemoteName );
                    }
                    else
                    {
                        *szServer = TEXT('\0');
                    }
                    SetDlgItemText( hdlg, IDE_SERVER, szServer );
                }
            }
            break;
    }

    return TRUE;
}

LRESULT MsgEnumDlgEnumExpand | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 304 of file ENUMDLG.C.

{
    LPENUMNODE lpNode = (LPENUMNODE) lparam;
    UINT cChild;
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );

    SetCursor( LoadCursor( NULL, IDC_WAIT ) );
    SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );

    cChild = lpNode->cChild;
    while( cChild-- )
    {
        // all of these bitmaps default to not expanded
        switch( lpNode->lpChild[cChild].lpNet->dwDisplayType )
        {
            case RESOURCEDISPLAYTYPE_DOMAIN:
                lpNode->lpChild[cChild].ndxBmp = DOM_NDX;
                break;

            case RESOURCEDISPLAYTYPE_SERVER:
                lpNode->lpChild[cChild].ndxBmp = SERV_NDX;
                break;
        }

        SendMessage( hwndBrowse, LB_INSERTSTRING, wparam+1, (LPARAM) &(lpNode->lpChild[cChild]) );

    }

    EnableWindow( GetDlgItem( hdlg, IDT_SELECT), TRUE );
    SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
    SetCursor( LoadCursor( NULL, IDC_ARROW ) );
    return TRUE;
}

LRESULT MsgEnumDlgInit | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 157 of file ENUMDLG.C.

{
    HANDLE hThread;
    DWORD tID;
    DWORD dwRet;
    RECT rect;
    HWND hwndBrowse;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    // create and initialize syncronization object
    if ( ERROR_SUCCESS == ( dwRet = MallocMem( &(lpTls->lpSync), sizeof( ENUMSYNC ) ) ) )
    {
        lpTls->lpSync->hwnd = hdlg;
        lpTls->lpSync->cThread = 1;
        lpTls->lpSync->cNetBuf = 0;
        lpTls->lpSync->lplpnetBuf = NULL;
        lpTls->lpSync->lpRoot = NULL;

        InitializeCriticalSection( &(lpTls->lpSync->cs) );

        // create root node and start enumeration thread
        if( ERROR_SUCCESS == ( dwRet = MallocMem( &(lpTls->lpSync->lpRoot), sizeof( ENUMNODE ) ) ) )
        {
            lpTls->lpSync->lpRoot->lpNet = NULL;
            lpTls->lpSync->lpRoot->cChild = 0;
            lpTls->lpSync->lpRoot->lpChild = NULL;

            lpTls->lpSync->cThread++;
            if ( ( hThread = CreateThread(NULL, 100,
                                         (LPTHREAD_START_ROUTINE)InitialEnumThread,
                                         (LPVOID) lpTls->lpSync,
                                         0, &tID) ) == NULL )
            {
                lpTls->lpSync->cThread--;
                dwRet = ERROR_FAILURE;
            }
            else
            {
                MarkOutstanding( &hThread ); // add thread to outstanding list

                // perform UI initialization
                LoadBitmapArray( lpTls->hbmpArray );
                lpTls->hbrushHL = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT) );

                hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );

                GetClientRect( hwndBrowse, &rect );

                lpTls->lpfnListProc = (WNDPROC) SetWindowLong( hwndBrowse, GWL_WNDPROC, (LONG) ListSubProc );
                SendMessage( hwndBrowse, LB_ADDSTRING, 0L, (LPARAM) WORKING );
                SendMessage( hwndBrowse, WM_SETFONT, (WPARAM) lpTls->hfont, 0 );

                SendDlgItemMessage( hdlg, IDE_SERVER, EM_LIMITTEXT, MAX_COMPUTERNAME_LENGTH, 0 );
                SendDlgItemMessage( hdlg, IDE_SERVER, WM_SETFONT, (WPARAM) lpTls->hfont, 0 );

                EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );

                if ( lpTls->lpfnHelpProc == NULL )
                    EnableWindow( GetDlgItem( hdlg, IDB_HELP), FALSE );

                // Center the dialog over the application window
                CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));

            }
        }
    }

    if ( dwRet != ERROR_SUCCESS )
    {
        // deallocation occurs in the WM_DESTROY message handler
        EndDialog(hdlg, ERROR_NOT_ENOUGH_MEMORY);
    }

    return TRUE;
}

LRESULT MsgEnumDlgInitEnum | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 250 of file ENUMDLG.C.

{
    UINT ndx;
    TCHAR szServer[MAX_COMPUTERNAME_LENGTH+3] = TEXT("\\\\");
    TCHAR szTemp[MAX_COMPUTERNAME_LENGTH+3];
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    SetCursor( LoadCursor( NULL, IDC_WAIT ) );
    SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
    SendMessage( hwndBrowse, LB_RESETCONTENT, 0L, 0L );

    // recursively add tree to listbox, looking for the listbox index
    // of the local machine along the way
    ndx = MAX_COMPUTERNAME_LENGTH+1;
    GetComputerName( szServer+2, &ndx );
    ndx = EnumListRecurse( hwndBrowse, lpTls->lpSync->lpRoot, szServer+2);

    // check to see if the user has typed in a server name
    // before reseting the edit control
    GetDlgItemText( hdlg, IDE_SERVER, szTemp, MAX_COMPUTERNAME_LENGTH+3);
    if ( *szTemp == TEXT('\0') )  // the user has not typed anything yet
    {
        SetDlgItemText( hdlg, IDE_SERVER, szServer );
    }

    SendMessage( hwndBrowse, LB_SETTOPINDEX, ndx, 0 );
    SendMessage( hwndBrowse, LB_SETCURSEL, ndx, 0 );

    EnableWindow( GetDlgItem( hdlg, IDT_SELECT), TRUE );
    SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
    SetCursor( LoadCursor( NULL, IDC_ARROW ) );

    return TRUE;
}

LRESULT MsgEnumDlgMeasureItem | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 356 of file ENUMDLG.C.

{
    LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lparam;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    lpmis->itemHeight = MAX( lpTls->tm.tmHeight, BITMAP_HEIGHT ) ;

    return TRUE;
}

LRESULT MsgEnumDlgSetCursor | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 689 of file ENUMDLG.C.

{
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
    LPTLSOBJECT lpTls;

    if ( (HWND)wparam == hwndBrowse )
    {
        lpTls = TlsGetValue(ndxTls);

        if ( lpTls->lpSync->cThread > 1 )
            SetCursor( LoadCursor( NULL, IDC_WAIT ) );
        else
            SetCursor( LoadCursor( NULL, IDC_ARROW ) );
        return TRUE;
    }

    return FALSE;
}

LRESULT MsgEnumDlgSysColor | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 726 of file ENUMDLG.C.

{
    UINT ndx = HIGHLIGHT_NDX*2;
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    while( ndx-- )
        DeleteObject( lpTls->hbmpArray[ndx] );

    LoadBitmapArray( lpTls->hbmpArray );

    DeleteObject( lpTls->hbrushHL );
    lpTls->hbrushHL = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT) );

    return TRUE;
}

LRESULT MsgEnumDlgVKeyToItem | ( | HWND | hdlg,
 |  | UINT | uMessage,
 |  | WPARAM | wparam,
 |  | LPARAM | lparam
 | ) |  |

Definition at line 541 of file ENUMDLG.C.

{
    int nCur;
    int nCount;
    int nItemsPerPage;
    LPTLSOBJECT lpTls;
    HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
    RECT rect;

    if ( (HWND)lparam == hwndBrowse )
    {

        lpTls = TlsGetValue(ndxTls);
        nCur = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
        nCount = SendMessage( hwndBrowse, LB_GETCOUNT, 0, 0 );
        GetClientRect( hwndBrowse, &rect );
        nItemsPerPage = rect.bottom / ( MAX( lpTls->tm.tmHeight, BITMAP_HEIGHT ) );

        if ( nCount != 0 )
        {
            switch( LOWORD(wparam) )
            {
                case VK_HOME:
                    SendMessage( hwndBrowse, LB_SETCURSEL, 0, 0 );
                    break;

                case VK_END:
                    SendMessage( hwndBrowse, LB_SETCURSEL, nCount-1, 0 );
                    break;

                case VK_UP:
                    SendMessage( hwndBrowse, LB_SETCURSEL, MAX( nCur-1, 0 ), 0 );
                    break;

                case VK_DOWN:
                    SendMessage( hwndBrowse, LB_SETCURSEL, MIN( nCur+1, nCount-1 ), 0 );
                    break;

                case VK_PRIOR:
                    SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
                    SendMessage( hwndBrowse, LB_SETCURSEL, MAX( nCur-nItemsPerPage, 0 ), 0 );
                    SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
                    break;

                case VK_NEXT:
                    SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
                    SendMessage( hwndBrowse, LB_SETCURSEL, MIN( nCur+nItemsPerPage, nCount-1 ), 0 );
                    SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
                    break;

                default:
                    return -1;
            }
            return -2;
        }
    }
    return -1;
}

Variable Documentation

CMDI cmdiEnumDlg
Initial value:
{
    sizeof(rgcmdEnumDlg) / sizeof(CMD),
    rgcmdEnumDlg,
    edwpNone
}

Definition at line 106 of file ENUMDLG.C.

MSDI msdiEnumDlg
Initial value:
{
    sizeof(rgmsdEnumDlg) / sizeof(MSD),
    rgmsdEnumDlg,
    edwpNone
}

Definition at line 90 of file ENUMDLG.C.

DWORD ndxTls

Definition at line 31 of file SERVENUM.C.

CMD rgcmdEnumDlg[]
Initial value:
{
    {IDOK,       CmdEnumDlgOK},
    {IDCANCEL,   CmdEnumDlgCancel},
    {IDB_HELP,   CmdEnumDlgHelp},
    {IDL_BROWSE, CmdEnumDlgBrowse}
}

Definition at line 98 of file ENUMDLG.C.

MSD rgmsdEnumDlg[]
Initial value:
{
    {WM_INITDIALOG,     MsgEnumDlgInit},
    {WM_INIT_ENUM,      MsgEnumDlgInitEnum},
    {WM_ENUM_EXPAND,    MsgEnumDlgEnumExpand},
    {WM_MEASUREITEM,    MsgEnumDlgMeasureItem},
    {WM_DRAWITEM,       MsgEnumDlgDrawItem},
    {WM_VKEYTOITEM,     MsgEnumDlgVKeyToItem},
    {WM_CHARTOITEM,     MsgEnumDlgCharToItem},
    {WM_SETCURSOR,      MsgEnumDlgSetCursor},
    {WM_SYSCOLORCHANGE, MsgEnumDlgSysColor},
    {WM_COMMAND,        MsgEnumDlgCommand},
    {WM_DESTROY,        MsgEnumDlgDestroy}
}

Definition at line 75 of file ENUMDLG.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMDLG.H File Reference

  • SERVENUM
  • DLL
Defines | Functions

ENUMDLG.H File Reference

Go to the source code of this file.

Defines

#define | DOMAIN_BMP 501
#define | DOMAINEX_BMP 502
#define | IDB_HELP 402
#define | IDC_STATIC -1
#define | IDE_SERVER 400
#define | IDL_BROWSE 401
#define | IDT_SELECT 403
#define | PROVIDER_BMP 503
#define | PROVIDEREX_BMP 504
#define | SERVER_BMP 500
#define | WM_ENUM_EXPAND WM_USER+101
#define | WM_INIT_ENUM WM_USER+100
#define | WORKING -1

Functions

LRESULT CALLBACK | EnumDlg (HWND, UINT, WPARAM, LPARAM)
LRESULT APIENTRY | ListSubProc (HWND, UINT, WPARAM, LPARAM)

Define Documentation

#define DOMAIN_BMP 501

Definition at line 28 of file ENUMDLG.H.

#define DOMAINEX_BMP 502

Definition at line 29 of file ENUMDLG.H.

#define IDB_HELP 402

Definition at line 21 of file ENUMDLG.H.

#define IDC_STATIC -1

Definition at line 23 of file ENUMDLG.H.

#define IDE_SERVER 400

Definition at line 19 of file ENUMDLG.H.

#define IDL_BROWSE 401

Definition at line 20 of file ENUMDLG.H.

#define IDT_SELECT 403

Definition at line 22 of file ENUMDLG.H.

#define PROVIDER_BMP 503

Definition at line 30 of file ENUMDLG.H.

#define PROVIDEREX_BMP 504

Definition at line 31 of file ENUMDLG.H.

#define SERVER_BMP 500

Definition at line 27 of file ENUMDLG.H.

#define WM_ENUM_EXPAND WM_USER+101

Definition at line 25 of file ENUMDLG.H.

#define WM_INIT_ENUM WM_USER+100

Definition at line 24 of file ENUMDLG.H.

#define WORKING -1

Definition at line 33 of file ENUMDLG.H.

Function Documentation

LRESULT CALLBACK EnumDlg | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 133 of file ENUMDLG.C.

{
    return DispMessage(&msdiEnumDlg, hdlg, uMessage, wparam, lparam);
}

LRESULT APIENTRY ListSubProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 994 of file ENUMDLG.C.

{
    LPTLSOBJECT lpTls = TlsGetValue(ndxTls);

    switch (uMessage)
    {
        case WM_SETCURSOR:
            SendMessage( GetParent(hwnd), WM_SETCURSOR, (WPARAM) hwnd, MAKELONG( HTCLIENT, 0 ) );
            break;

        case WM_GETDLGCODE:
            return DLGC_WANTALLKEYS | CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);

        default:
            return CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);
    }
    return (0);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMTHRD.C File Reference

  • SERVENUM
  • DLL
Functions

ENUMTHRD.C File Reference

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <lm.h>
#include "enumutil.h"
#include "enumthrd.h"
#include "enumdlg.h"
#include "mem.h"

Go to the source code of this file.

Functions

DWORD WINAPI | EnumContainerThread (LPENUMOBJECT lpObject)
DWORD WINAPI | EnumExpandThread (LPENUMLISTOBJECT lpListObject)
DWORD WINAPI | InitialEnumThread (LPENUMSYNC lpSync)

Function Documentation

DWORD WINAPI EnumContainerThread ( LPENUMOBJECT lpObject )

Definition at line 333 of file ENUMTHRD.C.

{
    DWORD  dwRet = ERROR_SUCCESS;
    HANDLE hEnum;
    DWORD  cTotal = 0;

    DWORD       cChild = 0; // count of children
    LPENUMNODE  lpenChild = NULL;

    DWORD cNetBuf = 0; // count of net buffers
    LPNETRESOURCE * lplpnetBuf = NULL; // array of enumerated buffers

    if ( lpObject->lpNode->cChild == 0 )
    {
        dwRet  = WNetOpenEnum( RESOURCE_GLOBALNET,
                               RESOURCETYPE_ANY,
                               RESOURCEUSAGE_CONTAINER,
                               lpObject->lpNode->lpNet,
                               &hEnum );

        if ( dwRet == NO_ERROR )
        {
            while ( dwRet == NO_ERROR )
            {
                DWORD  cEntries =  (DWORD)-1;  // as many entries as will fit
                DWORD  cbBuf = 8192;

                // allocate pointer for buffer
                if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lplpnetBuf, ++cNetBuf*sizeof(LPNETRESOURCE) ) ) )
                    break;

                // allocate buffer
                if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = MallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf ) ) )
                    break;

                if ( NO_ERROR == (dwRet = WNetEnumResource( hEnum, &cEntries, lplpnetBuf[cNetBuf-1], &cbBuf ) ) )
                {
                    // reallocate buffer to size needed
                    if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf) ) )
                        break;

                    // allocate array of ENUMNODEs
                    if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lpenChild, (cChild+cEntries)*sizeof(ENUMNODE) ) ) )
                        break;

                    while( cEntries-- )
                    {   // remote any leading \\'s
                        while( *((lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName) == '\\' )
                            (lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName++;

                        lpenChild[cChild].lpNet = lplpnetBuf[cNetBuf-1]+cEntries;
                        lpenChild[cChild].cChild = 0;
                        lpenChild[cChild].lpChild = NULL;
                        cChild++;
                    }
                }
                else
                {
                    cNetBuf--;
                    FreeMem( (LPVOID *) (lplpnetBuf+cNetBuf) );
                    // this will never fail because we shrink the buffer
                    ReallocMem( (LPVOID *) &lplpnetBuf, cNetBuf*sizeof(LPNETRESOURCE) );
                }

            }
            WNetCloseEnum( hEnum );

            if ( ( dwRet == ERROR_NO_MORE_ITEMS ) && cNetBuf )
            {
                qsort( (void *)lpenChild, (size_t)cChild, sizeof(ENUMNODE), CompareEnumNode );

                lpObject->lpNode->cChild = cChild;
                lpObject->lpNode->lpChild = lpenChild;

                EnterCriticalSection( &(lpObject->lpSync->cs) );
                    if ( ERROR_SUCCESS ==
                          ( dwRet = ReallocMem((LPVOID *) &(lpObject->lpSync->lplpnetBuf),
                                               (lpObject->lpSync->cNetBuf+cNetBuf)*sizeof(LPNETRESOURCE) ) ) )
                    {
                        while( cNetBuf-- )
                            lpObject->lpSync->lplpnetBuf[lpObject->lpSync->cNetBuf++] = lplpnetBuf[cNetBuf];
                    }
                LeaveCriticalSection( &(lpObject->lpSync->cs) );
            }

            if ( dwRet == ERROR_NOT_ENOUGH_MEMORY )
            {
                if ( lplpnetBuf != NULL )
                {
                    while( cNetBuf-- )
                        FreeMem( (LPVOID *) lplpnetBuf+cNetBuf );

                    FreeMem( (LPVOID *) &lpenChild );
                }
            }

            // because we made a copy of this buffer, we can free it
            FreeMem( (LPVOID *) &lplpnetBuf );

        }
    }

    FreeEnumSync( &(lpObject->lpSync) );

    return dwRet;
}

DWORD WINAPI EnumExpandThread ( LPENUMLISTOBJECT lpListObject )

Definition at line 298 of file ENUMTHRD.C.

{
    DWORD dwRet;

    InterlockedIncrement( &((LONG)lpListObject->Object.lpSync->cThread) );
    dwRet = EnumContainerThread( &(lpListObject->Object) );

    FreeEnumSync( &(lpListObject->Object.lpSync) );

    if ( lpListObject->Object.lpSync )
        PostMessage( lpListObject->Object.lpSync->hwnd,
                     WM_ENUM_EXPAND,
                     (WPARAM) lpListObject->nItem,
                     (LPARAM) lpListObject->Object.lpNode );

    FreeMem( &lpListObject );

    return dwRet;
}

DWORD WINAPI InitialEnumThread ( LPENUMSYNC lpSync )

Definition at line 68 of file ENUMTHRD.C.

{
    DWORD dwRet = ERROR_SUCCESS;
    DWORD dwTemp = ERROR_SUCCESS;
    DWORD dwWait;
    LPWKSTA_INFO_100 lpWksta = NULL;
    HKEY  hkey;
    DWORD cbProv = 0;
    TCHAR *lpProv = NULL;
    HANDLE lpHandles[NUM_HANDLES] = { INVALID_HANDLE_VALUE,
                                      INVALID_HANDLE_VALUE,
                                      INVALID_HANDLE_VALUE };
    DWORD  tID;
    ENUMOBJECT eo_prov;
    ENUMOBJECT eo_dom;
    ENUMOBJECT eo_serv;
    NETRESOURCE netr_dom;
    NETRESOURCE netr_serv;
    ENUMNODE en_dom;
    ENUMNODE en_serv;
    DWORD ndx;

    //***  enumerate the network providers  ***//
    eo_prov.lpSync = lpSync;
    eo_prov.lpNode = lpSync->lpRoot;

    // start provider enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_PROV]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_prov,
                                     0, &tID) ) == NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** enumerate the domains ***//
    // get the LanmanWorkstation provider name from registry
    if ( ERROR_SUCCESS == ( dwRet = RegOpenKey( HKEY_LOCAL_MACHINE,
                        TEXT("System\\CurrentControlSet\\Services\\LanmanWorkstation\\NetworkProvider"),
                        &hkey ) ) )
    {
        if ( ERROR_SUCCESS == (dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, NULL, &cbProv ) ) )
        {
            if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpProv, cbProv ) ) )
            {
                dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, (LPBYTE) lpProv, &cbProv );
            }
        }

        RegCloseKey( hkey );
    }
    if ( dwRet != ERROR_SUCCESS )
    {
        goto Cleanup;
    }

    // setup netresource structure from domain enumeration
    netr_dom.lpRemoteName = lpProv;
    netr_dom.dwScope = RESOURCE_GLOBALNET;
    netr_dom.dwType = RESOURCETYPE_ANY;
    netr_dom.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
    netr_dom.dwUsage = RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED;
    netr_dom.lpLocalName = NULL;
    netr_dom.lpComment = NULL;
    netr_dom.lpProvider = lpProv;

    en_dom.lpNet = &netr_dom;
    en_dom.cChild = 0;
    en_dom.lpChild = NULL;

    eo_dom.lpSync = lpSync;
    eo_dom.lpNode = &en_dom;

    // start domain enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_DOM]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_dom,
                                     0, &tID) )== NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** enumerate servers ***/
    // get the domain for this server, then enumerate to get servers
    if ( NERR_Success != NetWkstaGetInfo(NULL, 100, (LPBYTE *) &lpWksta) )
    {
        dwRet = ERROR_FAILURE;
        goto Cleanup;
    }

    // setup netresource structure
    netr_serv.lpRemoteName = lpWksta->wki100_langroup;
    netr_serv.dwScope = RESOURCE_GLOBALNET;
    netr_serv.dwType = RESOURCETYPE_ANY;
    netr_serv.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;
    netr_serv.dwUsage = RESOURCEUSAGE_CONTAINER;
    netr_serv.lpLocalName = NULL;
    netr_serv.lpComment = NULL;
    netr_serv.lpProvider = NULL;

    en_serv.lpNet = &netr_serv;
    en_serv.cChild = 0;
    en_serv.lpChild = NULL;

    eo_serv.lpSync = lpSync;
    eo_serv.lpNode = &en_serv;

    // start server enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_SERV]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_serv,
                                     0, &tID) )== NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** all threads started - now wait for them
    if ( (dwWait = WaitForMultipleObjects( NUM_HANDLES, lpHandles, TRUE, INFINITE ) ) == WAIT_FAILED )
    {
        dwRet = dwWait;
        goto Cleanup;
    }

    // if an error occuring during top level enum, there's
    // no hope, so shut down and signal error
    GetExitCodeThread( lpHandles[HANDLE_PROV], &dwRet );
    if ( dwRet == ERROR_SUCCESS )
    {
        GetExitCodeThread( lpHandles[HANDLE_DOM], &dwRet );
        if ( dwRet == ERROR_SUCCESS )
        {
            // now we just need to attach the domain list to the appropriate provider
            for ( ndx = 0; ndx < lpSync->lpRoot->cChild; ndx++ )
            {
                if ( _tcscmp( lpSync->lpRoot->lpChild[ndx].lpNet->lpRemoteName,
                              lpProv ) == 0 )
                {
                    lpSync->lpRoot->lpChild[ndx].lpChild = en_dom.lpChild;
                    lpSync->lpRoot->lpChild[ndx].cChild = en_dom.cChild;
                    break;
                }
            }

            GetExitCodeThread( lpHandles[HANDLE_SERV], &dwRet );
            if ( dwRet == ERROR_SUCCESS )
            {
                // now we just need to attach the server list to the appropriate domain
                for ( ndx = 0; ndx < eo_dom.lpNode->cChild; ndx++ )
                    if ( _tcscmp( eo_dom.lpNode->lpChild[ndx].lpNet->lpRemoteName,
                                 lpWksta->wki100_langroup ) == 0 )
                    {
                        eo_dom.lpNode->lpChild[ndx].lpChild = en_serv.lpChild;
                        eo_dom.lpNode->lpChild[ndx].cChild = en_serv.cChild;
                        break;
                    }
            }
        }
        else  // domain enumeration failed so free server memory
        {
            GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
            if ( dwTemp == ERROR_SUCCESS )
                FreeEnumChild( &en_serv );
        }
    }
    else // provider enumeration failed
    {
        GetExitCodeThread( lpHandles[HANDLE_DOM], &dwTemp );
        if ( dwTemp == ERROR_SUCCESS )
            FreeEnumChild( &en_dom );

        GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
        if ( dwTemp == ERROR_SUCCESS )
            FreeEnumChild( &en_serv );

    }

    Cleanup:
        if ( lpHandles[HANDLE_SERV] )
            CloseHandle( lpHandles[HANDLE_SERV] );

        if ( lpWksta )
            NetApiBufferFree(lpWksta);

        if ( lpHandles[HANDLE_DOM] )
            CloseHandle( lpHandles[HANDLE_DOM] );

        if ( lpProv )
            FreeMem( (LPVOID *) &lpProv );

        if ( lpHandles[HANDLE_PROV] )
            CloseHandle( lpHandles[HANDLE_PROV] );

        FreeEnumSync( &lpSync );
        if ( lpSync ) // if this is NULL, the dialog box doesn't exist anymore
            PostMessage( lpSync->hwnd, WM_INIT_ENUM, 0, 0 );

    return dwRet;

}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMTHRD.H File Reference

  • SERVENUM
  • DLL
Defines | Functions

ENUMTHRD.H File Reference

Go to the source code of this file.

Defines

#define | ERROR_FAILURE 1
#define | HANDLE_DOM 1
#define | HANDLE_PROV 0
#define | HANDLE_SERV 2
#define | NUM_HANDLES 3

Functions

DWORD WINAPI | EnumContainerThread (LPENUMOBJECT lpObject)
DWORD WINAPI | EnumExpandThread (LPENUMLISTOBJECT lpObject)
DWORD WINAPI | InitialEnumThread (LPENUMSYNC lpSync)

Define Documentation

#define ERROR_FAILURE 1

Definition at line 19 of file ENUMTHRD.H.

#define HANDLE_DOM 1

Definition at line 22 of file ENUMTHRD.H.

#define HANDLE_PROV 0

Definition at line 21 of file ENUMTHRD.H.

#define HANDLE_SERV 2

Definition at line 23 of file ENUMTHRD.H.

#define NUM_HANDLES 3

Definition at line 24 of file ENUMTHRD.H.

Function Documentation

DWORD WINAPI EnumContainerThread ( LPENUMOBJECT lpObject )

Definition at line 333 of file ENUMTHRD.C.

{
    DWORD  dwRet = ERROR_SUCCESS;
    HANDLE hEnum;
    DWORD  cTotal = 0;

    DWORD       cChild = 0; // count of children
    LPENUMNODE  lpenChild = NULL;

    DWORD cNetBuf = 0; // count of net buffers
    LPNETRESOURCE * lplpnetBuf = NULL; // array of enumerated buffers

    if ( lpObject->lpNode->cChild == 0 )
    {
        dwRet  = WNetOpenEnum( RESOURCE_GLOBALNET,
                               RESOURCETYPE_ANY,
                               RESOURCEUSAGE_CONTAINER,
                               lpObject->lpNode->lpNet,
                               &hEnum );

        if ( dwRet == NO_ERROR )
        {
            while ( dwRet == NO_ERROR )
            {
                DWORD  cEntries =  (DWORD)-1;  // as many entries as will fit
                DWORD  cbBuf = 8192;

                // allocate pointer for buffer
                if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lplpnetBuf, ++cNetBuf*sizeof(LPNETRESOURCE) ) ) )
                    break;

                // allocate buffer
                if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = MallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf ) ) )
                    break;

                if ( NO_ERROR == (dwRet = WNetEnumResource( hEnum, &cEntries, lplpnetBuf[cNetBuf-1], &cbBuf ) ) )
                {
                    // reallocate buffer to size needed
                    if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf) ) )
                        break;

                    // allocate array of ENUMNODEs
                    if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lpenChild, (cChild+cEntries)*sizeof(ENUMNODE) ) ) )
                        break;

                    while( cEntries-- )
                    {   // remote any leading \\'s
                        while( *((lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName) == '\\' )
                            (lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName++;

                        lpenChild[cChild].lpNet = lplpnetBuf[cNetBuf-1]+cEntries;
                        lpenChild[cChild].cChild = 0;
                        lpenChild[cChild].lpChild = NULL;
                        cChild++;
                    }
                }
                else
                {
                    cNetBuf--;
                    FreeMem( (LPVOID *) (lplpnetBuf+cNetBuf) );
                    // this will never fail because we shrink the buffer
                    ReallocMem( (LPVOID *) &lplpnetBuf, cNetBuf*sizeof(LPNETRESOURCE) );
                }

            }
            WNetCloseEnum( hEnum );

            if ( ( dwRet == ERROR_NO_MORE_ITEMS ) && cNetBuf )
            {
                qsort( (void *)lpenChild, (size_t)cChild, sizeof(ENUMNODE), CompareEnumNode );

                lpObject->lpNode->cChild = cChild;
                lpObject->lpNode->lpChild = lpenChild;

                EnterCriticalSection( &(lpObject->lpSync->cs) );
                    if ( ERROR_SUCCESS ==
                          ( dwRet = ReallocMem((LPVOID *) &(lpObject->lpSync->lplpnetBuf),
                                               (lpObject->lpSync->cNetBuf+cNetBuf)*sizeof(LPNETRESOURCE) ) ) )
                    {
                        while( cNetBuf-- )
                            lpObject->lpSync->lplpnetBuf[lpObject->lpSync->cNetBuf++] = lplpnetBuf[cNetBuf];
                    }
                LeaveCriticalSection( &(lpObject->lpSync->cs) );
            }

            if ( dwRet == ERROR_NOT_ENOUGH_MEMORY )
            {
                if ( lplpnetBuf != NULL )
                {
                    while( cNetBuf-- )
                        FreeMem( (LPVOID *) lplpnetBuf+cNetBuf );

                    FreeMem( (LPVOID *) &lpenChild );
                }
            }

            // because we made a copy of this buffer, we can free it
            FreeMem( (LPVOID *) &lplpnetBuf );

        }
    }

    FreeEnumSync( &(lpObject->lpSync) );

    return dwRet;
}

DWORD WINAPI EnumExpandThread ( LPENUMLISTOBJECT lpObject )

Definition at line 298 of file ENUMTHRD.C.

{
    DWORD dwRet;

    InterlockedIncrement( &((LONG)lpListObject->Object.lpSync->cThread) );
    dwRet = EnumContainerThread( &(lpListObject->Object) );

    FreeEnumSync( &(lpListObject->Object.lpSync) );

    if ( lpListObject->Object.lpSync )
        PostMessage( lpListObject->Object.lpSync->hwnd,
                     WM_ENUM_EXPAND,
                     (WPARAM) lpListObject->nItem,
                     (LPARAM) lpListObject->Object.lpNode );

    FreeMem( &lpListObject );

    return dwRet;
}

DWORD WINAPI InitialEnumThread ( LPENUMSYNC lpSync )

Definition at line 68 of file ENUMTHRD.C.

{
    DWORD dwRet = ERROR_SUCCESS;
    DWORD dwTemp = ERROR_SUCCESS;
    DWORD dwWait;
    LPWKSTA_INFO_100 lpWksta = NULL;
    HKEY  hkey;
    DWORD cbProv = 0;
    TCHAR *lpProv = NULL;
    HANDLE lpHandles[NUM_HANDLES] = { INVALID_HANDLE_VALUE,
                                      INVALID_HANDLE_VALUE,
                                      INVALID_HANDLE_VALUE };
    DWORD  tID;
    ENUMOBJECT eo_prov;
    ENUMOBJECT eo_dom;
    ENUMOBJECT eo_serv;
    NETRESOURCE netr_dom;
    NETRESOURCE netr_serv;
    ENUMNODE en_dom;
    ENUMNODE en_serv;
    DWORD ndx;

    //***  enumerate the network providers  ***//
    eo_prov.lpSync = lpSync;
    eo_prov.lpNode = lpSync->lpRoot;

    // start provider enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_PROV]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_prov,
                                     0, &tID) ) == NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** enumerate the domains ***//
    // get the LanmanWorkstation provider name from registry
    if ( ERROR_SUCCESS == ( dwRet = RegOpenKey( HKEY_LOCAL_MACHINE,
                        TEXT("System\\CurrentControlSet\\Services\\LanmanWorkstation\\NetworkProvider"),
                        &hkey ) ) )
    {
        if ( ERROR_SUCCESS == (dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, NULL, &cbProv ) ) )
        {
            if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpProv, cbProv ) ) )
            {
                dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, (LPBYTE) lpProv, &cbProv );
            }
        }

        RegCloseKey( hkey );
    }
    if ( dwRet != ERROR_SUCCESS )
    {
        goto Cleanup;
    }

    // setup netresource structure from domain enumeration
    netr_dom.lpRemoteName = lpProv;
    netr_dom.dwScope = RESOURCE_GLOBALNET;
    netr_dom.dwType = RESOURCETYPE_ANY;
    netr_dom.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
    netr_dom.dwUsage = RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED;
    netr_dom.lpLocalName = NULL;
    netr_dom.lpComment = NULL;
    netr_dom.lpProvider = lpProv;

    en_dom.lpNet = &netr_dom;
    en_dom.cChild = 0;
    en_dom.lpChild = NULL;

    eo_dom.lpSync = lpSync;
    eo_dom.lpNode = &en_dom;

    // start domain enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_DOM]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_dom,
                                     0, &tID) )== NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** enumerate servers ***/
    // get the domain for this server, then enumerate to get servers
    if ( NERR_Success != NetWkstaGetInfo(NULL, 100, (LPBYTE *) &lpWksta) )
    {
        dwRet = ERROR_FAILURE;
        goto Cleanup;
    }

    // setup netresource structure
    netr_serv.lpRemoteName = lpWksta->wki100_langroup;
    netr_serv.dwScope = RESOURCE_GLOBALNET;
    netr_serv.dwType = RESOURCETYPE_ANY;
    netr_serv.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;
    netr_serv.dwUsage = RESOURCEUSAGE_CONTAINER;
    netr_serv.lpLocalName = NULL;
    netr_serv.lpComment = NULL;
    netr_serv.lpProvider = NULL;

    en_serv.lpNet = &netr_serv;
    en_serv.cChild = 0;
    en_serv.lpChild = NULL;

    eo_serv.lpSync = lpSync;
    eo_serv.lpNode = &en_serv;

    // start server enumeration thread
    InterlockedIncrement( &((LONG)lpSync->cThread) );
    if ( ( lpHandles[HANDLE_SERV]=CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumContainerThread,
                                     (LPVOID) &eo_serv,
                                     0, &tID) )== NULL )
    {
        dwRet = ERROR_FAILURE;
        InterlockedDecrement( &((LONG)lpSync->cThread) );
        goto Cleanup;
    }

    //*** all threads started - now wait for them
    if ( (dwWait = WaitForMultipleObjects( NUM_HANDLES, lpHandles, TRUE, INFINITE ) ) == WAIT_FAILED )
    {
        dwRet = dwWait;
        goto Cleanup;
    }

    // if an error occuring during top level enum, there's
    // no hope, so shut down and signal error
    GetExitCodeThread( lpHandles[HANDLE_PROV], &dwRet );
    if ( dwRet == ERROR_SUCCESS )
    {
        GetExitCodeThread( lpHandles[HANDLE_DOM], &dwRet );
        if ( dwRet == ERROR_SUCCESS )
        {
            // now we just need to attach the domain list to the appropriate provider
            for ( ndx = 0; ndx < lpSync->lpRoot->cChild; ndx++ )
            {
                if ( _tcscmp( lpSync->lpRoot->lpChild[ndx].lpNet->lpRemoteName,
                              lpProv ) == 0 )
                {
                    lpSync->lpRoot->lpChild[ndx].lpChild = en_dom.lpChild;
                    lpSync->lpRoot->lpChild[ndx].cChild = en_dom.cChild;
                    break;
                }
            }

            GetExitCodeThread( lpHandles[HANDLE_SERV], &dwRet );
            if ( dwRet == ERROR_SUCCESS )
            {
                // now we just need to attach the server list to the appropriate domain
                for ( ndx = 0; ndx < eo_dom.lpNode->cChild; ndx++ )
                    if ( _tcscmp( eo_dom.lpNode->lpChild[ndx].lpNet->lpRemoteName,
                                 lpWksta->wki100_langroup ) == 0 )
                    {
                        eo_dom.lpNode->lpChild[ndx].lpChild = en_serv.lpChild;
                        eo_dom.lpNode->lpChild[ndx].cChild = en_serv.cChild;
                        break;
                    }
            }
        }
        else  // domain enumeration failed so free server memory
        {
            GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
            if ( dwTemp == ERROR_SUCCESS )
                FreeEnumChild( &en_serv );
        }
    }
    else // provider enumeration failed
    {
        GetExitCodeThread( lpHandles[HANDLE_DOM], &dwTemp );
        if ( dwTemp == ERROR_SUCCESS )
            FreeEnumChild( &en_dom );

        GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
        if ( dwTemp == ERROR_SUCCESS )
            FreeEnumChild( &en_serv );

    }

    Cleanup:
        if ( lpHandles[HANDLE_SERV] )
            CloseHandle( lpHandles[HANDLE_SERV] );

        if ( lpWksta )
            NetApiBufferFree(lpWksta);

        if ( lpHandles[HANDLE_DOM] )
            CloseHandle( lpHandles[HANDLE_DOM] );

        if ( lpProv )
            FreeMem( (LPVOID *) &lpProv );

        if ( lpHandles[HANDLE_PROV] )
            CloseHandle( lpHandles[HANDLE_PROV] );

        FreeEnumSync( &lpSync );
        if ( lpSync ) // if this is NULL, the dialog box doesn't exist anymore
            PostMessage( lpSync->hwnd, WM_INIT_ENUM, 0, 0 );

    return dwRet;

}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMUTIL.C File Reference

  • SERVENUM
  • DLL
Functions | Variables

ENUMUTIL.C File Reference

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>
#include <lm.h>
#include "enumutil.h"
#include "enumthrd.h"
#include "thrdutil.h"
#include "miscutil.h"
#include "mem.h"

Go to the source code of this file.

Functions

int __cdecl | CompareEnumNode (const void *lpNode1, const void *lpNode2)
VOID | EnumListCollapse (HWND hwnd, LPENUMNODE lpNode, UINT ndx)
VOID | EnumListExpand (HWND hwnd, LPENUMSYNC lpSync, LPENUMNODE lpNode, UINT ndx)
UINT | EnumListRecurse (HWND hwnd, LPENUMNODE lpNode, LPTSTR lpServer)
VOID | FreeEnumChild (LPENUMNODE lpNode)
VOID | FreeEnumSync (LPENUMSYNC *lplpSync)
VOID | LoadBitmapArray (HBITMAP *lphbmpArray)

Variables

HMODULE | g_hMod

Function Documentation

int __cdecl CompareEnumNode | ( | const void * | lpNode1,
 |  | const void * | lpNode2
 | ) |  |

Definition at line 123 of file ENUMUTIL.C.

{
    return _tcsicmp( ((LPENUMNODE)lpNode1)->lpNet->lpRemoteName,
                     ((LPENUMNODE)lpNode2)->lpNet->lpRemoteName );
}

VOID EnumListCollapse | ( | HWND | hwnd,
 |  | LPENUMNODE | lpNode,
 |  | UINT | ndx
 | ) |  |

Definition at line 254 of file ENUMUTIL.C.

{
    LPENUMNODE lpChild;
    SetCursor( LoadCursor( NULL, IDC_WAIT ) );
    SendMessage( hwnd, WM_SETREDRAW, FALSE, 0 );

    while ( LB_ERR != SendMessage( hwnd, LB_GETTEXT, (WPARAM) ndx+1, (LPARAM) &lpChild) )
    {
        if ( lpNode->lpNet->dwDisplayType == lpChild->lpNet->dwDisplayType )
            break;
        else
            SendMessage( hwnd, LB_DELETESTRING, ndx+1, 0 );
    }

    SendMessage( hwnd, WM_SETREDRAW, TRUE, 0 );
    SetCursor( LoadCursor( NULL, IDC_ARROW ) );
}

VOID EnumListExpand | ( | HWND | hwnd,
 |  | LPENUMSYNC | lpSync,
 |  | LPENUMNODE | lpNode,
 |  | UINT | ndx
 | ) |  |

Definition at line 208 of file ENUMUTIL.C.

{
    HANDLE hThread;
    DWORD  tID;
    LPENUMLISTOBJECT lpListObject;

    if ( ERROR_SUCCESS == MallocMem( &lpListObject, sizeof( ENUMLISTOBJECT ) ) )
    {
        lpListObject->nItem = ndx;
        lpListObject->Object.lpSync = lpSync;
        lpListObject->Object.lpNode = lpNode;

        InterlockedIncrement( &((LONG)lpSync->cThread) );
        if ( ( hThread = CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumExpandThread,
                                     (LPVOID) lpListObject,
                                     0, &tID) ) == NULL )
        {
            FreeMem( &lpListObject );
            InterlockedDecrement( &((LONG)lpSync->cThread) );
        }
        else
        {
            MarkOutstanding( &hThread ); // add to list of outstanding threads
        }
    }
}

UINT EnumListRecurse | ( | HWND | hwnd,
 |  | LPENUMNODE | lpNode,
 |  | LPTSTR | lpServer
 | ) |  |

Definition at line 145 of file ENUMUTIL.C.

{
    UINT ndx;
    UINT ndxTemp;
    UINT ndxComputer = 0;

    for ( ndx = 0; ndx < lpNode->cChild; ndx++ )
    {
        switch( lpNode->lpChild[ndx].lpNet->dwDisplayType )
        {
            case RESOURCEDISPLAYTYPE_GENERIC:  // network provider
                if ( lpNode->lpChild[ndx].cChild != 0 )
                    lpNode->lpChild[ndx].ndxBmp = PROVEX_NDX;
                else
                    lpNode->lpChild[ndx].ndxBmp = PROV_NDX;

                SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
                    ndxComputer = ndxTemp;
                break;

            case RESOURCEDISPLAYTYPE_DOMAIN:  // domain
                if ( lpNode->lpChild[ndx].cChild != 0 )
                    lpNode->lpChild[ndx].ndxBmp = DOMEX_NDX;
                else
                    lpNode->lpChild[ndx].ndxBmp = DOM_NDX;

                SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
                    ndxComputer = ndxTemp;
                break;

            case RESOURCEDISPLAYTYPE_SERVER:  // server
                lpNode->lpChild[ndx].ndxBmp = SERV_NDX;
                ndxTemp = SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( _tcscmp( lpNode->lpChild[ndx].lpNet->lpRemoteName, lpServer ) == 0 )
                    ndxComputer = ndxTemp;
                break;
        }

    }

    return ndxComputer;
}

VOID FreeEnumChild ( LPENUMNODE lpNode )

Definition at line 94 of file ENUMUTIL.C.

{
    if ( lpNode->cChild )
    {
        while( lpNode->cChild-- )
            FreeEnumChild( lpNode->lpChild + lpNode->cChild );

    FreeMem( (LPVOID *) &(lpNode->lpChild) );
    }
}

VOID FreeEnumSync ( LPENUMSYNC * lplpSync )

Definition at line 54 of file ENUMUTIL.C.

{
    // if usage count is 0 than free object
    if ( InterlockedDecrement( &((LONG)(*lplpSync)->cThread) ) == 0 )
    {
        DeleteCriticalSection( &((*lplpSync)->cs) );

        if ( (*lplpSync)->lpRoot )
        {
            // this frees lpObject->lpNode as well
            FreeEnumChild( (*lplpSync)->lpRoot );
            FreeMem( &((*lplpSync)->lpRoot) );
        }

        if ( (*lplpSync)->cNetBuf )
        {
            while( (*lplpSync)->cNetBuf-- )
                FreeMem( (LPVOID *) ((*lplpSync)->lplpnetBuf + (*lplpSync)->cNetBuf) );

            FreeMem( (LPVOID *) &((*lplpSync)->lplpnetBuf) );
        }

        FreeMem( (LPVOID *) lplpSync );
    }
}

VOID LoadBitmapArray ( HBITMAP * lphbmpArray )

Definition at line 287 of file ENUMUTIL.C.

{
    UINT ndxBmp;

    for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
        lphbmpArray[ndxBmp] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor(COLOR_WINDOW) );

    for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
        lphbmpArray[ndxBmp+HIGHLIGHT_NDX] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor( COLOR_HIGHLIGHT ) );
}

Variable Documentation

HMODULE g_hMod

Definition at line 32 of file SERVENUM.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMUTIL.H File Reference

  • SERVENUM
  • DLL
Data Structures | Defines | Typedefs | Functions

ENUMUTIL.H File Reference

Go to the source code of this file.

Data Structures

struct | _ENUMLISTOBJECT
struct | _ENUMNODE
struct | _ENUMOBJECT
struct | _ENUMSYNC
struct | _TLSOBJECT

Defines

#define | BITMAP_HEIGHT 16
#define | BITMAP_START 500
#define | BITMAP_WIDTH 16
#define | DOM_NDX 1
#define | DOMEX_NDX 2
#define | HIGHLIGHT_NDX 5
#define | PROV_NDX 3
#define | PROVEX_NDX 4
#define | SERV_NDX 0
#define | START_NDX 0

Typedefs

typedef struct _ENUMLISTOBJECT | ENUMLISTOBJECT
typedef struct _ENUMNODE | ENUMNODE
typedef struct _ENUMOBJECT | ENUMOBJECT
typedef struct _ENUMSYNC | ENUMSYNC
typedef struct _ENUMLISTOBJECT * | LPENUMLISTOBJECT
typedef struct _ENUMNODE * | LPENUMNODE
typedef struct _ENUMOBJECT * | LPENUMOBJECT
typedef struct _ENUMSYNC * | LPENUMSYNC
typedef struct _TLSOBJECT * | LPTLSOBJECT
typedef struct _TLSOBJECT | TLSOBJECT

Functions

int __cdecl | CompareEnumNode (const void *lpNode1, const void *lpNode2)
VOID | EnumListCollapse (HWND hwnd, LPENUMNODE lpNode, UINT ndx)
VOID | EnumListExpand (HWND hwnd, LPENUMSYNC lpSync, LPENUMNODE lpNode, UINT ndx)
UINT | EnumListRecurse (HWND hwnd, LPENUMNODE lpNode, LPTSTR lpServer)
VOID | FreeEnumChild (LPENUMNODE lplpNode)
VOID | FreeEnumSync (LPENUMSYNC *lplpSync)
VOID | LoadBitmapArray (HBITMAP *lphbmpArray)

Define Documentation

#define BITMAP_HEIGHT 16

Definition at line 22 of file ENUMUTIL.H.

#define BITMAP_START 500

Definition at line 20 of file ENUMUTIL.H.

#define BITMAP_WIDTH 16

Definition at line 23 of file ENUMUTIL.H.

#define DOM_NDX 1

Definition at line 27 of file ENUMUTIL.H.

#define DOMEX_NDX 2

Definition at line 28 of file ENUMUTIL.H.

#define HIGHLIGHT_NDX 5

Definition at line 31 of file ENUMUTIL.H.

#define PROV_NDX 3

Definition at line 29 of file ENUMUTIL.H.

#define PROVEX_NDX 4

Definition at line 30 of file ENUMUTIL.H.

#define SERV_NDX 0

Definition at line 26 of file ENUMUTIL.H.

#define START_NDX 0

Definition at line 25 of file ENUMUTIL.H.

Typedef Documentation

typedef struct _ENUMLISTOBJECT ENUMLISTOBJECT
typedef struct _ENUMNODE ENUMNODE
typedef struct _ENUMOBJECT ENUMOBJECT
typedef struct _ENUMSYNC ENUMSYNC
typedef struct _ENUMLISTOBJECT * LPENUMLISTOBJECT
typedef struct _ENUMNODE * LPENUMNODE
typedef struct _ENUMOBJECT * LPENUMOBJECT
typedef struct _ENUMSYNC * LPENUMSYNC
typedef struct _TLSOBJECT * LPTLSOBJECT
typedef struct _TLSOBJECT TLSOBJECT

Function Documentation

int __cdecl CompareEnumNode | ( | const void * | lpNode1,
 |  | const void * | lpNode2
 | ) |  |

Definition at line 123 of file ENUMUTIL.C.

{
    return _tcsicmp( ((LPENUMNODE)lpNode1)->lpNet->lpRemoteName,
                     ((LPENUMNODE)lpNode2)->lpNet->lpRemoteName );
}

VOID EnumListCollapse | ( | HWND | hwnd,
 |  | LPENUMNODE | lpNode,
 |  | UINT | ndx
 | ) |  |

Definition at line 254 of file ENUMUTIL.C.

{
    LPENUMNODE lpChild;
    SetCursor( LoadCursor( NULL, IDC_WAIT ) );
    SendMessage( hwnd, WM_SETREDRAW, FALSE, 0 );

    while ( LB_ERR != SendMessage( hwnd, LB_GETTEXT, (WPARAM) ndx+1, (LPARAM) &lpChild) )
    {
        if ( lpNode->lpNet->dwDisplayType == lpChild->lpNet->dwDisplayType )
            break;
        else
            SendMessage( hwnd, LB_DELETESTRING, ndx+1, 0 );
    }

    SendMessage( hwnd, WM_SETREDRAW, TRUE, 0 );
    SetCursor( LoadCursor( NULL, IDC_ARROW ) );
}

VOID EnumListExpand | ( | HWND | hwnd,
 |  | LPENUMSYNC | lpSync,
 |  | LPENUMNODE | lpNode,
 |  | UINT | ndx
 | ) |  |

Definition at line 208 of file ENUMUTIL.C.

{
    HANDLE hThread;
    DWORD  tID;
    LPENUMLISTOBJECT lpListObject;

    if ( ERROR_SUCCESS == MallocMem( &lpListObject, sizeof( ENUMLISTOBJECT ) ) )
    {
        lpListObject->nItem = ndx;
        lpListObject->Object.lpSync = lpSync;
        lpListObject->Object.lpNode = lpNode;

        InterlockedIncrement( &((LONG)lpSync->cThread) );
        if ( ( hThread = CreateThread(NULL, 100,
                                     (LPTHREAD_START_ROUTINE)EnumExpandThread,
                                     (LPVOID) lpListObject,
                                     0, &tID) ) == NULL )
        {
            FreeMem( &lpListObject );
            InterlockedDecrement( &((LONG)lpSync->cThread) );
        }
        else
        {
            MarkOutstanding( &hThread ); // add to list of outstanding threads
        }
    }
}

UINT EnumListRecurse | ( | HWND | hwnd,
 |  | LPENUMNODE | lpNode,
 |  | LPTSTR | lpServer
 | ) |  |

Definition at line 145 of file ENUMUTIL.C.

{
    UINT ndx;
    UINT ndxTemp;
    UINT ndxComputer = 0;

    for ( ndx = 0; ndx < lpNode->cChild; ndx++ )
    {
        switch( lpNode->lpChild[ndx].lpNet->dwDisplayType )
        {
            case RESOURCEDISPLAYTYPE_GENERIC:  // network provider
                if ( lpNode->lpChild[ndx].cChild != 0 )
                    lpNode->lpChild[ndx].ndxBmp = PROVEX_NDX;
                else
                    lpNode->lpChild[ndx].ndxBmp = PROV_NDX;

                SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
                    ndxComputer = ndxTemp;
                break;

            case RESOURCEDISPLAYTYPE_DOMAIN:  // domain
                if ( lpNode->lpChild[ndx].cChild != 0 )
                    lpNode->lpChild[ndx].ndxBmp = DOMEX_NDX;
                else
                    lpNode->lpChild[ndx].ndxBmp = DOM_NDX;

                SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
                    ndxComputer = ndxTemp;
                break;

            case RESOURCEDISPLAYTYPE_SERVER:  // server
                lpNode->lpChild[ndx].ndxBmp = SERV_NDX;
                ndxTemp = SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
                if ( _tcscmp( lpNode->lpChild[ndx].lpNet->lpRemoteName, lpServer ) == 0 )
                    ndxComputer = ndxTemp;
                break;
        }

    }

    return ndxComputer;
}

VOID FreeEnumChild ( LPENUMNODE lplpNode )

Definition at line 94 of file ENUMUTIL.C.

{
    if ( lpNode->cChild )
    {
        while( lpNode->cChild-- )
            FreeEnumChild( lpNode->lpChild + lpNode->cChild );

    FreeMem( (LPVOID *) &(lpNode->lpChild) );
    }
}

VOID FreeEnumSync ( LPENUMSYNC * lplpSync )

Definition at line 54 of file ENUMUTIL.C.

{
    // if usage count is 0 than free object
    if ( InterlockedDecrement( &((LONG)(*lplpSync)->cThread) ) == 0 )
    {
        DeleteCriticalSection( &((*lplpSync)->cs) );

        if ( (*lplpSync)->lpRoot )
        {
            // this frees lpObject->lpNode as well
            FreeEnumChild( (*lplpSync)->lpRoot );
            FreeMem( &((*lplpSync)->lpRoot) );
        }

        if ( (*lplpSync)->cNetBuf )
        {
            while( (*lplpSync)->cNetBuf-- )
                FreeMem( (LPVOID *) ((*lplpSync)->lplpnetBuf + (*lplpSync)->cNetBuf) );

            FreeMem( (LPVOID *) &((*lplpSync)->lplpnetBuf) );
        }

        FreeMem( (LPVOID *) lplpSync );
    }
}

VOID LoadBitmapArray ( HBITMAP * lphbmpArray )

Definition at line 287 of file ENUMUTIL.C.

{
    UINT ndxBmp;

    for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
        lphbmpArray[ndxBmp] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor(COLOR_WINDOW) );

    for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
        lphbmpArray[ndxBmp+HIGHLIGHT_NDX] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor( COLOR_HIGHLIGHT ) );
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MACROS.H File Reference

  • SERVENUM
  • DLL
Defines

MACROS.H File Reference

Go to the source code of this file.

Defines

#define | MAX(x, y) (x > y) ? x : y
#define | MIN(x, y) (x > y) ? y : x

Define Documentation

#define MAX | ( | x,
 |  | y |
 | ) |  | (x > y) ? x : y

Definition at line 17 of file MACROS.H.

#define MIN | ( | x,
 |  | y |
 | ) |  | (x > y) ? y : x

Definition at line 18 of file MACROS.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MEM.C File Reference

  • SERVENUM
  • DLL
Functions

MEM.C File Reference

#include <windows.h>
#include <malloc.h>

Go to the source code of this file.

Functions

VOID | FreeMem (LPVOID *lplpv)
DWORD | MallocMem (LPVOID *lplpv, DWORD dwSize)
DWORD | ReallocMem (LPVOID *lplpv, DWORD dwSize)

Function Documentation

VOID FreeMem ( LPVOID * lplpv )

Definition at line 105 of file MEM.C.

{
    free( *lplpv );
    *lplpv = NULL;
#ifdef _DEBUG
    InterlockedDecrement(&dwAlloc);
#endif

}

DWORD MallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 41 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = malloc( dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

    *lplpv = lpTemp;

#ifdef _DEBUG
    InterlockedIncrement(&dwAlloc);
#endif

    return ERROR_SUCCESS;

}

DWORD ReallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 73 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = realloc( *lplpv, dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

#ifdef _DEBUG
    if ( dwSize == 0 )
        InterlockedDecrement(&dwAlloc);
    else if ( *lplpv == NULL )
        InterlockedIncrement(&dwAlloc);
#endif

    *lplpv = lpTemp;

    return ERROR_SUCCESS;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MEM.H File Reference

  • SERVENUM
  • DLL
Functions

MEM.H File Reference

Go to the source code of this file.

Functions

VOID | FreeMem (LPVOID *lplpv)
BOOL | MallocMem (LPVOID *lplpv, DWORD dwSize)
BOOL | ReallocMem (LPVOID *lplpv, DWORD dwSize)

Function Documentation

VOID FreeMem ( LPVOID * lplpv )

Definition at line 119 of file MEM.C.

{
    _ffree( *lplpv );
    *lplpv = NULL;
#ifdef _DEBUG
#ifdef WIN16
    dwAlloc--;
#else
    InterlockedDecrement(&dwAlloc);
#endif
#endif

}

BOOL MallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 44 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _fmalloc( (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

    *lplpv = lpTemp;

#ifdef _DEBUG
#ifdef WIN16
    dwAlloc++;
#else
    InterlockedIncrement(&dwAlloc);
#endif
#endif

    return ERROR_SUCCESS;

}

BOOL ReallocMem | ( | LPVOID * | lplpv,
 |  | DWORD | dwSize
 | ) |  |

Definition at line 80 of file MEM.C.

{
    LPVOID lpTemp;

    if ( NULL == ( lpTemp = _frealloc( *lplpv, (size_t)dwSize ) ) )
        return ERROR_NOT_ENOUGH_MEMORY;

#ifdef _DEBUG
    if ( dwSize == 0 )
#ifdef WIN16
        dwAlloc--;
#else
        InterlockedDecrement(&dwAlloc);
#endif
    else if ( *lplpv == NULL )
#ifdef WIN16
        dwAlloc++;
#else
        InterlockedIncrement(&dwAlloc);
#endif
#endif

    *lplpv = lpTemp;

    return ERROR_SUCCESS;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MISCUTIL.C File Reference

  • SERVENUM
  • DLL
Defines | Functions

MISCUTIL.C File Reference

#include <windows.h>
#include <tchar.h>
#include "miscutil.h"
#include "mem.h"

Go to the source code of this file.

Defines

#define | RGBQ(dw) RGB(GetBValue(dw),GetGValue(dw),GetRValue(dw))

Functions

BOOL | CenterWindow (HWND hwndChild, HWND hwndParent)
HFONT | CreateStdFont (HWND hwnd, int heightPoints)
HBITMAP | SetBitmapBkgnd (HINSTANCE hinst, LPCTSTR szName, COLORREF rgbBkgnd)

Define Documentation

#define RGBQ ( dw ) RGB(GetBValue(dw),GetGValue(dw),GetRValue(dw))

Function Documentation

BOOL CenterWindow | ( | HWND | hwndChild,
 |  | HWND | hwndParent
 | ) |  |

Definition at line 46 of file MISCUTIL.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

HFONT CreateStdFont | ( | HWND | hwnd,
 |  | int | heightPoints
 | ) |  |

Definition at line 194 of file MISCUTIL.C.

{
    int heightPix;
    int heightTwips;
    UINT cyPixPerInch;
    UINT cyTwipsPerPixel;
    HDC hdc;
    LOGFONT lf;

    hdc = GetDC(hwnd);
    cyPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(hwnd, hdc);

    cyTwipsPerPixel = 1440 / cyPixPerInch;
    heightTwips = heightPoints * 20 + 10;   // 10 is for round-up
    heightPix = heightTwips / cyTwipsPerPixel;

    lf.lfHeight = -heightPix;
    lf.lfWidth = 0;
    lf.lfEscapement = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = FW_THIN;
    lf.lfItalic = 0;
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet = ANSI_CHARSET;
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = FF_SWISS;
    _tcscpy(lf.lfFaceName, TEXT("MS Sans Serif") );

    return CreateFontIndirect(&lf);
}

HBITMAP SetBitmapBkgnd | ( | HINSTANCE | hinst,
 |  | LPCTSTR | szName,
 |  | COLORREF | rgbBkgnd
 | ) |  |

Definition at line 119 of file MISCUTIL.C.

{
    LPBYTE              lpb;
    HBITMAP             hbmp;
    LPBITMAPINFOHEADER  lpbi;
    LPBITMAPINFOHEADER  lpbiTemp;
    HANDLE              h;
    HDC                 hdc;
    LPDWORD             lprgb;
    DWORD               cbClrTable;

#define RGBQ(dw) RGB(GetBValue(dw),GetGValue(dw),GetRValue(dw))

    h = LoadResource (hinst, FindResource(hinst, szName, RT_BITMAP));

    lpbi = (LPBITMAPINFOHEADER) LockResource(h);

    if (!lpbi)
        return NULL;

    if (lpbi->biSize != sizeof(BITMAPINFOHEADER))
        return NULL;

    if (lpbi->biBitCount != 4)
        return NULL;

    cbClrTable = ((int)lpbi->biClrUsed ?
                  (int)lpbi->biClrUsed :
                  (1 << (int)lpbi->biBitCount)) * sizeof(RGBQUAD);

    if ( ERROR_SUCCESS != MallocMem( &lpbiTemp, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage ) )
        return NULL;

    memcpy( lpbiTemp, lpbi, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage );

    // Calcluate the pointer to the Bits information
    // First skip over the header structure
    lprgb = (LPDWORD)((LPBYTE)(lpbiTemp) + lpbiTemp->biSize);

    // Skip the color table entries, if any
    lpb = (LPBYTE)lprgb + cbClrTable;

    lprgb[10] = RGBQ(rgbBkgnd);         // green

    hdc = GetDC(NULL);

    hbmp = CreateDIBitmap (hdc, lpbiTemp, CBM_INIT, (LPVOID)lpb,
                          (LPBITMAPINFO)lpbiTemp, DIB_RGB_COLORS);

    FreeMem( &lpbiTemp );
    ReleaseDC(NULL, hdc);
    UnlockResource(h);
    FreeResource(h);

    return(hbmp);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MISCUTIL.H File Reference

  • SERVENUM
  • DLL
Functions

MISCUTIL.H File Reference

Go to the source code of this file.

Functions

BOOL | CenterWindow (HWND hwndChild, HWND hwndParent)
HFONT | CreateStdFont (HWND hwnd, int heightPoints)
HBITMAP | SetBitmapBkgnd (HINSTANCE hinst, LPCTSTR szName, COLORREF rgbBkgnd)

Function Documentation

BOOL CenterWindow | ( | HWND | hwndChild,
 |  | HWND | hwndParent
 | ) |  |

Definition at line 50 of file MISC.C.

{
    RECT    rcChild, rcParent;
    int     cxChild, cyChild, cxParent, cyParent;
    int     cxScreen, cyScreen, xNew, yNew;
    HDC     hdc;

    // Get the Height and Width of the child window
    GetWindowRect(hwndChild, &rcChild);
    cxChild = rcChild.right - rcChild.left;
    cyChild = rcChild.bottom - rcChild.top;

    // Get the Height and Width of the parent window
    GetWindowRect(hwndParent, &rcParent);
    cxParent = rcParent.right - rcParent.left;
    cyParent = rcParent.bottom - rcParent.top;

    // Get the display limits
    hdc = GetDC(hwndChild);
    cxScreen = GetDeviceCaps(hdc, HORZRES);
    cyScreen = GetDeviceCaps(hdc, VERTRES);
    ReleaseDC(hwndChild, hdc);

    // Calculate new X position, then adjust for screen
    xNew = rcParent.left + ((cxParent - cxChild) / 2);
    if (xNew < 0)
    {
        xNew = 0;
    }
    else if ((xNew + cxChild) > cxScreen)
    {
        xNew = cxScreen - cxChild;
    }

    // Calculate new Y position, then adjust for screen
    yNew = rcParent.top  + ((cyParent - cyChild) / 2);
    if (yNew < 0)
    {
        yNew = 0;
    }
    else if ((yNew + cyChild) > cyScreen)
    {
        yNew = cyScreen - cyChild;
    }

    // Set it, and return
    return SetWindowPos(hwndChild,
                        NULL,
                        xNew, yNew,
                        0, 0,
                        SWP_NOSIZE | SWP_NOZORDER);
}

HFONT CreateStdFont | ( | HWND | hwnd,
 |  | int | heightPoints
 | ) |  |

Definition at line 194 of file MISCUTIL.C.

{
    int heightPix;
    int heightTwips;
    UINT cyPixPerInch;
    UINT cyTwipsPerPixel;
    HDC hdc;
    LOGFONT lf;

    hdc = GetDC(hwnd);
    cyPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
    ReleaseDC(hwnd, hdc);

    cyTwipsPerPixel = 1440 / cyPixPerInch;
    heightTwips = heightPoints * 20 + 10;   // 10 is for round-up
    heightPix = heightTwips / cyTwipsPerPixel;

    lf.lfHeight = -heightPix;
    lf.lfWidth = 0;
    lf.lfEscapement = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = FW_THIN;
    lf.lfItalic = 0;
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet = ANSI_CHARSET;
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = FF_SWISS;
    _tcscpy(lf.lfFaceName, TEXT("MS Sans Serif") );

    return CreateFontIndirect(&lf);
}

HBITMAP SetBitmapBkgnd | ( | HINSTANCE | hinst,
 |  | LPCTSTR | szName,
 |  | COLORREF | rgbBkgnd
 | ) |  |

Definition at line 119 of file MISCUTIL.C.

{
    LPBYTE              lpb;
    HBITMAP             hbmp;
    LPBITMAPINFOHEADER  lpbi;
    LPBITMAPINFOHEADER  lpbiTemp;
    HANDLE              h;
    HDC                 hdc;
    LPDWORD             lprgb;
    DWORD               cbClrTable;

#define RGBQ(dw) RGB(GetBValue(dw),GetGValue(dw),GetRValue(dw))

    h = LoadResource (hinst, FindResource(hinst, szName, RT_BITMAP));

    lpbi = (LPBITMAPINFOHEADER) LockResource(h);

    if (!lpbi)
        return NULL;

    if (lpbi->biSize != sizeof(BITMAPINFOHEADER))
        return NULL;

    if (lpbi->biBitCount != 4)
        return NULL;

    cbClrTable = ((int)lpbi->biClrUsed ?
                  (int)lpbi->biClrUsed :
                  (1 << (int)lpbi->biBitCount)) * sizeof(RGBQUAD);

    if ( ERROR_SUCCESS != MallocMem( &lpbiTemp, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage ) )
        return NULL;

    memcpy( lpbiTemp, lpbi, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage );

    // Calcluate the pointer to the Bits information
    // First skip over the header structure
    lprgb = (LPDWORD)((LPBYTE)(lpbiTemp) + lpbiTemp->biSize);

    // Skip the color table entries, if any
    lpb = (LPBYTE)lprgb + cbClrTable;

    lprgb[10] = RGBQ(rgbBkgnd);         // green

    hdc = GetDC(NULL);

    hbmp = CreateDIBitmap (hdc, lpbiTemp, CBM_INIT, (LPVOID)lpb,
                          (LPBITMAPINFO)lpbiTemp, DIB_RGB_COLORS);

    FreeMem( &lpbiTemp );
    ReleaseDC(NULL, hdc);
    UnlockResource(h);
    FreeResource(h);

    return(hbmp);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/SERVENUM.C File Reference

  • SERVENUM
  • DLL
Functions | Variables

SERVENUM.C File Reference

#include <windows.h>
#include "servenum.h"
#include "enumdlg.h"
#include "enumutil.h"
#include "thrdutil.h"
#include "miscutil.h"
#include "mem.h"

Go to the source code of this file.

Functions

BOOL WINAPI | DllMain (HMODULE hMod, DWORD dwReason, LPVOID lpReserved)
DWORD | ServerEnumDialogA (HWND hwnd, LPSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)
DWORD | ServerEnumDialogW (HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)

Variables

HMODULE | g_hMod
DWORD ndxTls

Function Documentation

BOOL WINAPI DllMain | ( | HMODULE | hMod,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 51 of file SERVENUM.C.

{
    BOOL bRet = TRUE;

    switch ( dwReason )
    {
        case DLL_PROCESS_ATTACH:
            g_hMod = hMod;
            InitializeCriticalSection( &g_csOutstanding );
            if ( (DWORD)-1 == (ndxTls = TlsAlloc() ) )
            {
               DeleteCriticalSection( &g_csOutstanding );
               bRet = FALSE;
            }
            break;

        case DLL_THREAD_ATTACH:
            break;

        case DLL_THREAD_DETACH:
            break;

        case DLL_PROCESS_DETACH:
            WaitCloseOutstanding();
            DeleteCriticalSection( &g_csOutstanding );
            TlsFree( ndxTls );
            break;
    }

    return bRet;
}

DWORD ServerEnumDialogA | ( | HWND | hwnd,
 |  | LPSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 161 of file SERVENUM.C.

{
    DWORD dwRet;
    WCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];

    if ( ERROR_SUCCESS == ( dwRet = ServerEnumDialogW( hwnd, szServer, lpcchServer, lpfnHelpProc ) ) )
        WideCharToMultiByte( CP_ACP, 0, szServer, *lpcchServer, lpszServer, *lpcchServer, NULL, NULL );
    return dwRet;
}

DWORD ServerEnumDialogW | ( | HWND | hwnd,
 |  | LPWSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 104 of file SERVENUM.C.

{
    HDC hdc;
    HFONT hfontOld;
    DWORD dwRet = ERROR_SUCCESS;
    LPTLSOBJECT lpTls;

    if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpTls, sizeof(TLSOBJECT) ) ) )
    {
        TlsSetValue( ndxTls, (LPVOID) lpTls );

        lpTls->lpszServer = lpszServer;
        lpTls->lpcchServer = lpcchServer;
        lpTls->lpfnHelpProc = lpfnHelpProc;

        lpTls->hfont = CreateStdFont( hwnd, 8 );
        hdc = GetDC( hwnd );
        hfontOld = SelectObject( hdc, lpTls->hfont );
        GetTextMetrics(hdc, &(lpTls->tm) );
        SelectObject( hdc, hfontOld );
        ReleaseDC( hwnd, hdc );

        dwRet = DialogBox(g_hMod, TEXT("EnumDlgBox"), hwnd, (DLGPROC)EnumDlg);

        DeleteObject( lpTls->hfont );

        FreeMem( &lpTls );
    }

    RefreshOutstanding(); // try cleaning up any outstanding threads

    return dwRet;

}

Variable Documentation

HMODULE g_hMod

Definition at line 32 of file SERVENUM.C.

DWORD ndxTls

Definition at line 31 of file SERVENUM.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/SERVENUM.H File Reference

  • SERVENUM
  • DLL
Defines | Functions

SERVENUM.H File Reference

Go to the source code of this file.

Defines

#define | ERROR_CANCELLED 1223L
#define | ServerEnumDialog ServerEnumDialogA

Functions

DWORD | ServerEnumDialogA (HWND hwnd, LPSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)
DWORD | ServerEnumDialogW (HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc)

Define Documentation

#define ERROR_CANCELLED 1223L

Definition at line 17 of file SERVENUM.H.

#define ServerEnumDialog ServerEnumDialogA

Definition at line 64 of file SERVENUM.H.

Function Documentation

DWORD ServerEnumDialogA | ( | HWND | hwnd,
 |  | LPSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 161 of file SERVENUM.C.

{
    DWORD dwRet;
    WCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];

    if ( ERROR_SUCCESS == ( dwRet = ServerEnumDialogW( hwnd, szServer, lpcchServer, lpfnHelpProc ) ) )
        WideCharToMultiByte( CP_ACP, 0, szServer, *lpcchServer, lpszServer, *lpcchServer, NULL, NULL );
    return dwRet;
}

DWORD ServerEnumDialogW | ( | HWND | hwnd,
 |  | LPWSTR | lpszServer,
 |  | LPDWORD | lpcchServer,
 |  | FARPROC | lpfnHelpProc
 | ) |  |

Definition at line 104 of file SERVENUM.C.

{
    HDC hdc;
    HFONT hfontOld;
    DWORD dwRet = ERROR_SUCCESS;
    LPTLSOBJECT lpTls;

    if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpTls, sizeof(TLSOBJECT) ) ) )
    {
        TlsSetValue( ndxTls, (LPVOID) lpTls );

        lpTls->lpszServer = lpszServer;
        lpTls->lpcchServer = lpcchServer;
        lpTls->lpfnHelpProc = lpfnHelpProc;

        lpTls->hfont = CreateStdFont( hwnd, 8 );
        hdc = GetDC( hwnd );
        hfontOld = SelectObject( hdc, lpTls->hfont );
        GetTextMetrics(hdc, &(lpTls->tm) );
        SelectObject( hdc, hfontOld );
        ReleaseDC( hwnd, hdc );

        dwRet = DialogBox(g_hMod, TEXT("EnumDlgBox"), hwnd, (DLGPROC)EnumDlg);

        DeleteObject( lpTls->hfont );

        FreeMem( &lpTls );
    }

    RefreshOutstanding(); // try cleaning up any outstanding threads

    return dwRet;

}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/THRDUTIL.C File Reference

  • SERVENUM
  • DLL
Functions | Variables

THRDUTIL.C File Reference

#include <windows.h>
#include <stdlib.h>
#include "thrdutil.h"
#include "mem.h"

Go to the source code of this file.

Functions

DWORD | MarkOutstanding (HANDLE *lpHandle)
VOID | RefreshOutstanding ()
VOID | WaitCloseOutstanding ()

Variables

CRITICAL_SECTION | g_csOutstanding
HANDLE * | g_lphOutstanding = NULL
UINT | g_nOutstanding = 0

Function Documentation

DWORD MarkOutstanding ( HANDLE * lpHandle )

Definition at line 133 of file THRDUTIL.C.

{
    DWORD dwRet;

    EnterCriticalSection(&g_csOutstanding);

    RefreshOutstanding();

    if ( ERROR_NOT_ENOUGH_MEMORY == ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*(g_nOutstanding+1) ) )
    {
        dwRet = ERROR_NOT_ENOUGH_MEMORY;
    }
    else
    {
        g_lphOutstanding[g_nOutstanding++] = *lpHandle;
        *lpHandle = NULL;
        dwRet = ERROR_SUCCESS;
    }

    LeaveCriticalSection(&g_csOutstanding);

    return dwRet;
}

VOID RefreshOutstanding ( )

Definition at line 85 of file THRDUTIL.C.

{
    UINT ndx = 0;
    UINT ndx2 = 0;

    EnterCriticalSection(&g_csOutstanding);

    for( ndx = 0; ndx < g_nOutstanding; ndx++ )
    {
        if ( WaitForSingleObject( g_lphOutstanding[ndx], 0 ) == WAIT_OBJECT_0 )
        {
            CloseHandle( g_lphOutstanding[ndx] );
            g_lphOutstanding[ndx] = NULL;
        }
        else  // handle still outstanding
        {
            g_lphOutstanding[ndx2++] = g_lphOutstanding[ndx];
        }
    }

    if ( g_nOutstanding < ndx2 )
    {
        // realloc won't fail because we are shrinking
        g_nOutstanding = ndx2;
        ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*g_nOutstanding );
    }

    LeaveCriticalSection(&g_csOutstanding);

}

VOID WaitCloseOutstanding ( )

Definition at line 47 of file THRDUTIL.C.

{
    UINT ndx;

    EnterCriticalSection(&g_csOutstanding);

    for( ndx = 0; ndx < g_nOutstanding; ndx+=MAXIMUM_WAIT_OBJECTS )
    {
        WaitForMultipleObjects( g_nOutstanding-ndx,
                                g_lphOutstanding+ndx,
                                TRUE, INFINITE );

    }

    for( ndx = 0; ndx < g_nOutstanding; ndx++ )
        CloseHandle(g_lphOutstanding[ndx]);

    FreeMem((LPVOID*)&g_lphOutstanding);
    g_nOutstanding = 0;

    LeaveCriticalSection(&g_csOutstanding);

}

Variable Documentation

CRITICAL_SECTION g_csOutstanding

Definition at line 27 of file THRDUTIL.C.

HANDLE* g_lphOutstanding = NULL

Definition at line 30 of file THRDUTIL.C.

UINT g_nOutstanding = 0

Definition at line 31 of file THRDUTIL.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/THRDUTIL.H File Reference

  • SERVENUM
  • DLL
Functions | Variables

THRDUTIL.H File Reference

Go to the source code of this file.

Functions

DWORD | MarkOutstanding (HANDLE *lpHandle)
VOID | RefreshOutstanding ()
VOID | WaitCloseOutstanding ()

Variables

CRITICAL_SECTION | g_csOutstanding

Function Documentation

DWORD MarkOutstanding ( HANDLE * lpHandle )

Definition at line 133 of file THRDUTIL.C.

{
    DWORD dwRet;

    EnterCriticalSection(&g_csOutstanding);

    RefreshOutstanding();

    if ( ERROR_NOT_ENOUGH_MEMORY == ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*(g_nOutstanding+1) ) )
    {
        dwRet = ERROR_NOT_ENOUGH_MEMORY;
    }
    else
    {
        g_lphOutstanding[g_nOutstanding++] = *lpHandle;
        *lpHandle = NULL;
        dwRet = ERROR_SUCCESS;
    }

    LeaveCriticalSection(&g_csOutstanding);

    return dwRet;
}

VOID RefreshOutstanding ( )

Definition at line 85 of file THRDUTIL.C.

{
    UINT ndx = 0;
    UINT ndx2 = 0;

    EnterCriticalSection(&g_csOutstanding);

    for( ndx = 0; ndx < g_nOutstanding; ndx++ )
    {
        if ( WaitForSingleObject( g_lphOutstanding[ndx], 0 ) == WAIT_OBJECT_0 )
        {
            CloseHandle( g_lphOutstanding[ndx] );
            g_lphOutstanding[ndx] = NULL;
        }
        else  // handle still outstanding
        {
            g_lphOutstanding[ndx2++] = g_lphOutstanding[ndx];
        }
    }

    if ( g_nOutstanding < ndx2 )
    {
        // realloc won't fail because we are shrinking
        g_nOutstanding = ndx2;
        ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*g_nOutstanding );
    }

    LeaveCriticalSection(&g_csOutstanding);

}

VOID WaitCloseOutstanding ( )

Definition at line 47 of file THRDUTIL.C.

{
    UINT ndx;

    EnterCriticalSection(&g_csOutstanding);

    for( ndx = 0; ndx < g_nOutstanding; ndx+=MAXIMUM_WAIT_OBJECTS )
    {
        WaitForMultipleObjects( g_nOutstanding-ndx,
                                g_lphOutstanding+ndx,
                                TRUE, INFINITE );

    }

    for( ndx = 0; ndx < g_nOutstanding; ndx++ )
        CloseHandle(g_lphOutstanding[ndx]);

    FreeMem((LPVOID*)&g_lphOutstanding);
    g_nOutstanding = 0;

    LeaveCriticalSection(&g_csOutstanding);

}

Variable Documentation

CRITICAL_SECTION g_csOutstanding

Definition at line 27 of file THRDUTIL.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SETINFO/SETINFO.C File Reference

  • SETINFO
Functions | Variables

SETINFO.C File Reference

#include <windows.h>
#include <stdlib.h>
#include "setinfo.h"

Go to the source code of this file.

Functions

LONG APIENTRY | FileDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
LONG APIENTRY | MainWndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
BOOL | RepStat (CHAR *API, DWORD retCode)
LONG APIENTRY | StatusDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hInst
HWND | hWnd
HWND | hWndDlg
HWND | hWndFileDlg
DWORD StepTime

Function Documentation

LONG APIENTRY FileDlgProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 401 of file SETINFO.C.

{
  CHAR     fileName[100];
  HANDLE   hFile;
  DWORD    retCode = 0;
  FILETIME ftCreation, ftAccessed, ftWrittenTo;
  WORD     wDosDate, wDosTime;
  CHAR     DD[3], MM[3], YY[3], HH[3], Mn[3], SS[3];
  DWORD    dwFileSize;
  CHAR     lpsFileSize[10];
  DWORD    dwFileAttr;

  UNREFERENCED_PARAMETER (wParam);
  UNREFERENCED_PARAMETER (lParam);

  switch (message)
    {

    case WM_COMMAND :
      switch (LOWORD(wParam))
        {
        case IDB_ATTR:

          dwFileAttr = 0;

          if (IsDlgButtonChecked (hDlg, IDC_HIDE))
             dwFileAttr |= FILE_ATTRIBUTE_HIDDEN;

          if (IsDlgButtonChecked (hDlg, IDC_NORMAL))
             dwFileAttr |= FILE_ATTRIBUTE_NORMAL;

          if (IsDlgButtonChecked (hDlg, IDC_ARC))
             dwFileAttr |= FILE_ATTRIBUTE_ARCHIVE;

          if (IsDlgButtonChecked (hDlg, IDC_SYSTEM))
             dwFileAttr |= FILE_ATTRIBUTE_SYSTEM;

          if (IsDlgButtonChecked (hDlg, IDC_READ))
             dwFileAttr |= FILE_ATTRIBUTE_READONLY;

          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);

          retCode = SetFileAttributes (fileName, dwFileAttr);
            RepStat ("SetFileAttributes()", retCode);

          return (0);

        case IDB_SET:

          GetDlgItemText (hDlg, IDE_YEAR,  YY, 3);
          GetDlgItemText (hDlg, IDE_DAY,   DD, 3);
          GetDlgItemText (hDlg, IDE_MONTH, MM, 3);
          wDosDate = (WORD)((atoi(YY) - 80)<<YRSHIFT |
                             atoi(MM)<<MONSHIFT |
                             atoi(DD)<<DAYSHIFT);

          GetDlgItemText (hDlg, IDE_HOURS,   HH, 3);
          GetDlgItemText (hDlg, IDE_SECONDS, SS, 3);
          GetDlgItemText (hDlg, IDE_MINUTES, Mn, 3);
          wDosTime = (WORD)((atoi(SS) / 2)<< SECSHIFT |
                             atoi(Mn)<<MINSHIFT |
                             atoi(HH)<<HRSHIFT);

          retCode = DosDateTimeToFileTime (wDosDate, wDosTime, &ftWrittenTo);
            RepStat("DosDateTimeToFileTime()", retCode);

          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
          hFile = CreateFile (fileName,
                              GENERIC_READ | GENERIC_WRITE,
                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (RepStat("CreateFile()", (DWORD)hFile))
            return (0);

          retCode = SetFileTime (hFile, NULL, NULL, &ftWrittenTo);
            RepStat("SetFileTime()", retCode);

          CloseHandle (hFile);
          return (0);

        case IDB_OPENFILE :
          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
          hFile = CreateFile (fileName,
                              GENERIC_READ,
                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (RepStat("CreateFile()", (DWORD)hFile))
            return (0);

          (BOOL)retCode = GetFileTime (hFile,
                                       &ftCreation,
                                       &ftAccessed,
                                       &ftWrittenTo);
          RepStat( "GetFileTime()", retCode);

          (BOOL)retCode = FileTimeToDosDateTime( &ftWrittenTo,
                                                 &wDosDate,
                                                 &wDosTime);
          RepStat("FileTimeToDosDateTime()", retCode);

          dwFileSize = GetFileSize (hFile, NULL);
          RepStat("GetFileSize()", dwFileSize);

          wsprintf(YY, "%02d", ((wDosDate & YRMASK) >> YRSHIFT ) + 80);
          SetDlgItemText (hDlg, IDE_YEAR, YY);

          wsprintf(MM, "%02d", ((wDosDate & MONMASK) >> MONSHIFT));
          SetDlgItemText (hDlg, IDE_MONTH, MM);

          wsprintf(DD, "%02d", ((wDosDate & DAYMASK) >> DAYSHIFT) );
          SetDlgItemText (hDlg, IDE_DAY, DD);

          wsprintf(SS, "%02d", ((wDosTime & SECMASK) >> SECSHIFT ) * 2);
          SetDlgItemText (hDlg, IDE_SECONDS, SS);

          wsprintf(Mn, "%02d", ((wDosTime & MINMASK) >> MINSHIFT));
          SetDlgItemText (hDlg, IDE_MINUTES, Mn);

          wsprintf(HH, "%02d", (DWORD)(wDosTime & HRMASK) >> HRSHIFT );
          SetDlgItemText (hDlg, IDE_HOURS, HH);

          wsprintf(lpsFileSize, "%d", dwFileSize);
          SetDlgItemText (hDlg, IDE_SIZE, lpsFileSize);

          dwFileAttr = GetFileAttributes (fileName);
            RepStat("GetFileAttributes()", dwFileAttr);

          if (dwFileAttr & FILE_ATTRIBUTE_NORMAL)
            CheckDlgButton (hDlg, IDC_NORMAL, TRUE);
          else
            CheckDlgButton (hDlg, IDC_NORMAL, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_READONLY)
            CheckDlgButton (hDlg, IDC_READ, TRUE);
          else
            CheckDlgButton (hDlg, IDC_READ, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_HIDDEN)
            CheckDlgButton (hDlg, IDC_HIDE, TRUE);
          else
            CheckDlgButton (hDlg, IDC_HIDE, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_SYSTEM)
            CheckDlgButton (hDlg, IDC_SYSTEM, TRUE);
          else
            CheckDlgButton (hDlg, IDC_SYSTEM, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_ARCHIVE)
            CheckDlgButton (hDlg, IDC_ARC, TRUE);
          else
            CheckDlgButton (hDlg, IDC_ARC, FALSE);

          CloseHandle (hFile);

          return (0);
        }
    }
  return (0);
}

LONG APIENTRY MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 207 of file SETINFO.C.

{
  switch (message)
      {

        case WM_SIZE :
          SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
          SetWindowPos (hWndFileDlg, NULL, 0,DIALOGHEIGHT, LOWORD(lParam), HIWORD(lParam), 0);
          return (0);

        case WM_DESTROY :
            PostQuitMessage (0);
            return (0);

       }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

BOOL RepStat | ( | CHAR * | API,
 |  | DWORD | retCode
 | ) |  |

Definition at line 612 of file SETINFO.C.

{
  CHAR TempBufW[40];
  CHAR TempBufL[40];

  wsprintf(TempBufW, API);

  if ((int)retCode <= 0 )
    retCode = GetLastError();
  else
    retCode = 0;

  if (retCode)
    MessageBeep(0);

  switch (retCode)
    {
    case ERROR_INVALID_FUNCTION:   // 1L
      wsprintf(TempBufL, "ERROR_INVALID_FUNCTION");
      break;

    case ERROR_FILE_NOT_FOUND:     // 2L
      wsprintf(TempBufL, "ERROR_FILE_NOT_FOUND");
      break;

    case ERROR_ACCESS_DENIED:      // 5L
      wsprintf(TempBufL, "ERROR_ACCESS_DENIED");
      break;

    case ERROR_INVALID_HANDLE:     // 6L
      wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
      break;

    case ERROR_INVALID_PARAMETER:  // 87L
      wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
      break;

    case ERROR_INVALID_NAME:       // 123L
      wsprintf(TempBufL, "ERROR_INVALID_NAME");
      break;

    default:
      wsprintf(TempBufL, "%d", retCode);
    }

  SendMessage (hWndDlg, WM_REPSTAT, (DWORD)TempBufW, (LONG)TempBufL);
  Sleep( StepTime );

  return (retCode != 0);
}

LONG APIENTRY StatusDlgProc | ( | HWND | hDlg,
 |  | UINT | message,
 |  | UINT | wParam,
 |  | LONG | lParam
 | ) |  |

Definition at line 278 of file SETINFO.C.

{
  BOOL bTranslated;

  UNREFERENCED_PARAMETER (wParam);
  UNREFERENCED_PARAMETER (lParam);

  switch (message)
    {
    case WM_INITDIALOG:
      StepTime = 0;
      SetDlgItemInt (hDlg, IDE_TIME, StepTime, FALSE);
      return (0);

    case WM_REPSTAT:
      SetDlgItemText (hDlg, IDE_API,(LPTSTR) wParam);
      SetDlgItemText (hDlg, IDE_RETSTAT, (LPTSTR)lParam);
      return (0);

    case WM_COMMAND:
      switch (LOWORD(wParam))
       {
       case IDB_STEP:
           StepTime = GetDlgItemInt (hDlg, IDE_TIME, &bTranslated, FALSE);
       }
    }
  return (0);
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 118 of file SETINFO.C.

{

  MSG  msg;
  WNDCLASS wc;
  RECT rect;

  UNREFERENCED_PARAMETER( lpCmdLine );
  UNREFERENCED_PARAMETER( hPrevInstance );

  hInst = hInstance;

  wc.style = 0;                          // Replaces CS_SIZEREDRAW.
  wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
  wc.cbClsExtra = 0;                     // No room reserved for extra data.
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = "";
  wc.lpszClassName = "SetInfoWClass";

  RegisterClass(&wc);

  hWnd = CreateWindow ("SetInfoWClass",
                       "Set File Info. Sample",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);

  hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, (DLGPROC)StatusDlgProc);
  hWndFileDlg = CreateDialog (hInst, "FileDlg",   hWnd, (DLGPROC)FileDlgProc);

  GetClientRect (hWnd, &rect);
  SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
  ShowWindow  (hWndDlg,  SW_SHOW);
  ShowWindow  (hWndFileDlg, SW_SHOW);
  ShowWindow  (hWnd, nCmdShow);

  while (GetMessage (&msg, NULL, 0, 0))
    if (!IsDialogMessage (hWndDlg, &msg)
        && !IsDialogMessage (hWndFileDlg, &msg))
      {
       DispatchMessage (&msg);   // Dispatch message to window.
      }

  return (msg.wParam);           // Returns value from PostQuitMessage.

}

Variable Documentation

HANDLE hInst

Definition at line 96 of file SETINFO.C.

HWND hWnd

Definition at line 97 of file SETINFO.C.

HWND hWndDlg

Definition at line 97 of file SETINFO.C.

HWND hWndFileDlg

Definition at line 97 of file SETINFO.C.

DWORD StepTime

Definition at line 98 of file SETINFO.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SETINFO/SETINFO.H File Reference

  • SETINFO
Defines | Functions

SETINFO.H File Reference

Go to the source code of this file.

Defines

#define | DAYMASK 0x001F
#define | DAYSHIFT 0
#define | DIALOGHEIGHT 80
#define | HRMASK 0xF800
#define | HRSHIFT 11
#define | IDB_ATTR 222
#define | IDB_OPENFILE 102
#define | IDB_SET 204
#define | IDB_STEP 103
#define | IDC_ARC 208
#define | IDC_HIDE 206
#define | IDC_NORMAL 210
#define | IDC_READ 209
#define | IDC_SYSTEM 207
#define | IDE_API 101
#define | IDE_DAY 104
#define | IDE_FILENAME 101
#define | IDE_HOURS 201
#define | IDE_MINUTES 202
#define | IDE_MONTH 103
#define | IDE_RETSTAT 102
#define | IDE_SECONDS 203
#define | IDE_SIZE 205
#define | IDE_TIME 104
#define | IDE_YEAR 105
#define | MINMASK 0x07E0
#define | MINSHIFT 5
#define | MONMASK 0x01E0
#define | MONSHIFT 5
#define | SECMASK 0x001F
#define | SECSHIFT 0
#define | WM_REPSTAT WM_USER+1
#define | YRMASK 0xFE00
#define | YRSHIFT 9

Functions

LONG APIENTRY | FileDlgProc (HWND, UINT, UINT, LONG)
LONG APIENTRY | MainWndProc (HWND, UINT, UINT, LONG)
BOOL | RepStat (CHAR *, DWORD)
LONG APIENTRY | StatusDlgProc (HWND, UINT, UINT, LONG)

Define Documentation

#define DAYMASK 0x001F

Definition at line 46 of file SETINFO.H.

#define DAYSHIFT 0

Definition at line 47 of file SETINFO.H.

#define DIALOGHEIGHT 80

Definition at line 17 of file SETINFO.H.

#define HRMASK 0xF800

Definition at line 49 of file SETINFO.H.

#define HRSHIFT 11

Definition at line 50 of file SETINFO.H.

#define IDB_ATTR 222

Definition at line 37 of file SETINFO.H.

#define IDB_OPENFILE 102

Definition at line 23 of file SETINFO.H.

#define IDB_SET 204

Definition at line 30 of file SETINFO.H.

#define IDB_STEP 103

Definition at line 14 of file SETINFO.H.

#define IDC_ARC 208

Definition at line 34 of file SETINFO.H.

#define IDC_HIDE 206

Definition at line 32 of file SETINFO.H.

#define IDC_NORMAL 210

Definition at line 36 of file SETINFO.H.

#define IDC_READ 209

Definition at line 35 of file SETINFO.H.

#define IDC_SYSTEM 207

Definition at line 33 of file SETINFO.H.

#define IDE_API 101

Definition at line 12 of file SETINFO.H.

#define IDE_DAY 104

Definition at line 25 of file SETINFO.H.

#define IDE_FILENAME 101

Definition at line 22 of file SETINFO.H.

#define IDE_HOURS 201

Definition at line 27 of file SETINFO.H.

#define IDE_MINUTES 202

Definition at line 28 of file SETINFO.H.

#define IDE_MONTH 103

Definition at line 24 of file SETINFO.H.

#define IDE_RETSTAT 102

Definition at line 13 of file SETINFO.H.

#define IDE_SECONDS 203

Definition at line 29 of file SETINFO.H.

#define IDE_SIZE 205

Definition at line 31 of file SETINFO.H.

#define IDE_TIME 104

Definition at line 15 of file SETINFO.H.

#define IDE_YEAR 105

Definition at line 26 of file SETINFO.H.

#define MINMASK 0x07E0

Definition at line 51 of file SETINFO.H.

#define MINSHIFT 5

Definition at line 52 of file SETINFO.H.

#define MONMASK 0x01E0

Definition at line 43 of file SETINFO.H.

#define MONSHIFT 5

Definition at line 44 of file SETINFO.H.

#define SECMASK 0x001F

Definition at line 53 of file SETINFO.H.

#define SECSHIFT 0

Definition at line 54 of file SETINFO.H.

#define WM_REPSTAT WM_USER+1

Definition at line 19 of file SETINFO.H.

#define YRMASK 0xFE00

Definition at line 40 of file SETINFO.H.

#define YRSHIFT 9

Definition at line 41 of file SETINFO.H.

Function Documentation

LONG APIENTRY FileDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 401 of file SETINFO.C.

{
  CHAR     fileName[100];
  HANDLE   hFile;
  DWORD    retCode = 0;
  FILETIME ftCreation, ftAccessed, ftWrittenTo;
  WORD     wDosDate, wDosTime;
  CHAR     DD[3], MM[3], YY[3], HH[3], Mn[3], SS[3];
  DWORD    dwFileSize;
  CHAR     lpsFileSize[10];
  DWORD    dwFileAttr;

  UNREFERENCED_PARAMETER (wParam);
  UNREFERENCED_PARAMETER (lParam);

  switch (message)
    {

    case WM_COMMAND :
      switch (LOWORD(wParam))
        {
        case IDB_ATTR:

          dwFileAttr = 0;

          if (IsDlgButtonChecked (hDlg, IDC_HIDE))
             dwFileAttr |= FILE_ATTRIBUTE_HIDDEN;

          if (IsDlgButtonChecked (hDlg, IDC_NORMAL))
             dwFileAttr |= FILE_ATTRIBUTE_NORMAL;

          if (IsDlgButtonChecked (hDlg, IDC_ARC))
             dwFileAttr |= FILE_ATTRIBUTE_ARCHIVE;

          if (IsDlgButtonChecked (hDlg, IDC_SYSTEM))
             dwFileAttr |= FILE_ATTRIBUTE_SYSTEM;

          if (IsDlgButtonChecked (hDlg, IDC_READ))
             dwFileAttr |= FILE_ATTRIBUTE_READONLY;

          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);

          retCode = SetFileAttributes (fileName, dwFileAttr);
            RepStat ("SetFileAttributes()", retCode);

          return (0);

        case IDB_SET:

          GetDlgItemText (hDlg, IDE_YEAR,  YY, 3);
          GetDlgItemText (hDlg, IDE_DAY,   DD, 3);
          GetDlgItemText (hDlg, IDE_MONTH, MM, 3);
          wDosDate = (WORD)((atoi(YY) - 80)<<YRSHIFT |
                             atoi(MM)<<MONSHIFT |
                             atoi(DD)<<DAYSHIFT);

          GetDlgItemText (hDlg, IDE_HOURS,   HH, 3);
          GetDlgItemText (hDlg, IDE_SECONDS, SS, 3);
          GetDlgItemText (hDlg, IDE_MINUTES, Mn, 3);
          wDosTime = (WORD)((atoi(SS) / 2)<< SECSHIFT |
                             atoi(Mn)<<MINSHIFT |
                             atoi(HH)<<HRSHIFT);

          retCode = DosDateTimeToFileTime (wDosDate, wDosTime, &ftWrittenTo);
            RepStat("DosDateTimeToFileTime()", retCode);

          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
          hFile = CreateFile (fileName,
                              GENERIC_READ | GENERIC_WRITE,
                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (RepStat("CreateFile()", (DWORD)hFile))
            return (0);

          retCode = SetFileTime (hFile, NULL, NULL, &ftWrittenTo);
            RepStat("SetFileTime()", retCode);

          CloseHandle (hFile);
          return (0);

        case IDB_OPENFILE :
          GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
          hFile = CreateFile (fileName,
                              GENERIC_READ,
                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
          if (RepStat("CreateFile()", (DWORD)hFile))
            return (0);

          (BOOL)retCode = GetFileTime (hFile,
                                       &ftCreation,
                                       &ftAccessed,
                                       &ftWrittenTo);
          RepStat( "GetFileTime()", retCode);

          (BOOL)retCode = FileTimeToDosDateTime( &ftWrittenTo,
                                                 &wDosDate,
                                                 &wDosTime);
          RepStat("FileTimeToDosDateTime()", retCode);

          dwFileSize = GetFileSize (hFile, NULL);
          RepStat("GetFileSize()", dwFileSize);

          wsprintf(YY, "%02d", ((wDosDate & YRMASK) >> YRSHIFT ) + 80);
          SetDlgItemText (hDlg, IDE_YEAR, YY);

          wsprintf(MM, "%02d", ((wDosDate & MONMASK) >> MONSHIFT));
          SetDlgItemText (hDlg, IDE_MONTH, MM);

          wsprintf(DD, "%02d", ((wDosDate & DAYMASK) >> DAYSHIFT) );
          SetDlgItemText (hDlg, IDE_DAY, DD);

          wsprintf(SS, "%02d", ((wDosTime & SECMASK) >> SECSHIFT ) * 2);
          SetDlgItemText (hDlg, IDE_SECONDS, SS);

          wsprintf(Mn, "%02d", ((wDosTime & MINMASK) >> MINSHIFT));
          SetDlgItemText (hDlg, IDE_MINUTES, Mn);

          wsprintf(HH, "%02d", (DWORD)(wDosTime & HRMASK) >> HRSHIFT );
          SetDlgItemText (hDlg, IDE_HOURS, HH);

          wsprintf(lpsFileSize, "%d", dwFileSize);
          SetDlgItemText (hDlg, IDE_SIZE, lpsFileSize);

          dwFileAttr = GetFileAttributes (fileName);
            RepStat("GetFileAttributes()", dwFileAttr);

          if (dwFileAttr & FILE_ATTRIBUTE_NORMAL)
            CheckDlgButton (hDlg, IDC_NORMAL, TRUE);
          else
            CheckDlgButton (hDlg, IDC_NORMAL, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_READONLY)
            CheckDlgButton (hDlg, IDC_READ, TRUE);
          else
            CheckDlgButton (hDlg, IDC_READ, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_HIDDEN)
            CheckDlgButton (hDlg, IDC_HIDE, TRUE);
          else
            CheckDlgButton (hDlg, IDC_HIDE, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_SYSTEM)
            CheckDlgButton (hDlg, IDC_SYSTEM, TRUE);
          else
            CheckDlgButton (hDlg, IDC_SYSTEM, FALSE);

          if (dwFileAttr & FILE_ATTRIBUTE_ARCHIVE)
            CheckDlgButton (hDlg, IDC_ARC, TRUE);
          else
            CheckDlgButton (hDlg, IDC_ARC, FALSE);

          CloseHandle (hFile);

          return (0);
        }
    }
  return (0);
}

LONG APIENTRY MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

BOOL RepStat | ( | CHAR * | ,
 |  | DWORD |
 | ) |  |

Definition at line 612 of file SETINFO.C.

{
  CHAR TempBufW[40];
  CHAR TempBufL[40];

  wsprintf(TempBufW, API);

  if ((int)retCode <= 0 )
    retCode = GetLastError();
  else
    retCode = 0;

  if (retCode)
    MessageBeep(0);

  switch (retCode)
    {
    case ERROR_INVALID_FUNCTION:   // 1L
      wsprintf(TempBufL, "ERROR_INVALID_FUNCTION");
      break;

    case ERROR_FILE_NOT_FOUND:     // 2L
      wsprintf(TempBufL, "ERROR_FILE_NOT_FOUND");
      break;

    case ERROR_ACCESS_DENIED:      // 5L
      wsprintf(TempBufL, "ERROR_ACCESS_DENIED");
      break;

    case ERROR_INVALID_HANDLE:     // 6L
      wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
      break;

    case ERROR_INVALID_PARAMETER:  // 87L
      wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
      break;

    case ERROR_INVALID_NAME:       // 123L
      wsprintf(TempBufL, "ERROR_INVALID_NAME");
      break;

    default:
      wsprintf(TempBufL, "%d", retCode);
    }

  SendMessage (hWndDlg, WM_REPSTAT, (DWORD)TempBufW, (LONG)TempBufL);
  Sleep( StepTime );

  return (retCode != 0);
}

LONG APIENTRY StatusDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 278 of file SETINFO.C.

{
  BOOL bTranslated;

  UNREFERENCED_PARAMETER (wParam);
  UNREFERENCED_PARAMETER (lParam);

  switch (message)
    {
    case WM_INITDIALOG:
      StepTime = 0;
      SetDlgItemInt (hDlg, IDE_TIME, StepTime, FALSE);
      return (0);

    case WM_REPSTAT:
      SetDlgItemText (hDlg, IDE_API,(LPTSTR) wParam);
      SetDlgItemText (hDlg, IDE_RETSTAT, (LPTSTR)lParam);
      return (0);

    case WM_COMMAND:
      switch (LOWORD(wParam))
       {
       case IDB_STEP:
           StepTime = GetDlgItemInt (hDlg, IDE_TIME, &bTranslated, FALSE);
       }
    }
  return (0);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SHAREMEM/SHAREMEM.C File Reference

  • SHAREMEM
Defines | Functions | Variables

SHAREMEM.C File Reference

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "sharemem.h"

Go to the source code of this file.

Defines

#define | WERR(who, where)

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

CHAR | Buf [80]
CHAR | Buf2 [80]
HANDLE | hInst
HANDLE | hMapObject
HWND | hWnd
HWND | hWndDlg
LONG * | MapView

Define Documentation

#define WERR | ( | who,
 |  | where
 | ) |
Value:
{sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
                            sprintf(Buf2,"From within %s", where);\
                            MessageBox(hwnd, Buf, Buf2, MB_OK);}

Definition at line 65 of file SHAREMEM.C.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 194 of file SHAREMEM.C.

{

  switch (message)
      {

        case WM_CREATE:
          hMapObject = CreateFileMapping ((HANDLE) 0xFFFFFFFF,
                                          NULL,
                                          PAGE_READWRITE,
                                          0,
                                          sizeof(DWORD),
                                          "shared_memory");
          if (!hMapObject)
            {
             WERR("CreateFileMapping","WM_CREATE");
            }
    MapView = (LONG *) MapViewOfFile (hMapObject,
                                           FILE_MAP_WRITE,
                                           0, 0, 0);
          if (!MapView)
            MessageBox (hwnd, "ERROR: MapViewOfFile was not successful.",
                        "From within WM_CREATE", MB_OK);
          return (0);

        case WM_SIZE :
          SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
          return (0);

        case WM_MOUSEMOVE:

          __try
            {
             MapView[0] = lParam;
            }
            __except(EXCEPTION_EXECUTE_HANDLER)
            {
              MessageBox( hwnd, "Trapped an exception when writing to memory.",
                          "From within WM_MOUSEMOVE", MB_OK);
            }

          SetDlgItemInt (hWndDlg, IDE_XCOORD, LOWORD(lParam), FALSE);
          SetDlgItemInt (hWndDlg, IDE_YCOORD, HIWORD(lParam), FALSE);
          return (0);

        case WM_DESTROY :
            CloseHandle (hMapObject);
            PostQuitMessage (0);
            return (0);

       }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 92 of file SHAREMEM.C.

{

  MSG  msg;
  WNDCLASS wc;
  RECT rect;
  DWORD dwVersion = GetVersion();

  UNREFERENCED_PARAMETER( lpCmdLine );
  UNREFERENCED_PARAMETER( hPrevInstance );

// check if running on Windows NT, if not, display notice and terminate
    if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
       MessageBoxA( NULL,
           "This sample application cannot run on Win32s.\n"
           "This application will now terminate.",
           "OthrProc",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
       return( 1 );
    }

  hInst = hInstance;

  wc.style = 0;
  wc.lpfnWndProc = (WNDPROC)MainWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = "";
  wc.lpszClassName = "ShareMemWClass";

  RegisterClass(&wc);

  hWnd = CreateWindow ("ShareMemWClass",
                       "Shared Memory Sample",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);

  hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, NULL);

  GetClientRect (hWnd, &rect);
  SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
  ShowWindow  (hWndDlg,  SW_SHOW);
  ShowWindow  (hWnd, nCmdShow);

  while (GetMessage (&msg, NULL, 0, 0))
    if (!IsDialogMessage (hWndDlg, &msg))
      {
       DispatchMessage (&msg);   // Dispatch message to window.
      }

  return (msg.wParam);           // Returns value from PostQuitMessage.

}

Variable Documentation

CHAR Buf[80]

Definition at line 69 of file SHAREMEM.C.

CHAR Buf2[80]

Definition at line 70 of file SHAREMEM.C.

HANDLE hInst

Definition at line 73 of file SHAREMEM.C.

HANDLE hMapObject

Definition at line 74 of file SHAREMEM.C.

HWND hWnd

Definition at line 75 of file SHAREMEM.C.

HWND hWndDlg

Definition at line 75 of file SHAREMEM.C.

LONG* MapView

Definition at line 76 of file SHAREMEM.C.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SHAREMEM/SHAREMEM.H File Reference

  • SHAREMEM
Defines | Functions

SHAREMEM.H File Reference

Go to the source code of this file.

Defines

#define | DIALOGHEIGHT 45
#define | IDE_XCOORD 101
#define | IDE_YCOORD 102

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)

Define Documentation

#define DIALOGHEIGHT 45

Definition at line 16 of file SHAREMEM.H.

#define IDE_XCOORD 101

Definition at line 12 of file SHAREMEM.H.

#define IDE_YCOORD 102

Definition at line 13 of file SHAREMEM.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LINKTEST.C File Reference

  • SIMPLDLL
Functions

LINKTEST.C File Reference

#include <windows.h>
#include "linktest.h"
#include "the_dll.h"

Go to the source code of this file.

Functions

BOOL CALLBACK | AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void | ThreadProc ()
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 199 of file LINKTEST.C.

{ switch (message)
  {
    case WM_COMMAND:

      if (LOWORD(wParam) == IDOK)
      {
        EndDialog(hwnd, TRUE);
        return (TRUE);
      }
      return (TRUE);
  }
  return (FALSE);
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 105 of file LINKTEST.C.

{
  switch (message)
  {
    case WM_COMMAND:

      switch (LOWORD(wParam))
      {
        case IDM_CREATETHREAD:
        {
          DWORD  threadId;

          CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc,
                        NULL, 0, &threadId);
          break;
        }

        case IDM_DLLFUNCTION1:

          DLLFunction1 ();
          break;

        case IDM_DLLFUNCTION2:

          DLLFunction2 ((int) 0);
          break;

        case IDM_DLLFUNCTION3:

          DLLFunction3 ((HANDLE) NULL);
          break;

        case IDM_DLLFUNCTION4:

          DLLFunction4 ((HWND) NULL);
          break;

        case IDM_DLLDIALOGBOX:

          DLLDialogBox (hwnd);
          break;

        case IDM_ABOUT:

          DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd,
                     (DLGPROC) AboutDlgProc);
          break;

        default:

          break;
      }
      break;

    case WM_DESTROY:

      PostQuitMessage(0);
      break;

    default:

      return (DefWindowProc(hwnd, message, wParam, lParam));
  }
  return (0);
}

void ThreadProc ( void )

Definition at line 182 of file LINKTEST.C.

{
  MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
              (LPCTSTR) "ThreadProc()", MB_OK);
  DLLFunction1 ();
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 46 of file LINKTEST.C.

{ MSG msg;

  if (!hPrevInstance)
  {
    WNDCLASS wc;

    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName  = (LPCTSTR) "Menu";
    wc.lpszClassName = (LPCTSTR) "LINKTEST";

    if (!RegisterClass (&wc))
    {
      MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
                  (LPCTSTR) "Err! - LINKTEST", MB_OK | MB_ICONEXCLAMATION);
      return(FALSE);
    }
  }

  if (!(ghwndMain = CreateWindow ("LINKTEST",
                                  "LINKTEST Sample Application",
                                  WS_OVERLAPPEDWINDOW,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  NULL, NULL, hInstance, NULL)))
    return (0);

  ShowWindow (ghwndMain, nCmdShow);

  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage  (&msg);
  }

  return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LINKTEST.H File Reference

  • SIMPLDLL
Defines | Functions | Variables

LINKTEST.H File Reference

Go to the source code of this file.

Defines

#define | IDM_ABOUT 106
#define | IDM_CREATETHREAD 100
#define | IDM_DLLDIALOGBOX 105
#define | IDM_DLLFUNCTION1 101
#define | IDM_DLLFUNCTION2 102
#define | IDM_DLLFUNCTION3 103
#define | IDM_DLLFUNCTION4 104

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
void | ThreadProc (void)

Variables

HWND | ghwndMain

Define Documentation

#define IDM_ABOUT 106

Definition at line 30 of file LINKTEST.H.

#define IDM_CREATETHREAD 100

Definition at line 24 of file LINKTEST.H.

#define IDM_DLLDIALOGBOX 105

Definition at line 29 of file LINKTEST.H.

#define IDM_DLLFUNCTION1 101

Definition at line 25 of file LINKTEST.H.

#define IDM_DLLFUNCTION2 102

Definition at line 26 of file LINKTEST.H.

#define IDM_DLLFUNCTION3 103

Definition at line 27 of file LINKTEST.H.

#define IDM_DLLFUNCTION4 104

Definition at line 28 of file LINKTEST.H.

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 288 of file APP16.C.

{
   switch( uMsg ) {
      case WM_INITDIALOG:
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;
   }
   return FALSE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

void ThreadProc ( void )

Definition at line 182 of file LINKTEST.C.

{
  MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
              (LPCTSTR) "ThreadProc()", MB_OK);
  DLLFunction1 ();
}

Variable Documentation

HWND ghwndMain

Definition at line 38 of file LINKTEST.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LOADTEST.C File Reference

  • SIMPLDLL
Functions

LOADTEST.C File Reference

#include <windows.h>
#include "loadtest.h"
#include "the_dll.h"

Go to the source code of this file.

Functions

BOOL CALLBACK | AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void | FixMenu (UINT choice, HMENU hSubMenu)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void | ThreadProc ()
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 320 of file LOADTEST.C.

{ switch (message)
  {
    case WM_COMMAND:

      if (LOWORD(wParam) == IDOK)
      {
        EndDialog(hwnd, TRUE);
        return (TRUE);
      }
      return (TRUE);
  }
  return (FALSE);
}

void FixMenu | ( | UINT | choice,
 |  | HMENU | hSubMenu
 | ) |  |

Definition at line 286 of file LOADTEST.C.

{
  UINT i;

  if (choice == IDM_LOADLIBRARY)
  {
    EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_DISABLED | MF_GRAYED |
                                               MF_BYCOMMAND);

    for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)

      EnableMenuItem (hSubMenu, i, MF_ENABLED | MF_BYCOMMAND);
  }
  else /* choice == IDM_FREELIBRARY */
  {
    EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_ENABLED | MF_BYCOMMAND);

    for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)

      EnableMenuItem (hSubMenu, i, MF_DISABLED | MF_GRAYED |MF_BYCOMMAND);

  }
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 110 of file LOADTEST.C.

{ static HANDLE hLib = NULL;
  static HMENU  hSubMenu;

  switch (message)
  {
    case WM_CREATE:
    {
      HMENU hMenu = GetMenu (hwnd);

      hSubMenu = GetSubMenu (hMenu, 0);
      FixMenu (IDM_FREELIBRARY, hSubMenu);
      break;
    }

    case WM_COMMAND:

      switch (LOWORD(wParam))
      {
        case IDM_LOADLIBRARY:

          if (!hLib)
          {
            if (!(hLib = LoadLibrary ("THE_DLL.DLL")))

              MessageBox (hwnd,
                          (LPCTSTR) "MainWndProc(): LoadLibrary () failed",
                          (LPCTSTR) "Err! - LOADTEST",
                          MB_OK | MB_ICONEXCLAMATION);
            else
            {
              gpfnDLLFunction1 = (PFNDLL) GetProcAddress (hLib,
                                                          "DLLFunction1");
              gpfnDLLFunction2 = (PFNDLL) GetProcAddress (hLib,
                                                          "DLLFunction2");
              gpfnDLLFunction3 = (PFNDLL) GetProcAddress (hLib,
                                                          "DLLFunction3");
              gpfnDLLFunction4 = (PFNDLL) GetProcAddress (hLib,
                                                          "DLLFunction4");
              gpfnDLLDialogBox = (PFNDLL) GetProcAddress (hLib,
                                                          "DLLDialogBox");
              FixMenu (IDM_LOADLIBRARY, hSubMenu);
            }
          }
          break;

        case IDM_FREELIBRARY:

          if (hLib)
          {
            FreeLibrary (hLib);
            gpfnDLLFunction1 = NULL;
            gpfnDLLFunction2 = NULL;
            gpfnDLLFunction3 = NULL;
            gpfnDLLFunction4 = NULL;
            gpfnDLLDialogBox = NULL;
            FixMenu (IDM_FREELIBRARY, hSubMenu);
            hLib = NULL;
          }
          break;

        case IDM_CREATETHREAD:
        {
          DWORD tid; /* thread identifier */

          if (gpfnDLLFunction1)

            CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)
                          ThreadProc, NULL, 0, &tid);

          break;
        }

        case IDM_DLLFUNCTION1:

          if (gpfnDLLFunction1)

            (gpfnDLLFunction1) ();

          break;

        case IDM_DLLFUNCTION2:

          if (gpfnDLLFunction2)

            (gpfnDLLFunction2) ((int) 0);

          break;

        case IDM_DLLFUNCTION3:

          if (gpfnDLLFunction3)

            (gpfnDLLFunction3) ((HANDLE) NULL);

          break;

        case IDM_DLLFUNCTION4:

          if (gpfnDLLFunction4)

            (gpfnDLLFunction4) ((HWND) NULL);

          break;

        case IDM_DLLDIALOGBOX:

          if (gpfnDLLDialogBox)

            (gpfnDLLDialogBox) (hwnd);

          break;

        case IDM_ABOUT:

          DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd,
                     (DLGPROC) AboutDlgProc);
          break;

        default:

          break;
      }
      break;

    case WM_DESTROY:

      PostQuitMessage(0);
      break;

    default:

      return (DefWindowProc(hwnd, message, wParam, lParam));
  }
  return (0);
}

void ThreadProc ( void )

Definition at line 262 of file LOADTEST.C.

{
  MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
              (LPCTSTR) "ThreadProc()", MB_OK);
  (gpfnDLLFunction1) ();
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 42 of file LOADTEST.C.

{
  MSG msg;

  if (!hPrevInstance)
  {
    WNDCLASS wc;

    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName  = (LPCTSTR) "Menu";
    wc.lpszClassName = (LPCTSTR) "LOADTEST";

    if (!RegisterClass (&wc))
    {
      MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
                  (LPCTSTR) "Err! - LOADTEST", MB_OK | MB_ICONEXCLAMATION);
      return(FALSE);
    }
  }

  if (!(ghwndMain = CreateWindow ("LOADTEST", "LOADTEST Sample Application",
                                  WS_OVERLAPPEDWINDOW,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  NULL, NULL, hInstance, NULL)))
    return (0);

  ShowWindow (ghwndMain, nCmdShow);

  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage  (&msg);
  }

  return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LOADTEST.H File Reference

  • SIMPLDLL
Defines | Typedefs | Functions | Variables

LOADTEST.H File Reference

Go to the source code of this file.

Defines

#define | IDM_ABOUT 108
#define | IDM_CREATETHREAD 102
#define | IDM_DLLDIALOGBOX 107
#define | IDM_DLLFUNCTION1 103
#define | IDM_DLLFUNCTION2 104
#define | IDM_DLLFUNCTION3 105
#define | IDM_DLLFUNCTION4 106
#define | IDM_FREELIBRARY 101
#define | IDM_LOADLIBRARY 100

Typedefs

typedef int(* | PFNDLL )()

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
void | FixMenu (UINT, HMENU)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
void | ThreadProc (void)

Variables

HWND | ghwndMain
PFNDLL | gpfnDLLDialogBox = NULL
PFNDLL | gpfnDLLFunction1 = NULL
PFNDLL | gpfnDLLFunction2 = NULL
PFNDLL | gpfnDLLFunction3 = NULL
PFNDLL | gpfnDLLFunction4 = NULL

Define Documentation

#define IDM_ABOUT 108

Definition at line 32 of file LOADTEST.H.

#define IDM_CREATETHREAD 102

Definition at line 26 of file LOADTEST.H.

#define IDM_DLLDIALOGBOX 107

Definition at line 31 of file LOADTEST.H.

#define IDM_DLLFUNCTION1 103

Definition at line 27 of file LOADTEST.H.

#define IDM_DLLFUNCTION2 104

Definition at line 28 of file LOADTEST.H.

#define IDM_DLLFUNCTION3 105

Definition at line 29 of file LOADTEST.H.

#define IDM_DLLFUNCTION4 106

Definition at line 30 of file LOADTEST.H.

#define IDM_FREELIBRARY 101

Definition at line 25 of file LOADTEST.H.

#define IDM_LOADLIBRARY 100

Definition at line 24 of file LOADTEST.H.

Typedef Documentation

typedef int(* PFNDLL)()

Definition at line 40 of file LOADTEST.H.

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 288 of file APP16.C.

{
   switch( uMsg ) {
      case WM_INITDIALOG:
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;
   }
   return FALSE;
}

void FixMenu | ( | UINT | ,
 |  | HMENU |
 | ) |  |

Definition at line 286 of file LOADTEST.C.

{
  UINT i;

  if (choice == IDM_LOADLIBRARY)
  {
    EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_DISABLED | MF_GRAYED |
                                               MF_BYCOMMAND);

    for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)

      EnableMenuItem (hSubMenu, i, MF_ENABLED | MF_BYCOMMAND);
  }
  else /* choice == IDM_FREELIBRARY */
  {
    EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_ENABLED | MF_BYCOMMAND);

    for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)

      EnableMenuItem (hSubMenu, i, MF_DISABLED | MF_GRAYED |MF_BYCOMMAND);

  }
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

void ThreadProc ( void )

Definition at line 182 of file LINKTEST.C.

{
  MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
              (LPCTSTR) "ThreadProc()", MB_OK);
  DLLFunction1 ();
}

Variable Documentation

HWND ghwndMain

Definition at line 48 of file LOADTEST.H.

PFNDLL gpfnDLLDialogBox = NULL

Definition at line 54 of file LOADTEST.H.

PFNDLL gpfnDLLFunction1 = NULL

Definition at line 50 of file LOADTEST.H.

PFNDLL gpfnDLLFunction2 = NULL

Definition at line 51 of file LOADTEST.H.

PFNDLL gpfnDLLFunction3 = NULL

Definition at line 52 of file LOADTEST.H.

PFNDLL gpfnDLLFunction4 = NULL

Definition at line 53 of file LOADTEST.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/THE_DLL.C File Reference

  • SIMPLDLL
Functions

THE_DLL.C File Reference

#include <windows.h>
#include "the_dll.h"

Go to the source code of this file.

Functions

INT | DLLDialogBox (HWND hwndParent)
BOOL CALLBACK | DLLDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
INT | DLLFunction1 ()
INT | DLLFunction2 (int i)
INT | DLLFunction3 (HANDLE h)
INT | DLLFunction4 (HWND hwnd)
BOOL WINAPI | DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)

Function Documentation

INT DLLDialogBox ( HWND hwndParent )

Definition at line 213 of file THE_DLL.C.

{
  DialogBox (ghMod, (LPCTSTR) "DLLDlg", hwndParent, (DLGPROC) DLLDlgProc);
  return 1;
}

BOOL CALLBACK DLLDlgProc | ( | HWND | hDlg,
 |  | UINT | msg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 227 of file THE_DLL.C.

{
  switch (msg)
  {
    case WM_COMMAND:

      EndDialog(hDlg, TRUE);
      return (TRUE);
  }
  return (FALSE);
}

INT DLLFunction1 ( void )

Definition at line 141 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction2 ( int i )

Definition at line 159 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction3 ( HANDLE h )

Definition at line 177 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction4 ( HWND hwnd )

Definition at line 195 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

BOOL WINAPI DllMain | ( | HINSTANCE | hDLL,
 |  | DWORD | dwReason,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 71 of file THE_DLL.C.

{
  switch (dwReason)
  {
    case DLL_PROCESS_ATTACH:
    {
      char buf[BUFSIZE+1];

      //
      // DLL is attaching to the address space of the current process.
      //

      ghMod = hDLL;
      GetModuleFileName (NULL, (LPTSTR) buf, BUFSIZE);
      MessageBox ( GetFocus(),
                  (LPCTSTR) buf,
                  (LPCTSTR) "THE_DLL: Process attaching",
                  MB_OK | MB_SYSTEMMODAL);
      break;
    }

    case DLL_THREAD_ATTACH:

      //
      // A new thread is being created in the current process.
      //

      MessageBox ( GetFocus(),
                  (LPCTSTR) "THE_DLL: Thread attaching",
                  (LPCTSTR) "",
                  MB_OK | MB_SYSTEMMODAL);
      break;

    case DLL_THREAD_DETACH:

      //
      // A thread is exiting cleanly.
      //

      MessageBox ( GetFocus(),
                  (LPCTSTR) "THE_DLL: Thread detaching",
                  (LPCTSTR) "",
                  MB_OK | MB_SYSTEMMODAL);
      break;

    case DLL_PROCESS_DETACH:

      //
      // The calling process is detaching the DLL from its address space.
      //
      MessageBox ( GetFocus(),
                  (LPCTSTR) "THE_DLL: Process detaching",
                  (LPCTSTR) "",
                  MB_OK | MB_SYSTEMMODAL );
      break;
  }

return TRUE;
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/THE_DLL.H File Reference

  • SIMPLDLL
Defines | Functions | Variables

THE_DLL.H File Reference

Go to the source code of this file.

Defines

#define | BUFSIZE 80

Functions

INT | DLLDialogBox (HWND)
BOOL CALLBACK | DLLDlgProc (HWND, UINT, WPARAM, LPARAM)
INT | DLLFunction1 (void)
INT | DLLFunction2 (int)
INT | DLLFunction3 (HANDLE)
INT | DLLFunction4 (HWND)

Variables

HANDLE | ghMod

Define Documentation

#define BUFSIZE 80

Definition at line 24 of file THE_DLL.H.

Function Documentation

INT DLLDialogBox ( HWND )

Definition at line 213 of file THE_DLL.C.

{
  DialogBox (ghMod, (LPCTSTR) "DLLDlg", hwndParent, (DLGPROC) DLLDlgProc);
  return 1;
}

BOOL CALLBACK DLLDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 227 of file THE_DLL.C.

{
  switch (msg)
  {
    case WM_COMMAND:

      EndDialog(hDlg, TRUE);
      return (TRUE);
  }
  return (FALSE);
}

INT DLLFunction1 ( void )

Definition at line 141 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction2 ( int )

Definition at line 159 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction3 ( HANDLE )

Definition at line 177 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

INT DLLFunction4 ( HWND )

Definition at line 195 of file THE_DLL.C.

{
  MessageBeep (0);
  return 1;
}

Variable Documentation

HANDLE ghMod

Definition at line 32 of file THE_DLL.H.

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STARTP/STARTP.C File Reference

  • STARTP
Defines | Functions

STARTP.C File Reference

#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Defines

#define | PERR(bSuccess, api) {if (!(bSuccess)) printf("%s: Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

Functions

void | help ()
int | main (int argc, char *argv[])

Define Documentation

#define PERR | ( | bSuccess,
 |  | api |
 | ) |  | {if (!(bSuccess)) printf("%s: Error %d from %s \ on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

Definition at line 44 of file STARTP.C.

Function Documentation

void help ( )

Definition at line 47 of file STARTP.C.

{
  puts("Starts a specified program, batch, or command file.");
  puts("STARTP [options] [program] [parameters]\n");
  puts("  /Ttitle        Title to display in window title bar. Quote the");
  puts("             entire paramter to include spaces in the title");
  puts("  /Dpath         Starting directory");
  puts("  /l|/h|/r       Set priority to low/high/realtime");
  puts("  /min|/max|/hid Start window minimized/maximized/hidden");
  puts("  /w             Wait for started process to end before returning");
  puts("                 control to the command processor. This option starts");
  puts("                 the process synchronously");
  puts("  /c             Use current console instead of creating a new console");
  puts("  /b             Start detached with no console at all");
  puts("  /p             Create new process group for ^c, ^break events");
  puts("  /s             Windows NT: Run Win16 app in separate VDM ");
  puts("  program        A batch file or program to run as either a GUI");
  puts("                 application or a console application");
  puts("  parameters     These are the parameters passed to the program");
  puts("\nNote that the priority parameters may have no effect if the child");
  puts("process changes its own priority.");
  exit(1);
}

int main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 71 of file STARTP.C.

{
  char szArgs[512], *p;  /* new process arguments buffer & temp pointer */
  char szPgmName[MAX_PATH];  /* name of the program */
  BOOL fSuccess;  /* API return code */
  STARTUPINFO si;  /* used for CreateProcess */
  PROCESS_INFORMATION pi;  /* used for CreateProcess */
  LPSTR lpszCurDir = NULL;  /* current directory for new process */
  BOOL bMoreParams;  /* flag end of new process parameter processing */
  BOOL bWait = FALSE;  /* wait/no wait for new process to end */
  DWORD dwResult;  /* API return code */
  DWORD dwCreate = CREATE_NEW_CONSOLE;  /* new process creation flags */
  BOOL bExtension;  /* input filename have an explicit extension? */
  int i;
  /* the following filename extensions must all be 4 chars long */
  char *aExt[] = { ".exe", ".com", ".bat", ".cmd" };
  DWORD dwExitCode;
  DWORD dwVersion = GetVersion();

  /* Check to make sure we are running on Windows NT or Windows 95 */
  if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
    MessageBox( NULL,
       "This application cannot run on Windows 3.1.\n"
       "This application will now terminate.",
       "StartP",
       MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
    return(1);
    }
  /* process all command-line parameters */
  if (argc < 2)
    help();
  memset(&si, 0, sizeof(STARTUPINFO));
  bMoreParams = TRUE;
  while(bMoreParams)
    {
    argv++;  /* point to the first parameter */
    if (!*argv) /* if *argv is NULL we're missing the program name! */
      {
      puts("Error: missing program name");
      exit(1);
      }
    if ((*argv)[0] == '/' || (*argv)[0] == '-')
      {
      strlwr(*argv);
      switch ((*argv)[1])  /* letter after the '/' or '-' */
        {
        case 't':
          si.lpTitle = &(*argv)[2];  /*  /Ttitle */
          break;
        case 'd':
          lpszCurDir = &(*argv)[2];  /*  /Dpath */
          break;
        case 'h':
      switch ((*argv)[2])
        {
      case '\0':
            dwCreate |= HIGH_PRIORITY_CLASS;
            break;
          case 'i':
            si.wShowWindow = SW_HIDE;
            si.dwFlags |= STARTF_USESHOWWINDOW;
      break;
            default:
              printf("Error: invalid switch - \"%s\"", *argv);
              help();
            } /* switch */
      break;
        case 'l':
          dwCreate |= IDLE_PRIORITY_CLASS;
          break;
        case 'r':
          dwCreate |= REALTIME_PRIORITY_CLASS;
          break;
        case 'm':
          switch ((*argv)[2])
            {
            case 'i':
              si.wShowWindow = SW_SHOWMINNOACTIVE;
              si.dwFlags |= STARTF_USESHOWWINDOW;
              break;
            case 'a':
              si.wShowWindow = SW_SHOWMAXIMIZED;
              si.dwFlags |= STARTF_USESHOWWINDOW;
              break;
            default:
              printf("Error: invalid switch - \"%s\"", *argv);
              help();
            } /* switch */
          break;
        case '?':
          help();  /* help() will terminate app */
        case 'w':
          bWait = TRUE;  /* don't end until new process ends as well */
          break;
        case 'b':
          dwCreate |= DETACHED_PROCESS;  /* start detached */
          /* detached implies no CREATE_NEW_CONSOLE so fall through */
        case 'c':
          dwCreate &= ~CREATE_NEW_CONSOLE;  /* turn off this bit */
          break;
        case 'p':
          dwCreate |= CREATE_NEW_PROCESS_GROUP;
          break;
        case 's':
          dwCreate |= CREATE_SEPARATE_WOW_VDM;
          break;
        case 'u':
          dwCreate |= CREATE_UNICODE_ENVIRONMENT;
          break;
        default:
          printf("Error: invalid switch - \"%s\"", *argv);
          help();
        } /* switch */
      } /* if */
    else  /* not a '-' or '/', must be the program name */
      bMoreParams = FALSE;
    } /* while */
  strcpy(szPgmName, *argv++);  /* copy program name as first param */
  bExtension = (BOOL) strchr(szPgmName, '.');  /* has an extension? */
  if (!bExtension)
    strcat(szPgmName, aExt[0]);  /* first extension to try */
  memset(szArgs, 0, sizeof(szArgs));
  strcpy(szArgs, szPgmName);  /* first arg: program name */
  p = strchr(szArgs, 0);  /* point past program name */
  while (*argv)  /* copy remaining arguments to szArgs separated by spaces */
    {
    strcat(p, " ");
    strcat(p, *argv++);
    }
  si.cb = sizeof(STARTUPINFO);
  i = 1;
  do
    {
    fSuccess = CreateProcess(NULL,  /* image file name */
        szArgs,  /* command line (including program name) */
        NULL,  /* security for process */
        NULL,  /* security for main thread */
        FALSE,  /* new process inherits handles? */
        dwCreate,  /* creation flags */
        NULL,  /* environment */
        lpszCurDir,  /* new current directory */
        &si,  /* STARTUPINFO structure */
        &pi);  /* PROCESS_INFORMATION structure */
    if (!fSuccess)
      switch (GetLastError())  /* process common errors */
        {
        case ERROR_FILE_NOT_FOUND:
          if (bExtension || i > 3)
            {
            puts("Error: program or batch file not found");
            exit(1);
            }
          else /* replace the filename extension with the next one */
            {
            strcpy(strchr(szPgmName, '.'), aExt[i++]);
            strncpy(szArgs, szPgmName, strlen(szPgmName));
            }
          break;
        case ERROR_DIRECTORY:
          puts("Error: bad starting directory");
          exit(1);
        case ERROR_PATH_NOT_FOUND:
          puts("Error: bad path");
          exit(1);
        default:
          PERR(0, "CreateProcess");
          exit(1);
        }  /* switch */
    } while (!fSuccess);
  /* pi.dwProcessId for win16 apps is actually an event handle, not */
  /* a process handle, so it can only be used with synchronization APIs */
  printf("Process %d (0x%x) created\n", pi.dwProcessId, pi.dwProcessId);
  /* close thread handle if not needed anymore */
  CloseHandle(pi.hThread);
  if (bWait)  /* /w flag specified? */
    {
    dwResult = WaitForSingleObject(pi.hProcess,  /* object to wait for */
        (DWORD) -1);  /* timeout time */
    PERR(dwResult != -1, "WaitForSingleObject");
    /* get and report the child's exit code */
    fSuccess = GetExitCodeProcess(pi.hProcess, &dwExitCode);
    PERR(fSuccess, "GetExitCodeProcess");
    printf("Child exit code: %d\n", dwExitCode);
    }
  CloseHandle(pi.hProcess);  /* close process handle or it won't die */
  return(0);
}

Generated on Wed Nov 13 2024 17:29:12 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/BITMAP.C File Reference

  • STREBLT
Functions

BITMAP.C File Reference

#include <windows.h>
#include <commdlg.h>

Go to the source code of this file.

Functions

VOID | DrawBitmap (HDC hdc, HBITMAP hbm)
HBITMAP | GetBitmap (HDC hdc, HANDLE hInst, BOOL monochrome)

Function Documentation

VOID DrawBitmap | ( | HDC | hdc,
 |  | HBITMAP | hbm
 | ) |  |

Definition at line 33 of file BITMAP.C.

{
    BOOL f;
    HDC hdcBits;
    BITMAP bm;

    hdcBits = CreateCompatibleDC(hdc);
    GetObject (hbm, sizeof(BITMAP), &bm);
    SelectObject(hdcBits,hbm);
    f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
    DeleteDC(hdcBits);
}

HBITMAP GetBitmap | ( | HDC | hdc,
 |  | HANDLE | hInst,
 |  | BOOL | monochrome
 | ) |  |

Definition at line 63 of file BITMAP.C.

{
    HBITMAP hbm;
    PBITMAPFILEHEADER pbmfh;
    PBITMAPINFOHEADER pbmih;
    PBYTE             pBits;
    int fh;
    int bfOffBits;
    int nbytes;
    OPENFILENAME  of;
    char buffer [MAX_PATH];

    buffer[0] = 0;

    /* set up the OPENFILE structure,
     *  then use the appropriate common dialog
     */
    of.lStructSize       = sizeof (OPENFILENAME);
    of.hwndOwner         = NULL;
    of.hInstance         = hInst;
    of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter    = 0;
    of.nFilterIndex      = 0;
    of.lpstrFile         = buffer;
    of.nMaxFile          = MAX_PATH;
    of.lpstrFileTitle    = NULL;
    of.nMaxFileTitle     = 0;
    of.lpstrInitialDir   = "c:\\nt\\windows";
    of.lpstrTitle        = NULL;
    of.Flags             = OFN_HIDEREADONLY;
    of.nFileOffset       = 0;
    of.nFileExtension    = 0;
    of.lpstrDefExt       = NULL;
    of.lCustData         = 0;
    of.lpfnHook          = NULL;
    of.lpTemplateName    = NULL;
    if (!GetOpenFileName (&of)) return NULL;

    /* Try to open the file.  If successful, then allocate space for it,
     *  and read in all of the bytes.
     */
    fh = _lopen (buffer, OF_READ);
    if (fh == -1) return NULL;
    nbytes = GetFileSize ((HANDLE) fh, NULL);

    /* The contents of the file are read in here in three parts.  First
     *  the bitmap file header is read, then the bitmap header along with
     *  the color table, then finally the actual bit data.  I.e. from
     *  a total of nbytes...
     *    1.  sizeof (BITMAPFILEHEADER)
     *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
     *    3.  (nbytes - bfOffBits)
     */

    /* read in the bitmap file header.  save the offset to bits. */
    if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
    bfOffBits=pbmfh->bfOffBits;

    /* read in the bitmap info header and the color table right after it.
     * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
     */
    if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));

    /* finally read in the bit data. */
    if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
    _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));

    /* in the case of desiring a monochrome bitmap (input parameter),
     *  verify that is what we got.  If it is, then use CreateBitmap,
     *  else use a device independent bitmap.
     */
    if (monochrome) {
      if (pbmih->biBitCount != 1) {
        MessageBox (NULL, "Mask must be monochrome bitmap.",
                    "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
        hbm = NULL;
      } else {
      hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
                          pbmih->biPlanes, pbmih->biBitCount,
                          pBits);
      }
    } else  /* bitmap is NOT monochrome, use DIB. */
      hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
                          pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);

    /* hbm is set... free up memory, and return */
    LocalFree (LocalHandle ((LPSTR)pBits));
    LocalFree (LocalHandle ((LPSTR)pbmih));
    LocalFree (LocalHandle ((LPSTR)pbmfh));
    _lclose (fh);

    return hbm;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/BITMAP.H File Reference

  • STREBLT
Functions

BITMAP.H File Reference

Go to the source code of this file.

Functions

VOID | DrawBitmap (HDC, HBITMAP)
HBITMAP | GetBitmap (HDC, HANDLE, BOOL)

Function Documentation

VOID DrawBitmap | ( | HDC | ,
 |  | HBITMAP |
 | ) |  |

Definition at line 33 of file BITMAP.C.

{
    BOOL f;
    HDC hdcBits;
    BITMAP bm;

    hdcBits = CreateCompatibleDC(hdc);
    GetObject (hbm, sizeof(BITMAP), &bm);
    SelectObject(hdcBits,hbm);
    f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
    DeleteDC(hdcBits);
}

HBITMAP GetBitmap | ( | HDC | ,
 |  | HANDLE | ,
 |  | BOOL |
 | ) |  |

Definition at line 63 of file BITMAP.C.

{
    HBITMAP hbm;
    PBITMAPFILEHEADER pbmfh;
    PBITMAPINFOHEADER pbmih;
    PBYTE             pBits;
    int fh;
    int bfOffBits;
    int nbytes;
    OPENFILENAME  of;
    char buffer [MAX_PATH];

    buffer[0] = 0;

    /* set up the OPENFILE structure,
     *  then use the appropriate common dialog
     */
    of.lStructSize       = sizeof (OPENFILENAME);
    of.hwndOwner         = NULL;
    of.hInstance         = hInst;
    of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
    of.lpstrCustomFilter = NULL;
    of.nMaxCustFilter    = 0;
    of.nFilterIndex      = 0;
    of.lpstrFile         = buffer;
    of.nMaxFile          = MAX_PATH;
    of.lpstrFileTitle    = NULL;
    of.nMaxFileTitle     = 0;
    of.lpstrInitialDir   = "c:\\nt\\windows";
    of.lpstrTitle        = NULL;
    of.Flags             = OFN_HIDEREADONLY;
    of.nFileOffset       = 0;
    of.nFileExtension    = 0;
    of.lpstrDefExt       = NULL;
    of.lCustData         = 0;
    of.lpfnHook          = NULL;
    of.lpTemplateName    = NULL;
    if (!GetOpenFileName (&of)) return NULL;

    /* Try to open the file.  If successful, then allocate space for it,
     *  and read in all of the bytes.
     */
    fh = _lopen (buffer, OF_READ);
    if (fh == -1) return NULL;
    nbytes = GetFileSize ((HANDLE) fh, NULL);

    /* The contents of the file are read in here in three parts.  First
     *  the bitmap file header is read, then the bitmap header along with
     *  the color table, then finally the actual bit data.  I.e. from
     *  a total of nbytes...
     *    1.  sizeof (BITMAPFILEHEADER)
     *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
     *    3.  (nbytes - bfOffBits)
     */

    /* read in the bitmap file header.  save the offset to bits. */
    if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
    bfOffBits=pbmfh->bfOffBits;

    /* read in the bitmap info header and the color table right after it.
     * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
     */
    if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
        return NULL;
    _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));

    /* finally read in the bit data. */
    if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
    _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));

    /* in the case of desiring a monochrome bitmap (input parameter),
     *  verify that is what we got.  If it is, then use CreateBitmap,
     *  else use a device independent bitmap.
     */
    if (monochrome) {
      if (pbmih->biBitCount != 1) {
        MessageBox (NULL, "Mask must be monochrome bitmap.",
                    "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
        hbm = NULL;
      } else {
      hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
                          pbmih->biPlanes, pbmih->biBitCount,
                          pBits);
      }
    } else  /* bitmap is NOT monochrome, use DIB. */
      hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
                          pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);

    /* hbm is set... free up memory, and return */
    LocalFree (LocalHandle ((LPSTR)pBits));
    LocalFree (LocalHandle ((LPSTR)pbmih));
    LocalFree (LocalHandle ((LPSTR)pbmfh));
    _lclose (fh);

    return hbm;
}

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/STREBLT.C File Reference

  • STREBLT
Defines | Functions | Variables

STREBLT.C File Reference

#include <windows.h>
#include <commdlg.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "streblt.h"
#include "track.h"
#include "bitmap.h"

Go to the source code of this file.

Defines

#define | NONE -1
#define | TICKSPACE 20

Functions

BOOL CALLBACK | DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | DrawGrids (HDC hdc, int width, int height)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HBITMAP | hbmSrc = NULL
HDC | hdcDest
HDC | hdcSrc
HANDLE | hInst
HWND | hwndDlg
HWND | hwndMain
int | iPatternBrush = NONE
PTrackObject | ptoDest = NULL
PTrackObject ptoSrc
int | strebltMode = NONE

Define Documentation

#define NONE -1

Definition at line 42 of file STREBLT.C.

#define TICKSPACE 20

Definition at line 796 of file STREBLT.C.

Function Documentation

BOOL CALLBACK DlgProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 561 of file STREBLT.C.

{
  char buffer[MAXCHARS];

  UNREFERENCED_PARAMETER(lParam);

  switch (message) {
    /**********************************************************************\
    *  WM_INITDIALOG
    *
    * Fill the entry fields with sensible original values.
    *  Also fill the combo boxes with the text entries from lookup tables.
    \**********************************************************************/
    case WM_INITDIALOG: {
      int i;

      for ( i = DID_X; i<= DID_SRCHEIGHT; i++)
        SetDlgItemText(hwnd, i , "0");

      SetDlgItemText(hwnd, DID_ROP0  , "cc");
      SetDlgItemText(hwnd, DID_ROP1  , "00");
      SetDlgItemText(hwnd, DID_ROP2  , "20");

      for (i = 0; i< NMODES; i++)
        SendDlgItemMessage (hwnd, DID_CB_MODE, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)strebltModes[i].String);

      for (i = 0; i< NPATTERNS; i++)
        SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)Patterns[i].String);

      for (i = 0; i< NROPS; i++)
        SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)StandardROPs[i].String);

    } return TRUE;

    /**********************************************************************\
    *  WM_PUTUPDESTRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the destination rectangle points.
    *  Conditionally change <x,y> or <width,height> depending on tracking mode.
    \**********************************************************************/
    case WM_PUTUPDESTRECT: {
        POINT p1,p2, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p2.x = pto->rect.right;
        p2.y = pto->rect.bottom;
        LPtoDP (pto->hdc, &p2, 1);
        p2.x -= p1.x; p2.y -= p1.y;

        p1.x -= origin.x; p1.y -= origin.y;

        if (!(pto->Mode & TMSIZEXY)) {
          SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
          SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
        }

        if (!(pto->Mode & TMMOVE)) {
          SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
          SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
        }
    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPSRCRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the source rectangle points.
    *  Conditionally change <x,y> or <width,height> depending on tracking mode.
    \**********************************************************************/
    case WM_PUTUPSRCRECT: {
        POINT p1,p2, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p2.x = pto->rect.right;
        p2.y = pto->rect.bottom;
        LPtoDP (pto->hdc, &p2, 1);
        p2.x -= p1.x; p2.y -= p1.y;

        p1.x -= origin.x; p1.y -= origin.y;

        if (!(pto->Mode & TMSIZEXY)) {
          SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
          SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);
        }

        if (!(pto->Mode & TMMOVE)) {
          SetDlgItemInt(hwnd, DID_SRCWIDTH,  p2.x, TRUE);
          SetDlgItemInt(hwnd, DID_SRCHEIGHT, p2.y, TRUE);
        }
    } return FALSE;

    case WM_COMMAND:

      switch (LOWORD(wParam)) {

        /******************************************************************\
        *  WM_COMMAND, DID_DRAW
        *
        * Draw button hit - send main window message to call StretchBlt().
        \******************************************************************/
        case DID_DRAW:
          SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_NEWSRC
        *
        * Try to get a new source bitmap. If successful, store it in the
        *  global handle (hbmSrc) then invalidate two sub windows so that
        *  we force a complete repaint in both.
        \******************************************************************/
        case DID_NEWSRC: {
          HBITMAP hbm;
          if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
            DeleteObject (hbmSrc);
            hbmSrc = hbm;
            InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }

        } break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_MODE
        *
        * A new streblt mode was selected.  Look up the value, store it
        *  in a global variable (strebltMode), then force a new StretchBlt
        \******************************************************************/
        case DID_CB_MODE:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            strebltMode = strebltModes[iSel].Value;

            SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_PATTERN
        *
        * A new pattern brush was selected.  Look up the value, store it
        *  in a global variable (iPatternBrush), then force a new StretchBlt
        \******************************************************************/
        case DID_CB_PATTERN:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            iPatternBrush = Patterns[iSel].Value;

            SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_ROPS
        *
        * A new standard rop entry was selected.  Lookup the value,
        *  then break it into three parts, convert to hex, and put
        *  it in the proper entry fields.
        \******************************************************************/
        case DID_CB_ROPS:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel, rop;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            rop = StandardROPs[iSel].Value;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP2, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP1, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP0, buffer);

            SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
          }
        break;

      } /* end switch */

    return FALSE; /* end WM_COMMAND */

  } /* end switch */
  return 0;
}

VOID DrawGrids | ( | HDC | hdc,
 |  | int | width,
 |  | int | height
 | ) |  |

Definition at line 809 of file STREBLT.C.

{
int i;

    /* Draw vertical lines. Double at the axis */
    for (i = 0; i<= width; i+=TICKSPACE){
      MoveToEx (hdc, i, 0, NULL);
      LineTo (hdc, i, height);
    }
    MoveToEx (hdc, 1, 0, NULL);
    LineTo (hdc, 1, height);

    /* Draw horizontal lines. Double at the axis */
    for (i = 0; i<= height; i+=TICKSPACE){
      MoveToEx (hdc, 0,i, NULL);
      LineTo (hdc, width,i);
    }
    MoveToEx (hdc, 0, 1, NULL);
    LineTo (hdc, width,1);

  return;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 174 of file STREBLT.C.

{
  static int miniWidth;
  static RECT rect;
  char buffer[MAXCHARS];
  static HANDLE hPenGrid, hPenSeparator;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Get the two hdc's for this window, allocate two track objects,
    *  and then create two pens to be used when painting the windows.
    \**********************************************************************/
    case WM_CREATE:
      hdcSrc  = GetDC (hwnd);
      hdcDest = GetDC (hwnd);

      ptoDest = doTrackObject (NULL, TROB_NEW, hwnd,0);
      ptoSrc  = doTrackObject (NULL, TROB_NEW, hwnd,0);

      hPenGrid      = CreatePen (PS_SOLID, 1, GRIDCOLOR);
      hPenSeparator = CreatePen (PS_SOLID, 2*SEPARATORWIDTH, (COLORREF) 0x01000000);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Complement of WM_CREATE.  Free up all of the HDCs, send all of the
    *  track objects their delete messages, then call PostQuitMessage.
    \**********************************************************************/
    case WM_DESTROY:
      ReleaseDC (hwnd, hdcSrc );
      ReleaseDC (hwnd, hdcDest);
      doTrackObject (ptoDest, TROB_DELETE, hwnd,0);
      doTrackObject (ptoSrc , TROB_DELETE, hwnd,0);

      DeleteObject(hPenGrid);
      DeleteObject(hPenSeparator);

      PostQuitMessage(0);
    break;

    /**********************************************************************\
    *  WM_SIZE
    *
    * streblt the top dialog to fill the width of the main window.
    * Adjust the viewport origins of the 4 HDCs.
    * Set the clip regions of the 4 HDCs.
    \**********************************************************************/
    case WM_SIZE: {
        HRGN hrgn;

        SetWindowPos (hwndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);

        GetClientRect (hwndMain, &rect);
        miniWidth = rect.right/2;

        SetViewportOrgEx (hdcDest,      0,           DIALOGHEIGHT, NULL);
        SetViewportOrgEx (ptoDest->hdc, 0,           DIALOGHEIGHT, NULL);
        SetViewportOrgEx (hdcSrc,       miniWidth,   DIALOGHEIGHT, NULL);
        SetViewportOrgEx (ptoSrc->hdc,  miniWidth,   DIALOGHEIGHT, NULL);

        ptoDest->rectClip.left    = 0;
        ptoDest->rectClip.top     = DIALOGHEIGHT;
        ptoDest->rectClip.right   = miniWidth-2*SEPARATORWIDTH;
        ptoDest->rectClip.bottom  = rect.bottom;
        hrgn = CreateRectRgnIndirect (&ptoDest->rectClip);
        SelectClipRgn (hdcDest,      hrgn);
        SelectClipRgn (ptoDest->hdc, hrgn);
        DeleteObject (hrgn);

        ptoSrc->rectClip.left    = miniWidth;
        ptoSrc->rectClip.top     = DIALOGHEIGHT;
        ptoSrc->rectClip.right   = 2*miniWidth;
        ptoSrc->rectClip.bottom  = rect.bottom;
        hrgn = CreateRectRgnIndirect (&ptoSrc->rectClip);
        SelectClipRgn (hdcSrc,       hrgn);
        SelectClipRgn (ptoSrc->hdc,  hrgn);
        DeleteObject (hrgn);

        SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD)hdcDest, (LONG)ptoDest);
        SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD)hdcSrc,  (LONG)ptoSrc);

        InvalidateRect (hwnd, NULL, TRUE);
    } break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * miniWidth, rect -- set by WM_SIZE message.
    *
    * First shift the viewport origin down so that 0,0 is the top left
    *  most visible point (out from underneath the top dialog).  Second,
    *  draw the grid with wider lines on the axes.  Finally, read the
    *  values out of the top dialog, do elementary validation, and then
    *  try to call StretchBlt() with the values.
    \**********************************************************************/
     case WM_PAINT: {
        HDC hdc;
        PAINTSTRUCT ps;

        hdc = BeginPaint(hwnd, &ps);

        /* Draw Separator lines for the three miniareas */
        SelectObject(hdc, hPenSeparator);
        MoveToEx (hdc, miniWidth-SEPARATORWIDTH,0, NULL);
        LineTo (hdc, miniWidth-SEPARATORWIDTH , rect.bottom);

        /* Grid the 2 HDCs */
        SelectObject (hdcSrc, hPenGrid);
        DrawGrids (hdcSrc, miniWidth, rect.bottom);
        SelectObject (hdcDest, hPenGrid);
        DrawGrids (hdcDest, miniWidth, rect.bottom);

        /* if a source bitmap has been selected, draw it. */
        if (hbmSrc)  DrawBitmap (hdcSrc, hbmSrc);

        /* paint the source track object on top of the bitmap */
        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);

        /* make the call to StretchBlt() for the left half the window */
        SendMessage (hwnd, WM_STRETCHBLT, 0,0);

        EndPaint (hwnd, &ps);
    } return FALSE;

    /**********************************************************************\
    *  WM_STRETCHBLT
    *
    * Separate out the StretchBlt() call from the rest of the WM_PAINT
    *  case in this user message.  In this way, we can blt() without erasing
    *  and/or repaint all of the rest of the window.  Send this message when
    *  only the blt() should be done.  Invalidate the left half of the window
    *  when it should be erased, re-grided, and then blt()ed.
    \**********************************************************************/
    case WM_STRETCHBLT: {
        int X,    Y,    nWidth,    nHeight,
            XSrc, YSrc, nSrcWidth, nSrcHeight;
        LONG rop, ropByte;
        BOOL success;

        /* erase source track object, or top left sides will show up in blt. */
        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);

        /* Get the parameters out of the top dialog box and call StretchBlt */
        if (IsWindow(hwndDlg)) {

          X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
          Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
          nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
          nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);
          XSrc = GetDlgItemInt(hwndDlg, DID_XSRC, &success, TRUE);
          YSrc = GetDlgItemInt(hwndDlg, DID_YSRC, &success, TRUE);
          nSrcWidth = GetDlgItemInt(hwndDlg,  DID_SRCWIDTH, &success, TRUE);
          nSrcHeight = GetDlgItemInt(hwndDlg, DID_SRCHEIGHT, &success, TRUE);

          /* get high order ROP byte and shift left by two bytes. */
          GetDlgItemText(hwndDlg, DID_ROP0, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop = ropByte * 256 * 256;

          /* get the next ROP byte and shift left by one byte. */
          GetDlgItemText(hwndDlg, DID_ROP1, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop += ropByte * 256;

          /* finally, get the low order ROP byte. */
          GetDlgItemText(hwndDlg, DID_ROP2, buffer, MAXCHARS);
          sscanf (buffer, "%lx", &ropByte);
          rop += ropByte;

          /* set streblt mode.  (user selects via combo box.) */
          if (strebltMode != NONE)
            SetStretchBltMode (hdcDest, strebltMode);

          /* select the pattern brush.  (user selects via combo box.) */
          if (iPatternBrush != NONE)
            SelectObject (hdcDest, GetStockObject (iPatternBrush));

          /**********************************************************/
          /**********************************************************/
          StretchBlt (hdcDest, X,    Y,    nWidth,    nHeight,
                      hdcSrc,  XSrc, YSrc, nSrcWidth, nSrcHeight, rop);
          /**********************************************************/
          /**********************************************************/
        }

        /* redraw source track object which was erased temporarily. */
        doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
    } break;

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    * On button down messages, hittest on the track object, and if
    *  it returns true, then send these messages to the track object.
    \**********************************************************************/
    case WM_LBUTTONDOWN:
      if (doTrackObject(ptoDest, TROB_HITTEST, hwnd, lParam))
         doTrackObject(ptoDest, message, hwnd, lParam);
      else if (doTrackObject(ptoSrc, TROB_HITTEST, hwnd, lParam))
         doTrackObject(ptoSrc, message, hwnd, lParam);
    break;

    /**********************************************************************\
    *  WM_LBUTTONUP
    * If the track object is in a "tracking mode" then send it this message.
    *  For the source track object, just send a STRETCHBLT message.
    *  For the dest. track object, invalidate the left half causing erase.
    \**********************************************************************/
    case WM_LBUTTONUP:
      if (ptoDest->Mode) {
        doTrackObject(ptoDest, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
        InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
        InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
      }
      if (ptoSrc->Mode) {
        doTrackObject(ptoSrc, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
        PostMessage (hwndMain, WM_STRETCHBLT, 0,0);
      }
    break;

    /**********************************************************************\
    *  MW_MOUSEMOVE
    * If the track object is in a "tracking mode" then send it these messages.
    *  Also, update the coordinates in the top dialog box.
    \**********************************************************************/
    case WM_MOUSEMOVE:
      if (ptoDest->Mode) {
        doTrackObject(ptoDest, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
      }
      if (ptoSrc->Mode) {
        doTrackObject(ptoSrc, message, hwnd, lParam);
        SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
      }
    break;

    /**********************************************************************\
    *  Accelerator & clipboard support.
    *
    * Certain key strokes (c.f. *.rc) will cause the following WM_COMMAND
    *  messages.  In response the app will copy a bitmap into the clipboard
    *  or paste down from it.  In both cases, it is necessary to create a
    *  new bitmap since a bitmap in the clipboard belongs to the clipboard
    *  and not to the application.
    \**********************************************************************/
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        HBITMAP hbmCompat, hbmOld;
        HDC hdcCompat;

        /******************************************************************\
        *  WM_COMMAND, AID_COPY
        *
        * Create a new bitmap, copy the destination HDC bits into it,
        *  and send the new bitmap to the clipboard.
        \******************************************************************/
        case AID_COPY: {
          int X,Y, nWidth, nHeight;
          BOOL success;

          X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
          Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
          nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
          nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);

          hdcCompat = CreateCompatibleDC(hdcDest);
          hbmCompat = CreateCompatibleBitmap (hdcDest, nWidth, nHeight);
          hbmOld = SelectObject(hdcCompat,hbmCompat);

          BitBlt (hdcCompat, 0,0,nWidth, nHeight, hdcDest, X,Y, SRCCOPY );

          SelectObject(hdcCompat,hbmOld);
          DeleteDC(hdcCompat);

          OpenClipboard (hwnd);
          SetClipboardData (CF_BITMAP,hbmCompat);
          CloseClipboard ();

          DeleteObject (hbmCompat);

        } break;

        /******************************************************************\
        *  WM_COMMAND, AID_PASTE
        *
        * Get bitmap handle from clipboard, create a new bitmap, draw
        *  the clipboard bitmap into the new one, and store the new
        *  handle in the global hbmSrc.
        \******************************************************************/
        case AID_PASTE: {
          HBITMAP hbm;
          BITMAP bm;

          OpenClipboard (hwnd);
          if ( hbm = GetClipboardData (CF_BITMAP)) {
            DeleteObject (hbmSrc);

            GetObject (hbm, sizeof(BITMAP), &bm);

            hdcCompat = CreateCompatibleDC(hdcDest);
            hbmCompat = CreateCompatibleBitmap (hdcDest, bm.bmWidth, bm.bmHeight);
            hbmOld = SelectObject(hdcCompat,hbmCompat);

            DrawBitmap (hdcCompat, hbm);

            SelectObject(hdcCompat,hbmOld);
            DeleteDC(hdcCompat);

            hbmSrc = hbmCompat;

            InvalidateRect (hwnd, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwnd, &ptoDest->rectClip, TRUE);
          }
          CloseClipboard ();
        } break;

        /******************************************************************\
        *  WM_COMMAND, AID_CYCLE
        *
        * Post a COPY and PASTE command message to this window so that with
        *  one key stroke the user can copy the DEST image into the clipboard,
        *  paste it down into the SRC hdc and cause the blt.
        \******************************************************************/
        case AID_CYCLE:
          PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_COPY , 1), 0);
          PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_PASTE, 1), 0);
        break;
      }  /* end switch */

    break;  /* end wm_command */

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 57 of file STREBLT.C.

{
    MSG   msg;
    RECT rect;
    HANDLE haccel;
    DWORD dwVersion;

    UNREFERENCED_PARAMETER( lpCmdLine );

    // check if running on Windows NT, if not, display notice and terminate
    dwVersion = GetVersion();
    if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4))
    {
        MessageBoxA( NULL,
            "This sample application cannot be run on Windows 3.1.\n"
            "This application will now terminate.",
            "StreBlt",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

    /* Check for previous instance.  If none, then register class. */
    if (!hPrevInstance) {
        WNDCLASS  wc;

        wc.style = 0;
        wc.lpfnWndProc = (WNDPROC)MainWndProc;

        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hInstance;
        wc.hIcon = LoadIcon(hInstance, "strebltIcon");
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
        wc.lpszMenuName =  NULL;
        wc.lpszClassName = "streblt";

        if (!RegisterClass(&wc)) return (FALSE);
    }  /* class registered o.k. */

    /* Create the main window.  Return false if CreateWindow() fails */
    hInst = hInstance;

    hwndMain = CreateWindow(
        "streblt",
        "StretchBlt()",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL);

    if (!hwndMain) return (FALSE);

    /* create the top dialog as a child of the main window. */
    hwndDlg = CreateDialog (hInst, "strebltDlg", hwndMain, (DLGPROC)DlgProc);

    /* Send main window a WM_SIZE message so that it will size the top
     *  dialog correctly.  Also, force a repaint of the main window
     *  now that the dialog is there and we can draw the arc.
     */
    GetClientRect (hwndMain, &rect);
    SendMessage (hwndMain, WM_SIZE, 0, (rect.right - rect.left));
    ShowWindow (hwndDlg, SW_SHOW);
    ShowWindow(hwndMain, nCmdShow);

    /* Load the accelerator table that provides clipboard support. */
    haccel = LoadAccelerators (hInst, "bltAccel");

    /* Loop getting messages and dispatching them. */
    while (GetMessage(&msg,NULL, 0,0)) {
      if (!TranslateAccelerator(hwndMain, haccel, &msg))
      if (!IsDialogMessage (hwndDlg, &msg)) {
        DispatchMessage(&msg);
      }
    }

    return (msg.wParam);           /* Returns the value from PostQuitMessage */
}

Variable Documentation

HBITMAP hbmSrc = NULL

Definition at line 40 of file STREBLT.C.

HDC hdcDest

Definition at line 39 of file STREBLT.C.

HDC hdcSrc

Definition at line 39 of file STREBLT.C.

HANDLE hInst

Definition at line 35 of file STREBLT.C.

HWND hwndDlg

Definition at line 36 of file STREBLT.C.

HWND hwndMain

Definition at line 36 of file STREBLT.C.

int iPatternBrush = NONE

Definition at line 44 of file STREBLT.C.

PTrackObject ptoDest = NULL

Definition at line 38 of file STREBLT.C.

PTrackObject ptoSrc

Definition at line 38 of file STREBLT.C.

int strebltMode = NONE

Definition at line 43 of file STREBLT.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/STREBLT.H File Reference

  • STREBLT
Data Structures | Defines | Typedefs | Functions | Variables

STREBLT.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | AID_COPY 56
#define | AID_CYCLE 57
#define | AID_PASTE 55
#define | DIALOGHEIGHT 90
#define | DID_CB_MODE 150
#define | DID_CB_PATTERN 151
#define | DID_CB_ROPS 152
#define | DID_DRAW 120
#define | DID_HEIGHT 103
#define | DID_NEWSRC 116
#define | DID_ROP0 110
#define | DID_ROP1 111
#define | DID_ROP2 112
#define | DID_SRCHEIGHT 107
#define | DID_SRCWIDTH 106
#define | DID_WIDTH 102
#define | DID_X 100
#define | DID_XSRC 104
#define | DID_Y 101
#define | DID_YSRC 105
#define | GRIDCOLOR (COLORREF) 0x01000006
#define | INC 5
#define | MAXCHARS 32
#define | NMODES 5
#define | NPATTERNS 6
#define | NROPS 15
#define | SEPARATORWIDTH 4
#define | WM_PUTUPDESTRECT WM_USER+20
#define | WM_PUTUPSRCRECT WM_USER+21
#define | WM_STRETCHBLT WM_USER+23

Typedefs

typedef struct tagLookupEntry | LookupEntry

Functions

BOOL CALLBACK | DlgProc (HWND, UINT, WPARAM, LPARAM)
VOID | DrawGrids (HDC, int, int)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)

Variables

LookupEntry | Patterns [NPATTERNS]
LookupEntry | StandardROPs [NROPS]
LookupEntry | strebltModes [NMODES]

Define Documentation

#define AID_COPY 56

Definition at line 45 of file STREBLT.H.

#define AID_CYCLE 57

Definition at line 46 of file STREBLT.H.

#define AID_PASTE 55

Definition at line 44 of file STREBLT.H.

#define DIALOGHEIGHT 90

Definition at line 52 of file STREBLT.H.

#define DID_CB_MODE 150

Definition at line 38 of file STREBLT.H.

#define DID_CB_PATTERN 151

Definition at line 39 of file STREBLT.H.

#define DID_CB_ROPS 152

Definition at line 40 of file STREBLT.H.

#define DID_DRAW 120

Definition at line 36 of file STREBLT.H.

#define DID_HEIGHT 103

Definition at line 25 of file STREBLT.H.

#define DID_NEWSRC 116

Definition at line 34 of file STREBLT.H.

#define DID_ROP0 110

Definition at line 31 of file STREBLT.H.

#define DID_ROP1 111

Definition at line 32 of file STREBLT.H.

#define DID_ROP2 112

Definition at line 33 of file STREBLT.H.

#define DID_SRCHEIGHT 107

Definition at line 29 of file STREBLT.H.

#define DID_SRCWIDTH 106

Definition at line 28 of file STREBLT.H.

#define DID_WIDTH 102

Definition at line 24 of file STREBLT.H.

#define DID_X 100

Definition at line 22 of file STREBLT.H.

#define DID_XSRC 104

Definition at line 26 of file STREBLT.H.

#define DID_Y 101

Definition at line 23 of file STREBLT.H.

#define DID_YSRC 105

Definition at line 27 of file STREBLT.H.

#define GRIDCOLOR (COLORREF) 0x01000006

Definition at line 51 of file STREBLT.H.

#define INC 5

Definition at line 55 of file STREBLT.H.

#define MAXCHARS 32

Definition at line 54 of file STREBLT.H.

#define NMODES 5

Definition at line 75 of file STREBLT.H.

#define NPATTERNS 6

Definition at line 103 of file STREBLT.H.

#define NROPS 15

Definition at line 84 of file STREBLT.H.

#define SEPARATORWIDTH 4

Definition at line 53 of file STREBLT.H.

#define WM_PUTUPDESTRECT WM_USER+20

Definition at line 61 of file STREBLT.H.

#define WM_PUTUPSRCRECT WM_USER+21

Definition at line 62 of file STREBLT.H.

#define WM_STRETCHBLT WM_USER+23

Definition at line 63 of file STREBLT.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Function Documentation

BOOL CALLBACK DlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 572 of file MASKBLT.C.

{
  char buffer[MAXCHARS];
  HBITMAP hbm;

  switch (message) {
    /**********************************************************************\
    *  WM_INITDIALOG
    *
    * Fill the entry fields with sensible original values.
    \**********************************************************************/
    case WM_INITDIALOG: {
      int i;

      for (i = DID_X; i<=  DID_YMASK; i++)
        SetDlgItemText(hwnd, i, "0");

      /* these are the three bytes from SRCCOPY */
      SetDlgItemText(hwnd, DID_ROP0  , "00");
      SetDlgItemText(hwnd, DID_ROP1  , "cc");
      SetDlgItemText(hwnd, DID_ROP2  , "00");
      SetDlgItemText(hwnd, DID_ROP3  , "20");

      for (i = 0; i< NROPS; i++)
        SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)StandardROPs[i].String);

      for (i = 0; i< NPATTERNS; i++)
        SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
                            (DWORD) -1, (LONG)Patterns[i].String);

    } return TRUE;

    /**********************************************************************\
    *  WM_PUTUPDESTRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the destination rectangle points.
    *  Conditionally change <x,y> or <width,height> depending on tracking mode.
    \**********************************************************************/
    case WM_PUTUPDESTRECT: {
        POINT p1,p2, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p2.x = pto->rect.right;
        p2.y = pto->rect.bottom;
        LPtoDP (pto->hdc, &p2, 1);
        p2.x -= p1.x; p2.y -= p1.y;

        p1.x -= origin.x; p1.y -= origin.y;

        if (!(pto->Mode & TMSIZEXY)) {
          SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
          SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
        }

        if (!(pto->Mode & TMMOVE)) {
          SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
          SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
        }
    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPSRCRECT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the source location point.
    \**********************************************************************/
    case WM_PUTUPSRCRECT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);

        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);

    } return FALSE;

    /**********************************************************************\
    *  WM_PUTUPMASKPT
    *
    * wParam -  HDC with the needed world transform.
    * lParam -  Pointer to the track object.
    *
    * Fill the entry fields for the mask location point.
    \**********************************************************************/
    case WM_PUTUPMASKPT: {
        POINT p1, origin;
        PTrackObject pto;
        HDC hdc;

        hdc = (HDC) wParam;
        pto = (PTrackObject) lParam;
        GetViewportOrgEx (hdc, &origin);

        p1.x = pto->rect.left;
        p1.y = pto->rect.top;
        LPtoDP (pto->hdc, &p1, 1);
        p1.x -= origin.x; p1.y -= origin.y;

        SetDlgItemInt(hwnd, DID_XMASK, p1.x, TRUE);
        SetDlgItemInt(hwnd, DID_YMASK, p1.y, TRUE);

    } return FALSE;

    case WM_COMMAND:
      switch (LOWORD(wParam)) {

        /******************************************************************\
        *  WM_COMMAND, DID_DRAW
        *
        * Draw button hit - send main window message to call MaskBlt().
        \******************************************************************/
        case DID_DRAW:
          SendMessage (hwndMain, WM_MASKBLT, 0,0);
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWSRC
        *
        * Try to get a new source bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWSRC:
          if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
            DeleteObject (hbmSrc);
            hbmSrc = hbm;
            InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /**********************************************************************\
        *  WM_COMMAND, DID_NEWMASK
        *
        * Try to get a new mask bitmap.  Then
        *  invalidate two sub windows so that we force a repaint.
        \**********************************************************************/
        case DID_NEWMASK:
          if ( hbm = GetBitmap (hdcMask, hInst, TRUE)) {
            DeleteObject (hbmMask);
            hbmMask = hbm;
            InvalidateRect (hwndMain, &ptoMask->rectClip, TRUE);
            InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_ROPS
        *
        * A new standard rop entry was selected.  Lookup the value,
        *  then break it into four parts, convert to hex, and put
        *  it in the proper entry fields.
        \******************************************************************/
        case DID_CB_ROPS:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel, rop;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            rop = StandardROPs[iSel].Value;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP3, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP2, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP1, buffer);
            rop /= 256;
            sprintf (buffer, "%2x", (rop & 0x000000ff));
            SetDlgItemText(hwnd, DID_ROP0, buffer);

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, DID_CB_PATTERN
        *
        * A new pattern brush was selected.  Look up the value, store it
        *  in a global variable (iPatternBrush), then force a new StretchBlt
        \******************************************************************/
        case DID_CB_PATTERN:
          if (HIWORD (wParam) == CBN_SELCHANGE) {
            int iSel;

            iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
            iPatternBrush = Patterns[iSel].Value;

            SendMessage (hwndMain, WM_MASKBLT, 0,0);
          }
        break;

      } return FALSE; /* end WM_COMMAND switch*/

  } /* end switch */
  return 0;
}

VOID DrawGrids | ( | HDC | ,
 |  | int | ,
 |  | int |
 | ) |  |

Definition at line 831 of file MASKBLT.C.

{
    int i;

    /* Draw vertical lines. Double at the axis */
    for (i = 0; i<= width; i+=TICKSPACE){
      MoveToEx (hdc, i, 0, NULL);
      LineTo (hdc, i, height);
    }
    MoveToEx (hdc, 1, 0, NULL);
    LineTo (hdc, 1, height);

    /* Draw horizontal lines. Double at the axis */
    for (i = 0; i<= height; i+=TICKSPACE){
      MoveToEx (hdc, 0,i, NULL);
      LineTo (hdc, width,i);
    }
    MoveToEx (hdc, 0, 1, NULL);
    LineTo (hdc, width,1);

  return;
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

Variable Documentation

LookupEntry Patterns[NPATTERNS]
Initial value:
    {{  0, "WHITE_BRUSH "},
     {  1, "LTGRAY_BRUSH"},
     {  2, "GRAY_BRUSH  "},
     {  3, "DKGRAY_BRUSH"},
     {  4, "BLACK_BRUSH "},
     {  5, "NULL_BRUSH  "}}

Definition at line 104 of file STREBLT.H.

LookupEntry StandardROPs[NROPS]
Initial value:
    {{ 0x00CC0020, "SRCCOPY"    },
     { 0x00EE0086, "SRCPAINT"   },
     { 0x008800C6, "SRCAND"     },
     { 0x00660046, "SRCINVERT"  },
     { 0x00440328, "SRCERASE"   },
     { 0x00330008, "NOTSRCCOPY" },
     { 0x001100A6, "NOTSRCERASE"},
     { 0x00C000CA, "MERGECOPY"  },
     { 0x00BB0226, "MERGEPAINT" },
     { 0x00F00021, "PATCOPY"    },
     { 0x00FB0A09, "PATPAINT"   },
     { 0x005A0049, "PATINVERT"  },
     { 0x00550009, "DSTINVERT"  },
     { 0x00000042, "BLACKNESS"  },
     { 0x00FF0062, "WHITENESS"  }}

Definition at line 85 of file STREBLT.H.

LookupEntry strebltModes[NMODES]
Initial value:
    {{ 1, "BLACKONWHITE"},
     { 2, "COLORONCOLOR"},
     { 3, "WHITEONBLACK"},
     { 4, "BLEND       "},
     { 5, "HALFTONE    "}}

Definition at line 76 of file STREBLT.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/TRACK.C File Reference

  • STREBLT
Defines | Functions

TRACK.C File Reference

#include <windows.h>
#include <math.h>
#include "track.h"

Go to the source code of this file.

Defines

#define | EPSILON (float) 0.0001
#define | RECTSIZE 60

Functions

PTrackObject | doTrackObject (PTrackObject pto, int msg, HWND hwnd, LONG lParam)
VOID | MouseMove (PTrackObject pto, int msg, HWND hwnd, LONG lParam)

Define Documentation

#define EPSILON (float) 0.0001

Definition at line 20 of file TRACK.C.

#define RECTSIZE 60

Definition at line 21 of file TRACK.C.

Function Documentation

PTrackObject doTrackObject | ( | PTrackObject | pto,
 |  | int | msg,
 |  | HWND | hwnd,
 |  | LONG | lParam
 | ) |  |

Definition at line 54 of file TRACK.C.

{
  if ((pto == NULL) && (msg != TROB_NEW))  return NULL;

  switch (msg) {

    /**********************************************************************\
    *  TROB_NEW
    *
    * Allocate new PTrackObject structure.  Fill in default values
    *  for the fields of the structure.  Set up the HDC correctly.
    * return - pointer to the new object.
    \**********************************************************************/
    case  TROB_NEW: {
        PTrackObject  pto;

        /* with LPTR returned value is a pointer. */
        pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));

        /* initialize the HDC and other fields. */
        pto->hdc = GetDC (hwnd);
        SetGraphicsMode (pto->hdc, GM_ADVANCED);
        SetROP2(pto->hdc, R2_NOT);
        SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
        pto->Mode = TMNONE;
        pto->allowedModes = TMMOVE | TMSIZEXY;

        GetWorldTransform (pto->hdc, &(pto->xfmChange));

        /* initialize the size. */
        pto->rect.top = pto->rect.left = 0;
        pto->rect.bottom = pto->rect.right = RECTSIZE;

        return (pto);
    }

    /**********************************************************************\
    *  TROB_DELETE
    *
    * Complement of TROB_NEW.  Free up the memory allocated for the object.
    \**********************************************************************/
    case  TROB_DELETE:
        doTrackObject (pto, TROB_PAINT, hwnd, lParam);
        ReleaseDC (hwnd, pto->hdc);
        LocalFree (LocalHandle ((LPSTR)pto));
    return NULL;

    /**********************************************************************\
    *  TROB_PAINT
    *
    * Paint the object into its hdc.  Called half the time to erase
    *  the object, and half the time to redraw it.
    \**********************************************************************/
    case TROB_PAINT: {
        MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);

        if (pto->allowedModes & TMSIZEXY) {
          LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
          LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
        }

        if (pto->allowedModes & TMROTATE) {
          MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
          AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
                 (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
        }

    } return NULL;

    /**********************************************************************\
    *  TROB_HITTEST
    *
    * Check the point sent in in the lParam to see if it lays within
    *  the bounds of the objects defining rectangle.
    * return - pointer to the object iff the point is in rectangle,
    *  otherwise return NULL.
    \**********************************************************************/
    case TROB_HITTEST:{
        POINT  mouWorld;
        mouWorld.x = LOWORD(lParam);
        mouWorld.y = HIWORD(lParam);

        DPtoLP (pto->hdc, &mouWorld, 1);

        if (PtInRect (&pto->rect, mouWorld))  return pto;
        else  return NULL;
    }

    /**********************************************************************\
    *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
    *
    * Capture the mouse, set the tracking mode depending on the mouse
    *  location in world coordinates, reset the mouse position.
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN: {
      POINT  newmouScreen;
      POINT  mouWorld;

      mouWorld.x = LOWORD(lParam);
      mouWorld.y = HIWORD(lParam);
      DPtoLP (pto->hdc, &mouWorld, 1);

      /* upper left hand corner. right button is no-op. */
      if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {
          if (msg == WM_RBUTTONDOWN) return NULL;
          pto->Mode = TMMOVE;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.top;

      /* lower left hand corner */
      } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.bottom;

      /* upper right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.top;

      /* lower right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.bottom;
      }

      if (! (pto->Mode & pto->allowedModes)) {
        pto->Mode = TMNONE;
        return NULL;
      }

      SetCapture(hwnd);
      LPtoDP (pto->hdc, &newmouScreen, 1);
      ClientToScreen (hwnd, &newmouScreen);
      SetCursorPos (newmouScreen.x,newmouScreen.y);

      GetWorldTransform (pto->hdc, &pto->xfmDown);
    } return NULL;

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * this is where almost all of the interesting calculation is done.
    *  First clip the mouse location to be in rectClip, then
    *  call MouseMove() to handle the different tracking modes.
    \**********************************************************************/
    case WM_MOUSEMOVE: {
      if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
        lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));

      if (LOWORD(lParam) > (WORD)pto->rectClip.right)
        lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));

      if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
        lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);

      if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
        lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);

      MouseMove (pto, msg, hwnd, lParam);

    } return NULL;

    /**********************************************************************\
    *  WM_RBUTTONUP & WM_LBUTTONUP
    *
    * simply release the mouse capture, and set the mode to TMNONE.
    \**********************************************************************/
    case WM_RBUTTONUP:
    case WM_LBUTTONUP: {
      if (pto->Mode) {
         ReleaseCapture();
         pto->Mode = TMNONE;
      }
    } return NULL;

  }  /* end switch(msg) */
}

VOID MouseMove | ( | PTrackObject | pto,
 |  | int | msg,
 |  | HWND | hwnd,
 |  | LONG | lParam
 | ) |  |

Definition at line 296 of file TRACK.C.

{
POINT  mouWorld, mouDevice, orgDevice;

    UNREFERENCED_PARAMETER(msg);

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);
    mouDevice.x = mouWorld.x = LOWORD(lParam);
    mouDevice.y = mouWorld.y = HIWORD(lParam);

    SetWorldTransform(pto->hdc, &pto->xfmDown);
    DPtoLP (pto->hdc, &mouWorld, 1);

    /* offset the mouse device point for the viewport's origin. */
    GetViewportOrgEx (pto->hdc, &orgDevice);
    mouDevice.x -= orgDevice.x;
    mouDevice.y -= orgDevice.y;

    GetWorldTransform(pto->hdc, &pto->xfmChange);

    switch (pto->Mode) {
      /*******************************************************\
      *    (     1         xShear       0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSHEARX: {
        pto->xfmChange.eM12 = (float) mouDevice.y;
        pto->xfmChange.eM12 -=pto->xfmChange.eDy;
        pto->xfmChange.eM12 /=(float) pto->rect.right ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (   yShear        1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSHEARY: {
        pto->xfmChange.eM21 = (float) mouDevice.x;
        pto->xfmChange.eM21 -=pto->xfmChange.eDx;
        pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

      } break;

      /*******************************************************\
      *    (   cos(a)      -sin(a)      0   )
      *    (   sin(a)       cos(a)      0   )
      *    (     0           0          1   )
      *
      * a == rotation angle.  Since mouse in in lower right,
      *  we need to shift this back 45 degrees (assuming that
      *  straight down is 0 degrees).  Thus we actually compute
      *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
      *  where b is angle from the origin to the mouse (x,y)
      *  cos(45) = sin(45) ~= 0.707107
      *  cos(b) = y/r    sin(b) = x/r
      *
      \*******************************************************/
      case TMROTATE: {
        float r;

        /* translate back to the origin. */
        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

        /* rotate about the origin. */
        r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
                          (double)(mouWorld.y * mouWorld.y));

        pto->xfmChange.eM11 = (float) mouWorld.y / r;
        pto->xfmChange.eM11 += (float) mouWorld.x / r;
        pto->xfmChange.eM11 *= (float) 0.707107;
        pto->xfmChange.eM22 = pto->xfmChange.eM11;

        pto->xfmChange.eM12 = (float) mouWorld.y / r;
        pto->xfmChange.eM12 -= (float) mouWorld.x / r;
        pto->xfmChange.eM12 *= (float) 0.707107;
        pto->xfmChange.eM21 = -pto->xfmChange.eM12;

        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;

        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);

        /* translate back to the original offset. */
        pto->xfmChange.eM11 =
        pto->xfmChange.eM22 = (float) 1.0;
        pto->xfmChange.eM12 =
        pto->xfmChange.eM21 = (float) 0.0;

        pto->xfmChange.eDx = pto->xfmDown.eDx;
        pto->xfmChange.eDy = pto->xfmDown.eDy;
        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
        GetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      \*******************************************************/
      case TMSIZEXY: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSIZEX: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSIZEY: {
        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0           1          0   )
      *    (   Move x      Move y       1   )
      *
      * xWorld = rect.left == 0;
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMMOVE: {
        pto->xfmChange.eDx = (float) mouDevice.x ;
        pto->xfmChange.eDy = (float) mouDevice.y ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;
    } /* end switch */

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);

    return;
 }

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/TRACK.H File Reference

  • STREBLT
Data Structures | Defines | Typedefs | Functions

TRACK.H File Reference

Go to the source code of this file.

Data Structures

struct | tagTrackObject

Defines

#define | TMALL 0x00ff
#define | TMMOVE 0x0001
#define | TMNONE 0x0000
#define | TMROTATE 0x0008
#define | TMSHEARX 0x0010
#define | TMSHEARY 0x0020
#define | TMSIZEX 0x0002
#define | TMSIZEXY 0x0006
#define | TMSIZEY 0x0004
#define | TROB_DELETE WM_USER+2
#define | TROB_HITTEST WM_USER+5
#define | TROB_NEW WM_USER+1
#define | TROB_PAINT WM_USER+3

Typedefs

typedef struct tagTrackObject * | PTrackObject
typedef struct tagTrackObject | TrackObject

Functions

PTrackObject | doTrackObject (PTrackObject, int, HWND, LONG)
VOID | MouseMove (PTrackObject, int, HWND, LONG)

Define Documentation

#define TMALL 0x00ff

Definition at line 31 of file TRACK.H.

#define TMMOVE 0x0001

Definition at line 24 of file TRACK.H.

#define TMNONE 0x0000

Definition at line 23 of file TRACK.H.

#define TMROTATE 0x0008

Definition at line 30 of file TRACK.H.

#define TMSHEARX 0x0010

Definition at line 28 of file TRACK.H.

#define TMSHEARY 0x0020

Definition at line 29 of file TRACK.H.

#define TMSIZEX 0x0002

Definition at line 25 of file TRACK.H.

#define TMSIZEXY 0x0006

Definition at line 27 of file TRACK.H.

#define TMSIZEY 0x0004

Definition at line 26 of file TRACK.H.

#define TROB_DELETE WM_USER+2

Definition at line 17 of file TRACK.H.

#define TROB_HITTEST WM_USER+5

Definition at line 19 of file TRACK.H.

#define TROB_NEW WM_USER+1

Definition at line 16 of file TRACK.H.

#define TROB_PAINT WM_USER+3

Definition at line 18 of file TRACK.H.

Typedef Documentation

typedef struct tagTrackObject * PTrackObject
typedef struct tagTrackObject TrackObject

Function Documentation

PTrackObject doTrackObject | ( | PTrackObject | ,
 |  | int | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |

Definition at line 54 of file TRACK.C.

{
  if ((pto == NULL) && (msg != TROB_NEW))  return NULL;

  switch (msg) {

    /**********************************************************************\
    *  TROB_NEW
    *
    * Allocate new PTrackObject structure.  Fill in default values
    *  for the fields of the structure.  Set up the HDC correctly.
    * return - pointer to the new object.
    \**********************************************************************/
    case  TROB_NEW: {
        PTrackObject  pto;

        /* with LPTR returned value is a pointer. */
        pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));

        /* initialize the HDC and other fields. */
        pto->hdc = GetDC (hwnd);
        SetGraphicsMode (pto->hdc, GM_ADVANCED);
        SetROP2(pto->hdc, R2_NOT);
        SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
        pto->Mode = TMNONE;
        pto->allowedModes = TMMOVE | TMSIZEXY;

        GetWorldTransform (pto->hdc, &(pto->xfmChange));

        /* initialize the size. */
        pto->rect.top = pto->rect.left = 0;
        pto->rect.bottom = pto->rect.right = RECTSIZE;

        return (pto);
    }

    /**********************************************************************\
    *  TROB_DELETE
    *
    * Complement of TROB_NEW.  Free up the memory allocated for the object.
    \**********************************************************************/
    case  TROB_DELETE:
        doTrackObject (pto, TROB_PAINT, hwnd, lParam);
        ReleaseDC (hwnd, pto->hdc);
        LocalFree (LocalHandle ((LPSTR)pto));
    return NULL;

    /**********************************************************************\
    *  TROB_PAINT
    *
    * Paint the object into its hdc.  Called half the time to erase
    *  the object, and half the time to redraw it.
    \**********************************************************************/
    case TROB_PAINT: {
        MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
        LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);

        if (pto->allowedModes & TMSIZEXY) {
          LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
          LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
        }

        if (pto->allowedModes & TMROTATE) {
          MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
          AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
                 (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
        }

    } return NULL;

    /**********************************************************************\
    *  TROB_HITTEST
    *
    * Check the point sent in in the lParam to see if it lays within
    *  the bounds of the objects defining rectangle.
    * return - pointer to the object iff the point is in rectangle,
    *  otherwise return NULL.
    \**********************************************************************/
    case TROB_HITTEST:{
        POINT  mouWorld;
        mouWorld.x = LOWORD(lParam);
        mouWorld.y = HIWORD(lParam);

        DPtoLP (pto->hdc, &mouWorld, 1);

        if (PtInRect (&pto->rect, mouWorld))  return pto;
        else  return NULL;
    }

    /**********************************************************************\
    *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
    *
    * Capture the mouse, set the tracking mode depending on the mouse
    *  location in world coordinates, reset the mouse position.
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN: {
      POINT  newmouScreen;
      POINT  mouWorld;

      mouWorld.x = LOWORD(lParam);
      mouWorld.y = HIWORD(lParam);
      DPtoLP (pto->hdc, &mouWorld, 1);

      /* upper left hand corner. right button is no-op. */
      if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {
          if (msg == WM_RBUTTONDOWN) return NULL;
          pto->Mode = TMMOVE;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.top;

      /* lower left hand corner */
      } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
          newmouScreen.x = pto->rect.left;
          newmouScreen.y = pto->rect.bottom;

      /* upper right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y <= (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.top;

      /* lower right hand corner */
      } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
          (mouWorld.y > (pto->rect.bottom / 2))) {

          pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
          newmouScreen.x = pto->rect.right;
          newmouScreen.y = pto->rect.bottom;
      }

      if (! (pto->Mode & pto->allowedModes)) {
        pto->Mode = TMNONE;
        return NULL;
      }

      SetCapture(hwnd);
      LPtoDP (pto->hdc, &newmouScreen, 1);
      ClientToScreen (hwnd, &newmouScreen);
      SetCursorPos (newmouScreen.x,newmouScreen.y);

      GetWorldTransform (pto->hdc, &pto->xfmDown);
    } return NULL;

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * this is where almost all of the interesting calculation is done.
    *  First clip the mouse location to be in rectClip, then
    *  call MouseMove() to handle the different tracking modes.
    \**********************************************************************/
    case WM_MOUSEMOVE: {
      if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
        lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));

      if (LOWORD(lParam) > (WORD)pto->rectClip.right)
        lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));

      if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
        lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);

      if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
        lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);

      MouseMove (pto, msg, hwnd, lParam);

    } return NULL;

    /**********************************************************************\
    *  WM_RBUTTONUP & WM_LBUTTONUP
    *
    * simply release the mouse capture, and set the mode to TMNONE.
    \**********************************************************************/
    case WM_RBUTTONUP:
    case WM_LBUTTONUP: {
      if (pto->Mode) {
         ReleaseCapture();
         pto->Mode = TMNONE;
      }
    } return NULL;

  }  /* end switch(msg) */
}

VOID MouseMove | ( | PTrackObject | ,
 |  | int | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |

Definition at line 296 of file TRACK.C.

{
POINT  mouWorld, mouDevice, orgDevice;

    UNREFERENCED_PARAMETER(msg);

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);
    mouDevice.x = mouWorld.x = LOWORD(lParam);
    mouDevice.y = mouWorld.y = HIWORD(lParam);

    SetWorldTransform(pto->hdc, &pto->xfmDown);
    DPtoLP (pto->hdc, &mouWorld, 1);

    /* offset the mouse device point for the viewport's origin. */
    GetViewportOrgEx (pto->hdc, &orgDevice);
    mouDevice.x -= orgDevice.x;
    mouDevice.y -= orgDevice.y;

    GetWorldTransform(pto->hdc, &pto->xfmChange);

    switch (pto->Mode) {
      /*******************************************************\
      *    (     1         xShear       0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSHEARX: {
        pto->xfmChange.eM12 = (float) mouDevice.y;
        pto->xfmChange.eM12 -=pto->xfmChange.eDy;
        pto->xfmChange.eM12 /=(float) pto->rect.right ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (   yShear        1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSHEARY: {
        pto->xfmChange.eM21 = (float) mouDevice.x;
        pto->xfmChange.eM21 -=pto->xfmChange.eDx;
        pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

      } break;

      /*******************************************************\
      *    (   cos(a)      -sin(a)      0   )
      *    (   sin(a)       cos(a)      0   )
      *    (     0           0          1   )
      *
      * a == rotation angle.  Since mouse in in lower right,
      *  we need to shift this back 45 degrees (assuming that
      *  straight down is 0 degrees).  Thus we actually compute
      *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
      *  where b is angle from the origin to the mouse (x,y)
      *  cos(45) = sin(45) ~= 0.707107
      *  cos(b) = y/r    sin(b) = x/r
      *
      \*******************************************************/
      case TMROTATE: {
        float r;

        /* translate back to the origin. */
        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
        SetWorldTransform (pto->hdc, &pto->xfmChange);

        /* rotate about the origin. */
        r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
                          (double)(mouWorld.y * mouWorld.y));

        pto->xfmChange.eM11 = (float) mouWorld.y / r;
        pto->xfmChange.eM11 += (float) mouWorld.x / r;
        pto->xfmChange.eM11 *= (float) 0.707107;
        pto->xfmChange.eM22 = pto->xfmChange.eM11;

        pto->xfmChange.eM12 = (float) mouWorld.y / r;
        pto->xfmChange.eM12 -= (float) mouWorld.x / r;
        pto->xfmChange.eM12 *= (float) 0.707107;
        pto->xfmChange.eM21 = -pto->xfmChange.eM12;

        pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;

        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);

        /* translate back to the original offset. */
        pto->xfmChange.eM11 =
        pto->xfmChange.eM22 = (float) 1.0;
        pto->xfmChange.eM12 =
        pto->xfmChange.eM21 = (float) 0.0;

        pto->xfmChange.eDx = pto->xfmDown.eDx;
        pto->xfmChange.eDy = pto->xfmDown.eDy;
        ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
        GetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      \*******************************************************/
      case TMSIZEXY: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (  Size X         0          0   )
      *    (     0           1          0   )
      *    (     0           0          1   )
      *
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMSIZEX: {
        pto->xfmChange.eM11 = (float) mouDevice.x;
        pto->xfmChange.eM11 -=pto->xfmChange.eDx;
        pto->xfmChange.eM11 /=(float) pto->rect.right ;
        if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM11 = EPSILON;

        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0        Size Y        0   )
      *    (     0           0          1   )
      *
      * xWorld = rect.left == 0;
      \*******************************************************/
      case TMSIZEY: {
        pto->xfmChange.eM22 = (float) mouDevice.y;
        pto->xfmChange.eM22 -=pto->xfmChange.eDy;
        pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
        if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
           pto->xfmChange.eM22 = EPSILON;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;

      /*******************************************************\
      *    (     1           0          0   )
      *    (     0           1          0   )
      *    (   Move x      Move y       1   )
      *
      * xWorld = rect.left == 0;
      * yWorld = rect.top == 0;
      \*******************************************************/
      case TMMOVE: {
        pto->xfmChange.eDx = (float) mouDevice.x ;
        pto->xfmChange.eDy = (float) mouDevice.y ;
        SetWorldTransform (pto->hdc, &pto->xfmChange);
      } break;
    } /* end switch */

    doTrackObject(pto, TROB_PAINT, hwnd, lParam);

    return;
 }

Generated on Wed Nov 13 2024 17:29:11 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SUBCLASS/SUBCLASS.C File Reference

  • SUBCLASS
Functions

SUBCLASS.C File Reference

#include <windows.h>
#include "subclass.h"

Go to the source code of this file.

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | PaintRect (HWND hwnd, LPRECT prect)
VOID | QueryWindowPos (HWND hwnd, LPRECT prect)
VOID | SubclassWindow (HWND hwnd, WNDPROC SubclassWndProc)
LRESULT CALLBACK | SubclassWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
DWORD | ToggleMenu (HMENU hmenu, UINT iditem)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 132 of file SUBCLASS.C.

{
   HWND hwndChild;

   switch (message) {

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Post quit message.
    \**********************************************************************/
    case WM_DESTROY:
        PostQuitMessage(0);
    break;

    /**********************************************************************\
    *  WM_COMMAND
    *
    * Switch on the different menu items.  Create a different class of
    *  window for most of them.  Switch on and off the fTestMode global
    *  variable on IDM_TEST.
    \**********************************************************************/

    case WM_COMMAND: {
      switch (LOWORD (wParam)) {
        case IDM_BUTTON:
          hwndChild = CreateWindow(
            "BUTTON", "button",
            WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
            50,10, 60, 32,
            hwnd, NULL, hInst, NULL);

          SubclassWindow (hwndChild, SubclassWndProc);
        break;

        case IDM_EDIT:
          hwndChild = CreateWindow(
            "EDIT", "edit",
            WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
            50,50, 60, 28,
            hwnd, NULL, hInst, NULL);

          SubclassWindow (hwndChild, SubclassWndProc);
        break;

        case IDM_LIST:
          hwndChild = CreateWindow(
            "LISTBOX", NULL,
            WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
            50,90, 60, 50,
            hwnd, NULL, hInst, NULL);

          SubclassWindow (hwndChild, SubclassWndProc);
        break;

        case IDM_TEST:
          fTestMode = ToggleMenu (GetMenu (hwnd), IDM_TEST);
        break;

      }       /* end switch */
    } break;  /* end WM_COMMAND  */

  }
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

VOID PaintRect | ( | HWND | hwnd,
 |  | LPRECT | prect
 | ) |  |

Definition at line 499 of file SUBCLASS.C.

{
    HDC hdc;

    hdc = GetDC (hwnd);
    SetROP2(hdc, R2_NOT);
    SelectObject (hdc, GetStockObject (NULL_BRUSH));
    Rectangle (hdc, prect->left, prect->top,
                    prect->right, prect->bottom);
    ReleaseDC (hwnd, hdc);
}

VOID QueryWindowPos | ( | HWND | hwnd,
 |  | LPRECT | prect
 | ) |  |

Definition at line 481 of file SUBCLASS.C.

{
  GetWindowRect (hwnd, prect);
  ScreenToClient (hwndMain, (LPPOINT)&(prect->left));
  ScreenToClient (hwndMain, (LPPOINT)&(prect->right));
}

VOID SubclassWindow | ( | HWND | hwnd,
 |  | WNDPROC | SubclassWndProc
 | ) |  |

Definition at line 458 of file SUBCLASS.C.

{
  PExtraBytes  peb;

  peb = (PExtraBytes)LocalAlloc (LPTR, sizeof (ExtraBytes));
  peb->pfnOldProc = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);

  SetWindowLong (hwnd, GWL_USERDATA, (LONG) peb);
  SetWindowLong (hwnd, GWL_WNDPROC,  (LONG) SubclassWndProc);
}

LRESULT CALLBACK SubclassWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 210 of file SUBCLASS.C.

{
  PExtraBytes  peb;

  /* get the pointer to the extra bytes structure out of the user data. */
  peb = (PExtraBytes)GetWindowLong (hwnd, GWL_USERDATA);

  /* if running in test mode, just return the old procedure. */
  if (fTestMode)
    return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));

  switch (message) {

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Free up the ExtraBytes structure which was allocated at subclass time.
    \**********************************************************************/
    case WM_DESTROY:
      LocalUnlock (LocalHandle ((LPSTR)peb));
    break;

    /**********************************************************************\
    *  WM_SETCURSOR
    *
    * Set the mouse pointer conditional on the Action which would be taken
    *  if the user presses mouse down.  This is set in WM_MOUSEMOVE.
    \**********************************************************************/
    case WM_SETCURSOR:
      switch (peb->Action) {
        case ACTIONNONE  :SetCursor (LoadCursor (NULL, IDC_ARROW)); break;
        case ACTIONMOVE  :SetCursor (LoadCursor (NULL, IDC_SIZEALL)); break;
        case ACTIONSIZEX :SetCursor (LoadCursor (NULL, IDC_SIZEWE)); break;
        case ACTIONSIZEY :SetCursor (LoadCursor (NULL, IDC_SIZENS)); break;
        case ACTIONSIZEXY:SetCursor (LoadCursor (NULL, IDC_SIZENWSE)); break;
      }
    return (0);

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    *
    * The user is beginning a drag operation.  Fill in an initial window pos
    *  in the rect field, figure out which corner the cursor should be set
    *  to, translate that point to screen coordinates, and finally capture
    *  the mouse.
    \**********************************************************************/

    case WM_LBUTTONDOWN: {
      POINT  mouse;

      QueryWindowPos (hwnd, &peb->rect);

      switch (peb->Action) {
        case ACTIONMOVE  :
          mouse.x = peb->rect.left;
          mouse.y = peb->rect.top ;
        break;

        case ACTIONSIZEX :
          mouse.x = peb->rect.right;
          mouse.y = peb->rect.top ;
        break;

        case ACTIONSIZEY :
          mouse.x = peb->rect.left;
          mouse.y = peb->rect.bottom;
        break;

        case ACTIONSIZEXY:
          mouse.x = peb->rect.right;
          mouse.y = peb->rect.bottom;
        break;
      }

      /* SetCursorPos() works based on screen position, and mouse is
       *  currently relative to hwndMain.
       */
      ClientToScreen (hwndMain, &mouse);
      SetCursorPos (mouse.x, mouse.y);
      SetCapture (hwnd);
    } return 0;

    /**********************************************************************\
    *  WM_LBUTTONUP
    *
    * Complement of the WM_LBUTTONDOWN message.  Release the capture,
    *  and reset the actual window's position.
    \**********************************************************************/

    case WM_LBUTTONUP: {
      LONG lTemp;

      if (GetCapture() == hwnd) {
        ReleaseCapture();

        if (peb->rect.left > peb->rect.right)
        {
            lTemp = peb->rect.left;
            peb->rect.left = peb->rect.right;
            peb->rect.right = lTemp;
        }

        if (peb->rect.top > peb->rect.bottom)
        {
            lTemp = peb->rect.top;
            peb->rect.top = peb->rect.bottom;
            peb->rect.bottom = lTemp;
        }

        SetWindowPos (hwnd, NULL, peb->rect.left, peb->rect.top,
                      (peb->rect.right - peb->rect.left),
                      (peb->rect.bottom - peb->rect.top),
                      SWP_NOZORDER);
        InvalidateRect (hwnd, NULL, TRUE);
      }
    return 0;
   }

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * There are two cases of interest here.  If the mouse is captured, then
    *  change the rect field in the extrabyte structure to reflect the new
    *  size/position that the user is selection.
    *
    *  If the mouse is not captured, then set the Action field dependent on
    *  the quadrant so that the WM_SETCURSOR will display the correct cursor.
    *
    \**********************************************************************/

    case WM_MOUSEMOVE: {
      POINT mouse;
      /* the LO/HI-WORD from lParam will be a signed short relative to
       *  the child control window.
       */
      mouse.x = (int)(short)LOWORD(lParam);
      mouse.y = (int)(short)HIWORD(lParam);

      /* if the mouse is captured, then we are doing direct manipulation */
      if (GetCapture() == hwnd) {

        /* translate mouse pos to be client relative, not control relative */
        ClientToScreen (hwnd, &mouse);
        ScreenToClient (hwndMain, &mouse);

        /* erase the old rectangle */
        PaintRect (hwndMain, &peb->rect);

        switch (peb->Action) {
          case ACTIONMOVE  : {
            int width, height;

            width = peb->rect.right - peb->rect.left;
            height = peb->rect.bottom - peb->rect.top;
            peb->rect.left = mouse.x;
            peb->rect.top  = mouse.y;
            peb->rect.right  = peb->rect.left + width;
            peb->rect.bottom = peb->rect.top +  height;
          }break;

          case ACTIONSIZEX :
            peb->rect.right  = mouse.x;
          break;

          case ACTIONSIZEY :
            peb->rect.bottom = mouse.y;
          break;

          case ACTIONSIZEXY:
            peb->rect.right  = mouse.x;
            peb->rect.bottom = mouse.y;
          break;
        }

        /* Redraw the new rectangle */
        PaintRect (hwndMain, &peb->rect);
      }

      /* if the mouse is not captured, then set the action for the sake of
       *  the WM_SETCURSOR message.  The action is dependent upon which
       *  quadrant of the window the mouse cursor is over.
       */
      else {
        int width2, height2;
        RECT rect;

        GetClientRect (hwnd, &rect);
        width2 =  (rect.right -  rect.left)/2;
        height2 =  (rect.bottom -  rect.top)/2;

        /* upper left hand corner */
        if ((mouse.x <= (width2)) && (mouse.y <= (height2))) {
            peb->Action = ACTIONMOVE;

        /* lower left hand corner */
        } else if ((mouse.x <= (width2)) && (mouse.y > (height2))) {
            peb->Action = ACTIONSIZEY;

        /* upper right hand corner */
        } else if ((mouse.x > (width2)) && (mouse.y <= (height2))) {
            peb->Action = ACTIONSIZEX;

        /* lower right hand corner */
        } else if ((mouse.x > (width2)) && (mouse.y > (height2))) {
            peb->Action = ACTIONSIZEXY;
        }
      }
    } return 0;

    /**********************************************************************\
    * for messages that are not handled explicitly here, pass them
    *  back to the old window procedure.
    \**********************************************************************/
    default:
      return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));
    break;
    } /* end switch */

  return 0;
}

DWORD ToggleMenu | ( | HMENU | hmenu,
 |  | UINT | iditem
 | ) |  |

Definition at line 523 of file SUBCLASS.C.

{
  DWORD  state;

  /* query the checked state.
   *  unfortunately, this turns checked off.
   */
  state = CheckMenuItem (hmenu, iditem, MF_BYCOMMAND);

  /* switch the truth value of oldstate. */
  state = (state) ? MF_UNCHECKED : MF_CHECKED;

  /* reset the menu item. */
  CheckMenuItem (hmenu, iditem, MF_BYCOMMAND | state);

  return state;
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 61 of file SUBCLASS.C.

{
  MSG   msg;

  UNREFERENCED_PARAMETER( lpCmdLine );

  /* Check for previous instance.  If none, then register class. */
  if (!hPrevInstance) {
      WNDCLASS  wc;

      wc.style = 0;
      wc.lpfnWndProc = (WNDPROC)MainWndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(hInstance, "subclassIcon");
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = GetStockObject(GRAY_BRUSH);
      wc.lpszMenuName =  "scMenu";
      wc.lpszClassName = "scClass";

      if (!RegisterClass(&wc)) return (FALSE);
  }  /* class registered o.k. */

  /* Create the main window.  Return false if CreateWindow() fails */
  hInst = hInstance;

  hwndMain = CreateWindow(
      "scClass",
      "Subclass Window Sample",
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      NULL,
      NULL,
      hInstance,
      NULL);

  if (!hwndMain) return (FALSE);

  ShowWindow(hwndMain, nCmdShow);

  /* Loop getting messages and dispatching them. */
  while (GetMessage(&msg,NULL, 0,0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  /* Return the value from PostQuitMessage */
  return (msg.wParam);
}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SUBCLASS/SUBCLASS.H File Reference

  • SUBCLASS
Data Structures | Defines | Typedefs | Functions | Variables

SUBCLASS.H File Reference

Go to the source code of this file.

Data Structures

struct | tagExtraBytes

Defines

#define | ACTIONMOVE 0x0001
#define | ACTIONNONE 0x0000
#define | ACTIONSIZEX 0x0002
#define | ACTIONSIZEXY 0x0006
#define | ACTIONSIZEY 0x0004
#define | EPSILON (float) 0.0001
#define | IDM_BUTTON 101
#define | IDM_EDIT 102
#define | IDM_LIST 103
#define | IDM_TEST 110
#define | INC 5
#define | MAXCHARS 32
#define | MINSIZE 5
#define | WM_SC_CREATE WM_USER+1

Typedefs

typedef struct tagExtraBytes | ExtraBytes
typedef struct tagExtraBytes * | PExtraBytes

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | PaintRect (HWND, LPRECT)
VOID | QueryWindowPos (HWND, LPRECT)
LONG | ShiftlParam (HWND, HWND, LONG)
VOID | SubclassWindow (HWND, WNDPROC)
LRESULT CALLBACK | SubclassWndProc (HWND, UINT, WPARAM, LPARAM)
DWORD | ToggleMenu (HMENU, UINT)

Variables

BOOL | fTestMode
HANDLE | hInst
HWND | hwndMain

Define Documentation

#define ACTIONMOVE 0x0001

Definition at line 38 of file SUBCLASS.H.

#define ACTIONNONE 0x0000

Definition at line 37 of file SUBCLASS.H.

#define ACTIONSIZEX 0x0002

Definition at line 39 of file SUBCLASS.H.

#define ACTIONSIZEXY 0x0006

Definition at line 41 of file SUBCLASS.H.

#define ACTIONSIZEY 0x0004

Definition at line 40 of file SUBCLASS.H.

#define EPSILON (float) 0.0001

Definition at line 46 of file SUBCLASS.H.

#define IDM_BUTTON 101

Definition at line 13 of file SUBCLASS.H.

#define IDM_EDIT 102

Definition at line 14 of file SUBCLASS.H.

#define IDM_LIST 103

Definition at line 15 of file SUBCLASS.H.

#define IDM_TEST 110

Definition at line 16 of file SUBCLASS.H.

#define INC 5

Definition at line 45 of file SUBCLASS.H.

#define MAXCHARS 32

Definition at line 47 of file SUBCLASS.H.

#define MINSIZE 5

Definition at line 48 of file SUBCLASS.H.

#define WM_SC_CREATE WM_USER+1

Definition at line 32 of file SUBCLASS.H.

Typedef Documentation

typedef struct tagExtraBytes ExtraBytes
typedef struct tagExtraBytes * PExtraBytes

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID PaintRect | ( | HWND | ,
 |  | LPRECT |
 | ) |  |

Definition at line 499 of file SUBCLASS.C.

{
    HDC hdc;

    hdc = GetDC (hwnd);
    SetROP2(hdc, R2_NOT);
    SelectObject (hdc, GetStockObject (NULL_BRUSH));
    Rectangle (hdc, prect->left, prect->top,
                    prect->right, prect->bottom);
    ReleaseDC (hwnd, hdc);
}

VOID QueryWindowPos | ( | HWND | ,
 |  | LPRECT |
 | ) |  |

Definition at line 481 of file SUBCLASS.C.

{
  GetWindowRect (hwnd, prect);
  ScreenToClient (hwndMain, (LPPOINT)&(prect->left));
  ScreenToClient (hwndMain, (LPPOINT)&(prect->right));
}

LONG ShiftlParam | ( | HWND | ,
 |  | HWND | ,
 |  | LONG |
 | ) |  |
VOID SubclassWindow | ( | HWND | ,
 |  | WNDPROC |
 | ) |  |

Definition at line 458 of file SUBCLASS.C.

{
  PExtraBytes  peb;

  peb = (PExtraBytes)LocalAlloc (LPTR, sizeof (ExtraBytes));
  peb->pfnOldProc = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);

  SetWindowLong (hwnd, GWL_USERDATA, (LONG) peb);
  SetWindowLong (hwnd, GWL_WNDPROC,  (LONG) SubclassWndProc);
}

LRESULT CALLBACK SubclassWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 210 of file SUBCLASS.C.

{
  PExtraBytes  peb;

  /* get the pointer to the extra bytes structure out of the user data. */
  peb = (PExtraBytes)GetWindowLong (hwnd, GWL_USERDATA);

  /* if running in test mode, just return the old procedure. */
  if (fTestMode)
    return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));

  switch (message) {

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Free up the ExtraBytes structure which was allocated at subclass time.
    \**********************************************************************/
    case WM_DESTROY:
      LocalUnlock (LocalHandle ((LPSTR)peb));
    break;

    /**********************************************************************\
    *  WM_SETCURSOR
    *
    * Set the mouse pointer conditional on the Action which would be taken
    *  if the user presses mouse down.  This is set in WM_MOUSEMOVE.
    \**********************************************************************/
    case WM_SETCURSOR:
      switch (peb->Action) {
        case ACTIONNONE  :SetCursor (LoadCursor (NULL, IDC_ARROW)); break;
        case ACTIONMOVE  :SetCursor (LoadCursor (NULL, IDC_SIZEALL)); break;
        case ACTIONSIZEX :SetCursor (LoadCursor (NULL, IDC_SIZEWE)); break;
        case ACTIONSIZEY :SetCursor (LoadCursor (NULL, IDC_SIZENS)); break;
        case ACTIONSIZEXY:SetCursor (LoadCursor (NULL, IDC_SIZENWSE)); break;
      }
    return (0);

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    *
    * The user is beginning a drag operation.  Fill in an initial window pos
    *  in the rect field, figure out which corner the cursor should be set
    *  to, translate that point to screen coordinates, and finally capture
    *  the mouse.
    \**********************************************************************/

    case WM_LBUTTONDOWN: {
      POINT  mouse;

      QueryWindowPos (hwnd, &peb->rect);

      switch (peb->Action) {
        case ACTIONMOVE  :
          mouse.x = peb->rect.left;
          mouse.y = peb->rect.top ;
        break;

        case ACTIONSIZEX :
          mouse.x = peb->rect.right;
          mouse.y = peb->rect.top ;
        break;

        case ACTIONSIZEY :
          mouse.x = peb->rect.left;
          mouse.y = peb->rect.bottom;
        break;

        case ACTIONSIZEXY:
          mouse.x = peb->rect.right;
          mouse.y = peb->rect.bottom;
        break;
      }

      /* SetCursorPos() works based on screen position, and mouse is
       *  currently relative to hwndMain.
       */
      ClientToScreen (hwndMain, &mouse);
      SetCursorPos (mouse.x, mouse.y);
      SetCapture (hwnd);
    } return 0;

    /**********************************************************************\
    *  WM_LBUTTONUP
    *
    * Complement of the WM_LBUTTONDOWN message.  Release the capture,
    *  and reset the actual window's position.
    \**********************************************************************/

    case WM_LBUTTONUP: {
      LONG lTemp;

      if (GetCapture() == hwnd) {
        ReleaseCapture();

        if (peb->rect.left > peb->rect.right)
        {
            lTemp = peb->rect.left;
            peb->rect.left = peb->rect.right;
            peb->rect.right = lTemp;
        }

        if (peb->rect.top > peb->rect.bottom)
        {
            lTemp = peb->rect.top;
            peb->rect.top = peb->rect.bottom;
            peb->rect.bottom = lTemp;
        }

        SetWindowPos (hwnd, NULL, peb->rect.left, peb->rect.top,
                      (peb->rect.right - peb->rect.left),
                      (peb->rect.bottom - peb->rect.top),
                      SWP_NOZORDER);
        InvalidateRect (hwnd, NULL, TRUE);
      }
    return 0;
   }

    /**********************************************************************\
    *  WM_MOUSEMOVE
    *
    * There are two cases of interest here.  If the mouse is captured, then
    *  change the rect field in the extrabyte structure to reflect the new
    *  size/position that the user is selection.
    *
    *  If the mouse is not captured, then set the Action field dependent on
    *  the quadrant so that the WM_SETCURSOR will display the correct cursor.
    *
    \**********************************************************************/

    case WM_MOUSEMOVE: {
      POINT mouse;
      /* the LO/HI-WORD from lParam will be a signed short relative to
       *  the child control window.
       */
      mouse.x = (int)(short)LOWORD(lParam);
      mouse.y = (int)(short)HIWORD(lParam);

      /* if the mouse is captured, then we are doing direct manipulation */
      if (GetCapture() == hwnd) {

        /* translate mouse pos to be client relative, not control relative */
        ClientToScreen (hwnd, &mouse);
        ScreenToClient (hwndMain, &mouse);

        /* erase the old rectangle */
        PaintRect (hwndMain, &peb->rect);

        switch (peb->Action) {
          case ACTIONMOVE  : {
            int width, height;

            width = peb->rect.right - peb->rect.left;
            height = peb->rect.bottom - peb->rect.top;
            peb->rect.left = mouse.x;
            peb->rect.top  = mouse.y;
            peb->rect.right  = peb->rect.left + width;
            peb->rect.bottom = peb->rect.top +  height;
          }break;

          case ACTIONSIZEX :
            peb->rect.right  = mouse.x;
          break;

          case ACTIONSIZEY :
            peb->rect.bottom = mouse.y;
          break;

          case ACTIONSIZEXY:
            peb->rect.right  = mouse.x;
            peb->rect.bottom = mouse.y;
          break;
        }

        /* Redraw the new rectangle */
        PaintRect (hwndMain, &peb->rect);
      }

      /* if the mouse is not captured, then set the action for the sake of
       *  the WM_SETCURSOR message.  The action is dependent upon which
       *  quadrant of the window the mouse cursor is over.
       */
      else {
        int width2, height2;
        RECT rect;

        GetClientRect (hwnd, &rect);
        width2 =  (rect.right -  rect.left)/2;
        height2 =  (rect.bottom -  rect.top)/2;

        /* upper left hand corner */
        if ((mouse.x <= (width2)) && (mouse.y <= (height2))) {
            peb->Action = ACTIONMOVE;

        /* lower left hand corner */
        } else if ((mouse.x <= (width2)) && (mouse.y > (height2))) {
            peb->Action = ACTIONSIZEY;

        /* upper right hand corner */
        } else if ((mouse.x > (width2)) && (mouse.y <= (height2))) {
            peb->Action = ACTIONSIZEX;

        /* lower right hand corner */
        } else if ((mouse.x > (width2)) && (mouse.y > (height2))) {
            peb->Action = ACTIONSIZEXY;
        }
      }
    } return 0;

    /**********************************************************************\
    * for messages that are not handled explicitly here, pass them
    *  back to the old window procedure.
    \**********************************************************************/
    default:
      return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));
    break;
    } /* end switch */

  return 0;
}

DWORD ToggleMenu | ( | HMENU | ,
 |  | UINT |
 | ) |  |

Definition at line 523 of file SUBCLASS.C.

{
  DWORD  state;

  /* query the checked state.
   *  unfortunately, this turns checked off.
   */
  state = CheckMenuItem (hmenu, iditem, MF_BYCOMMAND);

  /* switch the truth value of oldstate. */
  state = (state) ? MF_UNCHECKED : MF_CHECKED;

  /* reset the menu item. */
  CheckMenuItem (hmenu, iditem, MF_BYCOMMAND | state);

  return state;
}

Variable Documentation

BOOL fTestMode

Definition at line 54 of file SUBCLASS.H.

HANDLE hInst

Definition at line 53 of file SUBCLASS.H.

HWND hwndMain

Definition at line 52 of file SUBCLASS.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TERMPROC/TERMPROC.C File Reference

  • TERMPROC
Functions

TERMPROC.C File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windows.h>
#include <string.h>
#include <math.h>
#include <winbase.h>

Go to the source code of this file.

Functions

void | ErrorOut (char errstring[30])
void | main (int argc, char *argv[])

Function Documentation

void ErrorOut ( char errstring[30] )

Definition at line 22 of file TERMPROC.C.

       : Print out an meainful error code by means of
         GetLastError and printf

Inputs:  errstring - the action that failed, passed by the
                     calling proc.

Returns: none

Calls:   GetLastError
*/

{
DWORD Error;

Error= GetLastError();
printf("Error on %s = %d\n", errstring, Error);
}

void main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 45 of file TERMPROC.C.

       : terminate a process based on the PID passed in

Inputs:  argc - number of arguments passed in
         argv - arguments, including PID of process to terminate

Returns: none

Calls:   GetLastError
         OpenProcess - to get handle to process
         TerminateProcess - to terminate process
*/

{
HANDLE hProcess;
double ProcId;
BOOL TermSucc;
int chrintval, chrpos, downcount;
int count=0;
DWORD dwVersion;

    // check if running on Windows NT, if not, display notice and terminate
    dwVersion = GetVersion();
    if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
    {
         MessageBoxA( NULL,
         "This sample application cannot be run on Windows 3.1.\n"
         "This application will now terminate.",
         "TermProc",
         MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
      return;
    }

if (argc == 2)  /* if a PID is passed in */
  {
    chrpos= strcspn( argv[1], "\0");
    count=0;
    ProcId=0;

         /* convert decimal value to hex */
    for (downcount = chrpos -1 ; downcount >= 0; downcount--)
      {
      if (argv[1][downcount] >= '0' && argv[1][downcount] <= '9')
        chrintval= argv[1][downcount]-48;
      else
        if (argv[1][downcount] >= 'a' && argv[1][downcount] <= 'f')
          chrintval= argv[1][downcount]-87;
        else
          chrintval= argv[1][downcount]-55;
      ProcId+= chrintval * pow( (double)16.0, (double)count );
      count++;
      }
       /* open the process to terminate */
  hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, (DWORD)ProcId);
  if (hProcess == NULL)
    ErrorOut("OpenProcess");
  TermSucc= TerminateProcess(hProcess, 0); /* terminate it */
  if (TermSucc == FALSE)
    ErrorOut("TerminateProcess");
  else
    printf("Process# %s terminated successfully!\n", argv[1]);
  }
else  /* no PID, inform user of operation */
  {
  printf("\nTerminates an active Process\n");
  printf("Usage: termproc ProcessID\n");
  }

}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: THREADS/THREADS.C File Reference

  • THREADS
Functions | Variables

THREADS.C File Reference

#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include "threads.h"

Go to the source code of this file.

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | ThreadProc (LPVOID *Color)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

HANDLE | hInst
HANDLE | hWnd

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 191 of file THREADS.C.

{
  static HANDLE hThread1, hThread2;
  DWORD  ThreadID1, ThreadID2;
  CHAR Buf[80];
  static DWORD RedSuspendCnt = 0;
  static DWORD GreenSuspendCnt = 0;
  static DWORD *pColor1, *pColor2;

  switch (message)
      {

        case WM_CREATE :

          pColor1 = malloc(sizeof(DWORD));
          *pColor1 = GREEN;
          hThread1 = CreateThread (NULL, 0,
                                   (LPTHREAD_START_ROUTINE)ThreadProc,
                                   (LPVOID)pColor1, 0,
                                   (LPDWORD)&ThreadID1);

          if (!hThread1)
            {
             wsprintf(Buf, "Error in creating Green thread: %d",
                      GetLastError());
             MessageBox (hwnd, Buf, "WM_CREATE", MB_OK);
            }

          Sleep (500);             // Allow some time/distance between the
                                   // thread boxes.

          pColor2 = malloc(sizeof(DWORD));
          *pColor2 = RED;
          hThread2 = CreateThread (NULL, 0,
                                   (LPTHREAD_START_ROUTINE)ThreadProc,
                                   (LPVOID)pColor2, 0,
                                   (LPDWORD)&ThreadID2);
          if (!hThread2)
            {
             wsprintf(Buf, "Error in creating Red thread: %d",
                      GetLastError());
             MessageBox (hwnd, Buf, "WM_CREATE", MB_OK);
            }

          return (0);

        case WM_COMMAND:
          switch (LOWORD(wParam))
            {
            case IDM_SUSPENDGREEN:           // Suspends green thread.
              SuspendThread (hThread1);
              GreenSuspendCnt++;
              wsprintf(Buf, "The suspension count for the green thread is now %d",
                       GreenSuspendCnt);
              MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
              return (0);

            case IDM_SUSPENDRED:             // Suspends red thread.
              SuspendThread (hThread2);
              RedSuspendCnt++;
              wsprintf(Buf, "The suspension count for the red thread is now %d",
                       RedSuspendCnt);
              MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
              return (0);

            case IDM_RESUMEGREEN:            // Resumes green thread.
              ResumeThread (hThread1);
              if (GreenSuspendCnt > 0)
                GreenSuspendCnt--;
              wsprintf(Buf, "The suspension count for the green thread is now %d",
                       GreenSuspendCnt);
              MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
              return (0);

            case IDM_RESUMERED:              // Resumes red thread.
              ResumeThread (hThread2);
              if (RedSuspendCnt > 0)
                RedSuspendCnt--;
              wsprintf(Buf, "The suspension count for the red thread is now %d",
                       RedSuspendCnt);
              MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
              return (0);

            case IDM_GIDLE:                   // Sets green idle.
              SetThreadPriority (hThread1, THREAD_PRIORITY_IDLE);
              return (0);

            case IDM_GLOW:                   // Sets green lowest.
              SetThreadPriority (hThread1, THREAD_PRIORITY_LOWEST);
              return (0);

            case IDM_GBNORM:                 // Sets green below normal.
              SetThreadPriority (hThread1, THREAD_PRIORITY_BELOW_NORMAL);
              return (0);

            case IDM_GNORM:                  // Sets green to normal.
              SetThreadPriority (hThread1, THREAD_PRIORITY_NORMAL);
              return (0);

            case IDM_GANORM:                 // Sets green above normal.
              SetThreadPriority (hThread1, THREAD_PRIORITY_ABOVE_NORMAL);
              return (0);

            case IDM_GHIGH:                  // Sets green to highest.
              SetThreadPriority (hThread1, THREAD_PRIORITY_HIGHEST);
              return (0);

            case IDM_GTC:                   // Sets green time critical.
              SetThreadPriority (hThread1, THREAD_PRIORITY_TIME_CRITICAL);
              return (0);

            case IDM_RIDLE:                   // Sets red idle.
              SetThreadPriority (hThread1, THREAD_PRIORITY_IDLE);
              return (0);

            case IDM_RLOW:                   // Sets red to lowest possible
              SetThreadPriority (hThread2, THREAD_PRIORITY_LOWEST);
              return (0);

            case IDM_RBNORM:                 // Sets red below normal.
              SetThreadPriority (hThread2, THREAD_PRIORITY_BELOW_NORMAL);
              return (0);

            case IDM_RNORM:                  // Sets red to normal.
              SetThreadPriority (hThread2, THREAD_PRIORITY_NORMAL);
              return (0);

            case IDM_RANORM:                 // Sets red above normal.
              SetThreadPriority (hThread2, THREAD_PRIORITY_ABOVE_NORMAL);
              return (0);

            case IDM_RHIGH:                  // Sets red to highest.
              SetThreadPriority (hThread2, THREAD_PRIORITY_HIGHEST);
              return (0);

            case IDM_RTC:                   // Sets green time critical.
              SetThreadPriority (hThread1, THREAD_PRIORITY_TIME_CRITICAL);
              return (0);

            default:
              return (0);

            }

        case WM_DESTROY :
            TerminateThread(hThread1, 0);
            TerminateThread(hThread2, 0);
            free (pColor1);
            free (pColor2);
            PostQuitMessage (0);
            return (0);

       }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

VOID ThreadProc ( LPVOID * Color )

Definition at line 400 of file THREADS.C.

{
  int  horizontal, vertical;
  DWORD ulx, uly;
  RECT rect;
  HDC  hDC;
  SYSTEMTIME Time;
  HANDLE hBrush;
  DWORD width, height;

  width =  10;
  height = 10;

  GetSystemTime (&Time);                     // Get the time.

  do{}while(!GetClientRect(hWnd, &rect));    // Loop, making sure window
                                             // exists.

  ulx = (Time.wMilliseconds % rect.right);   // Use MOD to get a random
  uly = (Time.wMilliseconds % rect.bottom);  // position.

  if(Time.wMilliseconds % 2 == 0)            // Use MOD to pick random
    {                                        // directions.
     horizontal = 1;
     vertical = 1;
    }
  else
    {
     horizontal = 1;
     vertical = -1;
    }
                                             // Set color as per input
                                             // parameter.
  hBrush = CreateSolidBrush((COLORREF)*Color);

  do
    {                                        // do forever ...
     GetClientRect( hWnd, &rect);

     if ( (ulx+width) > (DWORD)rect.right)   // ... check for right edge,
      {
      ulx = rect.right - width;
      horizontal = -1;                       //   ... if so change direction;
      }

     if ((uly+height) > (DWORD)rect.bottom)  // ... check for bottom edge,
      {
      uly = rect.bottom - height;            //   ... if so change dir.
      vertical = -1;
      }

     if (uly <= 1)                           // ... check for right edge,
      {
      uly = 1;
      vertical = 1;
      }

     if (ulx <= 1)
      {                                      // ... check for top edge;
      ulx = 1;
      horizontal = 1;
      }

     hDC = GetDC(hWnd);                      // ... Get DC,
     SelectObject( hDC, hBrush);             // ... Set brush color,
                                             // ... Draw rectangle,
     Rectangle (hDC, ulx, uly, ulx+width, uly+height);
     ReleaseDC(hWnd, hDC);                   // ... Release DC
     ulx += horizontal;                      // ... Increment/decrement
     uly += vertical;                        // ... position.

    }while(1);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 62 of file THREADS.C.

{
  MSG  msg;
  WNDCLASS wc;

  UNREFERENCED_PARAMETER( lpCmdLine );
  UNREFERENCED_PARAMETER( hPrevInstance );

  // check if Win32s, if so, display notice and terminate
      if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) ==3)
      {
        MessageBox( NULL,
           "This application cannot run on Windows 3.1.\n"
           "This application will now terminate.",
           "Threads",
           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
      }

  hInst = hInstance;

  wc.style = 0;                          // Replaces CS_SIZEREDRAW.
  wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
  wc.cbClsExtra = 0;                     // No room reserved for extra data.
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = "Thread_Menu";
  wc.lpszClassName = "ThreadsWClass";

  RegisterClass(&wc);

  hWnd = CreateWindow ("ThreadsWClass",
                       "Threads Sample",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);

  ShowWindow(hWnd, nCmdShow);
  while (GetMessage (&msg, NULL, 0, 0))
    DispatchMessage (&msg);   // Dispatch message to window.

  return (msg.wParam);           // Returns value from PostQuitMessage.

}

Variable Documentation

HANDLE hInst

Definition at line 50 of file THREADS.C.

HANDLE hWnd

Definition at line 51 of file THREADS.C.

Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: THREADS/THREADS.H File Reference

  • THREADS
Defines | Functions

THREADS.H File Reference

Go to the source code of this file.

Defines

#define | GREEN 0x00007F00
#define | IDM_GANORM 704
#define | IDM_GBNORM 702
#define | IDM_GHIGH 705
#define | IDM_GIDLE 700
#define | IDM_GLOW 701
#define | IDM_GNORM 703
#define | IDM_GTC 706
#define | IDM_RANORM 754
#define | IDM_RBNORM 752
#define | IDM_RESUMEGREEN 601
#define | IDM_RESUMERED 602
#define | IDM_RHIGH 755
#define | IDM_RIDLE 750
#define | IDM_RLOW 751
#define | IDM_RNORM 753
#define | IDM_RTC 756
#define | IDM_SUSPENDGREEN 501
#define | IDM_SUSPENDRED 502
#define | RED 0x0000007F

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | ThreadProc (LPVOID *)

Define Documentation

#define GREEN 0x00007F00

Definition at line 33 of file THREADS.H.

#define IDM_GANORM 704

Definition at line 21 of file THREADS.H.

#define IDM_GBNORM 702

Definition at line 19 of file THREADS.H.

#define IDM_GHIGH 705

Definition at line 22 of file THREADS.H.

#define IDM_GIDLE 700

Definition at line 17 of file THREADS.H.

#define IDM_GLOW 701

Definition at line 18 of file THREADS.H.

#define IDM_GNORM 703

Definition at line 20 of file THREADS.H.

#define IDM_GTC 706

Definition at line 23 of file THREADS.H.

#define IDM_RANORM 754

Definition at line 29 of file THREADS.H.

#define IDM_RBNORM 752

Definition at line 27 of file THREADS.H.

#define IDM_RESUMEGREEN 601

Definition at line 14 of file THREADS.H.

#define IDM_RESUMERED 602

Definition at line 15 of file THREADS.H.

#define IDM_RHIGH 755

Definition at line 30 of file THREADS.H.

#define IDM_RIDLE 750

Definition at line 25 of file THREADS.H.

#define IDM_RLOW 751

Definition at line 26 of file THREADS.H.

#define IDM_RNORM 753

Definition at line 28 of file THREADS.H.

#define IDM_RTC 756

Definition at line 31 of file THREADS.H.

#define IDM_SUSPENDGREEN 501

Definition at line 12 of file THREADS.H.

#define IDM_SUSPENDRED 502

Definition at line 13 of file THREADS.H.

#define RED 0x0000007F

Definition at line 34 of file THREADS.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID ThreadProc ( LPVOID * )

Definition at line 363 of file SEMA.C.

{
  RECT   rect;
  HDC    hDC;
  HANDLE hBrush;
  DWORD  width, height, Col, Row;

  hBrush = CreateSolidBrush((COLORREF)*Color);

  while (TRUE)
  {
      WaitForSingleObject (hSemaphore, INFINITE);
      GetClientRect( hWnd, &rect);

      width  =  rect.right / 4;
      height = rect.bottom / 4;
      Col = (rect.right / 16)  * 6;
      Row = (rect.bottom / 16) * 6;

      hDC = GetDC(hWnd);
      SelectObject( hDC, hBrush);
      Rectangle (hDC, Col, Row, Col + width, Row + height);
      ReleaseDC(hWnd, hDC);
      Sleep (500);
      ReleaseSemaphore (hSemaphore, 1, NULL);
  }

  return;
}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TIMERS/TIMERS.C File Reference

  • TIMERS
Functions

TIMERS.C File Reference

#include <windows.h>
#include <string.h>
#include "timers.h"

Go to the source code of this file.

Functions

void | DrawStuff (HWND hwnd, HDC hdc)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
void | SetButtonPositions (int cx, int cy)
void | SetFlashRectPositions (LONG cx, LONG cy)
void CALLBACK | TimerFunc (HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Function Documentation

void DrawStuff | ( | HWND | hwnd,
 |  | HDC | hdc
 | ) |  |

Definition at line 368 of file TIMERS.C.

{
  RECT   rect;
  HBRUSH hbr;

  //
  // Draw the separator lines between the timer info "windows"
  //

  GetClientRect (hwnd, &rect);
  MoveToEx (hdc, rect.right/2, 0, NULL);
  LineTo (hdc, rect.right/2, rect.bottom);

  MoveToEx (hdc, 0, rect.bottom/2, NULL);
  LineTo (hdc, rect.right, rect.bottom/2);

  //
  // Draw the "Timer #" headers
  //

  TextOut (hdc, BUTTONBORDER, TEXTHEIGHT, "Timer 1:", 8);
  TextOut (hdc, rect.right/2 + BUTTONBORDER, TEXTHEIGHT, "Timer 2:", 8);
  TextOut (hdc, BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT, "Timer 3:", 8);
  TextOut (hdc, rect.right/2 + BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT,
           "Timer 4:", 8);

  //
  // Draw the rectangles to flash on timer messages
  //

  hbr = CreateSolidBrush (0x0000ff);
  FillRect (hdc, &gaFlashRects[ID_TIMER1], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0x00ff00);
  FillRect (hdc, &gaFlashRects[ID_TIMER2], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0xff0000);
  FillRect (hdc, &gaFlashRects[ID_TIMER3], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0x2266aa);
  FillRect (hdc, &gaFlashRects[ID_TIMER4], hbr);
  DeleteObject (hbr);
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 109 of file TIMERS.C.

{
  switch (message)
  {
    case WM_CREATE:
    {
      LONG i;

      //
      // Create the buttons to turn timer on/off
      //

      for (i= ID_TIMER1; i <= ID_TIMER4; i++)
      {
        gahwndButtons[i] = CreateWindow ("button", "Start timer",
                                       WS_CHILD | BS_PUSHBUTTON,
                                       0, 0, 0, 0, hwnd, NULL,
                                       ghInst, NULL);
        SetWindowLong (gahwndButtons[i], GWL_ID, i);
      }

      //
      // Have TIMER1 started initially (giving the user a clue what to do)
      //

      PostMessage (hwnd, WM_COMMAND, (DWORD) ID_TIMER1,
                   (LONG) gahwndButtons[ID_TIMER1]);
      break;
    }

    case WM_COMMAND:
    {
      char buf[BUFSIZE];
      WORD id;

      id = LOWORD (wParam);
      GetWindowText ((HWND) lParam, buf, BUFSIZE);
      if (!strcmp (buf, "Start timer"))
      {
        //
        // Set button text to "Stop timer" and start the timer. For
        //   timers 1&2 we'll specify a WNDPROC ("TimerFunc") which will
        //   get called for each timer tick. For timers 3&4 we'll just
        //   have WM_TIMER messages sent to this window procedure.
        //

        SetWindowText ((HWND) lParam, (LPTSTR) "Stop timer");
        if (id < ID_TIMER3)
        {
          if (SetTimer (hwnd, (UINT) id, (UINT) (id * TIMERINTERVAL),
                        (TIMERPROC) TimerFunc) == 0)

            MessageBox (NULL, (LPCTSTR) "MainWndProc(): SetTimer() failed",
                        (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
        }
        else
        {
          if (SetTimer (hwnd, (UINT) id, (UINT) (id * TIMERINTERVAL),
                        NULL) == 0)

            MessageBox (NULL, (LPCTSTR) "MainWndProc(): SetTimer() failed",
                        (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
        }
      }
      else
      {
        SetWindowText ((HWND) lParam, (LPTSTR) "Start timer");
        KillTimer (hwnd, (UINT) id);
      }
      break;
    }

    case WM_TIMER:
    {
      //
      // Invert the gaFlashRect associated with this timer event
      //

      HDC hdc = GetDC (hwnd);

      InvertRect (hdc, &gaFlashRects[wParam]); // wParam = timerId
      ReleaseDC  (hwnd, hdc);
      break;
    }

    case WM_SIZE:
    {
      int width  = (int) LOWORD(lParam);
      int height = (int) HIWORD(lParam);

      //
      // User resized the window, so reposition button & flashing rects
      //

      SetButtonPositions (width, height);
      SetFlashRectPositions (width, height);
      break;
    }

    case WM_PAINT:
    {
      PAINTSTRUCT ps;

      BeginPaint (hwnd, &ps);
      DrawStuff (hwnd, ps.hdc);
      EndPaint (hwnd, &ps);
      break;
    }

    case WM_DESTROY:

      PostQuitMessage(0);
      break;

    default:

      return (DefWindowProc(hwnd, message, wParam, lParam));
  }
  return (0);
}

void SetButtonPositions | ( | int | cx,
 |  | int | cy
 | ) |  |

Definition at line 275 of file TIMERS.C.

{
  SetWindowPos (gahwndButtons[ID_TIMER1], NULL,     // upper-left button
                BUTTONBORDER,
                cy/2 - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER2], NULL,     // upper-right button
                cx/2 + BUTTONBORDER,
                cy/2 - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER3], NULL,     // lower-left button
                BUTTONBORDER,
                cy - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER4], NULL,     // lower-right button
                cx/2 + BUTTONBORDER,
                cy - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);
}

void SetFlashRectPositions | ( | LONG | cx,
 |  | LONG | cy
 | ) |  |

Definition at line 323 of file TIMERS.C.

{                                                 /* upper-left rect  */
  gaFlashRects[ID_TIMER1].left   = BUTTONBORDER;
  gaFlashRects[ID_TIMER1].top    = 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER1].right  = cx/2 - BUTTONBORDER;
  gaFlashRects[ID_TIMER1].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* upper-right rect */
  gaFlashRects[ID_TIMER2].left   = cx/2 + BUTTONBORDER;
  gaFlashRects[ID_TIMER2].top    = 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER2].right  = cx - BUTTONBORDER;
  gaFlashRects[ID_TIMER2].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* lower-left rect  */
  gaFlashRects[ID_TIMER3].left   = BUTTONBORDER;
  gaFlashRects[ID_TIMER3].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER3].right  = cx/2 - BUTTONBORDER;
  gaFlashRects[ID_TIMER3].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* lower-right rect */
  gaFlashRects[ID_TIMER4].left   = cx/2 + BUTTONBORDER;
  gaFlashRects[ID_TIMER4].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER4].right  = cx - BUTTONBORDER;
  gaFlashRects[ID_TIMER4].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;
}

void CALLBACK TimerFunc | ( | HWND | hwnd,
 |  | UINT | uMsg,
 |  | UINT | idEvent,
 |  | DWORD | dwTime
 | ) |  |

Definition at line 252 of file TIMERS.C.

{
  HDC hdc = GetDC (hwnd);

  InvertRect (hdc, &gaFlashRects[idEvent]);
  ReleaseDC  (hwnd, hdc);
}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 50 of file TIMERS.C.

                                                   {
  HWND hwnd;
  MSG msg;

  if (!hPrevInstance)
  {
    WNDCLASS wc;

    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc   = (WNDPROC)MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (WHITE_BRUSH);
    wc.lpszMenuName  = (LPCTSTR) NULL;
    wc.lpszClassName = (LPCTSTR) "TIMERS";

    if (!RegisterClass (&wc))
    {
      MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
                  (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
      return(FALSE);
    }
  }

  ghInst = hInstance;
  if (!(hwnd = CreateWindow ("TIMERS", "TIMERS Sample Application",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             CW_USEDEFAULT, CW_USEDEFAULT,
                             NULL, NULL, ghInst, NULL)))
    return (0);

  ShowWindow (hwnd, nCmdShow);

  while (GetMessage (&msg, NULL, 0,0))
  {
    TranslateMessage (&msg);
    DispatchMessage  (&msg);
  }
  return (msg.wParam);
  UNREFERENCED_PARAMETER(lpCmdLine);
}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TIMERS/TIMERS.H File Reference

  • TIMERS
Defines | Functions | Variables

TIMERS.H File Reference

Go to the source code of this file.

Defines

#define | BUFSIZE 20
#define | BUTTONBORDER 5
#define | BUTTONHEIGHT 25
#define | ID_TIMER1 1
#define | ID_TIMER2 2
#define | ID_TIMER3 3
#define | ID_TIMER4 4
#define | TEXTHEIGHT 8
#define | TIMERINTERVAL 250

Functions

VOID | DrawStuff (HWND, HDC)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
VOID | SetButtonPositions (int, int)
VOID | SetFlashRectPositions (LONG, LONG)
VOID CALLBACK | TimerFunc (HWND, UINT, UINT, DWORD)

Variables

RECT | gaFlashRects [5]
HWND | gahwndButtons [5]
HANDLE | ghInst

Define Documentation

#define BUFSIZE 20

Definition at line 29 of file TIMERS.H.

#define BUTTONBORDER 5

Definition at line 31 of file TIMERS.H.

#define BUTTONHEIGHT 25

Definition at line 32 of file TIMERS.H.

#define ID_TIMER1 1

Definition at line 24 of file TIMERS.H.

#define ID_TIMER2 2

Definition at line 25 of file TIMERS.H.

#define ID_TIMER3 3

Definition at line 26 of file TIMERS.H.

#define ID_TIMER4 4

Definition at line 27 of file TIMERS.H.

#define TEXTHEIGHT 8

Definition at line 33 of file TIMERS.H.

#define TIMERINTERVAL 250

Definition at line 35 of file TIMERS.H.

Function Documentation

VOID DrawStuff | ( | HWND | ,
 |  | HDC |
 | ) |  |

Definition at line 368 of file TIMERS.C.

{
  RECT   rect;
  HBRUSH hbr;

  //
  // Draw the separator lines between the timer info "windows"
  //

  GetClientRect (hwnd, &rect);
  MoveToEx (hdc, rect.right/2, 0, NULL);
  LineTo (hdc, rect.right/2, rect.bottom);

  MoveToEx (hdc, 0, rect.bottom/2, NULL);
  LineTo (hdc, rect.right, rect.bottom/2);

  //
  // Draw the "Timer #" headers
  //

  TextOut (hdc, BUTTONBORDER, TEXTHEIGHT, "Timer 1:", 8);
  TextOut (hdc, rect.right/2 + BUTTONBORDER, TEXTHEIGHT, "Timer 2:", 8);
  TextOut (hdc, BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT, "Timer 3:", 8);
  TextOut (hdc, rect.right/2 + BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT,
           "Timer 4:", 8);

  //
  // Draw the rectangles to flash on timer messages
  //

  hbr = CreateSolidBrush (0x0000ff);
  FillRect (hdc, &gaFlashRects[ID_TIMER1], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0x00ff00);
  FillRect (hdc, &gaFlashRects[ID_TIMER2], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0xff0000);
  FillRect (hdc, &gaFlashRects[ID_TIMER3], hbr);
  DeleteObject (hbr);
  hbr = CreateSolidBrush (0x2266aa);
  FillRect (hdc, &gaFlashRects[ID_TIMER4], hbr);
  DeleteObject (hbr);
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

VOID SetButtonPositions | ( | int | ,
 |  | int |
 | ) |  |

Definition at line 275 of file TIMERS.C.

{
  SetWindowPos (gahwndButtons[ID_TIMER1], NULL,     // upper-left button
                BUTTONBORDER,
                cy/2 - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER2], NULL,     // upper-right button
                cx/2 + BUTTONBORDER,
                cy/2 - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER3], NULL,     // lower-left button
                BUTTONBORDER,
                cy - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);

  SetWindowPos (gahwndButtons[ID_TIMER4], NULL,     // lower-right button
                cx/2 + BUTTONBORDER,
                cy - BUTTONBORDER - BUTTONHEIGHT,
                cx/2 - 2*BUTTONBORDER,
                BUTTONHEIGHT,
                SWP_SHOWWINDOW);
}

VOID SetFlashRectPositions | ( | LONG | ,
 |  | LONG |
 | ) |  |

Definition at line 323 of file TIMERS.C.

{                                                 /* upper-left rect  */
  gaFlashRects[ID_TIMER1].left   = BUTTONBORDER;
  gaFlashRects[ID_TIMER1].top    = 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER1].right  = cx/2 - BUTTONBORDER;
  gaFlashRects[ID_TIMER1].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* upper-right rect */
  gaFlashRects[ID_TIMER2].left   = cx/2 + BUTTONBORDER;
  gaFlashRects[ID_TIMER2].top    = 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER2].right  = cx - BUTTONBORDER;
  gaFlashRects[ID_TIMER2].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* lower-left rect  */
  gaFlashRects[ID_TIMER3].left   = BUTTONBORDER;
  gaFlashRects[ID_TIMER3].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER3].right  = cx/2 - BUTTONBORDER;
  gaFlashRects[ID_TIMER3].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;

                                                  /* lower-right rect */
  gaFlashRects[ID_TIMER4].left   = cx/2 + BUTTONBORDER;
  gaFlashRects[ID_TIMER4].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
  gaFlashRects[ID_TIMER4].right  = cx - BUTTONBORDER;
  gaFlashRects[ID_TIMER4].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;
}

VOID CALLBACK TimerFunc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | DWORD |
 | ) |  |

Definition at line 252 of file TIMERS.C.

{
  HDC hdc = GetDC (hwnd);

  InvertRect (hdc, &gaFlashRects[idEvent]);
  ReleaseDC  (hwnd, hdc);
}

Variable Documentation

RECT gaFlashRects[5]

Definition at line 49 of file TIMERS.H.

HWND gahwndButtons[5]

Definition at line 44 of file TIMERS.H.

HANDLE ghInst

Definition at line 43 of file TIMERS.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSCALL.C File Reference

  • TLS
Functions

TLSCALL.C File Reference

Go to the source code of this file.

Functions

void | Another_Thread ()
void | ErrorOut (char errstring[30])
void | main (void)

Function Documentation

void Another_Thread ( )

Definition at line 52 of file TLSCALL.C.

       : Make a call into a DLL and then terminate, allowing
         DLL init. and termination to be called.

Inputs:  none

Returns: none

Calls:   TlsInit: Dummy proc. to allow DLL initialization.
*/

{
Sleep(300);      /* Sleep while other threads start */
TlsInit();       /* Call dummy init. procedure */
ExitThread(0);   /* Exit, calling DLL termination */
}

void ErrorOut ( char errstring[30] )

Definition at line 30 of file TLSCALL.C.

       : Print out an meainful error code by means of
         GetLastError and printf

Inputs:  errstring - the action that failed, passed by the
                     calling proc.

Returns: none

Calls:   GetLastError
*/

{
DWORD Error;

Error= GetLastError();
printf("Error on %s = %d\n", errstring, Error);
}

void main ( void )

Definition at line 72 of file TLSCALL.C.

       : Make a call into a DLL and then terminate, allowing
         DLL init. and termination to be called.

Inputs:  none

Returns: none

Calls:   CreateThread: to create threads for DLL init.
         ErrorOut: To output any errors
         WaitForMultipleObjects: To wait on thread(s) termination
*/

{
int  threadid;
HANDLE hThreads[NUMTHREADS];
int count;

  // check if Win32s, if so, display notice and terminate
     if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) ==3)
     {
       MessageBox( NULL,
          "This application cannot run on Windows 3.1.\n"
          "This application will now terminate.",
          "Tls",
          MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
       return;
     }

 /* start NUMTHREADS threads */
  for (count = 0 ; count < NUMTHREADS ; count++)
  {
  hThreads[count]= CreateThread(NULL,
                                0,
                                (LPTHREAD_START_ROUTINE)Another_Thread,
                                NULL,
                                0,
                                (LPDWORD)&threadid);
  if( hThreads[count] == 0)
    ErrorOut("CreateThread");
  else
    printf("\nStarting thread# %d\n\n", count +1);
  }

      /* now wait for threads to terminate */
printf("\n\n***** Waiting for %d Threads to Exit*****\n\n", NUMTHREADS);
WaitForMultipleObjects( NUMTHREADS,
                        hThreads,
                        FALSE,
                        0xFFFFFFFF);
Sleep(1000);
printf("\n\n*****   All %d Threads Terminated   *****\n\n", NUMTHREADS);

}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSDLL.C File Reference

  • TLS
Functions | Variables

TLSDLL.C File Reference

Go to the source code of this file.

Functions

BOOL WINAPI | DllMain (HINSTANCE hInst, ULONG ul_reason_being_called, LPVOID lpReserved)
void | ErrorOut (char errstring[30])
INT WINAPI | TlsInit ()
INT WINAPI | TlsRetreive (DWORD TlsIndex)

Variables

char | chTlsCount [3]
int | TlsCount = 0
DWORD TlsIndex

Function Documentation

BOOL WINAPI DllMain | ( | HINSTANCE | hInst,
 |  | ULONG | ul_reason_being_called,
 |  | LPVOID | lpReserved
 | ) |  |

Definition at line 53 of file TLSDLL.C.

       : Is called by LibEntry, upon entering a dll or detaching
         from a DLL.  This function does most of the TLS manipulation.

Inputs:  hInst - not used
         ul_reason_being_called - reason DllMain is called

Returns: N/A

Calls:   TlsAlloc - allocate a TLS index
         malloc - allocate space for tls storage
         TlsSetValue - Store TLS values
         TlsFree - free TLS index
         TlsRetreive - retreives TLS values, based on index
*/

{

LPVOID TlsString;  /* TLS string for storage */

UNREFERENCED_PARAMETER(hInst);
UNREFERENCED_PARAMETER(lpReserved);

switch (ul_reason_being_called)
  {
  case DLL_PROCESS_ATTACH:           /* process attaches         */
    printf("Process Attaching\n");
    TlsIndex= TlsAlloc();            /* create TLS index         */
    if (TlsIndex == 0xFFFFFFFF)
      ErrorOut("TlsAlloc");
    break;

  case DLL_THREAD_ATTACH:            /* thread attaches          */
    if (!(DLL_PROCESS_ATTACH & ul_reason_being_called))
    {
    printf("Thread Attaching\n");
    TlsCount++;
    TlsString= malloc(100);          /* allocate storage         */
    memset(TlsString, '\0', 1);
    strcat(TlsString, "Tls Thread#");/* build -                  */
    strcat(TlsString,
           itoa(TlsCount, chTlsCount,
           10) );                    /* - string                 */
    if (TlsSetValue(TlsIndex,        /* set TLS value            */
                    TlsString))
      printf("TlsSetValue success\n\n");
    else
      ErrorOut("TlsSetValue");
    }
    else
      printf("Process & Thread attaching\n\n");
    break;

  case DLL_THREAD_DETACH:            /* thread detaches          */
    printf("Thread Detaching\n");
    TlsRetreive(TlsIndex);           /* retreive TLS data        */
    break;

  case DLL_PROCESS_DETACH:           /* process detaches         */
    printf("Process Detaching\n");
    if (!TlsFree(TlsIndex))          /* free TLS index           */
      ErrorOut("TlsFree");
    else
      printf("TlsIndex Freed\n");
    break;

  default:
    break;
  }

return 1;
}

void ErrorOut ( char errstring[30] )

Definition at line 31 of file TLSDLL.C.

       : Print out an meainful error code by means of
         GetLastError and printf

Inputs:  errstring - the action that failed, passed by the
                     calling proc.

Returns: none

Calls:   GetLastError
*/

{
DWORD Error;

Error= GetLastError();
printf("Error on %s = %d\n", errstring, Error);
}

INT WINAPI TlsInit ( )

Definition at line 133 of file TLSDLL.C.

       : Allow DllMain to be executed for each thread

Inputs:  none

Returns: none

Calls:   none
*/

{
return 1;
}

INT WINAPI TlsRetreive ( DWORD TlsIndex )

Definition at line 151 of file TLSDLL.C.

       : Retreive TLS values and display (printf) them

Inputs:  TlsIndex - TLS index value

Returns: none

Calls:   TlsGetValue - Gets the TLS value from the index
                       based on the current thread.
*/

{
LPVOID tlsvals;

(LPVOID)tlsvals= TlsGetValue(TlsIndex);   /* get the TLS value */
if (tlsvals == 0)
  ErrorOut("TlsGetValue");
else
  printf("tls value=  %s\n\n", tlsvals ); /* output it         */
return 1;
}

Variable Documentation

char chTlsCount[3]

Definition at line 27 of file TLSDLL.C.

int TlsCount = 0

Definition at line 26 of file TLSDLL.C.

DWORD TlsIndex

Definition at line 25 of file TLSDLL.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSDLL.H File Reference

  • TLS
Functions

TLSDLL.H File Reference

Go to the source code of this file.

Functions

INT WINAPI | TlsInit ()
INT WINAPI | TlsRetreive (DWORD)

Function Documentation

INT WINAPI TlsInit ( )

Definition at line 133 of file TLSDLL.C.

       : Allow DllMain to be executed for each thread

Inputs:  none

Returns: none

Calls:   none
*/

{
return 1;
}

INT WINAPI TlsRetreive ( DWORD )

Definition at line 151 of file TLSDLL.C.

       : Retreive TLS values and display (printf) them

Inputs:  TlsIndex - TLS index value

Returns: none

Calls:   TlsGetValue - Gets the TLS value from the index
                       based on the current thread.
*/

{
LPVOID tlsvals;

(LPVOID)tlsvals= TlsGetValue(TlsIndex);   /* get the TLS value */
if (tlsvals == 0)
  ErrorOut("TlsGetValue");
else
  printf("tls value=  %s\n\n", tlsvals ); /* output it         */
return 1;
}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/DISPLAY.C File Reference

  • UNIPUT
Data Structures | Defines | Typedefs | Functions | Variables

DISPLAY.C File Reference

#include <windows.h>
#include "uniput.h"
#include "display.h"

Go to the source code of this file.

Data Structures

struct | tagSUBTABLE
struct | tagTABLE

Defines

#define | CMAPHEX 0x70616d63
#define | GWLU_NCHAR 0
#define | GWLU_SQRHEIGHT 4
#define | GWLU_SQRWIDTH 8
#define | MAXSEGMENTS 100
#define | NBYTES 256
#define | NUMCHARS 255
#define | OFFSETERROR 0
#define | SEGMENTERROR -1
#define | UNICODE

Typedefs

typedef struct tagSUBTABLE * | PSUBTABLE
typedef struct tagTABLE * | PTABLE
typedef struct tagSUBTABLE | SUBTABLE
typedef struct tagTABLE | TABLE

Functions

int | closeDisplay (VOID)
int | CountUCSegments (HDC)
LRESULT CALLBACK | DisplayWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
int | openDisplay (VOID)
VOID | SwapShort (PUSHORT)
VOID | SwapULong (PULONG)
int | transIndextoRect (int, PRECT, int, int, int)
int | transXYtoIndex (int, int, int, int, int)

Variables

USHORT * | endCount = NULL
int | FontHeight
int | FontWidth
HBITMAP | hbmMemXOR
HDC | hdcMemXOR
LOGFONT | logfont
int | nSegments
PVOID | pbitsAND
PVOID | pbitsXOR
USHORT * | startCount = NULL

Define Documentation

#define CMAPHEX 0x70616d63

Definition at line 761 of file DISPLAY.C.

#define GWLU_NCHAR 0

Definition at line 71 of file DISPLAY.C.

#define GWLU_SQRHEIGHT 4

Definition at line 72 of file DISPLAY.C.

#define GWLU_SQRWIDTH 8

Definition at line 73 of file DISPLAY.C.

#define MAXSEGMENTS 100

Definition at line 56 of file DISPLAY.C.

#define NBYTES 256

Definition at line 762 of file DISPLAY.C.

#define NUMCHARS 255
#define OFFSETERROR 0

Definition at line 763 of file DISPLAY.C.

#define SEGMENTERROR -1

Definition at line 62 of file DISPLAY.C.

#define UNICODE

Definition at line 48 of file DISPLAY.C.

Typedef Documentation

typedef struct tagSUBTABLE * PSUBTABLE
typedef struct tagTABLE * PTABLE
typedef struct tagSUBTABLE SUBTABLE
typedef struct tagTABLE TABLE

Function Documentation

int closeDisplay ( VOID )

Definition at line 205 of file DISPLAY.C.

{
HFONT hfont;

  hfont = SelectObject  (hdcMemXOR, GetStockObject(SYSTEM_FONT));
  DeleteObject (hfont);
  DeleteDC (hdcMemXOR);
  DeleteObject (hbmMemXOR);

  LocalFree (LocalHandle (pbitsXOR));
  LocalFree (LocalHandle (pbitsAND));

  if (startCount != NULL) LocalFree (LocalHandle (startCount));
  if (endCount != NULL) LocalFree (LocalHandle (endCount));

  return TRUE;
}

int CountUCSegments ( HDC hdc )

Definition at line 786 of file DISPLAY.C.

{
DWORD       cbData;
USHORT      aShort[2];
DWORD       nBytes;
USHORT      i, nTables;
PTABLE      pTable;
PSUBTABLE   pSubTable;
ULONG       offset,offsetFormat4;
USHORT      segCount;
BYTE        buffer[NBYTES];

    /* find number of "subtables", second long in cmap */
    nBytes=GetFontData (hdc, CMAPHEX, 0, aShort, 4);
    if (nBytes == GDI_ERROR) {
      MessageBox (NULL, MBGETFONTDATAERR,MBERROR , MBERRORFLAGS);
      return SEGMENTERROR;
    }
    if (nBytes == 0) {
      MessageBox (NULL, TEXT("No 'cmap' table."),MBERROR , MBERRORFLAGS);
      return SEGMENTERROR;
    }
    nTables = aShort[1];
    SwapShort (&nTables);

    cbData = nTables * sizeof(TABLE);
    if (cbData >NBYTES) {
      MessageBox (NULL, TEXT("cbData >NBYTES"),MBERROR , MBERRORFLAGS);
      return SEGMENTERROR;
    }

    /* get array of subtables information.  Check each one for 3,1*/
    nBytes=GetFontData (hdc, CMAPHEX, 4, buffer, cbData);
    pTable = (PTABLE)buffer;
    offsetFormat4 = OFFSETERROR;
    for (i = 0; i< nTables; i++) {

        SwapShort (&(pTable->encodingID));
        SwapShort (&(pTable->platformID));

        if ((pTable->platformID == 3)&&(pTable->encodingID == 1)) {
          offsetFormat4 = pTable->offset;
          SwapULong (&offsetFormat4);
          break;
        }
        pTable++;
    }

    /* verify that we got the correct offset to the FORMAT 4 subtable */
    if (offsetFormat4 == OFFSETERROR){
      MessageBox (NULL, TEXT("Can not find 3,1 subtable"),MBERROR , MBERRORFLAGS);
      return SEGMENTERROR;
    }

    /* Get the beginning of the subtable, especially the segment count */
    nBytes=GetFontData (hdc, CMAPHEX, offsetFormat4, buffer, sizeof(SUBTABLE));
    pSubTable = (PSUBTABLE) buffer;
    SwapShort (&(pSubTable->format));
    SwapShort (&(pSubTable->segCountX2));

    if (pSubTable->format != 4){
      MessageBox (NULL, TEXT("format !=4"), MBERROR, MBERRORFLAGS);
      return SEGMENTERROR;
    }

    segCount = pSubTable->segCountX2 / 2;

    /* Now that we know how many segments that the font contains,
     *  free up the old memory, and realloc. the two global arrays.
     */
    if (startCount != NULL) LocalFree (LocalHandle (startCount));
    if (endCount != NULL) LocalFree (LocalHandle (endCount));
    startCount = LocalAlloc (LPTR, segCount * sizeof(USHORT));
    endCount = LocalAlloc (LPTR, segCount * sizeof(USHORT));

    if ((startCount == NULL) || (endCount == NULL)) {
      MessageBox (NULL, TEXT("LocalAlloc failed"), MBERROR, MBERRORFLAGS);
      return SEGMENTERROR;
    }

    /* read in the array of endCount values */
    offset = offsetFormat4
           + (7 * sizeof (USHORT));  /* skip constant # bytes in subtable */
    cbData = segCount * sizeof (USHORT);
    nBytes=GetFontData (hdc, CMAPHEX, offset, endCount, cbData );
    for (i = 0; i<segCount; i++)
        SwapShort (& (endCount[i]));

    /* read in the array of startCount values */
    offset = offsetFormat4
           + (7 * sizeof (USHORT))   /* skip constant # bytes in subtable */
           + (segCount * sizeof (USHORT)) /* skip endCount array */
           + sizeof (USHORT);             /* skip reservedPad */
    cbData = segCount * sizeof (USHORT);
    nBytes=GetFontData (hdc, CMAPHEX, offset, startCount, cbData );
    for (i = 0; i<segCount; i++)
        SwapShort (& (startCount[i]));

    return segCount;
}

LRESULT CALLBACK DisplayWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 231 of file DISPLAY.C.

{
static HFONT  hfont, hfontOld;

static HDC hdc;
static RECT rect;
static int iSeg;
static TCHAR buffer[100];

/* rDown and index used as the user points to a square. */
static RECT rDown;
static int index;

static WCHAR DragDropChar;
static HICON hIcon;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Set up the LOGFONT in the HDC for this window.
    \**********************************************************************/
    case WM_CREATE:
      SendMessage (hwnd, WMU_SETNCHAR, 16, 0);
      SendMessage (hwnd, WMU_NEWFONT, FontWidth, FontHeight);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Get rid of the logical font we create for each display window.
    *  relying here on CS_ONWDC
    \**********************************************************************/
    case WM_DESTROY:
      hdc = GetDC (hwnd);
      hfont = SelectObject  (hdc, GetStockObject(SYSTEM_FONT));
      DeleteObject (hfont);
      ReleaseDC (hwnd, hdc);
    break;

    /**********************************************************************\
    *  WMU_SETNCHAR
    *
    * wParam - nCharPerLine
    *
    \**********************************************************************/
    case WMU_SETNCHAR:
      SetWindowLong (hwnd, GWLU_NCHAR, (int) wParam);
      InvalidateRect (hwnd, NULL, TRUE);
    break;

    /**********************************************************************\
    *  WMU_NEWFONT
    *
    * wParam - Width
    * lParam - Height
    *
    * Create font, select it into the HDC, and reset ranges.
    \**********************************************************************/
    case WMU_NEWFONT: {

      hdc = GetDC(hwnd);

      FontWidth  = (int) wParam;
      FontHeight = (int) lParam;
      logfont.lfHeight = FontHeight;
      logfont.lfWidth  = FontWidth;

      hfont = CreateFontIndirect (&logfont);
      hfontOld = SelectObject (hdc, hfont);
      DeleteObject (hfontOld);

      ReleaseDC (hwnd, hdc);

      SetScrollRange (hwnd, SB_HORZ, 0, (nSegments-1), TRUE);
      SetScrollPos (hwnd, SB_HORZ, 0, TRUE);

      SendMessage (hwnd, WMU_NEWRANGE, 0,0);

    } return TRUE;

    /**********************************************************************\
    *  WMU_NEWRANGE
    *
    *
    * Range changes, or font size changes, or title status changes.
    \**********************************************************************/
    case WMU_NEWRANGE: {
      int sqrHeight, sqrWidth;
      TEXTMETRIC tm;
      int i;

      hdc = GetDC(hwnd);
      GetTextMetrics (hdc, &tm);
      ReleaseDC (hwnd, hdc);

      /* index into the start, end arrays stored in scroll bar */
      iSeg = GetScrollPos (hwnd, SB_HORZ);

      /* Set the window title text to show display range. */
      wsprintf (buffer, TEXT("[%04x, %04x]"),
                                  (int)startCount[iSeg],
                                  (int)endCount[iSeg]);

      /* if we are supposed to look up the character range name,
       *  then step through the ranges stored in the RangeName
       *  table.  Find the correct one, and reset the buffer string.
       */
      if (gShowNames) {
        for (i = 0; i< NRANGE; i++) {
          if ((RangeName[i].start <= startCount[iSeg]) &&
              ( startCount[iSeg] <= RangeName[i].end))

            wsprintf (buffer, TEXT("%s [%04x, %04x]"),
                                  RangeName[i].String,
                                  (int)startCount[iSeg],
                                  (int)endCount[iSeg]);

        }
      }
      SetWindowText (hwnd, buffer);

      sqrHeight =  tm.tmHeight + tm.tmExternalLeading;
      sqrWidth = tm.tmMaxCharWidth;

      SetWindowLong (hwnd, GWLU_SQRHEIGHT,sqrHeight);
      SetWindowLong (hwnd, GWLU_SQRWIDTH, sqrWidth );

    } return TRUE;

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    *
    * Static, shared variables set in WM_LBUTTONDOWN:
    *   rDown, hIcon, DragDropChar
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN: {
      int x,y;
      int nCharPerLine;
      int sqrHeight, sqrWidth;
      nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
      sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
      sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );

      x = (int)LOWORD (lParam);
      y = (int)HIWORD (lParam);

      index = transXYtoIndex (x,y, sqrWidth, sqrHeight, nCharPerLine);

      /* verify that the index is within the shown segment range */
      iSeg= GetScrollPos (hwnd, SB_HORZ);
      if (index > (endCount[iSeg]- startCount[iSeg])) return 0;

      DragDropChar = index + startCount[iSeg];

      transIndextoRect (index, &rDown, sqrWidth, sqrHeight, nCharPerLine);

      hdc = GetDC (hwnd);
      InvertRect (hdc, &rDown);
      ReleaseDC (hwnd, hdc);

      /* Create a cursor which represents the character.
       * Global variables used:
       *   HDC hdcMemXOR;
       *   HBITMAP hbmMemXOR;
       *   PVOID pbitsXOR, pbitsAND;
       */
      {
      int cxCursor, cyCursor;
      RECT rect;

      cxCursor = GetSystemMetrics (SM_CXCURSOR);
      cyCursor = GetSystemMetrics (SM_CYCURSOR);

      rect.left = rect.top = 0;
      rect.right = cxCursor; rect.bottom = cyCursor;

      FrameRect (hdcMemXOR, &rect, GetStockObject (BLACK_BRUSH));
      InflateRect (&rect, -1, -1);
      FillRect (hdcMemXOR, &rect, GetStockObject (LTGRAY_BRUSH));
      FrameRect (hdcMemXOR, &rect, GetStockObject (GRAY_BRUSH));
      InflateRect (&rect, -1, -1);
      SelectObject (hdcMemXOR, GetStockObject (WHITE_PEN));
      MoveToEx (hdcMemXOR, rect.right, rect.top, NULL);
      LineTo (hdcMemXOR,rect.left, rect.top);
      LineTo (hdcMemXOR,rect.left, rect.bottom);

      ExtTextOut(hdcMemXOR, cxCursor/2,0, ETO_CLIPPED, &rect,
                   (LPCWSTR)&DragDropChar, 1, NULL);

      GetBitmapBits (hbmMemXOR, cxCursor*cyCursor/2, pbitsXOR);

      hIcon = CreateIcon( GetModuleHandle(NULL),
              cxCursor,cyCursor, 1,4,
              pbitsAND,
              pbitsXOR);

      SetCursor ((HCURSOR)hIcon);
      }

      GdiFlush ();
      SetCapture (hwnd);
    } break;

    /**********************************************************************\
    *  WM_LBUTTONUP
    *
    * Static, shared variables set in WM_LBUTTONDOWN:
    *   rDown, hIcon, DragDropChar
    *
    \**********************************************************************/
    case WM_LBUTTONUP: {
      POINT p;
      HWND hwndTarget, hwndTitle;
#define NUMCHARS  255
      TCHAR buffer[NUMCHARS];

      if (GetCapture() == hwnd) {

        p.x = (int)(short)LOWORD (lParam);
        p.y = (int)(short)HIWORD (lParam);

        ClientToScreen (hwnd, &p);
        hwndTarget = WindowFromPoint (p);

        if ((GetWindowThreadProcessId (hwnd, NULL)) !=
            (GetWindowThreadProcessId (hwndTarget, NULL))) {

          /* hack.  unipad has a client window which gets the chars,
           *  but we want to display the frame windows text (title bar),
           *  so try to get the parent of the target for Title purposes.
           */
          hwndTitle = (GetParent(hwndTarget)) ? GetParent(hwndTarget) : hwndTarget;
          GetWindowText (hwndTitle, buffer, NUMCHARS);

          SendMessage (hwndTarget, WM_CHAR, (WPARAM) DragDropChar, 0);
          SendMessage (hwndStatus, WMU_CHARACTER,
                         (WPARAM) DragDropChar, (LPARAM)hwndTarget);
          SendMessage (hwndStatus, WMU_SETTARGETNAME,
                         (WPARAM) IsWindowUnicode (hwndTarget), (LPARAM)buffer);
        } /* end different process */

        Beep (40,40);

        hdc = GetDC (hwnd);
        InvertRect (hdc, &rDown);
        ReleaseDC (hwnd, hdc);
        GdiFlush ();
        ReleaseCapture ();
        SetCursor ((HCURSOR)LoadCursor (NULL, IDC_ARROW));
        DestroyIcon (hIcon);
      }
    } break;

    /**********************************************************************\
    *  WM_HSCROLL
    *
    * Step through the character ranges.
    * In every case, inform the window the range has changed,
    *  and invalidate it to force a repaint.
    \**********************************************************************/
    case WM_HSCROLL:

      switch (LOWORD(wParam)){
        int OldPos, NewPos;

        case SB_PAGEDOWN:
        case SB_LINEDOWN:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          SetScrollPos (hwnd, SB_HORZ, (OldPos+1), TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

        case SB_PAGEUP:
        case SB_LINEUP:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          SetScrollPos (hwnd, SB_HORZ, (OldPos-1), TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

        case SB_THUMBPOSITION:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          NewPos = HIWORD (wParam);
          SetScrollPos (hwnd, SB_HORZ, NewPos, TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

      }

    break;

    /**********************************************************************\
    *  WM_SIZE
    *
    \**********************************************************************/
    case WM_SIZE:
      /* make sure that scroll metrics are ok */
      SendMessage (hwnd, WMU_NEWRANGE, 0,0);

    break;  /* fall through to MDIChildProc */

    /**********************************************************************\
    *  WM_PAINT
    *
    \**********************************************************************/
    case WM_PAINT: {
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;
      POINT  point;
      int i;
      USHORT start, end;
      WCHAR outChar;
      USHORT codepoint;
      int nCharPerLine;
      int sqrHeight, sqrWidth;
      nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
      sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
      sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );

      hdc = BeginPaint(hwnd, &ps);
      SetBkMode (hdc, TRANSPARENT);

      iSeg= GetScrollPos (hwnd, SB_HORZ);
      start = startCount[iSeg];
      end = endCount[iSeg];

      /* ensure that we are in a valid range... some fonts have problems */
      if (start != 0xffff)

        for (codepoint = start, i=0; codepoint<=end; codepoint++,i++) {

          /* paint box and frame it */
          transIndextoRect (i, &rect, sqrWidth, sqrHeight, nCharPerLine);
          InflateRect (&rect, -1, -1);
          FillRect (hdc, &rect, GetStockObject (LTGRAY_BRUSH));
          InflateRect (&rect, 1, 1);
          FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
          InflateRect (&rect, -1, -1);
          SelectObject (hdc, GetStockObject (WHITE_PEN));
          MoveToEx (hdc, rect.right, rect.top, NULL);
          LineTo (hdc,rect.left, rect.top);
          LineTo (hdc,rect.left, rect.bottom);

          /* set point that we will draw glyph at */
          point.x = (rect.right + rect.left)/2;
          point.y = rect.top;
          SetTextAlign (hdc, TA_CENTER | TA_TOP);
          SetTextColor (hdc, PALETTEINDEX (0));

          /* special case the non-spacing diacritic marks. U+0300 -> U+036F
           *  Write a space first, for them to 'modify.'
           */
          if ( (0x0300 <= codepoint) && (codepoint <= 0x036F) ) {
            outChar = (WCHAR) 0x0020;
            TextOutW (hdc, 0,0, &outChar, 1);
          }

          outChar = (WCHAR) codepoint;
          ExtTextOut(hdc, point.x, point.y, ETO_CLIPPED, &rect, (LPCWSTR)&outChar, 1, NULL);

          /* fill in unicode code point in hex */
          if (gShowhex) {
            int nchar;
            HANDLE hfonttemp;

            nchar = wsprintf (buffer, TEXT("%04x"), (int) codepoint);
            hfonttemp = SelectObject (hdc,GetStockObject (SYSTEM_FIXED_FONT));

            point.y = rect.bottom;
            SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
            SetTextColor (hdc, PALETTEINDEX (5));

            TextOut( hdc, point.x, point.y,
                          buffer, nchar);
            SelectObject (hdc,hfonttemp);
          }

        } /* end for */

      EndPaint (hwnd, &ps);
    } return FALSE; /* end WM_PAINT */

  } /* end switch */

  return (DefMDIChildProc(hwnd, message, wParam, lParam));
}

int openDisplay ( VOID )

Definition at line 125 of file DISPLAY.C.

{
WNDCLASS  wc;
static int cxCursor, cyCursor;
HFONT hfont;

  /* Register the window class*/
  wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
  wc.lpfnWndProc = (WNDPROC)DisplayWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 12;
  wc.hInstance = hInst;
  wc.hIcon = LoadIcon(hInst, TEXT("uniputIcon"));
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = DISPLAYCLASS;

  if (!RegisterClass(&wc)) return (FALSE);

  cxCursor = GetSystemMetrics (SM_CXCURSOR);
  cyCursor = GetSystemMetrics (SM_CYCURSOR);

  /* get pointer to 0-init memory */
  pbitsAND = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/8);

  /* Create a memory DC to draw into for creating cursors. */
  hdcMemXOR = CreateCompatibleDC (NULL);
  hbmMemXOR = CreateBitmap (cxCursor,cyCursor,1,4,NULL);
  SelectObject (hdcMemXOR, hbmMemXOR);

  /* set text modes for the memory HDC */
  SetBkMode (hdcMemXOR, TRANSPARENT);
  SetTextAlign (hdcMemXOR, TA_CENTER | TA_TOP);

  /* set a unicode font into the memory DC */
  logfont.lfHeight = cyCursor  *2/3;  // HACK.. scale down Y
  logfont.lfWidth  = cxCursor  *2/3;
  hfont = CreateFontIndirect (&logfont);
  SelectObject (hdcMemXOR, hfont);

  /* get pointer to be used later as pointer to bitmap bits */
  pbitsXOR = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/2);

  /* Assume that we got a unicode font.
   *  Count the number of segments, and fill in the proper global
   *  variables specifying the code point ranges covered.
   */
  nSegments = CountUCSegments (hdcMemXOR); /* slow computation */

  /* verify that we have SOME ranges to work with */
  if (nSegments == SEGMENTERROR) return FALSE;

  /* warn the user if we can't find the right font */
  if (nSegments < 30)
    MessageBox (NULL,
        TEXT("Working with limited codepoint coverage. \n Install uclucida.ttf"),
        TEXT("Warning: Lucida Sans Unicode font not found."), MB_OK);

  FontWidth  = UCFONTWIDTH;
  FontHeight = UCFONTHEIGHT;

  return TRUE;
}

VOID SwapShort ( PUSHORT p )

Definition at line 901 of file DISPLAY.C.

{
SHORT temp;

    temp =(SHORT)( HIBYTE (*p) + (LOBYTE(*p) << 8));
    *p = temp;
}

VOID SwapULong ( PULONG p )

Definition at line 911 of file DISPLAY.C.

{
ULONG temp;

    temp = (LONG) ((BYTE) *p);
    temp <<= 8;
    *p >>=8;

    temp += (LONG) ((BYTE) *p);
    temp <<= 8;
    *p >>=8;

    temp += (LONG) ((BYTE) *p);
    temp <<= 8;
    *p >>=8;

    temp += (LONG) ((BYTE) *p);
    *p = temp;
}

int transIndextoRect | ( | int | index,
 |  | PRECT | pr,
 |  | int | sqrWidth,
 |  | int | sqrHeight,
 |  | int | nCharPerLine
 | ) |  |

Definition at line 704 of file DISPLAY.C.

{
int x,y;

    x = index % nCharPerLine;
    y = index / nCharPerLine;

    pr->left = x*sqrWidth;
    pr->top = y*sqrHeight;
    pr->right = pr->left +sqrWidth;
    pr->bottom = pr->top +sqrHeight;

    return TRUE;
}

int transXYtoIndex | ( | int | x,
 |  | int | y,
 |  | int | sqrWidth,
 |  | int | sqrHeight,
 |  | int | nCharPerLine
 | ) |  |

Definition at line 683 of file DISPLAY.C.

{
    x /= sqrWidth;
    if (x < 0) x = 0;
    if (x >= nCharPerLine) x = nCharPerLine-1;

    y /= sqrHeight;
    if (y < 0) y = 0;

    return ( (y * nCharPerLine) + x);
}

Variable Documentation

USHORT* endCount = NULL

Definition at line 57 of file DISPLAY.C.

int FontHeight

Definition at line 106 of file DISPLAY.C.

int FontWidth

Definition at line 106 of file DISPLAY.C.

HBITMAP hbmMemXOR

Definition at line 103 of file DISPLAY.C.

HDC hdcMemXOR

Definition at line 102 of file DISPLAY.C.

LOGFONT logfont
Initial value:
 {
      UCFONTHEIGHT ,
      UCFONTWIDTH ,
       0 ,
       0 ,
     400 ,
       0 ,
       0 ,
       0 ,
       UNICODE_CHARSET ,
       0 ,
       0 ,
       2 ,
       2 ,
      TEXT("Lucida Sans Unicode")}

Definition at line 82 of file DISPLAY.C.

int nSegments

Definition at line 107 of file DISPLAY.C.

PVOID pbitsAND

Definition at line 104 of file DISPLAY.C.

PVOID pbitsXOR

Definition at line 104 of file DISPLAY.C.

USHORT* startCount = NULL

Definition at line 58 of file DISPLAY.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/DISPLAY.H File Reference

  • UNIPUT
Data Structures | Defines | Typedefs | Variables

DISPLAY.H File Reference

Go to the source code of this file.

Data Structures

struct | tagLookupEntry

Defines

#define | NRANGE 24

Typedefs

typedef struct tagLookupEntry | LookupEntry

Variables

LookupEntry | RangeName [NRANGE]

Define Documentation

#define NRANGE 24

Definition at line 20 of file DISPLAY.H.

Typedef Documentation

typedef struct tagLookupEntry LookupEntry

Variable Documentation

LookupEntry RangeName[NRANGE]
Initial value:
    {{ 0x0000,0x007f, TEXT("ASCII")},
     { 0x0080,0x00ff, TEXT("Latin1 Characters")},
     { 0x0100,0x017f, TEXT("European Latin")},
     { 0x0180,0x01ff, TEXT("Extended Latin")},
     { 0x0200,0x024f, TEXT("<Bad unicode range.>")},
     { 0x0250,0x02af, TEXT("Standard Phonetic")},
     { 0x02b0,0x02ff, TEXT("Modifier Letters")},
     { 0x0300,0x036f, TEXT("Generic Diacritical Marks")},
     { 0x0370,0x03ff, TEXT("Greek")},
     { 0x0400,0x04ff, TEXT("Cyrillic")},
     { 0x0500,0x052f, TEXT("<Bad unicode range.>")},
     { 0x0530,0x058f, TEXT("Armenian")},
     { 0x0590,0x05ff, TEXT("Hebrew")},
     { 0x0600,0x06ff, TEXT("Arabic")},
     { 0x0900,0x1fff, TEXT("<not specified in table.>")},
     { 0x2000,0x206f, TEXT("General Punctutation")},
     { 0x2070,0x209f, TEXT("Superscipts & Subscripts")},
     { 0x20a0,0x20cf, TEXT("Currency Symbols")},
     { 0x20d0,0x20ff, TEXT("Diacritical Marks for Symbols")},
     { 0x2100,0x214f, TEXT("Letterlike Symbols")},
     { 0x2150,0x218f, TEXT("Number Forms")},
     { 0x2190,0x21ff, TEXT("Arrows")},
     { 0x2200,0x22ff, TEXT("Mathematical Operators")},
     { 0x2300,0xffff, TEXT("<not specified in table.>")}}

Definition at line 21 of file DISPLAY.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/STATUS.C File Reference

  • UNIPUT
Defines | Functions | Variables

STATUS.C File Reference

#include <windows.h>
#include "uniput.h"

Go to the source code of this file.

Defines

#define | MAXCHARS 255
#define | UNICODE

Functions

VOID | framechildwindow (HDC, HWND, HWND)
LRESULT CALLBACK | StatusWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

Variables

HWND | hwndStatic0
HWND | hwndStatic1
HWND | hwndStatic2
LOGFONT | logfontsmall

Define Documentation

#define MAXCHARS 255
#define UNICODE

Definition at line 19 of file STATUS.C.

Function Documentation

VOID framechildwindow | ( | HDC | hdc,
 |  | HWND | hwndParent,
 |  | HWND | hwndChild
 | ) |  |

Definition at line 257 of file STATUS.C.

{
RECT rect;

      GetWindowRect (hwndChild, &rect);

      /* minor hack... assumes RECT is two points, right field starting first */
      ScreenToClient (hwndParent, (LPPOINT)&rect);
      ScreenToClient (hwndParent, (LPPOINT)&(rect.right));

      InflateRect (&rect, 1, 1);
      FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
      InflateRect (&rect, -1, -1);
      SelectObject (hdc, GetStockObject (WHITE_PEN));
      MoveToEx (hdc, rect.right, rect.top, NULL);
      LineTo (hdc,rect.right, rect.bottom);
      LineTo (hdc,rect.left, rect.bottom);

    return;
}

LRESULT CALLBACK StatusWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 58 of file STATUS.C.

{
static HFONT hfontStatic;
RECT rect, clientrect;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Create two static child windows, and select a font for them.
    \**********************************************************************/
    case WM_CREATE: {
      GetClientRect (hwnd, &clientrect);

      hwndStatic0 = CreateWindow(
              TEXT("STATIC"),
              TEXT("Target Window"),
              WS_CHILD | WS_VISIBLE | SS_CENTER,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hwndStatic1 = CreateWindow(
              TEXT("STATIC"),
              TEXT("Unicode/Ansi"),
              WS_CHILD | WS_VISIBLE | SS_CENTER,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hwndStatic2 = CreateWindow(
              TEXT("STATIC"),
              TEXT(""),
              WS_CHILD | WS_VISIBLE | SS_RIGHT,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hfontStatic = CreateFontIndirect (&logfontsmall);
      SendMessage (hwndStatic0, WM_SETFONT, (WPARAM) hfontStatic, 0);
      SendMessage (hwndStatic1, WM_SETFONT, (WPARAM) hfontStatic, 0);
      SendMessage (hwndStatic2, WM_SETFONT, (WPARAM) hfontStatic, 0);
    } break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * free the font we created at WM_CREATE time.
    * hwndStatic* child windows are destroyed automatically.
    \**********************************************************************/
    case WM_DESTROY:
      DeleteObject (hfontStatic);
    break;

    /**********************************************************************\
    *  WM_CTLCOLORSTATIC
    \**********************************************************************/
    case WM_CTLCOLORSTATIC: {
      HDC hdc;

      hdc = (HDC) wParam;
      SetBkMode (hdc, TRANSPARENT);
      return (LRESULT)GetStockObject (LTGRAY_BRUSH);
    } break;

    /**********************************************************************\
    *  WM_SIZE
    *
    * Resize the static controls to stretch them to always fill the status
    *  bar minus some border area.
    \**********************************************************************/
    case WM_SIZE: {
      GetClientRect (hwnd, &clientrect);
      rect.top = clientrect.top + SBORDER;
      rect.bottom = clientrect.bottom - SBORDER;

      rect.left = SBORDER;
      rect.right = rect.left + SFIELD0;

      SetWindowPos (hwndStatic0, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      rect.left = 3*SBORDER + SFIELD0;
      rect.right = rect.left + SFIELD1;

      SetWindowPos (hwndStatic1, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      rect.left  = 5*SBORDER + SFIELD0 + SFIELD1;
      rect.right = clientrect.right - SBORDER;

      SetWindowPos (hwndStatic2, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      return TRUE;
    } break;

    /**********************************************************************\
    *  WMU_SETTARGETNAME
    *
    * wParam - BOOL... TRUE: hwndTarget is unicode, FALSE: ansi
    * lParam - pointer to new string.
    *
    \**********************************************************************/
    case WMU_SETTARGETNAME:

      SetWindowText (hwndStatic0,(LPCTSTR) lParam);

      if (wParam == FALSE)
        SetWindowText (hwndStatic1,TEXT ("Ansi"));
      else
        SetWindowText (hwndStatic1,TEXT ("Unicode"));

    break;

#define MAXCHARS 255

    /**********************************************************************\
    *  WMU_CHARACTER
    *
    * wParam - WCHAR value
    *
    * Display a string of characters in the second static window. This is
    *  a FIFO buffer, if we fill it, shift characters to the left, and
    *  set the string back into the static control.
    *
    \**********************************************************************/
    case WMU_CHARACTER: {
      TCHAR buffer[MAXCHARS+1];
      int nchar;
      int i;

      GetWindowText (hwndStatic2,buffer, MAXCHARS+1);
      nchar = GetWindowTextLength (hwndStatic2);

      if (nchar >= MAXCHARS) {
        nchar = MAXCHARS-1;
        for (i= 0; i<(MAXCHARS-1); i++)
          buffer[i] = buffer[i+1];
      }

      buffer[nchar] = (TCHAR) wParam;
      buffer[nchar+1] = (TCHAR) '\000';

      SetWindowText (hwndStatic2,buffer);

    } break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * Gray background is done automatically, just outline the two static
    *  text windows with 3-D effect.
    \**********************************************************************/
    case WM_PAINT: {
      HDC hdc;
      PAINTSTRUCT ps;

      hdc = BeginPaint(hwnd, &ps);

      framechildwindow (hdc,hwnd, hwndStatic0);
      framechildwindow (hdc,hwnd, hwndStatic1);
      framechildwindow (hdc,hwnd, hwndStatic2);

      EndPaint (hwnd, &ps);
    } return FALSE; /* end WM_PAINT */

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

Variable Documentation

HWND hwndStatic0

Definition at line 48 of file STATUS.C.

HWND hwndStatic1

Definition at line 48 of file STATUS.C.

HWND hwndStatic2

Definition at line 48 of file STATUS.C.

LOGFONT logfontsmall
Initial value:
 {
      UCFONTHEIGHT /2 ,
      UCFONTWIDTH /2,
       0 ,
       0 ,
     400 ,
       0 ,
       0 ,
       0 ,
       UNICODE_CHARSET ,
       0 ,
       0 ,
       2 ,
       2 ,
      TEXT("Lucida Sans Unicode")}

Definition at line 30 of file STATUS.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/UNIPUT.C File Reference

  • UNIPUT
Defines | Functions | Variables

UNIPUT.C File Reference

#include <windows.h>
#include <commdlg.h>
#include "uniput.h"

Go to the source code of this file.

Defines

#define | FWW_STEPS 40
#define | GRIDCOLOR PALETTEINDEX (6)
#define | STATUSHEIGHT (UCFONTHEIGHT/2 + 3*SBORDER)
#define | TICKSPACE 20
#define | UNICODE

Functions

LRESULT CALLBACK | About (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
HANDLE | OpenNewFile (HWND)
int APIENTRY | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

int | gShowhex
int | gShowNames
HANDLE | hFile = INVALID_HANDLE_VALUE
HANDLE | hInst
HWND | hwndClient
HWND | hwndMain
HWND | hwndStatus
TCHAR | szHelpPathName [] = TEXT("uniput.HLP")

Define Documentation

#define FWW_STEPS 40

Definition at line 25 of file UNIPUT.C.

#define GRIDCOLOR PALETTEINDEX (6)

Definition at line 23 of file UNIPUT.C.

#define STATUSHEIGHT (UCFONTHEIGHT/2 + 3*SBORDER)

Definition at line 42 of file UNIPUT.C.

#define TICKSPACE 20

Definition at line 24 of file UNIPUT.C.

#define UNICODE

Definition at line 15 of file UNIPUT.C.

Function Documentation

LRESULT CALLBACK About | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 470 of file UNIPUT.C.

{
  if ((message == WM_COMMAND) && (LOWORD(wParam) == IDOK)) {
    EndDialog (hwnd, TRUE);
    return TRUE;
  }
  if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) {
    EndDialog (hwnd, TRUE);
    return TRUE;
  }
  return FALSE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 188 of file UNIPUT.C.

{
HWND hwndActive;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    \**********************************************************************/
    case WM_CREATE: {

    }

    /**********************************************************************\
    *  WM_SIZE
    *
    * When the frame is sized, then change the size of the MDI client,
    *  excluding the status bar, and change the size and position of the
    *  status bar.
    \**********************************************************************/
    case WM_SIZE: {

      RECT r;
      GetClientRect (hwnd, &r);
      r.bottom -= STATUSHEIGHT;

      SetWindowPos (hwndClient, HWND_BOTTOM,
                    r.left, r.top, r.right, r.bottom, 0);

      /* size & position status bar: left, right, & top just out of view */
      SetWindowPos (hwndStatus, HWND_TOP,
        r.left-1, r.bottom,
        r.right+2, STATUSHEIGHT+1, 0);

      return TRUE;

    } break;

    /**********************************************************************\
    *  WMU_CHARACTER
    *
    * global variable: hFile
    *
    * user message sent to main window when user hits a glyph square.
    *  if the main window has a file open, then write this unicode
    *  character to that file.
    \**********************************************************************/
    case WMU_CHARACTER: {
        DWORD nBytes;
        WCHAR tChar;

      tChar = (WCHAR)lParam;

      /* show it on the status bar */
      SendMessage (hwndStatus, WMU_CHARACTER, 0, lParam);

      if (hFile != INVALID_HANDLE_VALUE)
        WriteFile (hFile, &tChar, sizeof(WCHAR), &nBytes, NULL);

    } break;

    /**********************************************************************\
    *  WM_COMMAND
    *
    \**********************************************************************/
    case WM_COMMAND: {

      switch (LOWORD(wParam)) {

        /******************************************************************\
        *  WM_COMMAND, IDM_NEWWINDOW
        *
        * global - hwndClient, hInst
        *
        * Simply create a new MDI child window.
        \******************************************************************/
        case IDM_NEWWINDOW: {
          HWND hwndDisplay;

          hwndDisplay = CreateMDIWindow(
              DISPLAYCLASS,
              TEXT("Display"),
              WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE |
                         WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_HSCROLL,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              hwndClient, hInst, 0);
        } break;

        /******************************************************************\
        *  WM_COMMAND, IDM_NEWFILE
        *
        * global - hFile.
        \******************************************************************/
        case IDM_NEWFILE: {
          DWORD nBytes;

          hFile = OpenNewFile (hwnd);
          /* Write the unicode byte order mark */
          WriteFile (hFile, "\xFE\xFF", 2, &nBytes, NULL);
        } break;

        /******************************************************************\
        *  WM_COMMAND, IDM_CLOSEFILE
        *
        * global - hFile.
        \******************************************************************/
        case IDM_CLOSEFILE:
          CloseHandle (hFile);
          hFile = INVALID_HANDLE_VALUE;
          SendMessage (hwndStatus, WMU_SETTARGETNAME, 0, (LPARAM)NULL);
        break;

        case IDM_HELP:
          WinHelp( hwnd, szHelpPathName, HELP_INDEX, (DWORD) NULL );
        break;

        case IDM_ABOUT:
          DialogBox (hInst, TEXT("aboutBox"), hwnd, (DLGPROC) About);
        break;

        /******************************************************************\
        *  WM_COMMAND, IDM_SHOWHEX
        *
        * Check menu on and off.  Set global value: gShowHex
        \******************************************************************/
        case IDM_SHOWHEX:
          if (GetMenuState (GetMenu (hwnd),IDM_SHOWHEX, MF_BYCOMMAND)
                == MF_CHECKED) {
            CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED);
            gShowhex = FALSE;
            RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE |RDW_ALLCHILDREN);
          } else {
            CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED);
            gShowhex = TRUE;
            RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE |RDW_ALLCHILDREN);
          }
        break;

        /******************************************************************\
        *  WM_COMMAND, IDM_SHOWNAMES
        *
        * Check menu on and off.  Set global value: gShowNames
        \******************************************************************/
        case IDM_SHOWNAMES:
          if (GetMenuState (GetMenu (hwnd),IDM_SHOWNAMES, MF_BYCOMMAND)
                == MF_CHECKED) {
            CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED);
            gShowNames = FALSE;
          } else {
            CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED);
            gShowNames = TRUE;
          }
          // PROBLEM:  Need to send message to all child windows.

          hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
          SendMessage (hwndActive, WMU_NEWRANGE, 0,0);
          InvalidateRect (hwndActive, NULL, TRUE);

        break;

        /******************************************************************\
        *  WM_COMMAND, IDM_CHAR*
        *
        * manage mutually exclusive menu indicating number of chars per line
        \******************************************************************/
        case IDM_CHAR10:
        case IDM_CHAR16:
        case IDM_CHAR20:
        case IDM_CHAR32:
        case IDM_CHAR40:
        case IDM_CHAR64:

        { HMENU hMenu;
          int nCharPerLine;

          hMenu = GetMenu (hwnd);

          CheckMenuItem(hMenu, IDM_CHAR10, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_CHAR16, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_CHAR20, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_CHAR32, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_CHAR40, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_CHAR64, MF_UNCHECKED);

          CheckMenuItem(hMenu, LOWORD(wParam), MF_CHECKED);

          /* notice the value is coded into the menu i.d. */
          nCharPerLine = LOWORD(wParam)-IDM_CHARBASE;
          hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
          SendMessage (hwndActive, WMU_SETNCHAR, nCharPerLine ,0);
          InvalidateRect (hwndActive, NULL, TRUE);

        } break;

        /******************************************************************\
        *  WM_COMMAND, IDM_FONT*
        *
        * manage mutually exclusive menu indicating font height
        \******************************************************************/
        case IDM_FONT18:
        case IDM_FONT36:
        case IDM_FONT72:

        { HMENU hMenu;
          int Width, Height;
          hMenu = GetMenu (hwnd);

          CheckMenuItem(hMenu, IDM_FONT18, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_FONT36, MF_UNCHECKED);
          CheckMenuItem(hMenu, IDM_FONT72, MF_UNCHECKED);

          CheckMenuItem(hMenu, LOWORD(wParam), MF_CHECKED);

          /* notice the value is coded into the menu i.d. */
          Height = LOWORD(wParam)-IDM_FONTBASE;
          /* scale the width proportionately */
          Width = Height * UCFONTWIDTH/UCFONTHEIGHT;

          hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
          SendMessage (hwndActive, WMU_NEWFONT, (WPARAM)Width,(LPARAM)Height);
          InvalidateRect (hwndActive, NULL, TRUE);

        } break;

        /******************************************************************\
        *  WM_COMMAND, IDM_MDI*
        *
        * misc. MDI responsibilities.  hwndClient does real work.
        \******************************************************************/
        case IDM_MDICASCADE: SendMessage (hwndClient, WM_MDICASCADE, 0,0); break;
        case IDM_MDITILE:    SendMessage (hwndClient, WM_MDITILE, MDITILE_HORIZONTAL,0); break;
        break;

      } /* end switch */
    } break;  /* end WM_COMMAND */

    /**********************************************************************\
    *  WM_DESTROY
    \**********************************************************************/
    case WM_DESTROY:
      WinHelp( hwnd, szHelpPathName, (UINT) HELP_QUIT, (DWORD) NULL );
      PostQuitMessage(0);
    break;

  } /* end switch */
  return (DefFrameProc(hwnd, hwndClient, message, wParam, lParam));
}

HANDLE OpenNewFile ( HWND hwnd )

Definition at line 496 of file UNIPUT.C.

{
   TCHAR szFile[MAX_PATH],szFileTitle[MAX_PATH];
   OPENFILENAME OpenFileName;

   wsprintf (szFile, TEXT(""));
   wsprintf (szFileTitle, TEXT(""));

   OpenFileName.lStructSize       = sizeof(OPENFILENAME);
   OpenFileName.hwndOwner         = hwnd;
   OpenFileName.hInstance         = (HANDLE) hInst;
   OpenFileName.lpstrFilter       = NULL;
   OpenFileName.lpstrCustomFilter = NULL;
   OpenFileName.nMaxCustFilter    = 0L;
   OpenFileName.nFilterIndex      = 1L;
   OpenFileName.lpstrFile         = szFile;
   OpenFileName.nMaxFile          = sizeof(szFile);
   OpenFileName.lpstrFileTitle    = szFileTitle;
   OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
   OpenFileName.lpstrInitialDir   = NULL;
   OpenFileName.lpstrTitle        = TEXT("Open a File");

   OpenFileName.nFileOffset       = 0;
   OpenFileName.nFileExtension    = 0;
   OpenFileName.lpstrDefExt       = NULL;

   OpenFileName.lCustData         = 0;

   OpenFileName.Flags = OFN_HIDEREADONLY;

   if (!GetOpenFileName(&OpenFileName)) return INVALID_HANDLE_VALUE;

   /* update status bar with the file title. */
   SendMessage (hwndStatus, WMU_SETTARGETNAME, 0, (LPARAM)OpenFileName.lpstrFileTitle);

   return (CreateFile(OpenFileName.lpstrFile,
                      GENERIC_WRITE,
                      0,
                      NULL,
                      CREATE_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL,
                      NULL));
}

int APIENTRY WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 52 of file UNIPUT.C.

{
    MSG    msg;
    CLIENTCREATESTRUCT clientcreate;
    WNDCLASS  wc;
    DWORD dwVersion;

    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER(  nCmdShow );

    /* Check to make sure we are running on Windows NT, not Win95 or Win32s */
    dwVersion = GetVersion();
    if (dwVersion & 0x80000000)
    {
        MessageBoxA(NULL,
            "This sample application can only be run on Windows NT\n"
            "This application will now terminate",
            "UniPut",
            MB_ICONSTOP | MB_OK | MB_SETFOREGROUND);
        return(1);
    }

    hInst = hInstance;

    /* Check for previous instance.  If none, then register class. */
    if (!hPrevInstance) {

      wc.style = 0;
      wc.lpfnWndProc = (WNDPROC)MainWndProc;

      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(hInstance, TEXT("uniputIcon"));
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = NULL;
      wc.lpszMenuName =  TEXT("uniputMenu");
      wc.lpszClassName = TEXT("uniput");

      if (!RegisterClass(&wc)) return (FALSE);

    }  /* class registered o.k. */

    /* Create the main window.  Return false if CreateWindow() fails */
    hwndMain = CreateWindow(
        TEXT("uniput"),
        TEXT("Input unicode characters"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL, NULL, hInst, NULL);

    if (!hwndMain) return (FALSE);

    /* create the MDI "client" window. */
    clientcreate.hWindowMenu  = GetSubMenu(GetMenu(hwndMain),1);
    clientcreate.idFirstChild = 1;
    hwndClient = CreateWindow(
        TEXT("MDICLIENT"),
        NULL,
        WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
        0,0,0,0,
        hwndMain, NULL, hInst, (LPVOID)&clientcreate);
    if (!hwndClient) return (FALSE);

    /* create status bar */
    wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
    wc.lpfnWndProc = (WNDPROC)StatusWndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInst;
    wc.hIcon = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject (LTGRAY_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = TEXT("status");
    if (!RegisterClass(&wc)) return (FALSE);

    hwndStatus = CreateWindow(
        TEXT("status"),
        TEXT("status"),
        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_BORDER,
        0,0,
        GetSystemMetrics(SM_CXFULLSCREEN),
        STATUSHEIGHT,
        hwndMain, NULL, hInst, 0);
    if (!hwndStatus) return (FALSE);

    ShowWindow(hwndMain, SW_SHOWDEFAULT);
    SetCursor (LoadCursor (NULL, IDC_WAIT));

    /* Register display window class, and do class initialization. */
    if (!openDisplay()) return (FALSE);

    /* set the menus to be correct */
    SendMessage (hwndMain, WM_COMMAND, IDM_SHOWHEX,0);
    SendMessage (hwndMain, WM_COMMAND, IDM_SHOWNAMES,0);

    /* Create one MDI child window to get started */
    SendMessage (hwndMain, WM_COMMAND, IDM_NEWWINDOW, 0);

    SetCursor (LoadCursor (NULL, IDC_ARROW));

    /* Loop getting messages and dispatching them. */
    while (GetMessage(&msg,NULL, 0,0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    closeDisplay();
    return (msg.wParam);
}

Variable Documentation

int gShowhex

Definition at line 40 of file UNIPUT.C.

int gShowNames

Definition at line 40 of file UNIPUT.C.

HANDLE hFile = INVALID_HANDLE_VALUE

Definition at line 28 of file UNIPUT.C.

HANDLE hInst

Definition at line 35 of file UNIPUT.C.

HWND hwndClient

Definition at line 37 of file UNIPUT.C.

HWND hwndMain

Definition at line 36 of file UNIPUT.C.

HWND hwndStatus

Definition at line 38 of file UNIPUT.C.

TCHAR szHelpPathName[] = TEXT("uniput.HLP")

Definition at line 33 of file UNIPUT.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/UNIPUT.H File Reference

  • UNIPUT
Defines | Functions | Variables

UNIPUT.H File Reference

Go to the source code of this file.

Defines

#define | DISPLAYCLASS TEXT("DisplayClass")
#define | IDM_ABOUT 4002
#define | IDM_CHAR10 2410
#define | IDM_CHAR16 2416
#define | IDM_CHAR20 2420
#define | IDM_CHAR32 2432
#define | IDM_CHAR40 2440
#define | IDM_CHAR64 2464
#define | IDM_CHARBASE 2400
#define | IDM_CLOSEFILE 3003
#define | IDM_FONT18 2518
#define | IDM_FONT36 2536
#define | IDM_FONT72 2572
#define | IDM_FONTBASE 2500
#define | IDM_HELP 4001
#define | IDM_MDICASCADE 1001
#define | IDM_MDITILE 1002
#define | IDM_NEWFILE 3002
#define | IDM_NEWWINDOW 3001
#define | IDM_SHOWHEX 2000
#define | IDM_SHOWNAMES 2001
#define | MBERROR TEXT("Application Error.")
#define | MBERRORFLAGS MB_OK | MB_ICONHAND
#define | MBGETFONTDATAERR TEXT("Not a scalable font.")
#define | SBORDER 6
#define | SFIELD0 160
#define | SFIELD1 80
#define | UCFONTHEIGHT 36
#define | UCFONTWIDTH 16
#define | UNICODE_CHARSET 1
#define | WMU_CHARACTER WM_USER+0x1005
#define | WMU_NEWFONT WM_USER+0x1002
#define | WMU_NEWRANGE WM_USER+0x1001
#define | WMU_SETNCHAR WM_USER+0x1004
#define | WMU_SETTARGETNAME WM_USER+0x1003

Functions

LRESULT CALLBACK | About (HWND, UINT, WPARAM, LPARAM)
int | closeDisplay (VOID)
LRESULT CALLBACK | DisplayWndProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
int | openDisplay (VOID)
LRESULT CALLBACK | StatusWndProc (HWND, UINT, WPARAM, LPARAM)

Variables

int | gShowhex
int | gShowNames
HANDLE | hInst
HWND | hwndClient
HWND | hwndMain
HWND | hwndStatic0
HWND | hwndStatic1
HWND | hwndStatus

Define Documentation

#define DISPLAYCLASS TEXT("DisplayClass")

Definition at line 24 of file UNIPUT.H.

#define IDM_ABOUT 4002

Definition at line 62 of file UNIPUT.H.

#define IDM_CHAR10 2410

Definition at line 44 of file UNIPUT.H.

#define IDM_CHAR16 2416

Definition at line 45 of file UNIPUT.H.

#define IDM_CHAR20 2420

Definition at line 46 of file UNIPUT.H.

#define IDM_CHAR32 2432

Definition at line 47 of file UNIPUT.H.

#define IDM_CHAR40 2440

Definition at line 48 of file UNIPUT.H.

#define IDM_CHAR64 2464

Definition at line 49 of file UNIPUT.H.

#define IDM_CHARBASE 2400

Definition at line 43 of file UNIPUT.H.

#define IDM_CLOSEFILE 3003

Definition at line 59 of file UNIPUT.H.

#define IDM_FONT18 2518

Definition at line 52 of file UNIPUT.H.

#define IDM_FONT36 2536

Definition at line 53 of file UNIPUT.H.

#define IDM_FONT72 2572

Definition at line 54 of file UNIPUT.H.

#define IDM_FONTBASE 2500

Definition at line 51 of file UNIPUT.H.

#define IDM_HELP 4001

Definition at line 61 of file UNIPUT.H.

#define IDM_MDICASCADE 1001

Definition at line 37 of file UNIPUT.H.

#define IDM_MDITILE 1002

Definition at line 38 of file UNIPUT.H.

#define IDM_NEWFILE 3002

Definition at line 58 of file UNIPUT.H.

#define IDM_NEWWINDOW 3001

Definition at line 57 of file UNIPUT.H.

#define IDM_SHOWHEX 2000

Definition at line 40 of file UNIPUT.H.

#define IDM_SHOWNAMES 2001

Definition at line 41 of file UNIPUT.H.

#define MBERROR TEXT("Application Error.")

Definition at line 75 of file UNIPUT.H.

#define MBERRORFLAGS MB_OK | MB_ICONHAND

Definition at line 76 of file UNIPUT.H.

#define MBGETFONTDATAERR TEXT("Not a scalable font.")

Definition at line 74 of file UNIPUT.H.

#define SBORDER 6

Definition at line 84 of file UNIPUT.H.

#define SFIELD0 160

Definition at line 85 of file UNIPUT.H.

#define SFIELD1 80

Definition at line 86 of file UNIPUT.H.

#define UCFONTHEIGHT 36

Definition at line 80 of file UNIPUT.H.

#define UCFONTWIDTH 16

Definition at line 81 of file UNIPUT.H.

#define UNICODE_CHARSET 1

Definition at line 33 of file UNIPUT.H.

#define WMU_CHARACTER WM_USER+0x1005

Definition at line 70 of file UNIPUT.H.

#define WMU_NEWFONT WM_USER+0x1002

Definition at line 67 of file UNIPUT.H.

#define WMU_NEWRANGE WM_USER+0x1001

Definition at line 66 of file UNIPUT.H.

#define WMU_SETNCHAR WM_USER+0x1004

Definition at line 69 of file UNIPUT.H.

#define WMU_SETTARGETNAME WM_USER+0x1003

Definition at line 68 of file UNIPUT.H.

Function Documentation

LRESULT CALLBACK About | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 497 of file BOB.C.

{
    switch (message) {
        case WM_INITDIALOG:           /* message: initialize dialog box */
            return (TRUE);

        case WM_COMMAND:                      /* message: received a command */
            if (wParam == IDOK                /* "OK" box selected?          */
                || wParam == IDCANCEL) {      /* System menu close command?  */
                EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
                return (TRUE);
            }
            break;
    }
    return (FALSE);                           /* Didn't process a message    */
UNREFERENCED_PARAMETER(lParam);
}

int closeDisplay ( VOID )

Definition at line 205 of file DISPLAY.C.

{
HFONT hfont;

  hfont = SelectObject  (hdcMemXOR, GetStockObject(SYSTEM_FONT));
  DeleteObject (hfont);
  DeleteDC (hdcMemXOR);
  DeleteObject (hbmMemXOR);

  LocalFree (LocalHandle (pbitsXOR));
  LocalFree (LocalHandle (pbitsAND));

  if (startCount != NULL) LocalFree (LocalHandle (startCount));
  if (endCount != NULL) LocalFree (LocalHandle (endCount));

  return TRUE;
}

LRESULT CALLBACK DisplayWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 231 of file DISPLAY.C.

{
static HFONT  hfont, hfontOld;

static HDC hdc;
static RECT rect;
static int iSeg;
static TCHAR buffer[100];

/* rDown and index used as the user points to a square. */
static RECT rDown;
static int index;

static WCHAR DragDropChar;
static HICON hIcon;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Set up the LOGFONT in the HDC for this window.
    \**********************************************************************/
    case WM_CREATE:
      SendMessage (hwnd, WMU_SETNCHAR, 16, 0);
      SendMessage (hwnd, WMU_NEWFONT, FontWidth, FontHeight);
    break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * Get rid of the logical font we create for each display window.
    *  relying here on CS_ONWDC
    \**********************************************************************/
    case WM_DESTROY:
      hdc = GetDC (hwnd);
      hfont = SelectObject  (hdc, GetStockObject(SYSTEM_FONT));
      DeleteObject (hfont);
      ReleaseDC (hwnd, hdc);
    break;

    /**********************************************************************\
    *  WMU_SETNCHAR
    *
    * wParam - nCharPerLine
    *
    \**********************************************************************/
    case WMU_SETNCHAR:
      SetWindowLong (hwnd, GWLU_NCHAR, (int) wParam);
      InvalidateRect (hwnd, NULL, TRUE);
    break;

    /**********************************************************************\
    *  WMU_NEWFONT
    *
    * wParam - Width
    * lParam - Height
    *
    * Create font, select it into the HDC, and reset ranges.
    \**********************************************************************/
    case WMU_NEWFONT: {

      hdc = GetDC(hwnd);

      FontWidth  = (int) wParam;
      FontHeight = (int) lParam;
      logfont.lfHeight = FontHeight;
      logfont.lfWidth  = FontWidth;

      hfont = CreateFontIndirect (&logfont);
      hfontOld = SelectObject (hdc, hfont);
      DeleteObject (hfontOld);

      ReleaseDC (hwnd, hdc);

      SetScrollRange (hwnd, SB_HORZ, 0, (nSegments-1), TRUE);
      SetScrollPos (hwnd, SB_HORZ, 0, TRUE);

      SendMessage (hwnd, WMU_NEWRANGE, 0,0);

    } return TRUE;

    /**********************************************************************\
    *  WMU_NEWRANGE
    *
    *
    * Range changes, or font size changes, or title status changes.
    \**********************************************************************/
    case WMU_NEWRANGE: {
      int sqrHeight, sqrWidth;
      TEXTMETRIC tm;
      int i;

      hdc = GetDC(hwnd);
      GetTextMetrics (hdc, &tm);
      ReleaseDC (hwnd, hdc);

      /* index into the start, end arrays stored in scroll bar */
      iSeg = GetScrollPos (hwnd, SB_HORZ);

      /* Set the window title text to show display range. */
      wsprintf (buffer, TEXT("[%04x, %04x]"),
                                  (int)startCount[iSeg],
                                  (int)endCount[iSeg]);

      /* if we are supposed to look up the character range name,
       *  then step through the ranges stored in the RangeName
       *  table.  Find the correct one, and reset the buffer string.
       */
      if (gShowNames) {
        for (i = 0; i< NRANGE; i++) {
          if ((RangeName[i].start <= startCount[iSeg]) &&
              ( startCount[iSeg] <= RangeName[i].end))

            wsprintf (buffer, TEXT("%s [%04x, %04x]"),
                                  RangeName[i].String,
                                  (int)startCount[iSeg],
                                  (int)endCount[iSeg]);

        }
      }
      SetWindowText (hwnd, buffer);

      sqrHeight =  tm.tmHeight + tm.tmExternalLeading;
      sqrWidth = tm.tmMaxCharWidth;

      SetWindowLong (hwnd, GWLU_SQRHEIGHT,sqrHeight);
      SetWindowLong (hwnd, GWLU_SQRWIDTH, sqrWidth );

    } return TRUE;

    /**********************************************************************\
    *  WM_LBUTTONDOWN
    *
    * Static, shared variables set in WM_LBUTTONDOWN:
    *   rDown, hIcon, DragDropChar
    *
    \**********************************************************************/
    case WM_LBUTTONDOWN: {
      int x,y;
      int nCharPerLine;
      int sqrHeight, sqrWidth;
      nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
      sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
      sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );

      x = (int)LOWORD (lParam);
      y = (int)HIWORD (lParam);

      index = transXYtoIndex (x,y, sqrWidth, sqrHeight, nCharPerLine);

      /* verify that the index is within the shown segment range */
      iSeg= GetScrollPos (hwnd, SB_HORZ);
      if (index > (endCount[iSeg]- startCount[iSeg])) return 0;

      DragDropChar = index + startCount[iSeg];

      transIndextoRect (index, &rDown, sqrWidth, sqrHeight, nCharPerLine);

      hdc = GetDC (hwnd);
      InvertRect (hdc, &rDown);
      ReleaseDC (hwnd, hdc);

      /* Create a cursor which represents the character.
       * Global variables used:
       *   HDC hdcMemXOR;
       *   HBITMAP hbmMemXOR;
       *   PVOID pbitsXOR, pbitsAND;
       */
      {
      int cxCursor, cyCursor;
      RECT rect;

      cxCursor = GetSystemMetrics (SM_CXCURSOR);
      cyCursor = GetSystemMetrics (SM_CYCURSOR);

      rect.left = rect.top = 0;
      rect.right = cxCursor; rect.bottom = cyCursor;

      FrameRect (hdcMemXOR, &rect, GetStockObject (BLACK_BRUSH));
      InflateRect (&rect, -1, -1);
      FillRect (hdcMemXOR, &rect, GetStockObject (LTGRAY_BRUSH));
      FrameRect (hdcMemXOR, &rect, GetStockObject (GRAY_BRUSH));
      InflateRect (&rect, -1, -1);
      SelectObject (hdcMemXOR, GetStockObject (WHITE_PEN));
      MoveToEx (hdcMemXOR, rect.right, rect.top, NULL);
      LineTo (hdcMemXOR,rect.left, rect.top);
      LineTo (hdcMemXOR,rect.left, rect.bottom);

      ExtTextOut(hdcMemXOR, cxCursor/2,0, ETO_CLIPPED, &rect,
                   (LPCWSTR)&DragDropChar, 1, NULL);

      GetBitmapBits (hbmMemXOR, cxCursor*cyCursor/2, pbitsXOR);

      hIcon = CreateIcon( GetModuleHandle(NULL),
              cxCursor,cyCursor, 1,4,
              pbitsAND,
              pbitsXOR);

      SetCursor ((HCURSOR)hIcon);
      }

      GdiFlush ();
      SetCapture (hwnd);
    } break;

    /**********************************************************************\
    *  WM_LBUTTONUP
    *
    * Static, shared variables set in WM_LBUTTONDOWN:
    *   rDown, hIcon, DragDropChar
    *
    \**********************************************************************/
    case WM_LBUTTONUP: {
      POINT p;
      HWND hwndTarget, hwndTitle;
#define NUMCHARS  255
      TCHAR buffer[NUMCHARS];

      if (GetCapture() == hwnd) {

        p.x = (int)(short)LOWORD (lParam);
        p.y = (int)(short)HIWORD (lParam);

        ClientToScreen (hwnd, &p);
        hwndTarget = WindowFromPoint (p);

        if ((GetWindowThreadProcessId (hwnd, NULL)) !=
            (GetWindowThreadProcessId (hwndTarget, NULL))) {

          /* hack.  unipad has a client window which gets the chars,
           *  but we want to display the frame windows text (title bar),
           *  so try to get the parent of the target for Title purposes.
           */
          hwndTitle = (GetParent(hwndTarget)) ? GetParent(hwndTarget) : hwndTarget;
          GetWindowText (hwndTitle, buffer, NUMCHARS);

          SendMessage (hwndTarget, WM_CHAR, (WPARAM) DragDropChar, 0);
          SendMessage (hwndStatus, WMU_CHARACTER,
                         (WPARAM) DragDropChar, (LPARAM)hwndTarget);
          SendMessage (hwndStatus, WMU_SETTARGETNAME,
                         (WPARAM) IsWindowUnicode (hwndTarget), (LPARAM)buffer);
        } /* end different process */

        Beep (40,40);

        hdc = GetDC (hwnd);
        InvertRect (hdc, &rDown);
        ReleaseDC (hwnd, hdc);
        GdiFlush ();
        ReleaseCapture ();
        SetCursor ((HCURSOR)LoadCursor (NULL, IDC_ARROW));
        DestroyIcon (hIcon);
      }
    } break;

    /**********************************************************************\
    *  WM_HSCROLL
    *
    * Step through the character ranges.
    * In every case, inform the window the range has changed,
    *  and invalidate it to force a repaint.
    \**********************************************************************/
    case WM_HSCROLL:

      switch (LOWORD(wParam)){
        int OldPos, NewPos;

        case SB_PAGEDOWN:
        case SB_LINEDOWN:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          SetScrollPos (hwnd, SB_HORZ, (OldPos+1), TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

        case SB_PAGEUP:
        case SB_LINEUP:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          SetScrollPos (hwnd, SB_HORZ, (OldPos-1), TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

        case SB_THUMBPOSITION:
          OldPos = GetScrollPos (hwnd, SB_HORZ);
          NewPos = HIWORD (wParam);
          SetScrollPos (hwnd, SB_HORZ, NewPos, TRUE);
          SendMessage (hwnd,WMU_NEWRANGE, 0,0);
          InvalidateRect (hwnd, NULL, TRUE);
        break;

      }

    break;

    /**********************************************************************\
    *  WM_SIZE
    *
    \**********************************************************************/
    case WM_SIZE:
      /* make sure that scroll metrics are ok */
      SendMessage (hwnd, WMU_NEWRANGE, 0,0);

    break;  /* fall through to MDIChildProc */

    /**********************************************************************\
    *  WM_PAINT
    *
    \**********************************************************************/
    case WM_PAINT: {
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;
      POINT  point;
      int i;
      USHORT start, end;
      WCHAR outChar;
      USHORT codepoint;
      int nCharPerLine;
      int sqrHeight, sqrWidth;
      nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
      sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
      sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );

      hdc = BeginPaint(hwnd, &ps);
      SetBkMode (hdc, TRANSPARENT);

      iSeg= GetScrollPos (hwnd, SB_HORZ);
      start = startCount[iSeg];
      end = endCount[iSeg];

      /* ensure that we are in a valid range... some fonts have problems */
      if (start != 0xffff)

        for (codepoint = start, i=0; codepoint<=end; codepoint++,i++) {

          /* paint box and frame it */
          transIndextoRect (i, &rect, sqrWidth, sqrHeight, nCharPerLine);
          InflateRect (&rect, -1, -1);
          FillRect (hdc, &rect, GetStockObject (LTGRAY_BRUSH));
          InflateRect (&rect, 1, 1);
          FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
          InflateRect (&rect, -1, -1);
          SelectObject (hdc, GetStockObject (WHITE_PEN));
          MoveToEx (hdc, rect.right, rect.top, NULL);
          LineTo (hdc,rect.left, rect.top);
          LineTo (hdc,rect.left, rect.bottom);

          /* set point that we will draw glyph at */
          point.x = (rect.right + rect.left)/2;
          point.y = rect.top;
          SetTextAlign (hdc, TA_CENTER | TA_TOP);
          SetTextColor (hdc, PALETTEINDEX (0));

          /* special case the non-spacing diacritic marks. U+0300 -> U+036F
           *  Write a space first, for them to 'modify.'
           */
          if ( (0x0300 <= codepoint) && (codepoint <= 0x036F) ) {
            outChar = (WCHAR) 0x0020;
            TextOutW (hdc, 0,0, &outChar, 1);
          }

          outChar = (WCHAR) codepoint;
          ExtTextOut(hdc, point.x, point.y, ETO_CLIPPED, &rect, (LPCWSTR)&outChar, 1, NULL);

          /* fill in unicode code point in hex */
          if (gShowhex) {
            int nchar;
            HANDLE hfonttemp;

            nchar = wsprintf (buffer, TEXT("%04x"), (int) codepoint);
            hfonttemp = SelectObject (hdc,GetStockObject (SYSTEM_FIXED_FONT));

            point.y = rect.bottom;
            SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
            SetTextColor (hdc, PALETTEINDEX (5));

            TextOut( hdc, point.x, point.y,
                          buffer, nchar);
            SelectObject (hdc,hfonttemp);
          }

        } /* end for */

      EndPaint (hwnd, &ps);
    } return FALSE; /* end WM_PAINT */

  } /* end switch */

  return (DefMDIChildProc(hwnd, message, wParam, lParam));
}

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 234 of file BOB.C.

{
    DLGPROC lpProcAbout;
    CHAR buffer[80];

    HANDLE hToken;
    TOKEN_PRIVILEGES tkp;

    static CONTROLTEXT CtlText;
    static TCHAR szTitle[10];
    static RECT  FocusRect, SelectRect;

    switch (message) {

        case WM_CREATE: {

            HWND hWndButton;
            CREATESTRUCT createStruct;
            RECT rcClient;

            int   cbTitle;
            SIZE  size;
            HDC    hDC;
            int    nSpaceWidth, nSpaceHeight;

            createStruct = *(LPCREATESTRUCT)lParam;
            GetClientRect( hWnd,&rcClient );

            hWndButton = CreateWindow(
                "BUTTON",                  /* See RegisterClass() call.       */
                TEXT("B. O. B."),          /* Text for window title bar.      */
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
                rcClient.left,
                rcClient.top,
                rcClient.right,
                rcClient.bottom,
                hWnd,                      /* Parent                          */
                (HMENU)BOB,                /* Child ID                        */
                createStruct.hInstance,    /* This instance owns this window. */
                NULL                       /* Pointer to Createion Parameters */
            );

            wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
                      hWndButton, hWnd );
            OutputDebugString ( buffer );

            if ( !hWndButton ) {
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            SetFocus( hWndButton );

            OldButtonProc = SubclassWindow( hWndButton, ButtonProc );

            // define size of dashed rectangles around text in both bitmaps
            hDC = GetDC( hWndButton );
            cbTitle = SendMessage( hWndButton,
                                   WM_GETTEXT,
                                   (WPARAM) sizeof(szTitle),
                                   (LPARAM)(LPTSTR)szTitle );
            GetTextExtentPoint( hDC,
                                szTitle,
                                cbTitle,
                                &size );
            ReleaseDC( hWndButton, hDC);

            CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
            CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
            CtlText.szTitle = szTitle;
            CtlText.cbTitle = cbTitle;

            // load bitmap

            CtlText.hDefaultButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE( DEFAULTBUTTON )
            );

            if ( !CtlText.hDefaultButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            CtlText.hSelectButton = LoadBitmap(
                createStruct.hInstance,    /* This instance owns this window. */
                MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
            );

            if ( !CtlText.hSelectButton ) {
                wsprintf( buffer, "Error loading BUTTONBITMAP %d",
                          GetLastError() );
                MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
                SendMessage( hWnd, WM_DESTROY, 0, 0 );
            }

            nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
            nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;

            FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
            FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
            FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
            FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);

            SelectRect.top    = 2 + FocusRect.top;
            SelectRect.bottom = 2 + FocusRect.bottom;
            SelectRect.left   = 2 + FocusRect.left;
            SelectRect.right  = 2 + FocusRect.right;

            return ( TRUE );
        }

    case WM_DRAWITEM:
    {
        LPDRAWITEMSTRUCT  lpdisCtrl;

        if ( (int)wParam == BOB ) {
            lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
            switch (lpdisCtrl->itemAction)
            {
                // handle normal drawing of button, but check if its
                // selected or focus

                case ODA_DRAWENTIRE:
                    OutputDebugString(
                        "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");

                    // this handles both button down and button up
                    HandleSelectedState(lpdisCtrl, &CtlText);

                    // this handles focus rectangle around Button text
                    HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                    return TRUE;

                    // handle drawing selection if needed
                    //   selected is button down, not selected is button up
                    //   focus will occur when button is pressed.

                    case ODA_SELECT:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_SELECT\r\n");
                        HandleSelectedState(lpdisCtrl, &CtlText);
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;

                    // handle focus drawing if needed
                    case ODA_FOCUS:
                        OutputDebugString(
                            "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
                        HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
                        return TRUE;
                }
            }
            break;
        }

        case WM_COMMAND:       /* message: command from application menu */

            if ( HIWORD(wParam) == BN_CLICKED &&
                 LOWORD(wParam) == BOB ) {
                /*
                 * Below are the steps needed to reboot the machine.
                 */
                lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
#if defined(REBOOT)
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#else
                DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
#endif

                /* Get a token for this process. */

                if ( !(GetVersion() & WIN32S) )
                {
                    OutputDebugString("Setting token");
                    // Running on NT so need to change privileges

                    if (!OpenProcessToken(GetCurrentProcess(),
                                          TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                                          &hToken))
                    {
                        wsprintf ( buffer, "OpenProcessToken Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }

                    /* Get the LUID for shutdown privilege */

                    LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
                                         &tkp.Privileges[0].Luid);

                    tkp.PrivilegeCount = 1;  /* one privilege to set    */
                    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

                    /* Get shutdown privilege for this process. */
                    if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
                                               (PTOKEN_PRIVILEGES)NULL, 0)) {
                        wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
                                   GetLastError ());
                        MessageBox(hWnd, buffer, NULL, MB_OK);
                    }
                }

#if defined(REBOOT)
                /* Shut down the system, and reboot the system. */

                if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#else
                /* Shut down the system, and force all applications closed. */

                if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
                    wsprintf ( buffer, "Error ExitWindows Error #%d",
                               GetLastError ());
                    MessageBox(hWnd, buffer, NULL, MB_OK);
                }
#endif
                break;
        }
        else                /* Lets Windows process it       */
            return (DefWindowProc(hWnd, message, wParam, lParam));

    case WM_DESTROY:          /* message: window being destroyed */
        DeleteObject(CtlText.hDefaultButton);
        DeleteObject(CtlText.hSelectButton);
        PostQuitMessage(0);
        break;

    default:              /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return ( 0 );
}

int openDisplay ( VOID )

Definition at line 125 of file DISPLAY.C.

{
WNDCLASS  wc;
static int cxCursor, cyCursor;
HFONT hfont;

  /* Register the window class*/
  wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
  wc.lpfnWndProc = (WNDPROC)DisplayWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 12;
  wc.hInstance = hInst;
  wc.hIcon = LoadIcon(hInst, TEXT("uniputIcon"));
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = DISPLAYCLASS;

  if (!RegisterClass(&wc)) return (FALSE);

  cxCursor = GetSystemMetrics (SM_CXCURSOR);
  cyCursor = GetSystemMetrics (SM_CYCURSOR);

  /* get pointer to 0-init memory */
  pbitsAND = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/8);

  /* Create a memory DC to draw into for creating cursors. */
  hdcMemXOR = CreateCompatibleDC (NULL);
  hbmMemXOR = CreateBitmap (cxCursor,cyCursor,1,4,NULL);
  SelectObject (hdcMemXOR, hbmMemXOR);

  /* set text modes for the memory HDC */
  SetBkMode (hdcMemXOR, TRANSPARENT);
  SetTextAlign (hdcMemXOR, TA_CENTER | TA_TOP);

  /* set a unicode font into the memory DC */
  logfont.lfHeight = cyCursor  *2/3;  // HACK.. scale down Y
  logfont.lfWidth  = cxCursor  *2/3;
  hfont = CreateFontIndirect (&logfont);
  SelectObject (hdcMemXOR, hfont);

  /* get pointer to be used later as pointer to bitmap bits */
  pbitsXOR = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/2);

  /* Assume that we got a unicode font.
   *  Count the number of segments, and fill in the proper global
   *  variables specifying the code point ranges covered.
   */
  nSegments = CountUCSegments (hdcMemXOR); /* slow computation */

  /* verify that we have SOME ranges to work with */
  if (nSegments == SEGMENTERROR) return FALSE;

  /* warn the user if we can't find the right font */
  if (nSegments < 30)
    MessageBox (NULL,
        TEXT("Working with limited codepoint coverage. \n Install uclucida.ttf"),
        TEXT("Warning: Lucida Sans Unicode font not found."), MB_OK);

  FontWidth  = UCFONTWIDTH;
  FontHeight = UCFONTHEIGHT;

  return TRUE;
}

LRESULT CALLBACK StatusWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | WPARAM | ,
 |  | LPARAM |
 | ) |  |

Definition at line 58 of file STATUS.C.

{
static HFONT hfontStatic;
RECT rect, clientrect;

  switch (message) {

    /**********************************************************************\
    *  WM_CREATE
    *
    * Create two static child windows, and select a font for them.
    \**********************************************************************/
    case WM_CREATE: {
      GetClientRect (hwnd, &clientrect);

      hwndStatic0 = CreateWindow(
              TEXT("STATIC"),
              TEXT("Target Window"),
              WS_CHILD | WS_VISIBLE | SS_CENTER,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hwndStatic1 = CreateWindow(
              TEXT("STATIC"),
              TEXT("Unicode/Ansi"),
              WS_CHILD | WS_VISIBLE | SS_CENTER,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hwndStatic2 = CreateWindow(
              TEXT("STATIC"),
              TEXT(""),
              WS_CHILD | WS_VISIBLE | SS_RIGHT,
              0,0,0,0,
              hwnd, NULL, hInst, 0);

      hfontStatic = CreateFontIndirect (&logfontsmall);
      SendMessage (hwndStatic0, WM_SETFONT, (WPARAM) hfontStatic, 0);
      SendMessage (hwndStatic1, WM_SETFONT, (WPARAM) hfontStatic, 0);
      SendMessage (hwndStatic2, WM_SETFONT, (WPARAM) hfontStatic, 0);
    } break;

    /**********************************************************************\
    *  WM_DESTROY
    *
    * free the font we created at WM_CREATE time.
    * hwndStatic* child windows are destroyed automatically.
    \**********************************************************************/
    case WM_DESTROY:
      DeleteObject (hfontStatic);
    break;

    /**********************************************************************\
    *  WM_CTLCOLORSTATIC
    \**********************************************************************/
    case WM_CTLCOLORSTATIC: {
      HDC hdc;

      hdc = (HDC) wParam;
      SetBkMode (hdc, TRANSPARENT);
      return (LRESULT)GetStockObject (LTGRAY_BRUSH);
    } break;

    /**********************************************************************\
    *  WM_SIZE
    *
    * Resize the static controls to stretch them to always fill the status
    *  bar minus some border area.
    \**********************************************************************/
    case WM_SIZE: {
      GetClientRect (hwnd, &clientrect);
      rect.top = clientrect.top + SBORDER;
      rect.bottom = clientrect.bottom - SBORDER;

      rect.left = SBORDER;
      rect.right = rect.left + SFIELD0;

      SetWindowPos (hwndStatic0, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      rect.left = 3*SBORDER + SFIELD0;
      rect.right = rect.left + SFIELD1;

      SetWindowPos (hwndStatic1, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      rect.left  = 5*SBORDER + SFIELD0 + SFIELD1;
      rect.right = clientrect.right - SBORDER;

      SetWindowPos (hwndStatic2, HWND_TOP,
        rect.left,
        rect.top,
        rect.right - rect.left,
        rect.bottom - rect.top, 0);

      return TRUE;
    } break;

    /**********************************************************************\
    *  WMU_SETTARGETNAME
    *
    * wParam - BOOL... TRUE: hwndTarget is unicode, FALSE: ansi
    * lParam - pointer to new string.
    *
    \**********************************************************************/
    case WMU_SETTARGETNAME:

      SetWindowText (hwndStatic0,(LPCTSTR) lParam);

      if (wParam == FALSE)
        SetWindowText (hwndStatic1,TEXT ("Ansi"));
      else
        SetWindowText (hwndStatic1,TEXT ("Unicode"));

    break;

#define MAXCHARS 255

    /**********************************************************************\
    *  WMU_CHARACTER
    *
    * wParam - WCHAR value
    *
    * Display a string of characters in the second static window. This is
    *  a FIFO buffer, if we fill it, shift characters to the left, and
    *  set the string back into the static control.
    *
    \**********************************************************************/
    case WMU_CHARACTER: {
      TCHAR buffer[MAXCHARS+1];
      int nchar;
      int i;

      GetWindowText (hwndStatic2,buffer, MAXCHARS+1);
      nchar = GetWindowTextLength (hwndStatic2);

      if (nchar >= MAXCHARS) {
        nchar = MAXCHARS-1;
        for (i= 0; i<(MAXCHARS-1); i++)
          buffer[i] = buffer[i+1];
      }

      buffer[nchar] = (TCHAR) wParam;
      buffer[nchar+1] = (TCHAR) '\000';

      SetWindowText (hwndStatic2,buffer);

    } break;

    /**********************************************************************\
    *  WM_PAINT
    *
    * Gray background is done automatically, just outline the two static
    *  text windows with 3-D effect.
    \**********************************************************************/
    case WM_PAINT: {
      HDC hdc;
      PAINTSTRUCT ps;

      hdc = BeginPaint(hwnd, &ps);

      framechildwindow (hdc,hwnd, hwndStatic0);
      framechildwindow (hdc,hwnd, hwndStatic1);
      framechildwindow (hdc,hwnd, hwndStatic2);

      EndPaint (hwnd, &ps);
    } return FALSE; /* end WM_PAINT */

  } /* end switch */
  return (DefWindowProc(hwnd, message, wParam, lParam));
}

Variable Documentation

int gShowhex

Definition at line 40 of file UNIPUT.C.

int gShowNames

Definition at line 40 of file UNIPUT.C.

HANDLE hInst

Definition at line 32 of file CLIPTEXT.C.

HWND hwndClient

Definition at line 37 of file UNIPUT.C.

HWND hwndMain

Definition at line 29 of file HOOKTEST.C.

HWND hwndStatic0

Definition at line 48 of file STATUS.C.

HWND hwndStatic1

Definition at line 48 of file STATUS.C.

HWND hwndStatus

Definition at line 38 of file UNIPUT.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: VIRTMEM/VIRTMEM.C File Reference

  • VIRTMEM
Defines | Functions | Variables

VIRTMEM.C File Reference

#include <windows.h>
#include <excpt.h>
#include <stdio.h>
#include <stdlib.h>
#include "virtmem.h"

Go to the source code of this file.

Defines

#define | IMPLEMENTED
#define | WERR(who, where)

Functions

LRESULT CALLBACK | MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
VOID | ResetMenu (VOID)
BOOL CALLBACK | ShowDlgProc (HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

Variables

CHAR * | base
CHAR | Buf [80]
CHAR | Buf2 [80]
HANDLE | hInst
HANDLE | hWnd
MEMORY_BASIC_INFORMATION | MemInfo
CHAR * | page

Define Documentation

#define IMPLEMENTED

Definition at line 74 of file VIRTMEM.C.

#define WERR | ( | who,
 |  | where
 | ) |
Value:
{sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
                            sprintf(Buf2,"From within %s", where);\
                            MessageBox(hwnd, Buf, Buf2, MB_OK);}

Definition at line 69 of file VIRTMEM.C.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | hwnd,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 241 of file VIRTMEM.C.

{
  CHAR  Buf[80];
  DWORD retCode;
  DWORD oldProtection;
  CHAR  *page;
  CHAR  ExceptError[200] = "An exception was trapped and handled with this message box.\
    Make sure the page is commited and that you have Read/Write access.";
  CHAR ExceptSuccess[] = "Writing to memory was successful: base[100] = 'a'";

  switch (message)
      {

        case WM_CREATE:

            base = VirtualAlloc (NULL,
                                 PAGESIZE,
                                 MEM_RESERVE,
                                 PAGE_NOACCESS);

            if (!base)
              WERR ("VirtualAlloc", "WM_CREATE");

            PostMessage (hwnd, WM_USER, 0, 0);

            return (0);

        case WM_USER:
            ResetMenu();
            return (0);

        case WM_COMMAND:
          switch (LOWORD(wParam))
            {

#ifdef IMPLEMENTED

            case IDM_LOCK:

              VirtualQuery (base, &MemInfo, sizeof(MemInfo));
              if (MemInfo.State != MEM_COMMIT)
                {
                MessageBox (hWnd,
                           "Stop!  You must first COMMIT a page before locking it.",
                            "From IDM_LOCK", MB_OK);
                return (0);
                }

              retCode = VirtualLock(base, PAGESIZE);
              if (!retCode)

                  MessageBox(hWnd, "Error in locking memory",
                             "From within IDM_LOCK", MB_OK);
                else
                  MessageBox(hWnd, "The Memory was Locked.",
                             "From within IDM_LOCK", MB_OK);

              return (0);

            case IDM_UNLOCK:

              retCode = VirtualUnlock(base, PAGESIZE);
              if (!retCode)

                  MessageBox(hWnd, "Error in unlocking memory",
                             "From within IDM_UNLOCK", MB_OK);
                else
                  MessageBox(hWnd, "The Memory was Unlocked.",
                             "From within IDM_UNLOCK", MB_OK);

              return (0);

#endif

            case IDM_WRITE:
              __try
                {
                 base[100] = 'a';
                 MessageBox (hWnd, ExceptSuccess, "try/except", MB_OK);
                }
              __except (EXCEPTION_EXECUTE_HANDLER)
                {
                 MessageBox (hWnd, ExceptError, "try/except", MB_OK);
                }
              return (0);

            case IDM_SHOW:
              DialogBox (hInst, "Page_Info", hwnd, (DLGPROC)ShowDlgProc);
              return (0);

            case IDM_NOACCESS:

              retCode = VirtualQuery (base, &MemInfo,
                                      sizeof(MEMORY_BASIC_INFORMATION));
              if (!retCode)
                {
                 WERR("VirtualQuery", "IDM_NOACCESS");
                 return (0);
                }

              if (MemInfo.State != MEM_COMMIT)
                {
                 MessageBox ( hWnd, "The page must be commited first.",
                             "From IDM_NOACCESS", MB_OK);
                 return (0);
                }

              retCode = VirtualProtect (base, PAGESIZE,
                                        PAGE_NOACCESS, &oldProtection);
              if (!retCode)
                 WERR("VirtualProtect","IDM_NOACCESS");

              ResetMenu();
              return (0);

            case IDM_READONLY:
              retCode = VirtualQuery (base, &MemInfo,
                                      sizeof(MEMORY_BASIC_INFORMATION));
              if (!retCode)
                {
                 WERR("VirtualQuery", "IDM_READONLY");
                 return (0);
                }

              if (MemInfo.State != MEM_COMMIT)
                {
                 MessageBox ( hWnd, "The page must be commited first.",
                             "From IDM_READONLY", MB_OK);
                 return (0);
                }

              retCode = VirtualProtect (base, PAGESIZE,
                                        PAGE_READONLY, &oldProtection);
              if (!retCode)
                WERR("VirtualProtect", "IDM_READONLY");

              ResetMenu();
              return (0);

            case IDM_READWRITE:
              retCode = VirtualQuery (base, &MemInfo,
                                      sizeof(MEMORY_BASIC_INFORMATION));
              if (!retCode)
                {
                 WERR("VirtualQuery", "IDM_READWRITE");
                 return (0);
                }

              if (MemInfo.State != MEM_COMMIT)
                {
                 MessageBox ( hWnd, "The page must be commited first.",
                             "From IDM_READWRITE", MB_OK);
                 return (0);
                }

              retCode = VirtualProtect (base, PAGESIZE,
                                        PAGE_READWRITE, &oldProtection);
              if (!retCode)
                 WERR("VirtualProtect", "IDM_READWRITE");

              ResetMenu();
              return (0);

            case IDM_COMMIT:

              VirtualQuery ((LPVOID)base,
                            &MemInfo,
                            sizeof(MEMORY_BASIC_INFORMATION));

              switch (MemInfo.State)
                {
                case MEM_COMMIT:
                  return (0);

                case MEM_RESERVE:
                  page = VirtualAlloc (base,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);

                  if (page)
                    ResetMenu();
                  else
                    WERR("VirtualAlloc", "IDM_COMMIT");
                  break;

                case MEM_FREE:
                  base = VirtualAlloc(NULL,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);
                  if (base)
                    ResetMenu();
                  else
                    WERR("VirtualAlloc", "IDM_COMMIT");
                  break;
                }

              ResetMenu();
              return (0);

            case IDM_FREE:

              VirtualQuery (base,
                            &MemInfo,
                            sizeof(MEMORY_BASIC_INFORMATION));

              if (MemInfo.State == MEM_COMMIT)
                {
                retCode = VirtualFree(base, PAGESIZE, MEM_DECOMMIT);
                if (!retCode)
                  WERR("VirtualFree","IDM_FREE");

                }

              VirtualQuery (base,
                            &MemInfo,
                            sizeof(MEMORY_BASIC_INFORMATION));

              if (MemInfo.State == MEM_RESERVE)
                {
                retCode = VirtualFree(base, 0, MEM_RELEASE);
                if (!retCode)
                  WERR("VirtualFree", "IDM_FREE");
                }

              ResetMenu();
              return (0);

            case IDM_RESERVE:

              VirtualQuery ((LPVOID)base,
                            &MemInfo,
                            sizeof(MEMORY_BASIC_INFORMATION));

              switch (MemInfo.State)
                {
                 case MEM_RESERVE:
                   return (0);

                 case MEM_FREE:
                   base = VirtualAlloc(NULL, PAGESIZE, MEM_RESERVE, PAGE_NOACCESS);
                   if (!base)
                     WERR("VirtualAlloc","IDM_RESERVE");

                   ResetMenu();
                   return (0);

                 case MEM_COMMIT:
                   retCode = VirtualFree(base, PAGESIZE, MEM_DECOMMIT);

                   if (!retCode)
                     WERR("VirtualFree","IDM_RESERVE");

                   ResetMenu();
                   return (0);

                 default:
                   MessageBox(hWnd, "Unknown MemInfo.State", "From IDM_RESERVE", MB_OK);

                }
              return (0);

            default:
              return (0);
            }

        case WM_DESTROY:
          PostQuitMessage(0);
          return (0);

       }
    return DefWindowProc (hwnd, message, wParam, lParam);
}

VOID ResetMenu ( VOID )

Definition at line 547 of file VIRTMEM.C.

{

  HMENU hMenu;
  INT   i;

  hMenu = GetMenu(hWnd);

  for (i = IDM_FREE; i <= IDM_READWRITE; i++)
    CheckMenuItem(hMenu, i, MF_BYCOMMAND | MF_UNCHECKED);

  VirtualQuery (base,
                &MemInfo,
                sizeof(MEMORY_BASIC_INFORMATION));

  switch (MemInfo.State)
    {
    case MEM_COMMIT:
       CheckMenuItem(hMenu,
                     IDM_COMMIT,
                     MF_BYCOMMAND | MF_CHECKED);
       break;

    case MEM_FREE:
       CheckMenuItem(hMenu,
                     IDM_FREE,
                     MF_BYCOMMAND | MF_CHECKED);
       break;

    case MEM_RESERVE:
       CheckMenuItem(hMenu,
                     IDM_RESERVE,
                     MF_BYCOMMAND | MF_CHECKED);
       break;
    }

  switch (MemInfo.Protect)
    {
    case 0:
      break;

    case PAGE_READWRITE:
      CheckMenuItem(hMenu,
                    IDM_READWRITE,
                    MF_BYCOMMAND | MF_CHECKED);

      break;

    case PAGE_READONLY:
      CheckMenuItem(hMenu,
                    IDM_READONLY,
                    MF_BYCOMMAND | MF_CHECKED);
      break;

    case PAGE_NOACCESS:
      CheckMenuItem(hMenu,
                    IDM_NOACCESS,
                    MF_BYCOMMAND | MF_CHECKED);
      break;
    }
}

BOOL CALLBACK ShowDlgProc | ( | HWND | hdlg,
 |  | UINT | message,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 637 of file VIRTMEM.C.

{
  UNREFERENCED_PARAMETER( lParam );

  switch (message)
    {
    case WM_SYSCOMMAND:
      if (wParam == SC_CLOSE)
        {
         EndDialog(hdlg, TRUE);
         return (TRUE);
        }
      return (0);

    case WM_INITDIALOG:

      VirtualQuery ((LPVOID)base,
                    &MemInfo,
                    sizeof(MEMORY_BASIC_INFORMATION));

      SetDlgItemInt (hdlg, IDE_BASEADDR,  (int)MemInfo.BaseAddress,    FALSE);
      SetDlgItemInt (hdlg, IDE_ALLOCBASE, (int)MemInfo.AllocationBase, FALSE);

      switch (MemInfo.AllocationProtect)
        {
        case PAGE_NOACCESS:
            SetDlgItemText (hdlg, IDE_INITPROT, "No Access");
            break;

        case PAGE_READONLY:
            SetDlgItemText (hdlg, IDE_INITPROT, "Read Only");
            break;

        case PAGE_READWRITE:
            SetDlgItemText (hdlg, IDE_INITPROT, "Read/Write");
            break;

        default:
            SetDlgItemText (hdlg, IDE_INITPROT, "Unknown");

        }

      SetDlgItemInt (hdlg, IDE_SIZE, MemInfo.RegionSize, FALSE);

      switch (MemInfo.State)
        {
        case MEM_FREE:
            SetDlgItemText (hdlg, IDE_STATE, "Free");
            break;

        case MEM_RESERVE:
            SetDlgItemText (hdlg, IDE_STATE, "Reserved");
            break;

        case MEM_COMMIT:
            SetDlgItemText (hdlg, IDE_STATE, "Commited");
            break;

        default:
            SetDlgItemText (hdlg, IDE_STATE, "Unknown");

        }

      switch (MemInfo.Protect)
        {
        case 0:
            SetDlgItemText (hdlg, IDE_PROTECT, "Undefined");
            break;

        case PAGE_NOACCESS:
            SetDlgItemText (hdlg, IDE_PROTECT, "No Access");
            break;

        case PAGE_READONLY:
            SetDlgItemText (hdlg, IDE_PROTECT, "Read Only");
            break;

        case PAGE_READWRITE:
            SetDlgItemText (hdlg, IDE_PROTECT, "Read/Write");
            break;

        default:
            SetDlgItemText (hdlg, IDE_PROTECT, "Unknown");

        }

      return (TRUE);

    default:
      return (0);

    }

  return (0);

}

int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 96 of file VIRTMEM.C.

{
  MSG  msg;
  WNDCLASS wc;

  UNREFERENCED_PARAMETER( lpCmdLine );
  UNREFERENCED_PARAMETER( hPrevInstance );

  hInst = hInstance;

  wc.style = 0;
  wc.lpfnWndProc = (WNDPROC)MainWndProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = hInstance;
  wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = "Virtmem_Menu";
  wc.lpszClassName = "VirtmemWClass";

  RegisterClass(&wc);

  hWnd = CreateWindow ("VirtmemWClass",
                       "Virtual Memory Sample",
                       WS_OVERLAPPEDWINDOW,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       CW_USEDEFAULT,
                       NULL,
                       NULL,
                       hInstance,
                       NULL);

  ShowWindow(hWnd, nCmdShow);
  while (GetMessage (&msg, NULL, 0, 0))
    DispatchMessage (&msg);      // Dispatch message to window.

  return (msg.wParam);           // Returns value from PostQuitMessage.

}

Variable Documentation

CHAR* base

Definition at line 79 of file VIRTMEM.C.

CHAR Buf[80]

Definition at line 76 of file VIRTMEM.C.

CHAR Buf2[80]

Definition at line 77 of file VIRTMEM.C.

HANDLE hInst

Definition at line 82 of file VIRTMEM.C.

HANDLE hWnd

Definition at line 83 of file VIRTMEM.C.

MEMORY_BASIC_INFORMATION MemInfo

Definition at line 84 of file VIRTMEM.C.

CHAR* page

Definition at line 80 of file VIRTMEM.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: VIRTMEM/VIRTMEM.H File Reference

  • VIRTMEM
Defines | Functions

VIRTMEM.H File Reference

Go to the source code of this file.

Defines

#define | IDE_ALLOCBASE 102
#define | IDE_BASEADDR 101
#define | IDE_INITPROT 103
#define | IDE_PROTECT 106
#define | IDE_SIZE 104
#define | IDE_STATE 105
#define | IDM_COMMIT 503
#define | IDM_FREE 501
#define | IDM_LOCK 901
#define | IDM_NOACCESS 504
#define | IDM_READONLY 505
#define | IDM_READWRITE 506
#define | IDM_RESERVE 502
#define | IDM_SHOW 801
#define | IDM_UNLOCK 902
#define | IDM_WRITE 701
#define | PAGESIZE 0x1000

Functions

LRESULT CALLBACK | MainWndProc (HWND, UINT, UINT, LONG)
VOID | ResetMenu (VOID)
BOOL CALLBACK | ShowDlgProc (HWND, UINT, UINT, LONG)

Define Documentation

#define IDE_ALLOCBASE 102

Definition at line 35 of file VIRTMEM.H.

#define IDE_BASEADDR 101

Definition at line 34 of file VIRTMEM.H.

#define IDE_INITPROT 103

Definition at line 36 of file VIRTMEM.H.

#define IDE_PROTECT 106

Definition at line 39 of file VIRTMEM.H.

#define IDE_SIZE 104

Definition at line 37 of file VIRTMEM.H.

#define IDE_STATE 105

Definition at line 38 of file VIRTMEM.H.

#define IDM_COMMIT 503

Definition at line 14 of file VIRTMEM.H.

#define IDM_FREE 501

Definition at line 12 of file VIRTMEM.H.

#define IDM_LOCK 901

Definition at line 20 of file VIRTMEM.H.

#define IDM_NOACCESS 504

Definition at line 16 of file VIRTMEM.H.

#define IDM_READONLY 505

Definition at line 17 of file VIRTMEM.H.

#define IDM_READWRITE 506

Definition at line 18 of file VIRTMEM.H.

#define IDM_RESERVE 502

Definition at line 13 of file VIRTMEM.H.

#define IDM_SHOW 801

Definition at line 25 of file VIRTMEM.H.

#define IDM_UNLOCK 902

Definition at line 21 of file VIRTMEM.H.

#define IDM_WRITE 701

Definition at line 23 of file VIRTMEM.H.

#define PAGESIZE 0x1000

Definition at line 27 of file VIRTMEM.H.

Function Documentation

LRESULT CALLBACK MainWndProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |

Definition at line 204 of file CLIPTEXT.C.

{
    FARPROC lpProcAbout;
    HDC hDC;
    PAINTSTRUCT ps;
    RECT rectClient;
    LPSTR lpszText;

    switch (message) {

        case WM_INITMENU:
                if (wParam == (UINT)GetMenu(hWnd)) {
                if (OpenClipboard(hWnd)) {
                    if (IsClipboardFormatAvailable(CF_TEXT)
                        || IsClipboardFormatAvailable(CF_OEMTEXT))
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
                    else
                        EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
                    CloseClipboard();
                    return (TRUE);
                }
                else                           /* Clipboard is not available */
                    return (FALSE);

            }
            return (TRUE);

        case WM_COMMAND:
                switch(LOWORD(wParam)) {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
                    DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
                    FreeProcInstance(lpProcAbout);
                    break;

                /* file menu commands */

                case IDM_NEW:
                case IDM_OPEN:
                case IDM_SAVE:
                case IDM_SAVEAS:
                case IDM_PRINT:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;

                /* edit menu commands */

                case IDM_UNDO:
                case IDM_CLEAR:
                    MessageBox (
                          GetFocus ()
                        , "Command not implemented."
                        , "ClipText Sample Application"
                        , MB_ICONASTERISK | MB_OK
                    );
                    break;

                case IDM_CUT:
                case IDM_COPY:

                    if (hText != NULL) {

                        /* Allocate memory and copy the string to it */

                        if (!(hData
                             = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpData = GlobalLock(hData))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                        if (!(lpszText = GlobalLock (hText))) {
                            OutOfMemory();
                            return (TRUE);
                        }
                                    strcpy(lpData, lpszText);
                        GlobalUnlock(hData);
                        GlobalUnlock (hText);

                        /* Clear the current contents of the clipboard, and set
                         * the data handle to the new string.
                         */

                        if (OpenClipboard(hWnd)) {
                            EmptyClipboard();
                            SetClipboardData(CF_TEXT, hData);
                            CloseClipboard();
                        }
                        hData = NULL;

                                    if (LOWORD(wParam) == IDM_CUT) {
                            GlobalFree (hText);
                            hText = NULL;
                            EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
                            EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
                            InvalidateRect (hWnd, NULL, TRUE);
                            UpdateWindow (hWnd);
                        }
                    }

                    return (TRUE);

                case IDM_PASTE:
                    if (OpenClipboard(hWnd)) {

                        /* get text from the clipboard */

                        if (!(hClipData = GetClipboardData(CF_TEXT))) {
                            CloseClipboard();
                            break;
                        }
                        if (hText != NULL) {
                            GlobalFree(hText);
                        }
                        if (!(hText = GlobalAlloc(GMEM_MOVEABLE
                                                    , GlobalSize(hClipData)))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpClipData = GlobalLock(hClipData))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        if (!(lpszText = GlobalLock(hText))) {
                            OutOfMemory();
                            CloseClipboard();
                            break;
                        }
                        strcpy(lpszText, lpClipData);
                        GlobalUnlock(hClipData);
                        CloseClipboard();
                        GlobalUnlock(hText);
                        EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
                        EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);

                        /* copy text to the application window */

                        InvalidateRect(hWnd, NULL, TRUE);
                        UpdateWindow(hWnd);
                        return (TRUE);
                    }
                    else
                        return (FALSE);
            }
            break;

            case WM_SIZE:
                InvalidateRect(hWnd, NULL, TRUE);
                break;

            case WM_PAINT:
            hDC = BeginPaint (hWnd, &ps);
            if (hText != NULL) {
                if (!(lpszText = GlobalLock (hText))) {
                    OutOfMemory();
                } else {
                            GetClientRect (hWnd, &rectClient);
                    DrawText (hDC, lpszText, -1, &rectClient
                                , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
                    GlobalUnlock (hText);
                }
            }
                EndPaint (hWnd, &ps);
            break;

            case WM_DESTROY:
                PostQuitMessage(0);
            break;

            default:
                return (DefWindowProc(hWnd, message, wParam, lParam));
    }
    return (0);
}

VOID ResetMenu ( VOID )

Definition at line 547 of file VIRTMEM.C.

{

  HMENU hMenu;
  INT   i;

  hMenu = GetMenu(hWnd);

  for (i = IDM_FREE; i <= IDM_READWRITE; i++)
    CheckMenuItem(hMenu, i, MF_BYCOMMAND | MF_UNCHECKED);

  VirtualQuery (base,
                &MemInfo,
                sizeof(MEMORY_BASIC_INFORMATION));

  switch (MemInfo.State)
    {
    case MEM_COMMIT:
       CheckMenuItem(hMenu,
                     IDM_COMMIT,
                     MF_BYCOMMAND | MF_CHECKED);
       break;

    case MEM_FREE:
       CheckMenuItem(hMenu,
                     IDM_FREE,
                     MF_BYCOMMAND | MF_CHECKED);
       break;

    case MEM_RESERVE:
       CheckMenuItem(hMenu,
                     IDM_RESERVE,
                     MF_BYCOMMAND | MF_CHECKED);
       break;
    }

  switch (MemInfo.Protect)
    {
    case 0:
      break;

    case PAGE_READWRITE:
      CheckMenuItem(hMenu,
                    IDM_READWRITE,
                    MF_BYCOMMAND | MF_CHECKED);

      break;

    case PAGE_READONLY:
      CheckMenuItem(hMenu,
                    IDM_READONLY,
                    MF_BYCOMMAND | MF_CHECKED);
      break;

    case PAGE_NOACCESS:
      CheckMenuItem(hMenu,
                    IDM_NOACCESS,
                    MF_BYCOMMAND | MF_CHECKED);
      break;
    }
}

BOOL CALLBACK ShowDlgProc | ( | HWND | ,
 |  | UINT | ,
 |  | UINT | ,
 |  | LONG |
 | ) |  |
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WALK/WALK.C File Reference

  • WALK
Functions

WALK.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <process.h>
#include "walk.h"

Go to the source code of this file.

Functions

HANDLE | FindFirstDirectory (LPTSTR lpszSearchFile, LPWIN32_FIND_DATA lpffd)
BOOL | FindNextDirectory (HANDLE hSearch, LPWIN32_FIND_DATA lpffd)
VOID | main (int argc, char *argv[])
VOID | Walk (WORD wLevel)

Function Documentation

HANDLE FindFirstDirectory | ( | LPTSTR | lpszSearchFile,
 |  | LPWIN32_FIND_DATA | lpffd
 | ) |  |

Definition at line 65 of file WALK.C.

{
    BOOL     fContinue;
    HANDLE   hSearch;
    DWORD    dwAtt;     // file attributes
    int      iDiff;     // string comparison result

    hSearch = FindFirstFile(lpszSearchFile, lpffd);
    if (hSearch == INVALID_HANDLE_VALUE)
        return hSearch;

    for(;;)
    {
        dwAtt = GetFileAttributes(lpffd->cFileName);
        if (dwAtt != 0xFFFFFFFF)
        {
            if (dwAtt & FILE_ATTRIBUTE_DIRECTORY)
            {
                iDiff = strcmp(lpffd->cFileName, ".");
                if (iDiff)
                {
                    iDiff = strcmp(lpffd->cFileName, "..");
                    if (iDiff)
                        return hSearch;
                }
            }
        }

        fContinue = FindNextFile(hSearch, lpffd);
        if (fContinue == FALSE)
        {
            FindClose(hSearch);
            return INVALID_HANDLE_VALUE;
        }
    }
}

BOOL FindNextDirectory | ( | HANDLE | hSearch,
 |  | LPWIN32_FIND_DATA | lpffd
 | ) |  |

Definition at line 123 of file WALK.C.

{
    BOOL     bContinue;
    DWORD    dwAtt;

    for(;;)
    {
        bContinue = FindNextFile(hSearch, lpffd);
        if (bContinue == FALSE)
            return FALSE;

        dwAtt = GetFileAttributes(lpffd->cFileName);

        // If an error occurs while getting the file attributes, it is
        //   ignored, then the next file is tried.
        //   GetLastError could be called to determine the cause of the error.
        //   More than likely an invalid filename, or entry is secured.
        if (dwAtt == 0xFFFFFFFF)
            continue;

        if (dwAtt & FILE_ATTRIBUTE_DIRECTORY)
            return TRUE;
    }
}

VOID main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 225 of file WALK.C.

{
    // check if Win32s, if so, display notice and terminate
    if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) == 3)
    {
        MessageBox( NULL,
            "This application cannot run on Windows 3.1.\n"
            "This application will now terminate.",
            "Walk",
            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return;
    }

    // if a directory is supplied on the command line
    //  start there
    if (argc == 2)
    {
        if (!SetCurrentDirectory(argv[1]))
        {
            printf("Can't walk '%s'\n", argv[1]);
            return;
        }
    }

    Walk(0);

    return;
}

VOID Walk ( WORD wLevel )

Definition at line 178 of file WALK.C.

{
    BOOL              bContinue = TRUE;
    DWORD             dwSize;
    HANDLE            hSearch;
    WIN32_FIND_DATA   w32FindBuf;

    dwSize = GetCurrentDirectory(BUFSIZE, chPathName);
    if (dwSize == 0)
    {
        printf("Error getting current directory name.  Exiting...\n");
        exit(1);
    }

    if (dwSize >= (BUFSIZE-1))
    {
        printf("\nDirectory name too large.  Skipping over...\n");
        return;
    }

    printf("%s\n", chPathName);

    hSearch = FindFirstDirectory("*", &w32FindBuf);
    if (hSearch == INVALID_HANDLE_VALUE)
    {
        if (wLevel)
            SetCurrentDirectory("..");
        return;
    }

    for (;;)
    {
        if (SetCurrentDirectory(w32FindBuf.cFileName))
            Walk(++wLevel);
        else
            printf("\nSkipping subdirectory: %s\n", w32FindBuf.cFileName);

        bContinue = FindNextDirectory(hSearch, &w32FindBuf);
        if (bContinue == FALSE)
        {
            SetCurrentDirectory("..");
            FindClose(hSearch);
            return;
        }
    }
}

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WALK/WALK.H File Reference

  • WALK
Defines | Functions | Variables

WALK.H File Reference

Go to the source code of this file.

Defines

#define | BUFSIZE MAX_PATH

Functions

HANDLE | FindFirstDirectory (LPTSTR, LPWIN32_FIND_DATA)
VOID | main (int argc, char *argv[])
VOID | Walk (WORD)

Variables

CHAR | chPathName [BUFSIZE]

Define Documentation

#define BUFSIZE MAX_PATH

Definition at line 14 of file WALK.H.

Function Documentation

HANDLE FindFirstDirectory | ( | LPTSTR | ,
 |  | LPWIN32_FIND_DATA |
 | ) |  |

Definition at line 65 of file WALK.C.

{
    BOOL     fContinue;
    HANDLE   hSearch;
    DWORD    dwAtt;     // file attributes
    int      iDiff;     // string comparison result

    hSearch = FindFirstFile(lpszSearchFile, lpffd);
    if (hSearch == INVALID_HANDLE_VALUE)
        return hSearch;

    for(;;)
    {
        dwAtt = GetFileAttributes(lpffd->cFileName);
        if (dwAtt != 0xFFFFFFFF)
        {
            if (dwAtt & FILE_ATTRIBUTE_DIRECTORY)
            {
                iDiff = strcmp(lpffd->cFileName, ".");
                if (iDiff)
                {
                    iDiff = strcmp(lpffd->cFileName, "..");
                    if (iDiff)
                        return hSearch;
                }
            }
        }

        fContinue = FindNextFile(hSearch, lpffd);
        if (fContinue == FALSE)
        {
            FindClose(hSearch);
            return INVALID_HANDLE_VALUE;
        }
    }
}

VOID main | ( | int | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 43 of file ASYN_IO.C.

{
  BOOL       bSuccess ;          // return code of last API called

  CHAR       buf[SECTOR_SIZE] ;  // Buffer used by either
                                   // ReadFile() or WriteFile()

  DWORD      cbBytesRead,        // count of bytes read by ReadFile()
                                   // When asynchonous I/O is performed
                                   // one must check how many bytes were
                                   // read by calling GetOverLappedResults().

               cbBytesWritten,     // count of bytes written by WriteFile()

               cbBytesTransfered ; // this value is returned by
                                   // GetOverLappedResults() represents the
                                   // count of bytes transfered asynchronous

  DWORD      dwStatus,           // value returned by GetLastError()
               dwSuccess ;         // return code of last API called

    HANDLE     hInfile,            // Handle to the file to read
               hOutfile;           // Handle to the file to write to

    HANDLE     hEvent ;            // Handle to the synchronization Event

    OVERLAPPED OverLapped ;        // The operating system does not automatically
                                   // track the current file position of a file
                                   // open for asynchroous I/O. Instead one must
                                   // manually track this by updating the OVERLAPPED
                                   // structure. To update this structure one uses
                                   // the result returned by GetOverLappedResults().

/////////////////////////////////////////////////////////////////////////////
//
//  This block of code initalizes all the necessary variables needed to do
//  asynchronous IO. Specfically it opens the files and initializes the
//  synchronization EVENT and OVERLAPPED structure needed to keep track
//  of asynchronous file I/O
//
/////////////////////////////////////////////////////////////////////////////

  // check if running on Windows NT, if not, display notice and terminate
  if (GetVersion() & 0x80000000)
      {
      MessageBox(NULL,
                   "This sample application can only be run on Windows NT.\n"
                   "This application will now terminate.",
                   "Event",
                   MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return;
      }

    if (argc != 3)
      {
        printf ("\nUsage: ASYN_IO input_file output_file\n");
        ExitProcess(1L);
      }

  // Open file which will be copying.  Note we are opening this
  // asynchronously

    hInfile = CreateFile(argv[1],              // File to read
                         GENERIC_READ,         // Open file for reading only
                         FILE_SHARE_READ,      // Allow others to read file
                         NULL,                 // No security
                         OPEN_EXISTING,        // Fail if file doesn't exit
                         FILE_FLAG_OVERLAPPED, // Async I/o
                         NULL);

  if (hInfile == INVALID_HANDLE_VALUE)
      {
        printf("Error opening %s.\n", argv[1]);
        ErrorMsg("CreateFile");
      }

  // Create the file to write to; here we have opened it for synchronous IO.

  hOutfile = CreateFile(argv[2],                 // File to write to
                          GENERIC_WRITE,           // Open file only to write to
                          0,                       // No sharing allowed
                          NULL,                    // No security
                          CREATE_NEW,              // Fail if file exists
                          FILE_ATTRIBUTE_NORMAL,   // No attributes
                          NULL);

    if (hOutfile == INVALID_HANDLE_VALUE)
      {
      printf("Error opening %s.\n", argv[2]);
        ErrorMsg("CreateFile") ;
      }

  // Create Synchronizing Event

    hEvent = CreateEvent(NULL,    // No security
                         TRUE,    // Manual reset
                         FALSE,   // Initially Event set to non-signaled state
                         NULL);   // No name
    if (hEvent == NULL)
    ErrorMsg("CreateEvent") ;

  //
    // Intialize OverLapped structure. We will be using an Event instead
    // of the file handle for synchronizing I/O. One reason to use a unique
    // event instead of the file handle would be a so multi-threaded app
  // would know which thread to unblock when the handle is set to the
  // signaled state.
  //

    memset(&OverLapped, 0, sizeof(OVERLAPPED));
    OverLapped.hEvent = hEvent ;

    bSuccess = TRUE ;

  /***************************************************************************\
  **                                                                         **
  ** This is the main function of this program. Here we loop until the file  **
  ** has been copied. Notice that even though we are using asynchronous I/O  **
  ** ReadFile() may still return sychronously if it can be done fast enough  **
  **                                                                         **
  \***************************************************************************/

    while (bSuccess)
      {

    // Read file asynchronously

        bSuccess = ReadFile(hInfile,        // Handle of file to read
                      buf,            // Buffer to store input
                      SECTOR_SIZE,    // Number of bytes to read
                      &cbBytesRead,   // Number of bytes read. See note]
                                      // above in delcaration
                      &OverLapped);   // Used for asynchronous I/O

    // Check whether ReadFile() has completed yet

        if (!bSuccess && ((dwStatus = GetLastError()) == ERROR_IO_PENDING))
          {
          printf("\nIO Pending");

      // Read not complete yet first execute the background task then check
      // to the if event "hEvent" set to the signaled state. If the event is
      // not set signaled state then loop through again - run the background
      // task and check the event.

          Do_BackgroundTask();

          dwSuccess = WaitForSingleObject(hEvent, 0);

          if (dwSuccess == WAIT_FAILED)
        {
              ErrorMsg("WaitForSingleObject");
            }
          else if (dwSuccess == WAIT_OBJECT_0)
            {
              bSuccess = GetOverlappedResult(hInfile,
                                             &OverLapped,
                                             &cbBytesTransfered,
                                             FALSE);
              if (!bSuccess)
                  ErrorMsg("GetOverLappedResult");
              else
                {
                  // Read has completed now find out how many bytes have been read
                  printf ("\nNumber of bytes transfered is %d\n", cbBytesTransfered);
                  OverLapped.Offset += cbBytesTransfered ;
                  cbBytesRead = cbBytesTransfered ;
                }
            }
          else if (dwSuccess == WAIT_TIMEOUT)
              {
              Do_BackgroundTask () ;
            }
          }

    // ReadFile() read file synchronously; update Overlapped structure

    else if (bSuccess  && cbBytesRead != 0)
          {
          printf ( "\nNumber of bytes transfered is %d\n", cbBytesRead ) ;
          OverLapped.Offset += cbBytesRead ;
          }

    // ReadFile() has found the end of the file; exit loop

        else if (!bSuccess  && GetLastError() == ERROR_HANDLE_EOF)
          {
          printf("\nEnd of file read\n");
          break ;
          }
        else
      {

      // An error occured while reading, print out status and exit loop.

          ErrorMsg ("ReadFile");
      }

  // Write to file synchronously

  bSuccess = WriteFile(hOutfile,             // Handle of file to write to
                     buf,                  // Data to write to file
                     cbBytesRead,          // Number of bytes to write
                     &cbBytesWritten,      // Number of bytes written
                     NULL);                // Only need for asynchonous output

  if (!bSuccess)
      ErrorMsg("WriteFile");

   } // End of WHILE loop

   CloseHandle(hInfile);        // Close handle to input file
   FlushFileBuffers(hOutfile);  // Make sure all data written to file first
   CloseHandle (hOutfile);      // Close handle to output file
   ExitProcess(0L);

}

VOID Walk ( WORD )

Definition at line 178 of file WALK.C.

{
    BOOL              bContinue = TRUE;
    DWORD             dwSize;
    HANDLE            hSearch;
    WIN32_FIND_DATA   w32FindBuf;

    dwSize = GetCurrentDirectory(BUFSIZE, chPathName);
    if (dwSize == 0)
    {
        printf("Error getting current directory name.  Exiting...\n");
        exit(1);
    }

    if (dwSize >= (BUFSIZE-1))
    {
        printf("\nDirectory name too large.  Skipping over...\n");
        return;
    }

    printf("%s\n", chPathName);

    hSearch = FindFirstDirectory("*", &w32FindBuf);
    if (hSearch == INVALID_HANDLE_VALUE)
    {
        if (wLevel)
            SetCurrentDirectory("..");
        return;
    }

    for (;;)
    {
        if (SetCurrentDirectory(w32FindBuf.cFileName))
            Walk(++wLevel);
        else
            printf("\nSkipping subdirectory: %s\n", w32FindBuf.cFileName);

        bContinue = FindNextDirectory(hSearch, &w32FindBuf);
        if (bContinue == FALSE)
        {
            SetCurrentDirectory("..");
            FindClose(hSearch);
            return;
        }
    }
}

Variable Documentation

CHAR chPathName[BUFSIZE]

Definition at line 16 of file WALK.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WINNET/WINNET.C File Reference

  • WINNET
Data Structures | Defines | Typedefs | Functions | Variables

WINNET.C File Reference

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <winnetwk.h>

Go to the source code of this file.

Data Structures

struct | _DISK_RESOURCES_CONNECTABLE

Defines

#define | LOCAL_DEVICE_NAME "W:"
#define | MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST 3
#define | MAX_NUMBER_OF_RESOURCES_TO_ENUM 480000
#define | PERR(api)
#define | PMSG(msg)
#define | PrintAppStyleAPIError(ApiTxt, MsgTxt)
#define | RESOURCE_BUF_ENTRIES 5000
#define | STRICT
#define | SZ_BUF 1000
#define | SZ_BUF 1000
#define | SZ_ERROR_BUF 4000
#define | SZ_PROVIDER_NAME_BUF 400
#define | szMsgBuf SZ_ERROR_BUF * 2
#define | WHICH_TO_USE_FROM_LIST 0

Typedefs

typedef struct
_DISK_RESOURCES_CONNECTABLE 		DISK_RESOURCES_CONNECTABLE
typedef struct
_DISK_RESOURCES_CONNECTABLE * 		LPDISK_RESOURCES_CONNECTABLE

Functions

VOID | AddGetGetCancel (VOID)
VOID | AddGetGetCancel2 (VOID)
UINT | EnumResources (HANDLE hNetEnum)
UINT | main (UINT argc, char *argv[])
VOID | Open_Do_Close_1_Enum (LPNETRESOURCE lpNetContainerToOpen)
HANDLE | OpenEnum (LPNETRESOURCE lpNetContainerToOpen)
VOID | PrintAPIError (LPTSTR ApiTxt, LPTSTR MsgTxt, UINT Line, LPTSTR File)

Variables

DISK_RESOURCES_CONNECTABLE | ConnectablesList [MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST]
DWORD | dwDiskListI = 0
DWORD | dwResourcesEnumedSoFar = 0

Define Documentation

#define LOCAL_DEVICE_NAME "W:"

Definition at line 130 of file WINNET.C.

#define MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST 3

Definition at line 127 of file WINNET.C.

#define MAX_NUMBER_OF_RESOURCES_TO_ENUM 480000

Definition at line 128 of file WINNET.C.

#define PERR ( api )
Value:
printf("%s: Error %d from %s on line %d\n",  \
    __FILE__, GetLastError(), api, __LINE__);

Definition at line 108 of file WINNET.C.

#define PMSG ( msg )
Value:
printf("%s line %d: %s\n",  \
    __FILE__, __LINE__, msg);

Definition at line 110 of file WINNET.C.

#define PrintAppStyleAPIError | ( | ApiTxt,
 |  | MsgTxt
 | ) |
Value:
{                 \
  PrintAPIError( #ApiTxt , #MsgTxt , __LINE__ , __FILE__ ); \
  }

Definition at line 113 of file WINNET.C.

#define RESOURCE_BUF_ENTRIES 5000
#define STRICT

Definition at line 101 of file WINNET.C.

#define SZ_BUF 1000
#define SZ_BUF 1000
#define SZ_ERROR_BUF 4000
#define SZ_PROVIDER_NAME_BUF 400
#define szMsgBuf SZ_ERROR_BUF * 2
#define WHICH_TO_USE_FROM_LIST 0

Definition at line 131 of file WINNET.C.

Typedef Documentation

typedef struct _DISK_RESOURCES_CONNECTABLE DISK_RESOURCES_CONNECTABLE
typedef struct _DISK_RESOURCES_CONNECTABLE * LPDISK_RESOURCES_CONNECTABLE

Function Documentation

VOID AddGetGetCancel ( VOID )

Definition at line 486 of file WINNET.C.

{
    UCHAR ucLocalName[sizeof(LOCAL_DEVICE_NAME)+1] = LOCAL_DEVICE_NAME;
    UCHAR ucPassword[] = "Passw00";
    #define            SZ_BUF 1000
    UCHAR ucRemoteName[SZ_BUF];
    UCHAR ucUserName  [SZ_BUF];
    DWORD dwSzBuf    = SZ_BUF;

    if (NO_ERROR != WNetAddConnection(
                  ConnectablesList[WHICH_TO_USE_FROM_LIST].lpRemoteName,
                  (LPTSTR)ucPassword,(LPTSTR)ucLocalName))
    {
        PrintAppStyleAPIError(WNetAddConnection,"AddGetGetCancel");
        return;
    }

    dwSzBuf = SZ_BUF;

    if (NO_ERROR != WNetGetConnection((LPTSTR)ucLocalName,
                                      (LPTSTR)ucRemoteName,(LPDWORD)&dwSzBuf))
    {
        PrintAppStyleAPIError(WNetGetConnection,"AddGetGetCancel");
        return;
    }

    dwSzBuf = SZ_BUF;

    if (NO_ERROR != WNetGetUser((LPTSTR)ucLocalName,
                                (LPTSTR)ucUserName,(LPDWORD)&dwSzBuf))
    {
        PrintAppStyleAPIError(WNetGetUser,"AddGetGetCancel");
        return;
    }

    printf("\nDisk resource AddGetGetCancel connected = [%s], User name logged"
           "on to that resource = [%s]\n", ucRemoteName,ucUserName);

    if (NO_ERROR != WNetCancelConnection((LPTSTR)ucLocalName,FALSE))
    {
        PrintAppStyleAPIError(WNetCancelConnection,"AddGetGetCancel");
        return;
    }
}

VOID AddGetGetCancel2 ( VOID )

Definition at line 543 of file WINNET.C.

{
    UCHAR ucLocalName[sizeof(LOCAL_DEVICE_NAME)+1] = LOCAL_DEVICE_NAME;
    NETRESOURCE ToConnect;
    UCHAR ucPassword[] = "Passw00";
    #define            SZ_BUF 1000
    UCHAR ucRemoteName[SZ_BUF];
    UCHAR ucUserName  [SZ_BUF] = "AUserName";
    DWORD dwSzBuf    = SZ_BUF;

    ToConnect.lpRemoteName = ConnectablesList[WHICH_TO_USE_FROM_LIST].lpRemoteName;
    ToConnect.lpLocalName  = ucLocalName;
    ToConnect.lpProvider   = NULL;
    ToConnect.dwType       = RESOURCETYPE_DISK;

    if (NO_ERROR != WNetAddConnection2(&ToConnect,(LPTSTR)ucPassword,
                                       (LPTSTR)ucUserName,CONNECT_UPDATE_PROFILE))
    {
        PrintAppStyleAPIError(WNetAddConnection2,"AddGetGetCancel2");
        return;
    }

    dwSzBuf = SZ_BUF;

    if (NO_ERROR != WNetGetConnection((LPTSTR)ucLocalName,
                                      (LPTSTR)ucRemoteName,(LPDWORD)&dwSzBuf))
    {
        PrintAppStyleAPIError(WNetGetConnection,"AddGetGetCancel2");
        return;
    }

    dwSzBuf = SZ_BUF;

    if (NO_ERROR != WNetGetUser((LPTSTR)ucLocalName,
                                (LPTSTR)ucUserName,(LPDWORD)&dwSzBuf))
    {
        PrintAppStyleAPIError(WNetGetUser,"AddGetGetCancel2");
        return;
    }

    printf("\nDisk resource AddGetGetCancel2 connected = [%s], "
           "User name logged on to that resource = [%s]\n",
           ucRemoteName,ucUserName);

    if (NO_ERROR != WNetCancelConnection2((LPTSTR)ucLocalName,
                                          CONNECT_UPDATE_PROFILE,FALSE))
    {
        PrintAppStyleAPIError(WNetCancelConnection2,"AddGetGetCancel2");
        return;
    }
}

UINT EnumResources ( HANDLE hNetEnum )

Definition at line 300 of file WINNET.C.

{
    #define                    RESOURCE_BUF_ENTRIES 5000
    NETRESOURCE ResourceBuffer[RESOURCE_BUF_ENTRIES];
    DWORD       dwSzResourceBuf;
    DWORD       dwEntriesToGet;

    /**************************************************************************\
    *
    * It's possible that not all entries will fit in a RESOURCE_BUF_ENTRIES slot
    *   buffer, so we call WNetEnumResource in a loop, asking for
    *   RESOURCE_BUF_ENTRIES at a time, and continuing to call WNetEnumResource
    *   until it returns no more entries
    *
    \**************************************************************************/

    for (;;)
    {
        dwSzResourceBuf = sizeof(ResourceBuffer);
        dwEntriesToGet  = RESOURCE_BUF_ENTRIES;

        printf("Getting %d entries\n",dwEntriesToGet);

        if (NO_ERROR != WNetEnumResource(hNetEnum,
                                         (LPDWORD)&dwEntriesToGet,
                                         (LPVOID)ResourceBuffer,
                                         (LPDWORD)&dwSzResourceBuf))
        {
            switch (GetLastError())
            {
                case NO_ERROR:
                    // Drop out of the switch, walk the buffer
                    break;

                case ERROR_NO_MORE_ITEMS :
                    // Return with 0 code because this only happens when we got
                    //   RESOURCE_BUF_ENTRIES entries on the previous call to
                    //   WNetEnumResource, and there were coincidentally exactly
                    //   RESOURCE_BUF_ENTRIES entries total in the enum at the time of
                    //   that previous call
                    return(0);

                default                  :
                    PrintAppStyleAPIError(WNetEnumResource,"EnumResources");
                    return(1);
            }
        }

        /************************************************************************\
        *
        * Walk the returned buffer.  Now dwEntriesToGet has been set by the api
        *   call to be the number of entries actually returned
        *
        \************************************************************************/

        {
            DWORD i;

            printf("Got %d entries\n",dwEntriesToGet);

            for (i=0; i<dwEntriesToGet; i++)
            {
                printf("\nResourceBuffer[%d].dwScope      = 0x%x \n",i,
                        ResourceBuffer[i].dwScope);
                printf("ResourceBuffer[%d].dwType       = 0x%x \n",i,
                        ResourceBuffer[i].dwType);
                printf("ResourceBuffer[%d].dwUsage      = 0x%x \n",i,
                        ResourceBuffer[i].dwUsage);
                printf("ResourceBuffer[%d].lpLocalName  = %s   \n",i,
                        ResourceBuffer[i].lpLocalName);
                printf("ResourceBuffer[%d].lpRemoteName = %s   \n",i,
                        ResourceBuffer[i].lpRemoteName);
                printf("ResourceBuffer[%d].lpComment    = %s   \n",i,
                        ResourceBuffer[i].lpComment);
                printf("ResourceBuffer[%d].lpProvider   = %s   \n",i,
                        ResourceBuffer[i].lpProvider);

                dwResourcesEnumedSoFar += dwEntriesToGet;

                printf("dwResourcesEnumedSoFar = %d \n",dwResourcesEnumedSoFar);

                if (dwDiskListI >= MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST)
                    return(0);  // List full, stop enumerating

                switch (ResourceBuffer[i].dwUsage)
                {
                    case RESOURCEUSAGE_CONNECTABLE :
                        ConnectablesList[dwDiskListI].lpRemoteName =
                            malloc(1+strlen(ResourceBuffer[i].lpRemoteName));
                        ConnectablesList[dwDiskListI].lpComment    =
                            malloc(1+strlen(ResourceBuffer[i].lpComment   ));
                        ConnectablesList[dwDiskListI].lpProvider   =
                            malloc(1+strlen(ResourceBuffer[i].lpProvider  ));

                        if ((NULL == ConnectablesList[dwDiskListI].lpRemoteName) ||
                            (NULL == ConnectablesList[dwDiskListI].lpComment   ) ||
                            (NULL == ConnectablesList[dwDiskListI].lpProvider  ))
                            PERR("EnumResource - ran out of heap space");

                        strcpy(ConnectablesList[dwDiskListI].lpRemoteName,
                               ResourceBuffer[i].lpRemoteName);
                        strcpy(ConnectablesList[dwDiskListI].lpComment   ,
                               ResourceBuffer[i].lpComment   );
                        strcpy(ConnectablesList[dwDiskListI].lpProvider  ,
                               ResourceBuffer[i].lpProvider  );

                        dwDiskListI++;

                        break;

                    case  RESOURCEUSAGE_CONTAINER:      // Regular container
                    case (RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED):
                        //Top-level container

                        /****************************************************************\
                        *
                        * This next test is here to filter out servers we don't wish to
                        *   enumerate while running the sample.  A real app would be more
                        *   likely to look at all servers, but for running a sample, it's
                        *   worthwhile to think about which servers should actually be
                        *   enumerated, to avoid annoying people who have other servers on
                        *   the net they may not wish to be disturbed
                        *
                        * So, you may want to modify this test to filter out whatever
                        *   servers make sense to filter out in your environment
                        *
                        * The first clause shows how to include in the filter the top
                        *   level Windows NT network provider container, the second clause
                        *   shows how to include in the filter a domain name, and the
                        *   third and fourth clauses show how to include any servers whose
                        *   names start with particular characters
                        *
                        \****************************************************************/

                        if (!(  (0==_strnicmp("Microsoft Windows Network", ResourceBuffer[i].lpRemoteName,25))
                              ||(0==_strnicmp("DMAIN1",ResourceBuffer[i].lpRemoteName,6))
                              ||(0==_strnicmp("\\\\BLUMPR2",ResourceBuffer[i].lpRemoteName,9))
                              ||(0==_strnicmp("\\\\BLAMTR2",ResourceBuffer[i].lpRemoteName,9))))
                            break;

                        if (dwResourcesEnumedSoFar < MAX_NUMBER_OF_RESOURCES_TO_ENUM)
                            Open_Do_Close_1_Enum(&ResourceBuffer[i]);
                            break;

                    case RESOURCEUSAGE_RESERVED:   // Ignore these
                        break;

                    default:
                    {
                        UCHAR ucMsgBuf[1500];

                        sprintf(ucMsgBuf,"WNetEnumResources bad .dwUsage value = 0x%X,\n",
                        ResourceBuffer[i].dwUsage);
                        PERR(ucMsgBuf);
                        return(1);
                    }
                }
            }
        }

        /************************************************************************\
        *
        * We have walked the returned buffer.  Since dwEntriesToGet has been set
        *   by the api call to be the number of entries actually returned, if how
        *   many were returned is less than what we asked for, return out of the
        *   loop because this enum is done
        *
        \************************************************************************/

        if (dwEntriesToGet < RESOURCE_BUF_ENTRIES)
            return(0);

    }

    // Infinite loop never exits this way.
}

UINT main | ( | UINT | argc,
 |  | char * | argv[]
 | ) |  |

Definition at line 169 of file WINNET.C.

{
    UNREFERENCED_PARAMETER(argv[1]);

    // check if Win32s, if so, display notice and terminate
    if( GetVersion() & 0x80000000 )
    {
        MessageBox(NULL,
                   "This application only runs on Windows NT.\n"
                   "This application will now terminate.",
                   "WinNet",
                   MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
        return( 1 );
    }

    if (argc > 1)
    {
        printf("\nTo run type 'winnet', with no parameters\n");
        printf("\n  IMPORTANT: Ensure W: is not in use when you type WINNET\n");
        return(1);
    }

    /**************************************************************************\
    *
    * Pass NULL as container argument to get top level container.  This call
    *   starts the recursive exploration of the top level network resource
    *   container
    *
    \**************************************************************************/

    Open_Do_Close_1_Enum(NULL);

    /**************************************************************************\
    *
    * We now have a list of connectable resources in our table, but some error
    *   conditions may have caused the list to be 0 length
    *
    \**************************************************************************/

    if (0<dwDiskListI)
    {
        AddGetGetCancel();
        AddGetGetCancel2();
    }
    else
    {
        printf("\nError: enumerated 0 connectable disk resources!\n");
    }

    /**************************************************************************\
    *
    * Free the list of connectable resources, zero length or not
    *
    \**************************************************************************/

    {
        DWORD i;
        for (i=0; i<dwDiskListI; i++)
        {
            free(ConnectablesList[i].lpRemoteName);
            free(ConnectablesList[i].lpComment   );
            free(ConnectablesList[i].lpProvider  );
        }
    }

    return(0);
}

VOID Open_Do_Close_1_Enum ( LPNETRESOURCE lpNetContainerToOpen )

Definition at line 248 of file WINNET.C.

{
    HANDLE hNetEnum;

    hNetEnum = OpenEnum(lpNetContainerToOpen);

    if (!hNetEnum)
        return;

    if (!EnumResources(hNetEnum))
        return;

    if (NO_ERROR != WNetCloseEnum(hNetEnum))
    {
        PERR("WNetCloseEnum");
        return;
    }
}

HANDLE OpenEnum ( LPNETRESOURCE lpNetContainerToOpen )

Definition at line 273 of file WINNET.C.

{
    HANDLE hNetEnum;

    if (NO_ERROR != WNetOpenEnum(RESOURCE_GLOBALNET,
                                 RESOURCETYPE_DISK,
                                 (RESOURCEUSAGE_CONNECTABLE |
                                 RESOURCEUSAGE_CONTAINER),
                                 lpNetContainerToOpen,
                                 (LPHANDLE)&hNetEnum))
    {
        if (GetLastError() != NO_ERROR)
        {
            PrintAppStyleAPIError(WNetOpenEnum,"OpenEnum");
            return(NULL);
        }
    }

    return(hNetEnum);
}

VOID PrintAPIError | ( | LPTSTR | ApiTxt,
 |  | LPTSTR | MsgTxt,
 |  | UINT | Line,
 |  | LPTSTR | File
 | ) |  |

Definition at line 602 of file WINNET.C.

{
    DWORD dwLastError;

    dwLastError = GetLastError();
    switch (dwLastError)
    {
        case NO_ERROR:
            printf("\nNO_ERROR not expected (%s) line %d file %s",
                   MsgTxt,Line,File);
            break;

        case ERROR_EXTENDED_ERROR:
        {
            DWORD dwErrorCode;

            #define SZ_ERROR_BUF 4000
            UCHAR ucErrorBuf[SZ_ERROR_BUF];
            #define SZ_PROVIDER_NAME_BUF   400
            UCHAR ucProviderNameBuf[SZ_PROVIDER_NAME_BUF];

            if (NO_ERROR != WNetGetLastError(&dwErrorCode,
                                             (LPTSTR)ucErrorBuf,
                                             (DWORD)SZ_ERROR_BUF,
                                             (LPTSTR)ucProviderNameBuf,
                                             (DWORD)SZ_PROVIDER_NAME_BUF))
            {
                PERR("WNetGetLastError");
            }
            else
            {
                #define szMsgBuf SZ_ERROR_BUF * 2
                UCHAR ucMsgBuf[szMsgBuf];

                sprintf(ucMsgBuf, "WNetGetLastError code = %d, Msg=[%s],"
                        "Provider =[%s] line %d file %s", dwErrorCode,
                        ucErrorBuf, ucProviderNameBuf, Line, File);
                PERR(ucMsgBuf);
            }
        }
        break;

        case ERROR_NOT_SUPPORTED:
            printf("\nERROR_NOT_SUPPORTED (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_UNEXP_NET_ERR:
            printf("\nERROR_UNEXP_NET_ERR (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_MORE_DATA:
            printf("\nERROR_MORE_DATA (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_INVALID_ADDRESS:
            printf("\nERROR_INVALID_ADDRESS (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_INVALID_PARAMETER:
            printf("\nERROR_INVALID_PARAMETER (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_INVALID_PASSWORD:
            printf("\nERROR_INVALID_PASSWORD (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_ACCESS_DENIED:
            printf("\nERROR_ACCESS_DENIED (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_BUSY:
            printf("\nERROR_BUSY (%s) line %d file %s", MsgTxt, Line, File);
            break;

        case ERROR_BAD_USERNAME:
            printf("\nERROR_BAD_USERNAME (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_NOT_ENOUGH_MEMORY:
            printf("\nERROR_NOT_ENOUGH_MEMORY (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_NO_NETWORK:
            printf("\nERROR_NO_NETWORK (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_NOT_CONNECTED:
            printf("\nERROR_NOT_CONNECTED (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_OPEN_FILES:
            printf("\nERROR_OPEN_FILES (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_DEVICE_IN_USE:
            printf("\nERROR_DEVICE_IN_USE (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_BAD_NET_NAME:
            printf("\nERROR_BAD_NET_NAME (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_BAD_DEVICE:
            printf("\nERROR_BAD_DEVICE (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_ALREADY_ASSIGNED:
            printf("\nERROR_ALREADY_ASSIGNED (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_GEN_FAILURE:
            printf("\nERROR_GEN_FAILURE (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_CONNECTION_UNAVAIL:
            printf("\nERROR_CONNECTION_UNAVAIL (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_NO_NET_OR_BAD_PATH:
            printf("\nERROR_NO_NET_OR_BAD_PATH (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_BAD_PROVIDER:
            printf("\nERROR_BAD_PROVIDER (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_CANNOT_OPEN_PROFILE:
            printf("\nERROR_CANNOT_OPEN_PROFILE (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_BAD_PROFILE:
            printf("\nERROR_BAD_PROFILE (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_INVALID_HANDLE:
            printf("\nERROR_INVALID_HANDLE (%s) line %d file %s", MsgTxt,
                   Line, File);
            break;

        case ERROR_NO_MORE_ITEMS:
            printf("\nERROR_NO_MORE_ITEMS (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        case ERROR_NOT_CONTAINER:
            printf("\nERROR_NOT_CONTAINER (%s) line %d file %s", MsgTxt, Line,
                   File);
            break;

        default:
            printf("\n%s - unexpected return code=%d (%s) line %d file %s",
                   ApiTxt, dwLastError, MsgTxt, Line, File);
            break;
    }
}

Variable Documentation

DISK_RESOURCES_CONNECTABLE ConnectablesList[MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST]

Definition at line 145 of file WINNET.C.

DWORD dwDiskListI = 0

Definition at line 147 of file WINNET.C.

DWORD dwResourcesEnumedSoFar = 0

Definition at line 146 of file WINNET.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WORLD/WORLD.C File Reference

  • WORLD
Defines | Functions | Variables

WORLD.C File Reference

#include <windows.h>
#include <memory.h>
#include <stdlib.h>
#include "world.h"

Go to the source code of this file.

Defines

#define | FIRSTSTRING 0
#define | HORZSCALE HSCROLLMAX/3
#define | HSCROLLMAX 50
#define | LASTSTRING 10
#define | LINEINC 1
#define | MAXINPUT 10
#define | PAGEINC 4
#define | VERTSCALE VSCROLLMAX/3
#define | VSCROLLMAX 50

Functions

BOOL CALLBACK | AboutDlgProc (HWND, UINT, WPARAM, LPARAM)
LRESULT CALLBACK | MainWndProc (HWND, UINT, WPARAM, LPARAM)
BOOL | OpenMetafile (HWND)
BOOL CALLBACK | ScaleDlgProc (HWND, UINT, WPARAM, LPARAM)
void | SetUnityXform ()
void | SetUnityXform (VOID)
int PASCAL | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)

Variables

BOOL | bFileJustOpen
BOOL | bFileOpen
HANDLE | ghInstance
HENHMETAFILE | hEMF
OPENFILENAME | OpenFileName
CHAR | szFile [MAX_PATH]
CHAR | szFileTitle [MAX_PATH]
CHAR | szFilter [] = "Metafile (*.EMF)\0*.emf\0All Files (*.*)\0*.*\0"
XFORM | xForm

Define Documentation

#define FIRSTSTRING 0

Definition at line 54 of file WORLD.C.

#define HORZSCALE HSCROLLMAX/3

Definition at line 49 of file WORLD.C.

#define HSCROLLMAX 50

Definition at line 47 of file WORLD.C.

#define LASTSTRING 10

Definition at line 55 of file WORLD.C.

#define LINEINC 1

Definition at line 51 of file WORLD.C.

#define MAXINPUT 10

Definition at line 56 of file WORLD.C.

#define PAGEINC 4

Definition at line 52 of file WORLD.C.

#define VERTSCALE VSCROLLMAX/3

Definition at line 48 of file WORLD.C.

#define VSCROLLMAX 50

Definition at line 46 of file WORLD.C.

Function Documentation

BOOL CALLBACK AboutDlgProc | ( | HWND | hDlg,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 482 of file WORLD.C.

{
   switch( uMsg ) {
      case WM_INITDIALOG:
         return TRUE;
      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;
   }

   return FALSE;
}

LRESULT CALLBACK MainWndProc | ( | HWND | hWnd,
 |  | UINT | msg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 174 of file WORLD.C.

{
   static int nVscrollPos, nHscrollPos;
   int nVscrollInc, nHscrollInc;
   RECT rect;
   PAINTSTRUCT ps;
   HDC hDC;

   switch( msg ) {

/**************************************************************\
*     WM_CREATE: The scrollbar range is set. Global variables  *
*        are initialized. The new API SetGraphicsMode() must   *
*        be called before SetWorldCoordinates() can be called  *
*        in the WM_PAINT case.                                 *
\**************************************************************/

      case WM_CREATE:

         SetScrollRange( hWnd, SB_HORZ, 0, HSCROLLMAX, FALSE );
         SetScrollRange( hWnd, SB_VERT, 0, VSCROLLMAX, FALSE );

         bFileOpen = FALSE;
         bFileJustOpen = FALSE;

         hDC = GetDC( hWnd );
         SetGraphicsMode( hDC, GM_ADVANCED );
         ReleaseDC( hWnd, hDC );

         break;

/**************************************************************\
*     WM_HSCROLL: Standard template, except that instead of    *
*        calling ScrollWindow(), the transform is updated.     *
\**************************************************************/

      case WM_HSCROLL:
         switch( wParam ) {
            case SB_LINEUP:
               nHscrollInc = -LINEINC;
               break;
            case SB_LINEDOWN:
               nHscrollInc = LINEINC;
               break;
            case SB_PAGEUP:
               nHscrollInc = -PAGEINC;
               break;
            case SB_PAGEDOWN:
               nHscrollInc = PAGEINC;
               break;
            case SB_THUMBPOSITION:
               nHscrollInc = HIWORD(wParam) - nHscrollPos;
               break;
            default:
               nHscrollInc = 0;
         }
         if(nHscrollInc=max(-nHscrollPos,min(nHscrollInc,HSCROLLMAX-
               nHscrollPos))) {
            nHscrollPos += nHscrollInc;
            SetScrollPos( hWnd, SB_HORZ, nHscrollPos, TRUE );

            xForm.eDx += (FLOAT) (nHscrollInc * HORZSCALE);
            InvalidateRect( hWnd, NULL, TRUE );
         }
         return 0;

/**************************************************************\
*     WM_VSCROLL: Standard template, except that instead of    *
*        calling ScrollWindow(), the transform is updated.*    *
\**************************************************************/

      case WM_VSCROLL:
         switch( wParam ) {
            case SB_TOP:
               nVscrollInc = -nVscrollPos;
               break;
            case SB_BOTTOM:
               nVscrollInc = VSCROLLMAX - nVscrollPos;
               break;
            case SB_LINEUP:
               nVscrollInc = -LINEINC;
               break;
            case SB_LINEDOWN:
               nVscrollInc = LINEINC;
               break;
            case SB_PAGEUP:
               nVscrollInc = -PAGEINC;
               break;
            case SB_PAGEDOWN:
               nVscrollInc = PAGEINC;
               break;
            case SB_THUMBTRACK:
               nVscrollInc = HIWORD(wParam) - nVscrollPos;
               break;
            default:
               nVscrollInc = 0;
         }
         if(nVscrollInc=max(-nVscrollPos,min(nVscrollInc,VSCROLLMAX-
               nVscrollPos))) {
            nVscrollPos += nVscrollInc;
            SetScrollPos( hWnd, SB_VERT, nVscrollPos, TRUE );

            xForm.eDy += (FLOAT) (nVscrollInc * VERTSCALE);
            InvalidateRect( hWnd, NULL, TRUE );
         }
         return 0;

/**************************************************************\
*     WM_KEYDOWN: Standard template                            *
\**************************************************************/

      case WM_KEYDOWN:
         switch( wParam ) {
            case VK_UP:
               SendMessage( hWnd, WM_VSCROLL, SB_LINEUP, 0L );
               break;
            case VK_DOWN:
               SendMessage( hWnd, WM_VSCROLL, SB_LINEDOWN, 0L );
               break;
            case VK_LEFT:
               SendMessage( hWnd, WM_HSCROLL, SB_LINEUP, 0L );
               break;
            case VK_RIGHT:
               SendMessage( hWnd, WM_HSCROLL, SB_LINEDOWN, 0L );
               break;
            case VK_PRIOR:
               SendMessage( hWnd, WM_VSCROLL, SB_PAGEUP, 0L );
               break;
            case VK_NEXT:
               SendMessage( hWnd, WM_VSCROLL, SB_PAGEDOWN, 0L );
               break;
         }
         return 0;

/**************************************************************\
*     WM_PAINT: If a Metafile has been opened, the transform   *
*        is applied using SetWorldTransform() and the Metafile *
*        is displayed using PlayEnhMetaFile().                 *
\**************************************************************/

      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );

         if( bFileOpen ) {
            GetClientRect( hWnd, &rect );
            SetWorldTransform( hDC, &xForm );
            PlayEnhMetaFile( hDC, hEMF, &rect );
         }

         EndPaint( hWnd, &ps );
         break;

/**************************************************************\
*     WM_COMMAND: If Metafile.Open is selected, OpenMetafile   *
*        and InvalidateRect() are called and the thumb         *
*        position is centered. If Metafile.Exit is selected,   *
*        a WM_CLOSE message is sent. If Scale is chosen, then  *
*        the "Scale Image" dialog is displayed; if the user    *
*        choses OK, then InvalidateRect() is called. If        *
*        Help.About is chosen, then the "About" dialog box is  *
*        displayed.                                            *
\**************************************************************/

      case WM_COMMAND:
         switch( wParam ) {
            case IDM_OPEN:
               if( OpenMetafile( hWnd ) ) {
                  SetWindowText( hWnd, OpenFileName.lpstrFile );
                  SetUnityXform( );
                  nHscrollPos = HSCROLLMAX/2;
                  nVscrollPos = VSCROLLMAX/2;
                  SetScrollPos( hWnd, SB_HORZ, nHscrollPos, TRUE );
                  SetScrollPos( hWnd, SB_VERT, nVscrollPos, TRUE );

                  InvalidateRect( hWnd, NULL, TRUE );
               }
               break;
            case IDM_EXIT:
               SendMessage( hWnd, WM_CLOSE, 0, 0 );
               break;
            case IDM_SCALE:
               if( DialogBox( ghInstance, "ScaleDlg", hWnd,
                     (DLGPROC) ScaleDlgProc ) )
                  InvalidateRect( hWnd, NULL, TRUE );
               break;
            case IDM_ABOUT:
               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                             AboutDlgProc );
               break;
         }
         break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

BOOL OpenMetafile ( HWND hWnd )

Definition at line 513 of file WORLD.C.

{
   szFile[0] = '\0';
   szFileTitle[0] = '\0';
   memset( (LPVOID) &OpenFileName, 0, sizeof( OPENFILENAME ));

   OpenFileName.lStructSize = sizeof( OPENFILENAME );
   OpenFileName.hwndOwner = hWnd;
   OpenFileName.lpstrFilter = szFilter;
   OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
   OpenFileName.nMaxCustFilter = 0L;
   OpenFileName.nFilterIndex = 1L;
   OpenFileName.lpstrFile = szFile;
   OpenFileName.nMaxFile = sizeof( szFile );
   OpenFileName.lpstrFileTitle = szFileTitle;
   OpenFileName.nMaxFileTitle = sizeof( szFileTitle );
   OpenFileName.lpstrInitialDir = NULL;
   OpenFileName.lpstrTitle = "Open Metafile";
   OpenFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
   OpenFileName.nFileOffset = 0;
   OpenFileName.nFileExtension = 0;
   OpenFileName.lpstrDefExt = "*.EMF";

   if( !GetOpenFileName( &OpenFileName ) )
      return FALSE;

   hEMF = GetEnhMetaFile( OpenFileName.lpstrFile );
   bFileOpen = TRUE;
   bFileJustOpen = TRUE;

   return TRUE;
}

BOOL CALLBACK ScaleDlgProc | ( | HWND | hDlg,
 |  | UINT | uMsg,
 |  | WPARAM | wParam,
 |  | LPARAM | lParam
 | ) |  |

Definition at line 400 of file WORLD.C.

{
   char buffer[MAXINPUT];
   static char HorzInputBuf[MAXINPUT];
   static char VertInputBuf[MAXINPUT];
   int index;

   switch( uMsg ) {

/**************************************************************\
*     WM_INITDIALOG: Strings representing the possible scale   *
*        factors are loaded into the comboboxes. The current   *
*        selection is indicated.                               *
\**************************************************************/

      case WM_INITDIALOG:
         for( index=FIRSTSTRING; index <= LASTSTRING; index++ ) {
            LoadString( GetModuleHandle(NULL), index, buffer, MAXINPUT);
            SendDlgItemMessage( hDlg, IDC_HORZ, CB_ADDSTRING, 0,
                                 (LPARAM)buffer );
            SendDlgItemMessage( hDlg, IDC_VERT, CB_ADDSTRING, 0,
                                 (LPARAM)buffer );
         }

         if( bFileJustOpen || !bFileOpen ) {
            lstrcpy( HorzInputBuf, " 1.0" );
            lstrcpy( VertInputBuf, " 1.0" );
            bFileJustOpen = FALSE;
         }

         SendDlgItemMessage( hDlg, IDC_HORZ, CB_SELECTSTRING, 0,
                              (LPARAM)HorzInputBuf );
         SendDlgItemMessage( hDlg, IDC_VERT, CB_SELECTSTRING, 0,
                              (LPARAM)VertInputBuf );
         return TRUE;

/**************************************************************\
*     WM_COMMAND: If the OK button is selected, the current    *
*        horizontal and vertical scaling factors are obtained  *
*        from the ComboBox and the transform is updated. If    *
*        the CANCEL button is selected, EndDialog() is called. *
\**************************************************************/

      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               index = SendDlgItemMessage( hDlg, IDC_HORZ, CB_GETCURSEL,
                                            0, 0 );
               LoadString( GetModuleHandle(NULL), index, HorzInputBuf,
                            MAXINPUT );
               xForm.eM11 = (FLOAT) atof( HorzInputBuf );

               index = SendDlgItemMessage( hDlg, IDC_VERT, CB_GETCURSEL,
                                            0, 0 );
               LoadString( GetModuleHandle(NULL), index, VertInputBuf,
                            MAXINPUT );
               xForm.eM22 = (FLOAT) atof( VertInputBuf );

               EndDialog( hDlg, TRUE );
               return TRUE;
            case IDCANCEL:
               EndDialog( hDlg, FALSE );
               return TRUE;
         }
         break;
   }

   return FALSE;
}

void SetUnityXform ( )

Definition at line 564 of file WORLD.C.

{
   xForm.eM11 = (FLOAT) 1.0;
   xForm.eM12 = (FLOAT) 0.0;
   xForm.eM21 = (FLOAT) 0.0;
   xForm.eM22 = (FLOAT) 1.0;
   xForm.eDx  = (FLOAT) 0.0;
   xForm.eDy  = (FLOAT) 0.0;
}

void SetUnityXform ( VOID )
int PASCAL WinMain | ( | HINSTANCE | hInstance,
 |  | HINSTANCE | hPrevInstance,
 |  | LPSTR | lpszCmdLine,
 |  | int | nCmdShow
 | ) |  |

Definition at line 94 of file WORLD.C.

{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;

   // check if running on Windows NT, if not, display notice and terminate
   if( GetVersion() & 0x80000000 )
   {
      MessageBoxA( NULL,
         "This sample application can only be run on Windows NT.\n"
         "This application will now terminate.",
         "World",
         MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
      return( 1 );
   }

   if( !hPrevInstance ) {
      wc.lpszClassName = "WorldClass";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( hInstance, "WorldIcon" );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = "WorldMenu";
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   ghInstance = hInstance;

   hWnd = CreateWindow( "WorldClass",
                        "World Coordinate Transforms",
                        WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
                        0,
                        0,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        NULL,
                        NULL,
                        hInstance,
                        NULL
                      );

   ShowWindow( hWnd, nCmdShow );

   while( GetMessage( &msg, NULL, 0, 0 ) ) {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }

   return msg.wParam;
}

Variable Documentation

BOOL bFileJustOpen

Definition at line 73 of file WORLD.C.

BOOL bFileOpen

Definition at line 72 of file WORLD.C.

HANDLE ghInstance

Definition at line 68 of file WORLD.C.

HENHMETAFILE hEMF

Definition at line 70 of file WORLD.C.

OPENFILENAME OpenFileName

Definition at line 77 of file WORLD.C.

CHAR szFile[MAX_PATH]

Definition at line 78 of file WORLD.C.

CHAR szFileTitle[MAX_PATH]

Definition at line 79 of file WORLD.C.

CHAR szFilter[] = "Metafile (*.EMF)\0*.emf\0All Files (*.*)\0*.*\0"

Definition at line 80 of file WORLD.C.

XFORM xForm

Definition at line 71 of file WORLD.C.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WORLD/WORLD.H File Reference

  • WORLD
Defines

WORLD.H File Reference

Go to the source code of this file.

Defines

#define | IDC_HORZ 2000
#define | IDC_VERT 2001
#define | IDM_ABOUT 1003
#define | IDM_EXIT 1001
#define | IDM_OPEN 1000
#define | IDM_SCALE 1002

Define Documentation

#define IDC_HORZ 2000

Definition at line 29 of file WORLD.H.

#define IDC_VERT 2001

Definition at line 30 of file WORLD.H.

#define IDM_ABOUT 1003

Definition at line 24 of file WORLD.H.

#define IDM_EXIT 1001

Definition at line 22 of file WORLD.H.

#define IDM_OPEN 1000

Definition at line 21 of file WORLD.H.

#define IDM_SCALE 1002

Definition at line 23 of file WORLD.H.

Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Directory Hierarchy

Directories

This directory hierarchy is sorted roughly, but not completely, alphabetically:
  • ASYN_IO
  • BNDBUF
  • BOB
  • BPOINTER
  • CLIPTEXT
  • CMNDLG
  • CONSOLEC
  • CPL
  • CURSOR
  • DRIVES
  • EVENT
  • GETDEV
  • GETSYS
  • GLTHREAD
  • GUIGREP
  • HOOKS
  • INHERIT
  • INTEROP
  • IOCOMP
  • LOCALE
  • LOGGING
  • MASKBLT
  • MDI_
  • MENU
  • MINREC
  • NETDDE
  • NTSD
  • OTHRPROC
  • OVCOMM
  • OWNCOMBO
  • PATHS
  • PLATFORM
  • POLYDRAW
  • READWRIT
  • REBOOT
  • REGIONS
  • RESDLL
  • SCRNSAVE
  • SEMAPHOR
  • SERVENUM
    • DEMO
    • DLL
  • SETINFO
  • SHAREMEM
  • SIMPLDLL
  • STARTP
  • STREBLT
  • SUBCLASS
  • TERMPROC
  • THREADS
  • TIMERS
  • TLS
  • UNIPUT
  • VIRTMEM
  • WALK
  • WINNET
  • WORLD
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: ASYN_IO/ Directory Reference

  • ASYN_IO

ASYN_IO Directory Reference

Files

file ASYN_IO.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/ Directory Reference

  • BNDBUF

BNDBUF Directory Reference

Files

file | BNDBUF.IDL [code]
file | BNDBUFC.C [code]
file | BNDBUFP.C [code]
file | BNDBUFS.C [code]
file | COMMON.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BOB/ Directory Reference

  • BOB

BOB Directory Reference

Files

file | BOB.C [code]
file | BOB.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/ Directory Reference

  • BPOINTER

BPOINTER Directory Reference

Files

file | CHGDATA.C [code]
file | READDATA.C [code]
file | SHRSTUFF.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CLIPTEXT/ Directory Reference

  • CLIPTEXT

CLIPTEXT Directory Reference

Files

file | CLIPTEXT.C [code]
file | CLIPTEXT.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/ Directory Reference

  • CMNDLG

CMNDLG Directory Reference

Files

file | CDERR.H [code]
file | CMNDLG.C [code]
file | CMNDLG.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CONSOLEC/ Directory Reference

  • CONSOLEC

CONSOLEC Directory Reference

Files

file | COLOR.C [code]
file | COLOR.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CPL/ Directory Reference

  • CPL

CPL Directory Reference

Files

file | STEREO.C [code]
file | STEREO.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CURSOR/ Directory Reference

  • CURSOR

CURSOR Directory Reference

Files

file | CURSOR.C [code]
file | CURSOR.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: DRIVES/ Directory Reference

  • DRIVES

DRIVES Directory Reference

Files

file | DRIVES.C [code]
file | DRIVES.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: EVENT/ Directory Reference

  • EVENT

EVENT Directory Reference

Files

file ASYN_IO.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETDEV/ Directory Reference

  • GETDEV

GETDEV Directory Reference

Files

file | GETDEV.C [code]
file | GETDEV.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETSYS/ Directory Reference

  • GETSYS

GETSYS Directory Reference

Files

file | GETSYS.C [code]
file | GETSYS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/ Directory Reference

  • GLTHREAD

GLTHREAD Directory Reference

Files

file | GLOS.H [code]
file | GLTHREAD.C [code]
file | GLTHREAD.H [code]
file | RESOURCE.H [code]
file | THREADS.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/ Directory Reference

  • GUIGREP

GUIGREP Directory Reference

Files

file | GUIGREP.C [code]
file | GUIGREP.H [code]
file | NTGREP.C [code]
file | NTGREP.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: HOOKS/ Directory Reference

  • HOOKS

HOOKS Directory Reference

Files

file | HOOKTEST.C [code]
file | HOOKTEST.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INHERIT/ Directory Reference

  • INHERIT

INHERIT Directory Reference

Files

file | CHILD.C [code]
file | INHERIT.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/ Directory Reference

  • INTEROP

INTEROP Directory Reference

Files

file | APP16.C [code]
file | APP16.H [code]
file | DISP32.C [code]
file | DLL16.C [code]
file | DLL32.C [code]
file | MYUT.H [code]
file | STUB32.C [code]
file | UTDLL32.C [code]
file | W32SUT.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: IOCOMP/ Directory Reference

  • IOCOMP

IOCOMP Directory Reference

Files

file IOCOMP.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOCALE/ Directory Reference

  • LOCALE

LOCALE Directory Reference

Files

file | LOCALE.C [code]
file | LOCALE.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOGGING/ Directory Reference

  • LOGGING

LOGGING Directory Reference

Files

file LOG.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/ Directory Reference

  • MASKBLT

MASKBLT Directory Reference

Files

file | BITMAP.C [code]
file | BITMAP.H [code]
file | MASKBLT.C [code]
file | MASKBLT.H [code]
file | TRACK.C [code]
file | TRACK.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/ Directory Reference

  • MDI_

MDI_ Directory Reference

Files

file | MDI.C [code]
file | MDI.H [code]
file | MDITYPES.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MENU/ Directory Reference

  • MENU

MENU Directory Reference

Files

file | MENU.C [code]
file | MENU.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/ Directory Reference

  • MINREC

MINREC Directory Reference

Files

file | MINREC.C [code]
file | MINREC.H [code]
file | RECHOOK.C [code]
file | RECHOOK.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/ Directory Reference

  • NETDDE

NETDDE Directory Reference

Files

file | ABOUT.C [code]
file | CONNECT.C [code]
file | CONNECT.H [code]
file | DDECBACK.C [code]
file | DDECBACK.H [code]
file | DISPATCH.C [code]
file | GLOBALS.H [code]
file | INIT.C [code]
file | MEM.C [code]
file | MEM.H [code]
file | MISC.C [code]
file | NDDECHAT.C [code]
file | NDDEUTIL.C [code]
file | NDDEUTIL.H [code]
file | WIN16EXT.H [code]
file | WINMAIN.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/ Directory Reference

  • NTSD

NTSD Directory Reference

Files

file | DEBUG.C [code]
file | MDI.C [code]
file | MDI.H [code]
file | MDITYPES.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OTHRPROC/ Directory Reference

  • OTHRPROC

OTHRPROC Directory Reference

Files

file | OTHRPROC.C [code]
file | OTHRPROC.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OVCOMM/ Directory Reference

  • OVCOMM

OVCOMM Directory Reference

Files

file | OVCOMM.C [code]
file | OVCOMM.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OWNCOMBO/ Directory Reference

  • OWNCOMBO

OWNCOMBO Directory Reference

Files

file | OWNCOMBO.C [code]
file | OWNCOMBO.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PATHS/ Directory Reference

  • PATHS

PATHS Directory Reference

Files

file | PATHS.C [code]
file | PATHS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PLATFORM/ Directory Reference

  • PLATFORM

PLATFORM Directory Reference

Files

file | PLATFORM.C [code]
file | PLATFORM.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: POLYDRAW/ Directory Reference

  • POLYDRAW

POLYDRAW Directory Reference

Files

file | POLYDRAW.C [code]
file | POLYDRAW.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/ Directory Reference

  • READWRIT

READWRIT Directory Reference

Files

file | DATABASE.C [code]
file | DATABASE.H [code]
file | READWRIT.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REBOOT/ Directory Reference

  • REBOOT

REBOOT Directory Reference

Files

file REBOOT.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REGIONS/ Directory Reference

  • REGIONS

REGIONS Directory Reference

Files

file | REGIONS.C [code]
file | REGIONS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/ Directory Reference

  • RESDLL

RESDLL Directory Reference

Files

file | MAIN.C [code]
file | MAIN.H [code]
file | THE_DLL.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SCRNSAVE/ Directory Reference

  • SCRNSAVE

SCRNSAVE Directory Reference

Files

file | FRACTAL.C [code]
file | FRACTAL.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SEMAPHOR/ Directory Reference

  • SEMAPHOR

SEMAPHOR Directory Reference

Files

file | SEMA.C [code]
file | SEMA.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/ Directory Reference

  • SERVENUM

SERVENUM Directory Reference

Directories

directory | DEMO
directory | DLL
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/ Directory Reference

  • SERVENUM
  • DEMO

DEMO Directory Reference

Files

file | BROWSE.C [code]
file | DISPATCH.C [code]
file | GLOBALS.H [code]
file | INIT.C [code]
file | MISC.C [code]
file | SERVENUM.H [code]
file | WINMAIN.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ Directory Reference

  • SERVENUM
  • DLL

DLL Directory Reference

Files

file | DLLDISP.C [code]
file | DLLDISP.H [code]
file | ENUMDLG.C [code]
file | ENUMDLG.H [code]
file | ENUMTHRD.C [code]
file | ENUMTHRD.H [code]
file | ENUMUTIL.C [code]
file | ENUMUTIL.H [code]
file | MACROS.H [code]
file | MEM.C [code]
file | MEM.H [code]
file | MISCUTIL.C [code]
file | MISCUTIL.H [code]
file | SERVENUM.C [code]
file | SERVENUM.H [code]
file | THRDUTIL.C [code]
file | THRDUTIL.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SETINFO/ Directory Reference

  • SETINFO

SETINFO Directory Reference

Files

file | SETINFO.C [code]
file | SETINFO.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SHAREMEM/ Directory Reference

  • SHAREMEM

SHAREMEM Directory Reference

Files

file | SHAREMEM.C [code]
file | SHAREMEM.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/ Directory Reference

  • SIMPLDLL

SIMPLDLL Directory Reference

Files

file | LINKTEST.C [code]
file | LINKTEST.H [code]
file | LOADTEST.C [code]
file | LOADTEST.H [code]
file | THE_DLL.C [code]
file | THE_DLL.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STARTP/ Directory Reference

  • STARTP

STARTP Directory Reference

Files

file STARTP.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/ Directory Reference

  • STREBLT

STREBLT Directory Reference

Files

file | BITMAP.C [code]
file | BITMAP.H [code]
file | STREBLT.C [code]
file | STREBLT.H [code]
file | TRACK.C [code]
file | TRACK.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SUBCLASS/ Directory Reference

  • SUBCLASS

SUBCLASS Directory Reference

Files

file | SUBCLASS.C [code]
file | SUBCLASS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TERMPROC/ Directory Reference

  • TERMPROC

TERMPROC Directory Reference

Files

file TERMPROC.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: THREADS/ Directory Reference

  • THREADS

THREADS Directory Reference

Files

file | THREADS.C [code]
file | THREADS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TIMERS/ Directory Reference

  • TIMERS

TIMERS Directory Reference

Files

file | TIMERS.C [code]
file | TIMERS.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/ Directory Reference

  • TLS

TLS Directory Reference

Files

file | TLSCALL.C [code]
file | TLSDLL.C [code]
file | TLSDLL.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/ Directory Reference

  • UNIPUT

UNIPUT Directory Reference

Files

file | DISPLAY.C [code]
file | DISPLAY.H [code]
file | STATUS.C [code]
file | UNIPUT.C [code]
file | UNIPUT.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: VIRTMEM/ Directory Reference

  • VIRTMEM

VIRTMEM Directory Reference

Files

file | VIRTMEM.C [code]
file | VIRTMEM.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WALK/ Directory Reference

  • WALK

WALK Directory Reference

Files

file | WALK.C [code]
file | WALK.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WINNET/ Directory Reference

  • WINNET

WINNET Directory Reference

Files

file WINNET.C [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WORLD/ Directory Reference

  • WORLD

WORLD Directory Reference

Files

file | WORLD.C [code]
file | WORLD.H [code]
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- _ -

  • __based() : SHRSTUFF.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Alphabetical List

  • Data Structures
  • Data Structure Index
  • Data Fields

Data Structure Index

C | E | G | M | R | T | _
C
CHAINLIST
E
EVENTHEADER_STRUCT
G
GLOBAL_STRUCT
growmemory
M
memory
R
RGNSTRUCT
T
tagApplets
tagControlText
tagCOPYDATASTRUCT
tagExtraBytes
tagLookupEntry
tagMYREC
tagSUBTABLE
tagTABLE
tagTHREADPBLOCK
tagTrackObject
tagWIN32SINFO
TRACKRECTSTRUCT
_
_CMD
_CMDI
_DISK_RESOURCES_CONNECTABLE
_ENUMLISTOBJECT
_ENUMNODE
_ENUMOBJECT
_ENUMSYNC
_MSD
_MSDI
_MYHOOKDATA
_PerWndInfo
_TLSOBJECT
C | E | G | M | R | T | _
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields - Functions

  • Data Structures
  • Data Structure Index
  • Data Fields
  • All
  • Functions
  • Variables
  • __based() : CHAINLIST
  • add() : growmemory
  • Alloc() : memory
  • Free() : memory
  • GetHandle() : growmemory
  • growmemory() : growmemory
  • memory() : memory
  • Reset() : memory
  • ~growmemory() : growmemory
  • ~memory() : memory
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields - Variables

  • Data Structures
  • Data Structure Index
  • Data Fields
  • All
  • Functions
  • Variables
  • a
  • b
  • c
  • d
  • e
  • f
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- a -

  • Action : tagExtraBytes
  • allowedModes : tagTrackObject

- b -

  • BaseMsgTime : EVENTHEADER_STRUCT , GLOBAL_STRUCT
  • bClrCycle : _PerWndInfo
  • bDrawing : _PerWndInfo
  • bMajor : tagWIN32SINFO
  • bMandel : _PerWndInfo
  • bMinor : tagWIN32SINFO
  • bSetDIBsToDevice : _PerWndInfo
  • bStretch : _PerWndInfo

- c -

  • c1 : _PerWndInfo
  • c2 : _PerWndInfo
  • CaptionBarText : _PerWndInfo
  • cbData : tagCOPYDATASTRUCT
  • cbTitle : tagControlText
  • cChild : _ENUMNODE
  • ccmd : _CMDI
  • clientRect : TRACKRECTSTRUCT
  • cmsd : _MSDI
  • cNetBuf : _ENUMSYNC
  • cs : _ENUMSYNC
  • csAllocGuard : growmemory , memory
  • cThread : _ENUMSYNC

- d -

  • descstring : tagApplets
  • dlgfn : tagApplets
  • dlgtemplate : tagApplets
  • dwData : tagCOPYDATASTRUCT
  • dwElapsed : _PerWndInfo
  • dwThreadId : _PerWndInfo

- e -

  • edwp : _MSDI , _CMDI
  • encodingID : tagTABLE
  • end : tagLookupEntry
  • entrySelector : tagSUBTABLE
  • EventMsg : GLOBAL_STRUCT

- f -

  • fDebug : tagWIN32SINFO
  • format : tagSUBTABLE
  • fPlaying : GLOBAL_STRUCT
  • fRecording : GLOBAL_STRUCT
  • fStopPlaying : GLOBAL_STRUCT
  • fStopRecording : GLOBAL_STRUCT

- h -

  • hBlock : memory
  • hbmpArray : _TLSOBJECT
  • hBmpSaved : _PerWndInfo
  • hbrushHL : _TLSOBJECT
  • hCurrentBlock : growmemory
  • hdc : tagTrackObject , TRACKRECTSTRUCT
  • hDefaultButton : tagControlText
  • hDlgMain : GLOBAL_STRUCT
  • hFile : GLOBAL_STRUCT
  • hfont : _TLSOBJECT
  • hhook : _MYHOOKDATA
  • hHookGetMsg : GLOBAL_STRUCT
  • hHookPlayback : GLOBAL_STRUCT
  • hHookRecord : GLOBAL_STRUCT
  • hHTPal : _PerWndInfo
  • hInstance : GLOBAL_STRUCT
  • hkprc : _MYHOOKDATA
  • hMutex : GLOBAL_STRUCT
  • hPal : _PerWndInfo
  • hParent : _PerWndInfo
  • hrgn : RGNSTRUCT
  • hSelectButton : tagControlText
  • hTextWnd : _PerWndInfo
  • hThrd : _PerWndInfo
  • hwnd : _ENUMSYNC , _PerWndInfo
  • hWndFileBox : tagTHREADPBLOCK
  • hWndGlobal : tagTHREADPBLOCK

- i -

  • iActualBlockSize : memory
  • icon : tagApplets
  • iCurrentPointer : memory
  • iCurrentPt : growmemory
  • iCurrentSize : growmemory
  • iElement : CHAINLIST
  • iIncrement : growmemory
  • iIteration : _PerWndInfo
  • iLoop : tagTHREADPBLOCK
  • ilpszCRLF : growmemory
  • iPen : _PerWndInfo
  • iStep : _PerWndInfo
  • iStretchMode : _PerWndInfo

- l -

  • LastMsgTime : GLOBAL_STRUCT
  • lc1 : _PerWndInfo
  • lc2 : _PerWndInfo
  • length : tagSUBTABLE
  • lpBasePointer : memory
  • lpcchServer : _TLSOBJECT
  • lpChild : _ENUMNODE
  • lpComment : _DISK_RESOURCES_CONNECTABLE
  • lpCurrentPointer : memory
  • lpData : tagCOPYDATASTRUCT
  • lpfnHelpProc : _TLSOBJECT
  • lpfnListProc : _TLSOBJECT
  • lplpnetBuf : _ENUMSYNC
  • lpNet : _ENUMNODE
  • lpNode : _ENUMOBJECT
  • lpProvider : _DISK_RESOURCES_CONNECTABLE
  • lpRemoteName : _DISK_RESOURCES_CONNECTABLE
  • lpReturnPointer : memory
  • lpRoot : _ENUMSYNC
  • lpStartPt : growmemory
  • lpSync : _TLSOBJECT , _ENUMOBJECT
  • lpszApiFailedMsg : GLOBAL_STRUCT
  • lpszCRLF : growmemory
  • lpszServer : _TLSOBJECT
  • lxFrom : _PerWndInfo
  • lxTo : _PerWndInfo
  • lyFrom : _PerWndInfo
  • lyTo : _PerWndInfo

- m -

  • Mode : tagTrackObject

- n -

  • n : tagMYREC
  • namestring : tagApplets
  • ndxBmp : _ENUMNODE
  • Next : tagTrackObject
  • nItem : _ENUMLISTOBJECT
  • nType : _MYHOOKDATA

- o -

  • Object : _ENUMLISTOBJECT
  • offset : tagTABLE

- p -

  • pfncmd : _CMD
  • pfnmsg : _MSD
  • pfnOldProc : tagExtraBytes
  • platformID : tagTABLE
  • PlayedMsgCount : GLOBAL_STRUCT
  • prghPen : _PerWndInfo
  • ptPosition : tagControlText

- r -

  • rangeShift : tagSUBTABLE
  • rcClient : _PerWndInfo
  • RecordedMsgCount : GLOBAL_STRUCT , EVENTHEADER_STRUCT
  • rect : tagTrackObject , tagExtraBytes
  • rectClip : tagTrackObject
  • rgcmd : _CMDI
  • rgmsd : _MSDI

- s -

  • s1 : tagMYREC
  • s2 : tagMYREC
  • searchRange : tagSUBTABLE
  • segCountX2 : tagSUBTABLE
  • Signature : EVENTHEADER_STRUCT
  • start : tagLookupEntry
  • String : tagLookupEntry
  • szSavef : _PerWndInfo
  • szTitle : tagControlText

- t -

  • tm : _TLSOBJECT
  • trackRect : TRACKRECTSTRUCT
  • type : RGNSTRUCT

- u -

  • uMessage : _MSD

- v -

  • Value : tagLookupEntry
  • version : tagSUBTABLE

- w -

  • wBuildNumber : tagWIN32SINFO
  • wCommand : _CMD

- x -

  • xfmChange : tagTrackObject
  • xfmDown : tagTrackObject
  • xFrom : _PerWndInfo
  • xOrigin : TRACKRECTSTRUCT
  • xTo : _PerWndInfo

- y -

  • yFrom : _PerWndInfo
  • yOrigin : TRACKRECTSTRUCT
  • yTo : _PerWndInfo
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- j -

  • JournalPlaybackProc() : RECHOOK.C
  • JournalRecordProc() : RECHOOK.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- k -

  • KeyboardProc() : HOOKTEST.C , HOOKTEST.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- l -

  • langstrings : LOCALE.H
  • LASTSTRING : WORLD.C
  • lConThreadId : BNDBUFC.C
  • lf : CMNDLG.C
  • LibMain() : DLL16.C
  • LineCaps : GETDEV.H
  • LINEINC : WORLD.C
  • ListBoxExample() : OWNCOMBO.C , OWNCOMBO.H
  • ListSubProc() : ENUMDLG.C , ENUMDLG.H
  • LoadBitmapArray() : ENUMUTIL.C , ENUMUTIL.H
  • LoadLibraryEx32W() : MYUT.H
  • LOCAL_DEVICE_NAME : WINNET.C
  • localeentry : LOCALE.H
  • logfont : DISPLAY.C
  • logfontsmall : STATUS.C
  • LOGNAME : LOG.C
  • LOGSOURCE : LOG.C
  • LONG2POINT : MENU.H
  • LookupEntry : GETDEV.H , GETSYS.H , LOCALE.H , MASKBLT.H , STREBLT.H , DISPLAY.H
  • lookupStringFromMsgDll() : LOG.C
  • lpBufPtr : CMNDLG.C
  • lpClipData : CLIPTEXT.C
  • LPCMDI : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • LPCONTROLTEXT : BOB.H
  • LPCOPYDATASTRUCT : APP16.C
  • LPCSTR : UTDLL32.C
  • lpData : CLIPTEXT.C
  • LPDISK_RESOURCES_CONNECTABLE : WINNET.C
  • LPENUMLISTOBJECT : ENUMUTIL.H
  • LPENUMNODE : ENUMUTIL.H
  • LPENUMOBJECT : ENUMUTIL.H
  • LPENUMSYNC : ENUMUTIL.H
  • lpfnOldEditProc : GUIGREP.C
  • lpFR : CMNDLG.C
  • LPMSDI : DLLDISP.H , GLOBALS.H
  • lProdThreadId : BNDBUFC.C
  • LPSTR : DLL16.C
  • lpszCRLF : GUIGREP.C
  • lpszPort : OVCOMM.H
  • lpszSerialSpec : OVCOMM.H
  • lpTB : GUIGREP.C
  • LPTHREADPBLOCK : GUIGREP.H
  • LPTLSOBJECT : ENUMUTIL.H
  • LPTSTR : PLATFORM.C
  • LPVOID : UTDLL32.C
  • LPWIN32SINFO : DLL16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- m -

  • MACHINE : LOG.C
  • main() : ASYN_IO.C , BNDBUFS.C , DRIVES.C , READWRIT.C , STARTP.C , DRIVES.H , TERMPROC.C , TLSCALL.C , CHGDATA.C , ASYN_IO.C , WALK.C , WALK.H , CHILD.C , WINNET.C , BNDBUFC.C , READDATA.C , INHERIT.C , IOCOMP.C , COLOR.C , LOG.C , OVCOMM.C
  • MainDlgProc() : GETDEV.C , GETDEV.H , GETSYS.C , GETSYS.H , LOCALE.C , LOCALE.H , MINREC.C
  • MainWndProc() : CLIPTEXT.C , SETINFO.H , SHAREMEM.C , CMNDLG.C , SHAREMEM.H , LINKTEST.C , CMNDLG.H , LINKTEST.H , LOADTEST.C , CURSOR.C , LOADTEST.H , STREBLT.C , CURSOR.H , STREBLT.H , SUBCLASS.C , GLTHREAD.C , SUBCLASS.H , THREADS.C , GUIGREP.H , THREADS.H , TIMERS.C , NTGREP.C , TIMERS.H , UNIPUT.C , HOOKTEST.C , UNIPUT.H , VIRTMEM.C , HOOKTEST.H , VIRTMEM.H , WORLD.C , APP16.C , DISP32.C , STUB32.C , MASKBLT.C , MASKBLT.H , MDI.C , OTHRPROC.C , OTHRPROC.H , PATHS.C , PATHS.H , PLATFORM.C , PLATFORM.H , POLYDRAW.C , POLYDRAW.H , REGIONS.C , REGIONS.H , MAIN.C , BOB.C , MAIN.H , SEMA.C , BOB.H , SEMA.H , SETINFO.C
  • MallocMem() : MEM.C , MEM.H , MEM.C , MEM.H
  • MapView : OTHRPROC.C , SHAREMEM.C
  • MarkOutstanding() : THRDUTIL.C , THRDUTIL.H
  • MasterBlock : GUIGREP.C
  • MAX : DATABASE.C , READWRIT.C , MACROS.H
  • MAX_CONCURRENT_THREADS : GUIGREP.H
  • MAX_ITEM : COMMON.H
  • MAX_MSG_LENGTH : LOG.C
  • MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST : WINNET.C
  • MAX_NUMBER_OF_RESOURCES_TO_ENUM : WINNET.C
  • MAX_READ_BUFFER : OVCOMM.H
  • MAX_SIZE : COMMON.H
  • MAX_WRITE_BUFFER : OVCOMM.H
  • MAXCALLS : COMMON.H
  • MAXCHARS : MASKBLT.H , STREBLT.H , SUBCLASS.H , STATUS.C
  • MAXCOLORS : COLOR.H
  • MAXDOUBLELEN : FRACTAL.H
  • MAXINPUT : WORLD.C
  • MAXLINELEN : GUIGREP.H
  • MAXPATHLEN : FRACTAL.H
  • MAXPOINTS : POLYDRAW.H
  • MAXRGNSTRUCTS : REGIONS.H
  • MAXSEGMENTS : DISPLAY.C
  • MAXTCHAR : LOCALE.H
  • MBERROR : UNIPUT.H
  • MBERRORFLAGS : UNIPUT.H
  • MBGETFONTDATAERR : UNIPUT.H
  • MDIWndProc() : MDI.C
  • MEASUREITEMHEIGHT : MENU.H
  • MEASUREITEMWIDTH : MENU.H
  • MemInfo : VIRTMEM.C
  • MenuInit() : MENU.H , MENU.C
  • MenuWndProc() : MENU.C , MENU.H
  • MessageProc() : HOOKTEST.C , HOOKTEST.H
  • MIDL_user_allocate() : BNDBUFC.C , BNDBUFS.C
  • MIDL_user_free() : BNDBUFC.C , BNDBUFS.C
  • MIN : MACROS.H
  • MINMASK : SETINFO.H
  • MINREC_FILENAME : RECHOOK.C
  • MINREC_SIGNATURE : RECHOOK.C
  • MINSHIFT : SETINFO.H
  • MINSIZE : SUBCLASS.H
  • MM_ABOUT : MDI.H
  • MM_MDI : MDI.H
  • MM_OPT_1 : MDI.H
  • MM_OPT_2 : MDI.H
  • MM_OPT_3 : MDI.H
  • MM_OPT_4 : MDI.H
  • MM_OPT_5 : MDI.H
  • MM_OPT_6 : MDI.H
  • MM_OPT_7 : MDI.H
  • MM_OPT_8 : MDI.H
  • MM_RESERVE1 : MDI.H
  • MM_RESERVE2 : MDI.H
  • MONMASK : SETINFO.H
  • MONSHIFT : SETINFO.H
  • MouseMove() : TRACK.C , TRACK.H
  • MouseProc() : HOOKTEST.H , HOOKTEST.C
  • move : DEBUG.C
  • MPOINT : CURSOR.H
  • MPOINT2POINT : CURSOR.H
  • MSD : GLOBALS.H , DLLDISP.H
  • MSDI : GLOBALS.H , DLLDISP.H
  • msdiAbout : ABOUT.C
  • msdiConnectDlg : CONNECT.C
  • msdiEnumDlg : ENUMDLG.C
  • msdiMain : GLOBALS.H , NDDECHAT.C , GLOBALS.H , BROWSE.C
  • MSG_ID_MASK : LOG.C
  • MsgAboutCommand() : ABOUT.C
  • MsgAboutInit() : ABOUT.C
  • MsgCommand() : BROWSE.C , NDDECHAT.C , GLOBALS.H
  • MsgConnect() : GLOBALS.H , NDDECHAT.C
  • MsgConnectDlgCommand() : CONNECT.C
  • MsgConnectDlgInit() : CONNECT.C
  • MsgCreate() : BROWSE.C , GLOBALS.H , NDDECHAT.C
  • MsgDestroy() : NDDECHAT.C , GLOBALS.H , BROWSE.C
  • MsgDisconnect() : GLOBALS.H , NDDECHAT.C
  • MsgEnumDlgCharToItem() : ENUMDLG.C
  • MsgEnumDlgCommand() : ENUMDLG.C
  • MsgEnumDlgDestroy() : ENUMDLG.C
  • MsgEnumDlgDrawItem() : ENUMDLG.C
  • MsgEnumDlgEnumExpand() : ENUMDLG.C
  • MsgEnumDlgInit() : ENUMDLG.C
  • MsgEnumDlgInitEnum() : ENUMDLG.C
  • MsgEnumDlgMeasureItem() : ENUMDLG.C
  • MsgEnumDlgSetCursor() : ENUMDLG.C
  • MsgEnumDlgSysColor() : ENUMDLG.C
  • MsgEnumDlgVKeyToItem() : ENUMDLG.C
  • MsgReceiveText() : NDDECHAT.C , GLOBALS.H
  • MsgSetFocus() : GLOBALS.H
  • MsgSize() : NDDECHAT.C , GLOBALS.H
  • MUTX1 : DATABASE.C
  • MyCombineRgn() : REGIONS.C , REGIONS.H
  • MyCreateRgn() : REGIONS.H , REGIONS.C
  • myError() : CHILD.C
  • MyHelpMessage : FRACTAL.H
  • myhookdata : HOOKTEST.C
  • MYHOOKDATA : HOOKTEST.C
  • MYMAIN : REBOOT.C
  • MyPrint() : DLL32.C , DLL16.C , APP16.C
  • MYPRINT : MYUT.H
  • MyPrint() : UTDLL32.C , DISP32.C
  • MYREC : DISP32.C , APP16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- n -

  • nAge : APP16.C
  • NBYTES : DISPLAY.C
  • NClipCaps : GETDEV.H
  • NCurveCaps : GETDEV.H
  • NDevice : GETDEV.H
  • ndxTls : ENUMDLG.C , SERVENUM.C
  • NewAngleArc() : PATHS.C , PATHS.H
  • NINDEX : GETDEV.H
  • NITER : CURSOR.C
  • NLANG : LOCALE.H
  • NLineCaps : GETDEV.H
  • NLOCALEENTRIES : LOCALE.H
  • NMODES : STREBLT.H
  • NOMINMAX : ASYN_IO.C , DATABASE.C , READWRIT.C
  • NONE : MASKBLT.C , POLYDRAW.H , STREBLT.C
  • notifyChange() : LOG.C
  • NPATTERNS : MASKBLT.H , STREBLT.H
  • NPolygonalCaps : GETDEV.H
  • NRANGE : DISPLAY.H
  • NRasterCaps : GETDEV.H
  • NROPS : STREBLT.H , MASKBLT.H
  • nSegments : DISPLAY.C
  • NSYSCOLORS : GETSYS.H
  • NTextCaps : GETDEV.H
  • NUM_APPLETS : STEREO.C
  • NUM_HANDLES : ENUMTHRD.H
  • NUMBER_OF_WRITES : IOCOMP.C
  • NumberOfWrites : IOCOMP.C
  • NUMCHARS : DISPLAY.C
  • NUMHOOKS : HOOKTEST.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- o -

  • OEMRESOURCE : BOB.C
  • OFFSETERROR : DISPLAY.C
  • OldButtonProc : BOB.C
  • oldrect : THREADS.C
  • oneto8 : THREADS.C
  • Open_Do_Close_1_Enum() : WINNET.C
  • openDisplay() : UNIPUT.H , DISPLAY.C
  • OpenEnum() : WINNET.C
  • OpenFileName : CMNDLG.C , WORLD.C
  • OpenMetafile() : WORLD.C
  • OpenNewFile() : UNIPUT.C , CMNDLG.C , CMNDLG.H
  • OrgX : CURSOR.C
  • OrgY : CURSOR.C
  • OutOfMemory() : CLIPTEXT.C
  • OutputABuffer() : OVCOMM.C
  • OwnComboInit() : OWNCOMBO.C , OWNCOMBO.H
  • OwnComboWndProc() : OWNCOMBO.C , OWNCOMBO.H
  • OwnerComboBoxExample() : OWNCOMBO.C , OWNCOMBO.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- a -

  • About() : BOB.C , BOB.H , CMNDLG.C , GUIGREP.C , ABOUT.C , MDI.C , GUIGREP.C , OWNCOMBO.C , OWNCOMBO.H , CMNDLG.H , GUIGREP.H , PLATFORM.C , PLATFORM.H , NTGREP.C , UNIPUT.C , UNIPUT.H , CLIPTEXT.C , CURSOR.C , NTGREP.C , MDI.C , CURSOR.H , MENU.C , MENU.H
  • AboutDlgProc() : WORLD.C , APP16.C , MINREC.C , REGIONS.C , REGIONS.H , LINKTEST.C , LINKTEST.H , LOADTEST.C , LOADTEST.H
  • ACCEL_ID : MDI.H
  • ACTIONMOVE : SUBCLASS.H
  • ACTIONNONE : SUBCLASS.H
  • ACTIONSIZEX : SUBCLASS.H
  • ACTIONSIZEXY : SUBCLASS.H
  • ACTIONSIZEY : SUBCLASS.H
  • AddGetGetCancel() : WINNET.C
  • AddGetGetCancel2() : WINNET.C
  • addSourceToRegistry() : LOG.C
  • AID_COPY : STREBLT.H , MASKBLT.H
  • AID_CYCLE : STREBLT.H , MASKBLT.H
  • AID_PASTE : MASKBLT.H , STREBLT.H
  • AMP_DESC : STEREO.H
  • AMP_DLG : STEREO.H
  • AMP_ICON : STEREO.H
  • AMP_NAME : STEREO.H
  • AmpDlgProc() : STEREO.H , STEREO.C
  • Another_Thread() : TLSCALL.C
  • APIENTRY : WIN16EXT.H
  • APPLETS : STEREO.C
  • APPNAME : GLOBALS.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- b -

  • BACKGROUND_COLOR : COLOR.H
  • base : VIRTMEM.C
  • bCaseInsens : GUIGREP.C
  • bColorCycle() : FRACTAL.C
  • bDone : OVCOMM.H
  • bFileJustOpen : WORLD.C
  • bFileOpen : WORLD.C
  • bGetPPStr() : FRACTAL.C
  • bInitDlgItems() : FRACTAL.C
  • bInitInfo() : FRACTAL.C
  • BITMAP_HEIGHT : ENUMUTIL.H
  • BITMAP_START : ENUMUTIL.H
  • BITMAP_WIDTH : ENUMUTIL.H
  • BLUE : SEMA.H
  • BOB : BOB.H
  • bObjectExists : GUIGREP.C
  • BOOL() : UTDLL32.C
  • BreakDownCommPort() : OVCOMM.C , OVCOMM.H
  • bSetupPixelFormat() : GLTHREAD.H , THREADS.C
  • bTrack : CURSOR.C
  • Buf : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • Buf2 : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • buffer : COMMON.H , GETDEV.H , GETSYS.H , BNDBUFS.C
  • Buffer : IOCOMP.C
  • buffer : BNDBUFP.C
  • BUFFER_SIZE : IOCOMP.C
  • BufferSize : IOCOMP.C
  • BUFSIZE : TIMERS.H , THE_DLL.H , WALK.H , DRIVES.C
  • BUTTONBORDER : TIMERS.H
  • BUTTONHEIGHT : TIMERS.H
  • ButtonProc() : BOB.H , BOB.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- c -

  • CalculateVectorNormal() : GLTHREAD.H , THREADS.C
  • CallFindText() : CMNDLG.H , CMNDLG.C
  • CallProc32W() : MYUT.H
  • CallReplaceText() : CMNDLG.C , CMNDLG.H
  • CallWndProc() : HOOKTEST.C , HOOKTEST.H
  • CBTProc() : HOOKTEST.C , HOOKTEST.H
  • CCERR_CHOOSECOLORCODES : CDERR.H
  • CDERR_DIALOGFAILURE : CDERR.H
  • CDERR_FINDRESFAILURE : CDERR.H
  • CDERR_GENERALCODES : CDERR.H
  • CDERR_INITIALIZATION : CDERR.H
  • CDERR_LOADRESFAILURE : CDERR.H
  • CDERR_LOADSTRFAILURE : CDERR.H
  • CDERR_LOCKRESFAILURE : CDERR.H
  • CDERR_MEMALLOCFAILURE : CDERR.H
  • CDERR_MEMLOCKFAILURE : CDERR.H
  • CDERR_NOHINSTANCE : CDERR.H
  • CDERR_NOHOOK : CDERR.H
  • CDERR_NOTEMPLATE : CDERR.H
  • CDERR_STRUCTSIZE : CDERR.H
  • CenterWindow() : GLOBALS.H , MISC.C , GLOBALS.H , MISC.C , MISCUTIL.C , MISCUTIL.H
  • CFERR_CHOOSEFONTCODES : CDERR.H
  • CFERR_NOFONTS : CDERR.H
  • CHAINLIST : SHRSTUFF.H
  • chBuffer : DRIVES.C
  • CheckModemStatus() : OVCOMM.C
  • CheckRM() : DRIVES.C , DRIVES.H
  • chf : CMNDLG.C
  • ChooseColorHookProc() : CMNDLG.C , CMNDLG.H
  • ChooseFontHookProc() : CMNDLG.C , CMNDLG.H
  • ChooseNewColor() : CMNDLG.C , CMNDLG.H
  • ChooseNewFont() : CMNDLG.C , CMNDLG.H
  • chPathName : WALK.H
  • chsclr : CMNDLG.C
  • chTlsCount : TLSDLL.C
  • clBasePt : SHRSTUFF.H
  • CleanupApp() : DATABASE.C
  • CleanupSubsystem() : DATABASE.C
  • ClipCaps : GETDEV.H
  • CLIPPATHALT : PATHS.H
  • CLIPPATHWIND : PATHS.H
  • CloseDataBase() : DATABASE.C
  • closeDisplay() : DISPLAY.C , UNIPUT.H
  • CMAPHEX : DISPLAY.C
  • CMD : GLOBALS.H , DLLDISP.H
  • CmdAbout() : ABOUT.C , GLOBALS.H
  • CmdAboutDone() : ABOUT.C
  • CmdConnectDlg() : GLOBALS.H , NDDECHAT.C
  • CmdConnectDlgCancel() : CONNECT.C
  • CmdConnectDlgOK() : CONNECT.C
  • CmdDisconnect() : NDDECHAT.C , GLOBALS.H
  • CmdEnumDlg() : BROWSE.C , GLOBALS.H
  • CmdEnumDlgBrowse() : ENUMDLG.C
  • CmdEnumDlgCancel() : ENUMDLG.C
  • CmdEnumDlgHelp() : ENUMDLG.C
  • CmdEnumDlgOK() : ENUMDLG.C
  • CmdEnumHelpDlg() : GLOBALS.H , BROWSE.C
  • CmdExit() : GLOBALS.H , NDDECHAT.C , BROWSE.C , GLOBALS.H
  • CMDI : GLOBALS.H , DLLDISP.H
  • cmdiAbout : ABOUT.C
  • cmdiConnectDlg : CONNECT.C
  • cmdiEnumDlg : ENUMDLG.C
  • cmdiMain : BROWSE.C , GLOBALS.H , NDDECHAT.C , GLOBALS.H
  • CmdSendNotify() : NDDECHAT.C , GLOBALS.H
  • Color : COLOR.H
  • ColorWndProc() : GUIGREP.C
  • ComboBoxExample() : OWNCOMBO.H , OWNCOMBO.C
  • comHandle : OVCOMM.H
  • CommandHandler() : GLTHREAD.C
  • CompareEnumNode() : ENUMUTIL.H , ENUMUTIL.C
  • ComponentFromIndex() : THREADS.C
  • con_buf_pos : BNDBUFP.C , COMMON.H
  • ConnectablesList : WINNET.C
  • ConnectDlg() : CONNECT.C , CONNECT.H
  • consumer() : BNDBUFC.C
  • ControlHandlerProc() : OVCOMM.C
  • CONTROLTEXT : BOB.H
  • COPYDATASTRUCT : APP16.C
  • CountUCSegments() : DISPLAY.C
  • CPCAPTION : STEREO.H
  • CPlApplet() : STEREO.C , STEREO.H
  • crColor : CMNDLG.C
  • cRead : DATABASE.C
  • cReadQueue : DATABASE.C
  • cReadQueueEx : DATABASE.C
  • CreateRGBPalette() : THREADS.C
  • CreateStdFont() : MISCUTIL.H , MISCUTIL.C
  • currRgn : REGIONS.H
  • CurveCaps : GETDEV.H
  • cWrite : DATABASE.C
  • cWriteQueue : DATABASE.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- d -

  • DataBase : DATABASE.C
  • DAYMASK : SETINFO.H
  • DAYSHIFT : SETINFO.H
  • DdeCallback() : DDECBACK.C , DDECBACK.H
  • DebugMsg() : DATABASE.C
  • DebugProc() : HOOKTEST.H , HOOKTEST.C
  • DEFAULT : ASYN_IO.C
  • DEFAULTBUTTON : BOB.H
  • DevCaps : GETDEV.H
  • Device : GETDEV.H
  • DIALOGHEIGHT : SHAREMEM.H , STREBLT.H , MASKBLT.H , OTHRPROC.H , SETINFO.H
  • DID_CB_MODE : MASKBLT.H , STREBLT.H
  • DID_CB_PATTERN : MASKBLT.H , STREBLT.H
  • DID_CB_ROPS : MASKBLT.H , STREBLT.H
  • DID_COMBOBOX : LOCALE.H
  • DID_DIRECTORY : GETSYS.H
  • DID_DRAW : MASKBLT.H , STREBLT.H
  • DID_HEIGHT : MASKBLT.H , STREBLT.H
  • DID_INFO : GETSYS.H
  • DID_LISTBOX : GETSYS.H , LOCALE.H , GETDEV.H
  • DID_LOCALTIME : GETSYS.H
  • DID_METRICS : GETSYS.H
  • DID_NEWMASK : MASKBLT.H
  • DID_NEWSRC : MASKBLT.H , STREBLT.H
  • DID_PALETTE : GETSYS.H
  • DID_ROP0 : MASKBLT.H , STREBLT.H
  • DID_ROP1 : MASKBLT.H , STREBLT.H
  • DID_ROP2 : MASKBLT.H , STREBLT.H
  • DID_ROP3 : MASKBLT.H
  • DID_SRCHEIGHT : STREBLT.H
  • DID_SRCWIDTH : STREBLT.H
  • DID_SYSCOLORS : GETSYS.H
  • DID_TEXT : GETSYS.H , LOCALE.H
  • DID_TIME : GETSYS.H
  • DID_VERSIONEX : GETSYS.H
  • DID_WIDTH : MASKBLT.H , STREBLT.H
  • DID_X : MASKBLT.H , STREBLT.H
  • DID_XMASK : MASKBLT.H
  • DID_XSRC : MASKBLT.H , STREBLT.H
  • DID_Y : MASKBLT.H , STREBLT.H
  • DID_YMASK : MASKBLT.H
  • DID_YSRC : MASKBLT.H , STREBLT.H
  • dinfo() : DEBUG.C
  • DISABLE_COMBINERGN : REGIONS.H
  • DISK_RESOURCES_CONNECTABLE : WINNET.C
  • DispCommand() : DISPATCH.C , GLOBALS.H , DISPATCH.C , GLOBALS.H , DLLDISP.C , DLLDISP.H
  • DispDefault() : DISPATCH.C , DLLDISP.C
  • DISPLAYCLASS : UNIPUT.H
  • DisplayError() : REBOOT.C
  • DisplayWndProc() : DISPLAY.C , UNIPUT.H
  • DispMessage() : DISPATCH.C , GLOBALS.H , DISPATCH.C , GLOBALS.H , DLLDISP.C , DLLDISP.H
  • DlgProc() : STREBLT.H , MASKBLT.C , MASKBLT.H , STREBLT.C
  • DLGPROC : WIN16EXT.H
  • DLLBITMAP_HEIGHT : THE_DLL.H
  • DLLBITMAP_WIDTH : THE_DLL.H
  • DLLDialogBox() : THE_DLL.C , THE_DLL.H
  • DLLDlgProc() : THE_DLL.C , THE_DLL.H
  • DLLFunction1() : THE_DLL.C , THE_DLL.H
  • DLLFunction2() : THE_DLL.C , THE_DLL.H
  • DLLFunction3() : THE_DLL.C , THE_DLL.H
  • DLLFunction4() : THE_DLL.C , THE_DLL.H
  • DllMain() : STEREO.C , RECHOOK.C , GUIGREP.C , DLL32.C , UTDLL32.C , DEBUG.C , DATABASE.C , SERVENUM.C , TLSDLL.C , THE_DLL.C
  • Do_BackgroundTask() : ASYN_IO.C
  • doDirectory() : GETSYS.C , GETSYS.H
  • doInfo() : GETSYS.C , GETSYS.H
  • doLocalTime() : GETSYS.C , GETSYS.H
  • DOM_NDX : ENUMUTIL.H
  • DOMAIN_BMP : ENUMDLG.H
  • DOMAINEX_BMP : ENUMDLG.H
  • doMetrics() : GETSYS.C , GETSYS.H
  • DOMEX_NDX : ENUMUTIL.H
  • doPalette() : GETSYS.H , GETSYS.C
  • doSysColors() : GETSYS.H , GETSYS.C
  • doTime() : GETSYS.H , GETSYS.C
  • doTrackObject() : TRACK.H , TRACK.C
  • doVersionEx() : GETSYS.C , GETSYS.H
  • draw_scene() : GLTHREAD.H , THREADS.C
  • DrawBitmap() : BOB.H , BITMAP.H , MAIN.H , MAIN.C , BOB.C , BITMAP.C
  • DrawEntireItem() : OWNCOMBO.C
  • DrawGrids() : STREBLT.C , MASKBLT.H , MASKBLT.C , STREBLT.H
  • DrawPath() : PATHS.C , PATHS.H
  • DrawStuff() : TIMERS.C , TIMERS.H
  • DrawWave() : GLTHREAD.H , THREADS.C
  • DRIVE_CDROM : DRIVES.H
  • DRIVE_FIXED : DRIVES.H
  • DRIVE_RAMDISK : DRIVES.H
  • DRIVE_REMOTE : DRIVES.H
  • DRIVE_REMOVEABLE : DRIVES.H
  • dwDiskListI : WINNET.C
  • dwFileSize : CMNDLG.C
  • DWORD : DLL16.C
  • dwResourcesEnumedSoFar : WINNET.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- e -

  • EDWP : GLOBALS.H , DLLDISP.H
  • edwpDialog : GLOBALS.H , DLLDISP.H
  • edwpMDIChild : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • edwpMDIFrame : GLOBALS.H , DLLDISP.H
  • edwpNone : GLOBALS.H , DLLDISP.H
  • edwpWindow : GLOBALS.H , DLLDISP.H
  • ellipseRect : REGIONS.H
  • ELLIPTIC_RGN : REGIONS.H
  • ENABLE_COMBINERGN : REGIONS.H
  • ENABLE_OPTIONS : REGIONS.H
  • endCount : DISPLAY.C
  • enter_item() : BNDBUFP.C
  • EnterNew() : CMNDLG.C , CMNDLG.H
  • EnumContainerThread() : ENUMTHRD.C , ENUMTHRD.H
  • EnumDlg() : ENUMDLG.C , ENUMDLG.H
  • EnumExpandThread() : ENUMTHRD.H , ENUMTHRD.C
  • EnumListCollapse() : ENUMUTIL.C , ENUMUTIL.H
  • EnumListExpand() : ENUMUTIL.C , ENUMUTIL.H
  • ENUMLISTOBJECT : ENUMUTIL.H
  • EnumListRecurse() : ENUMUTIL.C , ENUMUTIL.H
  • ENUMNODE : ENUMUTIL.H
  • ENUMOBJECT : ENUMUTIL.H
  • EnumResources() : WINNET.C
  • ENUMSYNC : ENUMUTIL.H
  • EPSILON : TRACK.C , SUBCLASS.H
  • ERROR_BUFFER_SIZE : MINREC.C
  • ERROR_CANCELLED : SERVENUM.H , ENUMDLG.C , SERVENUM.H
  • ERROR_FAILURE : ENUMTHRD.H
  • ERROR_NOT_ENOUGH_MEMORY : MEM.H
  • ERROR_SUCCESS : MEM.H
  • ErrorHandler() : OVCOMM.C
  • ErrorInComm() : OVCOMM.C
  • ErrorMessageBox() : MINREC.C
  • ErrorMsg() : DATABASE.C , ASYN_IO.C
  • ErrorOut() : TLSCALL.C , FRACTAL.C , TERMPROC.C , TLSDLL.C
  • ErrorReporter() : OVCOMM.C
  • EVENT1 : DATABASE.C
  • EVENT2 : DATABASE.C
  • EVENT3 : DATABASE.C
  • EVENT4 : DATABASE.C
  • EVENT_FLAGS : OVCOMM.H
  • EVENTHEADER : RECHOOK.C
  • EVT_CHAR : OVCOMM.H
  • ExpandInfo() : GETDEV.H , GETDEV.C
  • ExtraBytes : SUBCLASS.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- f -

  • FAILURE : COMMON.H
  • FARPROC : UTDLL32.C
  • fBufferdIo : IOCOMP.C
  • FILBUFSIZE : GUIGREP.H
  • FILE_LEN : CMNDLG.H
  • FileBuf : CMNDLG.C
  • FileDlgProc() : SETINFO.H , SETINFO.C
  • FileName : IOCOMP.C
  • FileOpenHookProc() : CMNDLG.C , CMNDLG.H
  • FileSaveHookProc() : CMNDLG.C , CMNDLG.H
  • FILLPATH : PATHS.H
  • FindFirstDirectory() : WALK.H , WALK.C
  • FindNextDirectory() : WALK.C
  • FindReplaceMsg : CMNDLG.C
  • FindTextHookProc() : CMNDLG.C , CMNDLG.H
  • FIRST_PIXEL : FRACTAL.H
  • FIRSTSTRING : WORLD.C
  • FixMenu() : LOADTEST.C , LOADTEST.H
  • flags : CURSOR.C
  • FMExtensionProc() : GUIGREP.C
  • FNERR_BUFFERTOOSMALL : CDERR.H
  • FNERR_FILENAMECODES : CDERR.H
  • FNERR_INVALIDFILENAME : CDERR.H
  • FNERR_SUBCLASSFAILURE : CDERR.H
  • FontHeight : DISPLAY.C
  • FontWidth : DISPLAY.C
  • FPSERVENUMDLG : BROWSE.C
  • framechildwindow() : STATUS.C
  • FreeEnumChild() : ENUMUTIL.C , ENUMUTIL.H
  • FreeEnumSync() : ENUMUTIL.C , ENUMUTIL.H
  • FreeLibrary32W() : MYUT.H
  • FreeMem() : MEM.H , MEM.C , MEM.H
  • FRERR_FINDREPLACECODES : CDERR.H
  • frText : CMNDLG.C
  • fSequentialNew : IOCOMP.C
  • fTestMode : SUBCLASS.H
  • fWin32s : DLL16.C , STUB32.C
  • FWW_STEPS : UNIPUT.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- g -

  • g_csOutstanding : THRDUTIL.C , THRDUTIL.H
  • g_fState : NDDECHAT.C , GLOBALS.H
  • g_hInstNetDde : GLOBALS.H , WINMAIN.C
  • g_hLibrary : BROWSE.C
  • g_hMod : ENUMUTIL.C , SERVENUM.C
  • g_hwnd : GLOBALS.H , NDDECHAT.C , BROWSE.C
  • g_idInst : GLOBALS.H , NDDECHAT.C
  • g_lpfnServEnumDlg : BROWSE.C
  • g_lphOutstanding : THRDUTIL.C
  • g_nOutstanding : THRDUTIL.C
  • g_szServer : GLOBALS.H , NDDECHAT.C
  • g_szTopic : GLOBALS.H , NDDECHAT.C
  • g_timeouts : OVCOMM.H
  • gaFlashRects : TIMERS.H
  • gahwndButtons : TIMERS.H
  • gbStretch : FRACTAL.H
  • GET_WM_COMMAND_CMD : WIN16EXT.H
  • GET_WM_COMMAND_HWND : WIN16EXT.H
  • GET_WM_COMMAND_ID : WIN16EXT.H
  • GetBitmap() : BITMAP.H , BITMAP.C , BITMAP.H , BITMAP.C
  • GetConsoleTextAttribute() : COLOR.C , COLOR.H
  • GetData() : DATABASE.C
  • GetDataToTrans() : GLOBALS.H , NDDECHAT.C
  • GETHWND : MYUT.H
  • GetMsgProc() : HOOKTEST.C , HOOKTEST.H , RECHOOK.C
  • GetProcAddress32W() : MYUT.H
  • gFloat : FRACTAL.H
  • ghDLL : STUB32.C , UTDLL32.C
  • ghInst : BOB.C , DLL16.C , TIMERS.H
  • ghInstance : APP16.C , WORLD.C
  • ghLib : DLL16.C , MAIN.H
  • ghMod : THE_DLL.H
  • ghModule : MDI.C
  • ghMutex : DATABASE.C
  • ghPalette : GLTHREAD.C , THREADS.C
  • ghpalOld : GLTHREAD.C , THREADS.C
  • ghReadEvent1 : DATABASE.C
  • ghReadEvent2 : DATABASE.C
  • ghSemaphore : DATABASE.C
  • ghWnd : BOB.C , GLTHREAD.C , THREADS.C , APP16.C , DLL16.C , UTDLL32.C
  • ghwndClient : MDI.C
  • ghwndMain : MDI.C , LINKTEST.H , LOADTEST.H
  • ghWriteEvent1 : DATABASE.C
  • ghWriteEvent2 : DATABASE.C
  • giDmOrient : FRACTAL.H
  • gInfo : FRACTAL.H
  • giNPrinters : FRACTAL.H
  • giPen : FRACTAL.H
  • giStretchMode : FRACTAL.H
  • gIteration : FRACTAL.H
  • GLOBAL : MINREC.C , RECHOOK.C
  • gpfnDLLDialogBox : LOADTEST.H
  • gpfnDLLFunction1 : LOADTEST.H
  • gpfnDLLFunction2 : LOADTEST.H
  • gpfnDLLFunction3 : LOADTEST.H
  • gpfnDLLFunction4 : LOADTEST.H
  • gpUTCBack : DLL16.C
  • GRAY : SEMA.H
  • GREEN : SEMA.H , THREADS.H
  • GRIDCOLOR : UNIPUT.C , MASKBLT.H , STREBLT.H
  • gShowhex : UNIPUT.C , UNIPUT.H
  • gShowNames : UNIPUT.C , UNIPUT.H
  • gStep : FRACTAL.H
  • gszFile : MDI.C
  • gszMapName : MDI.C
  • gtext : FRACTAL.H
  • gUserCount : DATABASE.C
  • GVI() : DRIVES.C , DRIVES.H
  • GWLU_NCHAR : DISPLAY.C
  • GWLU_SQRHEIGHT : DISPLAY.C
  • GWLU_SQRWIDTH : DISPLAY.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- h -

  • hAccTable : CLIPTEXT.C
  • HANDLE_DOM : ENUMTHRD.H
  • HANDLE_PROV : ENUMTHRD.H
  • HANDLE_SERV : ENUMTHRD.H
  • HandleChangeColors() : MENU.C
  • HandleCreate() : MENU.C
  • HandleDrawItem() : MENU.C
  • HandleFocusState() : BOB.C , BOB.H , OWNCOMBO.C
  • HandlePaint() : MENU.C
  • HandlePopupMenu() : MENU.C
  • HandleSelectedState() : BOB.C , BOB.H
  • HandleSelectionState() : OWNCOMBO.C
  • hBigMenu : MENU.C
  • hbmCheckOff : MENU.C
  • hbmCheckOn : MENU.C
  • hbmMask : MASKBLT.C
  • hbmMemXOR : DISPLAY.C
  • hbmSrc : MASKBLT.C , STREBLT.C
  • hChildMenu : MDI.C
  • hChildMenuWindow : MDI.C
  • hClipData : CLIPTEXT.C
  • hConThrd : BNDBUFC.C
  • hconv : NDDECHAT.C
  • hData : CLIPTEXT.C
  • hdcDest : STREBLT.C , MASKBLT.C
  • hdcMask : MASKBLT.C
  • hdcMemXOR : DISPLAY.C
  • hdcSrc : MASKBLT.C , STREBLT.C
  • hDlgFR : CMNDLG.C
  • help() : STARTP.C
  • HelpProc() : BROWSE.C
  • hEMF : WORLD.C
  • hEmptySem : BNDBUFP.C , BNDBUFS.C , COMMON.H
  • HEVENT : ASYN_IO.C , DATABASE.C
  • hFile : UNIPUT.C
  • HFILEEX : ASYN_IO.C
  • hFontCopyright : ABOUT.C
  • hFullSem : BNDBUFP.C , BNDBUFS.C , COMMON.H
  • hHourGlass : CURSOR.C
  • HIGHLIGHT_NDX : ENUMUTIL.H
  • hInst : OWNCOMBO.C , PLATFORM.C , REGIONS.H , SEMA.C , GLOBALS.H , INIT.C , SETINFO.C , SHAREMEM.C , STREBLT.C , SUBCLASS.H , THREADS.C , UNIPUT.C , UNIPUT.H , VIRTMEM.C , CLIPTEXT.C , CMNDLG.C , CURSOR.C , NTGREP.C , HOOKTEST.C , MASKBLT.C , MENU.C , GLOBALS.H , INIT.C , OTHRPROC.C
  • HITSIZE : POLYDRAW.H
  • hKernel32 : UTDLL32.C
  • hMainThrd : BNDBUFC.C
  • hMapObject : OTHRPROC.C , SHAREMEM.C
  • hMenu : MDI.C , REGIONS.H
  • hMenuWindow : MDI.C
  • hModule : STEREO.C
  • hMutex : BNDBUFS.C
  • HMUTEX : DATABASE.C
  • hMutex : BNDBUFP.C , COMMON.H
  • HORZSCALE : WORLD.C
  • hOurselves : GUIGREP.C
  • hpnBlack : FRACTAL.H
  • hpnGreen : FRACTAL.H
  • hpnRed : FRACTAL.H
  • hProdThrd : BNDBUFC.C
  • hRC : GLTHREAD.C
  • HRMASK : SETINFO.H
  • HRSHIFT : SETINFO.H
  • hSaveCursor : CURSOR.C
  • HSCROLLMAX : WORLD.C
  • HSEM : DATABASE.C
  • hSemaphore : SEMA.C
  • hSetupEvent : OVCOMM.H
  • hText : CLIPTEXT.C
  • hThread : OTHRPROC.C
  • hThreads : THREADS.C
  • hWnd : THREADS.C
  • hwnd : CLIPTEXT.C
  • hWnd : OTHRPROC.C , SEMA.C , SETINFO.C , SHAREMEM.C , VIRTMEM.C
  • hwndClient : UNIPUT.H , UNIPUT.C
  • hWndDlg : SETINFO.C , SHAREMEM.C , OTHRPROC.C
  • hwndDlg : MASKBLT.C , STREBLT.C
  • hWndFileDlg : SETINFO.C
  • hWndGlobal : GUIGREP.C
  • hwndMain : STREBLT.C , SUBCLASS.H , MASKBLT.C , HOOKTEST.C , UNIPUT.H , UNIPUT.C
  • hwndMDIClient : GLOBALS.H , DLLDISP.H
  • hwndRecv : NDDECHAT.C
  • hwndSend : GLOBALS.H , NDDECHAT.C
  • hwndStatic0 : STATUS.C , UNIPUT.H
  • hwndStatic1 : UNIPUT.H , STATUS.C
  • hwndStatic2 : STATUS.C
  • hwndStatus : UNIPUT.C , UNIPUT.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- i -

  • ICONFILE : GLOBALS.H
  • iCreatePenFrPal() : FRACTAL.C
  • ID_ABOUT : MENU.H
  • ID_ADDBUTTON : OWNCOMBO.H
  • ID_BLACK : OWNCOMBO.H
  • ID_BLUE : OWNCOMBO.H
  • ID_CANCEL : APP16.H
  • ID_CBDIRBUTTON : OWNCOMBO.H
  • ID_CLRBUTTON : OWNCOMBO.H
  • ID_COMBOBOX : OWNCOMBO.H
  • ID_CPYBUTTON : OWNCOMBO.H
  • ID_DELETEBUTTON : OWNCOMBO.H
  • ID_DRAWWAVES : RESOURCE.H
  • ID_FNDSELBUTTON : OWNCOMBO.H
  • ID_GREEN : OWNCOMBO.H
  • ID_ITERATION : FRACTAL.H
  • ID_LISTBOX : OWNCOMBO.H
  • ID_NUMSELBUTTON : OWNCOMBO.H
  • ID_OK : APP16.H
  • ID_RED : OWNCOMBO.H
  • ID_SAVEAS : FRACTAL.H
  • ID_SINGLEEDIT : OWNCOMBO.H
  • ID_STEPSBOX : OWNCOMBO.H
  • ID_TEXT1 : OWNCOMBO.H
  • ID_TEXT2 : OWNCOMBO.H
  • ID_TIMER1 : TIMERS.H
  • ID_TIMER2 : TIMERS.H
  • ID_TIMER3 : TIMERS.H
  • ID_TIMER4 : TIMERS.H
  • ID_TXTSELBUTTON : OWNCOMBO.H
  • ID_UNSLBUTTON : OWNCOMBO.H
  • ID_WHITE : OWNCOMBO.H
  • ID_XFROM : FRACTAL.H
  • ID_XTO : FRACTAL.H
  • ID_YFROM : FRACTAL.H
  • ID_YTO : FRACTAL.H
  • IDB_ATTR : SETINFO.H
  • IDB_HELP : ENUMDLG.H
  • IDB_OPENFILE : SETINFO.H
  • IDB_SET : SETINFO.H
  • IDB_STEP : SETINFO.H
  • IDC_AGE : APP16.H
  • IDC_ARC : SETINFO.H
  • IDC_FIRSTNAME : APP16.H
  • IDC_HIDE : SETINFO.H
  • IDC_HORZ : WORLD.H
  • IDC_LASTNAME : APP16.H
  • IDC_NORMAL : SETINFO.H
  • IDC_READ : SETINFO.H
  • IDC_STATIC : GLOBALS.H , ENUMDLG.H
  • IDC_SYSTEM : SETINFO.H
  • IDC_VERT : WORLD.H
  • IDCOLORS_POS : MENU.H
  • IDD_VERFIRST : GLOBALS.H
  • IDD_VERLAST : GLOBALS.H
  • IDE_ALLOCBASE : VIRTMEM.H
  • IDE_API : SETINFO.H
  • IDE_BASEADDR : VIRTMEM.H
  • IDE_DAY : SETINFO.H
  • IDE_FILENAME : SETINFO.H
  • IDE_HOURS : SETINFO.H
  • IDE_INITPROT : VIRTMEM.H
  • IDE_MINUTES : SETINFO.H
  • IDE_MONTH : SETINFO.H
  • IDE_PROTECT : VIRTMEM.H
  • IDE_RECV : GLOBALS.H
  • IDE_RETSTAT : SETINFO.H
  • IDE_SECONDS : SETINFO.H
  • IDE_SEND : GLOBALS.H
  • IDE_SERVER : ENUMDLG.H
  • IDE_SERVERNAME : CONNECT.H , DDECBACK.H
  • IDE_SIZE : SETINFO.H , VIRTMEM.H
  • IDE_STATE : VIRTMEM.H
  • IDE_TIME : SETINFO.H
  • IDE_XCOORD : OTHRPROC.H , SHAREMEM.H
  • IDE_YCOORD : OTHRPROC.H , SHAREMEM.H
  • IDE_YEAR : SETINFO.H
  • IDEDIT : CMNDLG.H
  • IDFILE_POS : MENU.H
  • IDHELP_POS : MENU.H
  • IDL_BROWSE : ENUMDLG.H
  • IDM_ABOUT : CLIPTEXT.H , CMNDLG.H , CURSOR.H , GUIGREP.H , NTGREP.H , APP16.H , MENU.H , GLOBALS.H , OWNCOMBO.H , PLATFORM.H , REGIONS.H , LINKTEST.H , LOADTEST.H , UNIPUT.H , WORLD.H
  • IDM_AND : REGIONS.H
  • IDM_ARRANGE : MDI.H
  • IDM_BLACK : MENU.H
  • IDM_BLUE : MENU.H
  • IDM_BUTTON : SUBCLASS.H
  • IDM_CALLWNDPROC : HOOKTEST.H
  • IDM_CANCEL : GUIGREP.H , NTGREP.H
  • IDM_CASCADE : MDI.H
  • IDM_CASESENS : GUIGREP.H , NTGREP.H
  • IDM_CBT : HOOKTEST.H
  • IDM_CHAR10 : UNIPUT.H
  • IDM_CHAR16 : UNIPUT.H
  • IDM_CHAR20 : UNIPUT.H
  • IDM_CHAR32 : UNIPUT.H
  • IDM_CHAR40 : UNIPUT.H
  • IDM_CHAR64 : UNIPUT.H
  • IDM_CHARBASE : UNIPUT.H
  • IDM_CHOOSECOLOR : CMNDLG.H
  • IDM_CHOOSEFONT : CMNDLG.H
  • IDM_CLEAR : CLIPTEXT.H
  • IDM_CLOSEALL : MDI.H
  • IDM_CLOSEFILE : UNIPUT.H
  • IDM_COLOROWNERDR : MENU.H
  • IDM_COMBOBOX : OWNCOMBO.H
  • IDM_COMMIT : VIRTMEM.H
  • IDM_CONNECT : GLOBALS.H
  • IDM_COPY : CLIPTEXT.H , REGIONS.H
  • IDM_COPYDATA : APP16.H
  • IDM_CREATETHREAD : LINKTEST.H , LOADTEST.H
  • IDM_CUSTOM : CMNDLG.H
  • IDM_CUT : CLIPTEXT.H
  • IDM_DEBUG : HOOKTEST.H
  • IDM_DEFGREP : GUIGREP.H , NTGREP.H
  • IDM_DIFF : REGIONS.H
  • IDM_DISCONNECT : GLOBALS.H
  • IDM_DLLDIALOGBOX : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION1 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION2 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION3 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION4 : LINKTEST.H , LOADTEST.H
  • IDM_EDIT : SUBCLASS.H
  • IDM_ELLIPSE : REGIONS.H
  • IDM_ENTERNEW : CMNDLG.H
  • IDM_ENUM : GLOBALS.H
  • IDM_ENUMHELP : GLOBALS.H
  • IDM_ERASE : REGIONS.H
  • IDM_EXIT : CLIPTEXT.H , CMNDLG.H , RESOURCE.H , HOOKTEST.H , APP16.H , MENU.H , GLOBALS.H , OWNCOMBO.H , GLOBALS.H , WORLD.H
  • IDM_FILE_EXIT : MINREC.H
  • IDM_FINDTEXT : CMNDLG.H
  • IDM_FONT : MENU.H
  • IDM_FONT18 : UNIPUT.H
  • IDM_FONT36 : UNIPUT.H
  • IDM_FONT72 : UNIPUT.H
  • IDM_FONTBASE : UNIPUT.H
  • IDM_FRAMERGN : REGIONS.H
  • IDM_FREE : VIRTMEM.H
  • IDM_FREELIBRARY : LOADTEST.H
  • IDM_GANORM : THREADS.H
  • IDM_GBNORM : THREADS.H
  • IDM_GETMESSAGE : HOOKTEST.H
  • IDM_GETRGNBOX : REGIONS.H
  • IDM_GHIGH : THREADS.H
  • IDM_GIDLE : THREADS.H
  • IDM_GLOW : THREADS.H
  • IDM_GNORM : THREADS.H
  • IDM_GREEN : MENU.H
  • IDM_GTC : THREADS.H
  • IDM_HELP : OWNCOMBO.H , UNIPUT.H
  • IDM_HELP_ABOUT : MINREC.H
  • IDM_HOOK : CMNDLG.H
  • IDM_INSTALL : GUIGREP.H , NTGREP.H
  • IDM_INVERTRGN : REGIONS.H
  • IDM_KEYBOARD : HOOKTEST.H
  • IDM_LIST : SUBCLASS.H
  • IDM_LISTBOX : OWNCOMBO.H
  • IDM_LOADLIBRARY : LOADTEST.H
  • IDM_LOCK : VIRTMEM.H
  • IDM_MACRO_PLAYBACK : MINREC.H
  • IDM_MACRO_RECORD : MINREC.H
  • IDM_MACRO_STOP : MINREC.H
  • IDM_MDICASCADE : UNIPUT.H
  • IDM_MDITILE : UNIPUT.H
  • IDM_MOUSE : HOOKTEST.H
  • IDM_MSGFILTER : HOOKTEST.H
  • IDM_MULTILISTBOX : OWNCOMBO.H
  • IDM_NEW : CLIPTEXT.H
  • IDM_NEWFILE : UNIPUT.H
  • IDM_NEWWINDOW : UNIPUT.H
  • IDM_NOACCESS : VIRTMEM.H
  • IDM_OFFSETRGN : REGIONS.H
  • IDM_OPEN : CLIPTEXT.H , WORLD.H
  • IDM_OPENFILE : CMNDLG.H
  • IDM_OR : REGIONS.H
  • IDM_OWNERCOMBOBOX : OWNCOMBO.H
  • IDM_PASTE : CLIPTEXT.H
  • IDM_PLATFORM : PLATFORM.H
  • IDM_POLYPOLYGON : REGIONS.H
  • IDM_PRINT : CLIPTEXT.H , CMNDLG.H
  • IDM_PTINRGN : REGIONS.H
  • IDM_RANORM : THREADS.H
  • IDM_RBNORM : THREADS.H
  • IDM_READONLY : VIRTMEM.H
  • IDM_READWRITE : VIRTMEM.H
  • IDM_RECT : REGIONS.H
  • IDM_RECTINRGN : REGIONS.H
  • IDM_RED : MENU.H
  • IDM_REPLACETEXT : CMNDLG.H
  • IDM_RESERVE : VIRTMEM.H
  • IDM_RESUMEGREEN : THREADS.H
  • IDM_RESUMERED : THREADS.H
  • IDM_RHIGH : THREADS.H
  • IDM_RIDLE : THREADS.H
  • IDM_RLOW : THREADS.H
  • IDM_RNORM : THREADS.H
  • IDM_RTC : THREADS.H
  • IDM_SAVE : CLIPTEXT.H
  • IDM_SAVEAS : CLIPTEXT.H
  • IDM_SAVEFILE : CMNDLG.H
  • IDM_SAVEFILEAS : CMNDLG.H
  • IDM_SCALE : WORLD.H
  • IDM_SETRECTRGN : REGIONS.H
  • IDM_SHOW : VIRTMEM.H
  • IDM_SHOWHEX : UNIPUT.H
  • IDM_SHOWNAMES : UNIPUT.H
  • IDM_SIZE : MENU.H
  • IDM_SORTBOX : NTGREP.H , GUIGREP.H
  • IDM_STANDARD : CMNDLG.H
  • IDM_STARTGREP : GUIGREP.H , NTGREP.H
  • IDM_STATE1 : MENU.H
  • IDM_STATE2 : MENU.H
  • IDM_STATE3 : MENU.H
  • IDM_STATE4 : MENU.H
  • IDM_STRINGEDIT : NTGREP.H , GUIGREP.H
  • IDM_STYLE : MENU.H
  • IDM_SUSPENDGREEN : THREADS.H
  • IDM_SUSPENDRED : THREADS.H
  • IDM_TERMBOX : GUIGREP.H , NTGREP.H
  • IDM_TEST : SUBCLASS.H
  • IDM_THUNK : APP16.H
  • IDM_TILE : MDI.H
  • IDM_UNDO : CLIPTEXT.H
  • IDM_UNINSTALL : NTGREP.H , GUIGREP.H
  • IDM_UNLOCK : VIRTMEM.H
  • IDM_WRITE : VIRTMEM.H
  • IDM_XOR : REGIONS.H
  • IDS_APPNAME : GLOBALS.H , MINREC.H , GLOBALS.H
  • IDS_BUFFERTOOSMALL : CMNDLG.H
  • IDS_CREATEICFAILURE : CMNDLG.H
  • IDS_DESCRIPTION : GLOBALS.H
  • IDS_DIALOGFAILURE : CMNDLG.H
  • IDS_DNDMMISMATCH : CMNDLG.H
  • IDS_FILTERSTRING : CMNDLG.H
  • IDS_FINDRESFAILURE : CMNDLG.H
  • IDS_GETDEVMODEFAIL : CMNDLG.H
  • IDS_INITFAILURE : CMNDLG.H
  • IDS_INITIALIZATION : CMNDLG.H
  • IDS_INVALIDFILENAME : CMNDLG.H
  • IDS_ITEM : GLOBALS.H
  • IDS_LOADDRVFAILURE : CMNDLG.H
  • IDS_LOADRESFAILURE : CMNDLG.H
  • IDS_LOADSTRFAILURE : CMNDLG.H
  • IDS_LOCKRESFAILURE : CMNDLG.H
  • IDS_MEMALLOCFAILURE : CMNDLG.H
  • IDS_MEMLOCKFAILURE : CMNDLG.H
  • IDS_NODEFAULTPRN : CMNDLG.H
  • IDS_NODEVICES : CMNDLG.H
  • IDS_NOFONTS : CMNDLG.H
  • IDS_NOHINSTANCE : CMNDLG.H
  • IDS_NOHOOK : CMNDLG.H
  • IDS_NOTEMPLATE : CMNDLG.H
  • IDS_PARSEFAILURE : CMNDLG.H
  • IDS_PRINTERNOTFOUND : CMNDLG.H
  • IDS_RETDEFFAILURE : CMNDLG.H
  • IDS_SETUPFAILURE : CMNDLG.H
  • IDS_SHARENAME : GLOBALS.H
  • IDS_SHORT_APPNAME : MINREC.H
  • IDS_STRUCTSIZE : CMNDLG.H
  • IDS_SUBCLASSFAILURE : CMNDLG.H
  • IDS_TOPIC : GLOBALS.H
  • IDS_UNKNOWNERROR : CMNDLG.H
  • idsIteration : FRACTAL.H
  • idsName : FRACTAL.H
  • idsSaveAs : FRACTAL.H
  • IDSTATES_POS : MENU.H
  • idsXFrom : FRACTAL.H
  • idsXTo : FRACTAL.H
  • idsYFrom : FRACTAL.H
  • idsYTo : FRACTAL.H
  • IDT_SELECT : ENUMDLG.H
  • iFinishedFiles : GUIGREP.C
  • iGlobalSStLen : GUIGREP.C
  • iHitCount : GUIGREP.C
  • ilpszCRLF : GUIGREP.C
  • IMPLEMENTED : VIRTMEM.C
  • INC : SUBCLASS.H , STREBLT.H , MASKBLT.H
  • INFO : MDITYPES.H , MDI.C , FRACTAL.H , MDITYPES.H , MDI.C
  • InfoDlgProc() : APP16.C
  • InitApp() : DATABASE.C
  • InitApplication() : PLATFORM.C , GLOBALS.H , BOB.H , CLIPTEXT.C , HOOKTEST.C , INIT.C , NTGREP.C , BOB.C , GLOBALS.H , GUIGREP.H , INIT.C , CMNDLG.C , HOOKTEST.H , CMNDLG.H , PLATFORM.H , CURSOR.C , CURSOR.H
  • INITCLASSNAME : NTGREP.C
  • InitialEnumThread() : ENUMTHRD.H , ENUMTHRD.C
  • initialize() : THREADS.C , GLTHREAD.H
  • InitializeApp() : MDI.C
  • InitializeDataBase() : DATABASE.C
  • InitializeSubsystem() : DATABASE.C
  • InitializeWindow() : GLTHREAD.C
  • InitInstance() : NTGREP.C , CURSOR.C , BOB.C , PLATFORM.C , GUIGREP.H , CMNDLG.H , CURSOR.H , CMNDLG.C , GLOBALS.H , CLIPTEXT.C , PLATFORM.H , BOB.H , GLOBALS.H , HOOKTEST.H , HOOKTEST.C , INIT.C
  • InitStereoApplet() : STEREO.C
  • InitThunk() : STUB32.C , UTDLL32.C
  • insert_buffer() : BNDBUFP.C
  • InsertElement() : CHGDATA.C
  • insertMsgString() : LOG.C
  • instructions0 : POLYDRAW.H
  • instructions1 : POLYDRAW.H
  • instructions2 : POLYDRAW.H
  • instructions3 : POLYDRAW.H
  • InWrite : DATABASE.C
  • IO_ERROR : ASYN_IO.C
  • iPatternBrush : STREBLT.C , MASKBLT.C
  • IsWin32sLoaded() : DLL16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- p -

  • page : VIRTMEM.C
  • PAGEINC : WORLD.C
  • PAGESIZE : VIRTMEM.H
  • PaintRect() : SUBCLASS.C , SUBCLASS.H
  • PARAM_SIZE : LOG.C
  • ParseSwitch() : IOCOMP.C
  • Patterns : MASKBLT.H , STREBLT.H
  • pbitsAND : DISPLAY.C
  • pbitsXOR : DISPLAY.C
  • pd : CMNDLG.C
  • PDERR_CREATEICFAILURE : CDERR.H
  • PDERR_DNDMMISMATCH : CDERR.H
  • PDERR_GETDEVMODEFAIL : CDERR.H
  • PDERR_INITFAILURE : CDERR.H
  • PDERR_LOADDRVFAILURE : CDERR.H
  • PDERR_NODEFAULTPRN : CDERR.H
  • PDERR_NODEVICES : CDERR.H
  • PDERR_PARSEFAILURE : CDERR.H
  • PDERR_PRINTERCODES : CDERR.H
  • PDERR_PRINTERNOTFOUND : CDERR.H
  • PDERR_RETDEFFAILURE : CDERR.H
  • PDERR_SETUPFAILURE : CDERR.H
  • PERR : LOG.C , STARTP.C , WINNET.C , INHERIT.C
  • PEVENTHEADER : RECHOOK.C
  • PExtraBytes : SUBCLASS.H
  • PFNCMD : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • PFNDLL : LOADTEST.H
  • PFNMSG : GLOBALS.H , DLLDISP.H
  • pfnUTProc : UTDLL32.C
  • PGLOBAL : MINREC.C , RECHOOK.C
  • PHYSICAL_ADDRESS : DEBUG.C
  • PINFO : MDI.C , MDITYPES.H , MDI.C , MDITYPES.H , FRACTAL.H
  • PMSG : WINNET.C
  • POINT2MPOINT : CURSOR.H
  • POINTSIZE : ABOUT.C
  • Poll_On_Threads() : GUIGREP.C
  • PolygonalCaps : GETDEV.H
  • POLYPOLYGON_RGN : REGIONS.H
  • POLYPOLYGONCOUNT : REGIONS.H
  • polyPolygonCounts : REGIONS.H
  • polyPolygonPoints : REGIONS.H
  • PPHYSICAL_ADDRESS : DEBUG.C
  • PrevX : CURSOR.C
  • PrevY : CURSOR.C
  • PrintAPIError() : WINNET.C
  • PrintAppStyleAPIError : WINNET.C
  • PrintBanner() : COLOR.C , COLOR.H
  • PrintDlgHookProc() : CMNDLG.H , CMNDLG.C
  • PrintFile() : CMNDLG.C , CMNDLG.H
  • PrintSetupHookProc() : CMNDLG.C , CMNDLG.H
  • pro_buf_pos : COMMON.H , BNDBUFP.C
  • Proc : DLL16.C
  • ProcessCDError() : CMNDLG.C , CMNDLG.H
  • ProcessFileCommonCode() : GUIGREP.C
  • ProcessIO() : OVCOMM.C
  • produce_item() : BNDBUFC.C
  • producer() : BNDBUFC.C
  • PROV_NDX : ENUMUTIL.H
  • PROVEX_NDX : ENUMUTIL.H
  • PROVIDER_BMP : ENUMDLG.H
  • PROVIDEREX_BMP : ENUMDLG.H
  • PSUBTABLE : DISPLAY.C
  • pszLast : NDDECHAT.C
  • PTABLE : DISPLAY.C
  • ptCursor : CURSOR.C
  • ptoDest : STREBLT.C , MASKBLT.C
  • ptoMask : MASKBLT.C
  • ptoSrc : STREBLT.C , MASKBLT.C
  • PTrackObject : TRACK.H
  • PTRACKRECTSTRUCT : REGIONS.H
  • PURGE_FLAGS : OVCOMM.H
  • PutData() : DATABASE.C
  • pUTRegister : UTDLL32.C
  • pUTUnRegister : UTDLL32.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- q -

  • queryEventLog() : LOG.C
  • QueryWindowPos() : SUBCLASS.H , SUBCLASS.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- r -

  • radius : THREADS.C
  • RangeName : DISPLAY.H
  • RasterCaps : GETDEV.H
  • Read() : READWRIT.C
  • READ_TIMEOUT : OVCOMM.H
  • ReadDataBase() : DATABASE.C , DATABASE.H
  • ReaderProc() : OVCOMM.C
  • ReadProc() : OTHRPROC.C , OTHRPROC.H
  • ReallocMem() : MEM.C , MEM.H , MEM.C , MEM.H
  • Rect : CURSOR.C
  • RECT_RGN : REGIONS.H
  • rectRect : REGIONS.H
  • RECTSIZE : TRACK.C
  • RED : SEMA.H , THREADS.H
  • RefreshOutstanding() : THRDUTIL.C , THRDUTIL.H
  • REG_ERR : LOG.C
  • RegisterDialogClasses() : FRACTAL.C
  • REMOTE_MSG_DLL_PATH : LOG.C
  • remove_buffer() : BNDBUFP.C
  • remove_item() : BNDBUFP.C
  • repeat : CURSOR.C
  • ReplaceTextHookProc() : CMNDLG.C , CMNDLG.H
  • reportAnEvent() : LOG.C
  • ReportCommError() : OVCOMM.C
  • ReportModemStatus() : OVCOMM.C
  • ReportStatusEvent() : OVCOMM.C
  • RepStat() : SETINFO.C , SETINFO.H
  • Reset() : REGIONS.C , REGIONS.H
  • RESET_ALL : REGIONS.H
  • ResetMenu() : VIRTMEM.C , VIRTMEM.H
  • resize() : THREADS.C , GLTHREAD.H
  • RESOURCE_BUF_ENTRIES : WINNET.C
  • ResultBlock : GUIGREP.C
  • retCode : BNDBUFC.C , BNDBUFS.C
  • RETURN_IMEDIATELY : ASYN_IO.C
  • RGBQ : MISCUTIL.C
  • rgcmd : BROWSE.C , NDDECHAT.C
  • rgcmdAbout : ABOUT.C
  • rgcmdConnectDlg : CONNECT.C
  • rgcmdEnumDlg : ENUMDLG.C
  • rgmsd : BROWSE.C , NDDECHAT.C
  • rgmsdAbout : ABOUT.C
  • rgmsdConnectDlg : CONNECT.C
  • rgmsdEnumDlg : ENUMDLG.C
  • rgnArray : REGIONS.H
  • RgnBoxDlgProc() : REGIONS.C , REGIONS.H
  • ROP_PSDPxax : MENU.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- s -

  • SaveAs() : CMNDLG.C , CMNDLG.H
  • SaveBitmapFile() : FRACTAL.C
  • SaveToFile() : CMNDLG.C , CMNDLG.H
  • SBORDER : UNIPUT.H
  • ScaleDlgProc() : WORLD.C
  • ScreenSaverConfigureDialog() : FRACTAL.C
  • ScreenSaverProc() : FRACTAL.C
  • SearchFile() : CMNDLG.C , CMNDLG.H
  • SECMASK : SETINFO.H
  • SECSHIFT : SETINFO.H
  • SECTOR_SIZE : ASYN_IO.C
  • SEGMENTERROR : DISPLAY.C
  • SELECTEDBUTTON : BOB.H
  • SEM1 : DATABASE.C
  • SEPARATORWIDTH : MASKBLT.H , STREBLT.H
  • SERV_NDX : ENUMUTIL.H
  • SERVER_BMP : ENUMDLG.H
  • ServerEnumDialog : SERVENUM.H
  • ServerEnumDialogA() : SERVENUM.H , SERVENUM.C , SERVENUM.H
  • ServerEnumDialogW() : SERVENUM.H , SERVENUM.C , SERVENUM.H
  • SetBitmapBkgnd() : MISCUTIL.H , MISCUTIL.C
  • SetButtonPositions() : TIMERS.C , TIMERS.H
  • SetCurrentPrivilege() : REBOOT.C
  • SetFlashRectPositions() : TIMERS.C , TIMERS.H
  • SetUnityXform() : WORLD.C
  • SetupCommandLineOptions() : OVCOMM.C
  • SetupCommPort() : OVCOMM.C
  • SetupNDDEShare() : NDDEUTIL.C , NDDEUTIL.H
  • SFIELD0 : UNIPUT.H
  • SFIELD1 : UNIPUT.H
  • ShiftlParam() : SUBCLASS.H
  • ShowDlgProc() : VIRTMEM.C , VIRTMEM.H
  • ShowNDDEErrMsg() : NDDEUTIL.C , NDDEUTIL.H
  • ShowUsage() : IOCOMP.C
  • ShrinkBitmap() : MENU.C
  • SID_BUF_SIZE : LOG.C
  • sieve() : CURSOR.C , CURSOR.H
  • SIGNALED : DATABASE.C
  • SIZE : CURSOR.C
  • SIZEOFCAPTIONTEXT : MDI.H
  • solve() : GLTHREAD.H , THREADS.C
  • space : GETDEV.H
  • StandardROPs : STREBLT.H , MASKBLT.H
  • START_NDX : ENUMUTIL.H
  • startCount : DISPLAY.C
  • StartJournalPlayback() : RECHOOK.C , RECHOOK.H
  • StartJournalRecord() : RECHOOK.C , RECHOOK.H
  • StartMandelbrot() : FRACTAL.C
  • STATE_CLIENT : GLOBALS.H
  • STATE_PENDING : GLOBALS.H
  • STATE_SERVER : GLOBALS.H
  • STATE_UNCONN : GLOBALS.H
  • STATUS_CHECK_TIMEOUT : OVCOMM.H
  • StatusDlgProc() : OTHRPROC.H , SETINFO.C , SETINFO.H
  • STATUSHEIGHT : UNIPUT.C
  • StatusProc() : OVCOMM.C
  • StatusWndProc() : STATUS.C , UNIPUT.H
  • StepTime : SETINFO.C
  • StereoApplets : STEREO.C
  • StopAllJournalling() : RECHOOK.C , RECHOOK.H
  • StopJournalPlayback() : RECHOOK.C , RECHOOK.H
  • StopJournalRecord() : RECHOOK.C , RECHOOK.H
  • str : CURSOR.C
  • STR_DWORD : GLOBALS.H
  • strebltMode : STREBLT.C
  • strebltModes : STREBLT.H
  • STRICT : DATABASE.C , BOB.C , ASYN_IO.C , MDI.C , MINREC.C , RECHOOK.C , MDI.C , PLATFORM.C , READWRIT.C , REBOOT.C , WINNET.C
  • StringProc() : GUIGREP.C
  • STROKEANDFILLALT : PATHS.H
  • STROKEANDFILLWIND : PATHS.H
  • STROKEPATH : PATHS.H
  • SubclassWindow : BOB.H , SUBCLASS.C , SUBCLASS.H
  • SubclassWndProc() : SUBCLASS.C , SUBCLASS.H
  • SUBTABLE : DISPLAY.C
  • SUCCESS : COMMON.H , ASYN_IO.C
  • SwapShort() : DISPLAY.C
  • SwapULong() : DISPLAY.C
  • Syntax() : COLOR.C , COLOR.H
  • SysColors : GETSYS.H
  • SystemMetrics : GETSYS.H
  • SZ_BUF : WINNET.C
  • SZ_ERROR_BUF : WINNET.C
  • SZ_PROVIDER_NAME_BUF : WINNET.C
  • SZABOUT : GLOBALS.H
  • szAppName : GLTHREAD.C
  • SZAPPNAME : GLOBALS.H
  • szAppName : FRACTAL.H , INIT.C , GLOBALS.H
  • SZAPPNAME : GLOBALS.H
  • szAppName : INIT.C , GLOBALS.H
  • szCtlPanel : STEREO.C
  • SZDESCRIPTION : GLOBALS.H
  • szDirName : CMNDLG.C
  • szFile : WORLD.C , CMNDLG.C
  • szFileTitle : CMNDLG.C , WORLD.C
  • szFilter : WORLD.C , CMNDLG.C
  • szFindString : CMNDLG.C
  • szFirstName : APP16.C
  • szGlobalSearchString : GUIGREP.C
  • szHelpFile : FRACTAL.H
  • szHelpPathName : UNIPUT.C
  • szIniFile : FRACTAL.H
  • szInitialClientAreaText : CLIPTEXT.C
  • szItem : NDDECHAT.C
  • szIteration : FRACTAL.H
  • szLastName : APP16.C
  • szMsgBuf : WINNET.C
  • szName : FRACTAL.H
  • szNoHelpMemory : FRACTAL.H
  • SZRAPPNAME : GLOBALS.H
  • SZRCOMPANYNAME : GLOBALS.H
  • SZRCOPYRIGHT : GLOBALS.H
  • SZRDESCRIPTION : GLOBALS.H
  • szReplaceString : CMNDLG.C
  • SZRPRODNAME : GLOBALS.H
  • SZRPRODVER : GLOBALS.H
  • SZRTRADEMARK : GLOBALS.H
  • SZRVERSION : GLOBALS.H
  • szSaveFile : FRACTAL.H
  • szScreenSaver : FRACTAL.H
  • szShareName : NDDECHAT.C
  • szTitle : INIT.C , GLOBALS.H
  • SZVERSION : GLOBALS.H
  • szXFrom : FRACTAL.H
  • szXTo : FRACTAL.H
  • szYFrom : FRACTAL.H
  • szYTo : FRACTAL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- t -

  • TABLE : DISPLAY.C
  • TAPE_DESC : STEREO.H
  • TAPE_DLG : STEREO.H
  • TAPE_ICON : STEREO.H
  • TAPE_NAME : STEREO.H
  • TapeDlgProc() : STEREO.C , STEREO.H
  • TCHAR : PLATFORM.C
  • TermStereoApplet() : STEREO.C
  • TEST_REPEAT_COUNT : IOCOMP.C
  • TEXT : PLATFORM.C
  • TextCaps : GETDEV.H
  • TEXTHEIGHT : TIMERS.H
  • TextWndProc() : MDI.C
  • ThreadFunc1() : GLTHREAD.H , THREADS.C
  • ThreadFunc2() : GLTHREAD.H , THREADS.C
  • THREADPBLOCK : GUIGREP.H
  • ThreadProc() : SEMA.C , SEMA.H , LINKTEST.C , LINKTEST.H , LOADTEST.C , LOADTEST.H , THREADS.C , THREADS.H
  • threeto8 : THREADS.C
  • TICKSPACE : UNIPUT.C , MASKBLT.C , STREBLT.C
  • TimerFunc() : TIMERS.C , TIMERS.H
  • TIMERINTERVAL : TIMERS.H
  • TlsCount : TLSDLL.C
  • TlsIndex : TLSDLL.C
  • TlsInit() : TLSDLL.C , TLSDLL.H
  • TLSOBJECT : ENUMUTIL.H
  • TlsRetreive() : TLSDLL.C , TLSDLL.H
  • TMALL : TRACK.H
  • TMMOVE : TRACK.H
  • TMNONE : TRACK.H
  • TMROTATE : TRACK.H
  • TMSHEARX : TRACK.H
  • TMSHEARY : TRACK.H
  • TMSIZEX : TRACK.H
  • TMSIZEXY : TRACK.H
  • TMSIZEY : TRACK.H
  • ToggleMenu() : SUBCLASS.C , SUBCLASS.H
  • TrackObject : TRACK.H
  • TrackRect() : REGIONS.C , REGIONS.H
  • transIndextoRect() : DISPLAY.C
  • transXYtoIndex() : DISPLAY.C
  • TraverseFileCaseInsens() : GUIGREP.C
  • TraverseFileCaseSens() : GUIGREP.C
  • TRECT_DELETE : REGIONS.H
  • TRECT_NEW : REGIONS.H
  • TRECT_PAINT : REGIONS.H
  • TROB_DELETE : TRACK.H
  • TROB_HITTEST : TRACK.H
  • TROB_NEW : TRACK.H
  • TROB_PAINT : TRACK.H
  • TUNER_DESC : STEREO.H
  • TUNER_DLG : STEREO.H
  • TUNER_ICON : STEREO.H
  • TUNER_NAME : STEREO.H
  • TunerDlgProc() : STEREO.C , STEREO.H
  • TWO_PI : PATHS.C
  • twoto8 : THREADS.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- u -

  • UCFONTHEIGHT : UNIPUT.H
  • UCFONTWIDTH : UNIPUT.H
  • UNICODE : DISPLAY.C , STATUS.C , LOCALE.C , UNIPUT.C
  • UNICODE_CHARSET : UNIPUT.H , LOCALE.H
  • UNREFERENCED_PARAMETER : PLATFORM.C
  • UpdateBuffer() : DRIVES.C , DRIVES.H
  • Usage() : BNDBUFS.C
  • usage() : LOG.C
  • USESTDHANDLES : INHERIT.C
  • UTCBProc() : UTDLL32.C
  • UTInit() : DLL16.C
  • UTProc() : DLL16.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- v -

  • VERTSCALE : WORLD.C
  • vLoadStrings() : FRACTAL.C
  • VOID() : UTDLL32.C
  • void() : DLL16.C
  • VSCROLLMAX : WORLD.C
  • vTest() : MDI.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- w -

  • W32SUT_16 : DLL16.C
  • W32SUT_32 : UTDLL32.C
  • WAIT_ERROR : DATABASE.C , ASYN_IO.C
  • WaitCloseOutstanding() : THRDUTIL.C , THRDUTIL.H
  • Walk() : WALK.H , WALK.C
  • WEP() : DLL16.C
  • WERR : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • WF1_WINNT : PLATFORM.C
  • WF_WINNT : MYUT.H
  • WHICH_TO_USE_FROM_LIST : WINNET.C
  • WIN32S : BOB.C
  • WIN32SINFO : DLL16.C
  • WINAPI : PLATFORM.C
  • WinMain() : LOCALE.C , MASKBLT.C , MDI.C , MENU.C , MINREC.C , WINMAIN.C , BOB.C , MDI.C , OTHRPROC.C , BOB.H , OWNCOMBO.C , PATHS.C , CLIPTEXT.C , PLATFORM.C , PLATFORM.H , CMNDLG.C , POLYDRAW.C , REGIONS.C , CURSOR.C , MAIN.C , WORLD.C , VIRTMEM.C , SEMA.C , GETDEV.C , THREADS.C , SUBCLASS.C , STREBLT.C , WINMAIN.C , SETINFO.C , GETSYS.C , SHAREMEM.C , LINKTEST.C , GLTHREAD.C , LOADTEST.C , NTGREP.C , HOOKTEST.C , TIMERS.C , UNIPUT.C , APP16.C , DISP32.C , STUB32.C
  • WM_ADDITEM : GUIGREP.H
  • WM_CONNECT : GLOBALS.H
  • WM_COPYDATA : APP16.C
  • WM_DISCONNECT : GLOBALS.H
  • WM_ENUM_EXPAND : ENUMDLG.H
  • WM_FREEAGAIN : GUIGREP.H
  • WM_INIT_ENUM : ENUMDLG.H
  • WM_INQUIREFILES : GUIGREP.H
  • WM_LAUNCH : GUIGREP.H
  • WM_MASKBLT : MASKBLT.H
  • WM_PUTUPDESTRECT : MASKBLT.H , STREBLT.H
  • WM_PUTUPMASKPT : MASKBLT.H
  • WM_PUTUPSRCRECT : MASKBLT.H , STREBLT.H
  • WM_RECEIVE_TEXT : GLOBALS.H
  • WM_REPSTAT : SETINFO.H
  • WM_SC_CREATE : SUBCLASS.H
  • WM_STARTSYNC : GUIGREP.H
  • WM_STRETCHBLT : STREBLT.H
  • WM_TELLHANDLE : GUIGREP.H
  • wMode : CMNDLG.C
  • WMU_CHARACTER : UNIPUT.H
  • WMU_NEWFONT : UNIPUT.H
  • WMU_NEWRANGE : UNIPUT.H
  • WMU_SETNCHAR : UNIPUT.H
  • WMU_SETTARGETNAME : UNIPUT.H
  • WNDCLASSNAME : GUIGREP.C
  • WndProc() : GLOBALS.H , BROWSE.C , NDDECHAT.C , GLOBALS.H
  • WORKING : ENUMDLG.H
  • Write() : READWRIT.C
  • WriteDataBase() : DATABASE.H , DATABASE.C
  • WriterProc() : OVCOMM.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- x -

  • X : CURSOR.C
  • Xform : FRACTAL.H
  • xForm : WORLD.C
  • Xform2 : FRACTAL.H
  • XformFix : FRACTAL.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y
Here is a list of all functions, variables, defines, enums, and typedefs with links to the files they belong to:

- y -

  • Y : CURSOR.C
  • YRMASK : SETINFO.H
  • YRSHIFT : SETINFO.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- a -

  • ACCEL_ID : MDI.H
  • ACTIONMOVE : SUBCLASS.H
  • ACTIONNONE : SUBCLASS.H
  • ACTIONSIZEX : SUBCLASS.H
  • ACTIONSIZEXY : SUBCLASS.H
  • ACTIONSIZEY : SUBCLASS.H
  • AID_COPY : MASKBLT.H , STREBLT.H
  • AID_CYCLE : MASKBLT.H , STREBLT.H
  • AID_PASTE : MASKBLT.H , STREBLT.H
  • AMP_DESC : STEREO.H
  • AMP_DLG : STEREO.H
  • AMP_ICON : STEREO.H
  • AMP_NAME : STEREO.H
  • APIENTRY : WIN16EXT.H
  • APPNAME : GLOBALS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- l -

  • LASTSTRING : WORLD.C
  • LINEINC : WORLD.C
  • LOCAL_DEVICE_NAME : WINNET.C
  • LOGNAME : LOG.C
  • LOGSOURCE : LOG.C
  • LONG2POINT : MENU.H
  • lpTB : GUIGREP.C
  • LPTSTR : PLATFORM.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- m -

  • MACHINE : LOG.C
  • MAX : DATABASE.C , MACROS.H , READWRIT.C
  • MAX_CONCURRENT_THREADS : GUIGREP.H
  • MAX_ITEM : COMMON.H
  • MAX_MSG_LENGTH : LOG.C
  • MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST : WINNET.C
  • MAX_NUMBER_OF_RESOURCES_TO_ENUM : WINNET.C
  • MAX_READ_BUFFER : OVCOMM.H
  • MAX_SIZE : COMMON.H
  • MAX_WRITE_BUFFER : OVCOMM.H
  • MAXCALLS : COMMON.H
  • MAXCHARS : SUBCLASS.H , STATUS.C , MASKBLT.H , STREBLT.H
  • MAXCOLORS : COLOR.H
  • MAXDOUBLELEN : FRACTAL.H
  • MAXINPUT : WORLD.C
  • MAXLINELEN : GUIGREP.H
  • MAXPATHLEN : FRACTAL.H
  • MAXPOINTS : POLYDRAW.H
  • MAXRGNSTRUCTS : REGIONS.H
  • MAXSEGMENTS : DISPLAY.C
  • MAXTCHAR : LOCALE.H
  • MBERROR : UNIPUT.H
  • MBERRORFLAGS : UNIPUT.H
  • MBGETFONTDATAERR : UNIPUT.H
  • MEASUREITEMHEIGHT : MENU.H
  • MEASUREITEMWIDTH : MENU.H
  • MIN : MACROS.H
  • MINMASK : SETINFO.H
  • MINREC_FILENAME : RECHOOK.C
  • MINREC_SIGNATURE : RECHOOK.C
  • MINSHIFT : SETINFO.H
  • MINSIZE : SUBCLASS.H
  • MM_ABOUT : MDI.H
  • MM_MDI : MDI.H
  • MM_OPT_1 : MDI.H
  • MM_OPT_2 : MDI.H
  • MM_OPT_3 : MDI.H
  • MM_OPT_4 : MDI.H
  • MM_OPT_5 : MDI.H
  • MM_OPT_6 : MDI.H
  • MM_OPT_7 : MDI.H
  • MM_OPT_8 : MDI.H
  • MM_RESERVE1 : MDI.H
  • MM_RESERVE2 : MDI.H
  • MONMASK : SETINFO.H
  • MONSHIFT : SETINFO.H
  • move : DEBUG.C
  • MPOINT2POINT : CURSOR.H
  • MSG_ID_MASK : LOG.C
  • MUTX1 : DATABASE.C
  • MYMAIN : REBOOT.C
  • MYPRINT : MYUT.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- n -

  • NBYTES : DISPLAY.C
  • NClipCaps : GETDEV.H
  • NCurveCaps : GETDEV.H
  • NDevice : GETDEV.H
  • NINDEX : GETDEV.H
  • NITER : CURSOR.C
  • NLANG : LOCALE.H
  • NLineCaps : GETDEV.H
  • NLOCALEENTRIES : LOCALE.H
  • NMODES : STREBLT.H
  • NOMINMAX : ASYN_IO.C , DATABASE.C , READWRIT.C
  • NONE : STREBLT.C , MASKBLT.C , POLYDRAW.H
  • NPATTERNS : MASKBLT.H , STREBLT.H
  • NPolygonalCaps : GETDEV.H
  • NRANGE : DISPLAY.H
  • NRasterCaps : GETDEV.H
  • NROPS : MASKBLT.H , STREBLT.H
  • NSYSCOLORS : GETSYS.H
  • NTextCaps : GETDEV.H
  • NUM_APPLETS : STEREO.C
  • NUM_HANDLES : ENUMTHRD.H
  • NUMBER_OF_WRITES : IOCOMP.C
  • NUMCHARS : DISPLAY.C
  • NUMHOOKS : HOOKTEST.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- o -

  • OEMRESOURCE : BOB.C
  • OFFSETERROR : DISPLAY.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- b -

  • BACKGROUND_COLOR : COLOR.H
  • BITMAP_HEIGHT : ENUMUTIL.H
  • BITMAP_START : ENUMUTIL.H
  • BITMAP_WIDTH : ENUMUTIL.H
  • BLUE : SEMA.H
  • BOB : BOB.H
  • BUFFER_SIZE : IOCOMP.C
  • BUFSIZE : TIMERS.H , DRIVES.C , WALK.H , THE_DLL.H
  • BUTTONBORDER : TIMERS.H
  • BUTTONHEIGHT : TIMERS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- c -

  • CCERR_CHOOSECOLORCODES : CDERR.H
  • CDERR_DIALOGFAILURE : CDERR.H
  • CDERR_FINDRESFAILURE : CDERR.H
  • CDERR_GENERALCODES : CDERR.H
  • CDERR_INITIALIZATION : CDERR.H
  • CDERR_LOADRESFAILURE : CDERR.H
  • CDERR_LOADSTRFAILURE : CDERR.H
  • CDERR_LOCKRESFAILURE : CDERR.H
  • CDERR_MEMALLOCFAILURE : CDERR.H
  • CDERR_MEMLOCKFAILURE : CDERR.H
  • CDERR_NOHINSTANCE : CDERR.H
  • CDERR_NOHOOK : CDERR.H
  • CDERR_NOTEMPLATE : CDERR.H
  • CDERR_STRUCTSIZE : CDERR.H
  • CFERR_CHOOSEFONTCODES : CDERR.H
  • CFERR_NOFONTS : CDERR.H
  • CLIPPATHALT : PATHS.H
  • CLIPPATHWIND : PATHS.H
  • CMAPHEX : DISPLAY.C
  • CPCAPTION : STEREO.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- d -

  • DAYMASK : SETINFO.H
  • DAYSHIFT : SETINFO.H
  • DEFAULT : ASYN_IO.C
  • DEFAULTBUTTON : BOB.H
  • DIALOGHEIGHT : SHAREMEM.H , STREBLT.H , MASKBLT.H , OTHRPROC.H , SETINFO.H
  • DID_CB_MODE : MASKBLT.H , STREBLT.H
  • DID_CB_PATTERN : MASKBLT.H , STREBLT.H
  • DID_CB_ROPS : MASKBLT.H , STREBLT.H
  • DID_COMBOBOX : LOCALE.H
  • DID_DIRECTORY : GETSYS.H
  • DID_DRAW : MASKBLT.H , STREBLT.H
  • DID_HEIGHT : MASKBLT.H , STREBLT.H
  • DID_INFO : GETSYS.H
  • DID_LISTBOX : GETDEV.H , GETSYS.H , LOCALE.H
  • DID_LOCALTIME : GETSYS.H
  • DID_METRICS : GETSYS.H
  • DID_NEWMASK : MASKBLT.H
  • DID_NEWSRC : MASKBLT.H , STREBLT.H
  • DID_PALETTE : GETSYS.H
  • DID_ROP0 : MASKBLT.H , STREBLT.H
  • DID_ROP1 : MASKBLT.H , STREBLT.H
  • DID_ROP2 : MASKBLT.H , STREBLT.H
  • DID_ROP3 : MASKBLT.H
  • DID_SRCHEIGHT : STREBLT.H
  • DID_SRCWIDTH : STREBLT.H
  • DID_SYSCOLORS : GETSYS.H
  • DID_TEXT : GETSYS.H , LOCALE.H
  • DID_TIME : GETSYS.H
  • DID_VERSIONEX : GETSYS.H
  • DID_WIDTH : MASKBLT.H , STREBLT.H
  • DID_X : MASKBLT.H , STREBLT.H
  • DID_XMASK : MASKBLT.H
  • DID_XSRC : MASKBLT.H , STREBLT.H
  • DID_Y : STREBLT.H , MASKBLT.H
  • DID_YMASK : MASKBLT.H
  • DID_YSRC : STREBLT.H , MASKBLT.H
  • DISABLE_COMBINERGN : REGIONS.H
  • DISPLAYCLASS : UNIPUT.H
  • DLGPROC : WIN16EXT.H
  • DLLBITMAP_HEIGHT : THE_DLL.H
  • DLLBITMAP_WIDTH : THE_DLL.H
  • DOM_NDX : ENUMUTIL.H
  • DOMAIN_BMP : ENUMDLG.H
  • DOMAINEX_BMP : ENUMDLG.H
  • DOMEX_NDX : ENUMUTIL.H
  • DRIVE_CDROM : DRIVES.H
  • DRIVE_FIXED : DRIVES.H
  • DRIVE_RAMDISK : DRIVES.H
  • DRIVE_REMOTE : DRIVES.H
  • DRIVE_REMOVEABLE : DRIVES.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- e -

  • ELLIPTIC_RGN : REGIONS.H
  • ENABLE_COMBINERGN : REGIONS.H
  • ENABLE_OPTIONS : REGIONS.H
  • EPSILON : TRACK.C , SUBCLASS.H
  • ERROR_BUFFER_SIZE : MINREC.C
  • ERROR_CANCELLED : SERVENUM.H , ENUMDLG.C , SERVENUM.H
  • ERROR_FAILURE : ENUMTHRD.H
  • ERROR_NOT_ENOUGH_MEMORY : MEM.H
  • ERROR_SUCCESS : MEM.H
  • EVENT1 : DATABASE.C
  • EVENT2 : DATABASE.C
  • EVENT3 : DATABASE.C
  • EVENT4 : DATABASE.C
  • EVENT_FLAGS : OVCOMM.H
  • EVT_CHAR : OVCOMM.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- f -

  • FAILURE : COMMON.H
  • FILBUFSIZE : GUIGREP.H
  • FILE_LEN : CMNDLG.H
  • FILLPATH : PATHS.H
  • FIRST_PIXEL : FRACTAL.H
  • FIRSTSTRING : WORLD.C
  • FNERR_BUFFERTOOSMALL : CDERR.H
  • FNERR_FILENAMECODES : CDERR.H
  • FNERR_INVALIDFILENAME : CDERR.H
  • FNERR_SUBCLASSFAILURE : CDERR.H
  • FRERR_FINDREPLACECODES : CDERR.H
  • FWW_STEPS : UNIPUT.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- g -

  • GET_WM_COMMAND_CMD : WIN16EXT.H
  • GET_WM_COMMAND_HWND : WIN16EXT.H
  • GET_WM_COMMAND_ID : WIN16EXT.H
  • GETHWND : MYUT.H
  • GRAY : SEMA.H
  • GREEN : SEMA.H , THREADS.H
  • GRIDCOLOR : MASKBLT.H , STREBLT.H , UNIPUT.C
  • GWLU_NCHAR : DISPLAY.C
  • GWLU_SQRHEIGHT : DISPLAY.C
  • GWLU_SQRWIDTH : DISPLAY.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- h -

  • HANDLE_DOM : ENUMTHRD.H
  • HANDLE_PROV : ENUMTHRD.H
  • HANDLE_SERV : ENUMTHRD.H
  • HIGHLIGHT_NDX : ENUMUTIL.H
  • HITSIZE : POLYDRAW.H
  • HORZSCALE : WORLD.C
  • HRMASK : SETINFO.H
  • HRSHIFT : SETINFO.H
  • HSCROLLMAX : WORLD.C
  • hwndMDIClient : GLOBALS.H , DLLDISP.H , GLOBALS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- i -

  • ICONFILE : GLOBALS.H
  • ID_ABOUT : MENU.H
  • ID_ADDBUTTON : OWNCOMBO.H
  • ID_BLACK : OWNCOMBO.H
  • ID_BLUE : OWNCOMBO.H
  • ID_CANCEL : APP16.H
  • ID_CBDIRBUTTON : OWNCOMBO.H
  • ID_CLRBUTTON : OWNCOMBO.H
  • ID_COMBOBOX : OWNCOMBO.H
  • ID_CPYBUTTON : OWNCOMBO.H
  • ID_DELETEBUTTON : OWNCOMBO.H
  • ID_DRAWWAVES : RESOURCE.H
  • ID_FNDSELBUTTON : OWNCOMBO.H
  • ID_GREEN : OWNCOMBO.H
  • ID_ITERATION : FRACTAL.H
  • ID_LISTBOX : OWNCOMBO.H
  • ID_NUMSELBUTTON : OWNCOMBO.H
  • ID_OK : APP16.H
  • ID_RED : OWNCOMBO.H
  • ID_SAVEAS : FRACTAL.H
  • ID_SINGLEEDIT : OWNCOMBO.H
  • ID_STEPSBOX : OWNCOMBO.H
  • ID_TEXT1 : OWNCOMBO.H
  • ID_TEXT2 : OWNCOMBO.H
  • ID_TIMER1 : TIMERS.H
  • ID_TIMER2 : TIMERS.H
  • ID_TIMER3 : TIMERS.H
  • ID_TIMER4 : TIMERS.H
  • ID_TXTSELBUTTON : OWNCOMBO.H
  • ID_UNSLBUTTON : OWNCOMBO.H
  • ID_WHITE : OWNCOMBO.H
  • ID_XFROM : FRACTAL.H
  • ID_XTO : FRACTAL.H
  • ID_YFROM : FRACTAL.H
  • ID_YTO : FRACTAL.H
  • IDB_ATTR : SETINFO.H
  • IDB_HELP : ENUMDLG.H
  • IDB_OPENFILE : SETINFO.H
  • IDB_SET : SETINFO.H
  • IDB_STEP : SETINFO.H
  • IDC_AGE : APP16.H
  • IDC_ARC : SETINFO.H
  • IDC_FIRSTNAME : APP16.H
  • IDC_HIDE : SETINFO.H
  • IDC_HORZ : WORLD.H
  • IDC_LASTNAME : APP16.H
  • IDC_NORMAL : SETINFO.H
  • IDC_READ : SETINFO.H
  • IDC_STATIC : GLOBALS.H , ENUMDLG.H
  • IDC_SYSTEM : SETINFO.H
  • IDC_VERT : WORLD.H
  • IDCOLORS_POS : MENU.H
  • IDD_VERFIRST : GLOBALS.H
  • IDD_VERLAST : GLOBALS.H
  • IDE_ALLOCBASE : VIRTMEM.H
  • IDE_API : SETINFO.H
  • IDE_BASEADDR : VIRTMEM.H
  • IDE_DAY : SETINFO.H
  • IDE_FILENAME : SETINFO.H
  • IDE_HOURS : SETINFO.H
  • IDE_INITPROT : VIRTMEM.H
  • IDE_MINUTES : SETINFO.H
  • IDE_MONTH : SETINFO.H
  • IDE_PROTECT : VIRTMEM.H
  • IDE_RECV : GLOBALS.H
  • IDE_RETSTAT : SETINFO.H
  • IDE_SECONDS : SETINFO.H
  • IDE_SEND : GLOBALS.H
  • IDE_SERVER : ENUMDLG.H
  • IDE_SERVERNAME : CONNECT.H , DDECBACK.H
  • IDE_SIZE : SETINFO.H , VIRTMEM.H
  • IDE_STATE : VIRTMEM.H
  • IDE_TIME : SETINFO.H
  • IDE_XCOORD : OTHRPROC.H , SHAREMEM.H
  • IDE_YCOORD : OTHRPROC.H , SHAREMEM.H
  • IDE_YEAR : SETINFO.H
  • IDEDIT : CMNDLG.H
  • IDFILE_POS : MENU.H
  • IDHELP_POS : MENU.H
  • IDL_BROWSE : ENUMDLG.H
  • IDM_ABOUT : CLIPTEXT.H , CMNDLG.H , CURSOR.H , GUIGREP.H , NTGREP.H , APP16.H , MENU.H , GLOBALS.H , OWNCOMBO.H , PLATFORM.H , REGIONS.H , LINKTEST.H , LOADTEST.H , UNIPUT.H , WORLD.H
  • IDM_AND : REGIONS.H
  • IDM_ARRANGE : MDI.H
  • IDM_BLACK : MENU.H
  • IDM_BLUE : MENU.H
  • IDM_BUTTON : SUBCLASS.H
  • IDM_CALLWNDPROC : HOOKTEST.H
  • IDM_CANCEL : GUIGREP.H , NTGREP.H
  • IDM_CASCADE : MDI.H
  • IDM_CASESENS : GUIGREP.H , NTGREP.H
  • IDM_CBT : HOOKTEST.H
  • IDM_CHAR10 : UNIPUT.H
  • IDM_CHAR16 : UNIPUT.H
  • IDM_CHAR20 : UNIPUT.H
  • IDM_CHAR32 : UNIPUT.H
  • IDM_CHAR40 : UNIPUT.H
  • IDM_CHAR64 : UNIPUT.H
  • IDM_CHARBASE : UNIPUT.H
  • IDM_CHOOSECOLOR : CMNDLG.H
  • IDM_CHOOSEFONT : CMNDLG.H
  • IDM_CLEAR : CLIPTEXT.H
  • IDM_CLOSEALL : MDI.H
  • IDM_CLOSEFILE : UNIPUT.H
  • IDM_COLOROWNERDR : MENU.H
  • IDM_COMBOBOX : OWNCOMBO.H
  • IDM_COMMIT : VIRTMEM.H
  • IDM_CONNECT : GLOBALS.H
  • IDM_COPY : CLIPTEXT.H , REGIONS.H
  • IDM_COPYDATA : APP16.H
  • IDM_CREATETHREAD : LINKTEST.H , LOADTEST.H
  • IDM_CUSTOM : CMNDLG.H
  • IDM_CUT : CLIPTEXT.H
  • IDM_DEBUG : HOOKTEST.H
  • IDM_DEFGREP : GUIGREP.H , NTGREP.H
  • IDM_DIFF : REGIONS.H
  • IDM_DISCONNECT : GLOBALS.H
  • IDM_DLLDIALOGBOX : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION1 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION2 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION3 : LINKTEST.H , LOADTEST.H
  • IDM_DLLFUNCTION4 : LINKTEST.H , LOADTEST.H
  • IDM_EDIT : SUBCLASS.H
  • IDM_ELLIPSE : REGIONS.H
  • IDM_ENTERNEW : CMNDLG.H
  • IDM_ENUM : GLOBALS.H
  • IDM_ENUMHELP : GLOBALS.H
  • IDM_ERASE : REGIONS.H
  • IDM_EXIT : CLIPTEXT.H , CMNDLG.H , RESOURCE.H , HOOKTEST.H , APP16.H , MENU.H , GLOBALS.H , OWNCOMBO.H , GLOBALS.H , WORLD.H
  • IDM_FILE_EXIT : MINREC.H
  • IDM_FINDTEXT : CMNDLG.H
  • IDM_FONT : MENU.H
  • IDM_FONT18 : UNIPUT.H
  • IDM_FONT36 : UNIPUT.H
  • IDM_FONT72 : UNIPUT.H
  • IDM_FONTBASE : UNIPUT.H
  • IDM_FRAMERGN : REGIONS.H
  • IDM_FREE : VIRTMEM.H
  • IDM_FREELIBRARY : LOADTEST.H
  • IDM_GANORM : THREADS.H
  • IDM_GBNORM : THREADS.H
  • IDM_GETMESSAGE : HOOKTEST.H
  • IDM_GETRGNBOX : REGIONS.H
  • IDM_GHIGH : THREADS.H
  • IDM_GIDLE : THREADS.H
  • IDM_GLOW : THREADS.H
  • IDM_GNORM : THREADS.H
  • IDM_GREEN : MENU.H
  • IDM_GTC : THREADS.H
  • IDM_HELP : OWNCOMBO.H , UNIPUT.H
  • IDM_HELP_ABOUT : MINREC.H
  • IDM_HOOK : CMNDLG.H
  • IDM_INSTALL : GUIGREP.H , NTGREP.H
  • IDM_INVERTRGN : REGIONS.H
  • IDM_KEYBOARD : HOOKTEST.H
  • IDM_LIST : SUBCLASS.H
  • IDM_LISTBOX : OWNCOMBO.H
  • IDM_LOADLIBRARY : LOADTEST.H
  • IDM_LOCK : VIRTMEM.H
  • IDM_MACRO_PLAYBACK : MINREC.H
  • IDM_MACRO_RECORD : MINREC.H
  • IDM_MACRO_STOP : MINREC.H
  • IDM_MDICASCADE : UNIPUT.H
  • IDM_MDITILE : UNIPUT.H
  • IDM_MOUSE : HOOKTEST.H
  • IDM_MSGFILTER : HOOKTEST.H
  • IDM_MULTILISTBOX : OWNCOMBO.H
  • IDM_NEW : CLIPTEXT.H
  • IDM_NEWFILE : UNIPUT.H
  • IDM_NEWWINDOW : UNIPUT.H
  • IDM_NOACCESS : VIRTMEM.H
  • IDM_OFFSETRGN : REGIONS.H
  • IDM_OPEN : CLIPTEXT.H , WORLD.H
  • IDM_OPENFILE : CMNDLG.H
  • IDM_OR : REGIONS.H
  • IDM_OWNERCOMBOBOX : OWNCOMBO.H
  • IDM_PASTE : CLIPTEXT.H
  • IDM_PLATFORM : PLATFORM.H
  • IDM_POLYPOLYGON : REGIONS.H
  • IDM_PRINT : CLIPTEXT.H , CMNDLG.H
  • IDM_PTINRGN : REGIONS.H
  • IDM_RANORM : THREADS.H
  • IDM_RBNORM : THREADS.H
  • IDM_READONLY : VIRTMEM.H
  • IDM_READWRITE : VIRTMEM.H
  • IDM_RECT : REGIONS.H
  • IDM_RECTINRGN : REGIONS.H
  • IDM_RED : MENU.H
  • IDM_REPLACETEXT : CMNDLG.H
  • IDM_RESERVE : VIRTMEM.H
  • IDM_RESUMEGREEN : THREADS.H
  • IDM_RESUMERED : THREADS.H
  • IDM_RHIGH : THREADS.H
  • IDM_RIDLE : THREADS.H
  • IDM_RLOW : THREADS.H
  • IDM_RNORM : THREADS.H
  • IDM_RTC : THREADS.H
  • IDM_SAVE : CLIPTEXT.H
  • IDM_SAVEAS : CLIPTEXT.H
  • IDM_SAVEFILE : CMNDLG.H
  • IDM_SAVEFILEAS : CMNDLG.H
  • IDM_SCALE : WORLD.H
  • IDM_SETRECTRGN : REGIONS.H
  • IDM_SHOW : VIRTMEM.H
  • IDM_SHOWHEX : UNIPUT.H
  • IDM_SHOWNAMES : UNIPUT.H
  • IDM_SIZE : MENU.H
  • IDM_SORTBOX : GUIGREP.H , NTGREP.H
  • IDM_STANDARD : CMNDLG.H
  • IDM_STARTGREP : GUIGREP.H , NTGREP.H
  • IDM_STATE1 : MENU.H
  • IDM_STATE2 : MENU.H
  • IDM_STATE3 : MENU.H
  • IDM_STATE4 : MENU.H
  • IDM_STRINGEDIT : NTGREP.H , GUIGREP.H
  • IDM_STYLE : MENU.H
  • IDM_SUSPENDGREEN : THREADS.H
  • IDM_SUSPENDRED : THREADS.H
  • IDM_TERMBOX : NTGREP.H , GUIGREP.H
  • IDM_TEST : SUBCLASS.H
  • IDM_THUNK : APP16.H
  • IDM_TILE : MDI.H
  • IDM_UNDO : CLIPTEXT.H
  • IDM_UNINSTALL : NTGREP.H , GUIGREP.H
  • IDM_UNLOCK : VIRTMEM.H
  • IDM_WRITE : VIRTMEM.H
  • IDM_XOR : REGIONS.H
  • IDS_APPNAME : MINREC.H , GLOBALS.H
  • IDS_BUFFERTOOSMALL : CMNDLG.H
  • IDS_CREATEICFAILURE : CMNDLG.H
  • IDS_DESCRIPTION : GLOBALS.H
  • IDS_DIALOGFAILURE : CMNDLG.H
  • IDS_DNDMMISMATCH : CMNDLG.H
  • IDS_FILTERSTRING : CMNDLG.H
  • IDS_FINDRESFAILURE : CMNDLG.H
  • IDS_GETDEVMODEFAIL : CMNDLG.H
  • IDS_INITFAILURE : CMNDLG.H
  • IDS_INITIALIZATION : CMNDLG.H
  • IDS_INVALIDFILENAME : CMNDLG.H
  • IDS_ITEM : GLOBALS.H
  • IDS_LOADDRVFAILURE : CMNDLG.H
  • IDS_LOADRESFAILURE : CMNDLG.H
  • IDS_LOADSTRFAILURE : CMNDLG.H
  • IDS_LOCKRESFAILURE : CMNDLG.H
  • IDS_MEMALLOCFAILURE : CMNDLG.H
  • IDS_MEMLOCKFAILURE : CMNDLG.H
  • IDS_NODEFAULTPRN : CMNDLG.H
  • IDS_NODEVICES : CMNDLG.H
  • IDS_NOFONTS : CMNDLG.H
  • IDS_NOHINSTANCE : CMNDLG.H
  • IDS_NOHOOK : CMNDLG.H
  • IDS_NOTEMPLATE : CMNDLG.H
  • IDS_PARSEFAILURE : CMNDLG.H
  • IDS_PRINTERNOTFOUND : CMNDLG.H
  • IDS_RETDEFFAILURE : CMNDLG.H
  • IDS_SETUPFAILURE : CMNDLG.H
  • IDS_SHARENAME : GLOBALS.H
  • IDS_SHORT_APPNAME : MINREC.H
  • IDS_STRUCTSIZE : CMNDLG.H
  • IDS_SUBCLASSFAILURE : CMNDLG.H
  • IDS_TOPIC : GLOBALS.H
  • IDS_UNKNOWNERROR : CMNDLG.H
  • idsIteration : FRACTAL.H
  • idsName : FRACTAL.H
  • idsSaveAs : FRACTAL.H
  • IDSTATES_POS : MENU.H
  • idsXFrom : FRACTAL.H
  • idsXTo : FRACTAL.H
  • idsYFrom : FRACTAL.H
  • idsYTo : FRACTAL.H
  • IDT_SELECT : ENUMDLG.H
  • IMPLEMENTED : VIRTMEM.C
  • INC : MASKBLT.H , SUBCLASS.H , STREBLT.H
  • INITCLASSNAME : NTGREP.C
  • IO_ERROR : ASYN_IO.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- p -

  • PAGEINC : WORLD.C
  • PAGESIZE : VIRTMEM.H
  • PARAM_SIZE : LOG.C
  • PDERR_CREATEICFAILURE : CDERR.H
  • PDERR_DNDMMISMATCH : CDERR.H
  • PDERR_GETDEVMODEFAIL : CDERR.H
  • PDERR_INITFAILURE : CDERR.H
  • PDERR_LOADDRVFAILURE : CDERR.H
  • PDERR_NODEFAULTPRN : CDERR.H
  • PDERR_NODEVICES : CDERR.H
  • PDERR_PARSEFAILURE : CDERR.H
  • PDERR_PRINTERCODES : CDERR.H
  • PDERR_PRINTERNOTFOUND : CDERR.H
  • PDERR_RETDEFFAILURE : CDERR.H
  • PDERR_SETUPFAILURE : CDERR.H
  • PERR : LOG.C , STARTP.C , WINNET.C
  • PMSG : WINNET.C
  • POINT2MPOINT : CURSOR.H
  • POINTSIZE : ABOUT.C
  • POLYPOLYGON_RGN : REGIONS.H
  • POLYPOLYGONCOUNT : REGIONS.H
  • PrintAppStyleAPIError : WINNET.C
  • PROV_NDX : ENUMUTIL.H
  • PROVEX_NDX : ENUMUTIL.H
  • PROVIDER_BMP : ENUMDLG.H
  • PROVIDEREX_BMP : ENUMDLG.H
  • PURGE_FLAGS : OVCOMM.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- r -

  • READ_TIMEOUT : OVCOMM.H
  • RECT_RGN : REGIONS.H
  • RECTSIZE : TRACK.C
  • RED : SEMA.H , THREADS.H
  • REG_ERR : LOG.C
  • REMOTE_MSG_DLL_PATH : LOG.C
  • RESET_ALL : REGIONS.H
  • RESOURCE_BUF_ENTRIES : WINNET.C
  • RETURN_IMEDIATELY : ASYN_IO.C
  • RGBQ : MISCUTIL.C
  • ROP_PSDPxax : MENU.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- s -

  • SBORDER : UNIPUT.H
  • SECMASK : SETINFO.H
  • SECSHIFT : SETINFO.H
  • SECTOR_SIZE : ASYN_IO.C
  • SEGMENTERROR : DISPLAY.C
  • SELECTEDBUTTON : BOB.H
  • SEM1 : DATABASE.C
  • SEPARATORWIDTH : MASKBLT.H , STREBLT.H
  • SERV_NDX : ENUMUTIL.H
  • SERVER_BMP : ENUMDLG.H
  • ServerEnumDialog : SERVENUM.H
  • SFIELD0 : UNIPUT.H
  • SFIELD1 : UNIPUT.H
  • SID_BUF_SIZE : LOG.C
  • SIGNALED : DATABASE.C
  • SIZE : CURSOR.C
  • SIZEOFCAPTIONTEXT : MDI.H
  • START_NDX : ENUMUTIL.H
  • STATE_CLIENT : GLOBALS.H
  • STATE_PENDING : GLOBALS.H
  • STATE_SERVER : GLOBALS.H
  • STATE_UNCONN : GLOBALS.H
  • STATUS_CHECK_TIMEOUT : OVCOMM.H
  • STATUSHEIGHT : UNIPUT.C
  • STR_DWORD : GLOBALS.H
  • STRICT : REBOOT.C , MDI.C , MINREC.C , RECHOOK.C , MDI.C , PLATFORM.C , DATABASE.C , READWRIT.C , WINNET.C , BOB.C , ASYN_IO.C
  • STROKEANDFILLALT : PATHS.H
  • STROKEANDFILLWIND : PATHS.H
  • STROKEPATH : PATHS.H
  • SubclassWindow : BOB.H
  • SUCCESS : COMMON.H , ASYN_IO.C
  • SZ_BUF : WINNET.C
  • SZ_ERROR_BUF : WINNET.C
  • SZ_PROVIDER_NAME_BUF : WINNET.C
  • SZABOUT : GLOBALS.H
  • SZAPPNAME : GLOBALS.H
  • SZDESCRIPTION : GLOBALS.H
  • szMsgBuf : WINNET.C
  • SZRAPPNAME : GLOBALS.H
  • SZRCOMPANYNAME : GLOBALS.H
  • SZRCOPYRIGHT : GLOBALS.H
  • SZRDESCRIPTION : GLOBALS.H
  • SZRPRODNAME : GLOBALS.H
  • SZRPRODVER : GLOBALS.H
  • SZRTRADEMARK : GLOBALS.H
  • SZRVERSION : GLOBALS.H
  • SZVERSION : GLOBALS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- t -

  • TAPE_DESC : STEREO.H
  • TAPE_DLG : STEREO.H
  • TAPE_ICON : STEREO.H
  • TAPE_NAME : STEREO.H
  • TCHAR : PLATFORM.C
  • TEST_REPEAT_COUNT : IOCOMP.C
  • TEXT : PLATFORM.C
  • TEXTHEIGHT : TIMERS.H
  • TICKSPACE : MASKBLT.C , STREBLT.C , UNIPUT.C
  • TIMERINTERVAL : TIMERS.H
  • TMALL : TRACK.H
  • TMMOVE : TRACK.H
  • TMNONE : TRACK.H
  • TMROTATE : TRACK.H
  • TMSHEARX : TRACK.H
  • TMSHEARY : TRACK.H
  • TMSIZEX : TRACK.H
  • TMSIZEXY : TRACK.H
  • TMSIZEY : TRACK.H
  • TRECT_DELETE : REGIONS.H
  • TRECT_NEW : REGIONS.H
  • TRECT_PAINT : REGIONS.H
  • TROB_DELETE : TRACK.H
  • TROB_HITTEST : TRACK.H
  • TROB_NEW : TRACK.H
  • TROB_PAINT : TRACK.H
  • TUNER_DESC : STEREO.H
  • TUNER_DLG : STEREO.H
  • TUNER_ICON : STEREO.H
  • TUNER_NAME : STEREO.H
  • TWO_PI : PATHS.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- u -

  • UCFONTHEIGHT : UNIPUT.H
  • UCFONTWIDTH : UNIPUT.H
  • UNICODE : DISPLAY.C , STATUS.C , LOCALE.C , UNIPUT.C
  • UNICODE_CHARSET : UNIPUT.H , LOCALE.H
  • UNREFERENCED_PARAMETER : PLATFORM.C
  • USESTDHANDLES : INHERIT.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- v -

  • VERTSCALE : WORLD.C
  • VSCROLLMAX : WORLD.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- w -

  • W32SUT_16 : DLL16.C
  • W32SUT_32 : UTDLL32.C
  • WAIT_ERROR : DATABASE.C , ASYN_IO.C
  • WERR : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • WF1_WINNT : PLATFORM.C
  • WF_WINNT : MYUT.H
  • WHICH_TO_USE_FROM_LIST : WINNET.C
  • WIN32S : BOB.C
  • WINAPI : PLATFORM.C
  • WM_ADDITEM : GUIGREP.H
  • WM_CONNECT : GLOBALS.H
  • WM_COPYDATA : APP16.C
  • WM_DISCONNECT : GLOBALS.H
  • WM_ENUM_EXPAND : ENUMDLG.H
  • WM_FREEAGAIN : GUIGREP.H
  • WM_INIT_ENUM : ENUMDLG.H
  • WM_INQUIREFILES : GUIGREP.H
  • WM_LAUNCH : GUIGREP.H
  • WM_MASKBLT : MASKBLT.H
  • WM_PUTUPDESTRECT : MASKBLT.H , STREBLT.H
  • WM_PUTUPMASKPT : MASKBLT.H
  • WM_PUTUPSRCRECT : STREBLT.H , MASKBLT.H
  • WM_RECEIVE_TEXT : GLOBALS.H
  • WM_REPSTAT : SETINFO.H
  • WM_SC_CREATE : SUBCLASS.H
  • WM_STARTSYNC : GUIGREP.H
  • WM_STRETCHBLT : STREBLT.H
  • WM_TELLHANDLE : GUIGREP.H
  • WMU_CHARACTER : UNIPUT.H
  • WMU_NEWFONT : UNIPUT.H
  • WMU_NEWRANGE : UNIPUT.H
  • WMU_SETNCHAR : UNIPUT.H
  • WMU_SETTARGETNAME : UNIPUT.H
  • WNDCLASSNAME : GUIGREP.C
  • WORKING : ENUMDLG.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- x -

  • Xform : FRACTAL.H
  • Xform2 : FRACTAL.H
  • XformFix : FRACTAL.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • u
  • v
  • w
  • x
  • y

- y -

  • YRMASK : SETINFO.H
  • YRSHIFT : SETINFO.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • EDWP : GLOBALS.H , DLLDISP.H , GLOBALS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • edwpDialog : GLOBALS.H , DLLDISP.H
  • edwpMDIChild : GLOBALS.H , DLLDISP.H
  • edwpMDIFrame : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • edwpNone : GLOBALS.H , DLLDISP.H
  • edwpWindow : GLOBALS.H , DLLDISP.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- _ -

  • __based() : SHRSTUFF.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- j -

  • JournalPlaybackProc() : RECHOOK.C
  • JournalRecordProc() : RECHOOK.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- k -

  • KeyboardProc() : HOOKTEST.C , HOOKTEST.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- l -

  • LibMain() : DLL16.C
  • ListBoxExample() : OWNCOMBO.C , OWNCOMBO.H
  • ListSubProc() : ENUMDLG.C , ENUMDLG.H
  • LoadBitmapArray() : ENUMUTIL.H , ENUMUTIL.C
  • LoadLibraryEx32W() : MYUT.H
  • lookupStringFromMsgDll() : LOG.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- m -

  • main() : ASYN_IO.C , BNDBUFC.C , CHGDATA.C , DRIVES.H , STARTP.C , TERMPROC.C , ASYN_IO.C , TLSCALL.C , WALK.C , READDATA.C , CHILD.C , WALK.H , WINNET.C , INHERIT.C , BNDBUFS.C , COLOR.C , IOCOMP.C , LOG.C , DRIVES.C , OVCOMM.C , READWRIT.C
  • MainDlgProc() : GETDEV.C , GETDEV.H , GETSYS.C , GETSYS.H , LOCALE.C , LOCALE.H , MINREC.C
  • MainWndProc() : CMNDLG.C , SHAREMEM.C , SHAREMEM.H , CMNDLG.H , LINKTEST.C , LINKTEST.H , CURSOR.C , LOADTEST.C , LOADTEST.H , CURSOR.H , STREBLT.C , STREBLT.H , GLTHREAD.C , SUBCLASS.C , SUBCLASS.H , GUIGREP.H , THREADS.C , THREADS.H , NTGREP.C , TIMERS.C , TIMERS.H , HOOKTEST.C , UNIPUT.C , UNIPUT.H , HOOKTEST.H , VIRTMEM.C , VIRTMEM.H , APP16.C , WORLD.C , DISP32.C , STUB32.C , MASKBLT.C , MASKBLT.H , MDI.C , OTHRPROC.C , OTHRPROC.H , PATHS.C , PATHS.H , PLATFORM.C , PLATFORM.H , POLYDRAW.C , POLYDRAW.H , REGIONS.C , REGIONS.H , BOB.C , MAIN.C , MAIN.H , BOB.H , SEMA.C , SEMA.H , CLIPTEXT.C , SETINFO.C , SETINFO.H
  • MallocMem() : MEM.C , MEM.H , MEM.C , MEM.H
  • MarkOutstanding() : THRDUTIL.C , THRDUTIL.H
  • MDIWndProc() : MDI.C
  • MenuInit() : MENU.H , MENU.C
  • MenuWndProc() : MENU.C , MENU.H
  • MessageProc() : HOOKTEST.C , HOOKTEST.H
  • MIDL_user_allocate() : BNDBUFC.C , BNDBUFS.C
  • MIDL_user_free() : BNDBUFC.C , BNDBUFS.C
  • MouseMove() : TRACK.C , TRACK.H
  • MouseProc() : HOOKTEST.C , HOOKTEST.H
  • MsgAboutCommand() : ABOUT.C
  • MsgAboutInit() : ABOUT.C
  • MsgCommand() : NDDECHAT.C , BROWSE.C , GLOBALS.H
  • MsgConnect() : GLOBALS.H , NDDECHAT.C
  • MsgConnectDlgCommand() : CONNECT.C
  • MsgConnectDlgInit() : CONNECT.C
  • MsgCreate() : GLOBALS.H , NDDECHAT.C , BROWSE.C , GLOBALS.H
  • MsgDestroy() : GLOBALS.H , NDDECHAT.C , GLOBALS.H , BROWSE.C
  • MsgDisconnect() : GLOBALS.H , NDDECHAT.C
  • MsgEnumDlgCharToItem() : ENUMDLG.C
  • MsgEnumDlgCommand() : ENUMDLG.C
  • MsgEnumDlgDestroy() : ENUMDLG.C
  • MsgEnumDlgDrawItem() : ENUMDLG.C
  • MsgEnumDlgEnumExpand() : ENUMDLG.C
  • MsgEnumDlgInit() : ENUMDLG.C
  • MsgEnumDlgInitEnum() : ENUMDLG.C
  • MsgEnumDlgMeasureItem() : ENUMDLG.C
  • MsgEnumDlgSetCursor() : ENUMDLG.C
  • MsgEnumDlgSysColor() : ENUMDLG.C
  • MsgEnumDlgVKeyToItem() : ENUMDLG.C
  • MsgReceiveText() : GLOBALS.H , NDDECHAT.C
  • MsgSetFocus() : GLOBALS.H
  • MsgSize() : NDDECHAT.C , GLOBALS.H
  • MyCombineRgn() : REGIONS.H , REGIONS.C
  • MyCreateRgn() : REGIONS.C , REGIONS.H
  • myError() : CHILD.C
  • MYMAIN() : REBOOT.C
  • MyPrint() : DLL16.C , DISP32.C , UTDLL32.C , DLL32.C , APP16.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- n -

  • NewAngleArc() : PATHS.C , PATHS.H
  • notifyChange() : LOG.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- o -

  • Open_Do_Close_1_Enum() : WINNET.C
  • openDisplay() : DISPLAY.C , UNIPUT.H
  • OpenEnum() : WINNET.C
  • OpenMetafile() : WORLD.C
  • OpenNewFile() : UNIPUT.C , CMNDLG.C , CMNDLG.H
  • OutOfMemory() : CLIPTEXT.C
  • OutputABuffer() : OVCOMM.C
  • OwnComboInit() : OWNCOMBO.H , OWNCOMBO.C
  • OwnComboWndProc() : OWNCOMBO.H , OWNCOMBO.C
  • OwnerComboBoxExample() : OWNCOMBO.H , OWNCOMBO.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- a -

  • About() : BOB.C , BOB.H , CMNDLG.C , GUIGREP.C , ABOUT.C , MDI.C , GUIGREP.C , OWNCOMBO.C , OWNCOMBO.H , CMNDLG.H , GUIGREP.H , PLATFORM.C , PLATFORM.H , NTGREP.C , UNIPUT.C , UNIPUT.H , CLIPTEXT.C , CURSOR.C , NTGREP.C , MDI.C , CURSOR.H , MENU.C , MENU.H
  • AboutDlgProc() : APP16.C , WORLD.C , MINREC.C , LINKTEST.C , LINKTEST.H , REGIONS.C , LOADTEST.C , REGIONS.H , LOADTEST.H
  • AddGetGetCancel() : WINNET.C
  • AddGetGetCancel2() : WINNET.C
  • addSourceToRegistry() : LOG.C
  • AmpDlgProc() : STEREO.C , STEREO.H
  • Another_Thread() : TLSCALL.C
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- b -

  • bColorCycle() : FRACTAL.C
  • bGetPPStr() : FRACTAL.C
  • bInitDlgItems() : FRACTAL.C
  • bInitInfo() : FRACTAL.C
  • BOOL() : UTDLL32.C
  • BreakDownCommPort() : OVCOMM.H , OVCOMM.C
  • bSetupPixelFormat() : THREADS.C , GLTHREAD.H
  • ButtonProc() : BOB.C , BOB.H
Generated on Wed Nov 13 2024 17:29:13 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- c -

  • CalculateVectorNormal() : GLTHREAD.H , THREADS.C
  • CallFindText() : CMNDLG.H , CMNDLG.C
  • CallProc32W() : MYUT.H
  • CallReplaceText() : CMNDLG.C , CMNDLG.H
  • CallWndProc() : HOOKTEST.C , HOOKTEST.H
  • CBTProc() : HOOKTEST.C , HOOKTEST.H
  • CenterWindow() : MISCUTIL.C , MISCUTIL.H , GLOBALS.H , MISC.C , GLOBALS.H , MISC.C
  • CheckModemStatus() : OVCOMM.C
  • CheckRM() : DRIVES.C , DRIVES.H
  • ChooseColorHookProc() : CMNDLG.C , CMNDLG.H
  • ChooseFontHookProc() : CMNDLG.C , CMNDLG.H
  • ChooseNewColor() : CMNDLG.C , CMNDLG.H
  • ChooseNewFont() : CMNDLG.C , CMNDLG.H
  • CleanupApp() : DATABASE.C
  • CleanupSubsystem() : DATABASE.C
  • CloseDataBase() : DATABASE.C
  • closeDisplay() : DISPLAY.C , UNIPUT.H
  • CmdAbout() : ABOUT.C , GLOBALS.H
  • CmdAboutDone() : ABOUT.C
  • CmdConnectDlg() : GLOBALS.H , NDDECHAT.C
  • CmdConnectDlgCancel() : CONNECT.C
  • CmdConnectDlgOK() : CONNECT.C
  • CmdDisconnect() : GLOBALS.H , NDDECHAT.C
  • CmdEnumDlg() : BROWSE.C , GLOBALS.H
  • CmdEnumDlgBrowse() : ENUMDLG.C
  • CmdEnumDlgCancel() : ENUMDLG.C
  • CmdEnumDlgHelp() : ENUMDLG.C
  • CmdEnumDlgOK() : ENUMDLG.C
  • CmdEnumHelpDlg() : BROWSE.C , GLOBALS.H
  • CmdExit() : BROWSE.C , GLOBALS.H , NDDECHAT.C , GLOBALS.H
  • CmdSendNotify() : NDDECHAT.C , GLOBALS.H
  • ColorWndProc() : GUIGREP.C
  • ComboBoxExample() : OWNCOMBO.H , OWNCOMBO.C
  • CommandHandler() : GLTHREAD.C
  • CompareEnumNode() : ENUMUTIL.C , ENUMUTIL.H
  • ComponentFromIndex() : THREADS.C
  • ConnectDlg() : CONNECT.C , CONNECT.H
  • consumer() : BNDBUFC.C
  • ControlHandlerProc() : OVCOMM.C
  • CountUCSegments() : DISPLAY.C
  • CPlApplet() : STEREO.H , STEREO.C
  • CreateRGBPalette() : THREADS.C
  • CreateStdFont() : MISCUTIL.H , MISCUTIL.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- d -

  • DdeCallback() : DDECBACK.C , DDECBACK.H
  • DebugMsg() : DATABASE.C
  • DebugProc() : HOOKTEST.C , HOOKTEST.H
  • dinfo() : DEBUG.C
  • DispCommand() : GLOBALS.H , DISPATCH.C , GLOBALS.H , DLLDISP.C , DLLDISP.H , DISPATCH.C
  • DispDefault() : DISPATCH.C , DLLDISP.C
  • DisplayError() : REBOOT.C
  • DisplayWndProc() : DISPLAY.C , UNIPUT.H
  • DispMessage() : DISPATCH.C , GLOBALS.H , DISPATCH.C , GLOBALS.H , DLLDISP.C , DLLDISP.H
  • DlgProc() : MASKBLT.C , MASKBLT.H , STREBLT.C , STREBLT.H
  • DLLDialogBox() : THE_DLL.C , THE_DLL.H
  • DLLDlgProc() : THE_DLL.H , THE_DLL.C
  • DLLFunction1() : THE_DLL.C , THE_DLL.H
  • DLLFunction2() : THE_DLL.C , THE_DLL.H
  • DLLFunction3() : THE_DLL.C , THE_DLL.H
  • DLLFunction4() : THE_DLL.C , THE_DLL.H
  • DllMain() : STEREO.C , GUIGREP.C , DLL32.C , UTDLL32.C , RECHOOK.C , DEBUG.C , DATABASE.C , SERVENUM.C , THE_DLL.C , TLSDLL.C
  • Do_BackgroundTask() : ASYN_IO.C
  • doDirectory() : GETSYS.C , GETSYS.H
  • doInfo() : GETSYS.C , GETSYS.H
  • doLocalTime() : GETSYS.C , GETSYS.H
  • doMetrics() : GETSYS.C , GETSYS.H
  • doPalette() : GETSYS.C , GETSYS.H
  • doSysColors() : GETSYS.H , GETSYS.C
  • doTime() : GETSYS.C , GETSYS.H
  • doTrackObject() : TRACK.C , TRACK.H , TRACK.C , TRACK.H
  • doVersionEx() : GETSYS.H , GETSYS.C
  • draw_scene() : THREADS.C , GLTHREAD.H
  • DrawBitmap() : BOB.C , BOB.H , BITMAP.C , BITMAP.H , MAIN.C , MAIN.H , BITMAP.H
  • DrawEntireItem() : OWNCOMBO.C
  • DrawGrids() : STREBLT.H , STREBLT.C , MASKBLT.H , MASKBLT.C
  • DrawPath() : PATHS.C , PATHS.H
  • DrawStuff() : TIMERS.C , TIMERS.H
  • DrawWave() : GLTHREAD.H , THREADS.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- e -

  • enter_item() : BNDBUFP.C
  • EnterNew() : CMNDLG.C , CMNDLG.H
  • EnumContainerThread() : ENUMTHRD.C , ENUMTHRD.H
  • EnumDlg() : ENUMDLG.C , ENUMDLG.H
  • EnumExpandThread() : ENUMTHRD.C , ENUMTHRD.H
  • EnumListCollapse() : ENUMUTIL.C , ENUMUTIL.H
  • EnumListExpand() : ENUMUTIL.C , ENUMUTIL.H
  • EnumListRecurse() : ENUMUTIL.C , ENUMUTIL.H
  • EnumResources() : WINNET.C
  • ErrorHandler() : OVCOMM.C
  • ErrorInComm() : OVCOMM.C
  • ErrorMessageBox() : MINREC.C
  • ErrorMsg() : DATABASE.C , ASYN_IO.C
  • ErrorOut() : TLSDLL.C , TLSCALL.C , FRACTAL.C , TERMPROC.C
  • ErrorReporter() : OVCOMM.C
  • ExpandInfo() : GETDEV.C , GETDEV.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- f -

  • FileDlgProc() : SETINFO.C , SETINFO.H
  • FileOpenHookProc() : CMNDLG.H , CMNDLG.C
  • FileSaveHookProc() : CMNDLG.C , CMNDLG.H
  • FindFirstDirectory() : WALK.H , WALK.C
  • FindNextDirectory() : WALK.C
  • FindTextHookProc() : CMNDLG.C , CMNDLG.H
  • FixMenu() : LOADTEST.C , LOADTEST.H
  • FMExtensionProc() : GUIGREP.C
  • framechildwindow() : STATUS.C
  • FreeEnumChild() : ENUMUTIL.C , ENUMUTIL.H
  • FreeEnumSync() : ENUMUTIL.C , ENUMUTIL.H
  • FreeLibrary32W() : MYUT.H
  • FreeMem() : MEM.H , MEM.C , MEM.H , MEM.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- g -

  • GetBitmap() : BITMAP.C , BITMAP.H , BITMAP.C
  • GetConsoleTextAttribute() : COLOR.C , COLOR.H
  • GetData() : DATABASE.C
  • GetDataToTrans() : GLOBALS.H , NDDECHAT.C
  • GetMsgProc() : HOOKTEST.H , HOOKTEST.C , RECHOOK.C
  • GetProcAddress32W() : MYUT.H
  • GVI() : DRIVES.H , DRIVES.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- h -

  • HandleChangeColors() : MENU.C
  • HandleCreate() : MENU.C
  • HandleDrawItem() : MENU.C
  • HandleFocusState() : BOB.C , BOB.H , OWNCOMBO.C
  • HandlePaint() : MENU.C
  • HandlePopupMenu() : MENU.C
  • HandleSelectedState() : BOB.C , BOB.H
  • HandleSelectionState() : OWNCOMBO.C
  • help() : STARTP.C
  • HelpProc() : BROWSE.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- i -

  • iCreatePenFrPal() : FRACTAL.C
  • InfoDlgProc() : APP16.C
  • InitApp() : DATABASE.C
  • InitApplication() : BOB.C , CMNDLG.H , INIT.C , PLATFORM.C , CURSOR.C , PLATFORM.H , GLOBALS.H , BOB.H , CURSOR.H , INIT.C , GUIGREP.H , CLIPTEXT.C , NTGREP.C , HOOKTEST.C , CMNDLG.C , HOOKTEST.H , GLOBALS.H
  • InitialEnumThread() : ENUMTHRD.C , ENUMTHRD.H
  • initialize() : GLTHREAD.H , THREADS.C
  • InitializeApp() : MDI.C
  • InitializeDataBase() : DATABASE.C
  • InitializeSubsystem() : DATABASE.C
  • InitializeWindow() : GLTHREAD.C
  • InitInstance() : INIT.C , CLIPTEXT.C , GLOBALS.H , CMNDLG.C , PLATFORM.H , CMNDLG.H , CURSOR.H , GUIGREP.H , NTGREP.C , INIT.C , BOB.C , GLOBALS.H , HOOKTEST.H , PLATFORM.C , CURSOR.C , HOOKTEST.C , BOB.H
  • InitStereoApplet() : STEREO.C
  • InitThunk() : UTDLL32.C , STUB32.C
  • insert_buffer() : BNDBUFP.C
  • InsertElement() : CHGDATA.C
  • insertMsgString() : LOG.C
  • IsWin32sLoaded() : DLL16.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- p -

  • PaintRect() : SUBCLASS.C , SUBCLASS.H
  • ParseSwitch() : IOCOMP.C
  • PERR() : INHERIT.C
  • Poll_On_Threads() : GUIGREP.C
  • PrintAPIError() : WINNET.C
  • PrintBanner() : COLOR.H , COLOR.C
  • PrintDlgHookProc() : CMNDLG.C , CMNDLG.H
  • PrintFile() : CMNDLG.C , CMNDLG.H
  • PrintSetupHookProc() : CMNDLG.C , CMNDLG.H
  • ProcessCDError() : CMNDLG.H , CMNDLG.C
  • ProcessFileCommonCode() : GUIGREP.C
  • ProcessIO() : OVCOMM.C
  • produce_item() : BNDBUFC.C
  • producer() : BNDBUFC.C
  • PutData() : DATABASE.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- q -

  • queryEventLog() : LOG.C
  • QueryWindowPos() : SUBCLASS.H , SUBCLASS.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- r -

  • Read() : READWRIT.C
  • ReadDataBase() : DATABASE.C , DATABASE.H
  • ReaderProc() : OVCOMM.C
  • ReadProc() : OTHRPROC.C , OTHRPROC.H
  • ReallocMem() : MEM.H , MEM.C , MEM.H , MEM.C
  • RefreshOutstanding() : THRDUTIL.C , THRDUTIL.H
  • RegisterDialogClasses() : FRACTAL.C
  • remove_buffer() : BNDBUFP.C
  • remove_item() : BNDBUFP.C
  • ReplaceTextHookProc() : CMNDLG.C , CMNDLG.H
  • reportAnEvent() : LOG.C
  • ReportCommError() : OVCOMM.C
  • ReportModemStatus() : OVCOMM.C
  • ReportStatusEvent() : OVCOMM.C
  • RepStat() : SETINFO.C , SETINFO.H
  • Reset() : REGIONS.H , REGIONS.C
  • ResetMenu() : VIRTMEM.C , VIRTMEM.H
  • resize() : GLTHREAD.H , THREADS.C
  • RgnBoxDlgProc() : REGIONS.C , REGIONS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- s -

  • SaveAs() : CMNDLG.C , CMNDLG.H
  • SaveBitmapFile() : FRACTAL.C
  • SaveToFile() : CMNDLG.C , CMNDLG.H
  • ScaleDlgProc() : WORLD.C
  • ScreenSaverConfigureDialog() : FRACTAL.C
  • ScreenSaverProc() : FRACTAL.C
  • SearchFile() : CMNDLG.C , CMNDLG.H
  • ServerEnumDialogA() : SERVENUM.H , SERVENUM.C , SERVENUM.H
  • ServerEnumDialogW() : SERVENUM.H , SERVENUM.C
  • SetBitmapBkgnd() : MISCUTIL.C , MISCUTIL.H
  • SetButtonPositions() : TIMERS.C , TIMERS.H
  • SetCurrentPrivilege() : REBOOT.C
  • SetFlashRectPositions() : TIMERS.C , TIMERS.H
  • SetUnityXform() : WORLD.C
  • SetupCommandLineOptions() : OVCOMM.C
  • SetupCommPort() : OVCOMM.C
  • SetupNDDEShare() : NDDEUTIL.C , NDDEUTIL.H
  • ShiftlParam() : SUBCLASS.H
  • ShowDlgProc() : VIRTMEM.H , VIRTMEM.C
  • ShowNDDEErrMsg() : NDDEUTIL.C , NDDEUTIL.H
  • ShowUsage() : IOCOMP.C
  • ShrinkBitmap() : MENU.C
  • sieve() : CURSOR.C , CURSOR.H
  • solve() : THREADS.C , GLTHREAD.H
  • StartJournalPlayback() : RECHOOK.C , RECHOOK.H
  • StartJournalRecord() : RECHOOK.H , RECHOOK.C
  • StartMandelbrot() : FRACTAL.C
  • StatusDlgProc() : SETINFO.C , OTHRPROC.H , SETINFO.H
  • StatusProc() : OVCOMM.C
  • StatusWndProc() : UNIPUT.H , STATUS.C
  • StopAllJournalling() : RECHOOK.C , RECHOOK.H
  • StopJournalPlayback() : RECHOOK.H , RECHOOK.C
  • StopJournalRecord() : RECHOOK.H , RECHOOK.C
  • StringProc() : GUIGREP.C
  • SubclassWindow() : SUBCLASS.H , SUBCLASS.C
  • SubclassWndProc() : SUBCLASS.C , SUBCLASS.H
  • SwapShort() : DISPLAY.C
  • SwapULong() : DISPLAY.C
  • Syntax() : COLOR.H , COLOR.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- t -

  • TapeDlgProc() : STEREO.C , STEREO.H
  • TermStereoApplet() : STEREO.C
  • TextWndProc() : MDI.C
  • ThreadFunc1() : GLTHREAD.H , THREADS.C
  • ThreadFunc2() : GLTHREAD.H , THREADS.C
  • ThreadProc() : THREADS.C , THREADS.H , SEMA.C , SEMA.H , LINKTEST.C , LINKTEST.H , LOADTEST.C , LOADTEST.H
  • TimerFunc() : TIMERS.C , TIMERS.H
  • TlsInit() : TLSDLL.C , TLSDLL.H
  • TlsRetreive() : TLSDLL.C , TLSDLL.H
  • ToggleMenu() : SUBCLASS.H , SUBCLASS.C
  • TrackRect() : REGIONS.C , REGIONS.H
  • transIndextoRect() : DISPLAY.C
  • transXYtoIndex() : DISPLAY.C
  • TraverseFileCaseInsens() : GUIGREP.C
  • TraverseFileCaseSens() : GUIGREP.C
  • TunerDlgProc() : STEREO.H , STEREO.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- u -

  • UpdateBuffer() : DRIVES.C , DRIVES.H
  • Usage() : BNDBUFS.C
  • usage() : LOG.C
  • UTCBProc() : UTDLL32.C
  • UTInit() : DLL16.C
  • UTProc() : DLL16.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- v -

  • vLoadStrings() : FRACTAL.C
  • void() : DLL16.C
  • VOID() : UTDLL32.C
  • vTest() : MDI.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • _
  • a
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • j
  • k
  • l
  • m
  • n
  • o
  • p
  • q
  • r
  • s
  • t
  • u
  • v
  • w

- w -

  • WaitCloseOutstanding() : THRDUTIL.C , THRDUTIL.H
  • Walk() : WALK.H , WALK.C
  • WEP() : DLL16.C
  • WinMain() : CLIPTEXT.C , APP16.C , REGIONS.C , MAIN.C , WORLD.C , VIRTMEM.C , UNIPUT.C , TIMERS.C , THREADS.C , SUBCLASS.C , DISP32.C , LOADTEST.C , LINKTEST.C , SHAREMEM.C , SETINFO.C , SEMA.C , WINMAIN.C , CMNDLG.C , STUB32.C , POLYDRAW.C , PLATFORM.H , PLATFORM.C , PATHS.C , OWNCOMBO.C , OTHRPROC.C , MDI.C , LOCALE.C , MINREC.C , MENU.C , MDI.C , CURSOR.C , MASKBLT.C , STREBLT.C , GETDEV.C , BOB.C , HOOKTEST.C , NTGREP.C , GLTHREAD.C , GETSYS.C , WINMAIN.C , BOB.H
  • WndProc() : BROWSE.C , GLOBALS.H , NDDECHAT.C
  • Write() : READWRIT.C
  • WriteDataBase() : DATABASE.H , DATABASE.C
  • WriterProc() : OVCOMM.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • a
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • p
  • s
  • t
  • w

- a -

  • APPLETS : STEREO.C

- c -

  • CHAINLIST : SHRSTUFF.H
  • clBasePt : SHRSTUFF.H
  • CMD : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • CMDI : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • CONTROLTEXT : BOB.H
  • COPYDATASTRUCT : APP16.C

- d -

  • DISK_RESOURCES_CONNECTABLE : WINNET.C

- e -

  • ENUMLISTOBJECT : ENUMUTIL.H
  • ENUMNODE : ENUMUTIL.H
  • ENUMOBJECT : ENUMUTIL.H
  • ENUMSYNC : ENUMUTIL.H
  • EVENTHEADER : RECHOOK.C
  • ExtraBytes : SUBCLASS.H

- f -

  • FARPROC : UTDLL32.C
  • FPSERVENUMDLG : BROWSE.C

- g -

  • GLOBAL : MINREC.C , RECHOOK.C

- h -

  • HEVENT : ASYN_IO.C , DATABASE.C
  • HFILEEX : ASYN_IO.C
  • HMUTEX : DATABASE.C
  • HSEM : DATABASE.C

- i -

  • INFO : MDI.C , FRACTAL.H , MDITYPES.H , MDI.C , MDITYPES.H

- l -

  • LookupEntry : GETDEV.H , GETSYS.H , MASKBLT.H , STREBLT.H , LOCALE.H , DISPLAY.H
  • LPCMDI : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • LPCONTROLTEXT : BOB.H
  • LPCOPYDATASTRUCT : APP16.C
  • LPDISK_RESOURCES_CONNECTABLE : WINNET.C
  • LPENUMLISTOBJECT : ENUMUTIL.H
  • LPENUMNODE : ENUMUTIL.H
  • LPENUMOBJECT : ENUMUTIL.H
  • LPENUMSYNC : ENUMUTIL.H
  • LPMSDI : GLOBALS.H , DLLDISP.H
  • LPTHREADPBLOCK : GUIGREP.H
  • LPTLSOBJECT : ENUMUTIL.H
  • LPVOID : UTDLL32.C
  • LPWIN32SINFO : DLL16.C

- m -

  • MPOINT : CURSOR.H
  • MSD : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • MSDI : DLLDISP.H , GLOBALS.H
  • MYHOOKDATA : HOOKTEST.C
  • MYREC : APP16.C , DISP32.C

- p -

  • PEVENTHEADER : RECHOOK.C
  • PExtraBytes : SUBCLASS.H
  • PFNCMD : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • PFNDLL : LOADTEST.H
  • PFNMSG : GLOBALS.H , DLLDISP.H , GLOBALS.H
  • PGLOBAL : MINREC.C , RECHOOK.C
  • PHYSICAL_ADDRESS : DEBUG.C
  • PINFO : MDITYPES.H , FRACTAL.H , MDI.C , MDITYPES.H
  • PPHYSICAL_ADDRESS : DEBUG.C
  • PSUBTABLE : DISPLAY.C
  • PTABLE : DISPLAY.C
  • PTrackObject : TRACK.H
  • PTRACKRECTSTRUCT : REGIONS.H

- s -

  • SUBTABLE : DISPLAY.C

- t -

  • TABLE : DISPLAY.C
  • THREADPBLOCK : GUIGREP.H
  • TLSOBJECT : ENUMUTIL.H
  • TrackObject : TRACK.H

- w -

  • WIN32SINFO : DLL16.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- b -

  • base : VIRTMEM.C
  • bCaseInsens : GUIGREP.C
  • bDone : OVCOMM.H
  • bFileJustOpen : WORLD.C
  • bFileOpen : WORLD.C
  • bObjectExists : GUIGREP.C
  • bTrack : CURSOR.C
  • Buf : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • Buf2 : OTHRPROC.C , SHAREMEM.C , VIRTMEM.C
  • buffer : BNDBUFS.C , BNDBUFP.C , GETSYS.H
  • Buffer : IOCOMP.C
  • buffer : COMMON.H , GETDEV.H
  • BufferSize : IOCOMP.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- l -

  • langstrings : LOCALE.H
  • lConThreadId : BNDBUFC.C
  • lf : CMNDLG.C
  • LineCaps : GETDEV.H
  • localeentry : LOCALE.H
  • logfont : DISPLAY.C
  • logfontsmall : STATUS.C
  • lpBufPtr : CMNDLG.C
  • lpClipData : CLIPTEXT.C
  • LPCSTR : UTDLL32.C
  • lpData : CLIPTEXT.C
  • lpfnOldEditProc : GUIGREP.C
  • lpFR : CMNDLG.C
  • lProdThreadId : BNDBUFC.C
  • LPSTR : DLL16.C
  • lpszCRLF : GUIGREP.C
  • lpszPort : OVCOMM.H
  • lpszSerialSpec : OVCOMM.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- m -

  • MapView : OTHRPROC.C , SHAREMEM.C
  • MasterBlock : GUIGREP.C
  • MemInfo : VIRTMEM.C
  • msdiAbout : ABOUT.C
  • msdiConnectDlg : CONNECT.C
  • msdiEnumDlg : ENUMDLG.C
  • msdiMain : BROWSE.C , GLOBALS.H , NDDECHAT.C
  • MyHelpMessage : FRACTAL.H
  • myhookdata : HOOKTEST.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- n -

  • nAge : APP16.C
  • ndxTls : ENUMDLG.C , SERVENUM.C
  • nSegments : DISPLAY.C
  • NumberOfWrites : IOCOMP.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- o -

  • OldButtonProc : BOB.C
  • oldrect : THREADS.C
  • oneto8 : THREADS.C
  • OpenFileName : WORLD.C , CMNDLG.C
  • OrgX : CURSOR.C
  • OrgY : CURSOR.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- c -

  • chBuffer : DRIVES.C
  • chf : CMNDLG.C
  • chPathName : WALK.H
  • chsclr : CMNDLG.C
  • chTlsCount : TLSDLL.C
  • ClipCaps : GETDEV.H
  • cmdiAbout : ABOUT.C
  • cmdiConnectDlg : CONNECT.C
  • cmdiEnumDlg : ENUMDLG.C
  • cmdiMain : GLOBALS.H , NDDECHAT.C , BROWSE.C , GLOBALS.H
  • Color : COLOR.H
  • comHandle : OVCOMM.H
  • con_buf_pos : BNDBUFP.C , COMMON.H
  • ConnectablesList : WINNET.C
  • crColor : CMNDLG.C
  • cRead : DATABASE.C
  • cReadQueue : DATABASE.C
  • cReadQueueEx : DATABASE.C
  • currRgn : REGIONS.H
  • CurveCaps : GETDEV.H
  • cWrite : DATABASE.C
  • cWriteQueue : DATABASE.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- d -

  • DataBase : DATABASE.C
  • DevCaps : GETDEV.H
  • Device : GETDEV.H
  • dwDiskListI : WINNET.C
  • dwFileSize : CMNDLG.C
  • DWORD : DLL16.C
  • dwResourcesEnumedSoFar : WINNET.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- e -

  • ellipseRect : REGIONS.H
  • endCount : DISPLAY.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- f -

  • fBufferdIo : IOCOMP.C
  • FileBuf : CMNDLG.C
  • FileName : IOCOMP.C
  • FindReplaceMsg : CMNDLG.C
  • flags : CURSOR.C
  • FontHeight : DISPLAY.C
  • FontWidth : DISPLAY.C
  • frText : CMNDLG.C
  • fSequentialNew : IOCOMP.C
  • fTestMode : SUBCLASS.H
  • fWin32s : STUB32.C , DLL16.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- g -

  • g_csOutstanding : THRDUTIL.C , THRDUTIL.H
  • g_fState : NDDECHAT.C , GLOBALS.H
  • g_hInstNetDde : GLOBALS.H , WINMAIN.C
  • g_hLibrary : BROWSE.C
  • g_hMod : ENUMUTIL.C , SERVENUM.C
  • g_hwnd : GLOBALS.H , NDDECHAT.C , BROWSE.C
  • g_idInst : GLOBALS.H , NDDECHAT.C
  • g_lpfnServEnumDlg : BROWSE.C
  • g_lphOutstanding : THRDUTIL.C
  • g_nOutstanding : THRDUTIL.C
  • g_szServer : GLOBALS.H , NDDECHAT.C
  • g_szTopic : GLOBALS.H , NDDECHAT.C
  • g_timeouts : OVCOMM.H
  • gaFlashRects : TIMERS.H
  • gahwndButtons : TIMERS.H
  • gbStretch : FRACTAL.H
  • gFloat : FRACTAL.H
  • ghDLL : STUB32.C , UTDLL32.C
  • ghInst : BOB.C , DLL16.C , TIMERS.H
  • ghInstance : APP16.C , WORLD.C
  • ghLib : DLL16.C , MAIN.H
  • ghMod : THE_DLL.H
  • ghModule : MDI.C
  • ghMutex : DATABASE.C
  • ghPalette : GLTHREAD.C , THREADS.C
  • ghpalOld : GLTHREAD.C , THREADS.C
  • ghReadEvent1 : DATABASE.C
  • ghReadEvent2 : DATABASE.C
  • ghSemaphore : DATABASE.C
  • ghWnd : BOB.C , GLTHREAD.C , THREADS.C , APP16.C , DLL16.C , UTDLL32.C
  • ghwndClient : MDI.C
  • ghwndMain : MDI.C , LINKTEST.H , LOADTEST.H
  • ghWriteEvent1 : DATABASE.C
  • ghWriteEvent2 : DATABASE.C
  • giDmOrient : FRACTAL.H
  • gInfo : FRACTAL.H
  • giNPrinters : FRACTAL.H
  • giPen : FRACTAL.H
  • giStretchMode : FRACTAL.H
  • gIteration : FRACTAL.H
  • gpfnDLLDialogBox : LOADTEST.H
  • gpfnDLLFunction1 : LOADTEST.H
  • gpfnDLLFunction2 : LOADTEST.H
  • gpfnDLLFunction3 : LOADTEST.H
  • gpfnDLLFunction4 : LOADTEST.H
  • gpUTCBack : DLL16.C
  • gShowhex : UNIPUT.H , UNIPUT.C
  • gShowNames : UNIPUT.C , UNIPUT.H
  • gStep : FRACTAL.H
  • gszFile : MDI.C
  • gszMapName : MDI.C
  • gtext : FRACTAL.H
  • gUserCount : DATABASE.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- h -

  • hAccTable : CLIPTEXT.C
  • hBigMenu : MENU.C
  • hbmCheckOff : MENU.C
  • hbmCheckOn : MENU.C
  • hbmMask : MASKBLT.C
  • hbmMemXOR : DISPLAY.C
  • hbmSrc : STREBLT.C , MASKBLT.C
  • hChildMenu : MDI.C
  • hChildMenuWindow : MDI.C
  • hClipData : CLIPTEXT.C
  • hConThrd : BNDBUFC.C
  • hconv : NDDECHAT.C
  • hData : CLIPTEXT.C
  • hdcDest : MASKBLT.C , STREBLT.C
  • hdcMask : MASKBLT.C
  • hdcMemXOR : DISPLAY.C
  • hdcSrc : MASKBLT.C , STREBLT.C
  • hDlgFR : CMNDLG.C
  • hEMF : WORLD.C
  • hEmptySem : BNDBUFP.C , BNDBUFS.C , COMMON.H
  • hFile : UNIPUT.C
  • hFontCopyright : ABOUT.C
  • hFullSem : COMMON.H , BNDBUFP.C , BNDBUFS.C
  • hHourGlass : CURSOR.C
  • hInst : CLIPTEXT.C , CMNDLG.C , CURSOR.C , NTGREP.C , HOOKTEST.C , MASKBLT.C , MENU.C , GLOBALS.H , INIT.C , OTHRPROC.C , OWNCOMBO.C , PLATFORM.C , REGIONS.H , SEMA.C , GLOBALS.H , INIT.C , SETINFO.C , SHAREMEM.C , STREBLT.C , SUBCLASS.H , THREADS.C , UNIPUT.C , UNIPUT.H , VIRTMEM.C
  • hKernel32 : UTDLL32.C
  • hMainThrd : BNDBUFC.C
  • hMapObject : OTHRPROC.C , SHAREMEM.C
  • hMenu : REGIONS.H , MDI.C
  • hMenuWindow : MDI.C
  • hModule : STEREO.C
  • hMutex : BNDBUFP.C , BNDBUFS.C , COMMON.H
  • hOurselves : GUIGREP.C
  • hpnBlack : FRACTAL.H
  • hpnGreen : FRACTAL.H
  • hpnRed : FRACTAL.H
  • hProdThrd : BNDBUFC.C
  • hRC : GLTHREAD.C
  • hSaveCursor : CURSOR.C
  • hSemaphore : SEMA.C
  • hSetupEvent : OVCOMM.H
  • hText : CLIPTEXT.C
  • hThread : OTHRPROC.C
  • hThreads : THREADS.C
  • hwnd : CLIPTEXT.C
  • hWnd : SETINFO.C , OTHRPROC.C , THREADS.C , SEMA.C , VIRTMEM.C , SHAREMEM.C
  • hwndClient : UNIPUT.C , UNIPUT.H
  • hWndDlg : SHAREMEM.C
  • hwndDlg : STREBLT.C , MASKBLT.C
  • hWndDlg : OTHRPROC.C , SETINFO.C
  • hWndFileDlg : SETINFO.C
  • hWndGlobal : GUIGREP.C
  • hwndMain : HOOKTEST.C , STREBLT.C , UNIPUT.C , MASKBLT.C , UNIPUT.H , SUBCLASS.H
  • hwndRecv : NDDECHAT.C
  • hwndSend : GLOBALS.H , NDDECHAT.C
  • hwndStatic0 : STATUS.C , UNIPUT.H
  • hwndStatic1 : STATUS.C , UNIPUT.H
  • hwndStatic2 : STATUS.C
  • hwndStatus : UNIPUT.H , UNIPUT.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- i -

  • iFinishedFiles : GUIGREP.C
  • iGlobalSStLen : GUIGREP.C
  • iHitCount : GUIGREP.C
  • ilpszCRLF : GUIGREP.C
  • instructions0 : POLYDRAW.H
  • instructions1 : POLYDRAW.H
  • instructions2 : POLYDRAW.H
  • instructions3 : POLYDRAW.H
  • InWrite : DATABASE.C
  • iPatternBrush : MASKBLT.C , STREBLT.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- p -

  • page : VIRTMEM.C
  • Patterns : MASKBLT.H , STREBLT.H
  • pbitsAND : DISPLAY.C
  • pbitsXOR : DISPLAY.C
  • pd : CMNDLG.C
  • pfnUTProc : UTDLL32.C
  • PolygonalCaps : GETDEV.H
  • polyPolygonCounts : REGIONS.H
  • polyPolygonPoints : REGIONS.H
  • PrevX : CURSOR.C
  • PrevY : CURSOR.C
  • pro_buf_pos : BNDBUFP.C , COMMON.H
  • Proc : DLL16.C
  • pszLast : NDDECHAT.C
  • ptCursor : CURSOR.C
  • ptoDest : MASKBLT.C , STREBLT.C
  • ptoMask : MASKBLT.C
  • ptoSrc : MASKBLT.C , STREBLT.C
  • pUTRegister : UTDLL32.C
  • pUTUnRegister : UTDLL32.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- r -

  • radius : THREADS.C
  • RangeName : DISPLAY.H
  • RasterCaps : GETDEV.H
  • Rect : CURSOR.C
  • rectRect : REGIONS.H
  • repeat : CURSOR.C
  • ResultBlock : GUIGREP.C
  • retCode : BNDBUFC.C , BNDBUFS.C
  • rgcmd : NDDECHAT.C , BROWSE.C
  • rgcmdAbout : ABOUT.C
  • rgcmdConnectDlg : CONNECT.C
  • rgcmdEnumDlg : ENUMDLG.C
  • rgmsd : BROWSE.C , NDDECHAT.C
  • rgmsdAbout : ABOUT.C
  • rgmsdConnectDlg : CONNECT.C
  • rgmsdEnumDlg : ENUMDLG.C
  • rgnArray : REGIONS.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- s -

  • space : GETDEV.H
  • StandardROPs : MASKBLT.H , STREBLT.H
  • startCount : DISPLAY.C
  • StepTime : SETINFO.C
  • StereoApplets : STEREO.C
  • str : CURSOR.C
  • strebltMode : STREBLT.C
  • strebltModes : STREBLT.H
  • SysColors : GETSYS.H
  • SystemMetrics : GETSYS.H
  • szAppName : GLOBALS.H , INIT.C , GLTHREAD.C , GLOBALS.H , INIT.C , FRACTAL.H
  • szCtlPanel : STEREO.C
  • szDirName : CMNDLG.C
  • szFile : CMNDLG.C , WORLD.C
  • szFileTitle : CMNDLG.C , WORLD.C
  • szFilter : CMNDLG.C , WORLD.C
  • szFindString : CMNDLG.C
  • szFirstName : APP16.C
  • szGlobalSearchString : GUIGREP.C
  • szHelpFile : FRACTAL.H
  • szHelpPathName : UNIPUT.C
  • szIniFile : FRACTAL.H
  • szInitialClientAreaText : CLIPTEXT.C
  • szItem : NDDECHAT.C
  • szIteration : FRACTAL.H
  • szLastName : APP16.C
  • szName : FRACTAL.H
  • szNoHelpMemory : FRACTAL.H
  • szReplaceString : CMNDLG.C
  • szSaveFile : FRACTAL.H
  • szScreenSaver : FRACTAL.H
  • szShareName : NDDECHAT.C
  • szTitle : INIT.C , GLOBALS.H , INIT.C
  • szXFrom : FRACTAL.H
  • szXTo : FRACTAL.H
  • szYFrom : FRACTAL.H
  • szYTo : FRACTAL.H
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- t -

  • TextCaps : GETDEV.H
  • threeto8 : THREADS.C
  • TlsCount : TLSDLL.C
  • TlsIndex : TLSDLL.C
  • twoto8 : THREADS.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- w -

  • wMode : CMNDLG.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- x -

  • X : CURSOR.C
  • xForm : WORLD.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Data Fields

  • All
  • Functions
  • Variables
  • Typedefs
  • Enumerations
  • Enumerator
  • Defines
  • b
  • c
  • d
  • e
  • f
  • g
  • h
  • i
  • l
  • m
  • n
  • o
  • p
  • r
  • s
  • t
  • w
  • x
  • y

- y -

  • Y : CURSOR.C
Generated on Wed Nov 13 2024 17:29:14 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: Main Page

WinNT-Templates Documentation

End-User License Agreement

Introduction

This End-User License Agreement ("EULA") is a legal agreement between you (either an individual or a single entity) and SIEMA ("Licensor") for the use of SIEMA-REFERENCE ("Software"). This EULA governs your use of the Software provided by the Licensor. By installing or using the Software, you agree to be bound by the terms of this EULA.

License Grant

Licensor grants you a revocable, non-exclusive, non-transferable, limited license to download, install, and use the Software solely for your personal or commercial purposes strictly in accordance with the terms of this Agreement.

Restrictions on Use

You agree not to, and you will not permit others to:

  • Modify, or create derivative works of the Software;
  • Distribute, transfer, sublicense, lease, lend, or rent the Software to any third party;
  • Reverse engineer, decompile or disassemble the Software, except to the extent expressly permitted by applicable law;
  • Remove, alter, or obscure any proprietary notices on the Software;
  • Use the Software in any manner that could damage, disable, overburden, or impair the Software;
  • Use the Software to create or distribute any malicious software or for any unlawful purpose.

Related Agreements

By agreeing to this EULA, you also agree to comply with the terms of Terms and Conditions, Privacy Policy, and any other agreements incorporated herein by reference.

Jurisdiction

This EULA and any disputes arising out of or in connection with it will be governed by and construed in accordance with the laws of Switzerland, without regard to its conflict of laws principles. Any legal actions or proceedings arising out of this EULA shall be brought exclusively in the courts of Switzerland.Intellectual Property & Copyright Infringement

The Software and all rights, title, and interest in and to the Software, including all intellectual property rights therein, are and will remain the exclusive property of the Licensor. You agree to notify the Licensor promptly if you become aware of any infringement of the Licensor’s intellectual property rights in the Software.Termination of Licensing

Licensor may terminate this EULA at any time if you fail to comply with any term(s) of this Agreement. Upon termination, you must cease all use of the Software and destroy all copies, full or partial, of the Software.

Warranty Disclaimer

THE SOFTWARE IS PROVIDED "AS IS". LICENSOR MAKES NO WARRANTIES, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT. YOU BEAR THE ENTIRE RISK AS TO SELECTING THE SOFTWARE FOR YOUR PURPOSES AND AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE.

Limitations of Liability

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL LICENSOR BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS OR REVENUES, WHETHER INCURRED DIRECTLY OR INDIRECTLY, OR ANY LOSS OF DATA, USE, GOODWILL, OR OTHER INTANGIBLE LOSSES, RESULTING FROM:

  1. YOUR USE OR INABILITY TO USE THE SOFTWARE;
  2. ANY UNAUTHORIZED ACCESS TO OR USE OF OUR SERVERS AND/OR ANY PERSONAL INFORMATION STORED THEREIN;
  3. ANY INTERRUPTION OR CESSATION OF TRANSMISSION TO OR FROM THE SOFTWARE;
  4. ANY ERRORS OR OMISSIONS IN ANY CONTENT OR FOR ANY LOSS OR DAMAGE INCURRED AS A RESULT OF YOUR USE OF ANY CONTENT POSTED, EMAILED, TRANSMITTED, OR OTHERWISE MADE AVAILABLE THROUGH THE SOFTWARE;
  5. THE DEFAMATORY, OFFENSIVE, OR ILLEGAL CONDUCT OF ANY THIRD PARTY.

Business Contact Information

If you have any questions about this EULA, please contact us at:

Siema
siema.switzerland@gmail.com

By installing or using the Software, you acknowledge that you have read this Agreement, understand it, and agree to be bound by its terms and conditions.

Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMDLG.H Source File

  • SERVENUM
  • DLL

ENUMDLG.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumdlg.h
00009 //
00010 //  PURPOSE:  contains enumdlg declarations
00011 //
00012
00013 #ifndef _ENUMDLG_H
00014 #define _ENUMDLG_H
00015
00016 //-------------------------------------------------------------------------
00017 //  enumdlg dialog defines.
00018
00019 #define IDE_SERVER       400
00020 #define IDL_BROWSE       401
00021 #define IDB_HELP         402
00022 #define IDT_SELECT       403
00023 #define IDC_STATIC       -1
00024 #define WM_INIT_ENUM     WM_USER+100
00025 #define WM_ENUM_EXPAND   WM_USER+101
00026
00027 #define SERVER_BMP       500
00028 #define DOMAIN_BMP       501
00029 #define DOMAINEX_BMP     502
00030 #define PROVIDER_BMP     503
00031 #define PROVIDEREX_BMP   504
00032
00033 #define WORKING          -1
00034
00035
00036 //-----------------------------------------------------------------------
00037 // enumdlg prototypes
00038
00039 LRESULT CALLBACK EnumDlg(HWND, UINT, WPARAM, LPARAM);
00040 LRESULT APIENTRY ListSubProc(HWND, UINT, WPARAM, LPARAM);
00041
00042 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/READWRIT.C Source File

  • READWRIT

READWRIT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************\
00013 **   MODULE:  Test Engine                                                  **
00014 **                                                                         **
00015 **                                                                         **
00016 **   PURPOSE: This is a simple driver to test my database dll's            **
00017 **            ability to handle multiple read's and writes without         **
00018 **            corrupting the database.                                     **
00019 **                                                                         **
00020 **                                                                         **
00021 **                                                                         **
00022 **                                                                         **
00023 **   COMMENTS:                                                             **
00024 **                                                                         **
00025 **                                                                         **
00026 **                                                                         **
00027 \***************************************************************************/
00028
00029
00030
00031 #define STRICT
00032 #define NOMINMAX
00033 #include <windows.h>
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <string.h>
00037
00038 #include "DataBase.h"
00039
00040 VOID Read ( PSZ psz ) ;
00041 VOID Write ( PSZ psz ) ;
00042
00043 #define MAX 100
00044
00045
00046 /*
00047  * This is a simple driver to test my database dll's ability to handle
00048  * multiple read's and writes without corrupting the database.
00049  *
00050  */
00051
00052
00053
00054 void main( void )
00055 {
00056     char psz[20], psztmp[10] ;
00057     int  i ;
00058     DWORD idThread ;
00059     DWORD dwVersion = GetVersion();
00060
00061   // check if Win32s, if so, display notice and terminate
00062    if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00063         {
00064           MessageBox( NULL,
00065              "This application cannot run on Windows 3.1.\n"
00066              "This application will now terminate.",
00067              "ReadWrit",
00068              MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00069           return;
00070         }
00071
00072     printf ( "\nStart of program\n" ) ;
00073
00074 /*
00075  * Create the reader/writers to stress the database
00076  *
00077  */
00078
00079     for ( i=1; i<=MAX; i++ )
00080     {
00081         strcat (strcpy ( psz,"In Thread #" ),itoa( i,psztmp, 10)) ;
00082         CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE)Write,psz, 0,
00083                  &idThread ) ;
00084
00085         CreateThread ( NULL, 0, (LPTHREAD_START_ROUTINE)Read, psz, 0,
00086                  &idThread ) ;
00087
00088         Sleep( 0 ) ;                        // Relinquish timeslice
00089         printf ( "psz = %s\n", psz ) ;      // Print result of the test
00090     }
00091
00092     printf ( "\nEnd of program\n" ) ;
00093
00094     exit ( EXIT_SUCCESS ) ;
00095 }
00096
00097
00098 VOID Read ( PSZ psz )
00099 {
00100   ReadDataBase ( psz, NULL ) ;
00101 }
00102
00103 VOID Write ( PSZ psz )
00104 {
00105
00106   WriteDataBase ( psz, NULL ) ;
00107 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OVCOMM/OVCOMM.H Source File

  • OVCOMM

OVCOMM.H

Go to the documentation of this file.
00001 // OvComm.h
00002
00003 // DEFINES
00004 #define STATUS_CHECK_TIMEOUT    500
00005 #define READ_TIMEOUT            1000
00006 #define MAX_READ_BUFFER         80
00007 #define MAX_WRITE_BUFFER        1024
00008 #define PURGE_FLAGS             PURGE_RXABORT | PURGE_TXABORT | PURGE_RXCLEAR | PURGE_TXCLEAR
00009 //#define EVENT_FLAGS             EV_BREAK|EV_CTS|EV_DSR|EV_ERR|EV_RING|EV_RLSD|EV_RXCHAR|EV_TXEMPTY|EV_RXFLAG
00010 #define EVENT_FLAGS         EV_RING | EV_ERR
00011
00012 #define EVT_CHAR                (char) 0x0A
00013
00014
00015 // GLOBALS
00016 HANDLE  comHandle, hSetupEvent;
00017 BOOL  bDone;
00018 char    lpszPort[100];
00019 char    lpszSerialSpec[100];
00020 COMMTIMEOUTS g_timeouts;
00021
00022 // PROTOTYPES
00023 void BreakDownCommPort();
00024
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDI.H Source File

  • NTSD

MDI.H

Go to the documentation of this file.
00001 /******************************Module*Header*******************************\
00002 * Module Name: mdi.h
00003 *
00004 * Header file
00005 *
00006 * Created: 24-Oct-1991 18:15:12
00007 * Author: Petrus Wong
00008 *
00009 * Copyright (c) 1990-1996 Microsoft Corporation
00010 *
00011 *
00012 *
00013 * Dependencies:
00014 *
00015 *   windows.h
00016 *   string.h
00017 *
00018 \**************************************************************************/
00019
00020 #include <windows.h>
00021 #include <string.h>
00022
00023 /*
00024  * Menu ID's
00025  */
00026 #define MM_ABOUT        8000
00027 #define MM_MDI    8001
00028 #define MM_RESERVE1 8002
00029 #define MM_RESERVE2 8003
00030
00031 #define MM_OPT_1  7001
00032 #define MM_OPT_2  7002
00033 #define MM_OPT_3  7003
00034 #define MM_OPT_4  7004
00035 #define MM_OPT_5  7005
00036 #define MM_OPT_6  7006
00037 #define MM_OPT_7  7007
00038 #define MM_OPT_8  7008
00039
00040 #define IDM_CASCADE 30
00041 #define IDM_TILE  31
00042 #define IDM_ARRANGE 32
00043 #define IDM_CLOSEALL  33
00044
00045 #define SIZEOFCAPTIONTEXT 20
00046
00047 #define ACCEL_ID        100
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LINKTEST.C Source File

  • SIMPLDLL

LINKTEST.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     LINKTEST.C
00015 *
00016 *  PURPOSE:     A simple demonstration of an executable file linking
00017 *               with and calling into a DLL we created. This necessitates
00018 *               the creation of a .LIB file for the DLL, which is used
00019 *               when linking the .EXE. Doing this eliminates the need
00020 *               for explicitly loading the DLL (via LoadLibrary()) at
00021 *               runtime.
00022 *
00023 *  FUNTIONS:    WinMain     - initialization, create window, msg loop
00024 *               MainWndProc - processes main window msgs
00025 *               ThreadProc  - makes a single call into "THE_DLL.DLL"
00026 *               AboutDlgProc- processes about dialog messages
00027 *
00028 \******************************************************************************/
00029
00030 #include <windows.h>
00031 #include "linktest.h"
00032 #include "the_dll.h"
00033
00034
00035
00036 /******************************************************************************\
00037 *
00038 *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
00039 *
00040 *  GLOBAL VARS: ghwndMain - handle of main app window
00041 *
00042 *  LOCAL VARS:  msg - msg to get/dispatch
00043 *
00044 \******************************************************************************/
00045
00046 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00047                     LPSTR lpCmdLine, int nCmdShow)
00048 { MSG msg;
00049
00050   if (!hPrevInstance)
00051   {
00052     WNDCLASS wc;
00053
00054     wc.style         = 0;
00055     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00056     wc.cbClsExtra    = 0;
00057     wc.cbWndExtra    = 0;
00058     wc.hInstance     = hInstance;
00059     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
00060     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
00061     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00062     wc.lpszMenuName  = (LPCTSTR) "Menu";
00063     wc.lpszClassName = (LPCTSTR) "LINKTEST";
00064
00065     if (!RegisterClass (&wc))
00066     {
00067       MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
00068                   (LPCTSTR) "Err! - LINKTEST", MB_OK | MB_ICONEXCLAMATION);
00069       return(FALSE);
00070     }
00071   }
00072
00073   if (!(ghwndMain = CreateWindow ("LINKTEST",
00074                                   "LINKTEST Sample Application",
00075                                   WS_OVERLAPPEDWINDOW,
00076                                   CW_USEDEFAULT, CW_USEDEFAULT,
00077                                   CW_USEDEFAULT, CW_USEDEFAULT,
00078                                   NULL, NULL, hInstance, NULL)))
00079     return (0);
00080
00081   ShowWindow (ghwndMain, nCmdShow);
00082
00083   while (GetMessage (&msg, NULL, 0, 0))
00084   {
00085     TranslateMessage (&msg);
00086     DispatchMessage  (&msg);
00087   }
00088
00089   return (msg.wParam);
00090 }
00091
00092
00093
00094 /******************************************************************************\
00095 *
00096 *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
00097 *
00098 *  COMMENTS:    Menuitems IDM_DLLFUNCTION1 through IDM_DLLDIALOGBOX are
00099 *               all processed by calling their respective functions in
00100 *               "THE_DLL.DLL". The "CreateThread" menuitem causes a thread
00101 *               to be created- the thread then calls into "THE_DLL.DLL".
00102 *
00103 \******************************************************************************/
00104
00105 LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam,
00106                               LPARAM lParam)
00107 {
00108   switch (message)
00109   {
00110     case WM_COMMAND:
00111
00112       switch (LOWORD(wParam))
00113       {
00114         case IDM_CREATETHREAD:
00115         {
00116           DWORD  threadId;
00117
00118           CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadProc,
00119                         NULL, 0, &threadId);
00120           break;
00121         }
00122
00123         case IDM_DLLFUNCTION1:
00124
00125           DLLFunction1 ();
00126           break;
00127
00128         case IDM_DLLFUNCTION2:
00129
00130           DLLFunction2 ((int) 0);
00131           break;
00132
00133         case IDM_DLLFUNCTION3:
00134
00135           DLLFunction3 ((HANDLE) NULL);
00136           break;
00137
00138         case IDM_DLLFUNCTION4:
00139
00140           DLLFunction4 ((HWND) NULL);
00141           break;
00142
00143         case IDM_DLLDIALOGBOX:
00144
00145           DLLDialogBox (hwnd);
00146           break;
00147
00148         case IDM_ABOUT:
00149
00150           DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd,
00151                      (DLGPROC) AboutDlgProc);
00152           break;
00153
00154         default:
00155
00156           break;
00157       }
00158       break;
00159
00160     case WM_DESTROY:
00161
00162       PostQuitMessage(0);
00163       break;
00164
00165     default:
00166
00167       return (DefWindowProc(hwnd, message, wParam, lParam));
00168   }
00169   return (0);
00170 }
00171
00172
00173
00174 /******************************************************************************\
00175 *
00176 *  FUNCTION:    Thread
00177 *
00178 *  GLOBAL VARS: ghwndMain - handle of main app window
00179 *
00180 \******************************************************************************/
00181
00182 void ThreadProc ()
00183 {
00184   MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
00185               (LPCTSTR) "ThreadProc()", MB_OK);
00186   DLLFunction1 ();
00187 }
00188
00189
00190
00191 /******************************************************************************\
00192 *
00193 *  FUNCTION:    AboutDlgProc (standard dialog procedure INPUTS/RETURNS)
00194 *
00195 *  COMMENTS:    Displays "about" message
00196 *
00197 \******************************************************************************/
00198
00199 BOOL CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam,
00200                                LPARAM lParam)
00201 { switch (message)
00202   {
00203     case WM_COMMAND:
00204
00205       if (LOWORD(wParam) == IDOK)
00206       {
00207         EndDialog(hwnd, TRUE);
00208         return (TRUE);
00209       }
00210       return (TRUE);
00211   }
00212   return (FALSE);
00213 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: HOOKS/HOOKTEST.H Source File

  • HOOKS

HOOKTEST.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 // menu commands
00013
00014 #define IDM_CALLWNDPROC     0
00015 #define IDM_CBT             1
00016 #define IDM_DEBUG           2
00017 #define IDM_GETMESSAGE      3
00018 #define IDM_KEYBOARD        4
00019 #define IDM_MOUSE           5
00020 #define IDM_MSGFILTER       6
00021 #define IDM_EXIT            100
00022
00023 // function prototypes
00024 long APIENTRY MainWndProc(HWND, UINT, UINT, LONG);
00025 LRESULT CALLBACK CallWndProc(int, WPARAM, LPARAM);
00026 LRESULT CALLBACK GetMsgProc(int, WPARAM, LPARAM);
00027 LRESULT CALLBACK DebugProc(int, WPARAM, LPARAM);
00028 LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM);
00029 LRESULT CALLBACK MouseProc(int, WPARAM, LPARAM);
00030 LRESULT CALLBACK KeyboardProc(int, WPARAM, LPARAM);
00031 LRESULT CALLBACK MessageProc(int, WPARAM, LPARAM);
00032
00033
00034 //functions
00035 BOOL InitApplication(HANDLE);
00036 BOOL InitInstance(HANDLE, int);
00037
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUF.IDL Source File

  • BNDBUF

BNDBUF.IDL

Go to the documentation of this file.
00001 [ uuid (12345678-1234-1234-1234-123456789ABC),
00002   version(1.0),
00003   pointer_default(unique)]
00004 interface bndbufh
00005 {
00006 void insert_buffer([in, string] unsigned char * item);
00007 void remove_buffer([in, out, string] unsigned char * item);
00008 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MENU/MENU.H Source File

  • MENU

MENU.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 // Porting macro
00013 #ifdef WIN32
00014 #define LONG2POINT(l, pt)  ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
00015 #else
00016 #define LONG2POINT(l, pt)  ((pt).x = (INT)LOWORD(l), (pt).y = (INT)HIWORD(l))
00017 #endif
00018
00019 /* Defines for top-level menu positions */
00020 #define IDFILE_POS     0
00021 #define IDCOLORS_POS   1
00022 #define IDSTATES_POS   2
00023 #define IDHELP_POS     3
00024
00025 #define MEASUREITEMWIDTH  40
00026 #define MEASUREITEMHEIGHT 40
00027
00028 /* Dialog ID for the About.. dialog */
00029 #define ID_ABOUT 100
00030
00031 /* Defines for menu items */
00032 #define IDM_EXIT   202
00033 #define IDM_ABOUT  203
00034
00035 /* Colors menu IDs */
00036 #define IDM_COLOROWNERDR 500
00037 #define IDM_BLACK        501
00038 #define IDM_BLUE         502
00039 #define IDM_RED          503
00040 #define IDM_GREEN        504
00041
00042 /* Floating popup menu IDs */
00043 #define IDM_FONT         600
00044 #define IDM_SIZE         601
00045 #define IDM_STYLE        602
00046
00047 /* States menu IDs */
00048 #define IDM_STATE1       610
00049 #define IDM_STATE2       611
00050 #define IDM_STATE3       612
00051 #define IDM_STATE4       613
00052
00053 /* BitBlt Raster operation */
00054 #define ROP_PSDPxax     0x00B8074AL
00055
00056 BOOL NEAR PASCAL MenuInit(HANDLE);
00057 LONG APIENTRY MenuWndProc(HWND, UINT, UINT, LONG);
00058 BOOL APIENTRY About(HWND, UINT, UINT, LONG);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OTHRPROC/OTHRPROC.C Source File

  • OTHRPROC

OTHRPROC.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************************\
00013 *  PROGRAM: othrproc.c
00014 *
00015 *  PURPOSE:
00016 *
00017 *    To assist in showing how to processes can share named shared memory.
00018 *
00019 *  GLOBAL VARIABLES:
00020 *
00021 *    HANDLE hInst:  - Instance handle.
00022 *
00023 *    HWND   hWnd:   - Client window handle.
00024 *
00025 *    HWND   hWndDlg:- Window handle to upper dialog box.
00026 *
00027 *    HANDLE hMapObject:
00028 *                   - Handle to the file mapping object.
00029 *
00030 *    LONG *MapView: - Base address of the share memory.
00031 *
00032 *    CHAR Buf[80], Buf2[80]:
00033 *                   - Error buffers.
00034 *
00035 *
00036 *  FUNCTIONS:
00037 *
00038 *    WinMain()      - Initializes the window, and process the message loop.
00039 *    MainWndProc()  - To handle the messages to the main window.
00040 *    ReadProc()     - A thread which loops; reading the shared memory
00041 *                     and drawing a bitmap in a location indicated by
00042 *                     the values in the share memory.
00043 *
00044 *  COMMENTS:
00045 *
00046 *    Overview:
00047 *      This sample is meant to be run with the Sharemem sample.  This
00048 *      code basically reads the shared memory, and based on the values
00049 *      found there (an X and Y coordinate representing the mouse
00050 *      position in the window of the Sharemem sample), this code draws
00051 *      a bitmap in the same relative position.
00052 *
00053 *    To Use:
00054 *      Start the Sharemem sample first, and then this one.  Set the
00055 *      focus to this application, and then move the mouse in the window
00056 *      of the Sharemem application.  A bitmap will be drawn to represent
00057 *      the relative mouse position in the other application, and the
00058 *      mouse's X and Y coordinates will appear in the edit fields in
00059 *      the dialog box imposed on the top of the client space.
00060 *
00061 \*************************************************************************/
00062
00063 #include <windows.h>
00064 #include <stdlib.h>
00065 #include <stdio.h>
00066 #include "othrproc.h"
00067
00068 #define WERR(who,where)    {sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
00069                             sprintf(Buf2,"From within %s", where);\
00070                             MessageBox(hwnd, Buf, Buf2, MB_OK);}
00071
00072 CHAR Buf[80];
00073 CHAR Buf2[80];
00074
00075 HANDLE hInst;
00076 HANDLE hMapObject;
00077 HWND   hWnd, hWndDlg;
00078 HANDLE hThread;
00079 LONG   *MapView;
00080
00081
00082
00083 /*************************************************************************\
00084 *
00085 *  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00086 *
00087 *  PURPOSE:  To initialize the window, and process the message loop.
00088 *
00089 *  COMMENTS: A fairly standard WinMain except that it creates a dialog
00090 *            box which is imposed on the upper part of the window.  This
00091 *            dialog box is used to show the mouse coordinates.
00092 *
00093 \*************************************************************************/
00094
00095 int PASCAL WinMain ( HINSTANCE hInstance,
00096                      HINSTANCE hPrevInstance,
00097                      LPSTR  lpCmdLine,
00098                      int    nCmdShow)
00099
00100
00101 {
00102
00103     MSG  msg;
00104     WNDCLASS wc;
00105     RECT rect;
00106     DWORD dwVersion = GetVersion();
00107
00108     UNREFERENCED_PARAMETER( lpCmdLine );
00109     UNREFERENCED_PARAMETER( hPrevInstance );
00110
00111     // check if running on Windows NT, if not, display notice and terminate
00112     if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00113     {
00114         MessageBoxA(NULL,
00115                     "This sample application cannot run on Win32s.\n"
00116                     "This application will now terminate.",
00117                     "OthrProc",
00118                     MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00119         return( 1 );
00120     }
00121
00122     hInst = hInstance;
00123
00124     wc.style = 0;                          // Replaces CS_SIZEREDRAW.
00125     wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
00126     wc.cbClsExtra = 0;                     // No room reserved for extra data.
00127     wc.cbWndExtra = 0;
00128     wc.hInstance = hInstance;
00129     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00130     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
00131     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00132     wc.lpszMenuName = "";
00133     wc.lpszClassName = "OthrProcWClass";
00134
00135     RegisterClass(&wc);
00136
00137     hWnd = CreateWindow ("OthrProcWClass",
00138                          "Other Procedure",
00139                          WS_OVERLAPPEDWINDOW,
00140                          CW_USEDEFAULT,
00141                          CW_USEDEFAULT,
00142                          CW_USEDEFAULT,
00143                          CW_USEDEFAULT,
00144                          NULL,
00145                          NULL,
00146                          hInstance,
00147                          NULL);
00148
00149     hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, NULL);
00150
00151     GetClientRect (hWnd, &rect);
00152     SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
00153     ShowWindow  (hWndDlg,  SW_SHOW);
00154     ShowWindow  (hWnd, nCmdShow);
00155
00156     while (GetMessage (&msg, NULL, 0, 0))
00157     if (!IsDialogMessage (hWndDlg, &msg))
00158     {
00159         DispatchMessage (&msg);    // Dispatch message to window.
00160     }
00161
00162     return (msg.wParam);           // Returns value from PostQuitMessage.
00163 }
00164
00165 /*************************************************************************\
00166 *
00167 *  FUNCTION:  MainWndProc (HWND, UINT, WPARAM, LPARAM)
00168 *
00169 *  PURPOSE:   To process messages.  To open and gain access to the shared
00170 *             memory.
00171 *
00172 *  VARIABLES USED:
00173 *
00174 *    - ThreadID:
00175 *             DWORD, used in the CreateThread call.
00176 *
00177 *  MESSAGES:
00178 *
00179 *    WM_DESTROY      - Cleans up handles and destroys the window.
00180 *    WM_SIZE         - Sizes the dialog box to the client window.
00181 *    WM_CREATE       - First it opens the shared memory using
00182 *                      OpenFileMapping().  It then gets an address to
00183 *                      the shared memory by using MapViewOfFile().
00184 *                      If both calls were successful, this code then
00185 *                      creates a thread which continually reads the
00186 *                      shared memory and draws the bitmap.
00187 *
00188 *  CALLED BY:
00189 *
00190 *    WinMain();
00191 *
00192 *  CALLS TO:
00193 *
00194 *    ReadProc();
00195 *
00196 \*************************************************************************/
00197
00198 LRESULT CALLBACK MainWndProc (HWND hwnd,
00199                               UINT message,
00200                               WPARAM wParam,
00201                               LPARAM lParam)
00202 {
00203     DWORD ThreadID;
00204
00205     switch (message)
00206     {
00207         case WM_CREATE:
00208             hMapObject = OpenFileMapping (FILE_MAP_READ,
00209                                           FALSE,
00210                                           "shared_memory");
00211             if (!hMapObject)
00212             {
00213                 WERR("OpenFileMapping","WM_CREATE");
00214                 PostQuitMessage (0);
00215                 return (0);
00216             }
00217
00218             (LPVOID)MapView = MapViewOfFile (hMapObject,
00219                                              FILE_MAP_READ,
00220                                              0, 0, 0);
00221             if (!MapView)
00222             {
00223                 MessageBox (hwnd, "ERROR: MapViewOfFile was not successful.",
00224                             "From within WM_CREATE", MB_OK);
00225                 PostQuitMessage (0);
00226                 return (0);
00227             }
00228
00229             hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReadProc,
00230                                    NULL, 0, &ThreadID);
00231             if (!hThread)
00232             {
00233                 WERR("CreateThread", "WM_CREATE");
00234                 PostQuitMessage(0);
00235             }
00236
00237             return (0);
00238
00239         case WM_SIZE :
00240             SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
00241             return (0);
00242
00243         case WM_DESTROY :
00244             CloseHandle (hMapObject);
00245             CloseHandle (hThread);
00246             PostQuitMessage (0);
00247             return (0);
00248
00249     }
00250     return DefWindowProc (hwnd, message, wParam, lParam);
00251 }
00252
00253 /*************************************************************************\
00254 *
00255 *  FUNCTION:  VOID ReadProc (VOID)
00256 *
00257 *  PURPOSE:   A thread which continually reads the shared memory for new
00258 *             X and Y coordinates, and then draws the bitmap where indicated.
00259 *
00260 *  VARIABLES USED:
00261 *
00262 *    - hCrossHair:
00263 *             A handle to the bitmap.
00264 *
00265 *    - lParam, oldParam:
00266 *             LONGs used to hold the new and the old mouse coordinates.
00267 *
00268 *    - hDC, hDCMem:
00269 *             The DC of the window, and a memory DC used as the source
00270 *             of the bitmap.
00271 *
00272 *    - X, Y:  Integers representing the X and Y coordinates taken from
00273 *             the shared memory and used to locate the bitmap.
00274 *
00275 *    - hBrush:
00276 *             Handle to a brush, used to erase the old bitmap before
00277 *             redrawing it in the new location.
00278 *
00279 *    - rect:  A RECT, used to blot out the old bitmap (erasing it);
00280 *
00281 *    - bm:    a BITMAP structure for the bitmap.
00282 *
00283 *    - ptSize, ptOrg:
00284 *             POINTS used in transforming the coordinates for the bitmap.
00285 *
00286 *  COMMENTS:
00287 *
00288 *    This function first uses structured exception handling to try to
00289 *    read the shared memory a first time.  If successful, it's assumed
00290 *    that the rest of the read will not cause an exception.  The code then
00291 *    sets a brush for erasing the bitmap, and loads the bitmap.  It then
00292 *    begins to loop.  Each loop reads the memory.  If the value has
00293 *    changed since the last read the old bitmap is erased by drawing a
00294 *    rectangle over the old coordinates, and then the bitmap is moved
00295 *    and redrawn using the new coordinates.
00296 *
00297 \*************************************************************************/
00298 VOID ReadProc(VOID)
00299 {
00300     HBITMAP hCrossHair;
00301     LONG lParam, oldParam = 0;
00302     HDC hDC, hDCMem;
00303     int X, Y;
00304     HANDLE hBrush;
00305     RECT Rect;
00306     BITMAP bm;
00307     POINT ptSize, ptOrg;
00308
00309     _try
00310     {
00311         lParam = MapView[0];
00312     }
00313     _except(EXCEPTION_EXECUTE_HANDLER)
00314     {
00315         MessageBox(hWnd, "Trying to read shared memory caused an exception.",
00316                    "From within WM_MOUSEMOVE", MB_OK);
00317         PostMessage(hWnd, WM_DESTROY, 0, 0);
00318     }
00319
00320     hBrush = GetStockObject(WHITE_BRUSH);
00321     X = LOWORD(lParam);
00322     Y = HIWORD(lParam);
00323
00324     hCrossHair = LoadBitmap(hInst, "CrossHair");
00325
00326     while (1)
00327     {
00328         lParam = MapView[0];
00329
00330         if (lParam != oldParam)
00331         {
00332             hDC = GetDC(hWnd);
00333
00334             Rect.top = Y; Rect.left = X; Rect.bottom = Y+16; Rect.right = X+16;
00335             FillRect(hDC, &Rect, hBrush);
00336
00337             X = LOWORD(lParam);
00338             Y = HIWORD(lParam);
00339
00340             hDCMem = CreateCompatibleDC(hDC);
00341             SelectObject(hDCMem, hCrossHair);
00342             SetMapMode(hDCMem, GetMapMode(hDC));
00343
00344             GetObject(hCrossHair, sizeof(BITMAP), &bm);
00345
00346             ptSize.x = bm.bmWidth;
00347             ptSize.y = bm.bmHeight;
00348             DPtoLP (hDC, &ptSize, 1);
00349
00350             ptOrg.x = 0;
00351             ptOrg.y = 0;
00352             DPtoLP (hDCMem, &ptOrg, 1);
00353
00354             BitBlt(hDC, X, Y, ptSize.x, ptSize.y,
00355                    hDCMem, ptOrg.x, ptOrg.y, SRCCOPY);
00356
00357             oldParam = lParam;
00358             SetDlgItemInt (hWndDlg, IDE_XCOORD, X, FALSE);
00359             SetDlgItemInt (hWndDlg, IDE_YCOORD, Y, FALSE);
00360             ReleaseDC(hWnd, hDC);
00361             DeleteDC(hDCMem);
00362
00363             Sleep(100);
00364         }
00365     }
00366 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DLL16.C Source File

  • INTEROP

DLL16.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *                                                                    *
00003 *  File:      dll16.c                                                *
00004 *                                                                    *
00005 *  Comments:  16-bit side of the Universal/Generic Thunk             *
00006 *                                                                    *
00007 *  Functions: LibMain                                                *
00008 *             MyPrint                                                *
00009 *             UTInit                                                 *
00010 *             UTProc                                                 *
00011 *             WEP                                                    *
00012 *                                                                    *
00013 \********************************************************************/
00014
00015 /*********************  Header Files **********************/
00016
00017 #define W32SUT_16
00018
00019 #include <windows.h>
00020 #include "w32sut.h"
00021 #include "myut.h"
00022
00023 /*********************  Defines      **********************/
00024
00025 typedef void (FAR PASCAL *MYPROC)( LPSTR, LPSTR, DWORD );
00026
00027 typedef struct tagWIN32SINFO
00028 {
00029    BYTE bMajor;
00030    BYTE bMinor;
00031    WORD wBuildNumber;
00032    BOOL fDebug;
00033 } WIN32SINFO, FAR * LPWIN32SINFO;
00034
00035 /*********************  Globals      **********************/
00036
00037 BOOL fWin32s = FALSE;
00038 UT16CBPROC gpUTCBack = NULL;
00039
00040 MYPROC Proc;
00041 DWORD ghLib;
00042
00043 HWND ghWnd = NULL;
00044 HINSTANCE ghInst;
00045
00046 /*********************  Prototypes   **********************/
00047
00048 BOOL FAR PASCAL IsWin32sLoaded( void );
00049
00050 /********************************************************************\
00051 * Function: int FAR PASCAL LibMain( HINSTANCE, WORD, WORD, LPSTR )   *
00052 *                                                                    *
00053 *  Purpose: DLL entry point                                          *
00054 *                                                                    *
00055 * Comments: Loads the Win32 stub application                         *
00056 *                                                                    *
00057 *                                                                    *
00058 \********************************************************************/
00059
00060 int FAR PASCAL LibMain( HINSTANCE hInst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine )
00061 {
00062    DWORD dwVersion;
00063
00064    ghInst = hInst;
00065
00066    WinExec( "disp32.exe", SW_SHOW );
00067
00068    /* Check to see what version we're running on */
00069    dwVersion = GetVersion();
00070    if(( GetWinFlags() & WF_WINNT ) || ( HIBYTE(LOWORD(dwVersion)) == 95 ))
00071    {
00072       /* This is either Windows NT or Windows 95 */
00073       OutputDebugString( "This is either Windows NT or Windows 95\r\n" );
00074       ghLib = LoadLibraryEx32W( "dll32.dll", NULL, 0 );
00075    }
00076    else
00077    {
00078       fWin32s = IsWin32sLoaded( );
00079       if( fWin32s )
00080          WinExec( "stub32.exe", SW_SHOW );
00081       else
00082          return FALSE;
00083    }
00084    return TRUE;
00085 }
00086
00087 /********************************************************************\
00088 * Function: DWORD FAR PASCAL UTInit( UT16CBPROC, LPVOID )            *
00089 *                                                                    *
00090 *  Purpose: Universal Thunk initialization function                  *
00091 *                                                                    *
00092 * Comments: Called when UTRegister() is called by utdll32.dll. The   *
00093 *           window handle for the Win32 stub program is obtained and *
00094 *           saved in a global for cleanup purposes later on.         *
00095 *           FreeLibrary() is also called for cleanup purposes, by    *
00096 *           reducing the reference count (the DLL is also referenced *
00097 *           in the 32-bit side of the Universal Thunk through the    *
00098 *           call to UTRegister().                                    *
00099 *                                                                    *
00100 *                                                                    *
00101 \********************************************************************/
00102
00103 DWORD FAR PASCAL UTInit( UT16CBPROC pfnUT16CallBack, LPVOID lpBuff )
00104 {
00105    gpUTCBack = pfnUT16CallBack;
00106
00107    ghWnd = (HWND) (*gpUTCBack)( NULL, GETHWND, NULL );
00108
00109    FreeLibrary( ghInst );
00110
00111    return TRUE;
00112 }
00113
00114 /********************************************************************\
00115 * Function: DWORD FAR PASCAL UTProc( LPVOID, DWORD )                 *
00116 *                                                                    *
00117 *  Purpose: Universal Thunk 16-bit procedure                         *
00118 *                                                                    *
00119 * Comments: Unused                                                   *
00120 *                                                                    *
00121 *                                                                    *
00122 \********************************************************************/
00123
00124 DWORD FAR PASCAL UTProc( LPVOID lpBuff, DWORD dwFunc )
00125 {
00126    return FALSE;
00127 }
00128
00129 /********************************************************************\
00130 * Function: void WINAPI MyPrint( LPSTR, LPSTR, DWORD )               *
00131 *                                                                    *
00132 *  Purpose: Implementation of MyPrint()                              *
00133 *                                                                    *
00134 * Comments: Win32s: Implemented as a UT to the 32-bit side, where    *
00135 *           the actual implementation resides. The translation list  *
00136 *           is used to send multiple strings and have their          *
00137 *           addresses translated.                                    *
00138 *                                                                    *
00139 *           Windows NT: Implemented as a GenThunk to the 32-bit side *
00140 *           where the actual implementation resides. The address of  *
00141 *           the function is obtained with GetProcAddress32W() and    *
00142 *           the function is called via CallProc32W().                *
00143 *                                                                    *
00144 *                                                                    *
00145 \********************************************************************/
00146
00147 void WINAPI MyPrint( LPSTR lpString1, LPSTR lpString2, DWORD dwValue )
00148 {
00149    DWORD Args[3];
00150    LPVOID TransList[3];
00151
00152    /*
00153       The arguments are packed into the Args array to be passed through
00154       the thunk. The TransList contains any pointers which must be
00155       translated. We wish to pass dwValue by value, so it is not placed
00156       in the translation list. The last entry in the translation list
00157       must be NULL.
00158    */
00159
00160    if( fWin32s )
00161    {
00162       Args[0] = (DWORD) lpString1;
00163       Args[1] = (DWORD) lpString2;
00164       Args[2] = dwValue;
00165
00166       TransList[0] = &Args[0];
00167       TransList[1] = &Args[1];
00168       TransList[2] = NULL;
00169
00170       (*gpUTCBack)( Args, MYPRINT, TransList );
00171    }
00172
00173    /*
00174       CallProc32W() takes a variable number of parameters. The last
00175       parameter here indicates that the first three arguments are to
00176       be passed through the thunk. The next parameter specifies Proc
00177       as the address of the function to be called. The second to the
00178       last parameter is a mask that indicates which parameters are
00179       addresses which should be translated. Note that the mask is
00180       specified in the opposite order that the parameters are listed,
00181       so 6 = 0110, indicating that lpString1 and lpString2 should be
00182       translated.
00183    */
00184
00185    else
00186    {
00187       Proc = (MYPROC) GetProcAddress32W( ghLib, "MyPrint" );
00188       CallProc32W( (DWORD) lpString1, (DWORD) lpString2,
00189          (DWORD) dwValue, Proc, 6, 3 );
00190    }
00191 }
00192
00193 /********************************************************************\
00194 * Function: BOOL FAR PASCAL IsWin32sLoaded( );                       *
00195 *                                                                    *
00196 *  Purpose: Test if Win32s is loaded.                                *
00197 *                                                                    *
00198 * Comments: GetWin32sInfo.w32sys is used to verify if either Win32s  *
00199 *           version 1.0 or 1.1 is loaded.                            *
00200 *                                                                    *
00201 *                                                                    *
00202 \********************************************************************/
00203
00204 BOOL FAR PASCAL IsWin32sLoaded( )
00205 {
00206    BOOL       fWin32sLoaded = FALSE;
00207    HANDLE     hWin32sys;
00208    FARPROC    pfnInfo;
00209    WIN32SINFO Info;
00210
00211    hWin32sys = LoadLibrary( "w32sys.dll" );
00212
00213    if( hWin32sys > HINSTANCE_ERROR )
00214    {
00215       pfnInfo = GetProcAddress( hWin32sys, "GETWIN32SINFO" );
00216       if( pfnInfo )
00217       {
00218          if(!(*pfnInfo)((LPWIN32SINFO) &Info))
00219             fWin32sLoaded = TRUE;
00220          else fWin32sLoaded = FALSE;
00221       }
00222       else fWin32sLoaded = TRUE;
00223       FreeLibrary( hWin32sys );
00224    }
00225
00226    return fWin32sLoaded;
00227 }
00228
00229 /********************************************************************\
00230 * Function: int FAR PASCAL WEP ( int )                               *
00231 *                                                                    *
00232 *  Purpose: DLL exit procedure                                       *
00233 *                                                                    *
00234 * Comments: Win32s: Call into Win32 stub program to force cleanup of *
00235 *           Win32 DLLs.                                              *
00236 *                                                                    *
00237 *           Windows NT: Free dll32.dll and terminate disp32.exe      *
00238 *                                                                    *
00239 *                                                                    *
00240 \********************************************************************/
00241
00242 int FAR PASCAL WEP( int nParam )
00243 {
00244    SendMessage( FindWindow("Disp32Class", "Hidden Window"),
00245                 WM_CLOSE, 0, 0 );
00246
00247    if( fWin32s )
00248    {
00249       PostMessage( ghWnd, WM_CLOSE, 0, 0 );
00250    }
00251    else
00252    {
00253       FreeLibrary32W( ghLib );
00254    }
00255    return TRUE;
00256 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MISCUTIL.C Source File

  • SERVENUM
  • DLL

MISCUTIL.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   miscutil.c
00009 //
00010 //  PURPOSE:  Contains miscutil helper functions
00011 //
00012 //  FUNCTIONS:
00013 //    CenterWindow - Center one window over another.
00014 //    SetBitmapBkgnd - Sets the background color of a bitmap
00015 //    CreateStdFont - Creates a SansSerif font by pointsize
00016 //
00017 //  AUTHOR: Craig Link - Microsoft Developer Support
00018 //
00019
00020 #include <windows.h>            // required for all Windows applications
00021 #include <tchar.h>
00022 #include "miscutil.h"
00023 #include "mem.h"
00024
00025 //
00026 //  FUNCTION: CenterWindow(HWND, HWND)
00027 //
00028 //  PURPOSE:  Center one window over another.
00029 //
00030 //  PARAMETERS:
00031 //    hwndChild - The handle of the window to be centered.
00032 //    hwndParent- The handle of the window to center on.
00033 //
00034 //  RETURN VALUE:
00035 //
00036 //    TRUE  - Success
00037 //    FALSE - Failure
00038 //
00039 //  COMMENTS:
00040 //
00041 //    Dialog boxes take on the screen position that they were designed
00042 //    at, which is not always appropriate. Centering the dialog over a
00043 //    particular window usually results in a better position.
00044 //
00045
00046 BOOL CenterWindow(HWND hwndChild, HWND hwndParent)
00047 {
00048     RECT    rcChild, rcParent;
00049     int     cxChild, cyChild, cxParent, cyParent;
00050     int     cxScreen, cyScreen, xNew, yNew;
00051     HDC     hdc;
00052
00053     // Get the Height and Width of the child window
00054     GetWindowRect(hwndChild, &rcChild);
00055     cxChild = rcChild.right - rcChild.left;
00056     cyChild = rcChild.bottom - rcChild.top;
00057
00058     // Get the Height and Width of the parent window
00059     GetWindowRect(hwndParent, &rcParent);
00060     cxParent = rcParent.right - rcParent.left;
00061     cyParent = rcParent.bottom - rcParent.top;
00062
00063     // Get the display limits
00064     hdc = GetDC(hwndChild);
00065     cxScreen = GetDeviceCaps(hdc, HORZRES);
00066     cyScreen = GetDeviceCaps(hdc, VERTRES);
00067     ReleaseDC(hwndChild, hdc);
00068
00069     // Calculate new X position, then adjust for screen
00070     xNew = rcParent.left + ((cxParent - cxChild) / 2);
00071     if (xNew < 0)
00072     {
00073         xNew = 0;
00074     }
00075     else if ((xNew + cxChild) > cxScreen)
00076     {
00077         xNew = cxScreen - cxChild;
00078     }
00079
00080     // Calculate new Y position, then adjust for screen
00081     yNew = rcParent.top  + ((cyParent - cyChild) / 2);
00082     if (yNew < 0)
00083     {
00084         yNew = 0;
00085     }
00086     else if ((yNew + cyChild) > cyScreen)
00087     {
00088         yNew = cyScreen - cyChild;
00089     }
00090
00091     // Set it, and return
00092     return SetWindowPos(hwndChild,
00093                         NULL,
00094                         xNew, yNew,
00095                         0, 0,
00096                         SWP_NOSIZE | SWP_NOZORDER);
00097 }
00098
00099
00100 //
00101 //  FUNCTION: SetBitmapBkgnd( HINSTANCE hinst, LPCTSTR szName, COLORREF rgbBkgnd )
00102 //
00103 //  PURPOSE:  Sets the background color of a bitmap
00104 //
00105 //  PARAMETERS:
00106 //    hinst - module containing bitmap data
00107 //    szName - Name of bitmap in resource
00108 //    rgbBkgnd - color to set the background
00109 //
00110 //  RETURN VALUE:
00111 //    Non-NULL - Handle to new bitmap
00112 //    NULL - Failure
00113 //
00114 //  COMMENTS:
00115 //    The bitmap loaded in from the resource has a GREEN background
00116 //    The background color is changed by modifing the bmp's palette
00117 //    entry.  szName can be a value return by MAKEINTRESOURCE
00118
00119 HBITMAP SetBitmapBkgnd( HINSTANCE hinst, LPCTSTR szName, COLORREF rgbBkgnd )
00120 {
00121     LPBYTE              lpb;
00122     HBITMAP             hbmp;
00123     LPBITMAPINFOHEADER  lpbi;
00124     LPBITMAPINFOHEADER  lpbiTemp;
00125     HANDLE              h;
00126     HDC                 hdc;
00127     LPDWORD             lprgb;
00128     DWORD               cbClrTable;
00129
00130 #define RGBQ(dw) RGB(GetBValue(dw),GetGValue(dw),GetRValue(dw))
00131
00132     h = LoadResource (hinst, FindResource(hinst, szName, RT_BITMAP));
00133
00134     lpbi = (LPBITMAPINFOHEADER) LockResource(h);
00135
00136     if (!lpbi)
00137         return NULL;
00138
00139     if (lpbi->biSize != sizeof(BITMAPINFOHEADER))
00140         return NULL;
00141
00142     if (lpbi->biBitCount != 4)
00143         return NULL;
00144
00145
00146     cbClrTable = ((int)lpbi->biClrUsed ?
00147                   (int)lpbi->biClrUsed :
00148                   (1 << (int)lpbi->biBitCount)) * sizeof(RGBQUAD);
00149
00150     if ( ERROR_SUCCESS != MallocMem( &lpbiTemp, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage ) )
00151         return NULL;
00152
00153     memcpy( lpbiTemp, lpbi, sizeof(BITMAPINFOHEADER) + cbClrTable + lpbi->biSizeImage );
00154
00155     // Calcluate the pointer to the Bits information
00156     // First skip over the header structure
00157     lprgb = (LPDWORD)((LPBYTE)(lpbiTemp) + lpbiTemp->biSize);
00158
00159     // Skip the color table entries, if any
00160     lpb = (LPBYTE)lprgb + cbClrTable;
00161
00162     lprgb[10] = RGBQ(rgbBkgnd);         // green
00163
00164     hdc = GetDC(NULL);
00165
00166     hbmp = CreateDIBitmap (hdc, lpbiTemp, CBM_INIT, (LPVOID)lpb,
00167                           (LPBITMAPINFO)lpbiTemp, DIB_RGB_COLORS);
00168
00169     FreeMem( &lpbiTemp );
00170     ReleaseDC(NULL, hdc);
00171     UnlockResource(h);
00172     FreeResource(h);
00173
00174     return(hbmp);
00175 }
00176
00177
00178 //
00179 //  FUNCTION: CreateStdFont (HWND hwnd, int heightPoints)
00180 //
00181 //  PURPOSE:  Creates a "MS Sans Serif" font of desired point size
00182 //
00183 //  PARAMETERS:
00184 //    hwnd - window handle for DC
00185 //    heightPoints - point size of desired font
00186 //
00187 //  RETURN VALUE:
00188 //    Non-NULL - Handle to new font
00189 //    NULL - Failure
00190 //
00191 //  COMMENTS:
00192 //
00193
00194 HFONT CreateStdFont (HWND hwnd, int heightPoints)
00195 {
00196     int heightPix;
00197     int heightTwips;
00198     UINT cyPixPerInch;
00199     UINT cyTwipsPerPixel;
00200     HDC hdc;
00201     LOGFONT lf;
00202
00203     hdc = GetDC(hwnd);
00204     cyPixPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
00205     ReleaseDC(hwnd, hdc);
00206
00207     cyTwipsPerPixel = 1440 / cyPixPerInch;
00208     heightTwips = heightPoints * 20 + 10;   // 10 is for round-up
00209     heightPix = heightTwips / cyTwipsPerPixel;
00210
00211     lf.lfHeight = -heightPix;
00212     lf.lfWidth = 0;
00213     lf.lfEscapement = 0;
00214     lf.lfOrientation = 0;
00215     lf.lfWeight = FW_THIN;
00216     lf.lfItalic = 0;
00217     lf.lfUnderline = 0;
00218     lf.lfStrikeOut = 0;
00219     lf.lfCharSet = ANSI_CHARSET;
00220     lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
00221     lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
00222     lf.lfQuality = DEFAULT_QUALITY;
00223     lf.lfPitchAndFamily = FF_SWISS;
00224     _tcscpy(lf.lfFaceName, TEXT("MS Sans Serif") );
00225
00226     return CreateFontIndirect(&lf);
00227 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/BITMAP.C Source File

  • MASKBLT

BITMAP.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  bitmap.c -- support for reading in and drawing bitmaps.
00014 \**************************************************************************/
00015
00016 #include <windows.h>
00017 #include <commdlg.h>
00018
00019
00020
00021 /**************************************************************************\
00022 *
00023 *  function:  DrawBitmap()
00024 *
00025 *  input parameters:  HDC, HBITMAP
00026 *
00027 *  Draw the bitmap into the hdc.  Source rectangle computed to include the
00028 *   whole bitmap.  Destination location is 0,0.
00029 *
00030 *  global variables: none.
00031 *
00032 \**************************************************************************/
00033 VOID DrawBitmap (HDC hdc, HBITMAP hbm)
00034 {
00035     BOOL f;
00036     HDC hdcBits;
00037     BITMAP bm;
00038
00039     hdcBits = CreateCompatibleDC(hdc);
00040     GetObject (hbm, sizeof(BITMAP), &bm);
00041     SelectObject(hdcBits,hbm);
00042     f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
00043     DeleteDC(hdcBits);
00044 }
00045
00046
00047
00048 /**************************************************************************\
00049 *
00050 *  function:  GetBitmap()
00051 *
00052 *  input parameters:
00053 *   hdc - hdc to make the bitmap compatible with.
00054 *   hInst - instance handle
00055 *
00056 *  Put up a common dialog box to open a new *.BMP file.
00057 *   Once this is complete, open the file, read in the information,
00058 *   and create a compatible bitmap.
00059 *
00060 *  returns:  handle to the bitmap iff successful.  NULL otherwise.
00061 *
00062 \**************************************************************************/
00063 HBITMAP GetBitmap (HDC hdc, HANDLE hInst, BOOL monochrome)
00064 {
00065     HBITMAP hbm;
00066     PBITMAPFILEHEADER pbmfh;
00067     PBITMAPINFOHEADER pbmih;
00068     PBYTE             pBits;
00069     int fh;
00070     int bfOffBits;
00071     int nbytes;
00072     OPENFILENAME  of;
00073     char buffer [MAX_PATH];
00074
00075     buffer[0] = 0;
00076
00077     /* set up the OPENFILE structure,
00078      *  then use the appropriate common dialog
00079      */
00080     of.lStructSize       = sizeof (OPENFILENAME);
00081     of.hwndOwner         = NULL;
00082     of.hInstance         = hInst;
00083     of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
00084     of.lpstrCustomFilter = NULL;
00085     of.nMaxCustFilter    = 0;
00086     of.nFilterIndex      = 0;
00087     of.lpstrFile         = buffer;
00088     of.nMaxFile          = MAX_PATH;
00089     of.lpstrFileTitle    = NULL;
00090     of.nMaxFileTitle     = 0;
00091     of.lpstrInitialDir   = "c:\\nt\\windows";
00092     of.lpstrTitle        = NULL;
00093     of.Flags             = OFN_HIDEREADONLY;
00094     of.nFileOffset       = 0;
00095     of.nFileExtension    = 0;
00096     of.lpstrDefExt       = NULL;
00097     of.lCustData         = 0;
00098     of.lpfnHook          = NULL;
00099     of.lpTemplateName    = NULL;
00100     if (!GetOpenFileName (&of)) return NULL;
00101
00102     /* Try to open the file.  If successful, then allocate space for it,
00103      *  and read in all of the bytes.
00104      */
00105     fh = _lopen (buffer, OF_READ);
00106     if (fh == -1) return NULL;
00107     nbytes = GetFileSize ((HANDLE) fh, NULL);
00108
00109     /* The contents of the file are read in here in three parts.  First
00110      *  the bitmap file header is read, then the bitmap header along with
00111      *  the color table, then finally the actual bit data.  I.e. from
00112      *  a total of nbytes...
00113      *    1.  sizeof (BITMAPFILEHEADER)
00114      *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
00115      *    3.  (nbytes - bfOffBits)
00116      */
00117
00118     /* read in the bitmap file header.  save the offset to bits. */
00119     if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
00120         return NULL;
00121     _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
00122     bfOffBits=pbmfh->bfOffBits;
00123
00124     /* read in the bitmap info header and the color table right after it.
00125      * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
00126      */
00127     if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
00128         return NULL;
00129     _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));
00130
00131     /* finally read in the bit data. */
00132     if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
00133     _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));
00134
00135
00136     /* in the case of desiring a monochrome bitmap (input parameter),
00137      *  verify that is what we got.  If it is, then use CreateBitmap,
00138      *  else use a device independent bitmap.
00139      */
00140     if (monochrome) {
00141       if (pbmih->biBitCount != 1) {
00142         MessageBox (NULL, "Mask must be monochrome bitmap.",
00143                     "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
00144         hbm = NULL;
00145       } else {
00146       hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
00147                           pbmih->biPlanes, pbmih->biBitCount,
00148                           pBits);
00149       }
00150     } else  /* bitmap is NOT monochrome, use DIB. */
00151       hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
00152                           pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);
00153
00154
00155     /* hbm is set... free up memory, and return */
00156     LocalFree (LocalHandle ((LPSTR)pBits));
00157     LocalFree (LocalHandle ((LPSTR)pbmih));
00158     LocalFree (LocalHandle ((LPSTR)pbmfh));
00159     _lclose (fh);
00160
00161     return hbm;
00162 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETDEV/GETDEV.H Source File

  • GETDEV

GETDEV.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* getdev.h - header file for the getdev sample. */
00013
00014
00015 /* function prototypes.  Window procedures first. */
00016 long FAR PASCAL MainDlgProc(HWND, UINT, UINT, LONG);
00017
00018 VOID ExpandInfo (HWND, int, int);
00019
00020
00021
00022 /* declare global variable to be used to hold string sent to list box. */
00023 char buffer[100];
00024 char space[] = "   %s";
00025
00026
00027
00028 /* the control ID from the dialog box. */
00029 #define DID_LISTBOX     0x006B
00030
00031
00032 /* structure for the lookup tables.  */
00033 typedef struct tagLookupEntry{
00034     int     Value;
00035     char    String[100];
00036 } LookupEntry;
00037
00038
00039
00040 /* GetDeviceCaps() codes from WINGDI.H */
00041 #define NINDEX  28
00042 LookupEntry  DevCaps[NINDEX] =
00043     {{  0 , "DRIVERVERSION "},
00044      {  2 , "TECHNOLOGY    "},
00045      {  4 , "HORZSIZE      "},
00046      {  6 , "VERTSIZE      "},
00047      {  8 , "HORZRES       "},
00048      {  10, "VERTRES       "},
00049      {  12, "BITSPIXEL     "},
00050      {  14, "PLANES        "},
00051      {  16, "NUMBRUSHES    "},
00052      {  18, "NUMPENS       "},
00053      {  20, "NUMMARKERS    "},
00054      {  22, "NUMFONTS      "},
00055      {  24, "NUMCOLORS     "},
00056      {  26, "PDEVICESIZE   "},
00057      {  28, "CURVECAPS     "},
00058      {  30, "LINECAPS      "},
00059      {  32, "POLYGONALCAPS "},
00060      {  34, "TEXTCAPS      "},
00061      {  36, "CLIPCAPS      "},
00062      {  38, "RASTERCAPS    "},
00063      {  40, "ASPECTX       "},
00064      {  42, "ASPECTY       "},
00065      {  44, "ASPECTXY      "},
00066      {  88, "LOGPIXELSX    "},
00067      {  90, "LOGPIXELSY    "},
00068      { 104, "SIZEPALETTE   "},
00069      { 106, "NUMRESERVED   "},
00070      { 108, "COLORRES      "}};
00071
00072
00073
00074
00075 /* Device Technologies */
00076 #define NDevice 7
00077 LookupEntry  Device[NDevice] =
00078     {{ 0 , "DT_PLOTTER   "},
00079      { 1 , "DT_RASDISPLAY"},
00080      { 2 , "DT_RASPRINTER"},
00081      { 3 , "DT_RASCAMERA "},
00082      { 4 , "DT_CHARSTREAM"},
00083      { 5 , "DT_METAFILE  "},
00084      { 6 , "DT_DISPFILE  "}};
00085
00086
00087 /* Curve Capabilities */
00088 #define NCurveCaps 9
00089 LookupEntry  CurveCaps[NCurveCaps] =
00090     {{ 0   , "CC_NONE      "},
00091      { 1   , "CC_CIRCLES   "},
00092      { 2   , "CC_PIE       "},
00093      { 4   , "CC_CHORD     "},
00094      { 8   , "CC_ELLIPSES  "},
00095      { 16  , "CC_WIDE      "},
00096      { 32  , "CC_STYLED    "},
00097      { 64  , "CC_WIDESTYLED"},
00098      { 128 , "CC_INTERIORS "}};
00099
00100
00101 /* Line Capabilities */
00102 #define NLineCaps 8
00103 LookupEntry  LineCaps[NLineCaps] =
00104     {{ 0   , "LC_NONE       "},
00105      { 2   , "LC_POLYLINE   "},
00106      { 4   , "LC_MARKER     "},
00107      { 8   , "LC_POLYMARKER "},
00108      { 16  , "LC_WIDE       "},
00109      { 32  , "LC_STYLED     "},
00110      { 64  , "LC_WIDESTYLED "},
00111      { 128 , "LC_INTERIORS  "}};
00112
00113
00114 /* Polygonal Capabilities */
00115 #define NPolygonalCaps 10
00116 LookupEntry  PolygonalCaps[NPolygonalCaps] =
00117     {{ 0   , "PC_NONE       "},
00118      { 1   , "PC_POLYGON    "},
00119      { 2   , "PC_RECTANGLE  "},
00120      { 4   , "PC_WINDPOLYGON"},
00121      { 4   , "PC_TRAPEZOID  "},   // HACK   two 4's ???
00122      { 8   , "PC_SCANLINE   "},
00123      { 16  , "PC_WIDE       "},
00124      { 32  , "PC_STYLED     "},
00125      { 64  , "PC_WIDESTYLED "},
00126      { 128 , "PC_INTERIORS  "}};
00127
00128
00129 /* Clip Capabilities */
00130 #define NClipCaps 2
00131 LookupEntry  ClipCaps[NClipCaps] =
00132     {{ 0   , "CP_NONE     "},
00133      { 1   , "CP_RECTANGLE"}};
00134
00135
00136 /* Text Capabilities */
00137 #define NTextCaps 16
00138 LookupEntry  TextCaps[NTextCaps] =
00139     {{ 0x0001 , "TC_OP_CHARACTER"},
00140      { 0x0002 , "TC_OP_STROKE   "},
00141      { 0x0004 , "TC_CP_STROKE   "},
00142      { 0x0008 , "TC_CR_90       "},
00143      { 0x0010 , "TC_CR_ANY      "},
00144      { 0x0020 , "TC_SF_X_YINDEP "},
00145      { 0x0040 , "TC_SA_DOUBLE   "},
00146      { 0x0080 , "TC_SA_INTEGER  "},
00147      { 0x0100 , "TC_SA_CONTIN   "},
00148      { 0x0200 , "TC_EA_DOUBLE   "},
00149      { 0x0400 , "TC_IA_ABLE     "},
00150      { 0x0800 , "TC_UA_ABLE     "},
00151      { 0x1000 , "TC_SO_ABLE     "},
00152      { 0x2000 , "TC_RA_ABLE     "},
00153      { 0x4000 , "TC_VA_ABLE     "},
00154      { 0x8000 , "TC_RESERVED    "}};
00155
00156
00157 /* Raster Capabilities */
00158 #define NRasterCaps 12
00159 LookupEntry  RasterCaps[NRasterCaps] =
00160     {{  1     , "RC_BITBLT       "},
00161      {  2     , "RC_BANDING      "},
00162      {  4     , "RC_SCALING      "},
00163      {  8     , "RC_BITMAP64     "},
00164      {  0x0010, "RC_GDI20_OUTPUT "},
00165      {  0x0080, "RC_DI_BITMAP    "},
00166      {  0x0100, "RC_PALETTE      "},
00167      {  0x0200, "RC_DIBTODEV     "},
00168      {  0x0400, "RC_BIGFONT      "},
00169      {  0x0800, "RC_STRETCHBLT   "},
00170      {  0x1000, "RC_FLOODFILL    "},
00171      {  0x2000, "RC_STRETCHDIB   "}};
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDI.C Source File

  • NTSD

MDI.C

Go to the documentation of this file.
00001 /******************************Module*Header*******************************\
00002 * Module Name: mdi.c
00003 *
00004 * MDI demonstration
00005 *   +   Associating data with a MDI window (using Set/GetWindowLong )
00006 *
00007 * Created: 24-Oct-1991 18:34:08
00008 * Author: Petrus Wong []
00009 *
00010 * Copyright (c) 1990-1996 Microsoft Corporation
00011 *
00012 * Dependencies:
00013 *
00014 *   (#defines)
00015 *   (#includes)
00016 *       MDI.H
00017 *
00018 \**************************************************************************/
00019 #define STRICT
00020 #include <stdlib.h>
00021 #include "mdi.h"
00022 #include <stdarg.h>
00023
00024 HANDLE ghModule;
00025 HWND   ghwndMain   = NULL;
00026 HWND   ghwndClient = NULL;
00027
00028 HMENU  hMenu,      hMenuWindow;
00029 HMENU  hChildMenu, hChildMenuWindow;
00030
00031 CHAR   gszFile[20];
00032 CHAR   gszMapName[20];
00033
00034 //
00035 // Instance data for each MDI child window
00036 //
00037 typedef struct _PerWndInfo {
00038     HWND    hParent;
00039     HWND    hTextWnd;
00040     RECT    rcClient;
00041     char    CaptionBarText[SIZEOFCAPTIONTEXT];
00042 } INFO, *PINFO;
00043
00044 //
00045 // Forward declarations.
00046 //
00047 BOOL InitializeApp   (void);
00048 LONG APIENTRY MainWndProc     (HWND, UINT, DWORD, LONG);
00049 LONG APIENTRY MDIWndProc      (HWND, UINT, DWORD, LONG);
00050 BOOL CALLBACK About           (HWND, UINT, DWORD, LONG);
00051 LONG APIENTRY TextWndProc     (HWND, UINT, DWORD, LONG);
00052 VOID vTest           (PINFO);
00053
00054 /***************************************************************************\
00055 * WinMain
00056 *
00057 *
00058 * History:
00059 * 11-Feb-1992   Petrus Wong []
00060 *   Added conditional compile statement for internal build environment.
00061 * 04-17-91      ????      Created.
00062 \***************************************************************************/
00063 int APIENTRY WinMain(
00064     HINSTANCE hInstance,
00065     HINSTANCE hPrevInstance,
00066     LPSTR lpCmdLine,
00067     int nShowCmd)
00068 {
00069     MSG    msg;
00070     HANDLE hAccel;
00071
00072     ghModule = GetModuleHandle(NULL);
00073     if (!InitializeApp()) {
00074   MessageBox(ghwndMain, "MDI: InitializeApp failure!", "Error", MB_OK);
00075   return 0;
00076     }
00077
00078     if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
00079   MessageBox(ghwndMain, "MDI: Load Accel failure!", "Error", MB_OK);
00080
00081
00082     while (GetMessage(&msg, NULL, 0, 0)) {
00083   if (!TranslateAccelerator( ghwndMain, hAccel, &msg) &&
00084       !TranslateMDISysAccel(  ghwndClient, &msg)          ) {
00085       TranslateMessage(&msg);
00086       DispatchMessage(&msg);
00087   }
00088     }
00089
00090     return 1;
00091
00092     UNREFERENCED_PARAMETER(lpCmdLine);
00093     UNREFERENCED_PARAMETER(nShowCmd);
00094     UNREFERENCED_PARAMETER(hInstance);
00095     UNREFERENCED_PARAMETER(hPrevInstance);
00096 }
00097
00098
00099 /***************************************************************************\
00100 * InitializeApp
00101 *
00102 * History:
00103 * 11-Feb-1992   Petrus Wong []
00104 *   Name changes.
00105 * 09-09-91      Created.
00106 \***************************************************************************/
00107
00108 BOOL InitializeApp(void)
00109 {
00110     WNDCLASS wc;
00111
00112     wc.style            = CS_OWNDC;
00113     wc.lpfnWndProc      = (WNDPROC) MainWndProc;
00114     wc.cbClsExtra       = 0;
00115     wc.cbWndExtra       = sizeof(LONG);
00116     wc.hInstance        = ghModule;
00117     wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
00118     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
00119     wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE);
00120     wc.lpszMenuName     = "MainMenu";
00121     wc.lpszClassName    = "MDIDemoClass";
00122
00123     if (!RegisterClass(&wc))
00124   return FALSE;
00125
00126     wc.lpfnWndProc      = (WNDPROC) MDIWndProc;
00127     wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
00128     wc.lpszMenuName     = NULL;
00129     wc.lpszClassName    = "MDIClass";
00130
00131     if (!RegisterClass(&wc))
00132   return FALSE;
00133
00134     wc.style            = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
00135     wc.lpfnWndProc      = (WNDPROC) TextWndProc;
00136     wc.hIcon            = NULL;
00137     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
00138     wc.hbrBackground    = (HBRUSH)(COLOR_BTNSHADOW);
00139     wc.lpszMenuName     = NULL;
00140     wc.lpszClassName    = "Text";
00141
00142     if (!RegisterClass(&wc))
00143       return FALSE;
00144
00145
00146
00147     hMenu       = LoadMenu(ghModule, "MainMenu");
00148     hChildMenu  = LoadMenu(ghModule, "ChildMenu");
00149     hMenuWindow      = GetSubMenu(hMenu, 1);
00150     hChildMenuWindow = GetSubMenu(hChildMenu, 2);
00151
00152     ghwndMain = CreateWindowEx(0L, "MDIDemoClass", "MDI Demonstration",
00153       WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
00154       WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
00155       WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
00156       80, 70, 400, 300,
00157       NULL, hMenu, ghModule, NULL);
00158
00159     if (ghwndMain == NULL)
00160   return FALSE;
00161
00162     SetWindowLong(ghwndMain, GWL_USERDATA, 0L);
00163
00164     SetFocus(ghwndMain);    /* set initial focus */
00165
00166     return TRUE;
00167 }
00168
00169
00170 /***************************************************************************\
00171 * MainWndProc
00172 *
00173 * History:
00174 * 11-Feb-1992   Petrus Wong []
00175 *   Name changes.  Added comments.
00176 * 09-09-91      Created.
00177 \***************************************************************************/
00178
00179 long APIENTRY MainWndProc(
00180     HWND hwnd,
00181     UINT message,
00182     DWORD wParam,
00183     LONG lParam)
00184 {
00185     static int         iMDICount=1;
00186     CLIENTCREATESTRUCT clientcreate;
00187     HWND               hwndChildWindow;
00188
00189
00190     switch (message) {
00191
00192       case WM_CREATE:
00193   SetWindowLong(hwnd, 0, (LONG)NULL);
00194
00195   clientcreate.hWindowMenu  = hMenuWindow;
00196   clientcreate.idFirstChild = 1;
00197
00198   ghwndClient = CreateWindow("MDICLIENT", NULL,
00199             WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
00200             0,0,0,0,
00201             hwnd, NULL, ghModule, (LPVOID)&clientcreate);
00202   return 0L;
00203
00204       case WM_DESTROY: {
00205   PostQuitMessage(0);
00206   return 0L;
00207       }
00208
00209       case WM_COMMAND:
00210
00211   switch (LOWORD(wParam)) {
00212       //
00213       // Getting default MDI functionalities...
00214       //
00215       case IDM_TILE:
00216     SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
00217     return 0L;
00218       case IDM_CASCADE:
00219     SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
00220     return 0L;
00221       case IDM_ARRANGE:
00222     SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
00223     return 0L;
00224
00225       //
00226       // Creates MDI child
00227       //
00228       case MM_MDI: {
00229     HANDLE hInfo;
00230     PINFO  pInfo;
00231     MDICREATESTRUCT mdicreate;
00232
00233     //
00234     // Allocating memory for INFO to be associated with the
00235     //  new child
00236     //
00237     hInfo = LocalAlloc(LHND, (WORD) sizeof(INFO));
00238     if (hInfo) {
00239         if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00240       MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00241
00242         wsprintf((LPSTR) &(pInfo->CaptionBarText),
00243            "MDI %d", iMDICount);
00244         pInfo->hParent    = ghwndClient;
00245
00246         mdicreate.szClass = "MDIClass";
00247         mdicreate.szTitle = (LPTSTR)&(pInfo->CaptionBarText);
00248         mdicreate.hOwner  = ghModule;
00249         mdicreate.x       =
00250         mdicreate.y       =
00251         mdicreate.cx      =
00252         mdicreate.cy      = CW_USEDEFAULT;
00253         mdicreate.style   = 0L;
00254         //
00255         // passing the handle of the per MDI child INFO to the
00256         //  child MDI window for storage
00257         //
00258         mdicreate.lParam  = (LONG) hInfo;
00259
00260         /*Create Child Window*/
00261         hwndChildWindow =
00262       (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
00263             0L,
00264             (LONG)(LPMDICREATESTRUCT)&mdicreate);
00265
00266         if (hwndChildWindow == NULL) {
00267       MessageBox(ghwndMain, "Failed in Creating Child Window", "Error", MB_OK);
00268       return 0L;
00269         }
00270
00271         iMDICount++;
00272
00273         LocalUnlock(hInfo);
00274     } else {
00275           MessageBox(ghwndMain, "Failed to Allocate INFO data!", "Error", MB_OK);
00276     }
00277     return 0L;
00278       }
00279
00280
00281       case MM_ABOUT:
00282     if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
00283       MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
00284     return 0L;
00285
00286       //
00287       // Passes these WM_COMMAND messages to the appropriate active child
00288       //  window proc for processing
00289       //
00290       case MM_OPT_1:
00291       case MM_OPT_2:
00292       case MM_OPT_3:
00293       case MM_OPT_4:
00294       case MM_OPT_5:
00295       case MM_OPT_6:
00296       case MM_OPT_7:
00297       case MM_OPT_8: {
00298     HWND hActiveChild;
00299
00300     hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L);
00301     if (hActiveChild)
00302         SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
00303     return 0L;
00304       }
00305
00306       default:
00307     return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
00308   }
00309
00310     default:
00311
00312   return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
00313     }
00314 }
00315
00316 /***************************************************************************\
00317 * MDIWndProc
00318 *
00319 * History:
00320 * 11-Feb-1992   Petrus Wong []
00321 *   Name changes. Added comments.
00322 * 09-09-91      Petrus Wong Rewrote.
00323 * 04-17-91 ????      Created.
00324 \***************************************************************************/
00325
00326 long APIENTRY MDIWndProc(
00327     HWND hwnd,
00328     UINT message,
00329     DWORD wParam,
00330     LONG lParam)
00331 {
00332
00333     switch (message) {
00334   case WM_COMMAND: {
00335     HANDLE      hInfo;
00336     PINFO       pInfo;
00337     HWND        hTextWnd;
00338
00339     //
00340     // Retrieving this child window's INFO data for displaying
00341     //    messages in the text window
00342     //
00343     hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00344     if (hInfo) {
00345         if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00346       MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00347
00348         hTextWnd = pInfo->hTextWnd;
00349         vTest(pInfo);
00350         LocalUnlock(hInfo);
00351     } else {
00352         MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
00353     }
00354
00355
00356     switch (LOWORD(wParam)) {
00357       case MM_OPT_1: {
00358          SetWindowText(hTextWnd, "MM_OPT_1");
00359          return 0L;
00360       }
00361
00362       case MM_OPT_2: {
00363          SetWindowText(hTextWnd, "MM_OPT_2");
00364          return 0L;
00365       }
00366
00367       case MM_OPT_3: {
00368          SetWindowText(hTextWnd, "MM_OPT_3");
00369          return 0L;
00370       }
00371
00372       case MM_OPT_4: {
00373          SetWindowText(hTextWnd, "MM_OPT_4");
00374          return 0L;
00375       }
00376       default:
00377          return 0L;
00378
00379     }
00380
00381   }
00382   case WM_SETFOCUS:
00383       break;
00384
00385   //
00386   // Potentially, you can set different menu for different MDI
00387   //  child which is currently being active.
00388   //
00389   case WM_MDIACTIVATE:
00390       if ((HWND) lParam == hwnd) {
00391     SendMessage(GetParent(hwnd), WM_MDISETMENU,
00392           (DWORD)  hChildMenu,
00393           (LONG)   hChildMenuWindow) ;
00394     DrawMenuBar(GetParent(GetParent(hwnd))) ;
00395       }
00396       return 0L;
00397
00398   //
00399   // Whenever the MDI child window is resized, its children has to be
00400   //  resized accordingly.
00401   //
00402   case WM_SIZE: {
00403       HANDLE      hInfo;
00404       PINFO       pInfo;
00405       HWND        hTextWnd;
00406
00407       //
00408       // First, get the text window's handle from the per MDI child
00409       //  INFO data structure
00410       //
00411       hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00412       if (hInfo) {
00413     if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00414         MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00415
00416     hTextWnd = pInfo->hTextWnd;
00417     LocalUnlock(hInfo);
00418       } else {
00419     MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
00420       }
00421
00422       //
00423       // Always, put the text window at the bottom of the MDI window
00424       //
00425       MoveWindow(hTextWnd,
00426            0,
00427            HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
00428            LOWORD(lParam),
00429            HIWORD(lParam), TRUE);
00430       break;
00431   }
00432
00433   //
00434   // Creates the text window for this MDI child and saves its handle
00435   //  in the per MDI child INFO data structure.
00436   //
00437   case WM_CREATE: {
00438       PINFO           pInfo;
00439       HANDLE          hInfo;
00440       HWND            hTextWnd;
00441
00442       hTextWnd = CreateWindow("Text", NULL,
00443             WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
00444             0, 0, 0, 0,
00445             hwnd,
00446             (HMENU) 2,
00447             ghModule,
00448             NULL);
00449
00450       SetWindowText(hTextWnd, "Select 'Option' menu items");
00451       //
00452       // INFO was allocated in the MDIWndProc at MM_MDI time and is
00453       //  passed to us at WM_CREATE time...
00454       //
00455       hInfo = (HANDLE) ((LPMDICREATESTRUCT) ((LPCREATESTRUCT) lParam)->lpCreateParams)->lParam ;
00456       if (hInfo) {
00457     if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00458         MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00459
00460     if (!GetClientRect(hwnd, &pInfo->rcClient))
00461         MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);
00462
00463     pInfo->hTextWnd = hTextWnd;
00464     //
00465     // Save the handle to INFO in our window structure
00466     //
00467     SetWindowLong(hwnd, 0, (LONG) hInfo);
00468     LocalUnlock(hInfo);
00469       } else {
00470     MessageBox(ghwndMain, "Can't allocate hInfo!", "Error", MB_OK);
00471       }
00472
00473       break;
00474   }
00475
00476   //
00477   // Free the INFO data that associates with this window
00478   //  also, reset the menu.
00479   //
00480   case WM_CLOSE: {
00481       HANDLE           hInfo;
00482
00483       SendMessage(GetParent(hwnd), WM_MDISETMENU,
00484           (DWORD) hMenu,
00485           (LONG)  hMenuWindow) ;
00486       DrawMenuBar(GetParent(GetParent(hwnd))) ;
00487
00488       hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00489       LocalFree(hInfo);
00490       break;
00491   }
00492
00493   default:
00494       return DefMDIChildProc(hwnd, message, wParam, lParam);
00495
00496     } //switch
00497     return DefMDIChildProc(hwnd, message, wParam, lParam);
00498 }
00499
00500 /***************************************************************************\
00501 * About
00502 *
00503 * About dialog proc.
00504 *
00505 * History:
00506 * 09-09-91      Petrus Wong Rewrote.
00507 * 04-13-91 ????      Created.
00508 \***************************************************************************/
00509
00510 BOOL CALLBACK About (
00511     HWND hDlg,
00512     UINT message,
00513     DWORD wParam,
00514     LONG lParam)
00515 {
00516     switch (message) {
00517     case WM_INITDIALOG:
00518   return TRUE;
00519
00520     case WM_COMMAND:
00521   if (wParam == IDOK)
00522       EndDialog(hDlg, wParam);
00523   break;
00524     }
00525
00526     return FALSE;
00527
00528     UNREFERENCED_PARAMETER(lParam);
00529     UNREFERENCED_PARAMETER(hDlg);
00530 }
00531
00532 /***************************************************************************\
00533 *
00534 * TextWndProc
00535 *
00536 * Text Window procedure for displaying miscellaneous messages to user.
00537 *
00538 * History:
00539 * 10-07-91
00540 *   3D text output
00541 *
00542 \***************************************************************************/
00543
00544 LONG APIENTRY TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
00545 {
00546     static HFONT hFont = (HFONT) NULL;
00547
00548     switch (message)
00549     {
00550     case WM_CREATE:
00551   {
00552       LOGFONT    lf;
00553       HDC        hDC;
00554       HFONT      hOldFont;
00555       TEXTMETRIC tm;
00556       RECT       rect;
00557       LONG       lHeight;
00558
00559       SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);
00560
00561       hDC = GetDC(hwnd);
00562       // this is the height for 8 point size font in pixels
00563       lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
00564
00565       hFont = CreateFontIndirect(&lf);
00566       hOldFont = SelectObject(hDC, hFont);
00567       GetTextMetrics(hDC, &tm);
00568       GetClientRect(GetParent(hwnd), &rect);
00569
00570       // base the height of the window on size of text
00571       lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
00572       // saved the height for later reference
00573       SetWindowLong(hwnd, GWL_USERDATA, lHeight);
00574       SetWindowPos(hwnd, NULL,
00575         0,
00576         rect.bottom-lHeight,
00577         rect.right-rect.left,
00578         lHeight,
00579         SWP_NOZORDER | SWP_NOMOVE);
00580
00581       ReleaseDC(hwnd, hDC);
00582       break;
00583   }
00584
00585     case WM_DESTROY:
00586       if (hFont)
00587     DeleteObject(hFont);
00588       break;
00589
00590     case WM_SETTEXT:
00591       DefWindowProc(hwnd, message, wParam, lParam);
00592       InvalidateRect(hwnd,NULL,FALSE);
00593       UpdateWindow(hwnd);
00594       return 0L;
00595
00596     case WM_PAINT:
00597   {
00598       PAINTSTRUCT ps;
00599       RECT   rc;
00600       char   ach[128];
00601       int    len, nxBorder, nyBorder;
00602       HFONT  hOldFont = NULL;
00603
00604       BeginPaint(hwnd, &ps);
00605
00606       GetClientRect(hwnd,&rc);
00607
00608       nxBorder = GetSystemMetrics(SM_CXBORDER);
00609       rc.left  += 9*nxBorder;
00610       rc.right -= 9*nxBorder;
00611
00612       nyBorder = GetSystemMetrics(SM_CYBORDER);
00613       rc.top    += 3*nyBorder;
00614       rc.bottom -= 3*nyBorder;
00615
00616       // 3D Text
00617       len = GetWindowText(hwnd, ach, sizeof(ach));
00618       SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));
00619
00620       SetBkMode(ps.hdc, TRANSPARENT);
00621       SetTextColor(ps.hdc, RGB(64,96,96));
00622       if (hFont)
00623     hOldFont = SelectObject(ps.hdc, hFont);
00624       ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
00625       &rc, ach, len, NULL);
00626
00627       SetTextColor(ps.hdc, RGB(128,128,128));
00628       if (hFont)
00629     hOldFont = SelectObject(ps.hdc, hFont);
00630       ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
00631       &rc, ach, len, NULL);
00632
00633       SetTextColor(ps.hdc, RGB(255,255,255));
00634       if (hFont)
00635     hOldFont = SelectObject(ps.hdc, hFont);
00636       ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
00637       &rc, ach, len, NULL);
00638
00639       SetBkMode(ps.hdc, OPAQUE);
00640
00641       if (hOldFont)
00642     SelectObject(ps.hdc, hOldFont);
00643
00644       EndPaint(hwnd, &ps);
00645       return 0L;
00646   }
00647     }
00648     return DefWindowProc(hwnd, message, wParam, lParam);
00649 }
00650
00651 VOID vTest(PINFO pInfo)
00652 {
00653     OutputDebugString("Inside vTest()\n");
00654
00655     UNREFERENCED_PARAMETER(pInfo);
00656 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/MYUT.H Source File

  • INTEROP

MYUT.H

Go to the documentation of this file.
00001
00002 #define MYPRINT 1
00003 #define GETHWND 2
00004
00005 #define WF_WINNT 0x4000
00006
00007 DWORD FAR PASCAL LoadLibraryEx32W( LPCSTR, DWORD, DWORD );
00008 BOOL FAR PASCAL FreeLibrary32W( DWORD );
00009 DWORD FAR PASCAL GetProcAddress32W( DWORD, LPCSTR );
00010 DWORD FAR PASCAL CallProc32W( DWORD, DWORD, DWORD, LPVOID, DWORD, DWORD );
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INHERIT/INHERIT.C Source File

  • INHERIT

INHERIT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /********************************************************************
00013 * This program is to demonstrate the use of anonymous pipes used as *
00014 * stdout and stderr replacements. One of two techniques can be      *
00015 * chose to do this: the SetStdHandle technique or the               *
00016 * STARTF_USESTDHANDLES technique. The SetStdHandle technique sets   *
00017 * the standard output handles to the pipe that we will read from,   *
00018 * which the child will inherit. The STARTF_USESTDHANDLES technique  *
00019 * passes the pipe handles to the child as standard handles via the  *
00020 * STARTUPINFO structure. The STARTF_USESTDHANDLES technique *must*  *
00021 * be used for "console-less" processes such as GUI applications or  *
00022 * detached processes.                                               *
00023 *                                                                   *
00024 * This program demonstrates the use of the following Win32 APIs:    *
00025 *   CreatePipe, CreateProcess.                                      *
00026 *                                                                   *
00027 * This program also uses the following Win32 APIs:                  *
00028 *   GetLastError, CreateFile, CloseHandle, CreateProcess, ReadFile, *
00029 *   WriteFile.                                                      *
00030 *                                                                   *
00031 *                                                                   *
00032 * Execution instructions:                                           *
00033 *                                                                   *
00034 *   inherit <trace file> <command to execute>                       *
00035 *   trace file is the name of the file where the stdout             *
00036 *     and stderr of command will be redirected                      *
00037 *                                                                   *
00038 *   command to execute can be either an external executable or an   *
00039 *     internal cmd.exe command.                                     *
00040 *                                                                   *
00041 *   Examples:                                                       *
00042 *                                                                   *
00043 *   inherit chkdsk.dat chkdsk d:                                    *
00044 *   inherit nmake.txt nmake /f foo.mak                              *
00045 *                                                                   *
00046 ********************************************************************/
00047
00048 #include <windows.h>
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052
00053 /* define USESTDHANDLES to use the new technique of passing the
00054 standard handles to the child process via the STARTUPINFO structure.
00055 This technique must be used for "console-less" parents such as GUI
00056 applications or detached applications. */
00057
00058 #define USESTDHANDLES
00059
00060 /* Standard error macro for reporting API errors */
00061 //#define PERR(bSuccess, api) {if (!(bSuccess)) printf("%s: Error %d from %s
00062 //    on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
00063
00064 void PERR(BOOL bSuccess, char * api);
00065
00066 int main(int argc, char *argv[])
00067 {
00068   char chReadBuffer[64];  /* pipe read buffer */
00069   BOOL bSuccess;  /* BOOL return code for APIs */
00070   int j;
00071   HANDLE hOutFile;  /* handle to log file */
00072   /* handles to the anonymous pipe */
00073   HANDLE hReadPipe, hWritePipe, hWritePipe2;
00074   char szArgs[256];  /* child process argument buffer */
00075   char *p;  /* temporary pointer into szArgs */
00076   DWORD cchReadBuffer;  /* number of bytes read or to be written */
00077   STARTUPINFO si;  /* for CreateProcess call */
00078   PROCESS_INFORMATION pi;  /* for CreateProcess call */
00079   SECURITY_ATTRIBUTES saPipe;  /* security for anonymous pipe */
00080   OSVERSIONINFO os; /* operating system specs */
00081
00082   os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // required assignment
00083
00084   // check if running on Windows NT, if not, display notice and terminate
00085   if ( GetVersionEx(&os) )
00086   {
00087       if( os.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS &&
00088           os.dwPlatformId != VER_PLATFORM_WIN32_NT  )
00089       {
00090            MessageBox( NULL,
00091            "This sample application can only run on Windows NT and Windows 95.\n"
00092            "This application will now terminate.",
00093            "Inherit",
00094            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00095
00096            return( 1 );
00097       }
00098   }
00099   else
00100   {
00101        MessageBox( NULL,
00102        "Unable to test for OS version.",
00103        "Inherit Error",
00104        MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00105
00106        return( 1 );
00107   }
00108
00109   if (argc < 3)
00110     {
00111     puts("format: inherit <trace file> <command to execute>");
00112     puts("trace file is the name of the file where the stdout");
00113     puts("and stderr of command will be redirected\n");
00114     puts("command to execute is command line of the function");
00115     puts("you wish to perform.\n");
00116     puts("Examples:\n");
00117     puts("  inherit trace.txt chkdsk d:");
00118     puts("  inherit trace.txt nmake /f foo.mak");
00119     return(1);
00120     }
00121
00122   /* create the log file where we will save all output from child */
00123   hOutFile = CreateFile(argv[1],  /* file to open */
00124       GENERIC_WRITE,  /* access mode */
00125       FILE_SHARE_READ,  /* share mode */
00126       NULL,  /* security attributes */
00127       CREATE_ALWAYS,  /* creation flags - trash existing file */
00128       FILE_ATTRIBUTE_NORMAL,  /* file attributes */
00129       NULL);
00130   PERR(hOutFile != INVALID_HANDLE_VALUE, "CreateFile");
00131
00132   /* set up the security attributes for the anonymous pipe */
00133   saPipe.nLength = sizeof(SECURITY_ATTRIBUTES);
00134   saPipe.lpSecurityDescriptor = NULL;
00135   /* In order for the child to be able to write to the pipe, the handle */
00136   /* must be marked as inheritable by setting this flag: */
00137   saPipe.bInheritHandle = TRUE;
00138
00139   /* create the anonymous pipe */
00140   bSuccess = CreatePipe(&hReadPipe,  /* read handle */
00141       &hWritePipe,  /* write handle, used as stdout by child */
00142       &saPipe,  /* security descriptor */
00143       0);  /* pipe buffer size */
00144   PERR(bSuccess, "CreatePipe");
00145
00146   /* Now we need to change the inheritable property for the readable
00147   end of the pipe so that the child will not inherit that handle as
00148   a "garbage" handle. This will keep us from having extra,
00149   unclosable handles to the pipe. Alternatively, we could have
00150   opened the pipe with saPipe.bInheritHandle = FALSE and changed the
00151   inherit property on the *write* handle of the pipe to TRUE. */
00152
00153   bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
00154       hReadPipe, /* handle to duplicate */
00155       GetCurrentProcess(), /* destination process */
00156       NULL, /* new handle - don't want one, change original handle */
00157       0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
00158       FALSE, /* make it *not* inheritable */
00159       DUPLICATE_SAME_ACCESS);
00160   PERR(bSuccess, "DuplicateHandle");
00161
00162   /* I most cases you can get away with using the same anonymous
00163   pipe write handle for both the child's standard output and
00164   standard error, but this may cause problems if the child app
00165   explicitly closes one of its standard output or error handles. If
00166   that happens, the anonymous pipe will close, since the child's
00167   standard output and error handles are really the same handle. The
00168   child won't be able to write to the other write handle since the
00169   pipe is now gone, and parent reads from the pipe will return
00170   ERROR_BROKEN_PIPE and child output will be lost. To solve this
00171   problem, simply duplicate the write end of the pipe to create
00172   another distinct, separate handle to the write end of the pipe.
00173   One pipe write handle will serve as standard out, the other as
00174   standard error. Now *both* write handles must be closed before the
00175   write end of the pipe actually closes. */
00176
00177   bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
00178       hWritePipe, /* handle to duplicate */
00179       GetCurrentProcess(), /* destination process */
00180       &hWritePipe2, /* new handle, used as stderr by child */
00181       0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
00182       TRUE, /* it's inheritable */
00183       DUPLICATE_SAME_ACCESS);
00184   PERR(bSuccess, "DuplicateHandle");
00185
00186   /* Set up the STARTUPINFO structure for the CreateProcess() call */
00187   memset(&si, 0, sizeof(si));
00188   si.cb = sizeof(si);
00189
00190   /* Set up the command-line buffer for the child for CreateProcess() */
00191   memset(szArgs, 0, sizeof(szArgs));
00192   strcpy(szArgs, argv[2]);
00193   if (strchr(szArgs, '.') == NULL)  /* does it have a '.'? */
00194     strcat(szArgs, ".exe");  /* if not, assume it's an .exe */
00195   strcat(szArgs, " ");
00196   p = strchr(szArgs, 0);  /* point to the terminating null */
00197   for (j = 3; j < argc; j++)
00198     {
00199     strcat(p, argv[j]);
00200     /* the program and parameters are delimited by spaces */
00201     strcat(p, " ");
00202     }
00203
00204 #ifdef USESTDHANDLES
00205   /* If using the STARTUPINFO STARTF_USESTDHANDLES flag, be sure to
00206   set the CreateProcess fInheritHandles parameter too TRUE so that
00207   the file handles specified in the STARTUPINFO structure will be
00208   inheritied by the child. Note that we don't specify a standard
00209   input handle; the child will not inherit a valid input handle, so
00210   if it reads from stdin, it will encounter errors. */
00211
00212   si.hStdInput = hWritePipe2; /* hStdInput needs a valid handle in case it is checked by the child */
00213   si.hStdOutput = hWritePipe; /* write end of the pipe */
00214   si.hStdError = hWritePipe2; /* duplicate of write end of the pipe */
00215   si.dwFlags = STARTF_USESTDHANDLES;
00216 #else
00217   /* If we're not using the STARTF_USESTDHANDLES flag, set the
00218   standard output and error handles to the end of the pipe we want
00219   the child to inherit with SetStdHandle(). For this program, we
00220   don't want standard input inherited so we'll also change the
00221   handle inheritance property of standard input so that it is not
00222   inherited */
00223   bSuccess = SetStdHandle(STD_INPUT_HANDLE, hWritePipe2);
00224   PERR(bSuccess, "SetStdHandle");
00225   bSuccess = SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe);
00226   PERR(bSuccess, "SetStdHandle");
00227   bSuccess = SetStdHandle(STD_ERROR_HANDLE, hWritePipe2);
00228   PERR(bSuccess, "SetStdHandle");
00229   bSuccess = DuplicateHandle(GetCurrentProcess(), /* source process */
00230       GetStdHandle(STD_INPUT_HANDLE), /* handle to duplicate */
00231       GetCurrentProcess(), /* destination process */
00232       NULL, /* new handle - don't want one, change original handle */
00233       0, /* new access flags - ignored since DUPLICATE_SAME_ACCESS */
00234       FALSE, /* it's *not* inheritable */
00235       DUPLICATE_SAME_ACCESS);
00236   PERR(bSuccess, "DuplicateHandle");
00237 #endif
00238
00239   /* Now create the child process, inheriting handles */
00240
00241   bSuccess = CreateProcess(NULL,  /* filename */
00242       szArgs,  /* full command line for child */
00243       NULL,  /* process security descriptor */
00244       NULL,  /* thread security descriptor */
00245       TRUE,  /* inherit handles? Also use if STARTF_USESTDHANDLES */
00246       0,  /* creation flags */
00247       NULL,  /* inherited environment address */
00248       NULL,  /* startup dir; NULL = start in current */
00249       &si,  /* pointer to startup info (input) */
00250       &pi);  /* pointer to process info (output) */
00251   PERR(bSuccess, "CreateProcess");
00252
00253   /* We can close the returned child process handle and thread
00254   handle as we won't be needing them; you could, however, wait on
00255   the process handle to wait until the child process terminates. */
00256
00257   CloseHandle(pi.hThread);
00258   CloseHandle(pi.hProcess);
00259
00260   /* We need to close our instances of the inheritable pipe write
00261   handle now that it's been inherited so that all open handles to
00262   the pipe are closed when the child process ends and closes its
00263   handles to the pipe. */
00264
00265   bSuccess = CloseHandle(hWritePipe);
00266   PERR(bSuccess, "CloseHandle");
00267   bSuccess = CloseHandle(hWritePipe2);
00268   PERR(bSuccess, "CloseHandle");
00269
00270   /* read from the pipe until we get an ERROR_BROKEN_PIPE */
00271   for (;;)
00272     {
00273     bSuccess = ReadFile(hReadPipe,  /* read handle */
00274         chReadBuffer,  /* buffer for incoming data */
00275         sizeof(chReadBuffer),  /* number of bytes to read */
00276         &cchReadBuffer,  /* number of bytes actually read */
00277         NULL);  /* no overlapped reading */
00278     if (!bSuccess && (GetLastError() == ERROR_BROKEN_PIPE))
00279         break;  /* child has died */
00280
00281     PERR(bSuccess, "ReadFile");
00282     if (bSuccess && cchReadBuffer)
00283       {
00284       /* write the data from the child to the file */
00285       bSuccess = WriteFile(hOutFile,  /* write handle */
00286           chReadBuffer,  /* buffer to write */
00287           cchReadBuffer,  /* number of bytes to write */
00288           &cchReadBuffer,  /* number of bytes actually written */
00289           NULL);  /* no overlapped writing */
00290       PERR(bSuccess, "WriteFile");
00291
00292       /* write buffer (of specified length) to console */
00293       printf("%.*s", cchReadBuffer, chReadBuffer);
00294       }
00295     }
00296   /* close the trace file, pipe handles */
00297   CloseHandle(hOutFile);
00298   CloseHandle(hReadPipe);
00299   return(0);
00300 }
00301
00302 void PERR(BOOL bSuccess, char * api)
00303 {
00304     DWORD       dwError;
00305     TCHAR       szMsgBuf[500];
00306
00307     if (!(bSuccess))
00308     {
00309         dwError = GetLastError();
00310         printf("\nFile:%s\nError occured in %s on line %d\n", __FILE__, api, __LINE__);
00311
00312       FormatMessage(
00313           FORMAT_MESSAGE_FROM_SYSTEM,
00314           NULL,                               // ignored
00315           dwError,                     // message id
00316           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),   // message language
00317           szMsgBuf,                   // address of buffer pointer
00318           500,                                  // minimum buffer size
00319           NULL );                              // no other arguments
00320
00321         printf("\nError:(%ld)%s ", dwError, szMsgBuf);
00322      }
00323 }
00324
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/RESOURCE.H Source File

  • GLTHREAD

RESOURCE.H

Go to the documentation of this file.
00001 //{{NO_DEPENDENCIES}}
00002 // Microsoft Visual C++ generated include file.
00003 // Used by GLTHREAD.RC
00004 //
00005 #define IDM_EXIT                        40001
00006 #define ID_DRAWWAVES                    40004
00007
00008 // Next default values for new objects
00009 //
00010 #ifdef APSTUDIO_INVOKED
00011 #ifndef APSTUDIO_READONLY_SYMBOLS
00012 #define _APS_NEXT_RESOURCE_VALUE        101
00013 #define _APS_NEXT_COMMAND_VALUE         40005
00014 #define _APS_NEXT_CONTROL_VALUE         1000
00015 #define _APS_NEXT_SYMED_VALUE           101
00016 #endif
00017 #endif
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WALK/WALK.C Source File

  • WALK

WALK.C

Go to the documentation of this file.
00001
00002 /*****************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \*****************************************************************************/
00011
00012 /****************************************************************************
00013 *
00014 *    PROGRAM: WALK.C
00015 *
00016 *    PURPOSE: Uses recursion to walk through all subdirectories in the
00017 *             desired directory
00018 *
00019 *    FUNCTIONS:
00020 *
00021 *       FindFirstDirectory() - finds the first directory in the current
00022 *                 working directory
00023 *       Walk() - finds the subdirectories in the current working directory,
00024 *                 changes the current working directory to this subdirectory,
00025 *                 recusively calls itself until there are no more
00026 *                 subdirectories
00027 *
00028 *    COMMENTS:
00029 *
00030 *       This program does not report all subdirectories like a
00031 *       directory listing would yield.  The reason for this is
00032 *       because some subdirectories may be secured.  If so, they
00033 *       are ignored by this program.  The concept of this 'walk' is
00034 *       that items actually stepped into are reported.
00035 *
00036 ****************************************************************************/
00037
00038 #include <windows.h>
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <process.h>
00042 #include "walk.h"
00043
00044 /****************************************************************************
00045 *
00046 *    FUNCTION: FindFirstDirectory(LPTSTR, LPWIN32_FIND_DATA)
00047 *
00048 *    PURPOSE: finds the first directory in the current working directory
00049 *
00050 *    COMMENTS:
00051 *
00052 *       This function is called by Walk() each time a new subdirectory is
00053 *       entered.  Since only directory entries are of interest, this call
00054 *       provides a simple means to bypass non-directory filenames.
00055 *
00056 *    INPUT: lpszSearchFile -> "*"
00057 *           lpffd - pointer to the file find data structure of type
00058 *                   WIN32_FIND_DATA
00059 *
00060 *    OUTPUT: Returns a file handle if a directory is found
00061 *            Returns INVALID_HANDLE_VALUE if no directory is found
00062 *
00063 ****************************************************************************/
00064
00065 HANDLE FindFirstDirectory(LPTSTR lpszSearchFile, LPWIN32_FIND_DATA lpffd)
00066 {
00067     BOOL     fContinue;
00068     HANDLE   hSearch;
00069     DWORD    dwAtt;     // file attributes
00070     int      iDiff;     // string comparison result
00071
00072     hSearch = FindFirstFile(lpszSearchFile, lpffd);
00073     if (hSearch == INVALID_HANDLE_VALUE)
00074         return hSearch;
00075
00076     for(;;)
00077     {
00078         dwAtt = GetFileAttributes(lpffd->cFileName);
00079         if (dwAtt != 0xFFFFFFFF)
00080         {
00081             if (dwAtt & FILE_ATTRIBUTE_DIRECTORY)
00082             {
00083                 iDiff = strcmp(lpffd->cFileName, ".");
00084                 if (iDiff)
00085                 {
00086                     iDiff = strcmp(lpffd->cFileName, "..");
00087                     if (iDiff)
00088                         return hSearch;
00089                 }
00090             }
00091         }
00092
00093         fContinue = FindNextFile(hSearch, lpffd);
00094         if (fContinue == FALSE)
00095         {
00096             FindClose(hSearch);
00097             return INVALID_HANDLE_VALUE;
00098         }
00099     }
00100 }
00101
00102 /****************************************************************************
00103 *
00104 *    FUNCTION: FindNextDirectory(LPTSTR, LPWIN32_FIND_DATA)
00105 *
00106 *    PURPOSE: finds the next directory in the current working directory
00107 *
00108 *    COMMENTS:
00109 *
00110 *       This function is called by Walk() each time a new subdirectory is
00111 *       entered.  Since only directory entries are of interest, this call
00112 *       provides a simple means to bypass non-directory filenames.
00113 *
00114 *    INPUT: lpszSearchFile -> "*"
00115 *           lpffd - pointer to the file find data structure of type
00116 *                   WIN32_FIND_DATA
00117 *
00118 *    OUTPUT: Returns a file handle if a directory is found
00119 *            Returns a -1 if no directory is found
00120 *
00121 ****************************************************************************/
00122
00123 BOOL FindNextDirectory(HANDLE hSearch, LPWIN32_FIND_DATA lpffd)
00124 {
00125     BOOL     bContinue;
00126     DWORD    dwAtt;
00127
00128     for(;;)
00129     {
00130         bContinue = FindNextFile(hSearch, lpffd);
00131         if (bContinue == FALSE)
00132             return FALSE;
00133
00134         dwAtt = GetFileAttributes(lpffd->cFileName);
00135
00136         // If an error occurs while getting the file attributes, it is
00137         //   ignored, then the next file is tried.
00138         //   GetLastError could be called to determine the cause of the error.
00139         //   More than likely an invalid filename, or entry is secured.
00140         if (dwAtt == 0xFFFFFFFF)
00141             continue;
00142
00143         if (dwAtt & FILE_ATTRIBUTE_DIRECTORY)
00144             return TRUE;
00145     }
00146 }
00147
00148 /****************************************************************************
00149 *
00150 *    FUNCTION: Walk(WORD)
00151 *
00152 *    PURPOSE: finds a subdirectory in the current working directory,
00153 *             changes the current working directory to this subdirectory,
00154 *             and recusively calls itself until there are no more
00155 *             subdirectories
00156 *
00157 *    COMMENTS:When a new directory is entered from above, a handle for
00158 *             the new directory is obtained using FindFirstDirectory.  Once
00159 *             the first directory is found, the current working directory
00160 *             is changed to this first directory and Walk() is recursively
00161 *             called again.  At this point, the next available directory
00162 *             is searched for using FindNextFile, entered and a recursive
00163 *             call is made to Walk().  When each directory has been searched,
00164 *             until no more directories exist, the current working directory
00165 *             is changed to the parent directory (..).  This continues until
00166 *             the current working directory is equal to the original
00167 *             directory.
00168 *
00169 *    INPUT: wLevel - bookmark, when wLevel is greater than 0, then the
00170 *             current working directory is a subdirectory of the original
00171 *             directory.  If wLevel is equal to 0, then the directory is the
00172 *             original directory and the recursive calls stop
00173 *
00174 *    OUTPUT:
00175 *
00176 ****************************************************************************/
00177
00178 VOID Walk(WORD wLevel)
00179 {
00180     BOOL              bContinue = TRUE;
00181     DWORD             dwSize;
00182     HANDLE            hSearch;
00183     WIN32_FIND_DATA   w32FindBuf;
00184
00185     dwSize = GetCurrentDirectory(BUFSIZE, chPathName);
00186     if (dwSize == 0)
00187     {
00188         printf("Error getting current directory name.  Exiting...\n");
00189         exit(1);
00190     }
00191
00192     if (dwSize >= (BUFSIZE-1))
00193     {
00194         printf("\nDirectory name too large.  Skipping over...\n");
00195         return;
00196     }
00197
00198     printf("%s\n", chPathName);
00199
00200     hSearch = FindFirstDirectory("*", &w32FindBuf);
00201     if (hSearch == INVALID_HANDLE_VALUE)
00202     {
00203         if (wLevel)
00204             SetCurrentDirectory("..");
00205         return;
00206     }
00207
00208     for (;;)
00209     {
00210         if (SetCurrentDirectory(w32FindBuf.cFileName))
00211             Walk(++wLevel);
00212         else
00213             printf("\nSkipping subdirectory: %s\n", w32FindBuf.cFileName);
00214
00215         bContinue = FindNextDirectory(hSearch, &w32FindBuf);
00216         if (bContinue == FALSE)
00217         {
00218             SetCurrentDirectory("..");
00219             FindClose(hSearch);
00220             return;
00221         }
00222     }
00223 }
00224
00225 VOID main(int argc, char * argv[])
00226 {
00227     // check if Win32s, if so, display notice and terminate
00228     if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) == 3)
00229     {
00230         MessageBox( NULL,
00231             "This application cannot run on Windows 3.1.\n"
00232             "This application will now terminate.",
00233             "Walk",
00234             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00235         return;
00236     }
00237
00238     // if a directory is supplied on the command line
00239     //  start there
00240     if (argc == 2)
00241     {
00242         if (!SetCurrentDirectory(argv[1]))
00243         {
00244             printf("Can't walk '%s'\n", argv[1]);
00245             return;
00246         }
00247     }
00248
00249     Walk(0);
00250
00251     return;
00252 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CURSOR/CURSOR.C Source File

  • CURSOR

CURSOR.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************
00013
00014     PROGRAM: Cursor.c
00015
00016     PURPOSE: Demonstrates how to manipulate a cursor and select a region
00017
00018     FUNCTIONS:
00019
00020         WinMain() - calls initialization function, processes message loop
00021         InitApplication() - initializes window data and registers window
00022         InitInstance() - saves instance handle and creates main window
00023         MainWndProc() - processes messages
00024         About() - processes messages for "About" dialog box
00025         sieve() - time consuming function, generates primes
00026
00027 ****************************************************************************/
00028
00029 #include <windows.h>
00030 #include <string.h>
00031 #include "cursor.h"
00032
00033 HANDLE hInst;
00034
00035 CHAR str[255];                              /* general-purpose string buffer */
00036
00037 HCURSOR hSaveCursor;                        /* handle to current cursor      */
00038 HCURSOR hHourGlass;                         /* handle to hourglass cursor    */
00039
00040 BOOL bTrack = FALSE;                        /* TRUE if left button clicked   */
00041 INT OrgX = 0, OrgY = 0;                     /* original cursor position      */
00042 INT PrevX = 0, PrevY = 0;                   /* current cursor position       */
00043 INT X = 0, Y = 0;                           /* last cursor position          */
00044 RECT Rect;                                  /* selection rectangle           */
00045
00046 MPOINT ptCursor;                            /* x and y coordinates of cursor */
00047 INT repeat = 1;                             /* repeat count of keystroke     */
00048
00049 /****************************************************************************
00050
00051     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00052
00053     PURPOSE: calls initialization function, processes message loop
00054
00055 ****************************************************************************/
00056
00057 int APIENTRY WinMain(
00058     HANDLE hInstance,
00059     HANDLE hPrevInstance,
00060     LPSTR lpCmdLine,
00061     int nCmdShow
00062     )
00063 {
00064     MSG msg;                                 /* message                      */
00065
00066     UNREFERENCED_PARAMETER( lpCmdLine );
00067
00068     if (!hPrevInstance)
00069         if (!InitApplication(hInstance))
00070             return (FALSE);
00071
00072     if (!InitInstance(hInstance, nCmdShow))
00073         return (FALSE);
00074
00075     MessageBox (
00076           GetFocus ()
00077         , "Use the mouse button in this program for an example of graphics "
00078                         "selection, or the <Enter> key for an example of "
00079                         "using a special cursor to reflect a program state."
00080         , "Cursor Sample Application"
00081         , MB_ICONASTERISK | MB_OK
00082     );
00083
00084     while (GetMessage(&msg, NULL, 0, 0)) {
00085         TranslateMessage(&msg);
00086         DispatchMessage(&msg);
00087     }
00088     return (msg.wParam);
00089 }
00090
00091
00092 /****************************************************************************
00093
00094     FUNCTION: InitApplication(HANDLE)
00095
00096     PURPOSE: Initializes window data and registers window class
00097
00098 ****************************************************************************/
00099
00100 BOOL InitApplication(HANDLE hInstance)
00101 {
00102     WNDCLASS  wc;
00103
00104     wc.style = 0;
00105     wc.lpfnWndProc = (WNDPROC) MainWndProc;
00106     wc.cbClsExtra = 0;
00107     wc.cbWndExtra = 0;
00108     wc.hInstance = hInstance;
00109     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00110     wc.hCursor = LoadCursor(hInstance, "bullseye");
00111     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00112     wc.lpszMenuName =  "CursorMenu";
00113     wc.lpszClassName = "CursorWClass";
00114
00115     return (RegisterClass(&wc));
00116 }
00117
00118
00119 /****************************************************************************
00120
00121     FUNCTION:  InitInstance(HANDLE, int)
00122
00123     PURPOSE:  Saves instance handle and creates main window
00124
00125 ****************************************************************************/
00126
00127 BOOL InitInstance(
00128     HANDLE          hInstance,
00129     INT             nCmdShow)
00130 {
00131     HWND            hWnd;
00132
00133     hInst = hInstance;
00134
00135     strcpy(str,"");
00136
00137     hHourGlass = LoadCursor(NULL, IDC_WAIT);
00138
00139     hWnd = CreateWindow(
00140         "CursorWClass",
00141         "Cursor Sample Application",
00142         WS_OVERLAPPEDWINDOW,
00143         CW_USEDEFAULT,
00144         CW_USEDEFAULT,
00145         CW_USEDEFAULT,
00146         CW_USEDEFAULT,
00147         NULL,
00148         NULL,
00149         hInstance,
00150         NULL
00151     );
00152
00153     if (!hWnd)
00154         return (FALSE);
00155
00156     ShowWindow(hWnd, nCmdShow);
00157     UpdateWindow(hWnd);
00158     return (TRUE);
00159
00160 }
00161
00162 /****************************************************************************
00163
00164     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
00165
00166     PURPOSE:  Processes messages
00167
00168     MESSAGES:
00169
00170         WM_COMMAND     - application menu (About dialog box)
00171         WM_CHAR        - ASCII key value received
00172         WM_LBUTTONDOWN - left mouse button
00173         WM_MOUSEMOVE   - mouse movement
00174         WM_LBUTTONUP   - left button released
00175         WM_KEYDOWN     - key pressed
00176         WM_KEYUPS      - key released
00177         WM_PAINT       - update window
00178         WM_DESTROY     - destroy window
00179
00180     COMMENTS:
00181
00182         When the left mouse button is pressed, btrack is set to TRUE so that
00183         the code for WM_MOUSEMOVE will keep track of the mouse and update
00184         the box accordingly.  Once the button is released, btrack is set to
00185         FALSE, and the current position is saved.  Holding the SHIFT key
00186         while pressing the left button will extend the current box rather
00187         then erasing it and starting a new one.
00188
00189         When an arrow key is pressed, the cursor is repositioned in the
00190         direction of the arrow key.  A repeat count is kept so that the
00191         longer the user holds down the arrow key, the faster it will move.
00192         As soon as the key is released, the repeat count is set to 1 for
00193         normal cursor movement.
00194
00195 ****************************************************************************/
00196
00197 LONG APIENTRY MainWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam)
00198 {
00199     FARPROC lpProcAbout;
00200     POINT pt;
00201     HDC hDC;
00202
00203     switch (message) {
00204         case WM_COMMAND:
00205             // LOWORD added for portability
00206             if (LOWORD(wParam) == IDM_ABOUT) {
00207                 lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
00208
00209                 DialogBox(hInst,
00210                     "AboutBox",
00211                     hWnd,
00212                     lpProcAbout);
00213
00214                 FreeProcInstance(lpProcAbout);
00215                 break;
00216             }
00217             else
00218                 return (DefWindowProc(hWnd, message, wParam, lParam));
00219
00220         case WM_CHAR:
00221             if (wParam == '\r') {
00222                 SetCapture(hWnd);
00223
00224                 /* Set the cursor to an hourglass */
00225
00226                 hSaveCursor = SetCursor(hHourGlass);
00227
00228                 strcpy (str, "Calculating prime numbers...");
00229                 InvalidateRect (hWnd, NULL, TRUE);
00230                 UpdateWindow (hWnd);
00231                 wsprintf(str, "Calculated %d primes.       ", sieve());
00232                 InvalidateRect (hWnd, NULL, TRUE);
00233                 UpdateWindow (hWnd);
00234
00235                 SetCursor(hSaveCursor);          /* Restores previous cursor */
00236                 ReleaseCapture();
00237             }
00238             break;
00239
00240         case WM_LBUTTONDOWN:
00241             bTrack = TRUE;
00242             strcpy (str, "");
00243             PrevX = LOWORD(lParam);
00244             PrevY = HIWORD(lParam);
00245             if (!(wParam & MK_SHIFT)) {       /* If shift key is not pressed */
00246                 OrgX = LOWORD(lParam);
00247                 OrgY = HIWORD(lParam);
00248             }
00249             InvalidateRect (hWnd, NULL, TRUE);
00250             UpdateWindow (hWnd);
00251
00252             /* Capture all input even if the mouse goes outside of window */
00253
00254             SetCapture(hWnd);
00255             break;
00256
00257         case WM_MOUSEMOVE:
00258             {
00259                 RECT        rectClient;
00260                 INT         NextX;
00261                 INT         NextY;
00262
00263                 if (bTrack) {
00264                     NextX = (SHORT)LOWORD(lParam);
00265                     NextY = (SHORT)HIWORD(lParam);
00266
00267                     /* Do not draw outside the window's client area */
00268
00269                     GetClientRect (hWnd, &rectClient);
00270                     if (NextX < rectClient.left) {
00271                         NextX = rectClient.left;
00272                     } else if (NextX >= rectClient.right) {
00273                         NextX = rectClient.right - 1;
00274                     }
00275                     if (NextY < rectClient.top) {
00276                         NextY = rectClient.top;
00277                     } else if (NextY >= rectClient.bottom) {
00278                         NextY = rectClient.bottom - 1;
00279                     }
00280
00281                     /* If the mouse position has changed, then clear the */
00282                     /* previous rectangle and draw the new one.          */
00283
00284                     if ((NextX != PrevX) || (NextY != PrevY)) {
00285                         hDC = GetDC(hWnd);
00286                         SetROP2(hDC, R2_NOT);          /* Erases the previous box */
00287                         MoveToEx(hDC, OrgX, OrgY, NULL);
00288                         LineTo(hDC, OrgX, PrevY);
00289                         LineTo(hDC, PrevX, PrevY);
00290                         LineTo(hDC, PrevX, OrgY);
00291                         LineTo(hDC, OrgX, OrgY);
00292
00293                         /* Get the current mouse position */
00294
00295                         PrevX = NextX;
00296                         PrevY = NextY;
00297                         MoveToEx(hDC, OrgX, OrgY, NULL); /* Draws the new box */
00298                         LineTo(hDC, OrgX, PrevY);
00299                         LineTo(hDC, PrevX, PrevY);
00300                         LineTo(hDC, PrevX, OrgY);
00301                         LineTo(hDC, OrgX, OrgY);
00302                         ReleaseDC(hWnd, hDC);
00303                     }
00304                 }
00305             }
00306             break;
00307
00308         case WM_LBUTTONUP:
00309             bTrack = FALSE;                 /* No longer creating a selection */
00310             ReleaseCapture();               /* Releases hold on mouse input */
00311
00312             X = LOWORD(lParam);             /* Saves the current value      */
00313             Y = HIWORD(lParam);
00314             break;
00315
00316         case WM_KEYDOWN:
00317             if (wParam != VK_LEFT && wParam != VK_RIGHT
00318                     && wParam != VK_UP && wParam != VK_DOWN)
00319                 break;
00320
00321             MPOINT2POINT(ptCursor, pt);
00322             GetCursorPos(&pt);
00323
00324             /* Convert screen coordinates to client coordinates */
00325
00326             ScreenToClient(hWnd, &pt);
00327             POINT2MPOINT(pt, ptCursor);
00328             repeat++;                           /* Increases the repeat rate */
00329
00330             switch (wParam) {
00331
00332             /* Adjust cursor position according to which key was pressed. */
00333
00334                 case VK_LEFT:
00335                     ptCursor.x -= repeat;
00336                     break;
00337
00338                 case VK_RIGHT:
00339                     ptCursor.x += repeat;
00340                     break;
00341
00342                 case VK_UP:
00343                     ptCursor.y -= repeat;
00344                     break;
00345
00346                 case VK_DOWN:
00347                     ptCursor.y += repeat;
00348                     break;
00349
00350             }
00351
00352             /* Get the client boundaries */
00353
00354             GetClientRect(hWnd, &Rect);
00355
00356             /* Do not draw outside the window's client area */
00357
00358             MPOINT2POINT(ptCursor, pt);
00359             if (pt.x >= Rect.right)
00360                 pt.x = Rect.right - 1;
00361             else if (pt.x < Rect.left)
00362                 pt.x = Rect.left;
00363             if (pt.y >= Rect.bottom)
00364                 pt.y = Rect.bottom - 1;
00365             else if (pt.y < Rect.top)
00366                 pt.y = Rect.top;
00367
00368             /* Convert the coordinates to screen coordinates */
00369
00370             ClientToScreen(hWnd, &pt);
00371             SetCursorPos(pt.x, pt.y);
00372             break;
00373
00374         case WM_KEYUP:
00375             repeat = 1;                          /* Clears the repeat count. */
00376             break;
00377
00378         case WM_ACTIVATE:
00379             if (!GetSystemMetrics(SM_MOUSEPRESENT)) {
00380                 if (!HIWORD(wParam)) {
00381                     // LOWORD added for portability
00382                     if (LOWORD(wParam)) {
00383                         SetCursor(LoadCursor(hInst, "bullseye"));
00384                         pt.x = X;
00385                         pt.y = Y;
00386                         ClientToScreen(hWnd, &pt);
00387                         SetCursorPos(pt.x, pt.y);
00388                     }
00389                     ShowCursor(wParam);
00390                 }
00391             }
00392             break;
00393
00394         case WM_PAINT:
00395             {
00396                 PAINTSTRUCT     ps;
00397
00398                 hDC = BeginPaint (hWnd, &ps);
00399                 if (OrgX != PrevX || OrgY != PrevY) {
00400                     MoveToEx(hDC, OrgX, OrgY, NULL);
00401                     LineTo(hDC, OrgX, PrevY);
00402                     LineTo(hDC, PrevX, PrevY);
00403                     LineTo(hDC, PrevX, OrgY);
00404                     LineTo(hDC, OrgX, OrgY);
00405                 }
00406                 TextOut (hDC, 1, 1, str, strlen (str));
00407                 EndPaint (hWnd, &ps);
00408             }
00409             break;
00410
00411         case WM_DESTROY:
00412             PostQuitMessage(0);
00413             break;
00414
00415         default:
00416             return (DefWindowProc(hWnd, message, wParam, lParam));
00417     }
00418     return (0);
00419 }
00420
00421
00422 /****************************************************************************
00423
00424     FUNCTION: About(HWND, unsigned, WORD, LONG)
00425
00426     PURPOSE:  Processes messages for "About" dialog box
00427
00428     MESSAGES:
00429
00430         WM_INITDIALOG - initialize dialog box
00431         WM_COMMAND    - Input received
00432
00433 ****************************************************************************/
00434
00435 BOOL APIENTRY About(HWND hDlg, UINT message, UINT wParam, LONG lParam)
00436 {
00437     switch (message) {
00438         case WM_INITDIALOG:
00439             return (TRUE);
00440
00441         case WM_COMMAND:
00442             // LOWORD added for portability
00443             if (LOWORD(wParam) == IDOK
00444                 || LOWORD(wParam) == IDCANCEL) {
00445                 EndDialog(hDlg, TRUE);
00446                 return (TRUE);
00447             }
00448             break;
00449     }
00450     return (FALSE);
00451         UNREFERENCED_PARAMETER(lParam);
00452 }
00453
00454
00455 /****************************************************************************
00456
00457     FUNCTION: Sieve()
00458
00459     PURPOSE:  Example of time consuming process
00460
00461     COMMENTS:
00462
00463         Sieve of Eratosthenes, BYTE, Volume 8, Number 1, by Jim Gilbreath
00464         and Gary Gilbreath.  Code changed to give correct results.
00465
00466         One could return the count, and after restoring the cursor, use
00467         sprintf() to copy the information to a string which could then be
00468         put up in a MessageBox().
00469
00470 ****************************************************************************/
00471
00472 #define NITER   20                                 /* number of iterations */
00473 #define SIZE    8190
00474
00475 CHAR flags[SIZE+1]={ 0};
00476
00477 INT sieve() {
00478     INT i,k;
00479     INT iter, count;
00480
00481     for (iter = 1; iter <= NITER; iter++) {      /* Does sieve NITER times */
00482         count = 0;
00483         for (i = 0; i <= SIZE; i++)              /* Sets all flags TRUE    */
00484             flags[i] = TRUE;
00485
00486         for (i = 2; i <= SIZE; i++) {
00487             if (flags[i] ) {                        /* Found a prime?       */
00488                 for (k = i + i; k <= SIZE; k += i)
00489                     flags[k] = FALSE;              /* Cancelsits multiples */
00490                 count++;
00491             }
00492         }
00493     }
00494     return (count);
00495 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDI.C Source File

  • MDI_

MDI.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************Module*Header*******************************\
00013 * Module Name: mdi.c
00014 *
00015 * MDI demonstration
00016 *   +   Associating data with a MDI window (using Set/GetWindowLong )
00017 *
00018 * Dependencies:
00019 *
00020 *   (#defines)
00021 *   (#includes)
00022 *       MDI.H
00023 *
00024 \**************************************************************************/
00025 #define STRICT
00026 #include <stdlib.h>
00027 #include "mdi.h"
00028 #include <stdarg.h>
00029
00030 HANDLE ghModule;
00031 HWND   ghwndMain   = NULL;
00032 HWND   ghwndClient = NULL;
00033
00034 HMENU  hMenu,      hMenuWindow;
00035 HMENU  hChildMenu, hChildMenuWindow;
00036
00037 CHAR   gszFile[20];
00038 CHAR   gszMapName[20];
00039
00040 //
00041 // Instance data for each MDI child window
00042 //
00043 typedef struct _PerWndInfo {
00044     HWND    hParent;
00045     HWND    hTextWnd;
00046     RECT    rcClient;
00047     char    CaptionBarText[SIZEOFCAPTIONTEXT];
00048 } INFO, *PINFO;
00049
00050 //
00051 // Forward declarations.
00052 //
00053 BOOL InitializeApp   (void);
00054 LRESULT CALLBACK MainWndProc     (HWND, UINT, WPARAM, LPARAM);
00055 LRESULT CALLBACK MDIWndProc      (HWND, UINT, WPARAM, LPARAM);
00056 BOOL CALLBACK About           (HWND, UINT, WPARAM, LPARAM);
00057 LONG APIENTRY TextWndProc     (HWND, UINT, DWORD, LONG);
00058 VOID vTest           (PINFO);
00059
00060 /***************************************************************************\
00061 * WinMain
00062 *
00063 *
00064 * History:
00065 * 11-Feb-1992   Petrus Wong []
00066 *   Added conditional compile statement for internal build environment.
00067 * 04-17-91      ????      Created.
00068 \***************************************************************************/
00069 int PASCAL WinMain(
00070     HINSTANCE hInstance,
00071     HINSTANCE hPrevInstance,
00072     LPSTR lpCmdLine,
00073     int nShowCmd)
00074 {
00075     MSG    msg;
00076     HANDLE hAccel;
00077
00078     ghModule = GetModuleHandle(NULL);
00079     if (!InitializeApp()) {
00080         MessageBox(ghwndMain, "MDI: InitializeApp failure!", "Error", MB_OK);
00081         return 0;
00082     }
00083
00084     if (!(hAccel = LoadAccelerators (ghModule, MAKEINTRESOURCE(ACCEL_ID))))
00085         MessageBox(ghwndMain, "MDI: Load Accel failure!", "Error", MB_OK);
00086
00087
00088     while (GetMessage(&msg, NULL, 0, 0)) {
00089         if (!TranslateAccelerator( ghwndMain, hAccel, &msg) &&
00090             !TranslateMDISysAccel(  ghwndClient, &msg)          ) {
00091             TranslateMessage(&msg);
00092             DispatchMessage(&msg);
00093         }
00094     }
00095
00096     return 1;
00097
00098     UNREFERENCED_PARAMETER(lpCmdLine);
00099     UNREFERENCED_PARAMETER(nShowCmd);
00100     UNREFERENCED_PARAMETER(hInstance);
00101     UNREFERENCED_PARAMETER(hPrevInstance);
00102 }
00103
00104
00105 /***************************************************************************\
00106 * InitializeApp
00107 *
00108 * History:
00109 * 11-Feb-1992   Petrus Wong []
00110 *   Name changes.
00111 * 09-09-91      Created.
00112 \***************************************************************************/
00113
00114 BOOL InitializeApp(void)
00115 {
00116     WNDCLASS wc;
00117
00118     wc.style            = CS_OWNDC;
00119     wc.lpfnWndProc      = (WNDPROC) MainWndProc;
00120     wc.cbClsExtra       = 0;
00121     wc.cbWndExtra       = sizeof(LONG);
00122     wc.hInstance        = ghModule;
00123     wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
00124     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
00125     wc.hbrBackground    = (HBRUSH)(COLOR_APPWORKSPACE);
00126     wc.lpszMenuName     = "MainMenu";
00127     wc.lpszClassName    = "MDIDemoClass";
00128
00129     if (!RegisterClass(&wc))
00130         return FALSE;
00131
00132     wc.lpfnWndProc      = (WNDPROC) MDIWndProc;
00133     wc.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
00134     wc.lpszMenuName     = NULL;
00135     wc.lpszClassName    = "MDIClass";
00136
00137     if (!RegisterClass(&wc))
00138         return FALSE;
00139
00140     wc.style            = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
00141     wc.lpfnWndProc      = (WNDPROC) TextWndProc;
00142     wc.hIcon            = NULL;
00143     wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
00144     wc.hbrBackground    = (HBRUSH)(COLOR_BTNSHADOW);
00145     wc.lpszMenuName     = NULL;
00146     wc.lpszClassName    = "Text";
00147
00148     if (!RegisterClass(&wc))
00149             return FALSE;
00150
00151
00152
00153     hMenu       = LoadMenu(ghModule, "MainMenu");
00154     hChildMenu  = LoadMenu(ghModule, "ChildMenu");
00155     hMenuWindow      = GetSubMenu(hMenu, 1);
00156     hChildMenuWindow = GetSubMenu(hChildMenu, 2);
00157
00158     ghwndMain = CreateWindowEx(0L, "MDIDemoClass", "MDI Demonstration",
00159             WS_OVERLAPPED   | WS_CAPTION     | WS_BORDER       |
00160             WS_THICKFRAME   | WS_MAXIMIZEBOX | WS_MINIMIZEBOX  |
00161             WS_CLIPCHILDREN | WS_VISIBLE     | WS_SYSMENU,
00162             80, 70, 400, 300,
00163             NULL, hMenu, ghModule, NULL);
00164
00165     if (ghwndMain == NULL)
00166         return FALSE;
00167
00168     SetWindowLong(ghwndMain, GWL_USERDATA, 0L);
00169
00170     SetFocus(ghwndMain);    /* set initial focus */
00171
00172     return TRUE;
00173 }
00174
00175
00176 /***************************************************************************\
00177 * MainWndProc
00178 *
00179 * History:
00180 * 11-Feb-1992   Petrus Wong []
00181 *   Name changes.  Added comments.
00182 * 09-09-91      Created.
00183 \***************************************************************************/
00184
00185 LRESULT CALLBACK MainWndProc(
00186     HWND hwnd,
00187     UINT message,
00188     WPARAM wParam,
00189     LPARAM lParam)
00190 {
00191     static int         iMDICount=1;
00192     CLIENTCREATESTRUCT clientcreate;
00193     HWND               hwndChildWindow;
00194
00195
00196     switch (message) {
00197
00198       case WM_CREATE:
00199         SetWindowLong(hwnd, 0, (LONG)NULL);
00200
00201         clientcreate.hWindowMenu  = hMenuWindow;
00202         clientcreate.idFirstChild = 1;
00203
00204         ghwndClient = CreateWindow("MDICLIENT", NULL,
00205                                     WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
00206                                     0,0,0,0,
00207                                     hwnd, NULL, ghModule, (LPVOID)&clientcreate);
00208         return 0L;
00209
00210       case WM_DESTROY: {
00211         PostQuitMessage(0);
00212         return 0L;
00213       }
00214
00215       case WM_COMMAND:
00216
00217         switch (LOWORD(wParam)) {
00218             //
00219             // Getting default MDI functionalities...
00220             //
00221             case IDM_TILE:
00222                 SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
00223                 return 0L;
00224             case IDM_CASCADE:
00225                 SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
00226                 return 0L;
00227             case IDM_ARRANGE:
00228                 SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
00229                 return 0L;
00230
00231             //
00232             // Creates MDI child
00233             //
00234             case MM_MDI: {
00235                 HANDLE hInfo;
00236                 PINFO  pInfo;
00237                 MDICREATESTRUCT mdicreate;
00238
00239                 //
00240                 // Allocating memory for INFO to be associated with the
00241                 //  new child
00242                 //
00243                 hInfo = LocalAlloc(LHND, (WORD) sizeof(INFO));
00244                 if (hInfo) {
00245                     if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00246                         MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00247
00248                     wsprintf((LPSTR) &(pInfo->CaptionBarText),
00249                              "MDI %d", iMDICount);
00250                     pInfo->hParent    = ghwndClient;
00251
00252                     mdicreate.szClass = "MDIClass";
00253                     mdicreate.szTitle = (LPTSTR)&(pInfo->CaptionBarText);
00254                     mdicreate.hOwner  = ghModule;
00255                     mdicreate.x       =
00256                     mdicreate.y       =
00257                     mdicreate.cx      =
00258                     mdicreate.cy      = CW_USEDEFAULT;
00259                     mdicreate.style   = 0L;
00260                     //
00261                     // passing the handle of the per MDI child INFO to the
00262                     //  child MDI window for storage
00263                     //
00264                     mdicreate.lParam  = (LONG) hInfo;
00265
00266                     /*Create Child Window*/
00267                     hwndChildWindow =
00268                         (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
00269                                     0L,
00270                                     (LONG)(LPMDICREATESTRUCT)&mdicreate);
00271
00272                     if (hwndChildWindow == NULL) {
00273                         MessageBox(ghwndMain, "Failed in Creating Child Window", "Error", MB_OK);
00274                         return 0L;
00275                     }
00276
00277                     iMDICount++;
00278
00279                     LocalUnlock(hInfo);
00280                 } else {
00281                             MessageBox(ghwndMain, "Failed to Allocate INFO data!", "Error", MB_OK);
00282                 }
00283                 return 0L;
00284             }
00285
00286
00287             case MM_ABOUT:
00288                 if (DialogBox(ghModule, "AboutBox", ghwndMain, (DLGPROC)About) == -1)
00289                         MessageBox(ghwndMain, "DEMO: About Dialog Creation Error!", "Error", MB_OK);
00290                 return 0L;
00291
00292             //
00293             // Passes these WM_COMMAND messages to the appropriate active child
00294             //  window proc for processing
00295             //
00296             case MM_OPT_1:
00297             case MM_OPT_2:
00298             case MM_OPT_3:
00299             case MM_OPT_4:
00300             case MM_OPT_5:
00301             case MM_OPT_6:
00302             case MM_OPT_7:
00303             case MM_OPT_8: {
00304                 HWND hActiveChild;
00305
00306                 hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L);
00307                 if (hActiveChild)
00308                     SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
00309                 return 0L;
00310             }
00311
00312             default:
00313                 return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
00314         }
00315
00316     default:
00317
00318         return DefFrameProc(hwnd,  ghwndClient, message, wParam, lParam);
00319     }
00320 }
00321
00322 /***************************************************************************\
00323 * MDIWndProc
00324 *
00325 * History:
00326 * 11-Feb-1992   Petrus Wong []
00327 *   Name changes. Added comments.
00328 * 09-09-91      Petrus Wong Rewrote.
00329 * 04-17-91 ????      Created.
00330 \***************************************************************************/
00331
00332 LRESULT CALLBACK MDIWndProc(
00333     HWND hwnd,
00334     UINT message,
00335     WPARAM wParam,
00336     LPARAM lParam)
00337 {
00338
00339     switch (message) {
00340         case WM_COMMAND: {
00341           HANDLE      hInfo;
00342           PINFO       pInfo;
00343           HWND        hTextWnd;
00344
00345           //
00346           // Retrieving this child window's INFO data for displaying
00347           //    messages in the text window
00348           //
00349           hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00350           if (hInfo) {
00351               if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00352                   MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00353
00354               hTextWnd = pInfo->hTextWnd;
00355               vTest(pInfo);
00356               LocalUnlock(hInfo);
00357           } else {
00358               MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
00359           }
00360
00361
00362           switch (LOWORD(wParam)) {
00363             case MM_OPT_1: {
00364                SetWindowText(hTextWnd, "MM_OPT_1");
00365                return 0L;
00366             }
00367
00368             case MM_OPT_2: {
00369                SetWindowText(hTextWnd, "MM_OPT_2");
00370                return 0L;
00371             }
00372
00373             case MM_OPT_3: {
00374                SetWindowText(hTextWnd, "MM_OPT_3");
00375                return 0L;
00376             }
00377
00378             case MM_OPT_4: {
00379                SetWindowText(hTextWnd, "MM_OPT_4");
00380                return 0L;
00381             }
00382             default:
00383                return 0L;
00384
00385           }
00386
00387         }
00388         case WM_SETFOCUS:
00389             break;
00390
00391         //
00392         // Potentially, you can set different menu for different MDI
00393         //  child which is currently being active.
00394         //
00395         case WM_MDIACTIVATE:
00396             if ((HWND) lParam == hwnd) {
00397                 SendMessage(GetParent(hwnd), WM_MDISETMENU,
00398                             (DWORD)  hChildMenu,
00399                             (LONG)   hChildMenuWindow) ;
00400                 DrawMenuBar(GetParent(GetParent(hwnd))) ;
00401             }
00402             return 0L;
00403
00404         //
00405         // Whenever the MDI child window is resized, its children has to be
00406         //  resized accordingly.
00407         //
00408         case WM_SIZE: {
00409             HANDLE      hInfo;
00410             PINFO       pInfo;
00411             HWND        hTextWnd;
00412
00413             //
00414             // First, get the text window's handle from the per MDI child
00415             //  INFO data structure
00416             //
00417             hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00418             if (hInfo) {
00419                 if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00420                     MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00421
00422                 hTextWnd = pInfo->hTextWnd;
00423                 LocalUnlock(hInfo);
00424             } else {
00425                 MessageBox(ghwndMain, "Can't get hInfo!", "Error", MB_OK);
00426             }
00427
00428             //
00429             // Always, put the text window at the bottom of the MDI window
00430             //
00431             MoveWindow(hTextWnd,
00432                        0,
00433                        HIWORD(lParam) - GetWindowLong(hTextWnd, GWL_USERDATA),
00434                        LOWORD(lParam),
00435                        HIWORD(lParam), TRUE);
00436             break;
00437         }
00438
00439         //
00440         // Creates the text window for this MDI child and saves its handle
00441         //  in the per MDI child INFO data structure.
00442         //
00443         case WM_CREATE: {
00444             PINFO           pInfo;
00445             HANDLE          hInfo;
00446             HWND            hTextWnd;
00447
00448             hTextWnd = CreateWindow("Text", NULL,
00449                                     WS_BORDER | SS_LEFT | WS_CHILD | WS_VISIBLE,
00450                                     0, 0, 0, 0,
00451                                     hwnd,
00452                                     (HMENU) 2,
00453                                     ghModule,
00454                                     NULL);
00455
00456             SetWindowText(hTextWnd, "Select 'Option' menu items");
00457             //
00458             // INFO was allocated in the MDIWndProc at MM_MDI time and is
00459             //  passed to us at WM_CREATE time...
00460             //
00461             hInfo = (HANDLE) ((LPMDICREATESTRUCT) ((LPCREATESTRUCT) lParam)->lpCreateParams)->lParam ;
00462             if (hInfo) {
00463                 if ((pInfo = (PINFO)LocalLock(hInfo)) == NULL)
00464                     MessageBox(ghwndMain, "Failed in LocalLock", "Error", MB_OK);
00465
00466                 if (!GetClientRect(hwnd, &pInfo->rcClient))
00467                     MessageBox(ghwndMain, "Failed in GetClientRect!", "Error", MB_OK);
00468
00469                 pInfo->hTextWnd = hTextWnd;
00470                 //
00471                 // Save the handle to INFO in our window structure
00472                 //
00473                 SetWindowLong(hwnd, 0, (LONG) hInfo);
00474                 LocalUnlock(hInfo);
00475             } else {
00476                 MessageBox(ghwndMain, "Can't allocate hInfo!", "Error", MB_OK);
00477             }
00478
00479             break;
00480         }
00481
00482         //
00483         // Free the INFO data that associates with this window
00484         //  also, reset the menu.
00485         //
00486         case WM_CLOSE: {
00487             HANDLE           hInfo;
00488
00489             SendMessage(GetParent(hwnd), WM_MDISETMENU,
00490                             (DWORD) hMenu,
00491                             (LONG)  hMenuWindow) ;
00492             DrawMenuBar(GetParent(GetParent(hwnd))) ;
00493
00494             hInfo = (HANDLE) GetWindowLong(hwnd, 0);
00495             LocalFree(hInfo);
00496             break;
00497         }
00498
00499         default:
00500             return DefMDIChildProc(hwnd, message, wParam, lParam);
00501
00502     } //switch
00503     return DefMDIChildProc(hwnd, message, wParam, lParam);
00504 }
00505
00506 /***************************************************************************\
00507 * About
00508 *
00509 * About dialog proc.
00510 *
00511 * History:
00512 * 09-09-91      Petrus Wong Rewrote.
00513 * 04-13-91 ????      Created.
00514 \***************************************************************************/
00515
00516 BOOL CALLBACK About (
00517     HWND hDlg,
00518     UINT message,
00519     WPARAM wParam,
00520     LPARAM lParam)
00521 {
00522     switch (message) {
00523     case WM_INITDIALOG:
00524         return TRUE;
00525
00526     case WM_COMMAND:
00527         if (wParam == IDOK)
00528             EndDialog(hDlg, wParam);
00529         break;
00530     }
00531
00532     return FALSE;
00533
00534     UNREFERENCED_PARAMETER(lParam);
00535     UNREFERENCED_PARAMETER(hDlg);
00536 }
00537
00538 /***************************************************************************\
00539 *
00540 * TextWndProc
00541 *
00542 * Text Window procedure for displaying miscellaneous messages to user.
00543 *
00544 * History:
00545 * 10-07-91
00546 *   3D text output
00547 *
00548 \***************************************************************************/
00549
00550 LONG WINAPI TextWndProc (HWND hwnd, UINT message, DWORD wParam, LONG lParam)
00551 {
00552     static HFONT hFont = (HFONT) NULL;
00553
00554     switch (message)
00555     {
00556     case WM_CREATE:
00557         {
00558             LOGFONT    lf;
00559             HDC        hDC;
00560             HFONT      hOldFont;
00561             TEXTMETRIC tm;
00562             RECT       rect;
00563             LONG       lHeight;
00564
00565             SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), (PVOID) &lf, (UINT)FALSE);
00566
00567             hDC = GetDC(hwnd);
00568             // this is the height for 8 point size font in pixels
00569             lf.lfHeight = 8 * GetDeviceCaps(hDC, LOGPIXELSY) / 72;
00570
00571             hFont = CreateFontIndirect(&lf);
00572             hOldFont = SelectObject(hDC, hFont);
00573             GetTextMetrics(hDC, &tm);
00574             GetClientRect(GetParent(hwnd), &rect);
00575
00576             // base the height of the window on size of text
00577             lHeight = tm.tmHeight+6*GetSystemMetrics(SM_CYBORDER)+2;
00578             // saved the height for later reference
00579             SetWindowLong(hwnd, GWL_USERDATA, lHeight);
00580             SetWindowPos(hwnd, NULL,
00581                     0,
00582                     rect.bottom-lHeight,
00583                     rect.right-rect.left,
00584                     lHeight,
00585                     SWP_NOZORDER | SWP_NOMOVE);
00586
00587             ReleaseDC(hwnd, hDC);
00588             break;
00589         }
00590
00591     case WM_DESTROY:
00592             if (hFont)
00593                 DeleteObject(hFont);
00594             break;
00595
00596     case WM_SETTEXT:
00597             DefWindowProc(hwnd, message, wParam, lParam);
00598             InvalidateRect(hwnd,NULL,FALSE);
00599             UpdateWindow(hwnd);
00600             return 0L;
00601
00602     case WM_PAINT:
00603         {
00604             PAINTSTRUCT ps;
00605             RECT   rc;
00606             char   ach[128];
00607             int    len, nxBorder, nyBorder;
00608             HFONT  hOldFont = NULL;
00609
00610             BeginPaint(hwnd, &ps);
00611
00612             GetClientRect(hwnd,&rc);
00613
00614             nxBorder = GetSystemMetrics(SM_CXBORDER);
00615             rc.left  += 9*nxBorder;
00616             rc.right -= 9*nxBorder;
00617
00618             nyBorder = GetSystemMetrics(SM_CYBORDER);
00619             rc.top    += 3*nyBorder;
00620             rc.bottom -= 3*nyBorder;
00621
00622             // 3D Text
00623             len = GetWindowText(hwnd, ach, sizeof(ach));
00624             SetBkColor(ps.hdc, GetSysColor(COLOR_BTNFACE));
00625
00626             SetBkMode(ps.hdc, TRANSPARENT);
00627             SetTextColor(ps.hdc, RGB(64,96,96));
00628             if (hFont)
00629                 hOldFont = SelectObject(ps.hdc, hFont);
00630             ExtTextOut(ps.hdc, rc.left+2*nxBorder+2, rc.top+2, ETO_OPAQUE | ETO_CLIPPED,
00631                         &rc, ach, len, NULL);
00632
00633             SetTextColor(ps.hdc, RGB(128,128,128));
00634             if (hFont)
00635                 hOldFont = SelectObject(ps.hdc, hFont);
00636             ExtTextOut(ps.hdc, rc.left+2*nxBorder+1, rc.top+1, ETO_CLIPPED,
00637                         &rc, ach, len, NULL);
00638
00639             SetTextColor(ps.hdc, RGB(255,255,255));
00640             if (hFont)
00641                 hOldFont = SelectObject(ps.hdc, hFont);
00642             ExtTextOut(ps.hdc, rc.left+2*nxBorder, rc.top, ETO_CLIPPED,
00643                         &rc, ach, len, NULL);
00644
00645             SetBkMode(ps.hdc, OPAQUE);
00646
00647             if (hOldFont)
00648                 SelectObject(ps.hdc, hOldFont);
00649
00650             EndPaint(hwnd, &ps);
00651             return 0L;
00652         }
00653     }
00654     return DefWindowProc(hwnd, message, wParam, lParam);
00655 }
00656
00657 VOID vTest(PINFO pInfo)
00658 {
00659     OutputDebugString("Inside vTest()\n");
00660
00661     UNREFERENCED_PARAMETER(pInfo);
00662 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDEUTIL.H Source File

  • NETDDE

NDDEUTIL.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   nddeutil.h
00009 //
00010 //  PURPOSE:  contains NetDDE Utility declarations
00011 //
00012
00013 #ifndef _NDDEUTIL_H
00014 #define _NDDEUTIL_H
00015
00016 BOOL SetupNDDEShare( HWND  hwnd, LPSTR pszShareName, LPSTR pszApp, LPSTR pszTopic );
00017 VOID ShowNDDEErrMsg ( HWND hwnd, LPSTR lpstr, UINT uCode );
00018
00019 #endif
00020
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SEMAPHOR/SEMA.C Source File

  • SEMAPHOR

SEMA.C

Go to the documentation of this file.
00001 /*************************************************************************\
00002 *  PROGRAM: Sema.c
00003 *
00004 *  PURPOSE:
00005 *
00006 *     To demonstrate controlling multiple threads through the use of a
00007 *     semaphore.
00008 *
00009 *  FUNCTIONS:
00010 *
00011 *    WinMain()      - Initializes the window, and process the message loop.
00012 *    MainWndProc()  - Process messages, creates semaphore and threads.
00013 *
00014 *  GLOBAL VARIABLES:
00015 *
00016 *    - hWnd:  Handle to the window.
00017 *    - hSemaphore:
00018 *             Handle of the semaphore used between the threads.
00019 *
00020 *  COMMENTS:
00021 *
00022 *    To Use:
00023 *      Start the application.  You will see five rectangles: a dynamic
00024 *      rectangle in the center (always changing color), and four static
00025 *      rectangles surrounding it.  Each of the four rectagles has their
00026 *      own color: red, blue, green, and gray.  The one in the center
00027 *      alternates between these colors.
00028 *
00029 *      The four static rectangles represent four threads.  These four
00030 *      threads compete for the rectangle in the middle, and their access
00031 *      is controlled by the semaphore.  When the thread gains control of
00032 *      the semaphore, it gets to draw it's color in the center rectangle.
00033 *      (note: the threads do not actually draw any of the four static
00034 *      rectangles.  To make the code simpler this is handled in the
00035 *      WM_PAINT message in the MainWndProc().  They are only meant as
00036 *      a visual representation of the threads.  The threads do however
00037 *      draw the rectangle in the center with their specific color.)
00038 *
00039 *    What Happens:
00040 *      The semaphore has a use count.  When it is set to zero, any thread
00041 *      can access the semaphore and execute the code within its "semaphore
00042 *      gate" by using WaitForSingleObject().  When the thread gains
00043 *      control of the semaphore usint this call, the use count is
00044 *      incremented by one.  When the thread is done executing its code,
00045 *      it can call ReleaseSemaphore().  This will decrement the count
00046 *      by what ever value you indicate (this code uses 1) signalling
00047 *      to any other thread that it may gain control of the semaphore.
00048 *
00049 *      Note that any thread which has access to the semaphore may decrement
00050 *      its use count with ReleaseSemaphore(); the thread does not have
00051 *      to have control of the semaphore at the time.
00052 *
00053 *      In this code, the WM_CREATE message in MainWndProc creates a
00054 *      semaphore.  The four threads are then created, each waiting
00055 *      on the semaphore .
00056 *
00057 *      Each of the threads loop, blocking on a WaitForSingleObject()
00058 *      call.  Once any thread has set the use count to 0, the thread
00059 *      gets to draw draw the center rectagle with its color, and then
00060 *      sleeps for half a second before freeing the semaphore again.
00061 *      The thread then runs through the loop again.
00062 *
00063 \*************************************************************************/
00064 #include <windows.h>
00065 #include <stdlib.h>
00066 #include "sema.h"
00067
00068
00069 HANDLE hInst;
00070 HANDLE hWnd;
00071 HANDLE hSemaphore;
00072
00073 /*************************************************************************\
00074 *
00075 *  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00076 *
00077 *  PURPOSE: calls initialization function, processes message loop
00078 *
00079 *  COMMENTS:
00080 *
00081 \*************************************************************************/
00082 int PASCAL WinMain ( HINSTANCE hInstance,
00083                      HINSTANCE hPrevInstance,
00084                      LPSTR  lpCmdLine,
00085                      int    nCmdShow)
00086 {
00087   MSG  msg;
00088   WNDCLASS wc;
00089   DWORD dwVersion = GetVersion();
00090
00091   UNREFERENCED_PARAMETER( lpCmdLine );
00092   UNREFERENCED_PARAMETER( hPrevInstance );
00093
00094   // check if Win32s, if so, display notice and terminate
00095       if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00096       {
00097         MessageBox( NULL,
00098            "This application cannot run on Windows 3.1.\n"
00099            "This application will now terminate.",
00100            "Semaphor",
00101            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00102         return( 1 );
00103       }
00104
00105   hInst = hInstance;
00106
00107   wc.style         = CS_VREDRAW | CS_HREDRAW;
00108   wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00109   wc.cbClsExtra    = 0;
00110   wc.cbWndExtra    = 0;
00111   wc.hInstance     = hInstance;
00112   wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
00113   wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
00114   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00115   wc.lpszMenuName  = "";
00116   wc.lpszClassName = "SemaWClass";
00117
00118   RegisterClass(&wc);
00119
00120   hWnd = CreateWindow ("SemaWClass",
00121                        "Semaphore Sample",
00122                        WS_OVERLAPPEDWINDOW,
00123                        CW_USEDEFAULT,
00124                        CW_USEDEFAULT,
00125                        CW_USEDEFAULT,
00126                        CW_USEDEFAULT,
00127                        NULL,
00128                        NULL,
00129                        hInstance,
00130                        NULL);
00131
00132   ShowWindow(hWnd, nCmdShow);
00133   while (GetMessage (&msg, NULL, 0, 0))
00134       DispatchMessage (&msg);    // Dispatch message to window.
00135
00136   return (msg.wParam);           // Returns value from PostQuitMessage.
00137
00138 }
00139
00140 /*************************************************************************\
00141 *
00142 *  FUNCTION:  MainWndProc (HWND, UINT, WPARAM, LPARAM)
00143 *
00144 *  PURPOSE:   To process the windows messages.  This procedure creates
00145 *             the semaphore and the four threads.  It also draws the
00146 *             four static rectangles.
00147 *
00148 *  VARIABLES USED:
00149 *
00150 *    - hThread?:
00151 *             These four static varaibles are handles to the four
00152 *             created threads.
00153 *
00154 *    - ThreadID?:
00155 *             These four variables are local DWORDS used in the
00156 *             CreateThread() call.
00157 *
00158 *    - pColor?:
00159 *             These four variables are used as pointers to memory
00160 *             which is allocated and filled with color values to
00161 *             pass as a parameter to each of the threads (so the
00162 *             threads know what color they are to paint the rectangle).
00163 *
00164 *    - Paint: A paint structure used in BeginPaint() and EndPaint().
00165 *
00166 *    - rect:  A RECT structure used to get the windows client area.
00167 *             It's needed to figure out the new relative positions
00168 *             of the four static rectangles when the user resizes
00169 *             the window.
00170 *
00171 *    - Col?, Row?, width, height:
00172 *             These local DWORDs are used to position the four static
00173 *             rectangles and to determin their size.
00174 *
00175 *    - hDC:   Handle to the DC for the window.
00176 *
00177 *    - hBrush:
00178 *             Handle to a brush, used to set the color of the four static
00179 *             rectangles.
00180 *
00181 *  MESSAGES:
00182 *
00183 *    WM_CREATE:      - Creates a semaphore; allocates some
00184 *                      memory and sets it with color values to be passed
00185 *                      as parameter values to the threads.  It then
00186 *                      creates four threads, giving each its own color.
00187 *
00188 *    WM_PAINT:       - Checks the size of the client space and then
00189 *                      draws the four static rectangles to their relative
00190 *                      positions.
00191 *
00192 *    WM_DESTROY:     - Terminates the threads, and posts a quit message.
00193 *
00194 *  CALLED BY:
00195 *
00196 *    WinMain();
00197 *
00198 *  THREADS CREATED:
00199 *
00200 *    ThreadProc();   - Four instances
00201 *
00202 \*************************************************************************/
00203
00204
00205 LRESULT CALLBACK MainWndProc (HWND hwnd,
00206                               UINT message,
00207                               WPARAM wParam,
00208                               LPARAM lParam)
00209 {
00210   DWORD  ThreadID1, ThreadID2, ThreadID3, ThreadID4;
00211   RECT   rect;
00212   DWORD  Col1, Col2, Col3, Row1, Row2, Row3, width, height;
00213   HDC    hDC;
00214   HANDLE hBrush;
00215   PAINTSTRUCT Paint;
00216   static HANDLE hThread1, hThread2, hThread3, hThread4;
00217   static DWORD  *pColor1,  *pColor2,  *pColor3,  *pColor4;
00218   CHAR Buf[80];
00219
00220
00221   switch (message)
00222       {
00223
00224         case WM_PAINT:
00225           hDC = BeginPaint (hwnd, &Paint);
00226           GetClientRect( hWnd, &rect);       // Get window rectangle.
00227
00228           width =  rect.right / 4;           // Calculate static rectangle's
00229           height = rect.bottom / 4;          // width and height.
00230
00231           Col1 = (rect.right / 16)  * 1;     // Calculate x positions.
00232           Col2 = (rect.right / 16)  * 6;
00233           Col3 = (rect.right / 16)  * 11;
00234                                              // Calculate y positions.
00235           Row1 = (rect.bottom / 16) * 1;
00236           Row2 = (rect.bottom / 16) * 6;
00237           Row3 = (rect.bottom / 16) * 11;
00238
00239           hBrush = CreateSolidBrush((COLORREF)RED);
00240           SelectObject (hDC, hBrush);
00241           Rectangle (hDC, Col2, Row1, Col2+width, Row1+height);
00242           DeleteObject (hBrush);
00243                                              // Draw the Blue rectangle.
00244           hBrush = CreateSolidBrush((COLORREF)BLUE);
00245           SelectObject (hDC, hBrush);
00246           Rectangle (hDC, Col1, Row2, Col1+width, Row2+height);
00247           DeleteObject (hBrush);
00248                                              // Draw the Green rectangle.
00249           hBrush = CreateSolidBrush((COLORREF)GREEN);
00250           SelectObject (hDC, hBrush);
00251           Rectangle (hDC, Col2, Row3, Col2+width, Row3+height);
00252           DeleteObject (hBrush);
00253                                              // Draw the Gray rectangle.
00254           hBrush = CreateSolidBrush((COLORREF)GRAY);
00255           SelectObject (hDC, hBrush);
00256           Rectangle (hDC, Col3, Row2, Col3+width, Row2+height);
00257           DeleteObject (hBrush);
00258
00259           EndPaint (hwnd, &Paint);
00260           return (0);
00261
00262         case WM_CREATE :
00263                                              // Create the semaphore.
00264           hSemaphore = CreateSemaphore (NULL, 0, 1, NULL);
00265
00266           if (!hSemaphore)
00267             {
00268              wsprintf (Buf, "CreateSemaphore() Error = %d",
00269                        GetLastError());
00270              MessageBox(hwnd, Buf, "WM_CREATE", MB_OK);
00271              return (0);
00272             }
00273
00274           pColor1  = malloc(sizeof(DWORD));
00275           *pColor1 = GREEN;                  // Create the Green thread.
00276           hThread1 = CreateThread ( NULL,
00277                                     0,
00278                                     (LPTHREAD_START_ROUTINE)ThreadProc,
00279                             (LPVOID)pColor1,
00280                             0,
00281                                     &ThreadID1);
00282
00283           pColor2  = malloc(sizeof(DWORD));
00284           *pColor2 = RED;                    // Create the Red thread.
00285           hThread2 = CreateThread ( NULL,
00286                                     0,
00287                                     (LPTHREAD_START_ROUTINE)ThreadProc,
00288                             (LPVOID)pColor2,
00289                             0,
00290                                     &ThreadID2);
00291
00292           pColor3  = malloc(sizeof(DWORD));
00293           *pColor3 = BLUE;                   // Create the Blue thread.
00294           hThread3 = CreateThread ( NULL,
00295                                     0,
00296                                     (LPTHREAD_START_ROUTINE)ThreadProc,
00297                             (LPVOID)pColor3,
00298                             0,
00299                                     &ThreadID3);
00300
00301           pColor4  = malloc(sizeof(DWORD));
00302           *pColor4 = GRAY;                   // Create the Gray thread.
00303           hThread4 = CreateThread ( NULL,
00304                                     0,
00305                                     (LPTHREAD_START_ROUTINE)ThreadProc,
00306                             (LPVOID)pColor4,
00307                             0,
00308                                     &ThreadID4);
00309
00310           ReleaseSemaphore (hSemaphore, 1, NULL);
00311
00312           return (0);
00313
00314
00315         case WM_DESTROY :                    // Terminate the threads and
00316             TerminateThread(hThread1, 0);    // clean up.
00317             TerminateThread(hThread2, 0);
00318             TerminateThread(hThread3, 0);
00319             TerminateThread(hThread4, 0);
00320             free (pColor1);
00321             free (pColor2);
00322             free (pColor3);
00323             free (pColor4);
00324
00325             PostQuitMessage (0);
00326             return (0);
00327
00328        }
00329     return DefWindowProc (hwnd, message, wParam, lParam);
00330 }
00331
00332
00333 /*************************************************************************\
00334 *
00335 *  FUNCTION:  ThreadProc (LPVOID)
00336 *
00337 *  PURPOSE:   A thread procedure which requests a semaphore, and then
00338 *             draws it's color to the rectangle in the middle of the
00339 *             window.
00340 *
00341 *  VARIABLES USED:
00342 *
00343 *    - Color: An input parameter, a pointer to a DWORD with a color
00344 *             value in it.
00345 *
00346 *    - rect:  The RECT rectangle of the client window, needed to know where
00347 *             the center rectangle resides.
00348 *
00349 *    - hDC:   Handle to the DC of the window.
00350 *
00351 *    - hBrush:
00352 *             Handle to a brush, used to set the rectangle's color to the
00353 *             threads.
00354 *
00355 *    - width, height, Col, Row:
00356 *             DWORDs use to position the rectangle.
00357 *
00358 *  THREAD CREATED BY:
00359 *
00360 *    MainWndProc();
00361 *
00362 \*************************************************************************/
00363 VOID ThreadProc ( LPVOID *Color)
00364 {
00365   RECT   rect;
00366   HDC    hDC;
00367   HANDLE hBrush;
00368   DWORD  width, height, Col, Row;
00369
00370   hBrush = CreateSolidBrush((COLORREF)*Color);
00371
00372   while (TRUE)
00373   {
00374       WaitForSingleObject (hSemaphore, INFINITE);
00375       GetClientRect( hWnd, &rect);
00376
00377       width  =  rect.right / 4;
00378       height = rect.bottom / 4;
00379       Col = (rect.right / 16)  * 6;
00380       Row = (rect.bottom / 16) * 6;
00381
00382       hDC = GetDC(hWnd);
00383       SelectObject( hDC, hBrush);
00384       Rectangle (hDC, Col, Row, Col + width, Row + height);
00385       ReleaseDC(hWnd, hDC);
00386       Sleep (500);
00387       ReleaseSemaphore (hSemaphore, 1, NULL);
00388   }
00389
00390   return;
00391 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/MASKBLT.H Source File

  • MASKBLT

MASKBLT.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* maskblt.h - header file for the maskblt demonstration program. */
00013
00014
00015 /* function prototypes for the window procedures. */
00016 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00017 BOOL CALLBACK DlgProc    (HWND, UINT, WPARAM, LPARAM);
00018
00019 VOID DrawGrids (HDC, int, int);
00020
00021
00022 /* Top dialog item IDs */
00023 #define  DID_X          100
00024 #define  DID_Y          101
00025 #define  DID_WIDTH      102
00026 #define  DID_HEIGHT     103
00027 #define  DID_XSRC       104
00028 #define  DID_YSRC       105
00029 #define  DID_XMASK      106
00030 #define  DID_YMASK      107
00031
00032 #define  DID_ROP0       110
00033 #define  DID_ROP1       111
00034 #define  DID_ROP2       112
00035 #define  DID_ROP3       113
00036
00037 #define  DID_NEWSRC     300
00038 #define  DID_NEWMASK    301
00039
00040 #define  DID_DRAW       302
00041
00042 #define  DID_CB_MODE    150
00043 #define  DID_CB_PATTERN 151
00044 #define  DID_CB_ROPS    152
00045
00046
00047
00048 /* accelerator IDs */
00049 #define AID_PASTE       55
00050 #define AID_COPY        56
00051 #define AID_CYCLE       57
00052
00053
00054
00055 /* Misc. defines for size, color, and appearance of drawing. */
00056 #define GRIDCOLOR  (COLORREF) 0x01000006
00057 #define DIALOGHEIGHT  90
00058 #define SEPARATORWIDTH 4
00059 #define MAXCHARS      32
00060 #define INC            5
00061
00062
00063
00064 /* other user messages sent to the main window or the dialog */
00065 #define WM_PUTUPDESTRECT WM_USER+20
00066 #define WM_PUTUPSRCRECT  WM_USER+21
00067 #define WM_PUTUPMASKPT   WM_USER+22
00068 #define WM_MASKBLT       WM_USER+23
00069
00070
00071
00072 /* structure for the lookup tables.  */
00073 typedef struct tagLookupEntry{
00074     int     Value;
00075     char    String[30];
00076 } LookupEntry;
00077
00078
00079 #define NROPS  17
00080 LookupEntry  StandardROPs[NROPS] =
00081     {{ SRCCOPY     , "SRCCOPY"    },
00082      { SRCPAINT    , "SRCPAINT"   },
00083      { SRCAND      , "SRCAND"     },
00084      { SRCINVERT   , "SRCINVERT"  },
00085      { SRCERASE    , "SRCERASE"   },
00086      { NOTSRCCOPY  , "NOTSRCCOPY" },
00087      { NOTSRCERASE , "NOTSRCERASE"},
00088      { MERGECOPY   , "MERGECOPY"  },
00089      { MERGEPAINT  , "MERGEPAINT" },
00090      { PATCOPY     , "PATCOPY"    },
00091      { PATPAINT    , "PATPAINT"   },
00092      { PATINVERT   , "PATINVERT"  },
00093      { DSTINVERT   , "DSTINVERT"  },
00094      { BLACKNESS   , "BLACKNESS"  },
00095      { WHITENESS   , "WHITENESS"  },
00096      { 0xccaa0000  , "Transparent1"  },
00097      { 0xaacc0000  , "Transparent2"  }};
00098
00099
00100 #define NPATTERNS  6
00101 LookupEntry Patterns[NPATTERNS] =
00102     {{  0, "WHITE_BRUSH "},
00103      {  1, "LTGRAY_BRUSH"},
00104      {  2, "GRAY_BRUSH  "},
00105      {  3, "DKGRAY_BRUSH"},
00106      {  4, "BLACK_BRUSH "},
00107      {  5, "NULL_BRUSH  "}};
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/COMMON.H Source File

  • BNDBUF

COMMON.H

Go to the documentation of this file.
00001 #define MAX_ITEM 10
00002 #define MAX_SIZE 20
00003
00004 #define SUCCESS 1
00005 #define FAILURE 0
00006
00007
00008 #define MAXCALLS    20
00009
00010
00011 // Synchronization primitives to shared buffer
00012
00013 HANDLE hMutex;    // Handle to mutex
00014 HANDLE hEmptySem; // Handle to empty semaphore
00015 HANDLE hFullSem;    // Handle to full semaphore
00016
00017
00018 // This is the shared buffer
00019
00020 char buffer[MAX_ITEM][MAX_SIZE];
00021
00022
00023 // The current producer and consumer position in the buffer pool
00024
00025 int pro_buf_pos;
00026 int con_buf_pos;
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/RECHOOK.H Source File

  • MINREC

RECHOOK.H

Go to the documentation of this file.
00001 // ************************************************************************
00002 //
00003 //                      Microsoft Developer Support
00004 //               Copyright (c) 1992-1996 Microsoft Corporation
00005 //
00006 // ************************************************************************
00007 // PROGRAM   : RecHook.H
00008 // PURPOSE   : A Small Win32 Recorder-like Sample Application Hook DLL
00009 //             Header File
00010 // COMMENTS  :
00011 // ************************************************************************
00012 #ifndef RECHOOK_H
00013
00014  #define RECHOOK_H
00015
00016  // Global Defines
00017  // -----------------------------------------------------------------------
00018
00019  // Public Function Prototypes
00020  // -----------------------------------------------------------------------
00021  BOOL StartJournalRecord( VOID );
00022  BOOL StopJournalRecord( VOID );
00023  BOOL StartJournalPlayback( VOID );
00024  BOOL StopJournalPlayback( VOID );
00025  BOOL StopAllJournalling( VOID );
00026
00027 #endif // RECHOOK_H
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: DRIVES/DRIVES.C Source File

  • DRIVES

DRIVES.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************
00013 *
00014 *    PROGRAM: DRIVES.C
00015 *
00016 *    PURPOSE: Determines all drives in the system, both local and remote,
00017 *             and their file system type
00018 *
00019 *    FUNCTIONS:
00020 *
00021 *    CheckRM() - verifies that a removeable media drive contains a disk
00022 *    GVI() - gets the volume information for a drive and prints out the
00023 *            file system type
00024 *    UpdateBuffer() - updates string pointer to the next string in an array
00025 *            of strings
00026 *
00027 *    COMMENTS:
00028 *
00029 ****************************************************************************/
00030
00031 #include <windows.h>
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include "drives.h"
00035
00036 #define BUFSIZE 2048
00037
00038 CHAR chBuffer[BUFSIZE];
00039
00040 /****************************************************************************
00041 *
00042 *    FUNCTION: CheckRM(LPTSTR)
00043 *
00044 *    PURPOSE: Verifies that a removeable media drive contains a disk
00045 *
00046 *    COMMENTS:
00047 *
00048 *        This function is called each time a drive type is determined to be
00049 *        removeable (DRIVE_REMOVEABLE).  An attempt is made to open a
00050 *        file in the root directory of the drive.  If the attempt succeeds,
00051 *        then media is present in the drive and subsequent calls to the
00052 *        drive can be safely made.  If the call fails, then there is no media
00053 *        present in the drive and no attempts should be made to access this
00054 *        drive.  The Error Mode is temporarily set to 1 to allow failures
00055 *        to immediately return to the calling program.  This eliminates
00056 *        unwanted dialog boxes that prompt for disks to be placed in the
00057 *        drive.
00058 *
00059 *    INPUT: lpszDriveName - removeable media drive name (ex - "a:")
00060 *
00061 *    OUTPUT: Returns TRUE if media present
00062 *                    FALSE if media is not present
00063 *
00064 ****************************************************************************/
00065
00066 BOOL CheckRM(LPTSTR lpszDriveName)
00067 {
00068   int      iRC;
00069   LPTSTR   lpszFileName="         ";
00070   OFSTRUCT ofstruct;
00071   WORD     wStyle=OF_EXIST;
00072
00073   SetErrorMode(1);
00074   strcpy(lpszFileName,lpszDriveName);
00075   strcat(lpszFileName,".");
00076   iRC=OpenFile(lpszFileName,&ofstruct,wStyle);
00077   SetErrorMode(0);
00078   if (iRC==-1)
00079     return (FALSE);
00080   _lclose(iRC);
00081   return (TRUE);
00082 }
00083
00084 /****************************************************************************
00085 *
00086 *    FUNCTION: GVI(LPTSTR, LPTSTR, DWORD)
00087 *
00088 *    PURPOSE: gets the Volume Information for the specified drive and prints
00089 *             the file system type
00090 *
00091 *    COMMENTS:
00092 *        This function makes a call to GetVolumeInformation.  The file system
00093 *        type is returned in the szSystemName buffer.  The file system type
00094 *        is printed to the screen.
00095 *
00096 *    INPUT: lpszDriveName - pointer to the drive name (ex - "a:")
00097 *           lpszSystemName - pointer to the system name buffer.  This will
00098 *                            be filled in by the GetVolumeInformation call
00099 *                            (e.g. FAT, HPFS)
00100 *           nSystemNameSize - size of the lpszSystemName buffer
00101 *
00102 *    OUTPUT: None
00103 *
00104 ****************************************************************************/
00105
00106 VOID GVI(LPTSTR lpszDriveName,LPTSTR lpszSystemName, DWORD nSystemNameSize)
00107 {
00108   BOOL     bRC;
00109
00110   lstrcpy( lpszSystemName, "Unknown Media Type" );
00111   bRC=GetVolumeInformation(lpszDriveName,
00112                            NULL,
00113                            0,
00114                            NULL,
00115                            NULL,
00116                            NULL,
00117                            lpszSystemName,
00118                            nSystemNameSize);
00119   printf("File system = %s",lpszSystemName);
00120 }
00121
00122 /****************************************************************************
00123 *
00124 *    FUNCTION: UpdateBuffer(LPTSTR)
00125 *
00126 *    PURPOSE: updates string pointer to the next string in an array
00127 *             of strings
00128 *
00129 *    COMMENTS:
00130 *
00131 *    INPUT: lpszString - pointer to an array of zero terminated strings.
00132 *                        The final string is terminated with a double null.
00133 *
00134 *    OUTPUT: modified pointer that points to the next string in the array
00135 *
00136 ****************************************************************************/
00137
00138 LPTSTR UpdateBuffer(LPTSTR lpszString)
00139 {
00140   return (lpszString+strlen(lpszString)+1);
00141 }
00142
00143 /****************************************************************************
00144 *
00145 *    FUNCTION: main()
00146 *
00147 *    PURPOSE: the main C routine
00148 *
00149 *    COMMENTS:
00150 *        The number of available drives is first determined by a call to
00151 *        GetLogicalDrives.  This provides a bit mask of all logical drives.
00152 *        Next, a call is made to GetLogicalDriveStrings to get the valid
00153 *        drive strings for the system.
00154 *
00155 *        For each logical drive, a call is made to GetDriveType to determine
00156 *        the drive type.  If the logical drive is not in the bit mask that
00157 *        was created with the GetLogicalDrives call, then this drive is
00158 *        bypassed.
00159 *
00160 *        GetVolumeInformation is used to determine the file system
00161 *        for the logical drive.  This information is returned in the
00162 *        lpszFileSystemNameBuffer variable.  If the drive type is
00163 *        remote, a check must be made to see if the drive contains a
00164 *        disk. This is accomplished by opening '.' in the root
00165 *        directory of the remote drive.  The error level is temporarily
00166 *        changed from 0 to 1, to allow any OpenFileErrors to immediately
00167 *        return to the calling function, thus eliminating any unwanted
00168 *        dialog boxes.  If the remote drive contains a disk, then it is
00169 *        safe to proceed with the GetVolumeInformation call.
00170 *
00171 *    INPUT: None
00172 *
00173 *    OUTPUT: None
00174 *
00175 ****************************************************************************/
00176
00177 VOID main(VOID)
00178 {
00179   DWORD     dwDriveMask;
00180   DWORD     dwRC;
00181   DWORD     dwTemp;
00182   DWORD     cbDriveStringBufferSize=BUFSIZE;
00183   LPTSTR    lpszDriveStringBuffer=chBuffer;
00184   LPTSTR    lpszRootPathName="?:\\";
00185   LPTSTR    lpszFileSystemNameBuffer="                              ";
00186   DWORD     nFileSystemNameSize=sizeof("                              ");
00187   DWORD     dwVersion;
00188 //yg Modified to check for windows 95
00189
00190   // check if running on Windows NT or Windows 95, if not, display notice and terminate
00191
00192   dwVersion = GetVersion();
00193   if ((dwVersion & 0x80000000) && (LOBYTE(LOWORD(dwVersion))< 4))
00194   {
00195      MessageBox( NULL,
00196        "This sample application can only be run on Windows NT or Windows 95.\n"
00197        "This application will now terminate.",
00198        "Drives",
00199        MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00200        return;
00201   }
00202
00203   dwDriveMask=GetLogicalDrives();
00204   dwRC=GetLogicalDriveStrings(cbDriveStringBufferSize,lpszDriveStringBuffer);
00205   printf("%08X %s\n", dwDriveMask, lpszDriveStringBuffer);
00206   for (*lpszRootPathName='a';*lpszRootPathName<='z';(*lpszRootPathName)++)
00207     {
00208     dwTemp=dwDriveMask & 1;
00209     dwDriveMask >>= 1;
00210     if (dwTemp)
00211       {
00212       dwRC=GetDriveType(lpszRootPathName);
00213       printf("The drive type for %s is ",lpszDriveStringBuffer);
00214       lpszDriveStringBuffer=UpdateBuffer(lpszDriveStringBuffer);
00215       switch (dwRC)
00216         {
00217         case DRIVE_REMOVEABLE :
00218             printf("removeable. ");
00219             if (CheckRM(lpszRootPathName))
00220               GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
00221             else
00222               printf("File system = INDETERMINATE");
00223             break;
00224         case DRIVE_FIXED      :
00225             printf("fixed.      ");
00226             GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
00227             break;
00228         case DRIVE_REMOTE     :
00229             printf("remote.     ");
00230             GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
00231             break;
00232         case DRIVE_CDROM      :
00233             printf("CD-ROM.     ");
00234             GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
00235             break;
00236         case DRIVE_RAMDISK    :
00237             printf("RAM disk.   ");
00238             GVI(lpszRootPathName,lpszFileSystemNameBuffer,nFileSystemNameSize);
00239             break;
00240         default               :
00241             break;
00242         }
00243       printf("\n");
00244       }
00245     }
00246 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: IOCOMP/IOCOMP.C Source File

  • IOCOMP

IOCOMP.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1995-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 #include <windows.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <ctype.h>
00017
00018 //
00019 // Unbuffered write test
00020 //
00021
00022 #define TEST_REPEAT_COUNT   10
00023
00024 //
00025 // File is 20mb
00026 //
00027
00028 #define BUFFER_SIZE         (64*1024)
00029 #define NUMBER_OF_WRITES    (320*1)
00030
00031 int BufferSize;
00032 int NumberOfWrites;
00033
00034 char *Buffer;
00035
00036 BOOL fSequentialNew;
00037 BOOL fBufferdIo;
00038 LPSTR FileName;
00039
00040 VOID
00041 ParseSwitch(
00042     CHAR chSwitch,
00043     int *pArgc,
00044     char **pArgv[]
00045     );
00046
00047
00048 VOID
00049 ShowUsage(
00050     VOID
00051     );
00052
00053 int
00054 _CRTAPI1
00055 main(
00056     int argc,
00057     char *argv[],
00058     char *envp
00059     )
00060 {
00061     DWORD Start[TEST_REPEAT_COUNT];
00062     DWORD End[TEST_REPEAT_COUNT];
00063     DWORD Diff;
00064     double fDiff, fSec, fKb, fSumKbs;
00065     int TestNumber;
00066     HANDLE hFile, hPort;
00067     OVERLAPPED ov;
00068     LPOVERLAPPED ov2;
00069     int WriteCount;
00070     DWORD n,n2,key;
00071     BOOL b;
00072     int PendingIoCount;
00073     DWORD Version;
00074     DWORD FileFlags;
00075     char chChar, *pchChar;
00076
00077     Version = GetVersion() >> 16;
00078
00079     FileName = "unbufw.dat";
00080     fSequentialNew = FALSE;
00081     fBufferdIo = FALSE;
00082
00083     BufferSize = BUFFER_SIZE;
00084     NumberOfWrites = ( (20*(1024*1024)) / BufferSize);
00085
00086     while (--argc) {
00087   pchChar = *++argv;
00088   if (*pchChar == '/' || *pchChar == '-') {
00089       while (chChar = *++pchChar) {
00090     ParseSwitch( chChar, &argc, &argv );
00091     }
00092       }
00093   }
00094
00095
00096
00097
00098     if ( argc > 1 ) {
00099   FileName = argv[1];
00100   }
00101     else {
00102   }
00103
00104     fSumKbs = 0.0;
00105
00106     Buffer = VirtualAlloc(NULL,BUFFER_SIZE,MEM_COMMIT,PAGE_READONLY);
00107     if ( !Buffer ) {
00108   printf("Error allocating buffer %d\n",GetLastError());
00109   return 99;
00110   }
00111
00112     FileFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED;
00113
00114     if ( !fBufferdIo ) {
00115   FileFlags |= FILE_FLAG_NO_BUFFERING;
00116   }
00117
00118     DeleteFile(FileName);
00119
00120     for (TestNumber = 0; TestNumber < TEST_REPEAT_COUNT; TestNumber++ ) {
00121
00122
00123   hFile = CreateFile(
00124         FileName,
00125         GENERIC_READ | GENERIC_WRITE,
00126         FILE_SHARE_READ | FILE_SHARE_WRITE,
00127         NULL,
00128         OPEN_ALWAYS,
00129         FileFlags,
00130         NULL
00131         );
00132   if ( hFile == INVALID_HANDLE_VALUE ) {
00133       printf("Error opening file %s %d\n",FileName,GetLastError());
00134       return 99;
00135       }
00136
00137   hPort = CreateIoCompletionPort(
00138         hFile,
00139         NULL,
00140         (DWORD)hFile,
00141         0
00142         );
00143   if ( !hPort ) {
00144       printf("Error creating completion port %d\n",FileName,GetLastError());
00145       return 99;
00146       }
00147
00148   ZeroMemory(&ov,sizeof(ov));
00149
00150   if ( TestNumber == 0 && fSequentialNew == FALSE) {
00151
00152       Start[TestNumber] = GetTickCount();
00153
00154       //
00155       // Make sure the file is written out to the end...
00156       //
00157       ov.Offset = (NUMBER_OF_WRITES * BUFFER_SIZE) - 1024;
00158
00159       b = WriteFile(hFile,Buffer,1024,&n,&ov);
00160       if ( !b && GetLastError() != ERROR_IO_PENDING ) {
00161     printf("Error in pre-write %d\n",GetLastError());
00162     return 99;
00163     }
00164       b = GetQueuedCompletionStatus(
00165         hPort,
00166         &n2,
00167         &key,
00168         &ov2,
00169         (DWORD)-1
00170         );
00171       if ( !b ) {
00172     printf("Error picking up completion pre-write %d\n",GetLastError());
00173     return 99;
00174     }
00175
00176       End[TestNumber] = GetTickCount();
00177
00178       Diff = End[TestNumber] - Start[TestNumber];
00179
00180       fDiff = Diff;
00181       fSec = fDiff/1000.0;
00182       fKb = ( (NumberOfWrites * BufferSize) / 1024 );
00183
00184       printf("First Write %2dMb Written in %3.3fs I/O Rate %4.3f Kb/S\n\n",
00185     (NumberOfWrites * BufferSize) / ( 1024 * 1024),
00186     fSec,
00187     fKb / fSec
00188     );
00189       }
00190
00191   ov.Offset = 0;
00192
00193   PendingIoCount = 0;
00194
00195   Start[TestNumber] = GetTickCount();
00196
00197   //
00198   // Issue the writes
00199   //
00200
00201   for (WriteCount = 0; WriteCount < NumberOfWrites; WriteCount++){
00202 reissuewrite:
00203       b = WriteFile(hFile,Buffer,BufferSize,&n,&ov);
00204       if ( !b && GetLastError() != ERROR_IO_PENDING ) {
00205
00206     //
00207     // we reached our limit on outstanding I/Os
00208     //
00209
00210     if ( GetLastError() == ERROR_INVALID_USER_BUFFER ||
00211          GetLastError() == ERROR_NOT_ENOUGH_QUOTA ||
00212          GetLastError() == ERROR_NOT_ENOUGH_MEMORY ) {
00213
00214         //
00215         // wait for an outstanding I/O to complete and then go again
00216         //
00217         b = GetQueuedCompletionStatus(
00218           hPort,
00219           &n2,
00220           &key,
00221           &ov2,
00222           (DWORD)-1
00223           );
00224         if ( !b ) {
00225       printf("Error picking up completion write %d\n",GetLastError());
00226       return 99;
00227       }
00228
00229         PendingIoCount--;
00230         goto reissuewrite;
00231         }
00232     else {
00233         printf("Error in write %d\n",GetLastError());
00234         return 99;
00235         }
00236     }
00237       PendingIoCount++;
00238       ov.Offset += BufferSize;
00239       }
00240
00241   //
00242   // Pick up the I/O completion
00243   //
00244
00245   for (WriteCount = 0; WriteCount < PendingIoCount; WriteCount++){
00246       b = GetQueuedCompletionStatus(
00247         hPort,
00248         &n2,
00249         &key,
00250         &ov2,
00251         (DWORD)-1
00252         );
00253       if ( !b ) {
00254     printf("Error picking up completion write %d\n",GetLastError());
00255     return 99;
00256     }
00257       }
00258
00259   End[TestNumber] = GetTickCount();
00260
00261   CloseHandle(hFile);
00262
00263   if ( Version > 613 ) {
00264       CloseHandle(hPort);
00265       }
00266
00267   //
00268   // Dump the results
00269   //
00270
00271   Diff = End[TestNumber] - Start[TestNumber];
00272
00273   fDiff = Diff;
00274   fSec = fDiff/1000.0;
00275   fKb = ( (NumberOfWrites * BufferSize) / 1024 );
00276
00277   printf("Test %2d %2dMb Written in %3.3fs I/O Rate %4.3f Kb/S\n",
00278       TestNumber,
00279       (NumberOfWrites * BufferSize) / ( 1024 * 1024),
00280       fSec,
00281       fKb / fSec
00282       );
00283
00284   fSumKbs += (fKb / fSec);
00285
00286   if ( fSequentialNew ) {
00287       DeleteFile(FileName);
00288       }
00289
00290   }
00291
00292     DeleteFile(FileName);
00293
00294     //
00295     // Average
00296     //
00297
00298     printf("\n Average Throughput %4.3f\n\n",
00299       fSumKbs/TEST_REPEAT_COUNT
00300       );
00301 }
00302
00303
00304 VOID
00305 ParseSwitch(
00306     CHAR chSwitch,
00307     int *pArgc,
00308     char **pArgv[]
00309     )
00310 {
00311     int bs;
00312     switch (toupper( chSwitch )) {
00313
00314   case '?':
00315       ShowUsage();
00316       break;
00317
00318   case 'F':
00319       if (!--(*pArgc)) {
00320     ShowUsage();
00321     }
00322       (*pArgv)++;
00323       FileName =  *(*pArgv);
00324       break;
00325
00326   case 'K':
00327       if (!--(*pArgc)) {
00328     ShowUsage();
00329     }
00330       (*pArgv)++;
00331       bs = strtoul( *(*pArgv), NULL, 10 );
00332       bs *= 1024;
00333       if ( bs > BUFFER_SIZE ) {
00334     ShowUsage();
00335     }
00336
00337       BufferSize = bs;
00338       NumberOfWrites = ( (20*(1024*1024)) / BufferSize);
00339
00340       break;
00341
00342
00343   case 'S':
00344       fSequentialNew = TRUE;
00345       break;
00346
00347   case 'B':
00348       fBufferdIo = TRUE;
00349       break;
00350
00351
00352   default:
00353       fprintf( stderr, "UNBUFW: Invalid switch - /%c\n", chSwitch );
00354       ShowUsage();
00355       break;
00356
00357   }
00358 }
00359
00360
00361 VOID
00362 ShowUsage(
00363     VOID
00364     )
00365 {
00366     fputs( "usage: IOCOMP [switches]\n"
00367      "              [-f filename] supplies the output filename\n"
00368      "              [-s] write sequentially without pre-allocating the file\n"
00369      "              [-b] use buffered I/O instead of unbuffered I/O\n"
00370      "              [-k write-size] use write-size k as write-size (64 is max)\n",
00371      stderr );
00372
00373     exit( 1 );
00374 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SCRNSAVE/FRACTAL.H Source File

  • SCRNSAVE

FRACTAL.H

Go to the documentation of this file.
00001 #define idsName             100
00002 #define idsXFrom            9001
00003 #define idsYFrom            9002
00004 #define idsXTo              9003
00005 #define idsYTo              9004
00006 #define idsSaveAs           9005
00007 #define idsIteration        9006
00008
00009 #define FIRST_PIXEL     429496796
00010 #define MAXDOUBLELEN        22          // big enough?
00011 #define MAXPATHLEN          256
00012
00013 #define ID_XFROM              2000
00014 #define ID_XTO                2001
00015 #define ID_YFROM              2002
00016 #define ID_YTO                2003
00017 #define ID_SAVEAS             2004
00018 #define ID_ITERATION          2005
00019
00020 extern TCHAR szName[TITLEBARNAMELEN];
00021 extern TCHAR szAppName[APPNAMEBUFFERLEN];
00022 TCHAR szXFrom[MAXDOUBLELEN];
00023 TCHAR szXTo[MAXDOUBLELEN];
00024 TCHAR szYFrom[MAXDOUBLELEN];
00025 TCHAR szYTo[MAXDOUBLELEN];
00026 TCHAR szSaveFile[MAXPATHLEN];
00027 extern TCHAR szIniFile[MAXFILELEN];
00028 TCHAR szIteration[MAXDOUBLELEN];
00029 extern TCHAR szScreenSaver[22];
00030 extern TCHAR szHelpFile[MAXFILELEN];
00031 extern TCHAR szNoHelpMemory[BUFFLEN];
00032 extern UINT  MyHelpMessage;
00033
00034 CHAR  gtext[128];
00035 HPEN   hpnRed;
00036 HPEN   hpnBlack;
00037 HPEN   hpnGreen;
00038
00039
00040
00041 INT    giPen = 0;
00042
00043 BOOL   gFloat = TRUE;
00044 LONG   gStep = 1;
00045 LONG   gIteration = 500;
00046 BOOL   gbStretch = TRUE;
00047 INT    giStretchMode = COLORONCOLOR;
00048 INT    giDmOrient = DMORIENT_PORTRAIT;
00049 INT    giNPrinters = 0;
00050
00051 typedef struct _PerWndInfo {
00052     HWND    hwnd;               // hJulia or hView, the drawing surface
00053     HANDLE  hThrd;              // handle to drawing thread or play thread
00054     BOOL    bDrawing;           // curently drawing?
00055     DWORD   dwThreadId;         // drawing thread or play thread ID
00056     DWORD   dwElapsed;          // elapsed time for the drawing operation
00057     double  xFrom;              // drawing range in floating points
00058     double  xTo;                //
00059     double  yFrom;              //         Floating Points
00060     double  yTo;                //
00061     double  c1;                 // C = c1 + i c2 where c1, c2 are reals
00062     double  c2;                 // the C value corresponding to the Julia set
00063     LONG    lxFrom;             // drawing range in fix points
00064     LONG    lxTo;               //
00065     LONG    lyFrom;             //         Fix Points
00066     LONG    lyTo;               //
00067     LONG    lc1;                // C = c1 + i c2 where c1, c2 are reals
00068     LONG    lc2;                // the C value corresponding to the Julia set
00069     HBITMAP hBmpSaved;          // saved bitmap for the drawing
00070     BOOL    bMandel;            // Drawing is a Mandelbrot or Julia set?
00071     int     iIteration;         // number of computations done on each pixel
00072     int     iStep;              // drawn on every one, two or three line(s)?
00073     BOOL    bStretch;           // stretching bitmaps
00074     int     iStretchMode;       // stretching mode to use
00075     BOOL    bSetDIBsToDevice;   // SetDIBsToDevice reather than BitBlt?
00076     HPALETTE    hPal;           // The palette used for the drawing
00077     HPALETTE    hHTPal;         // The halftone palette used for the drawing
00078     PVOID   *prghPen;
00079     INT     iPen;
00080     char    szSavef[MAXPATHLEN];
00081     BOOL    bClrCycle;
00082 } INFO, *PINFO;
00083
00084 INFO  gInfo;
00085
00086
00087 //
00088 // Handy macros for the transformations used in fractal generations
00089 //
00090 #define Xform(Pt, SrcFrom, SrcTo, DestFrom, DestTo) \
00091          (((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom))+DestFrom)
00092 #define Xform2(Pt, SrcFrom, SrcTo, DestFrom, DestTo) \
00093          ((int) ((Pt-SrcFrom)/(SrcTo-SrcFrom)*(DestTo-DestFrom)+DestFrom))
00094 #define XformFix(Pt, SrcFrom, SrcTo, DestFrom, DestTo) \
00095          (lMul(lDiv(Pt-SrcFrom,SrcTo-SrcFrom), DestTo-DestFrom)+DestFrom)
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CPL/STEREO.H Source File

  • CPL

STEREO.H

Go to the documentation of this file.
00001 #define CPCAPTION      1
00002
00003 #define AMP_ICON     100
00004 #define AMP_NAME     101
00005 #define AMP_DESC     102
00006 #define AMP_DLG      103
00007
00008 #define TUNER_ICON   200
00009 #define TUNER_NAME   201
00010 #define TUNER_DESC   202
00011 #define TUNER_DLG    203
00012
00013 #define TAPE_ICON    300
00014 #define TAPE_NAME    301
00015 #define TAPE_DESC    302
00016 #define TAPE_DLG     303
00017
00018
00019 // function prototypes
00020 LONG CALLBACK CPlApplet(HWND, UINT, LONG, LONG);
00021 BOOL APIENTRY AmpDlgProc(HWND, UINT, UINT, LONG);
00022 BOOL APIENTRY TunerDlgProc(HWND, UINT, UINT, LONG);
00023 BOOL APIENTRY TapeDlgProc(HWND, UINT, UINT, LONG);
00024
00025 
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PLATFORM/PLATFORM.H Source File

  • PLATFORM

PLATFORM.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDM_ABOUT 100
00013 #define IDM_PLATFORM 200
00014
00015 int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
00016 BOOL InitApplication(HANDLE);
00017 BOOL InitInstance(HANDLE, int);
00018 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00019 BOOL CALLBACK About(HWND, UINT, WPARAM, LPARAM);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/THE_DLL.C Source File

  • SIMPLDLL

THE_DLL.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  MODULE:      THE_DLL.C
00015 *
00016 *  PURPOSE:     To provide a simple DLL template. This module contains a
00017 *               generic DLL entry point (replacing the LIbMain & WEP of
00018 *               Win16), four exported skeleton functions with varying
00019 *               parameter lists, and one exported "DLLDialogBox" function
00020 *               which loads a dialog template from the attached resource
00021 *               file.
00022 *
00023 *  FUNCTIONS:   DllMain() - DLL entry point
00024 *               DLLFunction1()  - skeleton function with no inputs
00025 *               DLLFunction2()  - skeleton function with int input
00026 *               DLLFunction3()  - skeleton function with HANDLE input
00027 *               DLLFunction4()  - skeleton function with HWND input
00028 *               DLLDialogBox()  - calls DialogBox using hndParent param
00029 *               DLLDlgProc()    - dialog window procedure
00030 *
00031 *  COMMENTS:    Another name may be used for the entry point
00032 *               ("DllMain" is only an example). If no initialization
00033 *               or notification is required in a DLL, the DLL entry point
00034 *               may be omitted. In either case, make sure to modify the
00035 *               "-entry:DllMain" part of the DLL's link line in the
00036 *               makefile; either substitute the new entry point name, or
00037 *               delete the line altogether (if omitting the entry point).
00038 *
00039 \******************************************************************************/
00040
00041 #include <windows.h>
00042 #include "the_dll.h"
00043
00044
00045
00046 /******************************************************************************\
00047 *
00048 *  FUNCTION:    DllMain
00049 *
00050 *  INPUTS:      hDLL       - handle of DLL
00051 *               dwReason   - indicates why DLL called
00052 *               lpReserved - reserved
00053 *
00054 *  RETURNS:     TRUE (always, in this example.)
00055 *
00056 *               Note that the retuRn value is used only when
00057 *               dwReason = DLL_PROCESS_ATTACH.
00058 *
00059 *               Normally the function would return TRUE if DLL initial-
00060 *               ization succeeded, or FALSE it it failed.
00061 *
00062 *  GLOBAL VARS: ghMod - handle of DLL (initialized when PROCESS_ATTACHes)
00063 *
00064 *  COMMENTS:    The function will display a dialog box informing user of
00065 *               each notification message & the name of the attaching/
00066 *               detaching process/thread. For more information see
00067 *               "DllMain" in the Win32 API reference.
00068 *
00069 \******************************************************************************/
00070
00071 BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
00072 {
00073   switch (dwReason)
00074   {
00075     case DLL_PROCESS_ATTACH:
00076     {
00077       char buf[BUFSIZE+1];
00078
00079       //
00080       // DLL is attaching to the address space of the current process.
00081       //
00082
00083       ghMod = hDLL;
00084       GetModuleFileName (NULL, (LPTSTR) buf, BUFSIZE);
00085       MessageBox ( GetFocus(),
00086                   (LPCTSTR) buf,
00087                   (LPCTSTR) "THE_DLL: Process attaching",
00088                   MB_OK | MB_SYSTEMMODAL);
00089       break;
00090     }
00091
00092     case DLL_THREAD_ATTACH:
00093
00094       //
00095       // A new thread is being created in the current process.
00096       //
00097
00098       MessageBox ( GetFocus(),
00099                   (LPCTSTR) "THE_DLL: Thread attaching",
00100                   (LPCTSTR) "",
00101                   MB_OK | MB_SYSTEMMODAL);
00102       break;
00103
00104     case DLL_THREAD_DETACH:
00105
00106       //
00107       // A thread is exiting cleanly.
00108       //
00109
00110       MessageBox ( GetFocus(),
00111                   (LPCTSTR) "THE_DLL: Thread detaching",
00112                   (LPCTSTR) "",
00113                   MB_OK | MB_SYSTEMMODAL);
00114       break;
00115
00116     case DLL_PROCESS_DETACH:
00117
00118       //
00119       // The calling process is detaching the DLL from its address space.
00120       //
00121       MessageBox ( GetFocus(),
00122                   (LPCTSTR) "THE_DLL: Process detaching",
00123                   (LPCTSTR) "",
00124                   MB_OK | MB_SYSTEMMODAL );
00125       break;
00126   }
00127
00128 return TRUE;
00129 }
00130
00131
00132
00133 /******************************************************************************\
00134 *
00135 *  FUNCTION: DLLFunction1
00136 *
00137 *  RETURNS:  1
00138 *
00139 \******************************************************************************/
00140
00141 INT DLLFunction1 ()
00142 {
00143   MessageBeep (0);
00144   return 1;
00145 }
00146
00147
00148
00149 /******************************************************************************\
00150 *
00151 *  FUNCTION: DLLFunction2
00152 *
00153 *  INPUTS:   i - a dummy int param
00154 *
00155 *  RETURNS:  1
00156 *
00157 \******************************************************************************/
00158
00159 INT DLLFunction2 (int i)
00160 {
00161   MessageBeep (0);
00162   return 1;
00163 }
00164
00165
00166
00167 /******************************************************************************\
00168 *
00169 *  FUNCTION: DLLFunction3
00170 *
00171 *  INPUTS:   h - a dummy HANDLE param
00172 *
00173 *  RETURNS:  1
00174 *
00175 \******************************************************************************/
00176
00177 INT DLLFunction3 (HANDLE h)
00178 {
00179   MessageBeep (0);
00180   return 1;
00181 }
00182
00183
00184
00185 /******************************************************************************\
00186 *
00187 *  FUNCTION: DLLFunction4
00188 *
00189 *  INPUTS:   i - a dummy HWND param
00190 *
00191 *  RETURNS:  1
00192 *
00193 \******************************************************************************/
00194
00195 INT DLLFunction4 (HWND hwnd)
00196 {
00197   MessageBeep (0);
00198   return 1;
00199 }
00200
00201
00202
00203 /******************************************************************************\
00204 *
00205 *  FUNCTION: DLLDialogBox
00206 *
00207 *  INPUTS:   hwndPArent - parent of the dialog box to display
00208 *
00209 *  RETURNS:  1
00210 *
00211 \******************************************************************************/
00212
00213 INT DLLDialogBox (HWND hwndParent)
00214 {
00215   DialogBox (ghMod, (LPCTSTR) "DLLDlg", hwndParent, (DLGPROC) DLLDlgProc);
00216   return 1;
00217 }
00218
00219
00220
00221 /******************************************************************************\
00222 *
00223 *  FUNCTION: DLLDlgProc (standard dialog procedure INPUTS/RETURNS)
00224 *
00225 \******************************************************************************/
00226
00227 BOOL CALLBACK DLLDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
00228 {
00229   switch (msg)
00230   {
00231     case WM_COMMAND:
00232
00233       EndDialog(hDlg, TRUE);
00234       return (TRUE);
00235   }
00236   return (FALSE);
00237 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/DISPATCH.C Source File

  • SERVENUM
  • DEMO

DISPATCH.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   dispatch.c
00009 //
00010 //  PURPOSE:  Implement the generic message and command dispatchers.
00011 //
00012 //
00013 //  FUNCTIONS:
00014 //    DispMessage - Call the function associated with a message.
00015 //    DispCommand - Call the function associated with a command.
00016 //    DispDefault - Call the appropriate default window procedure.
00017 //
00018 //  COMMENTS:
00019 //
00020
00021 #include <windows.h>            // required for all Windows applications
00022 #include <windowsx.h>
00023 #include "globals.h"            // prototypes specific to this application
00024
00025 LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
00026
00027 //
00028 //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
00029 //
00030 //  PURPOSE: Call the function associated with a message.
00031 //
00032 //  PARAMETERS:
00033 //    lpmsdi - Structure containing the message dispatch information.
00034 //    hwnd - The window handle
00035 //    uMessage - The message number
00036 //    wparam - Message specific data
00037 //    lparam - Message specific data
00038 //
00039 //  RETURN VALUE:
00040 //    The value returned by the message function that was called.
00041 //
00042 //  COMMENTS:
00043 //    Runs the table of messages stored in lpmsdi->rgmsd searching
00044 //    for a message number that matches uMessage.  If a match is found,
00045 //    call the associated function.  Otherwise, call DispDefault to
00046 //    call the default function, if any, associated with the message
00047 //    structure.  In either case, return the value recieved from the
00048 //    message or default function.
00049 //
00050
00051 LRESULT DispMessage(LPMSDI lpmsdi,
00052                     HWND   hwnd,
00053                     UINT   uMessage,
00054                     WPARAM wparam,
00055                     LPARAM lparam)
00056 {
00057     int  imsd = 0;
00058
00059     MSD *rgmsd = lpmsdi->rgmsd;
00060     int  cmsd  = lpmsdi->cmsd;
00061
00062     for (imsd = 0; imsd < cmsd; imsd++)
00063     {
00064         if (rgmsd[imsd].uMessage == uMessage)
00065             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
00066     }
00067
00068     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
00069 }
00070
00071 //
00072 //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
00073 //
00074 //  PURPOSE: Call the function associated with a command.
00075 //
00076 //  PARAMETERS:
00077 //    lpcmdi - Structure containing the command dispatch information.
00078 //    hwnd - The window handle
00079 //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
00080 //      control, or accelerator.
00081 //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
00082 //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
00083 //
00084 //  RETURN VALUE:
00085 //    The value returned by the command function that was called.
00086 //
00087 //  COMMENTS:
00088 //    Runs the table of commands stored in lpcmdi->rgcmd searching
00089 //    for a command number that matches wCommand.  If a match is found,
00090 //    call the associated function.  Otherwise, call DispDefault to
00091 //    call the default function, if any, associated with the command
00092 //    structure.  In either case, return the value recieved from the
00093 //    command or default function.
00094 //
00095
00096
00097 LRESULT DispCommand(LPCMDI lpcmdi,
00098                     HWND   hwnd,
00099                     WPARAM wparam,
00100                     LPARAM lparam)
00101 {
00102     LRESULT lRet = 0;
00103     WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
00104     int     icmd;
00105
00106     CMD    *rgcmd = lpcmdi->rgcmd;
00107     int     ccmd  = lpcmdi->ccmd;
00108
00109     // Message packing of wparam and lparam have changed for Win32,
00110     // so use the GET_WM_COMMAND macro to unpack the commnad
00111
00112     for (icmd = 0; icmd < ccmd; icmd++)
00113     {
00114         if (rgcmd[icmd].wCommand == wCommand)
00115         {
00116             return rgcmd[icmd].pfncmd(hwnd,
00117                                       wCommand,
00118                                       GET_WM_COMMAND_CMD(wparam, lparam),
00119                                       GET_WM_COMMAND_HWND(wparam, lparam));
00120         }
00121     }
00122
00123     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
00124 }
00125
00126
00127 //
00128 //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
00129 //
00130 //  PURPOSE: Call the appropriate default window procedure.
00131 //
00132 //  PARAMETERS:
00133 //    edwp - Enumerate specifying the appropriate default winow procedure.
00134 //    hwnd - The window handle
00135 //    uMessage - The message number
00136 //    wparam - Message specific data
00137 //    lparam - Message specific data
00138 //
00139 //  RETURN VALUE:
00140 //    If there is a default proc, return the value returned by the
00141 //    default proc.  Otherwise, return 0.
00142 //
00143 //  COMMENTS:
00144 //    Calls the default procedure associated with edwp using the specified
00145 //    parameters.
00146 //
00147
00148 LRESULT DispDefault(EDWP   edwp,
00149                     HWND   hwnd,
00150                     UINT   uMessage,
00151                     WPARAM wparam,
00152                     LPARAM lparam)
00153 {
00154     switch (edwp)
00155     {
00156         case edwpNone:
00157             return 0;
00158         case edwpWindow:
00159             return DefWindowProc(hwnd, uMessage, wparam, lparam);
00160         case edwpDialog:
00161             return DefDlgProc(hwnd, uMessage, wparam, lparam);
00162         case edwpMDIFrame:
00163             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
00164         case edwpMDIChild:
00165             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
00166     }
00167     return 0;
00168 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: HOOKS/HOOKTEST.C Source File

  • HOOKS

HOOKTEST.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #include <windows.h>    // includes basic windows functionality
00013 #include <stdio.h>      // includes standard file i/o functionality
00014 #include <string.h>     // includes string functions
00015 #include "hooktest.h"
00016
00017 #define NUMHOOKS 7
00018
00019 /* Global variables */
00020
00021 typedef struct _MYHOOKDATA {
00022     int nType;
00023     HOOKPROC hkprc;
00024     HHOOK hhook;
00025 } MYHOOKDATA;
00026
00027 MYHOOKDATA myhookdata[NUMHOOKS];
00028
00029 HWND         hwndMain;
00030 HANDLE       hInst;
00031
00032
00033 /****************************************************************************
00034 *
00035 *    FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00036 *
00037 *    PURPOSE: calls initialization function, processes message loop
00038 *
00039 *    COMMENTS:
00040 *
00041 *
00042 ****************************************************************************/
00043
00044 int APIENTRY WinMain(
00045     HINSTANCE hInstance,
00046     HINSTANCE hPrevInstance,
00047     LPSTR lpCmdLine,
00048     int nCmdShow
00049     )
00050 {
00051
00052     MSG msg;                         /* message                      */
00053
00054         if (!InitApplication(hInstance)) /* Initialize shared things */
00055             return (FALSE);              /* Exits if unable to initialize     */
00056
00057     hInst = hInstance;
00058
00059     /* Perform initializations that apply to a specific instance */
00060
00061     if (!InitInstance(hInstance, nCmdShow))
00062         return (FALSE);
00063
00064     // register window message for FindText() and ReplaceText() hook procs
00065     /* Acquire and dispatch messages until a WM_QUIT message is received. */
00066
00067     while (GetMessage(&msg,        /* message structure                      */
00068             NULL,                  /* handle of window receiving the message */
00069             0,                     /* lowest message to examine              */
00070             0))                    /* highest message to examine             */
00071         {
00072         TranslateMessage(&msg);    /* Translates virtual key codes           */
00073         DispatchMessage(&msg);     /* Dispatches message to window           */
00074     }
00075     return (msg.wParam);           /* Returns the value from PostQuitMessage */
00076
00077     // avoid compiler warnings at W3
00078     lpCmdLine;
00079     hPrevInstance;
00080 }
00081
00082
00083 /****************************************************************************
00084 *
00085 *    FUNCTION: InitApplication(HANDLE)
00086 *
00087 *    PURPOSE: Initializes window data and registers window class
00088 *
00089 *    COMMENTS:
00090 *
00091 *        In this function, we initialize a window class by filling out a data
00092 *        structure of type WNDCLASS and calling the Windows RegisterClass()
00093 *        function.
00094 *
00095 ****************************************************************************/
00096
00097 BOOL InitApplication(HANDLE hInstance)       /* current instance             */
00098 {
00099     WNDCLASS  wc;
00100
00101     /* Fill in window class structure with parameters that describe the       */
00102     /* main window.                                                           */
00103
00104     wc.style = 0;                       /* Class style(s).                    */
00105     wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
00106                                         /* windows of this class.             */
00107     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
00108     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
00109     wc.hInstance = hInstance;           /* Application that owns the class.   */
00110     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00111     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00112     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00113     wc.lpszMenuName =  "HookMenu";   /* Name of menu resource in .RC file. */
00114     wc.lpszClassName = "HookWClass"; /* Name used in call to CreateWindow. */
00115
00116     /* Register the window class and return success/failure code. */
00117
00118     return (RegisterClass(&wc));
00119
00120 }
00121
00122
00123 /****************************************************************************
00124 *
00125 *    FUNCTION:  InitInstance(HANDLE, int)
00126 *
00127 *    PURPOSE:  Saves instance handle and creates main window
00128 *
00129 *    COMMENTS:
00130 *
00131 *        In this function, we save the instance handle in a static variable and
00132 *        create and display the main program window.
00133 *
00134 ****************************************************************************/
00135
00136 BOOL InitInstance(
00137     HANDLE          hInstance,          /* Current instance identifier.       */
00138     int             nCmdShow)           /* Param for first ShowWindow() call. */
00139 {
00140
00141     /* Save the instance handle in static variable, which will be used in  */
00142     /* many subsequence calls from this application to Windows.            */
00143
00144     hInst = hInstance;
00145
00146     /* Create a main window for this application instance.  */
00147
00148     hwndMain = CreateWindow(
00149         "HookWClass",                 /* See RegisterClass() call.          */
00150         "Hooks Sample Application",   /* Text for window title bar.         */
00151         WS_OVERLAPPEDWINDOW,            /* Window style.                      */
00152         CW_USEDEFAULT,                  /* Default horizontal position.       */
00153         CW_USEDEFAULT,                  /* Default vertical position.         */
00154         CW_USEDEFAULT,                  /* Default width.                     */
00155         CW_USEDEFAULT,                  /* Default height.                    */
00156         NULL,                           /* Overlapped windows have no parent. */
00157         NULL,                           /* Use the window class menu.         */
00158         hInstance,                      /* This instance owns this window.    */
00159         NULL                            /* Pointer not needed.                */
00160     );
00161
00162     /* If window could not be created, return "failure" */
00163
00164     if (!hwndMain)
00165         return (FALSE);
00166
00167     /* Make the window visible; update its client area; and return "success" */
00168
00169     ShowWindow(hwndMain, nCmdShow);  /* Show the window                        */
00170     UpdateWindow(hwndMain);          /* Sends WM_PAINT message                 */
00171     return (TRUE);               /* Returns the value from PostQuitMessage */
00172
00173 }
00174
00175 /****************************************************************************
00176 *
00177 *    FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
00178 *
00179 *    PURPOSE:  Processes messages
00180 *
00181 *    COMMENTS:
00182 *
00183 *        This function processes all messages sent to the window.  When the
00184 *        user chooses one of the options from one of the menus, the command
00185 *        is processed here and passed onto the function for that command.
00186 *        This function also processes the special "FindReplace" message that
00187 *        this application registers for hook processing of the FindText()
00188 *        and ReplaceText() common dialog functions.
00189 *
00190 ****************************************************************************/
00191
00192
00193
00194 LONG APIENTRY MainWndProc(hwndMain, uMsg, wParam, lParam)
00195 HWND hwndMain;
00196 UINT uMsg;
00197 UINT wParam;
00198 LONG lParam;
00199 {
00200     static BOOL aHooks[NUMHOOKS];
00201     int index;
00202     static HMENU hmenu;
00203
00204
00205     switch (uMsg) {
00206         case WM_CREATE:
00207
00208             /* Save the menu handle. */
00209
00210             hmenu = GetMenu(hwndMain);
00211
00212             /*
00213              * Initialize structures with hook data. The menu-item
00214              * identifiers are defined as 0 through 6 in the
00215              * header file. They can be used to identify array
00216              * elements both here and during the WM_COMMAND
00217              * message.
00218              */
00219
00220             myhookdata[IDM_CALLWNDPROC].nType = WH_CALLWNDPROC;
00221             myhookdata[IDM_CALLWNDPROC].hkprc = CallWndProc;
00222
00223             myhookdata[IDM_CBT].nType = WH_CBT;
00224             myhookdata[IDM_CBT].hkprc = CBTProc;
00225             myhookdata[IDM_DEBUG].nType = WH_DEBUG;
00226             myhookdata[IDM_DEBUG].hkprc = DebugProc;
00227             myhookdata[IDM_GETMESSAGE].nType = WH_GETMESSAGE;
00228             myhookdata[IDM_GETMESSAGE].hkprc = GetMsgProc;
00229             myhookdata[IDM_KEYBOARD].nType = WH_KEYBOARD;
00230
00231             myhookdata[IDM_KEYBOARD].hkprc = KeyboardProc;
00232             myhookdata[IDM_MOUSE].nType = WH_MOUSE;
00233             myhookdata[IDM_MOUSE].hkprc = MouseProc;
00234             myhookdata[IDM_MSGFILTER].nType = WH_MSGFILTER;
00235             myhookdata[IDM_MSGFILTER].hkprc = MessageProc;
00236
00237             /* Initialize all flags in the array to FALSE. */
00238             memset(aHooks, FALSE, sizeof(aHooks));
00239
00240             return 0;
00241
00242         case WM_COMMAND:
00243
00244             switch (LOWORD(wParam)) {
00245
00246                 case IDM_EXIT:
00247                     PostQuitMessage(0);
00248                     break;
00249
00250                 /*
00251                  * The user selected a hook command from the menu.
00252                  */
00253
00254                 case IDM_CALLWNDPROC:
00255                 case IDM_CBT:
00256                 case IDM_DEBUG:
00257                 case IDM_GETMESSAGE:
00258                 case IDM_KEYBOARD:
00259                 case IDM_MOUSE:
00260                 case IDM_MSGFILTER:
00261
00262                     /*
00263                      * Use the menu-item identifier as an index
00264                      * into the array of structures with hook data.
00265
00266                      */
00267
00268                     index = LOWORD(wParam);
00269
00270                     /*
00271                      * If the selected type of hook procedure isn't
00272                      * installed yet, install it and check the
00273                      * associated menu item.
00274                      */
00275
00276                     if (!aHooks[index]) {
00277                         myhookdata[index].hhook = SetWindowsHookEx(
00278                             myhookdata[index].nType,
00279                             myhookdata[index].hkprc,
00280                             (HINSTANCE) NULL, GetCurrentThreadId());
00281                         CheckMenuItem(hmenu, index,
00282                             MF_BYCOMMAND | MF_CHECKED);
00283                         aHooks[index] = TRUE;
00284                     }
00285
00286                     /*
00287                      * If the selected type of hook procedure is
00288                      * already installed, remove it and remove the
00289                      * check mark from the associated menu item.
00290                      */
00291
00292
00293                     else {
00294                         UnhookWindowsHookEx(myhookdata[index].hhook);
00295                         CheckMenuItem(hmenu, index,
00296                             MF_BYCOMMAND | MF_UNCHECKED);
00297                         aHooks[index] = FALSE;
00298                         InvalidateRect(hwndMain, NULL, TRUE);
00299                         UpdateWindow(hwndMain);
00300                     }
00301
00302            }
00303             break;
00304
00305              case WM_DESTROY:
00306                  PostQuitMessage(0);
00307                  break;
00308
00309         default:
00310             return DefWindowProc(hwndMain, uMsg, wParam, lParam);
00311     }
00312     return 0;
00313 }
00314
00315 /****************************************************************
00316   WH_CALLWNDPROC hook procedure
00317  ****************************************************************/
00318
00319 LRESULT CALLBACK CallWndProc(nCode, wParam, lParam)
00320 int nCode;
00321 WPARAM wParam;
00322 LPARAM lParam;
00323 {
00324     CHAR szCWPBuf[256];
00325     HDC hdc;
00326
00327     static int c = 0;
00328     int cch;
00329
00330     if (nCode < 0)  /* do not process message */
00331         return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
00332                 wParam, lParam);
00333
00334     hdc = GetDC(hwndMain);
00335
00336     switch (nCode) {
00337         case HC_ACTION:
00338             cch = wsprintf(szCWPBuf,
00339                "CALLWNDPROC - tsk: %ld, msg: %d, %d times %20s",
00340                 wParam, nCode, c++, "" );
00341             TextOut(hdc, 2, 15, szCWPBuf, cch);
00342             break;
00343
00344         default:
00345             break;
00346     }
00347
00348     ReleaseDC(hwndMain, hdc);
00349     return CallNextHookEx(myhookdata[IDM_CALLWNDPROC].hhook, nCode,
00350         wParam, lParam);
00351 }
00352
00353 /****************************************************************
00354   WH_GETMESSAGE hook procedure
00355  ****************************************************************/
00356
00357 LRESULT CALLBACK GetMsgProc(nCode, wParam, lParam)
00358 int nCode;
00359 WPARAM wParam;
00360
00361 LPARAM lParam;
00362 {
00363     CHAR szMSGBuf[256];
00364     CHAR szRem[16];
00365     HDC hdc;
00366     static int c = 0;
00367     int cch;
00368
00369     if (nCode < 0) /* do not process message */
00370         return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
00371             wParam, lParam);
00372
00373     switch (nCode) {
00374         case HC_ACTION:
00375             switch (wParam) {
00376                 case PM_REMOVE:
00377                     lstrcpy(szRem, "PM_REMOVE");
00378                     break;
00379
00380                 case PM_NOREMOVE:
00381                     lstrcpy(szRem, "PM_NOREMOVE");
00382                     break;
00383
00384                 default:
00385                     lstrcpy(szRem, "Unknown");
00386                     break;
00387             }
00388
00389             hdc = GetDC(hwndMain);
00390
00391             cch = wsprintf(szMSGBuf,
00392                 "GETMESSAGE - wParam: %s, msg: %d, %d times %20s",
00393                 szRem, nCode, c++, "");
00394             TextOut(hdc, 2, 35, szMSGBuf, cch);
00395             break;
00396
00397         default:
00398             break;
00399     }
00400
00401     ReleaseDC(hwndMain, hdc);
00402     return CallNextHookEx(myhookdata[IDM_GETMESSAGE].hhook, nCode,
00403         wParam, lParam);
00404 }
00405
00406 /****************************************************************
00407   WH_DEBUG hook procedure
00408  ****************************************************************/
00409
00410 LRESULT CALLBACK DebugProc(nCode, wParam, lParam)
00411
00412 int nCode;
00413 WPARAM wParam;
00414 LPARAM lParam;
00415 {
00416     CHAR szBuf[128];
00417     HDC hdc;
00418     static int c = 0;
00419     int cch;
00420
00421     if (nCode < 0)  /* do not process message */
00422         return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode,
00423             wParam, lParam);
00424
00425     hdc = GetDC(hwndMain);
00426
00427     switch (nCode) {
00428         case HC_ACTION:
00429             cch = wsprintf(szBuf,
00430                 "DEBUG - nCode: %d, tsk: %ld, %d times %20s",
00431                 nCode,wParam, c++, "");
00432             TextOut(hdc, 2, 55, szBuf, cch);
00433             break;
00434
00435         default:
00436             break;
00437     }
00438
00439     ReleaseDC(hwndMain, hdc);
00440     return CallNextHookEx(myhookdata[IDM_DEBUG].hhook, nCode, wParam,
00441         lParam);
00442 }
00443
00444 /****************************************************************
00445   WH_CBT hook procedure
00446  ****************************************************************/
00447
00448 LRESULT CALLBACK CBTProc(nCode, wParam, lParam)
00449 int nCode;
00450 WPARAM wParam;
00451 LPARAM lParam;
00452
00453 {
00454     CHAR szBuf[128];
00455     CHAR szCode[128];
00456     HDC hdc;
00457     static int c = 0;
00458     int cch;
00459
00460     if (nCode < 0)  /* do not process message */
00461         return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
00462             lParam);
00463
00464     hdc = GetDC(hwndMain);
00465
00466     switch (nCode) {
00467         case HCBT_ACTIVATE:
00468             lstrcpy(szCode, "HCBT_ACTIVATE");
00469             break;
00470
00471         case HCBT_CLICKSKIPPED:
00472             lstrcpy(szCode, "HCBT_CLICKSKIPPED");
00473             break;
00474
00475         case HCBT_CREATEWND:
00476             lstrcpy(szCode, "HCBT_CREATEWND");
00477             break;
00478
00479         case HCBT_DESTROYWND:
00480             lstrcpy(szCode, "HCBT_DESTROYWND");
00481             break;
00482
00483         case HCBT_KEYSKIPPED:
00484             lstrcpy(szCode, "HCBT_KEYSKIPPED");
00485             break;
00486
00487         case HCBT_MINMAX:
00488             lstrcpy(szCode, "HCBT_MINMAX");
00489             break;
00490
00491         case HCBT_MOVESIZE:
00492             lstrcpy(szCode, "HCBT_MOVESIZE");
00493             break;
00494
00495         case HCBT_QS:
00496             lstrcpy(szCode, "HCBT_QS");
00497             break;
00498
00499         case HCBT_SETFOCUS:
00500             lstrcpy(szCode, "HCBT_SETFOCUS");
00501             break;
00502
00503         case HCBT_SYSCOMMAND:
00504
00505             lstrcpy(szCode, "HCBT_SYSCOMMAND");
00506             break;
00507
00508         default:
00509             lstrcpy(szCode, "Unknown");
00510             break;
00511     }
00512
00513     cch = wsprintf(szBuf, "CBT - nCode: %s, tsk: %ld, %d times %20s",
00514         szCode, wParam, c++, "");
00515     TextOut(hdc, 2, 75, szBuf, cch);
00516     ReleaseDC(hwndMain, hdc);
00517     return CallNextHookEx(myhookdata[IDM_CBT].hhook, nCode, wParam,
00518         lParam);
00519 }
00520
00521 /****************************************************************
00522   WH_MOUSE hook procedure
00523
00524  ****************************************************************/
00525
00526 LRESULT CALLBACK MouseProc(nCode, wParam, lParam)
00527 int nCode;
00528 WPARAM wParam;
00529 LPARAM lParam;
00530 {
00531     CHAR szBuf[128];
00532     HDC hdc;
00533     static int c = 0;
00534     int cch;
00535   LPMOUSEHOOKSTRUCT lpMouseHookStruct;
00536
00537     if (nCode < 0)  /* do not process the message */
00538         return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode,
00539             wParam, lParam);
00540
00541
00542     hdc = GetDC(hwndMain);
00543
00544   lpMouseHookStruct = (LPMOUSEHOOKSTRUCT)lParam;
00545     cch = wsprintf(szBuf,
00546         "MOUSE - nCode: %d, msg: %d, x: %d, y: %d, %d times %20s",
00547         nCode, wParam, lpMouseHookStruct->pt.x, lpMouseHookStruct->pt.y,
00548         c++, "" );
00549     TextOut(hdc, 2, 95, szBuf, cch);
00550     ReleaseDC(hwndMain, hdc);
00551     return CallNextHookEx(myhookdata[IDM_MOUSE].hhook, nCode, wParam,
00552
00553         lParam);
00554 }
00555
00556 /****************************************************************
00557   WH_KEYBOARD hook procedure
00558  ****************************************************************/
00559
00560 LRESULT CALLBACK KeyboardProc(nCode, wParam, lParam)
00561 int nCode;
00562 WPARAM wParam;
00563 LPARAM lParam;
00564 {
00565     CHAR szBuf[128];
00566     HDC hdc;
00567     static int c = 0;
00568     int cch;
00569
00570     if (nCode < 0)  /* do not process message */
00571         return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode,
00572             wParam, lParam);
00573
00574     hdc = GetDC(hwndMain);
00575
00576     cch = wsprintf(szBuf, "KEYBOARD - nCode: %d, vk: %d, %d times %20s",
00577         nCode, wParam, c++, "" );
00578     TextOut(hdc, 2, 115, szBuf, cch);
00579     ReleaseDC(hwndMain, hdc);
00580     return CallNextHookEx(myhookdata[IDM_KEYBOARD].hhook, nCode, wParam,
00581         lParam);
00582 }
00583
00584 /****************************************************************
00585   WH_MSGFILTER hook procedure
00586  ****************************************************************/
00587
00588 LRESULT CALLBACK MessageProc(nCode, wParam, lParam)
00589 int nCode;
00590 WPARAM wParam;
00591
00592 LPARAM lParam;
00593 {
00594     CHAR szBuf[128];
00595     CHAR szCode[32];
00596     HDC hdc;
00597     static int c = 0;
00598     int cch;
00599
00600     if (nCode < 0)  /* do not process message */
00601         return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
00602             wParam, lParam);
00603
00604     switch (nCode) {
00605         case MSGF_DIALOGBOX:
00606             lstrcpy(szCode, "MSGF_DIALOGBOX");
00607             break;
00608
00609
00610         case MSGF_MENU:
00611             lstrcpy(szCode, "MSGF_MENU");
00612             break;
00613
00614         case MSGF_SCROLLBAR:
00615             lstrcpy(szCode, "MSGF_SCROLLBAR");
00616             break;
00617
00618         case MSGF_NEXTWINDOW:
00619             lstrcpy(szCode, "MSGF_NEXTWINDOW");
00620             break;
00621
00622         default:
00623             wsprintf(szCode, "Unknown: %d", nCode);
00624             break;
00625     }
00626
00627     hdc = GetDC(hwndMain);
00628     cch = wsprintf(szBuf,
00629         "MSGFILTER  nCode: %s, msg: %d, %d times %20s",
00630         szCode, nCode, c++, "" );
00631     TextOut(hdc, 2, 135, szBuf, cch);
00632     ReleaseDC(hwndMain, hdc);
00633     return CallNextHookEx(myhookdata[IDM_MSGFILTER].hhook, nCode,
00634         wParam, lParam);
00635 }
00636
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CONSOLEC/COLOR.H Source File

  • CONSOLEC

COLOR.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 /************************************************************************\
00014 *                         SYMBOLIC CONSTANTS
00015 \************************************************************************/
00016
00017 #define MAXCOLORS        8
00018 #define BACKGROUND_COLOR 0x00F0
00019
00020 /************************************************************************\
00021 *                          GLOBAL VARIABLES
00022 \************************************************************************/
00023
00024 char* Color[MAXCOLORS] = {
00025   "BLACK",   /* 0                                                       */
00026   "BLUE",    /* 1, FOREGROUND_BLUE                                      */
00027   "GREEN",   /* 2, FOREGROUND_GREEN                                     */
00028   "CYAN",    /* 3, FOREGROUND_BLUE  | FOREGROUND_GREEN                  */
00029   "RED",     /* 4, FOREGROUND_RED                                       */
00030   "MAGENTA", /* 5, FOREGROUND_BLUE  | FOREGROUND_RED                    */
00031   "YELLOW",  /* 6, FOREGROUND_GREEN | FOREGROUND_RED                    */
00032   "GREY",   /* 7, FOREGROUND_BLUE  | FOREGROUND_GREEN | FOREGROUND_RED */
00033 };
00034 /************************************************************************\
00035  * FOREGROUND_INTENSITY & BACKGROUND_INTENSITY control support
00036  * could be easily added to this sample
00037 \************************************************************************/
00038
00039
00040 /************************************************************************\
00041 *                         FUNCTION PROTOTYPES
00042 \************************************************************************/
00043
00044 BOOL Syntax( HANDLE hConsole );
00045 WORD GetConsoleTextAttribute( HANDLE hConsole );
00046 void PrintBanner();
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OWNCOMBO/OWNCOMBO.C Source File

  • OWNCOMBO

OWNCOMBO.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /***************************************************************************
00013  *                                                                         *
00014  *  PROGRAM     : OwnCombo.c                                               *
00015  *                                                                         *
00016  *  PURPOSE     : Illustrates the use of functions and messages for        *
00017  *                combo boxes and owner-draw control styles.               *
00018  *                                                                         *
00019  *  FUNCTIONS   : WinMain                - Creates the app. window and     *
00020  *                                         enters the message loop.        *
00021  *                                                                         *
00022  *                OwnComboInit           - Registers the main window class *
00023  *                                                                         *
00024  *                About                  - Dialog function for the About   *
00025  *                                         dialog.                         *
00026  *                                                                         *
00027  *                OwnComboWndProc        - Window function for app. It     *
00028  *                                         handles the menu selections     *
00029  *                                         and processes the other window  *
00030  *                                         messages.                       *
00031  *                                                                         *
00032  *                DrawEntireItem         - Handles the drawing of a list   *
00033  *                                         list box or combo box item.     *
00034  *                                                                         *
00035  *                HandleSelectionState   - Handles the selecting/deselect- *
00036  *                                         ing of a list box or combo box  *
00037  *                                         item.                           *
00038  *                                                                         *
00039  *                HandleFocusState       - Handles the getting/losing of   *
00040  *                                         the input focus by a list box   *
00041  *                                                                         *
00042  *                ListBoxExample         - Dialog function for the         *
00043  *                                         owner-draw list box example.    *
00044  *                                                                         *
00045  *                ComboBoxExample        - Dialog function for the text    *
00046  *                                         combo dialog.                   *
00047  *                                                                         *
00048  *                OwnerComboBoxExample   - Dialog fubction for the drop-   *
00049  *                                         down-list combobox with         *
00050  *                                         ownerdraw.                      *
00051  *                                                                         *
00052  ***************************************************************************/
00053 #include "windows.h"
00054 #include "owncombo.h"
00055
00056 HANDLE  hInst;
00057
00058 /****************************************************************************
00059  *                                                                          *
00060  *  FUNCTION   : WinMain(HANDLE, HANDLE, LPSTR, int)                        *
00061  *                                                                          *
00062  *  PURPOSE    : Creates the app. window and enters the message loop.       *
00063  *                                                                          *
00064  ****************************************************************************/
00065
00066 int APIENTRY WinMain(
00067     HANDLE hInstance,
00068     HANDLE hPrevInstance,
00069     LPSTR lpCmdLine,
00070     int nCmdShow
00071     )
00072 {
00073
00074     HWND  hWnd;
00075     MSG   msg;
00076
00077     UNREFERENCED_PARAMETER( lpCmdLine );
00078
00079     if (!hPrevInstance)
00080         if (!OwnComboInit (hInstance))
00081             return (0);
00082
00083     hInst = hInstance;
00084
00085     /* Create the app. window */
00086     hWnd = CreateWindow ("owncombo",
00087                          "Owner-draw & Combo Box Example",
00088                          WS_OVERLAPPEDWINDOW,
00089                          CW_USEDEFAULT,
00090                          CW_USEDEFAULT,
00091                          CW_USEDEFAULT,
00092                          CW_USEDEFAULT,
00093                          (HWND) NULL,
00094                          NULL,
00095                          hInstance,
00096                          (LPSTR) NULL);
00097
00098     if (!hWnd)
00099         return (0);
00100
00101     ShowWindow (hWnd, nCmdShow);
00102
00103     while (GetMessage (&msg, NULL, 0, 0)){
00104         TranslateMessage (&msg);
00105         DispatchMessage (&msg);
00106     }
00107
00108     return(msg.wParam);
00109 }
00110
00111
00112 /****************************************************************************
00113  *                                                                          *
00114  *  FUNCTION   : OwnComboInit (hInstance)                                   *
00115  *                                                                          *
00116  *  PURPOSE    : Registers the main window class.                           *
00117  *                                                                          *
00118  *  RETURNS    : TRUE  - if RegisterClass () succeeds.                      *
00119  *               FALSE - if RegisterClass () fails.                         *
00120  *                                                                          *
00121  ****************************************************************************/
00122 BOOL NEAR PASCAL OwnComboInit (HANDLE hInstance)
00123 {
00124     HANDLE     hMemory;
00125     PWNDCLASS  pWndClass;
00126     BOOL       bSuccess;
00127
00128     /* Allocate for and fill class structure. */
00129     hMemory = LocalAlloc (LPTR, sizeof (WNDCLASS));
00130     if(!hMemory){
00131         MessageBox(NULL, "<OwnComboInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
00132         return(FALSE);
00133     }
00134
00135     pWndClass = (PWNDCLASS) LocalLock (hMemory);
00136
00137     pWndClass->style         = 0;
00138     pWndClass->lpfnWndProc   = (WNDPROC) OwnComboWndProc;
00139     pWndClass->hInstance    = hInstance;
00140     pWndClass->hIcon         = LoadIcon (hInstance, "owncombo");
00141     pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
00142     pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
00143     pWndClass->lpszMenuName  = (LPSTR) "OwnComboMenu",
00144     pWndClass->lpszClassName = (LPSTR) "owncombo";
00145
00146     bSuccess = RegisterClass (pWndClass);
00147     LocalUnlock (hMemory);
00148     LocalFree (hMemory);
00149
00150     return (bSuccess);
00151 }
00152
00153 /****************************************************************************
00154  *                                                                          *
00155  *  FUNCTION   : About (hDlg,message, wParam, lParam)                       *
00156  *                                                                          *
00157  *  PURPOSE    : Dialog function for the About... dialog.                   *
00158  *                                                                          *
00159  ****************************************************************************/
00160 BOOL APIENTRY About (
00161     HWND         hDlg,
00162     UINT     message,
00163     UINT         wParam,
00164     LONG         lParam)
00165 {
00166
00167         UNREFERENCED_PARAMETER(lParam);
00168     switch (message){
00169         case WM_INITDIALOG:
00170             return(TRUE);
00171
00172         case WM_COMMAND:
00173             if (LOWORD(wParam) == IDOK){
00174                 EndDialog (hDlg,0);
00175                 return(FALSE);
00176             }
00177             break;
00178
00179         default:
00180             break;
00181     }
00182   return(FALSE);
00183 }
00184
00185
00186 /****************************************************************************
00187  *                                                                          *
00188  *  FUNCTION   : OwnComboWndProc(hWnd, message, wParam, lParam)             *
00189  *                                                                          *
00190  *  PURPOSE    : Window function for the app. It handles menu selections    *
00191  *               and processes window WM_ messages.                         *
00192  *                                                                          *
00193  ****************************************************************************/
00194 LONG APIENTRY OwnComboWndProc (
00195     HWND         hWnd,
00196     UINT     message,
00197     UINT         wParam,
00198     LONG         lParam)
00199 {
00200     FARPROC          lpProc;
00201
00202     switch (message){
00203         case WM_COMMAND:
00204             switch (LOWORD(wParam)){
00205                 case IDM_EXIT:
00206                     DestroyWindow (hWnd);
00207                     break;
00208
00209                 case IDM_ABOUT:
00210                     /* Bring up the about box */
00211                     lpProc = MakeProcInstance ((FARPROC)About, hInst);
00212                     DialogBox (hInst,
00213                                "AboutBox",
00214                                hWnd,
00215                                lpProc);
00216
00217                     FreeProcInstance (lpProc);
00218                     break;
00219
00220                 case IDM_LISTBOX:
00221                     /* Bring up the list box example */
00222                     lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
00223                     DialogBox (hInst,
00224                                "ListBoxDialog",
00225                                hWnd,
00226                                lpProc);
00227                     FreeProcInstance (lpProc);
00228                     break;
00229
00230                 case IDM_MULTILISTBOX:
00231                     /* Bring up the multiple selection list box example */
00232                     lpProc = MakeProcInstance ((FARPROC)ListBoxExample, hInst);
00233                     DialogBox (hInst,
00234                                "MultiListBoxDialog",
00235                                hWnd,
00236                                lpProc);
00237                     FreeProcInstance (lpProc);
00238                     break;
00239
00240                 case IDM_COMBOBOX:
00241                     /* Bring up the combo box example */
00242                     lpProc = MakeProcInstance ((FARPROC)ComboBoxExample, hInst);
00243                     DialogBox (hInst,
00244                                "ComboBoxDialog",
00245                                hWnd,
00246                                lpProc);
00247                     FreeProcInstance (lpProc);
00248                     break;
00249
00250                 case IDM_OWNERCOMBOBOX:
00251                     /* Bring up the owner-draw dropdown list box example */
00252                     lpProc = MakeProcInstance ((FARPROC)OwnerComboBoxExample, hInst);
00253                     DialogBox (hInst,
00254                                "OwnerComboBoxDialog",
00255                                hWnd,
00256                                lpProc);
00257                     FreeProcInstance (lpProc);
00258                     break;
00259             }
00260             break;
00261
00262         case WM_DESTROY:
00263             PostQuitMessage (0);
00264             break;
00265
00266         default:
00267             return(DefWindowProc(hWnd, message, wParam, lParam));
00268     }
00269     return(0);
00270 }
00271
00272 /****************************************************************************
00273  *                                                                          *
00274  *  FUNCTION   : HandleSelectionState(LPDRAWITEMSTRUCT, int)                *
00275  *                                                                          *
00276  *  PURPOSE    : Handles a change in an item selection state. If an item is *
00277  *               selected, a black rectangular frame is drawn around that   *
00278  *               item; if an item is de-selected, the frame is removed.     *
00279  *                                                                          *
00280  *  COMMENT    : The black selection frame is slightly larger than the gray *
00281  *               focus frame so they won't paint over each other.           *
00282  *                                                                          *
00283  ****************************************************************************/
00284 VOID APIENTRY HandleSelectionState(
00285         LPDRAWITEMSTRUCT        lpdis,
00286         INT                     inflate)
00287 {
00288         RECT    rc;
00289         HBRUSH  hbr;
00290
00291         /* Resize rectangle to place selection frame outside of the focus
00292          * frame and the item.
00293          */
00294         CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
00295         InflateRect ((LPRECT)&rc, inflate, inflate);
00296
00297         if (lpdis->itemState & ODS_SELECTED)
00298         {
00299                 /* selecting item -- paint a black frame */
00300                 hbr = GetStockObject(BLACK_BRUSH);
00301         }
00302         else
00303         {
00304                 /* de-selecting item -- remove frame */
00305                 hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
00306         }
00307         FrameRect(lpdis->hDC, (LPRECT)&rc, hbr);
00308         DeleteObject (hbr);
00309 }
00310
00311 /****************************************************************************
00312  *                                                                          *
00313  *  FUNCTION   : HandleFocusState(LPDRAWITEMSTRUCT, int)                    *
00314  *                                                                          *
00315  *  PURPOSE    : Handle a change in item focus state. If an item gains the  *
00316  *               input focus, a gray rectangular frame is drawn around that *
00317  *               item; if an item loses the input focus, the gray frame is  *
00318  *               removed.                                                   *
00319  *                                                                          *
00320  *  COMMENT    : The gray focus frame is slightly smaller than the black    *
00321  *               selection frame so they won't paint over each other.       *
00322  *                                                                          *
00323  ****************************************************************************/
00324 VOID APIENTRY HandleFocusState(
00325         LPDRAWITEMSTRUCT        lpdis,
00326         INT                     inflate)
00327 {
00328         RECT    rc;
00329         HBRUSH  hbr;
00330
00331         /* Resize rectangle to place focus frame between the selection
00332          * frame and the item.
00333          */
00334         CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
00335         InflateRect ((LPRECT)&rc, inflate, inflate);
00336
00337         if (lpdis->itemState & ODS_FOCUS)
00338         {
00339                 /* gaining input focus -- paint a gray frame */
00340                 hbr = GetStockObject(GRAY_BRUSH);
00341         }
00342         else
00343         {
00344                 /* losing input focus -- remove (paint over) frame */
00345                 hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
00346         }
00347         FrameRect(lpdis->hDC, (LPRECT)&rc, hbr);
00348         DeleteObject (hbr);
00349 }
00350
00351 /****************************************************************************
00352  *                                                                          *
00353  *  FUNCTION   : DrawEntireItem(LPDRAWITEMSTRUCT, int)                      *
00354  *                                                                          *
00355  *  PURPOSE    : Draws an item and frames it with a selection frame and/or  *
00356  *               a focus frame when appropriate.                            *
00357  *                                                                          *
00358  ****************************************************************************/
00359 VOID APIENTRY DrawEntireItem(
00360         LPDRAWITEMSTRUCT        lpdis,
00361         INT                     inflate)
00362 {
00363         RECT    rc;
00364         HBRUSH  hbr;
00365
00366         /* Resize rectangle to leave space for frames */
00367         CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
00368         InflateRect ((LPRECT)&rc, inflate, inflate);
00369
00370         /* Create a brush using the value in the item data field (this value
00371          * was initialized when we added the item to the list/combo box using
00372          * LB_ADDSTRING/CB_ADDSTRING) and draw the color in the list/combo box.
00373          */
00374         hbr = CreateSolidBrush (lpdis->itemData);
00375         FillRect (lpdis->hDC, (LPRECT)&rc, hbr);
00376         DeleteObject (hbr);
00377
00378         /* Draw or erase appropriate frames */
00379         HandleSelectionState(lpdis, inflate + 4);
00380         HandleFocusState(lpdis, inflate + 2);
00381 }
00382
00383 /****************************************************************************
00384  *                                                                          *
00385  *  FUNCTION   : ListBoxExample (hDlg, message, wParam, lParam)             *
00386  *                                                                          *
00387  *  PURPOSE    : Dialog function for the owner-draw list box example.       *
00388  *               It sets up the example dialog with the owner-draw list box,*
00389  *               adds the colors to the list box, and handles setting the   *
00390  *               selection and focus for the items.                         *
00391  *                                                                          *
00392  ****************************************************************************/
00393 BOOL APIENTRY ListBoxExample (
00394     HWND hDlg,
00395     UINT message,
00396     UINT wParam,
00397     LONG lParam)
00398 {
00399     LPDRAWITEMSTRUCT    lpdis;
00400     LPMEASUREITEMSTRUCT lpmis;
00401
00402     /* Vars for WM_DRAWITEM */
00403
00404     switch (message){
00405         case WM_COMMAND:
00406             switch (LOWORD(wParam)){
00407                 case IDOK:
00408                    EndDialog (hDlg, 0);
00409                    return (TRUE);
00410                    break;
00411
00412                 /* Clicking any of these buttons adds the corresponding color
00413                  * to the list box. The application-supplied data is the RGB
00414                  * value for the color to be drawn in the listbox.
00415                  */
00416                 case ID_BLACK:
00417                     SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
00418                                  LB_ADDSTRING,
00419                                  0,
00420                                  RGB (0,0,0));
00421                     return(TRUE);
00422                     break;
00423                 case ID_RED:
00424                     SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
00425                                  LB_ADDSTRING,
00426                                  0,
00427                                  RGB (255,0,0));
00428                     return(TRUE);
00429                     break;
00430
00431                 case ID_BLUE:
00432                     SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
00433                                  LB_ADDSTRING,
00434                                  0,
00435                                  RGB (0,0,255));
00436                     return(TRUE);
00437                     break;
00438
00439                 case ID_GREEN:
00440                     SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
00441                                  LB_ADDSTRING,
00442                                  0,
00443                                  RGB (0,255,0));
00444                     return(TRUE);
00445                     break;
00446
00447                 default:
00448                     return(FALSE);
00449                     break;
00450             }
00451
00452         case WM_DRAWITEM:
00453             /* Get pointer to the DRAWITEMSTRUCT */
00454             lpdis = (LPDRAWITEMSTRUCT)lParam;
00455
00456             if (lpdis->itemID == -1)
00457             {
00458                 /* We have a request to draw an item in the list box, yet there
00459                  * are no list box items. This is sent when the user TABS into
00460                  * an empty list box or an empty list box gets the focus. We
00461                  * have to indicate (somehow) that this owner-draw list box has
00462                  * the focus. We do it in response to this message. Note that
00463                  * lpdis->itemData field would be invalid in this instance so
00464                  * we can't allow it to fall into our standard routines.
00465                  */
00466                 HandleFocusState(lpdis, -5);
00467             }
00468             else
00469             {
00470                 switch (lpdis->itemAction)
00471                 {
00472                         case ODA_DRAWENTIRE:
00473                                 DrawEntireItem(lpdis, -7);
00474                                 break;
00475
00476                         case ODA_SELECT:
00477                                 HandleSelectionState(lpdis, -3);
00478                                 break;
00479
00480                         case ODA_FOCUS:
00481                                 HandleFocusState(lpdis, -5);
00482                                 break;
00483                 }
00484             }
00485
00486             /* Return TRUE meaning that we processed this message. */
00487             return(TRUE);
00488             break;
00489
00490         case WM_MEASUREITEM:
00491             lpmis = (LPMEASUREITEMSTRUCT)lParam;
00492
00493             /* All the items are the same height since the list box style is
00494              * LBS_OWNERDRAWFIXED
00495              */
00496             lpmis->itemHeight = 30;
00497             break;
00498
00499         case WM_CLOSE:
00500             EndDialog(hDlg, 0);
00501             return(TRUE);
00502             break;
00503
00504         default:
00505             return(FALSE);
00506     }
00507
00508     return(TRUE);
00509 }
00510
00511 /****************************************************************************
00512  *                                                                          *
00513  *  FUNCTION   : ComboBoxExample(hWnd, message, wParam, lParam)             *
00514  *                                                                          *
00515  *  PURPOSE    : Dialog function for the text combo dialog. The push buttons*
00516  *               send various messages to the combo box and the edit control*
00517  *               when selected. They allow the user to vary data sent with  *
00518  *               each message.                                              *
00519  *                                                                          *
00520  ****************************************************************************/
00521 BOOL APIENTRY ComboBoxExample(
00522     HWND hDlg,
00523     UINT message,
00524     UINT wParam,
00525     LONG lParam)
00526 {
00527
00528     HWND hWndCombo;                  /* Handle to the combo box control */
00529                                      /* in the dialog box window        */
00530     HWND hWndCheckBox;               /* Handle to the Auto Check Box    */
00531     CHAR strSingleEditLine[255];     /* Single line edit control input  */
00532     INT  wIndex, wCount;
00533
00534     /* Get handles to the Combo box and the Check box */
00535     hWndCombo     = GetDlgItem(hDlg, ID_COMBOBOX);
00536     hWndCheckBox  = GetDlgItem(hDlg, ID_STEPSBOX);
00537
00538     switch (message){
00539         case WM_COMMAND:
00540             switch (LOWORD(wParam)){
00541                 case IDOK:
00542                     EndDialog (hDlg,0);
00543                     return(TRUE);
00544
00545                 case ID_UNSLBUTTON:
00546                     /* Selecting this button unselects any selection in the
00547                      * combo box.
00548                      */
00549                     SetDlgItemText (hDlg, ID_TEXT1, "");
00550                     SetDlgItemText (hDlg, ID_TEXT2, "");
00551                     wIndex = (WORD) SendMessage( hWndCombo, CB_GETCURSEL, 0, 0L);
00552                     if (wIndex == CB_ERR)
00553                         MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
00554                     else
00555                         SendMessage (hWndCombo, CB_SETCURSEL, (WPARAM)-1, 0L);
00556                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00557                     break;
00558
00559                 case ID_NUMSELBUTTON:
00560                     /* An integer value is taken from the edit control and an
00561                      * attempt is made to select a combo box entry having this
00562                      * index.
00563                      */
00564                     SetDlgItemText (hDlg, ID_TEXT1, "");
00565                     SetDlgItemText (hDlg, ID_TEXT2, "");
00566                     wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
00567                     wIndex = (INT) GetDlgItemInt (hDlg, ID_SINGLEEDIT, NULL, TRUE);
00568                     if (wIndex >= wCount)
00569                         MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
00570                     else
00571                         SendMessage(hWndCombo, CB_SETCURSEL, wIndex, 0L);
00572                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00573                     break;
00574
00575                 case ID_TXTSELBUTTON:
00576                     /* A text string is taken from the edit control and an
00577                      * attempt is made to select a combo box entry having the
00578                      * string as a prefix.
00579                      */
00580                     SetDlgItemText (hDlg, ID_TEXT1, "");
00581                     SetDlgItemText (hDlg, ID_TEXT2, "");
00582                     GetDlgItemText (hDlg, ID_SINGLEEDIT,
00583                                  (LPSTR)strSingleEditLine, 255);
00584                     wIndex = (WORD) SendMessage (hWndCombo,
00585                                                 CB_SELECTSTRING,
00586                                                 (WPARAM)-1,
00587                                                 (LONG)(LPSTR)strSingleEditLine);
00588                     if (wIndex == CB_ERR)
00589                       MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
00590                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00591                     break;
00592
00593                 case ID_FNDSELBUTTON:
00594                     /* Searches for the text specified in the list of combo
00595                      * entries and returns the index (in combo box) of the
00596                      * first match. The index is displayed in the "Text1"
00597                      * field of the dialog.
00598                      */
00599                     SetDlgItemText (hDlg, ID_TEXT1, "");
00600                     SetDlgItemText (hDlg, ID_TEXT2, "");
00601                     GetDlgItemText (hDlg,
00602                                     ID_SINGLEEDIT,
00603                                     (LPSTR)strSingleEditLine,
00604                                     255);
00605                     wIndex = (WORD)SendMessage (hWndCombo,
00606                                                CB_FINDSTRING,(WPARAM)-1,
00607                                                (LONG)(LPSTR)strSingleEditLine);
00608                     if (wIndex == CB_ERR)
00609                         MessageBox (hDlg, (LPSTR)"Bad Selection", NULL, MB_OK);
00610                     else
00611                         SetDlgItemInt (hDlg, ID_TEXT1, wIndex, FALSE);
00612                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00613                     break;
00614
00615                 case ID_CLRBUTTON:
00616                     /* Clears the combo box of all it's entries */
00617                     SetDlgItemText (hDlg, ID_TEXT1, "");
00618                     SetDlgItemText (hDlg, ID_TEXT2, "");
00619                     wCount = (WORD) SendMessage (hWndCombo, CB_GETCOUNT, 0, 0L);
00620                     if (!wCount)
00621                         MessageBox (hDlg, (LPSTR)"Already clear", NULL, MB_OK);
00622                     else{
00623                         SetDlgItemInt (hDlg, ID_TEXT1, wCount, TRUE);
00624                         SetDlgItemText (hDlg, ID_TEXT2, "Items cleared");
00625                         SendMessage (hWndCombo,CB_RESETCONTENT, 0, 0L);
00626                     }
00627                     SetFocus (GetDlgItem (hDlg,ID_SINGLEEDIT));
00628                     break;
00629
00630                 case ID_ADDBUTTON:
00631                     /* Takes the string specified in the edit control and
00632                      * adds it to the combo box.
00633                      */
00634                     SetDlgItemText (hDlg, ID_TEXT1, "");
00635                     SetDlgItemText (hDlg, ID_TEXT2, "");
00636                     GetDlgItemText (hDlg, ID_SINGLEEDIT, strSingleEditLine, 255);
00637                     SendMessage (hWndCombo,
00638                                  CB_ADDSTRING,
00639                                  0,
00640                                  (LONG)(LPSTR) strSingleEditLine);
00641                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00642                     break;
00643
00644                 case ID_DELETEBUTTON:
00645                     /* Delete the currently selected item from the combo box. */
00646                     SetDlgItemText (hDlg, ID_TEXT1, "");
00647                     SetDlgItemText (hDlg, ID_TEXT2, "");
00648                     wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
00649                     if (SendMessage (hWndCombo, CB_DELETESTRING, wIndex, 0L) == CB_ERR)
00650                         MessageBox (hDlg, (LPSTR)"No Selection", NULL, MB_OK);
00651                     else{
00652                         SetDlgItemText (hDlg, ID_TEXT1, "deleted index #");
00653                         SetDlgItemInt  (hDlg, ID_TEXT2, wIndex, TRUE);
00654                     }
00655                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00656                     break;
00657
00658                 case ID_CBDIRBUTTON:
00659                     /* Appends a directory listing of the current directory
00660                      * to the combo box entries.
00661                      */
00662                     SetDlgItemText (hDlg, ID_TEXT1, "");
00663                     SetDlgItemText (hDlg, ID_TEXT2, "");
00664                     wIndex = (WORD)SendMessage (hWndCombo,
00665                                                CB_DIR,
00666                                                0x10|0x4000,
00667                                                (LONG)(LPSTR)"*.*");
00668                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00669                     break;
00670
00671
00672                 case ID_CPYBUTTON:
00673                     /* Copies the currently selected item in the combo box to
00674                      * the edit control.
00675                      */
00676                     SetDlgItemText (hDlg, ID_TEXT1, "");
00677                     SetDlgItemText (hDlg, ID_TEXT2, "");
00678                     wIndex = (WORD) SendMessage (hWndCombo, CB_GETCURSEL, 0, 0L);
00679                     if (wIndex == CB_ERR)
00680                         MessageBox(hDlg, (LPSTR)"No Selection", NULL, MB_OK);
00681                     else{
00682                         wCount = SendMessage (hWndCombo, CB_GETLBTEXTLEN, wIndex, 0L);
00683                         SendMessage (hWndCombo,
00684                                      CB_GETLBTEXT,
00685                                      wIndex,
00686                                      (LONG)(LPSTR)strSingleEditLine);
00687                         SetDlgItemText(hDlg, ID_SINGLEEDIT,
00688                                        (LPSTR)strSingleEditLine);
00689                         SetDlgItemText(hDlg, ID_TEXT1, "copied index #");
00690                         SetDlgItemInt(hDlg, ID_TEXT2, wIndex, TRUE);
00691                     }
00692                     SetFocus (GetDlgItem (hDlg, ID_SINGLEEDIT));
00693                     break;
00694
00695                 /* When the combo notification box is checked, a message box
00696                  * is flashed showing what notification codes the combo box is
00697                  * returning to the app. in response to the messages sent by
00698                  * the buttons.
00699                  */
00700                 case ID_COMBOBOX:
00701                     if (SendMessage (hWndCheckBox, BM_GETCHECK, 0, 0L)){
00702                         switch (HIWORD(lParam)){
00703                             case (WORD)CBN_ERRSPACE:
00704                               MessageBox (hDlg, (LPSTR)"CB Out of Space",
00705                                          "CB MSG", MB_OK);
00706                               break;
00707
00708                             case CBN_SELCHANGE:
00709                               MessageBox (hDlg, (LPSTR)"CB Sel Change",
00710                                          "CB MSG", MB_OK);
00711                               break;
00712
00713                             case CBN_DBLCLK:
00714                               MessageBox(hDlg, (LPSTR)"CB Double Click",
00715                                          "CB MSG", MB_OK);
00716                               break;
00717
00718                             case CBN_SETFOCUS:
00719                               SetDlgItemText(hDlg, ID_TEXT1, "CB SetFocus");
00720                               break;
00721
00722                             case CBN_KILLFOCUS:
00723                               SetDlgItemText(hDlg, ID_TEXT1, "CB KillFocus");
00724                               break;
00725                         }
00726                     }
00727                     break;
00728
00729                 default:
00730                     return(FALSE);
00731             }
00732             break;
00733
00734         case WM_CLOSE:
00735             EndDialog(hDlg, 0);
00736             return(TRUE);
00737             break;
00738
00739         default:
00740             return(FALSE);
00741     }
00742     return(TRUE);
00743 }
00744
00745
00746 /****************************************************************************
00747  *                                                                          *
00748  *  FUNCTION   : OwnerComboBoxExample(hWnd, message, wParam, lParam)        *
00749  *                                                                          *
00750  *  PURPOSE    : Dialog function for the dropdown list combo box with       *
00751  *               owner-draw.                                                *
00752  *                                                                          *
00753  ****************************************************************************/
00754 BOOL APIENTRY OwnerComboBoxExample (
00755     HWND hDlg,
00756     UINT message,
00757     UINT wParam,
00758     LONG lParam)
00759 {
00760     LPDRAWITEMSTRUCT    lpdis;
00761     LPMEASUREITEMSTRUCT lpmis;
00762
00763     switch (message){
00764         case WM_COMMAND:
00765             switch (LOWORD(wParam)){
00766                 case IDOK:
00767                    EndDialog (hDlg, 0);
00768                    return(TRUE);
00769                    break;
00770
00771                 /* Clicking any of these buttons adds the corresponding color
00772                  * to the combo box. The application-supplied data is the RGB
00773                  * value for the color to be drawn in the listbox.
00774                  */
00775                 case ID_BLACK:
00776                    SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
00777                                 CB_ADDSTRING,
00778                                 0,
00779                                 RGB (0,0,0));
00780                    return(TRUE);
00781                    break;
00782
00783                 case ID_RED:
00784                    SendMessage (GetDlgItem (hDlg, ID_LISTBOX),
00785                                 CB_ADDSTRING,
00786                                 0,
00787                                 RGB (255,0,0));
00788                    return(TRUE);
00789                    break;
00790
00791                 case ID_BLUE:
00792                    SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
00793                                 CB_ADDSTRING,
00794                                 0,
00795                                 RGB (0,0,255));
00796                    return(TRUE);
00797                    break;
00798
00799                 case ID_GREEN:
00800                    SendMessage (GetDlgItem(hDlg, ID_LISTBOX),
00801                                 CB_ADDSTRING,
00802                                 0,
00803                                 RGB (0,255,0));
00804                    return(TRUE);
00805                    break;
00806
00807                 default:
00808                    return(TRUE);
00809                    break;
00810             }
00811
00812         case WM_DRAWITEM:
00813             /* Get pointer to the DRAWITEMSTRUCT */
00814             lpdis = (LPDRAWITEMSTRUCT)lParam;
00815
00816             if (lpdis->itemID == -1){
00817                 /* We have a request to draw an item in the combo box, yet there
00818                  * are no combo box items. This is sent when the user TABS into
00819                  * an empty combo box or an empty combo box gets the focus. We
00820                  * have to indicate (somehow) that this owner-draw combo box has
00821                  * the focus. We do it in response to this message. Note that
00822                  * lpdis->itemData field would be invalid in this instance so
00823                  * we can't allow it to fall into our standard routines.
00824                  */
00825                 HandleFocusState(lpdis, -2);
00826             }
00827             else
00828             {
00829                 switch (lpdis->itemAction)
00830                 {
00831                         case ODA_DRAWENTIRE:
00832                                 DrawEntireItem(lpdis, -4);
00833                                 break;
00834
00835                         case ODA_SELECT:
00836                                 HandleSelectionState(lpdis, 0);
00837                                 break;
00838
00839                         case ODA_FOCUS:
00840                                 HandleFocusState(lpdis, -2);
00841                                 break;
00842                 }
00843             }
00844
00845             /* Return TRUE meaning that we processed this message. */
00846             return(TRUE);
00847             break;
00848
00849         case WM_MEASUREITEM:
00850             lpmis = (LPMEASUREITEMSTRUCT)lParam;
00851
00852             /* All the items are the same height since the combo box is
00853              * CBS_OWNERDRAWFIXED
00854              */
00855             if (lpmis->itemID == -1){
00856                 /* If -1 for item, then we are setting the height of the
00857                  * always visible static item part of the dropdown combo box.
00858                  */
00859                 lpmis->itemHeight = 25;
00860                 return(TRUE);
00861             }
00862             lpmis->itemHeight = 30;
00863             break;
00864
00865         case WM_CLOSE:
00866             EndDialog(hDlg, 0);
00867             return(TRUE);
00868             break;
00869
00870         default:
00871             return(FALSE);
00872     }
00873     return(TRUE);
00874 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DDECBACK.H Source File

  • NETDDE

DDECBACK.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   ddecback.h
00009 //
00010 //  PURPOSE:  contains ddecback declarations
00011 //
00012
00013 #ifndef _DDECBACK_H
00014 #define _DDECBACK_H
00015
00016 #define IDE_SERVERNAME 100
00017
00018 #ifdef WIN16
00019 HDDEDATA CALLBACK __export DdeCallback (UINT iType, UINT iFmt, HCONV hConv,
00020                                HSZ hsz1, HSZ hsz2, HDDEDATA hData,
00021                                DWORD dwData1, DWORD dwData2);
00022
00023 #else
00024 HDDEDATA CALLBACK DdeCallback (UINT iType, UINT iFmt, HCONV hConv,
00025                                HSZ hsz1, HSZ hsz2, HDDEDATA hData,
00026                                DWORD dwData1, DWORD dwData2);
00027
00028 #endif
00029
00030 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSDLL.C Source File

  • TLS

TLSDLL.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************\
00013 * MODULE:       tlsdll.c
00014 /****************************************************************************/
00015
00016
00017 #include "windows.h"
00018 #include "stdlib.h"
00019 #include "string.h"
00020 #include "stdio.h"
00021 #include "tlsdll.h"
00022
00023 #define TLS_MINIMUM_AVAILABLE 64
00024
00025 DWORD TlsIndex;        /* Global TLS index */
00026 int TlsCount=0;        /* a counter for data in TLS storage */
00027 char chTlsCount[3];    /* string for counter values */
00028
00029 /*-----------------------------------------------------------------*/
00030
00031 void ErrorOut(char errstring[30])
00032 /*
00033 Purpose: Print out an meainful error code by means of
00034          GetLastError and printf
00035
00036 Inputs:  errstring - the action that failed, passed by the
00037                      calling proc.
00038
00039 Returns: none
00040
00041 Calls:   GetLastError
00042 */
00043
00044 {
00045 DWORD Error;
00046
00047 Error= GetLastError();
00048 printf("Error on %s = %d\n", errstring, Error);
00049 }
00050
00051 /*-----------------------------------------------------------------*/
00052
00053 BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_being_called, LPVOID lpReserved)
00054
00055 /*
00056 Purpose: Is called by LibEntry, upon entering a dll or detaching
00057          from a DLL.  This function does most of the TLS manipulation.
00058
00059 Inputs:  hInst - not used
00060          ul_reason_being_called - reason DllMain is called
00061
00062
00063 Returns: N/A
00064
00065 Calls:   TlsAlloc - allocate a TLS index
00066          malloc - allocate space for tls storage
00067          TlsSetValue - Store TLS values
00068          TlsFree - free TLS index
00069          TlsRetreive - retreives TLS values, based on index
00070 */
00071
00072 {
00073
00074 LPVOID TlsString;  /* TLS string for storage */
00075
00076
00077 UNREFERENCED_PARAMETER(hInst);
00078 UNREFERENCED_PARAMETER(lpReserved);
00079
00080 switch (ul_reason_being_called)
00081   {
00082   case DLL_PROCESS_ATTACH:           /* process attaches         */
00083     printf("Process Attaching\n");
00084     TlsIndex= TlsAlloc();            /* create TLS index         */
00085     if (TlsIndex == 0xFFFFFFFF)
00086       ErrorOut("TlsAlloc");
00087     break;
00088
00089   case DLL_THREAD_ATTACH:            /* thread attaches          */
00090     if (!(DLL_PROCESS_ATTACH & ul_reason_being_called))
00091     {
00092     printf("Thread Attaching\n");
00093     TlsCount++;
00094     TlsString= malloc(100);          /* allocate storage         */
00095     memset(TlsString, '\0', 1);
00096     strcat(TlsString, "Tls Thread#");/* build -                  */
00097     strcat(TlsString,
00098            itoa(TlsCount, chTlsCount,
00099            10) );                    /* - string                 */
00100     if (TlsSetValue(TlsIndex,        /* set TLS value            */
00101                     TlsString))
00102       printf("TlsSetValue success\n\n");
00103     else
00104       ErrorOut("TlsSetValue");
00105     }
00106     else
00107       printf("Process & Thread attaching\n\n");
00108     break;
00109
00110   case DLL_THREAD_DETACH:            /* thread detaches          */
00111     printf("Thread Detaching\n");
00112     TlsRetreive(TlsIndex);           /* retreive TLS data        */
00113     break;
00114
00115   case DLL_PROCESS_DETACH:           /* process detaches         */
00116     printf("Process Detaching\n");
00117     if (!TlsFree(TlsIndex))          /* free TLS index           */
00118       ErrorOut("TlsFree");
00119     else
00120       printf("TlsIndex Freed\n");
00121     break;
00122
00123
00124   default:
00125     break;
00126   }
00127
00128 return 1;
00129 }
00130
00131 /****************************************************************************/
00132
00133 INT WINAPI TlsInit()
00134
00135 /*
00136 Purpose: Allow DllMain to be executed for each thread
00137
00138 Inputs:  none
00139
00140 Returns: none
00141
00142 Calls:   none
00143 */
00144
00145 {
00146 return 1;
00147 }
00148
00149 /****************************************************************************/
00150
00151 INT WINAPI TlsRetreive(DWORD TlsIndex)
00152
00153 /*
00154 Purpose: Retreive TLS values and display (printf) them
00155
00156 Inputs:  TlsIndex - TLS index value
00157
00158 Returns: none
00159
00160 Calls:   TlsGetValue - Gets the TLS value from the index
00161                        based on the current thread.
00162 */
00163
00164 {
00165 LPVOID tlsvals;
00166
00167 (LPVOID)tlsvals= TlsGetValue(TlsIndex);   /* get the TLS value */
00168 if (tlsvals == 0)
00169   ErrorOut("TlsGetValue");
00170 else
00171   printf("tls value=  %s\n\n", tlsvals ); /* output it         */
00172 return 1;
00173 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/MINREC.C Source File

  • MINREC

MINREC.C

Go to the documentation of this file.
00001 // ************************************************************************
00002 //
00003 //                      Microsoft Developer Support
00004 //              Copyright (c) 1992-1996 Microsoft Corporation
00005 //
00006 // ************************************************************************
00007 // MODULE    : MinRec.C
00008 // PURPOSE   : A Small Win32 Recorder-like Sample Application
00009 // FUNCTIONS :
00010 //   WinMain()         - initializes the main window, dispatches messages
00011 //   MainDlgProc()     - processes messages for the main dialog box window
00012 //   ErrorMessageBox() - displays an error message box when called
00013 // COMMENTS  :
00014 // ************************************************************************
00015 #define   STRICT               // strict type checking enabled
00016
00017 // If this program is going to be run exclusively on Windows NT enable
00018 // the UNICODE define below.  However, Windows 95 doesn't support UNICODE
00019 // so for Windows 95 leave the define commented out.
00020
00021 // #define   UNICODE              // make the application unicode compliant
00022 #include <Windows.H>           // required for all Windows applications
00023
00024 #include "MinRec.H"            // specific to this program
00025 #include "RecHook.H"           // global journal hook functions
00026
00027 // internal defines
00028 // ------------------------------------------------------------------------
00029 typedef struct GLOBAL_STRUCT {
00030   HWND      hDlgMain;            // Main dialog box window handle
00031   HINSTANCE hInstance;           // current instance
00032   HANDLE    hMutex;
00033   LPCTSTR   lpszApiFailedMsg;    // "A Windows API Failed" message
00034 } GLOBAL, *PGLOBAL;
00035
00036 // internal data
00037 // ------------------------------------------------------------------------
00038 static GLOBAL Global;
00039 static TCHAR  szSourceFileName[] = TEXT(__FILE__);
00040
00041 // internal function prototypes
00042 // ------------------------------------------------------------------------
00043 BOOL CALLBACK MainDlgProc ( HWND, UINT, WPARAM, LPARAM );
00044 BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );
00045 BOOL          ErrorMessageBox ( LPCTSTR, LPCTSTR, LPCTSTR, INT );
00046
00047 // ************************************************************************
00048 // FUNCTION : WinMain( HINSTANCE, HINSTANCE, LPSTR, INT )
00049 // PURPOSE  : Calls initialization function, processes message loop
00050 // COMMENTS :
00051 // ************************************************************************
00052 INT PASCAL
00053 WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,
00054   INT nCmdShow )
00055 {
00056   MSG     Msg;
00057   HACCEL  hAccel;
00058   LPCTSTR lpszClassName   = TEXT( "MinRecClass" );
00059   LPCTSTR lpszMenuName    = TEXT( "MinRecMenu"  );
00060   LPCTSTR lpszIconName    = TEXT( "MinRecIcon"  );
00061   LPCTSTR lpszAccelName   = TEXT( "MinRecAccel" );
00062
00063   // Check to see if this is running on Windows 95 or Windows NT.  If not
00064   // display a message and exit.
00065   if( (GetVersion() >= 0x80000000) && (LOBYTE(LOWORD(GetVersion())) < 4) )
00066   {
00067       MessageBoxA( NULL,
00068       "This sample application cannot be run on Windows 3.1.\n"
00069       "This application will now terminate.",
00070       "MinRec",
00071       MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00072     return( 1 );
00073   }
00074
00075   Global.hInstance        = hInstance;
00076   Global.lpszApiFailedMsg = TEXT( "A Windows API Failed" );
00077
00078   // allow only one instance of MinRec to be active
00079   // (especially since this makes handling of hot keys easier)
00080   Global.hMutex = CreateMutex( NULL, TRUE, TEXT("MinRec") );
00081   switch( GetLastError() ) {
00082
00083     case ERROR_ALREADY_EXISTS: {
00084       MessageBox( NULL,
00085         TEXT( "Sorry, only one instance of MinRec\n"   )
00086         TEXT( "can be running at any given time.\n"    )
00087         TEXT( "This application will now terminate."   ),
00088         TEXT( "MinRec - Multiple Instances Detected!!" ),
00089         MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00090       return( 1 );
00091     }
00092
00093     case NO_ERROR:
00094       break;
00095
00096     default:
00097       ErrorMessageBox( TEXT("CreateMutex()"),
00098         Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00099
00100   }
00101
00102   // register the window class
00103   {
00104     WNDCLASS WndClass;
00105
00106     WndClass.style         = (UINT) NULL;
00107     WndClass.lpfnWndProc   = (WNDPROC) MainDlgProc;
00108     WndClass.cbClsExtra    = (int) NULL;
00109     WndClass.cbWndExtra    = DLGWINDOWEXTRA;
00110     WndClass.hInstance     = hInstance;
00111     WndClass.hIcon         = LoadIcon( Global.hInstance, lpszIconName );
00112     WndClass.hCursor       = LoadCursor( NULL, IDC_ARROW );
00113     WndClass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1);
00114     WndClass.lpszMenuName  = lpszMenuName;
00115     WndClass.lpszClassName = lpszClassName;
00116
00117     if( !RegisterClass(&WndClass) ) {
00118       ErrorMessageBox( TEXT("RegisterClass()"),
00119         Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00120     }
00121   }
00122
00123   // Create a main dialog window for this application instance
00124   Global.hDlgMain = CreateDialog( Global.hInstance, TEXT("MainDlgBox"),
00125                       NULL, NULL );
00126
00127   // If window could not be created, return "failure"
00128   if( !Global.hDlgMain ) {
00129     ErrorMessageBox( TEXT("CreateDialog()"),
00130       Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00131   }
00132
00133   // Load main menu accelerators
00134   if( !(hAccel = LoadAccelerators( Global.hInstance, lpszAccelName) ) ) {
00135     ErrorMessageBox( TEXT("LoadAccelerators()"),
00136       Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00137   }
00138
00139   // Make the window visible; update its client area; and return "success"
00140   ShowWindow( Global.hDlgMain, SW_SHOWDEFAULT );  // Show the window
00141
00142   // Acquire and dispatch messages until a WM_QUIT message is received.
00143   while( GetMessage( &Msg, NULL, 0, 0 ) ) {
00144     if( !TranslateAccelerator( Global.hDlgMain, hAccel, &Msg ) ) {
00145       if( !IsDialogMessage( Global.hDlgMain, &Msg ) ) {
00146         TranslateMessage( &Msg );     // Translates virtual key codes
00147         DispatchMessage( &Msg );      // Dispatches message to window
00148       }
00149     }
00150   }
00151
00152   // close the mutex handle
00153   if( !CloseHandle( Global.hMutex ) ) {
00154     ErrorMessageBox( TEXT("CloseHandle()"),
00155       Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00156   }
00157
00158   return( Msg.wParam );           // Returns the value from PostQuitMessage
00159   UNREFERENCED_PARAMETER( lpszCmdLine );  // avoid the warning
00160 }
00161
00162
00163 // ************************************************************************
00164 // FUNCTION : MainDlgProc( HWND, UINT, WPARAM, LPARAM )
00165 // PURPOSE  : Processes messages
00166 // MESSAGES :
00167 //   WM_COMMAND         - application menu
00168 //     IDM_FILE_EXIT    - exit the application
00169 //     IDM_HELP_ABOUT   - About Dialog Box
00170 //     ...
00171 //   WM_CREATE          - window initialization
00172 //   WM_CLOSE           - handles cleanup
00173 //   WM_DESTROY         - destroys window
00174 // ************************************************************************
00175 BOOL CALLBACK
00176 MainDlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
00177 {
00178   switch( uMsg ) {
00179
00180     case WM_CREATE:
00181       // Register the Playback (Ctrl+P) and Record (Ctrl+R) hot keys
00182       RegisterHotKey( hWnd, IDM_MACRO_PLAYBACK, MOD_CONTROL, 'P' );
00183       RegisterHotKey( hWnd, IDM_MACRO_RECORD, MOD_CONTROL, 'R' );
00184       return( TRUE );
00185
00186     case WM_COMMAND:
00187       switch( LOWORD(wParam) ) {
00188
00189         case IDM_FILE_EXIT:
00190           PostMessage( hWnd, WM_CLOSE, (WPARAM) 0, (LPARAM) 0 );
00191           return( TRUE );
00192
00193         case IDM_MACRO_PLAYBACK:
00194           StartJournalPlayback();
00195           return( TRUE );
00196
00197         case IDM_MACRO_RECORD:
00198           StartJournalRecord();
00199           return( TRUE );
00200
00201         case IDM_MACRO_STOP:
00202           StopAllJournalling();
00203           return( TRUE );
00204
00205         case IDM_HELP_ABOUT:
00206           if( DialogBox( Global.hInstance, TEXT( "AboutDlgBox" ),
00207                 hWnd, AboutDlgProc ) == -1 ) {
00208             ErrorMessageBox( TEXT("DialogBox()"),
00209               Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00210           }
00211           return( TRUE );
00212
00213       }
00214       break;
00215
00216     case WM_SYSCOMMAND:
00217       switch( LOWORD(wParam) ) {
00218         // return a nonzero value to disable the screen saver
00219         case SC_SCREENSAVE:
00220           return( TRUE );
00221       }
00222       break;
00223
00224     case WM_HOTKEY:
00225       PostMessage( hWnd, WM_COMMAND, wParam, lParam );
00226       return( TRUE );
00227
00228     case WM_CLOSE:
00229       // Unregister the Playback (Ctrl+P) and Record (Ctrl+R) hot keys
00230       if( !UnregisterHotKey( hWnd, IDM_MACRO_PLAYBACK ) ) {
00231         ErrorMessageBox( TEXT("UnregisterHotKey()"),
00232           Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00233       }
00234       if( !UnregisterHotKey( hWnd, IDM_MACRO_RECORD ) ) {
00235         ErrorMessageBox( TEXT("UnregisterHotKey()"),
00236           Global.lpszApiFailedMsg, szSourceFileName, __LINE__ );
00237       }
00238       DestroyWindow( Global.hDlgMain );
00239       Global.hDlgMain = NULL;
00240       PostQuitMessage( FALSE );
00241       return( TRUE );
00242   }
00243
00244   return( DefDlgProc( hWnd, uMsg, wParam, lParam )  );
00245 }
00246
00247
00248 // ************************************************************************
00249 // FUNCTION : AboutDlgProc( HWND, UINT, WPARAM, LPARAM )
00250 // PURPOSE  : Processes messages for "About" dialog box
00251 // MESSAGES :
00252 //   WM_INITDIALOG - initialize dialog box
00253 //   WM_COMMAND    - Input received
00254 //     IDOK        - OK button selected
00255 //     IDCANCEL    - Cancel button selected
00256 // COMMENTS:
00257 //   No initialization is needed for this particular dialog box.
00258 //   In this case, TRUE must be returned to Windows.
00259 //   Wait for user to click on "Ok" button, then close the dialog box.
00260 // ************************************************************************
00261 BOOL CALLBACK
00262 AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
00263 {
00264   switch( uMsg ) {
00265
00266     case WM_COMMAND:
00267       switch( LOWORD(wParam) ) {
00268
00269         case IDOK:
00270           EndDialog( hDlg, TRUE );
00271           return( TRUE );
00272
00273         case IDCANCEL:
00274           EndDialog( hDlg, FALSE );
00275           return( TRUE );
00276       }
00277       break;
00278
00279     case WM_INITDIALOG:
00280       return( TRUE );
00281
00282     case WM_CLOSE:
00283       return( TRUE );
00284
00285   }
00286
00287   return( FALSE );
00288   UNREFERENCED_PARAMETER( lParam );
00289 }
00290
00291
00292 // ************************************************************************
00293 // FUNCTION : ErrorMessageBox( LPCTSTR, LPCTSTR, LPCTSTR, INT )
00294 // PURPOSE  : Displays an error message box with various error information
00295 //            and allows the user to terminate or continue the process.
00296 //            For a Win32 Application, GetLastError and FormatMessage are
00297 //            used to retrieve the last API error code and error message.
00298 // COMMENTS :
00299 // ************************************************************************
00300 BOOL
00301 ErrorMessageBox( LPCTSTR lpszText, LPCTSTR lpszTitle, LPCTSTR lpszFile,
00302   INT Line )
00303 {
00304   #define ERROR_BUFFER_SIZE 512
00305
00306   static TCHAR szMessageFormat[] =
00307     TEXT( "%s\n"                                           )
00308     TEXT( "\n"                                             )
00309     TEXT( "-- Error Information --\n"                      )
00310     TEXT( "File : %s\n"                                    )
00311     TEXT( "Line : %d\n"                                    )
00312     TEXT( "Error Number : %d\n"                            )
00313     TEXT( "Error Message : %s\n"                           )
00314     TEXT( "\n"                                             )
00315     TEXT( "Press OK to terminate this application.\n"      )
00316     TEXT( "Press Cancel to ignore the error and continue." );
00317
00318   LPTSTR lpFormatMessageBuffer;
00319   DWORD  dwFormatMessage;
00320   DWORD  dwGetLastError;
00321   HLOCAL hMessageBoxBuffer;
00322   LPVOID lpMessageBoxBuffer;
00323
00324   // get the system error
00325   dwGetLastError = GetLastError();
00326
00327   // perform a simple check on the needed buffer size
00328   if( lstrlen(lpszText) > (ERROR_BUFFER_SIZE - lstrlen(szMessageFormat)) )
00329     return( FALSE );
00330
00331   // allocate the message box buffer
00332   hMessageBoxBuffer  = LocalAlloc( LMEM_MOVEABLE, ERROR_BUFFER_SIZE );
00333   lpMessageBoxBuffer = LocalLock( hMessageBoxBuffer );
00334
00335   // get the system error message
00336   dwFormatMessage = FormatMessage(
00337                       FORMAT_MESSAGE_ALLOCATE_BUFFER
00338                       | FORMAT_MESSAGE_FROM_SYSTEM,
00339                       NULL, dwGetLastError, LANG_NEUTRAL,
00340                       (LPTSTR) &lpFormatMessageBuffer, 0, NULL );
00341   if( !dwFormatMessage )
00342     lpFormatMessageBuffer = TEXT("FormatMessage() failed!");
00343
00344   // format the error messge box string
00345   wsprintf( lpMessageBoxBuffer, szMessageFormat, lpszText, lpszFile,
00346     Line, dwGetLastError, lpFormatMessageBuffer );
00347
00348   // -- display the error and allow the user to terminate or continue
00349   if( MessageBox( NULL, lpMessageBoxBuffer, lpszTitle,
00350         MB_APPLMODAL | MB_ICONSTOP | MB_OKCANCEL | MB_SETFOREGROUND ) == IDOK )
00351     ExitProcess( 0 );
00352
00353   // free all buffers
00354   if( dwFormatMessage )
00355     LocalFree( (HLOCAL) lpFormatMessageBuffer );
00356   LocalFree( (HLOCAL) hMessageBoxBuffer );
00357
00358   return( TRUE );
00359 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/THE_DLL.H Source File

  • SIMPLDLL

THE_DLL.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *                                 THE_DLL.H
00015 *
00016 \******************************************************************************/
00017
00018
00019
00020 /******************************************************************************\
00021 *                              SYMBOLIC CONSTANTS
00022 \******************************************************************************/
00023
00024 #define BUFSIZE 80
00025
00026
00027
00028 /******************************************************************************\
00029 *                               GLOBAL VARIABLES
00030 \******************************************************************************/
00031
00032 HANDLE ghMod;
00033
00034
00035
00036 /******************************************************************************\
00037 *                              FUNCTION PROTOTYPES
00038 \******************************************************************************/
00039
00040 INT DLLFunction1 (void);
00041 INT DLLFunction2 (int);
00042 INT DLLFunction3 (HANDLE);
00043 INT DLLFunction4 (HWND);
00044
00045 INT  DLLDialogBox (HWND);
00046
00047 BOOL CALLBACK DLLDlgProc (HWND, UINT, WPARAM, LPARAM);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETSYS/GETSYS.H Source File

  • GETSYS

GETSYS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* getsys.h - header file for the GETSYS sample. */
00013
00014
00015 /* function prototypes.  Window procedures first. */
00016 LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
00017
00018 VOID doSysColors (HWND);
00019 VOID doInfo      (HWND);
00020 VOID doDirectory (HWND);
00021 VOID doMetrics   (HWND);
00022 VOID doPalette   (HWND);
00023 VOID doLocalTime (HWND);
00024 VOID doTime      (HWND);
00025 VOID doVersionEx (HWND);
00026
00027
00028 /* declare global variable to be used by all of the do... functions */
00029 char buffer[256];
00030
00031
00032
00033 /* the control ID's from the dialog box. */
00034 #define DID_SYSCOLORS   61
00035 #define DID_DIRECTORY   62
00036 #define DID_INFO        63
00037 #define DID_METRICS     64
00038 #define DID_PALETTE     65
00039 #define DID_LOCALTIME   66
00040 #define DID_TIME        67
00041 #define DID_VERSIONEX   68
00042
00043 #define DID_LISTBOX     70
00044 #define DID_TEXT        71
00045
00046
00047 /* structure for the lookup tables.  */
00048 typedef struct tagLookupEntry{
00049     int     Value;
00050     char    String[100];
00051 } LookupEntry;
00052
00053
00054 /* GetSysColor() codes from WINUSER.H */
00055 #define NSYSCOLORS COLOR_BTNHIGHLIGHT+1 // assumes order puts BTNHIGHLIGHT last
00056 LookupEntry  SysColors[NSYSCOLORS] =
00057     {{ COLOR_SCROLLBAR          , "COLOR_SCROLLBAR           %06lx"},
00058      { COLOR_BACKGROUND         , "COLOR_BACKGROUND          %06lx"},
00059      { COLOR_ACTIVECAPTION      , "COLOR_ACTIVECAPTION       %06lx"},
00060      { COLOR_INACTIVECAPTION    , "COLOR_INACTIVECAPTION     %06lx"},
00061      { COLOR_MENU               , "COLOR_MENU                %06lx"},
00062      { COLOR_WINDOW             , "COLOR_WINDOW              %06lx"},
00063      { COLOR_WINDOWFRAME        , "COLOR_WINDOWFRAME         %06lx"},
00064      { COLOR_MENUTEXT           , "COLOR_MENUTEXT            %06lx"},
00065      { COLOR_WINDOWTEXT         , "COLOR_WINDOWTEXT          %06lx"},
00066      { COLOR_CAPTIONTEXT        , "COLOR_CAPTIONTEXT         %06lx"},
00067      { COLOR_ACTIVEBORDER       , "COLOR_ACTIVEBORDER        %06lx"},
00068      { COLOR_INACTIVEBORDER     , "COLOR_INACTIVEBORDER      %06lx"},
00069      { COLOR_APPWORKSPACE       , "COLOR_APPWORKSPACE        %06lx"},
00070      { COLOR_HIGHLIGHT          , "COLOR_HIGHLIGHT           %06lx"},
00071      { COLOR_HIGHLIGHTTEXT      , "COLOR_HIGHLIGHTTEXT       %06lx"},
00072      { COLOR_BTNFACE            , "COLOR_BTNFACE             %06lx"},
00073      { COLOR_BTNSHADOW          , "COLOR_BTNSHADOW           %06lx"},
00074      { COLOR_GRAYTEXT           , "COLOR_GRAYTEXT            %06lx"},
00075      { COLOR_BTNTEXT            , "COLOR_BTNTEXT             %06lx"},
00076      { COLOR_INACTIVECAPTIONTEXT, "COLOR_INACTIVECAPTIONTEXT %06lx"},
00077      { COLOR_BTNHIGHLIGHT       , "COLOR_BTNHIGHLIGHT        %06lx"}};
00078
00079
00080
00081 /* GetSystemMetrics() codes from WINUSER.H */
00082 LookupEntry  SystemMetrics[] =
00083     {{ SM_CXSCREEN         , "SM_CXSCREEN      \t%d"},
00084      { SM_CYSCREEN         , "SM_CYSCREEN      \t%d"},
00085      { SM_CXVSCROLL        , "SM_CXVSCROLL     \t%d"},
00086      { SM_CYHSCROLL        , "SM_CYHSCROLL     \t%d"},
00087      { SM_CYCAPTION        , "SM_CYCAPTION     \t%d"},
00088      { SM_CXBORDER         , "SM_CXBORDER      \t%d"},
00089      { SM_CYBORDER         , "SM_CYBORDER      \t%d"},
00090      { SM_CXDLGFRAME       , "SM_CXDLGFRAME    \t%d"},
00091      { SM_CYDLGFRAME       , "SM_CYDLGFRAME    \t%d"},
00092      { SM_CYVTHUMB         , "SM_CYVTHUMB      \t%d"},
00093      { SM_CXHTHUMB         , "SM_CXHTHUMB      \t%d"},
00094      { SM_CXICON           , "SM_CXICON        \t%d"},
00095      { SM_CYICON           , "SM_CYICON        \t%d"},
00096      { SM_CXCURSOR         , "SM_CXCURSOR      \t%d"},
00097      { SM_CYCURSOR         , "SM_CYCURSOR      \t%d"},
00098      { SM_CYMENU           , "SM_CYMENU        \t%d"},
00099      { SM_CXFULLSCREEN     , "SM_CXFULLSCREEN  \t%d"},
00100      { SM_CYFULLSCREEN     , "SM_CYFULLSCREEN  \t%d"},
00101      { SM_CYKANJIWINDOW    , "SM_CYKANJIWINDOW \t%d"},
00102      { SM_MOUSEPRESENT     , "SM_MOUSEPRESENT  \t%d"},
00103      { SM_CYVSCROLL        , "SM_CYVSCROLL     \t%d"},
00104      { SM_CXHSCROLL        , "SM_CXHSCROLL     \t%d"},
00105      { SM_DEBUG            , "SM_DEBUG         \t%d"},
00106      { SM_SWAPBUTTON       , "SM_SWAPBUTTON    \t%d"},
00107      { SM_RESERVED1        , "SM_RESERVED1     \t%d"},
00108      { SM_RESERVED2        , "SM_RESERVED2     \t%d"},
00109      { SM_RESERVED3        , "SM_RESERVED3     \t%d"},
00110      { SM_RESERVED4        , "SM_RESERVED4     \t%d"},
00111      { SM_CXMIN            , "SM_CXMIN         \t%d"},
00112      { SM_CYMIN            , "SM_CYMIN         \t%d"},
00113      { SM_CXSIZE           , "SM_CXSIZE        \t%d"},
00114      { SM_CYSIZE           , "SM_CYSIZE        \t%d"},
00115      { SM_CXFRAME          , "SM_CXFRAME       \t%d"},
00116      { SM_CYFRAME          , "SM_CYFRAME       \t%d"},
00117      { SM_CXMINTRACK       , "SM_CXMINTRACK    \t%d"},
00118      { SM_CYMINTRACK       , "SM_CYMINTRACK    \t%d"},
00119      { SM_CXDOUBLECLK      , "SM_CXDOUBLECLK   \t%d"},
00120      { SM_CYDOUBLECLK      , "SM_CYDOUBLECLK   \t%d"},
00121      { SM_CXICONSPACING    , "SM_CXICONSPACING \t%d"},
00122      { SM_CYICONSPACING    , "SM_CYICONSPACING \t%d"},
00123      { SM_MENUDROPALIGNMENT, "SM_MENUDROPALIGNMENT\t%d"},
00124      { SM_PENWINDOWS       , "SM_PENWINDOWS    \t%d"},
00125      { SM_DBCSENABLED      , "SM_DBCSENABLED   \t%d"},
00126      { SM_CMOUSEBUTTONS    , "SM_CMOUSEBUTTONS \t%d"},
00127
00128 #if(WINVER >= 0x0400)
00129      {  SM_SECURE            , "SM_SECURE          \t%d"},
00130      {  SM_CXEDGE            , "SM_CXEDGE          \t%d"},
00131      {  SM_CYEDGE            , "SM_CYEDGE          \t%d"},
00132      {  SM_CXMINSPACING      , "SM_CXMINSPACING    \t%d"},
00133      {  SM_CYMINSPACING      , "SM_CYMINSPACING    \t%d"},
00134      {  SM_CXSMICON          , "SM_CXSMICON        \t%d"},
00135      {  SM_CYSMICON          , "SM_CYSMICON        \t%d"},
00136      {  SM_CYSMCAPTION       , "SM_CYSMCAPTION     \t%d"},
00137      {  SM_CXSMSIZE          , "SM_CXSMSIZE        \t%d"},
00138      {  SM_CYSMSIZE          , "SM_CYSMSIZE        \t%d"},
00139      {  SM_CXMENUSIZE        , "SM_CXMENUSIZE      \t%d"},
00140      {  SM_CYMENUSIZE        , "SM_CYMENUSIZE      \t%d"},
00141      {  SM_ARRANGE           , "SM_ARRANGE         \t%d"},
00142      {  SM_CXMINIMIZED       , "SM_CXMINIMIZED     \t%d"},
00143      {  SM_CYMINIMIZED       , "SM_CYMINIMIZED     \t%d"},
00144      {  SM_CXMAXTRACK        , "SM_CXMAXTRACK      \t%d"},
00145      {  SM_CYMAXTRACK        , "SM_CYMAXTRACK      \t%d"},
00146      {  SM_CXMAXIMIZED       , "SM_CXMAXIMIZED     \t%d"},
00147      {  SM_CYMAXIMIZED       , "SM_CYMAXIMIZED     \t%d"},
00148      {  SM_NETWORK           , "SM_NETWORK         \t%d"},
00149      {  SM_CLEANBOOT         , "SM_CLEANBOOT       \t%d"},
00150      {  SM_CXDRAG            , "SM_CXDRAG          \t%d"},
00151      {  SM_CYDRAG            , "SM_CYDRAG          \t%d"},
00152 #endif /* WINVER >= 0x0400 */
00153
00154      {  SM_SHOWSOUNDS        , "SM_SHOWSOUNDS      \t%d"},
00155
00156 #if(WINVER >= 0x0400)
00157      {  SM_CXMENUCHECK       , "SM_CXMENUCHECK     \t%d"},
00158      {  SM_CYMENUCHECK       , "SM_CYMENUCHECK     \t%d"},
00159      {  SM_SLOWMACHINE       , "SM_SLOWMACHINE     \t%d"},
00160      {  SM_MIDEASTENABLED    , "SM_MIDEASTENABLED  \t%d"},
00161 #endif /* WINVER >= 0x0400 */
00162      };
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/UNIPUT.C Source File

  • UNIPUT

UNIPUT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 * uniput.c -- input of unicode characters.
00014 \**************************************************************************/
00015 #define UNICODE
00016
00017 #include <windows.h>
00018 #include <commdlg.h>
00019 #include "uniput.h"
00020
00021
00022 /* Misc. defines for size, color, and appearance of drawing. */
00023 #define GRIDCOLOR  PALETTEINDEX (6)
00024 #define TICKSPACE  20
00025 #define FWW_STEPS  40
00026
00027
00028 HANDLE hFile = INVALID_HANDLE_VALUE;
00029
00030 HANDLE OpenNewFile(HWND);
00031
00032
00033 TCHAR szHelpPathName[] = TEXT("uniput.HLP");
00034
00035 HANDLE hInst;
00036 HWND   hwndMain;
00037 HWND   hwndClient;
00038 HWND   hwndStatus;
00039
00040 int gShowhex, gShowNames;
00041
00042 #define STATUSHEIGHT (UCFONTHEIGHT/2 + 3*SBORDER)
00043
00044
00045 /**************************************************************************\
00046 *
00047 *  function:  WinMain()
00048 *
00049 *  input parameters:  c.f. generic sample
00050 *
00051 \**************************************************************************/
00052 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00053                      LPSTR lpCmdLine, int nCmdShow)
00054 {
00055     MSG    msg;
00056     CLIENTCREATESTRUCT clientcreate;
00057     WNDCLASS  wc;
00058     DWORD dwVersion;
00059
00060
00061     UNREFERENCED_PARAMETER( lpCmdLine );
00062     UNREFERENCED_PARAMETER(  nCmdShow );
00063
00064     /* Check to make sure we are running on Windows NT, not Win95 or Win32s */
00065     dwVersion = GetVersion();
00066     if (dwVersion & 0x80000000)
00067     {
00068         MessageBoxA(NULL,
00069             "This sample application can only be run on Windows NT\n"
00070             "This application will now terminate",
00071             "UniPut",
00072             MB_ICONSTOP | MB_OK | MB_SETFOREGROUND);
00073         return(1);
00074     }
00075
00076     hInst = hInstance;
00077
00078     /* Check for previous instance.  If none, then register class. */
00079     if (!hPrevInstance) {
00080
00081       wc.style = 0;
00082       wc.lpfnWndProc = (WNDPROC)MainWndProc;
00083
00084       wc.cbClsExtra = 0;
00085       wc.cbWndExtra = 0;
00086       wc.hInstance = hInstance;
00087       wc.hIcon = LoadIcon(hInstance, TEXT("uniputIcon"));
00088       wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00089       wc.hbrBackground = NULL;
00090       wc.lpszMenuName =  TEXT("uniputMenu");
00091       wc.lpszClassName = TEXT("uniput");
00092
00093       if (!RegisterClass(&wc)) return (FALSE);
00094
00095     }  /* class registered o.k. */
00096
00097
00098     /* Create the main window.  Return false if CreateWindow() fails */
00099     hwndMain = CreateWindow(
00100         TEXT("uniput"),
00101         TEXT("Input unicode characters"),
00102         WS_OVERLAPPEDWINDOW,
00103         CW_USEDEFAULT,
00104         CW_USEDEFAULT,
00105         CW_USEDEFAULT,
00106         CW_USEDEFAULT,
00107         NULL, NULL, hInst, NULL);
00108
00109     if (!hwndMain) return (FALSE);
00110
00111
00112     /* create the MDI "client" window. */
00113     clientcreate.hWindowMenu  = GetSubMenu(GetMenu(hwndMain),1);
00114     clientcreate.idFirstChild = 1;
00115     hwndClient = CreateWindow(
00116         TEXT("MDICLIENT"),
00117         NULL,
00118         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | MDIS_ALLCHILDSTYLES,
00119         0,0,0,0,
00120         hwndMain, NULL, hInst, (LPVOID)&clientcreate);
00121     if (!hwndClient) return (FALSE);
00122
00123
00124
00125     /* create status bar */
00126     wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
00127     wc.lpfnWndProc = (WNDPROC)StatusWndProc;
00128     wc.cbClsExtra = 0;
00129     wc.cbWndExtra = 0;
00130     wc.hInstance = hInst;
00131     wc.hIcon = NULL;
00132     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00133     wc.hbrBackground = GetStockObject (LTGRAY_BRUSH);
00134     wc.lpszMenuName = NULL;
00135     wc.lpszClassName = TEXT("status");
00136     if (!RegisterClass(&wc)) return (FALSE);
00137
00138     hwndStatus = CreateWindow(
00139         TEXT("status"),
00140         TEXT("status"),
00141         WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_BORDER,
00142         0,0,
00143         GetSystemMetrics(SM_CXFULLSCREEN),
00144         STATUSHEIGHT,
00145         hwndMain, NULL, hInst, 0);
00146     if (!hwndStatus) return (FALSE);
00147
00148
00149     ShowWindow(hwndMain, SW_SHOWDEFAULT);
00150     SetCursor (LoadCursor (NULL, IDC_WAIT));
00151
00152
00153     /* Register display window class, and do class initialization. */
00154     if (!openDisplay()) return (FALSE);
00155
00156     /* set the menus to be correct */
00157     SendMessage (hwndMain, WM_COMMAND, IDM_SHOWHEX,0);
00158     SendMessage (hwndMain, WM_COMMAND, IDM_SHOWNAMES,0);
00159
00160
00161
00162     /* Create one MDI child window to get started */
00163     SendMessage (hwndMain, WM_COMMAND, IDM_NEWWINDOW, 0);
00164
00165     SetCursor (LoadCursor (NULL, IDC_ARROW));
00166
00167
00168
00169     /* Loop getting messages and dispatching them. */
00170     while (GetMessage(&msg,NULL, 0,0)) {
00171         TranslateMessage(&msg);
00172         DispatchMessage(&msg);
00173     }
00174
00175     closeDisplay();
00176     return (msg.wParam);
00177 }
00178
00179
00180
00181 /**************************************************************************\
00182 *
00183 *  function:  MainWndProc()
00184 *
00185 *  input parameters:  normal window procedure parameters.
00186 *
00187 \**************************************************************************/
00188 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00189 {
00190 HWND hwndActive;
00191
00192   switch (message) {
00193
00194     /**********************************************************************\
00195     *  WM_CREATE
00196     \**********************************************************************/
00197     case WM_CREATE: {
00198
00199     }
00200
00201
00202     /**********************************************************************\
00203     *  WM_SIZE
00204     *
00205     * When the frame is sized, then change the size of the MDI client,
00206     *  excluding the status bar, and change the size and position of the
00207     *  status bar.
00208     \**********************************************************************/
00209     case WM_SIZE: {
00210
00211       RECT r;
00212       GetClientRect (hwnd, &r);
00213       r.bottom -= STATUSHEIGHT;
00214
00215       SetWindowPos (hwndClient, HWND_BOTTOM,
00216                     r.left, r.top, r.right, r.bottom, 0);
00217
00218       /* size & position status bar: left, right, & top just out of view */
00219       SetWindowPos (hwndStatus, HWND_TOP,
00220         r.left-1, r.bottom,
00221         r.right+2, STATUSHEIGHT+1, 0);
00222
00223
00224       return TRUE;
00225
00226     } break;
00227
00228
00229
00230     /**********************************************************************\
00231     *  WMU_CHARACTER
00232     *
00233     * global variable: hFile
00234     *
00235     * user message sent to main window when user hits a glyph square.
00236     *  if the main window has a file open, then write this unicode
00237     *  character to that file.
00238     \**********************************************************************/
00239     case WMU_CHARACTER: {
00240         DWORD nBytes;
00241         WCHAR tChar;
00242
00243       tChar = (WCHAR)lParam;
00244
00245       /* show it on the status bar */
00246       SendMessage (hwndStatus, WMU_CHARACTER, 0, lParam);
00247
00248       if (hFile != INVALID_HANDLE_VALUE)
00249         WriteFile (hFile, &tChar, sizeof(WCHAR), &nBytes, NULL);
00250
00251     } break;
00252
00253
00254
00255     /**********************************************************************\
00256     *  WM_COMMAND
00257     *
00258     \**********************************************************************/
00259     case WM_COMMAND: {
00260
00261       switch (LOWORD(wParam)) {
00262
00263         /******************************************************************\
00264         *  WM_COMMAND, IDM_NEWWINDOW
00265         *
00266         * global - hwndClient, hInst
00267         *
00268         * Simply create a new MDI child window.
00269         \******************************************************************/
00270         case IDM_NEWWINDOW: {
00271           HWND hwndDisplay;
00272
00273           hwndDisplay = CreateMDIWindow(
00274               DISPLAYCLASS,
00275               TEXT("Display"),
00276               WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE |
00277                          WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_HSCROLL,
00278               CW_USEDEFAULT,
00279               CW_USEDEFAULT,
00280               CW_USEDEFAULT,
00281               CW_USEDEFAULT,
00282               hwndClient, hInst, 0);
00283         } break;
00284
00285
00286         /******************************************************************\
00287         *  WM_COMMAND, IDM_NEWFILE
00288         *
00289         * global - hFile.
00290         \******************************************************************/
00291         case IDM_NEWFILE: {
00292           DWORD nBytes;
00293
00294           hFile = OpenNewFile (hwnd);
00295           /* Write the unicode byte order mark */
00296           WriteFile (hFile, "\xFE\xFF", 2, &nBytes, NULL);
00297         } break;
00298
00299
00300         /******************************************************************\
00301         *  WM_COMMAND, IDM_CLOSEFILE
00302         *
00303         * global - hFile.
00304         \******************************************************************/
00305         case IDM_CLOSEFILE:
00306           CloseHandle (hFile);
00307           hFile = INVALID_HANDLE_VALUE;
00308           SendMessage (hwndStatus, WMU_SETTARGETNAME, 0, (LPARAM)NULL);
00309         break;
00310
00311
00312         case IDM_HELP:
00313           WinHelp( hwnd, szHelpPathName, HELP_INDEX, (DWORD) NULL );
00314         break;
00315
00316
00317         case IDM_ABOUT:
00318           DialogBox (hInst, TEXT("aboutBox"), hwnd, (DLGPROC) About);
00319         break;
00320
00321
00322
00323         /******************************************************************\
00324         *  WM_COMMAND, IDM_SHOWHEX
00325         *
00326         * Check menu on and off.  Set global value: gShowHex
00327         \******************************************************************/
00328         case IDM_SHOWHEX:
00329           if (GetMenuState (GetMenu (hwnd),IDM_SHOWHEX, MF_BYCOMMAND)
00330                 == MF_CHECKED) {
00331             CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED);
00332             gShowhex = FALSE;
00333             RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE |RDW_ALLCHILDREN);
00334           } else {
00335             CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED);
00336             gShowhex = TRUE;
00337             RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE |RDW_ALLCHILDREN);
00338           }
00339         break;
00340
00341
00342         /******************************************************************\
00343         *  WM_COMMAND, IDM_SHOWNAMES
00344         *
00345         * Check menu on and off.  Set global value: gShowNames
00346         \******************************************************************/
00347         case IDM_SHOWNAMES:
00348           if (GetMenuState (GetMenu (hwnd),IDM_SHOWNAMES, MF_BYCOMMAND)
00349                 == MF_CHECKED) {
00350             CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_UNCHECKED);
00351             gShowNames = FALSE;
00352           } else {
00353             CheckMenuItem(GetMenu (hwnd), LOWORD(wParam) , MF_CHECKED);
00354             gShowNames = TRUE;
00355           }
00356           // PROBLEM:  Need to send message to all child windows.
00357
00358           hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
00359           SendMessage (hwndActive, WMU_NEWRANGE, 0,0);
00360           InvalidateRect (hwndActive, NULL, TRUE);
00361
00362         break;
00363
00364
00365         /******************************************************************\
00366         *  WM_COMMAND, IDM_CHAR*
00367         *
00368         * manage mutually exclusive menu indicating number of chars per line
00369         \******************************************************************/
00370         case IDM_CHAR10:
00371         case IDM_CHAR16:
00372         case IDM_CHAR20:
00373         case IDM_CHAR32:
00374         case IDM_CHAR40:
00375         case IDM_CHAR64:
00376
00377         { HMENU hMenu;
00378           int nCharPerLine;
00379
00380           hMenu = GetMenu (hwnd);
00381
00382           CheckMenuItem(hMenu, IDM_CHAR10, MF_UNCHECKED);
00383           CheckMenuItem(hMenu, IDM_CHAR16, MF_UNCHECKED);
00384           CheckMenuItem(hMenu, IDM_CHAR20, MF_UNCHECKED);
00385           CheckMenuItem(hMenu, IDM_CHAR32, MF_UNCHECKED);
00386           CheckMenuItem(hMenu, IDM_CHAR40, MF_UNCHECKED);
00387           CheckMenuItem(hMenu, IDM_CHAR64, MF_UNCHECKED);
00388
00389           CheckMenuItem(hMenu, LOWORD(wParam), MF_CHECKED);
00390
00391           /* notice the value is coded into the menu i.d. */
00392           nCharPerLine = LOWORD(wParam)-IDM_CHARBASE;
00393           hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
00394           SendMessage (hwndActive, WMU_SETNCHAR, nCharPerLine ,0);
00395           InvalidateRect (hwndActive, NULL, TRUE);
00396
00397         } break;
00398
00399
00400
00401         /******************************************************************\
00402         *  WM_COMMAND, IDM_FONT*
00403         *
00404         * manage mutually exclusive menu indicating font height
00405         \******************************************************************/
00406         case IDM_FONT18:
00407         case IDM_FONT36:
00408         case IDM_FONT72:
00409
00410         { HMENU hMenu;
00411           int Width, Height;
00412           hMenu = GetMenu (hwnd);
00413
00414           CheckMenuItem(hMenu, IDM_FONT18, MF_UNCHECKED);
00415           CheckMenuItem(hMenu, IDM_FONT36, MF_UNCHECKED);
00416           CheckMenuItem(hMenu, IDM_FONT72, MF_UNCHECKED);
00417
00418           CheckMenuItem(hMenu, LOWORD(wParam), MF_CHECKED);
00419
00420           /* notice the value is coded into the menu i.d. */
00421           Height = LOWORD(wParam)-IDM_FONTBASE;
00422           /* scale the width proportionately */
00423           Width = Height * UCFONTWIDTH/UCFONTHEIGHT;
00424
00425           hwndActive = (HWND)SendMessage (hwndClient, WM_MDIGETACTIVE, 0,0);
00426           SendMessage (hwndActive, WMU_NEWFONT, (WPARAM)Width,(LPARAM)Height);
00427           InvalidateRect (hwndActive, NULL, TRUE);
00428
00429         } break;
00430
00431
00432
00433         /******************************************************************\
00434         *  WM_COMMAND, IDM_MDI*
00435         *
00436         * misc. MDI responsibilities.  hwndClient does real work.
00437         \******************************************************************/
00438         case IDM_MDICASCADE: SendMessage (hwndClient, WM_MDICASCADE, 0,0); break;
00439         case IDM_MDITILE:    SendMessage (hwndClient, WM_MDITILE, MDITILE_HORIZONTAL,0); break;
00440         break;
00441
00442
00443
00444
00445       } /* end switch */
00446     } break;  /* end WM_COMMAND */
00447
00448
00449
00450
00451
00452     /**********************************************************************\
00453     *  WM_DESTROY
00454     \**********************************************************************/
00455     case WM_DESTROY:
00456       WinHelp( hwnd, szHelpPathName, (UINT) HELP_QUIT, (DWORD) NULL );
00457       PostQuitMessage(0);
00458     break;
00459
00460
00461   } /* end switch */
00462   return (DefFrameProc(hwnd, hwndClient, message, wParam, lParam));
00463 }
00464
00465
00466
00467 /***************************************************************************\
00468 *    FUNCTION: About
00469 \***************************************************************************/
00470 LRESULT CALLBACK About(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00471 {
00472   if ((message == WM_COMMAND) && (LOWORD(wParam) == IDOK)) {
00473     EndDialog (hwnd, TRUE);
00474     return TRUE;
00475   }
00476   if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) {
00477     EndDialog (hwnd, TRUE);
00478     return TRUE;
00479   }
00480   return FALSE;
00481 }
00482
00483
00484
00485
00486
00487
00488
00489 /***************************************************************************\
00490 *
00491 *    FUNCTION: OpenNewFile(HWND)
00492 *
00493 *    PURPOSE:  Invokes common dialog function to open a file and opens it.
00494 *
00495 \***************************************************************************/
00496 HANDLE OpenNewFile( HWND hwnd )
00497 {
00498    TCHAR szFile[MAX_PATH],szFileTitle[MAX_PATH];
00499    OPENFILENAME OpenFileName;
00500
00501
00502    wsprintf (szFile, TEXT(""));
00503    wsprintf (szFileTitle, TEXT(""));
00504
00505    OpenFileName.lStructSize       = sizeof(OPENFILENAME);
00506    OpenFileName.hwndOwner         = hwnd;
00507    OpenFileName.hInstance         = (HANDLE) hInst;
00508    OpenFileName.lpstrFilter       = NULL;
00509    OpenFileName.lpstrCustomFilter = NULL;
00510    OpenFileName.nMaxCustFilter    = 0L;
00511    OpenFileName.nFilterIndex      = 1L;
00512    OpenFileName.lpstrFile         = szFile;
00513    OpenFileName.nMaxFile          = sizeof(szFile);
00514    OpenFileName.lpstrFileTitle    = szFileTitle;
00515    OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
00516    OpenFileName.lpstrInitialDir   = NULL;
00517    OpenFileName.lpstrTitle        = TEXT("Open a File");
00518
00519    OpenFileName.nFileOffset       = 0;
00520    OpenFileName.nFileExtension    = 0;
00521    OpenFileName.lpstrDefExt       = NULL;
00522
00523    OpenFileName.lCustData         = 0;
00524
00525    OpenFileName.Flags = OFN_HIDEREADONLY;
00526
00527    if (!GetOpenFileName(&OpenFileName)) return INVALID_HANDLE_VALUE;
00528
00529    /* update status bar with the file title. */
00530    SendMessage (hwndStatus, WMU_SETTARGETNAME, 0, (LPARAM)OpenFileName.lpstrFileTitle);
00531
00532    return (CreateFile(OpenFileName.lpstrFile,
00533                       GENERIC_WRITE,
00534                       0,
00535                       NULL,
00536                       CREATE_ALWAYS,
00537                       FILE_ATTRIBUTE_NORMAL,
00538                       NULL));
00539 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BOB/BOB.H Source File

  • BOB

BOB.H

Go to the documentation of this file.
00001 typedef struct tagControlText {
00002     POINT   ptPosition;
00003     PTCHAR  szTitle;
00004     UINT    cbTitle;
00005     HBITMAP hDefaultButton;
00006     HBITMAP hSelectButton;
00007 } CONTROLTEXT, FAR * LPCONTROLTEXT;
00008
00009
00010 int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
00011 BOOL InitApplication(HANDLE);
00012 BOOL InitInstance(HANDLE, int);
00013 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00014 LRESULT CALLBACK ButtonProc(HWND, UINT, WPARAM, LPARAM);
00015 void HandleSelectedState(LPDRAWITEMSTRUCT lpdisCtrl, LPCONTROLTEXT lpCtlText);
00016 void HandleFocusState(LPDRAWITEMSTRUCT lpdis, LPRECT lpFocusRect, LPRECT lpSelectRect );
00017 void DrawBitmap(HDC hDC, RECT rect, HBITMAP hBitmap, DWORD rop);
00018 BOOL CALLBACK About(HWND, UINT, WPARAM, LPARAM);
00019
00020 #define BOB  10
00021 #define DEFAULTBUTTON  1
00022 #define SELECTEDBUTTON 2
00023
00024 #define     SubclassWindow(hwnd, lpfn)  \
00025     ((WNDPROC)SetWindowLong((hwnd), GWL_WNDPROC, (LPARAM)(WNDPROC)(lpfn)))
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CMNDLG.C Source File

  • CMNDLG

CMNDLG.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************
00013 *
00014 *
00015 *    PROGRAM: CmnDlg.c
00016 *
00017 *    PURPOSE: Sample demonstrating the use of the common dialogs in Windows
00018 *
00019 *    FUNCTIONS:
00020 *
00021 *        WinMain() - calls initialization function, processes message loop
00022 *        InitApplication() - initializes window data and registers window
00023 *        InitInstance() - saves instance handle and creates main window
00024 *        MainWndProc() - processes messages
00025 *        About() - processes messages for "About" dialog box
00026 *        OpenNewFile() - opens a new file
00027 *        SaveToFile() - saves the current text buffer to the current filename
00028 *        SaveAs() - saves the current text buffer to a new file name
00029 *        EnterNew() - to enter new text into the text buffer
00030 *        FileOpenHookProc() - Hook procedure for GetOpenFileName() common dialog
00031 *        FileSaveHookProc() - Hook procedure for GetSaveFileName() common dialog
00032 *        ChooseFontHookProc() - Hook procedure for ChooseFont() common dialog
00033 *        FindTextHookProc() - Hook procedure for FindText() common dialog
00034 *        ReplaceTextHookProc() - Hook procedure for the ReplaceText() common dialog
00035 *        PrintDlgHookProc() - Hook procedure for the PrintDlg() common dialog
00036 *        PrintSetupHookProc() - Hook procedure for the PrintDlg() setup common dialog
00037 *        SearchFile() - Searches for the specified text in the file buffer
00038 *        ChooseNewFont() - chooses a new font for display
00039 *        ChooseNewColor() - chooses a new color for display
00040 *        PrintFile() - prints the current text in the file buffer
00041 *        CallFindText() - calls the FindText() common dialog function
00042 *        CallReplaceText() - calls the ReplaceText() common dialog function
00043 *        ProcessCDError() - uses CommonDialogExtendedError() to output useful error messages
00044 *
00045 *    COMMENTS:
00046 *
00047 *
00048 *        The common dialog APIs demonstrated in the sample include:
00049 *
00050 *            ChooseColor()
00051 *            ChooseFont()
00052 *            FindText()
00053 *            GetOpenFileName()
00054 *            GetSaveFileName()
00055 *            PrintDlg()
00056 *            ReplaceText()
00057 *
00058 *
00059 *        Each dialog box is demonstrated being used in three different ways:
00060 *        standard, using a modified template and using a hook function.
00061 *
00062 *
00063 ****************************************************************************/
00064
00065 #include <windows.h>    // includes basic windows functionality
00066 #include <commdlg.h>    // includes common dialog functionality
00067 #include <dlgs.h>       // includes common dialog template defines
00068 #include <stdio.h>      // includes standard file i/o functionality
00069 #include <string.h>     // includes string functions
00070 #include <cderr.h>      // includes the common dialog error codes
00071 #include "cmndlg.h"     // includes my common dialog functions
00072
00073 HANDLE       hInst;
00074 OPENFILENAME OpenFileName;
00075 CHAR         szDirName[256]   = "";
00076 CHAR         szFile[256]      = "\0";
00077 CHAR         szFileTitle[256];
00078
00079 // Filter specification for the OPENFILENAME struct
00080 // This is portable for i386 and MIPS
00081 // Leaving out the \0 terminator will cause improper DWORD alignment
00082 // and cause a failure under MIPS
00083 CHAR szFilter[] = "Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0";
00084
00085 CHAR         FileBuf[FILE_LEN];
00086 DWORD        dwFileSize;
00087 UINT         FindReplaceMsg;
00088 CHAR         szFindString[64]   = "";
00089 CHAR         szReplaceString[64]   = "";
00090 FINDREPLACE  frText;
00091 LPFINDREPLACE lpFR;
00092 CHAR *       lpBufPtr = FileBuf;
00093 CHOOSEFONT   chf;
00094 CHOOSECOLOR  chsclr;
00095 COLORREF     crColor;
00096 LOGFONT      lf;
00097 WORD         wMode = IDM_STANDARD;
00098 HWND         hDlgFR = NULL;
00099 PRINTDLG     pd;
00100
00101 /****************************************************************************
00102 *
00103 *    FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00104 *
00105 *    PURPOSE: calls initialization function, processes message loop
00106 *
00107 *    COMMENTS:
00108 *
00109 *
00110 ****************************************************************************/
00111
00112 int PASCAL WinMain(
00113     HINSTANCE hInstance,
00114     HINSTANCE hPrevInstance,
00115     LPSTR lpCmdLine,
00116     int nCmdShow
00117     )
00118 {
00119
00120     MSG msg;                         /* message                      */
00121
00122     if (!hPrevInstance)                  /* Other instances of app running? */
00123         if (!InitApplication(hInstance)) /* Initialize shared things */
00124             return (FALSE);              /* Exits if unable to initialize     */
00125
00126     hInst = hInstance;
00127
00128     /* Perform initializations that apply to a specific instance */
00129
00130     if (!InitInstance(hInstance, nCmdShow))
00131         return (FALSE);
00132
00133     // register window message for FindText() and ReplaceText() hook procs
00134     FindReplaceMsg = RegisterWindowMessage( (LPSTR) FINDMSGSTRING );
00135
00136     /* Acquire and dispatch messages until a WM_QUIT message is received. */
00137
00138     while (GetMessage(&msg,        /* message structure                      */
00139             NULL,                  /* handle of window receiving the message */
00140             0,                     /* lowest message to examine              */
00141             0))                    /* highest message to examine             */
00142         if ( !hDlgFR || !IsWindow(hDlgFR) || !IsDialogMessage( hDlgFR, &msg ) )
00143             {
00144             TranslateMessage(&msg);    /* Translates virtual key codes */
00145             DispatchMessage(&msg);     /* Dispatches message to window */
00146             }
00147     return (msg.wParam);           /* Returns the value from PostQuitMessage */
00148
00149     // avoid compiler warnings at W3
00150     lpCmdLine;
00151 }
00152
00153
00154 /****************************************************************************
00155 *
00156 *    FUNCTION: InitApplication(HANDLE)
00157 *
00158 *    PURPOSE: Initializes window data and registers window class
00159 *
00160 *    COMMENTS:
00161 *
00162 *        In this function, we initialize a window class by filling out a data
00163 *        structure of type WNDCLASS and calling the Windows RegisterClass()
00164 *        function.
00165 *
00166 ****************************************************************************/
00167
00168 BOOL InitApplication(HANDLE hInstance)       /* current instance             */
00169 {
00170     WNDCLASS  wc;
00171
00172     /* Fill in window class structure with parameters that describe the       */
00173     /* main window.                                                           */
00174
00175     wc.style = 0;                       /* Class style(s).                    */
00176     wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
00177                                         /* windows of this class.             */
00178     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
00179     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
00180     wc.hInstance = hInstance;           /* Application that owns the class.   */
00181     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00182     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00183     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00184     wc.lpszMenuName =  "CmnDlgMenu";   /* Name of menu resource in .RC file. */
00185     wc.lpszClassName = "CmnDlgWClass"; /* Name used in call to CreateWindow. */
00186
00187     /* Register the window class and return success/failure code. */
00188
00189     return (RegisterClass(&wc));
00190
00191 }
00192
00193
00194 /****************************************************************************
00195 *
00196 *    FUNCTION:  InitInstance(HANDLE, int)
00197 *
00198 *    PURPOSE:  Saves instance handle and creates main window
00199 *
00200 *    COMMENTS:
00201 *
00202 *        In this function, we save the instance handle in a static variable and
00203 *        create and display the main program window.
00204 *
00205 ****************************************************************************/
00206
00207 BOOL InitInstance(
00208     HANDLE          hInstance,          /* Current instance identifier.       */
00209     int             nCmdShow)           /* Param for first ShowWindow() call. */
00210 {
00211     HWND            hWnd;               /* Main window handle.                */
00212
00213     /* Save the instance handle in static variable, which will be used in  */
00214     /* many subsequence calls from this application to Windows.            */
00215
00216     hInst = hInstance;
00217
00218     /* Create a main window for this application instance.  */
00219
00220     hWnd = CreateWindow(
00221         "CmnDlgWClass",                 /* See RegisterClass() call.          */
00222         "Common Dialogs Sample Application",   /* Text for window title bar.         */
00223         WS_OVERLAPPEDWINDOW,            /* Window style.                      */
00224         CW_USEDEFAULT,                  /* Default horizontal position.       */
00225         CW_USEDEFAULT,                  /* Default vertical position.         */
00226         CW_USEDEFAULT,                  /* Default width.                     */
00227         CW_USEDEFAULT,                  /* Default height.                    */
00228         NULL,                           /* Overlapped windows have no parent. */
00229         NULL,                           /* Use the window class menu.         */
00230         hInstance,                      /* This instance owns this window.    */
00231         NULL                            /* Pointer not needed.                */
00232     );
00233
00234     /* If window could not be created, return "failure" */
00235
00236     if (!hWnd)
00237         return (FALSE);
00238
00239     /* Make the window visible; update its client area; and return "success" */
00240
00241     ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
00242     UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */
00243     return (TRUE);               /* Returns the value from PostQuitMessage */
00244
00245 }
00246
00247 /****************************************************************************
00248 *
00249 *    FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
00250 *
00251 *    PURPOSE:  Processes messages
00252 *
00253 *    COMMENTS:
00254 *
00255 *        This function processes all messags sent to the window.  When the
00256 *        user choses one of the options from one of the menus, the command
00257 *        is processed here and passed onto the function for that command.
00258 *        This function also processes the special "FindReplace" message that
00259 *        this application registers for hook processing of the FindText()
00260 *        and ReplaceText() common dialog functions.
00261 *
00262 ****************************************************************************/
00263
00264 LRESULT CALLBACK MainWndProc(
00265         HWND hWnd,                /* window handle                   */
00266         UINT message,             /* type of message                 */
00267         WPARAM wParam,            /* additional information          */
00268         LPARAM lParam)            /* additional information          */
00269 {
00270     FARPROC lpProcAbout;          /* pointer to the "About" function */
00271     FARPROC lpProcEnterNew;       /* pointer to the "EnterNew" function */
00272     HDC hDC;
00273     PAINTSTRUCT ps;
00274     INT nDrawX;
00275     INT nDrawY;
00276     HFONT hFont;
00277     HANDLE Handle;
00278     static BOOL NewFont;
00279
00280     switch (message) {
00281
00282
00283         case WM_CREATE:
00284             //initialize the output on the screen
00285             strcpy( FileBuf, "Hello World!");
00286             lpBufPtr = FileBuf;
00287             dwFileSize = strlen(FileBuf);
00288             crColor = 0;
00289             NewFont = FALSE;
00290             break;
00291
00292
00293         case WM_PAINT:
00294             /* Set up a display context to begin painting */
00295             hDC = BeginPaint (hWnd, &ps);
00296
00297             /* Initialize drawing position to 1/4 inch from the top  */
00298             /* and from the left of the top, left corner of the      */
00299             /* client area of the main windows.                      */
00300             nDrawX = GetDeviceCaps(hDC, LOGPIXELSX) / 4;   /* 1/4 inch */
00301             nDrawY = GetDeviceCaps(hDC, LOGPIXELSY) / 4;   /* 1/4 inch */
00302
00303             if ( NewFont == TRUE )
00304             {
00305                 hFont = CreateFontIndirect( &lf );
00306                 Handle = SelectObject( hDC, hFont );
00307             }
00308
00309             SetTextColor( hDC, crColor );
00310             TextOut (hDC, nDrawX, nDrawY, (LPSTR)&FileBuf[0], dwFileSize);
00311
00312
00313             // end painting and release hDC
00314             EndPaint( hWnd, &ps );
00315             break;
00316
00317
00318         case WM_COMMAND:           /* message: command from application menu */
00319
00320             switch( LOWORD( wParam ))
00321             {
00322                 case IDM_OPENFILE:
00323                     if ( OpenNewFile( hWnd ) == TRUE )
00324                     {
00325                         // enable the Save As and Print menu items
00326                         EnableMenuItem( GetMenu( hWnd ), IDM_SAVEFILE,
00327                             MF_BYCOMMAND | MF_ENABLED );
00328                         EnableMenuItem( GetMenu( hWnd ), IDM_PRINT,
00329                             MF_BYCOMMAND | MF_ENABLED );
00330                         DrawMenuBar( hWnd);
00331                         // reset the title in the title bar to reflect the
00332                         // new open file
00333                         SetWindowText( hWnd, OpenFileName.lpstrFile );
00334                         // reset the current color and current font to the
00335                         // default
00336                         crColor = 0;
00337                         NewFont = FALSE;
00338                         InvalidateRect( hWnd, NULL, TRUE );
00339                     }
00340                     break;
00341
00342                 case IDM_SAVEFILE:
00343                     OpenFileName.Flags = 0L;
00344                     SaveToFile( hWnd );
00345                     break;
00346
00347                 case IDM_SAVEFILEAS:
00348                     if ( SaveAs( hWnd ) == TRUE )
00349                     {
00350                         EnableMenuItem( GetMenu( hWnd ), IDM_SAVEFILE,
00351                             MF_BYCOMMAND | MF_ENABLED );
00352                         SetWindowText( hWnd, OpenFileName.lpstrFile );
00353                         DrawMenuBar( hWnd );
00354                     }
00355                     break;
00356
00357                 case IDM_EXIT:
00358                     PostQuitMessage(0);
00359                     break;
00360
00361                 case IDM_PRINT:
00362                     PrintFile( hWnd );
00363                     break;
00364
00365                 case IDM_CHOOSECOLOR:
00366                     if (ChooseNewColor( hWnd ))
00367                         InvalidateRect( hWnd, NULL, TRUE );
00368                     break;
00369
00370                 case IDM_CHOOSEFONT:
00371                     if (NewFont = ChooseNewFont( hWnd ))
00372                         InvalidateRect( hWnd, NULL, TRUE );
00373
00374                     break;
00375
00376                 case IDM_FINDTEXT:
00377                     CallFindText( hWnd );
00378                     break;
00379
00380                 case IDM_REPLACETEXT:
00381                     CallReplaceText( hWnd );
00382                     break;
00383
00384                 case IDM_STANDARD:
00385                   // enable the ChooseColor() option
00386                     EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR,
00387                             MF_BYCOMMAND | MF_ENABLED );
00388                     // uncheck previous selection
00389                     CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
00390                     //reset mode
00391                     wMode = LOWORD(wParam);
00392                     //check new selection
00393                     CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
00394                     DrawMenuBar( hWnd);
00395                     break;
00396                 case IDM_HOOK:
00397                 case IDM_CUSTOM:
00398                     // disable the ChooseColor() option
00399                     EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR,
00400                             MF_BYCOMMAND | MF_GRAYED );
00401                      // uncheck previous selection
00402                     CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND);
00403                     //reset mode
00404                     wMode = LOWORD(wParam);
00405                     //check new selection
00406                     CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND);
00407                     DrawMenuBar( hWnd);
00408                     break;
00409
00410                 case IDM_ENTERNEW:
00411                     lpProcEnterNew = MakeProcInstance((FARPROC)EnterNew, hInst);
00412
00413                     if (DialogBox(hInst,                 /* current instance         */
00414                         "EnterNewBox",           /* resource to use          */
00415                         hWnd,                    /* parent handle            */
00416                         (DLGPROC)lpProcEnterNew) == TRUE)
00417
00418                         InvalidateRect( hWnd, NULL, TRUE );
00419
00420                     FreeProcInstance(lpProcEnterNew);
00421                     break;
00422
00423                 case IDM_ABOUT:
00424                     lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
00425
00426                     DialogBox(hInst,             /* current instance         */
00427                         "AboutBox",                      /* resource to use          */
00428                         hWnd,                    /* parent handle            */
00429                         (DLGPROC)lpProcAbout);           /* About() instance address */
00430
00431                     FreeProcInstance(lpProcAbout);
00432                     break;
00433
00434                 default:
00435                     return (DefWindowProc(hWnd, message, wParam, lParam));
00436
00437             }
00438             break;
00439
00440         case WM_DESTROY:                  /* message: window being destroyed */
00441             PostQuitMessage(0);
00442             break;
00443
00444
00445         default:
00446             // Handle the special findreplace message (FindReplaceMsg) which
00447             // was registered at initialization time.
00448             if ( message == FindReplaceMsg )
00449             {
00450                 if ( lpFR = (LPFINDREPLACE) lParam )
00451                     {
00452                     if (lpFR->Flags & FR_DIALOGTERM )  // terminating dialog
00453                         return (0);
00454                     SearchFile( lpFR );
00455                     InvalidateRect( hWnd, NULL, TRUE );
00456                     }
00457                 return (0);
00458             }
00459
00460             return (DefWindowProc(hWnd, message, wParam, lParam));
00461     }
00462     return (0);
00463 }
00464
00465
00466 /****************************************************************************
00467 *
00468 *    FUNCTION: EnterNew(HWND, UINT, WPARAM, LPARAM)
00469 *
00470 *    PURPOSE:  Processes messages for "EnterNew" dialog box
00471 *
00472 *    COMMENTS:
00473 *
00474 *        This function allows the user to enter new text in the current
00475 *        window.  This text is stored in the global current buffer.
00476 *
00477 ****************************************************************************/
00478
00479 BOOL CALLBACK EnterNew(
00480         HWND hDlg,                /* window handle of the dialog box */
00481         UINT message,             /* type of message                 */
00482         WPARAM wParam,            /* message-specific information    */
00483         LPARAM lParam)
00484 {
00485     CHAR Buf[FILE_LEN-1];
00486
00487     switch (message)
00488     {
00489         case WM_INITDIALOG:                /* message: initialize dialog box */
00490             return (TRUE);
00491
00492         case WM_COMMAND:                      /* message: received a command */
00493             if (LOWORD(wParam) == IDOK)
00494             {
00495                 GetDlgItemText( hDlg, IDEDIT, Buf, FILE_LEN-1);
00496                 strcpy( FileBuf, Buf);
00497                 lpBufPtr = FileBuf;
00498                 dwFileSize = strlen(FileBuf);
00499                 EndDialog( hDlg, TRUE );
00500                 return (TRUE);
00501             }
00502             else if (LOWORD(wParam) == IDCANCEL)
00503             {   /* System menu close command? */
00504                 EndDialog(hDlg, FALSE);       /* Exits the dialog box        */
00505                 return (TRUE);
00506             }
00507             break;
00508     }
00509     return (FALSE);                           /* Didn't process a message    */
00510
00511     // avoid compiler warnings at W3
00512     lParam;
00513 }
00514
00515
00516 /****************************************************************************
00517 *
00518 *    FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
00519 *
00520 *    PURPOSE:  Processes messages for "About" dialog box
00521 *
00522 *    COMMENTS:
00523 *
00524 *       No initialization is needed for this particular dialog box, but TRUE
00525 *       must be returned to Windows.
00526 *
00527 *       Wait for user to click on "Ok" button, then close the dialog box.
00528 *
00529 ****************************************************************************/
00530
00531 BOOL WINAPI About(
00532         HWND hDlg,                /* window handle of the dialog box */
00533         UINT message,             /* type of message                 */
00534         WPARAM wParam,            /* message-specific information    */
00535         LPARAM lParam)
00536 {
00537     switch (message)
00538     {
00539         case WM_INITDIALOG:                /* message: initialize dialog box */
00540             return (TRUE);
00541
00542         case WM_COMMAND:                      /* message: received a command */
00543             if (LOWORD(wParam) == IDOK          /* "OK" box selected?        */
00544                 || LOWORD(wParam) == IDCANCEL) {        /* System menu close command? */
00545                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
00546                 return (TRUE);
00547             }
00548             break;
00549     }
00550     return (FALSE);                           /* Didn't process a message    */
00551
00552     // avoid compiler warnings at W3
00553     lParam;
00554 }
00555
00556 /****************************************************************************
00557 *
00558 *    FUNCTION: FileOpenHookProc(HWND, UINT, WPARAM, LPARAM)
00559 *
00560 *    PURPOSE:  Processes messages for GetFileNameOpen() common dialog box
00561 *
00562 *    COMMENTS:
00563 *
00564 *        This function will prompt the user if they are sure they want
00565 *        to open the file if the OFN_ENABLEHOOK flag is set.
00566 *
00567 *        If the current option mode is CUSTOM, the user is allowed to check
00568 *        a box in the dialog prompting them whether or not they would like
00569 *        the file created.  If they check this box, the file is created and
00570 *        the string 'Empty' is written to it.
00571 *
00572 *    RETURN VALUES:
00573 *        TRUE - User chose 'Yes' from the "Are you sure message box".
00574 *        FALSE - User chose 'No'; return to the dialog box.
00575 *
00576 ****************************************************************************/
00577
00578 BOOL CALLBACK FileOpenHookProc(
00579         HWND hDlg,                /* window handle of the dialog box */
00580         UINT message,             /* type of message                 */
00581         WPARAM wParam,            /* message-specific information    */
00582         LPARAM lParam)
00583 {
00584
00585     int hFile;
00586     CHAR szTempText[256];
00587     CHAR szString[256];
00588     OFSTRUCT OfStruct;
00589
00590     switch (message)
00591     {
00592
00593         case WM_COMMAND:
00594             if (LOWORD(wParam) == IDOK)
00595             {
00596                 GetDlgItemText( hDlg, edt1, szTempText,
00597                         sizeof( szTempText ) - 1);
00598
00599                 if ( OpenFileName.Flags & OFN_PATHMUSTEXIST )
00600                 {
00601                     sprintf( szString, "Are you sure you want to open %s?",
00602                         szTempText);
00603                     if ( MessageBox( hDlg, szString, "Information",
00604                         MB_YESNO ) == IDYES )
00605
00606                         break;
00607                     return (TRUE);
00608                 }
00609
00610                 // check to see if the Create File box has been checked
00611                 if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
00612                     BM_GETCHECK, 0, 0L )) == TRUE )
00613                 {
00614                     // if so, create the file
00615                     if ((hFile = OpenFile(szTempText,
00616                         &OfStruct,
00617                         OF_CREATE)) == -1)
00618                     {
00619                         MessageBox( hDlg,
00620                             "Directory could not be created.",
00621                             NULL,
00622                             MB_OK );
00623                         return (FALSE);
00624                     }
00625
00626                     strcpy(FileBuf, "Empty");
00627                     lpBufPtr = FileBuf;
00628                     dwFileSize = strlen(FileBuf);
00629                     if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
00630                         MessageBox( hDlg, "Error writing file.", NULL, MB_OK );
00631
00632                     // close the file
00633                     _lclose( hFile );
00634                 }
00635
00636             }
00637             break;
00638     }
00639     return (FALSE);
00640
00641     // avoid compiler warnings at W3
00642     lParam;
00643
00644 }
00645
00646 /****************************************************************************
00647 *
00648 *    FUNCTION: OpenNewFile(HWND)
00649 *
00650 *    PURPOSE:  Invokes common dialog function to open a file and opens it.
00651 *
00652 *    COMMENTS:
00653 *
00654 *        This function initializes the OPENFILENAME structure and calls
00655 *        the GetOpenFileName() common dialog function.  This function will
00656 *        work regardless of the mode: standard, using a hook or using a
00657 *        customized template.
00658 *
00659 *    RETURN VALUES:
00660 *        TRUE - The file was opened successfully and read into the buffer.
00661 *        FALSE - No files were opened.
00662 *
00663 ****************************************************************************/
00664 BOOL OpenNewFile( HWND hWnd )
00665 {
00666    int hFile;
00667    int cBufLen;
00668    OFSTRUCT OfStruct;
00669    WORD wStyle;
00670
00671    strcpy( szFile, "");
00672    strcpy( szFileTitle, "");
00673
00674    OpenFileName.lStructSize       = sizeof(OPENFILENAME);
00675    OpenFileName.hwndOwner         = hWnd;
00676    OpenFileName.hInstance         = (HANDLE) hInst;
00677    OpenFileName.lpstrFilter       = szFilter;
00678    OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
00679    OpenFileName.nMaxCustFilter    = 0L;
00680    OpenFileName.nFilterIndex      = 1L;
00681    OpenFileName.lpstrFile         = szFile;
00682    OpenFileName.nMaxFile          = sizeof(szFile);
00683    OpenFileName.lpstrFileTitle    = szFileTitle;
00684    OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
00685    OpenFileName.lpstrInitialDir   = NULL;
00686    OpenFileName.lpstrTitle        = "Open a File";
00687    OpenFileName.nFileOffset       = 0;
00688    OpenFileName.nFileExtension    = 0;
00689    OpenFileName.lpstrDefExt       = "*.txt";
00690    OpenFileName.lCustData         = 0;
00691
00692    switch( wMode )
00693    {
00694         case IDM_STANDARD:
00695             OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
00696                 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
00697             break;
00698
00699         case IDM_HOOK:
00700             OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
00701                 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
00702             OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
00703             break;
00704
00705         case IDM_CUSTOM:
00706             OpenFileName.Flags = OFN_SHOWHELP | OFN_ENABLEHOOK |
00707                 OFN_HIDEREADONLY | OFN_ENABLETEMPLATE;
00708             OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL);
00709             OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
00710             break;
00711    }
00712
00713    if (GetOpenFileName(&OpenFileName))
00714    {
00715       if (OpenFileName.Flags & OFN_READONLY )
00716         wStyle = OF_READ;
00717       else
00718         wStyle = OF_READWRITE;
00719
00720       // open the file
00721       hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct, wStyle );
00722       if (hFile == -1)
00723       {
00724          MessageBox( hWnd, "File open failed.", NULL, MB_OK );
00725          return FALSE;
00726       }
00727       // read it's contents into a buffer
00728       cBufLen = _lread( hFile, FileBuf, FILE_LEN );
00729       lpBufPtr = FileBuf;
00730
00731       if (cBufLen == -1)
00732       {
00733          MessageBox( hWnd, "Zero bytes read.", NULL, MB_OK );
00734          return FALSE;
00735       }
00736       // close the file
00737       _lclose( hFile );
00738
00739       dwFileSize = cBufLen;
00740     }
00741     else
00742     {
00743       ProcessCDError(CommDlgExtendedError(), hWnd );
00744       return FALSE;
00745     }
00746     return TRUE;
00747 }
00748
00749 /****************************************************************************
00750 *
00751 *    FUNCTION: SaveToFile( HWND )
00752 *
00753 *    PURPOSE:  Saves the current buffer to the current file.
00754 *
00755 *    COMMENTS:
00756 *
00757 *        This function will save the current text buffer into the file
00758 *        specified from the GetSaveFileName() common dialog function.
00759 *
00760 *    RETURN VALUES:
00761 *        TRUE - The file was saved successfully.
00762 *        FALSE - The buffer was not saved to a file.
00763 *
00764 ****************************************************************************/
00765 BOOL SaveToFile( HWND hWnd )
00766 {
00767    int hFile;
00768    OFSTRUCT OfStruct;
00769    WORD wStyle;
00770    CHAR buf[256];
00771
00772    if (OpenFileName.Flags | OFN_FILEMUSTEXIST)
00773         wStyle = OF_READWRITE;
00774    else
00775         wStyle = OF_READWRITE | OF_CREATE;
00776
00777    if ((hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct,
00778          wStyle)) == -1)
00779    {
00780       sprintf( buf, "Could not create file %s", OpenFileName.lpstrFile );
00781       MessageBox( hWnd, buf, NULL, MB_OK );
00782       return FALSE;
00783    }
00784    // write it's contents into a file
00785    if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1)
00786    {
00787       MessageBox( hWnd, "Error writing file.", NULL, MB_OK );
00788       return FALSE;
00789    }
00790
00791    // close the file
00792    _lclose( hFile );
00793
00794    sprintf( buf, "%s", OpenFileName.lpstrFile );
00795    MessageBox( hWnd, buf, "File Saved", MB_OK );
00796    return TRUE;
00797 }
00798
00799
00800 /****************************************************************************
00801 *
00802 *    FUNCTION: FileSaveHookProc(HWND, UINT, WPARAM, LPARAM)
00803 *
00804 *    PURPOSE:  Processes messages for FileSave common dialog box
00805 *
00806 *    COMMENTS:
00807 *
00808 *        This hook procedure prompts the user if they want to save the
00809 *        current file.  If they choose YES, the file is saved and the dialog
00810 *        is dismissed.  If they choose NO, they are returned to the
00811 *        GetSaveFileName() common dialog.
00812 *
00813 *        If the current mode calls for a customized template, this function
00814 *        will test the 'Create File?' checkbox.  If the user choses no, the
00815 *        OFN_FILEMUSTEXIST flag is set.
00816 *
00817 *    RETURN VALUES:
00818 *        TRUE - User chose 'Yes' from the "Are you sure message box".
00819 *        FALSE - User chose 'No'; return to the dialog box.
00820 *
00821 *
00822 ****************************************************************************/
00823
00824 BOOL CALLBACK FileSaveHookProc(
00825         HWND hDlg,                /* window handle of the dialog box */
00826         UINT message,             /* type of message                 */
00827         WPARAM wParam,            /* message-specific information    */
00828         LPARAM lParam)
00829 {
00830     CHAR szTempText[256];
00831     CHAR szString[256];
00832
00833     switch (message)
00834     {
00835         case WM_COMMAND:
00836             if (LOWORD(wParam) == IDOK)
00837             {
00838                 GetDlgItemText( hDlg, edt1, szTempText,
00839                     sizeof( szTempText ) - 1);
00840                 if ( OpenFileName.Flags & OFN_ENABLETEMPLATE )
00841                 {
00842                     // check to see if the Create File box has been checked
00843                     if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2),
00844                         BM_GETCHECK, 0, 0L )) == FALSE )
00845                         OpenFileName.Flags |= OFN_FILEMUSTEXIST;
00846                     break;
00847
00848                 }
00849                 else
00850                 {
00851                     sprintf( szString, "Are you sure you want to save %s?",
00852                         szTempText);
00853                     if ( MessageBox( hDlg, szString, "Information",
00854                         MB_YESNO ) == IDYES )
00855                         break;
00856                     return(TRUE);
00857                 }
00858
00859             }
00860             break;
00861     }
00862     return (FALSE);
00863
00864     // avoid compiler warnings at W3
00865     lParam;
00866
00867 }
00868
00869 /****************************************************************************
00870 *
00871 *    FUNCTION: SaveAs(HWND)
00872 *
00873 *    PURPOSE:  Invokes the common dialog function to save the current
00874 *              buffer to a file.
00875 *    COMMENTS:
00876 *
00877 *        This function initializes the OPENFILENAME structure for any
00878 *        mode selected by the user: standard, using a hook or using a
00879 *        customized template.  It then calls the GetSaveFileName()
00880 *        common dialog function.
00881 *
00882 *    RETURN VALUES:
00883 *        TRUE - The file was saved successfully.
00884 *        FALSE - The buffer was not saved to a file.
00885 *
00886 ****************************************************************************/
00887 BOOL SaveAs( HWND hWnd )
00888 {
00889
00890    strcpy( szFile, "");
00891    strcpy( szFileTitle, "");
00892
00893    OpenFileName.lStructSize       = sizeof(OPENFILENAME);
00894    OpenFileName.hwndOwner         = hWnd;
00895    OpenFileName.hInstance         = (HANDLE) hInst;
00896    OpenFileName.lpstrFilter       = szFilter;
00897    OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
00898    OpenFileName.nMaxCustFilter    = 0L;
00899    OpenFileName.nFilterIndex      = 1L;
00900    OpenFileName.lpstrFile         = szFile;
00901    OpenFileName.nMaxFile          = sizeof(szFile);
00902    OpenFileName.lpstrFileTitle    = szFileTitle;
00903    OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
00904    OpenFileName.lpstrInitialDir   = NULL;
00905    OpenFileName.lpstrTitle        = "Save File As";
00906    OpenFileName.nFileOffset       = 0;
00907    OpenFileName.nFileExtension    = 0;
00908    OpenFileName.lpstrDefExt       = "txt";
00909    OpenFileName.lCustData         = 0;
00910
00911    switch( wMode )
00912    {
00913         case IDM_STANDARD:
00914             OpenFileName.Flags = 0L;
00915             OpenFileName.lpfnHook = (LPOFNHOOKPROC)(FARPROC)NULL;
00916             OpenFileName.lpTemplateName = (LPSTR)NULL;
00917             break;
00918
00919         case IDM_HOOK:
00920             OpenFileName.Flags = OFN_ENABLEHOOK;
00921             OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
00922             OpenFileName.lpTemplateName = (LPSTR)NULL;
00923             break;
00924
00925         case IDM_CUSTOM:
00926             OpenFileName.Flags = OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
00927             OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL);
00928             OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD);
00929             break;
00930    }
00931
00932    if ( GetSaveFileName( &OpenFileName ))
00933         return(SaveToFile( hWnd ));
00934    else
00935    {
00936         ProcessCDError(CommDlgExtendedError(), hWnd );
00937         return FALSE;
00938    }
00939
00940    return (FALSE);
00941 }
00942
00943
00944 /****************************************************************************
00945 *
00946 *    FUNCTION: ChooseColorHookProc(HWND, UINT, WPARAM, LPARAM)
00947 *
00948 *    PURPOSE:  Processes messages for ChooseColor common dialog box
00949 *
00950 *    COMMENTS:
00951 *
00952 *        This hook procedure simply prompts the user whether or not they
00953 *        want to change the color.  if they choose YES, the color of the
00954 *        text will be changed and the dialog will be dismissed.  If they
00955 *        choose NO, the color will not be changed and the user will be
00956 *        returned to the dialog
00957 *
00958 *    RETURN VALUES:
00959 *        TRUE - User chose 'Yes' from the "Are you sure message box".
00960 *        FALSE - User chose 'No'; return to the dialog box.
00961 *
00962 ****************************************************************************/
00963
00964 BOOL CALLBACK ChooseColorHookProc(
00965         HWND hDlg,                /* window handle of the dialog box */
00966         UINT message,             /* type of message                 */
00967         WPARAM wParam,            /* message-specific information    */
00968         LPARAM lParam)
00969 {
00970
00971     switch (message)
00972     {
00973         case WM_COMMAND:
00974             if (LOWORD(wParam) == IDOK)
00975             {
00976                 if (MessageBox( hDlg, "Are you sure you want to change the color?",
00977                     "Information", MB_YESNO ) == IDYES )
00978                     break;
00979                 return (TRUE);
00980
00981             }
00982             break;
00983     }
00984     return (FALSE);
00985
00986     // avoid compiler warnings at W3
00987     lParam;
00988
00989 }
00990
00991
00992 /****************************************************************************
00993 *
00994 *    FUNCTION: ChooseNewColor(HWND)
00995 *
00996 *    PURPOSE:  Invokes common dialog function to chose a new color.
00997 *
00998 *    COMMENTS:
00999 *        This function initializes the CHOOSECOLOR structure for any
01000 *        mode the user chooses: standard, using a hook or using a
01001 *        customized template.  It then calls the ChooseColor()
01002 *        common dialog function.
01003 *
01004 *    RETURN VALUES:
01005 *        TRUE - A new color was chosen.
01006 *        FALSE - No new color was chosen.
01007 *
01008 ****************************************************************************/
01009 BOOL ChooseNewColor( HWND hWnd )
01010 {
01011
01012     DWORD dwColor;
01013     DWORD dwCustClrs[16];
01014     BOOL fSetColor = FALSE;
01015     int i;
01016
01017
01018     for (i=0; i < 15; i++)
01019         dwCustClrs[i] = RGB( 255, 255, 255);
01020
01021     dwColor = RGB( 0, 0, 0 );
01022
01023     chsclr.lStructSize = sizeof(CHOOSECOLOR);
01024     chsclr.hwndOwner = hWnd;
01025     chsclr.hInstance = (HANDLE)hInst;
01026     chsclr.rgbResult = dwColor;
01027     chsclr.lpCustColors = (LPDWORD)dwCustClrs;
01028     chsclr.lCustData = 0L;
01029
01030     switch( wMode )
01031     {
01032         case IDM_HOOK:
01033         case IDM_CUSTOM:
01034             chsclr.Flags = CC_PREVENTFULLOPEN | CC_ENABLEHOOK;
01035             chsclr.lpfnHook = (LPCCHOOKPROC)MakeProcInstance(ChooseColorHookProc, NULL);
01036             chsclr.lpTemplateName = (LPSTR)NULL;
01037             break;
01038
01039         case IDM_STANDARD:
01040             chsclr.Flags = CC_PREVENTFULLOPEN;
01041             chsclr.lpfnHook = (LPCCHOOKPROC)(FARPROC)NULL;
01042             chsclr.lpTemplateName = (LPSTR)NULL;
01043             break;
01044
01045
01046    }
01047
01048    if ( fSetColor = ChooseColor( &chsclr ))
01049    {
01050        crColor = chsclr.rgbResult;
01051        return (TRUE);
01052    }
01053    else
01054    {
01055        ProcessCDError(CommDlgExtendedError(), hWnd );
01056        return FALSE;
01057    }
01058 }
01059
01060
01061 /****************************************************************************
01062 *
01063 *    FUNCTION: ChooseFontHookProc(HWND, UINT, WPARAM, LPARAM)
01064 *
01065 *    PURPOSE:  Processes messages for ChooseFont common dialog box
01066 *
01067 *    COMMENTS:
01068 *
01069 *        This hook procedure simply prompts the user whether or not they
01070 *        want to change the font.  if they choose YES, the color of the
01071 *        font will be changed and the dialog will be dismissed.  If they
01072 *        choose NO, the font will not be changed and the user will be
01073 *        returned to the dialog
01074 *
01075 *        If the current mode is set to use a customized template, the
01076 *        color drop down combo box is hidden.
01077 *
01078 *    RETURN VALUES:
01079 *        TRUE - Change the font.
01080 *        FALSE - Return to the dialog box.
01081 *
01082 ****************************************************************************/
01083
01084 BOOL CALLBACK ChooseFontHookProc(
01085         HWND hDlg,                /* window handle of the dialog box */
01086         UINT message,             /* type of message                 */
01087         WPARAM wParam,            /* message-specific information    */
01088         LPARAM lParam)
01089 {
01090
01091     switch (message)
01092     {
01093         case WM_INITDIALOG:
01094             if (chf.Flags & CF_ENABLETEMPLATE)
01095             {
01096                 ShowWindow(GetDlgItem(hDlg, stc4), SW_HIDE);
01097                 ShowWindow(GetDlgItem(hDlg, cmb4), SW_HIDE);
01098             }
01099             break;
01100
01101         case WM_COMMAND:
01102             if (LOWORD(wParam) == IDOK)
01103             {
01104                 if (MessageBox( hDlg, "Are you sure you want to change the font?",
01105                     "Information", MB_YESNO ) == IDYES )
01106                     break;
01107                 return (TRUE);
01108
01109             }
01110             break;
01111     }
01112     return (FALSE);
01113
01114     // avoid compiler warnings at W3
01115     lParam;
01116
01117 }
01118
01119
01120 /****************************************************************************
01121 *
01122 *    FUNCTION: ChooseNewFont(HWND)
01123 *
01124 *    PURPOSE:  Invokes common dialog function to chose a new font.
01125 *
01126 *    COMMENTS:
01127 *
01128 *        This function initializes the CHOOSEFONT structure for any mode
01129 *        the user chooses: standard, using a hook or using a customized
01130 *        template.  It then calls the ChooseFont() common dialog function.
01131 *
01132 *    RETURN VALUES:
01133 *        TRUE - A new font was chosen.
01134 *        FALSE - No new font was chosen.
01135 *
01136 ****************************************************************************/
01137 BOOL ChooseNewFont( HWND hWnd )
01138 {
01139
01140    HDC hDC;
01141
01142    hDC = GetDC( hWnd );
01143    chf.hDC = CreateCompatibleDC( hDC );
01144    ReleaseDC( hWnd, hDC );
01145    chf.lStructSize = sizeof(CHOOSEFONT);
01146    chf.hwndOwner = hWnd;
01147    chf.lpLogFont = &lf;
01148    chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
01149    chf.rgbColors = RGB(0, 255, 255);
01150    chf.lCustData = 0;
01151    chf.hInstance = (HANDLE)hInst;
01152    chf.lpszStyle = (LPSTR)NULL;
01153    chf.nFontType = SCREEN_FONTTYPE;
01154    chf.nSizeMin = 0;
01155    chf.nSizeMax = 0;
01156
01157    switch( wMode )
01158    {
01159         case IDM_STANDARD:
01160             chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
01161             chf.lpfnHook = (LPCFHOOKPROC)(FARPROC)NULL;
01162             chf.lpTemplateName = (LPSTR)NULL;
01163             break;
01164
01165         case IDM_HOOK:
01166             chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK;
01167             chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
01168             chf.lpTemplateName = (LPSTR)NULL;
01169             break;
01170
01171         case IDM_CUSTOM:
01172             chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK |
01173               CF_ENABLETEMPLATE;
01174             chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL);
01175             chf.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FORMATDLGORD31);
01176             break;
01177    }
01178
01179
01180    if( ChooseFont( &chf ) == FALSE )
01181    {
01182         DeleteDC( hDC );
01183         ProcessCDError(CommDlgExtendedError(), hWnd );
01184         return FALSE;
01185    }
01186
01187
01188    DeleteDC( hDC );
01189
01190    return (TRUE);
01191 }
01192
01193 /****************************************************************************
01194 *
01195 *    FUNCTION: PrintSetupHookProc(HWND, UINT, WPARAM, LPARAM)
01196 *
01197 *    PURPOSE:  Processes messages for PrintDlg setup common dialog box
01198 *
01199 *    COMMENTS:
01200 *
01201 *        This function processes the hook and customized template for the
01202 *        print setup common dialog box.  If the customized template has
01203 *        been provided, the 'Options' pushbutton is hidden.  If the hook only mode
01204 *        is chosen, a message box is displayed informing the user that the
01205 *        hook has been installed.
01206 *
01207 *    RETURN VALUES:
01208 *        TRUE - Continue.
01209 *        FALSE - Return to the dialog box.
01210 *
01211 ****************************************************************************/
01212
01213 BOOL CALLBACK PrintSetupHookProc(
01214         HWND hDlg,                /* window handle of the dialog box */
01215         UINT message,             /* type of message                 */
01216         WPARAM wParam,            /* message-specific information    */
01217         LPARAM lParam)
01218 {
01219
01220     switch (message)
01221     {
01222         case WM_INITDIALOG:
01223             if (pd.Flags & PD_ENABLESETUPTEMPLATE )
01224             {
01225                 ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE );
01226                 return(TRUE);
01227             }
01228             MessageBox( hDlg,
01229                     "Hook installed.",
01230                     "Information", MB_OK );
01231             return (TRUE);
01232     }
01233     return (FALSE);
01234
01235     // avoid compiler warnings at W3
01236     lParam;
01237     wParam;
01238 }
01239
01240
01241
01242 /****************************************************************************
01243 *
01244 *    FUNCTION: PrintDlgHookProc(HWND, UINT, UINT, LONG)
01245 *
01246 *    PURPOSE:  Processes messages for PrintDlg common dialog box
01247 *
01248 *    COMMENTS:
01249 *
01250 *        This hook procedure simply prompts the user whether or not they
01251 *        want to print.  if they choose YES, the text buf will be printed
01252 *        and the dialog will be dismissed.  If they choose NO, the text buf
01253 *        will not be printeded and the user will be returned to the dialog.
01254 *
01255 *        If the current mode is 'custom', the 'Print to file' and 'Collate
01256 *        Copies' options are hidden.
01257 *
01258 *    RETURN VALUES:
01259 *        TRUE - Continue.
01260 *        FALSE - Return to the dialog box.
01261 *
01262 ****************************************************************************/
01263
01264 BOOL CALLBACK PrintDlgHookProc(
01265         HWND hDlg,                /* window handle of the dialog box */
01266         UINT message,             /* type of message                 */
01267         WPARAM wParam,            /* message-specific information    */
01268         LPARAM lParam)
01269 {
01270
01271     switch (message)
01272     {
01273         case WM_INITDIALOG:
01274             if (pd.Flags & PD_ENABLEPRINTTEMPLATE )
01275             {
01276                 ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
01277                 ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
01278                 return(TRUE);
01279             }
01280             MessageBox( hDlg,
01281                     "Hook installed.",
01282                     "Information", MB_OK );
01283             return (TRUE);
01284
01285         case WM_COMMAND:
01286             if (LOWORD(wParam) == IDOK)
01287             {
01288                 if (MessageBox( hDlg, "Are you sure you want to print?",
01289                     "Information", MB_YESNO ) == IDYES )
01290                     break;
01291                 return (TRUE);
01292
01293             }
01294             break;
01295     }
01296     return (FALSE);
01297
01298     // avoid compiler warnings at W3
01299     lParam;
01300
01301 }
01302
01303
01304 /****************************************************************************
01305 *
01306 *    FUNCTION: PrintFile(HWND)
01307 *
01308 *    PURPOSE:  Invokes common dialog function to print.
01309 *
01310 *    COMMENTS:
01311 *
01312 *        This function initializes the PRINTDLG structure for all modes
01313 *        possible: standard, using a hook or using a customized template.
01314 *        When hook mode is chosen, a hook is installed for both the
01315 *        Print dialog and the Print Setup dialog.  When custom mode is
01316 *        chosen, the templates are enabled for both the print dialog and
01317 *        the Print Setup dialog boxes.
01318 *
01319 *        If the PrintDlg() common dialog returns TRUE, the current
01320 *        text buffer is printed out.
01321 *
01322 *
01323 *    RETURN VALUES:
01324 *        void.
01325 *
01326 ****************************************************************************/
01327 void PrintFile( HWND hWnd )
01328 {
01329
01330
01331     // initialize PRINTDLG structure
01332     pd.lStructSize = sizeof(PRINTDLG);
01333     pd.hwndOwner = hWnd;
01334     pd.hDevMode = (HANDLE)NULL;
01335     pd.hDevNames = (HANDLE)NULL;
01336     pd.nFromPage = 0;
01337     pd.nToPage = 0;
01338     pd.nMinPage = 0;
01339     pd.nMaxPage = 0;
01340     pd.nCopies = 0;
01341     pd.hInstance = (HANDLE)hInst;
01342
01343
01344     switch( wMode )
01345     {
01346         case IDM_STANDARD:
01347             pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | PD_PRINTSETUP;
01348             pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL;
01349             pd.lpSetupTemplateName = (LPSTR)NULL;
01350             pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL;
01351             pd.lpPrintTemplateName = (LPSTR)NULL;
01352             break;
01353
01354         case IDM_HOOK:
01355             pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
01356                 PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP;
01357             pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
01358             pd.lpSetupTemplateName = (LPSTR)NULL;
01359             pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
01360             pd.lpPrintTemplateName = (LPSTR)NULL;
01361             break;
01362
01363         case IDM_CUSTOM:
01364             pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
01365                 PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
01366                 PD_ENABLESETUPHOOK | PD_ENABLESETUPTEMPLATE | PD_PRINTSETUP;
01367             pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL);
01368             pd.lpSetupTemplateName = (LPSTR)MAKEINTRESOURCE(PRNSETUPDLGORD);
01369             pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL);
01370             pd.lpPrintTemplateName = (LPSTR)MAKEINTRESOURCE(PRINTDLGORD);
01371             break;
01372
01373     }
01374
01375     //print a test page if successful
01376     if (PrintDlg(&pd) == TRUE)
01377     {
01378         Escape(pd.hDC, STARTDOC, 8, "Test-Doc", NULL);
01379
01380         //Print text
01381         TextOut(pd.hDC, 5, 5, FileBuf, strlen(FileBuf));
01382
01383         Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
01384         Escape(pd.hDC, ENDDOC, 0, NULL, NULL );
01385         DeleteDC(pd.hDC);
01386         if (pd.hDevMode)
01387             GlobalFree(pd.hDevMode);
01388         if (pd.hDevNames)
01389             GlobalFree(pd.hDevNames);
01390     }
01391    else
01392         ProcessCDError(CommDlgExtendedError(), hWnd );
01393 }
01394
01395
01396 /****************************************************************************
01397 *
01398 *    FUNCTION: ReplaceTextHookProc(HWND, UINT, WPARAM, LPARAM)
01399 *
01400 *    PURPOSE:  Processes messages for ReplaceText common dialog box
01401 *
01402 *    COMMENTS:
01403 *
01404 *        Puts up a message stating that the hook is active if hook
01405 *        only active.  Otherwise, if template enabled, hides the
01406 *        Replace All pushbutton, plus the 'Match case' and
01407 *        'Match whole word' check box options.
01408 *
01409 *    RETURN VALUES:
01410 *        TRUE - Continue.
01411 *        FALSE - Return to the dialog box.
01412 *
01413 ****************************************************************************/
01414
01415 BOOL CALLBACK ReplaceTextHookProc(
01416         HWND hDlg,                /* window handle of the dialog box */
01417         UINT message,             /* type of message                 */
01418         WPARAM wParam,            /* message-specific information    */
01419         LPARAM lParam)
01420 {
01421     switch (message)
01422     {
01423         case WM_INITDIALOG:
01424             if (frText.Flags & FR_ENABLETEMPLATE )
01425                 {
01426                     ShowWindow( GetDlgItem(hDlg, psh2), SW_HIDE );
01427                     ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
01428                     ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
01429                 }
01430             MessageBox( hDlg,
01431                     "Hook installed.",
01432                     "Information", MB_OK );
01433             return (TRUE);
01434
01435
01436         default:
01437             break;
01438     }
01439     return (FALSE);
01440
01441     // avoid compiler warnings at W3
01442     lParam;
01443     wParam;
01444 }
01445
01446 /****************************************************************************
01447 *
01448 *    FUNCTION: FindTextHookProc(HWND, UINT, UINT, LONG)
01449 *
01450 *    PURPOSE:  Processes messages for FindText common dialog box
01451 *
01452 *    COMMENTS:
01453 *
01454 *        Puts up a message stating that the hook is active if hook
01455 *        only enabled.  If custom template, hides the 'Match case'
01456 *        and 'Match whole word' options, hides the group box 'Direction'
01457 *        with the radio buttons 'Up' and 'Down'.
01458 *
01459 *    RETURN VALUES:
01460 *        TRUE - Continue.
01461 *        FALSE - Return to the dialog box.
01462 *
01463 ****************************************************************************/
01464
01465 BOOL CALLBACK FindTextHookProc(
01466         HWND hDlg,                /* window handle of the dialog box */
01467         UINT message,             /* type of message                 */
01468         WPARAM wParam,            /* message-specific information    */
01469         LPARAM lParam)
01470 {
01471
01472     switch (message)
01473     {
01474         case WM_INITDIALOG:
01475             if (frText.Flags & FR_ENABLETEMPLATE )
01476             {
01477                 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
01478                 ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE);
01479                 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
01480                 ShowWindow(GetDlgItem(hDlg, rad1), SW_HIDE);
01481                 ShowWindow(GetDlgItem(hDlg, rad2), SW_HIDE);
01482             }
01483             MessageBox( hDlg,
01484                     "Hook installed.",
01485                     "Information", MB_OK );
01486             return (TRUE);
01487
01488
01489         default:
01490             break;
01491     }
01492     return (FALSE);
01493
01494     // avoid compiler warnings at W3
01495     lParam;
01496     wParam;
01497 }
01498
01499
01500 /****************************************************************************
01501 *
01502 *    FUNCTION: CallFindText( HWND )
01503 *
01504 *    PURPOSE:  Initializes and calls the FindText()
01505 *        common dialog.
01506 *
01507 *    COMMENTS:
01508 *
01509 *        This function initialzes the FINDREPLACE structure for any mode:
01510 *        standard, using a hook or using a customized template.  It then
01511 *        calls the FindText() common dialog function.
01512 *
01513 *    RETURN VALUES:
01514 *        void.
01515 *
01516 ****************************************************************************/
01517 void CallFindText( HWND hWnd )
01518 {
01519
01520     frText.lStructSize = sizeof( frText );
01521     frText.hwndOwner = hWnd;
01522     frText.hInstance = (HANDLE)hInst;
01523     frText.lpstrFindWhat = szFindString;
01524     frText.lpstrReplaceWith = (LPSTR)NULL;
01525     frText.wFindWhatLen = sizeof(szFindString);
01526     frText.wReplaceWithLen = 0;
01527     frText.lCustData = 0;
01528     lpBufPtr = FileBuf;
01529
01530     switch( wMode )
01531     {
01532         case IDM_STANDARD:
01533             frText.Flags =  FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
01534             frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
01535             frText.lpTemplateName = (LPSTR)NULL;
01536             break;
01537
01538         case IDM_HOOK:
01539             frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
01540                 FR_ENABLEHOOK;
01541             frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
01542             frText.lpTemplateName = (LPSTR)NULL;
01543             break;
01544
01545         case IDM_CUSTOM:
01546             frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
01547                  FR_ENABLEHOOK | FR_ENABLETEMPLATE;
01548             frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL);
01549             frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FINDDLGORD);
01550             break;
01551     }
01552
01553     if ((hDlgFR = FindText(&frText)) == NULL)
01554         ProcessCDError(CommDlgExtendedError(), hWnd );
01555
01556 }
01557
01558
01559 /****************************************************************************
01560 *
01561 *    FUNCTION: CallReplaceText( HWND )
01562 *
01563 *    PURPOSE:  Initializes and calls the ReplaceText()
01564 *        common dialog.
01565 *
01566 *    COMMENTS:
01567 *
01568 *        This function initialzes the FINDREPLACE structure for any mode:
01569 *        standard, using a hook or using a customized template.  It then
01570 *        calls the ReplaceText() common dialog function.
01571 *
01572 *    RETURN VALUES:
01573 *        void.
01574 *
01575 ****************************************************************************/
01576 void CallReplaceText( HWND hWnd )
01577 {
01578     frText.lStructSize = sizeof( frText );
01579     frText.hwndOwner = hWnd;
01580     frText.hInstance = (HANDLE)hInst;
01581     frText.lpstrFindWhat = szFindString;
01582     frText.lpstrReplaceWith = szReplaceString;
01583     frText.wFindWhatLen = sizeof(szFindString);
01584     frText.wReplaceWithLen = sizeof( szReplaceString );
01585     frText.lCustData = 0;
01586     lpBufPtr = FileBuf;
01587
01588     switch( wMode )
01589     {
01590         case IDM_STANDARD:
01591             frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
01592             frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
01593             frText.lpTemplateName = (LPSTR)NULL;
01594             break;
01595
01596         case IDM_HOOK:
01597             frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
01598                 FR_ENABLEHOOK;
01599             frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
01600             frText.lpTemplateName = (LPSTR)NULL;
01601             break;
01602
01603         case IDM_CUSTOM:
01604             frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
01605                 FR_ENABLEHOOK | FR_ENABLETEMPLATE;
01606             frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL);
01607             frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(REPLACEDLGORD);
01608             break;
01609     }
01610
01611     if ( (hDlgFR = ReplaceText( &frText )) == NULL )
01612             ProcessCDError(CommDlgExtendedError(), hWnd );
01613
01614 }
01615
01616 /****************************************************************************
01617 *
01618 *    FUNCTION: SearchFile(LPFINDREPLACE)
01619 *
01620 *    PURPOSE:  Does the find/replace specified by the Find/ReplaceText
01621 *        common dialog.
01622 *
01623 *    COMMENTS:
01624 *
01625 *        This function does the lease necessary to implement find and
01626 *        replace by calling existing c-runtime functions.  It is in
01627 *        no way intended to demonstrate either correct or efficient
01628 *        methods for doing textual search or replacement.
01629 *
01630 *    RETURN VALUES:
01631 *        void.
01632 *
01633 ****************************************************************************/
01634 void SearchFile( LPFINDREPLACE lpFR )
01635 {
01636
01637     CHAR Buf[FILE_LEN];
01638     CHAR *pStr;
01639     int count, newcount;
01640     static BOOL bFoundLast = FALSE;
01641
01642 if ( lpFR->Flags & ( FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL ) )
01643     {
01644     memset(Buf, '\0', FILE_LEN -1);
01645     if ( bFoundLast )
01646         {
01647         if ( (lpBufPtr != FileBuf) && (lpFR->Flags & FR_FINDNEXT) )
01648             lpBufPtr++;
01649         bFoundLast = FALSE;
01650         }
01651
01652     if (!*lpBufPtr || !(pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) )
01653         {
01654         sprintf( Buf, "'%s' not found!", lpFR->lpstrFindWhat );
01655         lpBufPtr = FileBuf;
01656         MessageBox( lpFR->hwndOwner, Buf, "No luck", MB_OK | MB_TASKMODAL);
01657         }
01658     else
01659         {
01660         if ( lpFR->Flags & FR_FINDNEXT )
01661             {
01662             sprintf( Buf, "Found Next '%s'!\nSubstring: '%.10s'",
01663                      lpFR->lpstrFindWhat, pStr );
01664             lpBufPtr = pStr;
01665             bFoundLast = TRUE;
01666             MessageBox( lpFR->hwndOwner, Buf, "Success!", MB_OK | MB_TASKMODAL );
01667             }
01668         else if ( lpFR->Flags & FR_REPLACE )
01669             {
01670             // replace string specified in the replace with found string
01671             // copy up to found string into new buffer
01672             for( count=0;
01673                  *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
01674                  count++);
01675                 strncpy( Buf, lpBufPtr, count );
01676             // concatenate new string
01677             strcat( Buf, lpFR->lpstrReplaceWith );
01678             // copy rest of string (less the found string)
01679             newcount = count + strlen(lpFR->lpstrFindWhat);
01680             strcat( Buf, lpBufPtr+newcount);
01681             strcpy( lpBufPtr, Buf );
01682             lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
01683             dwFileSize = strlen(FileBuf);
01684             MessageBox( lpFR->hwndOwner, FileBuf, "Success!", MB_OK | MB_TASKMODAL );
01685             }
01686         else if ( lpFR->Flags & FR_REPLACEALL)
01687             {
01688             do
01689                 {
01690                 // replace string specified in the replace with found string
01691                 // copy up to found string into new buffer
01692                 memset(Buf, '\0', FILE_LEN -1);
01693                 for( count=0;
01694                      *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count];
01695                      count++);
01696                      strncpy( Buf, lpBufPtr, count );
01697                 // concatenate new string
01698                 strcat( Buf, lpFR->lpstrReplaceWith );
01699                 // copy rest of string (less the found string)
01700                 newcount = count + strlen(lpFR->lpstrFindWhat);
01701                 strcat( Buf, lpBufPtr + newcount);
01702                 strcpy( lpBufPtr, Buf );
01703                 lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
01704                 }
01705             while ( *lpBufPtr &&
01706                     (pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) );
01707             dwFileSize = strlen(FileBuf);
01708             lpBufPtr = FileBuf;
01709             MessageBox( lpFR->hwndOwner, FileBuf,
01710                         "Success!", MB_OK | MB_TASKMODAL );
01711             }
01712
01713         }
01714     }
01715 }
01716
01717
01718 /****************************************************************************
01719 *
01720 *    FUNCTION: ProcessCDError(DWORD)
01721 *
01722 *    PURPOSE:  Processes errors from the common dialog functions.
01723 *
01724 *    COMMENTS:
01725 *
01726 *        This function is called whenever a common dialog function
01727 *        fails.  The CommonDialogExtendedError() value is passed to
01728 *        the function which maps the error value to a string table.
01729 *        The string is loaded and displayed for the user.
01730 *
01731 *    RETURN VALUES:
01732 *        void.
01733 *
01734 ****************************************************************************/
01735 void ProcessCDError(DWORD dwErrorCode, HWND hWnd)
01736 {
01737    WORD  wStringID;
01738    CHAR  buf[256];
01739
01740    switch(dwErrorCode)
01741       {
01742          case CDERR_DIALOGFAILURE:   wStringID=IDS_DIALOGFAILURE;   break;
01743          case CDERR_STRUCTSIZE:      wStringID=IDS_STRUCTSIZE;      break;
01744          case CDERR_INITIALIZATION:  wStringID=IDS_INITIALIZATION;  break;
01745          case CDERR_NOTEMPLATE:      wStringID=IDS_NOTEMPLATE;      break;
01746          case CDERR_NOHINSTANCE:     wStringID=IDS_NOHINSTANCE;     break;
01747          case CDERR_LOADSTRFAILURE:  wStringID=IDS_LOADSTRFAILURE;  break;
01748          case CDERR_FINDRESFAILURE:  wStringID=IDS_FINDRESFAILURE;  break;
01749          case CDERR_LOADRESFAILURE:  wStringID=IDS_LOADRESFAILURE;  break;
01750          case CDERR_LOCKRESFAILURE:  wStringID=IDS_LOCKRESFAILURE;  break;
01751          case CDERR_MEMALLOCFAILURE: wStringID=IDS_MEMALLOCFAILURE; break;
01752          case CDERR_MEMLOCKFAILURE:  wStringID=IDS_MEMLOCKFAILURE;  break;
01753          case CDERR_NOHOOK:          wStringID=IDS_NOHOOK;          break;
01754          case PDERR_SETUPFAILURE:    wStringID=IDS_SETUPFAILURE;    break;
01755          case PDERR_PARSEFAILURE:    wStringID=IDS_PARSEFAILURE;    break;
01756          case PDERR_RETDEFFAILURE:   wStringID=IDS_RETDEFFAILURE;   break;
01757          case PDERR_LOADDRVFAILURE:  wStringID=IDS_LOADDRVFAILURE;  break;
01758          case PDERR_GETDEVMODEFAIL:  wStringID=IDS_GETDEVMODEFAIL;  break;
01759          case PDERR_INITFAILURE:     wStringID=IDS_INITFAILURE;     break;
01760          case PDERR_NODEVICES:       wStringID=IDS_NODEVICES;       break;
01761          case PDERR_NODEFAULTPRN:    wStringID=IDS_NODEFAULTPRN;    break;
01762          case PDERR_DNDMMISMATCH:    wStringID=IDS_DNDMMISMATCH;    break;
01763          case PDERR_CREATEICFAILURE: wStringID=IDS_CREATEICFAILURE; break;
01764          case PDERR_PRINTERNOTFOUND: wStringID=IDS_PRINTERNOTFOUND; break;
01765          case CFERR_NOFONTS:         wStringID=IDS_NOFONTS;         break;
01766          case FNERR_SUBCLASSFAILURE: wStringID=IDS_SUBCLASSFAILURE; break;
01767          case FNERR_INVALIDFILENAME: wStringID=IDS_INVALIDFILENAME; break;
01768          case FNERR_BUFFERTOOSMALL:  wStringID=IDS_BUFFERTOOSMALL;  break;
01769
01770          case 0:   //User may have hit CANCEL or we got a *very* random error
01771             return;
01772
01773          default:
01774             wStringID=IDS_UNKNOWNERROR;
01775       }
01776
01777    LoadString(NULL, wStringID, buf, sizeof(buf));
01778    MessageBox(hWnd, buf, NULL, MB_OK);
01779    return;
01780 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SCRNSAVE/FRACTAL.C Source File

  • SCRNSAVE

FRACTAL.C

Go to the documentation of this file.
00001 /******************************Module*Header*******************************\
00002 * Module Name: fractal.c
00003 *
00004 * Fractal generation Screen saver
00005 *
00006 * Created: 19-Dec-1992 20:43:00
00007 * Author: Petrus Wong
00008 *
00009 * Copyright (c) 1992-1996 Microsoft Corporation
00010 *
00011 * The screen saver generates the Mandelbrot picture...
00012 *
00013 * Dependencies:
00014 *
00015 *   (#defines)
00016 *   (#includes)
00017 *
00018 \**************************************************************************/
00019 #include            <windows.h>
00020 #include            <scrnsave.h>
00021 #include            <stdio.h>
00022 #include            <math.h>
00023 #include            <commdlg.h>
00024 #include            "fractal.h"
00025
00026 LONG APIENTRY ScreenSaverProc(HWND, UINT, WPARAM, LPARAM);
00027 BOOL APIENTRY ScreenSaverConfigureDialog(HWND, UINT, WPARAM, LPARAM);
00028 BOOL WINAPI RegisterDialogClasses(HANDLE);
00029 BOOL StartMandelbrot (PINFO);
00030 INT  iCreatePenFrPal(HDC, PVOID *, INT, HPALETTE *);
00031 BOOL bInitInfo(PINFO);
00032 void vLoadStrings(VOID);
00033 BOOL SaveBitmapFile(HDC, HBITMAP, PSTR);
00034 void ErrorOut(char errstring[30]);
00035 BOOL bGetPPStr(char szXFr[MAXDOUBLELEN], char szYFr[MAXDOUBLELEN],
00036                char szX2[MAXDOUBLELEN],  char szY2[MAXDOUBLELEN],
00037                char szSavef[MAXFILELEN], char szIter[MAXDOUBLELEN]);
00038 BOOL bInitDlgItems(HWND);
00039 BOOL bColorCycle(HDC, PINFO);
00040 /******************************Public*Routine******************************\
00041 *
00042 * ScreenSaverProc
00043 *
00044 * Effects:  Creates a drawing thread.
00045 *
00046 * Warnings:
00047 *
00048 * History:
00049 *  18-Dec-1992 -by- Petrus Wong
00050 * Wrote it.
00051 \**************************************************************************/
00052
00053 LONG APIENTRY
00054 ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00055 {
00056     static HBRUSH hBkBr;
00057
00058     switch(message)
00059     {
00060         case WM_CREATE:
00061             hBkBr = GetStockObject(BLACK_BRUSH);
00062             hpnRed     = CreatePen(PS_SOLID, 0, RGB(0xFF, 0,    0));
00063             hpnGreen   = CreatePen(PS_SOLID, 0, RGB(0,    0xFF, 0));
00064             hpnBlack   = CreatePen(PS_SOLID, 0, RGB(0,    0,    0));
00065
00066             vLoadStrings();
00067             bInitInfo(&gInfo);
00068             break;
00069
00070         case WM_ERASEBKGND: {
00071             RECT    rc;
00072
00073             GetClientRect(hWnd, &rc);
00074             FillRect((HDC)wParam, &rc, hBkBr);
00075             gInfo.bMandel = TRUE;
00076             gInfo.hwnd = hWnd;
00077             gInfo.hHTPal = CreateHalftonePalette((HDC)wParam);
00078             gInfo.hThrd = CreateThread(NULL, 0,
00079                                  (LPTHREAD_START_ROUTINE)StartMandelbrot,
00080                                  &gInfo,
00081                                  STANDARD_RIGHTS_REQUIRED,
00082                                  &gInfo.dwThreadId );
00083
00084             if (gInfo.hThrd) {
00085                 SetThreadPriority(gInfo.hThrd, THREAD_PRIORITY_BELOW_NORMAL);
00086             }
00087
00088
00089             return 0L;
00090         }
00091         case WM_DESTROY:
00092             DeleteObject(hBkBr);
00093             DeleteObject(hpnRed);
00094             DeleteObject(hpnGreen);
00095             DeleteObject(hpnBlack);
00096             TerminateThread(gInfo.hThrd, (DWORD)0L);
00097             break;
00098     }
00099     return (DefScreenSaverProc(hWnd,message,wParam,lParam));
00100 }
00101
00102
00103 /******************************Public*Routine******************************\
00104 *
00105 * ScreenSaverConfigureDialog
00106 *
00107 * Effects:
00108 *
00109 * Warnings:
00110 *
00111 * History:
00112 *  19-Dec-1992 -by- Petrus Wong
00113 * Wrote it.
00114 \**************************************************************************/
00115
00116 BOOL APIENTRY
00117 ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00118 {
00119     switch(message)
00120     {
00121         case WM_INITDIALOG: {
00122             vLoadStrings();
00123             bInitDlgItems(hDlg);
00124             return TRUE;
00125         }
00126         case WM_COMMAND:
00127
00128             switch(LOWORD(wParam))
00129             {
00130                 static char         szFile[MAXPATHLEN];
00131                 static BOOL         bSave2DiffFile = FALSE;
00132
00133                 case ID_SAVEAS: {
00134                     OPENFILENAME ofn;
00135                     char         szDirName[MAXPATHLEN];
00136                     char         szFileTitle[256];
00137                     static char  *szFilter;
00138
00139                     szFilter = "DIB files (*.bmp)\0\0";
00140
00141                     GetSystemDirectory((LPSTR) szDirName, MAXPATHLEN);
00142                     strcpy(szFile, "*.bmp\0");
00143                     ofn.lStructSize = sizeof(OPENFILENAME);
00144                     ofn.hwndOwner = hDlg;
00145                     ofn.lpstrFilter = szFilter;
00146                     ofn.lpstrCustomFilter = (LPSTR) NULL;
00147                     ofn.nMaxCustFilter = 0L;
00148                     ofn.nFilterIndex = 0L;
00149                     ofn.lpstrFile = szFile;
00150                     ofn.nMaxFile = sizeof(szFile);
00151                     ofn.lpstrFileTitle = szFileTitle;
00152                     ofn.nMaxFileTitle = sizeof(szFileTitle);
00153                     ofn.lpstrInitialDir = szDirName;
00154                     ofn.lpstrTitle = "Save Bitmap As";
00155                     ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
00156                     ofn.nFileOffset = 0;
00157                     ofn.nFileExtension = 0;
00158                     ofn.lpstrDefExt = (LPSTR)NULL;
00159
00160                     if (GetSaveFileName(&ofn))
00161                         bSave2DiffFile = TRUE;
00162
00163                     break;
00164                 }
00165                 case IDOK: {
00166                     char    szXFr[MAXDOUBLELEN];
00167                     char    szYFr[MAXDOUBLELEN];
00168                     char    szX2[MAXDOUBLELEN];
00169                     char    szY2[MAXDOUBLELEN];
00170                     char    szIter[MAXDOUBLELEN];
00171
00172                     if (bSave2DiffFile)
00173                         WritePrivateProfileString(szAppName, szSaveFile, szFile, szIniFile);
00174
00175                     //
00176                     // Saves new configuartion...
00177                     //
00178                     GetDlgItemText(hDlg, ID_XFROM, szXFr, MAXDOUBLELEN);
00179                     GetDlgItemText(hDlg, ID_YFROM, szYFr, MAXDOUBLELEN);
00180                     GetDlgItemText(hDlg, ID_XTO,   szX2,  MAXDOUBLELEN);
00181                     GetDlgItemText(hDlg, ID_YTO,   szY2,  MAXDOUBLELEN);
00182                     GetDlgItemText(hDlg, ID_ITERATION, szIter, MAXDOUBLELEN);
00183                     WritePrivateProfileString(szAppName, szXFrom, szXFr, szIniFile);
00184                     WritePrivateProfileString(szAppName, szYFrom, szYFr, szIniFile);
00185                     WritePrivateProfileString(szAppName, szXTo,    szX2,  szIniFile);
00186                     WritePrivateProfileString(szAppName, szYTo,    szY2,  szIniFile);
00187                     WritePrivateProfileString(szAppName, szIteration, szIter,  szIniFile);
00188                 }
00189                 case IDCANCEL:
00190                     bSave2DiffFile = FALSE;
00191                     EndDialog(hDlg,LOWORD(wParam) == IDOK);
00192                     return TRUE;
00193                 default:
00194                     break;
00195             }
00196         default:
00197             break;
00198     }
00199     return FALSE;
00200 }
00201
00202 /******************************Public*Routine******************************\
00203 *
00204 * RegisterDialogClasses
00205 *
00206 * Effects: Register window classes used by the configuration dialog
00207 *
00208 * Warnings: Return TRUE even if no class needed to be registered.
00209 *
00210 * History:
00211 *  18-Dec-1992 -by- Petrus Wong
00212 * Wrote it.
00213 \**************************************************************************/
00214
00215 BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
00216 {
00217     return TRUE;
00218 }
00219
00220 /**************************************************************************\
00221 *
00222 * StartMandelbrot
00223 *              2
00224 * Effects: Draw'g the Mandelbrot Set for Q (z) = z  + c, where z, c complex
00225 *
00226 * Warnings:
00227 *
00228 * History:
00229 *  15-Jan-1993      Petrus Wong     Added color cycle and removed the red &
00230 *                                   black for saving the screen
00231 *  19-Dec-1992      Petrus Wong     Adapted from the Mandel SDK Sample
00232 *  14-Dec-1992 -by- Petrus Wong     Enable shadow bitmap
00233 *  14-Jun-1992 -by- Petrus Wong     Modified to use the pen array and LineTo
00234 *  20-Nov-1991 -by- Petrus Wong
00235 * Wrote it.
00236 \**************************************************************************/
00237 BOOL StartMandelbrot(PINFO pInfo)
00238 {
00239    DWORD       dwTick1;
00240    HDC         hDC;
00241    RECT        rc;
00242    int         m, n, i, iPrev;
00243    int         xCurr, yCurr;
00244    int         iPen;
00245
00246 #ifndef THRDONE
00247    INT      iNumClr;
00248    char     text[256];
00249 #endif
00250
00251    double c1, c2;
00252    double x1, y1, x, y, r;
00253
00254    HDC          hDCMem;
00255    HBITMAP      hBitmap, hOldBitmap;
00256
00257    pInfo->bMandel = TRUE;
00258    pInfo->bDrawing = TRUE;
00259    hDC = GetDC(pInfo->hwnd);
00260
00261 #ifndef THRDONE
00262     if ((iNumClr = iCreatePenFrPal(hDC, NULL, 0, &(pInfo->hPal))) != 0) {
00263         sprintf( gtext,"iNumClr = %d\n", iNumClr);
00264         OutputDebugString( gtext);
00265
00266         if ((pInfo->prghPen = (PVOID*) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(HPEN)*iNumClr)) == NULL) {
00267             MessageBox(GetFocus(), "Failed in Memory Allocation for pInfo->prghPen!", "Error", MB_OK);
00268         } else {
00269             if ((pInfo->iPen = iCreatePenFrPal(hDC, pInfo->prghPen, 1, &(pInfo->hPal))) == 0)
00270                 MessageBox(GetFocus(), "Failed in creating pen!", "Error", MB_OK);
00271         }
00272     }
00273
00274    hDCMem = CreateCompatibleDC(hDC);
00275
00276    if (pInfo->hPal) {
00277     SelectPalette(hDCMem, pInfo->hPal, FALSE);
00278     RealizePalette(hDCMem);
00279    }
00280    iPen = pInfo->iPen + 1;
00281    wsprintf(text, "iPen = %d\n", iPen);
00282    //MessageBox(GetFocus(), text, "Error", MB_OK);
00283 #endif
00284
00285    GetClientRect(pInfo->hwnd, &rc);
00286
00287    hBitmap = CreateCompatibleBitmap(hDC, (int)rc.right, (int)rc.bottom);
00288    hOldBitmap = SelectObject(hDCMem, hBitmap);
00289
00290 //#if 0
00291  {
00292    int iWidth, i, j;
00293
00294    iWidth = (((iWidth = rc.right/iNumClr) == 0) ? 1 : iWidth);
00295    sprintf( gtext,"iWidth = %d\n", iWidth);
00296    OutputDebugString( gtext);
00297
00298    for (i = 0; i < iNumClr; i++) {
00299    //for (i = 0; i < 256; i++) {
00300        //sprintf( gtext,"i mod iNumClr = %d\n", i % iNumClr);
00301        //OutputDebugString( gtext);
00302        if ((SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iNumClr])) == NULL) {
00303             sprintf( gtext,"Select Pen failed\n");
00304             OutputDebugString( gtext);
00305        }
00306        SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[i % iNumClr]);
00307        for (j = 0; j < iWidth; j++) {
00308             MoveToEx(hDC, i*iWidth+j, 0, NULL);
00309             LineTo(hDC, i*iWidth+j, rc.bottom);
00310             MoveToEx(hDCMem, i*iWidth+j, 0, NULL);
00311             LineTo(hDCMem, i*iWidth+j, rc.bottom);
00312        }
00313
00314    }
00315  }
00316 //#endif
00317
00318    dwTick1 = GetTickCount();
00319
00320    sprintf( gtext,"Start Drawing\n");
00321    OutputDebugString( gtext);
00322    yCurr = rc.top;
00323    for (n=rc.top; n<=rc.bottom; n+=pInfo->iStep, yCurr+=pInfo->iStep, iPrev = FIRST_PIXEL) {
00324        xCurr = rc.left;                   // since LineTo excludes last point
00325        MoveToEx(hDC, 0, yCurr, NULL);
00326        MoveToEx(hDCMem, 0, yCurr, NULL);
00327        c2 = Xform((double) n, 0.0, (double) rc.bottom, pInfo->yFrom, pInfo->yTo);
00328
00329        for (m=rc.left; m<=rc.right; m++, xCurr++) {
00330            c1 = Xform((double) m, 0.0, (double) rc.right, pInfo->xFrom, pInfo->xTo);
00331      x = c1;
00332      y = c2;
00333
00334      for (i=1; i<=pInfo->iIteration; i++) {
00335                x1 = (x - y) * (x + y) + c1;
00336                y1 = 2 * x * y + c2;
00337          r = x1 * x1 + y1 * y1;
00338          x = x1;
00339          y = y1;
00340          if (r > 4.0) {
00341                    break;
00342                }
00343            }
00344
00345            if (i != iPrev) {
00346                if (iPrev != FIRST_PIXEL) {
00347                  switch(iPrev) {
00348                    case 1: SelectObject(hDC, (HPEN)(pInfo->prghPen)[0]);
00349                            SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[0]);
00350                     break;
00351                    default:
00352                        if (iPrev >= pInfo->iIteration) {
00353                             SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPen/3]);
00354                             SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPen/3]);
00355                             break;
00356                        }
00357                        SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPrev % iPen]);
00358                        SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPrev % iPen]);
00359                        //SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPrev % iNumClr]);
00360                        break;
00361                  }
00362                  iPrev = i;
00363                  LineTo(hDC, xCurr, yCurr);
00364                  LineTo(hDCMem, xCurr, yCurr);
00365                }
00366                else
00367       iPrev = i;  // remember the color for the first pixel
00368            }
00369        }
00370
00371             switch(i)
00372     {
00373                    case 1: SelectObject(hDC, (HPEN)(pInfo->prghPen)[0]);
00374                            SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[0]);
00375                     break;
00376                    default:
00377                        if (i >= pInfo->iIteration) {
00378                             SelectObject(hDC, (HPEN)(pInfo->prghPen)[iPen/3]);
00379                             SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[iPen/3]);
00380                             break;
00381                        }
00382                        SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iPen]);
00383                        SelectObject(hDCMem, (HPEN)(pInfo->prghPen)[i % iPen]);
00384                        //SelectObject(hDC, (HPEN)(pInfo->prghPen)[i % iNumClr]);
00385                        break;
00386     }
00387
00388      LineTo(hDC,xCurr,yCurr);
00389                  LineTo(hDCMem,xCurr,yCurr);
00390
00391    }
00392
00393
00394
00395    pInfo->dwElapsed = GetTickCount() - dwTick1;
00396
00397    if (pInfo->hBmpSaved)
00398        DeleteObject(pInfo->hBmpSaved);
00399
00400    pInfo->hBmpSaved = SelectObject(hDCMem, hOldBitmap);
00401    pInfo->bDrawing = FALSE;
00402    SaveBitmapFile(hDC, pInfo->hBmpSaved, pInfo->szSavef);
00403    pInfo->bClrCycle = TRUE;
00404    if (pInfo->hPal)
00405       bColorCycle(hDC, pInfo);
00406    ReleaseDC(pInfo->hwnd, hDC);
00407
00408 #ifndef THRDONE
00409    if (pInfo->prghPen != NULL) {
00410        for (i = 0; i <= pInfo->iPen; i++) {
00411            DeleteObject((HPEN) (pInfo->prghPen)[i]);
00412        }
00413        GlobalFree(pInfo->prghPen);
00414    }
00415 #endif
00416
00417    DeleteDC(hDCMem);
00418
00419    ExitThread(0);
00420    if (!CloseHandle(pInfo->hThrd))
00421        MessageBox(GetFocus(), "Failed in CloseHandle!", "Error", MB_OK);
00422
00423    return TRUE;
00424 }
00425
00426
00427 /******************************Public*Routine******************************\
00428 *
00429 * iCreatePenFrPal
00430 *
00431 * Effects: Create an array of pens from palette.
00432 *          If device supports palette, then first creates a logical palette
00433 *          with a good spread of color. Then select the logical palette into
00434 *          the DC. Create pen that corresponds to each palette entry.
00435 *          If system does not support palette, then use the system palette.
00436 *
00437 *          prghPen pointer to an array of hPen
00438 *                  If this is NULL, the required size of the array is
00439 *                  returned. If this is not NULL, the array will be filled
00440 *                  with hPens.
00441 *
00442 *          returns the number of hPens created.
00443 *
00444 * Warnings:
00445 *
00446 * History:
00447 *  13-Jun-1992 -by- Petrus Wong
00448 * Wrote it.
00449 \**************************************************************************/
00450
00451 INT iCreatePenFrPal(HDC hDC, PVOID *prghPen, INT iWidth, HPALETTE *phPal)
00452 {
00453     INT             iNumClr, iResult, i, iEntry;
00454     PLOGPALETTE     plogPat;
00455     ULONG           ulSize;
00456
00457     iResult = 0;
00458
00459     if (!((GetDeviceCaps(hDC, RASTERCAPS)) & RC_PALETTE)) {
00460
00461         if (iNumClr = GetSystemPaletteEntries(hDC, 0, 0, NULL)) {
00462             if (prghPen == NULL) {
00463                 return (iNumClr);
00464             }
00465
00466             if (iWidth < 0) {
00467                 MessageBox(GetFocus(), "Invalid pen width!", "Error", MB_OK);
00468                 return 0L;
00469             }
00470
00471             for (i = 0; i < iNumClr; i++) {
00472                 prghPen[i] =
00473                      (PVOID) CreatePen(PS_SOLID, iWidth, PALETTEINDEX(i));
00474                 iResult = i;
00475 #if 0
00476                 SelectObject(hDC, (HPEN)prghPen[i]);
00477                 MoveToEx(hDC, i*iWidth, 0, NULL);
00478                 LineTo(hDC, i*iWidth, 300);
00479 #endif
00480             }
00481             return iResult;
00482         }
00483
00484         // GetPaletteEntries returns 0
00485         iNumClr = 1 << GetDeviceCaps(hDC, BITSPIXEL);
00486
00487         if (iNumClr <= 16) {
00488             sprintf( gtext,"Assertion failed: iCreatePenFrPal() \n");
00489             OutputDebugString( gtext);
00490             sprintf( gtext,"iNumClr <= 16! iNumClr = %d\n", iNumClr);
00491             OutputDebugString( gtext);
00492             return (iNumClr);
00493         }
00494
00495         // Assuming at least 16 bit device
00496         //
00497         iNumClr = 768;      // COLORREF format: 0x00bbggrr r,g,b=[0,255]
00498
00499         if (prghPen == NULL) {
00500             return (iNumClr);
00501         }
00502
00503         if (iWidth < 0) {
00504             MessageBox(GetFocus(), "Invalid pen width!", "Error", MB_OK);
00505             return 0L;
00506         }
00507
00508         for (i = 0; i < iNumClr; i++) {
00509             if (i < 256) {
00510                 prghPen[i] =
00511                     (PVOID) CreatePen(PS_SOLID, iWidth, RGB(i,0,255-i));
00512                 iResult = i;
00513 #if 0
00514                 SelectObject(hDC, (HPEN)prghPen[i]);
00515                 MoveToEx(hDC, i*iWidth, 0, NULL);
00516                 LineTo(hDC, i*iWidth, 300);
00517 #endif
00518                 continue;
00519             }
00520
00521             if (i < 512) {
00522                 prghPen[i] =
00523                     (PVOID) CreatePen(PS_SOLID, iWidth, RGB(511-i,i-256,0));
00524                 iResult = i;
00525 #if 0
00526                 SelectObject(hDC, (HPEN)prghPen[i]);
00527                 MoveToEx(hDC, i*iWidth, 0, NULL);
00528                 LineTo(hDC, i*iWidth, 300);
00529 #endif
00530                 continue;
00531             }
00532
00533
00534             prghPen[i] =
00535                 (PVOID) CreatePen(PS_SOLID, iWidth, RGB(0,767-i,i-512));
00536             iResult = i;
00537 #if 0
00538             SelectObject(hDC, (HPEN)prghPen[i]);
00539             MoveToEx(hDC, i*iWidth, 0, NULL);
00540             LineTo(hDC, i*iWidth, 300);
00541 #endif
00542         }
00543
00544         return iResult;
00545     }
00546
00547     //
00548     // Palette managed device
00549     //
00550     iEntry = iNumClr = 1 << GetDeviceCaps(hDC, BITSPIXEL);
00551
00552     if (iNumClr > 256) {
00553         sprintf( gtext,"Assertion failed: iCreatePenFrPal() \n");
00554         OutputDebugString( gtext);
00555         sprintf( gtext,"iNumClr > 256! iNumClr = %d\n", iNumClr);
00556         OutputDebugString( gtext);
00557         iEntry=iNumClr = 256;
00558     }
00559
00560     ulSize = sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*iNumClr;
00561
00562     iNumClr -= GetDeviceCaps(hDC, NUMRESERVED);
00563
00564     if (prghPen == NULL)
00565         return iNumClr;
00566
00567     if ((plogPat = (PLOGPALETTE) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, ulSize)) == NULL) {
00568         MessageBox(GetFocus(), "Failed in Memory Allocation for plogPat!", "Error", MB_OK);
00569         goto ErrExit1;
00570     }
00571
00572     plogPat->palVersion = 0x300;
00573     plogPat->palNumEntries = (WORD) iEntry;
00574
00575     {
00576     int     iFirst, iSecond, iInc;
00577
00578         iFirst = iNumClr/3;
00579         iSecond = iFirst * 2;
00580         iInc = (iNumClr <= 256) ? 3 : 1;
00581
00582
00583         for (i = 0; i < iNumClr; i++) {
00584             if (i < iFirst) {
00585                 plogPat->palPalEntry[i+10].peBlue   = 255-(i+1)*iInc;
00586                 plogPat->palPalEntry[i+10].peGreen  = 0;
00587                 plogPat->palPalEntry[i+10].peRed    = (i+1)*iInc;
00588                 plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
00589                 continue;
00590             }
00591             if (i < iSecond) {
00592                 plogPat->palPalEntry[i+10].peBlue   = 0;
00593                 plogPat->palPalEntry[i+10].peGreen  = (i+1-iFirst)*iInc;
00594                 plogPat->palPalEntry[i+10].peRed    = 255-(i+1-iFirst)*iInc;
00595                 plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
00596                 continue;
00597             }
00598             plogPat->palPalEntry[i+10].peBlue   = (i+1-iSecond)*iInc;
00599             plogPat->palPalEntry[i+10].peGreen  = 255-(i+1-iSecond)*iInc;
00600             plogPat->palPalEntry[i+10].peRed    = 0;
00601             plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
00602         }
00603     }
00604
00605     DeleteObject(*phPal);
00606
00607     if ((*phPal = CreatePalette(plogPat)) == (HPALETTE) NULL) {
00608         MessageBox(GetFocus(), "Failed in creating palette!", "Error", MB_OK);
00609         goto ErrExit2;
00610     }
00611     if (*phPal) {
00612        SelectPalette(hDC, *phPal, FALSE);
00613        RealizePalette(hDC);
00614     }
00615
00616     for (i = 0; i < iNumClr; i++) {
00617         HPEN    hPen;
00618
00619         hPen = CreatePen(PS_SOLID, iWidth, PALETTEINDEX(i+10));
00620         prghPen[i] = (PVOID) hPen;
00621         iResult = i;
00622 #if 0
00623         SelectObject(hDC, hPen);
00624         MoveToEx(hDC, i*iWidth, 0, NULL);
00625         LineTo(hDC, i*iWidth, 300);
00626 #endif
00627     }
00628
00629 ErrExit2:
00630     GlobalFree(plogPat);
00631 ErrExit1:
00632     return iResult;
00633
00634 }
00635
00636 /******************************Public*Routine******************************\
00637 *
00638 * bInitInfo
00639 *
00640 * Effects: Initialize the Info data structure
00641 *
00642 * Warnings:
00643 *
00644 * History:
00645 *  19-Dec-1992      Petrus Wong         Retrieve setup info fr control.ini
00646 *  14-Dec-1992 -by- Petrus Wong         Added Rle and pens stuff
00647 *  28-Jan-1992 -by- Petrus Wong
00648 * Wrote it.
00649 \**************************************************************************/
00650
00651 BOOL bInitInfo(PINFO pInfo)
00652 {
00653     char    szXFr[MAXDOUBLELEN], szYFr[MAXDOUBLELEN], szX2[MAXDOUBLELEN],
00654             szY2[MAXDOUBLELEN], szSavef[MAXPATHLEN], szIter[MAXDOUBLELEN];
00655
00656     bGetPPStr(szXFr, szYFr, szX2, szY2, szSavef, szIter);
00657     pInfo->xFrom        = atof(szXFr);
00658     pInfo->xTo          = atof(szX2);
00659     pInfo->yFrom        = atof(szYFr);
00660     pInfo->yTo          = atof(szY2);
00661     pInfo->lxFrom       = -4096;                // 20.11 fix point
00662     pInfo->lxTo         = 4096;                 // representation of
00663     pInfo->lyFrom       = 4096;                 // -2, 2, 2, and -2
00664     pInfo->lyTo         = -4096;                //
00665     pInfo->iIteration   = (INT) atof(szIter);
00666     pInfo->iStep        = gStep;
00667     pInfo->bStretch     = gbStretch;
00668     pInfo->iStretchMode = giStretchMode;
00669     pInfo->hwnd         = NULL;
00670     pInfo->hThrd        = NULL;
00671     pInfo->bDrawing     = FALSE;
00672     pInfo->dwThreadId   = 0;
00673     pInfo->dwElapsed    = 0L;
00674     pInfo->c1           = 0.0;
00675     pInfo->c2           = 0.0;
00676     pInfo->lc1          = 0L;
00677     pInfo->lc2          = 0L;
00678     pInfo->hBmpSaved    = NULL;
00679     pInfo->bMandel      = TRUE;
00680     pInfo->bSetDIBsToDevice = FALSE;
00681     pInfo->hPal         = NULL;
00682     pInfo->prghPen      = NULL;
00683     pInfo->iPen         = 0;
00684     pInfo->bClrCycle    = FALSE;
00685     wsprintf((LPSTR) &(pInfo->szSavef), szSavef);
00686     return TRUE;
00687 }
00688
00689
00690
00691
00692 /******************************Public*Routine******************************\
00693 *
00694 * vLoadStrings
00695 *
00696 * Effects: Load strings from resource
00697 *
00698 * Warnings:
00699 *
00700 * History:
00701 *  19-Dec-1992 -by- Petrus Wong
00702 * Wrote it.
00703 \**************************************************************************/
00704
00705 void vLoadStrings(VOID)
00706 {
00707     LoadString(hMainInstance, idsAppName, szAppName, APPNAMEBUFFERLEN);
00708     LoadString(hMainInstance, idsName, szName, TITLEBARNAMELEN);
00709     LoadString(hMainInstance, idsIniFile, szIniFile, MAXFILELEN);
00710     LoadString(hMainInstance, idsScreenSaver, szScreenSaver, 22);
00711     LoadString(hMainInstance, idsHelpFile, szHelpFile, MAXFILELEN);
00712     LoadString(hMainInstance, idsNoHelpMemory, szNoHelpMemory, BUFFLEN);
00713     LoadString(hMainInstance, idsXFrom, szXFrom, MAXDOUBLELEN);
00714     LoadString(hMainInstance, idsYFrom, szYFrom, MAXDOUBLELEN);
00715     LoadString(hMainInstance, idsXTo, szXTo, MAXDOUBLELEN);
00716     LoadString(hMainInstance, idsYTo, szYTo, MAXDOUBLELEN);
00717     LoadString(hMainInstance, idsSaveAs, szSaveFile, MAXPATHLEN);
00718     LoadString(hMainInstance, idsIteration, szIteration, MAXDOUBLELEN);
00719 }
00720
00721
00722
00723 /******************************Public*Routine******************************\
00724 * SaveBitmapFile
00725 *
00726 *
00727 * Effects: Save pInfo->hBmpSaved into disk specified by pszFileName
00728 *
00729 * Warnings: assumes hBmpSaved is not selected into window's DC other than
00730 *           pInfo->hwnd's DC
00731 *
00732 * History:
00733 *  14-Jan-1992 -by- Petrus Wong
00734 * Wrote it.
00735 \**************************************************************************/
00736
00737 BOOL SaveBitmapFile(HDC hDC, HBITMAP hBmp, PSTR pszFileName)
00738 {
00739     int         hFile;
00740     OFSTRUCT    ofReOpenBuff;
00741     HBITMAP     hTmpBmp, hBmpOld;
00742     BOOL        bSuccess;
00743     BITMAPFILEHEADER    bfh;
00744     PBITMAPINFO pbmi;
00745     PBYTE       pBits;
00746     BITMAPINFO  bmi;
00747     PBYTE pjTmp, pjTmpBmi;
00748     ULONG sizBMI;
00749
00750
00751     bSuccess = TRUE;
00752     if (!hBmp) {
00753         MessageBox(GetFocus(), "There's no Bitmap to save!", "Error", MB_OK);
00754         return FALSE;
00755     }
00756
00757     //
00758     // Let the graphics engine to retrieve the dimension of the bitmap for us
00759     // GetDIBits uses the size to determine if it's BITMAPCOREINFO or BITMAPINFO
00760     // if BitCount != 0, color table will be retrieved
00761     //
00762     bmi.bmiHeader.biSize = 0x28;              // GDI need this to work
00763     bmi.bmiHeader.biBitCount = 0;             // don't get the color table
00764     if ((GetDIBits(hDC, hBmp, 0, 0, (LPSTR)NULL, &bmi, DIB_RGB_COLORS)) == 0) {
00765         MessageBox(GetFocus(), "GetDIBits failed!", "Error", MB_OK);
00766         return FALSE;
00767     }
00768
00769     //
00770     // Now that we know the size of the image, alloc enough memory to retrieve
00771     // the actual bits
00772     //
00773     if ((pBits = (PBYTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
00774                 bmi.bmiHeader.biSizeImage)) == NULL) {
00775         MessageBox(GetFocus(), "Failed in Memory Allocation for pBits!", "Error", MB_OK);
00776         return FALSE;
00777     }
00778
00779     //
00780     // Note: 24 bits per pixel has no color table.  So, we don't have to
00781     // allocate memory for retrieving that.  Otherwise, we do.
00782     //
00783     pbmi = &bmi;                                      // assume no color table
00784     if (bmi.bmiHeader.biBitCount != 24) {             // has color table
00785         sizBMI = sizeof(BITMAPINFO)+sizeof(RGBQUAD)*(1<<bmi.bmiHeader.biBitCount);
00786         //
00787         // I need more memory for the color table
00788         //
00789         if ((pbmi = (PBITMAPINFO)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizBMI )) == NULL) {
00790             MessageBox(GetFocus(), "Failed in Memory Allocation for pbmi!", "Error", MB_OK);
00791             bSuccess = FALSE;
00792             goto ErrExit1;
00793         }
00794         //
00795         // Now that we've a bigger chunk of memory, let's copy the Bitmap
00796         // info header data over
00797         //
00798         pjTmp = (PBYTE)pbmi;
00799         pjTmpBmi = (PBYTE)&bmi;
00800         sizBMI = sizeof(BITMAPINFOHEADER);
00801
00802         while(sizBMI--)
00803         {
00804             *(((PBYTE)pjTmp)++) = *((pjTmpBmi)++);
00805         }
00806
00807     }
00808
00809     //
00810     // Let's open the file and get ready for writing
00811     //
00812     if ((hFile = OpenFile(pszFileName, (LPOFSTRUCT)&ofReOpenBuff,
00813                  OF_CREATE | OF_WRITE)) == -1) {
00814         MessageBox(GetFocus(), "Failed in OpenFile!", "Error", MB_OK);
00815         ErrorOut("OpenFile");
00816         goto ErrExit2;
00817     }
00818
00819     //
00820     // But first, fill in the info for the BitmapFileHeader
00821     //
00822     bfh.bfType = 0x4D42;                            // 'BM'
00823     bfh.bfSize = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*
00824         ((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1<<pbmi->bmiHeader.biBitCount))+
00825         pbmi->bmiHeader.biSizeImage;
00826     bfh.bfReserved1 =
00827     bfh.bfReserved2 = 0;
00828     bfh.bfOffBits = sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+
00829         sizeof(RGBQUAD)*((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1<<pbmi->bmiHeader.biBitCount));
00830
00831     //
00832     // Write out the file header now
00833     //
00834     if (_lwrite(hFile, (LPSTR)&bfh, sizeof(BITMAPFILEHEADER)) == -1) {
00835         MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
00836         bSuccess = FALSE;
00837         goto ErrExit3;
00838     }
00839
00840     //
00841     // Bitmap can't be selected into a DC when calling GetDIBits
00842     // Assume that the hDC is the DC where the bitmap would have been selected
00843     // if indeed it has been selected
00844     //
00845     if (hTmpBmp = CreateCompatibleBitmap(hDC, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight)) {
00846         hBmpOld = SelectObject(hDC, hTmpBmp);
00847         if ((GetDIBits(hDC, hBmp, 0, pbmi->bmiHeader.biHeight, (LPSTR)pBits, pbmi, DIB_RGB_COLORS))==0){
00848             MessageBox(GetFocus(), "Failed in GetDIBits!", "Error", MB_OK);
00849             bSuccess = FALSE;
00850             goto ErrExit4;
00851         }
00852     } else {
00853         MessageBox(GetFocus(), "Failed in creating bitmap!", "Error", MB_OK);
00854         bSuccess = FALSE;
00855         goto ErrExit3;
00856     }
00857
00858     //
00859     // Now write out the BitmapInfoHeader and color table, if any
00860     //
00861     if (_lwrite(hFile, (LPSTR)pbmi, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) *
00862         ((pbmi->bmiHeader.biBitCount == 24) ? 0 : (1 << pbmi->bmiHeader.biBitCount))) == -1) {
00863         MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
00864         bSuccess = FALSE;
00865         goto ErrExit4;
00866     }
00867
00868     //
00869     // write the bits also
00870     //
00871     if (_lwrite(hFile, (LPSTR)pBits, pbmi->bmiHeader.biSizeImage) == -1) {
00872         MessageBox(GetFocus(), "Failed in WriteFile!", "Error", MB_OK);
00873         bSuccess = FALSE;
00874         goto ErrExit4;
00875     }
00876
00877
00878 ErrExit4:
00879     SelectObject(hDC, hBmpOld);
00880     DeleteObject(hTmpBmp);
00881 ErrExit3:
00882     _lclose(hFile);
00883 ErrExit2:
00884     GlobalFree(pbmi);
00885 ErrExit1:
00886     GlobalFree(pBits);
00887     return bSuccess;
00888 }
00889
00890 /************************************************************************
00891  * void ErrorOut(char errstring[30])
00892  *
00893  * Purpose: Print out an meainful error code by means of
00894  *    GetLastError and printf
00895  *
00896  * Inputs:  errstring - the action that failed, passed by the
00897  *          calling proc.
00898  *
00899  * Returns: none
00900  *
00901  * Calls:   GetLastError
00902  *
00903  * History:
00904  *
00905 \************************************************************************/
00906
00907
00908 void ErrorOut(char errstring[30])
00909 {
00910 DWORD Error;
00911 CHAR  str[80];
00912
00913 Error= GetLastError();
00914 wsprintf((LPSTR) str, "Error on %s = %d\n", errstring, Error);
00915 MessageBox(GetFocus(), (LPSTR)str, "Error", MB_OK);
00916 }
00917
00918 BOOL bInitDlgItems(HWND hDlg)
00919 {
00920     char    szXFr[MAXDOUBLELEN], szYFr[MAXDOUBLELEN], szX2[MAXDOUBLELEN],
00921             szY2[MAXDOUBLELEN], szSavef[MAXPATHLEN], szIter[MAXDOUBLELEN];
00922     BOOL    bSuccess;
00923
00924     bSuccess = bGetPPStr(szXFr, szYFr, szX2, szY2, szSavef, szIter);
00925     SetDlgItemText(hDlg, ID_XFROM, szXFr);
00926     SetDlgItemText(hDlg, ID_YFROM, szYFr);
00927     SetDlgItemText(hDlg, ID_XTO, szX2);
00928     SetDlgItemText(hDlg, ID_YTO, szY2);
00929     SetDlgItemText(hDlg, ID_ITERATION, szIter);
00930
00931     return bSuccess;
00932 }
00933
00934
00935 /******************************Public*Routine******************************\
00936 *
00937 * bGetPPStr
00938 *
00939 * Effects: GetPrivateProfileString from control.ini
00940 *
00941 * Warnings:
00942 *
00943 * History:
00944 *  19-Dec-1992 -by- Petrus Wong
00945 * Wrote it.
00946 \**************************************************************************/
00947
00948 BOOL bGetPPStr(char szXFr[MAXDOUBLELEN], char szYFr[MAXDOUBLELEN],
00949                char szX2[MAXDOUBLELEN],  char szY2[MAXDOUBLELEN],
00950                char szSavef[MAXPATHLEN], char szIter[MAXDOUBLELEN])
00951 {
00952     char    szDefXFr[MAXDOUBLELEN];
00953     char    szDefYFr[MAXDOUBLELEN];
00954     char    szDefX2[MAXDOUBLELEN];
00955     char    szDefY2[MAXDOUBLELEN];
00956     char    szDefSavef[MAXPATHLEN];
00957     char    szDefIter[MAXDOUBLELEN];
00958
00959     sprintf(szDefXFr, "-2.00");
00960     sprintf(szDefYFr, "1.00");
00961     sprintf(szDefX2,  "1.00");
00962     sprintf(szDefY2,  "-1.00");
00963     sprintf(szDefSavef, "c:\\fractal.bmp");
00964     sprintf(szDefIter, "500");
00965     GetPrivateProfileString(szAppName, szXFrom, szDefXFr, szXFr, MAXDOUBLELEN, szIniFile);
00966     GetPrivateProfileString(szAppName, szYFrom, szDefYFr, szYFr, MAXDOUBLELEN, szIniFile);
00967     GetPrivateProfileString(szAppName, szXTo, szDefX2, szX2, MAXDOUBLELEN, szIniFile);
00968     GetPrivateProfileString(szAppName, szYTo, szDefY2, szY2, MAXDOUBLELEN, szIniFile);
00969     GetPrivateProfileString(szAppName, szSaveFile, szDefSavef, szSavef, MAXPATHLEN, szIniFile);
00970     GetPrivateProfileString(szAppName, szIteration, szDefIter, szIter, MAXDOUBLELEN, szIniFile);
00971     return TRUE;
00972 }
00973
00974
00975
00976 /******************************Public*Routine******************************\
00977 *
00978 * bColorCycle
00979 *
00980 * Effects:  Create a logical palette with a good spread of color
00981 *           Animate the palette, shift the palette entries and animate
00982 *           again for 256 times altogether.
00983 *           This creates the color cycling effect.
00984 *
00985 * Warnings: Only works in device that support palette.
00986 *
00987 * History:
00988 *  15-Jan-1993      Petrus Wong     Adaped from the SDK Mandel sample
00989 *  24-Apr-1992 -by- Petrus Wong
00990 * Wrote it.
00991 \**************************************************************************/
00992
00993 BOOL bColorCycle(HDC hDC, PINFO pInfo)
00994 {
00995     INT             iEntry, i, iNumClr;
00996     PLOGPALETTE     plogPat;
00997     ULONG           ulSize;
00998     BOOL            bSuccess;
00999     HPALETTE        hPal, hPalOld;
01000     PALETTEENTRY    peTemp;
01001     BOOL            bQuit;
01002
01003
01004 UINT uRC;
01005
01006     bSuccess = TRUE;
01007     iEntry = 1<<GetDeviceCaps(hDC, BITSPIXEL);
01008     iNumClr = 236;          // 256 minus 20 reserved colors
01009     ulSize = sizeof(LOGPALETTE)+sizeof(PALETTEENTRY)*256;
01010
01011     if ((plogPat = (PLOGPALETTE) GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, ulSize)) == NULL) {
01012         MessageBox(hMainWindow, "Failed in Memory Allocation for plogPat!", "Error", MB_OK);
01013         bSuccess = FALSE;
01014         goto ErrExit1;
01015     }
01016
01017     plogPat->palVersion = 0x300;
01018     plogPat->palNumEntries = (WORD) 256;
01019     {
01020     int     iFirst, iSecond, iInc;
01021
01022         iFirst = iNumClr/3;
01023         iSecond = iFirst * 2;
01024         iInc = (iNumClr <= 256) ? 3 : 1;
01025
01026         for (i = 0; i < iNumClr; i++) {
01027             if (i < iFirst) {
01028                 plogPat->palPalEntry[i+10].peBlue   = 255-(i+1)*iInc;
01029                 plogPat->palPalEntry[i+10].peGreen  = 0;
01030                 plogPat->palPalEntry[i+10].peRed    = (i+1)*iInc;
01031                 plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
01032                 continue;
01033             }
01034             if (i < iSecond) {
01035                 plogPat->palPalEntry[i+10].peBlue   = 0;
01036                 plogPat->palPalEntry[i+10].peGreen  = (i+1-iFirst)*iInc;
01037                 plogPat->palPalEntry[i+10].peRed    = 255-(i+1-iFirst)*iInc;
01038                 plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
01039                 continue;
01040             }
01041             plogPat->palPalEntry[i+10].peBlue   = (i+1-iSecond)*iInc;
01042             plogPat->palPalEntry[i+10].peGreen  = 255-(i+1-iSecond)*iInc;
01043             plogPat->palPalEntry[i+10].peRed    = 0;
01044             plogPat->palPalEntry[i+10].peFlags  = PC_RESERVED;
01045         }
01046     }
01047
01048     if ((hPal = CreatePalette(plogPat)) == (HPALETTE) NULL) {
01049         MessageBox(hMainWindow, "Failed in creating palette!", "Error", MB_OK);
01050         bSuccess = FALSE;
01051         goto ErrExit2;
01052     }
01053
01054     hPalOld = SelectPalette(hDC, hPal, FALSE);
01055     RealizePalette(hDC);
01056     //SelectPalette(hDC, hPalOld, FALSE);
01057
01058     bQuit = FALSE;
01059     while (TRUE && !bQuit) {
01060         if (!pInfo->bClrCycle) {
01061             //sprintf( gtext,"NOT to animate palette\n");
01062             //OutputDebugString( gtext );
01063             bQuit = TRUE;
01064         }
01065
01066         if (!bQuit) {
01067             //sprintf( gtext,"About to animate palette\n");
01068             //OutputDebugString( gtext );
01069
01070
01071             peTemp = plogPat->palPalEntry[10];
01072             for (i = 0; i < iNumClr; i++) {
01073                 plogPat->palPalEntry[i+10] = plogPat->palPalEntry[i+10+1];
01074             }
01075             plogPat->palPalEntry[i+10] = peTemp;
01076
01077             Sleep(25);
01078
01079             if (!AnimatePalette(hPal, 0, 256, plogPat->palPalEntry)) {
01080                 sprintf( gtext,"Anmiate palette failed\n");
01081                 OutputDebugString( gtext );
01082             }
01083
01084             if ((uRC = RealizePalette(hDC)) == -1) {
01085                 sprintf( gtext,"Realize palette failed\n");
01086                 OutputDebugString( gtext );
01087             }
01088
01089             if (!UpdateColors(hDC)) {
01090                 sprintf( gtext,"Update Colors failed\n");
01091                 OutputDebugString( gtext );
01092             }
01093
01094         }
01095
01096     }
01097
01098     SelectPalette(hDC, hPalOld, 0);
01099     DeleteObject(hPal);
01100 ErrExit2:
01101     GlobalFree(plogPat);
01102 ErrExit1:
01103     return bSuccess;
01104
01105 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/NTGREP.H Source File

  • GUIGREP

NTGREP.H

Go to the documentation of this file.
00001 #define IDM_ABOUT 100
00002 #define IDM_DEFGREP 101
00003 #define IDM_INSTALL 102
00004 #define IDM_STRINGEDIT 103
00005 #define IDM_TERMBOX 104
00006 #define IDM_STARTGREP 105
00007 #define IDM_UNINSTALL 106
00008 #define IDM_SORTBOX 107
00009 #define IDM_CASESENS 108
00010 #define IDM_CANCEL 109
00011
00012
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDITYPES.H Source File

  • MDI_

MDITYPES.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #include "mdi.h"
00013
00014 //
00015 // Instance data for each MDI child window
00016 //
00017 typedef struct _PerWndInfo {
00018     HWND    hParent;
00019     HWND    hTextWnd;
00020     RECT    rcClient;
00021     char    CaptionBarText[SIZEOFCAPTIONTEXT];
00022 } INFO, *PINFO;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/GLOBALS.H Source File

  • NETDDE

GLOBALS.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // PURPOSE:
00009 //    Contains declarations for all globally scoped names in the program.
00010 //
00011
00012
00013 //-------------------------------------------------------------------------
00014 // Product identifier string defines
00015
00016 //  **TODO** Change these strings to the name of your application.
00017
00018 #define APPNAME       nddechat
00019 #define ICONFILE      nddechat.ico
00020 #define SZAPPNAME     "nddechat"
00021 #define SZDESCRIPTION "NetDDE Chat Sample"
00022 #define SZABOUT       "About NetDDE Chat"
00023 #define SZVERSION     "Version 1.0"
00024
00025
00026 //-------------------------------------------------------------------------
00027 // Functions for handling main window messages.  The message-dispatching
00028 // mechanism expects all message-handling functions to have the following
00029 // prototype:
00030 //
00031 //     LRESULT FunctionName(HWND, UINT, WPARAM, LPARAM);
00032
00033 // **TODO**  Add message-handling function prototypes here.
00034 //           add the function names to the main window message table in
00035 //           rasberry.c.
00036
00037 LRESULT MsgCreate(HWND, UINT, WPARAM, LPARAM);
00038 LRESULT MsgSetFocus(HWND, UINT, WPARAM, LPARAM);
00039 LRESULT MsgSize(HWND, UINT, WPARAM, LPARAM);
00040 LRESULT MsgConnect(HWND, UINT, WPARAM, LPARAM);
00041 LRESULT MsgDisconnect(HWND, UINT, WPARAM, LPARAM);
00042 LRESULT MsgReceiveText(HWND, UINT, WPARAM, LPARAM);
00043 LRESULT MsgCommand(HWND, UINT, WPARAM, LPARAM);
00044 LRESULT MsgDestroy(HWND, UINT, WPARAM, LPARAM);
00045
00046
00047 //-------------------------------------------------------------------------
00048 // Functions for handling main window commands--ie. functions for
00049 // processing WM_COMMAND messages based on the wParam value.
00050 // The message-dispatching mechanism expects all command-handling
00051 // functions to have the following prototype:
00052 //
00053 //     LRESULT FunctionName(HWND, WORD, WORD, HWND);
00054
00055 // **TODO**  Add message-handling function prototypes here.  Be sure to
00056 //           add the function names to the main window command table in
00057 //           rasberry.c.
00058
00059 LRESULT CmdConnectDlg(HWND, WORD, WORD, HWND);
00060 LRESULT CmdDisconnect(HWND, WORD, WORD, HWND);
00061 LRESULT CmdSendNotify(HWND, WORD, WORD, HWND);
00062 LRESULT CmdAbout(HWND, WORD, WORD, HWND);
00063 LRESULT CmdExit(HWND, WORD, WORD, HWND);
00064
00065
00066 //-------------------------------------------------------------------------
00067 // Global function prototypes.
00068
00069 // **TODO**  Add global function prototypes here.
00070
00071 #ifdef WIN16
00072 #include <ddeml.h> // for HDDEDATA definition
00073 #define MAX_COMPUTERNAME_LENGTH 15
00074 #ifndef ERROR_SUCCESS
00075 #define ERROR_SUCCESS 0
00076 #endif
00077 #endif
00078
00079 BOOL InitApplication(HINSTANCE);
00080 BOOL InitInstance(HINSTANCE, int);
00081 BOOL CenterWindow(HWND, HWND);
00082 HDDEDATA GetDataToTrans( VOID );
00083
00084     // Callback functions.  These are called by Windows.
00085
00086 // **TODO**  Add new callback function prototypes here.  Win16 compiles
00087 //           require the __export keyword to generate proper prolog
00088 //           and epilog code for exported functions.
00089
00090 #ifdef WIN16
00091
00092 LRESULT CALLBACK __export WndProc(HWND, UINT, WPARAM, LPARAM);
00093
00094 #else
00095
00096 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
00097
00098 #endif
00099
00100
00101 //-------------------------------------------------------------------------
00102 // Command ID definitions.  These definitions are used to associate menu
00103 // items with commands.
00104
00105 // **TODO**  Add IDs for all menu commands here.  Be sure that the IDs you
00106 //           add are also added to the main window command table in rasberry.c
00107 //           and the menu statements in the resource file.
00108
00109 // File menu
00110 #define IDM_EXIT         1000
00111 #define IDM_CONNECT      1001
00112 #define IDM_DISCONNECT   1002
00113
00114 // Help menu
00115 #define IDM_ABOUT        1200
00116
00117 //-------------------------------------------------------------------------
00118 // String Table ID definitions.
00119
00120 #define IDS_APPNAME         1
00121 #define IDS_DESCRIPTION     2
00122 #define IDS_SHARENAME       3
00123 #define IDS_TOPIC           4
00124 #define IDS_ITEM            5
00125
00126 //-------------------------------------------------------------------------
00127 //  Main window defines.
00128
00129 #define IDE_SEND        100
00130 #define IDE_RECV        101
00131 #define IDC_STATIC       -1
00132
00133 #define WM_CONNECT      WM_USER+100
00134 #define WM_DISCONNECT   WM_USER+101
00135 #define WM_RECEIVE_TEXT WM_USER+102
00136
00137 #define STR_DWORD(x)   (*((UNALIGNED DWORD FAR*)(x+lstrlen(x)+1)))
00138
00139 #define STATE_UNCONN     0
00140 #define STATE_PENDING    1
00141 #define STATE_SERVER     2
00142 #define STATE_CLIENT     3
00143
00144 //-------------------------------------------------------------------------
00145 //  About dialog defines.
00146
00147 #define IDD_VERFIRST    200
00148 #define IDD_VERLAST     204
00149
00150
00151
00152 //-------------------------------------------------------------------------
00153 // Global variable declarations.
00154
00155 extern HINSTANCE hInst;          // The current instance handle
00156 extern char      szAppName[];    // The name of this application
00157 extern char      szTitle[];      // The title bar text
00158 extern HWND      g_hwnd;
00159 extern DWORD     g_idInst;
00160 extern char      g_szServer[];
00161 extern char      g_szTopic[];
00162 extern BOOL      g_fState;
00163 extern HWND      hwndSend;
00164 extern HINSTANCE g_hInstNetDde;  // Handle of the nddeapi.dll
00165
00166 // **TODO**  For NON-MDI applications uncomment line 1 below and comment
00167 //           line 2.  For MDI applications, uncomment line 2 below, comment
00168 //           line 1, and then define hwndMDIClient as a global variable in
00169 //           INIT.C
00170 #define hwndMDIClient NULL        /* (1) Stub for NON-MDI applications. */
00171 // extern HWND hwndMDIClient;     /* (2) For MDI applications.          */
00172
00173
00174 //-------------------------------------------------------------------------
00175 // Message and command dispatch infrastructure.  The following type
00176 // definitions and functions are used by the message and command dispatching
00177 // mechanism and do not need to be changed.
00178
00179     // Function pointer prototype for message handling functions.
00180 typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);
00181
00182     // Function pointer prototype for command handling functions.
00183 typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);
00184
00185     // Enumerated type used to determine which default window procedure
00186     // should be called by the message- and command-dispatching mechanism
00187     // if a message or command is not handled explicitly.
00188 typedef enum
00189 {
00190    edwpNone,            // Do not call any default procedure.
00191    edwpWindow,          // Call DefWindowProc.
00192    edwpDialog,          // Call DefDlgProc (This should be used only for
00193                         // custom dialogs - standard dialog use edwpNone).
00194    edwpMDIChild,        // Call DefMDIChildProc.
00195    edwpMDIFrame         // Call DefFrameProc.
00196 } EDWP;                // Enumeration for Default Window Procedures
00197
00198     // This structure maps messages to message handling functions.
00199 typedef struct _MSD
00200 {
00201     UINT   uMessage;
00202     PFNMSG pfnmsg;
00203 } MSD;                 // MeSsage Dispatch structure
00204
00205     // This structure contains all of the information that a window
00206     // procedure passes to DispMessage in order to define the message
00207     // dispatching behavior for the window.
00208 typedef struct _MSDI
00209 {
00210     int  cmsd;          // Number of message dispatch structs in rgmsd
00211     MSD *rgmsd;         // Table of message dispatch structures
00212     EDWP edwp;          // Type of default window handler needed.
00213 } MSDI, FAR *LPMSDI;   // MeSsage Dipatch Information
00214
00215     // This structure maps command IDs to command handling functions.
00216 typedef struct _CMD
00217 {
00218     WORD   wCommand;
00219     PFNCMD pfncmd;
00220 } CMD;                 // CoMmand Dispatch structure
00221
00222     // This structure contains all of the information that a command
00223     // message procedure passes to DispCommand in order to define the
00224     // command dispatching behavior for the window.
00225 typedef struct _CMDI
00226 {
00227     int  ccmd;          // Number of command dispatch structs in rgcmd
00228     CMD *rgcmd;         // Table of command dispatch structures
00229     EDWP edwp;          // Type of default window handler needed.
00230 } CMDI, FAR *LPCMDI;   // CoMmand Dispatch Information
00231
00232     // Message and command dispatching functions.  They look up messages
00233     // and commands in the dispatch tables and call the appropriate handler
00234     // function.
00235 LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
00236 LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);
00237
00238     // Message dispatch information for the main window
00239 extern MSDI msdiMain;
00240     // Command dispatch information for the main window
00241 extern CMDI cmdiMain;
00242
00243
00244
00245 //-------------------------------------------------------------------------
00246 // Version string definitions--Leave these alone.
00247
00248 #define SZRCOMPANYNAME "CompanyName"
00249 #define SZRDESCRIPTION "FileDescription"
00250 #define SZRVERSION     "FileVersion"
00251 #define SZRAPPNAME     "InternalName"
00252 #define SZRCOPYRIGHT   "LegalCopyright"
00253 #define SZRTRADEMARK   "LegalTrademarks"
00254 #define SZRPRODNAME    "ProductName"
00255 #define SZRPRODVER     "ProuctVersion"
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/W32SUT.H Source File

  • INTEROP

W32SUT.H

Go to the documentation of this file.
00001 /***
00002 *w32sut.h -
00003 *
00004 *       Copyright (c) 1987-1996, Microsoft Corporation.  All rights reserved.
00005 *
00006 *Purpose:
00007 *       This file declares the constants, structures, and functions
00008 *       used for accessing and using the Universal Thunk mechanism.
00009 *
00010 *       This file should be compiled either with constants W32SUT_16 or
00011 *       W32SUT_32 defined.
00012 *
00013 ****/
00014
00015 /* Check that one of the 2 constants is defined  */
00016 #ifdef W32SUT_16
00017 #ifdef W32SUT_32
00018 #error W32SUT_16 and W32SUT_32 cannot be defined simultaneously
00019 #endif
00020 #endif
00021
00022 #ifndef W32SUT_16
00023 #ifndef W32SUT_32
00024 #error  Either W32SUT_16 or W32SUT_32 should be defined
00025 #endif
00026 #endif
00027
00028
00029 /****      Prototypes for 32 bit DLL   ***********/
00030 #ifdef W32SUT_32
00031
00032 typedef DWORD  ( WINAPI * UT32PROC)( LPVOID lpBuff,
00033                                      DWORD  dwUserDefined,
00034                                      LPVOID *lpTranslationList
00035                                    );
00036
00037 BOOL    WINAPI UTRegister( HANDLE     hModule,
00038                            LPCSTR     lpsz16BitDLL,
00039                            LPCSTR     lpszInitName,
00040                            LPCSTR     lpszProcName,
00041                            UT32PROC * ppfn32Thunk,
00042                            FARPROC    pfnUT32Callback,
00043                            LPVOID     lpBuff
00044                          );
00045
00046
00047 VOID    WINAPI UTUnRegister(HANDLE hModule);
00048
00049 #endif
00050
00051
00052 /****      Prototypes for 16 bit DLL   ***********/
00053 #ifdef W32SUT_16
00054
00055 typedef DWORD (FAR PASCAL  * UT16CBPROC)( LPVOID lpBuff,
00056                                           DWORD  dwUserDefined,
00057                                           LPVOID FAR *lpTranslationList
00058                                         );
00059
00060
00061 LPVOID  WINAPI  UTLinearToSelectorOffset(LPBYTE lpByte);
00062 LPVOID  WINAPI  UTSelectorOffsetToLinear(LPBYTE lpByte);
00063
00064 #endif
00065
00066
00067
00068
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: DRIVES/DRIVES.H Source File

  • DRIVES

DRIVES.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* definitions */
00013
00014 #define DRIVE_REMOVEABLE 2
00015 #define DRIVE_FIXED      3
00016 #define DRIVE_REMOTE     4
00017 #define DRIVE_CDROM      5
00018 #define DRIVE_RAMDISK    6
00019
00020 /* procedure definitions */
00021
00022 BOOL   CheckRM      (LPTSTR);
00023 VOID   GVI          (LPTSTR, LPTSTR, DWORD);
00024 LPTSTR UpdateBuffer (LPTSTR);
00025 VOID   main         (VOID);
00026
00027
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/TRACK.C Source File

  • MASKBLT

TRACK.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  track.c -- support for direct manipulation of parallelogram object.
00014 \**************************************************************************/
00015
00016 #include <windows.h>
00017 #include <math.h>
00018 #include "track.h"
00019
00020 #define EPSILON  (float) 0.0001
00021 #define RECTSIZE  60
00022
00023
00024
00025 /**************************************************************************\
00026 *
00027 *  function:  doTrackObject()
00028 *
00029 *  input parameters:
00030 *   pto -  pointer to a track object.
00031 *   msg -  message selecting what action to take.  Values may include WM_*'s
00032 *           (see case statements below for more information.)
00033 *   hwnd - Window handle for the window the track object exists within.
00034 *   lParam - Usually fourth param to window proc. varies based on msg.
00035 *
00036 *  global variables:  none.
00037 *
00038 *  coordinate spaces:  There are three coordinate spaces of interest here,
00039 *   and this routine is frequently switching between them...
00040 *
00041 *           WORLD                   DEVICE                  SCREEN
00042 *
00043 *      object coordinates       input mouse pos       used w/ SetCursorPos()
00044 *         (pto->rect)          (lParam for WM_*)
00045 *
00046 *             ----->  LPtoDP() ---->    ----> ClientToScreen() -->
00047 *             <-----  DPtoLP() <----    <---- ScreenToClient() <--
00048 *
00049 *   in addition, the HDC has an offset origin.  Device coordinates for the
00050 *   mouse (lParam) never take this into account, but it is necessary to
00051 *   translate them in order to get direct manipulation right.
00052 *
00053 \**************************************************************************/
00054 PTrackObject doTrackObject(PTrackObject pto, int msg, HWND hwnd, LONG lParam)
00055 {
00056   if ((pto == NULL) && (msg != TROB_NEW))  return NULL;
00057
00058   switch (msg) {
00059
00060
00061     /**********************************************************************\
00062     *  TROB_NEW
00063     *
00064     * Allocate new PTrackObject structure.  Fill in default values
00065     *  for the fields of the structure.  Set up the HDC correctly.
00066     * return - pointer to the new object.
00067     \**********************************************************************/
00068     case  TROB_NEW: {
00069         PTrackObject  pto;
00070
00071         /* with LPTR returned value is a pointer. */
00072         pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));
00073
00074         /* initialize the HDC and other fields. */
00075         pto->hdc = GetDC (hwnd);
00076         SetGraphicsMode (pto->hdc, GM_ADVANCED);
00077         SetROP2(pto->hdc, R2_NOT);
00078         SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
00079         pto->Mode = TMNONE;
00080         pto->allowedModes = TMMOVE | TMSIZEXY;
00081
00082         GetWorldTransform (pto->hdc, &(pto->xfmChange));
00083
00084         /* initialize the size. */
00085         pto->rect.top = pto->rect.left = 0;
00086         pto->rect.bottom = pto->rect.right = RECTSIZE;
00087
00088         return (pto);
00089     }
00090
00091
00092
00093     /**********************************************************************\
00094     *  TROB_DELETE
00095     *
00096     * Complement of TROB_NEW.  Free up the memory allocated for the object.
00097     \**********************************************************************/
00098     case  TROB_DELETE:
00099         doTrackObject (pto, TROB_PAINT, hwnd, lParam);
00100         ReleaseDC (hwnd, pto->hdc);
00101         LocalFree (LocalHandle ((LPSTR)pto));
00102     return NULL;
00103
00104
00105
00106     /**********************************************************************\
00107     *  TROB_PAINT
00108     *
00109     * Paint the object into its hdc.  Called half the time to erase
00110     *  the object, and half the time to redraw it.
00111     \**********************************************************************/
00112     case TROB_PAINT: {
00113         MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
00114         LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
00115         LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);
00116
00117         if (pto->allowedModes & TMSIZEXY) {
00118           LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
00119           LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
00120         }
00121
00122         if (pto->allowedModes & TMROTATE) {
00123           MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
00124           AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
00125                  (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
00126         }
00127
00128     } return NULL;
00129
00130
00131
00132     /**********************************************************************\
00133     *  TROB_HITTEST
00134     *
00135     * Check the point sent in in the lParam to see if it lays within
00136     *  the bounds of the objects defining rectangle.
00137     * return - pointer to the object iff the point is in rectangle,
00138     *  otherwise return NULL.
00139     \**********************************************************************/
00140     case TROB_HITTEST:{
00141         POINT  mouWorld;
00142         mouWorld.x = LOWORD(lParam);
00143         mouWorld.y = HIWORD(lParam);
00144
00145         DPtoLP (pto->hdc, &mouWorld, 1);
00146
00147         if (PtInRect (&pto->rect, mouWorld))  return pto;
00148         else  return NULL;
00149     }
00150
00151
00152
00153     /**********************************************************************\
00154     *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
00155     *
00156     * Capture the mouse, set the tracking mode depending on the mouse
00157     *  location in world coordinates, reset the mouse position.
00158     *
00159     \**********************************************************************/
00160     case WM_LBUTTONDOWN:
00161     case WM_RBUTTONDOWN: {
00162       POINT  newmouScreen;
00163       POINT  mouWorld;
00164
00165       mouWorld.x = LOWORD(lParam);
00166       mouWorld.y = HIWORD(lParam);
00167       DPtoLP (pto->hdc, &mouWorld, 1);
00168
00169       /* upper left hand corner. right button is no-op. */
00170       if ((mouWorld.x <= (pto->rect.right  / 2)) &&
00171           (mouWorld.y <= (pto->rect.bottom / 2))) {
00172           if (msg == WM_RBUTTONDOWN) return NULL;
00173           pto->Mode = TMMOVE;
00174           newmouScreen.x = pto->rect.left;
00175           newmouScreen.y = pto->rect.top;
00176
00177       /* lower left hand corner */
00178       } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
00179           (mouWorld.y > (pto->rect.bottom / 2))) {
00180
00181           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
00182           newmouScreen.x = pto->rect.left;
00183           newmouScreen.y = pto->rect.bottom;
00184
00185       /* upper right hand corner */
00186       } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
00187           (mouWorld.y <= (pto->rect.bottom / 2))) {
00188
00189           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
00190           newmouScreen.x = pto->rect.right;
00191           newmouScreen.y = pto->rect.top;
00192
00193       /* lower right hand corner */
00194       } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
00195           (mouWorld.y > (pto->rect.bottom / 2))) {
00196
00197           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
00198           newmouScreen.x = pto->rect.right;
00199           newmouScreen.y = pto->rect.bottom;
00200       }
00201
00202       if (! (pto->Mode & pto->allowedModes)) {
00203         pto->Mode = TMNONE;
00204         return NULL;
00205       }
00206
00207       SetCapture(hwnd);
00208       LPtoDP (pto->hdc, &newmouScreen, 1);
00209       ClientToScreen (hwnd, &newmouScreen);
00210       SetCursorPos (newmouScreen.x,newmouScreen.y);
00211
00212       GetWorldTransform (pto->hdc, &pto->xfmDown);
00213     } return NULL;
00214
00215
00216
00217     /**********************************************************************\
00218     *  WM_MOUSEMOVE
00219     *
00220     * this is where almost all of the interesting calculation is done.
00221     *  First clip the mouse location to be in rectClip, then
00222     *  call MouseMove() to handle the different tracking modes.
00223     \**********************************************************************/
00224     case WM_MOUSEMOVE: {
00225       if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
00226         lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));
00227
00228       if (LOWORD(lParam) > (WORD)pto->rectClip.right)
00229         lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));
00230
00231       if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
00232         lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);
00233
00234       if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
00235         lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);
00236
00237       MouseMove (pto, msg, hwnd, lParam);
00238
00239     } return NULL;
00240
00241
00242
00243     /**********************************************************************\
00244     *  WM_RBUTTONUP & WM_LBUTTONUP
00245     *
00246     * simply release the mouse capture, and set the mode to TMNONE.
00247     \**********************************************************************/
00248     case WM_RBUTTONUP:
00249     case WM_LBUTTONUP: {
00250       if (pto->Mode) {
00251          ReleaseCapture();
00252          pto->Mode = TMNONE;
00253       }
00254     } return NULL;
00255
00256   }  /* end switch(msg) */
00257 }
00258
00259
00260
00261
00262
00263
00264 /**************************************************************************\
00265 *  function:  MouseMove()
00266 *
00267 *  input parameters:
00268 *   pto -  pointer to a track object.
00269 *   msg -  not used.
00270 *   hwnd - Window handle for the window the track object exists within.
00271 *   lParam - Usually fourth param to window proc. varies based on msg.
00272 *
00273 *  The tracking behavior which the user observers when moving the mouse
00274 *   is based on the current tracking mode of the object.  This is usually
00275 *   determined on the mouse down event (c.f. TM*).  First erase the old
00276 *   object, then figure out the change to the transform matrix, finally
00277 *   change the world transform matrix and redraw the object.
00278 *
00279 *  Tranform:
00280 *    (    eM11        eM12        0   )
00281 *    (    eM21        eM22        0   )
00282 *    (    eDx         eDy         1   )
00283 *
00284 *   xDevice = (xWorld * eM11) + (yWorld * eM21) + eDx
00285 *   yDevice = (xWorld * eM12) + (yWorld * eM22) + eDy
00286 *
00287 *   In this routine the Device (mouse location) and World (rectangle corner)
00288 *   points are known.  Therefore, the two equations above are solved for
00289 *   the desired matrix entry value (e.g. eM11, 1M12, ... eDy).  The tracking
00290 *   mode determines which one of these entries may be changed.  E.g. scaling
00291 *   in X modifies eM11 while shearing in X modifies eM12.  So rather than
00292 *   using the world transform to map from world to device points, we are
00293 *   back-computing the proper contents of the world transform.
00294 *
00295 \**************************************************************************/
00296 VOID MouseMove(PTrackObject pto, int msg, HWND hwnd, LONG lParam)
00297 {
00298 POINT  mouWorld, mouDevice, orgDevice;
00299
00300     UNREFERENCED_PARAMETER(msg);
00301
00302     doTrackObject(pto, TROB_PAINT, hwnd, lParam);
00303     mouDevice.x = mouWorld.x = LOWORD(lParam);
00304     mouDevice.y = mouWorld.y = HIWORD(lParam);
00305
00306     SetWorldTransform(pto->hdc, &pto->xfmDown);
00307     DPtoLP (pto->hdc, &mouWorld, 1);
00308
00309     /* offset the mouse device point for the viewport's origin. */
00310     GetViewportOrgEx (pto->hdc, &orgDevice);
00311     mouDevice.x -= orgDevice.x;
00312     mouDevice.y -= orgDevice.y;
00313
00314     GetWorldTransform(pto->hdc, &pto->xfmChange);
00315
00316     switch (pto->Mode) {
00317       /*******************************************************\
00318       *    (     1         xShear       0   )
00319       *    (     0           1          0   )
00320       *    (     0           0          1   )
00321       *
00322       * xWorld = rect.left == 0;
00323       \*******************************************************/
00324       case TMSHEARX: {
00325         pto->xfmChange.eM12 = (float) mouDevice.y;
00326         pto->xfmChange.eM12 -=pto->xfmChange.eDy;
00327         pto->xfmChange.eM12 /=(float) pto->rect.right ;
00328         SetWorldTransform (pto->hdc, &pto->xfmChange);
00329       } break;
00330
00331
00332       /*******************************************************\
00333       *    (     1           0          0   )
00334       *    (   yShear        1          0   )
00335       *    (     0           0          1   )
00336       *
00337       * yWorld = rect.top == 0;
00338       \*******************************************************/
00339       case TMSHEARY: {
00340         pto->xfmChange.eM21 = (float) mouDevice.x;
00341         pto->xfmChange.eM21 -=pto->xfmChange.eDx;
00342         pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
00343         SetWorldTransform (pto->hdc, &pto->xfmChange);
00344
00345       } break;
00346
00347
00348       /*******************************************************\
00349       *    (   cos(a)      -sin(a)      0   )
00350       *    (   sin(a)       cos(a)      0   )
00351       *    (     0           0          1   )
00352       *
00353       * a == rotation angle.  Since mouse in in lower right,
00354       *  we need to shift this back 45 degrees (assuming that
00355       *  straight down is 0 degrees).  Thus we actually compute
00356       *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
00357       *  where b is angle from the origin to the mouse (x,y)
00358       *  cos(45) = sin(45) ~= 0.707107
00359       *  cos(b) = y/r    sin(b) = x/r
00360       *
00361       \*******************************************************/
00362       case TMROTATE: {
00363         float r;
00364
00365         /* translate back to the origin. */
00366         pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
00367         SetWorldTransform (pto->hdc, &pto->xfmChange);
00368
00369         /* rotate about the origin. */
00370         r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
00371                           (double)(mouWorld.y * mouWorld.y));
00372
00373         pto->xfmChange.eM11 = (float) mouWorld.y / r;
00374         pto->xfmChange.eM11 += (float) mouWorld.x / r;
00375         pto->xfmChange.eM11 *= (float) 0.707107;
00376         pto->xfmChange.eM22 = pto->xfmChange.eM11;
00377
00378         pto->xfmChange.eM12 = (float) mouWorld.y / r;
00379         pto->xfmChange.eM12 -= (float) mouWorld.x / r;
00380         pto->xfmChange.eM12 *= (float) 0.707107;
00381         pto->xfmChange.eM21 = -pto->xfmChange.eM12;
00382
00383         pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
00384
00385         ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
00386
00387         /* translate back to the original offset. */
00388         pto->xfmChange.eM11 =
00389         pto->xfmChange.eM22 = (float) 1.0;
00390         pto->xfmChange.eM12 =
00391         pto->xfmChange.eM21 = (float) 0.0;
00392
00393         pto->xfmChange.eDx = pto->xfmDown.eDx;
00394         pto->xfmChange.eDy = pto->xfmDown.eDy;
00395         ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
00396         GetWorldTransform (pto->hdc, &pto->xfmChange);
00397       } break;
00398
00399
00400       /*******************************************************\
00401       *    (  Size X         0          0   )
00402       *    (     0        Size Y        0   )
00403       *    (     0           0          1   )
00404       *
00405       \*******************************************************/
00406       case TMSIZEXY: {
00407         pto->xfmChange.eM11 = (float) mouDevice.x;
00408         pto->xfmChange.eM11 -=pto->xfmChange.eDx;
00409         pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
00410         pto->xfmChange.eM11 /=(float) pto->rect.right ;
00411         if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
00412            pto->xfmChange.eM11 = EPSILON;
00413
00414         pto->xfmChange.eM22 = (float) mouDevice.y;
00415         pto->xfmChange.eM22 -=pto->xfmChange.eDy;
00416         pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
00417         pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
00418         if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
00419            pto->xfmChange.eM22 = EPSILON;
00420         SetWorldTransform (pto->hdc, &pto->xfmChange);
00421       } break;
00422
00423
00424       /*******************************************************\
00425       *    (  Size X         0          0   )
00426       *    (     0           1          0   )
00427       *    (     0           0          1   )
00428       *
00429       * yWorld = rect.top == 0;
00430       \*******************************************************/
00431       case TMSIZEX: {
00432         pto->xfmChange.eM11 = (float) mouDevice.x;
00433         pto->xfmChange.eM11 -=pto->xfmChange.eDx;
00434         pto->xfmChange.eM11 /=(float) pto->rect.right ;
00435         if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
00436            pto->xfmChange.eM11 = EPSILON;
00437
00438         SetWorldTransform (pto->hdc, &pto->xfmChange);
00439       } break;
00440
00441
00442       /*******************************************************\
00443       *    (     1           0          0   )
00444       *    (     0        Size Y        0   )
00445       *    (     0           0          1   )
00446       *
00447       * xWorld = rect.left == 0;
00448       \*******************************************************/
00449       case TMSIZEY: {
00450         pto->xfmChange.eM22 = (float) mouDevice.y;
00451         pto->xfmChange.eM22 -=pto->xfmChange.eDy;
00452         pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
00453         if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
00454            pto->xfmChange.eM22 = EPSILON;
00455         SetWorldTransform (pto->hdc, &pto->xfmChange);
00456       } break;
00457
00458
00459       /*******************************************************\
00460       *    (     1           0          0   )
00461       *    (     0           1          0   )
00462       *    (   Move x      Move y       1   )
00463       *
00464       * xWorld = rect.left == 0;
00465       * yWorld = rect.top == 0;
00466       \*******************************************************/
00467       case TMMOVE: {
00468         pto->xfmChange.eDx = (float) mouDevice.x ;
00469         pto->xfmChange.eDy = (float) mouDevice.y ;
00470         SetWorldTransform (pto->hdc, &pto->xfmChange);
00471       } break;
00472     } /* end switch */
00473
00474     doTrackObject(pto, TROB_PAINT, hwnd, lParam);
00475
00476     return;
00477  }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/CONNECT.C Source File

  • NETDDE

CONNECT.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   connect.c
00009 //
00010 //  PURPOSE:   Displays the "ConnectDlg" dialog box
00011 //
00012 //  FUNCTIONS:
00013 //    ConnectDlg           - Processes messages for "ConnectDlg" dialog box.
00014 //    MsgConnectDlgInit    - To initialize the connectdlg box.
00015 //    MsgConnectDlgCommand - Process WM_COMMAND message.
00016 //    CmdConnectDlgOK      - Free the ConnectDlg box and return Server Name.
00017 //    CmdConnectDlgCancel  - Free the ConnectDlg box.
00018 //
00019 //  COMMENTS:
00020 //    Dialog Box to get server to connect to
00021 //
00022 //  AUTHOR:  Craig Link - Microsoft Developer Support
00023 //
00024
00025 #include <windows.h>            // required for all Windows applications
00026 #include <windowsx.h>
00027 #ifdef WIN16
00028 #include "win16ext.h"           // required only for win16 applications
00029 #endif
00030 #include "globals.h"            // prototypes specific to this application
00031 #include "connect.h"
00032
00033 LRESULT MsgConnectDlgInit(HWND, UINT, WPARAM, LPARAM);
00034 LRESULT MsgConnectDlgCommand(HWND, UINT, WPARAM, LPARAM);
00035 LRESULT CmdConnectDlgOK(HWND, WORD, WORD, HWND);
00036 LRESULT CmdConnectDlgCancel(HWND, WORD, WORD, HWND);
00037
00038
00039 // ConnectDlg dialog message table definition.
00040 MSD rgmsdConnectDlg[] =
00041 {
00042     {WM_COMMAND,      MsgConnectDlgCommand},
00043     {WM_INITDIALOG,   MsgConnectDlgInit}
00044 };
00045
00046 MSDI msdiConnectDlg =
00047 {
00048     sizeof(rgmsdConnectDlg) / sizeof(MSD),
00049     rgmsdConnectDlg,
00050     edwpNone
00051 };
00052
00053 // ConnectDlg dialog command table definition.
00054 CMD rgcmdConnectDlg[] =
00055 {
00056     {IDOK,     CmdConnectDlgOK},
00057     {IDCANCEL, CmdConnectDlgCancel}
00058 };
00059
00060 CMDI cmdiConnectDlg =
00061 {
00062     sizeof(rgcmdConnectDlg) / sizeof(CMD),
00063     rgcmdConnectDlg,
00064     edwpNone
00065 };
00066
00067 // Module specific "globals"  Used when a variable needs to be
00068 // accessed in more than on handler function.
00069
00070 //
00071 //  FUNCTION: ConnectDlg(HWND, UINT, WPARAM, LPARAM)
00072 //
00073 //  PURPOSE:  Processes messages for "ConnectDlg" dialog box.
00074 //
00075 //  PARAMETERS:
00076 //    hdlg - window handle of the dialog box
00077 //    wMessage - type of message
00078 //    wparam - message-specific information
00079 //    lparam - message-specific information
00080 //
00081 //  RETURN VALUE:
00082 //    TRUE - message handled
00083 //    FALSE - message not handled
00084 //
00085 //  COMMENTS:
00086 //    Dispatches message to appropriate handler
00087 //
00088
00089 LRESULT CALLBACK ConnectDlg(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00090 {
00091     return DispMessage(&msdiConnectDlg, hdlg, uMessage, wparam, lparam);
00092 }
00093
00094
00095 //
00096 //  FUNCTION: MsgConnectDlgInit(HWND, UINT, WPARAM, LPARAM)
00097 //
00098 //  PURPOSE: To initialize the authdlg box
00099 //
00100 //  PARAMETERS:
00101 //    hwnd - The window handing the message.
00102 //    uMessage - The message number. WM_INITDIALOG.
00103 //    wparam - Message specific data (unused).
00104 //    lparam - Message specific data (unused).
00105 //
00106 //  RETURN VALUE:
00107 //    Always returns TRUE - message handled.
00108 //
00109 //  COMMENTS:
00110 //    Registers window message for RAS event.
00111 //    Makes call to RasDial with appropriate params.
00112 //
00113
00114 LRESULT MsgConnectDlgInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00115 {
00116     // Set text limits on edit controls
00117     SendDlgItemMessage(hdlg, IDE_SERVERNAME, EM_LIMITTEXT, (WPARAM) MAX_COMPUTERNAME_LENGTH+2, 0L );
00118
00119     // Center the dialog over the application window
00120     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
00121
00122     return TRUE;
00123 }
00124
00125
00126 //
00127 //  FUNCTION: MsgConnectDlgCommand(HWND, UINT, WPARAM, LPARAM)
00128 //
00129 //  PURPOSE: Process WM_COMMAND message sent to the authdlg box.
00130 //
00131 //  PARAMETERS:
00132 //    hwnd - The window handing the message.
00133 //    uMessage - The message number. WM_COMMAND
00134 //    wparam - Message specific data (unused).
00135 //    lparam - Message specific data (unused).
00136 //
00137 //  RETURN VALUE:
00138 //    Always returns TRUE - message handled.
00139 //
00140 //  COMMENTS:
00141 //    Uses this DispCommand function defined in wndproc.c combined
00142 //    with the cmdiConnectDlg structure defined in this file to handle
00143 //    the command messages for the authdlg dialog box.
00144 //
00145
00146 LRESULT MsgConnectDlgCommand(HWND   hwnd,
00147                         UINT   uMessage,
00148                         WPARAM wparam,
00149                         LPARAM lparam)
00150 {
00151     return DispCommand(&cmdiConnectDlg, hwnd, wparam, lparam);
00152 }
00153
00154 //
00155 //  FUNCTION: CmdConnectDlgOK(HWND, WORD, WORD,  HWND)
00156 //
00157 //  PURPOSE: Get the server name and free the dialog box.
00158 //
00159 //  PARAMETERS:
00160 //    hwnd - The window handling the command.
00161 //    wCommand - The command to be handle. IDOK.
00162 //    wNotify - The notification to be handled (unused).
00163 //    hwndCtrl - NULL (unused).
00164 //
00165 //  RETURN VALUE:
00166 //    Always returns TRUE.
00167 //
00168 //  COMMENTS:
00169 //    Calls EndDialog to finish the dialog session.
00170 //
00171
00172 LRESULT CmdConnectDlgOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00173 {
00174     char szServer[MAX_COMPUTERNAME_LENGTH+5] = "\\\\";
00175     LPSTR psz = (LPSTR)szServer+ 2L;
00176
00177     GetDlgItemText( hdlg, IDE_SERVERNAME, psz, MAX_COMPUTERNAME_LENGTH+3 );
00178
00179     if ( *psz == '\0' ) // no server name, so same as cancelled
00180     {
00181         EndDialog(hdlg, FALSE);
00182     }
00183     else
00184     {
00185         if ( *psz != '\\' ) // if the name does not begin with a '\', we make
00186         {                   // it begin with '\\' by ajusting the pointer
00187             psz = (LPSTR) szServer;
00188             psz[MAX_COMPUTERNAME_LENGTH+2] = '\0';
00189         }
00190
00191         lstrcpy( (LPSTR)g_szServer, psz );
00192         EndDialog(hdlg, TRUE);
00193     }
00194     return TRUE;
00195
00196 }
00197
00198 //
00199 //  FUNCTION: CmdConnectDlgCancel(HWND, WORD, WORD,  HWND)
00200 //
00201 //  PURPOSE: Free the dialog box.
00202 //
00203 //  PARAMETERS:
00204 //    hwnd - The window handling the command.
00205 //    wCommand - The command to be handled. IDCANCEL.
00206 //    wNotify - The notification to be handled (unused).
00207 //    hwndCtrl - NULL (unused).
00208 //
00209 //  RETURN VALUE:
00210 //    Always returns TRUE.
00211 //
00212 //  COMMENTS:
00213 //    Calls EndDialog to finish the dialog session.
00214 //
00215
00216 LRESULT CmdConnectDlgCancel(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00217 {
00218     EndDialog(hdlg, FALSE);          // Exit the dialog
00219     return TRUE;
00220 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFP.C Source File

  • BNDBUF

BNDBUFP.C

Go to the documentation of this file.
00001 /**********************************************************************
00002 *
00003 *   bndbufp.c - Contains the exported RPC interfaces for inserting and
00004 *   removing strings from the central buffer pool.
00005 *
00006 *   Frederick Chong
00007 *   Microsoft Developer Support
00008 *   Copyright (c) 1992-1996 Microsoft Corporation
00009 *
00010 ***********************************************************************/
00011
00012
00013 #include <windows.h>
00014 #include <stdio.h>
00015 #include <string.h>
00016 #include <stdlib.h>
00017 #include <rpc.h>
00018 #include "common.h"
00019 #include "bndbuf.h"
00020
00021
00022 // Functions prototype
00023
00024 void enter_item(char *input);
00025 void remove_item(char *output);
00026
00027
00028 // external variables
00029
00030 extern char buffer[MAX_ITEM][MAX_SIZE];     // Global buffer pool
00031 extern HANDLE hMutex;         // Handle to mutex
00032 extern HANDLE hEmptySem;        // Handle to empty semaphore
00033 extern HANDLE hFullSem;         // Handle to full semaphore
00034 extern int pro_buf_pos;         // Producer buffer position
00035 extern int con_buf_pos;         // Consumer buffer position
00036
00037
00038 /*************************************************************************
00039
00040 void insert_buffer(unsigned char *item)
00041
00042 Synchronizes access to the central buffer pool for inserting a string.
00043
00044 **************************************************************************/
00045
00046 void insert_buffer(unsigned char *item)
00047 {
00048
00049     WaitForSingleObject(hEmptySem, INFINITE);     // Decrease empty count
00050     WaitForSingleObject(hMutex, INFINITE);      // Acquire Mutex
00051     enter_item(item);           // Put item in buffer
00052     ReleaseMutex(hMutex);         // Release Mutex
00053     ReleaseSemaphore(hFullSem, 1, NULL);      // Increment full count
00054
00055 }
00056
00057
00058
00059 /*************************************************************************
00060
00061 void remove_buffer(unsigned char *item)
00062
00063 Synchronizes access to the the central buffer pool for removing a string.
00064
00065 **************************************************************************/
00066
00067 void remove_buffer(unsigned char *item)
00068 {
00069
00070     WaitForSingleObject(hFullSem, INFINITE);      // Decrease full count
00071     WaitForSingleObject(hMutex, INFINITE);      // Acquire Mutex
00072     remove_item(item);            // Take item from buffer
00073     ReleaseMutex(hMutex);         // Release Mutex
00074     ReleaseSemaphore(hEmptySem, 1, NULL);     // Increment full count
00075
00076 }
00077
00078
00079
00080 /*************************************************************************
00081
00082 void enter_item(char *input)
00083
00084 Puts a string in the centralized buffer pool
00085
00086 We maintain two buffer pointers separately for the producer
00087 and the consumer so that they can keep track of where they
00088 are in the buffer queue.
00089
00090     -----------------------------
00091 Producer -->  |   | |   ...     | |   | --> Consumer
00092     |   | |     | |   |
00093     -----------------------------
00094       ^     ^
00095       |     |
00096          current      current
00097          producer     consumer
00098          pointer      pointer
00099
00100 **************************************************************************/
00101
00102
00103 void enter_item(char *input)
00104 {
00105
00106     strncpy(buffer[pro_buf_pos], input, MAX_SIZE);
00107     printf("\nproduce    ---> %s", buffer[pro_buf_pos]);
00108     pro_buf_pos = ((++pro_buf_pos) % MAX_ITEM);
00109 }
00110
00111
00112 /*************************************************************************
00113
00114 void remove_item(char *output)
00115
00116 Removes a string from the centralized buffer pool.
00117
00118 **************************************************************************/
00119
00120 void remove_item(char *output)
00121 {
00122
00123     strncpy(output, buffer[con_buf_pos], 20);
00124     printf("\nconsume    ---> %s", output);
00125     con_buf_pos = ((++con_buf_pos) % MAX_ITEM);
00126
00127 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MEM.C Source File

  • NETDDE

MEM.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   mem.c
00009 //
00010 //  PURPOSE:  Contains memory management routines
00011 //
00012 //  FUNCTIONS:
00013 //    MallocMem - allocates memory
00014 //    ReallocMem - reallocates memory
00015 //    FreeMem - frees memory
00016 //
00017 //  AUTHOR: Craig Link - Microsoft Developer Support
00018 //
00019
00020 #include <windows.h>
00021 #include <windowsx.h>
00022 #include <stdlib.h>
00023 #include <malloc.h>
00024 #include "mem.h"
00025
00026 #ifdef _DEBUG
00027 DWORD dwAlloc = 0;
00028 #endif
00029
00030 //
00031 //  FUNCTION: MallocMem( LPVOID *lplpv, DWORD dwSize )
00032 //
00033 //  PURPOSE:  Dynamically allocates memory
00034 //
00035 //  PARAMETERS:
00036 //    lplpv - address of pointer to newly allocated memory
00037 //    dwSize - number of bytes to allocate
00038 //
00039 //  RETURN VALUE:
00040 //    ERROR_SUCCESS
00041 //    ERROR_NOT_ENOUGH_MEMORY
00042 //
00043 //
00044 DWORD MallocMem( LPVOID *lplpv, DWORD dwSize )
00045 {
00046     LPVOID lpTemp;
00047
00048     if ( NULL == ( lpTemp = _fmalloc( (size_t)dwSize ) ) )
00049         return ERROR_NOT_ENOUGH_MEMORY;
00050
00051     *lplpv = lpTemp;
00052
00053 #ifdef _DEBUG
00054 #ifdef WIN16
00055     dwAlloc++;
00056 #else
00057     InterlockedIncrement(&dwAlloc);
00058 #endif
00059 #endif
00060
00061     return ERROR_SUCCESS;
00062
00063 }
00064
00065
00066 //
00067 //  FUNCTION: ReallocMem( LPVOID *lplpv, DWORD dwSize )
00068 //
00069 //  PURPOSE:  Dynamically reallocates memory
00070 //
00071 //  PARAMETERS:
00072 //    lplpv - address of pointer to newly reallocated memory
00073 //    dwSize - number of bytes to allocate
00074 //
00075 //  RETURN VALUE:
00076 //    ERROR_SUCCESS
00077 //    ERROR_NOT_ENOUGH_MEMORY
00078 //
00079 //
00080 DWORD ReallocMem( LPVOID *lplpv, DWORD dwSize )
00081 {
00082     LPVOID lpTemp;
00083
00084     if ( NULL == ( lpTemp = _frealloc( *lplpv, (size_t)dwSize ) ) )
00085         return ERROR_NOT_ENOUGH_MEMORY;
00086
00087 #ifdef _DEBUG
00088     if ( dwSize == 0 )
00089 #ifdef WIN16
00090         dwAlloc--;
00091 #else
00092         InterlockedDecrement(&dwAlloc);
00093 #endif
00094     else if ( *lplpv == NULL )
00095 #ifdef WIN16
00096         dwAlloc++;
00097 #else
00098         InterlockedIncrement(&dwAlloc);
00099 #endif
00100 #endif
00101
00102     *lplpv = lpTemp;
00103
00104     return ERROR_SUCCESS;
00105 }
00106
00107 //
00108 //  FUNCTION: FreeMem( LPVOID *lplpv )
00109 //
00110 //  PURPOSE:  Frees dynamically allocated memory
00111 //
00112 //  PARAMETERS:
00113 //    lplpv - address of pointer to newly allocated memory
00114 //            Set to NULL on return
00115 //
00116 //  RETURN VALUE:
00117 //    none
00118 //
00119 VOID FreeMem( LPVOID *lplpv )
00120 {
00121     _ffree( *lplpv );
00122     *lplpv = NULL;
00123 #ifdef _DEBUG
00124 #ifdef WIN16
00125     dwAlloc--;
00126 #else
00127     InterlockedDecrement(&dwAlloc);
00128 #endif
00129 #endif
00130
00131 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CONSOLEC/COLOR.C Source File

  • CONSOLEC

COLOR.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /************************************************************************\
00013 *
00014 * PROGRAM   : COLOR.C
00015 *
00016 * PURPOSE   : To demonstrate the use of the SetConsoleTextAttribute()
00017 *             and GetConsoleScreenBufferInfo() APIs to set the console
00018 *             text color attributes.
00019 *
00020 * FUNCTIONS : main()                     - Open the console, parse args,
00021 *                                          and change console colors
00022 *             Syntax()                   - Display the command syntax
00023 *                                          and color table if no args.
00024 *             GetConsoleTextAttribute()  - Get the previous console
00025 *                                          color attributes
00026 *
00027 * COMMENTS  : The open handle to the console is obtained by specifying
00028 *             CONOUT$ as the file name in the CreateFile() API call.
00029 *             The OPEN_EXISTING create flag is used to get the current
00030 *             console handle.
00031 *
00032 \************************************************************************/
00033
00034 #include <Windows.H>
00035 #include <StdIO.H>
00036 #include <StdLib.H>
00037 #include <ConIO.H>
00038 #include <String.H>
00039
00040 #include "Color.H"
00041
00042
00043 /************************************************************************\
00044 *
00045 * FUNCTION    : main
00046 *
00047 * INPUTS      : __argc - argument count
00048 *               __argv - array of argument strings
00049 *
00050 * RETURNS     : 0 on success or -1 on failure.
00051 *
00052 * GLOBAL VARS : Color - array of text color attributes
00053 *
00054 * LOCAL VARS  : ForeColor  - foreground text color
00055 *               BackColor  - background text color
00056 *               ColorIndex - index in the Color array
00057 *               StrLen     - length of a command line argument string
00058 *               hConsole   - handle to the console
00059 *               ForeGround - string buffer containing the first argument
00060 *               BackGround - string buffer containing the second argument
00061 *
00062 * COMMENTS    :
00063 *
00064 \************************************************************************/
00065 int
00066 main( int __argc, char** __argv )
00067 {
00068   WORD          ForeColor;
00069   WORD          BackColor;
00070   int           ColorIndex;
00071   size_t        StrLen;
00072   HANDLE        hConsole;
00073   char          ForeGround[8];
00074   char          BackGround[8];
00075   BOOL          WIN95 = FALSE;
00076   OSVERSIONINFO os;
00077
00078   PrintBanner();
00079
00080   // check if Win32s, if so, display notice and terminate
00081   os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00082
00083   if( GetVersionEx(&os) )
00084   {
00085     if ( os.dwPlatformId != VER_PLATFORM_WIN32_NT)
00086     {
00087         if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
00088         {
00089             WIN95 = TRUE;
00090             printf("\n\nChanges to the text attibutes are not persistant in Windows 95.");
00091         }
00092         else
00093         {
00094             MessageBoxA( NULL,
00095               "This application cannot run on Windows 3.1.\n"
00096               "This application will now terminate.",
00097               "Color",
00098               MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00099               return( 1 );
00100         }
00101     }
00102   }
00103   else
00104       return( 1 );
00105
00106
00107   /**********************************************************************\
00108    * Open the current console input buffer
00109   \**********************************************************************/
00110   if( ( hConsole = CreateFile(
00111                      "CONOUT$", GENERIC_WRITE | GENERIC_READ,
00112                      FILE_SHARE_READ | FILE_SHARE_WRITE,
00113                      0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L) )
00114        == INVALID_HANDLE_VALUE ) {
00115     printf("\nError: Unable to open console.\n");
00116     return( -1 );
00117   }
00118
00119   ForeColor = MAXCOLORS;
00120   BackColor = MAXCOLORS;
00121
00122   if( __argc < 2 || WIN95 ) {
00123     Syntax( hConsole );
00124   }
00125   else {
00126
00127       /**********************************************************************\
00128        * Get the first argument; the foreground text color
00129       \**********************************************************************/
00130       if( __argc > 1 ) {
00131         sprintf( ForeGround, "%s", __argv[1] );
00132         StrLen = strlen( ForeGround );
00133         for( ColorIndex = 0; ColorIndex < MAXCOLORS; ColorIndex++ ) {
00134           if( strnicmp( ForeGround, Color[ColorIndex], StrLen ) == 0 ) {
00135             ForeColor = (WORD) ColorIndex;
00136             break;
00137           }
00138         }
00139       }
00140       /**********************************************************************\
00141        * Get the second (optional) argument; the background text color
00142       \**********************************************************************/
00143       if( __argc > 2 ) {
00144         sprintf( BackGround, "%s", __argv[2] );
00145         StrLen = strlen( BackGround );
00146         for( ColorIndex = 0; ColorIndex < MAXCOLORS; ColorIndex++ ) {
00147           if( strnicmp( BackGround, Color[ColorIndex], StrLen ) == 0 ) {
00148             BackColor = (WORD) ColorIndex;
00149             break;
00150           }
00151         }
00152       }
00153       else
00154         BackColor = (WORD) (( GetConsoleTextAttribute(hConsole) & BACKGROUND_COLOR ) >> 4);
00155
00156       /**********************************************************************\
00157        * Check if foreground and backgroud colors are the same; issue a error
00158        * and exit if they are
00159       \**********************************************************************/
00160       if( BackColor == MAXCOLORS || ForeColor == MAXCOLORS || BackColor == ForeColor) {
00161         printf("\n\nError: %s", BackColor == ForeColor ?
00162             "Foreground and background color cannot be the same." :
00163             "Invalid color specified.");
00164
00165         Syntax( hConsole );
00166       }
00167       else
00168         /**********************************************************************\
00169          * Set the new console text colors
00170         \**********************************************************************/
00171         SetConsoleTextAttribute( hConsole, (WORD) (ForeColor | (BackColor << 4) ) );
00172
00173   }
00174
00175   CloseHandle(hConsole);
00176   return( 0 );
00177 }
00178
00179
00180 /************************************************************************\
00181 *
00182 * FUNCTION    : Syntax
00183 *
00184 * INPUTS      : hConsole - handle to an open console
00185 *
00186 * RETURNS     : 0 and exits the process.
00187 *
00188 * GLOBAL VARS : Color - array of text color attributes
00189 *
00190 * LOCAL VARS  : ForeColor      - foreground text color
00191 *               BackColor      - background text color
00192 *               wAttributesOld - previous text attributes
00193 *
00194 * COMMENTS    : Displays the command syntax, a text color table and
00195 *               exits the process at completion.
00196 *
00197 \************************************************************************/
00198 BOOL
00199 Syntax( HANDLE hConsole )
00200 {
00201   WORD ForeColor;
00202   WORD BackColor;
00203   WORD wAttributesOld;
00204
00205   printf("\n\nSyntax: COLOR FOREGROUND [BACKGROUND]");
00206   printf("\n\nAvailable colors are:");
00207   printf("\n");
00208
00209   wAttributesOld = GetConsoleTextAttribute( hConsole );
00210
00211   printf("%36s BACKGROUND\n", " ");
00212   printf("FOREGROUND  ");
00213   for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
00214     printf("%-8s", Color[BackColor] );
00215   }
00216   printf("\n");
00217
00218   for( ForeColor = 0; ForeColor < MAXCOLORS; ForeColor++ ) {
00219     printf( "%-10s ",  Color[ForeColor] );
00220
00221     for( BackColor = 0; BackColor < MAXCOLORS; BackColor++ ) {
00222       SetConsoleTextAttribute( hConsole, (WORD) ( (BackColor << 4) | ForeColor) );
00223       printf(" XxXxXx ");
00224     }
00225     SetConsoleTextAttribute( hConsole, wAttributesOld );
00226     printf("\n");
00227   }
00228
00229   SetConsoleTextAttribute( hConsole, wAttributesOld );
00230
00231   return( TRUE );
00232 }
00233
00234
00235 /************************************************************************\
00236 *
00237 * FUNCTION    : GetConsoleTextAttribute
00238 *
00239 * INPUTS      : hConsole - handle to an open console
00240 *
00241 * RETURNS     : Current text attributes WORD.
00242 *
00243 * GLOBAL VARS : None.
00244 *
00245 * LOCAL VARS  : csbi - Console screen buffer information structure
00246 *
00247 * COMMENTS    : Gets the previous console color attributes
00248 *
00249 \************************************************************************/
00250 WORD
00251 GetConsoleTextAttribute( HANDLE hConsole )
00252 {
00253   CONSOLE_SCREEN_BUFFER_INFO csbi;
00254
00255   GetConsoleScreenBufferInfo( hConsole, &csbi );
00256   return( csbi.wAttributes );
00257 }
00258
00259
00260
00261 /************************************************************************\
00262 *
00263 * FUNCTION    : Syntax
00264 *
00265 * INPUTS      : none
00266 *
00267 * RETURNS     : none.
00268 *
00269 * COMMENTS    : Displays program banner.
00270 *
00271 \************************************************************************/
00272 void PrintBanner()
00273 {
00274   printf("Console Window Text Color Setter, Version 1.10");
00275   printf("\nMicrosoft Developer Support");
00276   printf("\nCopyright (c) 1992-1996 Microsoft Corp.");
00277 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OWNCOMBO/OWNCOMBO.H Source File

  • OWNCOMBO

OWNCOMBO.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* Defines for menu items */
00013 #define IDM_EXIT    201
00014 #define IDM_ABOUT   202
00015
00016 #define IDM_LISTBOX       300
00017 #define IDM_MULTILISTBOX  301
00018 #define IDM_COMBOBOX      302
00019 #define IDM_OWNERCOMBOBOX 303
00020
00021 #define IDM_HELP          400
00022
00023 /* Defines for dialog box ownerdraw controls. */
00024 #define ID_LISTBOX  1000
00025 #define ID_BLACK    1003
00026 #define ID_WHITE    1004
00027 #define ID_RED      1005
00028 #define ID_BLUE     1006
00029 #define ID_GREEN    1007
00030
00031 /* Defines for combo box example */
00032 #define ID_COMBOBOX     1000
00033 #define ID_SINGLEEDIT   1001
00034 #define ID_TEXT1        1002
00035 #define ID_TEXT2        1003
00036 #define ID_STEPSBOX     1004
00037 #define ID_UNSLBUTTON   1005
00038 #define ID_NUMSELBUTTON 1006
00039 #define ID_TXTSELBUTTON 1007
00040 #define ID_FNDSELBUTTON 1008
00041 #define ID_CLRBUTTON    1009
00042 #define ID_ADDBUTTON    1010
00043 #define ID_DELETEBUTTON 1011
00044 #define ID_CPYBUTTON    1012
00045 #define ID_CBDIRBUTTON  1013
00046
00047 LONG FAR  PASCAL OwnComboWndProc(HWND, UINT, UINT, LONG);
00048 BOOL NEAR PASCAL OwnComboInit(HANDLE);
00049 BOOL FAR  PASCAL About(HWND, UINT, UINT, LONG);
00050 BOOL FAR  PASCAL ListBoxExample(HWND, UINT, UINT, LONG);
00051 BOOL FAR  PASCAL ComboBoxExample(HWND, UINT, UINT, LONG);
00052 BOOL FAR  PASCAL OwnerComboBoxExample(HWND, UINT, UINT, LONG);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLTHREAD.C Source File

  • GLTHREAD

GLTHREAD.C

Go to the documentation of this file.
00001 //****************************************************************************
00002 // File: glthread.c
00003 //
00004 // Purpose: Contains main message loop and application entry point.  Also
00005 //      contains the code to handle palettes properly in an OpenGL
00006 //          application and the main window callback procedure.
00007 //
00008 // Functions:
00009 //    WinMain        - initializes everything and enters message loop
00010 //    InitializeWindow - Initializes the window class of and creates the main
00011 //             window
00012 //    MainWndProc      - Main window procedure
00013 //    CommandHandler   - Handle all WM_COMMAND messages
00014 //
00015 // Development Team:
00016 //         Greg Binkerd - Windows Developer Support
00017 //
00018 // Written by Microsoft Windows Developer Support
00019 // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
00020 //****************************************************************************
00021
00022 #include "glthread.h"
00023
00024 CHAR szAppName[]="GLThreads";
00025
00026 HGLRC hRC;
00027
00028 HWND ghWnd;
00029
00030 extern HPALETTE ghpalOld, ghPalette;
00031
00032 /* forward declarations of helper functions in this module */
00033 HWND   WINAPI InitializeWindow (HINSTANCE, int);
00034 LONG   WINAPI CommandHandler (HWND, WPARAM, LPARAM);
00035 LONG   WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
00036
00037
00038 //***********************************************************************
00039 // Function: WinMain
00040 //
00041 // Purpose: Called by Windows on app startup.  Initializes everything,
00042 //          and enters a message loop.
00043 //
00044 // Parameters:
00045 //    hInstance     == Handle to _this_ instance.
00046 //    hPrevInstance == Handle to last instance of app.
00047 //    lpCmdLine     == Command Line passed into app.
00048 //    nCmdShow      == How app should come up (i.e. minimized/normal)
00049 //
00050 // Returns: Return value from PostQuitMessage.
00051 //
00052 // Comments:
00053 //
00054 // History:  Date       Author        Reason
00055 //           6/08/94                  Created
00056 //****************************************************************************
00057
00058 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00059           LPSTR lpCmdLine, int nCmdShow)
00060 {
00061     MSG        msg;
00062     HWND       hWnd;
00063
00064     /* previous instances do not exist in Win32 */
00065     if (hPrevInstance)
00066         return 0;
00067
00068     if (!(hWnd = InitializeWindow (hInstance, nCmdShow)))
00069         return FALSE;
00070
00071     /* main window message loop */
00072     while (GetMessage (&msg, NULL, 0, 0))
00073     {
00074         TranslateMessage (&msg);
00075         DispatchMessage (&msg);
00076     }
00077
00078     /* return success of application */
00079     return TRUE;
00080 }
00081
00082
00083 //****************************************************************************
00084 // Function: InitializeWindow
00085 //
00086 // Purpose: Called by WinMain on first instance of app.  Registers
00087 //          the window class.
00088 //
00089 // Parameters:
00090 //    hInstance == Handle to _this_ instance.
00091 //    nCmdShow  == Initial state of window
00092 //
00093 // Returns: Handle to newly created window if successful
00094 //
00095 // Comments:
00096 //
00097 // History:  Date       Author        Reason
00098 //           3/15/95                  Created
00099 //****************************************************************************
00100
00101 HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow)
00102     {
00103     WNDCLASS   wc;
00104     HWND       hWnd;
00105
00106     /* Register the frame class */
00107     wc.style         = 0;
00108     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00109     wc.cbClsExtra    = 0;
00110     wc.cbWndExtra    = 0;
00111     wc.hInstance     = hInstance;
00112     wc.hIcon         = LoadIcon (hInstance, szAppName);
00113     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
00114     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
00115     wc.lpszMenuName  = szAppName;
00116     wc.lpszClassName = szAppName;
00117
00118     if (!RegisterClass (&wc) )
00119         return FALSE;
00120
00121     /* Create the frame */
00122     ghWnd = hWnd = CreateWindow (szAppName,
00123       "Generic OpenGL Sample",
00124       WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
00125       CW_USEDEFAULT,
00126       CW_USEDEFAULT,
00127       CW_USEDEFAULT,
00128       CW_USEDEFAULT,
00129       NULL,
00130       NULL,
00131       hInstance,
00132       NULL);
00133
00134     /* make sure window was created */
00135     if (!hWnd)
00136         return FALSE;
00137
00138     /* show and update main window */
00139     ShowWindow (hWnd, nCmdShow);
00140
00141     UpdateWindow (hWnd);
00142
00143     return hWnd;
00144 }
00145
00146
00147 //****************************************************************************
00148 // Function: MainWndProc
00149 //
00150 // Purpose: Message handler for main overlapped window.
00151 //
00152 // Parameters:
00153 //    hWnd    == Handle to this window.
00154 //    uMsg    == Message to process.
00155 //    wParam  == WORD parameter -- depends on message
00156 //    lParam  == LONG parameter -- depends on message
00157 //
00158 // Returns: Depends on message.
00159 //
00160 // Comments:
00161 //
00162 // History:  Date       Author        Reason
00163 //           3/15/95                  Created
00164 //****************************************************************************
00165
00166 LONG WINAPI MainWndProc (
00167     HWND    hWnd,
00168     UINT    uMsg,
00169     WPARAM  wParam,
00170     LPARAM  lParam)
00171 {
00172     LONG    lRet = 1;
00173
00174     switch (uMsg)
00175     {
00176       case WM_SIZE:
00177           resize(hWnd);
00178             break;
00179
00180         // The WM_QUERYNEWPALETTE message informs a window that it is about to
00181         // receive input focus. In response, the window receiving focus should
00182         // realize its palette as a foreground palette and update its client
00183         // area. If the window realizes its palette, it should return TRUE;
00184         // otherwise, it should return FALSE.
00185
00186         case WM_QUERYNEWPALETTE:
00187         {
00188             HDC     hDC;
00189
00190             if(ghPalette)
00191             {
00192                 hDC = GetDC(hWnd);
00193
00194                 // Select and realize the palette
00195
00196                 ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
00197                 RealizePalette(hDC);
00198
00199                 // Redraw the client area
00200
00201                 InvalidateRect(hWnd, NULL, TRUE);
00202                 UpdateWindow(hWnd);
00203
00204                 if(ghpalOld)
00205                     SelectPalette(hDC, ghpalOld, FALSE);
00206
00207                 ReleaseDC(hWnd, hDC);
00208
00209                 return TRUE;
00210             }
00211
00212             return FALSE;
00213         }
00214
00215         // The WM_PALETTECHANGED message informs all windows that the window
00216         // with input focus has realized its logical palette, thereby changing
00217         // the system palette. This message allows a window without input focus
00218         // that uses a color palette to realize its logical palettes and update
00219         // its client area.
00220         //
00221         // This message is sent to all windows, including the one that changed
00222         // the system palette and caused this message to be sent. The wParam of
00223         // this message contains the handle of the window that caused the system
00224         // palette to change. To avoid an infinite loop, care must be taken to
00225         // check that the wParam of this message does not match the window's
00226         // handle.
00227
00228         case WM_PALETTECHANGED:
00229         {
00230             HDC         hDC;
00231
00232             // Before processing this message, make sure we
00233             // are indeed using a palette
00234
00235             if (ghPalette)
00236             {
00237                 // If this application did not change the palette, select
00238                 // and realize this application's palette
00239
00240                 if (wParam != (WPARAM)hWnd)
00241                 {
00242                     // Need the window's DC for SelectPalette/RealizePalette
00243
00244                     hDC = GetDC(hWnd);
00245
00246                     // Select and realize our palette
00247
00248                     ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
00249                     RealizePalette(hDC);
00250
00251                     // WHen updating the colors for an inactive window,
00252                     // UpdateColors can be called because it is faster than
00253                     // redrawing the client area (even though the results are
00254                     // not as good)
00255
00256                     UpdateColors(hDC);
00257
00258                     // Clean up
00259
00260                     if (ghpalOld)
00261                        SelectPalette(hDC, ghpalOld, FALSE);
00262
00263                     ReleaseDC(hWnd, hDC);
00264                 }
00265             }
00266             break;
00267         }
00268
00269
00270       case WM_COMMAND:
00271             lRet = CommandHandler (hWnd, wParam, lParam);
00272             break;
00273
00274         case WM_CLOSE:
00275             /* call destroy window to cleanup and go away */
00276             DestroyWindow (hWnd);
00277           break;
00278
00279         case WM_DESTROY:
00280             PostQuitMessage (0);
00281           break;
00282
00283       default:
00284             /* pass all unhandled messages to DefWindowProc */
00285             lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
00286           break;
00287     }
00288
00289     /* return 1 if handled message, 0 if not */
00290     return lRet;
00291 }
00292
00293
00294 //****************************************************************************
00295 // Function: CommandHandler
00296 //
00297 // Purpose: Command handler for main overlapped window.
00298 //
00299 // Parameters:
00300 //    hWnd    == Handle to this window.
00301 //    wParam  == WORD parameter -- depends on message
00302 //    lParam  == LONG parameter -- depends on message
00303 //
00304 // Returns: Depends on message.
00305 //
00306 // Comments:
00307 //
00308 // History:  Date       Author        Reason
00309 //           3/15/95                  Created
00310 //****************************************************************************
00311
00312 LONG WINAPI CommandHandler (
00313     HWND    hWnd,
00314     WPARAM  wParam,
00315     LPARAM  lParam)
00316 {
00317     switch (LOWORD(wParam))
00318     {
00319       case IDM_EXIT:
00320             /* exit application */
00321             PostMessage (hWnd, WM_CLOSE, 0, 0L);
00322           break;
00323
00324       case ID_DRAWWAVES:
00325         draw_scene(hWnd);
00326           break;
00327
00328       default:
00329             return FALSE;
00330     }
00331     return TRUE;
00332 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WALK/WALK.H Source File

  • WALK

WALK.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* definitions */
00013
00014 #define BUFSIZE     MAX_PATH
00015
00016 CHAR chPathName[BUFSIZE];
00017
00018 /* procedure definitions */
00019
00020 HANDLE FindFirstDirectory(LPTSTR, LPWIN32_FIND_DATA);
00021 VOID Walk(WORD);
00022 VOID main(int argc, char * argv[]);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MENU/MENU.C Source File

  • MENU

MENU.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /***************************************************************************
00013  *                                                                         *
00014  *  PROGRAM     : Menu.c                                                   *
00015  *                                                                         *
00016  *  PURPOSE     : To give a demonstration of the use of popup menus, user  *
00017  *                defined menus and menu functions.                        *
00018  *                                                                         *
00019  *  FUNCTIONS   : WinMain()           - Calls the initialization function  *
00020  *                                      and enters the message loop.       *
00021  *                                                                         *
00022  *                MenuInit()          - Registers the app. window class.   *
00023  *                                                                         *
00024  *                About()             - Dialog function for the About..    *
00025  *                                      dialog.                            *
00026  *                                                                         *
00027  *                ShrinkBitmap()      - Shrinks a 64x64 bitmap to a size   *
00028  *                                      useable for a user-defined menu    *
00029  *                                      checkmark.                         *
00030  *                                                                         *
00031  *                HandleCreate()      - Creates a new menu and appends it  *
00032  *                                      to the main menu                   *
00033  *                                                                         *
00034  *                HandlePaint()       - Handles repainting the app's client*
00035  *                                      area                               *
00036  *                                                                         *
00037  *                HandleChangeColors()- Changes the state of the "colors"  *
00038  *                                      menu item.                         *
00039  *                                                                         *
00040  *                HandleDrawItem()    - Redraws the menu items in the      *
00041  *                                      "colors" menu                      *
00042  *                                                                         *
00043  *                HandlePopupMenu()   - handles display of the "floating"  *
00044  *                                      popup.                             *
00045  *                                                                         *
00046  *                MenuWndProc()       - Window function for the app.       *
00047  *                                                                         *
00048  *                                                                         *
00049  ***************************************************************************/
00050 #include "windows.h"
00051 #include "menu.h"
00052
00053
00054 HANDLE   hInst;
00055 HMENU    hBigMenu;
00056 HBITMAP  hbmCheckOn;
00057 HBITMAP  hbmCheckOff;
00058
00059 /****************************************************************************
00060  *                                                                          *
00061  *  FUNCTION   : WinMain(HANDLE, HANDLE, LPSTR, int)                        *
00062  *                                                                          *
00063  *  PURPOSE    : Creates the main app. window, calls an initialization      *
00064  *               function and enters the message loop.                      *
00065  *                                                                          *
00066  ****************************************************************************/
00067 int APIENTRY WinMain(
00068     HANDLE hInstance,
00069     HANDLE hPrevInstance,
00070     LPSTR lpCmdLine,
00071     int nCmdShow
00072     )
00073 {
00074
00075     HWND  hWnd;
00076     MSG msg;                                 /* message                      */
00077
00078     UNREFERENCED_PARAMETER( lpCmdLine );
00079
00080     /* Register main window class if this is the first instance of the app. */
00081     if (!hPrevInstance)
00082         if (!MenuInit (hInstance))
00083             return 0;
00084
00085     hInst = hInstance;
00086
00087     /* Create the app. window */
00088     hWnd = CreateWindow ("menu",
00089                          "Menu Example",
00090                          WS_OVERLAPPEDWINDOW,
00091                          CW_USEDEFAULT,
00092                          CW_USEDEFAULT,
00093                          CW_USEDEFAULT,
00094                          CW_USEDEFAULT,
00095                          (HWND) NULL,
00096                          NULL,
00097                          hInstance,
00098                          (LPSTR) NULL);
00099
00100     if (!hWnd)
00101         return 0;
00102
00103     ShowWindow (hWnd, nCmdShow);
00104     UpdateWindow (hWnd);
00105
00106     while (GetMessage (&msg, NULL, 0, 0)){
00107         /* Since we have no accelerators, no need to call
00108          * TranslateAccelerator here.
00109          */
00110         TranslateMessage (&msg);
00111         DispatchMessage (&msg);
00112     }
00113     return(msg.wParam);
00114 }
00115
00116
00117 /****************************************************************************
00118  *                                                                          *
00119  *  FUNCTION   : MenuInit (hInstance)                                       *
00120  *                                                                          *
00121  *  PURPOSE    : Registers the main window class.                           *
00122  *                                                                          *
00123  *  RETURNS    : TRUE   -  if RegisterClass() went off ok                   *
00124  *               FALSE  -  otherwise.                                       *
00125  *                                                                          *
00126  ****************************************************************************/
00127 BOOL NEAR PASCAL MenuInit (HANDLE hInstance)
00128 {
00129     HANDLE    hMemory;
00130     PWNDCLASS pWndClass;
00131     BOOL      bSuccess;
00132
00133     /* Initialize the menu window class */
00134     hMemory   = LocalAlloc(LPTR, sizeof(WNDCLASS));
00135     if(!hMemory){
00136         MessageBox(NULL, "<MenuInit> Not enough memory.", NULL, MB_OK | MB_ICONHAND);
00137         return(FALSE);
00138     }
00139
00140     pWndClass = (PWNDCLASS) LocalLock(hMemory);
00141
00142     pWndClass->style         = 0;
00143     pWndClass->lpfnWndProc   = (WNDPROC) MenuWndProc;
00144     pWndClass->hInstance     = hInstance;
00145     pWndClass->hIcon         = LoadIcon (hInstance, "menu");
00146     pWndClass->hCursor       = LoadCursor (NULL, IDC_ARROW);
00147     pWndClass->hbrBackground = GetStockObject (WHITE_BRUSH);
00148     pWndClass->lpszMenuName  = (LPSTR) "MenuMenu",
00149     pWndClass->lpszClassName = (LPSTR) "menu";
00150
00151     bSuccess = RegisterClass (pWndClass);
00152     LocalUnlock (hMemory);
00153     LocalFree (hMemory);
00154
00155     return bSuccess;
00156 }
00157
00158
00159 /****************************************************************************
00160  *                                                                          *
00161  *  FUNCTION   : About (hDlg, message, wParam, lParam)                      *
00162  *                                                                          *
00163  *  PURPOSE    : Dialog function for the About menu... dialog.              *
00164  *                                                                          *
00165  ****************************************************************************/
00166 BOOL APIENTRY About(
00167         HWND hDlg,
00168         UINT message,
00169         UINT wParam,
00170         LONG lParam)
00171
00172 {
00173     switch (message){
00174         case WM_INITDIALOG:
00175             return(TRUE);
00176
00177         case WM_COMMAND:
00178             // LOWORD added for portability
00179             if (LOWORD(wParam) == IDOK){
00180                 EndDialog(hDlg,0);
00181                 return(TRUE);
00182             }
00183             break;
00184     }
00185     return(FALSE);
00186         UNREFERENCED_PARAMETER(lParam);
00187 }
00188
00189
00190 /****************************************************************************
00191  *                                                                          *
00192  *  FUNCTION   : ShrinkBitmap(hwnd, hbm)                                    *
00193  *                                                                          *
00194  *  PURPOSE    : This function shrinks a 64x64 bitmap into a bitmap useable *
00195  *               for the user-defined checkmark for menu items. This can be *
00196  *               easily generalized to shrink bitmaps of any size.          *
00197  *                                                                          *
00198  *  RETURNS    : HBITMAP - A handle to the new bitmap.                      *
00199  *                                                                          *
00200  ****************************************************************************/
00201 HBITMAP APIENTRY ShrinkBitmap (
00202         HWND hwnd,
00203         HBITMAP hbm)
00204 {
00205     HDC     hdc;
00206     HDC     hmemorydcNew;
00207     HDC     hmemorydcOld;
00208     LONG    checkMarkSize;
00209     HBITMAP hCheckBitmap;
00210     HBITMAP hOldBitmapSave;
00211     HBITMAP hNewBitmapSave;
00212
00213     hdc = GetDC (hwnd);
00214
00215     /* Create DCs for the source (old) and target (new) bitmaps */
00216     hmemorydcNew = CreateCompatibleDC (hdc);
00217     hmemorydcOld = CreateCompatibleDC (hdc);
00218
00219     /* Determine the dimensions of the default menu checkmark and
00220      * create a target bitmap of the same dimensions
00221      */
00222     checkMarkSize = GetMenuCheckMarkDimensions ();
00223     hCheckBitmap  = CreateCompatibleBitmap (hdc,
00224                                             LOWORD (checkMarkSize),
00225                                             HIWORD (checkMarkSize));
00226
00227     /* Select the source bitmap and the target bitmap into their
00228      * respective DCs.
00229      */
00230     hOldBitmapSave = SelectObject (hmemorydcNew, hCheckBitmap);
00231     hNewBitmapSave = SelectObject (hmemorydcOld, hbm);
00232
00233     /* Shrink the source bitmap into the target DC */
00234     StretchBlt (hmemorydcNew,
00235                 0,
00236                 0,
00237                 LOWORD(checkMarkSize),
00238                 HIWORD(checkMarkSize),
00239                 hmemorydcOld,
00240                 0,
00241                 0,
00242                 64,
00243                 64,
00244                 SRCCOPY);
00245
00246     /* De-select the bitmaps and clean up .. */
00247     SelectObject (hmemorydcNew, hOldBitmapSave);
00248     SelectObject (hmemorydcOld, hNewBitmapSave);
00249     DeleteDC (hmemorydcNew);
00250     DeleteDC (hmemorydcOld);
00251     ReleaseDC (hwnd, hdc);
00252
00253     /* .. and return a handle to the target bitmap */
00254     return hCheckBitmap;
00255 }
00256
00257
00258 /****************************************************************************
00259  *                                                                          *
00260  *  FUNCTION   : HandleCreate ( hwnd )                                      *
00261  *                                                                          *
00262  *  PURPOSE    : Creates a new (empty) menu and appends to it the "State"   *
00263  *               menu items. It sets up the user-defined checkmarks for the *
00264  *               menu. It then inserts this menu into the main menu bar.    *
00265  *                                                                          *
00266  ****************************************************************************/
00267 VOID APIENTRY HandleCreate (HWND hwnd)
00268 {
00269     HMENU   hMenu;
00270     HMENU   hWndMenu;
00271
00272     /* Create a new menu into the menubar on the fly */
00273     hMenu = CreateMenu ();
00274     if (!hMenu)
00275         return;
00276
00277     /* Append the state menu items to it */
00278     AppendMenu (hMenu, MF_STRING, IDM_STATE1, "South Dakota");
00279     AppendMenu (hMenu, MF_STRING, IDM_STATE2, "Washington");
00280     AppendMenu (hMenu, MF_STRING, IDM_STATE3, "California");
00281     if (!AppendMenu (hMenu, MF_STRING, IDM_STATE4, "Oregon")){
00282         /* It is unlikely the other appends will fail and this will succeed.
00283          * So just check this one. And if it fails, Destroy the menu for
00284          * good measure and return.
00285          */
00286         DestroyMenu(hMenu);
00287         return;
00288     }
00289     hbmCheckOn  = ShrinkBitmap (hwnd, LoadBitmap (hInst, "checkon"));
00290     hbmCheckOff = ShrinkBitmap (hwnd, LoadBitmap (hInst, "checkoff"));
00291
00292     /* Set up the user-defined check marks */
00293     SetMenuItemBitmaps (hMenu, 0, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
00294     SetMenuItemBitmaps (hMenu, 1, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
00295     SetMenuItemBitmaps (hMenu, 2, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
00296     SetMenuItemBitmaps (hMenu, 3, MF_BYPOSITION, hbmCheckOff, hbmCheckOn);
00297
00298     /* Now insert the menu into the main menu bar. */
00299     hWndMenu = GetMenu (hwnd);
00300     InsertMenu (hWndMenu, 2, MF_POPUP|MF_BYPOSITION, (DWORD)hMenu, "States");
00301
00302     return;
00303 }
00304
00305 /****************************************************************************
00306  *                                                                          *
00307  *  FUNCTION   : HandlePaint ( hwnd )                                       *
00308  *                                                                          *
00309  *  PURPOSE    : Handles the repainting of the main app's client area.      *
00310  *                                                                          *
00311  ****************************************************************************/
00312 VOID APIENTRY HandlePaint (HWND hwnd)
00313 {
00314     HDC         hdc;
00315     PAINTSTRUCT ps;
00316     RECT        rc;
00317
00318     hdc = BeginPaint (hwnd, (LPPAINTSTRUCT)&ps);
00319
00320     /* Center the text in the client area */
00321     GetClientRect (hwnd, (LPRECT)&rc);
00322     DrawText (hdc,
00323               "Down click in the window for a popup menu",
00324                41,
00325                (LPRECT)&rc,
00326                DT_CENTER | DT_WORDBREAK);
00327     EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
00328 }
00329
00330
00331 /****************************************************************************
00332  *                                                                          *
00333  *  FUNCTION   : HandleChangeColors (hwnd)                                  *
00334  *                                                                          *
00335  *  PURPOSE    : Toggles the state of the Owner Draw item in the Colors     *
00336  *               menu. If it is on, the "Black", "Blue", "Red", and "Green" *
00337  *               individual menu text items are modified so that they will  *
00338  *               contain bands of color. Otherwise, the colors are replaced *
00339  *               by the text.                                               *
00340  *                                                                          *
00341  ****************************************************************************/
00342 VOID APIENTRY HandleChangeColors(HWND hwnd)
00343 {
00344     HMENU hMenu;
00345     BOOL  fOwnerDraw;
00346
00347     /* Get a handle to the Colors menu. This is at position 1. */
00348     hMenu = GetSubMenu (GetMenu (hwnd), IDCOLORS_POS);
00349
00350     /* Get the current state of the item */
00351     fOwnerDraw = GetMenuState ( hMenu,
00352                                 IDM_COLOROWNERDR, MF_BYCOMMAND) & MF_CHECKED;
00353
00354     /* Toggle the state of the item. */
00355     CheckMenuItem ( hMenu,
00356                     IDM_COLOROWNERDR,
00357                     MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED));
00358
00359     if (!fOwnerDraw){
00360         /* Change the items to owner-draw items. Pass the RGB value for the
00361          * color as the application-supplied data. This makes it easier for
00362          * us to draw the items.
00363          */
00364         ModifyMenu(hMenu,
00365                    IDM_BLACK,
00366                    MF_OWNERDRAW | MF_BYCOMMAND,
00367                    IDM_BLACK,
00368                    (LPSTR)RGB (0,0,0));
00369
00370         ModifyMenu(hMenu,
00371                    IDM_BLUE,
00372                    MF_OWNERDRAW | MF_BYCOMMAND,
00373                    IDM_BLUE,
00374                    (LPSTR)RGB (0,0,255));
00375
00376         ModifyMenu(hMenu,
00377                    IDM_RED,
00378                    MF_OWNERDRAW | MF_BYCOMMAND,
00379                    IDM_RED,
00380                    (LPSTR)RGB (255,0,0));
00381
00382         ModifyMenu(hMenu,
00383                    IDM_GREEN,
00384                    MF_OWNERDRAW | MF_BYCOMMAND,
00385                    IDM_GREEN,
00386                    (LPSTR)RGB (0,255,0));
00387     }
00388     else {
00389         /* Change the items to normal text items. */
00390         ModifyMenu(hMenu, IDM_BLACK, MF_BYCOMMAND, IDM_BLACK, "Black");
00391
00392         ModifyMenu(hMenu, IDM_BLUE, MF_BYCOMMAND, IDM_BLUE, "Blue");
00393
00394         ModifyMenu(hMenu, IDM_RED, MF_BYCOMMAND, IDM_RED, "Red");
00395
00396         ModifyMenu(hMenu, IDM_GREEN, MF_BYCOMMAND, IDM_GREEN, "Green");
00397     }
00398 }
00399
00400
00401 /****************************************************************************
00402  *                                                                          *
00403  *  FUNCTION   : HandleDrawItem ( hwnd, lpdis)                              *
00404  *                                                                          *
00405  *  PURPOSE    : Called in response to a WM_DRAWITEM message, i.e. when the *
00406  *               colors menu is being modified to an owner-draw menu, or    *
00407  *               one of the items is selected. It sizes the checkmark bitmap*
00408  *               to fit next to a color band and draws the color bands and  *
00409  *               the checkmark on the popup menu.                           *
00410  *                                                                          *
00411  ****************************************************************************/
00412 VOID APIENTRY HandleDrawItem(
00413         HWND             hwnd,
00414         LPDRAWITEMSTRUCT lpdis)
00415
00416 {
00417     HDC     hdcBitmap;
00418     HBITMAP hbmSave;
00419     HBRUSH  hbr;
00420     RECT    rc;
00421     LONG    checkMarkSize;
00422     DWORD   textColorSave;
00423     DWORD   bkColorSave;
00424
00425     /* Get the size of the checkmark so we can leave room for it since we
00426      * want to be able to check the selected color.
00427      */
00428     checkMarkSize = GetMenuCheckMarkDimensions ();
00429
00430     if (lpdis->itemAction == ODA_SELECT ||
00431         lpdis->itemAction == ODA_DRAWENTIRE){
00432
00433         CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
00434         InflateRect ((LPRECT)&rc, (-2 - LOWORD(checkMarkSize)), -2);
00435
00436         if (lpdis->itemState & ODS_SELECTED)
00437         {
00438             /* Item has been selected -- hilite with a gray frame */
00439             hbr = GetStockObject (GRAY_BRUSH);
00440             FrameRect (lpdis->hDC, (LPRECT)&rc, hbr);
00441         }
00442         else if (lpdis->itemAction == ODA_SELECT)
00443         {
00444             /* Item has been de-selected -- remove gray frame */
00445             hbr = CreateSolidBrush (GetSysColor (COLOR_MENU));
00446             FrameRect (lpdis->hDC, (LPRECT)&rc, hbr);
00447             DeleteObject (hbr);
00448         }
00449     }
00450
00451     if (lpdis->itemAction == ODA_DRAWENTIRE){
00452
00453         /* Paint the color item in the color requested. */
00454         hbr = CreateSolidBrush (lpdis->itemData);
00455         CopyRect ((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
00456         InflateRect ((LPRECT)&rc, -10-LOWORD(checkMarkSize), -10);
00457         FillRect (lpdis->hDC, (LPRECT)&rc, hbr);
00458         DeleteObject (hbr);
00459
00460         if (lpdis->itemState & ODS_CHECKED){
00461             /* Draw the check mark if the item is checked. */
00462             hdcBitmap = CreateCompatibleDC (lpdis->hDC);
00463             hbmSave = SelectObject (hdcBitmap, hbmCheckOn);
00464
00465             textColorSave = SetTextColor (lpdis->hDC, 0x00000000L);
00466             bkColorSave   = SetBkColor (lpdis->hDC, 0x00FFFFFFL);
00467
00468             /* Use Magic bitblt op so that monochrome bitmaps preserve
00469                background and foreground colors. */
00470             BitBlt (lpdis->hDC,
00471                     lpdis->rcItem.left,
00472                     lpdis->rcItem.top+
00473                            (MEASUREITEMHEIGHT - HIWORD (checkMarkSize)) / 2,
00474                     LOWORD (checkMarkSize),
00475                     HIWORD (checkMarkSize),
00476                     hdcBitmap,
00477                     0,
00478                     0,
00479                     ROP_PSDPxax);
00480
00481             /* Restore colors and bitmap and clean up */
00482             SetTextColor (lpdis->hDC, textColorSave);
00483             SetBkColor (lpdis->hDC, bkColorSave);
00484             SelectObject (hdcBitmap, hbmSave);
00485             DeleteDC (hdcBitmap);
00486
00487         }
00488     }
00489         UNREFERENCED_PARAMETER(hwnd);
00490 }
00491
00492 /****************************************************************************
00493  *                                                                          *
00494  *  FUNCTION   : HandlePopupMenu (hwnd, point)                              *
00495  *                                                                          *
00496  *  PURPOSE    : Handles the display of the "floating" popup that appears   *                                                           *
00497  *               on a mouse click in the app's client area.                 *
00498  *                                                                          *
00499  ****************************************************************************/
00500 VOID APIENTRY HandlePopupMenu (
00501         HWND   hwnd,
00502         POINT point)
00503
00504 {
00505     HMENU hMenu;
00506     HMENU hMenuTrackPopup;
00507
00508     /* Get the menu for the popup from the resource file. */
00509     hMenu = LoadMenu (hInst, "PopupMenu");
00510     if (!hMenu)
00511         return;
00512
00513     /* Get the first menu in it which we will use for the call to
00514      * TrackPopup(). This could also have been created on the fly using
00515      * CreatePopupMenu and then we could have used InsertMenu() or
00516      * AppendMenu.
00517      */
00518     hMenuTrackPopup = GetSubMenu (hMenu, 0);
00519
00520     /* Convert the mouse point to screen coordinates since that is what
00521      * TrackPopup expects.
00522      */
00523     ClientToScreen (hwnd, (LPPOINT)&point);
00524
00525     /* Draw and track the "floating" popup */
00526     TrackPopupMenu (hMenuTrackPopup, 0, point.x, point.y, 0, hwnd, NULL);
00527
00528     /* Destroy the menu since were are done with it. */
00529     DestroyMenu (hMenu);
00530 }
00531
00532 /****************************************************************************
00533  *                                                                          *
00534  *  FUNCTION   : MenuWndProc (hWnd, message, wParam, lParam)                *
00535  *                                                                          *
00536  *  PURPOSE    : Window function for the main app. window. Processes all the*
00537  *               menu selections and oter messages.                         *
00538  *                                                                          *
00539  ****************************************************************************/
00540 LONG APIENTRY MenuWndProc (
00541         HWND hWnd,
00542         UINT message,
00543         UINT wParam,
00544         LONG lParam)
00545
00546 {
00547     FARPROC lpProc;
00548     HMENU hMenu;
00549     RECT rc;
00550     POINT pt;
00551
00552
00553     switch (message){
00554         case WM_SYSCOMMAND:
00555             /* Show the About ... dialog */
00556             if (wParam == ID_ABOUT){
00557                 lpProc = MakeProcInstance ((FARPROC)About, hInst);
00558                 DialogBox (hInst,
00559                            "AboutBox",
00560                            hWnd,
00561                            lpProc);
00562
00563                 FreeProcInstance (lpProc);
00564                 break;
00565             }
00566             else
00567               return DefWindowProc (hWnd, message, wParam, lParam);
00568
00569         case WM_COMMAND:
00570             // LOWORD added for portability
00571             switch (LOWORD(wParam)){
00572                  case IDM_EXIT:
00573                    DestroyWindow (hWnd);
00574                    break;
00575
00576                  case IDM_ABOUT:
00577                    /* Bring up the About.. dialog box */
00578                    lpProc = MakeProcInstance ((FARPROC)About, hInst);
00579                    DialogBox (hInst,
00580                               "AboutBox",
00581                               hWnd,
00582                               lpProc);
00583
00584                    FreeProcInstance (lpProc);
00585                    break;
00586
00587                  case IDM_COLOROWNERDR:
00588                      /* Change colors in color menu depending on state of this
00589                         menu item. */
00590                      HandleChangeColors (hWnd);
00591                      break;
00592
00593                  case IDM_STATE1:
00594                  case IDM_STATE2:
00595                  case IDM_STATE3:
00596                  case IDM_STATE4:
00597                       /* Get a handle to the states menu... */
00598                       hMenu = GetSubMenu (GetMenu (hWnd), IDSTATES_POS);
00599
00600                       /* Uncheck all the items. */
00601                       CheckMenuItem (hMenu, IDM_STATE1,
00602                                      MF_BYCOMMAND | MF_UNCHECKED);
00603                       CheckMenuItem (hMenu, IDM_STATE2,
00604                                      MF_BYCOMMAND | MF_UNCHECKED);
00605                       CheckMenuItem (hMenu, IDM_STATE3,
00606                                      MF_BYCOMMAND | MF_UNCHECKED);
00607                       CheckMenuItem (hMenu, IDM_STATE4,
00608                                      MF_BYCOMMAND | MF_UNCHECKED);
00609
00610                       /* ...and just check the selected one.*/
00611                       CheckMenuItem (hMenu, (WORD)wParam,
00612                                      MF_BYCOMMAND | MF_CHECKED);
00613                      break;
00614
00615                  case IDM_BLACK:
00616                  case IDM_RED:
00617                  case IDM_BLUE:
00618                  case IDM_GREEN:
00619                       /* Get a handle to the Colors menu. */
00620                       hMenu = GetSubMenu (GetMenu (hWnd),IDCOLORS_POS);
00621
00622                       /* Uncheck all the items. */
00623                       CheckMenuItem (hMenu, IDM_BLACK,
00624                                      MF_BYCOMMAND | MF_UNCHECKED);
00625                       CheckMenuItem (hMenu, IDM_RED,
00626                                      MF_BYCOMMAND | MF_UNCHECKED);
00627                       CheckMenuItem (hMenu, IDM_BLUE,
00628                                      MF_BYCOMMAND | MF_UNCHECKED);
00629                       CheckMenuItem (hMenu, IDM_GREEN,
00630                                      MF_BYCOMMAND | MF_UNCHECKED);
00631
00632                       /* ...and just check the selected one.*/
00633                       CheckMenuItem (hMenu, (WORD)wParam,
00634                                      MF_BYCOMMAND | MF_CHECKED);
00635                       break;
00636
00637                  case IDM_FONT:
00638                       /* Messages sent to us from TrackPopupMenu when
00639                        * items are selected from the "floating" popups
00640                        */
00641                       MessageBox (hWnd,
00642                                   "A font was selected",
00643                                   "Popup Menu Alert",
00644                                   MB_APPLMODAL|MB_OK);
00645                       break;
00646
00647                  case IDM_SIZE:
00648                       MessageBox (hWnd,
00649                                   "A size was selected",
00650                                   "Popup Menu Alert",
00651                                   MB_APPLMODAL|MB_OK);
00652                       break;
00653
00654                  case IDM_STYLE:
00655                       MessageBox (hWnd,
00656                                   "A style was selected",
00657                                   "Popup Menu Alert",
00658                                   MB_APPLMODAL|MB_OK);
00659                       break;
00660             }
00661             break;
00662
00663         case WM_SIZE:
00664             if (lParam){
00665                 /* If window is being sized to a non zero value...
00666                  * invalidate it's client area.
00667                  */
00668                 InvalidateRect (hWnd, NULL, TRUE);
00669             }
00670             break;
00671
00672         case WM_PAINT:
00673             HandlePaint (hWnd);
00674             break;
00675
00676         case WM_MEASUREITEM:
00677             /* Use the same width for all items. We could examine the item id
00678                and use different widths/heights for each item. */
00679             ((LPMEASUREITEMSTRUCT)lParam)->itemWidth  = MEASUREITEMWIDTH;
00680             ((LPMEASUREITEMSTRUCT)lParam)->itemHeight = MEASUREITEMHEIGHT;
00681             return TRUE;
00682
00683         case WM_DRAWITEM:
00684             /* Redraw the "colors" menu in normal/ownerdrawmode */
00685             HandleDrawItem (hWnd,(LPDRAWITEMSTRUCT)lParam);
00686             return TRUE;
00687             break;
00688
00689         case WM_CREATE:
00690             /* Create the menu */
00691             HandleCreate (hWnd);
00692             break;
00693
00694         case WM_DESTROY:
00695             /* Delete the on/off bitmaps so that they don't waste memory. */
00696             DeleteObject (hbmCheckOn);
00697             DeleteObject (hbmCheckOff);
00698
00699             PostQuitMessage (0);
00700             break;
00701
00702         case WM_LBUTTONDOWN:
00703             /* Draw the "floating" popup in the app's client area */
00704             GetClientRect (hWnd, (LPRECT)&rc);
00705
00706             // Temporary porting macro
00707             LONG2POINT(lParam, pt);
00708             if (PtInRect ((LPRECT)&rc, pt))
00709                 HandlePopupMenu (hWnd, pt);
00710             break;
00711
00712         default:
00713             return DefWindowProc(hWnd, message, wParam, lParam);
00714     }
00715     return(0);
00716 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PLATFORM/PLATFORM.C Source File

  • PLATFORM

PLATFORM.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************
00013
00014     PROGRAM: Platform.c
00015
00016     PURPOSE: Platform template for Windows applications
00017
00018     FUNCTIONS:
00019
00020         WinMain() - calls initialization function, processes message loop
00021         InitApplication() - initializes window data and registers window
00022         InitInstance() - saves instance handle and creates main window
00023         MainWndProc() - processes messages
00024         About() - processes messages for "About" dialog box
00025
00026     COMMENTS:
00027
00028         Windows can have several copies of your application running at the
00029         same time.  The variable hInst keeps track of which instance this
00030         application is so that processing will be to the correct window.
00031
00032 ****************************************************************************/
00033
00034 #define STRICT
00035
00036
00037 #include <stddef.h>
00038 #include "windows.h"                /* required for all Windows applications */
00039
00040 #if defined(_WIN32)
00041 #define WIN32S  0x80000000l
00042 #else
00043 #define WINAPI   FAR PASCAL
00044 #define TCHAR char
00045 #define LPTSTR LPSTR
00046 #define UNREFERENCED_PARAMETER(x) x;
00047 #define TEXT(x) x
00048
00049 #define WF1_WINNT 0x40        /* A special version of GetWinFlags() will
00050                                * be provide in the WOW Layer which returns
00051                                * a MANEFEST CONSTANT signifing to Win16
00052                                * apps that it's running in WOW instead of
00053                                * DOS/Windows. Unfortunately this value
00054                                * was not specified at the time of this
00055                                * sample. As *soon* as Development has set
00056                                * on a manifest contanst PSS will upload a
00057                                * KnowledgeBase article. Describing this flag
00058                                * and any other relevent details need to get
00059                                * this sample correctly identifing what platform
00060                                * it's running on.
00061                                */
00062
00063 #endif
00064
00065
00066 #include "Platform.h"               /* specific to this program              */
00067
00068
00069 HINSTANCE hInst;                       /* current instance                      */
00070
00071
00072 /****************************************************************************
00073
00074     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00075
00076     PURPOSE: calls initialization function, processes message loop
00077
00078     COMMENTS:
00079
00080         Windows recognizes this function by name as the initial entry point
00081         for the program.  This function calls the application initialization
00082         routine, if no other instance of the program is running, and always
00083         calls the instance initialization routine.  It then executes a message
00084         retrieval and dispatch loop that is the top-level control structure
00085         for the remainder of execution.  The loop is terminated when a WM_QUIT
00086         message is received, at which time this function exits the application
00087         instance by returning the value passed by PostQuitMessage().
00088
00089         If this function must abort before entering the message loop, it
00090         returns the conventional value NULL.
00091
00092 ****************************************************************************/
00093
00094 int PASCAL WinMain(HINSTANCE hInstance,      /* current instance  */
00095                    HINSTANCE hPrevInstance,  /* previous instance */
00096                    LPSTR     lpCmdLine,      /* command line      */
00097                    int       nCmdShow)       /* show-window type (open/icon) */
00098 {
00099     MSG msg;                                 /* message                      */
00100
00101     if (!hPrevInstance)                  /* Other instances of app running? */
00102         if (!InitApplication(hInstance)) /* Initialize shared things */
00103             return (FALSE);              /* Exits if unable to initialize     */
00104
00105     /* Perform initializations that apply to a specific instance */
00106
00107     if (!InitInstance(hInstance, nCmdShow))
00108         return (FALSE);
00109
00110     /* Acquire and dispatch messages until a WM_QUIT message is received. */
00111
00112     while (GetMessage(&msg,        /* message structure                      */
00113             NULL,                  /* handle of window receiving the message */
00114             0,                     /* lowest message to examine              */
00115             0))                    /* highest message to examine             */
00116     {
00117             TranslateMessage(&msg);    /* Translates virtual key codes           */
00118             DispatchMessage(&msg);     /* Dispatches message to window           */
00119     }
00120
00121     return (msg.wParam);           /* Returns the value from PostQuitMessage */
00122 UNREFERENCED_PARAMETER(lpCmdLine);
00123 }
00124
00125
00126 /****************************************************************************
00127
00128     FUNCTION: InitApplication(HANDLE)
00129
00130     PURPOSE: Initializes window data and registers window class
00131
00132     COMMENTS:
00133
00134         This function is called at initialization time only if no other
00135         instances of the application are running.  This function performs
00136         initialization tasks that can be done once for any number of running
00137         instances.
00138
00139         In this case, we initialize a window class by filling out a data
00140         structure of type WNDCLASS and calling the Windows RegisterClass()
00141         function.  Since all instances of this application use the same window
00142         class, we only need to do this when the first instance is initialized.
00143
00144
00145 ****************************************************************************/
00146
00147 BOOL InitApplication(HANDLE hInstance)    /* current instance     */
00148 {
00149     WNDCLASS  wc;
00150
00151     /* Fill in window class structure with parameters that describe the       */
00152     /* main window.                                                           */
00153
00154     wc.style = 0;                        /* Class style(s).                    */
00155     wc.lpfnWndProc = (WNDPROC)MainWndProc;       /* Function to retrieve messages for  */
00156                                         /* windows of this class.             */
00157     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
00158     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
00159     wc.hInstance = hInstance;           /* Application that owns the class.   */
00160     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00161     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00162     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00163     wc.lpszMenuName =  "PlatformMenu";   /* Name of menu resource in .RC file. */
00164     wc.lpszClassName = "PlatformWClass"; /* Name used in call to CreateWindow. */
00165
00166     /* Register the window class and return success/failure code. */
00167
00168     return (RegisterClass(&wc));
00169
00170 }
00171
00172
00173 /****************************************************************************
00174
00175     FUNCTION:  InitInstance(HANDLE, int)
00176
00177     PURPOSE:  Saves instance handle and creates main window
00178
00179     COMMENTS:
00180
00181         This function is called at initialization time for every instance of
00182         this application.  This function performs initialization tasks that
00183         cannot be shared by multiple instances.
00184
00185         In this case, we save the instance handle in a static variable and
00186         create and display the main program window.
00187
00188 ****************************************************************************/
00189
00190 BOOL InitInstance(HANDLE hInstance,     /* Current instance identifier.     */
00191                   int nCmdShow )        /* Param for first ShowWindow() call. */
00192 {
00193     HWND            hWnd;               /* Main window handle.                */
00194
00195     /* Save the instance handle in static variable, which will be used in  */
00196     /* many subsequence calls from this application to Windows.            */
00197
00198     hInst = hInstance;
00199
00200     /* Create a main window for this application instance.  */
00201
00202     hWnd = CreateWindow(
00203         "PlatformWClass",                /* See RegisterClass() call.          */
00204         "Platform Sample Application",   /* Text for window title bar.         */
00205         WS_OVERLAPPEDWINDOW,            /* Window style.                      */
00206         10,                  /* Default horizontal position.       */
00207         10,                  /* Default vertical position.         */
00208         600,                  /* Default width.                     */
00209         400,                  /* Default height.                    */
00210         NULL,                           /* Overlapped windows have no parent. */
00211         NULL,                           /* Use the window class menu.         */
00212         hInstance,                      /* This instance owns this window.    */
00213         NULL                            /* Pointer not needed.                */
00214     );
00215
00216     /* If window could not be created, return "failure" */
00217
00218     if (!hWnd)
00219         return (FALSE);
00220
00221     /* Make the window visible; update its client area; and return "success" */
00222
00223     ShowWindow(hWnd, nCmdShow);  /* Show the window                        */
00224     UpdateWindow(hWnd);          /* Sends WM_PAINT message                 */
00225     return (TRUE);               /* Returns the value from PostQuitMessage */
00226
00227 }
00228
00229 /****************************************************************************
00230
00231     FUNCTION: MainWndProc(HWND, WORD, WPARAM, LPARAM)
00232
00233     PURPOSE:  Processes messages
00234
00235     MESSAGES:
00236
00237         WM_COMMAND    - application menu (About dialog box)
00238         WM_DESTROY    - destroy window
00239
00240     COMMENTS:
00241
00242         To process the IDM_ABOUT message, call MakeProcInstance() to get the
00243         current instance address of the About() function.  Then call Dialog
00244         box which will create the box according to the information in your
00245         Platform.rc file and turn control over to the About() function. When
00246         it returns, free the intance address.
00247
00248 ****************************************************************************/
00249
00250 LRESULT CALLBACK MainWndProc(HWND hWnd,      /* window handle             */
00251                              UINT message,   /* type of message           */
00252                              WPARAM wParam,  /* additional information    */
00253                              LPARAM lParam ) /* additional information    */
00254 {
00255     DLGPROC lpProcAbout;
00256     DWORD   version, flags;
00257     char    buf[80];
00258
00259     switch (message) {
00260
00261         case WM_COMMAND:           /* message: command from application menu */
00262             if (LOWORD(wParam) == IDM_ABOUT) {
00263                 lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, hInst );
00264
00265                 DialogBox(hInst,                 /* current instance         */
00266                     "AboutBox",                  /* resource to use          */
00267                     hWnd,                        /* parent handle            */
00268                     lpProcAbout);       /* About() instance address */
00269
00270                 FreeProcInstance((FARPROC)lpProcAbout);
00271                 break;
00272             }
00273             else if ( LOWORD(wParam) == IDM_PLATFORM ) {
00274                 version = GetVersion();
00275                 wsprintf( buf, "The version of Windows that you are running is %d.%d",
00276                           LOBYTE(LOWORD(version)), HIBYTE(LOWORD(version)) );
00277
00278                 MessageBox( hWnd, buf, "Platform", MB_OK );
00279 #if defined(_WIN32) || defined(WIN32)
00280 /*
00281  * bugbug Currently HIWORD of version is 500. The highbit is not set
00282  */
00283
00284                 if (version < 0x80000000)
00285                     wsprintf( buf, "This is running on Win32/NT" );
00286                 else
00287                     if (LOBYTE(LOWORD(version)) < 4)
00288                         wsprintf( buf, "This is running on Win32s" );
00289                     else
00290                         wsprintf( buf, "This is running on Windows 95" );
00291
00292                 UNREFERENCED_PARAMETER(flags);
00293 #else
00294                 flags = GetWinFlags();
00295                 wsprintf ( buf, "flags are %#lx", flags );
00296 //                MessageBox ( hWnd, buf, NULL, MB_OK );
00297
00298                 if ( flags & WF1_WINNT )
00299                     wsprintf ( buf, "This is running in the WOW layer" );
00300                 else
00301                     if (HIBYTE(LOWORD(version)) == 95)
00302                         wsprintf( buf, "This is running on Windows 95" );
00303                     else
00304                         wsprintf( buf, "The version of MS-DOS you're running is %d.%d",
00305                             HIBYTE(HIWORD(version)), LOBYTE(HIWORD(version)) );
00306 #endif
00307                 MessageBox( hWnd, buf, "Platform", MB_OK );
00308             }
00309             else                            /* Lets Windows process it       */
00310                 return (DefWindowProc(hWnd, message, wParam, lParam));
00311
00312             break;
00313
00314         case WM_DESTROY:                  /* message: window being destroyed */
00315             PostQuitMessage(0);
00316             break;
00317
00318         default:                          /* Passes it on if unproccessed    */
00319             return (DefWindowProc(hWnd, message, wParam, lParam));
00320     }
00321     return ( 0 );
00322 }
00323
00324
00325 /****************************************************************************
00326
00327     FUNCTION: About(HWND, unsigned, WORD, LONG)
00328
00329     PURPOSE:  Processes messages for "About" dialog box
00330
00331     MESSAGES:
00332
00333         WM_INITDIALOG - initialize dialog box
00334         WM_COMMAND    - Input received
00335
00336     COMMENTS:
00337
00338         No initialization is needed for this particular dialog box, but TRUE
00339         must be returned to Windows.
00340
00341         Wait for user to click on "Ok" button, then close the dialog box.
00342
00343 ****************************************************************************/
00344
00345 BOOL CALLBACK About( HWND hDlg,       /* window handle of the dialog box */
00346                      UINT message,    /* type of message                 */
00347                      WPARAM wParam,   /* message-specific information    */
00348                      LPARAM lParam )
00349 {
00350     switch (message) {
00351         case WM_INITDIALOG:                /* message: initialize dialog box */
00352             return (TRUE);
00353
00354         case WM_COMMAND:                      /* message: received a command */
00355             if (wParam == IDOK                /* "OK" box selected?          */
00356                 || wParam == IDCANCEL) {      /* System menu close command? */
00357                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
00358                 return (TRUE);
00359             }
00360             break;
00361     }
00362     return (FALSE);                           /* Didn't process a message    */
00363 UNREFERENCED_PARAMETER(lParam);
00364 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OVCOMM/OVCOMM.C Source File

  • OVCOMM

OVCOMM.C

Go to the documentation of this file.
00001 /*************************************************************************\
00002 *  PROGRAM: OvComm.c
00003 *
00004 *  PURPOSE:
00005 *
00006 *     To demonstrate overlapped serial communication in multiple threads
00007 *
00008 *  FUNCTIONS:
00009 *
00010 *    main()         - Setups up console mode
00011 *    ProcessIO      - Comm Port Setup, thread creation and cleanup
00012 *
00013 *  GLOBAL VARIABLES:
00014 *
00015 *    - comHandle      : Handle to comm device
00016 *    - hSetupEvent    : Handle of the event signalling setup completion
00017 *    - bDone          : Boolean controlling execution of threads
00018 *    - lpszPort       : String containing port name
00019 *    - lpszSerialSpec : String containing serial specification
00020 *    - g_timeouts     : Original COMMTIMEOUTS to be restored when closing
00021 *
00022 *  COMMENTS:
00023 *
00024 *    To Use:
00025 *       Start the application from the command line.  The application will
00026 *       by default use COM1 9600,N,8,1.  If desired, the comm port and
00027 *       serial specification can be supplied on the command line.
00028 *       The application uses the console to display received data.
00029 *       Keyboard input from the console's standard input handle
00030 *       is used to get data to send to the comm port.
00031 *
00032 *    What Happens:
00033 *       The program utilizes 4 threads.  A main thread initializes the comm
00034 *       port and console, creates 3 worker threads and waits for the threads
00035 *       to terminate.  Each worker thread controls a single facet of
00036 *       serial communications.
00037 *
00038 *       A Status Thread is created to monitor status events.
00039 *       When an event occurs, the event is communicated to the user via
00040 *       OutputDebugString.
00041 *
00042 *       A Reader Thread is created to read the comm port and display the
00043 *       received data on the console output.
00044 *
00045 *       A Writer Thread is created to accept keyboard input and send it
00046 *       out the comm port.
00047 *
00048 *       Control-Break causes program termination.
00049 *
00050 \*************************************************************************/
00051
00052 #include <windows.h>
00053 #include <stdio.h>
00054
00055 #include "OvComm.h"
00056
00057
00058 /*************************************************************************\
00059 *
00060 *  FUNCTION: ErrorReporter(char *)
00061 *
00062 *  PURPOSE: Report error to user
00063 *
00064 *  COMMENTS: Reports error string in console and in debugger
00065 *
00066 \*************************************************************************/
00067 void ErrorReporter(char * szMessage)
00068 {
00069   DWORD dwErr;
00070   char * szTemp;
00071     char * szFormat = "Error %d: %s.\n\r";
00072
00073     dwErr = GetLastError();
00074
00075   // allocate a temporary buffer
00076   szTemp = malloc(strlen(szMessage) + 20);
00077
00078   if (szTemp == NULL) // if no buffer, then printf message
00079     printf(szFormat, dwErr, szMessage);
00080   else {
00081     wsprintf(szTemp, szFormat, dwErr, szMessage);
00082     printf(szTemp);           // printf message on console
00083     OutputDebugString(szTemp);  // and debugger
00084     free(szTemp);         // free buffer
00085   }
00086
00087     return;
00088 }
00089
00090
00091 /*************************************************************************\
00092 *
00093 *  FUNCTION: ErrorHandler(char *)
00094 *
00095 *  PURPOSE: Handle a fatal error
00096 *
00097 *  COMMENTS: Calls ErrorReporter function and then exits.
00098 *            This function is used to report fatal errors before the comm
00099 *            port is opened.
00100 *
00101 \*************************************************************************/
00102 void ErrorHandler(char * szMessage)
00103 {
00104     ErrorReporter(szMessage);
00105   exit(0);
00106 }
00107
00108
00109 /*************************************************************************\
00110 *
00111 *  FUNCTION: ErrorInComm(char *)
00112 *
00113 *  PURPOSE: Handle a fatal error after comm has started
00114 *
00115 *  COMMENTS: Calls ErrorReporter, BreakDownCommPort and exits.
00116 *
00117 \*************************************************************************/
00118 void ErrorInComm(char * szMessage)
00119 {
00120   ErrorReporter(szMessage);
00121     BreakDownCommPort();
00122     exit(0);
00123 }
00124
00125
00126 /*************************************************************************\
00127 *
00128 *  FUNCTION: SetupCommPort( void )
00129 *
00130 *  PURPOSE: Setup Communication Port with our settings
00131 *
00132 *  COMMENTS:
00133 *
00134 \*************************************************************************/
00135 HANDLE SetupCommPort( void )
00136 {
00137   COMMTIMEOUTS timeouts;
00138   DCB dcb;
00139
00140   // sync event for controlling thread startup
00141   hSetupEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
00142   if (hSetupEvent == NULL)
00143     ErrorHandler("CreateEvent(Setup Event)");
00144
00145   // communication handle
00146   comHandle = CreateFile( lpszPort,
00147                           GENERIC_READ | GENERIC_WRITE,
00148                           0,
00149                           0,
00150                           OPEN_EXISTING,
00151               FILE_FLAG_OVERLAPPED,
00152               0);
00153
00154   if (comHandle == INVALID_HANDLE_VALUE) {
00155         printf("Problem opening port: %s\n", lpszPort);
00156     ErrorHandler("CreateFile");
00157     }
00158
00159     FillMemory(&dcb, sizeof(dcb), 0);
00160     dcb.DCBlength = sizeof(dcb);
00161     if (!BuildCommDCB(lpszSerialSpec, &dcb)) {
00162         printf("Problem with serial spec line: %s\n", lpszSerialSpec);
00163         ErrorInComm("BuildCommDCB");
00164     }
00165
00166     dcb.EvtChar = EVT_CHAR;
00167
00168   if (!SetCommState(comHandle, &dcb))
00169     ErrorInComm("SetCommState");
00170
00171     // Save original comm timeouts and set new ones
00172     if (!GetCommTimeouts(comHandle, &g_timeouts))
00173         ErrorInComm("GetCommTimeouts");
00174
00175     // Need ReadIntervalTimeout here to cause the read operations
00176     // that we do to actually timeout and become overlapped.
00177     // Specifying 1 here causes ReadFile to return very quickly
00178     // so that our reader thread will continue execution after a ReadFile
00179     // is overlapped.
00180     // Specifying MAXDWORD here causes ReadFile to return immediately
00181     // without overlapping.
00182     timeouts.ReadIntervalTimeout = 1;
00183   timeouts.ReadTotalTimeoutMultiplier = 0;
00184   timeouts.ReadTotalTimeoutConstant = 0;
00185   timeouts.WriteTotalTimeoutMultiplier = 0;
00186   timeouts.WriteTotalTimeoutConstant = 0;
00187
00188   if (!SetCommTimeouts(comHandle, &timeouts))
00189     ErrorInComm("SetCommTimeouts");
00190
00191     // raise DTR
00192   if (!EscapeCommFunction(comHandle, SETDTR))
00193     ErrorInComm("EscapeCommFunction (SETDTR)");
00194
00195     // set initial thread state: NOT DONE
00196   bDone = FALSE;
00197
00198   return comHandle;
00199 }
00200
00201
00202 /*************************************************************************\
00203 *
00204 *  FUNCTION: BreakDownCommPort( void )
00205 *
00206 *  PURPOSE: Clean-up and close comm port
00207 *
00208 *  COMMENTS:
00209 *
00210 \*************************************************************************/
00211 void BreakDownCommPort( void )
00212 {
00213     // lower DTR
00214   if (!EscapeCommFunction(comHandle, CLRDTR))
00215     ErrorReporter("EscapeCommFunction(CLRDTR)");
00216
00217     // restore original comm timeouts
00218     if (!SetCommTimeouts(comHandle, &g_timeouts))
00219         ErrorReporter("SetCommTimeouts (Restoration to original)");
00220
00221   if (!PurgeComm(comHandle, PURGE_FLAGS))
00222         ErrorReporter("PurgeComm");
00223
00224     CloseHandle(comHandle);
00225 }
00226
00227
00228 /*************************************************************************\
00229 *
00230 *  FUNCTION: ReportModemStatus(DWORD)
00231 *
00232 *  PURPOSE: Report modem status line states
00233 *
00234 *  COMMENTS: Upper case means the signal is high
00235 *
00236 \*************************************************************************/
00237 void ReportModemStatus(DWORD dwModemStatus)
00238 {
00239   BOOL bCTS, bDSR, bRING, bRLSD;
00240     char szMessage[35];
00241
00242   bCTS = MS_CTS_ON & dwModemStatus;
00243   bDSR = MS_DSR_ON & dwModemStatus;
00244   bRING = MS_RING_ON & dwModemStatus;
00245   bRLSD = MS_RLSD_ON & dwModemStatus;
00246
00247     strcpy(szMessage, "MODEM STATUS: ");
00248     strcat(szMessage, bCTS ? "CTS " : "cts ");
00249   strcat(szMessage, bDSR ? "DSR " : "dsr ");
00250   strcat(szMessage, bRING ? "RING " : "ring ");
00251   strcat(szMessage, bRLSD ? "RLSD " : "rlsd ");
00252     strcat(szMessage,"\n\r");
00253
00254     OutputDebugString(szMessage);
00255
00256     return;
00257 }
00258
00259
00260 /*************************************************************************\
00261 *
00262 *  FUNCTION: CheckModemStatus ( void )
00263 *
00264 *  PURPOSE: Check new status, report if changed
00265 *
00266 *  COMMENTS:
00267 *
00268 \*************************************************************************/
00269 void CheckModemStatus( void )
00270 {
00271   static DWORD dwOldStatus = 0;
00272   DWORD dwNewModemStatus;
00273
00274   if (!GetCommModemStatus(comHandle, &dwNewModemStatus))
00275     ErrorReporter("GetCommModemStatus");
00276
00277   if (dwNewModemStatus != dwOldStatus) {  // status changed?
00278         ReportModemStatus(dwNewModemStatus);
00279         dwOldStatus = dwNewModemStatus;
00280     }
00281
00282     return;
00283 }
00284
00285
00286 /*************************************************************************\
00287 *
00288 *  FUNCTION: ReportCommError( void )
00289 *
00290 *  PURPOSE: Call ClearCommError and report the results
00291 *
00292 *  COMMENTS: This function is called if an EV_ERR occurs.
00293 *
00294 \*************************************************************************/
00295 void ReportCommError( void )
00296 {
00297     COMSTAT comStat;
00298     DWORD   dwErrors;
00299     char    szMessage[100];
00300     BOOL    bBREAK, bDNS, bFRAME, bIOE, bMODE;
00301     BOOL    bOOP, bOVERRUN, bPTO, bRXOVER, bRXPARITY, bTXFULL;
00302
00303     if (!ClearCommError(comHandle, &dwErrors, &comStat))
00304         ErrorInComm("ClearCommError");
00305
00306     bDNS = dwErrors & CE_DNS;
00307     bIOE = dwErrors & CE_IOE;
00308     bOOP = dwErrors & CE_OOP;
00309     bPTO = dwErrors & CE_PTO;
00310     bMODE = dwErrors & CE_MODE;
00311     bBREAK = dwErrors & CE_BREAK;
00312     bFRAME = dwErrors & CE_FRAME;
00313     bRXOVER = dwErrors & CE_RXOVER;
00314     bTXFULL = dwErrors & CE_TXFULL;
00315     bOVERRUN = dwErrors & CE_OVERRUN;
00316     bRXPARITY = dwErrors & CE_RXPARITY;
00317
00318     strcpy(szMessage, "ERROR: ");
00319     strcat(szMessage, bDNS ? "DNS " : "");
00320     strcat(szMessage, bIOE ? "IOE " : "");
00321     strcat(szMessage, bOOP ? "OOP " : "");
00322     strcat(szMessage, bPTO ? "PTO " : "");
00323     strcat(szMessage, bMODE ? "MODE " : "");
00324     strcat(szMessage, bBREAK ? "BREAK " : "");
00325     strcat(szMessage, bFRAME ? "FRAME " : "");
00326     strcat(szMessage, bRXOVER ? "RXOVER " : "");
00327     strcat(szMessage, bTXFULL ? "TXFULL " : "");
00328     strcat(szMessage, bOVERRUN ? "OVERRUN " : "");
00329     strcat(szMessage, bRXPARITY ? "RXPARITY " : "");
00330     strcat(szMessage, "\n\r");
00331
00332     OutputDebugString(szMessage);
00333
00334     if (comStat.fCtsHold)
00335         OutputDebugString("Tx waiting for CTS signal\n\r");
00336
00337     if (comStat.fDsrHold)
00338         OutputDebugString("Tx waiting for DSR signal\n\r");
00339
00340     if (comStat.fRlsdHold)
00341         OutputDebugString("Tx waiting for RLSD signal\n\r");
00342
00343     if (comStat.fXoffHold)
00344         OutputDebugString("Tx waiting, XOFF char rec'd\n\r");
00345
00346     if (comStat.fXoffSent)
00347         OutputDebugString("Tx waiting, XOFF char sent\n\r");
00348
00349     if (comStat.fEof)
00350         OutputDebugString("EOF character received\n\r");
00351
00352     if (comStat.fTxim)
00353         OutputDebugString("Character waiting for Tx\n\r");
00354
00355     if (comStat.cbInQue) {
00356         sprintf(szMessage, "%d bytes in input buffer\n\r", comStat.cbInQue);
00357         OutputDebugString(szMessage);
00358     }
00359
00360     if (comStat.cbOutQue) {
00361         sprintf(szMessage, "%d bytes in output buffer\n\r", comStat.cbOutQue);
00362         OutputDebugString(szMessage);
00363     }
00364
00365     return;
00366 }
00367
00368 /*************************************************************************\
00369 *
00370 *  FUNCTION: ReportStatusEvent (DWORD)
00371 *
00372 *  PURPOSE: Report a comm status event
00373 *
00374 *  COMMENTS: This is different than line status (aka Modem Status).
00375 *
00376 \*************************************************************************/
00377 void ReportStatusEvent(DWORD dwStatus)
00378 {
00379   BOOL bBREAK, bCTS, bDSR, bERR;
00380   BOOL bRING, bRLSD, bRXCHAR, bRXFLAG, bTXEMPTY;
00381     char szMessage[70];
00382
00383   bCTS = EV_CTS & dwStatus;
00384   bDSR = EV_DSR & dwStatus;
00385   bERR = EV_ERR & dwStatus;
00386   bRING = EV_RING & dwStatus;
00387   bRLSD = EV_RLSD & dwStatus;
00388   bBREAK = EV_BREAK & dwStatus;
00389   bRXCHAR = EV_RXCHAR & dwStatus;
00390     bRXFLAG = EV_RXFLAG & dwStatus;
00391   bTXEMPTY = EV_TXEMPTY & dwStatus;
00392
00393     strcpy(szMessage, "EVENT: ");
00394     strcat(szMessage, bCTS ? "CTS " : "");
00395   strcat(szMessage, bDSR ? "DSR " : "");
00396   strcat(szMessage, bERR ? "ERR " : "");
00397   strcat(szMessage, bRING ? "RING " : "");
00398   strcat(szMessage, bRLSD ? "RLSD " : "");
00399   strcat(szMessage, bBREAK ? "BREAK " : "");
00400     strcat(szMessage, bRXFLAG ? "RXFLAG " : "");
00401   strcat(szMessage, bRXCHAR ? "RXCHAR " : "");
00402   strcat(szMessage, bTXEMPTY ? "TXEMPTY " : "");
00403     strcat(szMessage, "\n\r");
00404
00405     OutputDebugString(szMessage);
00406
00407     if (bERR)
00408         ReportCommError();
00409
00410   CheckModemStatus();
00411
00412   return;
00413 }
00414
00415
00416 /*************************************************************************\
00417 *
00418 *  FUNCTION: StatusProc (LPVOID)
00419 *
00420 *  PURPOSE: Thread function to control comm status checking
00421 *
00422 *  COMMENTS: Events that occur more than once in a while, like
00423 *            EV_RXCHAR, EV_TXEMPTY or event EV_RXFLAG may only be
00424 *            reported once.  The reason is that subsequent occurrences
00425 *            of an as yet unreported event simply trigger an already
00426 *            triggered flag.  Events are not queued up like Window
00427 *            Messages.
00428 *
00429 \*************************************************************************/
00430 DWORD WINAPI StatusProc(LPVOID lpV)
00431 {
00432   DWORD    dwWaitResult, dwCommEvent;
00433   HANDLE     hEvent;
00434   BOOL     bWaitingOnStatusHandle = FALSE;
00435   OVERLAPPED os = {0};
00436
00437   hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
00438   if (hEvent == NULL)
00439     ErrorInComm("CreateEvent(Status)");
00440
00441   os.hEvent = hEvent;
00442
00443   if (!SetCommMask(comHandle, EVENT_FLAGS))
00444     ErrorInComm("SetCommMask");
00445
00446     // initial check before everything else gets going
00447     CheckModemStatus();
00448
00449     // This event signals that the comm mask has been setup and initial
00450     // modem status reported.
00451     // This prevents any reads/writes until the program is ready to
00452     // start reporting events.
00453     if (!SetEvent(hSetupEvent))
00454     ErrorInComm("SetEvent (Setup Event)");
00455
00456   // wait for status changes to occur and report them every so often
00457   for ( ; !bDone ; Sleep(STATUS_CHECK_TIMEOUT))
00458   {
00459     // check and possibly report modem status
00460     CheckModemStatus();
00461
00462     // check and report event status
00463     if (bWaitingOnStatusHandle) {     // waiting on previous WaitCommEvent
00464       dwWaitResult = WaitForSingleObject(hEvent, 0);  // check event
00465       if (dwWaitResult == WAIT_OBJECT_0) {            //  event signalled
00466                 ReportStatusEvent(dwCommEvent);
00467                 bWaitingOnStatusHandle = FALSE;
00468                 ResetEvent(hEvent);
00469             }
00470         }
00471
00472         if (!bWaitingOnStatusHandle) {    // previous event isn't pending?
00473           // wait for another (or first) event
00474             if (!WaitCommEvent(comHandle, &dwCommEvent, &os)) {
00475                 if (GetLastError() != ERROR_IO_PENDING) // is Wait pending?
00476                     ErrorInComm("WaitCommEvent");
00477
00478                 bWaitingOnStatusHandle = TRUE;
00479             }
00480             else
00481                 // WaitCommEvent returned immediately
00482                 ReportStatusEvent(dwCommEvent);
00483         }
00484     }
00485
00486     CloseHandle(hEvent);
00487     OutputDebugString("Status Thread Exiting\n\r");
00488
00489     return 1;
00490 }
00491
00492
00493 /*************************************************************************\
00494 *
00495 *  FUNCTION: OutputABuffer (HANDLE, char *, DWORD)
00496 *
00497 *  PURPOSE: OutputABuffer to the console standard out
00498 *
00499 *  COMMENTS: If buffer is 0 length, then do nothing.
00500 *
00501 \*************************************************************************/
00502 void OutputABuffer(HANDLE hOut, char * lpBuf, DWORD dwBufLen)
00503 {
00504   DWORD dwWritten;
00505
00506   if (dwBufLen != 0) {
00507     if (!WriteFile(hOut, lpBuf, dwBufLen, &dwWritten, NULL))
00508       ErrorReporter("WriteFile (console) in Reader");
00509   }
00510     else
00511         OutputDebugString("Attempt to write empty buffer\n\r");
00512   return;
00513 }
00514
00515
00516 /*************************************************************************\
00517 *
00518 *  FUNCTION: ReaderProc (LPVOID)
00519 *
00520 *  PURPOSE: Thread function controls comm port reading and console output
00521 *
00522 *  COMMENTS:
00523 *
00524 \*************************************************************************/
00525 DWORD WINAPI ReaderProc(LPVOID lpV)
00526 {
00527   BOOL     bWaitingOnRead = FALSE;
00528   char     lpBuf[MAX_READ_BUFFER];
00529   DWORD      dwRead, dwRes;
00530   HANDLE     hReadEvent;
00531   OVERLAPPED ov = {0};
00532   HANDLE     hOut;  // std output
00533
00534   hOut = (HANDLE) lpV;
00535
00536   hReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
00537   if (hReadEvent == NULL)
00538     ErrorInComm("CreateEvent (ReadEvent)");
00539
00540   ov.hEvent = hReadEvent;
00541
00542   while (!bDone)
00543   {
00544     if (bWaitingOnRead) {
00545         // wait for read to finish
00546       dwRes = WaitForSingleObject(hReadEvent, READ_TIMEOUT);
00547       switch(dwRes)
00548       {
00549         case WAIT_TIMEOUT:      // read timed out
00550                     // timeouts are not reported because they happen too often
00551                     // take comments out of next line to report read timeouts
00552                     // OutputDebugString("Read timeout\n\r");
00553           break;
00554
00555         case WAIT_OBJECT_0:     // read completed
00556           if (!GetOverlappedResult(comHandle, &ov, &dwRead, TRUE)) {
00557                         if (GetLastError() == ERROR_OPERATION_ABORTED)
00558                             OutputDebugString("Read aborted\n\r");
00559                         else
00560                           ErrorInComm("GetOverlappedResult (in Reader)");
00561                     }
00562           else {
00563             // read completed successfully
00564             bWaitingOnRead = FALSE;
00565             OutputABuffer(hOut, lpBuf, dwRead);
00566             ResetEvent(hReadEvent);   // reset event for next read
00567           }
00568
00569           break;
00570
00571         default:          // wait on event failed
00572             ErrorReporter("WaitForSingleObject(hReadEvent)");
00573             break;
00574       }
00575     }
00576
00577     if (!bWaitingOnRead) {
00578             // issue read
00579       if (!ReadFile(comHandle, lpBuf, MAX_READ_BUFFER, &dwRead, &ov)) {
00580           // read failed
00581         if (GetLastError() != ERROR_IO_PENDING)   // read not delayed?
00582           ErrorInComm("ReadFile (comHandle) in Reader");
00583
00584         bWaitingOnRead = TRUE;
00585       }
00586       else {    // read completed immediately
00587         if (dwRead != 0)
00588           OutputABuffer(hOut, lpBuf, dwRead);
00589                 else
00590                     OutputDebugString("Read 0 bytes and didn't overlap.\n\r");
00591       }
00592     }
00593   }
00594
00595     CloseHandle(hReadEvent);
00596   OutputDebugString("Reader Thread Exiting\n");
00597
00598   return 1;
00599 }
00600
00601
00602 /*************************************************************************\
00603 *
00604 *  FUNCTION: WriterProc(LPVOID)
00605 *
00606 *  PURPOSE: Thread function controls console input and comm port writing
00607 *
00608 *  COMMENTS:
00609 *
00610 \*************************************************************************/
00611 DWORD WINAPI WriterProc(LPVOID lpV)
00612 {
00613   HANDLE     hIn;
00614   char       chRead;
00615   DWORD      dwRead, dwWritten;
00616   OVERLAPPED ov = {0};
00617
00618   hIn = (HANDLE) lpV;
00619
00620   while (!bDone)
00621   {
00622     // block the console read until a character key is pressed
00623     if (!ReadFile(hIn, &chRead, 1, &dwRead, NULL))
00624       ErrorInComm("ReadFile (std in) in Writer Thread");
00625
00626     // if char is actually read from the keyboard
00627     if (dwRead == 1) {
00628             // send character out comm port
00629       if (!WriteFile(comHandle, &chRead, 1, &dwWritten, &ov)) {
00630         if (GetLastError() == ERROR_IO_PENDING) {  // write is delayed
00631           // check write status and wait til complete.
00632           // can't do another write until the first one finishes.
00633           if (!GetOverlappedResult(comHandle, &ov, &dwWritten, TRUE))
00634             ErrorInComm("GetOverlappedResult(in Writer)");
00635         }
00636         else
00637           ErrorInComm("WriteFile (comHandle)");
00638       }
00639
00640       if (dwWritten != 1)
00641         OutputDebugString("Error writing character to port.\n\r");
00642     }
00643   }
00644
00645   OutputDebugString("Writer Thread Exiting\n");
00646
00647   return 1;
00648 }
00649
00650
00651 /*************************************************************************\
00652 *
00653 *  FUNCTION: ProcessIO (HANDLE, HANDLE)
00654 *
00655 *  PURPOSE: Get comm i/o going
00656 *
00657 *  COMMENTS:
00658 *
00659 \*************************************************************************/
00660 void ProcessIO(HANDLE hIn, HANDLE hOut)
00661 {
00662   DWORD dwReaderId, dwWriterId, dwStatusId, dwRes;
00663   HANDLE hReader, hWriter, hStatus;
00664     HANDLE hThreads[3];
00665
00666   // setup comm port
00667   SetupCommPort();
00668
00669     // create all threads (suspended)
00670   hReader = CreateThread( NULL,
00671                           0,
00672                           (LPTHREAD_START_ROUTINE) ReaderProc,
00673                           (LPVOID) hOut,
00674                           CREATE_SUSPENDED,
00675                           &dwReaderId);
00676   if (hReader == NULL)
00677     ErrorInComm("CreateThread (Reader)");
00678
00679   hWriter = CreateThread( NULL,
00680                           0,
00681                           (LPTHREAD_START_ROUTINE) WriterProc,
00682                           (LPVOID) hIn,
00683                           CREATE_SUSPENDED,
00684                           &dwWriterId);
00685   if (hWriter == NULL)
00686     ErrorInComm("CreateThread (Writer)");
00687
00688   hStatus = CreateThread( NULL,
00689                           0,
00690                           (LPTHREAD_START_ROUTINE) StatusProc,
00691                           (LPVOID) NULL,
00692                           CREATE_SUSPENDED,
00693                           &dwStatusId);
00694   if (hStatus == NULL)
00695     ErrorInComm("CreateThread (Status)");
00696
00697   // start status monitoring thread
00698   ResumeThread(hStatus);
00699
00700     // Comm event mask has been initialized and initial modem status reported
00701     // when hSetupEvent has been signalled.
00702     if (WaitForSingleObject(hSetupEvent, 1000) != WAIT_OBJECT_0)
00703     OutputDebugString("Setup event not set.  Proceeding anyway.\n\r");
00704
00705     CloseHandle(hSetupEvent);
00706
00707     // start reader/writer threads
00708   ResumeThread(hReader);
00709   ResumeThread(hWriter);
00710
00711     hThreads[0] = hStatus;
00712     hThreads[1] = hReader;
00713     hThreads[2] = hWriter;
00714
00715   // wait for threads to exit
00716   for (;;) {
00717         dwRes = WaitForMultipleObjects(3, hThreads, TRUE, 5000);
00718     if (dwRes == WAIT_OBJECT_0)
00719       break;
00720
00721     if (dwRes == WAIT_FAILED)
00722       ErrorInComm("WaitForMultipleObjects");
00723
00724         if (bDone && dwRes == WAIT_TIMEOUT) {
00725             if (WaitForSingleObject(hStatus, 0) == WAIT_TIMEOUT)
00726                 OutputDebugString("Status Thread didn't exit.\n\r");
00727
00728             if (WaitForSingleObject(hReader, 0) == WAIT_TIMEOUT)
00729                 OutputDebugString("Reader Thread didn't exit.\n\r");
00730
00731             if (WaitForSingleObject(hWriter, 0) == WAIT_TIMEOUT)
00732                 OutputDebugString("Writer Thread didn't exit.\n\r");
00733
00734             break;
00735         }
00736   }
00737
00738     BreakDownCommPort();
00739
00740   // clean up handles
00741
00742   CloseHandle(hReader);
00743   CloseHandle(hWriter);
00744   CloseHandle(hStatus);
00745
00746   OutputDebugString("ProcessIO Exiting\n");
00747 }
00748
00749
00750 /*************************************************************************\
00751 *
00752 *  FUNCTION: SetupCommandLineOptions(int, char *)
00753 *
00754 *  PURPOSE: Parse command line arguments
00755 *
00756 *  COMMENTS: If arguments are supplied, then use them.
00757 *            If arguments are not supplied, then use defaults.
00758 *
00759 \*************************************************************************/
00760 BOOL SetupCommandLineOptions(int cArgs, char * argv[])
00761 {
00762     int i;
00763
00764     for ( i = 0; i < cArgs; i++) {
00765         if (strchr(argv[i], '?'))
00766             return FALSE;
00767     }
00768
00769     switch(cArgs)
00770     {
00771         case 1:
00772                 strcpy(lpszPort, "COM1");   // default port
00773                 strcpy(lpszSerialSpec, "9600,n,8,1"); // default serial spec
00774                 break;
00775
00776         case 2:
00777                 strcpy(lpszPort, argv[1]);
00778                 strcpy(lpszSerialSpec, "9600,n,8,1");
00779                 break;
00780
00781         case 3:
00782                 strcpy(lpszPort, argv[1]);
00783                 strcpy(lpszSerialSpec, argv[2]);
00784                 break;
00785
00786         default:
00787                 return FALSE;
00788     }
00789
00790     return TRUE;
00791 }
00792
00793 /*************************************************************************\
00794 *
00795 *  FUNCTION: ControlHandlerProc( DWORD )
00796 *
00797 *  PURPOSE: Handle console control events
00798 *
00799 *  COMMENTS: All we do here is set our exiting flag
00800 *
00801 \*************************************************************************/
00802 BOOL WINAPI ControlHandlerProc( DWORD dwCtrlType )
00803 {
00804     // we can clean up here
00805     OutputDebugString("Control Event Handled\n\rExiting\n\r");
00806     printf("\n\n\rExiting...");
00807     bDone = TRUE;
00808
00809     return TRUE;   // don't call default handler
00810 }
00811
00812
00813
00814 /*************************************************************************\
00815 *
00816 *  FUNCTION: main(int, char *)
00817 *
00818 *  PURPOSE: Call ParseCommandLine function, Setup console mode, setup
00819 *           console control handling and start io routine
00820 *
00821 *  COMMENTS:
00822 *
00823 \*************************************************************************/
00824 int main(int argc, char * argv[])
00825 {
00826   DWORD dwOldMode, dwNewMode, dwVersion;
00827   HANDLE hStdOut, hStdIn;
00828
00829     // check if running on Win32s, if so, display notice and terminate
00830
00831     dwVersion = GetVersion();
00832     if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) ) {
00833         MessageBoxA( NULL,
00834             "This sample application will not run on Windows 3.1.\n"
00835             "This application will now terminate.",
00836             "OvComm",
00837             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00838         return 1 ;
00839     }
00840
00841     // parse command line
00842     if (!SetupCommandLineOptions(argc, argv)) {
00843         printf("Usage: comm <port identifier> <serial spec string>\n");
00844         printf("\n   example:  comm com1 9600,N,8,1\n");
00845         printf("     The serial spec string cannot contain spaces\n");
00846         printf("     The serial spec string follows the same guidelines\n");
00847         printf("       as the MS-DOS 'mode' command\n");
00848         return 0;
00849     }
00850
00851     // setup console mode and std handles
00852     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
00853   hStdIn = GetStdHandle(STD_INPUT_HANDLE);
00854
00855   if (hStdOut == hStdIn)
00856     ErrorHandler("GetStdHandle");
00857
00858   if (!GetConsoleMode(hStdIn, &dwOldMode))
00859     ErrorHandler("GetConsoleMode (old)");
00860
00861     // turn off echo and CR & ctrl-c handling; I'll do it myself.
00862   dwNewMode = dwOldMode
00863               & ~ENABLE_LINE_INPUT
00864               & ~ENABLE_ECHO_INPUT
00865               & ~ENABLE_PROCESSED_INPUT;
00866
00867   if (!SetConsoleMode(hStdIn, dwNewMode))
00868     ErrorHandler("SetConsoleMode (new)");
00869
00870     if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)ControlHandlerProc, TRUE))
00871         ErrorHandler("SetConsoleCtrlHandler");
00872
00873   ProcessIO(hStdIn, hStdOut);
00874
00875     // restore console mode
00876   if (!SetConsoleMode(hStdIn, dwOldMode))
00877     ErrorReporter("SetConsoleMode (old)");
00878
00879   return 0;
00880 }
00881
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: POLYDRAW/POLYDRAW.H Source File

  • POLYDRAW

POLYDRAW.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* polydraw.h - header file for the polydraw demonstration program. */
00013
00014
00015 /* function prototypes for the window procedures. */
00016 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00017
00018 #define MAXPOINTS  16
00019 #define NONE     -1
00020 #define HITSIZE  10
00021
00022 /* Strings to be written at the bottom of the window as instructions. */
00023 char instructions0[] =
00024     "Left mouse button places or moves points.  Right button erases.";
00025 char instructions1[] = "  default -- PT_LINETO  ";
00026 char instructions2[] = "  <shift> -- PT_MOVETO  ";
00027 char instructions3[] = "  <ctrl>  -- PT_BEZIERTO";
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PATHS/PATHS.H Source File

  • PATHS

PATHS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* paths.h - header file for the paths demonstration program. */
00013
00014
00015 /* function prototypes for the window procedures. */
00016 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00017 void DrawPath(HDC, LPRECT);
00018 BOOL NewAngleArc(HDC, int, int, DWORD, float, float);
00019
00020
00021 /* strings to write to the window as labels. */
00022 #define STROKEPATH        "StrokePath"
00023 #define FILLPATH          "FillPath"
00024 #define STROKEANDFILLWIND "StrokeAndFill, Winding"
00025 #define STROKEANDFILLALT  "StrokeAndFill, Alternate"
00026 #define CLIPPATHWIND      "ClipPath, Winding"
00027 #define CLIPPATHALT       "ClipPath, Alternate"
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/SHRSTUFF.H Source File

  • BPOINTER

SHRSTUFF.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 // These are the data structures used to change the data through the pointer.
00013
00014
00015
00016 typedef struct CHAINLIST;
00017
00018
00019 struct CHAINLIST   *clBasePt;
00020 struct CHAINLIST __based(clBasePt) *clRunning;
00021
00022 typedef struct CHAINLIST
00023 {   int iElement;
00024     struct CHAINLIST __based(clBasePt) *clNext;
00025 } CHAINLIST;
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MACROS.H Source File

  • SERVENUM
  • DLL

MACROS.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: macros.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations misc. functions
00012 //
00013
00014 #ifndef _MACROS_H
00015 #define _MACROS_H
00016
00017 #define MAX( x, y ) (x > y) ? x : y
00018 #define MIN( x, y ) (x > y) ? y : x
00019
00020 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CPL/STEREO.C Source File

  • CPL

STEREO.C

Go to the documentation of this file.
00001 /****************************************************************************
00002 *
00003 *
00004 *    PROGRAM: Stereo.c
00005 *
00006 *    PURPOSE: Example of a Control Panel Application
00007 *
00008 *    FUNCTIONS:
00009 *
00010 *        DllMain()
00011 *        InitStereoApplet()
00012 *        TermStereoApplet()
00013 *        CPIApplet()
00014 *        AmpDlgProc()
00015 *        TermDlgProc()
00016 *        TunerDlgProc()
00017 *
00018 *    COMMENTS:
00019 *
00020 *    The following code sample shows the CPlApplet function for a DLL containing
00021 *    three Control Panel applications that set preferences for a component stereo
00022 *    system attached to the computer. The sample uses an application-defined
00023 *    StereoApplets array that contains three structures, each corresponding to
00024 *    one of the Control Panel applications. Each structure contains all the
00025 *    information required by the CPL_NEWINQUIRE message, as well as the dialog
00026 *    box template and dialog box procedure required by the CPL_DBLCLK message.
00027 *    The code demonstrates how to fill the structures in the StereoApplets array.
00028 *
00029 ****************************************************************************/
00030
00031 #include <windows.h>
00032 #include <cpl.h>
00033 #include "stereo.h"
00034
00035 typedef struct tagApplets
00036 {
00037     int icon;           // icon resource identifier
00038     int namestring;     // name-string resource identifier
00039     int descstring;     // description-string resource identifier
00040     int dlgtemplate;    // dialog box template resource identifier
00041     DLGPROC dlgfn;      // dialog box procedure
00042 } APPLETS;
00043
00044 APPLETS StereoApplets[] =
00045 {
00046     AMP_ICON, AMP_NAME, AMP_DESC, AMP_DLG, AmpDlgProc,
00047     TUNER_ICON, TUNER_NAME, TUNER_DESC, TUNER_DLG, TunerDlgProc,
00048     TAPE_ICON, TAPE_NAME, TAPE_DESC, TAPE_DLG, TapeDlgProc,
00049
00050 };
00051
00052 #define NUM_APPLETS (sizeof(StereoApplets)/sizeof(StereoApplets[0]))
00053
00054
00055 HANDLE hModule = NULL;
00056
00057 char szCtlPanel[30];
00058
00059 /****************************************************************************
00060 *
00061 *    FUNCTION: DllMain(PVOID, ULONG, PCONTEXT)
00062 *
00063 *    PURPOSE: Win 32 Initialization DLL
00064 *
00065 *    COMMENTS:
00066 *
00067 *
00068 ****************************************************************************/
00069
00070 BOOL WINAPI DllMain(
00071 IN PVOID hmod,
00072 IN ULONG ulReason,
00073 IN PCONTEXT pctx OPTIONAL)
00074 {
00075     if (ulReason != DLL_PROCESS_ATTACH)
00076     {
00077         return TRUE;
00078     }
00079     else
00080     {
00081         hModule = hmod;
00082     }
00083
00084     return TRUE;
00085
00086     UNREFERENCED_PARAMETER(pctx);
00087 }
00088
00089
00090 /****************************************************************************
00091 *
00092 *    FUNCTION: InitStereoApplet(HWND)
00093 *
00094 *    PURPOSE: loads the caption string for the Control Panel
00095 *
00096 *    COMMENTS:
00097 *
00098 *
00099 ****************************************************************************/
00100
00101 BOOL InitStereoApplet (HWND hwndParent)
00102 {
00103     LoadString (hModule, CPCAPTION, szCtlPanel, sizeof(szCtlPanel));
00104
00105     return TRUE;
00106
00107     UNREFERENCED_PARAMETER(hwndParent);
00108 }
00109
00110
00111 /****************************************************************************
00112 *
00113 *    FUNCTION: TermStereoApplet()
00114 *
00115 *    PURPOSE: termination procedure for the stereo applets
00116 *
00117 *    COMMENTS:
00118 *
00119 *
00120 ****************************************************************************/
00121
00122 void TermStereoApplet()
00123 {
00124     return;
00125 }
00126
00127
00128
00129 /****************************************************************************
00130 *
00131 *    FUNCTION: CPIApplet(HWND, UINT, LONG, LONG)
00132 *
00133 *    PURPOSE: Processes messages for control panel applets
00134 *
00135 *    COMMENTS:
00136 *
00137 *
00138 ****************************************************************************/
00139 LONG CALLBACK CPlApplet (hwndCPL, uMsg, lParam1, lParam2)
00140 HWND hwndCPL;       // handle of Control Panel window
00141 UINT uMsg;          // message
00142 LONG lParam1;       // first message parameter
00143 LONG lParam2;       // second message parameter
00144 {
00145     int iApplet;
00146     LPNEWCPLINFO lpNewCPlInfo;
00147     static iInitCount = 0;
00148
00149     switch (uMsg) {
00150         case CPL_INIT:              // first message, sent once
00151             if (!iInitCount)
00152             {
00153                 if (!InitStereoApplet(hwndCPL))
00154                     return FALSE;
00155             }
00156             iInitCount++;
00157             return TRUE;
00158
00159         case CPL_GETCOUNT:          // second message, sent once
00160             return (LONG)NUM_APPLETS;
00161             break;
00162
00163         case CPL_NEWINQUIRE:        // third message, sent once per app
00164             lpNewCPlInfo = (LPNEWCPLINFO) lParam2;
00165
00166             iApplet = (int)(LONG)lParam1;
00167             lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO);
00168             lpNewCPlInfo->dwFlags = 0;
00169             lpNewCPlInfo->dwHelpContext = 0;
00170             lpNewCPlInfo->lData = 0;
00171             lpNewCPlInfo->hIcon = LoadIcon (hModule,
00172                 (LPCTSTR) MAKEINTRESOURCE(StereoApplets[iApplet].icon));
00173             lpNewCPlInfo->szHelpFile[0] = '\0';
00174
00175             LoadString (hModule, StereoApplets[iApplet].namestring,
00176                         lpNewCPlInfo->szName, 32);
00177
00178             LoadString (hModule, StereoApplets[iApplet].descstring,
00179                         lpNewCPlInfo->szInfo, 64);
00180             break;
00181
00182         case CPL_SELECT:            // application icon selected
00183             break;
00184
00185
00186         case CPL_DBLCLK:            // application icon double-clicked
00187             iApplet = (int)(LONG)lParam1;
00188             MessageBeep (MB_ICONEXCLAMATION);
00189
00190             DialogBox (hModule,
00191                        MAKEINTRESOURCE(StereoApplets[iApplet].dlgtemplate),
00192                        hwndCPL,
00193                        StereoApplets[iApplet].dlgfn);
00194             break;
00195
00196          case CPL_STOP:              // sent once per app. before CPL_EXIT
00197             break;
00198
00199          case CPL_EXIT:              // sent once before FreeLibrary called
00200             iInitCount--;
00201             if (!iInitCount)
00202                 TermStereoApplet();
00203             break;
00204
00205          default:
00206             break;
00207     }
00208     return 0;
00209 }
00210
00211 /****************************************************************************
00212 *
00213 *    FUNCTION: AmpDlgProc
00214 *
00215 *    PURPOSE: Processes messages sent to the Amp applet.
00216 *
00217 *    COMMENTS:
00218 *
00219 *    This dialog simply puts up a box and has an OK key.  It doesn't
00220 *    do anything except display.
00221 *
00222 ****************************************************************************/
00223 BOOL APIENTRY AmpDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
00224 {
00225     switch (message)
00226     {
00227       case WM_INITDIALOG:
00228           return (TRUE);
00229
00230       case WM_COMMAND:
00231             if (LOWORD(wParam))
00232             {
00233             EndDialog(hDlg, TRUE);
00234             return (TRUE);
00235           }
00236           break;
00237     }
00238     return (FALSE);
00239 }
00240
00241 /****************************************************************************
00242 *
00243 *    FUNCTION: TunerDlgProc
00244 *
00245 *    PURPOSE: Processes messages sent to the Tuner applet.
00246 *
00247 *    COMMENTS:
00248 *
00249 *    This dialog simply puts up a box and has an OK key.  It doesn't
00250 *    do anything except display.
00251 *
00252 ****************************************************************************/
00253 BOOL APIENTRY TunerDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
00254 {
00255     switch (message)
00256     {
00257       case WM_INITDIALOG:
00258           return (TRUE);
00259
00260       case WM_COMMAND:
00261             if (LOWORD(wParam))
00262             {
00263             EndDialog(hDlg, TRUE);
00264             return (TRUE);
00265           }
00266           break;
00267     }
00268     return (FALSE);
00269 }
00270
00271 /****************************************************************************
00272 *
00273 *    FUNCTION: TapeDlgProc
00274 *
00275 *    PURPOSE: Processes messages sent to the Tape applet.
00276 *
00277 *    COMMENTS:
00278 *
00279 *    This dialog simply puts up a box and has an OK key.  It doesn't
00280 *    do anything except display.
00281 *
00282 ****************************************************************************/
00283 BOOL APIENTRY TapeDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
00284 {
00285     switch (message)
00286     {
00287       case WM_INITDIALOG:
00288           return (TRUE);
00289
00290       case WM_COMMAND:
00291             if (LOWORD(wParam))
00292             {
00293             EndDialog(hDlg, TRUE);
00294             return (TRUE);
00295           }
00296           break;
00297     }
00298     return (FALSE);
00299 }
00300
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SETINFO/SETINFO.C Source File

  • SETINFO

SETINFO.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************************\
00013 *  PROGRAM: setinfo.c
00014 *
00015 *  PURPOSE:
00016 *
00017 *    To demonstrate queries and setting file information much as the
00018 *    OS/2 API's DosQFileInfo() and DosSetFileInfo().
00019 *
00020 *  GLOBAL VARIABLES:
00021 *
00022 *    HANDLE hInst;  - Instance handle.
00023 *
00024 *    HWND   hWnd;   - Client window handle.
00025 *
00026 *    HWND   hWndDlg;- Window handle to upper dialog box.
00027 *
00028 *    HWND   hWndFileDlg;
00029 *                   - Window handle to lower dialog box.
00030 *
00031 *    DWORD  StepTime;
00032 *                   - Time in ms., used to control the speed of reporting
00033 *                     return codes in the upper dialog box.
00034 *
00035 *  FUNCTIONS:
00036 *
00037 *    WinMain()      - Initializes the window, and process the message loop.
00038 *    MainWndProc()  - To handle the messages to the main window.
00039 *    StatusDlgProc()- To handle messages to the Status Dialog (upper) box.
00040 *    FileDlgProc()  - To handle messages to the File Dialog (lower) box.
00041 *    RepStat()      - To calculate return codes and to send results as
00042 *                     messages to the StatusDlgProc()
00043 *
00044 *  COMMENTS:
00045 *
00046 *    Overview:
00047 *      This sample captures and sets a files date/time, size, and
00048 *      attributes information (note it does not *set* file size
00049 *      information).  It also reports API return code status
00050 *      information.
00051 *
00052 *    To Use:
00053 *      Enter a file name into the appropriate edit field, and click on
00054 *      the Get Info. button.  File information will be retrieved and
00055 *      placed in the various edit fields and check buttons.  To set
00056 *      file information, modify the values in the Time and Date edit
00057 *      fields, and click the Set Info. button.  To set file attributes,
00058 *      set the approprate check boxes, and click on the Set Attr. button.
00059 *      Note this application does not check for rediculous Date and Time
00060 *      information, and does not understand i.e. values before 1980 or after
00061 *      2099.  The API are left to deal with such values as best they
00062 *      can.
00063 *
00064 *      As the buttons are clicked the code sends return code status
00065 *      information to be reported in the upper dialog box.  The user
00066 *      can leave this reporting to be done at default time ( 0ms. Sleep
00067 *      between each API), or can enter a time in the appropriate box
00068 *      and clicking the Set Time button.  This will put a Sleep between
00069 *      the API call so that the user can more easily read the return
00070 *      codes.
00071 *
00072 *    Time Conversion:
00073 *      Note that GetFileTime() and SetFileTime() use 64 bit FILETIME
00074 *      structures.  These structure consist of two DWORD fields: which
00075 *      represent file time in hundreds of nano-seconds.  This file time
00076 *      can be converted into DosDate time (or back again) with the
00077 *      FileTimeToDosDateTime() and DosDateTimeToFileTime() calls.  These
00078 *      calls use WORD values representing DosDate and DosTime.  The
00079 *      online Windows .hlp files will tell you how these WORDs break
00080 *      down into days, months, hours, seconds, etc.  This sample uses
00081 *      a combination of masking and shifting to extract the values
00082 *      from the file (see the FileDlgProc() and the symbolic constants
00083 *      mask defined in the header file).  Other points of interest are
00084 *      that seconds are stored in 2 second increments (1-29), and that
00085 *      years are represented from 1980 (meaning i.e. 1992 will be
00086 *      be represented by 12).
00087 *
00088 *
00089 \*************************************************************************/
00090
00091 #include <windows.h>
00092 #include <stdlib.h>
00093 #include "setinfo.h"
00094
00095
00096 HANDLE hInst;
00097 HWND   hWnd, hWndDlg, hWndFileDlg;
00098 DWORD  StepTime;
00099
00100
00101
00102 /*************************************************************************\
00103 *
00104 *  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00105 *
00106 *  PURPOSE:  Calls initialization function, processes message loop.
00107 *
00108 *  COMMENTS: A fairly standard WinMain, with the exception that it
00109 *            creates two modeless dialog boxes which fit over the window.
00110 *            Note the use of IsDialogMessage in the message loop.  This
00111 *            call not only returns a boolean value, but also processes
00112 *            the message if it is a dialog box message; otherwise the
00113 *            message falls through to the body of the loop to be translated
00114 *            and dispatched.
00115 *
00116 \*************************************************************************/
00117
00118 int APIENTRY WinMain (HINSTANCE hInstance,
00119                       HINSTANCE hPrevInstance,
00120                       LPSTR  lpCmdLine,
00121                       int    nCmdShow)
00122
00123
00124 {
00125
00126   MSG  msg;
00127   WNDCLASS wc;
00128   RECT rect;
00129
00130   UNREFERENCED_PARAMETER( lpCmdLine );
00131   UNREFERENCED_PARAMETER( hPrevInstance );
00132
00133   hInst = hInstance;
00134
00135   wc.style = 0;                          // Replaces CS_SIZEREDRAW.
00136   wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
00137   wc.cbClsExtra = 0;                     // No room reserved for extra data.
00138   wc.cbWndExtra = 0;
00139   wc.hInstance = hInstance;
00140   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00141   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
00142   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00143   wc.lpszMenuName = "";
00144   wc.lpszClassName = "SetInfoWClass";
00145
00146   RegisterClass(&wc);
00147
00148   hWnd = CreateWindow ("SetInfoWClass",
00149                        "Set File Info. Sample",
00150                        WS_OVERLAPPEDWINDOW,
00151                        CW_USEDEFAULT,
00152                        CW_USEDEFAULT,
00153                        CW_USEDEFAULT,
00154                        CW_USEDEFAULT,
00155                        NULL,
00156                        NULL,
00157                        hInstance,
00158                        NULL);
00159
00160   hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, (DLGPROC)StatusDlgProc);
00161   hWndFileDlg = CreateDialog (hInst, "FileDlg",   hWnd, (DLGPROC)FileDlgProc);
00162
00163   GetClientRect (hWnd, &rect);
00164   SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
00165   ShowWindow  (hWndDlg,  SW_SHOW);
00166   ShowWindow  (hWndFileDlg, SW_SHOW);
00167   ShowWindow  (hWnd, nCmdShow);
00168
00169   while (GetMessage (&msg, NULL, 0, 0))
00170     if (!IsDialogMessage (hWndDlg, &msg)
00171         && !IsDialogMessage (hWndFileDlg, &msg))
00172       {
00173        DispatchMessage (&msg);   // Dispatch message to window.
00174       }
00175
00176   return (msg.wParam);           // Returns value from PostQuitMessage.
00177
00178 }
00179
00180 /*************************************************************************\
00181 *
00182 *  FUNCTION:  MainWndProc (HWND, UINT, UINT, LONG)
00183 *
00184 *  PURPOSE:   To process messages.  To launch client and server threads
00185 *             as appropriate.
00186 *
00187 *  VARIABLES USED:
00188 *
00189 *    - hWndDlg:
00190 *             Global window handle for the upper dialog box.
00191 *
00192 *    - hWndFileDlg:
00193 *             Global window handle for the lower dialog box.
00194 *
00195 *  MESSAGES:
00196 *
00197 *    WM_DESTROY      - Standard, destroys the window.
00198 *    WM_SIZE         - Sends messages to the two dialog boxes so that they
00199 *                      maintain their relative size to the client window.
00200 *
00201 *  CALLED BY:
00202 *
00203 *    WinMain();
00204 *
00205 \*************************************************************************/
00206
00207 LONG APIENTRY MainWndProc (HWND hwnd,
00208                            UINT message,
00209                            UINT wParam,
00210                            LONG lParam)
00211 {
00212   switch (message)
00213       {
00214
00215         case WM_SIZE :
00216           SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
00217           SetWindowPos (hWndFileDlg, NULL, 0,DIALOGHEIGHT, LOWORD(lParam), HIWORD(lParam), 0);
00218           return (0);
00219
00220         case WM_DESTROY :
00221             PostQuitMessage (0);
00222             return (0);
00223
00224        }
00225     return DefWindowProc (hwnd, message, wParam, lParam);
00226 }
00227
00228 /*************************************************************************\
00229 *
00230 *  FUNCTION:  StatusDlgProc (HWND, UINT, UINT, LONG)
00231 *
00232 *  PURPOSE:   To process messages for the upper dialog box.
00233 *
00234 *  VARIABLES USED:
00235 *
00236 *    - StepTime:
00237 *             A global DWORD holding the value of the sleep time between
00238 *             API calls.
00239 *
00240 *    - bTranslated:
00241 *             A local BOOL needed for GetDlgItemInt().
00242 *
00243 *  MESSAGES:
00244 *
00245 *    WM_INITDIALOG:  - Sets a "0" in the time edit field IDE_TIME.  This
00246 *                      is to indicate to the user that the default time
00247 *                      set to sleep between reporting the results of
00248 *                      API calls is set to 0.
00249 *
00250 *    WM_REPSTAT:     - A user defined message.  This message uses wParam
00251 *                      as a pointer to a string holding an API i.e.
00252 *                      "CreateFile()".  It uses lParam to hold a string
00253 *                      reporting the value of returned by the API i.e.
00254 *                      "ERROR_ACCESS_DENIED", or a number if the return
00255 *                      value isn't identified in RepStat().  The code
00256 *                      then places these strings in the IDE_API and
00257 *                      IDE_REPSTAT edit fields.
00258 *
00259 *    WM_COMMAND
00260 *
00261 *      IDM_STEP:     - Captures the time value in the IDE_TIME edit
00262 *                      field, and then sets that value into the
00263 *                      global DWORD StepTime.  This value sets
00264 *                      a sleep time inbetween reporting the results of
00265 *                      each API (making it easier for the user to read).
00266 *
00267 *  COMMENTS:
00268 *
00269 *    This procedure controls the upper dialog box of the application.
00270 *    The purpose of this box is to report on the API being used by
00271 *    the lower box, and it's return code.  It also allows you to control
00272 *    the speed that the application steps through these calls.  This is
00273 *    basically a error checking/debugging feature, but it also lends an
00274 *    intuitive look at the API being used.
00275 *
00276 \*************************************************************************/
00277
00278 LONG APIENTRY StatusDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
00279 {
00280   BOOL bTranslated;
00281
00282   UNREFERENCED_PARAMETER (wParam);
00283   UNREFERENCED_PARAMETER (lParam);
00284
00285   switch (message)
00286     {
00287     case WM_INITDIALOG:
00288       StepTime = 0;
00289       SetDlgItemInt (hDlg, IDE_TIME, StepTime, FALSE);
00290       return (0);
00291
00292     case WM_REPSTAT:
00293       SetDlgItemText (hDlg, IDE_API,(LPTSTR) wParam);
00294       SetDlgItemText (hDlg, IDE_RETSTAT, (LPTSTR)lParam);
00295       return (0);
00296
00297     case WM_COMMAND:
00298       switch (LOWORD(wParam))
00299        {
00300        case IDB_STEP:
00301            StepTime = GetDlgItemInt (hDlg, IDE_TIME, &bTranslated, FALSE);
00302        }
00303     }
00304   return (0);
00305 }
00306
00307 /*************************************************************************\
00308 *
00309 *  FUNCTION:  FileDlgProc (HWND, UINT, UINT, LONG)
00310 *
00311 *  PURPOSE:   To process the messages to the lower dialog box.
00312 *
00313 *  VARIABLES USED:
00314 *
00315 *    - fileName:
00316 *             A local CHAR array used to capture the text from the
00317 *             IDE_FILENAME edit field.
00318 *
00319 *    - hFile: Local file handle.
00320 *
00321 *    - retCode:
00322 *             Local DWORD used to trap API return codes.
00323 *
00324 *    - ftCreation,
00325 *    - ftAccessed,
00326 *    - ftWrittenTo:
00327 *             Local FILETIME structures.
00328 *
00329 *    - wDosDate,
00330 *    - wDosTime:
00331 *             Local WORDs, used to hold the values converted from the
00332 *             FILETIME structures converted by FileTimeToDosDateTime()
00333 *             and DosDateTimeToFileTime().
00334 *
00335 *    - DD[],
00336 *    - MM[],
00337 *    - YY[],
00338 *    - Mn[],
00339 *    - SS[],
00340 *    - HH[]:  Local CHAR arrays used to trap the values in various
00341 *             edit fields representing date and time values.
00342 *
00343 *    - dwFileSize:
00344 *             Local DWORD holding file size.
00345 *
00346 *    - lpsFileSize[]:
00347 *             Local CHAR array used to trap the string from the IDE_SIZE
00348 *             edit field.
00349 *
00350 *    - dwFileAttr:
00351 *             Local DWORD holding the file attributes.
00352 *
00353 *    - hDlg:  Input parameter, handle to the dialog box.
00354 *
00355 *  MESSAGES:
00356 *
00357 *    WM_COMMAND
00358 *
00359 *      IDB_ATTR:
00360 *             It initializes the variable to hold the file attributes,
00361 *             dwFileAttr, and then traps the checked states of the
00362 *             dialog boxes checked buttons.  If a box is found to be
00363 *             checked, then the appropriate file attribute flag is
00364 *             OR'd into dwFileAttr.  When all of the attribute values
00365 *             have been collected, these attributes are set to the file
00366 *             listed in IDE_FILENAME.
00367 *
00368 *      IDB_SET:
00369 *             This collects the values from the various time and date
00370 *             edit fields, converts them into system time, and sets
00371 *             them to the file listed in IDE_FILENAME.  Basically the
00372 *             technique is to 1) get the values from the edit fields;
00373 *             2) shift them to their correct location in the WORD; and
00374 *             3) OR them together into a single WORD.
00375 *
00376 *      IDB_OPENFILE:
00377 *             This gets the date, time, size, and attribute information
00378 *             from the file listed in IDE_FILENAME.  It converts the
00379 *             values appropriately and puts them into the various
00380 *             edit fields and check buttons.  Again, to do time and date
00381 *             conversions, you must AND the values returned from
00382 *             GetFileTime() with certain masks to let the appropriate bits
00383 *             fall through from the WORD (see the mask and shift values
00384 *             in the setinfo.h file), and shift them to the low order
00385 *             bit to get the new values.  This is done in the wsprintf()
00386 *             call's parameter list.
00387 *
00388 *  CALLS TO:
00389 *
00390 *    RepStat();
00391 *
00392 *  COMMENTS:
00393 *    The basic function of this box is to capture and set file information,
00394 *    and to send messages to the upper dialog box via RepStat() to report
00395 *    return code information.  Special characteristics of this function
00396 *    is how to get and set file information and attributes, and how to
00397 *    convert Time and Date information.
00398 *
00399 \*************************************************************************/
00400
00401 LONG APIENTRY FileDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
00402 {
00403   CHAR     fileName[100];
00404   HANDLE   hFile;
00405   DWORD    retCode = 0;
00406   FILETIME ftCreation, ftAccessed, ftWrittenTo;
00407   WORD     wDosDate, wDosTime;
00408   CHAR     DD[3], MM[3], YY[3], HH[3], Mn[3], SS[3];
00409   DWORD    dwFileSize;
00410   CHAR     lpsFileSize[10];
00411   DWORD    dwFileAttr;
00412
00413   UNREFERENCED_PARAMETER (wParam);
00414   UNREFERENCED_PARAMETER (lParam);
00415
00416   switch (message)
00417     {
00418
00419     case WM_COMMAND :
00420       switch (LOWORD(wParam))
00421         {
00422         case IDB_ATTR:
00423
00424           dwFileAttr = 0;
00425
00426           if (IsDlgButtonChecked (hDlg, IDC_HIDE))
00427              dwFileAttr |= FILE_ATTRIBUTE_HIDDEN;
00428
00429           if (IsDlgButtonChecked (hDlg, IDC_NORMAL))
00430              dwFileAttr |= FILE_ATTRIBUTE_NORMAL;
00431
00432           if (IsDlgButtonChecked (hDlg, IDC_ARC))
00433              dwFileAttr |= FILE_ATTRIBUTE_ARCHIVE;
00434
00435           if (IsDlgButtonChecked (hDlg, IDC_SYSTEM))
00436              dwFileAttr |= FILE_ATTRIBUTE_SYSTEM;
00437
00438           if (IsDlgButtonChecked (hDlg, IDC_READ))
00439              dwFileAttr |= FILE_ATTRIBUTE_READONLY;
00440
00441           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
00442
00443           retCode = SetFileAttributes (fileName, dwFileAttr);
00444             RepStat ("SetFileAttributes()", retCode);
00445
00446           return (0);
00447
00448         case IDB_SET:
00449
00450           GetDlgItemText (hDlg, IDE_YEAR,  YY, 3);
00451           GetDlgItemText (hDlg, IDE_DAY,   DD, 3);
00452           GetDlgItemText (hDlg, IDE_MONTH, MM, 3);
00453           wDosDate = (WORD)((atoi(YY) - 80)<<YRSHIFT |
00454                              atoi(MM)<<MONSHIFT |
00455                              atoi(DD)<<DAYSHIFT);
00456
00457           GetDlgItemText (hDlg, IDE_HOURS,   HH, 3);
00458           GetDlgItemText (hDlg, IDE_SECONDS, SS, 3);
00459           GetDlgItemText (hDlg, IDE_MINUTES, Mn, 3);
00460           wDosTime = (WORD)((atoi(SS) / 2)<< SECSHIFT |
00461                              atoi(Mn)<<MINSHIFT |
00462                              atoi(HH)<<HRSHIFT);
00463
00464           retCode = DosDateTimeToFileTime (wDosDate, wDosTime, &ftWrittenTo);
00465             RepStat("DosDateTimeToFileTime()", retCode);
00466
00467           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
00468           hFile = CreateFile (fileName,
00469                               GENERIC_READ | GENERIC_WRITE,
00470                               FILE_SHARE_READ | FILE_SHARE_WRITE,
00471                               NULL,
00472                               OPEN_EXISTING,
00473                               FILE_ATTRIBUTE_NORMAL,
00474                               NULL);
00475           if (RepStat("CreateFile()", (DWORD)hFile))
00476             return (0);
00477
00478
00479           retCode = SetFileTime (hFile, NULL, NULL, &ftWrittenTo);
00480             RepStat("SetFileTime()", retCode);
00481
00482           CloseHandle (hFile);
00483           return (0);
00484
00485
00486         case IDB_OPENFILE :
00487           GetDlgItemText (hDlg, IDE_FILENAME, fileName, 100);
00488           hFile = CreateFile (fileName,
00489                               GENERIC_READ,
00490                               FILE_SHARE_READ | FILE_SHARE_WRITE,
00491                               NULL,
00492                               OPEN_EXISTING,
00493                               FILE_ATTRIBUTE_NORMAL,
00494                               NULL);
00495           if (RepStat("CreateFile()", (DWORD)hFile))
00496             return (0);
00497
00498           (BOOL)retCode = GetFileTime (hFile,
00499                                        &ftCreation,
00500                                        &ftAccessed,
00501                                        &ftWrittenTo);
00502           RepStat( "GetFileTime()", retCode);
00503
00504           (BOOL)retCode = FileTimeToDosDateTime( &ftWrittenTo,
00505                                                  &wDosDate,
00506                                                  &wDosTime);
00507           RepStat("FileTimeToDosDateTime()", retCode);
00508
00509           dwFileSize = GetFileSize (hFile, NULL);
00510           RepStat("GetFileSize()", dwFileSize);
00511
00512
00513           wsprintf(YY, "%02d", ((wDosDate & YRMASK) >> YRSHIFT ) + 80);
00514           SetDlgItemText (hDlg, IDE_YEAR, YY);
00515
00516           wsprintf(MM, "%02d", ((wDosDate & MONMASK) >> MONSHIFT));
00517           SetDlgItemText (hDlg, IDE_MONTH, MM);
00518
00519           wsprintf(DD, "%02d", ((wDosDate & DAYMASK) >> DAYSHIFT) );
00520           SetDlgItemText (hDlg, IDE_DAY, DD);
00521
00522           wsprintf(SS, "%02d", ((wDosTime & SECMASK) >> SECSHIFT ) * 2);
00523           SetDlgItemText (hDlg, IDE_SECONDS, SS);
00524
00525           wsprintf(Mn, "%02d", ((wDosTime & MINMASK) >> MINSHIFT));
00526           SetDlgItemText (hDlg, IDE_MINUTES, Mn);
00527
00528           wsprintf(HH, "%02d", (DWORD)(wDosTime & HRMASK) >> HRSHIFT );
00529           SetDlgItemText (hDlg, IDE_HOURS, HH);
00530
00531           wsprintf(lpsFileSize, "%d", dwFileSize);
00532           SetDlgItemText (hDlg, IDE_SIZE, lpsFileSize);
00533
00534           dwFileAttr = GetFileAttributes (fileName);
00535             RepStat("GetFileAttributes()", dwFileAttr);
00536
00537           if (dwFileAttr & FILE_ATTRIBUTE_NORMAL)
00538             CheckDlgButton (hDlg, IDC_NORMAL, TRUE);
00539           else
00540             CheckDlgButton (hDlg, IDC_NORMAL, FALSE);
00541
00542           if (dwFileAttr & FILE_ATTRIBUTE_READONLY)
00543             CheckDlgButton (hDlg, IDC_READ, TRUE);
00544           else
00545             CheckDlgButton (hDlg, IDC_READ, FALSE);
00546
00547           if (dwFileAttr & FILE_ATTRIBUTE_HIDDEN)
00548             CheckDlgButton (hDlg, IDC_HIDE, TRUE);
00549           else
00550             CheckDlgButton (hDlg, IDC_HIDE, FALSE);
00551
00552           if (dwFileAttr & FILE_ATTRIBUTE_SYSTEM)
00553             CheckDlgButton (hDlg, IDC_SYSTEM, TRUE);
00554           else
00555             CheckDlgButton (hDlg, IDC_SYSTEM, FALSE);
00556
00557           if (dwFileAttr & FILE_ATTRIBUTE_ARCHIVE)
00558             CheckDlgButton (hDlg, IDC_ARC, TRUE);
00559           else
00560             CheckDlgButton (hDlg, IDC_ARC, FALSE);
00561
00562           CloseHandle (hFile);
00563
00564           return (0);
00565         }
00566     }
00567   return (0);
00568 }
00569
00570 /*************************************************************************\
00571 *
00572 *  FUNCTION:  RepStat (CHAR *, DWORD)
00573 *
00574 *  PURPOSE:   To report return code information to the upper dialog box.
00575 *
00576 *  VARIABLES USED:
00577 *
00578 *    - TempBufW[],
00579 *    - TempBufL[]:
00580 *             Local CHAR arrays used to set the lParam and wParam of
00581 *             the WM_REPSTAT message.
00582 *
00583 *    - StepTime:
00584 *             Global DWORD representing the amount of sleep time chosen
00585 *             by the user.
00586 *
00587 *  CALLED BY:
00588 *
00589 *    FileDlgProc();
00590 *
00591 *  COMMENTS:
00592 *
00593 *    This function receives a string representing an API, and a DWORD
00594 *    representing it's return code value.  It checks the return code to
00595 *    see if it indicates an error.  If so, GetLastError is called to find
00596 *    the extended error information; if not, then retCode is set to 0.
00597 *    The case statement is used to exchange the retCode value for
00598 *    it's more intuitive string counterpart.  If no counterpart
00599 *    is listed, the function just sends the number value in string
00600 *    form.  Note that retCode 0 is just sent as a string number.
00601 *    Once the function drops from the switch statment, it sends the
00602 *    user define WM_REPSTAT message to the upper dialog box with the
00603 *    API and retCode information.  It will then enter a Sleep of a
00604 *    duration determined by the global StepTime value (set by the
00605 *    user through and edit field.  The function returns a boolean
00606 *    value so that the calling procedure can determine if it wants
00607 *    to continue processing or break.
00608 *
00609 \*************************************************************************/
00610
00611
00612 BOOL RepStat (CHAR *API, DWORD retCode)
00613 {
00614   CHAR TempBufW[40];
00615   CHAR TempBufL[40];
00616
00617   wsprintf(TempBufW, API);
00618
00619   if ((int)retCode <= 0 )
00620     retCode = GetLastError();
00621   else
00622     retCode = 0;
00623
00624   if (retCode)
00625     MessageBeep(0);
00626
00627   switch (retCode)
00628     {
00629     case ERROR_INVALID_FUNCTION:   // 1L
00630       wsprintf(TempBufL, "ERROR_INVALID_FUNCTION");
00631       break;
00632
00633     case ERROR_FILE_NOT_FOUND:     // 2L
00634       wsprintf(TempBufL, "ERROR_FILE_NOT_FOUND");
00635       break;
00636
00637     case ERROR_ACCESS_DENIED:      // 5L
00638       wsprintf(TempBufL, "ERROR_ACCESS_DENIED");
00639       break;
00640
00641     case ERROR_INVALID_HANDLE:     // 6L
00642       wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
00643       break;
00644
00645     case ERROR_INVALID_PARAMETER:  // 87L
00646       wsprintf(TempBufL, "ERROR_INVALID_HANDLE");
00647       break;
00648
00649     case ERROR_INVALID_NAME:       // 123L
00650       wsprintf(TempBufL, "ERROR_INVALID_NAME");
00651       break;
00652
00653     default:
00654       wsprintf(TempBufL, "%d", retCode);
00655     }
00656
00657   SendMessage (hWndDlg, WM_REPSTAT, (DWORD)TempBufW, (LONG)TempBufL);
00658   Sleep( StepTime );
00659
00660   return (retCode != 0);
00661 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/DEBUG.C Source File

  • NTSD

DEBUG.C

Go to the documentation of this file.
00001 /******************************Module*Header*******************************\
00002 * Module Name: debug.c
00003 *
00004 * Debugger extension for dumping the INFO structure in NTSD
00005 *
00006 * Created: 24-Feb-1992 20:47:03
00007 * Author: Petrus Wong
00008 *
00009 * Copyright (c) 1990-1996 Microsoft Corporation
00010 *
00011 * 1. Place the DLL in the correct path
00012 * 2. Run NTSD -d mdi
00013 * 3. Upon NTSD prompt, do
00014 *       !debug.dinfo address
00015 *       where address is the address of Info
00016 *
00017 * Dependencies:
00018 *
00019 *   (#defines)
00020 *   (#includes)
00021 *
00022 \**************************************************************************/
00023 #include <stdarg.h>
00024 #include <stdio.h>
00025
00026 #include <stddef.h>
00027 #include <windows.h>
00028 #include <winerror.h>
00029
00030 #include <excpt.h>
00031
00032 typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
00033
00034 #include <ntsdexts.h>
00035 #include "mditypes.h"
00036
00037 //
00038 // don't use try/except here.  Otherwise, mip2coff -c chokes with the
00039 // following fatal error on MIPS:
00040 //      tried to get local variable absolute addr with no procedure
00041 //
00042 // NTSD will catch the fault anyway
00043 //
00044 // Alternatively, we can get rid of the -c switch on mip2coff in the
00045 // module that use try/except, but we won't have any locals for the module
00046 //
00047 // Petrus Wong 05-Oct-1992
00048 //
00049 // We use mcl now which eliminates the need for mip2coff so we can use
00050 // try/except again
00051 //
00052 // Petrus Wong 10-Feb-1993
00053 //
00054 #define move(dst, src)\
00055 try {\
00056     ReadProcessMemory(hCurrentProcess, (LPVOID)(src), &(dst), sizeof(dst), NULL);\
00057 } except (EXCEPTION_EXECUTE_HANDLER) {\
00058     return;\
00059 }
00060
00061 /******************************Public*Routine******************************\
00062 *
00063 * DllMain
00064 *
00065 * Effects:   DllMain is called by Windows when
00066 *            the DLL is initialized, Thread Attached, and other times.
00067 *
00068 * Warnings:  The DllMain function should perform additional initialization
00069 *            tasks required by the DLL.  In this example, no initialization
00070 *            tasks are required.  DllMain should return a value of 1 if
00071 *            the initialization is successful.
00072 *
00073 * History:
00074 *  24-Feb-1992 -by- Petrus Wong
00075 * Wrote it.
00076 \**************************************************************************/
00077
00078 BOOL  WINAPI DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
00079 {
00080     return 1;
00081   UNREFERENCED_PARAMETER(hInst);
00082   UNREFERENCED_PARAMETER(ul_reason_being_called);
00083   UNREFERENCED_PARAMETER(lpReserved);
00084 }
00085
00086
00087 /******************************Public*Routine******************************\
00088 * dinfo
00089 *
00090 *
00091 * Effects: Debugger extension to dump the INFO structure
00092 *
00093 * To invoke the routine in NTSD, do the following:
00094 *
00095 *   1. place the debug.dll in the path
00096 *   2. on NTSD prompt, type
00097 *
00098 *      !debug.dinfo <address of the INFO structure>
00099 *
00100 * Warnings:
00101 *
00102 * History:
00103 *  24-Feb-1992 -by- Petrus Wong
00104 * Wrote it.
00105 \**************************************************************************/
00106
00107 void dinfo (
00108     HANDLE hCurrentProcess,
00109     HANDLE hCurrentThread,
00110     HANDLE dwCurrentPc,
00111     PNTSD_EXTENSION_APIS lpExtensionApis,
00112     LPSTR lpArgumentString)
00113 {
00114     PNTSD_OUTPUT_ROUTINE Print;
00115     PNTSD_GET_EXPRESSION EvalExpression;
00116     PNTSD_GET_SYMBOL GetSymbol;
00117
00118     PINFO   pInfo;
00119     INFO    info;
00120
00121     Print = lpExtensionApis->lpOutputRoutine;
00122     EvalExpression = lpExtensionApis->lpGetExpressionRoutine;
00123     GetSymbol = lpExtensionApis->lpGetSymbolRoutine;
00124
00125     pInfo = (PINFO)EvalExpression(lpArgumentString);
00126     move(info, pInfo);
00127     Print(info.CaptionBarText);
00128     Print("\n");
00129     Print("hParent             = %x\n", info.hParent         );
00130     Print("hTextWnd            = %x\n", info.hTextWnd        );
00131     Print("rcClient(l,t,r,b)   = (%d,%d,%d,%d)\n",
00132                                  info.rcClient.left,  info.rcClient.top,
00133                                  info.rcClient.right, info.rcClient.bottom );
00134     return;
00135 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WINNET/WINNET.C Source File

  • WINNET

WINNET.C

Go to the documentation of this file.
00001 /****************************************************************************\
00002 *
00003 *               Microsoft Developer Support
00004 *               Copyright (c) 1992-1996 Microsoft Corporation
00005 *
00006 * MODULE:       winnet.c
00007 *
00008 * PURPOSE:      Demonstrate the WNetXXX Win32 api(s) (10 of the 11 - all but
00009 *                 WNetConnectionDialog are demonstrated)
00010 *
00011 * TO RUN:       Ensure 1 or more network disk shares can be used by the
00012 *                 machine/user-id you run winnet on, and that these 1 or more
00013 *                 network disk shares aren't already connected to the
00014 *                 machine/user-id you run winnet on.  These net shares must
00015 *                 not require a password
00016 *
00017 *               IMPORTANT:  Ensure W: is not in use when you type "WINNET"
00018 *
00019 * OVERALL APPROACH: Find a connectable disk resource on the network, connect
00020 *                 to it, and disconnect
00021 *
00022 *               The first time you run this sample, it's probably best to
00023 *                 ensure there's a shared disk directory accessable to the
00024 *                 machine on which you run this program, so you can see the
00025 *                 success paths in this code exercised first.  Ensure this
00026 *                 shared disk is NOT already connected
00027 *
00028 *               We recursively open containers returned by the EnumResources
00029 *                 calls (recursively using OpenEnum), but will bail out of the
00030 *                 recursion without fully exploring all containers and enum's
00031 *                 if we hit the arbitrary limit placed on how many connectable
00032 *                 disk resources we enter into our list.  Since there may
00033 *                 possibly be many more enumerable resources on a net than
00034 *                 there are connectable disk resources, we also place another
00035 *                 arbitrary limit on the total number of resources we'll
00036 *                 enumerate
00037 *
00038 *               Both limits can easily be removed or raised by anyone working
00039 *                 with this sample code
00040 *
00041 *               After the container exploration is completed, we walk down the
00042 *                 list of connectable disk resources, arbitrarily picking one
00043 *                 to connect to and then disconnect from
00044 *
00045 * FUNCTIONS:  Open_Do_Close_1_Enum
00046 *
00047 *               Called by main with a NULL container to start the enumeration
00048 *                 of the top-level container.  Called recursively from
00049 *                 EnumResources
00050 *
00051 *             OpenEnum
00052 *
00053 *               Returns an enumeration handle by opening a container
00054 *
00055 *             EnumResources
00056 *
00057 *               Enumerates the connectable resources and containers, given an
00058 *                 enumeration handle.  Recusively calls Open_Do_Close_1_Enum
00059 *
00060 *             AddGetGetCancel
00061 *             AddGetGetCancel2
00062 *
00063 *               Identical logic in both functions adds a connection, gets the
00064 *                 user for the connection, gets information about the
00065 *                 connection and then cancels the connection.  The difference
00066 *                 is that AddGetGetCancel2 uses the new Win32 forms of the Add
00067 *                 and Cancel api's
00068 *
00069 *             PrintAPIError
00070 *
00071 *               Simple routine to print error message info
00072 *
00073 * GLOBAL VARS:
00074 *             ConnectablesList
00075 *
00076 *               List of disk resources we can connect to.  Filled in while
00077 *                 enumeration resources, walked after all enumeration is
00078 *                 complete
00079 *
00080 *             dwResourcesEnumedSoFar
00081 *
00082 *               Counter of resources enumerated so far, includes count of both
00083 *                 disk resources and containers enumerated.  If many
00084 *                 containers are enumerated compared to disk resources, this
00085 *                 counter will limit the search.  If many disk resources are
00086 *                 found compared to containers, the size of ConnectablesList
00087 *                 will limit the search
00088 *
00089 *             dwDiskListI
00090 *
00091 *               Index into ConnectablesList.  At all times, except when adding
00092 *                 a list entry, dwDiskListI is 1 greater than the number of
00093 *                 entries we have entered into ConnectablesList
00094 *
00095 \****************************************************************************/
00096
00097
00098 /****************************************************************************\
00099 *  INCLUDES, DEFINES, TYPEDEFS
00100 \****************************************************************************/
00101 #define STRICT
00102 #include <windows.h>
00103 #include <stdio.h>
00104 #include <string.h>
00105 #include <stdlib.h>
00106 #include <winnetwk.h>
00107
00108 #define PERR(api) printf("%s: Error %d from %s on line %d\n",  \
00109     __FILE__, GetLastError(), api, __LINE__);
00110 #define PMSG(msg) printf("%s line %d: %s\n",  \
00111     __FILE__, __LINE__, msg);
00112
00113 #define PrintAppStyleAPIError(ApiTxt,MsgTxt) {                 \
00114   PrintAPIError( #ApiTxt , #MsgTxt , __LINE__ , __FILE__ ); \
00115   }
00116
00117
00118 /****************************************************************************\
00119 *
00120 * These next two search limits are completely tunable.  On one net
00121 *   MAX_NUMBER_OF_RESOURCES_TO_ENUM had to be large to see 3 or 4 sharable disk
00122 *   resources.  This could vary widely depending on the number of servers on
00123 *   the net that have no shares up
00124 *
00125 \****************************************************************************/
00126
00127 #define MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST 3
00128 #define MAX_NUMBER_OF_RESOURCES_TO_ENUM      480000
00129
00130 #define LOCAL_DEVICE_NAME                    "W:"
00131 #define WHICH_TO_USE_FROM_LIST               0
00132
00133 typedef struct _DISK_RESOURCES_CONNECTABLE
00134 {
00135   LPTSTR lpRemoteName;
00136   LPTSTR lpComment;
00137   LPTSTR lpProvider;
00138 } DISK_RESOURCES_CONNECTABLE, *LPDISK_RESOURCES_CONNECTABLE;
00139
00140 /****************************************************************************\
00141 * GLOBAL VARIABLES
00142 \****************************************************************************/
00143
00144 DISK_RESOURCES_CONNECTABLE
00145                ConnectablesList[MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST];
00146 DWORD    dwResourcesEnumedSoFar = 0;
00147 DWORD    dwDiskListI            = 0;
00148
00149 /****************************************************************************\
00150 * FUNCTION PROTOTYPES
00151 \****************************************************************************/
00152
00153 VOID   Open_Do_Close_1_Enum(LPNETRESOURCE lpNetContainerToOpen);
00154 HANDLE OpenEnum            (LPNETRESOURCE lpNetContainerToOpen);
00155 UINT   EnumResources(HANDLE hNetEnum);
00156 VOID   AddGetGetCancel(VOID);
00157 VOID   AddGetGetCancel2(VOID);
00158 VOID   PrintAPIError(LPTSTR ApiTxt,
00159                      LPTSTR MsgTxt,
00160                      UINT   Line,
00161                      LPTSTR File);
00162
00163 /****************************************************************************\
00164 *
00165 * FUNCTION: Main
00166 *
00167 \****************************************************************************/
00168
00169 UINT main(UINT argc, char *argv[])
00170 {
00171     UNREFERENCED_PARAMETER(argv[1]);
00172
00173     // check if Win32s, if so, display notice and terminate
00174     if( GetVersion() & 0x80000000 )
00175     {
00176         MessageBox(NULL,
00177                    "This application only runs on Windows NT.\n"
00178                    "This application will now terminate.",
00179                    "WinNet",
00180                    MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00181         return( 1 );
00182     }
00183
00184     if (argc > 1)
00185     {
00186         printf("\nTo run type 'winnet', with no parameters\n");
00187         printf("\n  IMPORTANT: Ensure W: is not in use when you type WINNET\n");
00188         return(1);
00189     }
00190
00191     /**************************************************************************\
00192     *
00193     * Pass NULL as container argument to get top level container.  This call
00194     *   starts the recursive exploration of the top level network resource
00195     *   container
00196     *
00197     \**************************************************************************/
00198
00199     Open_Do_Close_1_Enum(NULL);
00200
00201     /**************************************************************************\
00202     *
00203     * We now have a list of connectable resources in our table, but some error
00204     *   conditions may have caused the list to be 0 length
00205     *
00206     \**************************************************************************/
00207
00208     if (0<dwDiskListI)
00209     {
00210         AddGetGetCancel();
00211         AddGetGetCancel2();
00212     }
00213     else
00214     {
00215         printf("\nError: enumerated 0 connectable disk resources!\n");
00216     }
00217
00218     /**************************************************************************\
00219     *
00220     * Free the list of connectable resources, zero length or not
00221     *
00222     \**************************************************************************/
00223
00224     {
00225         DWORD i;
00226         for (i=0; i<dwDiskListI; i++)
00227         {
00228             free(ConnectablesList[i].lpRemoteName);
00229             free(ConnectablesList[i].lpComment   );
00230             free(ConnectablesList[i].lpProvider  );
00231         }
00232     }
00233
00234     return(0);
00235 }
00236
00237
00238 /****************************************************************************\
00239 *
00240 * FUNCTION: Open_Do_Close_1_Enum
00241 *
00242 * COMMENTS: There's little reason this is in a separate function in this
00243 *             sample other than the code is used in two places, so putting it
00244 *             in a separate function saves repetition in the source code
00245 *
00246 \****************************************************************************/
00247
00248 VOID Open_Do_Close_1_Enum(LPNETRESOURCE lpNetContainerToOpen)
00249 {
00250     HANDLE hNetEnum;
00251
00252     hNetEnum = OpenEnum(lpNetContainerToOpen);
00253
00254     if (!hNetEnum)
00255         return;
00256
00257     if (!EnumResources(hNetEnum))
00258         return;
00259
00260     if (NO_ERROR != WNetCloseEnum(hNetEnum))
00261     {
00262         PERR("WNetCloseEnum");
00263         return;
00264     }
00265 }
00266
00267 /****************************************************************************\
00268 *
00269 * FUNCTION: OpenEnum
00270 *
00271 \****************************************************************************/
00272
00273 HANDLE OpenEnum(LPNETRESOURCE lpNetContainerToOpen)
00274 {
00275     HANDLE hNetEnum;
00276
00277     if (NO_ERROR != WNetOpenEnum(RESOURCE_GLOBALNET,
00278                                  RESOURCETYPE_DISK,
00279                                  (RESOURCEUSAGE_CONNECTABLE |
00280                                  RESOURCEUSAGE_CONTAINER),
00281                                  lpNetContainerToOpen,
00282                                  (LPHANDLE)&hNetEnum))
00283     {
00284         if (GetLastError() != NO_ERROR)
00285         {
00286             PrintAppStyleAPIError(WNetOpenEnum,"OpenEnum");
00287             return(NULL);
00288         }
00289     }
00290
00291     return(hNetEnum);
00292 }
00293
00294 /****************************************************************************\
00295 *
00296 * FUNCTION: EnumResources
00297 *
00298 \****************************************************************************/
00299
00300 UINT EnumResources(HANDLE hNetEnum)
00301 {
00302     #define                    RESOURCE_BUF_ENTRIES 5000
00303     NETRESOURCE ResourceBuffer[RESOURCE_BUF_ENTRIES];
00304     DWORD       dwSzResourceBuf;
00305     DWORD       dwEntriesToGet;
00306
00307     /**************************************************************************\
00308     *
00309     * It's possible that not all entries will fit in a RESOURCE_BUF_ENTRIES slot
00310     *   buffer, so we call WNetEnumResource in a loop, asking for
00311     *   RESOURCE_BUF_ENTRIES at a time, and continuing to call WNetEnumResource
00312     *   until it returns no more entries
00313     *
00314     \**************************************************************************/
00315
00316     for (;;)
00317     {
00318         dwSzResourceBuf = sizeof(ResourceBuffer);
00319         dwEntriesToGet  = RESOURCE_BUF_ENTRIES;
00320
00321         printf("Getting %d entries\n",dwEntriesToGet);
00322
00323         if (NO_ERROR != WNetEnumResource(hNetEnum,
00324                                          (LPDWORD)&dwEntriesToGet,
00325                                          (LPVOID)ResourceBuffer,
00326                                          (LPDWORD)&dwSzResourceBuf))
00327         {
00328             switch (GetLastError())
00329             {
00330                 case NO_ERROR:
00331                     // Drop out of the switch, walk the buffer
00332                     break;
00333
00334                 case ERROR_NO_MORE_ITEMS :
00335                     // Return with 0 code because this only happens when we got
00336                     //   RESOURCE_BUF_ENTRIES entries on the previous call to
00337                     //   WNetEnumResource, and there were coincidentally exactly
00338                     //   RESOURCE_BUF_ENTRIES entries total in the enum at the time of
00339                     //   that previous call
00340                     return(0);
00341
00342                 default                  :
00343                     PrintAppStyleAPIError(WNetEnumResource,"EnumResources");
00344                     return(1);
00345             }
00346         }
00347
00348         /************************************************************************\
00349         *
00350         * Walk the returned buffer.  Now dwEntriesToGet has been set by the api
00351         *   call to be the number of entries actually returned
00352         *
00353         \************************************************************************/
00354
00355         {
00356             DWORD i;
00357
00358             printf("Got %d entries\n",dwEntriesToGet);
00359
00360             for (i=0; i<dwEntriesToGet; i++)
00361             {
00362                 printf("\nResourceBuffer[%d].dwScope      = 0x%x \n",i,
00363                         ResourceBuffer[i].dwScope);
00364                 printf("ResourceBuffer[%d].dwType       = 0x%x \n",i,
00365                         ResourceBuffer[i].dwType);
00366                 printf("ResourceBuffer[%d].dwUsage      = 0x%x \n",i,
00367                         ResourceBuffer[i].dwUsage);
00368                 printf("ResourceBuffer[%d].lpLocalName  = %s   \n",i,
00369                         ResourceBuffer[i].lpLocalName);
00370                 printf("ResourceBuffer[%d].lpRemoteName = %s   \n",i,
00371                         ResourceBuffer[i].lpRemoteName);
00372                 printf("ResourceBuffer[%d].lpComment    = %s   \n",i,
00373                         ResourceBuffer[i].lpComment);
00374                 printf("ResourceBuffer[%d].lpProvider   = %s   \n",i,
00375                         ResourceBuffer[i].lpProvider);
00376
00377                 dwResourcesEnumedSoFar += dwEntriesToGet;
00378
00379                 printf("dwResourcesEnumedSoFar = %d \n",dwResourcesEnumedSoFar);
00380
00381                 if (dwDiskListI >= MAX_NUMBER_OF_DISK_RESOURCES_TO_LIST)
00382                     return(0);  // List full, stop enumerating
00383
00384                 switch (ResourceBuffer[i].dwUsage)
00385                 {
00386                     case RESOURCEUSAGE_CONNECTABLE :
00387                         ConnectablesList[dwDiskListI].lpRemoteName =
00388                             malloc(1+strlen(ResourceBuffer[i].lpRemoteName));
00389                         ConnectablesList[dwDiskListI].lpComment    =
00390                             malloc(1+strlen(ResourceBuffer[i].lpComment   ));
00391                         ConnectablesList[dwDiskListI].lpProvider   =
00392                             malloc(1+strlen(ResourceBuffer[i].lpProvider  ));
00393
00394                         if ((NULL == ConnectablesList[dwDiskListI].lpRemoteName) ||
00395                             (NULL == ConnectablesList[dwDiskListI].lpComment   ) ||
00396                             (NULL == ConnectablesList[dwDiskListI].lpProvider  ))
00397                             PERR("EnumResource - ran out of heap space");
00398
00399                         strcpy(ConnectablesList[dwDiskListI].lpRemoteName,
00400                                ResourceBuffer[i].lpRemoteName);
00401                         strcpy(ConnectablesList[dwDiskListI].lpComment   ,
00402                                ResourceBuffer[i].lpComment   );
00403                         strcpy(ConnectablesList[dwDiskListI].lpProvider  ,
00404                                ResourceBuffer[i].lpProvider  );
00405
00406                         dwDiskListI++;
00407
00408                         break;
00409
00410                     case  RESOURCEUSAGE_CONTAINER:      // Regular container
00411                     case (RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED):
00412                         //Top-level container
00413
00414                         /****************************************************************\
00415                         *
00416                         * This next test is here to filter out servers we don't wish to
00417                         *   enumerate while running the sample.  A real app would be more
00418                         *   likely to look at all servers, but for running a sample, it's
00419                         *   worthwhile to think about which servers should actually be
00420                         *   enumerated, to avoid annoying people who have other servers on
00421                         *   the net they may not wish to be disturbed
00422                         *
00423                         * So, you may want to modify this test to filter out whatever
00424                         *   servers make sense to filter out in your environment
00425                         *
00426                         * The first clause shows how to include in the filter the top
00427                         *   level Windows NT network provider container, the second clause
00428                         *   shows how to include in the filter a domain name, and the
00429                         *   third and fourth clauses show how to include any servers whose
00430                         *   names start with particular characters
00431                         *
00432                         \****************************************************************/
00433
00434                         if (!(  (0==_strnicmp("Microsoft Windows Network", ResourceBuffer[i].lpRemoteName,25))
00435                               ||(0==_strnicmp("DMAIN1",ResourceBuffer[i].lpRemoteName,6))
00436                               ||(0==_strnicmp("\\\\BLUMPR2",ResourceBuffer[i].lpRemoteName,9))
00437                               ||(0==_strnicmp("\\\\BLAMTR2",ResourceBuffer[i].lpRemoteName,9))))
00438                             break;
00439
00440                         if (dwResourcesEnumedSoFar < MAX_NUMBER_OF_RESOURCES_TO_ENUM)
00441                             Open_Do_Close_1_Enum(&ResourceBuffer[i]);
00442                             break;
00443
00444                     case RESOURCEUSAGE_RESERVED:   // Ignore these
00445                         break;
00446
00447                     default:
00448                     {
00449                         UCHAR ucMsgBuf[1500];
00450
00451                         sprintf(ucMsgBuf,"WNetEnumResources bad .dwUsage value = 0x%X,\n",
00452                         ResourceBuffer[i].dwUsage);
00453                         PERR(ucMsgBuf);
00454                         return(1);
00455                     }
00456                 }
00457             }
00458         }
00459
00460         /************************************************************************\
00461         *
00462         * We have walked the returned buffer.  Since dwEntriesToGet has been set
00463         *   by the api call to be the number of entries actually returned, if how
00464         *   many were returned is less than what we asked for, return out of the
00465         *   loop because this enum is done
00466         *
00467         \************************************************************************/
00468
00469         if (dwEntriesToGet < RESOURCE_BUF_ENTRIES)
00470             return(0);
00471
00472     }
00473
00474     // Infinite loop never exits this way.
00475 }
00476
00477
00478 /****************************************************************************\
00479 *
00480 * FUNCTION: AddGetGetCancel
00481 *
00482 * COMMENTS: Connects to first disk resource on our global list
00483 *
00484 \****************************************************************************/
00485
00486 VOID AddGetGetCancel(VOID)
00487 {
00488     UCHAR ucLocalName[sizeof(LOCAL_DEVICE_NAME)+1] = LOCAL_DEVICE_NAME;
00489     UCHAR ucPassword[] = "Passw00";
00490     #define            SZ_BUF 1000
00491     UCHAR ucRemoteName[SZ_BUF];
00492     UCHAR ucUserName  [SZ_BUF];
00493     DWORD dwSzBuf    = SZ_BUF;
00494
00495     if (NO_ERROR != WNetAddConnection(
00496                   ConnectablesList[WHICH_TO_USE_FROM_LIST].lpRemoteName,
00497                   (LPTSTR)ucPassword,(LPTSTR)ucLocalName))
00498     {
00499         PrintAppStyleAPIError(WNetAddConnection,"AddGetGetCancel");
00500         return;
00501     }
00502
00503     dwSzBuf = SZ_BUF;
00504
00505     if (NO_ERROR != WNetGetConnection((LPTSTR)ucLocalName,
00506                                       (LPTSTR)ucRemoteName,(LPDWORD)&dwSzBuf))
00507     {
00508         PrintAppStyleAPIError(WNetGetConnection,"AddGetGetCancel");
00509         return;
00510     }
00511
00512     dwSzBuf = SZ_BUF;
00513
00514     if (NO_ERROR != WNetGetUser((LPTSTR)ucLocalName,
00515                                 (LPTSTR)ucUserName,(LPDWORD)&dwSzBuf))
00516     {
00517         PrintAppStyleAPIError(WNetGetUser,"AddGetGetCancel");
00518         return;
00519     }
00520
00521     printf("\nDisk resource AddGetGetCancel connected = [%s], User name logged"
00522            "on to that resource = [%s]\n", ucRemoteName,ucUserName);
00523
00524     if (NO_ERROR != WNetCancelConnection((LPTSTR)ucLocalName,FALSE))
00525     {
00526         PrintAppStyleAPIError(WNetCancelConnection,"AddGetGetCancel");
00527         return;
00528     }
00529 }
00530
00531
00532 /****************************************************************************\
00533 *
00534 * FUNCTION: AddGetGetCancel2
00535 *
00536 * COMMENTS: If we had chosen to keep our list as a list of NetResource data
00537 *             structures, using the new form of AddConnection2 would have been
00538 *             easier to code.  As it is, declaring and filling in the
00539 *             NetResource takes a few more lines
00540 *
00541 \****************************************************************************/
00542
00543 VOID AddGetGetCancel2(VOID)
00544 {
00545     UCHAR ucLocalName[sizeof(LOCAL_DEVICE_NAME)+1] = LOCAL_DEVICE_NAME;
00546     NETRESOURCE ToConnect;
00547     UCHAR ucPassword[] = "Passw00";
00548     #define            SZ_BUF 1000
00549     UCHAR ucRemoteName[SZ_BUF];
00550     UCHAR ucUserName  [SZ_BUF] = "AUserName";
00551     DWORD dwSzBuf    = SZ_BUF;
00552
00553     ToConnect.lpRemoteName = ConnectablesList[WHICH_TO_USE_FROM_LIST].lpRemoteName;
00554     ToConnect.lpLocalName  = ucLocalName;
00555     ToConnect.lpProvider   = NULL;
00556     ToConnect.dwType       = RESOURCETYPE_DISK;
00557
00558     if (NO_ERROR != WNetAddConnection2(&ToConnect,(LPTSTR)ucPassword,
00559                                        (LPTSTR)ucUserName,CONNECT_UPDATE_PROFILE))
00560     {
00561         PrintAppStyleAPIError(WNetAddConnection2,"AddGetGetCancel2");
00562         return;
00563     }
00564
00565     dwSzBuf = SZ_BUF;
00566
00567     if (NO_ERROR != WNetGetConnection((LPTSTR)ucLocalName,
00568                                       (LPTSTR)ucRemoteName,(LPDWORD)&dwSzBuf))
00569     {
00570         PrintAppStyleAPIError(WNetGetConnection,"AddGetGetCancel2");
00571         return;
00572     }
00573
00574     dwSzBuf = SZ_BUF;
00575
00576     if (NO_ERROR != WNetGetUser((LPTSTR)ucLocalName,
00577                                 (LPTSTR)ucUserName,(LPDWORD)&dwSzBuf))
00578     {
00579         PrintAppStyleAPIError(WNetGetUser,"AddGetGetCancel2");
00580         return;
00581     }
00582
00583     printf("\nDisk resource AddGetGetCancel2 connected = [%s], "
00584            "User name logged on to that resource = [%s]\n",
00585            ucRemoteName,ucUserName);
00586
00587     if (NO_ERROR != WNetCancelConnection2((LPTSTR)ucLocalName,
00588                                           CONNECT_UPDATE_PROFILE,FALSE))
00589     {
00590         PrintAppStyleAPIError(WNetCancelConnection2,"AddGetGetCancel2");
00591         return;
00592     }
00593 }
00594
00595
00596 /****************************************************************************\
00597 *
00598 * FUNCTION: PrintAPIError
00599 *
00600 \****************************************************************************/
00601
00602 VOID   PrintAPIError(LPTSTR ApiTxt,
00603                      LPTSTR MsgTxt,
00604                      UINT   Line,
00605                      LPTSTR File)
00606 {
00607     DWORD dwLastError;
00608
00609     dwLastError = GetLastError();
00610     switch (dwLastError)
00611     {
00612         case NO_ERROR:
00613             printf("\nNO_ERROR not expected (%s) line %d file %s",
00614                    MsgTxt,Line,File);
00615             break;
00616
00617         case ERROR_EXTENDED_ERROR:
00618         {
00619             DWORD dwErrorCode;
00620
00621             #define SZ_ERROR_BUF 4000
00622             UCHAR ucErrorBuf[SZ_ERROR_BUF];
00623             #define SZ_PROVIDER_NAME_BUF   400
00624             UCHAR ucProviderNameBuf[SZ_PROVIDER_NAME_BUF];
00625
00626             if (NO_ERROR != WNetGetLastError(&dwErrorCode,
00627                                              (LPTSTR)ucErrorBuf,
00628                                              (DWORD)SZ_ERROR_BUF,
00629                                              (LPTSTR)ucProviderNameBuf,
00630                                              (DWORD)SZ_PROVIDER_NAME_BUF))
00631             {
00632                 PERR("WNetGetLastError");
00633             }
00634             else
00635             {
00636                 #define szMsgBuf SZ_ERROR_BUF * 2
00637                 UCHAR ucMsgBuf[szMsgBuf];
00638
00639                 sprintf(ucMsgBuf, "WNetGetLastError code = %d, Msg=[%s],"
00640                         "Provider =[%s] line %d file %s", dwErrorCode,
00641                         ucErrorBuf, ucProviderNameBuf, Line, File);
00642                 PERR(ucMsgBuf);
00643             }
00644         }
00645         break;
00646
00647         case ERROR_NOT_SUPPORTED:
00648             printf("\nERROR_NOT_SUPPORTED (%s) line %d file %s", MsgTxt, Line,
00649                    File);
00650             break;
00651
00652         case ERROR_UNEXP_NET_ERR:
00653             printf("\nERROR_UNEXP_NET_ERR (%s) line %d file %s", MsgTxt, Line,
00654                    File);
00655             break;
00656
00657         case ERROR_MORE_DATA:
00658             printf("\nERROR_MORE_DATA (%s) line %d file %s", MsgTxt, Line,
00659                    File);
00660             break;
00661
00662         case ERROR_INVALID_ADDRESS:
00663             printf("\nERROR_INVALID_ADDRESS (%s) line %d file %s", MsgTxt,
00664                    Line, File);
00665             break;
00666
00667         case ERROR_INVALID_PARAMETER:
00668             printf("\nERROR_INVALID_PARAMETER (%s) line %d file %s", MsgTxt,
00669                    Line, File);
00670             break;
00671
00672         case ERROR_INVALID_PASSWORD:
00673             printf("\nERROR_INVALID_PASSWORD (%s) line %d file %s", MsgTxt,
00674                    Line, File);
00675             break;
00676
00677         case ERROR_ACCESS_DENIED:
00678             printf("\nERROR_ACCESS_DENIED (%s) line %d file %s", MsgTxt, Line,
00679                    File);
00680             break;
00681
00682         case ERROR_BUSY:
00683             printf("\nERROR_BUSY (%s) line %d file %s", MsgTxt, Line, File);
00684             break;
00685
00686         case ERROR_BAD_USERNAME:
00687             printf("\nERROR_BAD_USERNAME (%s) line %d file %s", MsgTxt, Line,
00688                    File);
00689             break;
00690
00691         case ERROR_NOT_ENOUGH_MEMORY:
00692             printf("\nERROR_NOT_ENOUGH_MEMORY (%s) line %d file %s", MsgTxt,
00693                    Line, File);
00694             break;
00695
00696         case ERROR_NO_NETWORK:
00697             printf("\nERROR_NO_NETWORK (%s) line %d file %s", MsgTxt, Line,
00698                    File);
00699             break;
00700
00701         case ERROR_NOT_CONNECTED:
00702             printf("\nERROR_NOT_CONNECTED (%s) line %d file %s", MsgTxt, Line,
00703                    File);
00704             break;
00705
00706         case ERROR_OPEN_FILES:
00707             printf("\nERROR_OPEN_FILES (%s) line %d file %s", MsgTxt, Line,
00708                    File);
00709             break;
00710
00711         case ERROR_DEVICE_IN_USE:
00712             printf("\nERROR_DEVICE_IN_USE (%s) line %d file %s", MsgTxt, Line,
00713                    File);
00714             break;
00715
00716         case ERROR_BAD_NET_NAME:
00717             printf("\nERROR_BAD_NET_NAME (%s) line %d file %s", MsgTxt, Line,
00718                    File);
00719             break;
00720
00721         case ERROR_BAD_DEVICE:
00722             printf("\nERROR_BAD_DEVICE (%s) line %d file %s", MsgTxt, Line,
00723                    File);
00724             break;
00725
00726         case ERROR_ALREADY_ASSIGNED:
00727             printf("\nERROR_ALREADY_ASSIGNED (%s) line %d file %s", MsgTxt,
00728                    Line, File);
00729             break;
00730
00731         case ERROR_GEN_FAILURE:
00732             printf("\nERROR_GEN_FAILURE (%s) line %d file %s", MsgTxt, Line,
00733                    File);
00734             break;
00735
00736         case ERROR_CONNECTION_UNAVAIL:
00737             printf("\nERROR_CONNECTION_UNAVAIL (%s) line %d file %s", MsgTxt,
00738                    Line, File);
00739             break;
00740
00741         case ERROR_NO_NET_OR_BAD_PATH:
00742             printf("\nERROR_NO_NET_OR_BAD_PATH (%s) line %d file %s", MsgTxt,
00743                    Line, File);
00744             break;
00745
00746         case ERROR_BAD_PROVIDER:
00747             printf("\nERROR_BAD_PROVIDER (%s) line %d file %s", MsgTxt, Line,
00748                    File);
00749             break;
00750
00751         case ERROR_CANNOT_OPEN_PROFILE:
00752             printf("\nERROR_CANNOT_OPEN_PROFILE (%s) line %d file %s", MsgTxt,
00753                    Line, File);
00754             break;
00755
00756         case ERROR_BAD_PROFILE:
00757             printf("\nERROR_BAD_PROFILE (%s) line %d file %s", MsgTxt, Line,
00758                    File);
00759             break;
00760
00761         case ERROR_INVALID_HANDLE:
00762             printf("\nERROR_INVALID_HANDLE (%s) line %d file %s", MsgTxt,
00763                    Line, File);
00764             break;
00765
00766         case ERROR_NO_MORE_ITEMS:
00767             printf("\nERROR_NO_MORE_ITEMS (%s) line %d file %s", MsgTxt, Line,
00768                    File);
00769             break;
00770
00771         case ERROR_NOT_CONTAINER:
00772             printf("\nERROR_NOT_CONTAINER (%s) line %d file %s", MsgTxt, Line,
00773                    File);
00774             break;
00775
00776         default:
00777             printf("\n%s - unexpected return code=%d (%s) line %d file %s",
00778                    ApiTxt, dwLastError, MsgTxt, Line, File);
00779             break;
00780     }
00781 }
00782
00783
Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CLIPTEXT/CLIPTEXT.H Source File

  • CLIPTEXT

CLIPTEXT.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 #include "windows.h"
00014
00015 #define IDM_ABOUT 100
00016
00017 /* file menu items */
00018
00019 #define     IDM_NEW      101
00020 #define     IDM_OPEN     102
00021 #define     IDM_SAVE     103
00022 #define     IDM_SAVEAS   104
00023 #define     IDM_PRINT    105
00024 #define     IDM_EXIT     106
00025
00026 /* edit menu items */
00027
00028 #define     IDM_UNDO     200
00029 #define     IDM_CUT      201
00030 #define     IDM_COPY     202
00031 #define     IDM_PASTE    203
00032 #define     IDM_CLEAR    204
00033
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INHERIT/CHILD.C Source File

  • INHERIT

CHILD.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* Standard output handle/standard error handle redirection test
00013 program */
00014
00015 #include <stdio.h>
00016 #include <io.h>
00017 #include <string.h>
00018 #include <windows.h>
00019
00020 /* This function opens up a handle to CONOUT$ so that we can be
00021 guaranteed to get error messages to the console even if the standard
00022 handles are redirected. */
00023
00024 void myError(HANDLE h, char *api, int line)
00025 {
00026   char buf[512];
00027   BOOL fSuccess;
00028   DWORD cBytesWritten;
00029   HANDLE hConout;
00030
00031   sprintf(buf, "%s: Error %d from %s on line %d\n", __FILE__, GetLastError(),
00032       api, line);
00033   fSuccess = WriteFile(h, buf, strlen(buf), &cBytesWritten, NULL);
00034   if (!fSuccess)
00035     {
00036     hConout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
00037         FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
00038         FILE_ATTRIBUTE_NORMAL, NULL);
00039     sprintf(buf, "%s: Error %d from %s on line %d\n", __FILE__,
00040       GetLastError(), api, line);
00041     WriteFile(hConout, buf, strlen(buf), &cBytesWritten, NULL);
00042     CloseHandle(hConout);
00043     }
00044   return;
00045 }
00046
00047 /* get the standard output handle and standard error handle and
00048 write a message to each */
00049
00050 int main()
00051 {
00052   DWORD cBytesWritten;
00053   HANDLE hStdErr, hStdOut, hConout;
00054   BOOL fSuccess;
00055   char *stdErrMsg = "Hello from child to standard error!\n";
00056   char *stdOutMsg = "Hello from child to standard output!\n";
00057
00058   hConout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
00059       FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
00060       FILE_ATTRIBUTE_NORMAL, NULL);
00061   if ((int) hConout == -1)
00062     Beep(5000,500); /* no reliable way of reporting errors to the console */
00063                     /* if we can't open a console handle */
00064   hStdErr = GetStdHandle(STD_ERROR_HANDLE);
00065   if (hStdErr == INVALID_HANDLE_VALUE)
00066     myError(hConout, "GetStdHandle", __LINE__);
00067   hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
00068   if (hStdOut == INVALID_HANDLE_VALUE)
00069     myError(hConout, "GetStdHandle", __LINE__);
00070   fSuccess = WriteFile(hStdErr, stdErrMsg, strlen(stdErrMsg),
00071       &cBytesWritten, NULL);
00072   if (!fSuccess)
00073     myError(hConout, "WriteFile", __LINE__);
00074   fSuccess = WriteFile(hStdOut, stdOutMsg, strlen(stdOutMsg),
00075       &cBytesWritten, NULL);
00076   if (!fSuccess)
00077     myError(hConout, "WriteFile", __LINE__);
00078   CloseHandle(hConout);
00079   return(0);
00080 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CMNDLG.H Source File

  • CMNDLG

CMNDLG.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 // menu commands
00014
00015 // Find menu
00016 #define IDM_OPENFILE        100
00017 #define IDM_SAVEFILE        101
00018 #define IDM_SAVEFILEAS      102
00019 #define IDM_PRINT           103
00020 #define IDM_EXIT            104
00021
00022 // Options menu
00023 #define IDM_ENTERNEW        200
00024 #define IDM_CHOOSECOLOR     201
00025 #define IDM_CHOOSEFONT      202
00026 #define IDM_FINDTEXT        203
00027 #define IDM_REPLACETEXT     204
00028 #define IDM_STANDARD        205
00029 #define IDM_HOOK            206
00030 #define IDM_CUSTOM          207
00031
00032 // Help menu
00033 #define IDM_ABOUT           300
00034
00035
00036 // Dialog box constants
00037 #define IDEDIT              500
00038
00039 // string constants
00040
00041 #define IDS_DIALOGFAILURE     1
00042 #define IDS_STRUCTSIZE        2
00043 #define IDS_INITIALIZATION    3
00044 #define IDS_NOTEMPLATE        4
00045 #define IDS_NOHINSTANCE       5
00046 #define IDS_LOADSTRFAILURE    6
00047 #define IDS_FINDRESFAILURE    7
00048 #define IDS_LOADRESFAILURE    8
00049 #define IDS_LOCKRESFAILURE    9
00050 #define IDS_MEMALLOCFAILURE  10
00051 #define IDS_MEMLOCKFAILURE   11
00052 #define IDS_NOHOOK           12
00053 #define IDS_SETUPFAILURE     13
00054 #define IDS_PARSEFAILURE     14
00055 #define IDS_RETDEFFAILURE    15
00056 #define IDS_LOADDRVFAILURE   16
00057 #define IDS_GETDEVMODEFAIL   17
00058 #define IDS_INITFAILURE      18
00059 #define IDS_NODEVICES        19
00060 #define IDS_NODEFAULTPRN     20
00061 #define IDS_DNDMMISMATCH     21
00062 #define IDS_CREATEICFAILURE  22
00063 #define IDS_PRINTERNOTFOUND  23
00064 #define IDS_NOFONTS          24
00065 #define IDS_SUBCLASSFAILURE  25
00066 #define IDS_INVALIDFILENAME  26
00067 #define IDS_BUFFERTOOSMALL   27
00068 #define IDS_FILTERSTRING     28
00069 #define IDS_UNKNOWNERROR     29
00070
00071 // constants
00072
00073 #define FILE_LEN            80
00074
00075 // Function prototypes
00076
00077 // procs
00078 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00079 BOOL CALLBACK About(HWND, UINT, WPARAM, LPARAM);
00080 BOOL CALLBACK EnterNew(HWND, UINT, WPARAM, LPARAM);
00081 BOOL CALLBACK FileOpenHookProc(HWND, UINT, WPARAM, LPARAM);
00082 BOOL CALLBACK FileSaveHookProc(HWND, UINT, WPARAM, LPARAM);
00083 BOOL CALLBACK ChooseColorHookProc(HWND, UINT, WPARAM, LPARAM);
00084 BOOL CALLBACK ChooseFontHookProc(HWND, UINT, WPARAM, LPARAM);
00085 BOOL CALLBACK FindTextHookProc(HWND, UINT, WPARAM, LPARAM);
00086 BOOL CALLBACK ReplaceTextHookProc(HWND, UINT, WPARAM, LPARAM);
00087 BOOL CALLBACK PrintDlgHookProc(HWND, UINT, WPARAM, LPARAM);
00088 BOOL CALLBACK PrintSetupHookProc(HWND, UINT, WPARAM, LPARAM);
00089
00090 //functions
00091 BOOL InitApplication(HANDLE);
00092 BOOL InitInstance(HANDLE, int);
00093 BOOL OpenNewFile( HWND );
00094 BOOL SaveToFile( HWND );
00095 BOOL SaveAs( HWND );
00096 void SearchFile( LPFINDREPLACE );
00097 BOOL ChooseNewFont( HWND );
00098 BOOL ChooseNewColor( HWND );
00099 void PrintFile( HWND );
00100 void CallFindText( HWND );
00101 void CallReplaceText( HWND );
00102 void ProcessCDError(DWORD, HWND);
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CLIPTEXT/CLIPTEXT.C Source File

  • CLIPTEXT

CLIPTEXT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************
00013
00014     PROGRAM: Cliptext.c
00015
00016     PURPOSE: Demonstrates copying text to and from the clipboard
00017
00018     FUNCTIONS:
00019
00020         WinMain() - calls initialization function, processes message loop
00021         InitApplication() - initializes window data and registers window
00022         InitInstance() - saves instance handle and creates main window
00023         MainWndProc() - processes messages
00024         About() - processes messages for "About" dialog box
00025         OutOfMemory() - displays warning message
00026
00027 ****************************************************************************/
00028
00029 #include "cliptext.h"
00030 #include <string.h>
00031
00032 HANDLE hInst;
00033 HANDLE hAccTable;
00034 HWND   hwnd;
00035
00036 HANDLE hText = NULL;
00037
00038 CHAR szInitialClientAreaText[] =
00039     "This program demonstrates the use of the Edit menu to copy and "
00040     "paste text to and from the clipboard.  Try using the Copy command "
00041     "to move this text to the clipboard, and the Paste command to replace "
00042     "this text with data from another application.  \r\n\r\n"
00043     "You might want to try running Notepad and Clipbrd alongside this "
00044     "application so that you can watch the data exchanges take place.  ";
00045
00046 HANDLE hData, hClipData;                            /* handles to clip data  */
00047 LPSTR lpData, lpClipData;                           /* pointers to clip data */
00048
00049 /* functions declared here, because of MIPS lack of passing C_DEFINES*/
00050 BOOL InitApplication(HANDLE);
00051 BOOL InitInstance(HANDLE, INT);
00052 LONG APIENTRY MainWndProc(HWND, UINT, UINT, LONG);
00053 BOOL APIENTRY About(HWND, UINT, UINT, LONG);
00054 VOID OutOfMemory(VOID);
00055
00056 /****************************************************************************
00057
00058     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00059
00060     PURPOSE: calls initialization function, processes message loop
00061
00062 ****************************************************************************/
00063
00064 int APIENTRY WinMain(
00065     HANDLE hInstance,
00066     HANDLE hPrevInstance,
00067     LPSTR lpCmdLine,
00068     int nCmdShow
00069     )
00070 {
00071     MSG msg;
00072
00073     UNREFERENCED_PARAMETER( lpCmdLine );
00074
00075     if (!hPrevInstance)
00076         if (!InitApplication(hInstance))
00077             return (FALSE);
00078
00079     if (!InitInstance(hInstance, nCmdShow))
00080         return (FALSE);
00081
00082     while (GetMessage(&msg, NULL, 0, 0)) {
00083
00084     /* Only translate message if it is not an accelerator message */
00085
00086         if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
00087             TranslateMessage(&msg);
00088             DispatchMessage(&msg);
00089         }
00090     }
00091     return (msg.wParam);
00092 }
00093
00094
00095 /****************************************************************************
00096
00097     FUNCTION: InitApplication(HANDLE)
00098
00099     PURPOSE: Initializes window data and registers window class
00100
00101 ****************************************************************************/
00102
00103 BOOL InitApplication(HANDLE hInstance)
00104 {
00105     WNDCLASS  wc;
00106
00107     wc.style = 0;
00108     wc.lpfnWndProc = (WNDPROC) MainWndProc;
00109     wc.cbClsExtra = 0;
00110     wc.cbWndExtra = 0;
00111     wc.hInstance = hInstance;
00112     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00113     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00114     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00115     wc.lpszMenuName =  "CliptextMenu";
00116     wc.lpszClassName = "CliptextWClass";
00117
00118     return (RegisterClass(&wc));
00119 }
00120
00121
00122 /****************************************************************************
00123
00124     FUNCTION:  InitInstance(HANDLE, int)
00125
00126     PURPOSE:  Saves instance handle and creates main window
00127
00128 ****************************************************************************/
00129
00130 BOOL InitInstance(
00131     HANDLE          hInstance,
00132     INT             nCmdShow)
00133 {
00134     LPSTR           lpszText;
00135
00136     hInst = hInstance;
00137
00138     hAccTable = LoadAccelerators(hInst, "ClipTextAcc");
00139
00140     if (!(hText
00141           = GlobalAlloc(GMEM_MOVEABLE,(DWORD)sizeof(szInitialClientAreaText)))) {
00142         OutOfMemory();
00143         return (FALSE);
00144     }
00145
00146     if (!(lpszText = GlobalLock(hText))) {
00147         OutOfMemory();
00148         return (FALSE);
00149     }
00150
00151     strcpy(lpszText, szInitialClientAreaText);
00152     GlobalUnlock(hText);
00153
00154     hwnd = CreateWindow(
00155         "CliptextWClass",
00156         "Cliptext Sample Application",
00157         WS_OVERLAPPEDWINDOW,
00158         CW_USEDEFAULT,
00159         CW_USEDEFAULT,
00160         CW_USEDEFAULT,
00161         CW_USEDEFAULT,
00162         NULL,
00163         NULL,
00164         hInstance,
00165         NULL
00166     );
00167
00168     if (!hwnd)
00169         return (FALSE);
00170
00171     ShowWindow(hwnd, nCmdShow);
00172     UpdateWindow(hwnd);
00173     return (TRUE);
00174
00175 }
00176
00177 /****************************************************************************
00178
00179     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
00180
00181     PURPOSE:  Processes messages
00182
00183     MESSAGES:
00184
00185         WM_COMMAND    - message from menu
00186         WM_INITMENU   - initialize menu
00187         WM_PAINT      - update window
00188         WM_DESTROY    - destroy window
00189
00190     COMMENTS:
00191
00192         WM_INITMENU - when this message is received, the application checks
00193         to see if there is any text data in the clipboard, and enables or
00194         disables the Paste menu item accordingly.
00195
00196         Seclecting the Copy menu item will send the text "Hello Windows" to
00197         the clipboard.
00198
00199         Seclecting the Paste menu item will copy whatever text is in the
00200         clipboard to the application window.
00201
00202 ****************************************************************************/
00203
00204 LONG APIENTRY MainWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam)
00205 {
00206     FARPROC lpProcAbout;
00207     HDC hDC;
00208     PAINTSTRUCT ps;
00209     RECT rectClient;
00210     LPSTR lpszText;
00211
00212     switch (message) {
00213
00214         case WM_INITMENU:
00215                 if (wParam == (UINT)GetMenu(hWnd)) {
00216                 if (OpenClipboard(hWnd)) {
00217                     if (IsClipboardFormatAvailable(CF_TEXT)
00218                         || IsClipboardFormatAvailable(CF_OEMTEXT))
00219                         EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_ENABLED);
00220                     else
00221                         EnableMenuItem((HMENU)wParam, IDM_PASTE, MF_GRAYED);
00222                     CloseClipboard();
00223                     return (TRUE);
00224                 }
00225                 else                           /* Clipboard is not available */
00226                     return (FALSE);
00227
00228             }
00229             return (TRUE);
00230
00231         case WM_COMMAND:
00232                 switch(LOWORD(wParam)) {
00233                 case IDM_ABOUT:
00234                     lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
00235                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
00236                     FreeProcInstance(lpProcAbout);
00237                     break;
00238
00239                 /* file menu commands */
00240
00241                 case IDM_NEW:
00242                 case IDM_OPEN:
00243                 case IDM_SAVE:
00244                 case IDM_SAVEAS:
00245                 case IDM_PRINT:
00246                     MessageBox (
00247                           GetFocus ()
00248                         , "Command not implemented."
00249                         , "ClipText Sample Application"
00250                         , MB_ICONASTERISK | MB_OK
00251                     );
00252                     break;
00253
00254                 case IDM_EXIT:
00255                     DestroyWindow(hWnd);
00256                     break;
00257
00258                 /* edit menu commands */
00259
00260                 case IDM_UNDO:
00261                 case IDM_CLEAR:
00262                     MessageBox (
00263                           GetFocus ()
00264                         , "Command not implemented."
00265                         , "ClipText Sample Application"
00266                         , MB_ICONASTERISK | MB_OK
00267                     );
00268                     break;
00269
00270                 case IDM_CUT:
00271                 case IDM_COPY:
00272
00273                     if (hText != NULL) {
00274
00275                         /* Allocate memory and copy the string to it */
00276
00277                         if (!(hData
00278                              = GlobalAlloc(GMEM_DDESHARE, GlobalSize (hText)))) {
00279                             OutOfMemory();
00280                             return (TRUE);
00281                         }
00282                         if (!(lpData = GlobalLock(hData))) {
00283                             OutOfMemory();
00284                             return (TRUE);
00285                         }
00286                         if (!(lpszText = GlobalLock (hText))) {
00287                             OutOfMemory();
00288                             return (TRUE);
00289                         }
00290                                     strcpy(lpData, lpszText);
00291                         GlobalUnlock(hData);
00292                         GlobalUnlock (hText);
00293
00294                         /* Clear the current contents of the clipboard, and set
00295                          * the data handle to the new string.
00296                          */
00297
00298                         if (OpenClipboard(hWnd)) {
00299                             EmptyClipboard();
00300                             SetClipboardData(CF_TEXT, hData);
00301                             CloseClipboard();
00302                         }
00303                         hData = NULL;
00304
00305                                     if (LOWORD(wParam) == IDM_CUT) {
00306                             GlobalFree (hText);
00307                             hText = NULL;
00308                             EnableMenuItem(GetMenu (hWnd), IDM_CUT, MF_GRAYED);
00309                             EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_GRAYED);
00310                             InvalidateRect (hWnd, NULL, TRUE);
00311                             UpdateWindow (hWnd);
00312                         }
00313                     }
00314
00315                     return (TRUE);
00316
00317                 case IDM_PASTE:
00318                     if (OpenClipboard(hWnd)) {
00319
00320                         /* get text from the clipboard */
00321
00322                         if (!(hClipData = GetClipboardData(CF_TEXT))) {
00323                             CloseClipboard();
00324                             break;
00325                         }
00326                         if (hText != NULL) {
00327                             GlobalFree(hText);
00328                         }
00329                         if (!(hText = GlobalAlloc(GMEM_MOVEABLE
00330                                                     , GlobalSize(hClipData)))) {
00331                             OutOfMemory();
00332                             CloseClipboard();
00333                             break;
00334                         }
00335                         if (!(lpClipData = GlobalLock(hClipData))) {
00336                             OutOfMemory();
00337                             CloseClipboard();
00338                             break;
00339                         }
00340                         if (!(lpszText = GlobalLock(hText))) {
00341                             OutOfMemory();
00342                             CloseClipboard();
00343                             break;
00344                         }
00345                         strcpy(lpszText, lpClipData);
00346                         GlobalUnlock(hClipData);
00347                         CloseClipboard();
00348                         GlobalUnlock(hText);
00349                         EnableMenuItem(GetMenu(hWnd), IDM_CUT, MF_ENABLED);
00350                         EnableMenuItem(GetMenu(hWnd), IDM_COPY, MF_ENABLED);
00351
00352                         /* copy text to the application window */
00353
00354                         InvalidateRect(hWnd, NULL, TRUE);
00355                         UpdateWindow(hWnd);
00356                         return (TRUE);
00357                     }
00358                     else
00359                         return (FALSE);
00360             }
00361             break;
00362
00363             case WM_SIZE:
00364                 InvalidateRect(hWnd, NULL, TRUE);
00365                 break;
00366
00367             case WM_PAINT:
00368             hDC = BeginPaint (hWnd, &ps);
00369             if (hText != NULL) {
00370                 if (!(lpszText = GlobalLock (hText))) {
00371                     OutOfMemory();
00372                 } else {
00373                             GetClientRect (hWnd, &rectClient);
00374                     DrawText (hDC, lpszText, -1, &rectClient
00375                                 , DT_EXTERNALLEADING | DT_NOPREFIX | DT_WORDBREAK);
00376                     GlobalUnlock (hText);
00377                 }
00378             }
00379                 EndPaint (hWnd, &ps);
00380             break;
00381
00382             case WM_DESTROY:
00383                 PostQuitMessage(0);
00384             break;
00385
00386             default:
00387                 return (DefWindowProc(hWnd, message, wParam, lParam));
00388     }
00389     return (0);
00390 }
00391
00392
00393 /****************************************************************************
00394
00395     FUNCTION: About(HWND, unsigned, WORD, LONG)
00396
00397     PURPOSE:  Processes messages for "About" dialog box
00398
00399     MESSAGES:
00400
00401         WM_INITDIALOG - initialize dialog box
00402         WM_COMMAND    - Input received
00403
00404 ****************************************************************************/
00405
00406 BOOL APIENTRY About( HWND hDlg, UINT message, UINT wParam, LONG lParam)
00407 {
00408     switch (message) {
00409             case WM_INITDIALOG:
00410                 return (TRUE);
00411
00412             case WM_COMMAND:
00413                 if (LOWORD(wParam) == IDOK
00414                        || LOWORD(wParam) == IDCANCEL) {
00415
00416                         EndDialog(hDlg, TRUE);
00417                         return (TRUE);
00418             }
00419                 break;
00420     }
00421     return (FALSE);
00422         UNREFERENCED_PARAMETER(lParam);
00423 }
00424
00425
00426 /****************************************************************************
00427
00428     FUNCTION: OutOfMemory(void)
00429
00430     PURPOSE:  Displays warning message
00431
00432 ****************************************************************************/
00433 VOID OutOfMemory()
00434 {
00435     MessageBox(
00436         GetFocus(),
00437         "Out of Memory",
00438         NULL,
00439         MB_ICONHAND | MB_SYSTEMMODAL);
00440     return;
00441 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/SERVENUM.H Source File

  • SERVENUM
  • DLL

SERVENUM.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumdlg.h
00009 //
00010 //  PURPOSE:  contains enumdlg declarations
00011 //
00012 #ifndef _SERVENUM_H
00013 #define _SERVENUM_H
00014
00015 // MSVC++ 1.1 for NT does not define this in WINERROR.H
00016 #ifndef ERROR_CANCELLED
00017 #define ERROR_CANCELLED 1223L
00018 #endif
00019
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023
00024 //
00025 // ServerEnumDialog(
00026 //     HWND hwnd,              // Handle of calling window
00027 //     LPWSTR lpszServer,      // Buffer to store chosen server name
00028 //     LPDWORD lpcchServer,    // Pointer to size of buffer in bytes
00029 //     FARPROC lpfnHelpProc    // User-defined help procedure
00030 //     )
00031 //
00032 //  PURPOSE: Display a dialog box which allows a user to select
00033 //           a computer on the network.  The user may also type
00034 //           in a string.  The result is not guarenteed to be
00035 //           a valid computer name
00036 //
00037 //  PARAMETERS:
00038 //    hwnd - Handle of calling window
00039 //
00040 //    lpszServer - Buffer to store resultant server name in.
00041 //                 This should be of length MAX_COMPUTERNAME_LENGTH+3
00042 //
00043 //    lpcchServer - Pointer to size of lpszServer, including the NULL
00044 //                  terminating character.  The resultant length of the
00045 //                  string is stored here.  If ERROR_MORE_DATA is return,
00046 //                  the value is the required size of the buffer.
00047 //
00048 //    lpfnHelpProc - Pointer to user-defined help procedure.
00049 //                   The procedure should be prototyped as
00050 //                   int HelpProc( VOID );
00051 //
00052 //  RETURN VALUE:
00053 //    ERROR_SUCCESS - User selected or typed in a server name
00054 //    ERROR_CANCELLED - Dialog box was cancelled
00055 //    ERROR_NOT_ENOUGH_MEMORY - unable to initialize dialog box
00056 //    ERROR_MORE_DATA - lpszServer not large enough
00057 //
00058 //
00059
00060
00061 #ifdef UNICODE
00062 #define ServerEnumDialog ServerEnumDialogW
00063 #else
00064 #define ServerEnumDialog ServerEnumDialogA
00065 #endif
00066
00067
00068
00069 DWORD ServerEnumDialogW( HWND hwnd,
00070                          LPWSTR lpszServer,
00071                          LPDWORD lpcchServer,
00072                          FARPROC lpfnHelpProc
00073                         );
00074
00075 DWORD ServerEnumDialogA( HWND hwnd,
00076                          LPSTR lpszServer,
00077                          LPDWORD lpcchServer,
00078                          FARPROC lpfnHelpProc
00079                         );
00080
00081
00082 #ifdef __cplusplus
00083 }
00084 #endif
00085
00086 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CMNDLG/CDERR.H Source File

  • CMNDLG

CDERR.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define CDERR_DIALOGFAILURE   0xFFFF
00013
00014 #define CDERR_GENERALCODES     0x0000
00015 #define CDERR_STRUCTSIZE       0x0001
00016 #define CDERR_INITIALIZATION   0x0002
00017 #define CDERR_NOTEMPLATE       0x0003
00018 #define CDERR_NOHINSTANCE      0x0004
00019 #define CDERR_LOADSTRFAILURE   0x0005
00020 #define CDERR_FINDRESFAILURE   0x0006
00021 #define CDERR_LOADRESFAILURE   0x0007
00022 #define CDERR_LOCKRESFAILURE   0x0008
00023 #define CDERR_MEMALLOCFAILURE  0x0009
00024 #define CDERR_MEMLOCKFAILURE   0x000A
00025 #define CDERR_NOHOOK           0x000B
00026
00027 #define PDERR_PRINTERCODES     0x1000
00028 #define PDERR_SETUPFAILURE     0x1001
00029 #define PDERR_PARSEFAILURE     0x1002
00030 #define PDERR_RETDEFFAILURE    0x1003
00031 #define PDERR_LOADDRVFAILURE   0x1004
00032 #define PDERR_GETDEVMODEFAIL   0x1005
00033 #define PDERR_INITFAILURE      0x1006
00034 #define PDERR_NODEVICES        0x1007
00035 #define PDERR_NODEFAULTPRN     0x1008
00036 #define PDERR_DNDMMISMATCH     0x1009
00037 #define PDERR_CREATEICFAILURE  0x100A
00038 #define PDERR_PRINTERNOTFOUND  0x100B
00039
00040 #define CFERR_CHOOSEFONTCODES  0x2000
00041 #define CFERR_NOFONTS          0x2001
00042
00043 #define FNERR_FILENAMECODES    0x3000
00044 #define FNERR_SUBCLASSFAILURE  0x3001
00045 #define FNERR_INVALIDFILENAME  0x3002
00046 #define FNERR_BUFFERTOOSMALL   0x3003
00047
00048 #define FRERR_FINDREPLACECODES 0x4000
00049 #define CCERR_CHOOSECOLORCODES 0x5000
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/STREBLT.H Source File

  • STREBLT

STREBLT.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* streblt.h - header file for the streblt demonstration program. */
00013
00014
00015 /* function prototypes for the window procedures. */
00016 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00017 BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
00018
00019 VOID DrawGrids (HDC, int, int);
00020
00021 /* Top dialog item IDs */
00022 #define  DID_X           100
00023 #define  DID_Y           101
00024 #define  DID_WIDTH       102
00025 #define  DID_HEIGHT      103
00026 #define  DID_XSRC        104
00027 #define  DID_YSRC        105
00028 #define  DID_SRCWIDTH    106
00029 #define  DID_SRCHEIGHT   107
00030
00031 #define  DID_ROP0        110
00032 #define  DID_ROP1        111
00033 #define  DID_ROP2        112
00034 #define  DID_NEWSRC      116
00035
00036 #define  DID_DRAW        120
00037
00038 #define  DID_CB_MODE     150
00039 #define  DID_CB_PATTERN  151
00040 #define  DID_CB_ROPS     152
00041
00042
00043 /* accelerator IDs */
00044 #define AID_PASTE       55
00045 #define AID_COPY        56
00046 #define AID_CYCLE       57
00047
00048
00049
00050 /* Misc. defines for size, color, and appearance of drawing. */
00051 #define GRIDCOLOR  (COLORREF) 0x01000006
00052 #define DIALOGHEIGHT  90
00053 #define SEPARATORWIDTH 4
00054 #define MAXCHARS      32
00055 #define INC            5
00056
00057
00058
00059
00060 /* other user messages sent to the main window or the dialog */
00061 #define WM_PUTUPDESTRECT WM_USER+20
00062 #define WM_PUTUPSRCRECT  WM_USER+21
00063 #define WM_STRETCHBLT    WM_USER+23
00064
00065
00066
00067
00068 /* structure for the lookup tables.  */
00069 typedef struct tagLookupEntry{
00070     int     Value;
00071     char    String[30];
00072 } LookupEntry;
00073
00074
00075 #define NMODES  5
00076 LookupEntry  strebltModes[NMODES] =
00077     {{ 1, "BLACKONWHITE"},
00078      { 2, "COLORONCOLOR"},
00079      { 3, "WHITEONBLACK"},
00080      { 4, "BLEND       "},
00081      { 5, "HALFTONE    "}};
00082
00083
00084 #define NROPS  15
00085 LookupEntry  StandardROPs[NROPS] =
00086     {{ 0x00CC0020, "SRCCOPY"    },
00087      { 0x00EE0086, "SRCPAINT"   },
00088      { 0x008800C6, "SRCAND"     },
00089      { 0x00660046, "SRCINVERT"  },
00090      { 0x00440328, "SRCERASE"   },
00091      { 0x00330008, "NOTSRCCOPY" },
00092      { 0x001100A6, "NOTSRCERASE"},
00093      { 0x00C000CA, "MERGECOPY"  },
00094      { 0x00BB0226, "MERGEPAINT" },
00095      { 0x00F00021, "PATCOPY"    },
00096      { 0x00FB0A09, "PATPAINT"   },
00097      { 0x005A0049, "PATINVERT"  },
00098      { 0x00550009, "DSTINVERT"  },
00099      { 0x00000042, "BLACKNESS"  },
00100      { 0x00FF0062, "WHITENESS"  }};
00101
00102
00103 #define NPATTERNS  6
00104 LookupEntry Patterns[NPATTERNS] =
00105     {{  0, "WHITE_BRUSH "},
00106      {  1, "LTGRAY_BRUSH"},
00107      {  2, "GRAY_BRUSH  "},
00108      {  3, "DKGRAY_BRUSH"},
00109      {  4, "BLACK_BRUSH "},
00110      {  5, "NULL_BRUSH  "}};
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/WINMAIN.C Source File

  • NETDDE

WINMAIN.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   winmain.c
00009 //
00010 //  PURPOSE:   Calls initialization functions and processes the message loop
00011 //
00012 //
00013 //  PLATFORMS: Windows 95, Windows NT
00014 //
00015 //  FUNCTIONS:
00016 //    WinMain() - calls initialization functions, processes message loop
00017 //
00018 //  COMMENTS:
00019 //
00020 //
00021
00022 #include <windows.h>            // required for all Windows applications
00023 #ifdef WIN16
00024 #include "win16ext.h"           // required only for win16 applications
00025 #endif
00026 #include "globals.h"            // prototypes specific to this application
00027
00028 HINSTANCE g_hInstNetDde;
00029
00030 //
00031 //  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00032 //
00033 //  PURPOSE: calls initialization function, processes message loop
00034 //
00035 //  PARAMETERS:
00036 //
00037 //    hInstance - The handle to the instance of this application that
00038 //          is currently being executed.
00039 //
00040 //    hPrevInstance - The handle to the instance of this application
00041 //          that was last executed.  If this is the only instance
00042 //          of this application executing, hPrevInstance is NULL.
00043 //          In WindowsNT, this parameter is always NULL.
00044 //
00045 //    lpCmdLine - A pointer to a null terminated string specifying the
00046 //          command line of the application.
00047 //
00048 //    nCmdShow - Specifies how the main window is to be diplayed.
00049 //
00050 //  RETURN VALUE:
00051 //    If the function terminates before entering the message loop,
00052 //      return FALSE.
00053 //    Otherwise, return the WPARAM value sent by the WM_QUIT message.
00054 //
00055 //
00056 //  COMMENTS:
00057 //
00058 //    Windows recognizes this function by name as the initial entry point
00059 //    for the program.  This function calls the application initialization
00060 //    routine, if no other instance of the program is running, and always
00061 //    calls the instance initialization routine.  It then executes a
00062 //    message retrieval and dispatch loop that is the top-level control
00063 //    structure for the remainder of execution.  The loop is terminated
00064 //    when a WM_QUIT  message is received, at which time this function
00065 //    exits the application instance by returning the value passed by
00066 //    PostQuitMessage().
00067 //
00068 //    If this function must abort before entering the message loop, it
00069 //    returns the conventional value NULL.
00070 //
00071
00072 int APIENTRY WinMain(HINSTANCE hInstance,
00073                      HINSTANCE hPrevInstance,
00074                      LPSTR     lpCmdLine,
00075                      int       nCmdShow)
00076 {
00077     MSG msg;
00078     HANDLE hAccelTable;
00079     DWORD dwVersion;
00080
00081     // First check to see if we're running on Win95
00082     dwVersion = GetVersion();
00083     if (!(dwVersion < 0x8000000))
00084     {
00085         MessageBox(NULL,
00086                    TEXT("This application cannot run on Windows 95 or Win32s"),
00087                    TEXT("NDdeChat"), MB_OK | MB_ICONHAND);
00088         return (FALSE);
00089     }
00090
00091
00092     // Other instances of app running?
00093     if (!hPrevInstance)
00094     {
00095         // Initialize shared things
00096         if (!InitApplication(hInstance))
00097         {
00098             return FALSE;               // Exits if unable to initialize
00099         }
00100     }
00101
00102     // Attempt to load the NDDEAPI.DLL.  If this is Win95 it will fail.
00103     g_hInstNetDde = LoadLibrary(TEXT("NDDEAPI.DLL"));
00104     if (!g_hInstNetDde)
00105     {
00106         MessageBox(NULL, TEXT("Could not load NDDEAPI.DLL."), TEXT("NDDECHAT"), MB_OK);
00107         return (FALSE);
00108     }
00109
00110     // Perform initializations that apply to a specific instance
00111     if (!InitInstance(hInstance, nCmdShow))
00112     {
00113         return FALSE;
00114     }
00115
00116     hAccelTable = LoadAccelerators(hInstance, szAppName);
00117
00118
00119     // Acquire and dispatch messages until a WM_QUIT message is received.
00120     while (GetMessage(&msg, NULL, 0, 0))
00121     {
00122         //
00123         // **TODO** Add other Translation functions (for modeless dialogs
00124         //  and/or MDI windows) here.
00125         //
00126
00127         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
00128         {
00129             TranslateMessage(&msg);
00130             DispatchMessage(&msg);
00131         }
00132     }
00133
00134     //
00135     // **TODO** Call module specific instance free/delete functions here.
00136     //
00137     if (g_hInstNetDde)
00138         FreeLibrary(g_hInstNetDde);
00139
00140     // Returns the value from PostQuitMessage
00141     return msg.wParam;
00142 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SEMAPHOR/SEMA.H Source File

  • SEMAPHOR

SEMA.H

Go to the documentation of this file.
00001 #define GREEN    0x00007F00
00002 #define RED      0x0000007F
00003 #define GRAY     0x007F7F7F
00004 #define BLUE     0x007F0000
00005
00006 LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
00007 VOID ThreadProc (LPVOID *);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MISCUTIL.H Source File

  • SERVENUM
  • DLL

MISCUTIL.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: miscutil.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations misc. functions
00012 //
00013
00014 #ifndef _MISCUTIL_H
00015 #define _MISCUTIL_H
00016
00017 //-------------------------------------------------------------
00018 // misc prototypes
00019
00020 BOOL CenterWindow(HWND hwndChild, HWND hwndParent);
00021 HBITMAP SetBitmapBkgnd( HINSTANCE hinst, LPCTSTR szName, COLORREF rgbBkgnd );
00022 HFONT CreateStdFont (HWND hwnd, int heightPoints);
00023
00024 #endif
00025
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/WINMAIN.C Source File

  • SERVENUM
  • DEMO

WINMAIN.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   winmain.c
00009 //
00010 //  PURPOSE:   Calls initialization functions and processes the message loop
00011 //
00012 //
00013 //  PLATFORMS: Windows 95, Windows NT
00014 //
00015 //  FUNCTIONS:
00016 //    WinMain() - calls initialization functions, processes message loop
00017 //
00018 //  COMMENTS:
00019 //
00020 //
00021
00022 #include <windows.h>            // required for all Windows applications
00023 #include "globals.h"            // prototypes specific to this application
00024
00025 //
00026 //  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00027 //
00028 //  PURPOSE: calls initialization function, processes message loop
00029 //
00030 //  PARAMETERS:
00031 //
00032 //    hInstance - The handle to the instance of this application that
00033 //          is currently being executed.
00034 //
00035 //    hPrevInstance - The handle to the instance of this application
00036 //          that was last executed.  If this is the only instance
00037 //          of this application executing, hPrevInstance is NULL.
00038 //          In WindowsNT, this parameter is always NULL.
00039 //
00040 //    lpCmdLine - A pointer to a null terminated string specifying the
00041 //          command line of the application.
00042 //
00043 //    nCmdShow - Specifies how the main window is to be diplayed.
00044 //
00045 //  RETURN VALUE:
00046 //    If the function terminates before entering the message loop,
00047 //      return FALSE.
00048 //    Otherwise, return the WPARAM value sent by the WM_QUIT message.
00049 //
00050 //
00051 //  COMMENTS:
00052 //
00053 //    Windows recognizes this function by name as the initial entry point
00054 //    for the program.  This function calls the application initialization
00055 //    routine, if no other instance of the program is running, and always
00056 //    calls the instance initialization routine.  It then executes a
00057 //    message retrieval and dispatch loop that is the top-level control
00058 //    structure for the remainder of execution.  The loop is terminated
00059 //    when a WM_QUIT  message is received, at which time this function
00060 //    exits the application instance by returning the value passed by
00061 //    PostQuitMessage().
00062 //
00063 //    If this function must abort before entering the message loop, it
00064 //    returns the conventional value NULL.
00065 //
00066
00067 int APIENTRY WinMain(HINSTANCE hInstance,
00068                      HINSTANCE hPrevInstance,
00069                      LPSTR     lpCmdLine,
00070                      int       nCmdShow)
00071 {
00072     MSG msg;
00073     HANDLE hAccelTable;
00074
00075     // Check to see if this is Win95 or Windows NT.  This sample uses some
00076     // unicode and some other API's that aren't available in Win95 at least
00077     // in the BETA 2 release.  If it's not Win NT we'll gracefully exit.
00078     if (GetVersion() & 0x80000000)
00079     {
00080         MessageBox(NULL, TEXT("This program can only be run on Windows NT"),
00081                 TEXT("Server Enum Sample"), MB_ICONEXCLAMATION | MB_OK);
00082         return(0);
00083     }
00084
00085     // Other instances of app running?
00086     if (!hPrevInstance)
00087     {
00088         // Initialize shared things
00089         if (!InitApplication(hInstance))
00090         {
00091             return FALSE;               // Exits if unable to initialize
00092         }
00093     }
00094
00095     // Perform initializations that apply to a specific instance
00096     if (!InitInstance(hInstance, nCmdShow))
00097     {
00098         return FALSE;
00099     }
00100
00101     hAccelTable = LoadAccelerators(hInstance, szAppName);
00102
00103     // Acquire and dispatch messages until a WM_QUIT message is received.
00104     while (GetMessage(&msg, NULL, 0, 0))
00105     {
00106         //
00107         // **TODO** Add other Translation functions (for modeless dialogs
00108         //  and/or MDI windows) here.
00109         //
00110
00111         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
00112         {
00113             TranslateMessage(&msg);
00114             DispatchMessage(&msg);
00115         }
00116     }
00117
00118     //
00119     // **TODO** Call module specific instance free/delete functions here.
00120     //
00121
00122     // Returns the value from PostQuitMessage
00123     return msg.wParam;
00124 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDECHAT.C Source File

  • NETDDE

NDDECHAT.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:  nddechat.c
00009 //
00010 //  PURPOSE:  Implement the windows procedure for the main application
00011 //            windows.
00012 //
00013 //  FUNCTIONS:
00014 //    WndProc      - Processes messages for the main window.
00015 //    MsgCreate    - Handle the WM_CREATE messages for the main window.
00016 //    MsgSize      - Handle the WM_SIZE messages for the main window.
00017 //    MsgCommand   - Handle the WM_COMMAND messages for the main window.
00018 //    MsgDestroy   - Handles the WM_DESTROY message by calling
00019 //                   PostQuitMessage().
00020 //    CmdExit      - Handles the file exit command by calling destory
00021 //                   wi\nndow on the main window.
00022 //
00023 //  COMMENTS:
00024 //
00025 //  AUTHOR: Craig Link - Microsoft Developer Support
00026 //
00027
00028 #include <windows.h>            // required for all Windows applications
00029 #include <windowsx.h>
00030 #include <stdlib.h>
00031 #include <nddeapi.h>
00032 #ifdef WIN16
00033 #include "win16ext.h"           // required only for win16 applications
00034 #endif
00035
00036 #include "globals.h"            // prototypes specific to this application
00037 #include "nddeutil.h"
00038 #include "mem.h"
00039 #include "connect.h"
00040 #include "ddecback.h"
00041
00042 // Main window message table definition.
00043 MSD rgmsd[] =
00044 {
00045     {WM_CREATE,       MsgCreate},
00046     {WM_SIZE,         MsgSize},
00047     {WM_CONNECT,      MsgConnect},
00048     {WM_DISCONNECT,   MsgDisconnect},
00049     {WM_RECEIVE_TEXT, MsgReceiveText},
00050     {WM_COMMAND,      MsgCommand},
00051     {WM_DESTROY,      MsgDestroy}
00052 };
00053
00054 MSDI msdiMain =
00055 {
00056     sizeof(rgmsd) / sizeof(MSD),
00057     rgmsd,
00058     edwpWindow
00059 };
00060 // Main window command table definition.
00061 CMD rgcmd[] =
00062 {
00063     {IDM_CONNECT,    CmdConnectDlg},
00064     {IDM_DISCONNECT, CmdDisconnect},
00065     {IDE_SEND,       CmdSendNotify},
00066     {IDM_EXIT,       CmdExit},
00067     {IDM_ABOUT,      CmdAbout}
00068 };
00069
00070 CMDI cmdiMain =
00071 {
00072     sizeof(rgcmd) / sizeof(CMD),
00073     rgcmd,
00074     edwpWindow
00075 };
00076
00077 // Application "globals"
00078 HWND  g_hwnd;                     // handle of main window
00079 char  g_szServer[MAX_COMPUTERNAME_LENGTH+3];  // name of server connected to
00080 char  g_szTopic[MAX_TOPICNAME+1]; // netdde topic name
00081 BOOL  g_fState = STATE_UNCONN;    // the app is currently a DDE server
00082 DWORD g_idInst = 0;               // DDEML instance identifier
00083
00084 // Module specific "globals"  Used when a variable needs to be
00085 // accessed in more than on handler function.
00086
00087 LPSTR pszLast = NULL;             // contents of send buffer at time of last send
00088
00089 char szShareName[MAX_NDDESHARENAME+1];  // netdde share name
00090 char szItem[MAX_ITEMNAME+1];
00091
00092 HCONV hconv = 0;    // handle for DDEML conversation
00093
00094 HWND hwndRecv;      // handle of edit control for received data
00095 HWND hwndSend;      // handle of edit control for sent data
00096
00097
00098
00099 //
00100 //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
00101 //
00102 //  PURPOSE:  Processes messages for the main window.
00103 //
00104 //  PARAMETERS:
00105 //    hwnd     - window handle
00106 //    uMessage - message number
00107 //    wparam   - additional information (dependant on message number)
00108 //    lparam   - additional information (dependant on message number)
00109 //
00110 //  RETURN VALUE:
00111 //    The return value depends on the message number.  If the message
00112 //    is implemented in the message dispatch table, the return value is
00113 //    the value returned by the message handling function.  Otherwise,
00114 //    the return value is the value returned by the default window procedure.
00115 //
00116 //  COMMENTS:
00117 //    Call the DispMessage() function with the main window's message dispatch
00118 //    information (msdiMain) and the message specific information.
00119 //
00120
00121 LRESULT CALLBACK WndProc(HWND   hwnd,
00122                          UINT   uMessage,
00123                          WPARAM wparam,
00124                          LPARAM lparam)
00125 {
00126     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
00127 }
00128
00129
00130 //
00131 //  FUNCTION: MsgCreate(HWND, UINT, WPARAM, LPARAM)
00132 //
00133 //  PURPOSE: Initialized main window
00134 //
00135 //  PARAMETERS:
00136 //
00137 //    hwnd      - Window handle
00138 //    uMessage  - Message number WM_CREATE
00139 //    wparam    - Extra data     (Unused)
00140 //    lparam    - Extra data     (Unused)
00141 //
00142 //  RETURN VALUE:
00143 //
00144 //    Always returns 0 - Message handled
00145 //
00146 //  COMMENTS:
00147 //    Creates NetDDE share, initializes ddeml, and creates
00148 //    to edit controls in main window.
00149 //
00150
00151 LRESULT MsgCreate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00152 {
00153     RECT rc;
00154     HSZ  hszService;
00155
00156     g_hwnd = hwnd;
00157     EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
00158     EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );
00159
00160     // setup NetDDE Share ( require if acting as a server )
00161     LoadString(hInst, IDS_SHARENAME, (LPSTR)szShareName, MAX_NDDESHARENAME);
00162     LoadString(hInst, IDS_TOPIC, (LPSTR)g_szTopic, MAX_TOPICNAME);
00163     LoadString(hInst, IDS_ITEM, (LPSTR)szItem, MAX_ITEMNAME);
00164
00165     if ( !SetupNDDEShare(hwnd, (LPSTR)szShareName, (LPSTR)szAppName, (LPSTR)g_szTopic) )
00166     {
00167         MessageBox( hwnd, (LPSTR)"Unable to create NetDDE Share.",
00168                     (LPSTR)szAppName, MB_ICONSTOP | MB_OK );
00169         return 0;
00170     }
00171
00172     // Initialize DDEML conversation
00173     if (DdeInitialize (&g_idInst, (PFNCALLBACK) DdeCallback,
00174                        APPCLASS_STANDARD | CBF_FAIL_EXECUTES
00175                        | CBF_FAIL_REQUESTS | CBF_FAIL_SELFCONNECTIONS, 0L))
00176     {
00177         MessageBox (hwnd, (LPSTR)"Unable to initialize DDEML.",
00178                       szAppName, MB_ICONSTOP | MB_OK) ;
00179         return 0;
00180     }
00181
00182     hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0) ;
00183     DdeNameService (g_idInst, hszService, 0, DNS_REGISTER) ;
00184     DdeFreeStringHandle (g_idInst, hszService) ;
00185
00186     // Initialize user interface
00187     GetClientRect( hwnd, &rc );
00188
00189     hwndSend  = CreateWindow("EDIT",
00190                              NULL,
00191                              WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
00192                               | ES_LEFT | ES_MULTILINE | ES_WANTRETURN,
00193                              0,
00194                              0,
00195                              rc.right,
00196                              rc.bottom/2,
00197                              hwnd,
00198                              (HMENU) IDE_SEND,
00199                              hInst,
00200                              NULL );
00201
00202     hwndRecv  = CreateWindow("EDIT",
00203                              NULL,
00204                              WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER
00205                               | ES_LEFT | ES_MULTILINE | ES_READONLY | ES_WANTRETURN,
00206                              0,
00207                              rc.bottom/2,
00208                              rc.right,
00209                              rc.bottom/2,
00210                              hwnd,
00211                              (HMENU) IDE_RECV,
00212                              hInst,
00213                              NULL );
00214
00215     EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_ENABLED );
00216
00217     // initialize variable for last contents of send data
00218     MallocMem( (LPVOID *) &pszLast, 1 );
00219     *pszLast = '\0';
00220
00221     return 0;
00222 }
00223
00224
00225 //
00226 //  FUNCTION: MsgSize(HWND, UINT, WPARAM, LPARAM)
00227 //
00228 //  PURPOSE: Resize edit controls to client area size
00229 //
00230 //  PARAMETERS:
00231 //
00232 //    hwnd      - Window handle
00233 //    uMessage  - Message number WM_SIZE
00234 //    wparam    - Extra data     (Unused)
00235 //    lparam    - Extra data     (Unused)
00236 //
00237 //  RETURN VALUE:
00238 //
00239 //    Always returns 0 - Message handled
00240 //
00241 //  COMMENTS:
00242 //
00243 //
00244 LRESULT MsgSize(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00245 {
00246     MoveWindow(hwndSend, 0, 0, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
00247     MoveWindow(hwndRecv, 0, HIWORD(lparam)/2, LOWORD(lparam), HIWORD(lparam)/2, TRUE);
00248     return 0;
00249 }
00250
00251
00252 //
00253 //  FUNCTION: MsgConnect(HWND, UINT, WPARAM, LPARAM)
00254 //
00255 //  PURPOSE: Message indicating that a connection has occured
00256 //
00257 //  PARAMETERS:
00258 //    hwnd      - Window handle
00259 //    uMessage  - Message number WM_CONNECT
00260 //    wparam    - Extra data     (Unused)
00261 //    lparam    - HCONV for DDEML conversation
00262 //
00263 //  RETURN VALUE:
00264 //
00265 //    Always returns 0 - Message handled
00266 //
00267 //  COMMENTS:
00268 //
00269 //
00270 LRESULT MsgConnect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00271 {
00272     char szBuffer[128];
00273     DWORD cbBytes = 128;
00274     HSZ hszItem;
00275
00276     if ( g_fState == STATE_PENDING ) // only clients pend
00277     {
00278         // get the name of the local ( client ) computer to poke to server
00279 #ifdef WIN16
00280         NDdeGetNodeName( (LPSTR)szBuffer, cbBytes );
00281 #else
00282         GetComputerName( (LPSTR)szBuffer, &cbBytes );
00283 #endif
00284         // -1 signals computer name
00285         STR_DWORD((LPSTR)szBuffer) = (DWORD) -1;
00286
00287         hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0) ;
00288         DdeClientTransaction( (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer)+1+sizeof(DWORD),
00289                               hconv, hszItem, CF_TEXT, XTYP_POKE,
00290                               (DWORD) TIMEOUT_ASYNC, NULL);
00291
00292         DdeFreeStringHandle (g_idInst, hszItem) ;
00293
00294         g_fState = STATE_CLIENT;
00295
00296     }
00297
00298     // save conversation handle for disconnect
00299     hconv = (HCONV) lparam;
00300
00301     // set user interface
00302     if ( *g_szServer != '\0' )
00303     {
00304         wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connected to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
00305         SetWindowText( hwnd, (LPSTR)szBuffer );
00306     }
00307
00308     *pszLast = '\0';
00309
00310     SetWindowText( hwndRecv, (LPSTR)"" );
00311     SetWindowText( hwndSend, (LPSTR)"" );
00312     EnableMenuItem( GetMenu( g_hwnd ), IDM_DISCONNECT, MF_ENABLED );
00313     EnableMenuItem( GetMenu( g_hwnd ), IDM_CONNECT, MF_GRAYED );
00314
00315     SetFocus( hwndSend );
00316
00317     return 0;
00318 }
00319
00320
00321 //
00322 //  FUNCTION: MsgDisconnect(HWND, UINT, WPARAM, LPARAM)
00323 //
00324 //  PURPOSE: Message indicating that the conversation have been disconnected
00325 //
00326 //  PARAMETERS:
00327 //
00328 //    hwnd      - Window handle
00329 //    uMessage  - Message number WM_DISCONNECT
00330 //    wparam    - Extra data     (Unused)
00331 //    lparam    - Extra data     (Unused)
00332 //
00333 //  RETURN VALUE:
00334 //
00335 //    Always returns 0 - Message handled
00336 //
00337 //  COMMENTS:
00338 //
00339 //
00340 LRESULT MsgDisconnect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00341 {
00342     char szBuffer[128];
00343
00344     wsprintf( (LPSTR)szBuffer, (LPSTR)"Conversation with %s disconnected", (LPSTR) g_szServer );
00345     g_fState = STATE_UNCONN;
00346     *g_szServer = '\0';
00347     SetWindowText(hwnd, SZDESCRIPTION );
00348
00349     // reset menus
00350     EnableMenuItem(GetMenu(g_hwnd), IDM_CONNECT, MF_ENABLED );
00351     EnableMenuItem(GetMenu(g_hwnd), IDM_DISCONNECT, MF_GRAYED );
00352
00353     MessageBox( hwnd, szBuffer, szAppName, MB_OK );
00354     return 0;
00355 }
00356
00357
00358
00359 //
00360 //  FUNCTION: MsgReceiveText(HWND, UINT, WPARAM, LPARAM)
00361 //
00362 //  PURPOSE: Updates received edit control with received text
00363 //
00364 //  PARAMETERS:
00365 //    hwnd      - Window handle
00366 //    uMessage  - Message number WM_RECEIVE_TEXT
00367 //    wparam    - Size in bytes of data
00368 //    lparam    - Pointer to data
00369 //
00370 //  RETURN VALUE:
00371 //
00372 //    Always returns 0 - Message handled
00373 //
00374 //  COMMENTS:
00375 //    Data has the following format
00376 //    (LPSTR)String\0(DWORD)InsertionPrint
00377 //
00378 LRESULT MsgReceiveText(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00379 {
00380     DWORD ndx = GetWindowTextLength( hwndRecv );
00381
00382 #ifdef WIN16
00383     SendMessage( hwndRecv, EM_SETSEL, 1, MAKELONG((WORD)STR_DWORD((LPSTR)lparam), ndx) );
00384 #else
00385     SendMessage( hwndRecv, EM_SETSEL, (INT)STR_DWORD((LPSTR)lparam), (LPARAM)-1 );
00386 #endif
00387
00388     SendMessage( hwndRecv, EM_REPLACESEL, 0, lparam );
00389
00390     FreeMem( (LPVOID *) &lparam );
00391     return 0;
00392 }
00393
00394
00395
00396 //
00397 //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
00398 //
00399 //  PURPOSE: Handle the WM_COMMAND messages for the main window.
00400 //
00401 //  PARAMETERS:
00402 //    hwnd     - window handle
00403 //    uMessage - WM_COMMAND
00404 //    GET_WM_COMMAND_ID(wparam, lparam)   - Command identifier
00405 //    GET_WM_COMMAND_HWND(wparam, lparam) - Control handle
00406 //
00407 //  RETURN VALUE:
00408 //    The return value depends on the message number.  If the message
00409 //    is implemented in the message dispatch table, the return value is
00410 //    the value returned by the message handling function.  Otherwise,
00411 //    the return value is the value returned by the default window procedure.
00412 //
00413 //  COMMENTS:
00414 //    Call the DispCommand() function with the main window's command dispatch
00415 //    information (cmdiMain) and the command specific information.
00416 //
00417
00418 LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00419 {
00420     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
00421 }
00422
00423
00424 //
00425 //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
00426 //
00427 //  PURPOSE: Frees data and calls PostQuitMessage().
00428 //
00429 //  PARAMETERS:
00430 //
00431 //    hwnd      - Window handle  (Unused)
00432 //    uMessage  - Message number (Unused)
00433 //    wparam    - Extra data     (Unused)
00434 //    lparam    - Extra data     (Unused)
00435 //
00436 //  RETURN VALUE:
00437 //
00438 //    Always returns 0 - Message handled
00439 //
00440 //  COMMENTS:
00441 //
00442 //
00443 LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00444 {
00445     HSZ hszService = DdeCreateStringHandle (g_idInst, (LPSTR)szAppName, 0);
00446     DdeNameService (g_idInst, hszService, 0, DNS_UNREGISTER);
00447     DdeFreeStringHandle (g_idInst, hszService);
00448
00449     if ( pszLast )
00450         FreeMem( (LPVOID *) &pszLast );
00451
00452     PostQuitMessage(0);
00453     return 0;
00454 }
00455
00456
00457
00458 //
00459 //  FUNCTION: CmdConnectDlg(HWND, WORD, WORD, HWND)
00460 //
00461 //  PURPOSE: Displays the "ConnectDlg" dialog box and initiates connection
00462 //
00463 //  PARAMETERS:
00464 //    hwnd      - Window handle
00465 //    wCommand  - IDM_CONNECT
00466 //    wNotify   - Notification number (unused)
00467 //    hwndCtrl  - NULL (unused)
00468 //
00469 //  RETURN VALUE:
00470 //
00471 //    Always returns 0 - Message handled
00472 //
00473 //  COMMENTS:
00474 //    Only clients will encounter this message
00475 //
00476 LRESULT CmdConnectDlg(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00477 {
00478
00479     char szBuffer[128];
00480     char szService[MAX_COMPUTERNAME_LENGTH+9];  // extra for \\%s\NDDE$
00481     HSZ hszService;
00482     HSZ hszShare;
00483     HSZ hszItem;
00484
00485     *g_szServer = '\0';
00486
00487     if ( DialogBox(hInst, "ConnectDlgBox", hwnd, (DLGPROC)ConnectDlg) )
00488     {
00489         wsprintf( (LPSTR) szService, "%s\\NDDE$", (LPSTR) g_szServer );
00490
00491         hszService = DdeCreateStringHandle (g_idInst, (LPSTR) szService, 0) ;
00492         hszShare   = DdeCreateStringHandle (g_idInst, (LPSTR) szShareName,   0) ;
00493
00494         hconv = DdeConnect (g_idInst, hszService, hszShare, NULL) ;
00495
00496         DdeFreeStringHandle (g_idInst, hszService) ;
00497         DdeFreeStringHandle (g_idInst, hszShare) ;
00498
00499         if (!hconv)
00500         {
00501             MessageBox (hwnd, (LPSTR)"Cannot connect to server.",
00502                         (LPSTR)szAppName, MB_ICONEXCLAMATION | MB_OK) ;
00503
00504             return 0 ;
00505         }
00506
00507         // Request notification of item
00508         hszItem = DdeCreateStringHandle (g_idInst, szItem, 0) ;
00509
00510         DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
00511                               XTYP_ADVSTART | XTYPF_ACKREQ,
00512                               (DWORD )TIMEOUT_ASYNC, NULL) ;
00513
00514         DdeFreeStringHandle (g_idInst, hszItem) ;
00515
00516         g_fState = STATE_PENDING;
00517         wsprintf( (LPSTR)szBuffer, (LPSTR)"%s - Connecting to %s", (LPSTR)SZDESCRIPTION, (LPSTR)g_szServer );
00518         SetWindowText( hwnd, (LPSTR)szBuffer );
00519
00520         EnableMenuItem( GetMenu( hwnd ), IDM_DISCONNECT, MF_GRAYED );
00521         EnableMenuItem( GetMenu( hwnd ), IDM_CONNECT, MF_GRAYED );
00522     }
00523
00524     return 0;
00525 }
00526
00527
00528 //
00529 //  FUNCTION: CmdDisconnect(HWND, WORD, WORD, HWND)
00530 //
00531 //  PURPOSE: Issues a disconnect for the current converstaion
00532 //
00533 //  PARAMETERS:
00534 //    hwnd      - Window handle
00535 //    wCommand  - IDM_DISCONNECT
00536 //    wNotify   - Notification number (unused)
00537 //    hwndCtrl  - NULL (unused)
00538 //
00539 //  RETURN VALUE:
00540 //
00541 //    Always returns 0 - Message handled
00542 //
00543 //  COMMENTS:
00544 //    To process the IDM_ENTRY message, call DialogBox() to display the
00545 //    phbkdlg dialog box.
00546 //
00547 LRESULT CmdDisconnect(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00548 {
00549     HSZ hszItem;
00550
00551     if ( g_fState == STATE_CLIENT )
00552     {
00553         hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);
00554
00555         DdeClientTransaction (NULL, 0, hconv, hszItem, CF_TEXT,
00556                               XTYP_ADVSTOP, (DWORD)TIMEOUT_ASYNC, NULL) ;
00557
00558         DdeFreeStringHandle (g_idInst, hszItem) ;
00559     }
00560
00561     // Disconnect the conversation
00562     DdeDisconnect (hconv) ;
00563
00564     PostMessage( hwnd, WM_DISCONNECT, 0, 0 );
00565
00566     return 0;
00567 }
00568
00569
00570 //
00571 //  FUNCTION: CmdSendNotify(HWND, WORD, WORD, HWND)
00572 //
00573 //  PURPOSE: Handles notification messages for SEND edit control
00574 //
00575 //  PARAMETERS:
00576 //    hwnd      - Window handle
00577 //    wCommand  - IDM_DISCONNECT
00578 //    wNotify   - Notification number (unused)
00579 //    hwndCtrl  - NULL (unused)
00580 //
00581 //  RETURN VALUE:
00582 //
00583 //    Always returns 0 - Message handled
00584 //
00585 //  COMMENTS:
00586 //    To process the IDM_ENTRY message, call DialogBox() to display the
00587 //    phbkdlg dialog box.
00588 //
00589 LRESULT CmdSendNotify(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00590 {
00591     HSZ hszTopic;
00592     HSZ hszItem;
00593     HDDEDATA hdata;
00594
00595     if ( wNotify == EN_CHANGE )
00596     {
00597         hszTopic = DdeCreateStringHandle (g_idInst, (LPSTR)g_szTopic, 0);
00598         hszItem = DdeCreateStringHandle (g_idInst, (LPSTR)szItem, 0);
00599
00600         if ( g_fState == STATE_SERVER )
00601             DdePostAdvise (g_idInst, hszTopic, hszItem) ;
00602         else
00603         {
00604             if ( (hdata = GetDataToTrans()) != 0 )
00605             {
00606                 DdeClientTransaction( (LPBYTE) hdata, (DWORD) -1, hconv,
00607                                       hszItem, CF_TEXT, XTYP_POKE,
00608                                       (DWORD)TIMEOUT_ASYNC, NULL);
00609             }
00610         }
00611
00612         DdeFreeStringHandle (g_idInst, hszItem) ;
00613         DdeFreeStringHandle (g_idInst, hszTopic) ;
00614
00615     }
00616     return 0;
00617 }
00618
00619 //
00620 //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
00621 //
00622 //  PURPOSE: Exit the application.
00623 //
00624 //  PARAMETERS:
00625 //    hwnd     - The window.
00626 //    wCommand - IDM_EXIT
00627 //    wNotify  - Notification number (unused)
00628 //    hwndCtrl - NULL (unused)
00629 //
00630 //  RETURN VALUE:
00631 //    Always returns 0 - command handled.
00632 //
00633 //  COMMENTS:
00634 //
00635 //
00636 LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00637 {
00638     DestroyWindow(hwnd);
00639     return 0;
00640 }
00641
00642
00643 //
00644 //  FUNCTION: GetDataToTrans( VOID )
00645 //
00646 //  PURPOSE: Determines what data to needs to be transmitted
00647 //
00648 //  PARAMETERS:
00649 //    none
00650 //
00651 //  RETURN VALUE:
00652 //    Always returns 0 - command handled.
00653 //
00654 //  COMMENTS:
00655 //    Data has the following format
00656 //    (LPSTR)String\0(DWORD)InsertionPrint
00657 //
00658 HDDEDATA GetDataToTrans( VOID )
00659 {
00660     HDDEDATA hdata;
00661     HSZ hszItem;
00662     LPSTR pszNew;
00663     LPSTR pszN;
00664     LPSTR pszL;
00665     DWORD cbBytes = GetWindowTextLength( hwndSend );
00666
00667     if ( MallocMem( (LPVOID *) &pszNew, cbBytes+1+sizeof(DWORD) ) == ERROR_SUCCESS )
00668     {
00669         GetWindowText( hwndSend, pszNew, (int)cbBytes+1 );
00670
00671         pszN = pszNew;
00672         pszL = pszLast;
00673
00674         // increment pointed while ...
00675         // 1) not at end of Last string
00676         // 2) not at end of New string
00677         // 3) New char is equal to Last char
00678
00679         // compute the insertion point of changed text
00680         if( !(*pszL) || !(*pszN) )
00681             STR_DWORD(pszNew) = 0;
00682         else
00683         {
00684             while ( *pszN++ == *pszL++ ) ;
00685             pszN--;
00686             STR_DWORD(pszNew) = (DWORD) ( pszL - 1 - pszLast );
00687         }
00688
00689         hszItem = DdeCreateStringHandle (g_idInst, szItem, 0);
00690         hdata = DdeCreateDataHandle (g_idInst, pszN, cbBytes+1+sizeof(DWORD)-STR_DWORD(pszNew),
00691                                      0, hszItem, CF_TEXT, 0);
00692         DdeFreeStringHandle (g_idInst, hszItem) ;
00693
00694         FreeMem( &pszLast );
00695         pszLast = pszNew;
00696     }
00697
00698     return hdata;
00699 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LOADTEST.C Source File

  • SIMPLDLL

LOADTEST.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     LOADTEST.C
00015 *
00016 *  PURPOSE:     A simple demonstration of LoadLibrary()-ing a DLL at
00017 *               runtime and obtaining function addresses within the DLL.
00018 *
00019 *  FUNTIONS:    WinMain     - initialization, create window, msg loop
00020 *               MainWndProc - processes main window msgs
00021 *               ThreadProc  - makes a single call into "THE_DLL.DLL"
00022 *               AboutDlgProc- processes about dialog messages
00023 *
00024 \******************************************************************************/
00025
00026 #include <windows.h>
00027 #include "loadtest.h"
00028 #include "the_dll.h"
00029
00030
00031
00032 /******************************************************************************\
00033 *
00034 *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
00035 *
00036 *  GLOBAL VARS: ghwndMain - handle of main app window
00037 *
00038 *  LOCAL VARS:  msg - msg to get/dispatch
00039 *
00040 \******************************************************************************/
00041
00042 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00043                     LPSTR lpCmdLine, int nCmdShow)
00044 {
00045   MSG msg;
00046
00047   if (!hPrevInstance)
00048   {
00049     WNDCLASS wc;
00050
00051     wc.style         = 0;
00052     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00053     wc.cbClsExtra    = 0;
00054     wc.cbWndExtra    = 0;
00055     wc.hInstance     = hInstance;
00056     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
00057     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
00058     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00059     wc.lpszMenuName  = (LPCTSTR) "Menu";
00060     wc.lpszClassName = (LPCTSTR) "LOADTEST";
00061
00062     if (!RegisterClass (&wc))
00063     {
00064       MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
00065                   (LPCTSTR) "Err! - LOADTEST", MB_OK | MB_ICONEXCLAMATION);
00066       return(FALSE);
00067     }
00068   }
00069
00070   if (!(ghwndMain = CreateWindow ("LOADTEST", "LOADTEST Sample Application",
00071                                   WS_OVERLAPPEDWINDOW,
00072                                   CW_USEDEFAULT, CW_USEDEFAULT,
00073                                   CW_USEDEFAULT, CW_USEDEFAULT,
00074                                   NULL, NULL, hInstance, NULL)))
00075     return (0);
00076
00077   ShowWindow (ghwndMain, nCmdShow);
00078
00079   while (GetMessage (&msg, NULL, 0, 0))
00080   {
00081     TranslateMessage (&msg);
00082     DispatchMessage  (&msg);
00083   }
00084
00085   return (msg.wParam);
00086 }
00087
00088
00089
00090 /******************************************************************************\
00091 *
00092 *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
00093 *
00094 *  GLOBAL VARS: pfnDLLFunction1 - pointer to DLLFunction1
00095 *               pfnDLLFunction2 - pointer to DLLFunction2
00096 *               pfnDLLFunction3 - pointer to DLLFunction3
00097 *               pfnDLLFunction4 - pointer to DLLFunction4
00098 *               pfnDLLDialogBox - pointer to DLLDialogBox
00099 *
00100 *  LOCAL VARS:  hLib     - handle of THE_DLL.DLL
00101 *               hSubMenu - handle of our "Options" submenu
00102 *
00103 *  COMMENTS:    Menuitems IDM_DLLFUNCTION1 through IDM_DLLDIALOGBOX are
00104 *               all processed by calling their respective functions in
00105 *               "THE_DLL.DLL". The "CreateThread" menuitem causes a thread
00106 *               to be created- the thread then calls into "THE_DLL.DLL".
00107 *
00108 \******************************************************************************/
00109
00110 LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam,
00111                               LPARAM lParam)
00112 { static HANDLE hLib = NULL;
00113   static HMENU  hSubMenu;
00114
00115   switch (message)
00116   {
00117     case WM_CREATE:
00118     {
00119       HMENU hMenu = GetMenu (hwnd);
00120
00121       hSubMenu = GetSubMenu (hMenu, 0);
00122       FixMenu (IDM_FREELIBRARY, hSubMenu);
00123       break;
00124     }
00125
00126     case WM_COMMAND:
00127
00128       switch (LOWORD(wParam))
00129       {
00130         case IDM_LOADLIBRARY:
00131
00132           if (!hLib)
00133           {
00134             if (!(hLib = LoadLibrary ("THE_DLL.DLL")))
00135
00136               MessageBox (hwnd,
00137                           (LPCTSTR) "MainWndProc(): LoadLibrary () failed",
00138                           (LPCTSTR) "Err! - LOADTEST",
00139                           MB_OK | MB_ICONEXCLAMATION);
00140             else
00141             {
00142               gpfnDLLFunction1 = (PFNDLL) GetProcAddress (hLib,
00143                                                           "DLLFunction1");
00144               gpfnDLLFunction2 = (PFNDLL) GetProcAddress (hLib,
00145                                                           "DLLFunction2");
00146               gpfnDLLFunction3 = (PFNDLL) GetProcAddress (hLib,
00147                                                           "DLLFunction3");
00148               gpfnDLLFunction4 = (PFNDLL) GetProcAddress (hLib,
00149                                                           "DLLFunction4");
00150               gpfnDLLDialogBox = (PFNDLL) GetProcAddress (hLib,
00151                                                           "DLLDialogBox");
00152               FixMenu (IDM_LOADLIBRARY, hSubMenu);
00153             }
00154           }
00155           break;
00156
00157         case IDM_FREELIBRARY:
00158
00159           if (hLib)
00160           {
00161             FreeLibrary (hLib);
00162             gpfnDLLFunction1 = NULL;
00163             gpfnDLLFunction2 = NULL;
00164             gpfnDLLFunction3 = NULL;
00165             gpfnDLLFunction4 = NULL;
00166             gpfnDLLDialogBox = NULL;
00167             FixMenu (IDM_FREELIBRARY, hSubMenu);
00168             hLib = NULL;
00169           }
00170           break;
00171
00172         case IDM_CREATETHREAD:
00173         {
00174           DWORD tid; /* thread identifier */
00175
00176           if (gpfnDLLFunction1)
00177
00178             CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)
00179                           ThreadProc, NULL, 0, &tid);
00180
00181           break;
00182         }
00183
00184         case IDM_DLLFUNCTION1:
00185
00186           if (gpfnDLLFunction1)
00187
00188             (gpfnDLLFunction1) ();
00189
00190           break;
00191
00192         case IDM_DLLFUNCTION2:
00193
00194           if (gpfnDLLFunction2)
00195
00196             (gpfnDLLFunction2) ((int) 0);
00197
00198           break;
00199
00200         case IDM_DLLFUNCTION3:
00201
00202           if (gpfnDLLFunction3)
00203
00204             (gpfnDLLFunction3) ((HANDLE) NULL);
00205
00206           break;
00207
00208         case IDM_DLLFUNCTION4:
00209
00210           if (gpfnDLLFunction4)
00211
00212             (gpfnDLLFunction4) ((HWND) NULL);
00213
00214           break;
00215
00216         case IDM_DLLDIALOGBOX:
00217
00218           if (gpfnDLLDialogBox)
00219
00220             (gpfnDLLDialogBox) (hwnd);
00221
00222           break;
00223
00224         case IDM_ABOUT:
00225
00226           DialogBox (GetModuleHandle (NULL), (LPCTSTR)"About", hwnd,
00227                      (DLGPROC) AboutDlgProc);
00228           break;
00229
00230         default:
00231
00232           break;
00233       }
00234       break;
00235
00236     case WM_DESTROY:
00237
00238       PostQuitMessage(0);
00239       break;
00240
00241     default:
00242
00243       return (DefWindowProc(hwnd, message, wParam, lParam));
00244   }
00245   return (0);
00246 }
00247
00248
00249
00250 /******************************************************************************\
00251 *
00252 *  FUNCTION:    Thread
00253 *
00254 *  GLOBAL VARS: ghwndMain        - handle of main app window
00255 *               pfnDLLFunction1 - pointer to DLLFunction1
00256 *
00257 *  COMMENTS:    Makes a call into "THE_DLL.DLL", and then waits for the
00258 *               main window to call TerminateThread().
00259 *
00260 \******************************************************************************/
00261
00262 void ThreadProc ()
00263 {
00264   MessageBox (ghwndMain, (LPCTSTR) "calling DLLFunction1",
00265               (LPCTSTR) "ThreadProc()", MB_OK);
00266   (gpfnDLLFunction1) ();
00267 }
00268
00269
00270
00271 /******************************************************************************\
00272 *
00273 *  FUNCTION:    FixMenu
00274 *
00275 *  INPUTS:      choice   - IDM_LOADLIBRARY or IBM_FREELIBRARY
00276 *               hSubMenu - handle of submenu, the items of which we'll
00277 *                          enable/disable
00278 *
00279 *  LOCAL VARS:  i - loop variable
00280 *
00281 *  COMMENTS:    Enables/disables menuitems depending on whether THE_DLL
00282 *               is loaded/unloaded.
00283 *
00284 \******************************************************************************/
00285
00286 void FixMenu (UINT choice, HMENU hSubMenu)
00287 {
00288   UINT i;
00289
00290   if (choice == IDM_LOADLIBRARY)
00291   {
00292     EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_DISABLED | MF_GRAYED |
00293                                                MF_BYCOMMAND);
00294
00295     for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)
00296
00297       EnableMenuItem (hSubMenu, i, MF_ENABLED | MF_BYCOMMAND);
00298   }
00299   else /* choice == IDM_FREELIBRARY */
00300   {
00301     EnableMenuItem (hSubMenu, IDM_LOADLIBRARY, MF_ENABLED | MF_BYCOMMAND);
00302
00303     for (i = IDM_FREELIBRARY; i <= IDM_DLLDIALOGBOX; i++)
00304
00305       EnableMenuItem (hSubMenu, i, MF_DISABLED | MF_GRAYED |MF_BYCOMMAND);
00306
00307   }
00308 }
00309
00310
00311
00312 /******************************************************************************\
00313 *
00314 *  FUNCTION:    AboutDlgProc (standard dialog procedure INPUTS/RETURNS)
00315 *
00316 *  COMMENTS:    Displays "about" message
00317 *
00318 \******************************************************************************/
00319
00320 BOOL CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam,
00321                                LPARAM lParam)
00322 { switch (message)
00323   {
00324     case WM_COMMAND:
00325
00326       if (LOWORD(wParam) == IDOK)
00327       {
00328         EndDialog(hwnd, TRUE);
00329         return (TRUE);
00330       }
00331       return (TRUE);
00332   }
00333   return (FALSE);
00334 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/SERVENUM.C Source File

  • SERVENUM
  • DLL

SERVENUM.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   servenum.c
00009 //
00010 //  PURPOSE:   Implements ServerEnumDialog API
00011 //
00012 //  FUNCTIONS:
00013 //    DllMain - handles DLL initialization
00014 //    ServerEnumDialogW - Unicode version of API
00015 //    ServerEnumDialogA - ASCII version of API - calls unicode version
00016 //
00017 //  COMMENTS:
00018 //    Implements APIs for the ServerEnumDialog.
00019 //
00020 //  AUTHOR: Craig Link - Microsoft Developer Support
00021 //
00022
00023 #include <windows.h>
00024 #include "servenum.h"
00025 #include "enumdlg.h"
00026 #include "enumutil.h"
00027 #include "thrdutil.h"
00028 #include "miscutil.h"
00029 #include "mem.h"
00030
00031 DWORD ndxTls;
00032 HMODULE g_hMod;
00033
00034
00035 //
00036 //  FUNCTION: DllMain( HMODULE hMod, DWORD dwReason, LPVOID lpReserved )
00037 //
00038 //  PURPOSE:  Handle DLL issues
00039 //
00040 //  PARAMETERS:
00041 //    hMod - module handle of DLL
00042 //    dwReason - reason DllMain is being called
00043 //    lpReserved - reserved
00044 //
00045 //  RETURN VALUE:
00046 //    TRUE
00047 //    FALSE
00048 //
00049 //  COMMENTS:
00050 //
00051 BOOL WINAPI DllMain( HMODULE hMod, DWORD dwReason, LPVOID lpReserved )
00052 {
00053     BOOL bRet = TRUE;
00054
00055     switch ( dwReason )
00056     {
00057         case DLL_PROCESS_ATTACH:
00058             g_hMod = hMod;
00059             InitializeCriticalSection( &g_csOutstanding );
00060             if ( (DWORD)-1 == (ndxTls = TlsAlloc() ) )
00061             {
00062                DeleteCriticalSection( &g_csOutstanding );
00063                bRet = FALSE;
00064             }
00065             break;
00066
00067         case DLL_THREAD_ATTACH:
00068             break;
00069
00070         case DLL_THREAD_DETACH:
00071             break;
00072
00073         case DLL_PROCESS_DETACH:
00074             WaitCloseOutstanding();
00075             DeleteCriticalSection( &g_csOutstanding );
00076             TlsFree( ndxTls );
00077             break;
00078     }
00079
00080     return bRet;
00081 }
00082
00083
00084 //
00085 //  FUNCTION: ServerEnumDialogW( HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc )
00086 //
00087 //  PURPOSE: Display dialogbox which allows a user to select a computer
00088 //
00089 //  PARAMETERS:
00090 //    hwnd - Handle to calling window
00091 //    lpszServer - Buffer to store chosen server name
00092 //    lpcchServer - Size of buffer in bytes
00093 //    lpfnHelpProc - User-defined help procedure
00094 //
00095 //  RETURN VALUE:
00096 //    ERROR_SUCCESS
00097 //    ERROR_CANCELLED
00098 //    ERROR_NOT_ENOUGH_MEMORY
00099 //    ERROR_MORE_DATA
00100 //
00101 //  COMMENTS:
00102 //    Unicode version of the API
00103 //
00104 DWORD ServerEnumDialogW( HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc )
00105 {
00106     HDC hdc;
00107     HFONT hfontOld;
00108     DWORD dwRet = ERROR_SUCCESS;
00109     LPTLSOBJECT lpTls;
00110
00111
00112     if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpTls, sizeof(TLSOBJECT) ) ) )
00113     {
00114         TlsSetValue( ndxTls, (LPVOID) lpTls );
00115
00116         lpTls->lpszServer = lpszServer;
00117         lpTls->lpcchServer = lpcchServer;
00118         lpTls->lpfnHelpProc = lpfnHelpProc;
00119
00120         lpTls->hfont = CreateStdFont( hwnd, 8 );
00121         hdc = GetDC( hwnd );
00122         hfontOld = SelectObject( hdc, lpTls->hfont );
00123         GetTextMetrics(hdc, &(lpTls->tm) );
00124         SelectObject( hdc, hfontOld );
00125         ReleaseDC( hwnd, hdc );
00126
00127         dwRet = DialogBox(g_hMod, TEXT("EnumDlgBox"), hwnd, (DLGPROC)EnumDlg);
00128
00129         DeleteObject( lpTls->hfont );
00130
00131         FreeMem( &lpTls );
00132     }
00133
00134     RefreshOutstanding(); // try cleaning up any outstanding threads
00135
00136     return dwRet;
00137
00138 }
00139
00140
00141 //
00142 //  FUNCTION: ServerEnumDialogW( HWND hwnd, LPWSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc )
00143 //
00144 //  PURPOSE: Display dialogbox which allows a user to select a computer
00145 //
00146 //  PARAMETERS:
00147 //    hwnd - Handle to calling window
00148 //    lpszServer - Buffer to store chosen server name
00149 //    lpcchServer - Size of buffer in bytes
00150 //    lpfnHelpProc - User-defined help procedure
00151 //
00152 //  RETURN VALUE:
00153 //    ERROR_SUCCESS
00154 //    ERROR_CANCELLED
00155 //    ERROR_NOT_ENOUGH_MEMORY
00156 //    ERROR_MORE_DATA
00157 //
00158 //  COMMENTS:
00159 //    ASCII version of the API
00160 //
00161 DWORD ServerEnumDialogA( HWND hwnd, LPSTR lpszServer, LPDWORD lpcchServer, FARPROC lpfnHelpProc )
00162 {
00163     DWORD dwRet;
00164     WCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];
00165
00166     if ( ERROR_SUCCESS == ( dwRet = ServerEnumDialogW( hwnd, szServer, lpcchServer, lpfnHelpProc ) ) )
00167         WideCharToMultiByte( CP_ACP, 0, szServer, *lpcchServer, lpszServer, *lpcchServer, NULL, NULL );
00168     return dwRet;
00169 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TERMPROC/TERMPROC.C Source File

  • TERMPROC

TERMPROC.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <stdarg.h>
00015 #include <windows.h>
00016 #include <string.h>
00017 #include <math.h>
00018 #include <winbase.h>
00019
00020 /*-----------------------------------------------------------------*/
00021
00022 void ErrorOut(char errstring[30])
00023 /*
00024 Purpose: Print out an meainful error code by means of
00025          GetLastError and printf
00026
00027 Inputs:  errstring - the action that failed, passed by the
00028                      calling proc.
00029
00030 Returns: none
00031
00032 Calls:   GetLastError
00033 */
00034
00035 {
00036 DWORD Error;
00037
00038 Error= GetLastError();
00039 printf("Error on %s = %d\n", errstring, Error);
00040 }
00041
00042 /*-----------------------------------------------------------------*/
00043
00044
00045 void main(int argc, char *argv[])
00046 /*
00047 Purpose: terminate a process based on the PID passed in
00048
00049 Inputs:  argc - number of arguments passed in
00050          argv - arguments, including PID of process to terminate
00051
00052 Returns: none
00053
00054 Calls:   GetLastError
00055          OpenProcess - to get handle to process
00056          TerminateProcess - to terminate process
00057 */
00058
00059 {
00060 HANDLE hProcess;
00061 double ProcId;
00062 BOOL TermSucc;
00063 int chrintval, chrpos, downcount;
00064 int count=0;
00065 DWORD dwVersion;
00066
00067
00068     // check if running on Windows NT, if not, display notice and terminate
00069     dwVersion = GetVersion();
00070     if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00071     {
00072          MessageBoxA( NULL,
00073          "This sample application cannot be run on Windows 3.1.\n"
00074          "This application will now terminate.",
00075          "TermProc",
00076          MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00077       return;
00078     }
00079
00080 if (argc == 2)  /* if a PID is passed in */
00081   {
00082     chrpos= strcspn( argv[1], "\0");
00083     count=0;
00084     ProcId=0;
00085
00086          /* convert decimal value to hex */
00087     for (downcount = chrpos -1 ; downcount >= 0; downcount--)
00088       {
00089       if (argv[1][downcount] >= '0' && argv[1][downcount] <= '9')
00090         chrintval= argv[1][downcount]-48;
00091       else
00092         if (argv[1][downcount] >= 'a' && argv[1][downcount] <= 'f')
00093           chrintval= argv[1][downcount]-87;
00094         else
00095           chrintval= argv[1][downcount]-55;
00096       ProcId+= chrintval * pow( (double)16.0, (double)count );
00097       count++;
00098       }
00099        /* open the process to terminate */
00100   hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, (DWORD)ProcId);
00101   if (hProcess == NULL)
00102     ErrorOut("OpenProcess");
00103   TermSucc= TerminateProcess(hProcess, 0); /* terminate it */
00104   if (TermSucc == FALSE)
00105     ErrorOut("TerminateProcess");
00106   else
00107     printf("Process# %s terminated successfully!\n", argv[1]);
00108   }
00109 else  /* no PID, inform user of operation */
00110   {
00111   printf("\nTerminates an active Process\n");
00112   printf("Usage: termproc ProcessID\n");
00113   }
00114
00115 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/MINREC.H Source File

  • MINREC

MINREC.H

Go to the documentation of this file.
00001 // ************************************************************************
00002 //
00003 //                      Microsoft Developer Support
00004 //               Copyright (c) 1992-1996 Microsoft Corporation
00005 //
00006 // **************************************************************************
00007 // PROGRAM: MinRec.H
00008 // PURPOSE: A Small Win32 Recorder-like Sample Application Header File
00009 // **************************************************************************
00010
00011 //-- menu items
00012 #define IDM_FILE_EXIT          199
00013
00014 #define IDM_MACRO_PLAYBACK     801
00015 #define IDM_MACRO_RECORD       802
00016 #define IDM_MACRO_STOP         803
00017
00018 #define IDM_HELP_ABOUT         205
00019
00020 //-- string ids
00021 #define IDS_APPNAME           1000
00022 #define IDS_SHORT_APPNAME     1001
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/MAIN.H Source File

  • RESDLL

MAIN.H

Go to the documentation of this file.
00001 /******************************************************************************\
00002 *
00003 *                               MAIN.H
00004 *
00005 \******************************************************************************/
00006
00007
00008
00009 /******************************************************************************\
00010 *                          GLOBAL VARIABLES
00011 \******************************************************************************/
00012
00013 HANDLE ghLib;
00014
00015
00016
00017 /******************************************************************************\
00018 *                         FUNCTION PROTOTYPES
00019 \******************************************************************************/
00020
00021 LRESULT CALLBACK MainWndProc  (HWND, UINT, WPARAM, LPARAM);
00022
00023 void DrawBitmap               (HDC,  HBITMAP, int,  int);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/DISPLAY.H Source File

  • UNIPUT

DISPLAY.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* structure for the character range 'name' lookup table.  */
00013 typedef struct tagLookupEntry{
00014     USHORT   start;
00015     USHORT   end;
00016     TCHAR    String[32];
00017 } LookupEntry;
00018
00019 /* The following data comes straight out of the Addison-Wesley Unicode book. */
00020 #define NRANGE 24
00021 LookupEntry  RangeName[NRANGE] =
00022     {{ 0x0000,0x007f, TEXT("ASCII")},
00023      { 0x0080,0x00ff, TEXT("Latin1 Characters")},
00024      { 0x0100,0x017f, TEXT("European Latin")},
00025      { 0x0180,0x01ff, TEXT("Extended Latin")},
00026      { 0x0200,0x024f, TEXT("<Bad unicode range.>")},
00027      { 0x0250,0x02af, TEXT("Standard Phonetic")},
00028      { 0x02b0,0x02ff, TEXT("Modifier Letters")},
00029      { 0x0300,0x036f, TEXT("Generic Diacritical Marks")},
00030      { 0x0370,0x03ff, TEXT("Greek")},
00031      { 0x0400,0x04ff, TEXT("Cyrillic")},
00032      { 0x0500,0x052f, TEXT("<Bad unicode range.>")},
00033      { 0x0530,0x058f, TEXT("Armenian")},
00034      { 0x0590,0x05ff, TEXT("Hebrew")},
00035      { 0x0600,0x06ff, TEXT("Arabic")},
00036      { 0x0900,0x1fff, TEXT("<not specified in table.>")},
00037      { 0x2000,0x206f, TEXT("General Punctutation")},
00038      { 0x2070,0x209f, TEXT("Superscipts & Subscripts")},
00039      { 0x20a0,0x20cf, TEXT("Currency Symbols")},
00040      { 0x20d0,0x20ff, TEXT("Diacritical Marks for Symbols")},
00041      { 0x2100,0x214f, TEXT("Letterlike Symbols")},
00042      { 0x2150,0x218f, TEXT("Number Forms")},
00043      { 0x2190,0x21ff, TEXT("Arrows")},
00044      { 0x2200,0x22ff, TEXT("Mathematical Operators")},
00045      { 0x2300,0xffff, TEXT("<not specified in table.>")}};
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: POLYDRAW/POLYDRAW.C Source File

  • POLYDRAW

POLYDRAW.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  polydraw.c -- sample program demonstrating PolyDraw().
00014 *
00015 * The user is able to place control points on the screen, and then
00016 *  drag them.  The PolyDraw() call is made to dynamically show the
00017 *  resulting curve.
00018 \**************************************************************************/
00019
00020 #include <windows.h>
00021 #include "polydraw.h"
00022
00023
00024
00025 /**************************************************************************\
00026 *
00027 *  function:  WinMain()
00028 *
00029 *  input parameters:  c.f. generic sample
00030 *
00031 \**************************************************************************/
00032 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00033                    LPSTR lpCmdLine, int nCmdShow)
00034 {
00035     HANDLE hInst;
00036     HWND   hwndMain;
00037     MSG   msg;
00038
00039     UNREFERENCED_PARAMETER( lpCmdLine );
00040
00041
00042     /* Check for previous instance.  If none, then register class. */
00043     if (!hPrevInstance) {
00044         WNDCLASS  wc;
00045
00046         wc.style = CS_VREDRAW;
00047         wc.lpfnWndProc = (WNDPROC)MainWndProc;
00048
00049         wc.cbClsExtra = 0;
00050         wc.cbWndExtra = 0;
00051         wc.hInstance = hInstance;
00052         wc.hIcon = LoadIcon(hInstance, "polydrawIcon");
00053         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00054         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00055         wc.lpszMenuName =  NULL;
00056         wc.lpszClassName = "polydraw";
00057
00058         if (!RegisterClass(&wc)) return (FALSE);
00059     }  /* class registered o.k. */
00060
00061
00062     /* Create the main window.  Return false if CreateWindow() fails */
00063     hInst = hInstance;
00064
00065     hwndMain = CreateWindow(
00066         "polydraw",
00067         "PolyDraw",
00068         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
00069         CW_USEDEFAULT,
00070         CW_USEDEFAULT,
00071         CW_USEDEFAULT,
00072         CW_USEDEFAULT,
00073         NULL,
00074         NULL,
00075         hInstance,
00076         NULL);
00077
00078     if (!hwndMain) return (FALSE);
00079     ShowWindow(hwndMain, nCmdShow);
00080     UpdateWindow(hwndMain);
00081
00082
00083     /* Loop getting messages and dispatching them. */
00084     while (GetMessage(&msg,NULL, 0,0)) {
00085         TranslateMessage(&msg);
00086         DispatchMessage(&msg);
00087     }
00088
00089     return (msg.wParam);
00090 }
00091
00092
00093
00094 /**************************************************************************\
00095 *
00096 *  function:  MainWndProc()
00097 *
00098 *  input parameters:  normal window procedure parameters.
00099 *
00100 *  global variables: none.
00101 *
00102 *  static variables:
00103 *   svPoints[] - array that stores the points for the GDI calls.
00104 *   svTypes[]  - array of bytes to store the type for the PolyDraw() calls.
00105 *   svIndex    - when tracking, the index of the point we are modifying.
00106 *   svNumDown  - the number of points currently in the client area.
00107 *   hPen*     - Pens to draw the lines, curves, or erase with.
00108 *
00109 * The PolyDraw() function is different from PolyBezier in that the current
00110 *  point is taken to be the first point, and the first point passed in in
00111 *  the array is actually the second point in the bezier or line or whatever,
00112 *  thus ...
00113 *        PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);
00114 *  instead of ...
00115 *        PolyDraw (hdc, svPoints, svTypes, svNumDown+1);
00116 *
00117 \**************************************************************************/
00118 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00119 {
00120 static HANDLE hPenGrey, hPenLine, hPenpolydraw;
00121 static POINT svPoints [MAXPOINTS];
00122 static BYTE  svTypes  [MAXPOINTS];
00123 static int   svNumDown;
00124 static int   svIndex;
00125
00126   switch (message) {
00127
00128
00129     /**********************************************************************\
00130     *  WM_CREATE
00131     *
00132     * Initialize the static variables.
00133     *  Then create three pens for drawing with later.
00134     \**********************************************************************/
00135     case WM_CREATE:
00136         svNumDown = NONE;
00137         svIndex = NONE;
00138         hPenLine     = CreatePen (PS_SOLID, 1, (COLORREF) 0x0100000f);
00139         hPenpolydraw = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000005);
00140         hPenGrey     = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000007);
00141     break;
00142
00143
00144     /**********************************************************************\
00145     *  WM_DESTROY
00146     *
00147     * Complement of the WM_CREATE message.  Delete the pens that were
00148     *  created and then call postquitmessage.
00149     \**********************************************************************/
00150     case WM_DESTROY:
00151       DeleteObject (hPenLine);
00152       DeleteObject (hPenpolydraw);
00153       DeleteObject (hPenGrey);
00154
00155       PostQuitMessage(0);
00156     break;
00157
00158
00159
00160
00161     /**********************************************************************\
00162     *  WM_LBUTTONDOWN
00163     *
00164     * Hittest to see if the user is selecting an existing point.
00165     *  If not, check for point overflow.
00166     *  If o.k. then add a new point to the current list.
00167     \**********************************************************************/
00168     case WM_LBUTTONDOWN: {
00169       int i;
00170       RECT rectNear;
00171
00172       /* Construct a rectangle around the mouse point. */
00173       rectNear.left   = LOWORD(lParam) - HITSIZE;
00174       rectNear.right  = LOWORD(lParam) + HITSIZE;
00175       rectNear.top    = HIWORD(lParam) - HITSIZE;
00176       rectNear.bottom = HIWORD(lParam) + HITSIZE;
00177
00178       /* step through all points so far.  hittest mouse location against
00179        *  each one.  If we hit one, set index, capture mouse and exit
00180        *  window procedure.
00181        */
00182       for (i = 0; i<= svNumDown; i++) {
00183         if (PtInRect (&rectNear, svPoints[i])) {
00184           svIndex = i;
00185           SetCapture (hwnd);
00186           return 0;
00187         }
00188       }
00189
00190       /* we did not hit an old point, watch for overflow. */
00191       if (svNumDown == (MAXPOINTS-1)) {
00192         MessageBox (hwnd,
00193                     "Points may be dragged with left mouse button.",
00194                     "No more points allowed",
00195                     MB_OK | MB_ICONSTOP);
00196         return 0;
00197       }
00198
00199       /* don't have old point, still room for more.  Put down one more. */
00200       if (GetCapture() != hwnd) {
00201         svNumDown++;
00202         svPoints[svNumDown].x = LOWORD(lParam);
00203         svPoints[svNumDown].y = HIWORD(lParam);
00204
00205         /* set the type value in the array dependent upon keyboard state. */
00206         if (wParam & MK_SHIFT)        svTypes [svNumDown] = PT_MOVETO;
00207         else if (wParam & MK_CONTROL) svTypes [svNumDown] = PT_BEZIERTO;
00208         else                          svTypes [svNumDown] = PT_LINETO;
00209
00210         InvalidateRect (hwnd, NULL, TRUE);
00211       }
00212
00213     }break;
00214
00215
00216     /**********************************************************************\
00217     *  WM_MOUSEMOVE
00218     *
00219     * If the curve is tracking the mouse, the erase the old curve by drawing
00220     *  over it with the grey pen.  Redraw the new curves with the proper pens.
00221     \**********************************************************************/
00222     case WM_MOUSEMOVE: {
00223       if (GetCapture() == hwnd) {
00224         HDC hdc;
00225
00226         hdc = GetDC (hwnd);
00227         MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);
00228
00229         /* Erase the old lines and curves. */
00230         SelectObject(hdc, hPenGrey);
00231         Polyline (hdc, svPoints, svNumDown+1);
00232         PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);
00233
00234         /* Change the point to match the new mouse position. */
00235         svPoints[svIndex].x = (int)(short)LOWORD(lParam);
00236         svPoints[svIndex].y = (int)(short)HIWORD(lParam);
00237
00238         MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);
00239         SelectObject(hdc, hPenLine);
00240         Polyline (hdc, svPoints, svNumDown+1);
00241         SelectObject(hdc, hPenpolydraw);
00242         PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);
00243
00244         ReleaseDC (hwnd, hdc);
00245       }
00246     }break;
00247
00248
00249
00250     /**********************************************************************\
00251     *  WM_LBUTTONUP
00252     *
00253     * Finished tracking.  Release the mouse capture, and force repaint.
00254     \**********************************************************************/
00255     case WM_LBUTTONUP:
00256       if (GetCapture() == hwnd) {
00257         SetCapture (NULL);
00258         InvalidateRect (hwnd, NULL, FALSE);
00259       }
00260     break;
00261
00262
00263     /**********************************************************************\
00264     *  WM_RBUTTONDOWN
00265     *
00266     * Re-Initialize the static variables, and force a repaint
00267     \**********************************************************************/
00268     case WM_RBUTTONDOWN:
00269       svNumDown = NONE;
00270       svIndex = NONE;
00271       InvalidateRect (hwnd, NULL, TRUE);
00272     break;
00273
00274
00275
00276     /**********************************************************************\
00277     *  WM_PAINT
00278     *
00279     * Write the instructions at the bottom of the window.  (Note that these
00280     *  lines may be erased by user MOUSEMOVE actions.)  Draw the polyline
00281     *  then draw the PolyDraw.
00282     \**********************************************************************/
00283     case WM_PAINT: {
00284       HDC hdc;
00285       PAINTSTRUCT ps;
00286       RECT  rect;
00287       int   height,x,y;
00288
00289       hdc = BeginPaint(hwnd, &ps);
00290
00291       /* set the background mode, the write out the 4 instruction strings. */
00292       SetBkMode (hdc, TRANSPARENT);
00293       height = GetSystemMetrics (SM_CYCAPTION);
00294       GetClientRect (hwnd, &rect);
00295       x = rect.left + 10;
00296       y = rect.bottom - 4*height;
00297       TextOut (hdc, x,y, instructions0,sizeof(instructions0)-1);
00298       y = rect.bottom - 3*height;
00299       TextOut (hdc, x,y, instructions1,sizeof(instructions1)-1);
00300       y = rect.bottom - 2*height;
00301       TextOut (hdc, x,y, instructions2,sizeof(instructions2)-1);
00302       y = rect.bottom - 1*height;
00303       TextOut (hdc, x,y, instructions3,sizeof(instructions3)-1);
00304
00305
00306       /* Move to the first point in the array and then call polydraw */
00307       MoveToEx (hdc, svPoints[0].x, svPoints[0].y, NULL);
00308
00309       SelectObject(hdc, hPenLine);
00310       Polyline (hdc, svPoints, svNumDown+1);
00311       SelectObject(hdc, hPenpolydraw);
00312       PolyDraw (hdc, &svPoints[1], &svTypes[1], svNumDown);
00313
00314       EndPaint (hwnd, &ps);
00315     } return FALSE;
00316
00317   } /* end switch */
00318   return (DefWindowProc(hwnd, message, wParam, lParam));
00319 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSDLL.H Source File

  • TLS

TLSDLL.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 INT WINAPI TlsInit();
00013 INT WINAPI TlsRetreive(DWORD);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETSYS/GETSYS.C Source File

  • GETSYS

GETSYS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  getsys.c -- sample program demonstrating the GetSys... APIs
00014 *
00015 *  In this sample the main window is a dialog box.  There is no need to
00016 *   register a new window class or create a new window.  Instead just call
00017 *   DialogBox() and use the template defined in the .RC file.  All of the
00018 *   interesting code is thus in the window procedure for the dialog box.
00019 *   In this case, simply respond to the button command messsages and fill
00020 *   the list box with appropriate values.
00021 *
00022 \**************************************************************************/
00023
00024 #include <windows.h>
00025 #include "getsys.h"
00026
00027
00028 /**************************************************************************\
00029 *
00030 *  function:  WinMain()
00031 *
00032 *  input parameters:  c.f. generic sample
00033 *
00034 \**************************************************************************/
00035 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00036                    LPSTR lpCmdLine, int nCmdShow)
00037 {
00038 int ret;
00039
00040     UNREFERENCED_PARAMETER( hPrevInstance );
00041     UNREFERENCED_PARAMETER( lpCmdLine );
00042     UNREFERENCED_PARAMETER( nCmdShow);
00043
00044     ret = DialogBox (hInstance, "getsysDlg", NULL, (DLGPROC)MainDlgProc);
00045     return ret;
00046 }
00047
00048
00049
00050 /**************************************************************************\
00051 *
00052 *  function:  MainDlgProc()
00053 *
00054 *  input parameters:  standard window procedure parameters.
00055 *
00056 \**************************************************************************/
00057 LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00058 {
00059   UNREFERENCED_PARAMETER(lParam);
00060
00061
00062   switch (message) {
00063
00064     /********************************************************************\
00065     * WM_INITDIALOG
00066     *
00067     * Set a monospaced font into the listbox so columns line up nicely.
00068     \********************************************************************/
00069     case WM_INITDIALOG:
00070       SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT,
00071         (WPARAM) GetStockObject (SYSTEM_FIXED_FONT), (LPARAM) 0 );
00072     break;
00073
00074
00075     /********************************************************************\
00076     * WM_SYSCOMMAND
00077     *
00078     * ignore all syscommand messages, except for SC_CLOSE.
00079     *  on this one, call EndDialog().
00080     \********************************************************************/
00081     case WM_SYSCOMMAND:
00082       if (wParam == SC_CLOSE) {
00083         EndDialog (hwnd, TRUE);
00084         return TRUE;
00085       } else
00086         return FALSE;
00087     break;
00088
00089
00090     /********************************************************************\
00091     * WM_COMMAND
00092     *
00093     * When the different buttons are hit, clear the list box, disable
00094     *  updating to it, call the function which will fill it, reenable
00095     *  updating, and then force a repaint.
00096     *
00097     \********************************************************************/
00098     case WM_COMMAND:
00099
00100       /* if the list box sends back messages, return.  Otherwise we will
00101        *  clear it out, and that is not what we want to do at this point.
00102        */
00103       if (LOWORD(wParam)==DID_LISTBOX) return TRUE;
00104
00105       SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW,    FALSE, 0);
00106       SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0,     0);
00107
00108       /* switch on the control ID of the button that is pressed. */
00109       switch (LOWORD(wParam)) {
00110         case DID_SYSCOLORS : doSysColors (hwnd); break;
00111         case DID_DIRECTORY : doDirectory (hwnd); break;
00112         case DID_INFO      : doInfo      (hwnd); break;
00113         case DID_METRICS   : doMetrics   (hwnd); break;
00114         case DID_PALETTE   : doPalette   (hwnd); break;
00115         case DID_LOCALTIME : doLocalTime (hwnd); break;
00116         case DID_TIME      : doTime      (hwnd); break;
00117         case DID_VERSIONEX : doVersionEx (hwnd); break;
00118       } /* end switch (LOWORD()) */
00119
00120       SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETREDRAW, TRUE, 0);
00121       InvalidateRect (GetDlgItem (hwnd, DID_LISTBOX), NULL, TRUE);
00122       return TRUE;
00123     break; /* end WM_COMMAND */
00124
00125
00126     default: return FALSE;
00127   } /* end switch(message) */
00128 }
00129
00130
00131
00132
00133
00134
00135 /**************************************************************************\
00136 *
00137 *  functions:  do...()
00138 *
00139 * In all of the functions that follow, first set the text int the static
00140 *  text field to label the contents of the list box.  Then, query the
00141 *  desired system information, format it into strings, and add those strings
00142 *  to the listbox.
00143 *
00144 *  input parameters:  HWND - window handle for the dialog box.
00145 *  global variables:  buffer - array of char's to hold string w/ info.
00146 *
00147 \**************************************************************************/
00148
00149 VOID doSysColors (HWND hwnd)
00150 {
00151 int i;
00152 DWORD answer;
00153
00154   SetDlgItemText (hwnd, DID_TEXT, "System Colors");
00155
00156   for (i = 0; i<NSYSCOLORS; i++) {
00157
00158     /*******************************************************/
00159     /*******************************************************/
00160     answer = GetSysColor (SysColors[i].Value);
00161     /*******************************************************/
00162     /*******************************************************/
00163
00164     wsprintf (buffer, SysColors[i].String, (int)answer);
00165     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00166   }
00167   return;
00168 }
00169
00170
00171
00172 VOID doDirectory (HWND hwnd)
00173 {
00174 char buffer[MAX_PATH];
00175
00176   SetDlgItemText (hwnd, DID_TEXT, "System Directory");
00177
00178   /*******************************************************/
00179   /*******************************************************/
00180   GetSystemDirectory (buffer, MAX_PATH);
00181   /*******************************************************/
00182   /*******************************************************/
00183
00184   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00185
00186   return;
00187 }
00188
00189
00190 VOID doInfo(HWND hwnd)
00191 {
00192 SYSTEM_INFO  si;
00193
00194   SetDlgItemText (hwnd, DID_TEXT, "SYSTEM_INFO");
00195
00196   /*******************************************************/
00197   /*******************************************************/
00198   GetSystemInfo (&si);
00199   /*******************************************************/
00200   /*******************************************************/
00201
00202   wsprintf (buffer, "wProcessorArchitecture      %d", (int) si.wProcessorArchitecture    );
00203   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00204   wsprintf (buffer, "wReserved                   %d", (int) si.wReserved                 );
00205   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00206   wsprintf (buffer, "dwPageSize                  %d",  (int) si.dwPageSize                 );
00207   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00208   wsprintf (buffer, "lpMinimumApplicationAddress %08lx", (LONG)si.lpMinimumApplicationAddress );
00209   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00210   wsprintf (buffer, "lpMaximumApplicationAddress %08lx", (LONG)si.lpMaximumApplicationAddress );
00211   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00212   wsprintf (buffer, "dwActiveProcessorMask       %d",  (int) si.dwActiveProcessorMask      );
00213   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00214   wsprintf (buffer, "dwNumberOfProcessors        %d",  (int) si.dwNumberOfProcessors       );
00215   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00216   wsprintf (buffer, "dwProcessorType             %d",  (int) si.dwProcessorType            );
00217   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00218   wsprintf (buffer, "dwAllocationGranularity     %d",  (int) si.dwAllocationGranularity    );
00219   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00220   wsprintf (buffer, "wProcessorLevel             %d",  (int) si.wProcessorLevel            );
00221   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00222   wsprintf (buffer, "wProcessorRevision          %d",  (int) si.wProcessorRevision         );
00223   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00224
00225   return;
00226 }
00227
00228
00229
00230 VOID doMetrics   (HWND hwnd)
00231 {
00232 int  i;
00233 int  answer;
00234
00235   SetDlgItemText (hwnd, DID_TEXT, "System Metrics");
00236
00237   for (i = 0; i<sizeof(SystemMetrics)/sizeof(LookupEntry); i++) {
00238
00239     /*******************************************************/
00240     /*******************************************************/
00241     answer = GetSystemMetrics (SystemMetrics[i].Value);
00242     /*******************************************************/
00243     /*******************************************************/
00244
00245     wsprintf (buffer, SystemMetrics[i].String, (int)answer);
00246     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00247   }
00248
00249   return;
00250 }
00251
00252
00253
00254 VOID doPalette(HWND hwnd)
00255 {
00256 int nEntries;
00257 HDC hdc;
00258 int i;
00259 LPPALETTEENTRY  lpp;
00260
00261   SetDlgItemText (hwnd, DID_TEXT, "System Palette");
00262
00263   /* this function is slightly different because the amount of information
00264    * is not known until run time.  First find the number of entries in the
00265    * palette (16 for VGA, but 256 for 8514, ...), then allocate enough
00266    * space to hold all of them, query the information, put it in the list
00267    * box, and then free up the memory allocated.
00268    */
00269   hdc = GetDC (hwnd);
00270   nEntries = GetSystemPaletteEntries (hdc, 0,0, NULL);
00271   lpp = (LPPALETTEENTRY)LocalAlloc (LPTR,
00272                            (DWORD) (nEntries* sizeof (PALETTEENTRY)));
00273
00274   if (lpp == NULL) {
00275     MessageBox (hwnd, "Memory allocation failed.", "Warning", MB_ICONSTOP | MB_OK);
00276     return;
00277   }
00278
00279   /*******************************************************/
00280   /*******************************************************/
00281   nEntries = GetSystemPaletteEntries (hdc, 0,nEntries, lpp);
00282   /*******************************************************/
00283   /*******************************************************/
00284
00285   ReleaseDC (hwnd, hdc);
00286
00287   for (i = 0; i<nEntries; i++) {
00288     wsprintf (buffer, "%d) \t%02x \t%02x \t%02x \t%02x", i,
00289               lpp[i].peRed, lpp[i].peGreen, lpp[i].peBlue, lpp[i].peFlags);
00290     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00291   }
00292
00293   LocalFree (LocalHandle ((LPSTR)lpp));
00294   return;
00295 }
00296
00297
00298
00299
00300 VOID doLocalTime (HWND hwnd)
00301 {
00302 SYSTEMTIME  st;
00303
00304   SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");
00305
00306   /*******************************************************/
00307   /*******************************************************/
00308   GetLocalTime (&st);
00309   /*******************************************************/
00310   /*******************************************************/
00311
00312   wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
00313   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00314   wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
00315   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00316   wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
00317   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00318   wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
00319   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00320   wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
00321   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00322   wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
00323   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00324   wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
00325   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00326   wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
00327   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00328   return;
00329 }
00330
00331
00332
00333 VOID doTime (HWND hwnd)
00334 {
00335 SYSTEMTIME  st;
00336
00337   SetDlgItemText (hwnd, DID_TEXT, "SYSTEMTIME");
00338
00339   /*******************************************************/
00340   /*******************************************************/
00341   GetSystemTime (&st);
00342   /*******************************************************/
00343   /*******************************************************/
00344
00345   wsprintf (buffer, "wYear         \t%d",  (int)st.wYear         );
00346   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00347   wsprintf (buffer, "wMonth        \t%d",  (int)st.wMonth        );
00348   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00349   wsprintf (buffer, "wDayOfWeek    \t%d",  (int)st.wDayOfWeek    );
00350   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00351   wsprintf (buffer, "wDay          \t%d",  (int)st.wDay          );
00352   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00353   wsprintf (buffer, "wHour         \t%d",  (int)st.wHour         );
00354   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00355   wsprintf (buffer, "wMinute       \t%d",  (int)st.wMinute       );
00356   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00357   wsprintf (buffer, "wSecond       \t%d",  (int)st.wSecond       );
00358   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00359   wsprintf (buffer, "wMilliseconds \t%d",  (int)st.wMilliseconds );
00360   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00361   return;
00362 }
00363
00364
00365
00366
00367
00368 VOID doVersionEx (HWND hwnd)
00369 {
00370 OSVERSIONINFO osvi;
00371
00372   osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
00373   SetDlgItemText (hwnd, DID_TEXT, "OSVERSIONINFO");
00374
00375   /*******************************************************/
00376   /*******************************************************/
00377   GetVersionEx (&osvi);
00378   /*******************************************************/
00379   /*******************************************************/
00380
00381
00382   wsprintf (buffer, "dwOSVersionInfoSize %d",  (int)osvi.dwOSVersionInfoSize );
00383   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00384   wsprintf (buffer, "dwMajorVersion      %d",  (int)osvi.dwMajorVersion );
00385   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00386   wsprintf (buffer, "dwMinorVersion      %d",  (int)osvi.dwMinorVersion );
00387   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00388   wsprintf (buffer, "dwBuildNumber       %d",  (int)osvi.dwBuildNumber );
00389   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00390   wsprintf (buffer, "dwPlatformId        %d",  (int)osvi.dwPlatformId );
00391   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00392   wsprintf (buffer, "szCSDVersion:       %s",  (LPTSTR) osvi.szCSDVersion );
00393   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00394
00395
00396 #ifdef GETVERSION
00397   wsprintf (buffer, "GetVersion(): 0x%08x",  GetVersion () );
00398   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00399 #endif
00400
00401   return;
00402 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/STREBLT.C Source File

  • STREBLT

STREBLT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  streblt.c -- sample program demonstrating StretchBlt()
00014 *
00015 *  design:  There is one main window with one dialog box streblted to fill
00016 *   the top of it.  The parameters for the StretchBlt() are stored in the
00017 *   entry fields of this dialog box.  The user may change these values and
00018 *   see the effect on the blt.  The top dialog also offers a chance to set
00019 *   the streblt blt mode, to select pattern brushes for the hdc, and to
00020 *   select from standard raster operations
00021 \**************************************************************************/
00022
00023
00024 #include <windows.h>
00025 #include <commdlg.h>
00026 #include <math.h>
00027 #include <string.h>
00028 #include <stdio.h>
00029 #include "streblt.h"
00030 #include "track.h"
00031 #include "bitmap.h"
00032
00033
00034 /* Global variables */
00035 HANDLE hInst;
00036 HWND   hwndMain, hwndDlg;
00037
00038 PTrackObject ptoSrc, ptoDest = NULL;
00039 HDC          hdcSrc, hdcDest;
00040 HBITMAP      hbmSrc = NULL;
00041
00042 #define NONE -1
00043 int strebltMode = NONE;
00044 int iPatternBrush = NONE;
00045
00046
00047
00048
00049
00050 /**************************************************************************\
00051 *
00052 *  function:  WinMain()
00053 *
00054 *  input parameters:  c.f. generic sample
00055 *
00056 \**************************************************************************/
00057 int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
00058                     LPSTR lpCmdLine, int nCmdShow)
00059 {
00060     MSG   msg;
00061     RECT rect;
00062     HANDLE haccel;
00063     DWORD dwVersion;
00064
00065     UNREFERENCED_PARAMETER( lpCmdLine );
00066
00067     // check if running on Windows NT, if not, display notice and terminate
00068     dwVersion = GetVersion();
00069     if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4))
00070     {
00071         MessageBoxA( NULL,
00072             "This sample application cannot be run on Windows 3.1.\n"
00073             "This application will now terminate.",
00074             "StreBlt",
00075             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00076         return( 1 );
00077     }
00078
00079     /* Check for previous instance.  If none, then register class. */
00080     if (!hPrevInstance) {
00081         WNDCLASS  wc;
00082
00083         wc.style = 0;
00084         wc.lpfnWndProc = (WNDPROC)MainWndProc;
00085
00086         wc.cbClsExtra = 0;
00087         wc.cbWndExtra = 0;
00088         wc.hInstance = hInstance;
00089         wc.hIcon = LoadIcon(hInstance, "strebltIcon");
00090         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00091         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00092         wc.lpszMenuName =  NULL;
00093         wc.lpszClassName = "streblt";
00094
00095         if (!RegisterClass(&wc)) return (FALSE);
00096     }  /* class registered o.k. */
00097
00098
00099     /* Create the main window.  Return false if CreateWindow() fails */
00100     hInst = hInstance;
00101
00102     hwndMain = CreateWindow(
00103         "streblt",
00104         "StretchBlt()",
00105         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
00106         CW_USEDEFAULT,
00107         CW_USEDEFAULT,
00108         CW_USEDEFAULT,
00109         CW_USEDEFAULT,
00110         NULL,
00111         NULL,
00112         hInstance,
00113         NULL);
00114
00115     if (!hwndMain) return (FALSE);
00116
00117
00118     /* create the top dialog as a child of the main window. */
00119     hwndDlg = CreateDialog (hInst, "strebltDlg", hwndMain, (DLGPROC)DlgProc);
00120
00121     /* Send main window a WM_SIZE message so that it will size the top
00122      *  dialog correctly.  Also, force a repaint of the main window
00123      *  now that the dialog is there and we can draw the arc.
00124      */
00125     GetClientRect (hwndMain, &rect);
00126     SendMessage (hwndMain, WM_SIZE, 0, (rect.right - rect.left));
00127     ShowWindow (hwndDlg, SW_SHOW);
00128     ShowWindow(hwndMain, nCmdShow);
00129
00130
00131     /* Load the accelerator table that provides clipboard support. */
00132     haccel = LoadAccelerators (hInst, "bltAccel");
00133
00134
00135     /* Loop getting messages and dispatching them. */
00136     while (GetMessage(&msg,NULL, 0,0)) {
00137       if (!TranslateAccelerator(hwndMain, haccel, &msg))
00138       if (!IsDialogMessage (hwndDlg, &msg)) {
00139         DispatchMessage(&msg);
00140       }
00141     }
00142
00143     return (msg.wParam);           /* Returns the value from PostQuitMessage */
00144 }
00145
00146
00147
00148
00149 /**************************************************************************\
00150 *
00151 *  function:  MainWndProc()
00152 *
00153 *  input parameters:  normal window procedure parameters.
00154 *
00155 *  This is the main window window procedure.  Allocate needed structures
00156 *   at create time and free them at destroy time.  Pass the mouse messages
00157 *   down to the track objects when appropriate.  Size the top dialog on
00158 *   size messages.  The window is painted in two halfs.  One for the source
00159 *   region and one for the destination region.  The StretchBlt() call is
00160 *   separated out as a user message so that the call can be made without
00161 *   erasing the whole window.
00162 *
00163 *  global variables:
00164 *   hwndDlg  - dialog with entry fields containing arc parameters.
00165 *   ptoSrc   - pointer to the source track object
00166 *   hdcSrc   - device context for the right half the window.
00167 *   ptoDest  - pointer to the destination track object
00168 *   hdcDest  - device context for the left half the window.
00169 *   hbmSrc   - bitmap handle for the source bitmap.
00170 *
00171 *   strebltMode - Selection from combo box, to be used in SetStretchBltMode()
00172 *   iPatternBrush - Selection from combo box, set into the hdc.
00173 \**************************************************************************/
00174 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00175 {
00176   static int miniWidth;
00177   static RECT rect;
00178   char buffer[MAXCHARS];
00179   static HANDLE hPenGrid, hPenSeparator;
00180
00181
00182   switch (message) {
00183
00184     /**********************************************************************\
00185     *  WM_CREATE
00186     *
00187     * Get the two hdc's for this window, allocate two track objects,
00188     *  and then create two pens to be used when painting the windows.
00189     \**********************************************************************/
00190     case WM_CREATE:
00191       hdcSrc  = GetDC (hwnd);
00192       hdcDest = GetDC (hwnd);
00193
00194       ptoDest = doTrackObject (NULL, TROB_NEW, hwnd,0);
00195       ptoSrc  = doTrackObject (NULL, TROB_NEW, hwnd,0);
00196
00197       hPenGrid      = CreatePen (PS_SOLID, 1, GRIDCOLOR);
00198       hPenSeparator = CreatePen (PS_SOLID, 2*SEPARATORWIDTH, (COLORREF) 0x01000000);
00199     break;
00200
00201
00202     /**********************************************************************\
00203     *  WM_DESTROY
00204     *
00205     * Complement of WM_CREATE.  Free up all of the HDCs, send all of the
00206     *  track objects their delete messages, then call PostQuitMessage.
00207     \**********************************************************************/
00208     case WM_DESTROY:
00209       ReleaseDC (hwnd, hdcSrc );
00210       ReleaseDC (hwnd, hdcDest);
00211       doTrackObject (ptoDest, TROB_DELETE, hwnd,0);
00212       doTrackObject (ptoSrc , TROB_DELETE, hwnd,0);
00213
00214       DeleteObject(hPenGrid);
00215       DeleteObject(hPenSeparator);
00216
00217       PostQuitMessage(0);
00218     break;
00219
00220
00221
00222     /**********************************************************************\
00223     *  WM_SIZE
00224     *
00225     * streblt the top dialog to fill the width of the main window.
00226     * Adjust the viewport origins of the 4 HDCs.
00227     * Set the clip regions of the 4 HDCs.
00228     \**********************************************************************/
00229     case WM_SIZE: {
00230         HRGN hrgn;
00231
00232         SetWindowPos (hwndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
00233
00234         GetClientRect (hwndMain, &rect);
00235         miniWidth = rect.right/2;
00236
00237         SetViewportOrgEx (hdcDest,      0,           DIALOGHEIGHT, NULL);
00238         SetViewportOrgEx (ptoDest->hdc, 0,           DIALOGHEIGHT, NULL);
00239         SetViewportOrgEx (hdcSrc,       miniWidth,   DIALOGHEIGHT, NULL);
00240         SetViewportOrgEx (ptoSrc->hdc,  miniWidth,   DIALOGHEIGHT, NULL);
00241
00242         ptoDest->rectClip.left    = 0;
00243         ptoDest->rectClip.top     = DIALOGHEIGHT;
00244         ptoDest->rectClip.right   = miniWidth-2*SEPARATORWIDTH;
00245         ptoDest->rectClip.bottom  = rect.bottom;
00246         hrgn = CreateRectRgnIndirect (&ptoDest->rectClip);
00247         SelectClipRgn (hdcDest,      hrgn);
00248         SelectClipRgn (ptoDest->hdc, hrgn);
00249         DeleteObject (hrgn);
00250
00251         ptoSrc->rectClip.left    = miniWidth;
00252         ptoSrc->rectClip.top     = DIALOGHEIGHT;
00253         ptoSrc->rectClip.right   = 2*miniWidth;
00254         ptoSrc->rectClip.bottom  = rect.bottom;
00255         hrgn = CreateRectRgnIndirect (&ptoSrc->rectClip);
00256         SelectClipRgn (hdcSrc,       hrgn);
00257         SelectClipRgn (ptoSrc->hdc,  hrgn);
00258         DeleteObject (hrgn);
00259
00260         SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD)hdcDest, (LONG)ptoDest);
00261         SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD)hdcSrc,  (LONG)ptoSrc);
00262
00263         InvalidateRect (hwnd, NULL, TRUE);
00264     } break;
00265
00266
00267
00268     /**********************************************************************\
00269     *  WM_PAINT
00270     *
00271     * miniWidth, rect -- set by WM_SIZE message.
00272     *
00273     * First shift the viewport origin down so that 0,0 is the top left
00274     *  most visible point (out from underneath the top dialog).  Second,
00275     *  draw the grid with wider lines on the axes.  Finally, read the
00276     *  values out of the top dialog, do elementary validation, and then
00277     *  try to call StretchBlt() with the values.
00278     \**********************************************************************/
00279      case WM_PAINT: {
00280         HDC hdc;
00281         PAINTSTRUCT ps;
00282
00283         hdc = BeginPaint(hwnd, &ps);
00284
00285         /* Draw Separator lines for the three miniareas */
00286         SelectObject(hdc, hPenSeparator);
00287         MoveToEx (hdc, miniWidth-SEPARATORWIDTH,0, NULL);
00288         LineTo (hdc, miniWidth-SEPARATORWIDTH , rect.bottom);
00289
00290         /* Grid the 2 HDCs */
00291         SelectObject (hdcSrc, hPenGrid);
00292         DrawGrids (hdcSrc, miniWidth, rect.bottom);
00293         SelectObject (hdcDest, hPenGrid);
00294         DrawGrids (hdcDest, miniWidth, rect.bottom);
00295
00296         /* if a source bitmap has been selected, draw it. */
00297         if (hbmSrc)  DrawBitmap (hdcSrc, hbmSrc);
00298
00299         /* paint the source track object on top of the bitmap */
00300         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00301
00302         /* make the call to StretchBlt() for the left half the window */
00303         SendMessage (hwnd, WM_STRETCHBLT, 0,0);
00304
00305         EndPaint (hwnd, &ps);
00306     } return FALSE;
00307
00308
00309
00310     /**********************************************************************\
00311     *  WM_STRETCHBLT
00312     *
00313     * Separate out the StretchBlt() call from the rest of the WM_PAINT
00314     *  case in this user message.  In this way, we can blt() without erasing
00315     *  and/or repaint all of the rest of the window.  Send this message when
00316     *  only the blt() should be done.  Invalidate the left half of the window
00317     *  when it should be erased, re-grided, and then blt()ed.
00318     \**********************************************************************/
00319     case WM_STRETCHBLT: {
00320         int X,    Y,    nWidth,    nHeight,
00321             XSrc, YSrc, nSrcWidth, nSrcHeight;
00322         LONG rop, ropByte;
00323         BOOL success;
00324
00325         /* erase source track object, or top left sides will show up in blt. */
00326         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00327
00328         /* Get the parameters out of the top dialog box and call StretchBlt */
00329         if (IsWindow(hwndDlg)) {
00330
00331           X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
00332           Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
00333           nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
00334           nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);
00335           XSrc = GetDlgItemInt(hwndDlg, DID_XSRC, &success, TRUE);
00336           YSrc = GetDlgItemInt(hwndDlg, DID_YSRC, &success, TRUE);
00337           nSrcWidth = GetDlgItemInt(hwndDlg,  DID_SRCWIDTH, &success, TRUE);
00338           nSrcHeight = GetDlgItemInt(hwndDlg, DID_SRCHEIGHT, &success, TRUE);
00339
00340           /* get high order ROP byte and shift left by two bytes. */
00341           GetDlgItemText(hwndDlg, DID_ROP0, buffer, MAXCHARS);
00342           sscanf (buffer, "%lx", &ropByte);
00343           rop = ropByte * 256 * 256;
00344
00345           /* get the next ROP byte and shift left by one byte. */
00346           GetDlgItemText(hwndDlg, DID_ROP1, buffer, MAXCHARS);
00347           sscanf (buffer, "%lx", &ropByte);
00348           rop += ropByte * 256;
00349
00350           /* finally, get the low order ROP byte. */
00351           GetDlgItemText(hwndDlg, DID_ROP2, buffer, MAXCHARS);
00352           sscanf (buffer, "%lx", &ropByte);
00353           rop += ropByte;
00354
00355           /* set streblt mode.  (user selects via combo box.) */
00356           if (strebltMode != NONE)
00357             SetStretchBltMode (hdcDest, strebltMode);
00358
00359           /* select the pattern brush.  (user selects via combo box.) */
00360           if (iPatternBrush != NONE)
00361             SelectObject (hdcDest, GetStockObject (iPatternBrush));
00362
00363           /**********************************************************/
00364           /**********************************************************/
00365           StretchBlt (hdcDest, X,    Y,    nWidth,    nHeight,
00366                       hdcSrc,  XSrc, YSrc, nSrcWidth, nSrcHeight, rop);
00367           /**********************************************************/
00368           /**********************************************************/
00369         }
00370
00371         /* redraw source track object which was erased temporarily. */
00372         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00373     } break;
00374
00375
00376
00377     /**********************************************************************\
00378     *  WM_LBUTTONDOWN
00379     * On button down messages, hittest on the track object, and if
00380     *  it returns true, then send these messages to the track object.
00381     \**********************************************************************/
00382     case WM_LBUTTONDOWN:
00383       if (doTrackObject(ptoDest, TROB_HITTEST, hwnd, lParam))
00384          doTrackObject(ptoDest, message, hwnd, lParam);
00385       else if (doTrackObject(ptoSrc, TROB_HITTEST, hwnd, lParam))
00386          doTrackObject(ptoSrc, message, hwnd, lParam);
00387     break;
00388
00389
00390
00391     /**********************************************************************\
00392     *  WM_LBUTTONUP
00393     * If the track object is in a "tracking mode" then send it this message.
00394     *  For the source track object, just send a STRETCHBLT message.
00395     *  For the dest. track object, invalidate the left half causing erase.
00396     \**********************************************************************/
00397     case WM_LBUTTONUP:
00398       if (ptoDest->Mode) {
00399         doTrackObject(ptoDest, message, hwnd, lParam);
00400         SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
00401         InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
00402         InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
00403       }
00404       if (ptoSrc->Mode) {
00405         doTrackObject(ptoSrc, message, hwnd, lParam);
00406         SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
00407         PostMessage (hwndMain, WM_STRETCHBLT, 0,0);
00408       }
00409     break;
00410
00411
00412     /**********************************************************************\
00413     *  MW_MOUSEMOVE
00414     * If the track object is in a "tracking mode" then send it these messages.
00415     *  Also, update the coordinates in the top dialog box.
00416     \**********************************************************************/
00417     case WM_MOUSEMOVE:
00418       if (ptoDest->Mode) {
00419         doTrackObject(ptoDest, message, hwnd, lParam);
00420         SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
00421       }
00422       if (ptoSrc->Mode) {
00423         doTrackObject(ptoSrc, message, hwnd, lParam);
00424         SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
00425       }
00426     break;
00427
00428
00429
00430
00431
00432     /**********************************************************************\
00433     *  Accelerator & clipboard support.
00434     *
00435     * Certain key strokes (c.f. *.rc) will cause the following WM_COMMAND
00436     *  messages.  In response the app will copy a bitmap into the clipboard
00437     *  or paste down from it.  In both cases, it is necessary to create a
00438     *  new bitmap since a bitmap in the clipboard belongs to the clipboard
00439     *  and not to the application.
00440     \**********************************************************************/
00441     case WM_COMMAND:
00442       switch (LOWORD(wParam)) {
00443         HBITMAP hbmCompat, hbmOld;
00444         HDC hdcCompat;
00445
00446         /******************************************************************\
00447         *  WM_COMMAND, AID_COPY
00448         *
00449         * Create a new bitmap, copy the destination HDC bits into it,
00450         *  and send the new bitmap to the clipboard.
00451         \******************************************************************/
00452         case AID_COPY: {
00453           int X,Y, nWidth, nHeight;
00454           BOOL success;
00455
00456           X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
00457           Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
00458           nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
00459           nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);
00460
00461
00462           hdcCompat = CreateCompatibleDC(hdcDest);
00463           hbmCompat = CreateCompatibleBitmap (hdcDest, nWidth, nHeight);
00464           hbmOld = SelectObject(hdcCompat,hbmCompat);
00465
00466           BitBlt (hdcCompat, 0,0,nWidth, nHeight, hdcDest, X,Y, SRCCOPY );
00467
00468           SelectObject(hdcCompat,hbmOld);
00469           DeleteDC(hdcCompat);
00470
00471           OpenClipboard (hwnd);
00472           SetClipboardData (CF_BITMAP,hbmCompat);
00473           CloseClipboard ();
00474
00475           DeleteObject (hbmCompat);
00476
00477         } break;
00478
00479
00480         /******************************************************************\
00481         *  WM_COMMAND, AID_PASTE
00482         *
00483         * Get bitmap handle from clipboard, create a new bitmap, draw
00484         *  the clipboard bitmap into the new one, and store the new
00485         *  handle in the global hbmSrc.
00486         \******************************************************************/
00487         case AID_PASTE: {
00488           HBITMAP hbm;
00489           BITMAP bm;
00490
00491           OpenClipboard (hwnd);
00492           if ( hbm = GetClipboardData (CF_BITMAP)) {
00493             DeleteObject (hbmSrc);
00494
00495             GetObject (hbm, sizeof(BITMAP), &bm);
00496
00497             hdcCompat = CreateCompatibleDC(hdcDest);
00498             hbmCompat = CreateCompatibleBitmap (hdcDest, bm.bmWidth, bm.bmHeight);
00499             hbmOld = SelectObject(hdcCompat,hbmCompat);
00500
00501             DrawBitmap (hdcCompat, hbm);
00502
00503             SelectObject(hdcCompat,hbmOld);
00504             DeleteDC(hdcCompat);
00505
00506             hbmSrc = hbmCompat;
00507
00508             InvalidateRect (hwnd, &ptoSrc->rectClip, TRUE);
00509             InvalidateRect (hwnd, &ptoDest->rectClip, TRUE);
00510           }
00511           CloseClipboard ();
00512         } break;
00513
00514         /******************************************************************\
00515         *  WM_COMMAND, AID_CYCLE
00516         *
00517         * Post a COPY and PASTE command message to this window so that with
00518         *  one key stroke the user can copy the DEST image into the clipboard,
00519         *  paste it down into the SRC hdc and cause the blt.
00520         \******************************************************************/
00521         case AID_CYCLE:
00522           PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_COPY , 1), 0);
00523           PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_PASTE, 1), 0);
00524         break;
00525       }  /* end switch */
00526
00527     break;  /* end wm_command */
00528
00529
00530   } /* end switch */
00531   return (DefWindowProc(hwnd, message, wParam, lParam));
00532 }
00533
00534
00535
00536
00537
00538
00539 /**************************************************************************\
00540 *
00541 *  function:  DlgProc()
00542 *
00543 *  input parameters:  normal window procedure parameters.
00544 *
00545 *  This is the dialog that sits on top of the window (it is streblted on the
00546 *   WM_SIZE message of the main window).  In this window procedure, handle
00547 *   the command messages that arise as the user selects buttons on this
00548 *   dialog.  Also handle user messages for filling in entry field values.
00549 *
00550 *  global variables:
00551 *   hwndMain - the main window.  also the parent of this dialog
00552 *   ptoSrc   - pointer to the source track object
00553 *   hdcSrc   - device context for the right half the window.
00554 *   ptoDest  - pointer to the destination track object
00555 *   hdcDest  - device context for the left half the window.
00556 *   hbmSrc   - bitmap handle for the source bitmap.
00557 *
00558 *   strebltMode - Selection from combo box, to be used in SetStretchMode()
00559 *   iPatternBrush - Selection from combo box, set into the hdc.
00560 \**************************************************************************/
00561 BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00562 {
00563   char buffer[MAXCHARS];
00564
00565   UNREFERENCED_PARAMETER(lParam);
00566
00567   switch (message) {
00568     /**********************************************************************\
00569     *  WM_INITDIALOG
00570     *
00571     * Fill the entry fields with sensible original values.
00572     *  Also fill the combo boxes with the text entries from lookup tables.
00573     \**********************************************************************/
00574     case WM_INITDIALOG: {
00575       int i;
00576
00577       for ( i = DID_X; i<= DID_SRCHEIGHT; i++)
00578         SetDlgItemText(hwnd, i , "0");
00579
00580       SetDlgItemText(hwnd, DID_ROP0  , "cc");
00581       SetDlgItemText(hwnd, DID_ROP1  , "00");
00582       SetDlgItemText(hwnd, DID_ROP2  , "20");
00583
00584       for (i = 0; i< NMODES; i++)
00585         SendDlgItemMessage (hwnd, DID_CB_MODE, CB_INSERTSTRING,
00586                             (DWORD) -1, (LONG)strebltModes[i].String);
00587
00588       for (i = 0; i< NPATTERNS; i++)
00589         SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
00590                             (DWORD) -1, (LONG)Patterns[i].String);
00591
00592       for (i = 0; i< NROPS; i++)
00593         SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
00594                             (DWORD) -1, (LONG)StandardROPs[i].String);
00595
00596
00597     } return TRUE;
00598
00599
00600     /**********************************************************************\
00601     *  WM_PUTUPDESTRECT
00602     *
00603     * wParam -  HDC with the needed world transform.
00604     * lParam -  Pointer to the track object.
00605     *
00606     * Fill the entry fields for the destination rectangle points.
00607     *  Conditionally change <x,y> or <width,height> depending on tracking mode.
00608     \**********************************************************************/
00609     case WM_PUTUPDESTRECT: {
00610         POINT p1,p2, origin;
00611         PTrackObject pto;
00612         HDC hdc;
00613
00614         hdc = (HDC) wParam;
00615         pto = (PTrackObject) lParam;
00616         GetViewportOrgEx (hdc, &origin);
00617
00618         p1.x = pto->rect.left;
00619         p1.y = pto->rect.top;
00620         LPtoDP (pto->hdc, &p1, 1);
00621
00622         p2.x = pto->rect.right;
00623         p2.y = pto->rect.bottom;
00624         LPtoDP (pto->hdc, &p2, 1);
00625         p2.x -= p1.x; p2.y -= p1.y;
00626
00627         p1.x -= origin.x; p1.y -= origin.y;
00628
00629         if (!(pto->Mode & TMSIZEXY)) {
00630           SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
00631           SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
00632         }
00633
00634         if (!(pto->Mode & TMMOVE)) {
00635           SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
00636           SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
00637         }
00638     } return FALSE;
00639
00640
00641
00642
00643     /**********************************************************************\
00644     *  WM_PUTUPSRCRECT
00645     *
00646     * wParam -  HDC with the needed world transform.
00647     * lParam -  Pointer to the track object.
00648     *
00649     * Fill the entry fields for the source rectangle points.
00650     *  Conditionally change <x,y> or <width,height> depending on tracking mode.
00651     \**********************************************************************/
00652     case WM_PUTUPSRCRECT: {
00653         POINT p1,p2, origin;
00654         PTrackObject pto;
00655         HDC hdc;
00656
00657         hdc = (HDC) wParam;
00658         pto = (PTrackObject) lParam;
00659         GetViewportOrgEx (hdc, &origin);
00660
00661         p1.x = pto->rect.left;
00662         p1.y = pto->rect.top;
00663         LPtoDP (pto->hdc, &p1, 1);
00664
00665         p2.x = pto->rect.right;
00666         p2.y = pto->rect.bottom;
00667         LPtoDP (pto->hdc, &p2, 1);
00668         p2.x -= p1.x; p2.y -= p1.y;
00669
00670         p1.x -= origin.x; p1.y -= origin.y;
00671
00672         if (!(pto->Mode & TMSIZEXY)) {
00673           SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
00674           SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);
00675         }
00676
00677         if (!(pto->Mode & TMMOVE)) {
00678           SetDlgItemInt(hwnd, DID_SRCWIDTH,  p2.x, TRUE);
00679           SetDlgItemInt(hwnd, DID_SRCHEIGHT, p2.y, TRUE);
00680         }
00681     } return FALSE;
00682
00683
00684
00685
00686     case WM_COMMAND:
00687
00688       switch (LOWORD(wParam)) {
00689
00690         /******************************************************************\
00691         *  WM_COMMAND, DID_DRAW
00692         *
00693         * Draw button hit - send main window message to call StretchBlt().
00694         \******************************************************************/
00695         case DID_DRAW:
00696           SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
00697         break;
00698
00699
00700         /******************************************************************\
00701         *  WM_COMMAND, DID_NEWSRC
00702         *
00703         * Try to get a new source bitmap. If successful, store it in the
00704         *  global handle (hbmSrc) then invalidate two sub windows so that
00705         *  we force a complete repaint in both.
00706         \******************************************************************/
00707         case DID_NEWSRC: {
00708           HBITMAP hbm;
00709           if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
00710             DeleteObject (hbmSrc);
00711             hbmSrc = hbm;
00712             InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
00713             InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
00714           }
00715
00716         } break;
00717
00718
00719         /******************************************************************\
00720         *  WM_COMMAND, DID_CB_MODE
00721         *
00722         * A new streblt mode was selected.  Look up the value, store it
00723         *  in a global variable (strebltMode), then force a new StretchBlt
00724         \******************************************************************/
00725         case DID_CB_MODE:
00726           if (HIWORD (wParam) == CBN_SELCHANGE) {
00727             int iSel;
00728
00729             iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00730             strebltMode = strebltModes[iSel].Value;
00731
00732             SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
00733           }
00734         break;
00735
00736
00737         /******************************************************************\
00738         *  WM_COMMAND, DID_CB_PATTERN
00739         *
00740         * A new pattern brush was selected.  Look up the value, store it
00741         *  in a global variable (iPatternBrush), then force a new StretchBlt
00742         \******************************************************************/
00743         case DID_CB_PATTERN:
00744           if (HIWORD (wParam) == CBN_SELCHANGE) {
00745             int iSel;
00746
00747             iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00748             iPatternBrush = Patterns[iSel].Value;
00749
00750             SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
00751           }
00752         break;
00753
00754
00755
00756         /******************************************************************\
00757         *  WM_COMMAND, DID_CB_ROPS
00758         *
00759         * A new standard rop entry was selected.  Lookup the value,
00760         *  then break it into three parts, convert to hex, and put
00761         *  it in the proper entry fields.
00762         \******************************************************************/
00763         case DID_CB_ROPS:
00764           if (HIWORD (wParam) == CBN_SELCHANGE) {
00765             int iSel, rop;
00766
00767             iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00768             rop = StandardROPs[iSel].Value;
00769             sprintf (buffer, "%2x", (rop & 0x000000ff));
00770             SetDlgItemText(hwnd, DID_ROP2, buffer);
00771             rop /= 256;
00772             sprintf (buffer, "%2x", (rop & 0x000000ff));
00773             SetDlgItemText(hwnd, DID_ROP1, buffer);
00774             rop /= 256;
00775             sprintf (buffer, "%2x", (rop & 0x000000ff));
00776             SetDlgItemText(hwnd, DID_ROP0, buffer);
00777
00778             SendMessage (hwndMain, WM_STRETCHBLT, 0,0);
00779           }
00780         break;
00781
00782
00783
00784
00785       } /* end switch */
00786
00787
00788     return FALSE; /* end WM_COMMAND */
00789
00790
00791   } /* end switch */
00792   return 0;
00793 }
00794
00795
00796 #define TICKSPACE     20
00797
00798 /**************************************************************************\
00799 *
00800 *  function:  DrawGrids()
00801 *
00802 *  input parameters:
00803 *   hdc - Device context to draw into.
00804 *   width, height - size of the rectangle to fill with grids.
00805 *
00806 *  global variables:  none.
00807 *
00808 \**************************************************************************/
00809 VOID DrawGrids (HDC hdc, int width, int height)
00810 {
00811 int i;
00812
00813     /* Draw vertical lines. Double at the axis */
00814     for (i = 0; i<= width; i+=TICKSPACE){
00815       MoveToEx (hdc, i, 0, NULL);
00816       LineTo (hdc, i, height);
00817     }
00818     MoveToEx (hdc, 1, 0, NULL);
00819     LineTo (hdc, 1, height);
00820
00821     /* Draw horizontal lines. Double at the axis */
00822     for (i = 0; i<= height; i+=TICKSPACE){
00823       MoveToEx (hdc, 0,i, NULL);
00824       LineTo (hdc, width,i);
00825     }
00826     MoveToEx (hdc, 0, 1, NULL);
00827     LineTo (hdc, width,1);
00828
00829   return;
00830 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DISPATCH.C Source File

  • NETDDE

DISPATCH.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   dispatch.c
00009 //
00010 //  PURPOSE:  Implement the generic message and command dispatchers.
00011 //
00012 //
00013 //  FUNCTIONS:
00014 //    DispMessage - Call the function associated with a message.
00015 //    DispCommand - Call the function associated with a command.
00016 //    DispDefault - Call the appropriate default window procedure.
00017 //
00018 //  COMMENTS:
00019 //
00020
00021 #include <windows.h>            // required for all Windows applications
00022 #include <windowsx.h>
00023 #ifdef WIN16
00024 #include "win16ext.h"           // required only for win16 applications
00025 #endif
00026 #include "globals.h"            // prototypes specific to this application
00027
00028 LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
00029
00030 //
00031 //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
00032 //
00033 //  PURPOSE: Call the function associated with a message.
00034 //
00035 //  PARAMETERS:
00036 //    lpmsdi - Structure containing the message dispatch information.
00037 //    hwnd - The window handle
00038 //    uMessage - The message number
00039 //    wparam - Message specific data
00040 //    lparam - Message specific data
00041 //
00042 //  RETURN VALUE:
00043 //    The value returned by the message function that was called.
00044 //
00045 //  COMMENTS:
00046 //    Runs the table of messages stored in lpmsdi->rgmsd searching
00047 //    for a message number that matches uMessage.  If a match is found,
00048 //    call the associated function.  Otherwise, call DispDefault to
00049 //    call the default function, if any, associated with the message
00050 //    structure.  In either case, return the value recieved from the
00051 //    message or default function.
00052 //
00053
00054 LRESULT DispMessage(LPMSDI lpmsdi,
00055                     HWND   hwnd,
00056                     UINT   uMessage,
00057                     WPARAM wparam,
00058                     LPARAM lparam)
00059 {
00060     int  imsd = 0;
00061
00062     MSD *rgmsd = lpmsdi->rgmsd;
00063     int  cmsd  = lpmsdi->cmsd;
00064
00065     for (imsd = 0; imsd < cmsd; imsd++)
00066     {
00067         if (rgmsd[imsd].uMessage == uMessage)
00068             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
00069     }
00070
00071     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
00072 }
00073
00074 //
00075 //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
00076 //
00077 //  PURPOSE: Call the function associated with a command.
00078 //
00079 //  PARAMETERS:
00080 //    lpcmdi - Structure containing the command dispatch information.
00081 //    hwnd - The window handle
00082 //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
00083 //      control, or accelerator.
00084 //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
00085 //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
00086 //
00087 //  RETURN VALUE:
00088 //    The value returned by the command function that was called.
00089 //
00090 //  COMMENTS:
00091 //    Runs the table of commands stored in lpcmdi->rgcmd searching
00092 //    for a command number that matches wCommand.  If a match is found,
00093 //    call the associated function.  Otherwise, call DispDefault to
00094 //    call the default function, if any, associated with the command
00095 //    structure.  In either case, return the value recieved from the
00096 //    command or default function.
00097 //
00098
00099
00100 LRESULT DispCommand(LPCMDI lpcmdi,
00101                     HWND   hwnd,
00102                     WPARAM wparam,
00103                     LPARAM lparam)
00104 {
00105     LRESULT lRet = 0;
00106     WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
00107     int     icmd;
00108
00109     CMD    *rgcmd = lpcmdi->rgcmd;
00110     int     ccmd  = lpcmdi->ccmd;
00111
00112     // Message packing of wparam and lparam have changed for Win32,
00113     // so use the GET_WM_COMMAND macro to unpack the commnad
00114
00115     for (icmd = 0; icmd < ccmd; icmd++)
00116     {
00117         if (rgcmd[icmd].wCommand == wCommand)
00118         {
00119             return rgcmd[icmd].pfncmd(hwnd,
00120                                       wCommand,
00121                                       GET_WM_COMMAND_CMD(wparam, lparam),
00122                                       GET_WM_COMMAND_HWND(wparam, lparam));
00123         }
00124     }
00125
00126     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
00127 }
00128
00129
00130 //
00131 //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
00132 //
00133 //  PURPOSE: Call the appropriate default window procedure.
00134 //
00135 //  PARAMETERS:
00136 //    edwp - Enumerate specifying the appropriate default winow procedure.
00137 //    hwnd - The window handle
00138 //    uMessage - The message number
00139 //    wparam - Message specific data
00140 //    lparam - Message specific data
00141 //
00142 //  RETURN VALUE:
00143 //    If there is a default proc, return the value returned by the
00144 //    default proc.  Otherwise, return 0.
00145 //
00146 //  COMMENTS:
00147 //    Calls the default procedure associated with edwp using the specified
00148 //    parameters.
00149 //
00150
00151 LRESULT DispDefault(EDWP   edwp,
00152                     HWND   hwnd,
00153                     UINT   uMessage,
00154                     WPARAM wparam,
00155                     LPARAM lparam)
00156 {
00157     switch (edwp)
00158     {
00159         case edwpNone:
00160             return 0;
00161         case edwpWindow:
00162             return DefWindowProc(hwnd, uMessage, wparam, lparam);
00163         case edwpDialog:
00164             return DefDlgProc(hwnd, uMessage, wparam, lparam);
00165         case edwpMDIFrame:
00166             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
00167         case edwpMDIChild:
00168             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
00169     }
00170     return 0;
00171 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BOB/BOB.C Source File

  • BOB

BOB.C

Go to the documentation of this file.
00001 /****************************************************************************\
00002 **                                                                         **
00003 **               Microsoft Developer Support                               **
00004 **               Copyright (c) 1992-1996 Microsoft Corporation            **
00005 **                                                                         **
00006 **   MODULE:  BOB                                                          **
00007 **                                                                         **
00008 **                                                                         **
00009 **   PURPOSE: Demonstrates the steps needed to programmatically            **
00010 **            log off/reboot the machine. Note these features should       **
00011 **            only be used after you've notified the user what you         **
00012 **            are about to do. Windows itself will not provide any         **
00013 **            other warnings to the user.                                  **
00014 **                                                                         **
00015 **                                                                         **
00016 **                                                                         **
00017 **                                                                         **
00018 **   COMMENTS: Reads a file asynchronously writes to another synchronously **
00019 **                                                                         **
00020 **                                                                         **
00021 \***************************************************************************/
00022
00023
00024
00025 /*  To enable NT's Reboot feature enable the below
00026  *  manifest constants. By default the program will
00027  *  shut down the machine.
00028  */
00029
00030 // #define REBOOT
00031
00032 #define WIN32S  0x80000000l
00033
00034 #define STRICT
00035
00036 #include <stddef.h>
00037 #include <stdlib.h>
00038
00039
00040 #define  OEMRESOURCE
00041 #include "windows.h"            /* required for all Windows applications */
00042
00043 #include "BOB.H"                /* specific to this program */
00044
00045 HINSTANCE ghInst;               /* current instance */
00046 HWND      ghWnd;
00047 WNDPROC   OldButtonProc;
00048
00049 /****************************************************************************
00050
00051     FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00052
00053     PURPOSE: calls initialization function, processes message loop
00054
00055     COMMENTS:
00056
00057         Windows recognizes this function by name as the initial entry point
00058         for the program.  This function calls the application initialization
00059         routine, if no other instance of the program is running, and always
00060         calls the instance initialization routine.  It then executes a message
00061         retrieval and dispatch loop that is the top-level control structure
00062         for the remainder of execution.  The loop is terminated when a WM_QUIT
00063         message is received, at which time this function exits the application
00064         instance by returning the value passed by PostQuitMessage().
00065
00066         If this function must abort before entering the message loop, it
00067         returns the conventional value NULL.
00068
00069 ****************************************************************************/
00070
00071 int PASCAL WinMain(HINSTANCE hInstance, /* current instance  */
00072            HINSTANCE hPrevInstance,     /* previous instance */
00073            LPSTR     lpCmdLine,         /* command line      */
00074            int       nCmdShow)          /* show-window type (open/icon) */
00075 {
00076     MSG msg;                            /* message              */
00077
00078     if (!hPrevInstance)                 /* Other instances of app running? */
00079     if (!InitApplication(hInstance))    /* Initialize shared things */
00080         return (FALSE);                 /* Exits if unable to initialize */
00081
00082     /* Perform initializations that apply to a specific instance */
00083
00084     if (!InitInstance(hInstance, nCmdShow))
00085         return (FALSE);
00086
00087     /* Acquire and dispatch messages until a WM_QUIT message is received. */
00088
00089     while (GetMessage(&msg,    /* message structure                      */
00090         NULL,                  /* handle of window receiving the message */
00091         0,                     /* lowest message to examine              */
00092         0))                    /* highest message to examine             */
00093     {
00094         TranslateMessage(&msg);    /* Translates virtual key codes       */
00095         DispatchMessage(&msg);     /* Dispatches message to window       */
00096
00097     }
00098     return (msg.wParam);       /* Returns the value from PostQuitMessage */
00099 UNREFERENCED_PARAMETER(lpCmdLine);
00100 }
00101
00102
00103 /****************************************************************************
00104
00105     FUNCTION: InitApplication(HANDLE)
00106
00107     PURPOSE: Initializes window data and registers window class
00108
00109     COMMENTS:
00110
00111         This function is called at initialization time only if no other
00112         instances of the application are running.  This function performs
00113         initialization tasks that can be done once for any number of running
00114         instances.
00115
00116         In this case, we initialize a window class by filling out a data
00117         structure of type WNDCLASS and calling the Windows RegisterClass()
00118         function.  Since all instances of this application use the same window
00119         class, we only need to do this when the first instance is initialized.
00120
00121
00122 ****************************************************************************/
00123
00124 BOOL InitApplication(HANDLE hInstance)    /* current instance     */
00125 {
00126     WNDCLASS  wc;
00127
00128     /* Fill in window class structure with parameters that describe the       */
00129     /* main window.                                                           */
00130
00131     wc.style = 0;                       /* Class style(s).            */
00132     wc.lpfnWndProc = (WNDPROC)MainWndProc;   /* Function to retrieve messages for  */
00133                                         /* windows of this class.             */
00134     wc.cbClsExtra = 0;                  /* No per-class extra data.           */
00135     wc.cbWndExtra = 0;                  /* No per-window extra data.          */
00136     wc.hInstance = hInstance;           /* Application that owns the class.   */
00137     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00138     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00139     wc.hbrBackground = GetStockObject(WHITE_BRUSH);
00140     wc.lpszMenuName =  "BOBMenu";       /* Name of menu resource in .RC file. */
00141     wc.lpszClassName = "BOBWClass";     /* Name used in call to CreateWindow. */
00142
00143     /* Register the window class and return success/failure code. */
00144
00145
00146     if ( !RegisterClass(&wc) )
00147         return( FALSE );
00148
00149
00150 }
00151
00152
00153 /****************************************************************************
00154
00155     FUNCTION:  InitInstance(HANDLE, int)
00156
00157     PURPOSE:  Saves instance handle and creates main window
00158
00159     COMMENTS:
00160
00161         This function is called at initialization time for every instance of
00162         this application.  This function performs initialization tasks that
00163         cannot be shared by multiple instances.
00164
00165         In this case, we save the instance handle in a static variable and
00166         create and display the main program window.
00167
00168 ****************************************************************************/
00169
00170 BOOL InitInstance(HANDLE hInstance, /* Current instance identifier.       */
00171           int nCmdShow )            /* Param for first ShowWindow() call. */
00172 {
00173     HWND      hWnd;                 /* Main window handle.                */
00174     HWND      hWndDeskTop;
00175     RECT      rcDeskTop;
00176
00177
00178     /* Save the instance handle in static variable, which will be used in  */
00179     /* many subsequence calls from this application to Windows.            */
00180
00181     ghInst = hInstance;
00182
00183     /* Create a main window for this application instance.  */
00184
00185     hWndDeskTop = GetDesktopWindow();
00186     GetWindowRect( hWndDeskTop, &rcDeskTop );
00187
00188     hWnd = CreateWindow(
00189         "BOBWClass",                    /* See RegisterClass() call.          */
00190         "BOB",                          /* Text for window title bar.         */
00191         WS_OVERLAPPED,                  /* Window style.                      */
00192         rcDeskTop.left+50,              /* horizontal position.               */
00193         rcDeskTop.bottom-200,           /* vertical position.                 */
00194         150,                            /* width.                             */
00195         100,                            /* height.                            */
00196         NULL,                           /* Overlapped windows have no parent. */
00197         NULL,                           /* Use the window class menu.         */
00198         hInstance,                      /* This instance owns this window.    */
00199         NULL                            /* Pointer to Createion Parameters    */
00200     );
00201
00202     /* If window could not be created, return "failure" */
00203
00204     if (!hWnd)
00205         return (FALSE);
00206
00207     ShowWindow(hWnd, nCmdShow);  /* Show the window                */
00208     UpdateWindow(hWnd);          /* Sends WM_PAINT message         */
00209     ghWnd = hWnd;
00210
00211 }
00212
00213 /****************************************************************************
00214
00215     FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM)
00216
00217     PURPOSE:  Processes messages
00218
00219     MESSAGES:
00220
00221     WM_COMMAND    - application menu (About dialog box)
00222     WM_DESTROY    - destroy window
00223
00224     COMMENTS:
00225
00226     To process the IDM_ABOUT message, call MakeProcInstance() to get the
00227     current instance address of the About() function.  Then call Dialog
00228     box which will create the box according to the information in your
00229     BOB.RC file and turn control over to the About() function.  When
00230     it returns, free the intance address.
00231
00232 ****************************************************************************/
00233
00234 LRESULT CALLBACK MainWndProc( HWND hWnd,      /* window handle           */
00235                               UINT message,   /* type of message         */
00236                               WPARAM wParam,  /* additional information  */
00237                               LPARAM lParam ) /* additional information  */
00238 {
00239     DLGPROC lpProcAbout;
00240     CHAR buffer[80];
00241
00242     HANDLE hToken;
00243     TOKEN_PRIVILEGES tkp;
00244
00245     static CONTROLTEXT CtlText;
00246     static TCHAR szTitle[10];
00247     static RECT  FocusRect, SelectRect;
00248
00249     switch (message) {
00250
00251         case WM_CREATE: {
00252
00253             HWND hWndButton;
00254             CREATESTRUCT createStruct;
00255             RECT rcClient;
00256
00257             int   cbTitle;
00258             SIZE  size;
00259             HDC    hDC;
00260             int    nSpaceWidth, nSpaceHeight;
00261
00262             createStruct = *(LPCREATESTRUCT)lParam;
00263             GetClientRect( hWnd,&rcClient );
00264
00265             hWndButton = CreateWindow(
00266                 "BUTTON",                  /* See RegisterClass() call.       */
00267                 TEXT("B. O. B."),          /* Text for window title bar.      */
00268                 WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
00269                 rcClient.left,
00270                 rcClient.top,
00271                 rcClient.right,
00272                 rcClient.bottom,
00273                 hWnd,                      /* Parent                          */
00274                 (HMENU)BOB,                /* Child ID                        */
00275                 createStruct.hInstance,    /* This instance owns this window. */
00276                 NULL                       /* Pointer to Createion Parameters */
00277             );
00278
00279             wsprintf( buffer, "hWndButton is %#x and hWnd is %#x\r\n",
00280                       hWndButton, hWnd );
00281             OutputDebugString ( buffer );
00282
00283             if ( !hWndButton ) {
00284                 MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
00285                 SendMessage( hWnd, WM_DESTROY, 0, 0 );
00286             }
00287
00288             SetFocus( hWndButton );
00289
00290             OldButtonProc = SubclassWindow( hWndButton, ButtonProc );
00291
00292             // define size of dashed rectangles around text in both bitmaps
00293             hDC = GetDC( hWndButton );
00294             cbTitle = SendMessage( hWndButton,
00295                                    WM_GETTEXT,
00296                                    (WPARAM) sizeof(szTitle),
00297                                    (LPARAM)(LPTSTR)szTitle );
00298             GetTextExtentPoint( hDC,
00299                                 szTitle,
00300                                 cbTitle,
00301                                 &size );
00302             ReleaseDC( hWndButton, hDC);
00303
00304             CtlText.ptPosition.x = (rcClient.right - size.cx) >> 1;
00305             CtlText.ptPosition.y = (rcClient.bottom - size.cy) >> 1;
00306             CtlText.szTitle = szTitle;
00307             CtlText.cbTitle = cbTitle;
00308
00309             // load bitmap
00310
00311             CtlText.hDefaultButton = LoadBitmap(
00312                 createStruct.hInstance,    /* This instance owns this window. */
00313                 MAKEINTRESOURCE( DEFAULTBUTTON )
00314             );
00315
00316             if ( !CtlText.hDefaultButton ) {
00317                 wsprintf( buffer, "Error loading BUTTONBITMAP %d",
00318                           GetLastError() );
00319                 MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
00320                 SendMessage( hWnd, WM_DESTROY, 0, 0 );
00321             }
00322
00323             CtlText.hSelectButton = LoadBitmap(
00324                 createStruct.hInstance,    /* This instance owns this window. */
00325                 MAKEINTRESOURCE(SELECTEDBUTTON)    /* pushed state */
00326             );
00327
00328             if ( !CtlText.hSelectButton ) {
00329                 wsprintf( buffer, "Error loading BUTTONBITMAP %d",
00330                           GetLastError() );
00331                 MessageBox( hWnd, "Error creating Window", NULL, MB_OK );
00332                 SendMessage( hWnd, WM_DESTROY, 0, 0 );
00333             }
00334
00335             nSpaceWidth   = GetSystemMetrics(SM_CXBORDER) << 1;
00336             nSpaceHeight  = GetSystemMetrics(SM_CYBORDER) << 1;
00337
00338             FocusRect.top    = CtlText.ptPosition.y - nSpaceHeight;
00339             FocusRect.bottom = FocusRect.top + size.cy + (nSpaceHeight << 1);
00340             FocusRect.left   = CtlText.ptPosition.x - nSpaceWidth;
00341             FocusRect.right  = FocusRect.left + size.cx + (nSpaceWidth << 1);
00342
00343             SelectRect.top    = 2 + FocusRect.top;
00344             SelectRect.bottom = 2 + FocusRect.bottom;
00345             SelectRect.left   = 2 + FocusRect.left;
00346             SelectRect.right  = 2 + FocusRect.right;
00347
00348             return ( TRUE );
00349         }
00350
00351     case WM_DRAWITEM:
00352     {
00353         LPDRAWITEMSTRUCT  lpdisCtrl;
00354
00355         if ( (int)wParam == BOB ) {
00356             lpdisCtrl = (LPDRAWITEMSTRUCT)lParam;
00357             switch (lpdisCtrl->itemAction)
00358             {
00359                 // handle normal drawing of button, but check if its
00360                 // selected or focus
00361
00362                 case ODA_DRAWENTIRE:
00363                     OutputDebugString(
00364                         "WM_DRAWITEM: Action is ODA_DRAWENTIRE\r\n");
00365
00366                     // this handles both button down and button up
00367                     HandleSelectedState(lpdisCtrl, &CtlText);
00368
00369                     // this handles focus rectangle around Button text
00370                     HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
00371                     return TRUE;
00372
00373                     // handle drawing selection if needed
00374                     //   selected is button down, not selected is button up
00375                     //   focus will occur when button is pressed.
00376
00377                     case ODA_SELECT:
00378                         OutputDebugString(
00379                             "WM_DRAWITEM: Action is ODA_SELECT\r\n");
00380                         HandleSelectedState(lpdisCtrl, &CtlText);
00381                         HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
00382                         return TRUE;
00383
00384                     // handle focus drawing if needed
00385                     case ODA_FOCUS:
00386                         OutputDebugString(
00387                             "WM_DRAWITEM: Action is ODA_FOCUS\r\n");
00388                         HandleFocusState(lpdisCtrl, &FocusRect, &SelectRect);
00389                         return TRUE;
00390                 }
00391             }
00392             break;
00393         }
00394
00395         case WM_COMMAND:       /* message: command from application menu */
00396
00397             if ( HIWORD(wParam) == BN_CLICKED &&
00398                  LOWORD(wParam) == BOB ) {
00399                 /*
00400                  * Below are the steps needed to reboot the machine.
00401                  */
00402                 lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, ghInst );
00403 #if defined(REBOOT)
00404                 DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
00405 #else
00406                 DialogBox (ghInst, TEXT("AboutBox"), hWnd, lpProcAbout);
00407 #endif
00408
00409                 /* Get a token for this process. */
00410
00411                 if ( !(GetVersion() & WIN32S) )
00412                 {
00413                     OutputDebugString("Setting token");
00414                     // Running on NT so need to change privileges
00415
00416                     if (!OpenProcessToken(GetCurrentProcess(),
00417                                           TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
00418                                           &hToken))
00419                     {
00420                         wsprintf ( buffer, "OpenProcessToken Error #%d",
00421                                    GetLastError ());
00422                         MessageBox(hWnd, buffer, NULL, MB_OK);
00423                     }
00424
00425                     /* Get the LUID for shutdown privilege */
00426
00427                     LookupPrivilegeValue(NULL, TEXT("SeShutdownPrivilege"),
00428                                          &tkp.Privileges[0].Luid);
00429
00430                     tkp.PrivilegeCount = 1;  /* one privilege to set    */
00431                     tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
00432
00433                     /* Get shutdown privilege for this process. */
00434                     if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
00435                                                (PTOKEN_PRIVILEGES)NULL, 0)) {
00436                         wsprintf ( buffer, "AdjustTokenPrivileges Error #%d",
00437                                    GetLastError ());
00438                         MessageBox(hWnd, buffer, NULL, MB_OK);
00439                     }
00440                 }
00441
00442 #if defined(REBOOT)
00443                 /* Shut down the system, and reboot the system. */
00444
00445                 if ( !ExitWindowsEx( EWX_REBOOT, 0 )) {
00446                     wsprintf ( buffer, "Error ExitWindows Error #%d",
00447                                GetLastError ());
00448                     MessageBox(hWnd, buffer, NULL, MB_OK);
00449                 }
00450 #else
00451                 /* Shut down the system, and force all applications closed. */
00452
00453                 if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) {
00454                     wsprintf ( buffer, "Error ExitWindows Error #%d",
00455                                GetLastError ());
00456                     MessageBox(hWnd, buffer, NULL, MB_OK);
00457                 }
00458 #endif
00459                 break;
00460         }
00461         else                /* Lets Windows process it       */
00462             return (DefWindowProc(hWnd, message, wParam, lParam));
00463
00464     case WM_DESTROY:          /* message: window being destroyed */
00465         DeleteObject(CtlText.hDefaultButton);
00466         DeleteObject(CtlText.hSelectButton);
00467         PostQuitMessage(0);
00468         break;
00469
00470     default:              /* Passes it on if unproccessed    */
00471         return (DefWindowProc(hWnd, message, wParam, lParam));
00472     }
00473     return ( 0 );
00474 }
00475
00476
00477 /****************************************************************************
00478
00479     FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
00480
00481     PURPOSE:  Processes messages for "About" dialog box
00482
00483     MESSAGES:
00484
00485     WM_INITDIALOG - initialize dialog box
00486     WM_COMMAND    - Input received
00487
00488     COMMENTS:
00489
00490     No initialization is needed for this particular dialog box, but TRUE
00491     must be returned to Windows.
00492
00493     Wait for user to click on "Ok" button, then close the dialog box.
00494
00495 ****************************************************************************/
00496
00497 BOOL CALLBACK About( HWND hDlg,       /* window handle of the dialog box */
00498                      UINT message,    /* type of message                 */
00499                      WPARAM wParam,   /* message-specific information    */
00500                      LPARAM lParam )  /* message-specific information    */
00501 {
00502     switch (message) {
00503         case WM_INITDIALOG:           /* message: initialize dialog box */
00504             return (TRUE);
00505
00506         case WM_COMMAND:                      /* message: received a command */
00507             if (wParam == IDOK                /* "OK" box selected?          */
00508                 || wParam == IDCANCEL) {      /* System menu close command?  */
00509                 EndDialog(hDlg, TRUE);        /* Exits the dialog box        */
00510                 return (TRUE);
00511             }
00512             break;
00513     }
00514     return (FALSE);                           /* Didn't process a message    */
00515 UNREFERENCED_PARAMETER(lParam);
00516 }
00517
00518
00519
00520 /*****************************************************************************
00521
00522     FUNCTION: HandleSelectedState
00523
00524     PURPOSE:  Draw button bitmaps and text:
00525                   if button selected, draw "down"/pressed button bitmap
00526                       with text shifted right and down 2 pixels
00527                   else draw "up"/unpressed button bitmap
00528                       with text centered in button
00529
00530 *****************************************************************************/
00531 void HandleSelectedState(LPDRAWITEMSTRUCT lpdisCtrl, LPCONTROLTEXT lpCtlText)
00532 {
00533
00534     int nOldBkMode;
00535
00536     // handle button pressed down select state -- button down bitmap
00537     //   text is right & down 2 pixels
00538     if (lpdisCtrl->itemState & ODS_SELECTED)
00539     {
00540         DrawBitmap(lpdisCtrl->hDC,
00541            lpdisCtrl->rcItem,
00542            lpCtlText->hSelectButton,
00543                    SRCCOPY);
00544
00545         // put text 2 pixels right and down of center of bitmap
00546         nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);
00547
00548         TextOut( lpdisCtrl->hDC,
00549                  lpCtlText->ptPosition.x+2,
00550                  lpCtlText->ptPosition.y+2,
00551                  lpCtlText->szTitle,
00552                  lpCtlText->cbTitle );
00553
00554         SetBkMode(lpdisCtrl->hDC,nOldBkMode);
00555     }
00556     // not selected -- button up; text is in normal position
00557     else
00558     {
00559         DrawBitmap(lpdisCtrl->hDC,
00560            lpdisCtrl->rcItem,
00561            lpCtlText->hDefaultButton,
00562                    SRCCOPY);
00563
00564         // center text in bitmap
00565         nOldBkMode = SetBkMode(lpdisCtrl->hDC,TRANSPARENT);
00566         TextOut( lpdisCtrl->hDC,
00567                  lpCtlText->ptPosition.x,
00568                  lpCtlText->ptPosition.y,
00569                  lpCtlText->szTitle,
00570                  lpCtlText->cbTitle );
00571
00572         SetBkMode(lpdisCtrl->hDC,nOldBkMode);
00573     }
00574 }
00575
00576 /*****************************************************************************
00577
00578     FUNCTION: HandleFocusState
00579
00580     PURPOSE:  If button has focus, draw dashed rectangle around text in button
00581
00582 *****************************************************************************/
00583 void HandleFocusState(LPDRAWITEMSTRUCT lpdisCtrl, LPRECT lpFocusRect, LPRECT lpSelectRect )
00584 {
00585     // if focus state, draw a dashed rect around text
00586     if (lpdisCtrl->itemState & ODS_FOCUS)
00587     {
00588         // if selected, shift focus rect right and down 2 pixels around text
00589         if (lpdisCtrl->itemState & ODS_SELECTED) {
00590         OutputDebugString("HandleFocusState: State is ODS_SELECTED\r\n");
00591             DrawFocusRect(lpdisCtrl->hDC, lpSelectRect);
00592         }
00593         // else text centered, so focus rect will be too
00594         else {
00595             DrawFocusRect(lpdisCtrl->hDC, lpFocusRect);
00596             OutputDebugString("HandleFocusState: State is ODS_FOCUS\r\n");
00597         }
00598
00599     }
00600     else
00601         if (lpdisCtrl->itemState & ODS_SELECTED)
00602             OutputDebugString(
00603                 "Error HandleFocusState: State is ODS_SELECTED\r\n");
00604         else {
00605             char buffer[80];
00606             wsprintf(buffer,
00607                 "HandleFocusState:  lpdisCtrl->itemState is %#x\r\n",
00608                 lpdisCtrl->itemState );
00609             OutputDebugString(buffer);
00610         }
00611 }
00612
00613 /****************************************************************************
00614
00615     FUNCTION: DrawBitmap
00616
00617     PURPOSE:  Draw default or pushed button bitmap
00618
00619 ****************************************************************************/
00620
00621 void DrawBitmap(HDC hDC, RECT rect, HBITMAP hBitmap, DWORD rop)
00622 {
00623     HDC           hMemDC;
00624     BITMAP        bm;
00625     hMemDC = CreateCompatibleDC(hDC);
00626     SelectObject(hMemDC, hBitmap);
00627 //    BitBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, hMemDC, 0, 0, rop);
00628     GetObject(hBitmap, sizeof (BITMAP), (LPVOID) &bm);
00629     StretchBlt( hDC, rect.left, rect.top, rect.right, rect.bottom,
00630                 hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, rop);
00631     DeleteDC(hMemDC);
00632 }
00633
00634 /***************************************************************************
00635
00636     FUNCTION: ButtonProc
00637
00638 ***************************************************************************/
00639
00640 LRESULT CALLBACK ButtonProc(HWND hWnd,      /* window handle        */
00641                 UINT message,   /* type of message       */
00642                 WPARAM wParam,  /* additional information    */
00643                 LPARAM lParam ) /* additional information    */
00644 {
00645
00646    switch ( message )
00647    {
00648        case WM_CHAR:
00649           OutputDebugString("ButtonProc: WM_CHAR received\r\n");
00650           SendMessage( ghWnd, WM_COMMAND, MAKEWPARAM(BOB,BN_CLICKED),
00651                        (LPARAM)(hWnd));
00652
00653        default:
00654           return CallWindowProc( OldButtonProc, hWnd, message, wParam, lParam );
00655
00656    }
00657
00658    return ( 0 );
00659 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/UTDLL32.C Source File

  • INTEROP

UTDLL32.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *                                                                    *
00003 *  File:      utdll32.c                                              *
00004 *                                                                    *
00005 *  Comments:  32-bit side of the Universal Thunk                     *
00006 *                                                                    *
00007 *  Functions: DllMain                                                *
00008 *             InitThunk                                              *
00009 *             UTCBProc                                               *
00010 *                                                                    *
00011 \********************************************************************/
00012
00013 /*********************  Header Files **********************/
00014
00015 #define W32SUT_32
00016
00017 #include <windows.h>
00018 #include "w32sut.h"
00019 #include "myut.h"
00020
00021 /*********************  Defines    ************************/
00022
00023 typedef BOOL (WINAPI *PUTREGISTER) (HANDLE,
00024             LPCSTR,
00025             LPCSTR,
00026             LPCSTR,
00027             UT32PROC *,
00028             FARPROC,
00029             LPVOID);
00030
00031 typedef VOID (WINAPI *PUTUNREGISTER) (HANDLE);
00032
00033 /*********************  Globals    ************************/
00034
00035 HWND     ghWnd;
00036 HANDLE   ghDLL, hKernel32=0;
00037 UT32PROC pfnUTProc = NULL;
00038 PUTREGISTER pUTRegister = NULL;
00039 PUTUNREGISTER pUTUnRegister = NULL;
00040
00041 /*********************  Prototypes ************************/
00042
00043 DWORD WINAPI UTCBProc( LPVOID, DWORD );
00044
00045 void WINAPI MyPrint( LPSTR, LPSTR, DWORD );
00046
00047 /********************************************************************\
00048 * Function: BOOL WINAPI DllMain( HANDLE, DWORD, LPVOID )             *
00049 *                                                                    *
00050 *  Purpose: DLL entry point                                          *
00051 *                                                                    *
00052 * Comments: Standard template                                        *
00053 *           Saves instance handle in a global variable               *
00054 *                                                                    *
00055 *                                                                    *
00056 \********************************************************************/
00057
00058 BOOL WINAPI DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved )
00059 {
00060    static int cAttached = 0;
00061
00062    switch (dwReason)
00063    {
00064       case DLL_PROCESS_ATTACH:
00065    if( !cAttached ) {
00066       hKernel32 = LoadLibrary( "Kernel32.Dll" );
00067       pUTRegister = (PUTREGISTER) GetProcAddress(hKernel32, "UTRegister");
00068       pUTUnRegister = (PUTUNREGISTER) GetProcAddress(hKernel32, "UTUnRegister");
00069       ghDLL = hDLL;
00070    }
00071          cAttached++;
00072          break;
00073
00074       case DLL_THREAD_ATTACH:
00075          break;
00076
00077       case DLL_THREAD_DETACH:
00078          break;
00079
00080       case DLL_PROCESS_DETACH:
00081          --cAttached;
00082          if( !cAttached ) {
00083       (*pUTUnRegister)( hDLL );
00084          }
00085          break;
00086    }
00087
00088    return TRUE;
00089 }
00090
00091 /********************************************************************\
00092 * Function: void WINAPI InitThunk( HWND )                            *
00093 *                                                                    *
00094 *  Purpose: Initialize the Universal Thunk                           *
00095 *                                                                    *
00096 * Comments: Saves the window handle passed by the Win32 stub app     *
00097 *           and calls UTRegister() to establish the thunk and load   *
00098 *           dll16.dll.                                               *
00099 *                                                                    *
00100 *                                                                    *
00101 \********************************************************************/
00102
00103 void WINAPI InitThunk( HWND hWnd )
00104 {
00105    ghWnd = hWnd;
00106
00107    if( !(*pUTRegister)( ghDLL,
00108       "dll16.dll",
00109       "UTInit",
00110       "UTProc",
00111       &pfnUTProc,
00112       UTCBProc,
00113       NULL )
00114      )
00115    MessageBox( NULL, "UTRegister() failed", "UTDLL32", MB_OK );
00116 }
00117
00118 /********************************************************************\
00119 * Function: DWORD WINAPI UTCBProc( LPVOID, DWORD )                   *
00120 *                                                                    *
00121 *  Purpose: Dispatch routine                                         *
00122 *                                                                    *
00123 * Comments: Switches on dwFunc to determine which dll32 routine is   *
00124 *           being called and calls into that DLL (dll32.dll). Note   *
00125 *           that the two strings required by MyPrint() were put into *
00126 *           a translation list in dll16.c, now they are passed as  *
00127 *           separate arguments.                                      *
00128 *                                                                    *
00129 *                                                                    *
00130 \********************************************************************/
00131
00132 DWORD WINAPI UTCBProc( LPVOID lpBuf, DWORD dwFunc )
00133 {
00134    switch( dwFunc )
00135    {
00136       case MYPRINT:
00137          MyPrint( (LPSTR) ((LPDWORD)lpBuf)[0], (LPSTR) ((LPDWORD)lpBuf)[1],
00138             ((LPDWORD)lpBuf)[2] );
00139          break;
00140
00141    /*
00142       Return window handle so that app16.exe can force stub32.exe
00143       to terminate via SendMessage( ... WM_CLOSE ... )
00144    */
00145
00146       case GETHWND:
00147          return (DWORD) ghWnd;
00148          break;
00149
00150       default:
00151          MessageBox( NULL, "Unsupported routine called", "utdll32", MB_OK );
00152    }
00153    return TRUE;
00154 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LINKTEST.H Source File

  • SIMPLDLL

LINKTEST.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *                                 LINKTEST.H
00015 *
00016 \******************************************************************************/
00017
00018
00019
00020 /******************************************************************************\
00021 *                              SYMBOLIC CONSTANTS
00022 \******************************************************************************/
00023
00024 #define IDM_CREATETHREAD 100 /* menu identifiers */
00025 #define IDM_DLLFUNCTION1 101
00026 #define IDM_DLLFUNCTION2 102
00027 #define IDM_DLLFUNCTION3 103
00028 #define IDM_DLLFUNCTION4 104
00029 #define IDM_DLLDIALOGBOX 105
00030 #define IDM_ABOUT        106
00031
00032
00033
00034 /******************************************************************************\
00035 *                                  GLOBAL VARS
00036 \******************************************************************************/
00037
00038 HWND ghwndMain;
00039
00040
00041
00042 /******************************************************************************\
00043 *                              FUNCTION PROTOTYPES
00044 \******************************************************************************/
00045
00046 LRESULT CALLBACK MainWndProc  (HWND, UINT, WPARAM, LPARAM);
00047 BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM);
00048
00049 void ThreadProc   (void);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/STATUS.C Source File

  • UNIPUT

STATUS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 * status.c - module to support the status bar.
00014 *
00015 * resized by main frame window.
00016 * Title and type text may be set in display.c
00017 * text and painting managed in this module.
00018 \**************************************************************************/
00019 #define UNICODE
00020
00021 #include <windows.h>
00022 #include "uniput.h"
00023
00024
00025 /* prototype for function to do pseudo-3D outline */
00026 VOID framechildwindow (HDC, HWND, HWND);
00027
00028
00029 /* logfont for the font selected into the static windows on status bar */
00030 LOGFONT logfontsmall = {
00031       UCFONTHEIGHT /2 ,
00032       UCFONTWIDTH /2,
00033        0 ,
00034        0 ,
00035      400 ,
00036        0 ,
00037        0 ,
00038        0 ,
00039        UNICODE_CHARSET ,
00040        0 ,
00041        0 ,
00042        2 ,
00043        2 ,
00044       TEXT("Lucida Sans Unicode")};
00045
00046
00047
00048 HWND hwndStatic0, hwndStatic1, hwndStatic2;
00049
00050 /**************************************************************************\
00051 *
00052 *  function:  StatusWndProc()
00053 *
00054 *  input parameters:  normal window procedure parameters.
00055 *
00056 *  global variables:
00057 \**************************************************************************/
00058 LRESULT CALLBACK StatusWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00059 {
00060 static HFONT hfontStatic;
00061 RECT rect, clientrect;
00062
00063
00064   switch (message) {
00065
00066     /**********************************************************************\
00067     *  WM_CREATE
00068     *
00069     * Create two static child windows, and select a font for them.
00070     \**********************************************************************/
00071     case WM_CREATE: {
00072       GetClientRect (hwnd, &clientrect);
00073
00074       hwndStatic0 = CreateWindow(
00075               TEXT("STATIC"),
00076               TEXT("Target Window"),
00077               WS_CHILD | WS_VISIBLE | SS_CENTER,
00078               0,0,0,0,
00079               hwnd, NULL, hInst, 0);
00080
00081       hwndStatic1 = CreateWindow(
00082               TEXT("STATIC"),
00083               TEXT("Unicode/Ansi"),
00084               WS_CHILD | WS_VISIBLE | SS_CENTER,
00085               0,0,0,0,
00086               hwnd, NULL, hInst, 0);
00087
00088       hwndStatic2 = CreateWindow(
00089               TEXT("STATIC"),
00090               TEXT(""),
00091               WS_CHILD | WS_VISIBLE | SS_RIGHT,
00092               0,0,0,0,
00093               hwnd, NULL, hInst, 0);
00094
00095
00096       hfontStatic = CreateFontIndirect (&logfontsmall);
00097       SendMessage (hwndStatic0, WM_SETFONT, (WPARAM) hfontStatic, 0);
00098       SendMessage (hwndStatic1, WM_SETFONT, (WPARAM) hfontStatic, 0);
00099       SendMessage (hwndStatic2, WM_SETFONT, (WPARAM) hfontStatic, 0);
00100     } break;
00101
00102
00103     /**********************************************************************\
00104     *  WM_DESTROY
00105     *
00106     * free the font we created at WM_CREATE time.
00107     * hwndStatic* child windows are destroyed automatically.
00108     \**********************************************************************/
00109     case WM_DESTROY:
00110       DeleteObject (hfontStatic);
00111     break;
00112
00113
00114     /**********************************************************************\
00115     *  WM_CTLCOLORSTATIC
00116     \**********************************************************************/
00117     case WM_CTLCOLORSTATIC: {
00118       HDC hdc;
00119
00120       hdc = (HDC) wParam;
00121       SetBkMode (hdc, TRANSPARENT);
00122       return (LRESULT)GetStockObject (LTGRAY_BRUSH);
00123     } break;
00124
00125
00126     /**********************************************************************\
00127     *  WM_SIZE
00128     *
00129     * Resize the static controls to stretch them to always fill the status
00130     *  bar minus some border area.
00131     \**********************************************************************/
00132     case WM_SIZE: {
00133       GetClientRect (hwnd, &clientrect);
00134       rect.top = clientrect.top + SBORDER;
00135       rect.bottom = clientrect.bottom - SBORDER;
00136
00137       rect.left = SBORDER;
00138       rect.right = rect.left + SFIELD0;
00139
00140       SetWindowPos (hwndStatic0, HWND_TOP,
00141         rect.left,
00142         rect.top,
00143         rect.right - rect.left,
00144         rect.bottom - rect.top, 0);
00145
00146
00147       rect.left = 3*SBORDER + SFIELD0;
00148       rect.right = rect.left + SFIELD1;
00149
00150       SetWindowPos (hwndStatic1, HWND_TOP,
00151         rect.left,
00152         rect.top,
00153         rect.right - rect.left,
00154         rect.bottom - rect.top, 0);
00155
00156       rect.left  = 5*SBORDER + SFIELD0 + SFIELD1;
00157       rect.right = clientrect.right - SBORDER;
00158
00159       SetWindowPos (hwndStatic2, HWND_TOP,
00160         rect.left,
00161         rect.top,
00162         rect.right - rect.left,
00163         rect.bottom - rect.top, 0);
00164
00165       return TRUE;
00166     } break;
00167
00168
00169
00170
00171     /**********************************************************************\
00172     *  WMU_SETTARGETNAME
00173     *
00174     * wParam - BOOL... TRUE: hwndTarget is unicode, FALSE: ansi
00175     * lParam - pointer to new string.
00176     *
00177     \**********************************************************************/
00178     case WMU_SETTARGETNAME:
00179
00180       SetWindowText (hwndStatic0,(LPCTSTR) lParam);
00181
00182       if (wParam == FALSE)
00183         SetWindowText (hwndStatic1,TEXT ("Ansi"));
00184       else
00185         SetWindowText (hwndStatic1,TEXT ("Unicode"));
00186
00187     break;
00188
00189
00190 #define MAXCHARS 255
00191
00192     /**********************************************************************\
00193     *  WMU_CHARACTER
00194     *
00195     * wParam - WCHAR value
00196     *
00197     * Display a string of characters in the second static window. This is
00198     *  a FIFO buffer, if we fill it, shift characters to the left, and
00199     *  set the string back into the static control.
00200     *
00201     \**********************************************************************/
00202     case WMU_CHARACTER: {
00203       TCHAR buffer[MAXCHARS+1];
00204       int nchar;
00205       int i;
00206
00207       GetWindowText (hwndStatic2,buffer, MAXCHARS+1);
00208       nchar = GetWindowTextLength (hwndStatic2);
00209
00210       if (nchar >= MAXCHARS) {
00211         nchar = MAXCHARS-1;
00212         for (i= 0; i<(MAXCHARS-1); i++)
00213           buffer[i] = buffer[i+1];
00214       }
00215
00216       buffer[nchar] = (TCHAR) wParam;
00217       buffer[nchar+1] = (TCHAR) '\000';
00218
00219       SetWindowText (hwndStatic2,buffer);
00220
00221     } break;
00222
00223
00224
00225     /**********************************************************************\
00226     *  WM_PAINT
00227     *
00228     * Gray background is done automatically, just outline the two static
00229     *  text windows with 3-D effect.
00230     \**********************************************************************/
00231     case WM_PAINT: {
00232       HDC hdc;
00233       PAINTSTRUCT ps;
00234
00235       hdc = BeginPaint(hwnd, &ps);
00236
00237       framechildwindow (hdc,hwnd, hwndStatic0);
00238       framechildwindow (hdc,hwnd, hwndStatic1);
00239       framechildwindow (hdc,hwnd, hwndStatic2);
00240
00241       EndPaint (hwnd, &ps);
00242     } return FALSE; /* end WM_PAINT */
00243
00244   } /* end switch */
00245   return (DefWindowProc(hwnd, message, wParam, lParam));
00246 }
00247
00248
00249
00250 /**************************************************************************\
00251 *
00252 *  function:  framechildwindow()
00253 *
00254 * Simply draw a 3D frame around child window.
00255 *
00256 \**************************************************************************/
00257 VOID framechildwindow (HDC hdc, HWND hwndParent, HWND hwndChild)
00258 {
00259 RECT rect;
00260
00261       GetWindowRect (hwndChild, &rect);
00262
00263       /* minor hack... assumes RECT is two points, right field starting first */
00264       ScreenToClient (hwndParent, (LPPOINT)&rect);
00265       ScreenToClient (hwndParent, (LPPOINT)&(rect.right));
00266
00267       InflateRect (&rect, 1, 1);
00268       FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
00269       InflateRect (&rect, -1, -1);
00270       SelectObject (hdc, GetStockObject (WHITE_PEN));
00271       MoveToEx (hdc, rect.right, rect.top, NULL);
00272       LineTo (hdc,rect.right, rect.bottom);
00273       LineTo (hdc,rect.left, rect.bottom);
00274
00275     return;
00276 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/INIT.C Source File

  • NETDDE

INIT.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   init.c
00009 //
00010 //  PURPOSE:   Performs application and instance specific initialization.
00011 //
00012 //  FUNCTIONS:
00013 //    InitApplication() - Initializes window data and registers window.
00014 //    InitInstance() - Saves instance handle and creates main window.
00015 //
00016 //  COMMENTS:
00017 //
00018
00019 #include <windows.h>            // required for all Windows applications
00020 #ifdef WIN16
00021 #include "win16ext.h"           // required only for win16 applications
00022 #endif
00023 #include "globals.h"            // prototypes specific to this application
00024
00025 HINSTANCE hInst;                // current instance
00026
00027 char szAppName[9];              // The name of this application
00028 char szTitle[40];               // The title bar text
00029
00030 //
00031 //  FUNCTION: InitApplication(HINSTANCE)
00032 //
00033 //  PURPOSE: Initializes window data and registers window class.
00034 //
00035 //  PARAMETERS:
00036 //    hInstance - The handle to the instance of this application that
00037 //          is currently being executed.
00038 //
00039 //  RETURN VALUE:
00040 //    TRUE - Success
00041 //    FALSE - Initialization failed
00042 //
00043 //  COMMENTS:
00044 //
00045 //    This function is called at initialization time only if no other
00046 //    instances of the application are running.  This function performs
00047 //    initialization tasks that can be done once for any number of running
00048 //    instances.
00049 //
00050 //    In this case, we initialize a window class by filling out a data
00051 //    structure of type WNDCLASS and calling the Windows RegisterClass()
00052 //    function.  Since all instances of this application use the same
00053 //    window class, we only need to do this when the first instance is
00054 //    initialized.
00055 //
00056
00057 BOOL InitApplication(HINSTANCE hInstance)
00058 {
00059     WNDCLASS  wc;
00060
00061     // Load the application name and description strings.
00062
00063     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
00064     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
00065
00066     // Fill in window class structure with parameters that describe the
00067     // main window.
00068
00069     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
00070     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
00071     wc.cbClsExtra    = 0;                       // No per-class extra data.
00072     wc.cbWndExtra    = 0;                       // No per-window extra data.
00073     wc.hInstance     = hInstance;               // Owner of this class
00074     wc.hIcon         = LoadIcon(hInstance, szAppName); // Icon name from .RC
00075     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
00076     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
00077     wc.lpszMenuName  = szAppName;               // Menu name from .RC
00078     wc.lpszClassName = szAppName;               // Name to register as
00079
00080     // Register the window class and return FALSE if unsuccesful.
00081
00082     if (!RegisterClass(&wc))
00083     {
00084         return FALSE;
00085     }
00086     //
00087     // **TODO** Call module specific application initialization functions here.
00088     //
00089
00090     return TRUE;
00091 }
00092
00093
00094 //
00095 //  FUNCTION:  InitInstance(HINSTANCE, int)
00096 //
00097 //  PURPOSE:  Saves instance handle and creates main window.
00098 //
00099 //  PARAMTERS:
00100 //    hInstance - The handle to the instance of this application that
00101 //          is currently being executed.
00102 //    nCmdShow - Specifies how the main window is to be diplayed.
00103 //
00104 //  RETURN VALUE:
00105 //    TRUE - Success
00106 //    FALSE - Initialization failed
00107 //
00108 //  COMMENTS:
00109 //    This function is called at initialization time for every instance of
00110 //    this application.  This function performs initialization tasks that
00111 //    cannot be shared by multiple instances.
00112 //
00113 //    In this case, we save the instance handle in a static variable and
00114 //    create and display the main program window.
00115 //
00116
00117 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
00118 {
00119     HWND    hwnd; // Main window handle.
00120
00121     // Save the instance handle in static variable, which will be used in
00122     // many subsequence calls from this application to Windows.
00123
00124     hInst = hInstance; // Store instance handle in our global variable
00125
00126     // Create a main window for this application instance.
00127     hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
00128                         szTitle,             // Text for window title bar.
00129                         WS_OVERLAPPEDWINDOW, // Window style.
00130                         CW_USEDEFAULT, 0,    // Use default positioning
00131                         CW_USEDEFAULT, 0,    // Use default size
00132                         NULL,                // Overlapped has no parent.
00133                         NULL,                // Use the window class menu.
00134                         hInstance,
00135                         NULL);
00136
00137     // If window could not be created, return "failure"
00138     if (!hwnd)
00139         return FALSE;
00140
00141     //
00142     // **TODO** Call module specific instance initialization functions here.
00143     //
00144
00145     // Make the window visible; update its client area; and return "success"
00146     ShowWindow(hwnd, nCmdShow); // Show the window
00147     UpdateWindow(hwnd);         // Sends WM_PAINT message
00148
00149     return TRUE;                // We succeeded...
00150 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/THRDUTIL.C Source File

  • SERVENUM
  • DLL

THRDUTIL.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   thrdutil.c
00009 //
00010 //  PURPOSE:  Maintain list of outstanding threads
00011 //
00012 //  FUNCTIONS:
00013 //    WaitCloseOutstanding - Waits for all threads to finish,
00014 //                           and closes thread handles
00015 //    RefreshOutstanding - refreshs list, removing terminated threads
00016 //    MarkOutstanding - adds a thread to the outstanding list
00017 //
00018 //  AUTHOR: Craig Link - Microsoft Developer Support
00019 //
00020
00021 #include <windows.h>
00022 #include <stdlib.h>
00023 #include "thrdutil.h"
00024 #include "mem.h"
00025
00026 // initialized in DllMain procedure
00027 CRITICAL_SECTION g_csOutstanding;
00028
00029 // variables global to this module
00030 HANDLE *g_lphOutstanding = NULL;
00031 UINT    g_nOutstanding = 0;
00032
00033
00034 //
00035 //  FUNCTION: WaitCloseOutstanding()
00036 //
00037 //  PURPOSE:  Waits for all threads to finish, and closes thread handles
00038 //
00039 //  PARAMETERS:
00040 //    none
00041 //
00042 //  RETURN VALUE:
00043 //    none
00044 //
00045 //  COMMENTS:
00046 //
00047 VOID WaitCloseOutstanding()
00048 {
00049     UINT ndx;
00050
00051     EnterCriticalSection(&g_csOutstanding);
00052
00053     for( ndx = 0; ndx < g_nOutstanding; ndx+=MAXIMUM_WAIT_OBJECTS )
00054     {
00055         WaitForMultipleObjects( g_nOutstanding-ndx,
00056                                 g_lphOutstanding+ndx,
00057                                 TRUE, INFINITE );
00058
00059     }
00060
00061     for( ndx = 0; ndx < g_nOutstanding; ndx++ )
00062         CloseHandle(g_lphOutstanding[ndx]);
00063
00064     FreeMem((LPVOID*)&g_lphOutstanding);
00065     g_nOutstanding = 0;
00066
00067     LeaveCriticalSection(&g_csOutstanding);
00068
00069 }
00070
00071 //
00072 //  FUNCTION: RefreshOutstanding()
00073 //
00074 //  PURPOSE:  Refresh outstanding thread list, removing and threads
00075 //            which have terminated
00076 //
00077 //  PARAMETERS:
00078 //    none
00079 //
00080 //  RETURN VALUE:
00081 //    none
00082 //
00083 //  COMMENTS:
00084 //
00085 VOID RefreshOutstanding()
00086 {
00087     UINT ndx = 0;
00088     UINT ndx2 = 0;
00089
00090     EnterCriticalSection(&g_csOutstanding);
00091
00092     for( ndx = 0; ndx < g_nOutstanding; ndx++ )
00093     {
00094         if ( WaitForSingleObject( g_lphOutstanding[ndx], 0 ) == WAIT_OBJECT_0 )
00095         {
00096             CloseHandle( g_lphOutstanding[ndx] );
00097             g_lphOutstanding[ndx] = NULL;
00098         }
00099         else  // handle still outstanding
00100         {
00101             g_lphOutstanding[ndx2++] = g_lphOutstanding[ndx];
00102         }
00103     }
00104
00105     if ( g_nOutstanding < ndx2 )
00106     {
00107         // realloc won't fail because we are shrinking
00108         g_nOutstanding = ndx2;
00109         ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*g_nOutstanding );
00110     }
00111
00112     LeaveCriticalSection(&g_csOutstanding);
00113
00114 }
00115
00116
00117 //
00118 //  FUNCTION: MarkOutstanding( HANDLE *lpHandle )
00119 //
00120 //  PURPOSE:  Adds a thread to the outstanding thread list
00121 //
00122 //  PARAMETERS:
00123 //    lpHandle - pointer to thread to add
00124 //
00125 //  RETURN VALUE:
00126 //    ERROR_NOT_ENOUGH_MEMORY
00127 //    ERROR_SUCCESS
00128 //
00129 //  COMMENTS:
00130 //    If thread is successfully added the passed in handle
00131 //    is set to NULL
00132 //
00133 DWORD MarkOutstanding( HANDLE *lpHandle )
00134 {
00135     DWORD dwRet;
00136
00137     EnterCriticalSection(&g_csOutstanding);
00138
00139     RefreshOutstanding();
00140
00141     if ( ERROR_NOT_ENOUGH_MEMORY == ReallocMem( (LPVOID*)&g_lphOutstanding, sizeof(HANDLE)*(g_nOutstanding+1) ) )
00142     {
00143         dwRet = ERROR_NOT_ENOUGH_MEMORY;
00144     }
00145     else
00146     {
00147         g_lphOutstanding[g_nOutstanding++] = *lpHandle;
00148         *lpHandle = NULL;
00149         dwRet = ERROR_SUCCESS;
00150     }
00151
00152     LeaveCriticalSection(&g_csOutstanding);
00153
00154     return dwRet;
00155 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MEM.C Source File

  • SERVENUM
  • DLL

MEM.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   mem.c
00009 //
00010 //  PURPOSE:  Contains memory management routines
00011 //
00012 //  FUNCTIONS:
00013 //    MallocMem - allocates memory
00014 //    ReallocMem - reallocates memory
00015 //    FreeMem - frees memory
00016 //
00017 //  AUTHOR: Craig Link - Microsoft Developer Support
00018 //
00019
00020 #include <windows.h>
00021 #include <malloc.h>
00022
00023 #ifdef _DEBUG
00024 DWORD dwAlloc = 0;
00025 #endif
00026
00027 //
00028 //  FUNCTION: MallocMem( LPVOID *lplpv, DWORD dwSize )
00029 //
00030 //  PURPOSE:  Dynamically allocates memory
00031 //
00032 //  PARAMETERS:
00033 //    lplpv - address of pointer to newly allocated memory
00034 //    dwSize - number of bytes to allocate
00035 //
00036 //  RETURN VALUE:
00037 //    ERROR_SUCCESS
00038 //    ERROR_NOT_ENOUGH_MEMORY
00039 //
00040 //
00041 DWORD MallocMem( LPVOID *lplpv, DWORD dwSize )
00042 {
00043     LPVOID lpTemp;
00044
00045     if ( NULL == ( lpTemp = malloc( dwSize ) ) )
00046         return ERROR_NOT_ENOUGH_MEMORY;
00047
00048     *lplpv = lpTemp;
00049
00050 #ifdef _DEBUG
00051     InterlockedIncrement(&dwAlloc);
00052 #endif
00053
00054     return ERROR_SUCCESS;
00055
00056 }
00057
00058
00059 //
00060 //  FUNCTION: ReallocMem( LPVOID *lplpv, DWORD dwSize )
00061 //
00062 //  PURPOSE:  Dynamically reallocates memory
00063 //
00064 //  PARAMETERS:
00065 //    lplpv - address of pointer to newly reallocated memory
00066 //    dwSize - number of bytes to allocate
00067 //
00068 //  RETURN VALUE:
00069 //    ERROR_SUCCESS
00070 //    ERROR_NOT_ENOUGH_MEMORY
00071 //
00072 //
00073 DWORD ReallocMem( LPVOID *lplpv, DWORD dwSize )
00074 {
00075     LPVOID lpTemp;
00076
00077     if ( NULL == ( lpTemp = realloc( *lplpv, dwSize ) ) )
00078         return ERROR_NOT_ENOUGH_MEMORY;
00079
00080 #ifdef _DEBUG
00081     if ( dwSize == 0 )
00082         InterlockedDecrement(&dwAlloc);
00083     else if ( *lplpv == NULL )
00084         InterlockedIncrement(&dwAlloc);
00085 #endif
00086
00087     *lplpv = lpTemp;
00088
00089     return ERROR_SUCCESS;
00090 }
00091
00092 //
00093 //  FUNCTION: FreeMem( LPVOID *lplpv )
00094 //
00095 //  PURPOSE:  Frees dynamically allocated memory
00096 //
00097 //  PARAMETERS:
00098 //    lplpv - address of pointer to newly allocated memory
00099 //            Set to NULL on return
00100 //
00101 //  RETURN VALUE:
00102 //    none
00103 //
00104 //
00105 VOID FreeMem( LPVOID *lplpv )
00106 {
00107     free( *lplpv );
00108     *lplpv = NULL;
00109 #ifdef _DEBUG
00110     InterlockedDecrement(&dwAlloc);
00111 #endif
00112
00113 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GETDEV/GETDEV.C Source File

  • GETDEV

GETDEV.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  getdev.c -- sample program demonstrating the getdev... APIs
00014 *
00015 *  In this sample the main window is a dialog box.  There is no need to
00016 *   register a new window class or create a new window.  Instead just call
00017 *   DialogBox() and use the template defined in the .RC file.  All of the
00018 *   interesting code is thus in the window procedure for the dialog box.
00019 *
00020 *  The dialog template currently specifies a "monospaced font."  This makes
00021 *   the dialog look somewhat odd, but makes text formatting much easier.  If
00022 *   the specified font does not exist on the system running this sample, the
00023 *   program will work fine, but the contents of the listbox will not look
00024 *   very good.
00025 *
00026 \**************************************************************************/
00027
00028 #include <windows.h>
00029 #include "getdev.h"
00030
00031
00032 /**************************************************************************\
00033 *
00034 *  function:  WinMain()
00035 *
00036 *  input parameters:  c.f. generic sample
00037 *
00038 \**************************************************************************/
00039 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00040                      LPSTR lpCmdLine, int nCmdShow)
00041 {
00042 int ret;
00043
00044     UNREFERENCED_PARAMETER( hPrevInstance );
00045     UNREFERENCED_PARAMETER( lpCmdLine );
00046     UNREFERENCED_PARAMETER( nCmdShow);
00047
00048     ret = DialogBox (hInstance, "getdevDlg", NULL, (DLGPROC)MainDlgProc);
00049     return ret;
00050 }
00051
00052
00053
00054 /**************************************************************************\
00055 *
00056 *  function:  MainDlgProc()
00057 *
00058 *  input parameters:  standard window procedure parameters.
00059 *
00060 * At initialization time, call GetDeviceCaps() repeatedly and place the
00061 *  results in the list box.
00062 *
00063 \**************************************************************************/
00064 LONG APIENTRY MainDlgProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
00065 {
00066   UNREFERENCED_PARAMETER(lParam);
00067
00068
00069   switch (message) {
00070
00071     case WM_INITDIALOG: {
00072       int i;
00073       int value;
00074       HDC hdc;
00075
00076       hdc = GetDC (hwnd);
00077
00078       for (i = 0; i < NINDEX ; i++) {
00079         value = GetDeviceCaps (hdc , DevCaps[i].Value);
00080         wsprintf (buffer,"%s %8d", DevCaps[i].String, value);
00081         SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG) buffer);
00082         ExpandInfo (hwnd, DevCaps[i].Value, value);
00083       }
00084
00085       ReleaseDC (hwnd,hdc);
00086     } break;
00087
00088
00089     /********************************************************************\
00090     * WM_SYSCOMMAND
00091     *
00092     * ignore all syscommand messages, except for SC_CLOSE.
00093     *  on this one, call EndDialog().
00094     \********************************************************************/
00095     case WM_SYSCOMMAND:
00096       if (wParam == SC_CLOSE) {
00097         EndDialog (hwnd, TRUE);
00098         return TRUE;
00099       } else
00100         return FALSE;
00101     break;
00102
00103
00104     default: return FALSE;
00105   } /* end switch(message) */
00106   return 0;
00107 }
00108
00109
00110
00111
00112
00113 /**************************************************************************\
00114 *
00115 *  function:  ExpandInfo()
00116 *
00117 *  input parameters:
00118 *   hwnd  - parent of the list box with the info.
00119 *   index - the input value which was sent to GetDeviceCaps().
00120 *   value - the return value from calling GetDeviceCaps().
00121 *
00122 *  global variables:
00123 *   buffer - string to hold info sent to list box.
00124 *   space  - format string to wsprintf
00125 *
00126 *  Some of the return values from GetDeviceCaps() are bit strings
00127 *   where each bit has a constant defined for it in wingdi.h.  This
00128 *   function simply translates the bits into the string constant and
00129 *   then places that in the listbox.
00130 *
00131 \**************************************************************************/
00132 VOID ExpandInfo (HWND hwnd, int index, int value)
00133 {
00134   int i;
00135
00136   switch (index) {
00137
00138     case TECHNOLOGY   :
00139       for (i = 0 ; i< NDevice ; i++) {
00140         if (value == Device[i].Value) {
00141           wsprintf (buffer,space, Device[i].String);
00142           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00143         }
00144       }
00145     break;
00146
00147
00148
00149     case CURVECAPS    :
00150       for (i = 0 ; i< NCurveCaps ; i++) {
00151         if (value & CurveCaps[i].Value) {
00152           wsprintf (buffer,space, CurveCaps[i].String);
00153           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00154         }
00155       }
00156     break;
00157
00158
00159
00160     case LINECAPS     :
00161       for (i = 0 ; i< NLineCaps ; i++) {
00162         if (value & LineCaps[i].Value) {
00163           wsprintf (buffer,space, LineCaps[i].String);
00164           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00165         }
00166       }
00167     break;
00168
00169
00170
00171     case POLYGONALCAPS:
00172       for (i = 0 ; i< NPolygonalCaps ; i++) {
00173         if (value & PolygonalCaps[i].Value) {
00174           wsprintf (buffer,space, PolygonalCaps[i].String);
00175           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00176         }
00177       }
00178     break;
00179
00180
00181
00182     case TEXTCAPS     :
00183       for (i = 0 ; i< NTextCaps ; i++) {
00184         if (value & TextCaps[i].Value) {
00185           wsprintf (buffer,space, TextCaps[i].String);
00186           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00187         }
00188       }
00189     break;
00190
00191
00192
00193     case CLIPCAPS     :
00194       for (i = 0 ; i< NClipCaps ; i++) {
00195         if (value & ClipCaps[i].Value) {
00196           wsprintf (buffer,space, ClipCaps[i].String);
00197           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00198         }
00199       }
00200     break;
00201
00202
00203
00204     case RASTERCAPS   :
00205       for (i = 0 ; i< NRasterCaps ; i++) {
00206         if (value & RasterCaps[i].Value) {
00207           wsprintf (buffer,space, RasterCaps[i].String);
00208           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LONG)buffer);
00209         }
00210       }
00211     break;
00212
00213
00214     default:
00215     break;
00216
00217   } /* end switch */
00218 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMTHRD.C Source File

  • SERVENUM
  • DLL

ENUMTHRD.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: enumthrd.c
00009 //
00010 // PURPOSE:
00011 //    Contains thread procedures for enumeration.
00012 //
00013 //  FUNCTIONS:
00014 //    InitialEnumThread - performs initial network enumeration
00015 //    EnumExpandThread - expands a entry in list box by 1 level
00016 //    EnumContainerThread - does actual container enumeration
00017 //
00018 //  COMMENTS:
00019 //    cThread of the ENUMSYNC object should be incremented before calling
00020 //    or creating threads on these procedures since they call FreeEnumSync()
00021 //    befored returning
00022 //
00023 //  AUTHOR: Craig Link - Microsoft Developer Support
00024 //
00025
00026
00027
00028 #include <windows.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <tchar.h>
00032 #include <lm.h>
00033 #include "enumutil.h"
00034 #include "enumthrd.h"
00035 #include "enumdlg.h"
00036 #include "mem.h"
00037
00038
00039 //
00040 //  FUNCTION: InitialEnumThread( LPENUMSYNC lpSync )
00041 //
00042 //  PURPOSE:  Perform initial enumeration of network
00043 //
00044 //  PARAMETERS:
00045 //    lpSync - pointer to syncronization object for threads
00046 //
00047 //  RETURN VALUE:
00048 //    ERROR_SUCCESS
00049 //    ERROR_FAILURE
00050 //    ERROR_NOT_ENOUGH_MEMORY
00051 //
00052 //  COMMENTS:
00053 //
00054 //    This functions performs the following actions in 3 threads
00055 //    1) Enumerates Network providers - done by enumerating a NULL container
00056 //
00057 //    2) Enumerates Domains - Domains are only a concept of the LanMan
00058 //       provider, so we go to the registry to get the actual provider
00059 //       string, and then enumerate the provider
00060 //
00061 //    3) Enumerates Servers in the Local Machine's Domain - The local
00062 //       machine's domain is found by calling NetWkstaGetInfo ( this causes
00063 //       the need for unicode ).  It is then enumerated.
00064 //
00065 //    As long as the 1st thread successfully completes, the function will
00066 //    will notify the dialog box that the enumeration completed
00067 //
00068 DWORD WINAPI InitialEnumThread( LPENUMSYNC lpSync )
00069 {
00070     DWORD dwRet = ERROR_SUCCESS;
00071     DWORD dwTemp = ERROR_SUCCESS;
00072     DWORD dwWait;
00073     LPWKSTA_INFO_100 lpWksta = NULL;
00074     HKEY  hkey;
00075     DWORD cbProv = 0;
00076     TCHAR *lpProv = NULL;
00077     HANDLE lpHandles[NUM_HANDLES] = { INVALID_HANDLE_VALUE,
00078                                       INVALID_HANDLE_VALUE,
00079                                       INVALID_HANDLE_VALUE };
00080     DWORD  tID;
00081     ENUMOBJECT eo_prov;
00082     ENUMOBJECT eo_dom;
00083     ENUMOBJECT eo_serv;
00084     NETRESOURCE netr_dom;
00085     NETRESOURCE netr_serv;
00086     ENUMNODE en_dom;
00087     ENUMNODE en_serv;
00088     DWORD ndx;
00089
00090     //***  enumerate the network providers  ***//
00091     eo_prov.lpSync = lpSync;
00092     eo_prov.lpNode = lpSync->lpRoot;
00093
00094     // start provider enumeration thread
00095     InterlockedIncrement( &((LONG)lpSync->cThread) );
00096     if ( ( lpHandles[HANDLE_PROV]=CreateThread(NULL, 100,
00097                                      (LPTHREAD_START_ROUTINE)EnumContainerThread,
00098                                      (LPVOID) &eo_prov,
00099                                      0, &tID) ) == NULL )
00100     {
00101         dwRet = ERROR_FAILURE;
00102         InterlockedDecrement( &((LONG)lpSync->cThread) );
00103         goto Cleanup;
00104     }
00105
00106
00107     //*** enumerate the domains ***//
00108     // get the LanmanWorkstation provider name from registry
00109     if ( ERROR_SUCCESS == ( dwRet = RegOpenKey( HKEY_LOCAL_MACHINE,
00110                         TEXT("System\\CurrentControlSet\\Services\\LanmanWorkstation\\NetworkProvider"),
00111                         &hkey ) ) )
00112     {
00113         if ( ERROR_SUCCESS == (dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, NULL, &cbProv ) ) )
00114         {
00115             if ( ERROR_SUCCESS == ( dwRet = MallocMem( (LPVOID *) &lpProv, cbProv ) ) )
00116             {
00117                 dwRet = RegQueryValueEx( hkey, TEXT("Name"), NULL, NULL, (LPBYTE) lpProv, &cbProv );
00118             }
00119         }
00120
00121         RegCloseKey( hkey );
00122     }
00123     if ( dwRet != ERROR_SUCCESS )
00124     {
00125         goto Cleanup;
00126     }
00127
00128     // setup netresource structure from domain enumeration
00129     netr_dom.lpRemoteName = lpProv;
00130     netr_dom.dwScope = RESOURCE_GLOBALNET;
00131     netr_dom.dwType = RESOURCETYPE_ANY;
00132     netr_dom.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
00133     netr_dom.dwUsage = RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED;
00134     netr_dom.lpLocalName = NULL;
00135     netr_dom.lpComment = NULL;
00136     netr_dom.lpProvider = lpProv;
00137
00138     en_dom.lpNet = &netr_dom;
00139     en_dom.cChild = 0;
00140     en_dom.lpChild = NULL;
00141
00142     eo_dom.lpSync = lpSync;
00143     eo_dom.lpNode = &en_dom;
00144
00145     // start domain enumeration thread
00146     InterlockedIncrement( &((LONG)lpSync->cThread) );
00147     if ( ( lpHandles[HANDLE_DOM]=CreateThread(NULL, 100,
00148                                      (LPTHREAD_START_ROUTINE)EnumContainerThread,
00149                                      (LPVOID) &eo_dom,
00150                                      0, &tID) )== NULL )
00151     {
00152         dwRet = ERROR_FAILURE;
00153         InterlockedDecrement( &((LONG)lpSync->cThread) );
00154         goto Cleanup;
00155     }
00156
00157
00158     //*** enumerate servers ***/
00159     // get the domain for this server, then enumerate to get servers
00160     if ( NERR_Success != NetWkstaGetInfo(NULL, 100, (LPBYTE *) &lpWksta) )
00161     {
00162         dwRet = ERROR_FAILURE;
00163         goto Cleanup;
00164     }
00165
00166     // setup netresource structure
00167     netr_serv.lpRemoteName = lpWksta->wki100_langroup;
00168     netr_serv.dwScope = RESOURCE_GLOBALNET;
00169     netr_serv.dwType = RESOURCETYPE_ANY;
00170     netr_serv.dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN;
00171     netr_serv.dwUsage = RESOURCEUSAGE_CONTAINER;
00172     netr_serv.lpLocalName = NULL;
00173     netr_serv.lpComment = NULL;
00174     netr_serv.lpProvider = NULL;
00175
00176     en_serv.lpNet = &netr_serv;
00177     en_serv.cChild = 0;
00178     en_serv.lpChild = NULL;
00179
00180     eo_serv.lpSync = lpSync;
00181     eo_serv.lpNode = &en_serv;
00182
00183     // start server enumeration thread
00184     InterlockedIncrement( &((LONG)lpSync->cThread) );
00185     if ( ( lpHandles[HANDLE_SERV]=CreateThread(NULL, 100,
00186                                      (LPTHREAD_START_ROUTINE)EnumContainerThread,
00187                                      (LPVOID) &eo_serv,
00188                                      0, &tID) )== NULL )
00189     {
00190         dwRet = ERROR_FAILURE;
00191         InterlockedDecrement( &((LONG)lpSync->cThread) );
00192         goto Cleanup;
00193     }
00194
00195
00196     //*** all threads started - now wait for them
00197     if ( (dwWait = WaitForMultipleObjects( NUM_HANDLES, lpHandles, TRUE, INFINITE ) ) == WAIT_FAILED )
00198     {
00199         dwRet = dwWait;
00200         goto Cleanup;
00201     }
00202
00203     // if an error occuring during top level enum, there's
00204     // no hope, so shut down and signal error
00205     GetExitCodeThread( lpHandles[HANDLE_PROV], &dwRet );
00206     if ( dwRet == ERROR_SUCCESS )
00207     {
00208         GetExitCodeThread( lpHandles[HANDLE_DOM], &dwRet );
00209         if ( dwRet == ERROR_SUCCESS )
00210         {
00211             // now we just need to attach the domain list to the appropriate provider
00212             for ( ndx = 0; ndx < lpSync->lpRoot->cChild; ndx++ )
00213             {
00214                 if ( _tcscmp( lpSync->lpRoot->lpChild[ndx].lpNet->lpRemoteName,
00215                               lpProv ) == 0 )
00216                 {
00217                     lpSync->lpRoot->lpChild[ndx].lpChild = en_dom.lpChild;
00218                     lpSync->lpRoot->lpChild[ndx].cChild = en_dom.cChild;
00219                     break;
00220                 }
00221             }
00222
00223             GetExitCodeThread( lpHandles[HANDLE_SERV], &dwRet );
00224             if ( dwRet == ERROR_SUCCESS )
00225             {
00226                 // now we just need to attach the server list to the appropriate domain
00227                 for ( ndx = 0; ndx < eo_dom.lpNode->cChild; ndx++ )
00228                     if ( _tcscmp( eo_dom.lpNode->lpChild[ndx].lpNet->lpRemoteName,
00229                                  lpWksta->wki100_langroup ) == 0 )
00230                     {
00231                         eo_dom.lpNode->lpChild[ndx].lpChild = en_serv.lpChild;
00232                         eo_dom.lpNode->lpChild[ndx].cChild = en_serv.cChild;
00233                         break;
00234                     }
00235             }
00236         }
00237         else  // domain enumeration failed so free server memory
00238         {
00239             GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
00240             if ( dwTemp == ERROR_SUCCESS )
00241                 FreeEnumChild( &en_serv );
00242         }
00243     }
00244     else // provider enumeration failed
00245     {
00246         GetExitCodeThread( lpHandles[HANDLE_DOM], &dwTemp );
00247         if ( dwTemp == ERROR_SUCCESS )
00248             FreeEnumChild( &en_dom );
00249
00250         GetExitCodeThread( lpHandles[HANDLE_SERV], &dwTemp );
00251         if ( dwTemp == ERROR_SUCCESS )
00252             FreeEnumChild( &en_serv );
00253
00254     }
00255
00256
00257     Cleanup:
00258         if ( lpHandles[HANDLE_SERV] )
00259             CloseHandle( lpHandles[HANDLE_SERV] );
00260
00261         if ( lpWksta )
00262             NetApiBufferFree(lpWksta);
00263
00264         if ( lpHandles[HANDLE_DOM] )
00265             CloseHandle( lpHandles[HANDLE_DOM] );
00266
00267         if ( lpProv )
00268             FreeMem( (LPVOID *) &lpProv );
00269
00270         if ( lpHandles[HANDLE_PROV] )
00271             CloseHandle( lpHandles[HANDLE_PROV] );
00272
00273         FreeEnumSync( &lpSync );
00274         if ( lpSync ) // if this is NULL, the dialog box doesn't exist anymore
00275             PostMessage( lpSync->hwnd, WM_INIT_ENUM, 0, 0 );
00276
00277     return dwRet;
00278
00279 }
00280
00281
00282 //
00283 //  FUNCTION: EnumExpandThread( LPENUMLISTOBJECT lpListObject )
00284 //
00285 //  PURPOSE:  Expands a entries in listbox by 1 level
00286 //
00287 //  PARAMETERS:
00288 //    lpListObject - pointer to entry to expand
00289 //
00290 //  RETURN VALUE:
00291 //    ERROR_SUCCESS
00292 //    ERROR_NOT_ENOUGH_MEMORY
00293 //
00294 //  COMMENTS:
00295 //    Calls EnumContainerThread to expand the object by 1 level
00296 //    and then post a message to the dialog
00297 //
00298 DWORD WINAPI EnumExpandThread( LPENUMLISTOBJECT lpListObject )
00299 {
00300     DWORD dwRet;
00301
00302     InterlockedIncrement( &((LONG)lpListObject->Object.lpSync->cThread) );
00303     dwRet = EnumContainerThread( &(lpListObject->Object) );
00304
00305     FreeEnumSync( &(lpListObject->Object.lpSync) );
00306
00307     if ( lpListObject->Object.lpSync )
00308         PostMessage( lpListObject->Object.lpSync->hwnd,
00309                      WM_ENUM_EXPAND,
00310                      (WPARAM) lpListObject->nItem,
00311                      (LPARAM) lpListObject->Object.lpNode );
00312
00313     FreeMem( &lpListObject );
00314
00315     return dwRet;
00316 }
00317
00318
00319 //
00320 //  FUNCTION: EnumContainerThread( LPENUMOBJECT lpObject )
00321 //
00322 //  PURPOSE:  Expands a network container by 1 level
00323 //
00324 //  PARAMETERS:
00325 //    lpObject - pointer to ENUMOBJECT to enumeration
00326 //
00327 //  RETURN VALUE:
00328 //    ERROR_SUCCESS
00329 //    ERROR_NOT_ENOUGH_MEMORY
00330 //
00331 //  COMMENTS:
00332 //
00333 DWORD WINAPI EnumContainerThread( LPENUMOBJECT lpObject )
00334 {
00335     DWORD  dwRet = ERROR_SUCCESS;
00336     HANDLE hEnum;
00337     DWORD  cTotal = 0;
00338
00339     DWORD       cChild = 0; // count of children
00340     LPENUMNODE  lpenChild = NULL;
00341
00342     DWORD cNetBuf = 0; // count of net buffers
00343     LPNETRESOURCE * lplpnetBuf = NULL; // array of enumerated buffers
00344
00345     if ( lpObject->lpNode->cChild == 0 )
00346     {
00347         dwRet  = WNetOpenEnum( RESOURCE_GLOBALNET,
00348                                RESOURCETYPE_ANY,
00349                                RESOURCEUSAGE_CONTAINER,
00350                                lpObject->lpNode->lpNet,
00351                                &hEnum );
00352
00353         if ( dwRet == NO_ERROR )
00354         {
00355             while ( dwRet == NO_ERROR )
00356             {
00357                 DWORD  cEntries =  (DWORD)-1;  // as many entries as will fit
00358                 DWORD  cbBuf = 8192;
00359
00360                 // allocate pointer for buffer
00361                 if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lplpnetBuf, ++cNetBuf*sizeof(LPNETRESOURCE) ) ) )
00362                     break;
00363
00364                 // allocate buffer
00365                 if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = MallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf ) ) )
00366                     break;
00367
00368                 if ( NO_ERROR == (dwRet = WNetEnumResource( hEnum, &cEntries, lplpnetBuf[cNetBuf-1], &cbBuf ) ) )
00369                 {
00370                     // reallocate buffer to size needed
00371                     if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) (lplpnetBuf+cNetBuf-1), cbBuf) ) )
00372                         break;
00373
00374                     // allocate array of ENUMNODEs
00375                     if ( ERROR_NOT_ENOUGH_MEMORY == ( dwRet = ReallocMem( (LPVOID *) &lpenChild, (cChild+cEntries)*sizeof(ENUMNODE) ) ) )
00376                         break;
00377
00378                     while( cEntries-- )
00379                     {   // remote any leading \\'s
00380                         while( *((lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName) == '\\' )
00381                             (lplpnetBuf[cNetBuf-1]+cEntries)->lpRemoteName++;
00382
00383                         lpenChild[cChild].lpNet = lplpnetBuf[cNetBuf-1]+cEntries;
00384                         lpenChild[cChild].cChild = 0;
00385                         lpenChild[cChild].lpChild = NULL;
00386                         cChild++;
00387                     }
00388                 }
00389                 else
00390                 {
00391                     cNetBuf--;
00392                     FreeMem( (LPVOID *) (lplpnetBuf+cNetBuf) );
00393                     // this will never fail because we shrink the buffer
00394                     ReallocMem( (LPVOID *) &lplpnetBuf, cNetBuf*sizeof(LPNETRESOURCE) );
00395                 }
00396
00397             }
00398             WNetCloseEnum( hEnum );
00399
00400             if ( ( dwRet == ERROR_NO_MORE_ITEMS ) && cNetBuf )
00401             {
00402                 qsort( (void *)lpenChild, (size_t)cChild, sizeof(ENUMNODE), CompareEnumNode );
00403
00404                 lpObject->lpNode->cChild = cChild;
00405                 lpObject->lpNode->lpChild = lpenChild;
00406
00407                 EnterCriticalSection( &(lpObject->lpSync->cs) );
00408                     if ( ERROR_SUCCESS ==
00409                           ( dwRet = ReallocMem((LPVOID *) &(lpObject->lpSync->lplpnetBuf),
00410                                                (lpObject->lpSync->cNetBuf+cNetBuf)*sizeof(LPNETRESOURCE) ) ) )
00411                     {
00412                         while( cNetBuf-- )
00413                             lpObject->lpSync->lplpnetBuf[lpObject->lpSync->cNetBuf++] = lplpnetBuf[cNetBuf];
00414                     }
00415                 LeaveCriticalSection( &(lpObject->lpSync->cs) );
00416             }
00417
00418             if ( dwRet == ERROR_NOT_ENOUGH_MEMORY )
00419             {
00420                 if ( lplpnetBuf != NULL )
00421                 {
00422                     while( cNetBuf-- )
00423                         FreeMem( (LPVOID *) lplpnetBuf+cNetBuf );
00424
00425                     FreeMem( (LPVOID *) &lpenChild );
00426                 }
00427             }
00428
00429             // because we made a copy of this buffer, we can free it
00430             FreeMem( (LPVOID *) &lplpnetBuf );
00431
00432         }
00433     }
00434
00435     FreeEnumSync( &(lpObject->lpSync) );
00436
00437     return dwRet;
00438 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/WIN16EXT.H Source File

  • NETDDE

WIN16EXT.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // PURPOSE: Defines additions to windows.h included in WIN32, but not
00009 //          in win16.
00010
00011 #include <ver.h>
00012
00013 // Windows NT defines APIENTRY, but 3.x doesn't
00014 #define APIENTRY far pascal
00015
00016 // Windows 3.x uses a FARPROC for dialogs
00017 #define DLGPROC FARPROC
00018
00019 // Windows NT defines the following in windowsx.h
00020 #define GET_WM_COMMAND_ID(w,l) (w)
00021 #define GET_WM_COMMAND_CMD(w,l) HIWORD(l)
00022 #define GET_WM_COMMAND_HWND(w,l) LOWORD(l)
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/GLOBALS.H Source File

  • SERVENUM
  • DEMO

GLOBALS.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // PURPOSE:
00009 //    Contains declarations for all globally scoped names in the program.
00010 //
00011
00012
00013 //-------------------------------------------------------------------------
00014 // Product identifier string defines
00015
00016 #define APPNAME       browse
00017 #define ICONFILE      browse.ico
00018 #define SZAPPNAME     "Browse"
00019 #define SZDESCRIPTION "ServerEnumDialog Sample"
00020 #define SZABOUT       "About Browse"
00021 #define SZVERSION     "Version 1.0"
00022
00023
00024 //-------------------------------------------------------------------------
00025 // Functions for handling main window messages.  The message-dispatching
00026 // mechanism expects all message-handling functions to have the following
00027 // prototype:
00028 //
00029 //     LRESULT FunctionName(HWND, UINT, WPARAM, LPARAM);
00030
00031
00032 LRESULT MsgCreate(HWND, UINT, WPARAM, LPARAM);
00033 LRESULT MsgCommand(HWND, UINT, WPARAM, LPARAM);
00034 LRESULT MsgDestroy(HWND, UINT, WPARAM, LPARAM);
00035
00036
00037 //-------------------------------------------------------------------------
00038 // Functions for handling main window commands--ie. functions for
00039 // processing WM_COMMAND messages based on the wParam value.
00040 // The message-dispatching mechanism expects all command-handling
00041 // functions to have the following prototype:
00042 //
00043 //     LRESULT FunctionName(HWND, WORD, WORD, HWND);
00044
00045
00046 LRESULT CmdEnumDlg(HWND, WORD, WORD, HWND);
00047 LRESULT CmdEnumHelpDlg(HWND, WORD, WORD, HWND);
00048 LRESULT CmdExit(HWND, WORD, WORD, HWND);
00049
00050
00051 //-------------------------------------------------------------------------
00052 // Global function prototypes.
00053
00054
00055 BOOL InitApplication(HINSTANCE);
00056 BOOL InitInstance(HINSTANCE, int);
00057 BOOL CenterWindow(HWND, HWND);
00058
00059 // Callback functions.  These are called by Windows.
00060
00061 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
00062
00063
00064
00065 //-------------------------------------------------------------------------
00066 // Command ID definitions.  These definitions are used to associate menu
00067 // items with commands.
00068
00069 // **TODO**  Add IDs for all menu commands here.  Be sure that the IDs you
00070 //           add are also added to the main window command table in rasberry.c
00071 //           and the menu statements in the resource file.
00072
00073 // File menu
00074 #define IDM_EXIT         1000
00075 #define IDM_ENUM         1001
00076 #define IDM_ENUMHELP     1002
00077
00078
00079
00080 //-------------------------------------------------------------------------
00081 // String Table ID definitions.
00082
00083 #define IDS_APPNAME         1
00084 #define IDS_DESCRIPTION     2
00085
00086
00087
00088
00089
00090 //-------------------------------------------------------------------------
00091 // Global variable declarations.
00092
00093 extern HINSTANCE hInst;          // The current instance handle
00094 extern TCHAR     szAppName[];    // The name of this application
00095 extern TCHAR     szTitle[];      // The title bar text
00096
00097
00098 // **TODO**  For NON-MDI applications uncomment line 1 below and comment
00099 //           line 2.  For MDI applications, uncomment line 2 below, comment
00100 //           line 1, and then define hwndMDIClient as a global variable in
00101 //           INIT.C
00102 #define hwndMDIClient NULL        /* (1) Stub for NON-MDI applications. */
00103 // extern HWND hwndMDIClient;     /* (2) For MDI applications.          */
00104
00105
00106 //-------------------------------------------------------------------------
00107 // Message and command dispatch infrastructure.  The following type
00108 // definitions and functions are used by the message and command dispatching
00109 // mechanism and do not need to be changed.
00110
00111     // Function pointer prototype for message handling functions.
00112 typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);
00113
00114     // Function pointer prototype for command handling functions.
00115 typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);
00116
00117     // Enumerated type used to determine which default window procedure
00118     // should be called by the message- and command-dispatching mechanism
00119     // if a message or command is not handled explicitly.
00120 typedef enum
00121 {
00122    edwpNone,            // Do not call any default procedure.
00123    edwpWindow,          // Call DefWindowProc.
00124    edwpDialog,          // Call DefDlgProc (This should be used only for
00125                         // custom dialogs - standard dialog use edwpNone).
00126    edwpMDIChild,        // Call DefMDIChildProc.
00127    edwpMDIFrame         // Call DefFrameProc.
00128 } EDWP;                // Enumeration for Default Window Procedures
00129
00130     // This structure maps messages to message handling functions.
00131 typedef struct _MSD
00132 {
00133     UINT   uMessage;
00134     PFNMSG pfnmsg;
00135 } MSD;                 // MeSsage Dispatch structure
00136
00137     // This structure contains all of the information that a window
00138     // procedure passes to DispMessage in order to define the message
00139     // dispatching behavior for the window.
00140 typedef struct _MSDI
00141 {
00142     int  cmsd;          // Number of message dispatch structs in rgmsd
00143     MSD *rgmsd;         // Table of message dispatch structures
00144     EDWP edwp;          // Type of default window handler needed.
00145 } MSDI, FAR *LPMSDI;   // MeSsage Dipatch Information
00146
00147     // This structure maps command IDs to command handling functions.
00148 typedef struct _CMD
00149 {
00150     WORD   wCommand;
00151     PFNCMD pfncmd;
00152 } CMD;                 // CoMmand Dispatch structure
00153
00154     // This structure contains all of the information that a command
00155     // message procedure passes to DispCommand in order to define the
00156     // command dispatching behavior for the window.
00157 typedef struct _CMDI
00158 {
00159     int  ccmd;          // Number of command dispatch structs in rgcmd
00160     CMD *rgcmd;         // Table of command dispatch structures
00161     EDWP edwp;          // Type of default window handler needed.
00162 } CMDI, FAR *LPCMDI;   // CoMmand Dispatch Information
00163
00164     // Message and command dispatching functions.  They look up messages
00165     // and commands in the dispatch tables and call the appropriate handler
00166     // function.
00167 LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
00168 LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);
00169
00170     // Message dispatch information for the main window
00171 extern MSDI msdiMain;
00172     // Command dispatch information for the main window
00173 extern CMDI cmdiMain;
00174
00175
00176
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLOS.H Source File

  • GLTHREAD

GLOS.H

Go to the documentation of this file.
00001 // GLOS.H
00002 //
00003 // This is an OS specific header file
00004
00005 #include <windows.h>
00006
00007 // disable data conversion warnings
00008
00009 #pragma warning(disable : 4244)     // MIPS
00010 #pragma warning(disable : 4136)     // X86
00011 #pragma warning(disable : 4051)     // ALPHA
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/TRACK.H Source File

  • MASKBLT

TRACK.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* track.h - header file for doTrackObject support */
00013
00014
00015 /* special messages for doTrackobject(). */
00016 #define TROB_NEW         WM_USER+1
00017 #define TROB_DELETE      WM_USER+2
00018 #define TROB_PAINT       WM_USER+3
00019 #define TROB_HITTEST     WM_USER+5
00020
00021
00022 /* Different "Track modes." */
00023 #define TMNONE    0x0000
00024 #define TMMOVE    0x0001
00025 #define TMSIZEX   0x0002
00026 #define TMSIZEY   0x0004
00027 #define TMSIZEXY  0x0006
00028 #define TMSHEARX  0x0010
00029 #define TMSHEARY  0x0020
00030 #define TMROTATE  0x0008
00031 #define TMALL     0x00ff
00032
00033
00034
00035 /* structure for the track object.  */
00036 typedef struct tagTrackObject{
00037     RECT   rect;
00038     XFORM  xfmChange;   /* World coordinate transform      */
00039     XFORM  xfmDown;     /* transform when the mouse down happens. */
00040     HDC    hdc;
00041     int    Mode;        /* TMROTATE, TMSIZEXY, TMMOVE, ... */
00042     int    allowedModes;
00043     RECT   rectClip;
00044     struct tagTrackObject* Next;
00045 } TrackObject, *PTrackObject;
00046
00047
00048 /* function prototypes. */
00049 PTrackObject doTrackObject(PTrackObject, int, HWND, LONG);
00050 VOID MouseMove(PTrackObject, int, HWND, LONG);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REGIONS/REGIONS.H Source File

  • REGIONS

REGIONS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *                                    REGIONS.H
00015 *
00016 \******************************************************************************/
00017
00018
00019
00020 /******************************************************************************\
00021 *                                SYMBOLIC CONSTANTS
00022 \******************************************************************************/
00023
00024 #define IDM_ERASE           101    // menuitems
00025 #define IDM_OFFSETRGN       102
00026 #define IDM_INVERTRGN       103
00027 #define IDM_FRAMERGN      104
00028 #define IDM_PTINRGN         105
00029 #define IDM_RECTINRGN       106
00030 #define IDM_SETRECTRGN      107
00031 #define IDM_GETRGNBOX       108
00032 #define IDM_ABOUT           109
00033
00034 #define IDM_ELLIPSE         201
00035 #define IDM_POLYPOLYGON     202
00036 #define IDM_RECT            203
00037
00038 #define IDM_AND             301
00039 #define IDM_COPY            302
00040 #define IDM_DIFF            303
00041 #define IDM_OR              304
00042 #define IDM_XOR             305
00043
00044 #define ELLIPTIC_RGN        0X0001 // flags used in RGNSTRUCT.flags
00045 #define POLYPOLYGON_RGN     0X0002
00046 #define RECT_RGN            0X0004
00047
00048 #define MAXRGNSTRUCTS       3      // max # of rgns existing at 1 time
00049
00050 #define POLYPOLYGONCOUNT    3      // # of polygons in call to
00051                                    //   CreatePolyPolygonRgn
00052
00053 #define TRECT_NEW           1      // TrackRect() actions
00054 #define TRECT_DELETE        2
00055 #define TRECT_PAINT         3
00056
00057 #define  RESET_ALL          0      // Reset() actions
00058 #define  ENABLE_OPTIONS     1
00059 #define  ENABLE_COMBINERGN  2
00060 #define  DISABLE_COMBINERGN 3
00061
00062
00063
00064 /******************************************************************************\
00065 *                                    TYPEDEFS
00066 \******************************************************************************/
00067
00068 typedef struct
00069 {
00070   HRGN hrgn;
00071   WORD type;
00072 } RGNSTRUCT;
00073
00074
00075 typedef struct
00076 {
00077     WORD   xOrigin, yOrigin;
00078     RECT   trackRect, clientRect;
00079     HDC    hdc;
00080 } TRACKRECTSTRUCT, *PTRACKRECTSTRUCT;
00081
00082
00083
00084 /******************************************************************************\
00085 *                                GLOBAL VARIABLES
00086 \******************************************************************************/
00087
00088 HANDLE    hInst;
00089 RGNSTRUCT rgnArray[MAXRGNSTRUCTS];
00090 int       currRgn;
00091 HMENU     hMenu;
00092
00093 RECT      ellipseRect = {40,  40, 180, 160};
00094 POINT     polyPolygonPoints[] = {{120, 20}, {200, 20}, {200, 80},
00095                                                        { 80,140},
00096                                  { 20, 20}, { 80, 20}, { 20, 80},
00097                                  {200,120}, {200,200}, {160,200}};
00098
00099 int       polyPolygonCounts[] = {4,3,3};
00100 RECT      rectRect    = {20, 100, 120, 200};
00101
00102
00103
00104 /******************************************************************************\
00105 *                               FUNCTION PROTOTYPES
00106 \******************************************************************************/
00107
00108 LRESULT CALLBACK MainWndProc   (HWND, UINT, WPARAM, LPARAM);
00109 BOOL CALLBACK AboutDlgProc  (HWND, UINT, WPARAM, LPARAM);
00110 BOOL CALLBACK RgnBoxDlgProc (HWND, UINT, WPARAM, LPARAM);
00111
00112 VOID             MyCreateRgn   (WORD);
00113 VOID             MyCombineRgn  (int);
00114 PTRACKRECTSTRUCT TrackRect     (PTRACKRECTSTRUCT, int, HWND, LONG);
00115 VOID             Reset         (WORD);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SHAREMEM/SHAREMEM.C Source File

  • SHAREMEM

SHAREMEM.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************************\
00013 *  PROGRAM: sharemem.c
00014 *
00015 *  PURPOSE:
00016 *
00017 *    To demonstrate the use of named shared memory between two independent
00018 *    processes.
00019 *
00020 *  GLOBAL VARIABLES:
00021 *
00022 *    HANDLE hInst:  - Instance handle.
00023 *
00024 *    HWND hWnd:     - Client window handle.
00025 *
00026 *    HWND hWndDlg:  - Handle to the dialog box which is imposed over the
00027 *                     parent window.
00028 *
00029 *    LONG *MapView: - Address of where the file will be mapped to.
00030 *
00031 *    HANDLE hMapObject:
00032 *                   - Handle to the file mapping object.
00033 *
00034 *
00035 *  FUNCTIONS:
00036 *
00037 *    WinMain()      - Initializes the window, and process the message loop.
00038 *    MainWndProc()  - To handle the messages to the main window.
00039 *
00040 *  COMMENTS:
00041 *
00042 *    Overview:
00043 *      This sample is accompanied by the Othrproc (Other Procedure)
00044 *      application.  Basically this code traps WM_MOUSEMOVE messages
00045 *      and writes them to the shared memory.  The Otherproc code
00046 *      reads the share memory and blts a small bitmap in the same
00047 *      relative coordinates.  The effect is to have the mouse move
00048 *      in one window, while the bitmap moves in the same relative
00049 *      position in the other window.  The mouse coordinates will appear
00050 *      in the edit fields of the dialog box at the top of the parent
00051 *      windows.
00052 *
00053 *    To Use:
00054 *      First start Sharemem, then start Otherproc.  The visual effect
00055 *      is better if the focus remains with Otherproc, while the mouse
00056 *      moves with the Sharemem window.
00057 *
00058 \*************************************************************************/
00059
00060 #include <windows.h>
00061 #include <stdlib.h>
00062 #include <stdio.h>
00063 #include "sharemem.h"
00064
00065 #define WERR(who,where)    {sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
00066                             sprintf(Buf2,"From within %s", where);\
00067                             MessageBox(hwnd, Buf, Buf2, MB_OK);}
00068
00069 CHAR Buf[80];
00070 CHAR Buf2[80];
00071
00072
00073 HANDLE hInst;
00074 HANDLE hMapObject;
00075 HWND   hWnd, hWndDlg;
00076 LONG   *MapView;
00077
00078
00079
00080 /*************************************************************************\
00081 *
00082 *  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00083 *
00084 *  PURPOSE:  Initializes the window, processes message loop.
00085 *
00086 *  COMMENTS: A fairly standard WinMain except that it creates a dialog
00087 *            box which is imposed on the upper part of the window.  This
00088 *            dialog box is used to show the mouse coordinates.
00089 *
00090 \*************************************************************************/
00091
00092 int PASCAL WinMain ( HINSTANCE hInstance,
00093                      HINSTANCE hPrevInstance,
00094                      LPSTR  lpCmdLine,
00095                      int    nCmdShow)
00096
00097
00098 {
00099
00100   MSG  msg;
00101   WNDCLASS wc;
00102   RECT rect;
00103   DWORD dwVersion = GetVersion();
00104
00105   UNREFERENCED_PARAMETER( lpCmdLine );
00106   UNREFERENCED_PARAMETER( hPrevInstance );
00107
00108 // check if running on Windows NT, if not, display notice and terminate
00109     if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00110     {
00111        MessageBoxA( NULL,
00112            "This sample application cannot run on Win32s.\n"
00113            "This application will now terminate.",
00114            "OthrProc",
00115            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00116        return( 1 );
00117     }
00118
00119   hInst = hInstance;
00120
00121   wc.style = 0;
00122   wc.lpfnWndProc = (WNDPROC)MainWndProc;
00123   wc.cbClsExtra = 0;
00124   wc.cbWndExtra = 0;
00125   wc.hInstance = hInstance;
00126   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00127   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
00128   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00129   wc.lpszMenuName = "";
00130   wc.lpszClassName = "ShareMemWClass";
00131
00132   RegisterClass(&wc);
00133
00134   hWnd = CreateWindow ("ShareMemWClass",
00135                        "Shared Memory Sample",
00136                        WS_OVERLAPPEDWINDOW,
00137                        CW_USEDEFAULT,
00138                        CW_USEDEFAULT,
00139                        CW_USEDEFAULT,
00140                        CW_USEDEFAULT,
00141                        NULL,
00142                        NULL,
00143                        hInstance,
00144                        NULL);
00145
00146   hWndDlg     = CreateDialog (hInst, "StatusDlg", hWnd, NULL);
00147
00148   GetClientRect (hWnd, &rect);
00149   SendMessage (hWnd, WM_SIZE, 0, (rect.right - rect.left));
00150   ShowWindow  (hWndDlg,  SW_SHOW);
00151   ShowWindow  (hWnd, nCmdShow);
00152
00153   while (GetMessage (&msg, NULL, 0, 0))
00154     if (!IsDialogMessage (hWndDlg, &msg))
00155       {
00156        DispatchMessage (&msg);   // Dispatch message to window.
00157       }
00158
00159   return (msg.wParam);           // Returns value from PostQuitMessage.
00160
00161 }
00162
00163 /*************************************************************************\
00164 *
00165 *  FUNCTION:  MainWndProc (HWND, UINT, WPARAM, LPARAM)
00166 *
00167 *  PURPOSE:   To process messages.  To create the shared memory.
00168 *
00169 *  MESSAGES:
00170 *
00171 *    WM_CREATE       - Create the shared memory by calling
00172 *                      CreateFileMapping().  This memory is the size
00173 *                      of a DWORD, all the size that is needed to pass
00174 *                      mouse coordinates.  If the CreateFileMapping()
00175 *                      call is successful, it then calls MapViewOfFile()
00176 *                      to get the address of the memory.
00177 *
00178 *    WM_MOUSEMOVE    - Traps the mouse move messages, and uses structured
00179 *                      exception handling to write the mouse coordinates
00180 *                      to the share memory.  It also sends the coordinates
00181 *                      to the edit fields of the dialog box.
00182 *
00183 *    WM_DESTROY      - Closes the memory handle, and destroys the window.
00184 *
00185 *    WM_SIZE         - Updates the size of the dialog box to maintain
00186 *                      its relative size to the client window.
00187 *
00188 *  CALLED BY:
00189 *
00190 *    WinMain();
00191 *
00192 \*************************************************************************/
00193
00194 LRESULT CALLBACK MainWndProc (HWND hwnd,
00195                               UINT message,
00196                               WPARAM wParam,
00197                               LPARAM lParam)
00198 {
00199
00200   switch (message)
00201       {
00202
00203         case WM_CREATE:
00204           hMapObject = CreateFileMapping ((HANDLE) 0xFFFFFFFF,
00205                                           NULL,
00206                                           PAGE_READWRITE,
00207                                           0,
00208                                           sizeof(DWORD),
00209                                           "shared_memory");
00210           if (!hMapObject)
00211             {
00212              WERR("CreateFileMapping","WM_CREATE");
00213             }
00214     MapView = (LONG *) MapViewOfFile (hMapObject,
00215                                            FILE_MAP_WRITE,
00216                                            0, 0, 0);
00217           if (!MapView)
00218             MessageBox (hwnd, "ERROR: MapViewOfFile was not successful.",
00219                         "From within WM_CREATE", MB_OK);
00220           return (0);
00221
00222
00223         case WM_SIZE :
00224           SetWindowPos (hWndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
00225           return (0);
00226
00227
00228         case WM_MOUSEMOVE:
00229
00230           __try
00231             {
00232              MapView[0] = lParam;
00233             }
00234             __except(EXCEPTION_EXECUTE_HANDLER)
00235             {
00236               MessageBox( hwnd, "Trapped an exception when writing to memory.",
00237                           "From within WM_MOUSEMOVE", MB_OK);
00238             }
00239
00240           SetDlgItemInt (hWndDlg, IDE_XCOORD, LOWORD(lParam), FALSE);
00241           SetDlgItemInt (hWndDlg, IDE_YCOORD, HIWORD(lParam), FALSE);
00242           return (0);
00243
00244         case WM_DESTROY :
00245             CloseHandle (hMapObject);
00246             PostQuitMessage (0);
00247             return (0);
00248
00249        }
00250     return DefWindowProc (hwnd, message, wParam, lParam);
00251 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DLL32.C Source File

  • INTEROP

DLL32.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *                                                                    *
00003 *  File:      dll32.c                                                *
00004 *                                                                    *
00005 *  Comments:  Win32 DLL                                              *
00006 *                                                                    *
00007 *  Functions: DllMain                                                *
00008 *             MyPrint                                                *
00009 *                                                                    *
00010 *                                                                    *
00011 \********************************************************************/
00012
00013 /*********************  Header Files  *********************/
00014
00015 #include <windows.h>
00016 #include <stdio.h>
00017
00018 /********************************************************************\
00019 * Function: BOOL WINAPI DllMain( HANDLE, DWORD, LPVOID )             *
00020 *                                                                    *
00021 *  Purpose: DLL entry point                                          *
00022 *                                                                    *
00023 * Comments: Standard template                                        *
00024 *                                                                    *
00025 *                                                                    *
00026 \********************************************************************/
00027
00028 BOOL WINAPI DllMain( HANDLE hDLL, DWORD dwReason, LPVOID lpReserved )
00029 {
00030    switch (dwReason)
00031    {
00032       case DLL_PROCESS_ATTACH:
00033          break;
00034
00035       case DLL_THREAD_ATTACH:
00036          break;
00037
00038       case DLL_THREAD_DETACH:
00039          break;
00040
00041       case DLL_PROCESS_DETACH:
00042          break;
00043    }
00044
00045    return TRUE;
00046 }
00047
00048 /********************************************************************\
00049 * Function: void WINAPI MyPrint( LPSTR, LPSTR, DWORD )               *
00050 *                                                                    *
00051 *  Purpose: Print the strings passed in as arguments                 *
00052 *                                                                    *
00053 * Comments: This simple routine is called by app16.exe in order to   *
00054 *           demonstrate calling a routine in a Win32 DLL from a      *
00055 *           Win16 application.                                       *
00056 *                                                                    *
00057 *                                                                    *
00058 \********************************************************************/
00059
00060 void WINAPI MyPrint( LPSTR lpString1, LPSTR lpString2, DWORD dwValue )
00061 {
00062    char buf[200];
00063
00064    wsprintf( buf, "Data received:\n\n%s\n%s\n%d\n", lpString1, lpString2,
00065                  dwValue );
00066    MessageBox( NULL, buf, "Dll32", MB_OK|MB_SETFOREGROUND );
00067 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/APP16.H Source File

  • INTEROP

APP16.H

Go to the documentation of this file.
00001
00002 #define IDM_THUNK                   101
00003 #define IDM_COPYDATA                102
00004 #define IDM_EXIT                    103
00005 #define IDM_ABOUT                   104
00006
00007 #define IDC_FIRSTNAME               202
00008 #define IDC_LASTNAME                203
00009 #define IDC_AGE                     204
00010 #define ID_OK                       208
00011 #define ID_CANCEL                   209
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/GUIGREP.C Source File

  • GUIGREP

GUIGREP.C

Go to the documentation of this file.
00001
00002 /*************************************************************************/
00003 /*                                                                       */
00004 /*           NT-based multithreaded file browser                         */
00005 /*           Ruediger R. Asche                                           */
00006 /*           Copyright (c) 1992-1996 Microsoft Corporation               */
00007 /*                                                                       */
00008 /*************************************************************************/
00009
00010 /*************************************************************************/
00011 /*                                                                       */
00012 /*           Description:                                                */
00013 /*           This file manager extension will perform the following:     */
00014 /*           - user clicks "search". This will open the target window    */
00015 /*             which has an edit control embedded in it and send a       */
00016 /*             WM_LAUNCH message to that window.                         */
00017 /*           - The window function then dispatches the "master thread"   */
00018 /*             which will, in turn, dispatch a new thread for every      */
00019 /*             file selected by the user. The master thread waits until  */
00020 /*             all file threads have finished, then send a WM_FREEAGAIN  */
00021 /*             message to the main window which will then display the    */
00022 /*             results and clean up.                                     */
00023 /*                                                                       */
00024 /*************************************************************************/
00025
00026
00027 /*************************************************************************/
00028 /*                                                                       */
00029 /*           Includes                                                    */
00030 /*                                                                       */
00031 /*************************************************************************/
00032
00033
00034 extern "C"
00035 {
00036 #include <windows.h>
00037 #include <string.h>
00038 #include <ctype.h>
00039 #include <stdlib.h>
00040 #include "guigrep.h"
00041 #include "wfext.h"
00042 }
00043
00044 /*************************************************************************/
00045 /*                                                                       */
00046 /*           Global variables                                            */
00047 /*                                                                       */
00048 /*************************************************************************/
00049
00050 memory *MasterBlock;
00051 growmemory *ResultBlock;
00052 HWND hWndGlobal;
00053 int iHitCount=0;
00054 char szGlobalSearchString[MAXLINELEN];
00055 unsigned int iGlobalSStLen;
00056 int iFinishedFiles;
00057 BOOL bCaseInsens=FALSE;
00058 HINSTANCE hOurselves;
00059 WNDPROC lpfnOldEditProc;
00060 char lpszCRLF[]="\r\n";
00061 int ilpszCRLF = strlen("\r\n");
00062 BOOL bObjectExists = FALSE;
00063
00064 /*************************************************************************/
00065 /*                                                                       */
00066 /*           Symbolic equals.                                            */
00067 /*                                                                       */
00068 /*************************************************************************/
00069
00070 #define WNDCLASSNAME "SearchWndClass"
00071
00072 /*************************************************************************/
00073 /*                                                                       */
00074 /*           Forward function declarations                               */
00075 /*                                                                       */
00076 /*************************************************************************/
00077
00078
00079 BOOL APIENTRY About(
00080   HWND hDlg,
00081   UINT message,
00082   UINT wParam,
00083   LONG lParam);
00084
00085
00086
00087 long Poll_On_Threads(LONG lParam);
00088
00089
00090 /*************************************************************************/
00091 /*                                                                       */
00092 /* A generic window class that carries an edit child in its entire       */
00093 /* client area wherever it goes.                                                                                 */
00094 /*                                                                       */
00095 /*************************************************************************/
00096
00097
00098 LONG APIENTRY ColorWndProc(
00099   HWND hWnd,
00100   UINT message,
00101   UINT wParam,
00102   LONG lParam)
00103 {
00104     static char szBuf[13];
00105     static char szPathName[MAX_PATH];
00106
00107     RECT   rcClient;
00108   static HWND hWndHitBox,hWndFileMan;
00109   HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
00110     switch (message) {
00111   case WM_CREATE:
00112       AppendMenu(GetSystemMenu(hWnd,FALSE),MF_STRING, IDM_ABOUT, "About...");
00113       hWndHitBox = CreateWindow("EDIT","",WS_CHILD | WS_VISIBLE | ES_WANTRETURN | ES_AUTOHSCROLL |
00114                  DS_LOCALEDIT|ES_MULTILINE | WS_BORDER|WS_VSCROLL|WS_HSCROLL,
00115              0,0,1,1,hWnd, NULL, hInst,
00116              NULL);
00117     if (!hWndHitBox)
00118        {MessageBox(hWnd,"Unable to create Child Window!","Browse Extension",MB_OK);
00119         return(-1);
00120        };
00121
00122       CloseHandle((HANDLE)SendMessage(hWndHitBox,EM_GETHANDLE,0,0));
00123     ShowWindow(hWndHitBox,SW_SHOWNORMAL);
00124       break;
00125   case WM_SIZE:
00126       GetClientRect(hWnd,&rcClient);
00127       MoveWindow(hWndHitBox,rcClient.left,rcClient.top,
00128            rcClient.right, rcClient.bottom, TRUE);
00129       break;
00130   case WM_LAUNCH:
00131     hWndFileMan = (HWND)lParam;
00132        { static THREADPBLOCK tpbParms;
00133          int iPollThreadID;
00134          tpbParms.hWndGlobal = hWnd;
00135          tpbParms.hWndFileBox = hWndFileMan;
00136          SendMessage(hWndHitBox,LB_RESETCONTENT,0,0);
00137          ResultBlock = new growmemory(4*4096,4096);
00138          bObjectExists=TRUE;
00139          HANDLE hNewThread=CreateThread(NULL,0,
00140            (LPTHREAD_START_ROUTINE)Poll_On_Threads,(LPVOID)&tpbParms,0,(LPDWORD)&iPollThreadID);
00141      };
00142        break;
00143   case WM_ADDITEM:
00144     { char szBuf[40];
00145       wsprintf(szBuf,"Finished %d File(s)",(int)lParam);
00146      SetWindowText(hWnd,szBuf);
00147     };
00148     break;
00149     case WM_FREEAGAIN:
00150     SendMessage(hWndHitBox,EM_SETHANDLE,(WPARAM)ResultBlock->GetHandle(),0);
00151     InvalidateRect(hWndHitBox,NULL,FALSE);
00152     break;
00153
00154   case WM_SYSCOMMAND:
00155     if (wParam == IDM_ABOUT)
00156        DialogBox(hOurselves,
00157            "AboutBox",
00158            hWnd,
00159            (DLGPROC)About);
00160        else
00161       return (DefWindowProc(hWnd, message, wParam, lParam));
00162     break;
00163
00164   case WM_DESTROY:
00165    bObjectExists=FALSE;
00166    delete(ResultBlock);
00167    break;
00168   default:
00169       return (DefWindowProc(hWnd, message, wParam, lParam));
00170     }
00171     return (NULL);
00172 }
00173
00174
00175 /*************************************************************************/
00176 /*                                                                       */
00177 /*           The inevitable about box...                                 */
00178 /*                                                                       */
00179 /*************************************************************************/
00180
00181
00182 BOOL APIENTRY About(
00183   HWND hDlg,
00184   UINT message,
00185   WPARAM wParam,
00186   LPARAM lParam)
00187 {
00188     switch (message) {
00189   case WM_INITDIALOG:
00190       return (TRUE);
00191
00192   case WM_COMMAND:
00193       if (LOWORD(wParam) == IDOK
00194     || LOWORD(wParam) == IDCANCEL) {
00195     EndDialog(hDlg, TRUE);
00196     return (TRUE);
00197       }
00198       break;
00199     }
00200     return (FALSE);
00201   UNREFERENCED_PARAMETER(lParam);
00202 }
00203
00204 /*************************************************************************/
00205 /*                                                                       */
00206 /*           The DLL Entry and exit dispatcher.                          */
00207 /*                                                                       */
00208 /*************************************************************************/
00209
00210
00211
00212 extern "C"
00213 {
00214 BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
00215 {
00216   switch (dwReason)
00217   {
00218     case DLL_PROCESS_ATTACH:
00219     {
00220     WNDCLASS  wc;
00221     hOurselves=hDLL;
00222
00223     wc.style = NULL;
00224     wc.lpfnWndProc = (WNDPROC)ColorWndProc;
00225     wc.cbClsExtra = 0;
00226     wc.cbWndExtra = 0;
00227     wc.hInstance = (HINSTANCE)GetCurrentProcess();
00228     wc.hIcon = LoadIcon(hDLL, "GrepIcon");
00229     wc.hCursor = LoadCursor(NULL,IDC_ARROW);
00230     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
00231     wc.lpszMenuName =  NULL;
00232     wc.lpszClassName = WNDCLASSNAME;
00233
00234     if (!RegisterClass(&wc))
00235     {
00236     MessageBox(GetFocus(),"Unable to create class",
00237      "Browse extension",MB_OK);
00238     return(NULL);
00239     }
00240     };
00241    };
00242    return( TRUE );
00243 }
00244 }
00245
00246 /*************************************************************************/
00247 /*                                                                       */
00248 /*           Dialog box function for the "Select string" dialog          */
00249 /*                                                                       */
00250 /*************************************************************************/
00251
00252
00253
00254 BOOL APIENTRY StringProc(
00255   HWND hDlg,
00256   UINT message,
00257   WPARAM wParam,
00258   LPARAM lParam)
00259 {   HWND hEditControl;
00260     switch (message)
00261       {
00262   case WM_INITDIALOG:
00263       hEditControl = GetDlgItem(hDlg, IDM_STRINGEDIT);
00264       SetWindowText(hEditControl,szGlobalSearchString);
00265     SendMessage(GetDlgItem(hDlg,IDM_CASESENS),BM_SETCHECK,bCaseInsens,0);
00266       return (TRUE);
00267
00268   case WM_COMMAND:
00269     switch (LOWORD(wParam))
00270      {
00271      case IDM_CANCEL:
00272        EndDialog(hDlg,FALSE);
00273        return(TRUE);
00274        break;
00275        case IDM_TERMBOX:
00276       {int iLoopVar, iLen;
00277          bCaseInsens = SendMessage(GetDlgItem(hDlg,IDM_CASESENS),BM_GETCHECK,0,0);
00278          hEditControl = GetDlgItem(hDlg,IDM_STRINGEDIT);
00279          GetWindowText(hEditControl,szGlobalSearchString,MAXLINELEN);
00280        if (bCaseInsens)
00281         { iLen = strlen(szGlobalSearchString);
00282         for (iLoopVar = 0; iLoopVar < iLen;iLoopVar++)
00283        if (IsCharUpper(szGlobalSearchString[iLoopVar]))
00284        szGlobalSearchString[iLoopVar] = (char)_tolower((int)szGlobalSearchString[iLoopVar]);
00285       };
00286        EndDialog(hDlg, TRUE);
00287       }
00288          break;
00289
00290       }
00291       break;
00292     }
00293     return (FALSE);
00294   UNREFERENCED_PARAMETER(lParam);
00295 }
00296
00297
00298 long TraverseFileCaseInsens(HANDLE hFile, LPSTR lpFilNam, LPSTR lpFileView)
00299 {
00300   unsigned int iGlobalSearchString, iCurrentBuffPt, iPrefixLength;
00301   BOOL bMatch;
00302   LPSTR lpLineBuff;
00303   unsigned int iLineCt = 0;
00304   DWORD dwFileSize, dwCurrentFilePt;
00305
00306   dwFileSize = GetFileSize(hFile,NULL);
00307   lpLineBuff = MasterBlock->Alloc(MAXLINELEN);
00308   if (!lpLineBuff)
00309    {
00310    MessageBox(GetFocus(),lpFilNam,"Out of memory processing:",MB_OK);
00311    return (-1);
00312    };
00313 /**************************************************************************/
00314 /*    Initialize variables:                                               */
00315 /*    lpLineBuff contains the buffer in which we store the whole line.    */
00316 /*    If the line doesn't match, we "recycle" the buffer by using it      */
00317 /*    for the next line; if it does, we send it off.                      */
00318 /*    iCurrentBuff is the length of the line we currently work on,        */
00319 /*    and iGlobalSearchString describes how far in the global search      */
00320 /*    string we have progreesed so far matching.                          */
00321 /**************************************************************************/
00322
00323   strcpy(lpLineBuff,lpFilNam);
00324   strcat(lpLineBuff," <    >: ");
00325   iPrefixLength = strlen(lpLineBuff);
00326   iCurrentBuffPt = iPrefixLength-1;
00327   iGlobalSearchString = 0;
00328   bMatch = FALSE;
00329 /**************************************************************************/
00330 /*    Now go through the mapping character by character                   */
00331 /**************************************************************************/
00332
00333   for (dwCurrentFilePt=0;
00334        dwCurrentFilePt<dwFileSize;
00335        dwCurrentFilePt++)
00336
00337     { if (iCurrentBuffPt >= MAXLINELEN)
00338     {MessageBox(GetFocus(),"File not readable!",lpFilNam,MB_OK);
00339      return(-1);
00340     };
00341
00342       iCurrentBuffPt++;
00343       lpLineBuff[iCurrentBuffPt]= lpFileView[dwCurrentFilePt];
00344      if (lpLineBuff[iCurrentBuffPt] == '\n')
00345   {
00346
00347    iLineCt++;
00348        if (bMatch)
00349          {
00350 /**************************************************************************/
00351 /*    A match has occurred!                                               */
00352 /*    At this point, lpLineBuff points to the string that contains the    */
00353 /*    matching line; iCurrentBuffPt its length.                           */
00354 /**************************************************************************/
00355
00356     OemToChar(lpLineBuff,lpLineBuff);
00357     wsprintf(&lpLineBuff[strlen(lpFilNam)+2],"%4d",iLineCt);
00358     lpLineBuff[strlen(lpFilNam)+6] = '>';
00359     iHitCount++;
00360         ResultBlock->add(lpLineBuff,iCurrentBuffPt-1);
00361     strcpy(lpLineBuff, lpFilNam);
00362     wsprintf(&lpLineBuff[strlen(lpFilNam)]," <    >: ");
00363
00364          };
00365 /**************************************************************************/
00366 /*    The FOR-logic will increment the pointer,                           */
00367 /*    so we reduce it by one because we use it in the NEXT iteration.     */
00368 /**************************************************************************/
00369
00370   iCurrentBuffPt = iPrefixLength -1;
00371   iGlobalSearchString = 0;
00372   bMatch = FALSE;
00373   }
00374      else
00375
00376   { if (iGlobalSearchString < iGlobalSStLen)
00377       if ( /* This is the only difference to case-sensitive... */
00378       (IsCharUpper(lpLineBuff[iCurrentBuffPt]) ? (char)_tolower(lpLineBuff[iCurrentBuffPt])
00379         : lpLineBuff[iCurrentBuffPt]) == szGlobalSearchString[iGlobalSearchString])
00380          { iGlobalSearchString++;
00381      bMatch = TRUE;
00382          }
00383       else
00384          { bMatch = FALSE;
00385      iGlobalSearchString = 0;
00386
00387          };
00388
00389    };
00390
00391    };
00392 return(TRUE);
00393 }
00394
00395 /**************************************************************************/
00396 /*    The case sensitive traversal function is basically the same         */
00397 /*    as the case-insensitive one, just one line difference.              */
00398 /*    The reason why we separate this is that at runtime it is much more  */
00399 /*    efficient not to have to test for case-insensitivity on each and    */
00400 /*    every character we test...                                          */
00401 /**************************************************************************/
00402
00403
00404 long TraverseFileCaseSens(HANDLE hFile, LPSTR lpFilNam, LPSTR lpFileView)
00405 {
00406   unsigned int iGlobalSearchString, iCurrentBuffPt, iPrefixLength;
00407   BOOL bMatch;
00408   LPSTR lpLineBuff;
00409   unsigned int iLineCt = 0;
00410   DWORD dwFileSize, dwCurrentFilePt;
00411
00412   dwFileSize = GetFileSize(hFile,NULL);
00413   lpLineBuff = MasterBlock->Alloc(MAXLINELEN);
00414   if (!lpLineBuff)
00415    {
00416    MessageBox(GetFocus(),lpFilNam,"Out of memory processing:",MB_OK);
00417    return (-1);
00418    };
00419
00420   strcpy(lpLineBuff,lpFilNam);
00421   strcat(lpLineBuff," <    >: ");
00422   iPrefixLength = strlen(lpLineBuff);
00423   iCurrentBuffPt = iPrefixLength-1;
00424   iGlobalSearchString = 0;
00425   bMatch = FALSE;
00426   for (dwCurrentFilePt=0;
00427        dwCurrentFilePt<dwFileSize;
00428        dwCurrentFilePt++)
00429
00430     { if (iCurrentBuffPt >= MAXLINELEN)
00431     {MessageBox(GetFocus(),"File not readable!",lpFilNam,MB_OK);
00432      return(-1);
00433     };
00434
00435       iCurrentBuffPt++;
00436       lpLineBuff[iCurrentBuffPt]= lpFileView[dwCurrentFilePt];
00437      if (lpLineBuff[iCurrentBuffPt] == '\n')
00438   {
00439
00440    iLineCt++;
00441        if (bMatch)
00442          {
00443     OemToChar(lpLineBuff,lpLineBuff);
00444     wsprintf(&lpLineBuff[strlen(lpFilNam)+2],"%4d",iLineCt);
00445     lpLineBuff[strlen(lpFilNam)+6] = '>';
00446     iHitCount++;
00447     ResultBlock->add(lpLineBuff,iCurrentBuffPt-1);
00448     strcpy(lpLineBuff, lpFilNam);
00449     wsprintf(&lpLineBuff[strlen(lpFilNam)]," <    >: ");
00450
00451          };
00452   iCurrentBuffPt = iPrefixLength -1;
00453   iGlobalSearchString = 0;
00454   bMatch = FALSE;
00455   }
00456      else
00457
00458   { if (iGlobalSearchString < iGlobalSStLen)
00459       if (lpLineBuff[iCurrentBuffPt] == szGlobalSearchString[iGlobalSearchString])
00460          { iGlobalSearchString++;
00461      bMatch = TRUE;
00462          }
00463       else
00464          { bMatch = FALSE;
00465      iGlobalSearchString = 0;
00466
00467          };
00468
00469    };
00470
00471    };
00472
00473 return(TRUE);
00474 }
00475
00476
00477
00478
00479 long ProcessFileCommonCode (LPTHREADPBLOCK tpArgs)
00480 { FMS_GETFILESEL gfsSelection;
00481   LPSTR lpFilNam;
00482   HANDLE hFile, hMappedFile;
00483   LPSTR lpFileView;
00484   unsigned int iLineCt = 0;
00485 /**************************************************************************/
00486 /*    Set up file mapping etc.                                            */
00487 /**************************************************************************/
00488   SendMessage(tpArgs->hWndFileBox,FM_GETFILESEL,tpArgs->iLoop,(LPARAM)&gfsSelection);
00489   lpFilNam = MasterBlock->Alloc(1+strlen(gfsSelection.szName));
00490     strcpy(lpFilNam,gfsSelection.szName);
00491
00492   if ((hFile = CreateFile(lpFilNam, GENERIC_READ, FILE_SHARE_READ, NULL,
00493         OPEN_ALWAYS, FILE_ATTRIBUTE_READONLY, NULL))
00494       == INVALID_HANDLE_VALUE)
00495        return(FALSE);
00496   if (!(hMappedFile = CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,0)))
00497        {MessageBox(GetFocus(),"Could not open file mapping!",lpFilNam,MB_OK);
00498   return(FALSE);
00499        };
00500   if (!(lpFileView = (LPSTR)MapViewOfFile(hMappedFile,FILE_MAP_READ,0,0,0)))
00501        {MessageBox(GetFocus(),"Could not map file view",lpFilNam,MB_OK);
00502   return(FALSE);
00503        };
00504 /**************************************************************************/
00505 /*    Now traverse file                                                   */
00506 /**************************************************************************/
00507   if (bCaseInsens)
00508     TraverseFileCaseInsens(hFile,lpFilNam,lpFileView);
00509   else
00510     TraverseFileCaseSens(hFile,lpFilNam,lpFileView);
00511
00512 /**************************************************************************/
00513 /*    Clean up.                                                   */
00514 /**************************************************************************/
00515
00516   if (!UnmapViewOfFile(lpFileView))
00517    MessageBox(GetFocus(),"UnmapViewOfFile Failure",lpFilNam,MB_OK);
00518   if (!CloseHandle(hMappedFile))
00519    MessageBox(GetFocus(),"CloseHandle Failure...",lpFilNam,MB_OK);
00520   if (!CloseHandle(hFile))
00521    MessageBox(GetFocus(),"CloseHandle Failure...",lpFilNam,MB_OK);
00522
00523 iFinishedFiles++;
00524 SendMessage(hWndGlobal,WM_ADDITEM,(WPARAM)iHitCount,iFinishedFiles);
00525   return(1);
00526
00527 }
00528
00529
00530
00531 /*************************************************************************/
00532 /*                                                                       */
00533 /*          This is the "master thread." Its only purpose is to          */
00534 /*          dispatch one thread for each file selected, then wait for    */
00535 /*          completition of all threads, and return to the main window.  */
00536 /*          This has been made a separate thread due to possible         */
00537 /*          deadlock conditions that might occurr if it was in the       */
00538 /*          main window function.                                        */
00539 /*                                                                       */
00540 /*          Since there is no system-provided way to limit the number    */
00541 /*          of threads AND it doesn't make sense to have zillions        */
00542 /*          of threads in the system, there is a mechanism that          */
00543 /*          limits the number of threads to a certain limit (currently   */
00544 /*          30). Would make sense to devise some kind of a fancy         */
00545 /*          algorithm to compute the number of threads dynamically.      */
00546 /*                                                                       */
00547 /*************************************************************************/
00548
00549
00550
00551 long Poll_On_Threads(LONG lParam)
00552 { int iLoop, iEndLoop,iThread,iArrayIndex;
00553   char tempFilBuf[80];
00554   static HANDLE aThreads[MAX_CONCURRENT_THREADS];
00555   HWND hWndFileBox;
00556   LPTHREADPBLOCK lpTB = (LPTHREADPBLOCK)lParam;
00557   iHitCount = 0;
00558   iFinishedFiles = 0;
00559   iGlobalSStLen = strlen(szGlobalSearchString);
00560   hWndFileBox = lpTB->hWndFileBox;
00561   hWndGlobal =  lpTB->hWndGlobal;
00562   MasterBlock = new memory(150000);
00563   iEndLoop = SendMessage(hWndFileBox,FM_GETSELCOUNT,0,0);
00564   if (iEndLoop == 0)
00565    { MessageBox(hWndFileBox,"No files selected","Browser extension",MB_OK);
00566      return(0);
00567    };
00568   for (iLoop = 0; iLoop < iEndLoop; iLoop++)
00569   {HANDLE hNewThread;
00570
00571     if (iLoop < MAX_CONCURRENT_THREADS)
00572              iArrayIndex = iLoop;
00573     else
00574       {
00575        iArrayIndex = WaitForMultipleObjects(
00576            MAX_CONCURRENT_THREADS,aThreads,FALSE,INFINITE);
00577        if (iArrayIndex == -1)
00578         {MessageBeep(0);
00579             return(-1);
00580          };
00581
00582        CloseHandle(aThreads[iArrayIndex]);
00583       };
00584     lpTB = (LPTHREADPBLOCK)MasterBlock->Alloc(sizeof(THREADPBLOCK));
00585     lpTB->hWndFileBox=hWndFileBox;
00586   lpTB->iLoop = iLoop;
00587       hNewThread = CreateThread(NULL,0,
00588     (LPTHREAD_START_ROUTINE) ProcessFileCommonCode,
00589          (LPVOID)lpTB,0,(LPDWORD)&iThread);
00590   if (!hNewThread)
00591      MessageBox(GetFocus(),"Failed","CreateThread",MB_OK);
00592     aThreads[iArrayIndex] = hNewThread;
00593
00594
00595    };
00596 /* We are now processing the last few threads. Clean up. */
00597   iEndLoop = min(iEndLoop,MAX_CONCURRENT_THREADS);
00598   WaitForMultipleObjects(iEndLoop, aThreads,TRUE,INFINITE);
00599   for (iLoop = 0; iLoop < iEndLoop ; iLoop++)
00600     if (!CloseHandle(aThreads[iLoop]))
00601       MessageBox(GetFocus(),"Can't delete thread!","",MB_OK);
00602   wsprintf(tempFilBuf,"Total Hits: %d",iHitCount);
00603   SetWindowText(hWndGlobal,tempFilBuf);
00604   delete (MasterBlock);
00605   SendMessage(hWndGlobal,WM_FREEAGAIN,0,0);
00606     return(0);
00607 }
00608
00609 /********************************************************************/
00610 /* Following is the relevant stuff for the file manager extensions. */
00611 /********************************************************************/
00612
00613 LONG WINAPI FMExtensionProc(HWND hWndFileMan, WORD wMsg, LONG lParam)
00614 {
00615   static HMENU hSubMenu;
00616   static UINT wDelta;
00617   static HWND hWnd;
00618  switch (wMsg)
00619  {
00620
00621 /* this message is sent to the extension proc to update its toolbar to
00622    add custom buttons as accelarators for the extension menu. */
00623
00624   case FMEVENT_TOOLBARLOAD:
00625    {
00626      static EXT_BUTTON ExtButtons[1] =
00627      { { IDM_STARTGREP-100, 0 , 0} };   /* This must correspond to the wMsg parameter passed to the extension proc */
00628
00629 #define lpTB ((LPFMS_TOOLBARLOAD) lParam)
00630
00631   lpTB->dwSize = sizeof(FMS_TOOLBARLOAD);
00632   lpTB->lpButtons = (LPEXT_BUTTON) &ExtButtons;
00633   lpTB->cButtons = 1;
00634   lpTB->cBitmaps = 1;
00635   lpTB->idBitmap = IDM_STARTGREP;       /* Must correspond to the bitmap identifier */
00636   return(TRUE);
00637    };
00638
00639 /* this message is sent to the extension proc to associate a help string with
00640    a menu item. */
00641
00642   case FMEVENT_HELPSTRING:
00643    strcpy(((LPFMS_HELPSTRING)lParam)->szHelp,"Search for a string in multiple files");
00644    return (TRUE);
00645
00646   case FMEVENT_LOAD:
00647    if (!hOurselves)
00648     return(NULL);
00649
00650      hSubMenu = LoadMenu(hOurselves,"FileManMenu");
00651      wDelta = ((LPFMS_LOAD)lParam)->wMenuDelta;
00652      ((LPFMS_LOAD)lParam)->dwSize= sizeof(FMS_LOAD);
00653      strcpy(((LPFMS_LOAD)lParam)->szMenuName,"S&earch");
00654      ((LPFMS_LOAD)lParam)->hMenu = hSubMenu;
00655
00656
00657      return (LONG) hSubMenu;
00658   default:
00659        switch (wMsg+100)
00660        {
00661         case IDM_DEFGREP:
00662        DialogBox(hOurselves,
00663            "StringDialog",
00664            hWndFileMan,
00665            (DLGPROC)StringProc);
00666        break;
00667
00668     case IDM_STARTGREP:
00669     if (strlen(szGlobalSearchString) == 0)
00670        if (!DialogBox(hOurselves,
00671            "StringDialog",
00672            hWndFileMan,
00673            (DLGPROC)StringProc))
00674         break;
00675   if (IsWindow(hWndGlobal))
00676    {MessageBox(GetFocus(),"No more than one window supported","Close hit window",MB_OK);
00677     break;
00678    };
00679     hWnd = CreateWindow(
00680   WNDCLASSNAME,
00681   "Windows NT File Search Extension",
00682   WS_OVERLAPPEDWINDOW,
00683   CW_USEDEFAULT,
00684   CW_USEDEFAULT,
00685   CW_USEDEFAULT,
00686   CW_USEDEFAULT,
00687   NULL,
00688   NULL,
00689   (HINSTANCE)GetCurrentProcess(),
00690   NULL
00691     );
00692   SendMessage(hWnd,WM_LAUNCH,0,(LONG)hWndFileMan);
00693     ShowWindow(hWnd, SW_SHOWNORMAL);
00694     UpdateWindow(hWnd);
00695     break;
00696     default:
00697     break;
00698     };
00699   return(0);
00700  };
00701 }
00702
00703
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/DATABASE.H Source File

  • READWRIT

DATABASE.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 BOOL WINAPI ReadDataBase  ( PSZ, PSZ ) ;
00013 BOOL WINAPI WriteDataBase ( PSZ, PSZ ) ;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NTSD/MDITYPES.H Source File

  • NTSD

MDITYPES.H

Go to the documentation of this file.
00001 /******************************Module*Header*******************************\
00002 * Module Name: mditypes.h
00003 *
00004 * Contains typedefs for the MDI project
00005 *
00006 * Created: 24-Feb-1992 21:04:30
00007 * Author: Petrus Wong
00008 *
00009 * Copyright (c) 1990-1996 Microsoft Corporation
00010 *
00011 * (General description of its use)
00012 *
00013 * Dependencies:
00014 *
00015 *   (#defines)
00016 *   (#includes)
00017 *
00018 \**************************************************************************/
00019 #include "mdi.h"
00020
00021 //
00022 // Instance data for each MDI child window
00023 //
00024 typedef struct _PerWndInfo {
00025     HWND    hParent;
00026     HWND    hTextWnd;
00027     RECT    rcClient;
00028     char    CaptionBarText[SIZEOFCAPTIONTEXT];
00029 } INFO, *PINFO;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: THREADS/THREADS.H Source File

  • THREADS

THREADS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDM_SUSPENDGREEN     501
00013 #define IDM_SUSPENDRED       502
00014 #define IDM_RESUMEGREEN      601
00015 #define IDM_RESUMERED        602
00016
00017 #define IDM_GIDLE            700
00018 #define IDM_GLOW             701
00019 #define IDM_GBNORM           702
00020 #define IDM_GNORM            703
00021 #define IDM_GANORM           704
00022 #define IDM_GHIGH            705
00023 #define IDM_GTC              706
00024
00025 #define IDM_RIDLE            750
00026 #define IDM_RLOW             751
00027 #define IDM_RBNORM           752
00028 #define IDM_RNORM            753
00029 #define IDM_RANORM           754
00030 #define IDM_RHIGH            755
00031 #define IDM_RTC              756
00032
00033 #define GREEN    0x00007F00
00034 #define RED      0x0000007F
00035
00036 LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
00037 VOID ThreadProc (LPVOID *);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/BITMAP.H Source File

  • STREBLT

BITMAP.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* bitmap.h  */
00013
00014 /* function prototypes */
00015 VOID DrawBitmap (HDC, HBITMAP);
00016 HBITMAP GetBitmap (HDC, HANDLE, BOOL);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/TRACK.H Source File

  • STREBLT

TRACK.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* track.h - header file for doTrackObject support */
00013
00014
00015 /* special messages for doTrackobject(). */
00016 #define TROB_NEW         WM_USER+1
00017 #define TROB_DELETE      WM_USER+2
00018 #define TROB_PAINT       WM_USER+3
00019 #define TROB_HITTEST     WM_USER+5
00020
00021
00022 /* Different "Track modes." */
00023 #define TMNONE    0x0000
00024 #define TMMOVE    0x0001
00025 #define TMSIZEX   0x0002
00026 #define TMSIZEY   0x0004
00027 #define TMSIZEXY  0x0006
00028 #define TMSHEARX  0x0010
00029 #define TMSHEARY  0x0020
00030 #define TMROTATE  0x0008
00031 #define TMALL     0x00ff
00032
00033
00034
00035 /* structure for the track object.  */
00036 typedef struct tagTrackObject{
00037     RECT   rect;
00038     XFORM  xfmChange;   /* World coordinate transform      */
00039     XFORM  xfmDown;     /* transform when the mouse down happens. */
00040     HDC    hdc;
00041     int    Mode;        /* TMROTATE, TMSIZEXY, TMMOVE, ... */
00042     int    allowedModes;
00043     RECT   rectClip;
00044     struct tagTrackObject* Next;
00045 } TrackObject, *PTrackObject;
00046
00047
00048 /* function prototypes. */
00049 PTrackObject doTrackObject(PTrackObject, int, HWND, LONG);
00050 VOID MouseMove(PTrackObject, int, HWND, LONG);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/THE_DLL.H Source File

  • RESDLL

THE_DLL.H

Go to the documentation of this file.
00001 /************************************************************************\
00002 *
00003 *                               THE_DLL.H
00004 *
00005 \************************************************************************/
00006
00007
00008
00009 /************************************************************************\
00010 *                          SYMBOLIC CONSTANTS
00011 \************************************************************************/
00012
00013 #define DLLBITMAP_WIDTH  128 /* width & height of the_dll.bmp  */
00014 #define DLLBITMAP_HEIGHT 64  /* these are referenced in main.c */
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SUBCLASS/SUBCLASS.C Source File

  • SUBCLASS

SUBCLASS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  subclass.c -- Demonstrate subclassing of standard controls.
00014 *
00015 * This sample allows the user to create an arbitrary number of child
00016 *  controls on the main window.  These controls are subclassed, and the
00017 *  subclass procedure provides the user a way to move and size the controls.
00018 *  A menu item switches in and out of "Test Mode."  When this is on, the
00019 *  subclass procedure passes all messages through to the old procedure, and
00020 *  the controls act just like normal.
00021 *
00022 * There is a single subclass window procedure for a variety of different
00023 *  control classes.  This is accomplished by storing the old window procedure
00024 *  for the control in a structure pointed at by the 4 "user extra bytes."
00025 *  I.e. the GWL_USERDATA contains a pointer to the following structure:
00026 *
00027 *       typedef struct tagExtraBytes{
00028 *           WNDPROC    pfnOldProc;
00029 *           RECT       rect;
00030 *           int        Action;
00031 *       } ExtraBytes, *PExtraBytes;
00032 *
00033 *  and the old window procedure is stored in the pfnOldProc field.
00034 *  The rect field is used for drawing the temporary rectangle while the
00035 *  user is dragging, and the Action field holds the type of action that
00036 *  is allowed (move, size, ...).  Notice that the rect rectangle is in
00037 *  the coordinate space of the parent window.
00038 *
00039 * Warning:  buttons, edit fields, and list boxes are easy.  It is difficult
00040 *  to extend this to static controls because they do not normally receive
00041 *  input and thus do not get mousedown messages.  It is difficult to extend
00042 *  this to comboboxes because of the compound structure and the fact that
00043 *  the comboboxes children controls (edit field & list box) get the mouse
00044 *  messages first.
00045 *
00046 \**************************************************************************/
00047
00048 #include <windows.h>
00049 #include "subclass.h"
00050
00051
00052
00053 /**************************************************************************\
00054 *
00055 *  function:  WinMain()
00056 *
00057 *  input parameters:  c.f. generic sample
00058 *
00059 \**************************************************************************/
00060
00061 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00062                    LPSTR lpCmdLine, int nCmdShow)
00063 {
00064   MSG   msg;
00065
00066   UNREFERENCED_PARAMETER( lpCmdLine );
00067
00068
00069   /* Check for previous instance.  If none, then register class. */
00070   if (!hPrevInstance) {
00071       WNDCLASS  wc;
00072
00073       wc.style = 0;
00074       wc.lpfnWndProc = (WNDPROC)MainWndProc;
00075       wc.cbClsExtra = 0;
00076       wc.cbWndExtra = 0;
00077       wc.hInstance = hInstance;
00078       wc.hIcon = LoadIcon(hInstance, "subclassIcon");
00079       wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00080       wc.hbrBackground = GetStockObject(GRAY_BRUSH);
00081       wc.lpszMenuName =  "scMenu";
00082       wc.lpszClassName = "scClass";
00083
00084       if (!RegisterClass(&wc)) return (FALSE);
00085   }  /* class registered o.k. */
00086
00087
00088   /* Create the main window.  Return false if CreateWindow() fails */
00089   hInst = hInstance;
00090
00091   hwndMain = CreateWindow(
00092       "scClass",
00093       "Subclass Window Sample",
00094       WS_OVERLAPPEDWINDOW,
00095       CW_USEDEFAULT,
00096       CW_USEDEFAULT,
00097       CW_USEDEFAULT,
00098       CW_USEDEFAULT,
00099       NULL,
00100       NULL,
00101       hInstance,
00102       NULL);
00103
00104   if (!hwndMain) return (FALSE);
00105
00106
00107   ShowWindow(hwndMain, nCmdShow);
00108
00109   /* Loop getting messages and dispatching them. */
00110   while (GetMessage(&msg,NULL, 0,0)) {
00111     TranslateMessage(&msg);
00112     DispatchMessage(&msg);
00113   }
00114
00115   /* Return the value from PostQuitMessage */
00116   return (msg.wParam);
00117 }
00118
00119
00120 /**************************************************************************\
00121 *
00122 *  function:  MainWndProc()
00123 *
00124 *  input parameters:  normal window procedure parameters.
00125 *  global variables:
00126 *   hInst     - global instance handle.  used in create window.
00127 *   fTestMode - global boolean, set by menu, if true ignore subclass actions.
00128 *
00129 * The main window actually does very little.  Just respond to menu commands.
00130 \**************************************************************************/
00131
00132 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00133 {
00134    HWND hwndChild;
00135
00136    switch (message) {
00137
00138     /**********************************************************************\
00139     *  WM_DESTROY
00140     *
00141     * Post quit message.
00142     \**********************************************************************/
00143     case WM_DESTROY:
00144         PostQuitMessage(0);
00145     break;
00146
00147
00148     /**********************************************************************\
00149     *  WM_COMMAND
00150     *
00151     * Switch on the different menu items.  Create a different class of
00152     *  window for most of them.  Switch on and off the fTestMode global
00153     *  variable on IDM_TEST.
00154     \**********************************************************************/
00155
00156     case WM_COMMAND: {
00157       switch (LOWORD (wParam)) {
00158         case IDM_BUTTON:
00159           hwndChild = CreateWindow(
00160             "BUTTON", "button",
00161             WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
00162             50,10, 60, 32,
00163             hwnd, NULL, hInst, NULL);
00164
00165           SubclassWindow (hwndChild, SubclassWndProc);
00166         break;
00167
00168         case IDM_EDIT:
00169           hwndChild = CreateWindow(
00170             "EDIT", "edit",
00171             WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
00172             50,50, 60, 28,
00173             hwnd, NULL, hInst, NULL);
00174
00175           SubclassWindow (hwndChild, SubclassWndProc);
00176         break;
00177
00178         case IDM_LIST:
00179           hwndChild = CreateWindow(
00180             "LISTBOX", NULL,
00181             WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CLIPSIBLINGS,
00182             50,90, 60, 50,
00183             hwnd, NULL, hInst, NULL);
00184
00185           SubclassWindow (hwndChild, SubclassWndProc);
00186         break;
00187
00188         case IDM_TEST:
00189           fTestMode = ToggleMenu (GetMenu (hwnd), IDM_TEST);
00190         break;
00191
00192       }       /* end switch */
00193     } break;  /* end WM_COMMAND  */
00194
00195   }
00196   return (DefWindowProc(hwnd, message, wParam, lParam));
00197 }
00198
00199
00200 /**************************************************************************\
00201 *
00202 *  function:  SubclassWndProc
00203 *
00204 *  input parameters:  normal window procedure parameters.
00205 *  global variables:
00206 *   hwndMain  - parent window of the control.
00207 *   fTestMode - global boolean, set by menu, if true ignore subclass actions.
00208 \**************************************************************************/
00209
00210 LRESULT CALLBACK SubclassWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00211 {
00212   PExtraBytes  peb;
00213
00214
00215   /* get the pointer to the extra bytes structure out of the user data. */
00216   peb = (PExtraBytes)GetWindowLong (hwnd, GWL_USERDATA);
00217
00218   /* if running in test mode, just return the old procedure. */
00219   if (fTestMode)
00220     return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));
00221
00222
00223   switch (message) {
00224
00225
00226     /**********************************************************************\
00227     *  WM_DESTROY
00228     *
00229     * Free up the ExtraBytes structure which was allocated at subclass time.
00230     \**********************************************************************/
00231     case WM_DESTROY:
00232       LocalUnlock (LocalHandle ((LPSTR)peb));
00233     break;
00234
00235
00236     /**********************************************************************\
00237     *  WM_SETCURSOR
00238     *
00239     * Set the mouse pointer conditional on the Action which would be taken
00240     *  if the user presses mouse down.  This is set in WM_MOUSEMOVE.
00241     \**********************************************************************/
00242     case WM_SETCURSOR:
00243       switch (peb->Action) {
00244         case ACTIONNONE  :SetCursor (LoadCursor (NULL, IDC_ARROW)); break;
00245         case ACTIONMOVE  :SetCursor (LoadCursor (NULL, IDC_SIZEALL)); break;
00246         case ACTIONSIZEX :SetCursor (LoadCursor (NULL, IDC_SIZEWE)); break;
00247         case ACTIONSIZEY :SetCursor (LoadCursor (NULL, IDC_SIZENS)); break;
00248         case ACTIONSIZEXY:SetCursor (LoadCursor (NULL, IDC_SIZENWSE)); break;
00249       }
00250     return (0);
00251
00252
00253     /**********************************************************************\
00254     *  WM_LBUTTONDOWN
00255     *
00256     * The user is beginning a drag operation.  Fill in an initial window pos
00257     *  in the rect field, figure out which corner the cursor should be set
00258     *  to, translate that point to screen coordinates, and finally capture
00259     *  the mouse.
00260     \**********************************************************************/
00261
00262     case WM_LBUTTONDOWN: {
00263       POINT  mouse;
00264
00265       QueryWindowPos (hwnd, &peb->rect);
00266
00267       switch (peb->Action) {
00268         case ACTIONMOVE  :
00269           mouse.x = peb->rect.left;
00270           mouse.y = peb->rect.top ;
00271         break;
00272
00273         case ACTIONSIZEX :
00274           mouse.x = peb->rect.right;
00275           mouse.y = peb->rect.top ;
00276         break;
00277
00278         case ACTIONSIZEY :
00279           mouse.x = peb->rect.left;
00280           mouse.y = peb->rect.bottom;
00281         break;
00282
00283         case ACTIONSIZEXY:
00284           mouse.x = peb->rect.right;
00285           mouse.y = peb->rect.bottom;
00286         break;
00287       }
00288
00289       /* SetCursorPos() works based on screen position, and mouse is
00290        *  currently relative to hwndMain.
00291        */
00292       ClientToScreen (hwndMain, &mouse);
00293       SetCursorPos (mouse.x, mouse.y);
00294       SetCapture (hwnd);
00295     } return 0;
00296
00297
00298     /**********************************************************************\
00299     *  WM_LBUTTONUP
00300     *
00301     * Complement of the WM_LBUTTONDOWN message.  Release the capture,
00302     *  and reset the actual window's position.
00303     \**********************************************************************/
00304
00305     case WM_LBUTTONUP: {
00306       LONG lTemp;
00307
00308       if (GetCapture() == hwnd) {
00309         ReleaseCapture();
00310
00311         if (peb->rect.left > peb->rect.right)
00312         {
00313             lTemp = peb->rect.left;
00314             peb->rect.left = peb->rect.right;
00315             peb->rect.right = lTemp;
00316         }
00317
00318         if (peb->rect.top > peb->rect.bottom)
00319         {
00320             lTemp = peb->rect.top;
00321             peb->rect.top = peb->rect.bottom;
00322             peb->rect.bottom = lTemp;
00323         }
00324
00325         SetWindowPos (hwnd, NULL, peb->rect.left, peb->rect.top,
00326                       (peb->rect.right - peb->rect.left),
00327                       (peb->rect.bottom - peb->rect.top),
00328                       SWP_NOZORDER);
00329         InvalidateRect (hwnd, NULL, TRUE);
00330       }
00331     return 0;
00332    }
00333
00334     /**********************************************************************\
00335     *  WM_MOUSEMOVE
00336     *
00337     * There are two cases of interest here.  If the mouse is captured, then
00338     *  change the rect field in the extrabyte structure to reflect the new
00339     *  size/position that the user is selection.
00340     *
00341     *  If the mouse is not captured, then set the Action field dependent on
00342     *  the quadrant so that the WM_SETCURSOR will display the correct cursor.
00343     *
00344     \**********************************************************************/
00345
00346     case WM_MOUSEMOVE: {
00347       POINT mouse;
00348       /* the LO/HI-WORD from lParam will be a signed short relative to
00349        *  the child control window.
00350        */
00351       mouse.x = (int)(short)LOWORD(lParam);
00352       mouse.y = (int)(short)HIWORD(lParam);
00353
00354
00355
00356       /* if the mouse is captured, then we are doing direct manipulation */
00357       if (GetCapture() == hwnd) {
00358
00359         /* translate mouse pos to be client relative, not control relative */
00360         ClientToScreen (hwnd, &mouse);
00361         ScreenToClient (hwndMain, &mouse);
00362
00363         /* erase the old rectangle */
00364         PaintRect (hwndMain, &peb->rect);
00365
00366         switch (peb->Action) {
00367           case ACTIONMOVE  : {
00368             int width, height;
00369
00370             width = peb->rect.right - peb->rect.left;
00371             height = peb->rect.bottom - peb->rect.top;
00372             peb->rect.left = mouse.x;
00373             peb->rect.top  = mouse.y;
00374             peb->rect.right  = peb->rect.left + width;
00375             peb->rect.bottom = peb->rect.top +  height;
00376           }break;
00377
00378           case ACTIONSIZEX :
00379             peb->rect.right  = mouse.x;
00380           break;
00381
00382           case ACTIONSIZEY :
00383             peb->rect.bottom = mouse.y;
00384           break;
00385
00386           case ACTIONSIZEXY:
00387             peb->rect.right  = mouse.x;
00388             peb->rect.bottom = mouse.y;
00389           break;
00390         }
00391
00392         /* Redraw the new rectangle */
00393         PaintRect (hwndMain, &peb->rect);
00394       }
00395
00396
00397       /* if the mouse is not captured, then set the action for the sake of
00398        *  the WM_SETCURSOR message.  The action is dependent upon which
00399        *  quadrant of the window the mouse cursor is over.
00400        */
00401       else {
00402         int width2, height2;
00403         RECT rect;
00404
00405         GetClientRect (hwnd, &rect);
00406         width2 =  (rect.right -  rect.left)/2;
00407         height2 =  (rect.bottom -  rect.top)/2;
00408
00409         /* upper left hand corner */
00410         if ((mouse.x <= (width2)) && (mouse.y <= (height2))) {
00411             peb->Action = ACTIONMOVE;
00412
00413         /* lower left hand corner */
00414         } else if ((mouse.x <= (width2)) && (mouse.y > (height2))) {
00415             peb->Action = ACTIONSIZEY;
00416
00417         /* upper right hand corner */
00418         } else if ((mouse.x > (width2)) && (mouse.y <= (height2))) {
00419             peb->Action = ACTIONSIZEX;
00420
00421         /* lower right hand corner */
00422         } else if ((mouse.x > (width2)) && (mouse.y > (height2))) {
00423             peb->Action = ACTIONSIZEXY;
00424         }
00425       }
00426     } return 0;
00427
00428
00429
00430     /**********************************************************************\
00431     * for messages that are not handled explicitly here, pass them
00432     *  back to the old window procedure.
00433     \**********************************************************************/
00434     default:
00435       return (CallWindowProc ((peb->pfnOldProc), hwnd, message, wParam, lParam));
00436     break;
00437     } /* end switch */
00438
00439   return 0;
00440 }
00441
00442
00443
00444 /**************************************************************************\
00445 *  function:  SubclassWindow
00446 *
00447 *  input parameters:
00448 *   hwnd            - window handle to be subclassed,
00449 *   SubclassWndProc - the new window procedure.
00450 *
00451 *  Set in a new window procedure for this window.  Store the old window
00452 *   procedure in the first field of the extrabytes structure.  This routine
00453 *   is specific to this program in the use of this particular extrabyte
00454 *   structure.  Note that the pointer in the user bytes needs to be freed
00455 *   later (in WM_DESTROY).
00456 \**************************************************************************/
00457
00458 VOID SubclassWindow (HWND hwnd, WNDPROC SubclassWndProc)
00459 {
00460   PExtraBytes  peb;
00461
00462   peb = (PExtraBytes)LocalAlloc (LPTR, sizeof (ExtraBytes));
00463   peb->pfnOldProc = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);
00464
00465   SetWindowLong (hwnd, GWL_USERDATA, (LONG) peb);
00466   SetWindowLong (hwnd, GWL_WNDPROC,  (LONG) SubclassWndProc);
00467 }
00468
00469
00470 /**************************************************************************\
00471 *  function:  QueryWindowPos
00472 *
00473 *  input parameters:
00474 *   hwnd - window handle,  prect - pointer to rectangle to hold the answer.
00475 *
00476 *  global variables:
00477 *   hwndMain  - parent window of the control.
00478 *
00479 *  Return the bounding rectangle for the hwnd control relative to hwndMain.
00480 \**************************************************************************/
00481 VOID QueryWindowPos (HWND hwnd, LPRECT prect)
00482 {
00483   GetWindowRect (hwnd, prect);
00484   ScreenToClient (hwndMain, (LPPOINT)&(prect->left));
00485   ScreenToClient (hwndMain, (LPPOINT)&(prect->right));
00486 }
00487
00488
00489 /**************************************************************************\
00490 *  function:  PaintRect
00491 *
00492 *  input parameters:
00493 *   hwnd - window handle,  prect - pointer to rectangle to be painted.
00494 *
00495 *  Get an HDC and draw the rectangle in R2_NOT mode which if done twice will
00496 *   leave the screen in its initial state.
00497 \**************************************************************************/
00498
00499 VOID PaintRect (HWND hwnd, LPRECT prect)
00500 {
00501     HDC hdc;
00502
00503     hdc = GetDC (hwnd);
00504     SetROP2(hdc, R2_NOT);
00505     SelectObject (hdc, GetStockObject (NULL_BRUSH));
00506     Rectangle (hdc, prect->left, prect->top,
00507                     prect->right, prect->bottom);
00508     ReleaseDC (hwnd, hdc);
00509 }
00510
00511
00512 /**************************************************************************\
00513 *  function:  ToggleMenu
00514 *
00515 *  input parameters:
00516 *   hmenu - menu handle,  iditem - id of the item to check.
00517 *
00518 *  returns:  the new checked state.
00519 *
00520 *  Change a menu item to be checked if it is not, or unchecked if it is.
00521 \**************************************************************************/
00522
00523 DWORD ToggleMenu (HMENU hmenu, UINT iditem)
00524 {
00525   DWORD  state;
00526
00527   /* query the checked state.
00528    *  unfortunately, this turns checked off.
00529    */
00530   state = CheckMenuItem (hmenu, iditem, MF_BYCOMMAND);
00531
00532   /* switch the truth value of oldstate. */
00533   state = (state) ? MF_UNCHECKED : MF_CHECKED;
00534
00535   /* reset the menu item. */
00536   CheckMenuItem (hmenu, iditem, MF_BYCOMMAND | state);
00537
00538   return state;
00539 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REGIONS/REGIONS.C Source File

  • REGIONS

REGIONS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     Regions.c
00015 *
00016 *  PURPOSE:     To demonstrate the region APIs in Win32, namely:
00017 *
00018 *                          CombineRgn()
00019 *                          CreateEllipticRgn()
00020 *                          CreateEllipticRgnIndirect()
00021 *                          CreatePolygonRgn()
00022 *                          CreatePolyPolygonRgn()
00023 *                          CreateRectRgn()
00024 *                          FillRgn()
00025 *                          FrameRgn()
00026 *                          GetRgnBox()
00027 *                          InvertRgn()
00028 *                          OffsetRgn()
00029 *                          PaintRgn()
00030 *                          PtInRegion()
00031 *                          RectInRegion()
00032 *                          SetRectRgn()
00033 *
00034 *               The EqualRgn() API is *not* called in this program.
00035 *
00036 *  FUNCTIONS:
00037 *               WinMain()       - initialization, create window, msg loop
00038 *               MainWndProc()   - processes main window msgs
00039 *               AboutDlgProc()  - processes About dialog box msgs
00040 *               RgnBoxDlgProc() - processes RgnBox dialog box msgs
00041 *               MyCreateRgn()   - calls any one of Create*Rgn*() APIs
00042 *               MyCombineRgn()  - calls CombineRgn() API
00043 *               TrackRect()     - creates\draws\deletes a tracking rectangle
00044 *                                 (for use with RectInRegion menu item.)
00045 *               Reset()         - enables\disables menu items, modifies
00046 *                                 global vars (rgnArray[], currRgn).
00047 *
00048 *  COMMENTS:    This program allows a user to create the different kinds
00049 *               of regions available in Win32, and to perform the various
00050 *               operations on them. All operations are immediately
00051 *               reflected on the screen. The order in which the regions
00052 *               are created determines the order in which they are drawn,
00053 *               as well as which operation affects which region(s); for
00054 *               example, the last region created will be drawn on top of
00055 *               the others, and the operations in "Options" menu will
00056 *               affect this region. When two regions are combined the
00057 *               second region will be destroyed.
00058 *
00059 \******************************************************************************/
00060
00061 #include <windows.h>
00062 #include "regions.h"
00063
00064
00065
00066 /******************************************************************************\
00067 *
00068 *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
00069 *
00070 *  GLOBAL VARS: hInst - Handle of program instance
00071 *
00072 \******************************************************************************/
00073
00074 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00075                     LPSTR lpCmdLine, int nCmdShow)
00076 { HWND hwnd;
00077   MSG  msg;
00078
00079   if (!hPrevInstance)
00080   {
00081     WNDCLASS wc;
00082
00083     wc.style         = 0;
00084     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00085     wc.cbClsExtra    = 0;
00086     wc.cbWndExtra    = 0;
00087     wc.hInstance     = hInstance;
00088     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
00089     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
00090     wc.hbrBackground = GetStockObject (DKGRAY_BRUSH);
00091     wc.lpszMenuName  = (LPCTSTR) "Menu";
00092     wc.lpszClassName = (LPCTSTR) "Main";
00093
00094     if (!RegisterClass (&wc))
00095     {
00096       MessageBox (NULL, (LPCTSTR) "RegisterClass() failed",
00097                   (LPCTSTR) "Err! - REGIONS", MB_OK | MB_ICONEXCLAMATION);
00098       return(FALSE);
00099     }
00100   }
00101   hInst = hInstance;
00102   if (!(hwnd  = CreateWindow ("Main", "Regions API Sample",
00103                               WS_OVERLAPPED | WS_CAPTION |
00104                               WS_SYSMENU | WS_MINIMIZEBOX,
00105                               CW_USEDEFAULT, CW_USEDEFAULT,
00106                               220, 280, NULL, NULL, hInstance, NULL)))
00107     return (0);
00108
00109   ShowWindow   (hwnd, nCmdShow);
00110
00111   while (GetMessage (&msg, NULL, 0,0))
00112   {
00113     TranslateMessage (&msg);
00114     DispatchMessage  (&msg);
00115   }
00116
00117   return (msg.wParam);
00118 }
00119
00120
00121
00122 /******************************************************************************\
00123 *
00124 *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
00125 *
00126 *  GLOBAL VARS: hInst    - Handle of program instance
00127 *               rgnArray - Array of RGNSTRUCTs describing regions user has
00128 *                          created
00129 *               currRgn  - Index (in rgnArray) of most recently created
00130 *                          region. If -1 then no regions created. Otherwise,
00131 *                          values range from 0 to MAXRGNSTRUCTS - 1.
00132 *               hMenu    - Handle of main window's menu.
00133 *
00134 *  LOCAL VARS:  rect     - Scratch rectangle used in various places.
00135 *               ptr      - Pointer to a TRACKRECTSTRUCT (used for
00136 *                          tracking rectangle).
00137 *               i        - For-loop variable.
00138 *               hdc      - Scratch HDC used in various places.
00139 *               lButtonFlag - Tells what to do when left mouse button goes
00140 *                             down (eg. nothing, check point in region,
00141 *                             check rect in region).
00142 *               bOffsetRgnFlag - A BOOL which tells whether to offset up
00143 *                                and left or down and right.
00144 *
00145 \******************************************************************************/
00146
00147 LRESULT CALLBACK MainWndProc (HWND hWnd, UINT message, WPARAM wParam,
00148                               LPARAM lParam)
00149 {
00150   static RECT             rect;
00151   static PTRACKRECTSTRUCT ptr;
00152   static BOOL             bOffsetRgnFlag = FALSE;
00153   static WORD             lButtonFlag = 0;
00154          int              i;
00155          HDC              hdc;
00156
00157   switch (message)
00158   {
00159     case WM_CREATE:
00160
00161       hMenu   = GetMenu (hWnd);
00162       currRgn = -1;
00163       Reset (RESET_ALL);
00164       break;
00165
00166     case WM_COMMAND:
00167
00168       switch (LOWORD(wParam))
00169       {
00170         case IDM_ERASE:
00171           Reset (RESET_ALL);
00172           InvalidateRect (hWnd, NULL, TRUE);
00173           break;
00174
00175         case IDM_OFFSETRGN:
00176
00177           //
00178           // Offset rgnArray[currRgn].hrgn either down & right, or up &
00179           //   left (depending on bOffsetRgnFlag). Toggle bOffsetRgnFlag.
00180           //
00181
00182           if (bOffsetRgnFlag)
00183
00184             OffsetRgn (rgnArray[currRgn].hrgn, 15, 10);
00185
00186           else
00187
00188             OffsetRgn (rgnArray[currRgn].hrgn, -15, -10);
00189
00190           bOffsetRgnFlag = ~bOffsetRgnFlag;
00191           InvalidateRect (hWnd, NULL, TRUE);
00192           break;
00193
00194         case IDM_INVERTRGN:
00195
00196           hdc = GetDC (hWnd);
00197           InvertRgn (hdc, rgnArray[currRgn].hrgn);
00198           ReleaseDC (hWnd, hdc);
00199           break;
00200
00201         case IDM_FRAMERGN:
00202
00203           hdc = GetDC (hWnd);
00204
00205           FrameRgn (hdc, rgnArray[currRgn].hrgn,
00206                     GetStockObject (LTGRAY_BRUSH), 2, 2);
00207           ReleaseDC (hWnd, hdc);
00208           break;
00209
00210         case IDM_PTINRGN:
00211
00212           //
00213           // Uncheck "RectInRgn" menu item, toggle "PtInRgn" menu item,
00214           //   toggle lButtonFlag
00215           //
00216
00217           if (lButtonFlag == IDM_RECTINRGN)
00218             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
00219                             MF_UNCHECKED | MF_BYCOMMAND);
00220           if (lButtonFlag == IDM_PTINRGN)
00221           {
00222             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
00223                             MF_UNCHECKED | MF_BYCOMMAND);
00224             lButtonFlag = 0;
00225           }
00226           else
00227           {
00228             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
00229                             MF_CHECKED | MF_BYCOMMAND);
00230             lButtonFlag = IDM_PTINRGN;
00231           }
00232           break;
00233
00234         case IDM_RECTINRGN:
00235
00236           //
00237           // Uncheck "PtInRgn" menu item, toggle "RectInRgn" menu item,
00238           //   toggle lButtonFlag
00239           //
00240
00241           if (lButtonFlag == IDM_PTINRGN)
00242
00243             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_PTINRGN,
00244                             MF_UNCHECKED | MF_BYCOMMAND);
00245
00246           if (lButtonFlag == IDM_RECTINRGN)
00247           {
00248             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
00249                             MF_UNCHECKED | MF_BYCOMMAND);
00250             lButtonFlag = 0;
00251           }
00252           else
00253           {
00254             CheckMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
00255                             MF_CHECKED | MF_BYCOMMAND);
00256             lButtonFlag = IDM_RECTINRGN;
00257           }
00258           break;
00259
00260         case IDM_SETRECTRGN:
00261
00262           //
00263           // Reset rgnArray[currRgn].hrgn to be the rectangle which
00264           //   currently bounds it.
00265           //
00266
00267           GetRgnBox  (rgnArray[currRgn].hrgn, &rect);
00268           SetRectRgn (rgnArray[currRgn].hrgn, (int) rect.left,
00269                       (int) rect.top, (int) rect.right,
00270                       (int) rect.bottom);
00271           InvalidateRect (hWnd, NULL, TRUE);
00272           break;
00273
00274         case IDM_GETRGNBOX: // put up dlg which call GetRgnBox
00275
00276           DialogBox (hInst, (LPCTSTR) "RgnBox", hWnd, (DLGPROC)RgnBoxDlgProc);
00277           break;
00278
00279         case IDM_ELLIPSE: // create an elliptic region
00280
00281           MyCreateRgn (ELLIPTIC_RGN);
00282           InvalidateRect (hWnd, NULL, TRUE);
00283           break;
00284
00285         case IDM_POLYPOLYGON: // create a polyPolygon region
00286
00287           MyCreateRgn (POLYPOLYGON_RGN);
00288           InvalidateRect (hWnd, NULL, TRUE);
00289           break;
00290
00291         case IDM_RECT: // create a rectangular rgn
00292
00293           MyCreateRgn (RECT_RGN);
00294           InvalidateRect (hWnd, NULL, TRUE);
00295           break;
00296
00297         case IDM_AND:  // combine previous 2 rgns
00298
00299           MyCombineRgn (RGN_AND);
00300           InvalidateRect (hWnd, NULL, TRUE);
00301           break;
00302
00303         case IDM_COPY: // combine previous 2 rgns
00304
00305           MyCombineRgn (RGN_COPY);
00306           InvalidateRect (hWnd, NULL, TRUE);
00307           break;
00308
00309         case IDM_DIFF: // combine previous 2 rgns
00310
00311           MyCombineRgn (RGN_DIFF);
00312           InvalidateRect (hWnd, NULL, TRUE);
00313           break;
00314
00315         case IDM_OR: // combine previous 2 rgns
00316
00317           MyCombineRgn (RGN_OR);
00318           InvalidateRect (hWnd, NULL, TRUE);
00319           break;
00320
00321         case IDM_XOR: // combine previous 2 rgns
00322
00323           MyCombineRgn (RGN_XOR);
00324           InvalidateRect (hWnd, NULL, TRUE);
00325           break;
00326
00327         case IDM_ABOUT:  // put up About dialog box
00328
00329           DialogBox (hInst, (LPCTSTR) "About", hWnd, (DLGPROC)AboutDlgProc);
00330           break;
00331       }
00332       return (0);
00333
00334     case WM_LBUTTONDOWN:
00335     {
00336       //
00337       // if the "PtInRgn" menu item is checked, then see if the point at
00338       //   which this event happened is within currRgn, MessageBeep if so.
00339       //
00340       // else if the "RectInRgn" menu items are checked, then start
00341       //   tracking rectangle mode
00342       //
00343
00344       if (lButtonFlag == IDM_PTINRGN)
00345       {
00346         if (currRgn > -1)
00347
00348           if (PtInRegion (rgnArray[currRgn].hrgn, (int) LOWORD(lParam),
00349                           (int) HIWORD(lParam)))
00350             MessageBeep (0);
00351       }
00352       else if (lButtonFlag == IDM_RECTINRGN)
00353
00354         if ((ptr = TrackRect (NULL, TRECT_NEW, hWnd, lParam)) == NULL)
00355
00356         //
00357         // If TrackRect failed to LocalAlloc, then disable the
00358         //   IDM_RECTINRGN opion.
00359         //
00360
00361           EnableMenuItem (GetSubMenu (hMenu, 0), IDM_RECTINRGN,
00362                           MF_DISABLED | MF_GRAYED | MF_BYCOMMAND);
00363
00364       return (0);
00365     }
00366     case WM_MOUSEMOVE:
00367
00368       //
00369       // if in tracking rectangle mode call TrackRect
00370       //
00371
00372       if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd)
00373
00374         TrackRect (ptr, TRECT_PAINT, hWnd, lParam);
00375
00376       return (0);
00377
00378     case WM_LBUTTONUP:
00379
00380       //
00381       // if in tracking rectangle mode call TrackRect, check out the final
00382       //   rectangle, and see if it intersects currRgn
00383       //
00384
00385       if (lButtonFlag == IDM_RECTINRGN && GetCapture () == hWnd)
00386       {
00387         //
00388         // call TrackRect with TRECT_PAINT so it updates the rectangle
00389         //   for the last time, then again with TRECT_DELETE so it frees
00390         //   up the TRACKRECTSTRUCT it allocated
00391         //
00392
00393         TrackRect (ptr, TRECT_PAINT, hWnd, lParam);
00394         rect = ptr->trackRect;
00395         TrackRect (ptr, TRECT_DELETE, hWnd, lParam);
00396         if (RectInRegion (rgnArray[currRgn].hrgn, &rect))
00397
00398           MessageBeep (0);
00399       }
00400       return (0);
00401
00402     case WM_PAINT:
00403     {
00404       PAINTSTRUCT ps;
00405       COLORREF    crColor;
00406       HBRUSH      hBrush;
00407
00408       hdc = BeginPaint (hWnd, &ps);
00409
00410       //
00411       // For each rgn we created determine appropriate color & draw it
00412       //
00413
00414       for (i = 0; i <= currRgn; i++)
00415       {
00416         if (rgnArray[i].hrgn != NULL)
00417         {
00418           crColor = 0x000000;
00419           if (rgnArray[i].type & ELLIPTIC_RGN)    // add some red
00420
00421             crColor |= 0x0000ff;
00422
00423           if (rgnArray[i].type & POLYPOLYGON_RGN) // add some green
00424
00425             crColor |= 0x00ff00;
00426
00427           if (rgnArray[i].type & RECT_RGN)        // add some blue
00428
00429             crColor |= 0xff0000;
00430
00431           hBrush = CreateSolidBrush (crColor);
00432
00433           //
00434           // Alternately, the following would work:
00435           //    SelectObject (hdc, hBrush);
00436           //    FillRgn (hdc, rgnArray[i].hrgn);
00437           //
00438
00439           FillRgn (hdc, rgnArray[i].hrgn, hBrush);
00440           DeleteObject (hBrush);
00441         }
00442       }
00443       EndPaint (hWnd, &ps);
00444       return (0);
00445     }
00446     case WM_DESTROY:
00447
00448       PostQuitMessage(0);
00449       return (0);
00450   }
00451   return (DefWindowProc(hWnd, message, wParam, lParam));
00452 }
00453
00454
00455
00456 /******************************************************************************\
00457 *
00458 *  FUNCTION:    AboutDlgProc (standard dialog procedure INPUTS/RETURNS)
00459 *
00460 *  COMMENTS:    Displays "about" message
00461 *
00462 \******************************************************************************/
00463
00464 BOOL CALLBACK AboutDlgProc (HWND hwnd, UINT message, WPARAM wParam,
00465                                LPARAM lParam)
00466 { switch (message)
00467   {
00468     case WM_COMMAND:
00469
00470       if (LOWORD(wParam) == IDOK)
00471       {
00472         EndDialog(hwnd, TRUE);
00473         return (TRUE);
00474       }
00475       return (TRUE);
00476   }
00477   return (FALSE);
00478 }
00479
00480
00481
00482 /******************************************************************************\
00483 *
00484 *  FUNCTION:    RgnBoxDlgProc (standard dialog procedure INPUTS/RETURNS)
00485 *
00486 *  GLOBAL VARS: rgnArray - Array of RGNSTRUCTs describing regions user has
00487 *                          created
00488 *               currRgn  - Index (in rgnArray) of most recently created
00489 *                          region. If -1 then no regions created. Other-
00490 *                          wise, values range from 0 to MAXRGNSTRUCTS - 1.
00491 *
00492 *  COMMENTS:    Displays bounding rectangle of most recently created
00493 *               region.
00494 *
00495 \******************************************************************************/
00496
00497 BOOL CALLBACK RgnBoxDlgProc (HWND hwnd, UINT message, WPARAM wParam,
00498                              LPARAM lParam)
00499 {
00500   switch (message)
00501   {
00502     case WM_INITDIALOG:
00503     {
00504       RECT rect;
00505       char buf[15];
00506
00507       //
00508       // get the bounding rect of currRgn, fill in the dlg controls
00509       //   with text string describing the bounding rect.
00510       //
00511
00512       if (GetRgnBox (rgnArray[currRgn].hrgn, &rect) == SIMPLEREGION)
00513
00514         SetDlgItemText (hwnd, 102, "SIMPLEREGION");
00515
00516       else
00517
00518         SetDlgItemText (hwnd, 102, "COMPLEXREGION");
00519
00520       wsprintf (buf, "%ld", rect.left);
00521       SetDlgItemText (hwnd, 107, buf);
00522       wsprintf (buf, "%ld", rect.top);
00523       SetDlgItemText (hwnd, 108, buf);
00524       wsprintf (buf, "%ld", rect.right);
00525       SetDlgItemText (hwnd, 109, buf);
00526       wsprintf (buf, "%ld", rect.bottom);
00527       SetDlgItemText (hwnd, 110, buf);
00528
00529       return (TRUE);
00530     }
00531
00532     case WM_COMMAND:
00533
00534       if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00535       {
00536         EndDialog(hwnd, TRUE);
00537         return (TRUE);
00538       }
00539       return (TRUE);
00540   }
00541   return (FALSE);
00542 }
00543
00544
00545
00546 /******************************************************************************\
00547 *
00548 *  FUNCTION:    MyCreateRgn
00549 *
00550 *  INPUTS:      rgnStyle - The type of region to create (ELLIPTIC_RGN,
00551 *                          POLYPOLYGON_RGN, RECT_RGN)
00552 *
00553 *  GLOBAL VARS: rgnArray          - Array of RGNSTRUCTs describing regions
00554 *                                   user has created.
00555 *               currRgn           - Index (in rgnArray) of most recently
00556 *                                   created region. If -1 then no regions
00557 *                                   created. Otherwise, values range from
00558 *                                   0 to MAXRGNSTRUCTS-1.
00559 *               hMenu             - Handle of main window's menu.
00560 *               ellipseRect       - Rectangle bounding elliptical region.
00561 *               polyPolygonPoints - The points for the polyPolygon region.
00562 *               polyPolygonCounts - The count of points for each polygon
00563 *                                   in the polyPolygon region.
00564 *               rectRect          - The points for the rectangular region.
00565 *
00566 *  COMMENTS:    Creates a region (based on rgnStyle), increments currRgn,
00567 *               and fills in rgnArray[currRgn].
00568 *
00569 \******************************************************************************/
00570
00571 void MyCreateRgn (WORD rgnStyle)
00572 {
00573   if (++currRgn == 0)         // if this is 1st region enable options menu
00574
00575     Reset (ENABLE_OPTIONS);
00576
00577   else if (currRgn == 1)      // if this is 2nd region enable combine menu
00578
00579     Reset (ENABLE_COMBINERGN);
00580
00581   rgnArray[currRgn].type = rgnStyle;
00582
00583   switch (rgnStyle)
00584   {
00585     case ELLIPTIC_RGN:
00586
00587       //
00588       //  The following will also work here:
00589       //     CreateEllipticRgn ((int) ellipseRect.left,
00590       //                        (int) ellipseRect.top,
00591       //                        (int) ellipseRect.right,
00592       //                        (int) ellipseRect.bottom);
00593       //
00594
00595       rgnArray[currRgn].hrgn = CreateEllipticRgnIndirect (&ellipseRect);
00596
00597       EnableMenuItem (GetSubMenu (hMenu, 1), IDM_ELLIPSE,
00598                       MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
00599       break;
00600
00601     case POLYPOLYGON_RGN:
00602
00603       //
00604       // Alternately, several calls to CreatePolygonRgn could be made.
00605       //
00606
00607       rgnArray[currRgn].hrgn = CreatePolyPolygonRgn (polyPolygonPoints,
00608                                                      polyPolygonCounts,
00609                                                      POLYPOLYGONCOUNT,
00610                                                      WINDING);
00611       EnableMenuItem (GetSubMenu (hMenu, 1), IDM_POLYPOLYGON,
00612                       MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
00613       break;
00614
00615     case RECT_RGN:
00616
00617       //
00618       // Alternately, a call to CreatePolygonRgn could be made.
00619       //
00620
00621       rgnArray[currRgn].hrgn = CreateRectRgn (rectRect.left,
00622                                               rectRect.top,
00623                                               rectRect.right,
00624                                               rectRect.bottom);
00625
00626       EnableMenuItem (GetSubMenu (hMenu, 1), IDM_RECT,
00627                       MF_GRAYED | MF_DISABLED | MF_BYCOMMAND);
00628       break;
00629   }
00630 }
00631
00632
00633
00634 /******************************************************************************\
00635 *
00636 *  FUNCTION:    MyCombineRgn
00637 *
00638 *  INPUTS:      fnCombineMode- Operation to perform on the two regions
00639 *                              (RGN_AND, RGN_COPY, RGN_DIFF, RGN_OR,
00640 *                              RGN_XOR)
00641 *
00642 *  GLOBAL VARS: rgnArray- Array of RGNSTRUCTs describing regions user has
00643 *                         created
00644 *               currRgn - Index (in rgnArray) of most recently created
00645 *                         region. If -1 then no regions created. Otherwise,
00646 *                         values range from 0 to MAXRGNSTRUCTS - 1.
00647 *
00648 *  COMMENTS:    Combines the two regions rgnArray[currRgn-1] and
00649 *               rgnArray[currRgn] using fnCombineMode, placing the
00650 *               results in rgnArray[currRgn-1]. Destroys rgnArray[currRgn]
00651 *               and decrements currRgn.
00652 *
00653 \******************************************************************************/
00654
00655 void MyCombineRgn (int fnCombineMode)
00656 {
00657   if (currRgn >= 1) // only if two or more regions have been created
00658   {
00659     CombineRgn (rgnArray[currRgn-1].hrgn, rgnArray[currRgn-1].hrgn,
00660                 rgnArray[currRgn].hrgn, fnCombineMode);
00661
00662     rgnArray[currRgn-1].type |= rgnArray[currRgn].type;
00663
00664     //
00665     // Delete the second of the two regions after combining
00666     //
00667
00668     DeleteObject (rgnArray[currRgn--].hrgn);
00669
00670     if (currRgn == 0)
00671
00672       Reset (DISABLE_COMBINERGN);
00673   }
00674 }
00675
00676
00677
00678 /******************************************************************************\
00679 *
00680 *  FUNCTION:    Reset
00681 *
00682 *  INPUTS:      action - Describes which reset action to take, eg. which
00683 *                        menus to enable/disable etc...
00684 *
00685 *  GLOBAL VARS: rgnArray - Array of RGNSTRUCTs describing regions user has
00686 *                          created
00687 *               currRgn  - Index (in rgnArray) of most recently created
00688 *                          region. If -1 then no regions created. Other-
00689 *                          wise, values range from 0 to MAXRGNSTRUCTS - 1.
00690 *               hMenu    - Handle of main window's menu.
00691 *
00692 *  COMMENTS:    Sets appropriate menu states and deletes old regions
00693 *               according to "action" parameter.
00694 *
00695 \******************************************************************************/
00696
00697 void Reset (WORD action)
00698 {
00699   UINT i;
00700
00701   switch (action)
00702   {
00703     case RESET_ALL:
00704       if (currRgn > 0)
00705
00706         for (i = 0; i <= (UINT) currRgn; i++)
00707
00708           DeleteObject (rgnArray[i].hrgn);
00709
00710       currRgn = -1;
00711       for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)
00712
00713         EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_DISABLED | MF_GRAYED
00714                                                   | MF_BYCOMMAND);
00715       for (i = IDM_ELLIPSE; i <= IDM_RECT; i++)
00716
00717         EnableMenuItem (GetSubMenu (hMenu, 1), i, MF_ENABLED |
00718                                                   MF_BYCOMMAND);
00719       for (i = IDM_AND; i <= IDM_XOR; i++)
00720
00721         EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
00722                                                   | MF_BYCOMMAND);
00723       break;
00724
00725    case ENABLE_OPTIONS:
00726
00727       for (i = IDM_ERASE; i <= IDM_GETRGNBOX; i++)
00728
00729         EnableMenuItem (GetSubMenu (hMenu, 0), i, MF_ENABLED |
00730                                                   MF_BYCOMMAND);
00731       break;
00732
00733    case ENABLE_COMBINERGN:
00734
00735       for (i = IDM_AND; i <= IDM_XOR; i++)
00736
00737         EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_ENABLED |
00738                                                   MF_BYCOMMAND);
00739       break;
00740
00741    case DISABLE_COMBINERGN:
00742
00743       for (i = IDM_AND; i <= IDM_XOR; i++)
00744
00745         EnableMenuItem (GetSubMenu (hMenu, 2), i, MF_DISABLED | MF_GRAYED
00746                                                   | MF_BYCOMMAND);
00747       break;
00748   }
00749 }
00750
00751
00752 /******************************************************************************\
00753 *
00754 *  FUNCTION:    TrackRect()
00755 *
00756 *  INPUTS:      ptr    - Pointer to a PTRACKRECTSTRUCT.
00757 *               action - Message selecting what action to take.
00758 *               hWnd   - Window handle for the window the track rect
00759 *                        exists within.
00760 *               lParam - Fourth param to window proc (as with WM_MOUSEMOVE,
00761 *                        WM_LBUTTONDOWN, WM_LBUTTONUP...) desribing
00762 *                        event location.
00763 *
00764 *  RETURNS:     A pointer to a new TRACKRECTSTRUCT if msg == TRECT_NEW,
00765 *               NULL if msg != NEW
00766 *
00767 *  COMMENTS:    This function provides tracking rectangle functionality.
00768 *
00769 \******************************************************************************/
00770
00771 PTRACKRECTSTRUCT TrackRect (PTRACKRECTSTRUCT ptr, int action, HWND hWnd,
00772                             LPARAM lParam)
00773 {
00774   if ((ptr == NULL) && (action != TRECT_NEW))  return NULL;
00775
00776   switch (action)
00777   {
00778     //
00779     // TRECT_NEW: Allocate new PTRACKRECTSTRUCT. Fill in initial values
00780     //            for the fields of the structure. Set up the HDC
00781     //            correctly.
00782     //
00783     // return - pointer to the new object.
00784     //
00785
00786     case TRECT_NEW:
00787     {
00788       PTRACKRECTSTRUCT ptr;
00789
00790       if ((ptr = LocalAlloc (LPTR, sizeof (TRACKRECTSTRUCT))) == NULL)
00791       {
00792         MessageBox (hWnd, (LPCTSTR) "REGIONS: LocalAlloc() failed", "Err!",
00793                     MB_OK | MB_ICONEXCLAMATION);
00794         return NULL;
00795       }
00796
00797       //
00798       // initialize the HDC and other fields.
00799       //
00800
00801       ptr->hdc = GetDC(hWnd);
00802       SetROP2(ptr->hdc, R2_NOT);
00803       SelectObject (ptr->hdc, GetStockObject (NULL_BRUSH));
00804       SelectObject (ptr->hdc, CreatePen (PS_SOLID, 2,
00805                    (COLORREF) 0x01000009));
00806
00807       //
00808       // initialize the size
00809       //
00810
00811       ptr->trackRect.left = ptr->trackRect.right =
00812                             (LONG) (ptr->xOrigin = LOWORD (lParam));
00813       ptr->trackRect.top = ptr->trackRect.bottom =
00814                             (LONG) (ptr->yOrigin = HIWORD (lParam));
00815
00816       SetCapture (hWnd);
00817       GetClientRect (hWnd, &(ptr->clientRect));
00818       return (ptr);
00819     }
00820
00821     //
00822     // TRECT_DELETE: Free up the memory allocated for the tracking rect.
00823     //               Also, erase the last rectangle we drew.
00824     //
00825
00826     case  TRECT_DELETE:
00827
00828       Rectangle (ptr->hdc, (int) ptr->trackRect.left,
00829                            (int) ptr->trackRect.top,
00830                            (int) ptr->trackRect.right,
00831                            (int) ptr->trackRect.bottom);
00832       ReleaseDC (hWnd, ptr->hdc);
00833       LocalFree (LocalHandle ((LPSTR)ptr));
00834       ReleaseCapture ();
00835       return NULL;
00836
00837     //
00838     // TRECT_PAINT: Draw the tracking rectangle (involves erasing last
00839     //              rectangle at old coordinates, and drawing new rect
00840     //              at new coordinates).
00841     //
00842
00843     case TRECT_PAINT:
00844
00845       //
00846       // Remove the last rectangle we painted by painting over it again
00847       //
00848
00849       Rectangle (ptr->hdc, (int) ptr->trackRect.left,
00850                            (int) ptr->trackRect.top,
00851                            (int) ptr->trackRect.right,
00852                            (int) ptr->trackRect.bottom);
00853
00854       //
00855       // We want to restrict our Rectangle() calls to paint within the
00856       //   client area, so do a bounds check on lParam and reset any
00857       //   values which fall outside the client area (eg. <1,
00858       //   >clientRect.left, >clientRect.top).
00859       //
00860
00861       if ((SHORT)LOWORD(lParam) < 1)
00862
00863         lParam &= 0xffff0000;
00864
00865       else if (LOWORD(lParam) > (WORD) (ptr->clientRect.right- 1))
00866
00867         lParam = MAKELONG ((WORD) ptr->clientRect.right - 1,
00868                            HIWORD(lParam));
00869
00870       if ((SHORT)HIWORD(lParam) < 1)
00871
00872         lParam &= 0x0000ffff;
00873
00874       else if (HIWORD(lParam) > (WORD) (ptr->clientRect.bottom - 1))
00875
00876         lParam = MAKELONG (LOWORD(lParam),
00877                            (WORD) ptr->clientRect.bottom - 1);
00878
00879       ptr->trackRect.left   = (LONG) (ptr->xOrigin > LOWORD(lParam)
00880                                ? LOWORD(lParam) : ptr->xOrigin);
00881       ptr->trackRect.right  = (LONG) (ptr->xOrigin > LOWORD(lParam)
00882                                ? ptr->xOrigin : LOWORD(lParam));
00883       ptr->trackRect.top    = (LONG) (ptr->yOrigin > HIWORD(lParam)
00884                                ? HIWORD(lParam) : ptr->yOrigin);
00885       ptr->trackRect.bottom = (LONG) (ptr->yOrigin > HIWORD(lParam)
00886                                ? ptr->yOrigin : HIWORD(lParam));
00887
00888       //
00889       // Redraw the tracking rectangle
00890       //
00891
00892       Rectangle (ptr->hdc, (int) ptr->trackRect.left,
00893                            (int) ptr->trackRect.top,
00894                            (int) ptr->trackRect.right,
00895                            (int) ptr->trackRect.bottom);
00896       return NULL;
00897   }
00898 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/NTGREP.C Source File

  • GUIGREP

NTGREP.C

Go to the documentation of this file.
00001 /****************************************************************************
00002
00003     PROGRAM: NTGREP.C
00004
00005     PURPOSE: Installation application for the search browse file manager extension
00006
00007     FUNCTIONS:
00008
00009
00010 ****************************************************************************/
00011
00012 #include <windows.h>
00013 #include <string.h>
00014 #include "ntgrep.h"
00015
00016 HINSTANCE hInst;
00017
00018
00019 #define INITCLASSNAME "SearchInitClass"
00020
00021 LONG APIENTRY MainWndProc(
00022   HWND hWnd,
00023   UINT message,
00024   UINT wParam,
00025   LONG lParam);
00026
00027
00028 BOOL APIENTRY About(
00029   HWND hDlg,
00030   UINT message,
00031   UINT wParam,
00032   LONG lParam);
00033
00034 BOOL InitApplication(HINSTANCE hInstance);
00035 BOOL InitInstance(
00036     HINSTANCE          hInstance,
00037     int             nCmdShow);
00038
00039
00040 int PASCAL WinMain(
00041     HINSTANCE hInstance,
00042     HINSTANCE hPrevInstance,
00043     LPSTR lpCmdLine,
00044     int nCmdShow
00045     )
00046 {
00047
00048     MSG msg;
00049     DWORD dwVersion;
00050
00051     UNREFERENCED_PARAMETER( lpCmdLine );
00052
00053     /* Get the version we're running on to make sure it's NT */
00054     dwVersion = GetVersion();
00055     if (dwVersion & 0x80000000)
00056     {
00057         /* This is not NT.  Display an error message and exit. */
00058         MessageBox( NULL,
00059             "This sample application can only be run on Windows NT.\n"
00060             "This application will now terminate.",
00061             "GUIGrep",
00062             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00063         return( 1 );
00064     }
00065
00066
00067     if (!hPrevInstance)
00068   if (!InitApplication((HINSTANCE)hInstance))
00069       return (FALSE);
00070
00071
00072     if (!InitInstance((HINSTANCE)hInstance, nCmdShow))
00073   return (FALSE);
00074
00075
00076     while (GetMessage(&msg,NULL,0,0))
00077   {
00078   TranslateMessage(&msg);
00079   DispatchMessage(&msg);
00080     }
00081     return (msg.wParam);
00082 }
00083
00084
00085
00086 BOOL InitApplication(HINSTANCE hInstance)
00087 {
00088     WNDCLASS  wc;
00089     wc.style = 0;
00090     wc.lpfnWndProc = (WNDPROC)MainWndProc;
00091
00092     wc.cbClsExtra = 0;
00093     wc.cbWndExtra = 0;
00094     wc.hInstance = hInstance;
00095     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
00096     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00097     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
00098     wc.lpszMenuName =  "GrepMenu";
00099     wc.lpszClassName = INITCLASSNAME;
00100
00101     return (RegisterClass(&wc));
00102
00103 }
00104
00105
00106 BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
00107 {
00108     HWND            hWnd;
00109
00110
00111     hInst = hInstance;
00112
00113     hWnd = CreateWindow(
00114   INITCLASSNAME,
00115   "File Search Installer",
00116   WS_OVERLAPPEDWINDOW,
00117   CW_USEDEFAULT,
00118   CW_USEDEFAULT,
00119   CW_USEDEFAULT,
00120   CW_USEDEFAULT,
00121   NULL,
00122   NULL,
00123   hInstance,
00124   NULL
00125     );
00126
00127
00128
00129     if (!hWnd)
00130   return (FALSE);
00131
00132
00133     ShowWindow(hWnd, nCmdShow);
00134     UpdateWindow(hWnd);
00135     return (TRUE);
00136
00137 }
00138
00139
00140 LONG APIENTRY MainWndProc(
00141   HWND hWnd,
00142   UINT message,
00143   UINT wParam,
00144   LONG lParam)
00145 {
00146
00147     switch (message) {
00148   case WM_COMMAND:
00149       switch (LOWORD(wParam))
00150       { static char szDirBuff[MAX_PATH+12];
00151         case IDM_INSTALL:
00152        GetSystemDirectory(szDirBuff,MAX_PATH);
00153        strcat(szDirBuff,"\\guigrep.dll");
00154        if (!CopyFile("guigrep.dll",szDirBuff,FALSE))
00155         { MessageBox(hWnd,"Error copying file to system directory",
00156             "Grep setup",MB_OK);
00157         break;
00158       };
00159       WritePrivateProfileString("AddOns","File Grepper",
00160               "guigrep.dll","winfile.ini");
00161      DialogBox(hInst,"ExplainBox",hWnd,(DLGPROC)About);
00162       /* Fall through... (vanity) */
00163         case IDM_ABOUT:
00164        DialogBox(hInst,"AboutBox",hWnd,(DLGPROC)About);
00165        break;
00166       case IDM_UNINSTALL:
00167       WritePrivateProfileString("AddOns","File Grepper",
00168               "","winfile.ini");
00169       break;
00170
00171       default:
00172         return (DefWindowProc(hWnd, message, wParam, lParam));
00173       };
00174       break;
00175   case WM_DESTROY:
00176       PostQuitMessage(0);
00177       break;
00178
00179   default:
00180       return (DefWindowProc(hWnd, message, wParam, lParam));
00181     }
00182     return (0);
00183 }
00184
00185
00186 BOOL APIENTRY About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
00187 {
00188     switch (message) {
00189   case WM_INITDIALOG:
00190       return (TRUE);
00191
00192   case WM_COMMAND:
00193       if (LOWORD(wParam) == IDOK
00194     || LOWORD(wParam) == IDCANCEL) {
00195     EndDialog(hDlg, TRUE);
00196     return (TRUE);
00197       }
00198       break;
00199     }
00200     return (FALSE);
00201   UNREFERENCED_PARAMETER(lParam);
00202 }
00203
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOGGING/LOG.C Source File

  • LOGGING

LOG.C

Go to the documentation of this file.
00001 // Microsoft Developer Support Copyright (c) 1995-1996 Microsoft Corporation.
00002 /*
00003 version 1.0 (initial release)
00004 version 1.1 (3.51 release)
00005   - added support for replaceable parameter strings ("%%xxx" codes)
00006   - corrected processing of registry API return codes and errors
00007   - added support for PrimaryModule key - default message file
00008   - added support for multiple message files per message
00009   - can now dump arbitrary log from command line
00010 version 1.2
00011   - fixed bug with multiple paths ('path;path' format) for message DLL
00012   - display event type (error, warning, etc.) as string instead of number
00013   - dumps account names from SID in eventlog record
00014 version 1.3
00015   - added category ID support
00016   - added logging of the callers Sid
00017 version 1.4
00018   - added support for remote logging. Easier than I thought. :-)
00019   - removed FormatMessage call to insert message strings - do it manually
00020     like the Event Viewer to avoid unwanted formatting of the message string
00021
00022 ToDo: this app isn't super robust and will not cleanly recover from all
00023   possible problems, though I do try to handle the major, common problems.
00024   Robustness left as an excercise for the reader. :-) */
00025
00026 #include <stdio.h>
00027 #include <windows.h>
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <process.h>
00031 #include "messages.h"
00032
00033 #define PERR(bSuccess, api) {if (!(bSuccess)) printf("\n%s: Error %d from %s \
00034     on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
00035
00036 #define REG_ERR(lRegError, api) {if (lRegError!=ERROR_SUCCESS) printf("%s: \
00037     Error %d from %s on line %d\n", __FILE__, lRegError, api, __LINE__);}
00038
00039 #define MAX_MSG_LENGTH 1024
00040 #define MSG_ID_MASK 0x0000FFFF
00041 /* MACHINE should either be NULL for local logging or a UNC name of a remote
00042    machine, i.e. "\\\\Server1" */
00043 #define MACHINE NULL
00044 /* if MACHINE != NULL, REMOTE_MSG_DLL_PATH must have a UNC path to the proper
00045    directory containing messages.dll. The machine must have access to
00046    this remote directory via the UNC pathname given */
00047 #define REMOTE_MSG_DLL_PATH "\\\\ericsa2\\d$\\ntwork\\eventlog"
00048
00049 /*********************************************************************
00050 * FUNCTION: addSourceToRegistry(LPSTR pszLogName, LPSTR pszSrcName,  *
00051 *                               LPSTR pszMsgDLL)                     *
00052 *                                                                    *
00053 * PURPOSE: Add a source name key, message DLL name value, and        *
00054 *          'message types supported' value to the registry           *
00055 *                                                                    *
00056 * INPUT: name of log (Application, System, or Security),             *
00057 *        source name, path of message DLL                            *
00058 *                                                                    *
00059 * RETURNS: none                                                      *
00060 *********************************************************************/
00061
00062 void addSourceToRegistry(LPSTR pszLogName, LPSTR pszSrcName, LPSTR pszMsgDLL)
00063 {
00064   HKEY hk, hklm;          // registry key handle
00065   DWORD dwData;
00066   TCHAR szTemp[MAX_PATH];
00067   LONG lRegError;         // return value from registry APIs
00068
00069   /* connect to remote registry (or local if MACHINE == NULL) */
00070   lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
00071   REG_ERR(lRegError, "RegConnectRegistry");
00072   /* When a process uses the RegisterEventSource or OpenEventLog function to
00073      get a handle of an event log, the event logging service searches for the
00074      specified source name in the registry. You can add a new source name to
00075      the registry by opening a new registry subkey under the EventLog key and
00076      adding registry values to the new subkey. */
00077   // Create a new key for our source
00078   sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
00079       pszLogName, pszSrcName);
00080   lRegError = RegCreateKey(hklm, szTemp, &hk);
00081   REG_ERR(lRegError, "RegCreateKey");
00082   RegCloseKey(hklm);
00083   // Add the Event-ID message-file name to the subkey.
00084   lRegError = RegSetValueEx(hk,  // subkey handle
00085       "EventMessageFile",        // value name
00086       0,                         // must be zero
00087       REG_EXPAND_SZ,             // value type
00088       (LPBYTE) pszMsgDLL,        // address of value data
00089       strlen(pszMsgDLL) + 1);    // length of value data
00090   REG_ERR(lRegError, "RegSetValueEx");
00091
00092   /* Add the Category message-file name to the subkey. These category strings
00093      correspond to the fwCategory parameter passed into ReportEvent(). */
00094   lRegError = RegSetValueEx(hk,  // subkey handle
00095       "CategoryMessageFile",     // value name
00096       0,                         // must be zero
00097       REG_EXPAND_SZ,             // value type
00098       (LPBYTE) pszMsgDLL,        // address of value data
00099       strlen(pszMsgDLL) + 1);    // length of value data
00100   REG_ERR(lRegError, "RegSetValueEx");
00101
00102   /* Add the replaceable parameter message-file name to the subkey. This is
00103      used to replace %%nnn values in messages with the appropriate string */
00104   lRegError = RegSetValueEx(hk,  // subkey handle
00105       "ParameterMessageFile",    // value name
00106       0,                         // must be zero
00107       REG_EXPAND_SZ,             // value type
00108       (LPBYTE) pszMsgDLL,        // address of value data
00109       strlen(pszMsgDLL) + 1);    // length of value data
00110   REG_ERR(lRegError, "RegSetValueEx");
00111
00112   // Set the supported types flags and add it to the subkey.
00113   dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
00114     EVENTLOG_INFORMATION_TYPE;
00115   lRegError = RegSetValueEx(hk,  // subkey handle
00116       "TypesSupported",          // value name
00117       0,                         // must be zero
00118       REG_DWORD,                 // value type
00119       (LPBYTE) &dwData,          // address of value data
00120       sizeof(DWORD));            // length of value data
00121   REG_ERR(lRegError, "RegSetValueEx");
00122
00123   // Set the number of categories supported
00124   dwData = 3;
00125   lRegError = RegSetValueEx(hk,  // subkey handle
00126       "CategoryCount",           // value name
00127       0,                         // must be zero
00128       REG_DWORD,                 // value type
00129       (LPBYTE) &dwData,          // address of value data
00130       sizeof(DWORD));            // length of value data
00131   REG_ERR(lRegError, "RegSetValueEx");
00132   RegCloseKey(hk);
00133   return;
00134 } // addSourceToRegistry
00135
00136 /*********************************************************************
00137 * FUNCTION: reportAnEvent(LPSTR pszSrcName, DWORD dwIdEvent,         *
00138 *                         WORD wCategory, WORD cStrings,             *
00139 *                         LPTSTR *pszStrings);                       *
00140 *                                                                    *
00141 * PURPOSE: add the event to the event log                            *
00142 *                                                                    *
00143 * INPUT: source name, the event ID to report in the log,             *
00144 *        the category, the number of insert strings, and an array of *
00145 *        null-terminated insert strings                              *
00146 *                                                                    *
00147 * RETURNS: none                                                      *
00148 *********************************************************************/
00149
00150 void reportAnEvent(LPSTR pszSrcName, DWORD dwIdEvent, WORD wCategory,
00151      WORD cStrings, LPTSTR * pszStrings)
00152 {
00153   #define SID_BUF_SIZE 1024
00154   HANDLE hLog;
00155   HANDLE hAccessToken;
00156   PTOKEN_USER ptgUser;
00157   BYTE UserBuf[SID_BUF_SIZE];
00158   DWORD cbUserBufSize = SID_BUF_SIZE;
00159   BOOL bSuccess;
00160
00161   // get the current process access token
00162   bSuccess = OpenProcessToken(
00163             GetCurrentProcess(),
00164             TOKEN_QUERY,
00165             &hAccessToken);
00166   PERR(bSuccess, "OpenProcessToken");
00167
00168   ptgUser = (PTOKEN_USER) UserBuf;
00169
00170   // get the TOKEN_USER structure from the access token, which contains
00171   // the Sid representing the caller
00172   bSuccess = GetTokenInformation(
00173             hAccessToken,
00174             TokenUser,
00175             ptgUser,
00176             cbUserBufSize,
00177             &cbUserBufSize
00178             );
00179   PERR(bSuccess, "GetTokenInformation");
00180
00181   CloseHandle(hAccessToken);
00182
00183   // Get a handle to the event log
00184   hLog = RegisterEventSource(MACHINE,  // use machine defined elsewhere
00185       pszSrcName);                  // source name
00186   PERR(hLog, "RegisterEventSource");
00187
00188   // Now report the event, which will add this event to the event log
00189   bSuccess = ReportEvent(hLog,  // event-log handle
00190       EVENTLOG_ERROR_TYPE,      // event type
00191       wCategory,                // category
00192       dwIdEvent,                // event ID
00193       ptgUser->User.Sid,        // Sid representing caller
00194       cStrings,                 // number of substitution strings
00195       0,                        // no binary data
00196       pszStrings,               // string array
00197       NULL);                    // address of data
00198   PERR(bSuccess, "ReportEvent");
00199
00200   DeregisterEventSource(hLog);
00201
00202   return;
00203 } // reportAnEvent
00204
00205 /*********************************************************************
00206 * FUNCTION: insertMsgString(HKEY hk, PTCHAR szMsg, WORD wNumStrings  *
00207 *     PTCHAR szInsStrings);                                          *
00208 *                                                                    *
00209 * PURPOSE: replace "%xxx" parameters in message strings with         *
00210 *          appropriate value from eventlog insert strings            *
00211 *                                                                    *
00212 * INPUT: message to scan for "%xxx" parameters, strings to insert,   *
00213 *        and the number of strings to insert                         *
00214 *                                                                    *
00215 * RETURNS: the string resulting from the string replacement          *
00216 *          operation. This memory must be freed by the caller via    *
00217 *          free().                                                   *
00218 *********************************************************************/
00219
00220 // size of replaceable parameter strings - should fit a DWORD as a string
00221 #define PARAM_SIZE (16)
00222
00223 PTCHAR insertMsgString(HKEY hk, PTCHAR szMsg, WORD wNumStrings,
00224     PTCHAR szInsStrings)
00225 {
00226   BOOL bSuccess;
00227   DWORD dwType;    // for RegQueryValueEx
00228   LONG lRegError;  // return value from registry APIs
00229   // paths to ParameterMessageFile
00230   TCHAR szParamMsgPath[MAX_PATH], szTemp[MAX_PATH];
00231   DWORD dwcbData;
00232   HINSTANCE hLib;   // handle to DLL containing ParameterMessageFile
00233   DWORD dwID;       // message ID
00234   LPTSTR msgBuf;
00235   PTCHAR szTempMsg;  // the message with replaced "%" or "%%" insert strings
00236   PTCHAR p1 = szMsg, p2 = szMsg; // temp pointers to walk the string
00237   PTCHAR szInsStr;   // point to insert strings in the EVENTLOGRECORD struct
00238   DWORD cchDest;
00239   int i;
00240
00241   szTempMsg = malloc(MAX_MSG_LENGTH);
00242   szTempMsg[0] = 0;
00243   while (p2)
00244   {
00245     p2 = strchr(p1, '%');
00246     if (!p2)  // "%" not found, just copy the rest of the string and quit
00247     {
00248       strcat(szTempMsg, p1);
00249       continue;
00250     }
00251     strncat(szTempMsg, p1, p2 - p1);  // copy up to "%"
00252     /* is this a special "%%" string? If so, replace with language-dependant
00253        insert string from the ParameterMessageFile from registry. If it's not
00254        a "%%" string, skip down to else clause to replace as normal insert
00255        strings from the EVENTLOGRECORD structure */
00256     if (p2[1] == '%') // yup, it's a "%%" parameter string
00257     {
00258       p2 += 2;          // point to number, past the "%%"
00259       dwID = atoi(p2);  // get the message ID following the "%%"
00260       if (!dwID)        // it's not a number, copy "%%" as-is
00261       {
00262         strcat(szTempMsg, "%%");
00263         p1 = p2;
00264         continue;
00265       }
00266       else
00267         p1 = p2 + strspn(p2, "0123456789"); // point past number
00268
00269       /* now look up the string corresponding to the message ID and append
00270          it into our temp string */
00271       dwcbData = MAX_PATH;
00272       lRegError = RegQueryValueEx(hk,  // handle of key to query
00273           "ParameterMessageFile",      // value name
00274           NULL,                        // must be NULL
00275           &dwType,                     // address of type value
00276           szTemp,                      // path to replaceable parameter message file
00277           &dwcbData);                  // length of value data
00278       REG_ERR(lRegError, "RegQueryValueEx");
00279
00280       /* Expand environment variable strings in the message DLL path name, in
00281          case any are there */
00282       cchDest = ExpandEnvironmentStrings(szTemp, szParamMsgPath, MAX_PATH);
00283       PERR(cchDest != 0, "ExpandEnvironmentStrings");
00284       PERR(cchDest < MAX_PATH, "ExpandEnvironmentStrings");
00285
00286       hLib = LoadLibraryEx(szParamMsgPath, NULL, DONT_RESOLVE_DLL_REFERENCES);
00287       PERR(hLib != NULL, "LoadLibraryEx");
00288       bSuccess = FormatMessage(
00289           FORMAT_MESSAGE_FROM_HMODULE |     // get the message from the DLL
00290           FORMAT_MESSAGE_ALLOCATE_BUFFER |  // allocate the msg buffer
00291           FORMAT_MESSAGE_ARGUMENT_ARRAY |   // lpArgs is an array of pointers
00292           FORMAT_MESSAGE_IGNORE_INSERTS |   // don't do any formatting
00293           70,                     // line length for the mesages
00294           hLib,                   // the messagetable DLL handle
00295           dwID,                   // message ID
00296           LANG_USER_DEFAULT,      // language ID
00297           (LPTSTR) &msgBuf,       // address of pointer to buffer for message
00298           PARAM_SIZE,             // maximum size of the message buffer
00299           NULL);                  // array of insert strings for the message
00300       PERR(bSuccess, "FormatMessage");
00301       FreeLibrary(hLib);
00302       strcat(szTempMsg, msgBuf);
00303       LocalFree((HLOCAL) msgBuf);
00304     }
00305     else //a normal insert string, look up in EVENTLOGRECORD structure
00306     {
00307       p2++;            // point to number, past the "%"
00308       dwID = atoi(p2);  // get the message ID following the "%"
00309       if (!dwID)        // it's not a number, copy "%" as-is
00310       {
00311         strcat(szTempMsg, "%");
00312         p1 = p2;
00313         continue;
00314       }
00315       else
00316         p1 = p2 + strspn(p2, "0123456789"); // point past number
00317       szInsStr = szInsStrings;
00318       for (i = 1; i < (int) dwID; i++) // find string number dwID
00319       {
00320         if (i > wNumStrings) // handle bogus string number
00321         {
00322           puts("**Error! Insert string ID too large");
00323           continue;
00324         }
00325         szInsStr += (strlen(szInsStr) + 1); // point to next string
00326       }
00327       strcat(szTempMsg, szInsStr);
00328     } //else
00329   } //while
00330   return (szTempMsg);  // caller must free()!
00331 } // insertMsgString
00332
00333 /*********************************************************************
00334 * FUNCTION: lookupStringFromMsgDll(HKEY hk, DWORD dwEventID,         *
00335 *     WORD wNumStrings, PTCHAR szStrings, PTCHAR szMsgDllPath);      *
00336 *                                                                    *
00337 * PURPOSE: look up a string from a message file                      *
00338 *                                                                    *
00339 * INPUT: root of the key containing the eventlog info for this       *
00340 *        eventlog source, the ID of the string to look up, the       *
00341 *        number of replacement strings, the replacement strings      *
00342 *        from the EVENTLOGRECORD structure, and the list of message  *
00343 *        DLLs to search for the message                              *
00344 *                                                                    *
00345 * RETURNS: the string string from the message file. This string      *
00346 *          should be freed by the caller                             *
00347 *********************************************************************/
00348
00349 PTCHAR lookupStringFromMsgDll(HKEY hk, DWORD dwEventID, WORD wNumStrings,
00350     PTCHAR szStrings, PTCHAR szMsgDllPath)
00351 {
00352   DWORD cchDest;
00353   PTCHAR pMsgDll;   // one of the message DLLs in the list
00354   PTCHAR pNextDll;  // pointer to next DLL in the list
00355   HINSTANCE hLib;  // handle to the messagetable DLL
00356   LPTSTR msgBuf;   // hold text of the error message that we build
00357   PTCHAR p;
00358   TCHAR szTempMsg[MAX_MSG_LENGTH];
00359   BOOL bSuccess;
00360   TCHAR szMsgDllPathEx[MAX_PATH];  // after environment string expansion
00361
00362   /* Expand environment variable strings in the message DLL path name, in
00363      case any are there, such as %systemroot% */
00364   cchDest = ExpandEnvironmentStrings(szMsgDllPath, szMsgDllPathEx, MAX_PATH);
00365   PERR(cchDest != 0, "ExpandEnvironmentStrings");
00366   PERR(cchDest < MAX_PATH, "ExpandEnvironmentStrings");
00367
00368   // The list is delimited by ';' chars, check each DLL for the message
00369   pMsgDll = szMsgDllPathEx;  // point to beginning of DLL list
00370   while (pMsgDll)
00371   {
00372     pNextDll = strchr(szMsgDllPathEx, ';');
00373     if (pNextDll)
00374     {
00375       *pNextDll = 0;  // replace ';' with 0 to null terminate the name
00376       pNextDll++;     // point to the next name in the list
00377     }
00378
00379     // Now we've got a message DLL name, load the DLL.
00380     hLib = LoadLibraryEx(pMsgDll, NULL, DONT_RESOLVE_DLL_REFERENCES);
00381     PERR(hLib != NULL, "LoadLibraryEx");
00382     if (!hLib)
00383       continue;
00384
00385     /* retrieve the message from the messagetable DLL. For the language
00386     identifier, use the values we defined in the LanguageNames statements in
00387     the .mc file. If no LanguageNames values were defined in the .mc file, as
00388     in this case, use the LANG_USER_DEFAULT macro defined in winnt.h */
00389     bSuccess = FormatMessage(
00390         FORMAT_MESSAGE_FROM_HMODULE |     // get the message from the DLL
00391         FORMAT_MESSAGE_ALLOCATE_BUFFER |  // allocate the msg buffer for us
00392         FORMAT_MESSAGE_ARGUMENT_ARRAY |   // lpArgs is an array of pointers
00393         FORMAT_MESSAGE_IGNORE_INSERTS |   // just get the message
00394         70,                 // line length for the mesages
00395         hLib,               // the messagetable DLL handle
00396         dwEventID,          // message ID
00397         LANG_USER_DEFAULT,  // language ID
00398         (LPTSTR) &msgBuf,   // address of pointer to buffer for message
00399         MAX_MSG_LENGTH,     // maximum size of the message buffer
00400         NULL);              // array of insert strings for the message
00401     // if the message was not found, try the next DLL in the list
00402     if (!bSuccess && GetLastError() == ERROR_MR_MID_NOT_FOUND && pNextDll)
00403     {
00404       FreeLibrary(hLib);
00405       pMsgDll = pNextDll;  // point to next DLL in list (or NULL if no more)
00406       continue;            /* if the msg doesn't exist, and we have more
00407                               DLL's to check, continue down the list */
00408     }
00409     PERR(bSuccess, "FormatMessage");
00410
00411     // if everything is ok, continue on, otherwise proceed to next event
00412     if (bSuccess)
00413     {
00414       /* process insert strings. Call twice - insert strings may contain
00415          special "%%" language-dependant replaceable parameter strings */
00416       strcpy(szTempMsg, msgBuf);
00417       LocalFree((HLOCAL) msgBuf);
00418       p = insertMsgString(hk, szTempMsg, wNumStrings, szStrings);
00419       strcpy(szTempMsg, p);
00420       free(p);  // free buffer allocated by insertParamString()
00421       p = insertMsgString(hk, szTempMsg, wNumStrings, szStrings);
00422       strcpy(szTempMsg, p);
00423       //don't free p again, it will be returned to the caller to free.
00424     } // if
00425     else
00426       p = NULL;
00427     pMsgDll = pNextDll;  // point to next DLL in list (or NULL if no more)
00428     // free the message DLL since we don't know if we'll need it again
00429     FreeLibrary(hLib);
00430   } // while
00431   return(p);  // p will be freed by our caller
00432 } // lookupStringFromMsgDll
00433
00434 /*********************************************************************
00435 * FUNCTION: queryEventLog(HANDLE hEventLog, LPCTSTR pszLogName,      *
00436 *           LPCTSTR pszSourceName)                                   *
00437 *                                                                    *
00438 * PURPOSE: dump out some of the data for each event in the specified *
00439 *          event log                                                 *
00440 *                                                                    *
00441 * INPUT: handle of the open eventlog (or NULL if not open), the name *
00442 *        of the log to dump (application, system, security),         *
00443 *        and the name of an eventlog source within that log (or NULL *
00444 *        if not available, but required if hLog is NULL)             *
00445 *                                                                    *
00446 * RETURNS: none                                                      *
00447 *                                                                    *
00448 * NOTES: Add functionality to get category strings from category     *
00449 *        DLL and display them along with the message string          *
00450 *********************************************************************/
00451
00452 void queryEventLog(HANDLE hEventLog, LPCTSTR pszLogName, LPCTSTR pszSourceName)
00453 {
00454   EVENTLOGRECORD *pevlr;
00455   BYTE bBuffer[1024 * 64];    // hold the event log record raw data
00456   DWORD dwRead, dwNeeded, dwThisRecord = 0;
00457   HANDLE hLog;                // handle to the log
00458   BOOL bSuccess;
00459   DWORD cRecords;             // number of event records in the log
00460   LONG lRegError;
00461   DWORD dwType;
00462   DWORD dwcbData;
00463   HKEY hklm, hk;
00464   TCHAR szTemp[MAX_PATH];
00465   TCHAR szPrimaryMsgFile[64];  // name of primary (default) message file
00466   PTCHAR p;
00467
00468   if (!hEventLog)
00469   {
00470     hLog = OpenEventLog(NULL,  // use local machine
00471         pszSourceName);        // source name - assumed to be valid
00472     PERR(hLog, "OpenEventLog");
00473   }
00474   else
00475     hLog = hEventLog;
00476
00477   // Get the number of records in the log.
00478   bSuccess = GetNumberOfEventLogRecords(hLog, &cRecords);
00479   PERR(bSuccess, "GetNumberOfEventLogRecords");
00480   printf("There are %d records in the %s log.\n", cRecords, pszLogName);
00481
00482   /* If the eventlog key contains a PrimaryModule value, get the default
00483      messagefile from it. This is the default EventMessageFile if an
00484      EventMessageFile value doesn't exist for a given source. */
00485   sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s",
00486       pszLogName);
00487   lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
00488   REG_ERR(lRegError, "RegConnectRegistry");
00489   lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
00490   REG_ERR(lRegError, "RegOpenKeyEx");
00491   RegCloseKey(hklm);
00492   dwcbData = MAX_PATH;
00493   lRegError = RegQueryValueEx(hk,  // handle of key to query
00494       "PrimaryModule",             // value name
00495       NULL,                        // must be NULL
00496       &dwType,                     // address of type value
00497       szPrimaryMsgFile,            // path to primary (default) message DLL
00498       &dwcbData);                  // length of value data
00499   if (lRegError == ERROR_FILE_NOT_FOUND)  // the key doesn't exist
00500     szPrimaryMsgFile[0] = 0;       // so we can test for it later
00501   else
00502     REG_ERR(lRegError, "RegQueryValueEx");
00503   RegCloseKey(hk);
00504   /* if the key exists, get the default EventMessageFile from the specified
00505      subkey */
00506   if (lRegError == ERROR_SUCCESS)
00507   {
00508     strcat(szTemp, "\\");
00509     strcat(szTemp, szPrimaryMsgFile);
00510     lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
00511     REG_ERR(lRegError, "RegConnectRegistry");
00512     lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
00513     REG_ERR(lRegError, "RegOpenKeyEx");
00514     RegCloseKey(hklm);
00515     dwcbData = MAX_PATH;
00516     lRegError = RegQueryValueEx(hk,  // handle of key to query
00517         "EventMessageFile",          // value name
00518         NULL,                        // must be NULL
00519         &dwType,                     // address of type value
00520         szPrimaryMsgFile,            // path(s) to message DLL
00521         &dwcbData);                  // length of value data
00522     REG_ERR(lRegError, "RegQueryValueEx");
00523     RegCloseKey(hk);
00524   }
00525
00526   pevlr = (EVENTLOGRECORD *) &bBuffer;
00527   /* Opening the log positions the file pointer for this handle at the
00528      beginning of the log. Read records sequentially until there are no more
00529      records. */
00530   while (bSuccess = ReadEventLog(hLog,  // event-log handle
00531           EVENTLOG_FORWARDS_READ |      // read forward
00532           EVENTLOG_SEQUENTIAL_READ,     // sequential read
00533           0,                            // ignored for sequential reads
00534           bBuffer,                      // address of buffer
00535           sizeof(bBuffer),              // size of buffer
00536           &dwRead,                      // count of bytes read
00537           &dwNeeded))                   // bytes in next record
00538   {
00539     while (dwRead > 0)
00540     {
00541       /* Print the event ID, type, source name, and category. The source name
00542          is just past the end of the formal structure. */
00543       printf("\n%03d  Event ID: 0x%08X  EventType: ", dwThisRecord++,
00544           pevlr->EventID);
00545       switch (pevlr->EventType)
00546       {
00547         case EVENTLOG_ERROR_TYPE:
00548           printf("EVENTLOG_ERROR_TYPE");
00549           break;
00550         case EVENTLOG_WARNING_TYPE:
00551           printf("EVENTLOG_WARNING_TYPE");
00552           break;
00553         case EVENTLOG_INFORMATION_TYPE:
00554           printf("EVENTLOG_INFORMATION_TYPE");
00555           break;
00556         case EVENTLOG_AUDIT_SUCCESS:
00557           printf("EVENTLOG_AUDIT_SUCCESS");
00558           break;
00559         case EVENTLOG_AUDIT_FAILURE:
00560           printf("EVENTLOG_AUDIT_FAILURE");
00561           break;
00562         default:
00563           printf("UNKNOWN");
00564           break;
00565       }
00566
00567       printf("\nSource: %s", (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)));
00568       // mask off the actual message number and show it
00569       printf("  Message ID: %d", pevlr->EventID & MSG_ID_MASK);
00570
00571       /* From the event log source name, we know the name of the registry key
00572          to look under for the list of the message DLLs that may contain the
00573          message we need to extract with FormatMessage. Get the event log
00574          source name list... */
00575       // The source name follows the EVENTLOGRECORD structure
00576       sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
00577           pszLogName, (PTCHAR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)));
00578       /* Now open this key and get the EventMessageFile value, which is the
00579          list of the message DLLs for that source */
00580       lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
00581       REG_ERR(lRegError, "RegConnectRegistry");
00582       lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
00583       REG_ERR(lRegError, "RegOpenKeyEx");
00584       RegCloseKey(hklm);
00585       // first, look up the path(s) to the category message DLL
00586       dwcbData = MAX_PATH;
00587       lRegError = RegQueryValueEx(hk,  // handle of key to query
00588           "CategoryMessageFile",       // value name
00589           NULL,                        // must be NULL
00590           &dwType,                     // address of type value
00591           szTemp,                      // path to category message DLL
00592           &dwcbData);                  // length of value data
00593         REG_ERR(lRegError, "RegQueryValueEx");
00594
00595       // get the string from the category DLL
00596       p = lookupStringFromMsgDll(hk, pevlr->EventCategory, 0, NULL, szTemp);
00597       printf("  Category: %s", p);
00598
00599       // print out the user's account name if the SID was logged in the record
00600       if (pevlr->UserSidLength)
00601       {
00602         UCHAR szAccountName[64], szDomainName[64];
00603         DWORD cbAccountSize, cbDomainSize;
00604         SID_NAME_USE snu;
00605         PSID psid;
00606
00607         /* get the user name associated with the Security identifier (SID)
00608            in the event log record */
00609         psid = (PSID)((LPBYTE) pevlr + pevlr->UserSidOffset);
00610         cbAccountSize = sizeof(szAccountName);
00611         cbDomainSize = sizeof(szDomainName);
00612         bSuccess = LookupAccountSid(NULL, psid, szAccountName, &cbAccountSize,
00613             szDomainName, &cbDomainSize, &snu);
00614         PERR(bSuccess, "LookupAccountSid");
00615         printf("  User: %s", bSuccess ? szAccountName : "NA");
00616       }
00617
00618       // now look up the path(s) to the message DLL to get the message text
00619       dwcbData = MAX_PATH;
00620       lRegError = RegQueryValueEx(hk,  // handle of key to query
00621           "EventMessageFile",          // value name
00622           NULL,                        // must be NULL
00623           &dwType,                     // address of type value
00624           szTemp,                      // path(s) to message DLL
00625           &dwcbData);                  // length of value data
00626       // if the message file isn't there, and a default exists, use default
00627       if (lRegError == ERROR_FILE_NOT_FOUND && szPrimaryMsgFile[0])
00628         strcpy(szTemp, szPrimaryMsgFile);
00629       else
00630         REG_ERR(lRegError, "RegQueryValueEx");
00631
00632       /* get the message from the message DLL, replacing parameters and
00633          replaceable parameter strings as appropriate */
00634       p = lookupStringFromMsgDll(hk, pevlr->EventID, pevlr->NumStrings,
00635           (PTCHAR) ((LPBYTE) pevlr + pevlr->StringOffset), szTemp);
00636       printf("\nMessage: %s\n", p);
00637
00638       // Subtract the size of the event log record we just read
00639       dwRead -= pevlr->Length;
00640       // Point to the next event log record in the buffer
00641       pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length);
00642       RegCloseKey(hk);  // close key for this event source
00643     } // while
00644     /* reset our event log record pointer back to the beginning of the buffer
00645        in preparation for reading the next record. */
00646     pevlr = (EVENTLOGRECORD *) &bBuffer;
00647   } // while
00648   if (GetLastError() != ERROR_HANDLE_EOF)
00649     PERR(bSuccess, "ReadEventLog");
00650   RegCloseKey(hk);
00651   if (!hEventLog)  // if we had to open the event log, close it
00652   {
00653     bSuccess = CloseEventLog(hLog);
00654     PERR(bSuccess, "CloseEventLog");
00655   }
00656   return;
00657 } // queryEventLog
00658
00659 void usage()
00660 {
00661   puts("log [logname] [backuplog]>");
00662   puts("[logname] is an optional eventlog category such as Application, Security,"
00663       " or System."
00664       "[backuplog] is the filename of a backup log file to view. If this\n"
00665       "parameter is specified, [logname] must be given as well.");
00666   return;
00667 } // usage()
00668
00669 void notifyChange(LPCTSTR logSource)
00670 {
00671   BOOL bSuccess;
00672   HANDLE hEventLog, hEvent;
00673   DWORD dwWaitResult;
00674
00675   hEvent = CreateEvent(NULL,    // address of security attributes
00676       FALSE,                    // no manual reset
00677       FALSE,                    // create as not signaled
00678       NULL);                    // event name
00679   hEventLog = OpenEventLog(MACHINE,  // open on machine defined elsewhere
00680       logSource);                 // event log source name
00681   PERR(hEventLog, "OpenEventLog");
00682   bSuccess = NotifyChangeEventLog(hEventLog,
00683       hEvent);
00684   PERR(bSuccess, "NotifyChangeEventLog");
00685   dwWaitResult = WaitForSingleObject(hEvent, INFINITE);
00686   if (dwWaitResult != WAIT_FAILED)
00687     printf("**Notification: %s has changed\n", logSource);
00688   else
00689     PERR(dwWaitResult == WAIT_FAILED, "EventLogNotifyProc");
00690   CloseHandle(hEvent);
00691   CloseHandle(hEventLog);
00692   return;
00693 } // notifyChange
00694
00695 #define LOGNAME "Application"
00696 #define LOGSOURCE "LogSample"
00697
00698 int main(int argc, char *argv[])
00699 {
00700   TCHAR szMsgPath[MAX_PATH];
00701   PTCHAR aInsertStrs[16];  // array of pointers to insert strings
00702   TCHAR szTemp[MAX_PATH];
00703   BOOL bSuccess;
00704   HANDLE hEventLog;
00705   OSVERSIONINFO osv;
00706
00707   // Check to make sure we are running on Windows NT
00708   osv.dwOSVersionInfoSize = sizeof(osv);
00709   bSuccess = GetVersionEx(&osv);
00710   if (osv.dwPlatformId != VER_PLATFORM_WIN32_NT)
00711   {
00712     MessageBox(NULL, "Sorry, this application requires Windows NT.\n"
00713         "This application will now terminate.",
00714         "Error", MB_OK);
00715     return (1);
00716   }
00717
00718   if (argc == 1)  // no args, use default defines
00719   {
00720     /* set up a notification event thread that will print a message when the
00721        first message is added to LOGSOURCE. This will only work for local
00722        logging. */
00723     if (MACHINE == NULL)
00724       _beginthread(notifyChange, 0, LOGSOURCE);
00725
00726     /* Set the Event-ID message-file name. For local logging, we assume that
00727        the message DLL is in the same directory as this application. For
00728        remote logging, this sample will access the message DLL over the net
00729        via a UNC name for simplicity. This will be very slow when reading a
00730        large number of events from the eventlog. */
00731     if (MACHINE == NULL)
00732       GetCurrentDirectory(sizeof(szMsgPath), szMsgPath);
00733     else
00734       strcpy(szMsgPath, REMOTE_MSG_DLL_PATH);
00735     strcat(szMsgPath, "\\messages.dll");
00736     addSourceToRegistry(LOGNAME, LOGSOURCE, szMsgPath);
00737
00738     // clear the event log
00739     hEventLog = OpenEventLog(MACHINE,  // open on machine defined elsewhere
00740         LOGSOURCE);                 // event log source name
00741     PERR(hEventLog, "OpenEventLog");
00742     bSuccess = ClearEventLog(hEventLog, NULL);
00743     PERR(bSuccess, "ClearEventLog");
00744     // can't use the log handle now that it's been cleared, we must close it
00745     bSuccess = CloseEventLog(hEventLog);
00746     PERR(bSuccess, "CloseEventLog");
00747
00748     // Set up our array of insert strings for our error message
00749     reportAnEvent(LOGSOURCE,  // source name
00750         MSG_BAD_COMMAND,      // the message to log
00751         CAT_1,                // category
00752         0,                    // number of insert strings
00753         aInsertStrs);         // the array of insert strings
00754     reportAnEvent(LOGSOURCE,  // source name
00755         MSG_BAD_PARM1,        // the message to log
00756         CAT_3,                // category
00757         0,                    // number of insert strings
00758         aInsertStrs);         // the array of insert strings
00759     reportAnEvent(LOGSOURCE,  // source name
00760         MSG_STRIKE_ANY_KEY,   // the message to log
00761         CAT_2,                // category
00762         0,                    // number of insert strings
00763         aInsertStrs);         // the array of insert strings
00764     aInsertStrs[0] = "2,567";
00765     aInsertStrs[1] = "10";
00766     reportAnEvent(LOGSOURCE,  // source name
00767         MSG_RETRYS,           // the message to log
00768         CAT_1,                // category
00769         2,                    // number of insert strings
00770         aInsertStrs);         // the array of insert strings
00771     strcpy(szTemp, "%%");
00772     itoa(SPROCKETS, szTemp + 2, 10);  // concatenate the value
00773     aInsertStrs[0] = "foo.dat";
00774     aInsertStrs[1] = szTemp;
00775     reportAnEvent(LOGSOURCE,    // source name
00776         MSG_FILE_BAD_CONTENTS,  // the message to log
00777         CAT_1,                  // category
00778         2,                      // number of insert strings
00779         aInsertStrs);           // the array of insert strings
00780     aInsertStrs[0] = "a:";
00781     reportAnEvent(LOGSOURCE,    // source name
00782         MSG_INSERT_DISK,        // the message to log
00783         CAT_1,                  // category
00784         1,                      // number of insert strings
00785         aInsertStrs);           // the array of insert strings
00786     queryEventLog(NULL, LOGNAME, LOGSOURCE);  // query the log
00787   }
00788   else
00789   {  // we've got parameters
00790     if (argc > 1 && !strcmpi(argv[1], "Application") ||
00791         !strcmpi(argv[1], "Security") || !strcmpi(argv[1], "System"))
00792     {
00793       if (argc > 2)  // got a backup log name
00794       {
00795         hEventLog = OpenBackupEventLog(NULL, argv[2]); // must be local
00796         if (hEventLog)
00797         {
00798           queryEventLog(hEventLog, argv[1], NULL);  // dump the backup log
00799           bSuccess = CloseEventLog(hEventLog);
00800           PERR(bSuccess, "CloseEventLog");
00801         }
00802         else
00803         {  // 2nd arg was bad
00804           printf("can't open backup eventlog %s\n", argv[2]);
00805           PERR(hEventLog, "OpenBackupEventLog");
00806           usage();
00807         }
00808       }
00809       else
00810       {  // only got logname, dump it
00811         HKEY hk, hklm;
00812         FILETIME ft;
00813         LONG lRegError;
00814         DWORD cchName = sizeof(szTemp);
00815
00816         // get arbitrary subkey of param to be used to open event log
00817         sprintf(szTemp, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s",
00818             argv[1]);
00819         lRegError = RegConnectRegistry(MACHINE, HKEY_LOCAL_MACHINE, &hklm);
00820         REG_ERR(lRegError, "RegConnectRegistry");
00821         lRegError = RegOpenKeyEx(hklm, szTemp, 0, KEY_READ, &hk);
00822         REG_ERR(lRegError, "RegOpenKeyEx");
00823         RegCloseKey(hklm);
00824         lRegError = RegEnumKeyEx(hk, 0, szTemp, &cchName, NULL,
00825             NULL, NULL, &ft);
00826         REG_ERR(lRegError, "RegEnumKeyEx");
00827         queryEventLog(NULL, argv[1], szTemp);  // query the log
00828       }
00829     }
00830     else  // first arg was bad
00831       usage();
00832   }  // else
00833   return (0);
00834 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MISC.C Source File

  • NETDDE

MISC.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   misc.c
00009 //
00010 //  PURPOSE:  Contains all helper functions "global" to the application.
00011 //
00012 //  FUNCTIONS:
00013 //    CenterWindow - Center one window over another.
00014 //
00015 //  COMMENTS:
00016 //
00017 //
00018
00019 #include <windows.h>            // required for all Windows applications
00020 #include <windowsx.h>
00021
00022 #ifdef WIN16
00023 #include "win16ext.h"           // required only for win16 applications
00024 #endif
00025 #include "globals.h"            // prototypes specific to this application
00026
00027
00028
00029 //
00030 //  FUNCTION: CenterWindow(HWND, HWND)
00031 //
00032 //  PURPOSE:  Center one window over another.
00033 //
00034 //  PARAMETERS:
00035 //    hwndChild - The handle of the window to be centered.
00036 //    hwndParent- The handle of the window to center on.
00037 //
00038 //  RETURN VALUE:
00039 //
00040 //    TRUE  - Success
00041 //    FALSE - Failure
00042 //
00043 //  COMMENTS:
00044 //
00045 //    Dialog boxes take on the screen position that they were designed
00046 //    at, which is not always appropriate. Centering the dialog over a
00047 //    particular window usually results in a better position.
00048 //
00049
00050 BOOL CenterWindow(HWND hwndChild, HWND hwndParent)
00051 {
00052     RECT    rcChild, rcParent;
00053     int     cxChild, cyChild, cxParent, cyParent;
00054     int     cxScreen, cyScreen, xNew, yNew;
00055     HDC     hdc;
00056
00057     // Get the Height and Width of the child window
00058     GetWindowRect(hwndChild, &rcChild);
00059     cxChild = rcChild.right - rcChild.left;
00060     cyChild = rcChild.bottom - rcChild.top;
00061
00062     // Get the Height and Width of the parent window
00063     GetWindowRect(hwndParent, &rcParent);
00064     cxParent = rcParent.right - rcParent.left;
00065     cyParent = rcParent.bottom - rcParent.top;
00066
00067     // Get the display limits
00068     hdc = GetDC(hwndChild);
00069     cxScreen = GetDeviceCaps(hdc, HORZRES);
00070     cyScreen = GetDeviceCaps(hdc, VERTRES);
00071     ReleaseDC(hwndChild, hdc);
00072
00073     // Calculate new X position, then adjust for screen
00074     xNew = rcParent.left + ((cxParent - cxChild) / 2);
00075     if (xNew < 0)
00076     {
00077         xNew = 0;
00078     }
00079     else if ((xNew + cxChild) > cxScreen)
00080     {
00081         xNew = cxScreen - cxChild;
00082     }
00083
00084     // Calculate new Y position, then adjust for screen
00085     yNew = rcParent.top  + ((cyParent - cyChild) / 2);
00086     if (yNew < 0)
00087     {
00088         yNew = 0;
00089     }
00090     else if ((yNew + cyChild) > cyScreen)
00091     {
00092         yNew = cyScreen - cyChild;
00093     }
00094
00095     // Set it, and return
00096     return SetWindowPos(hwndChild,
00097                         NULL,
00098                         xNew, yNew,
00099                         0, 0,
00100                         SWP_NOSIZE | SWP_NOZORDER);
00101 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MDI_/MDI.H Source File

  • MDI_

MDI.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 #include <windows.h>
00014 #include <string.h>
00015
00016 /*
00017  * Menu ID's
00018  */
00019 #define MM_ABOUT        8000
00020 #define MM_MDI          8001
00021 #define MM_RESERVE1     8002
00022 #define MM_RESERVE2     8003
00023
00024 #define MM_OPT_1        7001
00025 #define MM_OPT_2        7002
00026 #define MM_OPT_3        7003
00027 #define MM_OPT_4        7004
00028 #define MM_OPT_5        7005
00029 #define MM_OPT_6        7006
00030 #define MM_OPT_7        7007
00031 #define MM_OPT_8        7008
00032
00033 #define IDM_CASCADE     30
00034 #define IDM_TILE        31
00035 #define IDM_ARRANGE     32
00036 #define IDM_CLOSEALL    33
00037
00038 #define SIZEOFCAPTIONTEXT       20
00039
00040 #define ACCEL_ID        100
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/MASKBLT.C Source File

  • MASKBLT

MASKBLT.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  maskblt.c -- sample program demonstrating MaskBlt()
00014 *
00015 *  design:  There is one main window with one dialog box maskblted to fill
00016 *   the top of it.  The parameters for the MaskBlt() are stored in the
00017 *   entry fields of this dialog box.  The user may change these values and
00018 *   see the effect on the blt.  The top dialog also offers a chance to
00019 *   select from standard raster operations.
00020 *
00021 *  other modules:  track.c  bitmap.c
00022 *   (these other 2 modules are the same for all of the XBlt samples,
00023 *   i.e. STREBLT, PLGBLT, ...)
00024 *
00025 \**************************************************************************/
00026
00027 #include <windows.h>
00028 #include <commdlg.h>
00029 #include <math.h>
00030 #include <stdio.h>
00031 #include "maskblt.h"
00032 #include "track.h"
00033 #include "bitmap.h"
00034
00035
00036 /* Global variables */
00037 HANDLE hInst;
00038 HWND   hwndMain, hwndDlg;
00039
00040 PTrackObject ptoSrc, ptoDest, ptoMask = NULL;
00041 HDC          hdcSrc, hdcDest, hdcMask;
00042 HBITMAP      hbmSrc = NULL;
00043 HBITMAP      hbmMask = NULL;
00044
00045 #define NONE -1
00046 int iPatternBrush = NONE;
00047
00048
00049
00050 /**************************************************************************\
00051 *
00052 *  function:  WinMain()
00053 *
00054 *  input parameters:  c.f. generic sample
00055 *
00056 \**************************************************************************/
00057 int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
00058                     LPSTR lpCmdLine, int nCmdShow)
00059 {
00060     MSG   msg;
00061     RECT rect;
00062     HANDLE haccel;
00063
00064
00065     UNREFERENCED_PARAMETER( lpCmdLine );
00066
00067     // check if running on Windows NT, if not, display notice and terminate
00068     if( GetVersion() & 0x80000000 )
00069     {
00070        MessageBoxA( NULL,
00071            "This sample application can only be run on Windows NT.\n"
00072            "This application will now terminate.",
00073            "MaskBlt",
00074            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00075         return( 1 );
00076      }
00077
00078     /* Check for previous instance.  If none, then register class. */
00079     if (!hPrevInstance) {
00080         WNDCLASS  wc;
00081
00082         wc.style = 0;
00083         wc.lpfnWndProc = (WNDPROC)MainWndProc;
00084
00085         wc.cbClsExtra = 0;
00086         wc.cbWndExtra = 0;
00087         wc.hInstance = hInstance;
00088         wc.hIcon = LoadIcon(hInstance, "MaskBltIcon");
00089         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00090         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00091         wc.lpszMenuName =  NULL;
00092         wc.lpszClassName = "MaskBlt";
00093
00094         if (!RegisterClass(&wc)) return (FALSE);
00095     }  /* class registered o.k. */
00096
00097
00098     /* Create the main window.  Return false if CreateWindow() fails */
00099     hInst = hInstance;
00100
00101     hwndMain = CreateWindow(
00102         "MaskBlt",
00103         "MaskBlt",
00104         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
00105         CW_USEDEFAULT,
00106         CW_USEDEFAULT,
00107         CW_USEDEFAULT,
00108         CW_USEDEFAULT,
00109         NULL,
00110         NULL,
00111         hInstance,
00112         NULL);
00113
00114     if (!hwndMain) return (FALSE);
00115
00116
00117     /* create the top dialog as a child of the main window. */
00118     hwndDlg = CreateDialog (hInst, "maskbltDlg", hwndMain, (DLGPROC)DlgProc);
00119
00120     /* Send main window a WM_SIZE message so that it will size the top
00121      *  dialog correctly.
00122      */
00123     GetClientRect (hwndMain, &rect);
00124     SendMessage (hwndMain, WM_SIZE, 0, (rect.right - rect.left));
00125     ShowWindow (hwndDlg, SW_SHOW);
00126     ShowWindow(hwndMain, nCmdShow);
00127
00128
00129     /* Load the accelerator table that provides clipboard support. */
00130     haccel = LoadAccelerators (hInst, "bltAccel");
00131
00132
00133     /* Loop getting messages and dispatching them. */
00134     while (GetMessage(&msg,NULL, 0,0)) {
00135       if (!TranslateAccelerator(hwndMain, haccel, &msg))
00136       if (!IsDialogMessage (hwndDlg, &msg)){
00137         DispatchMessage(&msg);
00138       }
00139     }
00140
00141     /* Return the value from PostQuitMessage */
00142     return (msg.wParam);
00143 }
00144
00145
00146
00147
00148 /**************************************************************************\
00149 *
00150 *  function:  MainWndProc()
00151 *
00152 *  input parameters:  normal window procedure parameters.
00153 *
00154 *  There are 6 different HDCs used for the main window (in addition to the
00155 *   temporary one returned from BeginPaint).  There are two for each of the
00156 *   three thirds of the window.  The first one contains the bitmap.  The
00157 *   second one is for the track object and is stored in the TRACKOBJECT
00158 *   structure.
00159 *
00160 *  global variables:
00161 *   hwndDlg - dialog with entry fields containing parameters.
00162 *   ptoDest, ptoSrc, ptoMask - pointers to the direct manipulation objects
00163 *   hdcDest, hdcSrc, hdcMask - HDCs for the 3 sub regions of the window.
00164 *   hbmSrc, hbmMask          - bitmap handles for source and mask.
00165 *   iPatternBrush - Selection from combo box, set into the hdc.
00166 \**************************************************************************/
00167 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00168 {
00169 static int miniWidth;
00170 static RECT rect;
00171 static HANDLE hPenGrid, hPenSeparator;
00172
00173   switch (message) {
00174
00175     /**********************************************************************\
00176     *  WM_CREATE
00177     *
00178     * Get three new HDCs, then create three new track objects.
00179     *  Each track object has different allowed tracking modes.
00180     *  Finally create two pens for drawing later on.
00181     \**********************************************************************/
00182     case WM_CREATE:
00183         hdcSrc  = GetDC (hwnd);
00184         hdcDest = GetDC (hwnd);
00185         hdcMask = GetDC (hwnd);
00186
00187         ptoDest = doTrackObject (NULL, TROB_NEW, hwnd,0);
00188         ptoDest->allowedModes = TMMOVE | TMSIZEXY;
00189         ptoSrc  = doTrackObject (NULL, TROB_NEW, hwnd,0);
00190         ptoSrc->allowedModes = TMMOVE;
00191         ptoMask = doTrackObject (NULL, TROB_NEW, hwnd,0);
00192         ptoMask->allowedModes = TMMOVE;
00193
00194         hPenGrid      = CreatePen (PS_SOLID, 1, GRIDCOLOR);
00195         hPenSeparator = CreatePen (PS_SOLID, 2*SEPARATORWIDTH, (COLORREF) 0x01000000);
00196     break;
00197
00198
00199     /**********************************************************************\
00200     *  WM_DESTROY
00201     *
00202     * Complement of WM_CREATE.  Free up all of the HDCs, send all of the
00203     *  track objects their delete messages, delete the pens,
00204     *  then call PostQuitMessage.
00205     \**********************************************************************/
00206     case WM_DESTROY:
00207         ReleaseDC (hwnd, hdcSrc );
00208         ReleaseDC (hwnd, hdcDest);
00209         ReleaseDC (hwnd, hdcMask);
00210         doTrackObject (ptoDest, TROB_DELETE, hwnd,0);
00211         doTrackObject (ptoSrc , TROB_DELETE, hwnd,0);
00212         doTrackObject (ptoMask, TROB_DELETE, hwnd,0);
00213
00214         DeleteObject(hPenGrid);
00215         DeleteObject(hPenSeparator);
00216
00217         PostQuitMessage(0);
00218     break;
00219
00220
00221
00222     /**********************************************************************\
00223     *  WM_SIZE
00224     *
00225     * Stretch the top dialog to fill the width of the main window.
00226     * Adjust the viewport origins of the 6 HDCs.
00227     * Set the clip regions of the 6 HDCs.
00228     \**********************************************************************/
00229     case WM_SIZE: {
00230         HRGN hrgn;
00231
00232         SetWindowPos (hwndDlg, NULL, 0,0, LOWORD(lParam), DIALOGHEIGHT, 0);
00233
00234         GetClientRect (hwndMain, &rect);
00235         miniWidth = rect.right/3;
00236
00237         SetViewportOrgEx (hdcDest,      0,           DIALOGHEIGHT, NULL);
00238         SetViewportOrgEx (ptoDest->hdc, 0,           DIALOGHEIGHT, NULL);
00239         SetViewportOrgEx (hdcSrc,       miniWidth,   DIALOGHEIGHT, NULL);
00240         SetViewportOrgEx (ptoSrc->hdc,  miniWidth,   DIALOGHEIGHT, NULL);
00241         SetViewportOrgEx (hdcMask,      2*miniWidth, DIALOGHEIGHT, NULL);
00242         SetViewportOrgEx (ptoMask->hdc, 2*miniWidth, DIALOGHEIGHT, NULL);
00243
00244         ptoDest->rectClip.left    = 0;
00245         ptoDest->rectClip.top     = DIALOGHEIGHT;
00246         ptoDest->rectClip.right   = miniWidth-2*SEPARATORWIDTH;
00247         ptoDest->rectClip.bottom  = rect.bottom;
00248         hrgn = CreateRectRgnIndirect (&ptoDest->rectClip);
00249         SelectClipRgn (hdcDest,      hrgn);
00250         SelectClipRgn (ptoDest->hdc, hrgn);
00251         DeleteObject (hrgn);
00252
00253         ptoSrc->rectClip.left    = miniWidth;
00254         ptoSrc->rectClip.top     = DIALOGHEIGHT;
00255         ptoSrc->rectClip.right   = 2*miniWidth-2*SEPARATORWIDTH;
00256         ptoSrc->rectClip.bottom  = rect.bottom;
00257         hrgn = CreateRectRgnIndirect (&ptoSrc->rectClip);
00258         SelectClipRgn (hdcSrc,       hrgn);
00259         SelectClipRgn (ptoSrc->hdc,  hrgn);
00260         DeleteObject (hrgn);
00261
00262         ptoMask->rectClip.left    = 2*miniWidth;
00263         ptoMask->rectClip.top     = DIALOGHEIGHT;
00264         ptoMask->rectClip.right   = 3*miniWidth;
00265         ptoMask->rectClip.bottom  = rect.bottom;
00266         hrgn = CreateRectRgnIndirect (&ptoMask->rectClip);
00267         SelectClipRgn (hdcMask,      hrgn);
00268         SelectClipRgn (ptoMask->hdc, hrgn);
00269         DeleteObject (hrgn);
00270
00271         SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD)hdcDest, (LONG)ptoDest);
00272         SendMessage (hwndDlg, WM_PUTUPSRCRECT,  (DWORD)hdcSrc,  (LONG)ptoSrc);
00273         SendMessage (hwndDlg, WM_PUTUPMASKPT,   (DWORD)hdcMask, (LONG)ptoMask);
00274
00275         /* repaint the whole window. */
00276         InvalidateRect (hwnd, NULL, TRUE);
00277     } break;
00278
00279
00280
00281     /**********************************************************************\
00282     *  WM_PAINT
00283     *
00284     * miniWidth, rect -- set by WM_SIZE message.
00285     *
00286     * First shift the viewport origin down so that 0,0 is the top left
00287     *  most visible point (out from underneath the top dialog).  Second,
00288     *  draw the grid with wider lines on the axes.  Finally, read the
00289     *  values out of the top dialog, do elementary validation, and then
00290     *  try to call MaskBlt() with the values.
00291     \**********************************************************************/
00292      case WM_PAINT: {
00293         HDC hdc;
00294         PAINTSTRUCT ps;
00295
00296         hdc = BeginPaint(hwnd, &ps);
00297
00298         /* Draw Separator lines for the three miniareas */
00299         SelectObject(hdc, hPenSeparator);
00300         MoveToEx (hdc,   miniWidth-SEPARATORWIDTH,0, NULL);
00301         LineTo   (hdc,   miniWidth-SEPARATORWIDTH, rect.bottom);
00302         MoveToEx (hdc, 2*miniWidth-SEPARATORWIDTH,0, NULL);
00303         LineTo   (hdc, 2*miniWidth-SEPARATORWIDTH, rect.bottom);
00304
00305         /* Grid the HDCs */
00306         SelectObject(hdcSrc, hPenGrid);
00307         DrawGrids (hdcSrc, miniWidth, rect.bottom);
00308         SelectObject(hdcMask, hPenGrid);
00309         DrawGrids (hdcMask, miniWidth, rect.bottom);
00310
00311         /* Draw bitmaps if any, then draw track objects over them. */
00312         if (hbmSrc)  DrawBitmap (hdcSrc, hbmSrc);
00313         if (hbmMask) DrawBitmap (hdcMask, hbmMask);
00314         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00315         doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);
00316
00317         /* paint the left third of the window. */
00318         SendMessage (hwnd, WM_MASKBLT, 0,0);
00319
00320         EndPaint (hwnd, &ps);
00321     } return FALSE;
00322
00323
00324
00325     /**********************************************************************\
00326     *  WM_MASKBLT
00327     *
00328     * WM_USER message.  This paints the left third of the window.  It
00329     *  is called on the WM_PAINT message.  It is separated out here because
00330     *  it is common for just the MaskBlt() to need to be called and not the
00331     *  whole window painted.
00332     \**********************************************************************/
00333     case WM_MASKBLT: {
00334         int X, Y, nWidth, nHeight;
00335         int XSrc, YSrc, XMask, YMask;
00336         DWORD rop, ropByte;
00337         char buffer[MAXCHARS];
00338
00339         BOOL success;
00340         RECT cliprect;
00341
00342         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00343         doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);
00344
00345         GetClipBox (hdcDest, &cliprect);
00346         FillRect (hdcDest, &cliprect,
00347                   (HBRUSH) GetClassLong (hwnd, GCL_HBRBACKGROUND));
00348         SelectObject(hdcDest, hPenGrid);
00349
00350         DrawGrids (hdcDest, miniWidth, rect.bottom);
00351         if (IsWindow(hwndDlg)) {
00352
00353           /* Grab points out of the dialog entry fields. */
00354           X =      GetDlgItemInt(hwndDlg, DID_X,      &success, TRUE);
00355           Y =      GetDlgItemInt(hwndDlg, DID_Y,      &success, TRUE);
00356           nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH,  &success, TRUE);
00357           nHeight= GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);
00358
00359           XSrc =   GetDlgItemInt(hwndDlg, DID_XSRC,   &success, TRUE);
00360           YSrc =   GetDlgItemInt(hwndDlg, DID_YSRC,   &success, TRUE);
00361           XMask =  GetDlgItemInt(hwndDlg, DID_XMASK,  &success, TRUE);
00362           YMask =  GetDlgItemInt(hwndDlg, DID_YMASK,  &success, TRUE);
00363
00364           /* get high order ROP byte and shift left by two bytes. */
00365           GetDlgItemText(hwndDlg, DID_ROP0, buffer, MAXCHARS);
00366           sscanf (buffer, "%lx", &ropByte);
00367           rop = ropByte * 256 * 256 * 256;
00368
00369           /* get the next ROP byte and shift left by one byte. */
00370           GetDlgItemText(hwndDlg, DID_ROP1, buffer, MAXCHARS);
00371           sscanf (buffer, "%lx", &ropByte);
00372           rop += ropByte * 256 * 256;
00373
00374           /* get the next ROP byte and shift left by one byte. */
00375           GetDlgItemText(hwndDlg, DID_ROP2, buffer, MAXCHARS);
00376           sscanf (buffer, "%lx", &ropByte);
00377           rop += ropByte * 256;
00378
00379           /* finally, get the low order ROP byte. */
00380           GetDlgItemText(hwndDlg, DID_ROP3, buffer, MAXCHARS);
00381           sscanf (buffer, "%lx", &ropByte);
00382           rop += ropByte;
00383
00384           /* select the pattern brush.  (user selects via combo box.) */
00385           if (iPatternBrush != NONE)
00386             SelectObject (hdcDest, GetStockObject (iPatternBrush));
00387
00388
00389           /**********************************************************/
00390           /**********************************************************/
00391           MaskBlt (hdcDest, X, Y, nWidth, nHeight,
00392                   hdcSrc, XSrc, YSrc,
00393                   hbmMask, XMask, YMask, rop);
00394           /**********************************************************/
00395           /**********************************************************/
00396         }
00397         doTrackObject (ptoSrc , TROB_PAINT, hwnd, 0);
00398         doTrackObject (ptoMask, TROB_PAINT, hwnd, 0);
00399     } break;
00400
00401
00402
00403     /**********************************************************************\
00404     *  WM_LBUTTONDOWN & WM_RBUTTONDOWN
00405     * On button down messages, hittest on the track object, and if
00406     *  it returns true, then send these messages to the track object.
00407     \**********************************************************************/
00408     case WM_RBUTTONDOWN:
00409     case WM_LBUTTONDOWN:
00410       if (doTrackObject(ptoDest, TROB_HITTEST, hwnd, lParam))
00411          doTrackObject(ptoDest, message, hwnd, lParam);
00412       else if (doTrackObject(ptoSrc, TROB_HITTEST, hwnd, lParam))
00413          doTrackObject(ptoSrc, message, hwnd, lParam);
00414       else if (doTrackObject(ptoMask, TROB_HITTEST, hwnd, lParam))
00415          doTrackObject(ptoMask, message, hwnd, lParam);
00416     break;
00417
00418
00419
00420     /**********************************************************************\
00421     *  WM_LBUTTONUP & WM_RBUTTONDOWN & MW_MOUSEMOVE
00422     * If the track object is in a "tracking mode" then send it these messages.
00423     *  If the transform dialog is not minimized, fill it with numbers.
00424     *  If the mouse dialog is not minimized, fill it with numbers.
00425     \**********************************************************************/
00426     case WM_RBUTTONUP:
00427     case WM_LBUTTONUP:
00428       /* user action complete.  Force MaskBlt() update. */
00429       PostMessage (hwndMain, WM_MASKBLT, 0,0);
00430     case WM_MOUSEMOVE:
00431       if (ptoDest->Mode) {
00432         doTrackObject(ptoDest, message, hwnd, lParam);
00433         SendMessage (hwndDlg, WM_PUTUPDESTRECT, (DWORD) hdcDest, (LONG) ptoDest);
00434       }
00435       if (ptoSrc->Mode) {
00436         doTrackObject(ptoSrc, message, hwnd, lParam);
00437         SendMessage (hwndDlg, WM_PUTUPSRCRECT, (DWORD) hdcSrc, (LONG) ptoSrc);
00438       }
00439
00440       if (ptoMask->Mode) {
00441         doTrackObject(ptoMask, message, hwnd, lParam);
00442         SendMessage (hwndDlg, WM_PUTUPMASKPT, (DWORD) hdcMask, (LONG) ptoMask);
00443       }
00444
00445     break;
00446
00447
00448
00449     /**********************************************************************\
00450     *  Accelerator & clipboard support.
00451     *
00452     * Certain key strokes (c.f. *.rc) will cause the following WM_COMMAND
00453     *  messages.  In response the app will copy a bitmap into the clipboard
00454     *  or paste down from it.  In both cases, it is necessary to create a
00455     *  new bitmap since a bitmap in the clipboard belongs to the clipboard
00456     *  and not to the application.
00457     \**********************************************************************/
00458     case WM_COMMAND:
00459       switch (LOWORD(wParam)) {
00460         HBITMAP hbmCompat, hbmOld;
00461         HDC hdcCompat;
00462
00463         /******************************************************************\
00464         *  WM_COMMAND, AID_COPY
00465         *
00466         * Create a new bitmap, copy the destination HDC bits into it,
00467         *  and send the new bitmap to the clipboard.
00468         \******************************************************************/
00469         case AID_COPY: {
00470           int X,Y, nWidth, nHeight;
00471           BOOL success;
00472
00473           X = GetDlgItemInt(hwndDlg, DID_X, &success, TRUE);
00474           Y = GetDlgItemInt(hwndDlg, DID_Y, &success, TRUE);
00475           nWidth = GetDlgItemInt(hwndDlg, DID_WIDTH, &success, TRUE);
00476           nHeight = GetDlgItemInt(hwndDlg, DID_HEIGHT, &success, TRUE);
00477
00478
00479           hdcCompat = CreateCompatibleDC(hdcDest);
00480           hbmCompat = CreateCompatibleBitmap (hdcDest, nWidth, nHeight);
00481           hbmOld = SelectObject(hdcCompat,hbmCompat);
00482
00483           BitBlt (hdcCompat, 0,0,nWidth, nHeight, hdcDest, X,Y, SRCCOPY );
00484
00485           SelectObject(hdcCompat,hbmOld);
00486           DeleteDC(hdcCompat);
00487
00488           OpenClipboard (hwnd);
00489           SetClipboardData (CF_BITMAP,hbmCompat);
00490           CloseClipboard ();
00491
00492           DeleteObject (hbmCompat);
00493
00494         } break;
00495
00496
00497         /******************************************************************\
00498         *  WM_COMMAND, AID_PASTE
00499         *
00500         * Get bitmap handle from clipboard, create a new bitmap, draw
00501         *  the clipboard bitmap into the new one, and store the new
00502         *  handle in the global hbmSrc.
00503         \******************************************************************/
00504         case AID_PASTE: {
00505           HBITMAP hbm;
00506           BITMAP bm;
00507
00508           OpenClipboard (hwnd);
00509           if ( hbm = GetClipboardData (CF_BITMAP)) {
00510             DeleteObject (hbmSrc);
00511
00512             GetObject (hbm, sizeof(BITMAP), &bm);
00513
00514             hdcCompat = CreateCompatibleDC(hdcDest);
00515             hbmCompat = CreateCompatibleBitmap (hdcDest, bm.bmWidth, bm.bmHeight);
00516             hbmOld = SelectObject(hdcCompat,hbmCompat);
00517
00518             DrawBitmap (hdcCompat, hbm);
00519
00520             SelectObject(hdcCompat,hbmOld);
00521             DeleteDC(hdcCompat);
00522
00523             hbmSrc = hbmCompat;
00524
00525             InvalidateRect (hwnd, &ptoSrc->rectClip, TRUE);
00526             InvalidateRect (hwnd, &ptoDest->rectClip, TRUE);
00527           }
00528           CloseClipboard ();
00529         } break;
00530
00531         /******************************************************************\
00532         *  WM_COMMAND, AID_CYCLE
00533         *
00534         * Post a COPY and PASTE command message to this window so that with
00535         *  one key stroke the user can copy the DEST image into the clipboard,
00536         *  paste it down into the SRC hdc and cause the blt.
00537         \******************************************************************/
00538         case AID_CYCLE:
00539           PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_COPY , 1), 0);
00540           PostMessage (hwnd, WM_COMMAND, MAKELONG (AID_PASTE, 1), 0);
00541         break;
00542       }  /* end switch */
00543
00544     break;  /* end wm_command */
00545
00546
00547
00548   } /* end switch */
00549   return (DefWindowProc(hwnd, message, wParam, lParam));
00550 }
00551
00552
00553
00554
00555 /**************************************************************************\
00556 *
00557 *  function:  DlgProc()
00558 *
00559 *  input parameters:  normal window procedure parameters.
00560 *
00561 *  Respond to user button presses by getting new bitmaps or by sending
00562 *   the main window a WM_MASKBLT message.  Also handle special user messages
00563 *   for updating the entry fields with the contents of the direct manipulation
00564 *   objects.
00565 *
00566 *  global variables:
00567 *   hwndMain - the main window.  also the parent of this dialog
00568 *   ptoDest, ptoSrc, ptoMask - pointers to the direct manipulation objects
00569 *   hdcDest, hdcSrc, hdcMask - HDCs for the 3 sub regions of the window.
00570 *   hbmSrc, hbmMask          - bitmap handles for source and mask.
00571 \**************************************************************************/
00572 BOOL CALLBACK DlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00573 {
00574   char buffer[MAXCHARS];
00575   HBITMAP hbm;
00576
00577
00578   switch (message) {
00579     /**********************************************************************\
00580     *  WM_INITDIALOG
00581     *
00582     * Fill the entry fields with sensible original values.
00583     \**********************************************************************/
00584     case WM_INITDIALOG: {
00585       int i;
00586
00587       for (i = DID_X; i<=  DID_YMASK; i++)
00588         SetDlgItemText(hwnd, i, "0");
00589
00590       /* these are the three bytes from SRCCOPY */
00591       SetDlgItemText(hwnd, DID_ROP0  , "00");
00592       SetDlgItemText(hwnd, DID_ROP1  , "cc");
00593       SetDlgItemText(hwnd, DID_ROP2  , "00");
00594       SetDlgItemText(hwnd, DID_ROP3  , "20");
00595
00596       for (i = 0; i< NROPS; i++)
00597         SendDlgItemMessage (hwnd, DID_CB_ROPS, CB_INSERTSTRING,
00598                             (DWORD) -1, (LONG)StandardROPs[i].String);
00599
00600       for (i = 0; i< NPATTERNS; i++)
00601         SendDlgItemMessage (hwnd, DID_CB_PATTERN, CB_INSERTSTRING,
00602                             (DWORD) -1, (LONG)Patterns[i].String);
00603
00604
00605     } return TRUE;
00606
00607
00608
00609
00610     /**********************************************************************\
00611     *  WM_PUTUPDESTRECT
00612     *
00613     * wParam -  HDC with the needed world transform.
00614     * lParam -  Pointer to the track object.
00615     *
00616     * Fill the entry fields for the destination rectangle points.
00617     *  Conditionally change <x,y> or <width,height> depending on tracking mode.
00618     \**********************************************************************/
00619     case WM_PUTUPDESTRECT: {
00620         POINT p1,p2, origin;
00621         PTrackObject pto;
00622         HDC hdc;
00623
00624         hdc = (HDC) wParam;
00625         pto = (PTrackObject) lParam;
00626         GetViewportOrgEx (hdc, &origin);
00627
00628         p1.x = pto->rect.left;
00629         p1.y = pto->rect.top;
00630         LPtoDP (pto->hdc, &p1, 1);
00631
00632         p2.x = pto->rect.right;
00633         p2.y = pto->rect.bottom;
00634         LPtoDP (pto->hdc, &p2, 1);
00635         p2.x -= p1.x; p2.y -= p1.y;
00636
00637         p1.x -= origin.x; p1.y -= origin.y;
00638
00639         if (!(pto->Mode & TMSIZEXY)) {
00640           SetDlgItemInt(hwnd, DID_X, p1.x, TRUE);
00641           SetDlgItemInt(hwnd, DID_Y, p1.y, TRUE);
00642         }
00643
00644         if (!(pto->Mode & TMMOVE)) {
00645           SetDlgItemInt(hwnd, DID_WIDTH,  p2.x, TRUE);
00646           SetDlgItemInt(hwnd, DID_HEIGHT, p2.y, TRUE);
00647         }
00648     } return FALSE;
00649
00650
00651
00652
00653     /**********************************************************************\
00654     *  WM_PUTUPSRCRECT
00655     *
00656     * wParam -  HDC with the needed world transform.
00657     * lParam -  Pointer to the track object.
00658     *
00659     * Fill the entry fields for the source location point.
00660     \**********************************************************************/
00661     case WM_PUTUPSRCRECT: {
00662         POINT p1, origin;
00663         PTrackObject pto;
00664         HDC hdc;
00665
00666         hdc = (HDC) wParam;
00667         pto = (PTrackObject) lParam;
00668         GetViewportOrgEx (hdc, &origin);
00669
00670         p1.x = pto->rect.left;
00671         p1.y = pto->rect.top;
00672         LPtoDP (pto->hdc, &p1, 1);
00673
00674         p1.x -= origin.x; p1.y -= origin.y;
00675
00676         SetDlgItemInt(hwnd, DID_XSRC, p1.x, TRUE);
00677         SetDlgItemInt(hwnd, DID_YSRC, p1.y, TRUE);
00678
00679     } return FALSE;
00680
00681
00682
00683     /**********************************************************************\
00684     *  WM_PUTUPMASKPT
00685     *
00686     * wParam -  HDC with the needed world transform.
00687     * lParam -  Pointer to the track object.
00688     *
00689     * Fill the entry fields for the mask location point.
00690     \**********************************************************************/
00691     case WM_PUTUPMASKPT: {
00692         POINT p1, origin;
00693         PTrackObject pto;
00694         HDC hdc;
00695
00696         hdc = (HDC) wParam;
00697         pto = (PTrackObject) lParam;
00698         GetViewportOrgEx (hdc, &origin);
00699
00700         p1.x = pto->rect.left;
00701         p1.y = pto->rect.top;
00702         LPtoDP (pto->hdc, &p1, 1);
00703         p1.x -= origin.x; p1.y -= origin.y;
00704
00705         SetDlgItemInt(hwnd, DID_XMASK, p1.x, TRUE);
00706         SetDlgItemInt(hwnd, DID_YMASK, p1.y, TRUE);
00707
00708     } return FALSE;
00709
00710
00711
00712
00713
00714     case WM_COMMAND:
00715       switch (LOWORD(wParam)) {
00716
00717         /******************************************************************\
00718         *  WM_COMMAND, DID_DRAW
00719         *
00720         * Draw button hit - send main window message to call MaskBlt().
00721         \******************************************************************/
00722         case DID_DRAW:
00723           SendMessage (hwndMain, WM_MASKBLT, 0,0);
00724         break;
00725
00726
00727
00728
00729         /**********************************************************************\
00730         *  WM_COMMAND, DID_NEWSRC
00731         *
00732         * Try to get a new source bitmap.  Then
00733         *  invalidate two sub windows so that we force a repaint.
00734         \**********************************************************************/
00735         case DID_NEWSRC:
00736           if ( hbm = GetBitmap (hdcSrc, hInst, FALSE)) {
00737             DeleteObject (hbmSrc);
00738             hbmSrc = hbm;
00739             InvalidateRect (hwndMain, &ptoSrc->rectClip, TRUE);
00740             InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
00741           }
00742         break;
00743
00744         /**********************************************************************\
00745         *  WM_COMMAND, DID_NEWMASK
00746         *
00747         * Try to get a new mask bitmap.  Then
00748         *  invalidate two sub windows so that we force a repaint.
00749         \**********************************************************************/
00750         case DID_NEWMASK:
00751           if ( hbm = GetBitmap (hdcMask, hInst, TRUE)) {
00752             DeleteObject (hbmMask);
00753             hbmMask = hbm;
00754             InvalidateRect (hwndMain, &ptoMask->rectClip, TRUE);
00755             InvalidateRect (hwndMain, &ptoDest->rectClip, TRUE);
00756           }
00757         break;
00758
00759
00760
00761         /******************************************************************\
00762         *  WM_COMMAND, DID_CB_ROPS
00763         *
00764         * A new standard rop entry was selected.  Lookup the value,
00765         *  then break it into four parts, convert to hex, and put
00766         *  it in the proper entry fields.
00767         \******************************************************************/
00768         case DID_CB_ROPS:
00769           if (HIWORD (wParam) == CBN_SELCHANGE) {
00770             int iSel, rop;
00771
00772             iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00773             rop = StandardROPs[iSel].Value;
00774             sprintf (buffer, "%2x", (rop & 0x000000ff));
00775             SetDlgItemText(hwnd, DID_ROP3, buffer);
00776             rop /= 256;
00777             sprintf (buffer, "%2x", (rop & 0x000000ff));
00778             SetDlgItemText(hwnd, DID_ROP2, buffer);
00779             rop /= 256;
00780             sprintf (buffer, "%2x", (rop & 0x000000ff));
00781             SetDlgItemText(hwnd, DID_ROP1, buffer);
00782             rop /= 256;
00783             sprintf (buffer, "%2x", (rop & 0x000000ff));
00784             SetDlgItemText(hwnd, DID_ROP0, buffer);
00785
00786             SendMessage (hwndMain, WM_MASKBLT, 0,0);
00787           }
00788         break;
00789
00790
00791         /******************************************************************\
00792         *  WM_COMMAND, DID_CB_PATTERN
00793         *
00794         * A new pattern brush was selected.  Look up the value, store it
00795         *  in a global variable (iPatternBrush), then force a new StretchBlt
00796         \******************************************************************/
00797         case DID_CB_PATTERN:
00798           if (HIWORD (wParam) == CBN_SELCHANGE) {
00799             int iSel;
00800
00801             iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00802             iPatternBrush = Patterns[iSel].Value;
00803
00804             SendMessage (hwndMain, WM_MASKBLT, 0,0);
00805           }
00806         break;
00807
00808
00809
00810       } return FALSE; /* end WM_COMMAND switch*/
00811
00812   } /* end switch */
00813   return 0;
00814 }
00815
00816
00817
00818 #define TICKSPACE     20
00819
00820 /**************************************************************************\
00821 *
00822 *  function:  DrawGrids()
00823 *
00824 *  input parameters:
00825 *   hdc - Device context to draw into.
00826 *   width, height - size of the rectangle to fill with grids.
00827 *
00828 *  global variables:  none.
00829 *
00830 \**************************************************************************/
00831 VOID DrawGrids (HDC hdc, int width, int height)
00832 {
00833     int i;
00834
00835     /* Draw vertical lines. Double at the axis */
00836     for (i = 0; i<= width; i+=TICKSPACE){
00837       MoveToEx (hdc, i, 0, NULL);
00838       LineTo (hdc, i, height);
00839     }
00840     MoveToEx (hdc, 1, 0, NULL);
00841     LineTo (hdc, 1, height);
00842
00843     /* Draw horizontal lines. Double at the axis */
00844     for (i = 0; i<= height; i+=TICKSPACE){
00845       MoveToEx (hdc, 0,i, NULL);
00846       LineTo (hdc, width,i);
00847     }
00848     MoveToEx (hdc, 0, 1, NULL);
00849     LineTo (hdc, width,1);
00850
00851   return;
00852 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: READWRIT/DATABASE.C Source File

  • READWRIT

DATABASE.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************\
00013 **   MODULE:  DataBase                                                     **
00014 **                                                                         **
00015 **                                                                         **
00016 **   PURPOSE: Demonstrates the basic concepts of one of the classical      **
00017 **            synchronous problems. A derivative of the Reader/Writer      **
00018 **            problem. In which one must allow access to each without      **
00019 **            jeopardizing the Database.                                   **
00020 **                                                                         **
00021 **   INTERNAL FUNCTIONS:                                                   **
00022 **                                                                         **
00023 **          InitializeDataBase                                             **
00024 **          CloseDataBase                                                  **
00025 **          InitializeSubsystem                                            **
00026 **          InitApp                                                        **
00027 **          CleanupSubsystem                                               **
00028 **          CleanupApp                                                     **
00029 **          TestInitExitPoint                                              **
00030 **          ErrorMsg                                                       **
00031 **          DebugMsg                                                       **
00032 **                                                                         **
00033 **                                                                         **
00034 **   EXPORTED FUNCTIONS                                                    **
00035 **                                                                         **
00036 **          ReadDataBase                                                   **
00037 **          WriteDataBase                                                  **
00038 **                                                                         **
00039 **                                                                         **
00040 **   COMMENTS:                                                             **
00041 **                                                                         **
00042 **          This also demonstrates how to have both global shared data     **
00043 **          instance data. What I've done is named the shared section      **
00044 **          with the #pragma data_seg( SEGNAME) statement and              **
00045 **          referenced this in the DEF file as READ/WRITE/SHARED.          **
00046 **                                                                         **
00047 \***************************************************************************/
00048
00049
00050
00051
00052 #define STRICT
00053 #define NOMINMAX
00054 #include <windows.h>
00055 #include <stdio.h>
00056 #include <string.h>
00057 #include <stdlib.h>
00058
00059
00060 typedef HANDLE HMUTEX ;
00061 typedef HANDLE HSEM ;
00062 typedef HANDLE HEVENT ;
00063
00064 /* Names for synchronization objects */
00065 #define SEM1    "semph1"
00066 #define MUTX1   "mutx1"
00067 #define EVENT1  "event1"
00068 #define EVENT2  "event2"
00069 #define EVENT3  "evnet3"
00070 #define EVENT4  "event4"
00071
00072 #define MAX     10
00073
00074 #define SIGNALED    0
00075 #define WAIT_ERROR  0xFFFFFFFF
00076
00077
00078 /*global Variables */
00079
00080
00081 /* Put gUserCount in a GLOBAL section. This is because first time
00082  * initialization is handled differently than others
00083  */
00084
00085 #pragma data_seg("MYSEG")
00086
00087 int    gUserCount = 0 ;
00088
00089 #pragma data_seg(".data")
00090
00091
00092
00093
00094 HMUTEX ghMutex ;
00095 HSEM   ghSemaphore ;
00096 HEVENT ghReadEvent1, ghReadEvent2, ghWriteEvent1, ghWriteEvent2 ;
00097 UINT   cReadQueue, cWriteQueue, cReadQueueEx ;
00098 UINT   cRead, cWrite ;
00099 BOOL   InWrite ;
00100
00101 /*
00102  * This is the data type which this
00103  *
00104  */
00105
00106 char   *DataBase[MAX] ;
00107
00108
00109
00110 /***** Private functions *****/
00111
00112 BOOL InitializeSubsystem ( VOID ) ;
00113 BOOL InitApp ( VOID ) ;
00114 BOOL CleanupSubsystem ( VOID ) ;
00115 BOOL CleanupApp ( VOID ) ;
00116 BOOL InitializeDataBase ( VOID ) ;
00117 BOOL CloseDataBase ( VOID ) ;
00118 BOOL GetData ( PSZ psz ) ;
00119 BOOL PutData ( PSZ psz ) ;
00120
00121
00122 /***** DLL Entry/Exit point *****/
00123
00124 BOOL WINAPI DllMain ( HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved ) ;
00125
00126
00127 /***** Debuging functions *****/
00128
00129 VOID ErrorMsg ( PSZ psz ) ;
00130 VOID DebugMsg ( PSZ psz ) ;
00131
00132
00133
00134
00135
00136 /***************************************************************************\
00137 **                                                                         **
00138 **   FUNCTION: ErrorMsg(LPTSTR)                                            **
00139 **                                                                         **
00140 **   PURPOSE: Prints out an error message the return code of the last API  **
00141 **            to fail.                                                     **
00142 **                                                                         **
00143 **   INPUT: psz: This string is a description of where the code failed in  **
00144 **          the module                                                     **
00145 **                                                                         **
00146 **   OUTPUT: None                                                          **
00147 **                                                                         **
00148 \****************************************************************************/
00149
00150 VOID ErrorMsg ( PSZ psz )
00151 {
00152     printf ("\n%s: return code = %d\n", psz, GetLastError()) ;
00153 }
00154
00155
00156 /***************************************************************************\
00157 **                                                                         **
00158 **   FUNCTION: DebugMsg(LPTSTR)                                            **
00159 **                                                                         **
00160 **   PURPOSE: Prints out an debug message                                  **
00161 **                                                                         **
00162 **   INPUT: psz: This string is used for informational purposes only       **
00163 **                                                                         **
00164 **   OUTPUT: None                                                          **
00165 **                                                                         **
00166 \****************************************************************************/
00167
00168
00169 VOID DebugMsg ( PSZ psz )
00170 {
00171     printf ( psz ) ;
00172 }
00173
00174
00175 /***************************************************************************\
00176 **                                                                         **
00177 **   FUNCTION: DllMain                                            **
00178 **                                                                         **
00179 **   PURPOSE: Handles both initialization and cleanup of DLL               **
00180 **                                                                         **
00181 **   INPUT: Handle to module calling this DLL. Flag which indicates        **
00182 **          why the DLL entry routine is being called.                     **
00183 **                                                                         **
00184 **   OUTPUT: None                                                          **
00185 **                                                                         **
00186 **   ERRORS: Returns FALSE if an error occured while the process was being **
00187 **           attached. Any other time the return value is ignored.         **
00188 **                                                                         **
00189 **   COMMENTS: This function takes place of the LIBMAIN/LIBENTRY and WEP   **
00190 **                                                                         **
00191 **             Even if no initialization is need this function must return **
00192 **                                                                         **
00193 **                                                                         **
00194 \****************************************************************************/
00195
00196
00197
00198 BOOL WINAPI DllMain ( HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved )
00199 {
00200
00201     BOOL bSuccess ;
00202     UNREFERENCED_PARAMETER ( hModule ) ;
00203     UNREFERENCED_PARAMETER ( lpReserved ) ;
00204
00205
00206     if ( dwReason == DLL_PROCESS_ATTACH ) {
00207
00208         gUserCount++ ;
00209
00210         printf ( "\nNumber of clients currently using this are %d\n", gUserCount ) ;
00211
00212         if ( gUserCount == 1 )
00213             bSuccess = InitializeSubsystem ( ) ;
00214         else
00215             bSuccess = InitApp ( ) ;
00216     }
00217
00218     else if ( dwReason == DLL_PROCESS_DETACH ) {
00219
00220         printf ( "\nCleaning up subsystem ...\n" ) ;
00221         printf ( "Number of clients currently using this are %d\n", gUserCount ) ;
00222
00223         if ( gUserCount ==  1 )
00224             bSuccess = CleanupSubsystem ( ) ;
00225         else
00226             bSuccess = CleanupApp ( ) ;
00227
00228         gUserCount-- ;
00229
00230     }
00231
00232
00233     return ( bSuccess ) ;
00234 }
00235
00236
00237 /***************************************************************************\
00238 **                                                                         **
00239 **   FUNCTION: InitializeSubsystem                                         **
00240 **                                                                         **
00241 **   PURPOSE: Sets up the required synchronization objects to insure both  **
00242 **            system performance and data integrity. This is only done     **
00243 **            once; by the first process that attaches itself to the DLL   **
00244 **                                                                         **
00245 **   INPUT: None                                                           **
00246 **                                                                         **
00247 **   OUTPUT: Returns TRUE if successfull otherwise FALSE                   **
00248 **                                                                         **
00249 \****************************************************************************/
00250
00251 BOOL InitializeSubsystem ( VOID )
00252 {
00253     LONG cSemMax = 5;
00254     BOOL bSuccess ;
00255
00256     DebugMsg ( "InitializeSubsystem\n" ) ;
00257
00258     ghSemaphore = CreateSemaphore ( NULL,       // No security descriptor
00259
00260                                    0,           // Initial count of zero so
00261                                                 // access to database is blocked
00262                                                 // till initialization completed
00263                                    cSemMax,
00264                                                 // Maximun threads allowed to
00265                                                 // access the database at one time
00266                                    SEM1) ;      // No name
00267
00268     if ( !ghSemaphore )
00269     {
00270         ErrorMsg ( "Error Creating semaphore" ) ;
00271         return ( FALSE ) ;
00272     }
00273
00274
00275     ghMutex = CreateMutex ( NULL,               // No security descriptor
00276                             TRUE,               // Block access till database
00277                                                 // is setup
00278                             MUTX1 ) ;           // No name
00279     if ( !ghMutex )
00280     {
00281         ErrorMsg ( "Error Creating Mutex" ) ;
00282         return ( FALSE ) ;
00283     }
00284
00285     ghReadEvent1 = CreateEvent ( NULL,           // No security descriptor
00286                                 FALSE,          // Use manual reset so all
00287                                                 // waiting threads get signaled
00288                                 FALSE,          // Set to non-signaled state
00289                                 EVENT1 ) ;
00290
00291
00292     if ( !ghReadEvent1 )
00293     {
00294         ErrorMsg ( "Error Creating ghReadEvent1" ) ;
00295         return ( FALSE ) ;
00296     }
00297
00298     ghWriteEvent1 = CreateEvent ( NULL,           // No security descriptor
00299                                 FALSE,          // Use manual reset so all
00300                                                 // waiting threads get signaled
00301                                 FALSE,          // Set to non-signaled state
00302                                 EVENT2 ) ;
00303
00304
00305     if ( !ghWriteEvent1 )
00306     {
00307         ErrorMsg ( "Error Creating ghWriteEvent1" ) ;
00308         return ( FALSE ) ;
00309     }
00310
00311     ghReadEvent2 = CreateEvent ( NULL,           // No security descriptor
00312                                 FALSE,          // Use manual reset so all
00313                                                 // waiting threads get signaled
00314                                 FALSE,          // Set to non-signaled state
00315                                 EVENT3 ) ;
00316
00317
00318     if ( !ghReadEvent2 )
00319     {
00320         ErrorMsg ( "Error Creating ghReadEvent2" ) ;
00321         return ( FALSE ) ;
00322     }
00323
00324     ghWriteEvent2 = CreateEvent ( NULL,           // No security descriptor
00325                                 FALSE,          // Use manual reset so all
00326                                                 // waiting threads get signaled
00327                                 FALSE,          // Set to non-signaled state
00328                                 EVENT4 ) ;
00329
00330     if ( !ghWriteEvent2 )
00331     {
00332         ErrorMsg ( "Error Creating ghWriteEvent2" ) ;
00333         return ( FALSE ) ;
00334     }
00335
00336     bSuccess = InitializeDataBase () ;
00337
00338
00339     /*
00340      * Now that all the initialization is done it's save to
00341      * release the semaphore and mutex.
00342      *
00343      */
00344
00345     if ( !ReleaseSemaphore ( ghSemaphore,       // Handle to semaphore
00346                        cSemMax,                 // Size to increment
00347                        NULL ) )                 // Don't care about previous value
00348         {
00349             ErrorMsg ( "Error releasing semaphore" ) ;
00350             return ( FALSE ) ;
00351         }
00352
00353
00354     if ( !ReleaseMutex ( ghMutex ) )            // Handle to semaphore
00355         {
00356             ErrorMsg ( "Error releasing mutex" ) ;
00357             return ( FALSE ) ;
00358         }
00359
00360     return ( bSuccess ) ;
00361 }
00362
00363 /***************************************************************************\
00364 **                                                                         **
00365 **   FUNCTION: InitApp                                                     **
00366 **                                                                         **
00367 **   PURPOSE: Sets up the required synchronization objects to insure both  **
00368 **            system performance and data integrity. This is done each     **
00369 **            a process attaches itself to this DLL                        **
00370 **                                                                         **
00371 **   INPUT: None                                                           **
00372 **                                                                         **
00373 **   OUTPUT: Returns TRUE if successfull otherwise FALSE                   **
00374 **                                                                         **
00375 \****************************************************************************/
00376
00377 BOOL InitApp ( VOID )
00378 {
00379
00380     DebugMsg ( "InitApp\n" ) ;
00381
00382     ghSemaphore = OpenSemaphore ( SEMAPHORE_ALL_ACCESS,  //
00383                                  FALSE,                  // No inheritance
00384                                  SEM1 ) ;                // No name
00385
00386     if ( !ghSemaphore )
00387     {
00388         ErrorMsg ( "Error Opening semaphore" ) ;
00389         return ( FALSE ) ;
00390     }
00391
00392
00393     ghMutex = OpenMutex  ( MUTEX_ALL_ACCESS,    //
00394                            FALSE,               // No inheritance
00395                            MUTX1 ) ;            // No name
00396     if ( !ghMutex )
00397     {
00398         ErrorMsg ( "Error Opening Mutex" ) ;
00399         return ( FALSE ) ;
00400     }
00401
00402     ghReadEvent1 = OpenEvent ( EVENT_ALL_ACCESS, //
00403                               FALSE,            // No inheritance
00404                               EVENT1 ) ;        //
00405
00406     if ( !ghReadEvent1 )
00407     {
00408         ErrorMsg ( "Error Opening ghReadEvent1" ) ;
00409         return ( FALSE ) ;
00410     }
00411
00412
00413     ghWriteEvent1 = OpenEvent ( EVENT_ALL_ACCESS, //
00414                                FALSE,            // No inheritance
00415                                EVENT2 ) ;        //
00416
00417
00418     if ( !ghWriteEvent1 )
00419     {
00420         ErrorMsg ( "Error Opening ghWriteEvent1" ) ;
00421         return ( FALSE ) ;
00422     }
00423
00424     ghReadEvent2 = OpenEvent ( EVENT_ALL_ACCESS, //
00425                               FALSE,            // No inheritance
00426                               EVENT3 ) ;        //
00427
00428     if ( !ghReadEvent2 )
00429     {
00430         ErrorMsg ( "Error Opening ghReadEvent2" ) ;
00431         return ( FALSE ) ;
00432     }
00433
00434
00435     ghWriteEvent2 = OpenEvent ( EVENT_ALL_ACCESS, //
00436                                FALSE,            // No inheritance
00437                                EVENT4 ) ;        //
00438
00439
00440     if ( !ghWriteEvent2 )
00441     {
00442         ErrorMsg ( "Error Opening ghWriteEvent2" ) ;
00443         return ( FALSE ) ;
00444     }
00445
00446     return ( TRUE ) ;
00447 }
00448
00449
00450
00451 BOOL CleanupSubsystem ( VOID )
00452 {
00453     DebugMsg ( "CleanupSubsystem\n" ) ;
00454
00455     if ( !CloseHandle ( ghSemaphore ) )
00456         ErrorMsg ( "Error Closing Semaphore" ) ;
00457
00458     if ( !CloseHandle ( ghMutex ) )
00459         ErrorMsg ( "Error Closing Mutex" ) ;
00460
00461     if ( !CloseHandle ( ghReadEvent1 ) )
00462         ErrorMsg ( "Error Closing Event" ) ;
00463
00464     if ( !CloseHandle ( ghWriteEvent1 ) )
00465         ErrorMsg ( "Error Closing Event" ) ;
00466
00467     CloseDataBase ( ) ;
00468
00469     return ( TRUE ) ;
00470 }
00471
00472
00473 /***************************************************************************\
00474 **                                                                         **
00475 **   FUNCTION: CleanupApp                                                  **
00476 **                                                                         **
00477 **   PURPOSE: Cleans up (closes) the synchronization objects.              **
00478 **            This is done each a process attaches itself to this DLL      **
00479 **                                                                         **
00480 **   INPUT: None                                                           **
00481 **                                                                         **
00482 **   OUTPUT: Returns TRUE if successfull otherwise FALSE                   **
00483 **                                                                         **
00484 \****************************************************************************/
00485
00486 BOOL CleanupApp ( VOID )
00487 {
00488     DebugMsg ( "CleanupApp\n" ) ;
00489
00490     if ( !CloseHandle ( ghSemaphore ) )
00491         ErrorMsg ( "Error Closing Semaphore" ) ;
00492
00493     if ( !CloseHandle ( ghMutex ) )
00494         ErrorMsg ( "Error Closing Mutex" ) ;
00495
00496     if ( !CloseHandle ( ghReadEvent1 ) )
00497         ErrorMsg ( "Error Closing Event" ) ;
00498
00499     if ( !CloseHandle ( ghWriteEvent1 ) )
00500         ErrorMsg ( "Error Closing Event" ) ;
00501
00502     return ( TRUE ) ;
00503 }
00504
00505
00506 /***************************************************************************\
00507 **                                                                         **
00508 **   FUNCTION: InitializeDataBase                                          **
00509 **                                                                         **
00510 **   PURPOSE:
00511 **
00512 **                                                                         **
00513 **   INPUT: None                                                           **
00514 **                                                                         **
00515 **   OUTPUT: Returns TRUE if successfull otherwise FALSE                   **
00516 **                                                                         **
00517 \****************************************************************************/
00518
00519 BOOL InitializeDataBase ( VOID )
00520 {
00521     UINT i ;
00522
00523     DebugMsg ( "Initializing database\n" ) ;
00524
00525     for ( i=0; i< MAX; i++ )
00526         PutData ( "Unintialized" ) ;
00527
00528     return ( TRUE ) ;
00529 }
00530
00531
00532 /***************************************************************************\
00533 **                                                                         **
00534 **   FUNCTION: CloseDataBase                                               **
00535 **                                                                         **
00536 **   PURPOSE:
00537 **
00538 **                                                                         **
00539 **   INPUT: None                                                           **
00540 **                                                                         **
00541 **   OUTPUT: Returns TRUE if successfull otherwise FALSE                   **
00542 **                                                                         **
00543 \****************************************************************************/
00544
00545 BOOL CloseDataBase ( VOID )
00546 {
00547     DebugMsg ( "Closing database\n" ) ;
00548     return ( TRUE ) ;
00549 }
00550
00551
00552 /***************************************************************************\
00553 **                                                                         **
00554 **   FUNCTION: ReadDataBase ( PSZ                                          **
00555 **                                                                         **
00556 **   PURPOSE: Fetches data out of the database                             **
00557 **                                                                         **
00558 **   INPUT: None                                                           **
00559 **                                                                         **
00560 **   OUTPUT: Pointer to data                                               **
00561 **                                                                         **
00562 **   ERROR: Returns False if it can not complete the request               **
00563 **                                                                         **
00564 **   COMMENTS:  A reader can not enter the database if                     **
00565 **                                                                         **
00566 **              1) A writer already is in the database                     **
00567 **              2) The maximum number of readers are in the database       **
00568 **                                                                         **
00569 **              A new reader can not enter the databse if                  **
00570 **                                                                         **
00571 **              1) A writer is waiting                                     **
00572 **                                                                         **
00573 \****************************************************************************/
00574
00575
00576 BOOL WINAPI ReadDataBase  ( PSZ psz1, PSZ psz2 )
00577 {
00578    BOOL bSuccess ;
00579    DWORD dwSuccess ;
00580    UNREFERENCED_PARAMETER ( psz2 ) ;
00581
00582 //   DebugMsg ("In ReadDataBase\n" ) ;
00583
00584    cReadQueueEx++ ;
00585    dwSuccess = SIGNALED ;
00586
00587    if ( cWriteQueue )                               // Block if Writer waiting
00588          dwSuccess = WaitForSingleObject ( ghReadEvent1, 0xFFFFFFFF ) ;
00589 //       dwSuccess = WaitForSingleObject ( ghReadEvent1, 5000 ) ;
00590
00591    cReadQueue++ ;                                   // Reader entering queue
00592    cReadQueueEx-- ;
00593
00594    if ( dwSuccess != SIGNALED )
00595    {
00596       ErrorMsg ( "ReadDatabase: Error Waiting for ghReadEvent1" ) ;
00597       bSuccess = FALSE ;
00598    }
00599    else
00600    {
00601    /*
00602     * Only let N readers in the queue at one time
00603     */
00604       switch ( WaitForSingleObject ( ghSemaphore, 0xFFFFFFFF ) )
00605 //      switch ( WaitForSingleObject ( ghSemaphore, 3000 ) )
00606       {
00607           case SIGNALED:
00608               __try {
00609                    if ( InWrite )               // Block if Writer in database
00610                       dwSuccess = WaitForSingleObject ( ghReadEvent2, 0xFFFFFFFF ) ;
00611 //                    dwSuccess = WaitForSingleObject ( ghReadEvent2, 1500 ) ;
00612
00613                    cRead++ ;                    // Number readers in database
00614                    cReadQueue-- ;               // Reader leaving queue
00615
00616                    /*
00617                     * Signal Writer if no Reader waiting
00618                     *
00619                     */
00620                    if ( !cReadQueue )
00621                       bSuccess = SetEvent ( ghWriteEvent1 ) ;
00622
00623                    if ( dwSuccess == SIGNALED )
00624                    {
00625                       bSuccess = GetData ( psz1 ) ;   // Read data
00626                       cRead-- ;
00627                       /*
00628                        * Signal Writer if no Reader in database
00629                        *
00630                        */
00631
00632                       if ( !cRead )
00633                          bSuccess = SetEvent ( ghWriteEvent2 ) ;
00634
00635                       ReleaseSemaphore ( ghSemaphore, // Let next waiting
00636                                           1,          // reader in the queue
00637                                           NULL ) ;
00638                    }
00639                    else
00640                    {
00641                       cRead-- ;
00642                       /*
00643                        * Signal Writer if no Reader in database
00644                        *
00645                        */
00646
00647                       if ( !cRead )
00648                          bSuccess = SetEvent ( ghWriteEvent2 ) ;
00649
00650                       bSuccess = FALSE ;
00651                       DebugMsg ( "ReadDataBase: Error Waiting for ghReadEvent2\n" ) ;
00652                    }
00653               }
00654               __finally {
00655                  // what if these is already decremented above????
00656                    cRead-- ;
00657                    /*
00658                     * Signal Writer if no Reader in database
00659                     *
00660                     */
00661
00662                    if ( !cRead )
00663                       bSuccess = SetEvent ( ghWriteEvent2 ) ;
00664
00665                    /*
00666                     * Signal Writer if no Reader in queue
00667                     *
00668                     */
00669                    if ( !cReadQueue )
00670                       bSuccess = SetEvent ( ghWriteEvent1 ) ;
00671
00672                    bSuccess = FALSE ;
00673                    ReleaseSemaphore ( ghSemaphore,     // Let next waiting
00674                                   1,                   // reader in the queue
00675                                   NULL ) ;
00676               }
00677
00678               break ;
00679
00680           case WAIT_TIMEOUT:
00681               DebugMsg ( "ReadDataBase: Error WAIT_TIMEOUT ghSemaphore\n" ) ;
00682
00683               //where to put this?
00684               cReadQueue-- ;            // Reader leaving queue
00685               /*
00686                * Signal Writer if no Reader waiting
00687                *
00688                */
00689               if ( !cReadQueue )
00690                  bSuccess = SetEvent ( ghWriteEvent1 ) ;
00691
00692               bSuccess = FALSE ;
00693               break ;
00694
00695           case WAIT_ERROR:
00696               ErrorMsg ( "ReadDataBase: Error WAIT_ERROR ghSemaphore" ) ;
00697
00698               //where to put this?
00699               cReadQueue-- ;            // Reader leaving queue
00700               /*
00701                * Signal Writer if no Reader waiting
00702                *
00703                */
00704               if ( !cReadQueue )
00705                  bSuccess = SetEvent ( ghWriteEvent1 ) ;
00706
00707               bSuccess = FALSE ;
00708               break ;
00709
00710           default:
00711               DebugMsg ( "ReadDataBase: Dropped through switch\n" ) ;
00712
00713               //where to put this?
00714               cReadQueue-- ;            // Reader leaving queue
00715               /*
00716                * Signal Writer if no Reader waiting
00717                *
00718                */
00719               if ( !cReadQueue )
00720                  bSuccess = SetEvent ( ghWriteEvent1 ) ;
00721
00722               bSuccess = FALSE ;
00723               break ;
00724       }
00725    } // END IF
00726
00727
00728
00729    return ( bSuccess ) ;
00730 }
00731
00732
00733
00734
00735
00736 /***************************************************************************\
00737 **                                                                         **
00738 **   FUNCTION: WriteDataBase ( PSZ                                         **
00739 **                                                                         **
00740 **   PURPOSE: Puts data into the database                                  **
00741 **                                                                         **
00742 **   INPUT: Pointer to data                                                **
00743 **                                                                         **
00744 **   OUTPUT: None                                                          **
00745 **                                                                         **
00746 **   ERROR: Returns False if it can not complete the request               **
00747 **                                                                         **
00748 **   COMMENTS:  A writer can not enter the database if                     **
00749 **                                                                         **
00750 **              1) A writer already is in the database                     **
00751 **              2) Any readers are in the database                         **
00752 **                                                                         **
00753 **              All reader waiting at the end of a write operation         **
00754 **              have priority over the next writer                         **
00755 **                                                                         **
00756 \****************************************************************************/
00757
00758 BOOL WINAPI WriteDataBase ( PSZ psz1, PSZ psz2 )
00759 {
00760    BOOL bSuccess ;
00761    DWORD dwSuccess ;
00762    UNREFERENCED_PARAMETER ( psz2 ) ;
00763
00764 //   DebugMsg ( "In WriteDataBase\n" ) ;
00765
00766    cWriteQueue++ ;                             // Writer entering queue
00767    dwSuccess = SIGNALED ;
00768
00769                    // should the same event be used twice ???
00770
00771    if ( cReadQueue )                           // Block if Reader waiting
00772       dwSuccess = WaitForSingleObject ( ghWriteEvent1, 0xFFFFFFFF ) ;
00773 //      dwSuccess = WaitForSingleObject ( ghWriteEvent1, 5000 ) ;
00774
00775    if ( dwSuccess != SIGNALED )
00776    {
00777       DebugMsg ( "WriteDataBase: Error Waiting for ghWriteEvent1\n" ) ;
00778       bSuccess = FALSE ;
00779    }
00780    else
00781    {
00782    /*
00783     * Only allow 1 writer at a time in the database
00784     *
00785     */
00786       switch ( WaitForSingleObject ( ghMutex, 0xFFFFFFFF ) ) {
00787 //      switch ( WaitForSingleObject ( ghMutex, 3000 ) ) {
00788          case SIGNALED:
00789             __try {
00790                InWrite = TRUE ;
00791                cWriteQueue-- ;
00792
00793                /*
00794                 * Signal Reader if any waiting
00795                 *
00796                 */
00797                if ( cReadQueueEx )
00798                   bSuccess = SetEvent ( ghReadEvent1 ) ;
00799
00800                                // Writer leaving queue
00801                if ( cRead )               // Block if Reader in database
00802                   dwSuccess = WaitForSingleObject ( ghWriteEvent2, 0xFFFFFFFF ) ;
00803 //                dwSuccess = WaitForSingleObject ( ghWriteEvent2, 1500 ) ;
00804
00805                if ( dwSuccess == SIGNALED )
00806                {
00807                   bSuccess = PutData ( psz1 ) ;
00808                   InWrite = FALSE ;
00809                   /*
00810                    * Signal Reader when no Writer waiting
00811                    *
00812                    */
00813                   bSuccess = SetEvent ( ghReadEvent2 ) ;
00814                   ReleaseMutex ( ghMutex ) ;    // Let next waiting writer in the queue
00815                }
00816                else
00817                {
00818                   bSuccess = FALSE ;
00819                   InWrite = FALSE ;
00820                   /*
00821                    * Signal Reader when no Writer waiting
00822                    *
00823                    */
00824                   bSuccess = SetEvent ( ghReadEvent2 ) ;
00825                   DebugMsg ( "WriteDataBase: Error Waiting on ghWriteEvent2\n" ) ;
00826                }
00827             }
00828             __finally {
00829                InWrite = FALSE ;
00830                /*
00831                 * Signal Reader after leaving database
00832                 *
00833                 */
00834                bSuccess = SetEvent ( ghReadEvent2 ) ;
00835
00836                /*
00837                 * Signal Reader if no Writer in queue
00838                 *
00839                 */
00840                if ( !cWriteQueue )
00841                   bSuccess = SetEvent ( ghReadEvent1 ) ;
00842
00843                bSuccess = FALSE ;
00844                ReleaseMutex ( ghMutex ) ;
00845             }
00846             break ;
00847
00848          case WAIT_TIMEOUT:
00849             DebugMsg ( "WriteDataBase: Error WAIT_TIMEOUT ghMutex\n" ) ;
00850             cWriteQueue-- ;
00851             /*
00852              * Signal Reader if no Writer waiting
00853              *
00854              */
00855             if ( !cWriteQueue )
00856                bSuccess = SetEvent ( ghReadEvent1 ) ;
00857
00858             bSuccess = FALSE ;
00859             break ;
00860
00861          case WAIT_ABANDONED:
00862             DebugMsg ( "WriteDataBase: Error WAIT_ABANDONED ghMutex\n" ) ;
00863             cWriteQueue-- ;
00864             /*
00865              * Signal Reader if no Writer waiting
00866              *
00867              */
00868             if ( !cWriteQueue )
00869                bSuccess = SetEvent ( ghReadEvent1 ) ;
00870
00871             bSuccess = FALSE ;
00872             break ;
00873
00874          case WAIT_ERROR:
00875             ErrorMsg ( "WriteDataBase: Error WAIT_ERROR ghMutex" ) ;
00876             cWriteQueue-- ;
00877             /*
00878              * Signal Reader if no Writer waiting
00879              *
00880              */
00881             if ( !cWriteQueue )
00882                bSuccess = SetEvent ( ghReadEvent1 ) ;
00883
00884             bSuccess = FALSE ;
00885             break ;
00886
00887          default:
00888             DebugMsg ( "WriteDataBase: Dropped through switch\n" ) ;
00889             cWriteQueue-- ;
00890             /*
00891              * Signal Reader if no Writer waiting
00892              *
00893              */
00894             if ( !cWriteQueue )
00895                bSuccess = SetEvent ( ghReadEvent1 ) ;
00896
00897             bSuccess = FALSE ;
00898             break ;
00899       }
00900    } // END IF
00901
00902
00903    if ( cReadQueue )
00904        bSuccess = SetEvent ( ghReadEvent1 ) ;          // Signal Reader
00905    else
00906        bSuccess = SetEvent ( ghWriteEvent1 ) ;         // Signal Writer
00907
00908    return ( bSuccess ) ;
00909 }
00910
00911
00912
00913 BOOL GetData ( PSZ psz )
00914 {
00915     static UINT i = 0 ;
00916
00917     strcpy ( psz, DataBase[i++ % MAX] ) ;
00918     return ( TRUE ) ;
00919 }
00920
00921
00922 BOOL PutData ( PSZ psz )
00923 {
00924     static UINT i = 0 ;
00925
00926     i++ ;
00927     DataBase[i % MAX] = strdup ( psz ) ;
00928     return ( TRUE ) ;
00929 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SUBCLASS/SUBCLASS.H Source File

  • SUBCLASS

SUBCLASS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012
00013 #define   IDM_BUTTON        101
00014 #define   IDM_EDIT          102
00015 #define   IDM_LIST          103
00016 #define   IDM_TEST          110
00017
00018
00019
00020 /* function prototypes for the window procedures. */
00021 LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
00022 LRESULT CALLBACK SubclassWndProc(HWND, UINT, WPARAM, LPARAM);
00023
00024 VOID QueryWindowPos (HWND, LPRECT);
00025 VOID PaintRect (HWND, LPRECT);
00026 VOID SubclassWindow (HWND, WNDPROC);
00027 DWORD ToggleMenu (HMENU, UINT);
00028 LONG ShiftlParam(HWND, HWND, LONG);
00029
00030
00031
00032 #define WM_SC_CREATE  WM_USER+1
00033
00034
00035
00036 /* Different "Tracking actions." */
00037 #define ACTIONNONE    0x0000
00038 #define ACTIONMOVE    0x0001
00039 #define ACTIONSIZEX   0x0002
00040 #define ACTIONSIZEY   0x0004
00041 #define ACTIONSIZEXY  0x0006
00042
00043
00044 /* misc. defines for drawing and formating */
00045 #define INC   5
00046 #define EPSILON  (float) 0.0001
00047 #define MAXCHARS 32
00048 #define MINSIZE 5
00049
00050
00051 /* Global variables. */
00052 HWND   hwndMain;
00053 HANDLE hInst;
00054 BOOL   fTestMode;
00055
00056
00057 /* structure pointed at by the extra user bytes. */
00058 typedef struct tagExtraBytes{
00059     WNDPROC    pfnOldProc;
00060     RECT       rect;
00061     int        Action;   /* ACTIONSIZEXY, ACTIONMOVE, ... */
00062 } ExtraBytes, *PExtraBytes;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/STUB32.C Source File

  • INTEROP

STUB32.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *                                                                    *
00003 *  File:      stub32.c                                               *
00004 *                                                                    *
00005 *  Comments:  Loads the 32-bit side of the Universal Thunk           *
00006 *             (utdll32.dll) and calls the initialization routine     *
00007 *                                                                    *
00008 *  Functions: WinMain                                                *
00009 *             MainWndProc                                            *
00010 *                                                                    *
00011 \********************************************************************/
00012
00013 /*********************  Header Files  *********************/
00014
00015 #include <windows.h>
00016 #include "myut.h"
00017
00018 /*********************  Globals     ***********************/
00019
00020 BOOL fWin32s;
00021 HINSTANCE ghDLL;
00022
00023 /*********************  Prototypes  ***********************/
00024
00025 LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM );
00026
00027 void WINAPI InitThunk( HWND );
00028
00029
00030 /********************************************************************\
00031 *  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
00032 *                                                                    *
00033 *   Purpose: Initializes Application                                 *
00034 *                                                                    *
00035 *  Comments: Standard template                                       *
00036 *                                                                    *
00037 *                                                                    *
00038 \********************************************************************/
00039
00040
00041 int PASCAL WinMain( HINSTANCE hInstance,
00042         HINSTANCE hPrevInstance,
00043         LPSTR lpszCmdLine,
00044         int nCmdShow )
00045 {
00046    WNDCLASS wc;
00047    MSG msg;
00048    HWND hWnd;
00049
00050    if( !hPrevInstance ) {
00051       wc.lpszClassName = "Stub32Class";
00052       wc.lpfnWndProc = MainWndProc;
00053       wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
00054       wc.hInstance = hInstance;
00055       wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
00056       wc.hCursor = LoadCursor( NULL, IDC_ARROW );
00057       wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
00058       wc.lpszMenuName = NULL;
00059       wc.cbClsExtra = 0;
00060       wc.cbWndExtra = 0;
00061
00062       RegisterClass( &wc );
00063    }
00064
00065    hWnd = CreateWindow( "Stub32Class",
00066       "Hidden Window",
00067       WS_OVERLAPPEDWINDOW,
00068       0,
00069       0,
00070       CW_USEDEFAULT,
00071       CW_USEDEFAULT,
00072       NULL,
00073       NULL,
00074       hInstance,
00075       NULL
00076           );
00077
00078    ShowWindow( hWnd, SW_HIDE );
00079
00080    while( GetMessage( &msg, NULL, 0, 0 ) ) {
00081       TranslateMessage( &msg );
00082       DispatchMessage( &msg );
00083    }
00084
00085    return msg.wParam;
00086 }
00087
00088
00089 /********************************************************************\
00090 * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
00091 *                                                                    *
00092 *  Purpose: Processes Application Messages                           *
00093 *                                                                    *
00094 * Comments: The following messages are processed                     *
00095 *                                                                    *
00096 *           WM_CREATE                                                *
00097 *           WM_DESTROY                                               *
00098 *                                                                    *
00099 *                                                                    *
00100 \********************************************************************/
00101
00102
00103 LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
00104    LPARAM lParam )
00105 {
00106    switch( msg ) {
00107
00108 /**************************************************************\
00109 *     WM_CREATE: Let the 32-bit UT DLL initialize the thunk    *
00110 \**************************************************************/
00111
00112       case WM_CREATE:
00113          InitThunk( hWnd );
00114    break;
00115
00116 /**************************************************************\
00117 *     WM_DESTROY: PostQuitMessage() is called                  *
00118 \**************************************************************/
00119
00120       case WM_DESTROY:
00121    PostQuitMessage( 0 );
00122    break;
00123
00124 /**************************************************************\
00125 *     Let the default window proc handle all other messages    *
00126 \**************************************************************/
00127
00128       default:
00129    return( DefWindowProc( hWnd, msg, wParam, lParam ));
00130    }
00131
00132    return 0;
00133 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/CHGDATA.C Source File

  • BPOINTER

CHGDATA.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     chgdata.C
00015 *  Part of:     BPointer sample application
00016 *
00017 \******************************************************************************/
00018
00019 #include <windows.h>
00020 #include <stdio.h>
00021 #include "shrstuff.h"
00022
00023
00024 void InsertElement(int iValue)
00025 {
00026   clRunning->iElement = iValue;
00027   clRunning->clNext = clRunning + 1;
00028   clRunning += 1;
00029 }
00030
00031
00032 int main(void)
00033 {   HANDLE hFileMapping;
00034     DWORD dwVersion;
00035     int iCounter;
00036     int iNextElement;
00037     int iInternalCounter = 0;
00038
00039 // check if running on Win32s, if so, display notice and terminate
00040
00041     dwVersion = GetVersion();
00042     if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00043     {
00044         MessageBox( NULL,
00045             "This sample application will not run on Windows 3.1.\n"
00046             "This application will now terminate.",
00047             "ChgData",
00048             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00049         return( 1 );
00050     }
00051
00052 // Set up the shared memory.
00053 // In this process, the file mapping must not yet exist.
00054
00055     hFileMapping = CreateFileMapping( (HANDLE)0xffffffff,
00056                                       NULL,
00057                                       PAGE_READWRITE,
00058                                       0,4096,
00059                                       "FM_DemoMapObject");
00060
00061     if (GetLastError() == ERROR_ALREADY_EXISTS)
00062     {   printf("Please close ReadData before running this application!");
00063         CloseHandle(hFileMapping);
00064         return 0;
00065     }
00066
00067     if (!hFileMapping)
00068     {   printf ("Error %d: CreateFileMapping failed.", GetLastError());
00069         return 0;
00070     }
00071
00072 // MapViewOfFile is used here to get the file mapping mapped into
00073 // this processe's address space.  There is no guarantee about which address
00074 // will be chosen for this process.  The address used by another
00075 // process could be different.  That is why we need based pointers.
00076 // The pointers in this process are based on whatever address is used
00077 // by this process. For another process, the pointers will be based on some
00078 // other address.
00079
00080     clBasePt = (CHAINLIST *)MapViewOfFile( hFileMapping,
00081                                            FILE_MAP_ALL_ACCESS,
00082                                            0,0,
00083                                            0);
00084
00085     if (clBasePt == NULL)
00086     {   printf("Error %d: MapViewOfFileEx failed.\n", GetLastError());
00087         CloseHandle(hFileMapping);
00088         return 0;
00089     }
00090
00091 // Now the memory is set up. The following loops and prompts the user for new
00092 // elements until a 0 is hit. The memory is displayed so that we see that
00093 // the offsets are entered into the link fields, ignoring the based
00094 // pointers.
00095
00096     printf("Address of file mapping in this process: 0x%08x\n", (int)clBasePt);
00097     printf("Enter element to insert; 0 terminates: ");
00098     scanf("%d",&iNextElement);
00099     while (iNextElement != 0)
00100     {
00101         InsertElement(iNextElement);
00102         iInternalCounter += (sizeof(CHAINLIST)/sizeof(DWORD));
00103         printf ("Now displaying raw data at address: 0x%x\n", (int)clBasePt);
00104         printf ("You might want to run readdata.exe now.\n");
00105         for (iCounter = 0; iCounter <= iInternalCounter; iCounter += 2)
00106             printf("%p: %08x %08x\n", (LPVOID)((DWORD *)clBasePt+iCounter),
00107                                      ((DWORD *)clBasePt)[iCounter],
00108                                      ((DWORD *)clBasePt)[iCounter+1]);
00109         printf("\nEnter next element to insert; 0 terminates: ");
00110         scanf("%d", &iNextElement);
00111     }
00112
00113 // user has entered 0 -- now clean up.
00114
00115     UnmapViewOfFile(clBasePt);
00116     CloseHandle(hFileMapping);
00117
00118     return(0);
00119 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/DLLDISP.C Source File

  • SERVENUM
  • DLL

DLLDISP.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   dlldisp.c
00009 //
00010 //  PURPOSE:  Implement the generic message and command dispatchers.
00011 //
00012 //
00013 //  FUNCTIONS:
00014 //    DispMessage - Call the function associated with a message.
00015 //    DispCommand - Call the function associated with a command.
00016 //    DispDefault - Call the appropriate default window procedure.
00017 //
00018 //  COMMENTS:
00019 //
00020
00021 #include <windows.h>            // required for all Windows applications
00022 #include <windowsx.h>
00023 #include "dlldisp.h"
00024
00025 LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
00026
00027 //
00028 //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
00029 //
00030 //  PURPOSE: Call the function associated with a message.
00031 //
00032 //  PARAMETERS:
00033 //    lpmsdi - Structure containing the message dispatch information.
00034 //    hwnd - The window handle
00035 //    uMessage - The message number
00036 //    wparam - Message specific data
00037 //    lparam - Message specific data
00038 //
00039 //  RETURN VALUE:
00040 //    The value returned by the message function that was called.
00041 //
00042 //  COMMENTS:
00043 //    Runs the table of messages stored in lpmsdi->rgmsd searching
00044 //    for a message number that matches uMessage.  If a match is found,
00045 //    call the associated function.  Otherwise, call DispDefault to
00046 //    call the default function, if any, associated with the message
00047 //    structure.  In either case, return the value recieved from the
00048 //    message or default function.
00049 //
00050
00051 LRESULT DispMessage(LPMSDI lpmsdi,
00052                     HWND   hwnd,
00053                     UINT   uMessage,
00054                     WPARAM wparam,
00055                     LPARAM lparam)
00056 {
00057     int  imsd = 0;
00058
00059     MSD *rgmsd = lpmsdi->rgmsd;
00060     int  cmsd  = lpmsdi->cmsd;
00061
00062     for (imsd = 0; imsd < cmsd; imsd++)
00063     {
00064         if (rgmsd[imsd].uMessage == uMessage)
00065             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
00066     }
00067
00068     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
00069 }
00070
00071 //
00072 //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
00073 //
00074 //  PURPOSE: Call the function associated with a command.
00075 //
00076 //  PARAMETERS:
00077 //    lpcmdi - Structure containing the command dispatch information.
00078 //    hwnd - The window handle
00079 //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
00080 //      control, or accelerator.
00081 //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
00082 //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
00083 //
00084 //  RETURN VALUE:
00085 //    The value returned by the command function that was called.
00086 //
00087 //  COMMENTS:
00088 //    Runs the table of commands stored in lpcmdi->rgcmd searching
00089 //    for a command number that matches wCommand.  If a match is found,
00090 //    call the associated function.  Otherwise, call DispDefault to
00091 //    call the default function, if any, associated with the command
00092 //    structure.  In either case, return the value recieved from the
00093 //    command or default function.
00094 //
00095
00096
00097 LRESULT DispCommand(LPCMDI lpcmdi,
00098                     HWND   hwnd,
00099                     WPARAM wparam,
00100                     LPARAM lparam)
00101 {
00102     LRESULT lRet = 0;
00103     WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
00104     int     icmd;
00105
00106     CMD    *rgcmd = lpcmdi->rgcmd;
00107     int     ccmd  = lpcmdi->ccmd;
00108
00109     // Message packing of wparam and lparam have changed for Win32,
00110     // so use the GET_WM_COMMAND macro to unpack the commnad
00111
00112     for (icmd = 0; icmd < ccmd; icmd++)
00113     {
00114         if (rgcmd[icmd].wCommand == wCommand)
00115         {
00116             return rgcmd[icmd].pfncmd(hwnd,
00117                                       wCommand,
00118                                       GET_WM_COMMAND_CMD(wparam, lparam),
00119                                       GET_WM_COMMAND_HWND(wparam, lparam));
00120         }
00121     }
00122
00123     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
00124 }
00125
00126
00127 //
00128 //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
00129 //
00130 //  PURPOSE: Call the appropriate default window procedure.
00131 //
00132 //  PARAMETERS:
00133 //    edwp - Enumerate specifying the appropriate default winow procedure.
00134 //    hwnd - The window handle
00135 //    uMessage - The message number
00136 //    wparam - Message specific data
00137 //    lparam - Message specific data
00138 //
00139 //  RETURN VALUE:
00140 //    If there is a default proc, return the value returned by the
00141 //    default proc.  Otherwise, return 0.
00142 //
00143 //  COMMENTS:
00144 //    Calls the default procedure associated with edwp using the specified
00145 //    parameters.
00146 //
00147
00148 LRESULT DispDefault(EDWP   edwp,
00149                     HWND   hwnd,
00150                     UINT   uMessage,
00151                     WPARAM wparam,
00152                     LPARAM lparam)
00153 {
00154     switch (edwp)
00155     {
00156         case edwpNone:
00157             return 0;
00158         case edwpWindow:
00159             return DefWindowProc(hwnd, uMessage, wparam, lparam);
00160         case edwpDialog:
00161             return DefDlgProc(hwnd, uMessage, wparam, lparam);
00162         case edwpMDIFrame:
00163             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
00164         case edwpMDIChild:
00165             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
00166     }
00167     return 0;
00168 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: REBOOT/REBOOT.C Source File

  • REBOOT

REBOOT.C

Go to the documentation of this file.
00001 // ************************************************************************
00002 //
00003 //                      Microsoft Developer Support
00004 //             Copyright (c) 1992-1996 Microsoft Corporation
00005 //
00006 // ************************************************************************
00007 // MODULE    : Reboot.C
00008 // PURPOSE   : A Reboot Win32 Console Application Source File
00009 // FUNCTIONS :
00010 //  main                - application-defined entry point
00011 //  SetCurrentPrivilege - enables/disables a privilege for caller
00012 //  DisplayError        - displays an API error message
00013 // COMMENTS  : none.
00014 // ************************************************************************
00015
00016 #define   STRICT               // enable strict typing
00017 #include <windows.h>           // required for all Windows applications
00018 #include <stdio.h>             // printf()
00019
00020 #ifdef UNICODE
00021
00022 #define MYMAIN wmain // Unicode main
00023 #else
00024
00025 #define MYMAIN main  // Ansi main
00026 #endif
00027
00028 // internal function prototypes
00029 // --------------------------------------------------------------------------
00030 BOOL
00031 SetCurrentPrivilege(
00032     LPTSTR MachineName,     // target machine name
00033     LPCTSTR Privilege,      // Privilege to enable/disable
00034     BOOL bEnablePrivilege   // to enable or disable privilege
00035     );
00036
00037 void
00038 DisplayError(
00039     LPSTR
00040     );
00041
00042 // ************************************************************************
00043 // FUNCTION : main( int, char** )
00044 // PURPOSE  : main is called by the true application entry point
00045 //            mainCRTStartup right after the C Run-Time libaries are
00046 //            initialized when the executable is first loaded.  That is,
00047 //            main is the application-defined entry point.
00048 // COMMENTS : none.
00049 // ************************************************************************
00050 int _cdecl
00051 MYMAIN(int argc, LPTSTR argv[])
00052 {
00053     LPTSTR lpPrivilege;
00054     int iReturnValue;   // return value from main()
00055
00056     // if Win32s or Windows 95, display notice and terminate
00057     if(GetVersion() & 0x80000000) {
00058         MessageBoxA(
00059             NULL,
00060             "This application cannot run on Windows 3.1 or Windows 95.\n"
00061             "This application will now terminate.",
00062             "REBOOT",
00063             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND
00064             );
00065
00066         return 1;
00067     }
00068
00069     if(argc != 2) {
00070         printf("Reboot Program, Version 1.1\n");
00071         printf("Copyright (c) 1992-1996 Microsoft Corp.\n");
00072
00073         printf("\nSyntax: reboot \\\\MachineName OR . for local machine\n");
00074         return 1;
00075     }
00076
00077     lpPrivilege = SE_SHUTDOWN_NAME;
00078
00079     //
00080     // enable the appropriate privilege
00081     //
00082     if(!SetCurrentPrivilege(argv[1], lpPrivilege, TRUE)) {
00083         DisplayError("SetCurrentPrivilege");
00084         return 2;
00085     }
00086
00087     printf("Attempting to shutdown %s\n", argv[1]);
00088
00089     //
00090     // attempt to shutdown the target machine
00091     // since we use a non-zero shutdown timeout, we could abort the shutdown
00092     // via the Win32 AbortSystemShutdown() API
00093     //
00094     if(!InitiateSystemShutdown(
00095         argv[1], // machine name
00096         NULL,    // dialog box message
00097         10,      // shutdown timeout
00098         TRUE,    // force apps closed
00099         TRUE     // reboot
00100         )) {
00101
00102         DisplayError("InitiateSystemShutdown");
00103         iReturnValue = 2; // error
00104     }
00105     else {
00106         printf( "InitiateSystemShutdown successful.\n");
00107         iReturnValue = 0; // success
00108     }
00109
00110     //
00111     // disable the privilege
00112     //
00113     SetCurrentPrivilege(argv[1], lpPrivilege, FALSE);
00114
00115     return iReturnValue;
00116 }
00117
00118 //
00119 // FUNCTION : SetCurrentPrivilege
00120 // PURPOSE  : Enables or disables a privilege in the calling process, based
00121 //            on whether the caller has this privilege on the target machine
00122 // COMMENTS : none.
00123 //
00124 BOOL
00125 SetCurrentPrivilege(
00126     LPTSTR MachineName,     // target machine name
00127     LPCTSTR Privilege,      // Privilege to enable/disable
00128     BOOL bEnablePrivilege   // to enable or disable privilege
00129     )
00130 {
00131     HANDLE hToken;
00132     TOKEN_PRIVILEGES tp;
00133     LUID luid;
00134     TOKEN_PRIVILEGES tpPrevious;
00135     DWORD cbPrevious=sizeof(TOKEN_PRIVILEGES);
00136     BOOL bSuccess=FALSE; // assume this function will fail
00137
00138     //
00139     // obtain the Luid of the privilege from the target computer
00140     //
00141     if(!LookupPrivilegeValue(MachineName, Privilege, &luid)) return FALSE;
00142
00143     //
00144     // open our access token, which we read and modify later
00145     //
00146     if(!OpenProcessToken(
00147             GetCurrentProcess(),
00148             TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES,
00149             &hToken
00150             )) return FALSE;
00151
00152     //
00153     // first pass.  get current privilege setting
00154     //
00155     tp.PrivilegeCount           = 1;
00156     tp.Privileges[0].Luid       = luid;
00157     tp.Privileges[0].Attributes = 0;
00158
00159     AdjustTokenPrivileges(
00160             hToken,
00161             FALSE,
00162             &tp,
00163             sizeof(TOKEN_PRIVILEGES),
00164             &tpPrevious,
00165             &cbPrevious
00166             );
00167
00168     if(GetLastError() == ERROR_SUCCESS) {
00169         //
00170         // second pass.  set privilege based on previous setting
00171         //
00172         tpPrevious.PrivilegeCount     = 1;
00173         tpPrevious.Privileges[0].Luid = luid;
00174
00175         if(bEnablePrivilege)
00176             tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
00177         else
00178             tpPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED &
00179                 tpPrevious.Privileges[0].Attributes);
00180
00181         AdjustTokenPrivileges(
00182                 hToken,
00183                 FALSE,
00184                 &tpPrevious,
00185                 cbPrevious,
00186                 NULL,
00187                 NULL
00188                 );
00189
00190         if (GetLastError() == ERROR_SUCCESS) bSuccess=TRUE;
00191     }
00192
00193     CloseHandle(hToken);
00194
00195     return bSuccess;
00196 }
00197
00198 //
00199 // FUNCTION : DisplayError(LPSTR, DWORD)
00200 // PURPOSE  : Displays the error text associated with GetLastError()
00201 // COMMENTS : none.
00202 //
00203 void
00204 DisplayError(LPSTR szAPI)
00205 {
00206     LPSTR MessageBuffer;
00207     DWORD dwBufferLength;
00208
00209     fprintf(stderr,"%s error!\n", szAPI);
00210
00211     if(dwBufferLength=FormatMessageA(
00212                 FORMAT_MESSAGE_ALLOCATE_BUFFER |
00213                 FORMAT_MESSAGE_FROM_SYSTEM,
00214                 NULL,
00215                 GetLastError(),
00216                 GetUserDefaultLangID(),
00217                 (LPSTR) &MessageBuffer,
00218                 0,
00219                 NULL
00220                 ))
00221     {
00222         DWORD dwBytesWritten;
00223
00224         //
00225         // Output message string on stderr
00226         //
00227         WriteFile(
00228                 GetStdHandle(STD_ERROR_HANDLE),
00229                 MessageBuffer,
00230                 dwBufferLength,
00231                 &dwBytesWritten,
00232                 NULL
00233                 );
00234
00235         //
00236         // free the buffer allocated by the system
00237         //
00238         LocalFree(MessageBuffer);
00239     }
00240 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: VIRTMEM/VIRTMEM.C Source File

  • VIRTMEM

VIRTMEM.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************************\
00013 *  PROGRAM: Virtmem.c
00014 *
00015 *  PURPOSE:
00016 *
00017 *     To demonstrate the use of various virtual memory API.
00018 *
00019 *  FUNCTIONS:
00020 *
00021 *    WinMain()      - Initializes the window, and process the message loop.
00022 *    MainWndProc()  - Process messages, launches server & client threads.
00023 *    ResetMenu()    - Looks at the memory page and checks the menu items
00024 *                     accordingly.
00025 *    ShowDlgProc()  - Shows information regarding the virtual page.
00026 *
00027 *  GLOBAL VARIABLES:
00028 *
00029 *    - Buf, Buf2:
00030 *             Character arrays used for error messages.
00031 *
00032 *    - base:  Pointer to CHAR, used as a pointer to the base of the page.
00033 *    - hInst: Handle to the application's Instance.
00034 *    - hWnd:  Handle to the parent window.
00035 *    - MemInfo:
00036 *             Structure used to hold the page's memory information.
00037 *
00038 *  COMMENTS:
00039 *
00040 *    To Use:
00041 *      Start the application.  You are automatically given a Reserved page
00042 *      of memory with no access (4096 bytes in size).  You can then use
00043 *      the various menu selection to change the state and protection on
00044 *      the page.  "State" allows you to change the page between Free,
00045 *      Reserved, and Committed.  "Access" allows you to change the
00046 *      protection on the page between Read/Write, Read Only, or No Access.
00047 *      Lock allows you to Lock or Unlock the page in memory (note that
00048 *      this was not yet implemented in PDK-2).  Test trys to write to
00049 *      memory.  If the page is not committed, and is marked with read/
00050 *      write access, this will cause an exception.  There is an example
00051 *      of exception handling in the code.
00052 *
00053 *      The menu will keep track of the state and protection access
00054 *      to the page, and the menu items will be checked accordingly.
00055 *      For more information on the page, you can select "Show Page"
00056 *      from the menu.  A dialog box will appear showing you the page
00057 *      information.  You can dismiss the dialog box through its system
00058 *      menu.
00059 *
00060 \*************************************************************************/
00061
00062
00063 #include <windows.h>
00064 #include <excpt.h>
00065 #include <stdio.h>
00066 #include <stdlib.h>
00067 #include "virtmem.h"
00068
00069 #define WERR(who,where)    {sprintf(Buf,"ERROR: %s returned %u, line: %u", who, GetLastError(), __LINE__);\
00070                             sprintf(Buf2,"From within %s", where);\
00071                             MessageBox(hwnd, Buf, Buf2, MB_OK);}
00072
00073
00074 #define IMPLEMENTED   // Used if VirtualLock and VirtualUnlock are implemented.
00075
00076 CHAR Buf[80];
00077 CHAR Buf2[80];
00078
00079 CHAR *base;
00080 CHAR *page;
00081
00082 HANDLE hInst;
00083 HANDLE hWnd;
00084 MEMORY_BASIC_INFORMATION MemInfo;
00085
00086 /*************************************************************************\
00087 *
00088 *  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
00089 *
00090 *  PURPOSE: calls initialization function, processes message loop
00091 *
00092 *  COMMENTS:
00093 *
00094 \*************************************************************************/
00095
00096 int PASCAL WinMain (HINSTANCE hInstance,
00097                     HINSTANCE hPrevInstance,
00098                     LPSTR  lpCmdLine,
00099                     int    nCmdShow)
00100 {
00101   MSG  msg;
00102   WNDCLASS wc;
00103
00104   UNREFERENCED_PARAMETER( lpCmdLine );
00105   UNREFERENCED_PARAMETER( hPrevInstance );
00106
00107   hInst = hInstance;
00108
00109   wc.style = 0;
00110   wc.lpfnWndProc = (WNDPROC)MainWndProc;
00111   wc.cbClsExtra = 0;
00112   wc.cbWndExtra = 0;
00113   wc.hInstance = hInstance;
00114   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00115   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
00116   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00117   wc.lpszMenuName = "Virtmem_Menu";
00118   wc.lpszClassName = "VirtmemWClass";
00119
00120   RegisterClass(&wc);
00121
00122
00123   hWnd = CreateWindow ("VirtmemWClass",
00124                        "Virtual Memory Sample",
00125                        WS_OVERLAPPEDWINDOW,
00126                        CW_USEDEFAULT,
00127                        CW_USEDEFAULT,
00128                        CW_USEDEFAULT,
00129                        CW_USEDEFAULT,
00130                        NULL,
00131                        NULL,
00132                        hInstance,
00133                        NULL);
00134
00135
00136   ShowWindow(hWnd, nCmdShow);
00137   while (GetMessage (&msg, NULL, 0, 0))
00138     DispatchMessage (&msg);      // Dispatch message to window.
00139
00140   return (msg.wParam);           // Returns value from PostQuitMessage.
00141
00142 }
00143
00144 /*************************************************************************\
00145 *
00146 *  FUNCTION:  MainWndProc (HWND, UINT, WPARAM, LPARAM)
00147 *
00148 *  PURPOSE:   To process the windows messages.
00149 *
00150 *  VARIABLES USED:
00151 *
00152 *    - Buf[]: Array of CHAR, error message buffer.
00153 *    - retCode:
00154 *             DWORD used to trap return codes.
00155 *    - oldProtection:
00156 *             DWORD used to hold the old protection value returned from
00157 *             VirtualProtect() call.
00158 *    - page:  Array of CHAR, used as a base pointer to the page.
00159 *    - ExceptError[]:
00160 *             Array of CHAR, used to be printed as an error message string.
00161 *    - ExceptSuccess[]:
00162 *             Array of CHAR, used to be printed an a success message string.
00163 *
00164 *  MESSAGES:
00165 *
00166 *    WM_DESTROY:     - Terminates the threads and post the quit message.
00167 *    WM_CREATE:      - Allocates memory to hold some color values, and
00168 *                      creates the two threads.
00169 *    WM_USER:        - Used to delay the message to reset the menu until
00170 *                      the window is created.
00171 *
00172 *    WM_COMMAND
00173 *
00174 *      IDM_LOCK:
00175 *               Uses VirtualLock() to lock the page into memory (preventing
00176 *               it from being paged out.
00177 *
00178 *      IDM_UNLOCK:
00179 *               Unlocks the page from memory allowing it to be paged out
00180 *               by the system.
00181 *
00182 *      IDM_WRITE:
00183 *               Attempts to write to the page.  This message uses structured
00184 *               exception handling and tries to write to offset 100 in the
00185 *               page.  If there is an exception (usually due to the memory
00186 *               not being committed, or not having the proper read/write
00187 *               access), then the exception is handled by putting up a message
00188 *               box.  If no exception is trapped, a success message is
00189 *               put up.
00190 *
00191 *      IDM_SHOW:
00192 *               Puts up a dialog box which gives information about the current
00193 *               state of the page (See comments on ShowDlgProc);
00194 *
00195 *      IDM_NOACCESS:
00196 *               Uses VirtualProtect() to change the protection on the page
00197 *               to PAGE_NOACCESS.  Note a page must be committed before
00198 *               changing its protection.
00199 *
00200 *      IDM_READONLY:
00201 *               Uses VirtualProtect() to change the protection on the page to
00202 *               PAGE_READONLY.  Note a page must be committed before changing
00203 *               its protection.
00204 *
00205 *      IDM_READWRITE:
00206 *               Uses VirtualProtect() to change the protection on the page to
00207 *               PAGE_READWRITE.  Note a page must be committed before
00208 *               changing its protection.
00209 *
00210 *      IDM_COMMIT:
00211 *               Uses VirtualAlloc() to commit the page.  Note that if the
00212 *               page has been previously RESERVED with VirtualAlloc, then
00213 *               you can use a pointer to the base of the memory as the first
00214 *               parameter of the call.  If the page is FREE rather than
00215 *               RESERVED, then you use NULL as the first parameter.
00216 *
00217 *      IDM_FREE:
00218 *               Uses VirtualFree() to commit the page.  Note that a committed
00219 *               page must first be decommitted before it can be freed.
00220 *
00221 *      IDM_RESERVE:
00222 *               If the page is FREE, this uses VirtualAlloc() reserve it.
00223 *               If the page is committed, this uses VirtualFree() to
00224 *               decommit the page.
00225 *
00226 *  CALLED BY:
00227 *
00228 *    WinMain();
00229 *
00230 *  CALLS TO:
00231 *
00232 *    ResetMenu();
00233 *    ShowDlgProc();
00234 *
00235 *  COMMENTS:
00236 *
00237 *
00238 \*************************************************************************/
00239
00240
00241 LRESULT CALLBACK MainWndProc (HWND hwnd,
00242                               UINT message,
00243                               WPARAM wParam,
00244                               LPARAM lParam)
00245 {
00246   CHAR  Buf[80];
00247   DWORD retCode;
00248   DWORD oldProtection;
00249   CHAR  *page;
00250   CHAR  ExceptError[200] = "An exception was trapped and handled with this message box.\
00251     Make sure the page is commited and that you have Read/Write access.";
00252   CHAR ExceptSuccess[] = "Writing to memory was successful: base[100] = 'a'";
00253
00254   switch (message)
00255       {
00256
00257         case WM_CREATE:
00258
00259             base = VirtualAlloc (NULL,
00260                                  PAGESIZE,
00261                                  MEM_RESERVE,
00262                                  PAGE_NOACCESS);
00263
00264             if (!base)
00265               WERR ("VirtualAlloc", "WM_CREATE");
00266
00267             PostMessage (hwnd, WM_USER, 0, 0);
00268
00269             return (0);
00270
00271
00272         case WM_USER:
00273             ResetMenu();
00274             return (0);
00275
00276         case WM_COMMAND:
00277           switch (LOWORD(wParam))
00278             {
00279
00280 #ifdef IMPLEMENTED
00281
00282             case IDM_LOCK:
00283
00284               VirtualQuery (base, &MemInfo, sizeof(MemInfo));
00285               if (MemInfo.State != MEM_COMMIT)
00286                 {
00287                 MessageBox (hWnd,
00288                            "Stop!  You must first COMMIT a page before locking it.",
00289                             "From IDM_LOCK", MB_OK);
00290                 return (0);
00291                 }
00292
00293               retCode = VirtualLock(base, PAGESIZE);
00294               if (!retCode)
00295
00296                   MessageBox(hWnd, "Error in locking memory",
00297                              "From within IDM_LOCK", MB_OK);
00298                 else
00299                   MessageBox(hWnd, "The Memory was Locked.",
00300                              "From within IDM_LOCK", MB_OK);
00301
00302               return (0);
00303
00304             case IDM_UNLOCK:
00305
00306               retCode = VirtualUnlock(base, PAGESIZE);
00307               if (!retCode)
00308
00309                   MessageBox(hWnd, "Error in unlocking memory",
00310                              "From within IDM_UNLOCK", MB_OK);
00311                 else
00312                   MessageBox(hWnd, "The Memory was Unlocked.",
00313                              "From within IDM_UNLOCK", MB_OK);
00314
00315               return (0);
00316
00317 #endif
00318
00319             case IDM_WRITE:
00320               __try
00321                 {
00322                  base[100] = 'a';
00323                  MessageBox (hWnd, ExceptSuccess, "try/except", MB_OK);
00324                 }
00325               __except (EXCEPTION_EXECUTE_HANDLER)
00326                 {
00327                  MessageBox (hWnd, ExceptError, "try/except", MB_OK);
00328                 }
00329               return (0);
00330
00331
00332             case IDM_SHOW:
00333               DialogBox (hInst, "Page_Info", hwnd, (DLGPROC)ShowDlgProc);
00334               return (0);
00335
00336
00337             case IDM_NOACCESS:
00338
00339               retCode = VirtualQuery (base, &MemInfo,
00340                                       sizeof(MEMORY_BASIC_INFORMATION));
00341               if (!retCode)
00342                 {
00343                  WERR("VirtualQuery", "IDM_NOACCESS");
00344                  return (0);
00345                 }
00346
00347               if (MemInfo.State != MEM_COMMIT)
00348                 {
00349                  MessageBox ( hWnd, "The page must be commited first.",
00350                              "From IDM_NOACCESS", MB_OK);
00351                  return (0);
00352                 }
00353
00354               retCode = VirtualProtect (base, PAGESIZE,
00355                                         PAGE_NOACCESS, &oldProtection);
00356               if (!retCode)
00357                  WERR("VirtualProtect","IDM_NOACCESS");
00358
00359               ResetMenu();
00360               return (0);
00361
00362
00363             case IDM_READONLY:
00364               retCode = VirtualQuery (base, &MemInfo,
00365                                       sizeof(MEMORY_BASIC_INFORMATION));
00366               if (!retCode)
00367                 {
00368                  WERR("VirtualQuery", "IDM_READONLY");
00369                  return (0);
00370                 }
00371
00372               if (MemInfo.State != MEM_COMMIT)
00373                 {
00374                  MessageBox ( hWnd, "The page must be commited first.",
00375                              "From IDM_READONLY", MB_OK);
00376                  return (0);
00377                 }
00378
00379               retCode = VirtualProtect (base, PAGESIZE,
00380                                         PAGE_READONLY, &oldProtection);
00381               if (!retCode)
00382                 WERR("VirtualProtect", "IDM_READONLY");
00383
00384               ResetMenu();
00385               return (0);
00386
00387
00388             case IDM_READWRITE:
00389               retCode = VirtualQuery (base, &MemInfo,
00390                                       sizeof(MEMORY_BASIC_INFORMATION));
00391               if (!retCode)
00392                 {
00393                  WERR("VirtualQuery", "IDM_READWRITE");
00394                  return (0);
00395                 }
00396
00397               if (MemInfo.State != MEM_COMMIT)
00398                 {
00399                  MessageBox ( hWnd, "The page must be commited first.",
00400                              "From IDM_READWRITE", MB_OK);
00401                  return (0);
00402                 }
00403
00404               retCode = VirtualProtect (base, PAGESIZE,
00405                                         PAGE_READWRITE, &oldProtection);
00406               if (!retCode)
00407                  WERR("VirtualProtect", "IDM_READWRITE");
00408
00409               ResetMenu();
00410               return (0);
00411
00412
00413             case IDM_COMMIT:
00414
00415               VirtualQuery ((LPVOID)base,
00416                             &MemInfo,
00417                             sizeof(MEMORY_BASIC_INFORMATION));
00418
00419               switch (MemInfo.State)
00420                 {
00421                 case MEM_COMMIT:
00422                   return (0);
00423
00424                 case MEM_RESERVE:
00425                   page = VirtualAlloc (base,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);
00426
00427                   if (page)
00428                     ResetMenu();
00429                   else
00430                     WERR("VirtualAlloc", "IDM_COMMIT");
00431                   break;
00432
00433                 case MEM_FREE:
00434                   base = VirtualAlloc(NULL,PAGESIZE,MEM_COMMIT,PAGE_READWRITE);
00435                   if (base)
00436                     ResetMenu();
00437                   else
00438                     WERR("VirtualAlloc", "IDM_COMMIT");
00439                   break;
00440                 }
00441
00442               ResetMenu();
00443               return (0);
00444
00445
00446             case IDM_FREE:
00447
00448               VirtualQuery (base,
00449                             &MemInfo,
00450                             sizeof(MEMORY_BASIC_INFORMATION));
00451
00452               if (MemInfo.State == MEM_COMMIT)
00453                 {
00454                 retCode = VirtualFree(base, PAGESIZE, MEM_DECOMMIT);
00455                 if (!retCode)
00456                   WERR("VirtualFree","IDM_FREE");
00457
00458                 }
00459
00460               VirtualQuery (base,
00461                             &MemInfo,
00462                             sizeof(MEMORY_BASIC_INFORMATION));
00463
00464               if (MemInfo.State == MEM_RESERVE)
00465                 {
00466                 retCode = VirtualFree(base, 0, MEM_RELEASE);
00467                 if (!retCode)
00468                   WERR("VirtualFree", "IDM_FREE");
00469                 }
00470
00471               ResetMenu();
00472               return (0);
00473
00474
00475
00476             case IDM_RESERVE:
00477
00478               VirtualQuery ((LPVOID)base,
00479                             &MemInfo,
00480                             sizeof(MEMORY_BASIC_INFORMATION));
00481
00482               switch (MemInfo.State)
00483                 {
00484                  case MEM_RESERVE:
00485                    return (0);
00486
00487                  case MEM_FREE:
00488                    base = VirtualAlloc(NULL, PAGESIZE, MEM_RESERVE, PAGE_NOACCESS);
00489                    if (!base)
00490                      WERR("VirtualAlloc","IDM_RESERVE");
00491
00492                    ResetMenu();
00493                    return (0);
00494
00495                  case MEM_COMMIT:
00496                    retCode = VirtualFree(base, PAGESIZE, MEM_DECOMMIT);
00497
00498                    if (!retCode)
00499                      WERR("VirtualFree","IDM_RESERVE");
00500
00501                    ResetMenu();
00502                    return (0);
00503
00504                  default:
00505                    MessageBox(hWnd, "Unknown MemInfo.State", "From IDM_RESERVE", MB_OK);
00506
00507                 }
00508               return (0);
00509
00510             default:
00511               return (0);
00512             }
00513
00514         case WM_DESTROY:
00515           PostQuitMessage(0);
00516           return (0);
00517
00518
00519        }
00520     return DefWindowProc (hwnd, message, wParam, lParam);
00521 }
00522
00523
00524 /*************************************************************************\
00525 *
00526 *  FUNCTION:  VOID ResetMenu (VOID)
00527 *
00528 *  PURPOSE:   Updates the menu with check marks to indicate the pages state
00529 *             and protection.
00530 *
00531 *  VARIABLES USED:
00532 *
00533 *    - i:     Local integer used for counting in a for loop.
00534 *    - hMenu: Local menu handle to the menu.
00535 *
00536 *  CALLED BY:
00537 *
00538 *    MainWndProc();
00539 *
00540 *  COMMENTS:
00541 *    This function uses a for loop to uncheck all the menu items.  It then
00542 *    calls VirtualQuery() to  determine information about the page, and
00543 *    updates the menu items with check marks as appropriate.
00544 *
00545 \*************************************************************************/
00546
00547 VOID ResetMenu (VOID)
00548 {
00549
00550   HMENU hMenu;
00551   INT   i;
00552
00553   hMenu = GetMenu(hWnd);
00554
00555   for (i = IDM_FREE; i <= IDM_READWRITE; i++)
00556     CheckMenuItem(hMenu, i, MF_BYCOMMAND | MF_UNCHECKED);
00557
00558
00559   VirtualQuery (base,
00560                 &MemInfo,
00561                 sizeof(MEMORY_BASIC_INFORMATION));
00562
00563   switch (MemInfo.State)
00564     {
00565     case MEM_COMMIT:
00566        CheckMenuItem(hMenu,
00567                      IDM_COMMIT,
00568                      MF_BYCOMMAND | MF_CHECKED);
00569        break;
00570
00571     case MEM_FREE:
00572        CheckMenuItem(hMenu,
00573                      IDM_FREE,
00574                      MF_BYCOMMAND | MF_CHECKED);
00575        break;
00576
00577     case MEM_RESERVE:
00578        CheckMenuItem(hMenu,
00579                      IDM_RESERVE,
00580                      MF_BYCOMMAND | MF_CHECKED);
00581        break;
00582     }
00583
00584
00585   switch (MemInfo.Protect)
00586     {
00587     case 0:
00588       break;
00589
00590     case PAGE_READWRITE:
00591       CheckMenuItem(hMenu,
00592                     IDM_READWRITE,
00593                     MF_BYCOMMAND | MF_CHECKED);
00594
00595       break;
00596
00597     case PAGE_READONLY:
00598       CheckMenuItem(hMenu,
00599                     IDM_READONLY,
00600                     MF_BYCOMMAND | MF_CHECKED);
00601       break;
00602
00603     case PAGE_NOACCESS:
00604       CheckMenuItem(hMenu,
00605                     IDM_NOACCESS,
00606                     MF_BYCOMMAND | MF_CHECKED);
00607       break;
00608     }
00609 }
00610
00611
00612 /*************************************************************************\
00613 *
00614 *  FUNCTION:  BOOL CALLBACK ShowDlgProc (HWND, UINT, WPARAM, LPARAM)
00615 *
00616 *  PURPOSE:   This is a dialog box function which queries page information
00617 *             using VirtualQuery, and then displays the information in
00618 *             the appropriate edit fields.
00619 *
00620 *  MESSAGES:
00621 *
00622 *    WM_SYSCOMMAND:
00623 *             If this message is trapped, the dialog box is terminated.
00624 *
00625 *    WM_INITDIALOG:
00626 *             Does a VirtualQuery, checks the values returned in the
00627 *             fields of the MEMORY_BASIC_INFORMATION structure, and
00628 *             fills the edit fields of the dialog box with the appropriate
00629 *             information.
00630 *
00631 *  CALLED BY:
00632 *
00633 *    MainWndProc();
00634 *
00635 \*************************************************************************/
00636
00637 BOOL CALLBACK ShowDlgProc (HWND hdlg,
00638                            UINT message,
00639                            WPARAM wParam,
00640                            LPARAM lParam)
00641 {
00642   UNREFERENCED_PARAMETER( lParam );
00643
00644   switch (message)
00645     {
00646     case WM_SYSCOMMAND:
00647       if (wParam == SC_CLOSE)
00648         {
00649          EndDialog(hdlg, TRUE);
00650          return (TRUE);
00651         }
00652       return (0);
00653
00654     case WM_INITDIALOG:
00655
00656       VirtualQuery ((LPVOID)base,
00657                     &MemInfo,
00658                     sizeof(MEMORY_BASIC_INFORMATION));
00659
00660       SetDlgItemInt (hdlg, IDE_BASEADDR,  (int)MemInfo.BaseAddress,    FALSE);
00661       SetDlgItemInt (hdlg, IDE_ALLOCBASE, (int)MemInfo.AllocationBase, FALSE);
00662
00663       switch (MemInfo.AllocationProtect)
00664         {
00665         case PAGE_NOACCESS:
00666             SetDlgItemText (hdlg, IDE_INITPROT, "No Access");
00667             break;
00668
00669         case PAGE_READONLY:
00670             SetDlgItemText (hdlg, IDE_INITPROT, "Read Only");
00671             break;
00672
00673         case PAGE_READWRITE:
00674             SetDlgItemText (hdlg, IDE_INITPROT, "Read/Write");
00675             break;
00676
00677         default:
00678             SetDlgItemText (hdlg, IDE_INITPROT, "Unknown");
00679
00680         }
00681
00682       SetDlgItemInt (hdlg, IDE_SIZE, MemInfo.RegionSize, FALSE);
00683
00684
00685       switch (MemInfo.State)
00686         {
00687         case MEM_FREE:
00688             SetDlgItemText (hdlg, IDE_STATE, "Free");
00689             break;
00690
00691         case MEM_RESERVE:
00692             SetDlgItemText (hdlg, IDE_STATE, "Reserved");
00693             break;
00694
00695         case MEM_COMMIT:
00696             SetDlgItemText (hdlg, IDE_STATE, "Commited");
00697             break;
00698
00699         default:
00700             SetDlgItemText (hdlg, IDE_STATE, "Unknown");
00701
00702         }
00703
00704
00705       switch (MemInfo.Protect)
00706         {
00707         case 0:
00708             SetDlgItemText (hdlg, IDE_PROTECT, "Undefined");
00709             break;
00710
00711         case PAGE_NOACCESS:
00712             SetDlgItemText (hdlg, IDE_PROTECT, "No Access");
00713             break;
00714
00715         case PAGE_READONLY:
00716             SetDlgItemText (hdlg, IDE_PROTECT, "Read Only");
00717             break;
00718
00719         case PAGE_READWRITE:
00720             SetDlgItemText (hdlg, IDE_PROTECT, "Read/Write");
00721             break;
00722
00723         default:
00724             SetDlgItemText (hdlg, IDE_PROTECT, "Unknown");
00725
00726         }
00727
00728
00729       return (TRUE);
00730
00731     default:
00732       return (0);
00733
00734     }
00735
00736   return (0);
00737
00738 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/DDECBACK.C Source File

  • NETDDE

DDECBACK.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   ddecback.c
00009 //
00010 //  PURPOSE:   Contains the DDEML Callback procedure
00011 //
00012 //  FUNCTIONS:
00013 //    DdeCallback - callback routine for the ddeml conversation
00014 //
00015 //  COMMENTS:
00016 //
00017 //  AUTHOR:  Craig Link - Microsoft Developer Support
00018 //
00019
00020 #include <windows.h>            // required for all Windows applications
00021 #include <windowsx.h>
00022 #ifdef WIN16
00023 #include "win16ext.h"           // required only for win16 applications
00024 #endif
00025 #include "globals.h"            // prototypes specific to this application
00026 #include "mem.h"
00027 #include "ddecback.h"
00028
00029
00030
00031 //  FUNCTION: DdeCallback ( UINT, UINT, HCONV, HSZ, HSZ, HDDEDATA,
00032 //                          DWORD, DWORD )
00033 //
00034 //  PURPOSE:  Process ddeml conversation messages
00035 //
00036 //  PARAMETERS:
00037 //    lplpv - address of pointer to newly allocated memory
00038 //    dwSize - number of bytes to allocate
00039 //
00040 //  RETURN VALUE:
00041 //    ERROR_SUCCESS
00042 //    ERROR_NOT_ENOUGH_MEMORY
00043 //
00044 //
00045 HDDEDATA CALLBACK DdeCallback (UINT iType, UINT iFmt, HCONV hConv,
00046                                HSZ hsz1, HSZ hsz2, HDDEDATA hData,
00047                                DWORD dwData1, DWORD dwData2)
00048 {
00049     char szBuffer[128];
00050     LPSTR psz;
00051     DWORD cbBytes;
00052
00053     switch (iType)
00054     {
00055
00056         //** DDEML messages handled by client side of the conversation **//
00057         case XTYP_ADVDATA:
00058             // Check for matching format and data item
00059             if (iFmt != CF_TEXT)
00060                 return (HDDEDATA) DDE_FNOTPROCESSED ;
00061
00062             if ( g_fState == STATE_PENDING )
00063             {
00064                 PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
00065                 return (HDDEDATA) DDE_FACK ;
00066             }
00067
00068             // get data being advised
00069             cbBytes = DdeGetData (hData, NULL, 0, 0) ;
00070             if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
00071             {
00072                 DdeGetData( hData, psz, cbBytes, 0 );
00073                 PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM)cbBytes, (LPARAM)psz );
00074             }
00075             return (HDDEDATA) DDE_FACK ;
00076             break;
00077
00078
00079         //** DDEML messages handled by both sides of the conversation **//
00080         case XTYP_DISCONNECT:
00081             PostMessage( g_hwnd, WM_DISCONNECT, 0L, (LPARAM)hConv );
00082             return (HDDEDATA) TRUE ;
00083             break;
00084
00085
00086         //** DDEML messages handled by server side of the conversation **//
00087         case XTYP_CONNECT:
00088             // hsz1 = topic, hsz2 = service
00089             if ( g_fState  != STATE_UNCONN)
00090                 return (HDDEDATA) FALSE;
00091
00092             // validate service for connection
00093             DdeQueryString (g_idInst, hsz2, (LPSTR)szBuffer, 128, 0) ;
00094
00095             if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)szAppName))
00096                 return (HDDEDATA) FALSE ;
00097
00098             // validate topic for connection
00099             DdeQueryString (g_idInst, hsz1, (LPSTR)szBuffer, 128, 0) ;
00100
00101             if (0 != lstrcmp ( (LPSTR) szBuffer, (LPSTR)g_szTopic))
00102                 return (HDDEDATA) FALSE ;
00103
00104             g_fState = STATE_SERVER;
00105             return (HDDEDATA) TRUE;
00106             break;
00107
00108         case XTYP_CONNECT_CONFIRM:
00109             PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM) hConv );
00110             return (HDDEDATA) TRUE;
00111             break;
00112
00113         case XTYP_POKE:
00114             if (iFmt != CF_TEXT)
00115                 return (HDDEDATA) DDE_FNOTPROCESSED;
00116
00117             // get data being poked
00118             cbBytes = DdeGetData (hData, NULL, 0, 0) ;
00119             if ( MallocMem( (LPVOID *) &psz, cbBytes ) == ERROR_SUCCESS )
00120             {
00121                 DdeGetData( hData, psz, cbBytes, 0 );
00122
00123                 if ( STR_DWORD(psz) == (DWORD) -1 ) // computer name poked
00124                 {
00125                     wsprintf( (LPSTR)g_szServer, psz );
00126                     PostMessage( g_hwnd, WM_CONNECT, 0, (LPARAM)hConv );
00127                 }
00128                 else
00129                     PostMessage( g_hwnd, WM_RECEIVE_TEXT, (WPARAM) cbBytes, (LPARAM)psz );
00130
00131                 return (HDDEDATA) DDE_FACK;
00132             }
00133             break;
00134
00135         case XTYP_ADVSTART:
00136 #ifdef WIN16
00137             PostMessage( g_hwnd, WM_COMMAND, (WPARAM) IDE_SEND, MAKELONG( hwndSend, EN_CHANGE ) );
00138 #else
00139             PostMessage( g_hwnd, WM_COMMAND, MAKELONG( IDE_SEND, EN_CHANGE ), (LPARAM) hwndSend );
00140 #endif
00141             return (HDDEDATA) TRUE;
00142             break;
00143
00144         case XTYP_ADVREQ:  // send data
00145             return GetDataToTrans();
00146             break;
00147
00148         case XTYP_ADVSTOP:  // stop advising client
00149             return (HDDEDATA) TRUE ;
00150             break;
00151
00152      }
00153
00154      return (HDDEDATA) 0 ;
00155 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MASKBLT/BITMAP.H Source File

  • MASKBLT

BITMAP.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* bitmap.h  */
00013
00014 /* function prototypes */
00015 VOID DrawBitmap (HDC, HBITMAP);
00016 HBITMAP GetBitmap (HDC, HANDLE, BOOL);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/APP16.C Source File

  • INTEROP

APP16.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *  Julie Solon                                                       *
00003 *  Microsoft Developer Support                                       *
00004 *  Copyright (c) 1992-1996 Microsoft Corporation                          *
00005 *                                                                    *
00006 *  Comments:                                                         *
00007 *     Demonstrates a Win16 app (app16.exe) calling routines in a     *
00008 *     Win32 DLL (dll32.dll) on Win32s and Windows NT. On Win32s, the *
00009 *     user has a choice of Reverse Universal Thunks or WM_COPYDATA.  *
00010 *     On Windows NT, the user has a choice of Generic Thunks or      *
00011 *     WM_COPYDATA.
00012 *                                                                    *
00013 *  Modules in sample:                                                *
00014 *     app16.c    -  Win16 Application (this file)                    *
00015 *     dll16.c    -  16-bit side of Universal Thunk/Generic Thunk     *
00016 *     stub32.c   -  32-bit stub that loads the 32-bit DLLs on Win32s *
00017 *     utdll32.c  -  32-bit side of the Universal Thunk               *
00018 *     disp32.c   -  Dispatch calls sent through WM_COPYDATA (both    *
00019 *                   platforms)                                       *
00020 *     dll32.c    -  Win32 DLL                                        *
00021 *                                                                    *
00022 *  Functions in this module:                                         *
00023 *     WinMain()                                                      *
00024 *     MainWndProc()                                                  *
00025 *     InfoDlgProc()                                                  *
00026 *     AboutDlgProc()                                                 *
00027 *                                                                    *
00028 \********************************************************************/
00029
00030 /*********************  Header Files  *********************/
00031
00032 #include <windows.h>
00033 #include <stdlib.h>
00034 #include "app16.h"
00035 #include "myut.h"
00036
00037 /*********************  Definitions   *********************/
00038
00039 typedef struct tagCOPYDATASTRUCT
00040 {
00041    DWORD dwData;
00042    DWORD cbData;
00043    VOID FAR *lpData;
00044 } COPYDATASTRUCT, FAR *LPCOPYDATASTRUCT;
00045
00046 #define WM_COPYDATA 0x004A
00047
00048 typedef struct tagMYREC
00049 {
00050    char  s1[80];
00051    char  s2[80];
00052    DWORD n;
00053 } MYREC;
00054
00055 /*********************  Globals       *********************/
00056
00057 HANDLE ghWnd;
00058 HINSTANCE ghInstance;
00059
00060 char  szFirstName[80];
00061 char  szLastName[80];
00062 DWORD nAge;
00063
00064 /*********************  Prototypes    *********************/
00065
00066 LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM );
00067 BOOL CALLBACK InfoDlgProc( HWND, UINT, WPARAM, LPARAM );
00068 BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );
00069
00070 void WINAPI MyPrint( LPSTR, LPSTR, DWORD );
00071
00072 /********************************************************************\
00073 *  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
00074 *                                                                    *
00075 *   Purpose: Initializes Application                                 *
00076 *                                                                    *
00077 *  Comments: Standard template                                       *
00078 *                                                                    *
00079 *                                                                    *
00080 \********************************************************************/
00081
00082 int PASCAL WinMain( HINSTANCE hInstance,
00083                     HINSTANCE hPrevInstance,
00084                     LPSTR lpszCmdLine,
00085                     int nCmdShow )
00086 {
00087    WNDCLASS wc;
00088    MSG msg;
00089    HWND hWnd;
00090
00091    if( !hPrevInstance ) {
00092       wc.lpszClassName = "App16Class";
00093       wc.lpfnWndProc = MainWndProc;
00094       wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
00095       wc.hInstance = hInstance;
00096       wc.hIcon = LoadIcon( hInstance, "App16Icon" );
00097       wc.hCursor = LoadCursor( NULL, IDC_ARROW );
00098       wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
00099       wc.lpszMenuName = "App16Menu";
00100       wc.cbClsExtra = 0;
00101       wc.cbWndExtra = 0;
00102
00103       RegisterClass( &wc );
00104    }
00105
00106    hWnd = CreateWindow( "App16Class",
00107                         "App16",
00108                         WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
00109                         0,
00110                         0,
00111                         CW_USEDEFAULT,
00112                         CW_USEDEFAULT,
00113                         NULL,
00114                         NULL,
00115                         hInstance,
00116                         NULL
00117           );
00118
00119    ghWnd = hWnd;
00120    ghInstance = hInstance;
00121
00122    ShowWindow( hWnd, nCmdShow );
00123
00124    while( GetMessage( &msg, NULL, 0, 0 ) ) {
00125       TranslateMessage( &msg );
00126       DispatchMessage( &msg );
00127    }
00128
00129    return msg.wParam;
00130 }
00131
00132 /********************************************************************\
00133 * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
00134 *                                                                    *
00135 *  Purpose: Processes Application Messages                           *
00136 *                                                                    *
00137 * Comments: The following messages are processed                     *
00138 *                                                                    *
00139 *           WM_COMMAND                                               *
00140 *           WM_DESTROY                                               *
00141 *                                                                    *
00142 *                                                                    *
00143 \********************************************************************/
00144
00145 LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
00146    LPARAM lParam )
00147 {
00148    COPYDATASTRUCT MyCDS;
00149    MYREC MyRec;
00150    HWND hwDispatch;
00151
00152    switch( msg ) {
00153
00154 /**************************************************************\
00155 *     WM_COMMAND: Process menu commands                        *
00156 \**************************************************************/
00157
00158       case WM_COMMAND:
00159          switch( wParam ) {
00160             case IDM_THUNK:
00161
00162             /* Get data from user (stored in globals) */
00163
00164                DialogBox( ghInstance, "InfoDlg", hWnd, (DLGPROC)
00165                              InfoDlgProc );
00166
00167             /* Call routine (through thunk) */
00168
00169                MyPrint( (LPSTR) szFirstName,
00170                         (LPSTR) szLastName,
00171                         (DWORD) nAge );
00172                break;
00173
00174             case IDM_COPYDATA:
00175
00176             /* Get data from user (stored in globals) */
00177
00178                DialogBox( ghInstance, "InfoDlg", hWnd, (DLGPROC)
00179                              InfoDlgProc );
00180
00181             /* Copy data into structure to be passed via WM_COPYDATA */
00182
00183                lstrcpy( MyRec.s1, szFirstName );
00184                lstrcpy( MyRec.s2, szLastName );
00185                MyRec.n = nAge;
00186
00187             /* Fill the COPYDATA structure */
00188
00189                MyCDS.dwData = MYPRINT;          // function identifier
00190                MyCDS.cbData = sizeof( MyRec );  // size of data
00191                MyCDS.lpData = &MyRec;           // data structure
00192
00193             /* Call function through identifier, passing data in &MyCDS */
00194
00195                hwDispatch = FindWindow( "Disp32Class", "Hidden Window" );
00196                if( hwDispatch != NULL )
00197                   SendMessage( hwDispatch,
00198                                WM_COPYDATA,
00199                                (WPARAM)(HWND) hWnd,
00200                                (LPARAM) (VOID FAR *) &MyCDS );
00201                else
00202                   MessageBox( hWnd, "Can't send WM_COPYDATA", "app16",
00203                               MB_OK );
00204                break;
00205             case IDM_EXIT:
00206                SendMessage( hWnd, WM_CLOSE, 0, 0 );
00207                break;
00208             case IDM_ABOUT:
00209                DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
00210                              AboutDlgProc );
00211                break;
00212          }
00213          break;
00214
00215 /**************************************************************\
00216 *     WM_DESTROY: PostQuitMessage() is called                  *
00217 \**************************************************************/
00218
00219       case WM_DESTROY:
00220          PostQuitMessage( 0 );
00221          break;
00222
00223 /**************************************************************\
00224 *     Let the default window proc handle all other messages    *
00225 \**************************************************************/
00226
00227       default:
00228          return( DefWindowProc( hWnd, msg, wParam, lParam ));
00229    }
00230
00231    return 0;
00232 }
00233
00234 /********************************************************************\
00235 * Function: BOOL CALLBACK InfoDlgProc(HWND, UINT, WPARAM, LPARAM)    *
00236 *                                                                    *
00237 *  Purpose: Gets information for data record to be sent              *
00238 *                                                                    *
00239 * Comments: The dialog box is displayed when the user selects        *
00240 *           Send Data.Thunk or Send Data.WM_COPYDATA.                *
00241 *                                                                    *
00242 \********************************************************************/
00243
00244
00245 BOOL CALLBACK InfoDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam,
00246                               LPARAM lParam )
00247 {
00248    char szAge[5];
00249
00250    switch( uMsg ) {
00251       case WM_INITDIALOG:
00252          szFirstName[0] = '\0';
00253          szLastName[0] = '\0';
00254          nAge = 0;
00255          return TRUE;
00256       case WM_COMMAND:
00257          switch( wParam ) {
00258             case ID_OK:
00259                SendMessage( GetDlgItem(hDlg, IDC_FIRSTNAME), WM_GETTEXT,
00260                   sizeof(szFirstName), (LPARAM) ((LPSTR) szFirstName) );
00261                SendMessage( GetDlgItem(hDlg, IDC_LASTNAME), WM_GETTEXT,
00262                   sizeof(szLastName), (LPARAM) ((LPSTR) szLastName) );
00263                SendMessage( GetDlgItem(hDlg, IDC_AGE), WM_GETTEXT,
00264                   sizeof(szAge), (LPARAM) ((LPSTR) szAge) );
00265                nAge = atoi( szAge );
00266                EndDialog( hDlg, TRUE );
00267                return TRUE;
00268             case ID_CANCEL:
00269                EndDialog( hDlg, FALSE );
00270                return TRUE;
00271          }
00272       break;
00273    }
00274    return FALSE;
00275 }
00276
00277 /********************************************************************\
00278 * Function: BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)   *
00279 *                                                                    *
00280 *  Purpose: Processes "About" Dialog Box Messages                    *
00281 *                                                                    *
00282 * Comments: The dialog box is displayed when the user selects        *
00283 *           Help.About.                                              *
00284 *                                                                    *
00285 \********************************************************************/
00286
00287
00288 BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
00289 {
00290    switch( uMsg ) {
00291       case WM_INITDIALOG:
00292          return TRUE;
00293       case WM_COMMAND:
00294          switch( wParam ) {
00295             case IDOK:
00296                EndDialog( hDlg, TRUE );
00297                return TRUE;
00298          }
00299       break;
00300    }
00301    return FALSE;
00302 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SHAREMEM/SHAREMEM.H Source File

  • SHAREMEM

SHAREMEM.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDE_XCOORD                  101
00013 #define IDE_YCOORD                  102
00014
00015
00016 #define DIALOGHEIGHT                45
00017
00018
00019
00020 LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/BITMAP.C Source File

  • STREBLT

BITMAP.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  bitmap.c -- support for reading in and drawing bitmaps.
00014 \**************************************************************************/
00015
00016 #include <windows.h>
00017 #include <commdlg.h>
00018
00019
00020
00021 /**************************************************************************\
00022 *
00023 *  function:  DrawBitmap()
00024 *
00025 *  input parameters:  HDC, HBITMAP
00026 *
00027 *  Draw the bitmap into the hdc.  Source rectangle computed to include the
00028 *   whole bitmap.  Destination location is 0,0.
00029 *
00030 *  global variables: none.
00031 *
00032 \**************************************************************************/
00033 VOID DrawBitmap (HDC hdc, HBITMAP hbm)
00034 {
00035     BOOL f;
00036     HDC hdcBits;
00037     BITMAP bm;
00038
00039     hdcBits = CreateCompatibleDC(hdc);
00040     GetObject (hbm, sizeof(BITMAP), &bm);
00041     SelectObject(hdcBits,hbm);
00042     f = BitBlt(hdc,0,0,bm.bmWidth, bm.bmHeight,hdcBits,0,0,SRCCOPY);
00043     DeleteDC(hdcBits);
00044 }
00045
00046
00047
00048 /**************************************************************************\
00049 *
00050 *  function:  GetBitmap()
00051 *
00052 *  input parameters:
00053 *   hdc - hdc to make the bitmap compatible with.
00054 *   hInst - instance handle
00055 *
00056 *  Put up a common dialog box to open a new *.BMP file.
00057 *   Once this is complete, open the file, read in the information,
00058 *   and create a compatible bitmap.
00059 *
00060 *  returns:  handle to the bitmap iff successful.  NULL otherwise.
00061 *
00062 \**************************************************************************/
00063 HBITMAP GetBitmap (HDC hdc, HANDLE hInst, BOOL monochrome)
00064 {
00065     HBITMAP hbm;
00066     PBITMAPFILEHEADER pbmfh;
00067     PBITMAPINFOHEADER pbmih;
00068     PBYTE             pBits;
00069     int fh;
00070     int bfOffBits;
00071     int nbytes;
00072     OPENFILENAME  of;
00073     char buffer [MAX_PATH];
00074
00075     buffer[0] = 0;
00076
00077     /* set up the OPENFILE structure,
00078      *  then use the appropriate common dialog
00079      */
00080     of.lStructSize       = sizeof (OPENFILENAME);
00081     of.hwndOwner         = NULL;
00082     of.hInstance         = hInst;
00083     of.lpstrFilter       = "Bitmaps\000 *.BMP\000\000";
00084     of.lpstrCustomFilter = NULL;
00085     of.nMaxCustFilter    = 0;
00086     of.nFilterIndex      = 0;
00087     of.lpstrFile         = buffer;
00088     of.nMaxFile          = MAX_PATH;
00089     of.lpstrFileTitle    = NULL;
00090     of.nMaxFileTitle     = 0;
00091     of.lpstrInitialDir   = "c:\\nt\\windows";
00092     of.lpstrTitle        = NULL;
00093     of.Flags             = OFN_HIDEREADONLY;
00094     of.nFileOffset       = 0;
00095     of.nFileExtension    = 0;
00096     of.lpstrDefExt       = NULL;
00097     of.lCustData         = 0;
00098     of.lpfnHook          = NULL;
00099     of.lpTemplateName    = NULL;
00100     if (!GetOpenFileName (&of)) return NULL;
00101
00102     /* Try to open the file.  If successful, then allocate space for it,
00103      *  and read in all of the bytes.
00104      */
00105     fh = _lopen (buffer, OF_READ);
00106     if (fh == -1) return NULL;
00107     nbytes = GetFileSize ((HANDLE) fh, NULL);
00108
00109     /* The contents of the file are read in here in three parts.  First
00110      *  the bitmap file header is read, then the bitmap header along with
00111      *  the color table, then finally the actual bit data.  I.e. from
00112      *  a total of nbytes...
00113      *    1.  sizeof (BITMAPFILEHEADER)
00114      *    2.  bfOffBits- sizeof (BITMAPFILEHEADER)
00115      *    3.  (nbytes - bfOffBits)
00116      */
00117
00118     /* read in the bitmap file header.  save the offset to bits. */
00119     if (!(pbmfh = (PBITMAPFILEHEADER)LocalAlloc (LPTR, sizeof (BITMAPFILEHEADER))))
00120         return NULL;
00121     _lread (fh, (LPSTR)pbmfh, sizeof (BITMAPFILEHEADER));
00122     bfOffBits=pbmfh->bfOffBits;
00123
00124     /* read in the bitmap info header and the color table right after it.
00125      * both BITMAPINFOHEADER and BITMAPINFO needed for CreateDIBitmap()
00126      */
00127     if (!(pbmih = (PBITMAPINFOHEADER)LocalAlloc (LPTR, bfOffBits- sizeof (BITMAPFILEHEADER))))
00128         return NULL;
00129     _lread (fh, (LPSTR)pbmih, bfOffBits- sizeof (BITMAPFILEHEADER));
00130
00131     /* finally read in the bit data. */
00132     if (!(pBits = (PBYTE)LocalAlloc (LPTR, (nbytes - bfOffBits)))) return NULL;
00133     _lread (fh, (LPSTR)pBits, (nbytes - bfOffBits));
00134
00135
00136     /* in the case of desiring a monochrome bitmap (input parameter),
00137      *  verify that is what we got.  If it is, then use CreateBitmap,
00138      *  else use a device independent bitmap.
00139      */
00140     if (monochrome) {
00141       if (pbmih->biBitCount != 1) {
00142         MessageBox (NULL, "Mask must be monochrome bitmap.",
00143                     "Error", MB_APPLMODAL | MB_ICONSTOP | MB_OK);
00144         hbm = NULL;
00145       } else {
00146       hbm = CreateBitmap (pbmih->biWidth, pbmih->biHeight,
00147                           pbmih->biPlanes, pbmih->biBitCount,
00148                           pBits);
00149       }
00150     } else  /* bitmap is NOT monochrome, use DIB. */
00151       hbm = CreateDIBitmap (hdc, pbmih, CBM_INIT,
00152                           pBits, (PBITMAPINFO) pbmih, DIB_RGB_COLORS);
00153
00154
00155     /* hbm is set... free up memory, and return */
00156     LocalFree (LocalHandle ((LPSTR)pBits));
00157     LocalFree (LocalHandle ((LPSTR)pbmih));
00158     LocalFree (LocalHandle ((LPSTR)pbmfh));
00159     _lclose (fh);
00160
00161     return hbm;
00162 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMDLG.C Source File

  • SERVENUM
  • DLL

ENUMDLG.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumdlg.c
00009 //
00010 //  PURPOSE:   Displays the ServerEnum dialog box
00011 //
00012 //  FUNCTIONS:
00013 //    EnumDlg - Processes messages for "EnumDlg" dialog box.
00014 //    MsgEnumDlgInit - Initializes the dialog box
00015 //    MsgEnumDlgInitEnum - Adds result of initial enumeration to listbox
00016 //    MsgEnumDlgEnumExpand - Adds result of entry expansion to listbox
00017 //    MsgEnumDlgMeasureItem - Computes height of list box item
00018 //    MsgEnumDlgDrawItem - Draws items in owner draw listbox
00019 //    MsgEnumDlgVKeyToItem - Process key presses in listbox
00020 //    MsgEnumDlgCharToItem - Searches for items in listbox by character
00021 //    MsgEnumDlgSetCursor - Sets the cursor to wait is enumerationg
00022 //    MsgEnumDlgSysColor - Updates colors used in dialog box
00023 //    MsgEnumDlgCommand - Processes WM_COMMAND messages
00024 //    MsgEnumDlgDestroy - Unititializes dialog box
00025 //    CmdEnumDlgOK - Process OK button click
00026 //    CmdEnumDlgCancel - Process Cancel button click
00027 //    CmdEnumDlgHelp - Calls user defined procedure
00028 //    CmdEnumDlgBrowse - Process listbox notification messages
00029 //
00030 //  COMMENTS:
00031 //    Display dialog box which allows the user to select a computer.
00032 //    The list box is filled when the threads doing the enumeration
00033 //    finish
00034 //
00035 //  AUTHOR: Craig Link - Microsoft Developer Support
00036 //
00037
00038 #include <windows.h>
00039 #include <windowsx.h>
00040 #include <tchar.h>
00041 #include "dlldisp.h"
00042 #include "enumdlg.h"
00043 #include "enumutil.h"
00044 #include "enumthrd.h"
00045 #include "thrdutil.h"
00046 #include "miscutil.h"
00047 #include "mem.h"
00048 #include "macros.h"
00049
00050 // MSVC++ 1.1 for NT does not define this in WINERROR.H
00051 #ifndef ERROR_CANCELLED
00052 #define ERROR_CANCELLED 1223L
00053 #endif
00054
00055 extern DWORD ndxTls;
00056
00057 LRESULT MsgEnumDlgInit(HWND, UINT, WPARAM, LPARAM);
00058 LRESULT MsgEnumDlgInitEnum(HWND, UINT, WPARAM, LPARAM);
00059 LRESULT MsgEnumDlgEnumExpand(HWND, UINT, WPARAM, LPARAM);
00060 LRESULT MsgEnumDlgMeasureItem(HWND, UINT, WPARAM, LPARAM);
00061 LRESULT MsgEnumDlgDrawItem(HWND, UINT, WPARAM, LPARAM);
00062 LRESULT MsgEnumDlgVKeyToItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam);
00063 LRESULT MsgEnumDlgCharToItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam);
00064 LRESULT MsgEnumDlgSetCursor(HWND, UINT, WPARAM, LPARAM);
00065 LRESULT MsgEnumDlgSysColor(HWND, UINT, WPARAM, LPARAM);
00066 LRESULT MsgEnumDlgCommand(HWND, UINT, WPARAM, LPARAM);
00067 LRESULT MsgEnumDlgDestroy(HWND, UINT, WPARAM, LPARAM);
00068 LRESULT CmdEnumDlgOK(HWND, WORD, WORD, HWND);
00069 LRESULT CmdEnumDlgCancel(HWND, WORD, WORD, HWND);
00070 LRESULT CmdEnumDlgHelp(HWND, WORD, WORD, HWND);
00071 LRESULT CmdEnumDlgBrowse(HWND, WORD, WORD, HWND);
00072
00073
00074 // EnumDlg dialog message table definition.
00075 MSD rgmsdEnumDlg[] =
00076 {
00077     {WM_INITDIALOG,     MsgEnumDlgInit},
00078     {WM_INIT_ENUM,      MsgEnumDlgInitEnum},
00079     {WM_ENUM_EXPAND,    MsgEnumDlgEnumExpand},
00080     {WM_MEASUREITEM,    MsgEnumDlgMeasureItem},
00081     {WM_DRAWITEM,       MsgEnumDlgDrawItem},
00082     {WM_VKEYTOITEM,     MsgEnumDlgVKeyToItem},
00083     {WM_CHARTOITEM,     MsgEnumDlgCharToItem},
00084     {WM_SETCURSOR,      MsgEnumDlgSetCursor},
00085     {WM_SYSCOLORCHANGE, MsgEnumDlgSysColor},
00086     {WM_COMMAND,        MsgEnumDlgCommand},
00087     {WM_DESTROY,        MsgEnumDlgDestroy}
00088 };
00089
00090 MSDI msdiEnumDlg =
00091 {
00092     sizeof(rgmsdEnumDlg) / sizeof(MSD),
00093     rgmsdEnumDlg,
00094     edwpNone
00095 };
00096
00097 // EnumDlg dialog command table definition.
00098 CMD rgcmdEnumDlg[] =
00099 {
00100     {IDOK,       CmdEnumDlgOK},
00101     {IDCANCEL,   CmdEnumDlgCancel},
00102     {IDB_HELP,   CmdEnumDlgHelp},
00103     {IDL_BROWSE, CmdEnumDlgBrowse}
00104 };
00105
00106 CMDI cmdiEnumDlg =
00107 {
00108     sizeof(rgcmdEnumDlg) / sizeof(CMD),
00109     rgcmdEnumDlg,
00110     edwpNone
00111 };
00112
00113
00114 //
00115 //  FUNCTION: EnumDlg(HWND, UINT, WPARAM, LPARAM)
00116 //
00117 //  PURPOSE:  Processes messages for "EnumDlg" dialog box.
00118 //
00119 //  PARAMETERS:
00120 //    hdlg - window handle of the dialog box
00121 //    wMessage - type of message
00122 //    wparam - message-specific information
00123 //    lparam - message-specific information
00124 //
00125 //  RETURN VALUE:
00126 //    TRUE - message handled
00127 //    FALSE - message not handled
00128 //
00129 //  COMMENTS:
00130 //    Dispatches messages for dialog box
00131 //
00132
00133 LRESULT CALLBACK EnumDlg(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00134 {
00135     return DispMessage(&msdiEnumDlg, hdlg, uMessage, wparam, lparam);
00136 }
00137
00138
00139 //
00140 //  FUNCTION: MsgEnumDlgInit(HWND, UINT, WPARAM, LPARAM)
00141 //
00142 //  PURPOSE: To initialize the enumdlg box.
00143 //
00144 //  PARAMETERS:
00145 //    hwnd - The window handing the message.
00146 //    uMessage - The message number. WM_INITDIALOG.
00147 //    wparam - Message specific data (unused).
00148 //    lparam - Message specific data (unused).
00149 //
00150 //  RETURN VALUE:
00151 //    Always returns TRUE - message handled.
00152 //
00153 //  COMMENTS:
00154 //    Initializes syncronization object, and creates a thread for initial
00155 //    enumeration.  If any initialization fails, the dialog box ends
00156 //
00157 LRESULT MsgEnumDlgInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00158 {
00159     HANDLE hThread;
00160     DWORD tID;
00161     DWORD dwRet;
00162     RECT rect;
00163     HWND hwndBrowse;
00164     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00165
00166     // create and initialize syncronization object
00167     if ( ERROR_SUCCESS == ( dwRet = MallocMem( &(lpTls->lpSync), sizeof( ENUMSYNC ) ) ) )
00168     {
00169         lpTls->lpSync->hwnd = hdlg;
00170         lpTls->lpSync->cThread = 1;
00171         lpTls->lpSync->cNetBuf = 0;
00172         lpTls->lpSync->lplpnetBuf = NULL;
00173         lpTls->lpSync->lpRoot = NULL;
00174
00175         InitializeCriticalSection( &(lpTls->lpSync->cs) );
00176
00177         // create root node and start enumeration thread
00178         if( ERROR_SUCCESS == ( dwRet = MallocMem( &(lpTls->lpSync->lpRoot), sizeof( ENUMNODE ) ) ) )
00179         {
00180             lpTls->lpSync->lpRoot->lpNet = NULL;
00181             lpTls->lpSync->lpRoot->cChild = 0;
00182             lpTls->lpSync->lpRoot->lpChild = NULL;
00183
00184             lpTls->lpSync->cThread++;
00185             if ( ( hThread = CreateThread(NULL, 100,
00186                                          (LPTHREAD_START_ROUTINE)InitialEnumThread,
00187                                          (LPVOID) lpTls->lpSync,
00188                                          0, &tID) ) == NULL )
00189             {
00190                 lpTls->lpSync->cThread--;
00191                 dwRet = ERROR_FAILURE;
00192             }
00193             else
00194             {
00195                 MarkOutstanding( &hThread ); // add thread to outstanding list
00196
00197                 // perform UI initialization
00198                 LoadBitmapArray( lpTls->hbmpArray );
00199                 lpTls->hbrushHL = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT) );
00200
00201                 hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00202
00203                 GetClientRect( hwndBrowse, &rect );
00204
00205                 lpTls->lpfnListProc = (WNDPROC) SetWindowLong( hwndBrowse, GWL_WNDPROC, (LONG) ListSubProc );
00206                 SendMessage( hwndBrowse, LB_ADDSTRING, 0L, (LPARAM) WORKING );
00207                 SendMessage( hwndBrowse, WM_SETFONT, (WPARAM) lpTls->hfont, 0 );
00208
00209                 SendDlgItemMessage( hdlg, IDE_SERVER, EM_LIMITTEXT, MAX_COMPUTERNAME_LENGTH, 0 );
00210                 SendDlgItemMessage( hdlg, IDE_SERVER, WM_SETFONT, (WPARAM) lpTls->hfont, 0 );
00211
00212                 EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );
00213
00214                 if ( lpTls->lpfnHelpProc == NULL )
00215                     EnableWindow( GetDlgItem( hdlg, IDB_HELP), FALSE );
00216
00217                 // Center the dialog over the application window
00218                 CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
00219
00220             }
00221         }
00222     }
00223
00224     if ( dwRet != ERROR_SUCCESS )
00225     {
00226         // deallocation occurs in the WM_DESTROY message handler
00227         EndDialog(hdlg, ERROR_NOT_ENOUGH_MEMORY);
00228     }
00229
00230     return TRUE;
00231 }
00232
00233
00234 //
00235 //  FUNCTION: MsgEnumDlgInitEnum(HWND, UINT, WPARAM, LPARAM)
00236 //
00237 //  PURPOSE: Adds result of initial enumeration to listbox
00238 //
00239 //  PARAMETERS:
00240 //    hwnd - The window handing the message.
00241 //    uMessage - The message number. WM_INIT_ENUM.
00242 //    wparam - Message specific data (unused).
00243 //    lparam - Message specific data (unused).
00244 //
00245 //  RETURN VALUE:
00246 //    Always returns TRUE - message handled.
00247 //
00248 //  COMMENTS:
00249 //
00250 LRESULT MsgEnumDlgInitEnum(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00251 {
00252     UINT ndx;
00253     TCHAR szServer[MAX_COMPUTERNAME_LENGTH+3] = TEXT("\\\\");
00254     TCHAR szTemp[MAX_COMPUTERNAME_LENGTH+3];
00255     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00256     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00257
00258     SetCursor( LoadCursor( NULL, IDC_WAIT ) );
00259     SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
00260     SendMessage( hwndBrowse, LB_RESETCONTENT, 0L, 0L );
00261
00262     // recursively add tree to listbox, looking for the listbox index
00263     // of the local machine along the way
00264     ndx = MAX_COMPUTERNAME_LENGTH+1;
00265     GetComputerName( szServer+2, &ndx );
00266     ndx = EnumListRecurse( hwndBrowse, lpTls->lpSync->lpRoot, szServer+2);
00267
00268     // check to see if the user has typed in a server name
00269     // before reseting the edit control
00270     GetDlgItemText( hdlg, IDE_SERVER, szTemp, MAX_COMPUTERNAME_LENGTH+3);
00271     if ( *szTemp == TEXT('\0') )  // the user has not typed anything yet
00272     {
00273         SetDlgItemText( hdlg, IDE_SERVER, szServer );
00274     }
00275
00276     SendMessage( hwndBrowse, LB_SETTOPINDEX, ndx, 0 );
00277     SendMessage( hwndBrowse, LB_SETCURSEL, ndx, 0 );
00278
00279     EnableWindow( GetDlgItem( hdlg, IDT_SELECT), TRUE );
00280     SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
00281     SetCursor( LoadCursor( NULL, IDC_ARROW ) );
00282
00283
00284     return TRUE;
00285 }
00286
00287
00288 //
00289 //  FUNCTION: MsgEnumDlgEnumExpand(HWND, UINT, WPARAM, LPARAM)
00290 //
00291 //  PURPOSE: Adds results of an single enumeration to listbox.
00292 //
00293 //  PARAMETERS:
00294 //    hwnd - The window handing the message.
00295 //    uMessage - The message number. WM_ENUM_EXPAND
00296 //    wparam - Index of node that was expanded.
00297 //    lparam - Pointer to ENUMNODE that was expanded.
00298 //
00299 //  RETURN VALUE:
00300 //    Always returns TRUE - message handled.
00301 //
00302 //  COMMENTS:
00303 //
00304 LRESULT MsgEnumDlgEnumExpand(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00305 {
00306     LPENUMNODE lpNode = (LPENUMNODE) lparam;
00307     UINT cChild;
00308     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00309
00310     SetCursor( LoadCursor( NULL, IDC_WAIT ) );
00311     SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
00312
00313     cChild = lpNode->cChild;
00314     while( cChild-- )
00315     {
00316         // all of these bitmaps default to not expanded
00317         switch( lpNode->lpChild[cChild].lpNet->dwDisplayType )
00318         {
00319             case RESOURCEDISPLAYTYPE_DOMAIN:
00320                 lpNode->lpChild[cChild].ndxBmp = DOM_NDX;
00321                 break;
00322
00323             case RESOURCEDISPLAYTYPE_SERVER:
00324                 lpNode->lpChild[cChild].ndxBmp = SERV_NDX;
00325                 break;
00326         }
00327
00328         SendMessage( hwndBrowse, LB_INSERTSTRING, wparam+1, (LPARAM) &(lpNode->lpChild[cChild]) );
00329
00330     }
00331
00332     EnableWindow( GetDlgItem( hdlg, IDT_SELECT), TRUE );
00333     SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
00334     SetCursor( LoadCursor( NULL, IDC_ARROW ) );
00335     return TRUE;
00336 }
00337
00338
00339 //
00340 //  FUNCTION: MsgEnumDlgMeasureItem(HWND, UINT, WPARAM, LPARAM)
00341 //
00342 //  PURPOSE: Computes the height of an item in the listbox.
00343 //
00344 //  PARAMETERS:
00345 //    hwnd - The window handing the message.
00346 //    uMessage - The message number. WM_MEASUREITEM.
00347 //    wparam - Message specific data (unused).
00348 //    lparam - LPMEASUREITEMSTRUCT.
00349 //
00350 //  RETURN VALUE:
00351 //    TRUE - message handled.
00352 //
00353 //
00354 //  COMMENTS:
00355 //
00356 LRESULT MsgEnumDlgMeasureItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00357 {
00358     LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lparam;
00359     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00360
00361     lpmis->itemHeight = MAX( lpTls->tm.tmHeight, BITMAP_HEIGHT ) ;
00362
00363     return TRUE;
00364 }
00365
00366
00367 //
00368 //  FUNCTION: MsgEnumDlgDrawItem(HWND, UINT, WPARAM, LPARAM)
00369 //
00370 //  PURPOSE: Draws items in the owner draw listbox.
00371 //
00372 //  PARAMETERS:
00373 //    hwnd - The window handing the message.
00374 //    uMessage - The message number. WM_DRAWITEM.
00375 //    wparam - id of control.
00376 //    lparam - LPDRAWITEMSTRUCT.
00377 //
00378 //  RETURN VALUE:
00379 //    TRUE - message handled.
00380 //    FALSE - message not handled.
00381 //
00382 //  COMMENTS:
00383 //
00384 LRESULT MsgEnumDlgDrawItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00385 {
00386     LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lparam;
00387     LPENUMNODE lpNode = (LPENUMNODE) lpdis->itemData;
00388     HBITMAP hbmpOld = NULL;
00389     HDC hdcMem = NULL;
00390     HBRUSH hbrush;
00391     COLORREF crefOldText;
00392     COLORREF crefOldBk;
00393     UINT nTop;
00394     UINT nIndent = 0;
00395     TCHAR szWorking[] = TEXT("Working...");
00396     TCHAR szServer[MAX_COMPUTERNAME_LENGTH+3];
00397     UINT nHighlight = 0;
00398     LPTLSOBJECT lpTls;
00399
00400     // If this isn't the correct dialog item, skip this message
00401     if ( (UINT) wparam != IDL_BROWSE )
00402         return FALSE;
00403
00404     // If there are no list box items, skip this message.
00405     if (lpdis->itemID == -1)
00406         return FALSE;
00407
00408     switch (lpdis->itemAction)
00409     {
00410         case ODA_SELECT:
00411         case ODA_DRAWENTIRE:
00412
00413             // if we're still doing the initial enumeration
00414             if ( (LONG) lpNode == WORKING )
00415             {
00416                 TextOut(lpdis->hDC, 2, 2, szWorking, _tcslen(szWorking) );
00417             }
00418             else
00419             {
00420                 lpTls = TlsGetValue(ndxTls);
00421
00422                 // compute indent for list item
00423                 switch( lpNode->lpNet->dwDisplayType )
00424                 {
00425                     case RESOURCEDISPLAYTYPE_GENERIC:
00426                         nIndent = 0;
00427                         break;
00428
00429                     case RESOURCEDISPLAYTYPE_DOMAIN:
00430                         nIndent = BITMAP_WIDTH;
00431                         break;
00432
00433                     case RESOURCEDISPLAYTYPE_SERVER:
00434                         nIndent = 2 * BITMAP_WIDTH;
00435                         break;
00436                 }
00437
00438                 // Create MemDC for bitmap
00439                 hdcMem = CreateCompatibleDC(lpdis->hDC);
00440
00441                 // Is the item selected?
00442                 if (lpdis->itemState & ODS_SELECTED)
00443                 {
00444                     hbmpOld = SelectObject(hdcMem, lpTls->hbmpArray[lpNode->ndxBmp+HIGHLIGHT_NDX]);
00445                     hbrush = lpTls->hbrushHL;
00446                     crefOldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT) );
00447                     crefOldBk = SetBkColor( lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT) );
00448                 }
00449                 else
00450                 {
00451                     hbmpOld = SelectObject(hdcMem, lpTls->hbmpArray[lpNode->ndxBmp]);
00452                     hbrush = GetStockObject( WHITE_BRUSH );
00453                     crefOldText = SetTextColor( lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT) );
00454                     crefOldBk = SetBkColor( lpdis->hDC, GetSysColor(COLOR_WINDOW) );
00455                 }
00456
00457                 // Draw background
00458                 FillRect( lpdis->hDC,
00459                           &(lpdis->rcItem),
00460                           hbrush );
00461
00462                 // Display bitmap
00463                 nTop = (lpdis->rcItem.bottom + lpdis->rcItem.top - BITMAP_HEIGHT) / 2;
00464                 BitBlt(lpdis->hDC,
00465                        lpdis->rcItem.left+nIndent,
00466                        nTop,
00467                        lpdis->rcItem.right - lpdis->rcItem.left,
00468                        lpdis->rcItem.bottom - lpdis->rcItem.top,
00469                        hdcMem, 0, 0, SRCCOPY);
00470
00471                 // Display the text associated with the item. */
00472                 nTop = (lpdis->rcItem.bottom + lpdis->rcItem.top - lpTls->tm.tmHeight) / 2;
00473                 TextOut(lpdis->hDC,
00474                     BITMAP_WIDTH + nIndent + 4,
00475                     nTop,
00476                     lpNode->lpNet->lpRemoteName,
00477                     _tcslen(lpNode->lpNet->lpRemoteName) );
00478
00479                 // Display comment if there is one
00480                 if ( lpNode->lpNet->lpComment )
00481                 {
00482                     TextOut(lpdis->hDC,
00483                         lpdis->rcItem.right/2,
00484                         nTop,
00485                         lpNode->lpNet->lpComment,
00486                         _tcslen(lpNode->lpNet->lpComment) );
00487                 }
00488
00489                 SetBkColor( lpdis->hDC, crefOldBk );
00490                 SetTextColor( lpdis->hDC, crefOldText );
00491                 SelectObject(hdcMem, hbmpOld);
00492
00493                 DeleteDC(hdcMem);
00494             }
00495             break;
00496
00497         case ODA_FOCUS: // taks appropriate measures if item has focus
00498             if ( (LONG) lpNode != WORKING )
00499             {
00500                 DrawFocusRect( lpdis->hDC, &(lpdis->rcItem) );
00501
00502                 if (lpdis->itemState & ODS_FOCUS)
00503                 {
00504                     if ( lpNode->lpNet->dwDisplayType == RESOURCEDISPLAYTYPE_SERVER )
00505                     {
00506                         _tcscpy( szServer, TEXT("\\\\") );
00507                         _tcscat( szServer, lpNode->lpNet->lpRemoteName );
00508                     }
00509                     else
00510                     {
00511                         *szServer = TEXT('\0');
00512                     }
00513                     SetDlgItemText( hdlg, IDE_SERVER, szServer );
00514                 }
00515             }
00516             break;
00517     }
00518
00519     return TRUE;
00520 }
00521
00522
00523
00524 //
00525 //  FUNCTION: MsgEnumDlgVKeyToItem(HWND, UINT, WPARAM, LPARAM)
00526 //
00527 //  PURPOSE: Handles ccrolling in listbox
00528 //
00529 //  PARAMETERS:
00530 //    hwnd - The window handing the message.
00531 //    uMessage - The message number. WM_VKEYTOITEM.
00532 //    wparam - LOWORD(wparam) = v-key code.
00533 //    lparam - Handle of listbox.
00534 //
00535 //  RETURN VALUE:
00536 //    -2 - message handled.
00537 //    -1  - message not handled
00538 //
00539 //  COMMENTS:
00540 //
00541 LRESULT MsgEnumDlgVKeyToItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00542 {
00543     int nCur;
00544     int nCount;
00545     int nItemsPerPage;
00546     LPTLSOBJECT lpTls;
00547     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00548     RECT rect;
00549
00550     if ( (HWND)lparam == hwndBrowse )
00551     {
00552
00553         lpTls = TlsGetValue(ndxTls);
00554         nCur = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
00555         nCount = SendMessage( hwndBrowse, LB_GETCOUNT, 0, 0 );
00556         GetClientRect( hwndBrowse, &rect );
00557         nItemsPerPage = rect.bottom / ( MAX( lpTls->tm.tmHeight, BITMAP_HEIGHT ) );
00558
00559         if ( nCount != 0 )
00560         {
00561             switch( LOWORD(wparam) )
00562             {
00563                 case VK_HOME:
00564                     SendMessage( hwndBrowse, LB_SETCURSEL, 0, 0 );
00565                     break;
00566
00567                 case VK_END:
00568                     SendMessage( hwndBrowse, LB_SETCURSEL, nCount-1, 0 );
00569                     break;
00570
00571                 case VK_UP:
00572                     SendMessage( hwndBrowse, LB_SETCURSEL, MAX( nCur-1, 0 ), 0 );
00573                     break;
00574
00575                 case VK_DOWN:
00576                     SendMessage( hwndBrowse, LB_SETCURSEL, MIN( nCur+1, nCount-1 ), 0 );
00577                     break;
00578
00579                 case VK_PRIOR:
00580                     SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
00581                     SendMessage( hwndBrowse, LB_SETCURSEL, MAX( nCur-nItemsPerPage, 0 ), 0 );
00582                     SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
00583                     break;
00584
00585                 case VK_NEXT:
00586                     SendMessage( hwndBrowse, WM_SETREDRAW, FALSE, 0 );
00587                     SendMessage( hwndBrowse, LB_SETCURSEL, MIN( nCur+nItemsPerPage, nCount-1 ), 0 );
00588                     SendMessage( hwndBrowse, WM_SETREDRAW, TRUE, 0 );
00589                     break;
00590
00591                 default:
00592                     return -1;
00593             }
00594             return -2;
00595         }
00596     }
00597     return -1;
00598 }
00599
00600
00601 //
00602 //  FUNCTION: MsgEnumDlgCharToItem(HWND, UINT, WPARAM, LPARAM)
00603 //
00604 //  PURPOSE: Search for items in listbox based on character
00605 //
00606 //  PARAMETERS:
00607 //    hwnd - The window handing the message.
00608 //    uMessage - The message number. WM_CHARTOITEM.
00609 //    wparam - LOWORD(wparam) = character
00610 //    lparam - Handle of listbox.
00611 //
00612 //  RETURN VALUE:
00613 //    -2 - message handled.
00614 //    -1  - message not handled
00615 //
00616 //  COMMENTS:
00617 //    Because we have to use unicode, we need to convert the character
00618 //    keypress to unicode before search.  If no match is found, we
00619 //    leave the current selection highlighted
00620 //
00621 LRESULT MsgEnumDlgCharToItem(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00622 {
00623     int nCur;
00624     int nCount;
00625     int ndx;
00626     LPENUMNODE lpNode  = NULL;
00627     TCHAR w_key[2];
00628     CHAR key = (CHAR) LOWORD(wparam);
00629     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00630
00631     if ( (HWND)lparam == hwndBrowse )  // handle message for this listbox
00632     {
00633         if ( (UINT)key == 0xD )  // enter key is the same as a double click
00634         {
00635             SendMessage( hdlg, WM_COMMAND, MAKELONG(IDL_BROWSE, LBN_DBLCLK), (LPARAM) hwndBrowse );
00636             return -2;
00637         }
00638
00639         nCur = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
00640         nCount = SendMessage( hwndBrowse, LB_GETCOUNT, 0, 0 );
00641
00642         if ( nCount > 0 )
00643         {
00644             if ( MultiByteToWideChar( CP_ACP, 0, &key, 1, w_key, 2 ) )
00645             {
00646                 for( ndx = nCur+1; ndx != nCur; ndx++ )
00647                 {
00648                      if ( ndx >= nCount )
00649                      {
00650                          ndx = -1;
00651                          continue;
00652                      }
00653
00654                      if ( LB_ERR != SendMessage( hwndBrowse, LB_GETTEXT, ndx, (LPARAM) &lpNode) )
00655                      {
00656                          if ( _totupper(*w_key) == _totupper(*lpNode->lpNet->lpRemoteName) )
00657                          {
00658                              SendMessage( hwndBrowse, LB_SETCURSEL, ndx, 0 );
00659                              return -2;
00660                          }
00661                      }
00662                 }
00663             }
00664         }
00665     }
00666     return -1;
00667 }
00668
00669
00670
00671 //
00672 //  FUNCTION: MsgEnumDlgSetCursor(HWND, UINT, WPARAM, LPARAM)
00673 //
00674 //  PURPOSE: Sets the cursor to Wait when over listbox and
00675 //           and enumeration is occuring
00676 //
00677 //  PARAMETERS:
00678 //    hwnd - The window handing the message.
00679 //    uMessage - The message number. WM_SETCURSOR.
00680 //    wparam - handle of window of which the cursor is over.
00681 //    lparam - Message specific data (unused).
00682 //
00683 //  RETURN VALUE:
00684 //    TRUE - message handled.
00685 //    FALSE - message not handled.
00686 //
00687 //  COMMENTS:
00688 //
00689 LRESULT MsgEnumDlgSetCursor(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00690 {
00691     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00692     LPTLSOBJECT lpTls;
00693
00694     if ( (HWND)wparam == hwndBrowse )
00695     {
00696         lpTls = TlsGetValue(ndxTls);
00697
00698         if ( lpTls->lpSync->cThread > 1 )
00699             SetCursor( LoadCursor( NULL, IDC_WAIT ) );
00700         else
00701             SetCursor( LoadCursor( NULL, IDC_ARROW ) );
00702         return TRUE;
00703     }
00704
00705     return FALSE;
00706 }
00707
00708
00709
00710 //
00711 //  FUNCTION: MsgEnumDlgSysColor(HWND, UINT, WPARAM, LPARAM)
00712 //
00713 //  PURPOSE: Updates the colors used by the dialog box
00714 //
00715 //  PARAMETERS:
00716 //    hwnd - The window handing the message.
00717 //    uMessage - The message number. WM_SYSCOLORCHANGE.
00718 //    wparam - Message specific data (unused).
00719 //    lparam - Message specific data (unused).
00720 //
00721 //  RETURN VALUE:
00722 //    Always returns TRUE - message handled.
00723 //
00724 //  COMMENTS:
00725 //
00726 LRESULT MsgEnumDlgSysColor(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00727 {
00728     UINT ndx = HIGHLIGHT_NDX*2;
00729     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00730
00731     while( ndx-- )
00732         DeleteObject( lpTls->hbmpArray[ndx] );
00733
00734     LoadBitmapArray( lpTls->hbmpArray );
00735
00736     DeleteObject( lpTls->hbrushHL );
00737     lpTls->hbrushHL = CreateSolidBrush( GetSysColor(COLOR_HIGHLIGHT) );
00738
00739     return TRUE;
00740 }
00741
00742
00743 //
00744 //  FUNCTION: MsgEnumDlgCommand(HWND, UINT, WPARAM, LPARAM)
00745 //
00746 //  PURPOSE: Process WM_COMMAND message sent to the enumdlg box.
00747 //
00748 //  PARAMETERS:
00749 //    hwnd - The window handing the message.
00750 //    uMessage - The message number. WM_COMMAND.
00751 //    wparam - Message specific data (unused).
00752 //    lparam - Message specific data (unused).
00753 //
00754 //  RETURN VALUE:
00755 //    TRUE for message handled
00756 //    FALSE for message not handled
00757 //
00758 //  COMMENTS:
00759 //    Uses this DispCommand function defined in wndproc.c combined
00760 //    with the cmdiEnumDlg structure defined in this file to handle
00761 //    the command messages for the enumdlg dialog box.
00762 //
00763 LRESULT MsgEnumDlgCommand(HWND   hwnd,
00764                         UINT   uMessage,
00765                         WPARAM wparam,
00766                         LPARAM lparam)
00767 {
00768     return DispCommand(&cmdiEnumDlg, hwnd, wparam, lparam);
00769 }
00770
00771
00772 //
00773 //  FUNCTION: MsgEnumDlgDestroy(HWND, UINT, WPARAM, LPARAM)
00774 //
00775 //  PURPOSE: Frees memory and resource used by dialogbox
00776 //
00777 //  PARAMETERS:
00778 //    hwnd - The window handing the message.
00779 //    uMessage - The message number. WM_DESTROY.
00780 //    wparam - Message specific data (unused).
00781 //    lparam - Message specific data (unused).
00782 //
00783 //  RETURN VALUE:
00784 //    Always returns TRUE - message handled.
00785 //
00786 //  COMMENTS:
00787 //
00788 LRESULT MsgEnumDlgDestroy(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00789 {
00790     UINT ndx = HIGHLIGHT_NDX*2;
00791     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00792     HWND hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00793
00794     if ( lpTls->hbmpArray[0] )
00795     {
00796         while( ndx-- )
00797             DeleteObject( lpTls->hbmpArray[ndx] );
00798     }
00799
00800     if ( lpTls->hbrushHL )
00801         DeleteObject( lpTls->hbrushHL );
00802
00803     if ( lpTls->lpfnListProc )
00804         SetWindowLong( hwndBrowse, GWL_WNDPROC, (LONG) lpTls->lpfnListProc );
00805
00806     if ( lpTls->lpSync )
00807         FreeEnumSync( &(lpTls->lpSync) );
00808
00809     return TRUE;
00810 }
00811
00812
00813 //
00814 //  FUNCTION: CmdEnumDlgOK(HWND, WORD, WORD, HWND)
00815 //
00816 //  PURPOSE: Processes the OK Button press.
00817 //
00818 //  PARAMETERS:
00819 //    hwnd - The window handling the command.
00820 //    wCommand - The command to be handled IDOK.
00821 //    wNotify  - The notification code to be handled (unused).
00822 //    hwndCtrl - NULL (unused).
00823 //
00824 //  RETURN VALUE:
00825 //    Always returns TRUE.
00826 //
00827 //  COMMENTS:
00828 //    Calls EndDialog to finish the dialog session.
00829 //    If there is not not text in the edit control
00830 //    this behaves the same as a cancel.  If there
00831 //    is text, we make sure that it is prepended
00832 //    with a '\\'.  Next, we make sure there is
00833 //    enough room to store it in the user's buffer.
00834 //
00835 LRESULT CmdEnumDlgOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00836 {
00837     TCHAR szServer[MAX_COMPUTERNAME_LENGTH+5] = TEXT("\\\\");
00838     LPTSTR psz = szServer+2;
00839     DWORD cchServer = 0;
00840     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00841
00842     SendDlgItemMessage( hdlg, IDE_SERVER, WM_GETTEXT, (WPARAM)(MAX_COMPUTERNAME_LENGTH+3), (LPARAM)psz );
00843
00844     if ( *psz == TEXT('\0') ) // no server name, so same as cancelled
00845     {
00846         EndDialog(hdlg, ERROR_CANCELLED);
00847     }
00848     else
00849     {
00850         if ( *psz != TEXT('\\') ) // if the name does not begin with a '\', we make
00851         {                         // it begin with '\\' by ajusting the pointer
00852             psz = szServer;
00853             psz[MAX_COMPUTERNAME_LENGTH+2] = TEXT('\0');
00854         }
00855         cchServer = _tcslen( psz )+1;
00856
00857         if ( ( cchServer > *(lpTls->lpcchServer) ) ||
00858              ( lpTls->lpszServer == NULL ) )
00859         {
00860             *(lpTls->lpcchServer) = cchServer;
00861             EndDialog(hdlg, ERROR_MORE_DATA);
00862         }
00863         else
00864         {
00865             _tcscpy( lpTls->lpszServer, psz );
00866             *(lpTls->lpcchServer) = cchServer;
00867             EndDialog(hdlg, ERROR_SUCCESS);
00868         }
00869     }
00870     return TRUE;
00871 }
00872
00873
00874 //
00875 //  FUNCTION: CmdEnumDlgCancel(HWND, WORD, WORD, HWND)
00876 //
00877 //  PURPOSE: Process the cancel button press
00878 //
00879 //  PARAMETERS:
00880 //    hwnd - The window handling the command.
00881 //    wCommand - The command to be handled IDCANCEL.
00882 //    wNotify  - The notification code to be handled (unused).
00883 //    hwndCtrl - NULL (unused).
00884 //
00885 //  RETURN VALUE:
00886 //    Always returns TRUE.
00887 //
00888 //  COMMENTS:
00889 //    Calls EndDialog to finish the dialog session.
00890 //
00891 LRESULT CmdEnumDlgCancel(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00892 {
00893     EndDialog(hdlg, ERROR_CANCELLED);          // Exit the dialog
00894     return TRUE;
00895 }
00896
00897
00898 //
00899 //  FUNCTION: CmdEnumDlgHelp(HWND, WORD, WORD, HWND)
00900 //
00901 //  PURPOSE: Process the help button press
00902 //
00903 //  PARAMETERS:
00904 //    hwnd - The window handling the command.
00905 //    wCommand - The command to be handled IDB_HELP.
00906 //    wNotify  - The notification code to be handled (unused).
00907 //    hwndCtrl - NULL (unused).
00908 //
00909 //  RETURN VALUE:
00910 //    Always returns TRUE.
00911 //
00912 //  COMMENTS:
00913 //    Calls the users defined help procedure
00914 //
00915 LRESULT CmdEnumDlgHelp(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00916 {
00917     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00918
00919     (*(lpTls->lpfnHelpProc))();
00920     return TRUE;
00921 }
00922
00923
00924 //
00925 //  FUNCTION: CmdEnumDlgBrowse(HWND, WORD, WORD, HWND)
00926 //
00927 //  PURPOSE: Process notification messages for listbox
00928 //
00929 //  PARAMETERS:
00930 //    hwnd - The window handling the command.
00931 //    wCommand - The command to be handled IDL_BROWSE.
00932 //    wNotify  - The notification code to be handled - LBN_DBLCLK.
00933 //    hwndCtrl - NULL (unused).
00934 //
00935 //  RETURN VALUE:
00936 //    TRUE if message is processed.
00937 //
00938 //  COMMENTS:
00939 //    Double click on an item causes either expansion or contraction
00940 //
00941 LRESULT CmdEnumDlgBrowse(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00942 {
00943     LPENUMNODE lpNode;
00944     UINT ndx;
00945     HWND hwndBrowse;
00946     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00947
00948     if ( lpTls->lpSync->cThread == 1 )
00949     {
00950
00951         hwndBrowse = GetDlgItem( hdlg, IDL_BROWSE );
00952         ndx = SendMessage( hwndBrowse, LB_GETCURSEL, 0, 0 );
00953         SendMessage( hwndBrowse, LB_GETTEXT, (WPARAM) ndx, (LPARAM) &lpNode );
00954
00955         switch( wNotify )
00956         {
00957             case LBN_DBLCLK:  // expanding and collapsing nodes
00958                 switch( lpNode->ndxBmp )
00959                 {
00960                     case PROV_NDX:
00961                         lpNode->ndxBmp = PROVEX_NDX;
00962                         EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );
00963                         EnumListExpand( hwndBrowse, lpTls->lpSync, lpNode, ndx );
00964                         break;
00965
00966                     case DOM_NDX:
00967                         lpNode->ndxBmp = DOMEX_NDX;
00968                         EnableWindow( GetDlgItem( hdlg, IDT_SELECT), FALSE );
00969                         EnumListExpand( hwndBrowse, lpTls->lpSync, lpNode, ndx );
00970                         break;
00971
00972                     case PROVEX_NDX:
00973                         lpNode->ndxBmp = PROV_NDX;
00974                         EnumListCollapse( hwndBrowse, lpNode, ndx );
00975                         break;
00976
00977                     case DOMEX_NDX:
00978                         lpNode->ndxBmp = DOM_NDX;
00979                         EnumListCollapse( hwndBrowse, lpNode, ndx );
00980                         break;
00981
00982                     case SERV_NDX:
00983                         SendMessage( hdlg, WM_COMMAND, (WPARAM) IDOK, 0 );
00984                         break;
00985                 }
00986                 return TRUE;
00987         }
00988     }
00989     return FALSE;
00990 }
00991
00992
00993
00994 LRESULT APIENTRY ListSubProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00995 {
00996     LPTLSOBJECT lpTls = TlsGetValue(ndxTls);
00997
00998     switch (uMessage)
00999     {
01000         case WM_SETCURSOR:
01001             SendMessage( GetParent(hwnd), WM_SETCURSOR, (WPARAM) hwnd, MAKELONG( HTCLIENT, 0 ) );
01002             break;
01003
01004         case WM_GETDLGCODE:
01005             return DLGC_WANTALLKEYS | CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);
01006
01007         default:
01008             return CallWindowProc(lpTls->lpfnListProc, hwnd, uMessage, wparam, lparam);
01009     }
01010     return (0);
01011 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFC.C Source File

  • BNDBUF

BNDBUFC.C

Go to the documentation of this file.
00001 /**********************************************************************
00002 *   bndbufc.c -- sample program demonstrating two client threads
00003 *        producing to and consuming from a central buffer
00004 *        pool via RPC.
00005 *
00006 *   Frederick Chong
00007 *   Microsoft Developer Support
00008 *   Copyright (c) 1992-1996 Microsoft Corporation
00009 *
00010 ***********************************************************************/
00011
00012
00013 #include <windows.h>
00014 #include <stdio.h>
00015 #include <string.h>
00016 #include <stdlib.h>
00017 #include <rpc.h>
00018 #include "common.h"
00019 #include "bndbuf.h"
00020
00021 // Function prototypes
00022
00023 void producer();
00024 void consumer();
00025 void produce_item(char * string);
00026 void main(int argc, char *argv[]);
00027
00028 // Global variables
00029
00030 HANDLE hMainThrd;   // Handle to main thread
00031 HANDLE hConThrd;    // Handle to consumer thread
00032 HANDLE hProdThrd;   // Handle to producer thread
00033 LONG   lConThreadId;    // Consumer thread ID
00034 LONG   lProdThreadId;   // Producer thread ID
00035 DWORD  retCode;
00036
00037
00038 /**********************************************************************
00039
00040 void main(int argc, char *argv[])
00041
00042 Creates the producer and consumer thread and then suspend itself.
00043
00044 ***********************************************************************/
00045
00046 void main(int argc, char *argv[])
00047 {
00048
00049   // check if Win32s, if so, display notice and terminate
00050       if( GetVersion() & 0x80000000 )
00051       {
00052         MessageBox( NULL,
00053            "This application cannot run on Windows 3.1 or Windows 95.\n"
00054            "This application will now terminate.",
00055            "BndBuf",
00056            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00057         return;
00058       }
00059
00060     // Create Consumer Thread
00061
00062     hConThrd = CreateThread(NULL,
00063                 0,
00064                 (LPTHREAD_START_ROUTINE)consumer,
00065                 NULL,
00066                 0,
00067                 (LPDWORD) &lConThreadId );
00068
00069
00070     // Create producer thread
00071
00072     hProdThrd = CreateThread(NULL,
00073                  0,
00074                  (LPTHREAD_START_ROUTINE)producer,
00075                  NULL,
00076                  0,
00077                  (LPDWORD) &lProdThreadId );
00078
00079
00080     // Suspend the main thread
00081
00082     hMainThrd = GetCurrentThread();
00083
00084     if (SuspendThread(hMainThrd) == -1)
00085     {
00086         retCode = GetLastError();
00087         printf("\nSuspendThread returns %d\n", retCode);
00088         ExitProcess(0);
00089     }
00090
00091
00092
00093
00094 }
00095
00096
00097 /***********************************************************************
00098
00099 void producer()
00100
00101 This is the producer thread function. It produces a string of 20 random
00102 characters then make a RPC to insert the string item.
00103
00104 ************************************************************************/
00105
00106 void producer()
00107 {
00108     char item[MAX_SIZE];
00109
00110     // Delay for awhile before starting
00111     Sleep(200);
00112
00113     while (TRUE)
00114     {
00115     produce_item(item);     // Produce random string
00116
00117
00118     // RPC guarded statements
00119
00120     RpcTryExcept
00121     {
00122         insert_buffer(item);    // Put item in buffer
00123         printf("\nproduce   ---> %s", item);
00124     }
00125     RpcExcept(1)
00126     {
00127         printf("The RPC runtime library raised exception 0x%lx.\n", RpcExceptionCode());
00128         printf("Please verify that the server application and \n");
00129         printf("the locator service have been started.");
00130     }
00131     RpcEndExcept
00132
00133     // End RPC guarded statements
00134
00135     }
00136 }
00137
00138
00139 /***********************************************************************
00140
00141 void consumer()
00142
00143 This is the consumer thread function. It makes a RPC and then remove
00144 the string item from the central buffer pool.
00145
00146 ************************************************************************/
00147
00148
00149 void consumer()
00150 {
00151     char item[20];
00152
00153     while (TRUE)
00154     {
00155
00156     // RPC guarded statements
00157
00158     RpcTryExcept
00159     {
00160         remove_buffer(item);        // Take item from buffer
00161         printf("\nconsume   ---> %s", item);
00162     }
00163
00164     RpcExcept(1)
00165     {
00166         printf("The RPC runtime library raised exception %lx.\n", RpcExceptionCode());
00167         printf("Please verify that the server application and \n");
00168         printf("the locator service have been started.");
00169     }
00170     RpcEndExcept
00171
00172     // End RPC guarded statements
00173
00174
00175     }
00176
00177
00178 }
00179
00180
00181 /***********************************************************************
00182
00183 void produce_item(char *string)
00184
00185 Generates a random string of 20 characters.
00186
00187 ************************************************************************/
00188
00189 void produce_item(char *string)
00190 {
00191     char *tmp;
00192     int i;
00193
00194     tmp = string;
00195
00196     for (i = MAX_SIZE; i > 1; i--)
00197     {
00198         *tmp = (rand() % 26) + 'A';
00199         tmp++;
00200     }
00201     strcpy(tmp, "\0");
00202
00203 }
00204
00205
00206
00207 /***********************************************************************
00208     MIDL allocate and free
00209 ***********************************************************************/
00210
00211 void __RPC_FAR * __RPC_API MIDL_user_allocate(size_t len)
00212 {
00213     return(malloc(len));
00214 }
00215
00216 void __RPC_API MIDL_user_free(void __RPC_FAR * ptr)
00217 {
00218     free(ptr);
00219 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: INTEROP/DISP32.C Source File

  • INTEROP

DISP32.C

Go to the documentation of this file.
00001 /********************************************************************\
00002 *                                                                    *
00003 *  File:      disp32.c                                               *
00004 *                                                                    *
00005 *  Comments:  Dispatches function calls made through WM_COPYDATA on  *
00006 *             both Windows NT and Win32s.                            *
00007 *                                                                    *
00008 *  Functions: WinMain                                                *
00009 *             MainWndProc                                            *
00010 *                                                                    *
00011 \********************************************************************/
00012
00013 /*********************  Header Files  *********************/
00014
00015 #include <windows.h>
00016 #include "myut.h"
00017
00018 /*********************  Definitions ***********************/
00019
00020 typedef struct tagMYREC
00021 {
00022    char  s1[80];
00023    char  s2[80];
00024    DWORD n;
00025 } MYREC;
00026
00027 /*********************  Prototypes  ***********************/
00028
00029 LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM );
00030
00031 void WINAPI MyPrint( LPSTR, LPSTR, DWORD );
00032
00033 /********************************************************************\
00034 *  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
00035 *                                                                    *
00036 *   Purpose: Initializes Application                                 *
00037 *                                                                    *
00038 *  Comments: Standard template                                       *
00039 *                                                                    *
00040 *                                                                    *
00041 \********************************************************************/
00042
00043
00044 int PASCAL WinMain( HINSTANCE hInstance,
00045                     HINSTANCE hPrevInstance,
00046                     LPSTR lpszCmdLine,
00047                     int nCmdShow )
00048 {
00049    WNDCLASS wc;
00050    MSG msg;
00051    HWND hWnd;
00052
00053    if( !hPrevInstance ) {
00054       wc.lpszClassName = "Disp32Class";
00055       wc.lpfnWndProc = MainWndProc;
00056       wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
00057       wc.hInstance = hInstance;
00058       wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
00059       wc.hCursor = LoadCursor( NULL, IDC_ARROW );
00060       wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
00061       wc.lpszMenuName = NULL;
00062       wc.cbClsExtra = 0;
00063       wc.cbWndExtra = 0;
00064
00065       RegisterClass( &wc );
00066    }
00067
00068    hWnd = CreateWindow( "Disp32Class",
00069                         "Hidden Window",
00070                         WS_OVERLAPPEDWINDOW,
00071                         0,
00072                         0,
00073                         GetSystemMetrics(SM_CXMIN),
00074                         GetSystemMetrics(SM_CYMIN),
00075                         NULL,
00076                         NULL,
00077                         hInstance,
00078                         NULL
00079           );
00080
00081    ShowWindow( hWnd, SW_HIDE );
00082
00083    while( GetMessage( &msg, NULL, 0, 0 ) ) {
00084       TranslateMessage( &msg );
00085       DispatchMessage( &msg );
00086    }
00087
00088    return msg.wParam;
00089 }
00090
00091
00092 /********************************************************************\
00093 * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
00094 *                                                                    *
00095 *  Purpose: Processes Application Messages                           *
00096 *                                                                    *
00097 * Comments: The following messages are processed                     *
00098 *                                                                    *
00099 *           WM_DESTROY                                               *
00100 *                                                                    *
00101 *                                                                    *
00102 \********************************************************************/
00103
00104
00105 LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
00106    LPARAM lParam )
00107 {
00108    PCOPYDATASTRUCT pMyCDS;
00109
00110    switch( msg ) {
00111
00112 /**************************************************************\
00113 *     WM_COPYDATA: Dispatch calls to dll32.dll. The switch     *
00114 *        statement is not strictly necessary here, since there *
00115 *        is only one function thunked, but it is used to       *
00116 *        demonstrate how you would dispatch more than one      *
00117 *        function call.                                        *
00118 \**************************************************************/
00119
00120       case WM_COPYDATA:
00121          pMyCDS = (PCOPYDATASTRUCT) lParam;
00122
00123          switch( pMyCDS->dwData )
00124          {
00125             case MYPRINT:
00126                MyPrint( (LPSTR) ((MYREC *)(pMyCDS->lpData))->s1,
00127                         (LPSTR) ((MYREC *)(pMyCDS->lpData))->s2,
00128                         (DWORD) ((MYREC *)(pMyCDS->lpData))->n );
00129          }
00130          break;
00131
00132 /**************************************************************\
00133 *     WM_DESTROY: PostQuitMessage() is called                  *
00134 \**************************************************************/
00135
00136       case WM_DESTROY:
00137          PostQuitMessage( 0 );
00138          break;
00139
00140 /**************************************************************\
00141 *     Let the default window proc handle all other messages    *
00142 \**************************************************************/
00143
00144       default:
00145          return( DefWindowProc( hWnd, msg, wParam, lParam ));
00146    }
00147
00148    return 0;
00149 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WORLD/WORLD.H Source File

  • WORLD

WORLD.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************\
00013 * world.h: Header file for WORLD sample                       *
00014 *                                                             *
00015 *                                                             *
00016 \*************************************************************/
00017
00018
00019 /******* Menu Defines *******/
00020
00021 #define IDM_OPEN       1000
00022 #define IDM_EXIT       1001
00023 #define IDM_SCALE      1002
00024 #define IDM_ABOUT      1003
00025
00026
00027 /***** Control Defines ******/
00028
00029 #define IDC_HORZ       2000
00030 #define IDC_VERT       2001
00031
Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SIMPLDLL/LOADTEST.H Source File

  • SIMPLDLL

LOADTEST.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *                                LOADTEST.H
00015 *
00016 \******************************************************************************/
00017
00018
00019
00020 /******************************************************************************\
00021 *                            SYMBOLIC CONSTANTS
00022 \******************************************************************************/
00023
00024 #define IDM_LOADLIBRARY  100 /* menu identifiers */
00025 #define IDM_FREELIBRARY  101
00026 #define IDM_CREATETHREAD 102
00027 #define IDM_DLLFUNCTION1 103
00028 #define IDM_DLLFUNCTION2 104
00029 #define IDM_DLLFUNCTION3 105
00030 #define IDM_DLLFUNCTION4 106
00031 #define IDM_DLLDIALOGBOX 107
00032 #define IDM_ABOUT        108
00033
00034
00035
00036 /******************************************************************************\
00037 *                                  TYPEDEFS
00038 \******************************************************************************/
00039
00040 typedef int (*PFNDLL)();
00041
00042
00043
00044 /******************************************************************************\
00045 *                                 GLOBAL VARS
00046 \******************************************************************************/
00047
00048 HWND ghwndMain;
00049
00050 PFNDLL gpfnDLLFunction1 = NULL;
00051 PFNDLL gpfnDLLFunction2 = NULL;
00052 PFNDLL gpfnDLLFunction3 = NULL;
00053 PFNDLL gpfnDLLFunction4 = NULL;
00054 PFNDLL gpfnDLLDialogBox = NULL;
00055
00056
00057
00058 /******************************************************************************\
00059 *                              FUNCTION PROTOTYPES
00060 \******************************************************************************/
00061
00062 LRESULT CALLBACK MainWndProc  (HWND, UINT, WPARAM, LPARAM);
00063 BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM);
00064
00065 void ThreadProc  (void);
00066 void FixMenu    (UINT, HMENU);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STREBLT/TRACK.C Source File

  • STREBLT

TRACK.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  track.c -- support for direct manipulation of parallelogram object.
00014 \**************************************************************************/
00015
00016 #include <windows.h>
00017 #include <math.h>
00018 #include "track.h"
00019
00020 #define EPSILON  (float) 0.0001
00021 #define RECTSIZE  60
00022
00023
00024
00025 /**************************************************************************\
00026 *
00027 *  function:  doTrackObject()
00028 *
00029 *  input parameters:
00030 *   pto -  pointer to a track object.
00031 *   msg -  message selecting what action to take.  Values may include WM_*'s
00032 *           (see case statements below for more information.)
00033 *   hwnd - Window handle for the window the track object exists within.
00034 *   lParam - Usually fourth param to window proc. varies based on msg.
00035 *
00036 *  global variables:  none.
00037 *
00038 *  coordinate spaces:  There are three coordinate spaces of interest here,
00039 *   and this routine is frequently switching between them...
00040 *
00041 *           WORLD                   DEVICE                  SCREEN
00042 *
00043 *      object coordinates       input mouse pos       used w/ SetCursorPos()
00044 *         (pto->rect)          (lParam for WM_*)
00045 *
00046 *             ----->  LPtoDP() ---->    ----> ClientToScreen() -->
00047 *             <-----  DPtoLP() <----    <---- ScreenToClient() <--
00048 *
00049 *   in addition, the HDC has an offset origin.  Device coordinates for the
00050 *   mouse (lParam) never take this into account, but it is necessary to
00051 *   translate them in order to get direct manipulation right.
00052 *
00053 \**************************************************************************/
00054 PTrackObject doTrackObject(PTrackObject pto, int msg, HWND hwnd, LONG lParam)
00055 {
00056   if ((pto == NULL) && (msg != TROB_NEW))  return NULL;
00057
00058   switch (msg) {
00059
00060
00061     /**********************************************************************\
00062     *  TROB_NEW
00063     *
00064     * Allocate new PTrackObject structure.  Fill in default values
00065     *  for the fields of the structure.  Set up the HDC correctly.
00066     * return - pointer to the new object.
00067     \**********************************************************************/
00068     case  TROB_NEW: {
00069         PTrackObject  pto;
00070
00071         /* with LPTR returned value is a pointer. */
00072         pto = (PTrackObject) LocalAlloc (LPTR, sizeof (TrackObject));
00073
00074         /* initialize the HDC and other fields. */
00075         pto->hdc = GetDC (hwnd);
00076         SetGraphicsMode (pto->hdc, GM_ADVANCED);
00077         SetROP2(pto->hdc, R2_NOT);
00078         SelectObject (pto->hdc, GetStockObject (NULL_BRUSH));
00079         pto->Mode = TMNONE;
00080         pto->allowedModes = TMMOVE | TMSIZEXY;
00081
00082         GetWorldTransform (pto->hdc, &(pto->xfmChange));
00083
00084         /* initialize the size. */
00085         pto->rect.top = pto->rect.left = 0;
00086         pto->rect.bottom = pto->rect.right = RECTSIZE;
00087
00088         return (pto);
00089     }
00090
00091
00092
00093     /**********************************************************************\
00094     *  TROB_DELETE
00095     *
00096     * Complement of TROB_NEW.  Free up the memory allocated for the object.
00097     \**********************************************************************/
00098     case  TROB_DELETE:
00099         doTrackObject (pto, TROB_PAINT, hwnd, lParam);
00100         ReleaseDC (hwnd, pto->hdc);
00101         LocalFree (LocalHandle ((LPSTR)pto));
00102     return NULL;
00103
00104
00105
00106     /**********************************************************************\
00107     *  TROB_PAINT
00108     *
00109     * Paint the object into its hdc.  Called half the time to erase
00110     *  the object, and half the time to redraw it.
00111     \**********************************************************************/
00112     case TROB_PAINT: {
00113         MoveToEx (pto->hdc, pto->rect.right, pto->rect.top, NULL);
00114         LineTo (pto->hdc,  pto->rect.left, pto->rect.top);
00115         LineTo (pto->hdc,  pto->rect.left, pto->rect.bottom);
00116
00117         if (pto->allowedModes & TMSIZEXY) {
00118           LineTo (pto->hdc,  pto->rect.right, pto->rect.bottom);
00119           LineTo (pto->hdc,  pto->rect.right, pto->rect.top);
00120         }
00121
00122         if (pto->allowedModes & TMROTATE) {
00123           MoveToEx (pto->hdc, pto->rect.left, pto->rect.bottom/ 4, NULL);
00124           AngleArc (pto->hdc, pto->rect.left, pto->rect.top,
00125                  (DWORD) pto->rect.bottom/ 4, (float) 270.0, (float) 90.0);
00126         }
00127
00128     } return NULL;
00129
00130
00131
00132     /**********************************************************************\
00133     *  TROB_HITTEST
00134     *
00135     * Check the point sent in in the lParam to see if it lays within
00136     *  the bounds of the objects defining rectangle.
00137     * return - pointer to the object iff the point is in rectangle,
00138     *  otherwise return NULL.
00139     \**********************************************************************/
00140     case TROB_HITTEST:{
00141         POINT  mouWorld;
00142         mouWorld.x = LOWORD(lParam);
00143         mouWorld.y = HIWORD(lParam);
00144
00145         DPtoLP (pto->hdc, &mouWorld, 1);
00146
00147         if (PtInRect (&pto->rect, mouWorld))  return pto;
00148         else  return NULL;
00149     }
00150
00151
00152
00153     /**********************************************************************\
00154     *  WM_LBUTTONDOWN &  WM_RBUTTONDOWN
00155     *
00156     * Capture the mouse, set the tracking mode depending on the mouse
00157     *  location in world coordinates, reset the mouse position.
00158     *
00159     \**********************************************************************/
00160     case WM_LBUTTONDOWN:
00161     case WM_RBUTTONDOWN: {
00162       POINT  newmouScreen;
00163       POINT  mouWorld;
00164
00165       mouWorld.x = LOWORD(lParam);
00166       mouWorld.y = HIWORD(lParam);
00167       DPtoLP (pto->hdc, &mouWorld, 1);
00168
00169       /* upper left hand corner. right button is no-op. */
00170       if ((mouWorld.x <= (pto->rect.right  / 2)) &&
00171           (mouWorld.y <= (pto->rect.bottom / 2))) {
00172           if (msg == WM_RBUTTONDOWN) return NULL;
00173           pto->Mode = TMMOVE;
00174           newmouScreen.x = pto->rect.left;
00175           newmouScreen.y = pto->rect.top;
00176
00177       /* lower left hand corner */
00178       } else if ((mouWorld.x <= (pto->rect.right  / 2)) &&
00179           (mouWorld.y > (pto->rect.bottom / 2))) {
00180
00181           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARY : TMSIZEY;
00182           newmouScreen.x = pto->rect.left;
00183           newmouScreen.y = pto->rect.bottom;
00184
00185       /* upper right hand corner */
00186       } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
00187           (mouWorld.y <= (pto->rect.bottom / 2))) {
00188
00189           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMSHEARX : TMSIZEX;
00190           newmouScreen.x = pto->rect.right;
00191           newmouScreen.y = pto->rect.top;
00192
00193       /* lower right hand corner */
00194       } else if ((mouWorld.x > (pto->rect.right  / 2)) &&
00195           (mouWorld.y > (pto->rect.bottom / 2))) {
00196
00197           pto->Mode = (msg == WM_RBUTTONDOWN) ? TMROTATE : TMSIZEXY;
00198           newmouScreen.x = pto->rect.right;
00199           newmouScreen.y = pto->rect.bottom;
00200       }
00201
00202       if (! (pto->Mode & pto->allowedModes)) {
00203         pto->Mode = TMNONE;
00204         return NULL;
00205       }
00206
00207       SetCapture(hwnd);
00208       LPtoDP (pto->hdc, &newmouScreen, 1);
00209       ClientToScreen (hwnd, &newmouScreen);
00210       SetCursorPos (newmouScreen.x,newmouScreen.y);
00211
00212       GetWorldTransform (pto->hdc, &pto->xfmDown);
00213     } return NULL;
00214
00215
00216
00217     /**********************************************************************\
00218     *  WM_MOUSEMOVE
00219     *
00220     * this is where almost all of the interesting calculation is done.
00221     *  First clip the mouse location to be in rectClip, then
00222     *  call MouseMove() to handle the different tracking modes.
00223     \**********************************************************************/
00224     case WM_MOUSEMOVE: {
00225       if ((short) LOWORD(lParam) < (short)pto->rectClip.left)
00226         lParam = MAKELONG ((WORD)pto->rectClip.left, HIWORD(lParam));
00227
00228       if (LOWORD(lParam) > (WORD)pto->rectClip.right)
00229         lParam = MAKELONG ((WORD)pto->rectClip.right, HIWORD(lParam));
00230
00231       if ((short) HIWORD(lParam) < (short)pto->rectClip.top)
00232         lParam = MAKELONG (LOWORD(lParam), (WORD)pto->rectClip.top);
00233
00234       if (HIWORD(lParam) > (WORD)pto->rectClip.bottom)
00235         lParam = MAKELONG (LOWORD(lParam),(WORD)pto->rectClip.bottom);
00236
00237       MouseMove (pto, msg, hwnd, lParam);
00238
00239     } return NULL;
00240
00241
00242
00243     /**********************************************************************\
00244     *  WM_RBUTTONUP & WM_LBUTTONUP
00245     *
00246     * simply release the mouse capture, and set the mode to TMNONE.
00247     \**********************************************************************/
00248     case WM_RBUTTONUP:
00249     case WM_LBUTTONUP: {
00250       if (pto->Mode) {
00251          ReleaseCapture();
00252          pto->Mode = TMNONE;
00253       }
00254     } return NULL;
00255
00256   }  /* end switch(msg) */
00257 }
00258
00259
00260
00261
00262
00263
00264 /**************************************************************************\
00265 *  function:  MouseMove()
00266 *
00267 *  input parameters:
00268 *   pto -  pointer to a track object.
00269 *   msg -  not used.
00270 *   hwnd - Window handle for the window the track object exists within.
00271 *   lParam - Usually fourth param to window proc. varies based on msg.
00272 *
00273 *  The tracking behavior which the user observers when moving the mouse
00274 *   is based on the current tracking mode of the object.  This is usually
00275 *   determined on the mouse down event (c.f. TM*).  First erase the old
00276 *   object, then figure out the change to the transform matrix, finally
00277 *   change the world transform matrix and redraw the object.
00278 *
00279 *  Tranform:
00280 *    (    eM11        eM12        0   )
00281 *    (    eM21        eM22        0   )
00282 *    (    eDx         eDy         1   )
00283 *
00284 *   xDevice = (xWorld * eM11) + (yWorld * eM21) + eDx
00285 *   yDevice = (xWorld * eM12) + (yWorld * eM22) + eDy
00286 *
00287 *   In this routine the Device (mouse location) and World (rectangle corner)
00288 *   points are known.  Therefore, the two equations above are solved for
00289 *   the desired matrix entry value (e.g. eM11, 1M12, ... eDy).  The tracking
00290 *   mode determines which one of these entries may be changed.  E.g. scaling
00291 *   in X modifies eM11 while shearing in X modifies eM12.  So rather than
00292 *   using the world transform to map from world to device points, we are
00293 *   back-computing the proper contents of the world transform.
00294 *
00295 \**************************************************************************/
00296 VOID MouseMove(PTrackObject pto, int msg, HWND hwnd, LONG lParam)
00297 {
00298 POINT  mouWorld, mouDevice, orgDevice;
00299
00300     UNREFERENCED_PARAMETER(msg);
00301
00302     doTrackObject(pto, TROB_PAINT, hwnd, lParam);
00303     mouDevice.x = mouWorld.x = LOWORD(lParam);
00304     mouDevice.y = mouWorld.y = HIWORD(lParam);
00305
00306     SetWorldTransform(pto->hdc, &pto->xfmDown);
00307     DPtoLP (pto->hdc, &mouWorld, 1);
00308
00309     /* offset the mouse device point for the viewport's origin. */
00310     GetViewportOrgEx (pto->hdc, &orgDevice);
00311     mouDevice.x -= orgDevice.x;
00312     mouDevice.y -= orgDevice.y;
00313
00314     GetWorldTransform(pto->hdc, &pto->xfmChange);
00315
00316     switch (pto->Mode) {
00317       /*******************************************************\
00318       *    (     1         xShear       0   )
00319       *    (     0           1          0   )
00320       *    (     0           0          1   )
00321       *
00322       * xWorld = rect.left == 0;
00323       \*******************************************************/
00324       case TMSHEARX: {
00325         pto->xfmChange.eM12 = (float) mouDevice.y;
00326         pto->xfmChange.eM12 -=pto->xfmChange.eDy;
00327         pto->xfmChange.eM12 /=(float) pto->rect.right ;
00328         SetWorldTransform (pto->hdc, &pto->xfmChange);
00329       } break;
00330
00331
00332       /*******************************************************\
00333       *    (     1           0          0   )
00334       *    (   yShear        1          0   )
00335       *    (     0           0          1   )
00336       *
00337       * yWorld = rect.top == 0;
00338       \*******************************************************/
00339       case TMSHEARY: {
00340         pto->xfmChange.eM21 = (float) mouDevice.x;
00341         pto->xfmChange.eM21 -=pto->xfmChange.eDx;
00342         pto->xfmChange.eM21 /=(float) pto->rect.bottom ;
00343         SetWorldTransform (pto->hdc, &pto->xfmChange);
00344
00345       } break;
00346
00347
00348       /*******************************************************\
00349       *    (   cos(a)      -sin(a)      0   )
00350       *    (   sin(a)       cos(a)      0   )
00351       *    (     0           0          1   )
00352       *
00353       * a == rotation angle.  Since mouse in in lower right,
00354       *  we need to shift this back 45 degrees (assuming that
00355       *  straight down is 0 degrees).  Thus we actually compute
00356       *  cos(a) = cos(b - 45) = cos(b)sin(45) + cos(45)sin(45)
00357       *  where b is angle from the origin to the mouse (x,y)
00358       *  cos(45) = sin(45) ~= 0.707107
00359       *  cos(b) = y/r    sin(b) = x/r
00360       *
00361       \*******************************************************/
00362       case TMROTATE: {
00363         float r;
00364
00365         /* translate back to the origin. */
00366         pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
00367         SetWorldTransform (pto->hdc, &pto->xfmChange);
00368
00369         /* rotate about the origin. */
00370         r = (float) sqrt( (double)(mouWorld.x * mouWorld.x) +
00371                           (double)(mouWorld.y * mouWorld.y));
00372
00373         pto->xfmChange.eM11 = (float) mouWorld.y / r;
00374         pto->xfmChange.eM11 += (float) mouWorld.x / r;
00375         pto->xfmChange.eM11 *= (float) 0.707107;
00376         pto->xfmChange.eM22 = pto->xfmChange.eM11;
00377
00378         pto->xfmChange.eM12 = (float) mouWorld.y / r;
00379         pto->xfmChange.eM12 -= (float) mouWorld.x / r;
00380         pto->xfmChange.eM12 *= (float) 0.707107;
00381         pto->xfmChange.eM21 = -pto->xfmChange.eM12;
00382
00383         pto->xfmChange.eDx = pto->xfmChange.eDy = (float)0.0;
00384
00385         ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
00386
00387         /* translate back to the original offset. */
00388         pto->xfmChange.eM11 =
00389         pto->xfmChange.eM22 = (float) 1.0;
00390         pto->xfmChange.eM12 =
00391         pto->xfmChange.eM21 = (float) 0.0;
00392
00393         pto->xfmChange.eDx = pto->xfmDown.eDx;
00394         pto->xfmChange.eDy = pto->xfmDown.eDy;
00395         ModifyWorldTransform (pto->hdc, &pto->xfmChange, MWT_RIGHTMULTIPLY);
00396         GetWorldTransform (pto->hdc, &pto->xfmChange);
00397       } break;
00398
00399
00400       /*******************************************************\
00401       *    (  Size X         0          0   )
00402       *    (     0        Size Y        0   )
00403       *    (     0           0          1   )
00404       *
00405       \*******************************************************/
00406       case TMSIZEXY: {
00407         pto->xfmChange.eM11 = (float) mouDevice.x;
00408         pto->xfmChange.eM11 -=pto->xfmChange.eDx;
00409         pto->xfmChange.eM11 -=((float) pto->rect.bottom*pto->xfmChange.eM21);
00410         pto->xfmChange.eM11 /=(float) pto->rect.right ;
00411         if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
00412            pto->xfmChange.eM11 = EPSILON;
00413
00414         pto->xfmChange.eM22 = (float) mouDevice.y;
00415         pto->xfmChange.eM22 -=pto->xfmChange.eDy;
00416         pto->xfmChange.eM22 -=((float) pto->rect.right*pto->xfmChange.eM12);
00417         pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
00418         if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
00419            pto->xfmChange.eM22 = EPSILON;
00420         SetWorldTransform (pto->hdc, &pto->xfmChange);
00421       } break;
00422
00423
00424       /*******************************************************\
00425       *    (  Size X         0          0   )
00426       *    (     0           1          0   )
00427       *    (     0           0          1   )
00428       *
00429       * yWorld = rect.top == 0;
00430       \*******************************************************/
00431       case TMSIZEX: {
00432         pto->xfmChange.eM11 = (float) mouDevice.x;
00433         pto->xfmChange.eM11 -=pto->xfmChange.eDx;
00434         pto->xfmChange.eM11 /=(float) pto->rect.right ;
00435         if (fabs(pto->xfmChange.eM11) < EPSILON)  // HACK.  system bug ?
00436            pto->xfmChange.eM11 = EPSILON;
00437
00438         SetWorldTransform (pto->hdc, &pto->xfmChange);
00439       } break;
00440
00441
00442       /*******************************************************\
00443       *    (     1           0          0   )
00444       *    (     0        Size Y        0   )
00445       *    (     0           0          1   )
00446       *
00447       * xWorld = rect.left == 0;
00448       \*******************************************************/
00449       case TMSIZEY: {
00450         pto->xfmChange.eM22 = (float) mouDevice.y;
00451         pto->xfmChange.eM22 -=pto->xfmChange.eDy;
00452         pto->xfmChange.eM22 /=(float) pto->rect.bottom ;
00453         if (fabs(pto->xfmChange.eM22) < EPSILON)  // HACK.  system bug ?
00454            pto->xfmChange.eM22 = EPSILON;
00455         SetWorldTransform (pto->hdc, &pto->xfmChange);
00456       } break;
00457
00458
00459       /*******************************************************\
00460       *    (     1           0          0   )
00461       *    (     0           1          0   )
00462       *    (   Move x      Move y       1   )
00463       *
00464       * xWorld = rect.left == 0;
00465       * yWorld = rect.top == 0;
00466       \*******************************************************/
00467       case TMMOVE: {
00468         pto->xfmChange.eDx = (float) mouDevice.x ;
00469         pto->xfmChange.eDy = (float) mouDevice.y ;
00470         SetWorldTransform (pto->hdc, &pto->xfmChange);
00471       } break;
00472     } /* end switch */
00473
00474     doTrackObject(pto, TROB_PAINT, hwnd, lParam);
00475
00476     return;
00477  }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TLS/TLSCALL.C Source File

  • TLS

TLSCALL.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************\
00013 *
00014 * MODULE:       tlscall.c
00015 *
00016 /****************************************************************************/
00017
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <stdarg.h>
00021 #include <windows.h>
00022 #include <string.h>
00023 #include <winbase.h>
00024 #include "tlsdll.h"
00025
00026 #define NUMTHREADS 3    /* The number of threads to start */
00027
00028 /*-----------------------------------------------------------------*/
00029
00030 void ErrorOut(char errstring[30])
00031 /*
00032 Purpose: Print out an meainful error code by means of
00033          GetLastError and printf
00034
00035 Inputs:  errstring - the action that failed, passed by the
00036                      calling proc.
00037
00038 Returns: none
00039
00040 Calls:   GetLastError
00041 */
00042
00043 {
00044 DWORD Error;
00045
00046 Error= GetLastError();
00047 printf("Error on %s = %d\n", errstring, Error);
00048 }
00049
00050 /*-----------------------------------------------------------------*/
00051
00052 void Another_Thread()
00053 /*
00054 Purpose: Make a call into a DLL and then terminate, allowing
00055          DLL init. and termination to be called.
00056
00057 Inputs:  none
00058
00059 Returns: none
00060
00061 Calls:   TlsInit: Dummy proc. to allow DLL initialization.
00062 */
00063
00064 {
00065 Sleep(300);      /* Sleep while other threads start */
00066 TlsInit();       /* Call dummy init. procedure */
00067 ExitThread(0);   /* Exit, calling DLL termination */
00068 }
00069
00070 /*-----------------------------------------------------------------*/
00071
00072 void main(void)
00073 /*
00074 Purpose: Make a call into a DLL and then terminate, allowing
00075          DLL init. and termination to be called.
00076
00077 Inputs:  none
00078
00079 Returns: none
00080
00081 Calls:   CreateThread: to create threads for DLL init.
00082          ErrorOut: To output any errors
00083          WaitForMultipleObjects: To wait on thread(s) termination
00084 */
00085
00086 {
00087 int  threadid;
00088 HANDLE hThreads[NUMTHREADS];
00089 int count;
00090
00091   // check if Win32s, if so, display notice and terminate
00092      if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) ==3)
00093      {
00094        MessageBox( NULL,
00095           "This application cannot run on Windows 3.1.\n"
00096           "This application will now terminate.",
00097           "Tls",
00098           MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00099        return;
00100      }
00101
00102  /* start NUMTHREADS threads */
00103   for (count = 0 ; count < NUMTHREADS ; count++)
00104   {
00105   hThreads[count]= CreateThread(NULL,
00106                                 0,
00107                                 (LPTHREAD_START_ROUTINE)Another_Thread,
00108                                 NULL,
00109                                 0,
00110                                 (LPDWORD)&threadid);
00111   if( hThreads[count] == 0)
00112     ErrorOut("CreateThread");
00113   else
00114     printf("\nStarting thread# %d\n\n", count +1);
00115   }
00116
00117       /* now wait for threads to terminate */
00118 printf("\n\n***** Waiting for %d Threads to Exit*****\n\n", NUMTHREADS);
00119 WaitForMultipleObjects( NUMTHREADS,
00120                         hThreads,
00121                         FALSE,
00122                         0xFFFFFFFF);
00123 Sleep(1000);
00124 printf("\n\n*****   All %d Threads Terminated   *****\n\n", NUMTHREADS);
00125
00126 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: EVENT/ASYN_IO.C Source File

  • EVENT

ASYN_IO.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /****************************************************************************\
00013 **   MODULE:  IO.C                                                         **
00014 **                                                                         **
00015 **                                                                         **
00016 **   PURPOSE: Demonstrates the basic concepts envolved when using          **
00017 **            asynchronous IO. In particular the main advantage is your    **
00018 **            app more correctly thread can go about doing useful work     **
00019 **            while waiting for IO. The main disadvantage is you must keep **
00020 **            track of the file pointer.                                   **
00021 **                                                                         **
00022 **   INPUT: Both the File to read and File to write to must be entered     **
00023 **          on via the command line. Note the file to write to must be     **
00024 **          unique.                                                        **
00025 **                                                                         **
00026 **   FUNCTIONS:                                                            **
00027 **                                                                         **
00028 **       Do_BackgroundTask()                                               **
00029 **                                                                         **
00030 **                                                                         **
00031 **   COMMENTS: Reads a file asynchronously writes to another synchronously **
00032 **                                                                         **
00033 **                                                                         **
00034 \***************************************************************************/
00035
00036
00037
00038 #define STRICT
00039 #define NOMINMAX
00040 #include <windows.h>
00041
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 #include <memory.h>
00045 #include <string.h>
00046
00047 #define DEFAULT           0L
00048 #define SUCCESS           0L
00049 #define IO_ERROR          (HANDLE)0xFFFFFFFF
00050 #define WAIT_ERROR        0xFFFFFFFF
00051 #define SECTOR_SIZE       1024
00052 #define RETURN_IMEDIATELY 0L
00053
00054 #if !defined(HEVENT)
00055 typedef HANDLE HEVENT;
00056 #endif
00057
00058 #if !defined(HFILEEX)
00059 typedef HANDLE HFILEEX;
00060 #endif
00061
00062 VOID ErrorMsg ( PSZ psz ) ;
00063 VOID Do_BackgroundTask ( VOID ) ;
00064
00065
00066
00067 void main ( int argc, char *argv[] )
00068
00069 {
00070
00071
00072    HFILEEX    hInfile,  // Handle to the file to read
00073             hOutfile; // Handle to the file to write to
00074
00075    HEVENT   hEvent ;  // Handle to the synchronization Event
00076
00077    OVERLAPPED
00078             OverLapped ; // The operating system does not automatically
00079                          // track the current file position of a file
00080                          // open for asynchroous I/O. Instead one must
00081                          // manually track this by updating the OVERLAPPED
00082                          // structure. To update this structure one uses
00083                          // the result returned by GetOverLappedResults().
00084
00085
00086    CHAR     buf[SECTOR_SIZE] ; // Buffer used by either
00087                                // ReadFile() or WriteFile()
00088
00089    DWORD    cbBytesRead,         // count of bytes read by ReadFile()
00090                                  // When asynchonous I/O is performed
00091                                  // one must check how many bytes were
00092                                  // read by calling GetOverLappedResults().
00093
00094
00095             cbBytesWritten,      // count of bytes written by WriteFile()
00096
00097             cbBytesTransfered ;  // this value is returned by
00098                                  // GetOverLappedResults() represents the
00099                                  // count of bytes transfered asynchronous
00100
00101    DWORD    dwStatus,            // value returned by GetLastError()
00102             dwSuccess ;          // return code of last API called
00103
00104    BOOL     bSuccess ;           // return code of last API called
00105
00106    CHAR     buffer[80] ;
00107
00108 /***************************************************************************\
00109 **                                                                         **
00110 **  This block of code initalizes all the necessary variables needed to do **
00111 **  asynchronous IO. Specfically it opens the files and initializes the    **
00112 **  synchronization EVENT and OVERLAPPED structure needed to keep track    **
00113 **  of asynchronous file I/O                                               **
00114 **                                                                         **
00115 \***************************************************************************/
00116
00117 // check if running on Windows NT, if not, display notice and terminate
00118     if( GetVersion() & 0x80000000 )
00119     {
00120        MessageBox( NULL,
00121          "This sample application can only be run on Windows NT.\n"
00122          "This application will now terminate.",
00123          "Event",
00124          MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00125       return;
00126    }
00127
00128    if ( argc != 3 )
00129    {
00130       printf ( "\nUsage: ASYN_IO input_file output_file\n" ) ;
00131       exit ( EXIT_FAILURE ) ;
00132    }
00133
00134
00135
00136 /*
00137  * Open file which we will be copying. Note we are opening this
00138  * asynchronously.
00139  */
00140
00141    hInfile = CreateFile
00142                   (
00143                      argv[1]              // File to read
00144                     ,GENERIC_READ         // Open file for reading only
00145                     ,FILE_SHARE_READ      // Allow others to read file
00146                     ,NULL                 // No security
00147                     ,OPEN_EXISTING        // Fail if file doesn't exit
00148                     ,FILE_FLAG_OVERLAPPED // Async I/o
00149                     ,DEFAULT
00150                   ) ;
00151
00152
00153    if ( hInfile == IO_ERROR )
00154    {
00155       strcpy ( buffer, "Error opening" ) ;
00156       strcat ( buffer, argv[1] ) ;
00157       ErrorMsg ( buffer ) ;
00158    }
00159
00160
00161 /*
00162  * Create the file to write to; here we have opened it for synchronous IO.
00163  */
00164
00165    hOutfile = CreateFile
00166                   (
00167                      argv[2]                 // File to write to
00168                     ,GENERIC_WRITE           // Open file only to write to
00169                     ,DEFAULT                 // No sharing allowed
00170                     ,NULL                    // No security
00171                     ,CREATE_NEW              // Fail if file exists
00172                     ,FILE_ATTRIBUTE_NORMAL   // No attributes
00173                     ,DEFAULT
00174                   ) ;
00175
00176
00177    if ( hOutfile == IO_ERROR )
00178    {
00179       strcpy ( buffer, "Error opening" ) ;
00180       strcat ( buffer, argv[1] ) ;
00181       ErrorMsg ( buffer ) ;
00182    }
00183
00184
00185
00186 /*
00187  * Create Synchronoizing Event
00188  */
00189
00190    hEvent = CreateEvent
00191                     (
00192                       NULL    // No security
00193                      ,TRUE    // Manual reset
00194                      ,FALSE   // Initially Event set to non-signaled state
00195                      ,NULL    // No name
00196                     ) ;
00197    if ( !hEvent )
00198       ErrorMsg ( "Error creating Event" ) ;
00199
00200
00201 /*
00202  * Intialize OverLapped structure. We will be using an Event instead
00203  * of the file handle for synchronizing I/O. One reason to use a unique
00204  * event instead of the file handle would be a so multi-threaded app
00205  * would know which thread to unblock when the handle is set to the
00206  * signaled state.
00207  */
00208
00209    memset ( &OverLapped, 0, sizeof ( OVERLAPPED ) ) ;
00210    OverLapped.hEvent = hEvent ;
00211
00212
00213    bSuccess = TRUE ;
00214
00215
00216 /***************************************************************************\
00217 **                                                                         **
00218 ** This is the main function of this program. Here we loop until the file  **
00219 ** has been copied. Notice that even though we are using asynchronous I/O  **
00220 ** ReadFile() may still return sychronously if it can be done fast enough  **
00221 **                                                                         **
00222 \***************************************************************************/
00223
00224    while ( bSuccess )
00225    {
00226
00227 /*
00228  * Read file asynchronously
00229  */
00230
00231       bSuccess = ReadFile
00232             (
00233                hInfile        // Handle of file to read
00234               ,buf            // Buffer to store input
00235               ,SECTOR_SIZE    // Number of bytes to read
00236               ,&cbBytesRead   // Number of bytes read. See note]
00237                               // above in delcaration
00238               ,&OverLapped    // Used for asynchronous I/O
00239             ) ;
00240
00241
00242
00243 /*
00244  * Check whether ReadFile() has completed yet
00245  */
00246       if ( !bSuccess && (( dwStatus = GetLastError ()) == ERROR_IO_PENDING ) )
00247       {
00248         printf ( "\nIO Pending" ) ;
00249 /*
00250  * Read not complete yet first execute the background task then check
00251  * to the if event "hEvent" set to the signaled state. If the event is
00252  * not set signaled state then loop through again - run the background
00253  * task and check the event.
00254  *
00255  */
00256
00257         Do_BackgroundTask () ;
00258
00259         dwSuccess = WaitForSingleObject ( hEvent, RETURN_IMEDIATELY ) ;
00260
00261         if ( dwSuccess == WAIT_ERROR )
00262             ErrorMsg("Error in WaitForSingleObject") ;
00263         else if ( dwSuccess == SUCCESS )
00264         {
00265
00266             bSuccess = GetOverlappedResult(
00267                             hInfile, &OverLapped, &cbBytesTransfered, FALSE) ;
00268             if ( !bSuccess )
00269                 ErrorMsg ( "Error in GetOverLappedResult" ) ;
00270             else
00271             {
00272                 // Read has completed now find out how many bytes have been read
00273
00274                 printf ( "\nNumber of bytes transfered is %d\n", cbBytesTransfered ) ;
00275                 OverLapped.Offset += cbBytesTransfered ;
00276                 cbBytesRead = cbBytesTransfered ;
00277             }
00278         }
00279         else if ( dwSuccess == WAIT_TIMEOUT )
00280             Do_BackgroundTask () ;
00281       }
00282 /*
00283  * ReadFile() read file synchronously; update Overlapped structure
00284  */
00285       else if ( bSuccess  && cbBytesRead != 0 )
00286       {
00287          printf ( "\nNumber of bytes transfered is %d\n", cbBytesRead ) ;
00288          OverLapped.Offset += cbBytesRead ;
00289       }
00290 /*
00291  * ReadFile() has found the end of the file; exit loop
00292  */
00293       else if ( bSuccess  && cbBytesRead == 0 )
00294       {
00295          printf ( "End of file read\n" ) ;
00296          break ;
00297       }
00298 /*
00299  * An error occured while reading, print out status and exit loop.
00300  */
00301       else
00302          ErrorMsg ( "Error reading to file" ) ;
00303
00304
00305
00306 /*
00307  * Write to file synchronously
00308  */
00309       bSuccess = WriteFile
00310             (
00311                hOutfile             // Handle of file to write to
00312               ,buf                  // Data to write to file
00313               ,cbBytesRead          // Number of bytes to write
00314               ,&cbBytesWritten      // Number of bytes written
00315               ,NULL                 // Only need for asynchonous output
00316             ) ;
00317
00318
00319       if ( !bSuccess )
00320          ErrorMsg ( "Error writing to file" ) ;
00321
00322    } // End of WHILE loop
00323
00324
00325
00326    CloseHandle ( hInfile ) ;        // Close handle to input file
00327    FlushFileBuffers ( hOutfile ) ;  // Make sure all data written to file first
00328    CloseHandle ( hOutfile ) ;       // Close handle to output file
00329    exit ( EXIT_SUCCESS ) ;
00330
00331 }
00332
00333
00334
00335 /***************************************************************************\
00336 **                                                                         **
00337 **   FUNCTION: ErrorMsg(LPTSTR)                                            **
00338 **                                                                         **
00339 **   PURPOSE: Prints out an error message the return code of the last API  **
00340 **            to fail.                                                     **
00341 **                                                                         **
00342 **   INPUT: psz: This string is a description of where the code failed in  **
00343 **          the module                                                     **
00344 **                                                                         **
00345 **   OUTPUT: None                                                          **
00346 **                                                                         **
00347 \****************************************************************************/
00348
00349 VOID ErrorMsg ( PSZ psz )
00350 {
00351
00352   printf ("\n%s: return code = %d\n", psz, GetLastError()) ;
00353   exit ( EXIT_FAILURE ) ;
00354 }
00355
00356 /***************************************************************************\
00357 **                                                                         **
00358 **   FUNCTION: Do_BackgroundTask ( VOID )                                  **
00359 **                                                                         **
00360 **   PURPOSE: Works in the background while IO sytems                      **
00361 **                                                                         **
00362 **   COMMENTS:                                                             **
00363 **                                                                         **
00364 **      Currently this does nothing if I have the time I will come up      **
00365 **      with some silly task to keep the user entertained.                 **
00366 **                                                                         **
00367 **   INPUT: None                                                           **
00368 **                                                                         **
00369 **   OUTPUT: None                                                          **
00370 **                                                                         **
00371 \***************************************************************************/
00372
00373 VOID Do_BackgroundTask ( VOID )
00374 {
00375   Sleep ( 5000L ) ;
00376 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GUIGREP/GUIGREP.H Source File

  • GUIGREP

GUIGREP.H

Go to the documentation of this file.
00001
00002 #define IDM_ABOUT 100
00003 #define IDM_DEFGREP 101
00004 #define IDM_INSTALL 102
00005 #define IDM_STRINGEDIT 103
00006 #define IDM_TERMBOX 104
00007 #define IDM_STARTGREP 105
00008 #define IDM_UNINSTALL 106
00009 #define IDM_SORTBOX 107
00010 #define IDM_CASESENS 108
00011 #define IDM_CANCEL 109
00012
00013 #define WM_INQUIREFILES WM_USER+0xc001
00014 #define WM_LAUNCH       WM_USER+0xc002
00015 #define WM_FREEAGAIN    WM_USER+0xc003
00016 #define WM_ADDITEM      WM_USER+0xc004
00017 #define WM_TELLHANDLE   WM_USER+0xc005
00018 #define WM_STARTSYNC    WM_USER+0xc006
00019
00020
00021 #define MAXLINELEN      256
00022 #define FILBUFSIZE      16384
00023 #define MAX_CONCURRENT_THREADS 30
00024
00025
00026 BOOL InitApplication(HANDLE);
00027 BOOL InitInstance(HANDLE, int);
00028 long FAR PASCAL MainWndProc(HWND, UINT, UINT, LONG);
00029 BOOL FAR PASCAL About(HWND, UINT, UINT, LONG);
00030
00031
00032 typedef struct tagTHREADPBLOCK
00033 {
00034  int  iLoop;
00035  HWND hWndGlobal;
00036  HWND hWndFileBox;
00037 } THREADPBLOCK, *LPTHREADPBLOCK;
00038
00039
00040 /*********************************************************************/
00041 /*                                                                   */
00042 /*     C++ declarations here                                         */
00043 /*                                                                   */
00044 /*********************************************************************/
00045
00046 /*********************************************************************/
00047 /*                                                                   */
00048 /*     The memory class is a simple fast allocator. It provides      */
00049 /*     one static memory block from which little chunks are          */
00050 /*     allocated by each thread.                                     */
00051 /*                                                                   */
00052 /*********************************************************************/
00053
00054 class memory
00055 {
00056 private:  LPSTR lpBasePointer;  /* Probably don't need this one at all... */
00057     LPSTR lpCurrentPointer;
00058     LPSTR lpReturnPointer;
00059     int iCurrentPointer;
00060     int iActualBlockSize;
00061     HANDLE hBlock;
00062     CRITICAL_SECTION csAllocGuard;
00063 public:   memory(int);
00064     ~memory(void);
00065     LPSTR Alloc (int iSize)
00066     {      EnterCriticalSection(&csAllocGuard);
00067 #ifdef MIPS
00068   /* MIPS requires all DWORDs to be aligned on DWORD boundaries.
00069      That's why under MIPS, we round up all alignments to
00070      multiples of sizeof(DWORD).   */
00071      if (iSize != (int)((iSize / sizeof (DWORD)) * sizeof (DWORD)))
00072         iSize = (1 + (iSize / sizeof (DWORD))) * sizeof (DWORD);
00073 #endif
00074        if (iSize + iCurrentPointer > iActualBlockSize)
00075     {               MessageBox(GetFocus(),"No memory left",
00076           "Grepper",MB_OK);
00077             return((LPSTR)0);
00078     };
00079     iCurrentPointer+= iSize;
00080     lpReturnPointer = lpCurrentPointer;
00081   _try {
00082     lpCurrentPointer = &lpCurrentPointer[iSize];
00083     }
00084     _except (EXCEPTION_EXECUTE_HANDLER) {
00085      MessageBox(GetFocus(),"Access Violation","Memory Allocator",MB_OK);
00086     };
00087     LeaveCriticalSection(&csAllocGuard);
00088     return (lpReturnPointer);
00089      };
00090      void Reset()
00091      {lpCurrentPointer = lpBasePointer;
00092       iCurrentPointer = 0;
00093      };
00094      void Free (LPSTR lpBlockPt)
00095      {};
00096 };
00097
00098 memory::memory(int iSize)
00099 {
00100   hBlock = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,iSize);
00101   lpBasePointer = (LPSTR) LocalLock(hBlock);
00102   lpCurrentPointer = lpBasePointer;
00103   iActualBlockSize = iSize;
00104   iCurrentPointer = 0;
00105   InitializeCriticalSection(&csAllocGuard);
00106 }
00107
00108 memory::~memory()
00109 { LocalUnlock(hBlock);
00110   LocalFree(hBlock);
00111   DeleteCriticalSection(&csAllocGuard);
00112 }
00113
00114 /*********************************************************************/
00115 /*                                                                   */
00116 /*     GrowMemory provides a growable block of memory.               */
00117 /*     It is used for the local handle of the edit box that          */
00118 /*     accomodates the hits.
00119 /*                                                                   */
00120 /*********************************************************************/
00121
00122 class growmemory
00123 {
00124 private: int iCurrentSize,iCurrentPt,iIncrement;
00125      HANDLE hCurrentBlock;
00126      LPSTR lpStartPt;
00127      CRITICAL_SECTION csAllocGuard;
00128    char lpszCRLF[3];
00129    int ilpszCRLF;
00130
00131 public: growmemory(int iInitSize, int iInc);
00132       ~growmemory(void);
00133       BOOL add(LPSTR lpSource, int iSize)
00134 /* watch out here: We assume that the requested size is never bigger than
00135    the increment. This is safe with the hardcoded values but may fail in
00136    the general case. */
00137
00138        { int iSizeOld = iSize;
00139          EnterCriticalSection(&csAllocGuard);
00140 /* adjust the size for the line feed to follow */
00141            iSize+=ilpszCRLF;
00142          if (iCurrentPt+iSize > iCurrentSize)
00143           {iCurrentSize+=iIncrement;
00144        hCurrentBlock = LocalReAlloc(hCurrentBlock,iCurrentSize,LMEM_MOVEABLE);
00145           };
00146           lpStartPt = (LPSTR)LocalLock(hCurrentBlock);
00147           if (!lpStartPt)
00148            { MessageBeep(0);
00149              return(FALSE);     };
00150           strncpy(&lpStartPt[iCurrentPt],lpSource,iSizeOld);
00151 /* add the CRLF at the end. */
00152           strncpy(&lpStartPt[iCurrentPt+iSizeOld],lpszCRLF,ilpszCRLF);
00153           LocalUnlock(hCurrentBlock);
00154           iCurrentPt+=iSize;
00155           LeaveCriticalSection(&csAllocGuard);
00156           return(TRUE);
00157           };
00158     HANDLE GetHandle(void)
00159       { return (hCurrentBlock);
00160       };
00161 };
00162
00163 growmemory::growmemory(int iInitSize, int iInc)
00164        { iIncrement=iInc;
00165          iCurrentPt=0;
00166          iCurrentSize=iInitSize;
00167          hCurrentBlock = LocalAlloc(LMEM_MOVEABLE,iCurrentSize);
00168          InitializeCriticalSection(&csAllocGuard);
00169          strcpy(lpszCRLF,"\r\n");
00170          ilpszCRLF=strlen(lpszCRLF);
00171        }
00172 growmemory::~growmemory(void)
00173        {DeleteCriticalSection(&csAllocGuard);
00174         LocalFree(hCurrentBlock);
00175        }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMTHRD.H Source File

  • SERVENUM
  • DLL

ENUMTHRD.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumthrd.h
00009 //
00010 //  PURPOSE:  contains enumthrd declarations
00011 //
00012
00013 #ifndef _ENUMTHRD_H
00014 #define _ENUMTHRD_H
00015
00016 //-----------------------------------------------------------------------
00017 // enumthrd defines
00018
00019 #define ERROR_FAILURE 1
00020
00021 #define HANDLE_PROV  0
00022 #define HANDLE_DOM   1
00023 #define HANDLE_SERV  2
00024 #define NUM_HANDLES  3
00025
00026
00027 //-----------------------------------------------------------------------
00028 // enumthrd prototypes
00029
00030 DWORD WINAPI InitialEnumThread( LPENUMSYNC lpSync );
00031 DWORD WINAPI EnumExpandThread( LPENUMLISTOBJECT lpObject );
00032 DWORD WINAPI EnumContainerThread( LPENUMOBJECT lpObject );
00033
00034 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: CURSOR/CURSOR.H Source File

  • CURSOR

CURSOR.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1993 - 1996 Microsoft Corp.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDM_ABOUT 100
00013
00014 typedef POINTS MPOINT;
00015 #define MPOINT2POINT(mpt,pt)  ((pt).x = (mpt).x, (pt).y = (mpt).y)
00016 #define POINT2MPOINT(pt, mpt) ((mpt).x = (SHORT)(pt).x, (mpt).y = (SHORT)(pt).y)
00017
00018 BOOL InitApplication(HANDLE);
00019 BOOL InitInstance(HANDLE, INT);
00020 LONG APIENTRY MainWndProc(HWND, UINT, UINT, LONG);
00021 BOOL APIENTRY About(HWND, UINT, UINT, LONG);
00022 INT sieve(VOID);
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/MISC.C Source File

  • SERVENUM
  • DEMO

MISC.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   misc.c
00009 //
00010 //  PURPOSE:  Contains all helper functions "global" to the application.
00011 //
00012 //  FUNCTIONS:
00013 //    CenterWindow - Center one window over another.
00014 //
00015 //  COMMENTS:
00016 //
00017 //
00018
00019 #include <windows.h>            // required for all Windows applications
00020 #include <windowsx.h>
00021
00022 #include "globals.h"            // prototypes specific to this application
00023
00024
00025
00026 //
00027 //  FUNCTION: CenterWindow(HWND, HWND)
00028 //
00029 //  PURPOSE:  Center one window over another.
00030 //
00031 //  PARAMETERS:
00032 //    hwndChild - The handle of the window to be centered.
00033 //    hwndParent- The handle of the window to center on.
00034 //
00035 //  RETURN VALUE:
00036 //
00037 //    TRUE  - Success
00038 //    FALSE - Failure
00039 //
00040 //  COMMENTS:
00041 //
00042 //    Dialog boxes take on the screen position that they were designed
00043 //    at, which is not always appropriate. Centering the dialog over a
00044 //    particular window usually results in a better position.
00045 //
00046
00047 BOOL CenterWindow(HWND hwndChild, HWND hwndParent)
00048 {
00049     RECT    rcChild, rcParent;
00050     int     cxChild, cyChild, cxParent, cyParent;
00051     int     cxScreen, cyScreen, xNew, yNew;
00052     HDC     hdc;
00053
00054     // Get the Height and Width of the child window
00055     GetWindowRect(hwndChild, &rcChild);
00056     cxChild = rcChild.right - rcChild.left;
00057     cyChild = rcChild.bottom - rcChild.top;
00058
00059     // Get the Height and Width of the parent window
00060     GetWindowRect(hwndParent, &rcParent);
00061     cxParent = rcParent.right - rcParent.left;
00062     cyParent = rcParent.bottom - rcParent.top;
00063
00064     // Get the display limits
00065     hdc = GetDC(hwndChild);
00066     cxScreen = GetDeviceCaps(hdc, HORZRES);
00067     cyScreen = GetDeviceCaps(hdc, VERTRES);
00068     ReleaseDC(hwndChild, hdc);
00069
00070     // Calculate new X position, then adjust for screen
00071     xNew = rcParent.left + ((cxParent - cxChild) / 2);
00072     if (xNew < 0)
00073     {
00074         xNew = 0;
00075     }
00076     else if ((xNew + cxChild) > cxScreen)
00077     {
00078         xNew = cxScreen - cxChild;
00079     }
00080
00081     // Calculate new Y position, then adjust for screen
00082     yNew = rcParent.top  + ((cyParent - cyChild) / 2);
00083     if (yNew < 0)
00084     {
00085         yNew = 0;
00086     }
00087     else if ((yNew + cyChild) > cyScreen)
00088     {
00089         yNew = cyScreen - cyChild;
00090     }
00091
00092     // Set it, and return
00093     return SetWindowPos(hwndChild,
00094                         NULL,
00095                         xNew, yNew,
00096                         0, 0,
00097                         SWP_NOSIZE | SWP_NOZORDER);
00098 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BPOINTER/READDATA.C Source File

  • BPOINTER

READDATA.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     readdata.C
00015 *  Part of:     BPointer sample application
00016 *
00017 \******************************************************************************/
00018 #include <windows.h>
00019 #include <stdio.h>
00020 #include "shrstuff.h"
00021
00022
00023 int main(void)
00024 {   HANDLE hFileMapping;
00025     DWORD dwVersion;
00026     char cInput;
00027
00028 // check if running on Win32s, if so, display notice and terminate
00029
00030     dwVersion = GetVersion();
00031     if( !(dwVersion < 0x80000000 ) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00032     {
00033         MessageBox(NULL,
00034             "This sample application cannot be run on Windows 3.1.\n"
00035             "This application will now terminate.",
00036             "ReadData",
00037             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00038         return( 1 );
00039     }
00040
00041 // Set up the shared memory.
00042 // In this process, the mapped file must already exist.
00043
00044     hFileMapping = OpenFileMapping( FILE_MAP_READ, FALSE, "FM_DemoMapObject");
00045
00046     if (!hFileMapping)
00047     {   printf("Error %d: OpenFileMapping failed.  ", GetLastError());
00048         printf("Make sure ChgData is running first.\n");
00049         return(0);
00050     }
00051
00052 // MapViewOfFile is used here to get the file mapping mapped into
00053 // this processe's address space.  There is no guarantee about which address
00054 // will be chosen for this process.  The address used by another
00055 // process could be different.  That is why we need based pointers.
00056 // The pointers in this process are based on whatever address is used
00057 // by this process. For another process, the pointers will be based on some
00058 // other address.
00059
00060     clBasePt = (CHAINLIST *)MapViewOfFile(hFileMapping,
00061                                           FILE_MAP_READ,
00062                                           0,0,
00063                                           0);
00064
00065
00066     if (clBasePt == NULL)
00067     {   printf("Error in MapViewOfFile: %d",GetLastError());
00068         CloseHandle(hFileMapping);
00069         return(0);
00070     }
00071
00072 // This loop continuously traverses the linked list, dereferencing the
00073 // link pointers through the base implicitly.
00074
00075     printf("Press q to quit, or <enter> to display list: ");
00076     scanf("%c",&cInput);
00077     while (cInput != 'q')
00078     {
00079         clRunning = 0;
00080         printf("Address of file mapping in this process: 0x%08x\n",(int)clBasePt);
00081         while (clRunning->clNext != 0)
00082         {
00083             printf ("Next Element in chain: %d\n",clRunning->iElement);
00084             clRunning = clRunning->clNext;
00085         }
00086
00087         printf("Press q to quit, anything else to continue: ");
00088         scanf("%c",&cInput);
00089     }
00090
00091 // user didn't want any more dumps, so clean up.
00092
00093     UnmapViewOfFile(clBasePt);
00094     CloseHandle(hFileMapping);
00095     return(0);
00096 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/ABOUT.C Source File

  • NETDDE

ABOUT.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   about.c
00009 //
00010 //  PURPOSE:   Displays the "About" dialog box
00011 //
00012 //  FUNCTIONS:
00013 //    CmdAbout        - Displays the "About" dialog box
00014 //    About           - Processes messages for "About" dialog box.
00015 //    MsgAboutInit    - To initialize the about box with version info
00016 //                      from resources.
00017 //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
00018 //    CmdAboutDone    - Free the about box and related data.
00019 //
00020 //  COMMENTS:
00021 //
00022 //
00023
00024 #include <windows.h>            // required for all Windows applications
00025 #include <windowsx.h>
00026
00027 #ifdef WIN16
00028 #include "win16ext.h"           // required only for win16 applications
00029 #endif
00030 #include "globals.h"            // prototypes specific to this application
00031
00032
00033 #ifdef WIN16
00034 // Dialog box procedures must be exported in 16-bit applications for Windows.
00035 LRESULT CALLBACK __export About(HWND, UINT, WPARAM, LPARAM);
00036 #else
00037 LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
00038 #endif
00039
00040 LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
00041 LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
00042 LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
00043
00044 // About dialog message table definition.
00045 MSD rgmsdAbout[] =
00046 {
00047     {WM_COMMAND,    MsgAboutCommand},
00048     {WM_INITDIALOG, MsgAboutInit}
00049 };
00050
00051 MSDI msdiAbout =
00052 {
00053     sizeof(rgmsdAbout) / sizeof(MSD),
00054     rgmsdAbout,
00055     edwpNone
00056 };
00057
00058 // About dialog command table definition.
00059 CMD rgcmdAbout[] =
00060 {
00061     {IDOK,     CmdAboutDone},
00062     {IDCANCEL, CmdAboutDone}
00063 };
00064
00065 CMDI cmdiAbout =
00066 {
00067     sizeof(rgcmdAbout) / sizeof(CMD),
00068     rgcmdAbout,
00069     edwpNone
00070 };
00071
00072 // Module specific "globals"  Used when a variable needs to be
00073 // accessed in more than on handler function.
00074
00075 HFONT hFontCopyright;
00076
00077 //
00078 //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
00079 //
00080 //  PURPOSE: Displays the "About" dialog box
00081 //
00082 //  PARAMETERS:
00083 //    hwnd      - Window handle
00084 //    wCommand  - IDM_ABOUT (unused)
00085 //    wNotify   - Notification number (unused)
00086 //    hwndCtrl  - NULL (unused)
00087 //
00088 //  RETURN VALUE:
00089 //
00090 //    Always returns 0 - Message handled
00091 //
00092 //  COMMENTS:
00093 //    To process the IDM_ABOUT message, call DialogBox() to display the
00094 //    about dialog box.
00095
00096 LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00097 {
00098     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
00099     return 0;
00100 }
00101
00102
00103 //
00104 //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
00105 //
00106 //  PURPOSE:  Processes messages for "About" dialog box.
00107 //
00108 //  PARAMETERS:
00109 //    hdlg - window handle of the dialog box
00110 //    wMessage - type of message
00111 //    wparam - message-specific information
00112 //    lparam - message-specific information
00113 //
00114 //  RETURN VALUE:
00115 //    TRUE - message handled
00116 //    FALSE - message not handled
00117 //
00118 //  COMMENTS:
00119 //
00120 //     Display version information from the version section of the
00121 //     application resource.
00122 //
00123 //     Wait for user to click on "Ok" button, then close the dialog box.
00124 //
00125
00126 LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00127 {
00128     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
00129 }
00130
00131
00132 //
00133 //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
00134 //
00135 //  PURPOSE: To initialize the about box with version info from resources.
00136 //
00137 //  PARAMETERS:
00138 //    hwnd - The window handing the message.
00139 //    uMessage - The message number. (unused).
00140 //    wparam - Message specific data (unused).
00141 //    lparam - Message specific data (unused).
00142 //
00143 //  RETURN VALUE:
00144 //    Always returns 0 - message handled.
00145 //
00146 //  COMMENTS:
00147 //    Uses the version apis to retrieve version information for
00148 //    each of the static text boxes in the about box.
00149 //
00150
00151 LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
00152 {
00153     #define POINTSIZE 8
00154
00155     char  szFullPath[256];
00156     DWORD dwVerHnd;
00157     DWORD dwVerInfoSize;
00158     HDC   hDC;
00159     int   iLogPixelsY, iPointSize;
00160
00161     // Center the dialog over the application window
00162     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
00163
00164     // Set the copyright font to something smaller than default
00165     hDC = GetDC(hdlg);
00166     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
00167     ReleaseDC(hdlg, hDC);
00168     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
00169     iPointSize *= -1;
00170
00171     hFontCopyright = CreateFont(iPointSize,
00172                                 0, 0, 0,
00173                                 FW_BOLD,
00174                                 0, 0, 0, 0,
00175                                 0, 0, 0, 0,
00176                                 "Arial");
00177
00178     SendDlgItemMessage(hdlg,
00179                        IDD_VERLAST,
00180                        WM_SETFONT,
00181                        (WPARAM)hFontCopyright,
00182                        0L);
00183
00184     // Get version information from the application
00185     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
00186     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
00187     if (dwVerInfoSize)
00188     {
00189         // If we were able to get the information, process it:
00190         HANDLE  hMem;
00191         LPVOID  lpvMem;
00192         char    szGetName[256];
00193         int     cchRoot;
00194         int     i;
00195
00196         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
00197         lpvMem = GlobalLock(hMem);
00198         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
00199         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
00200         cchRoot = lstrlen(szGetName);
00201
00202         // Walk through the dialog items that we want to replace:
00203         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
00204         {
00205             BOOL  fRet;
00206             UINT  cchVer = 0;
00207             LPSTR lszVer = NULL;
00208             char  szResult[256];
00209
00210             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
00211             lstrcpy(&szGetName[cchRoot], szResult);
00212             fRet = VerQueryValue(lpvMem, szGetName, &lszVer, &cchVer);
00213
00214             if (fRet && cchVer && lszVer)
00215             {
00216                 // Replace dialog item text with version info
00217                 lstrcpy(szResult, lszVer);
00218                 SetDlgItemText(hdlg, i, szResult);
00219             }
00220         }
00221         GlobalUnlock(hMem);
00222         GlobalFree(hMem);
00223     }
00224     return TRUE;
00225 }
00226
00227 //
00228 //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
00229 //
00230 //  PURPOSE: Process WM_COMMAND message sent to the about box.
00231 //
00232 //  PARAMETERS:
00233 //    hwnd - The window handing the message.
00234 //    uMessage - The message number. (unused).
00235 //    wparam - Message specific data (unused).
00236 //    lparam - Message specific data (unused).
00237 //
00238 //  RETURN VALUE:
00239 //    Always returns 0 - message handled.
00240 //
00241 //  COMMENTS:
00242 //    Uses this DispCommand function defined in wndproc.c combined
00243 //    with the cmdiAbout structure defined in this file to handle
00244 //    the command messages for the about dialog box.
00245 //
00246
00247 LRESULT MsgAboutCommand(HWND   hwnd,
00248                         UINT   uMessage,
00249                         WPARAM wparam,
00250                         LPARAM lparam)
00251 {
00252     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
00253 }
00254
00255 //
00256 //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
00257 //
00258 //  PURPOSE: Free the about box and related data.
00259 //
00260 //  PARAMETERS:
00261 //    hwnd - The window handling the command.
00262 //    wCommand - The command to be handled (unused).
00263 //    wNotify   - Notification number (unused)
00264 //    hwndCtrl - NULL (unused).
00265 //
00266 //  RETURN VALUE:
00267 //    Always returns TRUE.
00268 //
00269 //  COMMENTS:
00270 //    Calls EndDialog to finish the dialog session.
00271 //
00272
00273 LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00274 {
00275     if (hFontCopyright)
00276        DeleteObject(hFontCopyright);
00277
00278     EndDialog(hdlg, TRUE);          // Exit the dialog
00279     return TRUE;
00280 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SETINFO/SETINFO.H Source File

  • SETINFO

SETINFO.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDE_API                     101
00013 #define IDE_RETSTAT                 102
00014 #define IDB_STEP                    103
00015 #define IDE_TIME                    104
00016
00017 #define DIALOGHEIGHT                80
00018
00019 #define WM_REPSTAT                  WM_USER+1
00020
00021
00022 #define IDE_FILENAME                101
00023 #define IDB_OPENFILE                102
00024 #define IDE_MONTH                   103
00025 #define IDE_DAY                     104
00026 #define IDE_YEAR                    105
00027 #define IDE_HOURS                   201
00028 #define IDE_MINUTES                 202
00029 #define IDE_SECONDS                 203
00030 #define IDB_SET                     204
00031 #define IDE_SIZE                    205
00032 #define IDC_HIDE                    206
00033 #define IDC_SYSTEM                  207
00034 #define IDC_ARC                     208
00035 #define IDC_READ                    209
00036 #define IDC_NORMAL                  210
00037 #define IDB_ATTR                    222
00038
00039
00040 #define YRMASK        0xFE00
00041 #define YRSHIFT       9
00042
00043 #define MONMASK       0x01E0
00044 #define MONSHIFT      5
00045
00046 #define DAYMASK       0x001F
00047 #define DAYSHIFT      0
00048
00049 #define HRMASK        0xF800
00050 #define HRSHIFT       11
00051 #define MINMASK       0x07E0
00052 #define MINSHIFT      5
00053 #define SECMASK       0x001F
00054 #define SECSHIFT      0
00055
00056 LONG APIENTRY MainWndProc (HWND, UINT, UINT, LONG);
00057 LONG APIENTRY FileDlgProc (HWND, UINT, UINT, LONG);
00058 LONG APIENTRY StatusDlgProc (HWND, UINT, UINT, LONG);
00059 BOOL RepStat (CHAR *, DWORD);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/CONNECT.H Source File

  • NETDDE

CONNECT.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   connect.h
00009 //
00010 //  PURPOSE:  contains ConnectDlg declarations
00011 //
00012
00013 #ifndef _CONNECT_H
00014 #define _CONNECT_H
00015
00016 //-------------------------------------------------------------------------
00017 //  Simple connection dialog defines.
00018
00019 #define IDE_SERVERNAME 100
00020
00021 #ifdef WIN16
00022 // Dialog box procedures must be exported in 16-bit applications for Windows.
00023 LRESULT CALLBACK __export ConnectDlg(HWND, UINT, WPARAM, LPARAM);
00024 #else
00025 LRESULT CALLBACK ConnectDlg(HWND, UINT, WPARAM, LPARAM);
00026 #endif
00027
00028 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TIMERS/TIMERS.C Source File

  • TIMERS

TIMERS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *  PROGRAM:     TIMERS.C
00015 *
00016 *  PURPOSE:     To demonstrate the use of APIs SetTimer() and KillTimer().
00017 *
00018 *  FUNCTIONS:   WinMain               - standard WinMain()
00019 *               MainWndProc           - main window procedure
00020 *               TimerFunc             - handles timer messages
00021 *               SetButtonPositions    - sizes buttons to client area
00022 *               SetFlashRectPositions - sizes flashing rectangles to
00023 *                                         client area
00024 *               DrawStuff()             - draws separator, headers,
00025 *                                         rectangles
00026 *
00027 *  COMMENTS:    When a timer is started it's corresponding rectangle (in
00028 *               the client area) is inverted each time a WM_TIMER is
00029 *               received or each timer the TimerFunc() is called.
00030 *
00031 \******************************************************************************/
00032
00033 #include <windows.h>
00034 #include <string.h>
00035 #include "timers.h"
00036
00037
00038
00039 /******************************************************************************\
00040 *
00041 *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
00042 *
00043 *  GLOBAL VARS: ghInst - handle of program instance
00044 *
00045 *  LOCAL VARS:  hwnd - handle of the main standard window
00046 *               msg  - msg to get/dispatch
00047 *
00048 \******************************************************************************/
00049
00050 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00051                     LPSTR lpCmdLine, int nCmdShow) {
00052   HWND hwnd;
00053   MSG msg;
00054
00055   if (!hPrevInstance)
00056   {
00057     WNDCLASS wc;
00058
00059     wc.style         = CS_HREDRAW | CS_VREDRAW;
00060     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00061     wc.cbClsExtra    = 0;
00062     wc.cbWndExtra    = 0;
00063     wc.hInstance     = hInstance;
00064     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
00065     wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
00066     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00067     wc.lpszMenuName  = (LPCTSTR) NULL;
00068     wc.lpszClassName = (LPCTSTR) "TIMERS";
00069
00070     if (!RegisterClass (&wc))
00071     {
00072       MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed",
00073                   (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
00074       return(FALSE);
00075     }
00076   }
00077
00078   ghInst = hInstance;
00079   if (!(hwnd = CreateWindow ("TIMERS", "TIMERS Sample Application",
00080                              WS_OVERLAPPEDWINDOW,
00081                              CW_USEDEFAULT, CW_USEDEFAULT,
00082                              CW_USEDEFAULT, CW_USEDEFAULT,
00083                              NULL, NULL, ghInst, NULL)))
00084     return (0);
00085
00086   ShowWindow (hwnd, nCmdShow);
00087
00088   while (GetMessage (&msg, NULL, 0,0))
00089   {
00090     TranslateMessage (&msg);
00091     DispatchMessage  (&msg);
00092   }
00093   return (msg.wParam);
00094   UNREFERENCED_PARAMETER(lpCmdLine);
00095 }
00096
00097
00098
00099 /******************************************************************************\
00100 *
00101 *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
00102 *
00103 *  GLOBAL VARS: ghInst       - handle of program instance
00104 *               gahwndButtons - array of button window handles
00105 *               gaFlashRects  - array of flashing rectangles coordinates
00106 *
00107 \******************************************************************************/
00108
00109 LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam,
00110                               LPARAM lParam)
00111 {
00112   switch (message)
00113   {
00114     case WM_CREATE:
00115     {
00116       LONG i;
00117
00118       //
00119       // Create the buttons to turn timer on/off
00120       //
00121
00122       for (i= ID_TIMER1; i <= ID_TIMER4; i++)
00123       {
00124         gahwndButtons[i] = CreateWindow ("button", "Start timer",
00125                                        WS_CHILD | BS_PUSHBUTTON,
00126                                        0, 0, 0, 0, hwnd, NULL,
00127                                        ghInst, NULL);
00128         SetWindowLong (gahwndButtons[i], GWL_ID, i);
00129       }
00130
00131       //
00132       // Have TIMER1 started initially (giving the user a clue what to do)
00133       //
00134
00135       PostMessage (hwnd, WM_COMMAND, (DWORD) ID_TIMER1,
00136                    (LONG) gahwndButtons[ID_TIMER1]);
00137       break;
00138     }
00139
00140     case WM_COMMAND:
00141     {
00142       char buf[BUFSIZE];
00143       WORD id;
00144
00145       id = LOWORD (wParam);
00146       GetWindowText ((HWND) lParam, buf, BUFSIZE);
00147       if (!strcmp (buf, "Start timer"))
00148       {
00149         //
00150         // Set button text to "Stop timer" and start the timer. For
00151         //   timers 1&2 we'll specify a WNDPROC ("TimerFunc") which will
00152         //   get called for each timer tick. For timers 3&4 we'll just
00153         //   have WM_TIMER messages sent to this window procedure.
00154         //
00155
00156         SetWindowText ((HWND) lParam, (LPTSTR) "Stop timer");
00157         if (id < ID_TIMER3)
00158         {
00159           if (SetTimer (hwnd, (UINT) id, (UINT) (id * TIMERINTERVAL),
00160                         (TIMERPROC) TimerFunc) == 0)
00161
00162             MessageBox (NULL, (LPCTSTR) "MainWndProc(): SetTimer() failed",
00163                         (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
00164         }
00165         else
00166         {
00167           if (SetTimer (hwnd, (UINT) id, (UINT) (id * TIMERINTERVAL),
00168                         NULL) == 0)
00169
00170             MessageBox (NULL, (LPCTSTR) "MainWndProc(): SetTimer() failed",
00171                         (LPCTSTR) "Err! - TIMERS", MB_OK | MB_ICONEXCLAMATION);
00172         }
00173       }
00174       else
00175       {
00176         SetWindowText ((HWND) lParam, (LPTSTR) "Start timer");
00177         KillTimer (hwnd, (UINT) id);
00178       }
00179       break;
00180     }
00181
00182     case WM_TIMER:
00183     {
00184       //
00185       // Invert the gaFlashRect associated with this timer event
00186       //
00187
00188       HDC hdc = GetDC (hwnd);
00189
00190       InvertRect (hdc, &gaFlashRects[wParam]); // wParam = timerId
00191       ReleaseDC  (hwnd, hdc);
00192       break;
00193     }
00194
00195     case WM_SIZE:
00196     {
00197       int width  = (int) LOWORD(lParam);
00198       int height = (int) HIWORD(lParam);
00199
00200       //
00201       // User resized the window, so reposition button & flashing rects
00202       //
00203
00204       SetButtonPositions (width, height);
00205       SetFlashRectPositions (width, height);
00206       break;
00207     }
00208
00209     case WM_PAINT:
00210     {
00211       PAINTSTRUCT ps;
00212
00213       BeginPaint (hwnd, &ps);
00214       DrawStuff (hwnd, ps.hdc);
00215       EndPaint (hwnd, &ps);
00216       break;
00217     }
00218
00219     case WM_DESTROY:
00220
00221       PostQuitMessage(0);
00222       break;
00223
00224     default:
00225
00226       return (DefWindowProc(hwnd, message, wParam, lParam));
00227   }
00228   return (0);
00229 }
00230
00231
00232
00233 /******************************************************************************\
00234 *
00235 *  FUNCTION:    TimerFunc
00236 *
00237 *  INPUTS:      hwnd     - window associated with timer
00238 *               uMsg     - WM_TIMER message
00239 *               idEvent  - timer's ID
00240 *               dwTime   - current system time
00241 *
00242 *  RETURNS:     0
00243 *
00244 *  GLOBAL VARS: gaFlashRects - array of flashing rectangles coordinates
00245 *
00246 *  LOCAL VARS:  hdc - device context of main window
00247 *
00248 *  COMMENTS:    Inverts the gaFlashRect corresponding to idEvent
00249 *
00250 \******************************************************************************/
00251
00252 void CALLBACK TimerFunc (HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
00253 {
00254   HDC hdc = GetDC (hwnd);
00255
00256   InvertRect (hdc, &gaFlashRects[idEvent]);
00257   ReleaseDC  (hwnd, hdc);
00258 }
00259
00260
00261
00262 /******************************************************************************\
00263 *
00264 *  FUNCTION:    SetButtonPositions
00265 *
00266 *  INPUTS:      cx - new width of main window
00267 *               cy - new height of main window
00268 *
00269 *  GLOBAL VARS: gahwndButtons - array of button HWNDs (unmodified)
00270 *
00271 *  COMMENTS:    Repositions buttons according to new window size (cx,cy)
00272 *
00273 \******************************************************************************/
00274
00275 void SetButtonPositions (int cx, int cy)
00276 {
00277   SetWindowPos (gahwndButtons[ID_TIMER1], NULL,     // upper-left button
00278                 BUTTONBORDER,
00279                 cy/2 - BUTTONBORDER - BUTTONHEIGHT,
00280                 cx/2 - 2*BUTTONBORDER,
00281                 BUTTONHEIGHT,
00282                 SWP_SHOWWINDOW);
00283
00284   SetWindowPos (gahwndButtons[ID_TIMER2], NULL,     // upper-right button
00285                 cx/2 + BUTTONBORDER,
00286                 cy/2 - BUTTONBORDER - BUTTONHEIGHT,
00287                 cx/2 - 2*BUTTONBORDER,
00288                 BUTTONHEIGHT,
00289                 SWP_SHOWWINDOW);
00290
00291   SetWindowPos (gahwndButtons[ID_TIMER3], NULL,     // lower-left button
00292                 BUTTONBORDER,
00293                 cy - BUTTONBORDER - BUTTONHEIGHT,
00294                 cx/2 - 2*BUTTONBORDER,
00295                 BUTTONHEIGHT,
00296                 SWP_SHOWWINDOW);
00297
00298   SetWindowPos (gahwndButtons[ID_TIMER4], NULL,     // lower-right button
00299                 cx/2 + BUTTONBORDER,
00300                 cy - BUTTONBORDER - BUTTONHEIGHT,
00301                 cx/2 - 2*BUTTONBORDER,
00302                 BUTTONHEIGHT,
00303                 SWP_SHOWWINDOW);
00304 }
00305
00306
00307
00308 /******************************************************************************\
00309 *
00310 *  FUNCTION:    SetgaFlashRectPositions
00311 *
00312 *  INPUTS:      cx - new width of main window
00313 *               cy - new height of main window
00314 *
00315 *  GLOBAL VARS: gaFlashRects - array of flashing rectangles coordinates
00316 *                            (modified)
00317 *
00318 *  COMMENTS:    Repositions flashing rectangles according to new window
00319 *               size (cx,cy)
00320 *
00321 \******************************************************************************/
00322
00323 void SetFlashRectPositions (LONG cx, LONG cy)
00324 {                                                 /* upper-left rect  */
00325   gaFlashRects[ID_TIMER1].left   = BUTTONBORDER;
00326   gaFlashRects[ID_TIMER1].top    = 3*TEXTHEIGHT + BUTTONBORDER;
00327   gaFlashRects[ID_TIMER1].right  = cx/2 - BUTTONBORDER;
00328   gaFlashRects[ID_TIMER1].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;
00329
00330                                                   /* upper-right rect */
00331   gaFlashRects[ID_TIMER2].left   = cx/2 + BUTTONBORDER;
00332   gaFlashRects[ID_TIMER2].top    = 3*TEXTHEIGHT + BUTTONBORDER;
00333   gaFlashRects[ID_TIMER2].right  = cx - BUTTONBORDER;
00334   gaFlashRects[ID_TIMER2].bottom = cy/2 - BUTTONHEIGHT - 2*BUTTONBORDER;
00335
00336                                                   /* lower-left rect  */
00337   gaFlashRects[ID_TIMER3].left   = BUTTONBORDER;
00338   gaFlashRects[ID_TIMER3].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
00339   gaFlashRects[ID_TIMER3].right  = cx/2 - BUTTONBORDER;
00340   gaFlashRects[ID_TIMER3].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;
00341
00342                                                   /* lower-right rect */
00343   gaFlashRects[ID_TIMER4].left   = cx/2 + BUTTONBORDER;
00344   gaFlashRects[ID_TIMER4].top    = cy/2 + 3*TEXTHEIGHT + BUTTONBORDER;
00345   gaFlashRects[ID_TIMER4].right  = cx - BUTTONBORDER;
00346   gaFlashRects[ID_TIMER4].bottom = cy - BUTTONHEIGHT - 2*BUTTONBORDER;
00347 }
00348
00349
00350
00351 /******************************************************************************\
00352 *
00353 *  FUNCTION:    DrawStuff
00354 *
00355 *  INPUTS:      hwnd - main window handle
00356 *               hdc  - DC for main window
00357 *
00358 *  GLOBAL VARS: gaFlashRects - array of flashing rectangles coordinates
00359 *                            (not modified)
00360 *
00361 *  LOCAL VARS:  rect - client rectangle
00362 *               hbr  - temporary brush handle
00363 *
00364 *  COMMENTS:    Draws separators, "Timer #" headers, & rectangles
00365 *
00366 \******************************************************************************/
00367
00368 void DrawStuff (HWND hwnd, HDC hdc)
00369 {
00370   RECT   rect;
00371   HBRUSH hbr;
00372
00373   //
00374   // Draw the separator lines between the timer info "windows"
00375   //
00376
00377   GetClientRect (hwnd, &rect);
00378   MoveToEx (hdc, rect.right/2, 0, NULL);
00379   LineTo (hdc, rect.right/2, rect.bottom);
00380
00381   MoveToEx (hdc, 0, rect.bottom/2, NULL);
00382   LineTo (hdc, rect.right, rect.bottom/2);
00383
00384   //
00385   // Draw the "Timer #" headers
00386   //
00387
00388   TextOut (hdc, BUTTONBORDER, TEXTHEIGHT, "Timer 1:", 8);
00389   TextOut (hdc, rect.right/2 + BUTTONBORDER, TEXTHEIGHT, "Timer 2:", 8);
00390   TextOut (hdc, BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT, "Timer 3:", 8);
00391   TextOut (hdc, rect.right/2 + BUTTONBORDER, rect.bottom/2 + TEXTHEIGHT,
00392            "Timer 4:", 8);
00393
00394   //
00395   // Draw the rectangles to flash on timer messages
00396   //
00397
00398   hbr = CreateSolidBrush (0x0000ff);
00399   FillRect (hdc, &gaFlashRects[ID_TIMER1], hbr);
00400   DeleteObject (hbr);
00401   hbr = CreateSolidBrush (0x00ff00);
00402   FillRect (hdc, &gaFlashRects[ID_TIMER2], hbr);
00403   DeleteObject (hbr);
00404   hbr = CreateSolidBrush (0xff0000);
00405   FillRect (hdc, &gaFlashRects[ID_TIMER3], hbr);
00406   DeleteObject (hbr);
00407   hbr = CreateSolidBrush (0x2266aa);
00408   FillRect (hdc, &gaFlashRects[ID_TIMER4], hbr);
00409   DeleteObject (hbr);
00410 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMUTIL.C Source File

  • SERVENUM
  • DLL

ENUMUTIL.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumutil.c
00009 //
00010 //  PURPOSE:   Various utility functions used by the enumdlg dialogbox
00011 //
00012 //  FUNCTIONS:
00013 //    FreeEnumSync - frees ENUMSYNC object
00014 //    FreeEnumChild - recusively frees children of an ENUMNODE
00015 //    CompareEnumNode - compares lpRemoteNames of ENUMNODEs
00016 //    EnumListRecurse - Recursively adds ENUMNODE entries to listbox
00017 //    EnumListExpand - Creates a Thread to enumerate an ENUMNODEs children
00018 //    EnumListCollapse - Removes ENUMNODE children from listbox
00019 //    LoadBitmapArray - loads bitmaps used by owner draw listbox
00020 //
00021 //
00022 //  AUTHOR: Craig Link - Microsoft Developer Support
00023 //
00024
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <windows.h>
00028 #include <tchar.h>
00029 #include <lm.h>
00030 #include "enumutil.h"
00031 #include "enumthrd.h"
00032 #include "thrdutil.h"
00033 #include "miscutil.h"
00034 #include "mem.h"
00035
00036 extern HMODULE g_hMod;
00037
00038 //
00039 //  FUNCTION: FreeEnumSync( LPENUMSYNC * lplpSync )
00040 //
00041 //  PURPOSE:  Decrements usage count and frees ENUMSYNC object
00042 //
00043 //  PARAMETERS:
00044 //    lplpSync - address of pointer to ENUMSYNC object
00045 //
00046 //  RETURN VALUE:
00047 //    none
00048 //
00049 //  COMMENTS:
00050 //    Before the create of any enumeration threads, cThread should
00051 //    be incremented.  Before the thread returns, it should call
00052 //    FreeEnumSync to reduce the usage count
00053 //
00054 VOID FreeEnumSync( LPENUMSYNC * lplpSync )
00055 {
00056     // if usage count is 0 than free object
00057     if ( InterlockedDecrement( &((LONG)(*lplpSync)->cThread) ) == 0 )
00058     {
00059         DeleteCriticalSection( &((*lplpSync)->cs) );
00060
00061         if ( (*lplpSync)->lpRoot )
00062         {
00063             // this frees lpObject->lpNode as well
00064             FreeEnumChild( (*lplpSync)->lpRoot );
00065             FreeMem( &((*lplpSync)->lpRoot) );
00066         }
00067
00068         if ( (*lplpSync)->cNetBuf )
00069         {
00070             while( (*lplpSync)->cNetBuf-- )
00071                 FreeMem( (LPVOID *) ((*lplpSync)->lplpnetBuf + (*lplpSync)->cNetBuf) );
00072
00073             FreeMem( (LPVOID *) &((*lplpSync)->lplpnetBuf) );
00074         }
00075
00076         FreeMem( (LPVOID *) lplpSync );
00077     }
00078 }
00079
00080
00081 //
00082 //  FUNCTION: FreeEnumChild( LPENUMNODE lpNode )
00083 //
00084 //  PURPOSE:  Frees all child nodes and the buffer containing their pointers
00085 //
00086 //  PARAMETERS:
00087 //    lpNode - address of pointer to ENUMNODE object
00088 //
00089 //  RETURN VALUE:
00090 //    none
00091 //
00092 //  COMMENTS:
00093 //
00094 VOID FreeEnumChild( LPENUMNODE lpNode )
00095 {
00096     if ( lpNode->cChild )
00097     {
00098         while( lpNode->cChild-- )
00099             FreeEnumChild( lpNode->lpChild + lpNode->cChild );
00100
00101     FreeMem( (LPVOID *) &(lpNode->lpChild) );
00102     }
00103 }
00104
00105
00106 //
00107 //  FUNCTION: CompareEnumNode( const void *lpNode1, const void *lpNode2 )
00108 //
00109 //  PURPOSE:  Compares the lpRemoteName strings of the ENUMNODE objects
00110 //
00111 //  PARAMETERS:
00112 //    lpNode1 - pointer to an ENUMNODE object
00113 //    lpNode2 - pointer to an ENUMNODE object
00114 //
00115 //  RETURN VALUE:
00116 //    value < 0    lpNode1 proceeds lpNode2
00117 //    value = 0    lpNode1 is identicall to lpNode2
00118 //    value > 0    lpNode2 proceeds lpNode1
00119 //
00120 //  COMMENTS:
00121 //    This is used by the call to QSORT
00122 //
00123 int __cdecl CompareEnumNode( const void *lpNode1, const void *lpNode2 )
00124 {
00125     return _tcsicmp( ((LPENUMNODE)lpNode1)->lpNet->lpRemoteName,
00126                      ((LPENUMNODE)lpNode2)->lpNet->lpRemoteName );
00127 }
00128
00129
00130 //
00131 //  FUNCTION: EnumListRecurse( HWND hwnd, LPENUMNODE lpNode, LPTSTR lpServer )
00132 //
00133 //  PURPOSE:  Recursively add the ENUMNODE tree structure to a listbox
00134 //
00135 //  PARAMETERS:
00136 //    hwnd - handle to listbox
00137 //    lpNode - pointer to node from which to being recursion
00138 //    lpServer - server name to match
00139 //
00140 //  RETURN VALUE:
00141 //    listbox index of entry matching lpServer, otherwise 0
00142 //
00143 //  COMMENTS:
00144 //
00145 UINT EnumListRecurse( HWND hwnd, LPENUMNODE lpNode, LPTSTR lpServer )
00146 {
00147     UINT ndx;
00148     UINT ndxTemp;
00149     UINT ndxComputer = 0;
00150
00151     for ( ndx = 0; ndx < lpNode->cChild; ndx++ )
00152     {
00153         switch( lpNode->lpChild[ndx].lpNet->dwDisplayType )
00154         {
00155             case RESOURCEDISPLAYTYPE_GENERIC:  // network provider
00156                 if ( lpNode->lpChild[ndx].cChild != 0 )
00157                     lpNode->lpChild[ndx].ndxBmp = PROVEX_NDX;
00158                 else
00159                     lpNode->lpChild[ndx].ndxBmp = PROV_NDX;
00160
00161                 SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
00162                 if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
00163                     ndxComputer = ndxTemp;
00164                 break;
00165
00166             case RESOURCEDISPLAYTYPE_DOMAIN:  // domain
00167                 if ( lpNode->lpChild[ndx].cChild != 0 )
00168                     lpNode->lpChild[ndx].ndxBmp = DOMEX_NDX;
00169                 else
00170                     lpNode->lpChild[ndx].ndxBmp = DOM_NDX;
00171
00172                 SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
00173                 if ( (ndxTemp = EnumListRecurse( hwnd, &(lpNode->lpChild[ndx]), lpServer ) ) != 0 )
00174                     ndxComputer = ndxTemp;
00175                 break;
00176
00177             case RESOURCEDISPLAYTYPE_SERVER:  // server
00178                 lpNode->lpChild[ndx].ndxBmp = SERV_NDX;
00179                 ndxTemp = SendMessage( hwnd, LB_ADDSTRING, 0L, (LPARAM) &(lpNode->lpChild[ndx]) );
00180                 if ( _tcscmp( lpNode->lpChild[ndx].lpNet->lpRemoteName, lpServer ) == 0 )
00181                     ndxComputer = ndxTemp;
00182                 break;
00183         }
00184
00185     }
00186
00187     return ndxComputer;
00188 }
00189
00190
00191 //
00192 //  FUNCTION: EnumListExpand( HWND hwnd, LPENUMSYNC lpSync, LPENUMNODE lpNode, UINT ndx )
00193 //
00194 //  PURPOSE:  CreateThread to expand the selected network object
00195 //            by one level
00196 //
00197 //  PARAMETERS:
00198 //    hwnd - handle to listbox
00199 //    lpSync - pointer to syncronization object
00200 //    lpNode - pointer to node fto expand
00201 //    ndx - index at which to insert entries in the listbox
00202 //
00203 //  RETURN VALUE:
00204 //    none
00205 //
00206 //  COMMENTS:
00207 //
00208 VOID EnumListExpand( HWND hwnd, LPENUMSYNC lpSync, LPENUMNODE lpNode, UINT ndx )
00209 {
00210     HANDLE hThread;
00211     DWORD  tID;
00212     LPENUMLISTOBJECT lpListObject;
00213
00214     if ( ERROR_SUCCESS == MallocMem( &lpListObject, sizeof( ENUMLISTOBJECT ) ) )
00215     {
00216         lpListObject->nItem = ndx;
00217         lpListObject->Object.lpSync = lpSync;
00218         lpListObject->Object.lpNode = lpNode;
00219
00220         InterlockedIncrement( &((LONG)lpSync->cThread) );
00221         if ( ( hThread = CreateThread(NULL, 100,
00222                                      (LPTHREAD_START_ROUTINE)EnumExpandThread,
00223                                      (LPVOID) lpListObject,
00224                                      0, &tID) ) == NULL )
00225         {
00226             FreeMem( &lpListObject );
00227             InterlockedDecrement( &((LONG)lpSync->cThread) );
00228         }
00229         else
00230         {
00231             MarkOutstanding( &hThread ); // add to list of outstanding threads
00232         }
00233     }
00234 }
00235
00236
00237 //
00238 //  FUNCTION: EnumListCollapse( HWND hwnd, LPENUMNODE lpNode, UINT ndx )
00239 //
00240 //  PURPOSE:  Collapses all children under selected network container
00241 //
00242 //  PARAMETERS:
00243 //    hwnd - handle to listbox
00244 //    lpNode - pointer to node fto expand
00245 //    ndx - index of node to collapse
00246 //
00247 //  RETURN VALUE:
00248 //    none
00249 //
00250 //  COMMENTS:
00251 //    This deletes strings until we encounter LB_ERR or
00252 //    encounter a ENUMNODE of the same level
00253 //
00254 VOID EnumListCollapse( HWND hwnd, LPENUMNODE lpNode, UINT ndx )
00255 {
00256     LPENUMNODE lpChild;
00257     SetCursor( LoadCursor( NULL, IDC_WAIT ) );
00258     SendMessage( hwnd, WM_SETREDRAW, FALSE, 0 );
00259
00260     while ( LB_ERR != SendMessage( hwnd, LB_GETTEXT, (WPARAM) ndx+1, (LPARAM) &lpChild) )
00261     {
00262         if ( lpNode->lpNet->dwDisplayType == lpChild->lpNet->dwDisplayType )
00263             break;
00264         else
00265             SendMessage( hwnd, LB_DELETESTRING, ndx+1, 0 );
00266     }
00267
00268     SendMessage( hwnd, WM_SETREDRAW, TRUE, 0 );
00269     SetCursor( LoadCursor( NULL, IDC_ARROW ) );
00270 }
00271
00272
00273 //
00274 //  FUNCTION: LoadBitmapArray( HBITMAP * lphbmpArray)
00275 //
00276 //  PURPOSE:  Loads owner draw bitmaps into an array
00277 //            creating highlighted and un hightlighted versions
00278 //
00279 //  PARAMETERS:
00280 //    lphbmpArray - array of HBITMAPs, 2*HIGHLIGHT_NDX in length
00281 //
00282 //  RETURN VALUE:
00283 //    none
00284 //
00285 //  COMMENTS:
00286 //
00287 VOID LoadBitmapArray( HBITMAP * lphbmpArray)
00288 {
00289     UINT ndxBmp;
00290
00291     for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
00292         lphbmpArray[ndxBmp] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor(COLOR_WINDOW) );
00293
00294     for ( ndxBmp = START_NDX; ndxBmp < HIGHLIGHT_NDX; ndxBmp++ )
00295         lphbmpArray[ndxBmp+HIGHLIGHT_NDX] = SetBitmapBkgnd( g_hMod, MAKEINTRESOURCE(ndxBmp+BITMAP_START), GetSysColor( COLOR_HIGHLIGHT ) );
00296 }
00297
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/DLLDISP.H Source File

  • SERVENUM
  • DLL

DLLDISP.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // PURPOSE:
00009 //    Contains declarations for message dispatching.
00010 //
00011
00012 #ifndef _DLLDISP_H
00013 #define _DLLDISP_H
00014
00015 // **TODO**  For NON-MDI applications uncomment line 1 below and comment
00016 //           line 2.  For MDI applications, uncomment line 2 below, comment
00017 //           line 1, and then define hwndMDIClient as a global variable in
00018 //           INIT.C
00019 #define hwndMDIClient NULL        /* (1) Stub for NON-MDI applications. */
00020 // extern HWND hwndMDIClient;     /* (2) For MDI applications.          */
00021
00022 //-------------------------------------------------------------------------
00023 // Message and command dispatch infrastructure.  The following type
00024 // definitions and functions are used by the message and command dispatching
00025 // mechanism and do not need to be changed.
00026
00027     // Function pointer prototype for message handling functions.
00028 typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);
00029
00030     // Function pointer prototype for command handling functions.
00031 typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);
00032
00033     // Enumerated type used to determine which default window procedure
00034     // should be called by the message- and command-dispatching mechanism
00035     // if a message or command is not handled explicitly.
00036 typedef enum
00037 {
00038    edwpNone,            // Do not call any default procedure.
00039    edwpWindow,          // Call DefWindowProc.
00040    edwpDialog,          // Call DefDlgProc (This should be used only for
00041                         // custom dialogs - standard dialog use edwpNone).
00042    edwpMDIChild,        // Call DefMDIChildProc.
00043    edwpMDIFrame         // Call DefFrameProc.
00044 } EDWP;                // Enumeration for Default Window Procedures
00045
00046     // This structure maps messages to message handling functions.
00047 typedef struct _MSD
00048 {
00049     UINT   uMessage;
00050     PFNMSG pfnmsg;
00051 } MSD;                 // MeSsage Dispatch structure
00052
00053     // This structure contains all of the information that a window
00054     // procedure passes to DispMessage in order to define the message
00055     // dispatching behavior for the window.
00056 typedef struct _MSDI
00057 {
00058     int  cmsd;          // Number of message dispatch structs in rgmsd
00059     MSD *rgmsd;         // Table of message dispatch structures
00060     EDWP edwp;          // Type of default window handler needed.
00061 } MSDI, FAR *LPMSDI;   // MeSsage Dipatch Information
00062
00063     // This structure maps command IDs to command handling functions.
00064 typedef struct _CMD
00065 {
00066     WORD   wCommand;
00067     PFNCMD pfncmd;
00068 } CMD;                 // CoMmand Dispatch structure
00069
00070     // This structure contains all of the information that a command
00071     // message procedure passes to DispCommand in order to define the
00072     // command dispatching behavior for the window.
00073 typedef struct _CMDI
00074 {
00075     int  ccmd;          // Number of command dispatch structs in rgcmd
00076     CMD *rgcmd;         // Table of command dispatch structures
00077     EDWP edwp;          // Type of default window handler needed.
00078 } CMDI, FAR *LPCMDI;   // CoMmand Dispatch Information
00079
00080     // Message and command dispatching functions.  They look up messages
00081     // and commands in the dispatch tables and call the appropriate handler
00082     // function.
00083 LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
00084 LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);
00085
00086 #endif
00087
00088
00089
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: RESDLL/MAIN.C Source File

  • RESDLL

MAIN.C

Go to the documentation of this file.
00001 /******************************************************************************\
00002 *
00003 *  PROGRAM:     MAIN.C
00004 *
00005 *  PURPOSE:     To test the resource-only DLL "THE_DLL.DLL".
00006 *
00007 *  FUNCTIONS:   WinMain()     - initialization, create window, msg loop
00008 *               MainWndProc() - processes main window msgs
00009 *               DrawBitmap()  - draw a specified bitmap in a specified DC
00010 *
00011 *  COMMENTS:    Loads the bitmap, the cursor, and the icon from
00012 *               THE_DLL.DLL. Uses the first two ni registering the
00013 *               app's window class. Uses the bitmap when painting
00014 *               the client area.
00015 *
00016 *
00017 *                           Microsoft Developer Support
00018 *                  Copyright (c) 1992-1996 Microsoft Corporation
00019 *
00020 \******************************************************************************/
00021
00022 #include <windows.h>
00023 #include "Main.h"
00024 #include "the_dll.h"
00025
00026
00027
00028 /******************************************************************************\
00029 *
00030 *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
00031 *
00032 *  GLOBAL VARS: ghLib - library instance handle
00033 *
00034 *  LOCAL VARS:  hwnd - handle of the main standard window
00035 *               msg  - msg to get/dispatch
00036 *
00037 \******************************************************************************/
00038
00039 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00040                     LPSTR lpCmdLine,  int nCmdShow)
00041 {
00042   HWND hwnd;
00043   MSG msg;
00044
00045
00046   if ((ghLib = LoadLibrary (TEXT("the_dll.dll"))) == NULL)
00047   {
00048     MessageBox (NULL, TEXT( "WinMain(): LoadLibrary() failed"),
00049                 TEXT( "Err! - RESDLL"), MB_OK | MB_ICONEXCLAMATION);
00050     return 0;
00051   }
00052
00053   if (!hPrevInstance)
00054   {
00055     WNDCLASS wc;
00056
00057     wc.style         = CS_HREDRAW | CS_VREDRAW;;
00058     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
00059     wc.cbClsExtra    = 0;
00060     wc.cbWndExtra    = 0;
00061     wc.hInstance     = hInstance;
00062     wc.hIcon         = LoadIcon (ghLib, TEXT("dllicon"));
00063     wc.hCursor       = LoadCursor (ghLib, TEXT("dllcursor"));
00064     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00065     wc.lpszMenuName  = NULL;
00066     wc.lpszClassName = TEXT( "RESDLL");
00067
00068     if (!RegisterClass (&wc))
00069     {
00070       MessageBox (NULL, TEXT( "WinMain(): RegisterClass() failed"),
00071                   TEXT( "Err! - MAIN"), MB_OK | MB_ICONEXCLAMATION);
00072       return(FALSE);
00073     }
00074   }
00075
00076   if (!(hwnd = CreateWindow (TEXT("RESDLL"), TEXT("RESDLL Sample Application"),
00077                              WS_OVERLAPPEDWINDOW,
00078                              CW_USEDEFAULT, CW_USEDEFAULT,
00079                              CW_USEDEFAULT, CW_USEDEFAULT,
00080                              NULL, NULL, hInstance, NULL)))
00081     return (0);
00082
00083   ShowWindow (hwnd, nCmdShow);
00084
00085   while (GetMessage (&msg, NULL, 0,0))
00086   {
00087     TranslateMessage (&msg);
00088     DispatchMessage  (&msg);
00089   }
00090   FreeLibrary (ghLib);
00091   return (msg.wParam);
00092 }
00093
00094
00095
00096 /******************************************************************************\
00097 *
00098 *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
00099 *
00100 *  GLOBAL VARS: ghLib - library instance handle
00101 *
00102 *  LOCAL VARS:  hbm - handle of bitmap in THE_DLL.DLL
00103 *
00104 \******************************************************************************/
00105
00106 LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam,
00107                               LPARAM lParam)
00108 {
00109   static HBITMAP hbm;
00110
00111   switch (message)
00112   {
00113     case WM_CREATE:
00114
00115       hbm = LoadBitmap (ghLib, TEXT( "dllbitmap"));
00116       break;
00117
00118     case WM_PAINT:
00119     {
00120       RECT        rect;
00121       PAINTSTRUCT ps;
00122
00123       GetClientRect (hwnd, &rect);
00124       BeginPaint (hwnd, &ps);
00125
00126       //
00127       // draw the dllbitmap centered in middle of our client rect
00128       //
00129
00130       DrawBitmap (ps.hdc, hbm,
00131                   rect.right/2 - DLLBITMAP_WIDTH/2,
00132                   rect.bottom/2 - DLLBITMAP_HEIGHT/2);
00133       EndPaint (hwnd, &ps);
00134       return 0;
00135     }
00136
00137     case WM_DESTROY:
00138
00139       DeleteObject ((HANDLE) hbm);
00140       PostQuitMessage (0);
00141       break;
00142
00143     default:
00144
00145       return (DefWindowProc(hwnd, message, wParam, lParam));
00146   }
00147   return (0);
00148 }
00149
00150
00151
00152 /******************************************************************************\
00153 *
00154 *  FUNCTION:    DrawBitmap
00155 *
00156 *  INPUTS:      hdc    - device context in which to draw bitmap
00157 *               hbm    - handle of bitmap to draw
00158 *               xStart - x-coordinate of upper-left corner of destination
00159 *                        rectangle
00160 *               yStart - y-coordinate of upper-left corner of destination
00161 *                        rectangle
00162 *
00163 *  LOCAL VARS:  bm     - BITMAP info of "hbm"
00164 *               hdcMem - a memory DC used for blt-ing
00165 *
00166 *  COMMENTS:    Draws a bitmap "hbm" in a DC "hdc" given the upper-left
00167 *               corner "xStart,yStart" of a destination rectangle.
00168 *
00169 \******************************************************************************/
00170
00171 void DrawBitmap (HDC hdc, HBITMAP hbm, int xStart, int yStart)
00172 {
00173   BITMAP bm;
00174   HDC    hdcMem;
00175
00176   hdcMem = CreateCompatibleDC (hdc);
00177   SelectObject (hdcMem, hbm);
00178   SetMapMode (hdcMem, GetMapMode(hdc));
00179
00180   GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm);
00181   BitBlt (hdc, xStart, yStart, bm.bmWidth, bm.bmHeight,
00182           hdcMem, 0, 0, SRCCOPY);
00183
00184   DeleteDC(hdcMem);
00185 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/UNIPUT.H Source File

  • UNIPUT

UNIPUT.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* uniput.h - header file */
00013
00014 /* function prototypes, window procedures first. */
00015 LRESULT CALLBACK MainWndProc    (HWND, UINT, WPARAM, LPARAM);
00016 LRESULT CALLBACK DisplayWndProc (HWND, UINT, WPARAM, LPARAM);
00017 LRESULT CALLBACK StatusWndProc (HWND, UINT, WPARAM, LPARAM);
00018 LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
00019
00020 int  openDisplay(VOID);
00021 int  closeDisplay(VOID);
00022
00023 /* Name of the display window window class */
00024 #define DISPLAYCLASS TEXT("DisplayClass")
00025
00026
00027 /* Define a value for the LOGFONT.lfCharSet
00028  *  This should be included in wingdi.h, but it
00029  *  was removed because the font mapper is not
00030  *  using it anyway in version 1.0.  Currently
00031  *  scheduled to be included in NT ver 1.1.
00032  */
00033 #define UNICODE_CHARSET  1
00034
00035
00036 /* menu IDs */
00037 #define  IDM_MDICASCADE     1001
00038 #define  IDM_MDITILE        1002
00039
00040 #define  IDM_SHOWHEX        2000
00041 #define  IDM_SHOWNAMES      2001
00042
00043 #define    IDM_CHARBASE     2400
00044 #define    IDM_CHAR10       2410
00045 #define    IDM_CHAR16       2416
00046 #define    IDM_CHAR20       2420
00047 #define    IDM_CHAR32       2432
00048 #define    IDM_CHAR40       2440
00049 #define    IDM_CHAR64       2464
00050
00051 #define    IDM_FONTBASE     2500
00052 #define    IDM_FONT18       2518
00053 #define    IDM_FONT36       2536
00054 #define    IDM_FONT72       2572
00055
00056
00057 #define  IDM_NEWWINDOW      3001
00058 #define  IDM_NEWFILE        3002
00059 #define  IDM_CLOSEFILE      3003
00060
00061 #define  IDM_HELP           4001
00062 #define  IDM_ABOUT          4002
00063
00064
00065 /* USER messages sent between windows. */
00066 #define  WMU_NEWRANGE       WM_USER+0x1001
00067 #define  WMU_NEWFONT        WM_USER+0x1002
00068 #define  WMU_SETTARGETNAME    WM_USER+0x1003
00069 #define  WMU_SETNCHAR       WM_USER+0x1004
00070 #define  WMU_CHARACTER      WM_USER+0x1005
00071
00072
00073 /* define strings and flags for use in warning message boxes */
00074 #define MBGETFONTDATAERR    TEXT("Not a scalable font.")
00075 #define MBERROR             TEXT("Application Error.")
00076 #define MBERRORFLAGS        MB_OK | MB_ICONHAND
00077
00078
00079 /* properties of the "Lucida Sans Unicode" font */
00080 #define UCFONTHEIGHT       36
00081 #define UCFONTWIDTH        16
00082
00083 /* spacing for the fields in the status bar... */
00084 #define SBORDER 6
00085 #define SFIELD0 160
00086 #define SFIELD1  80
00087
00088
00089
00090 /* global variables */
00091 extern HANDLE  hInst;
00092 extern HWND    hwndMain;
00093 extern HWND    hwndClient;
00094 extern HWND    hwndStatus;
00095 extern HWND hwndStatic0, hwndStatic1;
00096
00097 extern int gShowhex, gShowNames;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: TIMERS/TIMERS.H Source File

  • TIMERS

TIMERS.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /******************************************************************************\
00013 *
00014 *                                  TIMERS.H
00015 *
00016 \******************************************************************************/
00017
00018
00019
00020 /******************************************************************************\
00021 *                              SYMBOLIC CONSTANTS
00022 \******************************************************************************/
00023
00024 #define ID_TIMER1      1
00025 #define ID_TIMER2      2
00026 #define ID_TIMER3      3
00027 #define ID_TIMER4      4
00028
00029 #define BUFSIZE        20
00030
00031 #define BUTTONBORDER   5
00032 #define BUTTONHEIGHT   25
00033 #define TEXTHEIGHT     8
00034
00035 #define TIMERINTERVAL  250
00036
00037
00038
00039 /******************************************************************************\
00040 *                               GLOBAL VARIABLES
00041 \******************************************************************************/
00042
00043 HANDLE ghInst;
00044 HWND   gahwndButtons[5];  /*  array of HWNDs for the start/stop timer
00045                            *  buttons. Note: the first element
00046                            *  (hwndButtons[0]) is unused (since it doesn't
00047                            *  correspond with a timer ID).
00048                            */
00049 RECT   gaFlashRects[5];   /*  array of RECTs for the flashing rectandgles.
00050                            *  Note: the first element (flashRects[0]) is
00051                            *  unused (since it doesn't correspond with a
00052                            *  timer ID).
00053                            */
00054
00055
00056 /******************************************************************************\
00057 *                              FUNCTION PROTOTYPES
00058 \******************************************************************************/
00059
00060 LRESULT CALLBACK MainWndProc  (HWND, UINT, WPARAM, LPARAM);
00061 VOID    CALLBACK TimerFunc    (HWND, UINT, UINT, DWORD);
00062 VOID SetButtonPositions    (int,  int);
00063 VOID SetFlashRectPositions (LONG, LONG);
00064 VOID DrawStuff             (HWND, HDC);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: PATHS/PATHS.C Source File

  • PATHS

PATHS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  paths.c -- sample program demonstrating paths.
00014 \**************************************************************************/
00015
00016
00017 #include <windows.h>
00018 #include <string.h>
00019 #include <math.h>
00020 #include "paths.h"
00021
00022
00023 /**************************************************************************\
00024 *
00025 *  function:  WinMain()
00026 *
00027 *  input parameters:  c.f. generic sample
00028 *
00029 \**************************************************************************/
00030 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00031                      LPSTR lpCmdLine, int nCmdShow)
00032 {
00033     HANDLE hInst;
00034     HWND   hwndMain;
00035     MSG    msg;
00036
00037     UNREFERENCED_PARAMETER( lpCmdLine );
00038
00039 #if 0
00040      // check if running on Windows NT, if not, display notice and terminate
00041         if( GetVersion() & 0x80000000 )
00042         {
00043           MessageBoxA( NULL,
00044            "This sample application can only be run on Windows NT.\n"
00045              "This application will now terminate.",
00046              "Paths",
00047              MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00048           return( 1 );
00049         }
00050 #endif
00051
00052     /* Check for previous instance.  If none, then register class. */
00053     if (!hPrevInstance) {
00054         WNDCLASS  wc;
00055
00056         wc.style = CS_HREDRAW | CS_VREDRAW;
00057         wc.lpfnWndProc = (WNDPROC)MainWndProc;
00058
00059         wc.cbClsExtra = 0;
00060         wc.cbWndExtra = 0;
00061         wc.hInstance = hInstance;
00062         wc.hIcon = LoadIcon(hInstance, "pathsIcon");
00063         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00064         wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
00065         wc.lpszMenuName =  NULL;
00066         wc.lpszClassName = "paths";
00067
00068         if (!RegisterClass(&wc)) return (FALSE);
00069     }  /* class registered o.k. */
00070
00071
00072     /* Create the main window.  Return false if CreateWindow() fails */
00073     hInst = hInstance;
00074
00075     hwndMain = CreateWindow(
00076         "paths",
00077         "Paths",
00078         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
00079         CW_USEDEFAULT,
00080         CW_USEDEFAULT,
00081         CW_USEDEFAULT,
00082         CW_USEDEFAULT,
00083         NULL,
00084         NULL,
00085         hInstance,
00086         NULL);
00087
00088     if (!hwndMain) return (FALSE);
00089     ShowWindow(hwndMain, nCmdShow);
00090     UpdateWindow(hwndMain);
00091
00092
00093     /* Loop getting messages and dispatching them. */
00094     while (GetMessage(&msg,NULL, 0,0)) {
00095       TranslateMessage(&msg);
00096       DispatchMessage(&msg);
00097     }
00098
00099     return (msg.wParam);
00100 }
00101
00102
00103
00104 /**************************************************************************\
00105 *
00106 *  function:  MainWndProc()
00107 *
00108 *  input parameters:  normal window procedure parameters.
00109 *
00110 *  This is a very simple window.  On create it creates pens to draw with.
00111 *   They are later destroyed at destroy time.  The only interesting code
00112 *   is in the paint message.  We draw 6 different paths into the client
00113 *   area demonstrating various features of paths.
00114 *
00115 *  global variables: none.
00116 \**************************************************************************/
00117 LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00118 {
00119   static HANDLE hPenFill, hPenPath;
00120
00121
00122   switch (message) {
00123
00124
00125     /**********************************************************************\
00126     *  WM_CREATE
00127     *
00128     * Create three pens for drawing with later.
00129     \**********************************************************************/
00130     case WM_CREATE:
00131         hPenPath   = CreatePen (PS_SOLID, 2, (COLORREF) 0x01000005);
00132         hPenFill   = CreatePen (PS_SOLID, 1, (COLORREF) 0x01000002);
00133     break;
00134
00135
00136     /**********************************************************************\
00137     *  WM_DESTROY
00138     *
00139     * Complement of the WM_CREATE message.  Delete the pens that were
00140     *  created and then call postquitmessage.
00141     \**********************************************************************/
00142     case WM_DESTROY:
00143       DeleteObject (hPenFill);
00144       DeleteObject (hPenPath);
00145
00146       PostQuitMessage(0);
00147     break;
00148
00149
00150     /**********************************************************************\
00151     *  WM_PAINT
00152     *
00153     * Query the client rectangle.  Divide it into six sub rectangles
00154     *  (only actually compute the top left sixth).  Now, set the origin
00155     *  for each one of these, write text describing the operation, and
00156     *  then stroke or fill or whatever the path.
00157     \**********************************************************************/
00158     case WM_PAINT: {
00159       HDC  hdc;
00160       PAINTSTRUCT ps;
00161       RECT rect;
00162       HRGN hrgn;
00163       int  i;
00164
00165       hdc = BeginPaint(hwnd, &ps);
00166       SetBkMode (hdc, TRANSPARENT);
00167
00168       GetClientRect (hwnd, &rect);
00169       rect.bottom /= 2;
00170       rect.right /= 3;
00171       SelectObject(hdc, hPenPath);
00172
00173       /* 1. Just stroke the path */
00174       SetViewportOrgEx (hdc, 0, 0, NULL);
00175       TextOut (hdc, 2, 10, STROKEPATH, sizeof (STROKEPATH)-1);
00176       DrawPath(hdc, &rect);
00177       StrokePath (hdc);
00178
00179
00180       /* 2. Fill the path */
00181       SetViewportOrgEx (hdc, 0, rect.bottom, NULL);
00182       TextOut (hdc, 2, 10, FILLPATH, sizeof (FILLPATH)-1);
00183       DrawPath(hdc, &rect);
00184       FillPath (hdc);
00185
00186       /* 3. Stroke and fill the path */
00187       SetViewportOrgEx (hdc,rect.right, 0, NULL);
00188       SetPolyFillMode (hdc, WINDING);
00189       TextOut (hdc, 2, 10, STROKEANDFILLWIND, sizeof (STROKEANDFILLWIND)-1);
00190       DrawPath(hdc, &rect);
00191       StrokeAndFillPath (hdc);
00192
00193       /* 4. Stroke and fill it again, but with different mode. */
00194       SetViewportOrgEx (hdc,rect.right, rect.bottom, NULL);
00195       SetPolyFillMode (hdc, ALTERNATE);
00196       TextOut (hdc, 2, 10, STROKEANDFILLALT, sizeof (STROKEANDFILLALT)-1);
00197       DrawPath(hdc, &rect);
00198       StrokeAndFillPath (hdc);
00199
00200
00201       /* 5. Set the clipping region based on the path. */
00202       SetViewportOrgEx (hdc,rect.right*2, 0, NULL);
00203       SetPolyFillMode (hdc, WINDING);
00204       TextOut (hdc, 2, 10, CLIPPATHWIND, sizeof (CLIPPATHWIND)-1);
00205       SelectObject(hdc, hPenFill);
00206       DrawPath(hdc, &rect);
00207       hrgn = PathToRegion(hdc);
00208       SelectClipRgn (hdc, hrgn);
00209       DeleteObject (hrgn);
00210       MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL);
00211       for (i = 0; i < (rect.right/2); i += 5)
00212         NewAngleArc (hdc, rect.right/2, rect.bottom/2, i,
00213                      (FLOAT)0.0, (FLOAT)360.0);
00214
00215       /* 6. Set the clipping region based on the path, with different mode. */
00216       SetViewportOrgEx (hdc,rect.right*2, rect.bottom, NULL);
00217       SetPolyFillMode (hdc, ALTERNATE);
00218       /* clear the clip region so that TextOut() shows up. */
00219       ExtSelectClipRgn (hdc, NULL, RGN_COPY);
00220       TextOut (hdc, 2, 10, CLIPPATHALT, sizeof (CLIPPATHALT)-1);
00221       DrawPath(hdc, &rect);
00222       hrgn = PathToRegion(hdc);
00223       SelectClipRgn (hdc, hrgn);
00224       DeleteObject (hrgn);
00225       MoveToEx (hdc, rect.right/2, rect.bottom/2, NULL);
00226       for (i = 0; i < (rect.right/2); i += 5)
00227         NewAngleArc (hdc, rect.right/2, rect.bottom/2, i,
00228                      (FLOAT)0.0, (FLOAT)360.0);
00229
00230       EndPaint (hwnd, &ps);
00231
00232     } return 0;
00233
00234
00235   } /* end switch */
00236   return (DefWindowProc(hwnd, message, wParam, lParam));
00237 }
00238
00239
00240
00241 /**************************************************************************\
00242 *
00243 *  function:  DrawPath()
00244 *
00245 * The path used here is a simple rectangle with an ellipse inside of it.
00246 *  The InflateRect() calls have nothing to do with the path, but are just
00247 *  used for convenience.
00248 \**************************************************************************/
00249 void DrawPath(HDC hdc, PRECT prect)
00250 {
00251     RECT destRect;
00252     POINT ptRect[4];
00253     DWORD dwError;
00254     BOOL fRet;
00255
00256     /* make a copy that we can modify with impunity. */
00257     CopyRect (&destRect, prect);
00258
00259     BeginPath (hdc);
00260
00261     InflateRect (&destRect, ((destRect.left- destRect.right)/5),
00262                         ((destRect.top- destRect.bottom)/5));
00263
00264 //    Rectangle (hdc, destRect.left, destRect.top,
00265 //                    destRect.right, destRect.bottom);
00266     ptRect[0].x = destRect.left; ptRect[0].y = destRect.top;
00267     ptRect[1].x = destRect.left; ptRect[1].y = destRect.bottom;
00268     ptRect[2].x = destRect.right; ptRect[2].y = destRect.bottom;
00269     ptRect[3].x = destRect.right; ptRect[3].y = destRect.top;
00270     fRet = Polygon (hdc, ptRect, 4);
00271     if (!fRet)
00272         dwError = GetLastError();
00273
00274     InflateRect (&destRect, ((destRect.left- destRect.right)/4),
00275                         ((destRect.top- destRect.bottom)/4));
00276
00277 //    Ellipse (hdc, destRect.left, destRect.top,
00278 //                  destRect.right, destRect.bottom);
00279     ptRect[0].x = destRect.left; ptRect[0].y = destRect.top;
00280     ptRect[1].x = destRect.left; ptRect[1].y = destRect.bottom;
00281     ptRect[2].x = destRect.right; ptRect[2].y = destRect.bottom;
00282     ptRect[3].x = destRect.right; ptRect[3].y = destRect.top;
00283     fRet = Polygon (hdc, ptRect, 4);
00284     if (!fRet)
00285         dwError = GetLastError();
00286
00287
00288
00289     EndPath (hdc);
00290 }
00291
00292
00293 /**************************************************************************\
00294 *
00295 *  function:  NewAngleArc()
00296 *
00297 *  input parameters:
00298 *       hdc           - handle to the device context
00299 *       X             - x coordinate of circle's center
00300 *       Y             - y coordinate of circle's center
00301 *       dwRadius      - circle's radius
00302 *       fStartDegrees - arc's start angle in degrees
00303 *       fEndDegrees   - arc's end angle in degrees
00304 *
00305 *  This function checks to see if the program is running on Windows NT
00306 *  or Windows 95.  The AngleArc() API is not implemented on Windows 95,
00307 *  so in that case we draw our own arc instead of calling AngleArc().
00308 *
00309 *  global variables: none.
00310 \**************************************************************************/
00311
00312 #define TWO_PI  6.2831853f      // 3.141592 * 2
00313 BOOL NewAngleArc(HDC hdc, int X, int Y, DWORD dwRadius, float fStartDegrees,
00314                  float fEndDegrees)
00315 {
00316     float fCurrentAngle, fStepAngle = 0.03f;
00317     float fx, fy;
00318     float fStart, fEnd;
00319
00320     /* Use NT version if we are on NT else do it ourselves*/
00321     if (GetVersion() & 0x80000000)
00322     {
00323         /* Not NT, so we draw it the hard way */
00324
00325         /* Convert degrees to radians */
00326         /* radians = (deg / 360) * 2pi */
00327         fStart = (fStartDegrees / 360.0f) * TWO_PI;
00328         fEnd = (fEndDegrees / 360.0f) * TWO_PI;
00329
00330         /* Calculate and move to starting point for sweep */
00331         fx = (float)dwRadius * (float)cos(fStart);
00332         fy = (float)dwRadius * (float)sin(fStart);
00333         MoveToEx(hdc, (int)fx + X, Y - (int)fy, NULL);
00334
00335         /* Calculate and draw the sweep */
00336         for (fCurrentAngle = fStart; fCurrentAngle <= fEnd;
00337              fCurrentAngle += fStepAngle)
00338         {
00339             /* Convert from polar to cartesian coordinate */
00340             fx = (float)dwRadius * (float)cos(fCurrentAngle);
00341             fy = (float)dwRadius * (float)sin(fCurrentAngle);
00342
00343             /* Draw the segment */
00344             LineTo(hdc, (int)fx + X, Y - (int)fy);
00345         }
00346     }
00347     else
00348         /* This is NT, so use the API */
00349         return AngleArc(hdc, X, Y, dwRadius, fStartDegrees, fEndDegrees);
00350
00351     return TRUE;
00352 }
00353
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/MEM.H Source File

  • SERVENUM
  • DLL

MEM.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: mem.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations memory allocation functions
00012 //
00013
00014 #ifndef _MEM_H
00015 #define _MEM_H
00016
00017 //-------------------------------------------------------------
00018 // mem prototypes
00019
00020 BOOL MallocMem( LPVOID *lplpv, DWORD dwSize );
00021 BOOL ReallocMem( LPVOID *lplpv, DWORD dwSize );
00022 VOID FreeMem( LPVOID *lplpv );
00023
00024 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/SERVENUM.H Source File

  • SERVENUM
  • DEMO

SERVENUM.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   enumdlg.h
00009 //
00010 //  PURPOSE:  contains enumdlg declarations
00011 //
00012 #ifndef _SERVENUM_H
00013 #define _SERVENUM_H
00014
00015 // MSVC++ 1.1 for NT does not define this in WINERROR.H
00016 #ifndef ERROR_CANCELLED
00017 #define ERROR_CANCELLED 1223L
00018 #endif
00019
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023
00024 //
00025 // ServerEnumDialog(
00026 //     HWND hwnd,              // Handle of calling window
00027 //     LPWSTR lpszServer,      // Buffer to store chosen server name
00028 //     LPDWORD lpcchServer,    // Pointer to size of buffer in bytes
00029 //     FARPROC lpfnHelpProc    // User-defined help procedure
00030 //     )
00031 //
00032 //  PURPOSE: Display a dialog box which allows a user to select
00033 //           a computer on the network.  The user may also type
00034 //           in a string.  The result is not guarenteed to be
00035 //           a valid computer name
00036 //
00037 //  PARAMETERS:
00038 //    hwnd - Handle of calling window
00039 //
00040 //    lpszServer - Buffer to store resultant server name in.
00041 //                 This should be of length MAX_COMPUTERNAME_LENGTH+3
00042 //
00043 //    lpcchServer - Pointer to size of lpszServer, including the NULL
00044 //                  terminating character.  The resultant length of the
00045 //                  string is stored here.  If ERROR_MORE_DATA is return,
00046 //                  the value is the required size of the buffer.
00047 //
00048 //    lpfnHelpProc - Pointer to user-defined help procedure.
00049 //                   The procedure should be prototyped as
00050 //                   int HelpProc( VOID );
00051 //
00052 //  RETURN VALUE:
00053 //    ERROR_SUCCESS - User selected or typed in a server name
00054 //    ERROR_CANCELLED - Dialog box was cancelled
00055 //    ERROR_NOT_ENOUGH_MEMORY - unable to initialize dialog box
00056 //    ERROR_MORE_DATA - lpszServer not large enough
00057 //
00058 //
00059
00060
00061 #ifdef UNICODE
00062 #define ServerEnumDialog ServerEnumDialogW
00063 #else
00064 #define ServerEnumDialog ServerEnumDialogA
00065 #endif
00066
00067
00068
00069 DWORD ServerEnumDialogW( HWND hwnd,
00070                          LPWSTR lpszServer,
00071                          LPDWORD lpcchServer,
00072                          FARPROC lpfnHelpProc
00073                         );
00074
00075 DWORD ServerEnumDialogA( HWND hwnd,
00076                          LPSTR lpszServer,
00077                          LPDWORD lpcchServer,
00078                          FARPROC lpfnHelpProc
00079                         );
00080
00081
00082 #ifdef __cplusplus
00083 }
00084 #endif
00085
00086 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/THRDUTIL.H Source File

  • SERVENUM
  • DLL

THRDUTIL.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: thrdutil.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations thrdutil functions
00012 //
00013
00014 #ifndef _THRDUTIL_H
00015 #define _THRDUTIL_H
00016
00017 extern CRITICAL_SECTION g_csOutstanding;
00018
00019 //-------------------------------------------------------------
00020 // thrdutil prototypes
00021
00022 VOID  WaitCloseOutstanding();
00023 VOID  RefreshOutstanding();
00024 DWORD MarkOutstanding(HANDLE *lpHandle);
00025
00026 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DLL/ENUMUTIL.H Source File

  • SERVENUM
  • DLL

ENUMUTIL.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: enumutil.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations enumutil functions
00012 //
00013
00014 #ifndef _ENUMUTIL_H
00015 #define _ENUMUTIL_H
00016
00017 //-------------------------------------------------------------
00018 // enumutil defines
00019
00020 #define BITMAP_START     500
00021
00022 #define BITMAP_HEIGHT    16
00023 #define BITMAP_WIDTH     16
00024
00025 #define START_NDX        0
00026 #define SERV_NDX         0
00027 #define DOM_NDX          1
00028 #define DOMEX_NDX        2
00029 #define PROV_NDX         3
00030 #define PROVEX_NDX       4
00031 #define HIGHLIGHT_NDX    5
00032
00033 //-------------------------------------------------------------
00034 // enumutil structs
00035
00036 // ENUMNODE is the basic tree data structure
00037 typedef struct _ENUMNODE
00038 {
00039     UINT ndxBmp;                 // ndx into bitmap array ( non highlight )
00040     LPNETRESOURCE lpNet;         // pointer to the corresponding NETRESOURCE entry
00041     DWORD cChild;                // number of children that have been enumerated
00042     struct _ENUMNODE * lpChild;  // dynamically allocated array of children
00043 } ENUMNODE, *LPENUMNODE;
00044
00045 // ENUMSYNC is used for thread syncronization
00046 typedef struct _ENUMSYNC
00047 {
00048     HANDLE hwnd;                 // handle to dialog box
00049     DWORD cThread;               // number of executing threads
00050     DWORD cNetBuf;               // number of buffers containing NETRESOURCE info
00051     LPNETRESOURCE * lplpnetBuf;  // dynamically allocated array of buffers
00052     LPENUMNODE lpRoot;           // pointer to root of ENUMNODE tree
00053     CRITICAL_SECTION cs;         // critical section object for syncronization
00054 } ENUMSYNC, *LPENUMSYNC;
00055
00056 // ENUMOBJECT bundles syncronization with a node
00057 typedef struct _ENUMOBJECT
00058 {
00059     LPENUMSYNC lpSync;
00060     LPENUMNODE lpNode;
00061 } ENUMOBJECT, *LPENUMOBJECT;
00062
00063 // ENUMLISTOBJECT bundles ENUMOBJECT with an index into the listbox
00064 typedef struct _ENUMLISTOBJECT
00065 {
00066     UINT nItem;
00067     ENUMOBJECT Object;
00068 } ENUMLISTOBJECT, *LPENUMLISTOBJECT;
00069
00070 // TLSOBJECT stores all thread local data
00071 typedef struct _TLSOBJECT
00072 {
00073     LPENUMSYNC lpSync;
00074
00075     HBITMAP hbmpArray[HIGHLIGHT_NDX*2];
00076     HFONT   hfont;
00077     HBRUSH  hbrushHL;
00078
00079     TEXTMETRIC tm;
00080
00081     WNDPROC lpfnListProc;
00082
00083     LPWSTR lpszServer;
00084     LPDWORD lpcchServer;
00085     FARPROC lpfnHelpProc;
00086
00087 } TLSOBJECT, *LPTLSOBJECT;
00088
00089
00090 //-------------------------------------------------------------
00091 // enumutil prototypes
00092
00093 VOID FreeEnumSync( LPENUMSYNC * lplpSync );
00094 VOID FreeEnumChild( LPENUMNODE lplpNode );
00095 int __cdecl CompareEnumNode( const void * lpNode1, const void * lpNode2 );
00096
00097 UINT EnumListRecurse( HWND hwnd, LPENUMNODE lpNode, LPTSTR lpServer );
00098 VOID EnumListExpand( HWND hwnd, LPENUMSYNC lpSync, LPENUMNODE lpNode, UINT ndx );
00099 VOID EnumListCollapse( HWND hwnd, LPENUMNODE lpNode, UINT ndx );
00100
00101 VOID LoadBitmapArray( HBITMAP * lphbmpArray);
00102
00103 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: OTHRPROC/OTHRPROC.H Source File

  • OTHRPROC

OTHRPROC.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDE_XCOORD                  101
00013 #define IDE_YCOORD                  102
00014
00015
00016 #define DIALOGHEIGHT                45
00017
00018
00019
00020 LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
00021 BOOL CALLBACK StatusDlgProc (HWND, UINT, WPARAM, LPARAM);
00022 VOID ReadProc(VOID);
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: VIRTMEM/VIRTMEM.H Source File

  • VIRTMEM

VIRTMEM.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 #define IDM_FREE           501
00013 #define IDM_RESERVE        502
00014 #define IDM_COMMIT         503
00015
00016 #define IDM_NOACCESS       504
00017 #define IDM_READONLY       505
00018 #define IDM_READWRITE      506
00019
00020 #define IDM_LOCK           901
00021 #define IDM_UNLOCK         902
00022
00023 #define IDM_WRITE          701
00024
00025 #define IDM_SHOW           801
00026
00027 #define PAGESIZE           0x1000
00028
00029 LRESULT CALLBACK MainWndProc (HWND, UINT, UINT, LONG);
00030 BOOL CALLBACK ShowDlgProc (HWND, UINT, UINT, LONG);
00031 VOID ResetMenu (VOID);
00032
00033
00034 #define IDE_BASEADDR                101
00035 #define IDE_ALLOCBASE               102
00036 #define IDE_INITPROT                103
00037 #define IDE_SIZE                    104
00038 #define IDE_STATE                   105
00039 #define IDE_PROTECT                 106
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: BNDBUF/BNDBUFS.C Source File

  • BNDBUF

BNDBUFS.C

Go to the documentation of this file.
00001 /************************************************************************
00002 *
00003 *   bndbufs.c - sample program demonstrating the server initialization of
00004 *       the distributed bounded buffer solution
00005 *
00006 *   Frederick Chong
00007 *   Microsoft Developer Support
00008 *   Copyright (c) 1992-1996 Microsoft Corporation
00009 *
00010 *************************************************************************/
00011
00012
00013 #include <windows.h>
00014 #include <stdio.h>
00015 #include <string.h>
00016 #include <stdlib.h>
00017 #include <malloc.h>
00018 #include <rpc.h>
00019 #include "common.h"
00020 #include "bndbuf.h"
00021
00022
00023 // Synchronization primitives to shared buffer
00024
00025 extern HANDLE hMutex;       // Handle to mutex
00026 extern HANDLE hEmptySem;    // Handle to empty semaphore
00027 extern HANDLE hFullSem;     // Handle to full semaphore
00028
00029
00030 // This is the shared buffer
00031
00032 extern char buffer[MAX_ITEM][MAX_SIZE];
00033
00034
00035 DWORD retCode;
00036
00037
00038 /************************************************************************
00039
00040 void Usage(char * pszProgramName)
00041
00042 prints out the command line options for starting the server
00043
00044 *************************************************************************/
00045
00046 void Usage(char * pszProgramName)
00047 {
00048     fprintf(stderr, "Usage:  %s\n", pszProgramName);
00049     fprintf(stderr, " -p protocol_sequence\n");
00050     fprintf(stderr, " -e endpoint\n");
00051     ExitProcess(1);
00052 }
00053
00054
00055 /*************************************************************************
00056
00057 void main(int argc, char *argv[])
00058
00059 Parses the command line arguments which allow the user to override the
00060 default protocol sequence and endpoint. It then initializes the
00061 synchronization primitives to be used for the central buffer pool.
00062 Finally, it registers its interface with the name service and then
00063 listens for an incoming call.
00064
00065 **************************************************************************/
00066
00067 void main(int argc, char *argv[])
00068 {
00069
00070     RPC_STATUS status;
00071     RPC_BINDING_VECTOR * pBindingVector;
00072
00073     unsigned char * pszEndpoint         = "\\pipe\\boundbuf";
00074     unsigned char * pszProtocolSequence     = "ncacn_np";
00075
00076     int i;
00077
00078     // This program only runs on Windows NT
00079     if (GetVersion() & 0x80000000)
00080     {
00081         MessageBox(NULL,
00082             "This application cannot run on Windows 3.1 or Windows 95\n"
00083             "This application will now terminate.",
00084             "BndBuf",
00085             MB_OK | MB_ICONSTOP | MB_SETFOREGROUND);
00086         return;
00087     }
00088
00089
00090     // allow the user to override settings with command line switches
00091     for (i = 1; i < argc; i++)
00092     {
00093     if ((*argv[i] == '-') || (*argv[i] == '/'))
00094     {
00095         switch (tolower(*(argv[i]+1)))
00096         {
00097         case 'p':  // protocol sequence
00098             pszProtocolSequence = argv[++i];
00099             break;
00100         case 'e':
00101             pszEndpoint = argv[++i];
00102             break;
00103         case 'h':
00104         case '?':
00105         default:
00106             Usage(argv[0]);
00107         }
00108      }
00109
00110         else
00111         Usage(argv[0]);
00112     }
00113
00114
00115
00116
00117     // Create semaphores and mutex for synchronization
00118
00119     hMutex = CreateMutex(NULL,
00120              FALSE,
00121              "Buffer_Mutex");
00122
00123     if (hMutex == NULL)
00124     {
00125         retCode = GetLastError();
00126         printf("\nCreateMutex returns error %d\n", retCode);
00127         ExitProcess(0);
00128     }
00129
00130
00131     if ((hEmptySem = CreateSemaphore(NULL,
00132                     MAX_ITEM,
00133                     MAX_ITEM,
00134                     "Empty_Sem")) == NULL)
00135
00136     {
00137         retCode = GetLastError();
00138         printf("\nCreateSemaphore for empty returns error %d\n", retCode);
00139         ExitProcess(0);
00140     }
00141
00142
00143     if ((hFullSem = CreateSemaphore(NULL,
00144                     0,
00145                     MAX_ITEM,
00146                     "Full_Sem")) == NULL)
00147
00148     {
00149         retCode = GetLastError();
00150         printf("\nCreateSemaphore for full returns error %d\n", retCode);
00151         ExitProcess(0);
00152     }
00153
00154
00155
00156 // Initialize RPC Interface server
00157
00158
00159     status = RpcServerUseProtseqEp((unsigned char *)pszProtocolSequence,
00160                    MAXCALLS,
00161                    pszEndpoint,
00162                    0);
00163     printf("RpcServerUseProtseqEp returned %d\n", status);
00164     if (status)
00165     ExitProcess(2);
00166
00167
00168     status = RpcServerRegisterIf(bndbufh_ServerIfHandle,
00169                  0,
00170                  0);
00171     printf("RpcServerRegisterIf returned %d\n", status);
00172     if (status)
00173     ExitProcess(2);
00174
00175
00176     status = RpcServerInqBindings(&pBindingVector);
00177     printf("RpcServerInqBindings returned %d\n", status);
00178     if (status)
00179     ExitProcess(2);
00180
00181
00182     status = RpcNsBindingExport(RPC_C_NS_SYNTAX_DEFAULT,    /* name syntax */
00183                 "/.:/Boundbuf_sample",      /* name */
00184                 bndbufh_ServerIfHandle,
00185                 pBindingVector,
00186                 NULL);
00187     printf("RpcNsBindingExport returned %d\n", status);
00188     if (status)
00189     ExitProcess(2);
00190
00191
00192     printf("Calling RpcServerListen\n");
00193     status = RpcServerListen(1,
00194                  MAXCALLS,
00195                  0);
00196     printf("RpcServerListen returned %d\n", status);
00197     if (status)
00198     ExitProcess(2);
00199
00200 }
00201
00202
00203 /**************************************************************************
00204         MIDL allocate and free
00205 ***************************************************************************/
00206
00207 void __RPC_FAR * __RPC_API MIDL_user_allocate(size_t len)
00208 {
00209     return(malloc(len));
00210 }
00211
00212 void __RPC_API MIDL_user_free(void __RPC_FAR * ptr)
00213 {
00214     free(ptr);
00215 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: UNIPUT/DISPLAY.C Source File

  • UNIPUT

DISPLAY.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  display.c -- module to support the main MDI child windows.
00014 *
00015 * This module contains Window Procedure, openDisplay() and closeDisplay()
00016 *  routines.  Call openDisplay() one time per process before creating the
00017 *  first window, and call closeDisplay() one time at process termination.
00018 *
00019 * windows are created in main frame window procedure.
00020 *
00021 * design:  We have one window procedure here for potentially multiple
00022 *  MDI child windows.  The nCharPerLine, SqrHeight, and SqrWidth are
00023 *  stored on a per window basis.  Also, the window class is registered
00024 *  with the style CS_OWNDC.  For this reason, it is possible to select
00025 *  a logical font into the HDC, and it will be there each time you get
00026 *  the DC new for the window.  In this way we have a log font for each
00027 *  window without actually doing any work in this module.
00028 *
00029 *  Some of the data is global, and works for all of the windows.  The
00030 *  startcount & endcount arrays are a good example.  These are computed
00031 *  once when the font is created, but the values remain the same for each
00032 *  window.  Thus we have the following assumption:
00033 *
00034 *   1.  No fonts will be installed or removed while program is running.
00035 *       (CountUCSegments values remain valid for run time duration).
00036 *
00037 *
00038 *  There are WM_USER+ messages to set values for this window, and to
00039 *  notify it of global changes.  Looking at the create time, user message
00040 *  stream is helpful.  On the WM_CREATE message, we send ourselves a
00041 *  WMU_NEWFONT message to create a logical font and count the number of
00042 *  character ranges (segments).  Before returning from this message, we
00043 *  send ourselves a WMU_NEWRANGE message to set the title, and the
00044 *  horizontal scroll bar correctly.
00045 *
00046 *
00047 \**************************************************************************/
00048 #define UNICODE
00049
00050 #include <windows.h>
00051 #include "uniput.h"
00052 #include "display.h"
00053
00054
00055 /* global variables store the start and end codepoints for UC ranges. */
00056 #define MAXSEGMENTS  100
00057 USHORT *endCount= NULL;
00058 USHORT *startCount= NULL;
00059
00060 int CountUCSegments (HDC);
00061 /* error return value from CountUCSegments */
00062 #define SEGMENTERROR -1
00063
00064
00065 /* conversion between (x,y) pairs and rectangle index */
00066 int transXYtoIndex (int, int, int, int, int);
00067 int transIndextoRect (int, PRECT, int, int, int);
00068
00069
00070 /* window extra bytes for use to store window specific data (see register class) */
00071 #define GWLU_NCHAR        0
00072 #define GWLU_SQRHEIGHT    4
00073 #define GWLU_SQRWIDTH     8
00074
00075
00076
00077
00078
00079 /* Global logfont.  Used for CreateFontIndirect().
00080  *  also regerenced in the uniput.c file.
00081  */
00082 LOGFONT logfont = {
00083       UCFONTHEIGHT ,
00084       UCFONTWIDTH ,
00085        0 ,
00086        0 ,
00087      400 ,
00088        0 ,
00089        0 ,
00090        0 ,
00091        UNICODE_CHARSET ,
00092        0 ,
00093        0 ,
00094        2 ,
00095        2 ,
00096       TEXT("Lucida Sans Unicode")};
00097
00098
00099 /* Global, class specific data.
00100  *  ought to allocate once per class, and free once at app exit time.
00101  */
00102 HDC hdcMemXOR;
00103 HBITMAP hbmMemXOR;
00104 PVOID pbitsXOR, pbitsAND;
00105
00106 int FontWidth, FontHeight;
00107 int nSegments;
00108
00109 /**************************************************************************\
00110 *
00111 *  function:  openDisplay()
00112 *
00113 *  Global variables:
00114 *   HDC hdcMemXOR;
00115 *   HBITMAP hbmMemXOR;
00116 *   PVOID pbitsXOR, pbitsAND;
00117 *   int FontWidth, FontHeight;
00118 *   int nSegments;
00119 *
00120 *  returns:  TRUE - if success,  FALSE - if fail.
00121 *
00122 *  essential side effect:
00123 *   Registers window class, and initial global variables.
00124 \**************************************************************************/
00125 int openDisplay(VOID )
00126 {
00127 WNDCLASS  wc;
00128 static int cxCursor, cyCursor;
00129 HFONT hfont;
00130
00131   /* Register the window class*/
00132   wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
00133   wc.lpfnWndProc = (WNDPROC)DisplayWndProc;
00134   wc.cbClsExtra = 0;
00135   wc.cbWndExtra = 12;
00136   wc.hInstance = hInst;
00137   wc.hIcon = LoadIcon(hInst, TEXT("uniputIcon"));
00138   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00139   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00140   wc.lpszMenuName = NULL;
00141   wc.lpszClassName = DISPLAYCLASS;
00142
00143   if (!RegisterClass(&wc)) return (FALSE);
00144
00145   cxCursor = GetSystemMetrics (SM_CXCURSOR);
00146   cyCursor = GetSystemMetrics (SM_CYCURSOR);
00147
00148   /* get pointer to 0-init memory */
00149   pbitsAND = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/8);
00150
00151   /* Create a memory DC to draw into for creating cursors. */
00152   hdcMemXOR = CreateCompatibleDC (NULL);
00153   hbmMemXOR = CreateBitmap (cxCursor,cyCursor,1,4,NULL);
00154   SelectObject (hdcMemXOR, hbmMemXOR);
00155
00156   /* set text modes for the memory HDC */
00157   SetBkMode (hdcMemXOR, TRANSPARENT);
00158   SetTextAlign (hdcMemXOR, TA_CENTER | TA_TOP);
00159
00160   /* set a unicode font into the memory DC */
00161   logfont.lfHeight = cyCursor  *2/3;  // HACK.. scale down Y
00162   logfont.lfWidth  = cxCursor  *2/3;
00163   hfont = CreateFontIndirect (&logfont);
00164   SelectObject (hdcMemXOR, hfont);
00165
00166   /* get pointer to be used later as pointer to bitmap bits */
00167   pbitsXOR = (PVOID) LocalAlloc (LPTR, cxCursor*cyCursor/2);
00168
00169   /* Assume that we got a unicode font.
00170    *  Count the number of segments, and fill in the proper global
00171    *  variables specifying the code point ranges covered.
00172    */
00173   nSegments = CountUCSegments (hdcMemXOR); /* slow computation */
00174
00175
00176   /* verify that we have SOME ranges to work with */
00177   if (nSegments == SEGMENTERROR) return FALSE;
00178
00179   /* warn the user if we can't find the right font */
00180   if (nSegments < 30)
00181     MessageBox (NULL,
00182         TEXT("Working with limited codepoint coverage. \n Install uclucida.ttf"),
00183         TEXT("Warning: Lucida Sans Unicode font not found."), MB_OK);
00184
00185
00186
00187   FontWidth  = UCFONTWIDTH;
00188   FontHeight = UCFONTHEIGHT;
00189
00190   return TRUE;
00191 }
00192
00193 /**************************************************************************\
00194 *
00195 *  function:  closeDisplay()
00196 *
00197 *  Global variables:
00198 *   HDC hdcMemXOR;
00199 *   HBITMAP hbmMemXOR;
00200 *   PVOID pbitsXOR, pbitsAND;
00201 *
00202 *  essential side effect:
00203 *   Frees global variables.
00204 \**************************************************************************/
00205 int closeDisplay(VOID)
00206 {
00207 HFONT hfont;
00208
00209   hfont = SelectObject  (hdcMemXOR, GetStockObject(SYSTEM_FONT));
00210   DeleteObject (hfont);
00211   DeleteDC (hdcMemXOR);
00212   DeleteObject (hbmMemXOR);
00213
00214   LocalFree (LocalHandle (pbitsXOR));
00215   LocalFree (LocalHandle (pbitsAND));
00216
00217   if (startCount != NULL) LocalFree (LocalHandle (startCount));
00218   if (endCount != NULL) LocalFree (LocalHandle (endCount));
00219
00220   return TRUE;
00221 }
00222
00223
00224 /**************************************************************************\
00225 *
00226 *  function:  DisplayWndProc()
00227 *
00228 *  input parameters:  normal window procedure parameters.
00229 *
00230 \**************************************************************************/
00231 LRESULT CALLBACK DisplayWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00232 {
00233 static HFONT  hfont, hfontOld;
00234
00235 static HDC hdc;
00236 static RECT rect;
00237 static int iSeg;
00238 static TCHAR buffer[100];
00239
00240 /* rDown and index used as the user points to a square. */
00241 static RECT rDown;
00242 static int index;
00243
00244 static WCHAR DragDropChar;
00245 static HICON hIcon;
00246
00247
00248
00249   switch (message) {
00250
00251     /**********************************************************************\
00252     *  WM_CREATE
00253     *
00254     * Set up the LOGFONT in the HDC for this window.
00255     \**********************************************************************/
00256     case WM_CREATE:
00257       SendMessage (hwnd, WMU_SETNCHAR, 16, 0);
00258       SendMessage (hwnd, WMU_NEWFONT, FontWidth, FontHeight);
00259     break;
00260
00261
00262     /**********************************************************************\
00263     *  WM_DESTROY
00264     *
00265     * Get rid of the logical font we create for each display window.
00266     *  relying here on CS_ONWDC
00267     \**********************************************************************/
00268     case WM_DESTROY:
00269       hdc = GetDC (hwnd);
00270       hfont = SelectObject  (hdc, GetStockObject(SYSTEM_FONT));
00271       DeleteObject (hfont);
00272       ReleaseDC (hwnd, hdc);
00273     break;
00274
00275
00276
00277
00278
00279     /**********************************************************************\
00280     *  WMU_SETNCHAR
00281     *
00282     * wParam - nCharPerLine
00283     *
00284     \**********************************************************************/
00285     case WMU_SETNCHAR:
00286       SetWindowLong (hwnd, GWLU_NCHAR, (int) wParam);
00287       InvalidateRect (hwnd, NULL, TRUE);
00288     break;
00289
00290     /**********************************************************************\
00291     *  WMU_NEWFONT
00292     *
00293     * wParam - Width
00294     * lParam - Height
00295     *
00296     * Create font, select it into the HDC, and reset ranges.
00297     \**********************************************************************/
00298     case WMU_NEWFONT: {
00299
00300       hdc = GetDC(hwnd);
00301
00302       FontWidth  = (int) wParam;
00303       FontHeight = (int) lParam;
00304       logfont.lfHeight = FontHeight;
00305       logfont.lfWidth  = FontWidth;
00306
00307       hfont = CreateFontIndirect (&logfont);
00308       hfontOld = SelectObject (hdc, hfont);
00309       DeleteObject (hfontOld);
00310
00311       ReleaseDC (hwnd, hdc);
00312
00313
00314       SetScrollRange (hwnd, SB_HORZ, 0, (nSegments-1), TRUE);
00315       SetScrollPos (hwnd, SB_HORZ, 0, TRUE);
00316
00317       SendMessage (hwnd, WMU_NEWRANGE, 0,0);
00318
00319     } return TRUE;
00320
00321
00322     /**********************************************************************\
00323     *  WMU_NEWRANGE
00324     *
00325     *
00326     * Range changes, or font size changes, or title status changes.
00327     \**********************************************************************/
00328     case WMU_NEWRANGE: {
00329       int sqrHeight, sqrWidth;
00330       TEXTMETRIC tm;
00331       int i;
00332
00333       hdc = GetDC(hwnd);
00334       GetTextMetrics (hdc, &tm);
00335       ReleaseDC (hwnd, hdc);
00336
00337       /* index into the start, end arrays stored in scroll bar */
00338       iSeg = GetScrollPos (hwnd, SB_HORZ);
00339
00340       /* Set the window title text to show display range. */
00341       wsprintf (buffer, TEXT("[%04x, %04x]"),
00342                                   (int)startCount[iSeg],
00343                                   (int)endCount[iSeg]);
00344
00345       /* if we are supposed to look up the character range name,
00346        *  then step through the ranges stored in the RangeName
00347        *  table.  Find the correct one, and reset the buffer string.
00348        */
00349       if (gShowNames) {
00350         for (i = 0; i< NRANGE; i++) {
00351           if ((RangeName[i].start <= startCount[iSeg]) &&
00352               ( startCount[iSeg] <= RangeName[i].end))
00353
00354             wsprintf (buffer, TEXT("%s [%04x, %04x]"),
00355                                   RangeName[i].String,
00356                                   (int)startCount[iSeg],
00357                                   (int)endCount[iSeg]);
00358
00359         }
00360       }
00361       SetWindowText (hwnd, buffer);
00362
00363       sqrHeight =  tm.tmHeight + tm.tmExternalLeading;
00364       sqrWidth = tm.tmMaxCharWidth;
00365
00366       SetWindowLong (hwnd, GWLU_SQRHEIGHT,sqrHeight);
00367       SetWindowLong (hwnd, GWLU_SQRWIDTH, sqrWidth );
00368
00369     } return TRUE;
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379     /**********************************************************************\
00380     *  WM_LBUTTONDOWN
00381     *
00382     * Static, shared variables set in WM_LBUTTONDOWN:
00383     *   rDown, hIcon, DragDropChar
00384     *
00385     \**********************************************************************/
00386     case WM_LBUTTONDOWN: {
00387       int x,y;
00388       int nCharPerLine;
00389       int sqrHeight, sqrWidth;
00390       nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
00391       sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
00392       sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );
00393
00394
00395
00396       x = (int)LOWORD (lParam);
00397       y = (int)HIWORD (lParam);
00398
00399       index = transXYtoIndex (x,y, sqrWidth, sqrHeight, nCharPerLine);
00400
00401       /* verify that the index is within the shown segment range */
00402       iSeg= GetScrollPos (hwnd, SB_HORZ);
00403       if (index > (endCount[iSeg]- startCount[iSeg])) return 0;
00404
00405       DragDropChar = index + startCount[iSeg];
00406
00407       transIndextoRect (index, &rDown, sqrWidth, sqrHeight, nCharPerLine);
00408
00409       hdc = GetDC (hwnd);
00410       InvertRect (hdc, &rDown);
00411       ReleaseDC (hwnd, hdc);
00412
00413
00414       /* Create a cursor which represents the character.
00415        * Global variables used:
00416        *   HDC hdcMemXOR;
00417        *   HBITMAP hbmMemXOR;
00418        *   PVOID pbitsXOR, pbitsAND;
00419        */
00420       {
00421       int cxCursor, cyCursor;
00422       RECT rect;
00423
00424       cxCursor = GetSystemMetrics (SM_CXCURSOR);
00425       cyCursor = GetSystemMetrics (SM_CYCURSOR);
00426
00427       rect.left = rect.top = 0;
00428       rect.right = cxCursor; rect.bottom = cyCursor;
00429
00430
00431       FrameRect (hdcMemXOR, &rect, GetStockObject (BLACK_BRUSH));
00432       InflateRect (&rect, -1, -1);
00433       FillRect (hdcMemXOR, &rect, GetStockObject (LTGRAY_BRUSH));
00434       FrameRect (hdcMemXOR, &rect, GetStockObject (GRAY_BRUSH));
00435       InflateRect (&rect, -1, -1);
00436       SelectObject (hdcMemXOR, GetStockObject (WHITE_PEN));
00437       MoveToEx (hdcMemXOR, rect.right, rect.top, NULL);
00438       LineTo (hdcMemXOR,rect.left, rect.top);
00439       LineTo (hdcMemXOR,rect.left, rect.bottom);
00440
00441       ExtTextOut(hdcMemXOR, cxCursor/2,0, ETO_CLIPPED, &rect,
00442                    (LPCWSTR)&DragDropChar, 1, NULL);
00443
00444       GetBitmapBits (hbmMemXOR, cxCursor*cyCursor/2, pbitsXOR);
00445
00446       hIcon = CreateIcon( GetModuleHandle(NULL),
00447               cxCursor,cyCursor, 1,4,
00448               pbitsAND,
00449               pbitsXOR);
00450
00451       SetCursor ((HCURSOR)hIcon);
00452       }
00453
00454
00455
00456       GdiFlush ();
00457       SetCapture (hwnd);
00458     } break;
00459
00460     /**********************************************************************\
00461     *  WM_LBUTTONUP
00462     *
00463     * Static, shared variables set in WM_LBUTTONDOWN:
00464     *   rDown, hIcon, DragDropChar
00465     *
00466     \**********************************************************************/
00467     case WM_LBUTTONUP: {
00468       POINT p;
00469       HWND hwndTarget, hwndTitle;
00470 #define NUMCHARS  255
00471       TCHAR buffer[NUMCHARS];
00472
00473
00474       if (GetCapture() == hwnd) {
00475
00476         p.x = (int)(short)LOWORD (lParam);
00477         p.y = (int)(short)HIWORD (lParam);
00478
00479         ClientToScreen (hwnd, &p);
00480         hwndTarget = WindowFromPoint (p);
00481
00482         if ((GetWindowThreadProcessId (hwnd, NULL)) !=
00483             (GetWindowThreadProcessId (hwndTarget, NULL))) {
00484
00485           /* hack.  unipad has a client window which gets the chars,
00486            *  but we want to display the frame windows text (title bar),
00487            *  so try to get the parent of the target for Title purposes.
00488            */
00489           hwndTitle = (GetParent(hwndTarget)) ? GetParent(hwndTarget) : hwndTarget;
00490           GetWindowText (hwndTitle, buffer, NUMCHARS);
00491
00492           SendMessage (hwndTarget, WM_CHAR, (WPARAM) DragDropChar, 0);
00493           SendMessage (hwndStatus, WMU_CHARACTER,
00494                          (WPARAM) DragDropChar, (LPARAM)hwndTarget);
00495           SendMessage (hwndStatus, WMU_SETTARGETNAME,
00496                          (WPARAM) IsWindowUnicode (hwndTarget), (LPARAM)buffer);
00497         } /* end different process */
00498
00499         Beep (40,40);
00500
00501         hdc = GetDC (hwnd);
00502         InvertRect (hdc, &rDown);
00503         ReleaseDC (hwnd, hdc);
00504         GdiFlush ();
00505         ReleaseCapture ();
00506         SetCursor ((HCURSOR)LoadCursor (NULL, IDC_ARROW));
00507         DestroyIcon (hIcon);
00508       }
00509     } break;
00510
00511
00512
00513     /**********************************************************************\
00514     *  WM_HSCROLL
00515     *
00516     * Step through the character ranges.
00517     * In every case, inform the window the range has changed,
00518     *  and invalidate it to force a repaint.
00519     \**********************************************************************/
00520     case WM_HSCROLL:
00521
00522       switch (LOWORD(wParam)){
00523         int OldPos, NewPos;
00524
00525         case SB_PAGEDOWN:
00526         case SB_LINEDOWN:
00527           OldPos = GetScrollPos (hwnd, SB_HORZ);
00528           SetScrollPos (hwnd, SB_HORZ, (OldPos+1), TRUE);
00529           SendMessage (hwnd,WMU_NEWRANGE, 0,0);
00530           InvalidateRect (hwnd, NULL, TRUE);
00531         break;
00532
00533         case SB_PAGEUP:
00534         case SB_LINEUP:
00535           OldPos = GetScrollPos (hwnd, SB_HORZ);
00536           SetScrollPos (hwnd, SB_HORZ, (OldPos-1), TRUE);
00537           SendMessage (hwnd,WMU_NEWRANGE, 0,0);
00538           InvalidateRect (hwnd, NULL, TRUE);
00539         break;
00540
00541         case SB_THUMBPOSITION:
00542           OldPos = GetScrollPos (hwnd, SB_HORZ);
00543           NewPos = HIWORD (wParam);
00544           SetScrollPos (hwnd, SB_HORZ, NewPos, TRUE);
00545           SendMessage (hwnd,WMU_NEWRANGE, 0,0);
00546           InvalidateRect (hwnd, NULL, TRUE);
00547         break;
00548
00549       }
00550
00551     break;
00552
00553
00554
00555
00556
00557
00558
00559     /**********************************************************************\
00560     *  WM_SIZE
00561     *
00562     \**********************************************************************/
00563     case WM_SIZE:
00564       /* make sure that scroll metrics are ok */
00565       SendMessage (hwnd, WMU_NEWRANGE, 0,0);
00566
00567     break;  /* fall through to MDIChildProc */
00568
00569
00570     /**********************************************************************\
00571     *  WM_PAINT
00572     *
00573     \**********************************************************************/
00574     case WM_PAINT: {
00575       HDC hdc;
00576       PAINTSTRUCT ps;
00577       RECT rect;
00578       POINT  point;
00579       int i;
00580       USHORT start, end;
00581       WCHAR outChar;
00582       USHORT codepoint;
00583       int nCharPerLine;
00584       int sqrHeight, sqrWidth;
00585       nCharPerLine = GetWindowLong (hwnd, GWLU_NCHAR);
00586       sqrHeight    = GetWindowLong (hwnd, GWLU_SQRHEIGHT);
00587       sqrWidth     = GetWindowLong (hwnd, GWLU_SQRWIDTH );
00588
00589
00590       hdc = BeginPaint(hwnd, &ps);
00591       SetBkMode (hdc, TRANSPARENT);
00592
00593       iSeg= GetScrollPos (hwnd, SB_HORZ);
00594       start = startCount[iSeg];
00595       end = endCount[iSeg];
00596
00597       /* ensure that we are in a valid range... some fonts have problems */
00598       if (start != 0xffff)
00599
00600         for (codepoint = start, i=0; codepoint<=end; codepoint++,i++) {
00601
00602           /* paint box and frame it */
00603           transIndextoRect (i, &rect, sqrWidth, sqrHeight, nCharPerLine);
00604           InflateRect (&rect, -1, -1);
00605           FillRect (hdc, &rect, GetStockObject (LTGRAY_BRUSH));
00606           InflateRect (&rect, 1, 1);
00607           FrameRect (hdc, &rect, GetStockObject (GRAY_BRUSH));
00608           InflateRect (&rect, -1, -1);
00609           SelectObject (hdc, GetStockObject (WHITE_PEN));
00610           MoveToEx (hdc, rect.right, rect.top, NULL);
00611           LineTo (hdc,rect.left, rect.top);
00612           LineTo (hdc,rect.left, rect.bottom);
00613
00614
00615
00616           /* set point that we will draw glyph at */
00617           point.x = (rect.right + rect.left)/2;
00618           point.y = rect.top;
00619           SetTextAlign (hdc, TA_CENTER | TA_TOP);
00620           SetTextColor (hdc, PALETTEINDEX (0));
00621
00622
00623           /* special case the non-spacing diacritic marks. U+0300 -> U+036F
00624            *  Write a space first, for them to 'modify.'
00625            */
00626           if ( (0x0300 <= codepoint) && (codepoint <= 0x036F) ) {
00627             outChar = (WCHAR) 0x0020;
00628             TextOutW (hdc, 0,0, &outChar, 1);
00629           }
00630
00631           outChar = (WCHAR) codepoint;
00632           ExtTextOut(hdc, point.x, point.y, ETO_CLIPPED, &rect, (LPCWSTR)&outChar, 1, NULL);
00633
00634
00635
00636           /* fill in unicode code point in hex */
00637           if (gShowhex) {
00638             int nchar;
00639             HANDLE hfonttemp;
00640
00641             nchar = wsprintf (buffer, TEXT("%04x"), (int) codepoint);
00642             hfonttemp = SelectObject (hdc,GetStockObject (SYSTEM_FIXED_FONT));
00643
00644             point.y = rect.bottom;
00645             SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
00646             SetTextColor (hdc, PALETTEINDEX (5));
00647
00648             TextOut( hdc, point.x, point.y,
00649                           buffer, nchar);
00650             SelectObject (hdc,hfonttemp);
00651           }
00652
00653
00654         } /* end for */
00655
00656       EndPaint (hwnd, &ps);
00657     } return FALSE; /* end WM_PAINT */
00658
00659
00660
00661
00662   } /* end switch */
00663
00664   return (DefMDIChildProc(hwnd, message, wParam, lParam));
00665 }
00666
00667
00668
00669
00670 /**************************************************************************\
00671 *
00672 * Need a mapping between the (x,y) pair, and the index of the square on
00673 *  the window.  Two routines provide this... one for each direction.
00674 *
00675 \**************************************************************************/
00676
00677 /**********************************************************************\
00678 *  transXYtoIndex
00679 *
00680 *  Given x & y values, return the index.
00681 *
00682 \**********************************************************************/
00683 int transXYtoIndex (int x, int y,
00684      int sqrWidth, int sqrHeight, int nCharPerLine)
00685 {
00686     x /= sqrWidth;
00687     if (x < 0) x = 0;
00688     if (x >= nCharPerLine) x = nCharPerLine-1;
00689
00690     y /= sqrHeight;
00691     if (y < 0) y = 0;
00692
00693     return ( (y * nCharPerLine) + x);
00694 }
00695
00696
00697 /**********************************************************************\
00698 *  transIndextoRect
00699 *
00700 *  Given an index, i.e. the number of one of the squares on the display
00701 *   window, fill in the rectangle structure.
00702 *
00703 \**********************************************************************/
00704 int transIndextoRect (int index, PRECT pr,
00705      int sqrWidth, int sqrHeight, int nCharPerLine)
00706 {
00707 int x,y;
00708
00709     x = index % nCharPerLine;
00710     y = index / nCharPerLine;
00711
00712     pr->left = x*sqrWidth;
00713     pr->top = y*sqrHeight;
00714     pr->right = pr->left +sqrWidth;
00715     pr->bottom = pr->top +sqrHeight;
00716
00717     return TRUE;
00718 }
00719
00720
00721
00722
00723
00724
00725 /**************************************************************************\
00726 *
00727 * All of the code below is used for parsing 'font data.'  It will only
00728 *  make sense if you have a copy of the True Type font spec.  In short,
00729 *  we grab the 'cmap' table, look through it for a subtable, and then
00730 *  get two parallel arrays from the subtable.  Complications arise because
00731 *  the true type data is 'BIG ENDIAN' and NT is being run 'little endian.'
00732 *  For this reason, once we locate the short or long, we call Swap* to
00733 *  change the byte ordering.
00734 *
00735 \**************************************************************************/
00736
00737
00738 VOID SwapShort (PUSHORT);
00739 VOID SwapULong  (PULONG);
00740
00741
00742
00743 typedef struct tagTABLE{
00744     USHORT platformID;
00745     USHORT encodingID;
00746     ULONG  offset;
00747 } TABLE, *PTABLE;
00748
00749 typedef struct tagSUBTABLE{
00750     USHORT format;
00751     USHORT length;
00752     USHORT version;
00753     USHORT segCountX2;
00754     USHORT searchRange;
00755     USHORT entrySelector;
00756     USHORT rangeShift;
00757 } SUBTABLE, *PSUBTABLE;
00758
00759
00760 /* 'cmap' is passed in by value in a DWORD */
00761 #define CMAPHEX  0x70616d63
00762 #define NBYTES   256
00763 #define OFFSETERROR  0
00764
00765
00766
00767 /**************************************************************************\
00768 *
00769 *  function:  CountUCSegments()
00770 *
00771 *  input parameters:
00772 *   hdc - with the logical font set into it.
00773 *   prect - pointer to client rectangle.
00774 *
00775 *  Global variables:
00776 *   startCount
00777 *   endCount
00778 *
00779 *  returns:
00780 *   number of UC segments or
00781 *   SEGMENTERROR if there is some kind of error.
00782 *
00783 *  essential side effect:
00784 *   Fills in global startCount, endCount arrays.
00785 \**************************************************************************/
00786 int CountUCSegments (HDC hdc)
00787 {
00788 DWORD       cbData;
00789 USHORT      aShort[2];
00790 DWORD       nBytes;
00791 USHORT      i, nTables;
00792 PTABLE      pTable;
00793 PSUBTABLE   pSubTable;
00794 ULONG       offset,offsetFormat4;
00795 USHORT      segCount;
00796 BYTE        buffer[NBYTES];
00797
00798
00799
00800
00801     /* find number of "subtables", second long in cmap */
00802     nBytes=GetFontData (hdc, CMAPHEX, 0, aShort, 4);
00803     if (nBytes == GDI_ERROR) {
00804       MessageBox (NULL, MBGETFONTDATAERR,MBERROR , MBERRORFLAGS);
00805       return SEGMENTERROR;
00806     }
00807     if (nBytes == 0) {
00808       MessageBox (NULL, TEXT("No 'cmap' table."),MBERROR , MBERRORFLAGS);
00809       return SEGMENTERROR;
00810     }
00811     nTables = aShort[1];
00812     SwapShort (&nTables);
00813
00814
00815     cbData = nTables * sizeof(TABLE);
00816     if (cbData >NBYTES) {
00817       MessageBox (NULL, TEXT("cbData >NBYTES"),MBERROR , MBERRORFLAGS);
00818       return SEGMENTERROR;
00819     }
00820
00821     /* get array of subtables information.  Check each one for 3,1*/
00822     nBytes=GetFontData (hdc, CMAPHEX, 4, buffer, cbData);
00823     pTable = (PTABLE)buffer;
00824     offsetFormat4 = OFFSETERROR;
00825     for (i = 0; i< nTables; i++) {
00826
00827         SwapShort (&(pTable->encodingID));
00828         SwapShort (&(pTable->platformID));
00829
00830         if ((pTable->platformID == 3)&&(pTable->encodingID == 1)) {
00831           offsetFormat4 = pTable->offset;
00832           SwapULong (&offsetFormat4);
00833           break;
00834         }
00835         pTable++;
00836     }
00837
00838     /* verify that we got the correct offset to the FORMAT 4 subtable */
00839     if (offsetFormat4 == OFFSETERROR){
00840       MessageBox (NULL, TEXT("Can not find 3,1 subtable"),MBERROR , MBERRORFLAGS);
00841       return SEGMENTERROR;
00842     }
00843
00844     /* Get the beginning of the subtable, especially the segment count */
00845     nBytes=GetFontData (hdc, CMAPHEX, offsetFormat4, buffer, sizeof(SUBTABLE));
00846     pSubTable = (PSUBTABLE) buffer;
00847     SwapShort (&(pSubTable->format));
00848     SwapShort (&(pSubTable->segCountX2));
00849
00850     if (pSubTable->format != 4){
00851       MessageBox (NULL, TEXT("format !=4"), MBERROR, MBERRORFLAGS);
00852       return SEGMENTERROR;
00853     }
00854
00855     segCount = pSubTable->segCountX2 / 2;
00856
00857     /* Now that we know how many segments that the font contains,
00858      *  free up the old memory, and realloc. the two global arrays.
00859      */
00860     if (startCount != NULL) LocalFree (LocalHandle (startCount));
00861     if (endCount != NULL) LocalFree (LocalHandle (endCount));
00862     startCount = LocalAlloc (LPTR, segCount * sizeof(USHORT));
00863     endCount = LocalAlloc (LPTR, segCount * sizeof(USHORT));
00864
00865     if ((startCount == NULL) || (endCount == NULL)) {
00866       MessageBox (NULL, TEXT("LocalAlloc failed"), MBERROR, MBERRORFLAGS);
00867       return SEGMENTERROR;
00868     }
00869
00870     /* read in the array of endCount values */
00871     offset = offsetFormat4
00872            + (7 * sizeof (USHORT));  /* skip constant # bytes in subtable */
00873     cbData = segCount * sizeof (USHORT);
00874     nBytes=GetFontData (hdc, CMAPHEX, offset, endCount, cbData );
00875     for (i = 0; i<segCount; i++)
00876         SwapShort (& (endCount[i]));
00877
00878     /* read in the array of startCount values */
00879     offset = offsetFormat4
00880            + (7 * sizeof (USHORT))   /* skip constant # bytes in subtable */
00881            + (segCount * sizeof (USHORT)) /* skip endCount array */
00882            + sizeof (USHORT);             /* skip reservedPad */
00883     cbData = segCount * sizeof (USHORT);
00884     nBytes=GetFontData (hdc, CMAPHEX, offset, startCount, cbData );
00885     for (i = 0; i<segCount; i++)
00886         SwapShort (& (startCount[i]));
00887
00888
00889     return segCount;
00890 }
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901 VOID SwapShort (PUSHORT p)
00902 {
00903 SHORT temp;
00904
00905     temp =(SHORT)( HIBYTE (*p) + (LOBYTE(*p) << 8));
00906     *p = temp;
00907 }
00908
00909
00910
00911 VOID SwapULong (PULONG p)
00912 {
00913 ULONG temp;
00914
00915     temp = (LONG) ((BYTE) *p);
00916     temp <<= 8;
00917     *p >>=8;
00918
00919     temp += (LONG) ((BYTE) *p);
00920     temp <<= 8;
00921     *p >>=8;
00922
00923     temp += (LONG) ((BYTE) *p);
00924     temp <<= 8;
00925     *p >>=8;
00926
00927     temp += (LONG) ((BYTE) *p);
00928     *p = temp;
00929 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/BROWSE.C Source File

  • SERVENUM
  • DEMO

BROWSE.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   browse.c
00009 //
00010 //  PURPOSE:  Implement the windows procedure for the main application
00011 //            windows.
00012 //
00013 //  FUNCTIONS:
00014 //    WndProc      - Processes messages for the main window.
00015 //    MsgCreate    - Handle the WM_CREATE messages for the main window.
00016 //    MsgCommand   - Handle the WM_COMMAND messages for the main window.
00017 //    MsgDestroy   - Handles the WM_DESTROY message by calling
00018 //                   PostQuitMessage().
00019 //    CmdExit      - Handles the file exit command by calling destory
00020 //                   window on the main window.
00021 //    CmdEnum      - Calls ServerEnumDialog
00022 //    CmdEnumHelp  - Calls ServerEnumDialog with a Help Procedure
00023 //    HelpProc     - Help procedure for callback
00024 //
00025 //  COMMENTS:
00026 //
00027 //  AUTHOR: Craig Link - Microsoft Developer Support
00028 //
00029
00030 #include <windows.h>            // required for all Windows applications
00031 #include <windowsx.h>
00032 #include <stdlib.h>
00033 #include <malloc.h>
00034 #include <tchar.h>
00035
00036 #include "globals.h"            // prototypes specific to this application
00037 #include "servenum.h"
00038
00039 // typedef's for dynamic linking to functions in servenum.dll
00040 typedef DWORD (*FPSERVENUMDLG)(HWND, LPTSTR, LPDWORD, FARPROC);
00041
00042 int HelpProc(VOID);
00043
00044 // Main window message table definition.
00045 MSD rgmsd[] =
00046 {
00047     {WM_CREATE,   MsgCreate},
00048     {WM_COMMAND,  MsgCommand},
00049     {WM_DESTROY,  MsgDestroy}
00050 };
00051
00052 MSDI msdiMain =
00053 {
00054     sizeof(rgmsd) / sizeof(MSD),
00055     rgmsd,
00056     edwpWindow
00057 };
00058
00059
00060 // Main window command table definition.
00061 CMD rgcmd[] =
00062 {
00063     {IDM_ENUM, CmdEnumDlg},
00064     {IDM_ENUMHELP, CmdEnumHelpDlg},
00065     {IDM_EXIT, CmdExit},
00066 };
00067
00068 CMDI cmdiMain =
00069 {
00070     sizeof(rgcmd) / sizeof(CMD),
00071     rgcmd,
00072     edwpWindow
00073 };
00074
00075 // Application "globals"
00076
00077 // Module specific "globals"  Used when a variable needs to be
00078 // accessed in more than on handler function.
00079
00080 HWND g_hwnd;
00081 HINSTANCE g_hLibrary;
00082 FPSERVENUMDLG g_lpfnServEnumDlg;
00083
00084 //
00085 //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
00086 //
00087 //  PURPOSE:  Processes messages for the main window.
00088 //
00089 //  PARAMETERS:
00090 //    hwnd     - window handle
00091 //    uMessage - message number
00092 //    wparam   - additional information (dependant on message number)
00093 //    lparam   - additional information (dependant on message number)
00094 //
00095 //  RETURN VALUE:
00096 //    The return value depends on the message number.  If the message
00097 //    is implemented in the message dispatch table, the return value is
00098 //    the value returned by the message handling function.  Otherwise,
00099 //    the return value is the value returned by the default window procedure.
00100 //
00101 //  COMMENTS:
00102 //    Call the DispMessage() function with the main window's message dispatch
00103 //    information (msdiMain) and the message specific information.
00104 //
00105
00106 LRESULT CALLBACK WndProc(HWND   hwnd,
00107                          UINT   uMessage,
00108                          WPARAM wparam,
00109                          LPARAM lparam)
00110 {
00111     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
00112 }
00113
00114
00115 //
00116 //  FUNCTION: MsgCreate(HWND, UINT, WPARAM, LPARAM)
00117 //
00118 //  PURPOSE: Initialized main window
00119 //
00120 //  PARAMETERS:
00121 //
00122 //    hwnd      - Window handle
00123 //    uMessage  - Message number (Unused)
00124 //    wparam    - Extra data     (Unused)
00125 //    lparam    - Extra data     (Unused)
00126 //
00127 //  RETURN VALUE:
00128 //
00129 //    Always returns 0 - Message handled
00130 //
00131 //  COMMENTS:
00132 //    Creates a listbox the size of the window and fills it
00133 //    with a list of RAS connections.
00134 //
00135
00136 LRESULT MsgCreate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00137 {
00138     DWORD dwError;
00139     TCHAR szError[128];
00140
00141     // Store the main window handle
00142     g_hwnd = hwnd;
00143
00144     // Attempt to dynamically load the servenum.dll
00145     g_hLibrary = LoadLibrary(TEXT("servenum.dll"));
00146     if (!g_hLibrary)
00147     {
00148         dwError = GetLastError();
00149         wsprintf(szError, TEXT("Error loading SERVENUM.DLL.  ")
00150                  TEXT("GetLastError() == %d."), dwError);
00151         MessageBox(hwnd, szError, TEXT("Server Enum"), MB_ICONEXCLAMATION | MB_OK);
00152         return(-1);
00153     }
00154
00155     // The DLL is loaded, get a pointer to the exported function
00156 #ifdef UNICODE
00157     g_lpfnServEnumDlg = (FPSERVENUMDLG) GetProcAddress(g_hLibrary,
00158             "ServerEnumDialogW");
00159 #else
00160     g_lpfnServEnumDlg = (FPSERVENUMDLG) GetProcAddress(g_hLibrary,
00161             "ServerEnumDialogA");
00162 #endif
00163
00164     if (!g_lpfnServEnumDlg)
00165     {
00166         dwError = GetLastError();
00167         wsprintf(szError, TEXT("Error loading SERVENUM.DLL.  ")
00168                  TEXT("GetLastError() == %d."), dwError);
00169         MessageBox(hwnd, szError, TEXT("Server Enum"), MB_ICONEXCLAMATION | MB_OK);
00170         return(-1);
00171     }
00172
00173     return 0;
00174 }
00175
00176
00177
00178
00179
00180 //
00181 //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
00182 //
00183 //  PURPOSE: Handle the WM_COMMAND messages for the main window.
00184 //
00185 //  PARAMETERS:
00186 //    hwnd     - window handle
00187 //    uMessage - WM_COMMAND (Unused)
00188 //    GET_WM_COMMAND_ID(wparam, lparam)   - Command identifier
00189 //    GET_WM_COMMAND_HWND(wparam, lparam) - Control handle
00190 //
00191 //  RETURN VALUE:
00192 //    The return value depends on the message number.  If the message
00193 //    is implemented in the message dispatch table, the return value is
00194 //    the value returned by the message handling function.  Otherwise,
00195 //    the return value is the value returned by the default window procedure.
00196 //
00197 //  COMMENTS:
00198 //    Call the DispCommand() function with the main window's command dispatch
00199 //    information (cmdiMain) and the command specific information.
00200 //
00201
00202 LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00203 {
00204     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
00205 }
00206
00207
00208 //
00209 //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
00210 //
00211 //  PURPOSE: Calls PostQuitMessage().
00212 //
00213 //  PARAMETERS:
00214 //
00215 //    hwnd      - Window handle  (Unused)
00216 //    uMessage  - Message number (Unused)
00217 //    wparam    - Extra data     (Unused)
00218 //    lparam    - Extra data     (Unused)
00219 //
00220 //  RETURN VALUE:
00221 //
00222 //    Always returns 0 - Message handled
00223 //
00224 //  COMMENTS:
00225 //
00226 //
00227
00228 LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
00229 {
00230
00231     PostQuitMessage(0);
00232     return 0;
00233 }
00234
00235
00236
00237 //
00238 //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
00239 //
00240 //  PURPOSE: Exit the application.
00241 //
00242 //  PARAMETERS:
00243 //    hwnd     - The window.
00244 //    wCommand - IDM_EXIT
00245 //    wNotify  - Notification number (unused)
00246 //    hwndCtrl - NULL (unused)
00247 //
00248 //  RETURN VALUE:
00249 //    Always returns 0 - command handled.
00250 //
00251 //  COMMENTS:
00252 //
00253 //
00254
00255 LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00256 {
00257     DestroyWindow(hwnd);
00258     return 0;
00259 }
00260
00261
00262
00263 //
00264 //  FUNCTION: CmdEnumDlg(HWND, WORD, WORD, HWND)
00265 //
00266 //  PURPOSE: Calls the ServerEnumDialog API
00267 //
00268 //  PARAMETERS:
00269 //    hwnd      - Window handle
00270 //    wCommand  - IDM_ENUM
00271 //    wNotify   - Notification number (unused)
00272 //    hwndCtrl  - NULL (unused)
00273 //
00274 //  RETURN VALUE:
00275 //
00276 //    Always returns 0 - Message handled
00277 //
00278 //  COMMENTS:
00279 //
00280 LRESULT CmdEnumDlg(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00281 {
00282     TCHAR szBuf[64];
00283     TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
00284     DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
00285     DWORD dwRet;
00286
00287     dwRet = g_lpfnServEnumDlg( hwnd, szServer, &cchServer, NULL );
00288
00289     if ( dwRet == ERROR_SUCCESS )
00290         wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );
00291
00292     else if ( dwRet == ERROR_CANCELLED )
00293         _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );
00294
00295     else
00296         wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );
00297
00298     MessageBox( hwnd, szBuf, szAppName, MB_OK );
00299
00300     return 0;
00301 }
00302
00303
00304 //
00305 //  FUNCTION: CmdEnumHelpDlg(HWND, WORD, WORD, HWND)
00306 //
00307 //  PURPOSE: Calls the ServerEnumDialog API with a HelpProcedure
00308 //
00309 //  PARAMETERS:
00310 //    hwnd      - Window handle
00311 //    wCommand  - IDM_ENUMHELP
00312 //    wNotify   - Notification number (unused)
00313 //    hwndCtrl  - NULL (unused)
00314 //
00315 //  RETURN VALUE:
00316 //
00317 //    Always returns 0 - Message handled
00318 //
00319 //  COMMENTS:
00320 //
00321 LRESULT CmdEnumHelpDlg(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
00322 {
00323     TCHAR szBuf[64];
00324     TCHAR szServer[MAX_COMPUTERNAME_LENGTH+1];
00325     DWORD cchServer = MAX_COMPUTERNAME_LENGTH+1;
00326     DWORD dwRet;
00327
00328     dwRet = g_lpfnServEnumDlg(hwnd, szServer, &cchServer, (FARPROC) HelpProc);
00329
00330     if ( dwRet == ERROR_SUCCESS )
00331         wsprintf( szBuf, TEXT("Selected Server: %s"), szServer );
00332
00333     else if ( dwRet == ERROR_CANCELLED )
00334         _tcscpy( szBuf, TEXT("ServerEnumDialog Cancelled" ) );
00335
00336     else
00337         wsprintf( szBuf, TEXT("ServerEnumDialog return error 0x%x" ), dwRet );
00338
00339     MessageBox( hwnd, szBuf, szAppName, MB_OK );
00340
00341     return 0;
00342 }
00343
00344
00345 //
00346 //  FUNCTION: HelpProc( VOID )
00347 //
00348 //  PURPOSE: Called by the ServerEnumDialog API
00349 //
00350 //  PARAMETERS:
00351 //    none
00352 //
00353 //  RETURN VALUE:
00354 //    none
00355 //
00356 //  COMMENTS:
00357 //
00358 int HelpProc( VOID )
00359 {
00360     MessageBox( g_hwnd, TEXT("Help Procedure Called"), szAppName, MB_OK );
00361     return 0;
00362 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: WORLD/WORLD.C Source File

  • WORLD

WORLD.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /********************************************************************\
00013 *  world.c -- Sample program demonstrating scaling and translating   *
00014 *             an image from a metafile with World Coordinate         *
00015 *             Transforms.                                            *
00016 *                                                                    *
00017 *  Comments:                                                         *
00018 *                                                                    *
00019 *  The application loads the specified metafile. The user can        *
00020 *  scale the image through a menu option and translate it via        *
00021 *  the scrollbars and arrow keys.                                    *
00022 *                                                                    *
00023 *  Functions:                                                        *
00024 *                                                                    *
00025 *  WinMain()         - Initializes Application                       *
00026 *  MainWndProc()     - Processes Application Messages                *
00027 *  ScaleDlgProc()    - Processes "Scale Image" Dialog Box Messages   *
00028 *  AboutDlgProc()    - Processes "About" Dialog Box Messages         *
00029 *  OpenMetaFile()    - Gets Metafile name and opens the Metafile     *
00030 *  SetUnityXform()   - Helper routine which sets the unity transform *
00031 *                                                                    *
00032 *                                                                    *
00033 \********************************************************************/
00034
00035
00036 /*********************  Header Files  *********************/
00037
00038 #include <windows.h>
00039 #include <memory.h>
00040 #include <stdlib.h>
00041 #include "world.h"
00042
00043
00044 /**********************  Defines  *************************/
00045
00046 #define VSCROLLMAX  50
00047 #define HSCROLLMAX  50
00048 #define VERTSCALE   VSCROLLMAX/3
00049 #define HORZSCALE   HSCROLLMAX/3
00050
00051 #define LINEINC     1
00052 #define PAGEINC     4
00053
00054 #define FIRSTSTRING 0
00055 #define LASTSTRING  10
00056 #define MAXINPUT    10
00057
00058 /*********************  Prototypes  ***********************/
00059
00060 LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM );
00061 BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );
00062 BOOL CALLBACK ScaleDlgProc( HWND, UINT, WPARAM, LPARAM );
00063 BOOL OpenMetafile( HWND );
00064 void SetUnityXform( VOID );
00065
00066 /*******************  Global Variables ********************/
00067
00068 HANDLE ghInstance;
00069
00070 HENHMETAFILE hEMF;  /* Handle of metafile opened                  */
00071 XFORM xForm;        /* Transform to apply in SetWorldTransform()  */
00072 BOOL bFileOpen;     /* Logs if a metafile has been opened or not  */
00073 BOOL bFileJustOpen; /* Used to re-initialize "Scale Image" values */
00074
00075 /* Used for putting up File Open common dialog */
00076
00077 OPENFILENAME OpenFileName;
00078 CHAR szFile[MAX_PATH];
00079 CHAR szFileTitle[MAX_PATH];
00080 CHAR szFilter[] = "Metafile (*.EMF)\0*.emf\0All Files (*.*)\0*.*\0";
00081
00082
00083 /********************************************************************\
00084 *  Function: int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)  *
00085 *                                                                    *
00086 *   Purpose: Initializes Application                                 *
00087 *                                                                    *
00088 *  Comments: Standard template                                       *
00089 *                                                                    *
00090 *                                                                    *
00091 \********************************************************************/
00092
00093
00094 int PASCAL WinMain( HINSTANCE hInstance,
00095                     HINSTANCE hPrevInstance,
00096                     LPSTR lpszCmdLine,
00097                     int nCmdShow )
00098 {
00099    WNDCLASS wc;
00100    MSG msg;
00101    HWND hWnd;
00102
00103    // check if running on Windows NT, if not, display notice and terminate
00104    if( GetVersion() & 0x80000000 )
00105    {
00106       MessageBoxA( NULL,
00107          "This sample application can only be run on Windows NT.\n"
00108          "This application will now terminate.",
00109          "World",
00110          MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00111       return( 1 );
00112    }
00113
00114    if( !hPrevInstance ) {
00115       wc.lpszClassName = "WorldClass";
00116       wc.lpfnWndProc = MainWndProc;
00117       wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
00118       wc.hInstance = hInstance;
00119       wc.hIcon = LoadIcon( hInstance, "WorldIcon" );
00120       wc.hCursor = LoadCursor( NULL, IDC_ARROW );
00121       wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
00122       wc.lpszMenuName = "WorldMenu";
00123       wc.cbClsExtra = 0;
00124       wc.cbWndExtra = 0;
00125
00126       RegisterClass( &wc );
00127    }
00128
00129    ghInstance = hInstance;
00130
00131    hWnd = CreateWindow( "WorldClass",
00132                         "World Coordinate Transforms",
00133                         WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
00134                         0,
00135                         0,
00136                         CW_USEDEFAULT,
00137                         CW_USEDEFAULT,
00138                         NULL,
00139                         NULL,
00140                         hInstance,
00141                         NULL
00142                       );
00143
00144    ShowWindow( hWnd, nCmdShow );
00145
00146    while( GetMessage( &msg, NULL, 0, 0 ) ) {
00147       TranslateMessage( &msg );
00148       DispatchMessage( &msg );
00149    }
00150
00151    return msg.wParam;
00152 }
00153
00154
00155 /********************************************************************\
00156 * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
00157 *                                                                    *
00158 *  Purpose: Processes Application Messages                           *
00159 *                                                                    *
00160 * Comments: The following messages are processed                     *
00161 *                                                                    *
00162 *           WM_CREATE                                                *
00163 *           WM_HSCROLL                                               *
00164 *           WM_VSCROLL                                               *
00165 *           WM_KEYDOWN                                               *
00166 *           WM_PAINT                                                 *
00167 *           WM_COMMAND                                               *
00168 *           WM_DESTROY                                               *
00169 *                                                                    *
00170 *                                                                    *
00171 \********************************************************************/
00172
00173
00174 LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
00175    LPARAM lParam )
00176 {
00177    static int nVscrollPos, nHscrollPos;
00178    int nVscrollInc, nHscrollInc;
00179    RECT rect;
00180    PAINTSTRUCT ps;
00181    HDC hDC;
00182
00183    switch( msg ) {
00184
00185 /**************************************************************\
00186 *     WM_CREATE: The scrollbar range is set. Global variables  *
00187 *        are initialized. The new API SetGraphicsMode() must   *
00188 *        be called before SetWorldCoordinates() can be called  *
00189 *        in the WM_PAINT case.                                 *
00190 \**************************************************************/
00191
00192       case WM_CREATE:
00193
00194          SetScrollRange( hWnd, SB_HORZ, 0, HSCROLLMAX, FALSE );
00195          SetScrollRange( hWnd, SB_VERT, 0, VSCROLLMAX, FALSE );
00196
00197          bFileOpen = FALSE;
00198          bFileJustOpen = FALSE;
00199
00200          hDC = GetDC( hWnd );
00201          SetGraphicsMode( hDC, GM_ADVANCED );
00202          ReleaseDC( hWnd, hDC );
00203
00204          break;
00205
00206 /**************************************************************\
00207 *     WM_HSCROLL: Standard template, except that instead of    *
00208 *        calling ScrollWindow(), the transform is updated.     *
00209 \**************************************************************/
00210
00211       case WM_HSCROLL:
00212          switch( wParam ) {
00213             case SB_LINEUP:
00214                nHscrollInc = -LINEINC;
00215                break;
00216             case SB_LINEDOWN:
00217                nHscrollInc = LINEINC;
00218                break;
00219             case SB_PAGEUP:
00220                nHscrollInc = -PAGEINC;
00221                break;
00222             case SB_PAGEDOWN:
00223                nHscrollInc = PAGEINC;
00224                break;
00225             case SB_THUMBPOSITION:
00226                nHscrollInc = HIWORD(wParam) - nHscrollPos;
00227                break;
00228             default:
00229                nHscrollInc = 0;
00230          }
00231          if(nHscrollInc=max(-nHscrollPos,min(nHscrollInc,HSCROLLMAX-
00232                nHscrollPos))) {
00233             nHscrollPos += nHscrollInc;
00234             SetScrollPos( hWnd, SB_HORZ, nHscrollPos, TRUE );
00235
00236             xForm.eDx += (FLOAT) (nHscrollInc * HORZSCALE);
00237             InvalidateRect( hWnd, NULL, TRUE );
00238          }
00239          return 0;
00240
00241 /**************************************************************\
00242 *     WM_VSCROLL: Standard template, except that instead of    *
00243 *        calling ScrollWindow(), the transform is updated.*    *
00244 \**************************************************************/
00245
00246       case WM_VSCROLL:
00247          switch( wParam ) {
00248             case SB_TOP:
00249                nVscrollInc = -nVscrollPos;
00250                break;
00251             case SB_BOTTOM:
00252                nVscrollInc = VSCROLLMAX - nVscrollPos;
00253                break;
00254             case SB_LINEUP:
00255                nVscrollInc = -LINEINC;
00256                break;
00257             case SB_LINEDOWN:
00258                nVscrollInc = LINEINC;
00259                break;
00260             case SB_PAGEUP:
00261                nVscrollInc = -PAGEINC;
00262                break;
00263             case SB_PAGEDOWN:
00264                nVscrollInc = PAGEINC;
00265                break;
00266             case SB_THUMBTRACK:
00267                nVscrollInc = HIWORD(wParam) - nVscrollPos;
00268                break;
00269             default:
00270                nVscrollInc = 0;
00271          }
00272          if(nVscrollInc=max(-nVscrollPos,min(nVscrollInc,VSCROLLMAX-
00273                nVscrollPos))) {
00274             nVscrollPos += nVscrollInc;
00275             SetScrollPos( hWnd, SB_VERT, nVscrollPos, TRUE );
00276
00277             xForm.eDy += (FLOAT) (nVscrollInc * VERTSCALE);
00278             InvalidateRect( hWnd, NULL, TRUE );
00279          }
00280          return 0;
00281
00282 /**************************************************************\
00283 *     WM_KEYDOWN: Standard template                            *
00284 \**************************************************************/
00285
00286       case WM_KEYDOWN:
00287          switch( wParam ) {
00288             case VK_UP:
00289                SendMessage( hWnd, WM_VSCROLL, SB_LINEUP, 0L );
00290                break;
00291             case VK_DOWN:
00292                SendMessage( hWnd, WM_VSCROLL, SB_LINEDOWN, 0L );
00293                break;
00294             case VK_LEFT:
00295                SendMessage( hWnd, WM_HSCROLL, SB_LINEUP, 0L );
00296                break;
00297             case VK_RIGHT:
00298                SendMessage( hWnd, WM_HSCROLL, SB_LINEDOWN, 0L );
00299                break;
00300             case VK_PRIOR:
00301                SendMessage( hWnd, WM_VSCROLL, SB_PAGEUP, 0L );
00302                break;
00303             case VK_NEXT:
00304                SendMessage( hWnd, WM_VSCROLL, SB_PAGEDOWN, 0L );
00305                break;
00306          }
00307          return 0;
00308
00309 /**************************************************************\
00310 *     WM_PAINT: If a Metafile has been opened, the transform   *
00311 *        is applied using SetWorldTransform() and the Metafile *
00312 *        is displayed using PlayEnhMetaFile().                 *
00313 \**************************************************************/
00314
00315       case WM_PAINT:
00316          hDC = BeginPaint( hWnd, &ps );
00317
00318          if( bFileOpen ) {
00319             GetClientRect( hWnd, &rect );
00320             SetWorldTransform( hDC, &xForm );
00321             PlayEnhMetaFile( hDC, hEMF, &rect );
00322          }
00323
00324          EndPaint( hWnd, &ps );
00325          break;
00326
00327 /**************************************************************\
00328 *     WM_COMMAND: If Metafile.Open is selected, OpenMetafile   *
00329 *        and InvalidateRect() are called and the thumb         *
00330 *        position is centered. If Metafile.Exit is selected,   *
00331 *        a WM_CLOSE message is sent. If Scale is chosen, then  *
00332 *        the "Scale Image" dialog is displayed; if the user    *
00333 *        choses OK, then InvalidateRect() is called. If        *
00334 *        Help.About is chosen, then the "About" dialog box is  *
00335 *        displayed.                                            *
00336 \**************************************************************/
00337
00338       case WM_COMMAND:
00339          switch( wParam ) {
00340             case IDM_OPEN:
00341                if( OpenMetafile( hWnd ) ) {
00342                   SetWindowText( hWnd, OpenFileName.lpstrFile );
00343                   SetUnityXform( );
00344                   nHscrollPos = HSCROLLMAX/2;
00345                   nVscrollPos = VSCROLLMAX/2;
00346                   SetScrollPos( hWnd, SB_HORZ, nHscrollPos, TRUE );
00347                   SetScrollPos( hWnd, SB_VERT, nVscrollPos, TRUE );
00348
00349                   InvalidateRect( hWnd, NULL, TRUE );
00350                }
00351                break;
00352             case IDM_EXIT:
00353                SendMessage( hWnd, WM_CLOSE, 0, 0 );
00354                break;
00355             case IDM_SCALE:
00356                if( DialogBox( ghInstance, "ScaleDlg", hWnd,
00357                      (DLGPROC) ScaleDlgProc ) )
00358                   InvalidateRect( hWnd, NULL, TRUE );
00359                break;
00360             case IDM_ABOUT:
00361                DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
00362                              AboutDlgProc );
00363                break;
00364          }
00365          break;
00366
00367 /**************************************************************\
00368 *     WM_DESTROY: PostQuitMessage() is called                  *
00369 \**************************************************************/
00370
00371       case WM_DESTROY:
00372          PostQuitMessage( 0 );
00373          break;
00374
00375 /**************************************************************\
00376 *     Let the default window proc handle all other messages    *
00377 \**************************************************************/
00378
00379       default:
00380          return( DefWindowProc( hWnd, msg, wParam, lParam ));
00381    }
00382
00383    return 0;
00384 }
00385
00386
00387 /********************************************************************\
00388 * Function: BOOL CALLBACK ScaleDlgProc(HWND, UINT, WPARAM, LPARAM)   *
00389 *                                                                    *
00390 *  Purpose: Processes "Scale Image" Dialog Box Messages.             *
00391 *                                                                    *
00392 * Comments: The following messages are processed:                    *
00393 *                                                                    *
00394 *           WM_INITDIALOG                                            *
00395 *           WM_COMMAND                                               *
00396 *                                                                    *
00397 \********************************************************************/
00398
00399
00400 BOOL CALLBACK ScaleDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
00401 {
00402    char buffer[MAXINPUT];
00403    static char HorzInputBuf[MAXINPUT];
00404    static char VertInputBuf[MAXINPUT];
00405    int index;
00406
00407    switch( uMsg ) {
00408
00409 /**************************************************************\
00410 *     WM_INITDIALOG: Strings representing the possible scale   *
00411 *        factors are loaded into the comboboxes. The current   *
00412 *        selection is indicated.                               *
00413 \**************************************************************/
00414
00415       case WM_INITDIALOG:
00416          for( index=FIRSTSTRING; index <= LASTSTRING; index++ ) {
00417             LoadString( GetModuleHandle(NULL), index, buffer, MAXINPUT);
00418             SendDlgItemMessage( hDlg, IDC_HORZ, CB_ADDSTRING, 0,
00419                                  (LPARAM)buffer );
00420             SendDlgItemMessage( hDlg, IDC_VERT, CB_ADDSTRING, 0,
00421                                  (LPARAM)buffer );
00422          }
00423
00424          if( bFileJustOpen || !bFileOpen ) {
00425             lstrcpy( HorzInputBuf, " 1.0" );
00426             lstrcpy( VertInputBuf, " 1.0" );
00427             bFileJustOpen = FALSE;
00428          }
00429
00430          SendDlgItemMessage( hDlg, IDC_HORZ, CB_SELECTSTRING, 0,
00431                               (LPARAM)HorzInputBuf );
00432          SendDlgItemMessage( hDlg, IDC_VERT, CB_SELECTSTRING, 0,
00433                               (LPARAM)VertInputBuf );
00434          return TRUE;
00435
00436 /**************************************************************\
00437 *     WM_COMMAND: If the OK button is selected, the current    *
00438 *        horizontal and vertical scaling factors are obtained  *
00439 *        from the ComboBox and the transform is updated. If    *
00440 *        the CANCEL button is selected, EndDialog() is called. *
00441 \**************************************************************/
00442
00443       case WM_COMMAND:
00444          switch( wParam ) {
00445             case IDOK:
00446                index = SendDlgItemMessage( hDlg, IDC_HORZ, CB_GETCURSEL,
00447                                             0, 0 );
00448                LoadString( GetModuleHandle(NULL), index, HorzInputBuf,
00449                             MAXINPUT );
00450                xForm.eM11 = (FLOAT) atof( HorzInputBuf );
00451
00452                index = SendDlgItemMessage( hDlg, IDC_VERT, CB_GETCURSEL,
00453                                             0, 0 );
00454                LoadString( GetModuleHandle(NULL), index, VertInputBuf,
00455                             MAXINPUT );
00456                xForm.eM22 = (FLOAT) atof( VertInputBuf );
00457
00458                EndDialog( hDlg, TRUE );
00459                return TRUE;
00460             case IDCANCEL:
00461                EndDialog( hDlg, FALSE );
00462                return TRUE;
00463          }
00464          break;
00465    }
00466
00467    return FALSE;
00468 }
00469
00470
00471 /********************************************************************\
00472 * Function: BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)   *
00473 *                                                                    *
00474 *  Purpose: Processes "About" Dialog Box Messages                    *
00475 *                                                                    *
00476 * Comments: The Dialog Box is displayed when the user selects        *
00477 *           Help.About.                                              *
00478 *                                                                    *
00479 \********************************************************************/
00480
00481
00482 BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
00483 {
00484    switch( uMsg ) {
00485       case WM_INITDIALOG:
00486          return TRUE;
00487       case WM_COMMAND:
00488          switch( wParam ) {
00489             case IDOK:
00490                EndDialog( hDlg, TRUE );
00491                return TRUE;
00492          }
00493       break;
00494    }
00495
00496    return FALSE;
00497 }
00498
00499
00500 /********************************************************************\
00501 * Function: BOOL OpenMetafile( HWND )                                *
00502 *                                                                    *
00503 *  Purpose: Gets Metafile name and opens the Metafile                *
00504 *                                                                    *
00505 * Comments: Uses the Common Dialog GetOpenFileName() to prompt user  *
00506 *           for the name of the Metafile to be opened.  If the name  *
00507 *           is successfully retrieved, GetEnhMetaFile() is used to   *
00508 *           open the Metafile.                                       *
00509 *                                                                    *
00510 \********************************************************************/
00511
00512
00513 BOOL OpenMetafile( HWND hWnd )
00514 {
00515    szFile[0] = '\0';
00516    szFileTitle[0] = '\0';
00517    memset( (LPVOID) &OpenFileName, 0, sizeof( OPENFILENAME ));
00518
00519    OpenFileName.lStructSize = sizeof( OPENFILENAME );
00520    OpenFileName.hwndOwner = hWnd;
00521    OpenFileName.lpstrFilter = szFilter;
00522    OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
00523    OpenFileName.nMaxCustFilter = 0L;
00524    OpenFileName.nFilterIndex = 1L;
00525    OpenFileName.lpstrFile = szFile;
00526    OpenFileName.nMaxFile = sizeof( szFile );
00527    OpenFileName.lpstrFileTitle = szFileTitle;
00528    OpenFileName.nMaxFileTitle = sizeof( szFileTitle );
00529    OpenFileName.lpstrInitialDir = NULL;
00530    OpenFileName.lpstrTitle = "Open Metafile";
00531    OpenFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
00532    OpenFileName.nFileOffset = 0;
00533    OpenFileName.nFileExtension = 0;
00534    OpenFileName.lpstrDefExt = "*.EMF";
00535
00536    if( !GetOpenFileName( &OpenFileName ) )
00537       return FALSE;
00538
00539    hEMF = GetEnhMetaFile( OpenFileName.lpstrFile );
00540    bFileOpen = TRUE;
00541    bFileJustOpen = TRUE;
00542
00543    return TRUE;
00544 }
00545
00546
00547 /********************************************************************\
00548 * Function: void SetUnityXform( VOID )                               *
00549 *                                                                    *
00550 *  Purpose: Helper routine which sets the unity transform            *
00551 *                                                                    *
00552 * Comments: These fields have the following use in this application: *
00553 *                                                                    *
00554 *                  eM11: Horizontal Scaling Factor                   *
00555 *                  eM12: Not Used                                    *
00556 *                  eM21: Not Used                                    *
00557 *                  eM22: Vertical Scaling Factor                     *
00558 *                  eDx: Horizontal Translation                       *
00559 *                  eDy: Vertical Translation                         *
00560 *                                                                    *
00561 \********************************************************************/
00562
00563
00564 void SetUnityXform( )
00565 {
00566    xForm.eM11 = (FLOAT) 1.0;
00567    xForm.eM12 = (FLOAT) 0.0;
00568    xForm.eM21 = (FLOAT) 0.0;
00569    xForm.eM22 = (FLOAT) 1.0;
00570    xForm.eDx  = (FLOAT) 0.0;
00571    xForm.eDy  = (FLOAT) 0.0;
00572 }
Generated on Wed Nov 13 2024 17:29:10 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: THREADS/THREADS.C Source File

  • THREADS

THREADS.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /*************************************************************************\
00013 *  PROGRAM: Threads.c
00014 *
00015 *  PURPOSE:
00016 *
00017 *     To demonstrate suspending, resuming, and setting the priorities
00018 *     of threads.
00019 *
00020 *  FUNCTIONS:
00021 *
00022 *    WinMain()      - Initializes the window, and process the message loop.
00023 *    MainWndProc()  - Process messages, launches server & client threads.
00024 *    ThreadProc()   - Draws rectangles to the window, demonstrating the
00025 *                     threads performance.
00026 *
00027 *  COMMENTS:
00028 *
00029 *    To Use:
00030 *      When starting this application, two threads are created.  The
00031 *      first draws a green box, the second a red.  Both boxes are moved
00032 *      about the screen as their individual threads calculate a new
00033 *      position and redraws the box.  The user can Suspend either thread,
00034 *      Resume them, or change their priority through the menu selections.
00035 *      The colored boxes will respond accordingly.
00036 *
00037 *      Note through out the sample "red thread" or "green thread" are
00038 *      referred to.  This simply indicates the thread which draws either the
00039 *      red or green rectangle.
00040 *
00041 \*************************************************************************/
00042
00043
00044 #include <windows.h>
00045 #include <stdlib.h>
00046 #include <time.h>
00047 #include "threads.h"
00048
00049
00050 HANDLE hInst;
00051 HANDLE hWnd;
00052
00053 /*************************************************************************\
00054 *
00055 *  FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
00056 *
00057 *  PURPOSE: calls initialization function, processes message loop
00058 *
00059 *  COMMENTS:
00060 *
00061 \*************************************************************************/
00062 int PASCAL WinMain ( HINSTANCE hInstance,
00063                      HINSTANCE hPrevInstance,
00064                      LPSTR  lpCmdLine,
00065                      int    nCmdShow)
00066 {
00067   MSG  msg;
00068   WNDCLASS wc;
00069
00070   UNREFERENCED_PARAMETER( lpCmdLine );
00071   UNREFERENCED_PARAMETER( hPrevInstance );
00072
00073   // check if Win32s, if so, display notice and terminate
00074       if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) ==3)
00075       {
00076         MessageBox( NULL,
00077            "This application cannot run on Windows 3.1.\n"
00078            "This application will now terminate.",
00079            "Threads",
00080            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00081         return( 1 );
00082       }
00083
00084   hInst = hInstance;
00085
00086   wc.style = 0;                          // Replaces CS_SIZEREDRAW.
00087   wc.lpfnWndProc = (WNDPROC)MainWndProc; // The client window procedure.
00088   wc.cbClsExtra = 0;                     // No room reserved for extra data.
00089   wc.cbWndExtra = 0;
00090   wc.hInstance = hInstance;
00091   wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00092   wc.hCursor = LoadCursor (NULL, IDC_ARROW);
00093   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
00094   wc.lpszMenuName = "Thread_Menu";
00095   wc.lpszClassName = "ThreadsWClass";
00096
00097   RegisterClass(&wc);
00098
00099
00100   hWnd = CreateWindow ("ThreadsWClass",
00101                        "Threads Sample",
00102                        WS_OVERLAPPEDWINDOW,
00103                        CW_USEDEFAULT,
00104                        CW_USEDEFAULT,
00105                        CW_USEDEFAULT,
00106                        CW_USEDEFAULT,
00107                        NULL,
00108                        NULL,
00109                        hInstance,
00110                        NULL);
00111
00112
00113   ShowWindow(hWnd, nCmdShow);
00114   while (GetMessage (&msg, NULL, 0, 0))
00115     DispatchMessage (&msg);   // Dispatch message to window.
00116
00117   return (msg.wParam);           // Returns value from PostQuitMessage.
00118
00119 }
00120
00121 /*************************************************************************\
00122 *
00123 *  FUNCTION:  MainWndProc (HWND, UINT, WPARAM, LPARAM)
00124 *
00125 *  PURPOSE:   To process the windows messages.  This procedure totally
00126 *             controls the priority and suspension/resumption of the
00127 *             thread.
00128 *
00129 *  VARIABLES USED:
00130 *
00131 *    - hThread1, hThread2:
00132 *             Static handles to the two created threads.
00133 *
00134 *    - ThreadID1 ThreadID2:
00135 *             DWORDs used in the CreateThread call.
00136 *
00137 *    - pColor1, pColor2:
00138 *             DWORDs used to allocate some memory to use as a parameter
00139 *             to pass color values to the threads.  This memory was
00140 *             allocated so that the threads wouldn't have to rely on this
00141 *             procedures stack for the values.
00142 *
00143 *    - Buf[80]:
00144 *             Character buffer used to write messages to the user.
00145 *
00146 *    - RedSuspendCnt, GreenSuspendCnt:
00147 *             Static DWORDs used to track the count of suspension put
00148 *             on the specific thread.
00149 *
00150 *  MESSAGES:
00151 *
00152 *    WM_DESTROY:     - Terminates the threads and post the quit message.
00153 *    WM_CREATE:      - Allocates memory to hold some color values, and
00154 *                      creates the two threads.
00155 *    WM_COMMAND
00156 *
00157 *      IDM_SUSPEND***:
00158 *               Suspends the specified thread, updates the globally kept
00159 *               count (number of times the thread has been suspended),
00160 *               and then produces a message box telling the user the
00161 *               number of suspensions.
00162 *
00163 *      IDM_RESUME***:
00164 *               Resumes the specified thread, updates the gobally kept
00165 *               count (number of times the thread has been suspended),
00166 *               and then produces a message box telling the user the
00167 *               number of suspensions.
00168 *
00169 *      IDM_G***:
00170 *               These 7 messages use SetThreadPriority to set the
00171 *               priority of the Green Thread.
00172 *
00173 *      IDM_R***:
00174 *               These 7 messages use SetThreadPriority to set the
00175 *               priority of the Red Thread.
00176 *
00177 *  CALLED BY:
00178 *
00179 *    WinMain();
00180 *
00181 *  CALLS TO:
00182 *
00183 *    ThreadProc();
00184 *
00185 *  COMMENTS:
00186 *
00187 *
00188 \*************************************************************************/
00189
00190
00191 LRESULT CALLBACK MainWndProc (HWND hwnd,
00192                               UINT message,
00193                               WPARAM wParam,
00194                               LPARAM lParam)
00195 {
00196   static HANDLE hThread1, hThread2;
00197   DWORD  ThreadID1, ThreadID2;
00198   CHAR Buf[80];
00199   static DWORD RedSuspendCnt = 0;
00200   static DWORD GreenSuspendCnt = 0;
00201   static DWORD *pColor1, *pColor2;
00202
00203   switch (message)
00204       {
00205
00206         case WM_CREATE :
00207
00208           pColor1 = malloc(sizeof(DWORD));
00209           *pColor1 = GREEN;
00210           hThread1 = CreateThread (NULL, 0,
00211                                    (LPTHREAD_START_ROUTINE)ThreadProc,
00212                                    (LPVOID)pColor1, 0,
00213                                    (LPDWORD)&ThreadID1);
00214
00215           if (!hThread1)
00216             {
00217              wsprintf(Buf, "Error in creating Green thread: %d",
00218                       GetLastError());
00219              MessageBox (hwnd, Buf, "WM_CREATE", MB_OK);
00220             }
00221
00222           Sleep (500);             // Allow some time/distance between the
00223                                    // thread boxes.
00224
00225           pColor2 = malloc(sizeof(DWORD));
00226           *pColor2 = RED;
00227           hThread2 = CreateThread (NULL, 0,
00228                                    (LPTHREAD_START_ROUTINE)ThreadProc,
00229                                    (LPVOID)pColor2, 0,
00230                                    (LPDWORD)&ThreadID2);
00231           if (!hThread2)
00232             {
00233              wsprintf(Buf, "Error in creating Red thread: %d",
00234                       GetLastError());
00235              MessageBox (hwnd, Buf, "WM_CREATE", MB_OK);
00236             }
00237
00238
00239           return (0);
00240
00241         case WM_COMMAND:
00242           switch (LOWORD(wParam))
00243             {
00244             case IDM_SUSPENDGREEN:           // Suspends green thread.
00245               SuspendThread (hThread1);
00246               GreenSuspendCnt++;
00247               wsprintf(Buf, "The suspension count for the green thread is now %d",
00248                        GreenSuspendCnt);
00249               MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
00250               return (0);
00251
00252             case IDM_SUSPENDRED:             // Suspends red thread.
00253               SuspendThread (hThread2);
00254               RedSuspendCnt++;
00255               wsprintf(Buf, "The suspension count for the red thread is now %d",
00256                        RedSuspendCnt);
00257               MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
00258               return (0);
00259
00260             case IDM_RESUMEGREEN:            // Resumes green thread.
00261               ResumeThread (hThread1);
00262               if (GreenSuspendCnt > 0)
00263                 GreenSuspendCnt--;
00264               wsprintf(Buf, "The suspension count for the green thread is now %d",
00265                        GreenSuspendCnt);
00266               MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
00267               return (0);
00268
00269             case IDM_RESUMERED:              // Resumes red thread.
00270               ResumeThread (hThread2);
00271               if (RedSuspendCnt > 0)
00272                 RedSuspendCnt--;
00273               wsprintf(Buf, "The suspension count for the red thread is now %d",
00274                        RedSuspendCnt);
00275               MessageBox(hWnd, Buf, "Suspension Count", MB_OK);
00276               return (0);
00277
00278
00279             case IDM_GIDLE:                   // Sets green idle.
00280               SetThreadPriority (hThread1, THREAD_PRIORITY_IDLE);
00281               return (0);
00282
00283
00284             case IDM_GLOW:                   // Sets green lowest.
00285               SetThreadPriority (hThread1, THREAD_PRIORITY_LOWEST);
00286               return (0);
00287
00288             case IDM_GBNORM:                 // Sets green below normal.
00289               SetThreadPriority (hThread1, THREAD_PRIORITY_BELOW_NORMAL);
00290               return (0);
00291
00292             case IDM_GNORM:                  // Sets green to normal.
00293               SetThreadPriority (hThread1, THREAD_PRIORITY_NORMAL);
00294               return (0);
00295
00296             case IDM_GANORM:                 // Sets green above normal.
00297               SetThreadPriority (hThread1, THREAD_PRIORITY_ABOVE_NORMAL);
00298               return (0);
00299
00300             case IDM_GHIGH:                  // Sets green to highest.
00301               SetThreadPriority (hThread1, THREAD_PRIORITY_HIGHEST);
00302               return (0);
00303
00304             case IDM_GTC:                   // Sets green time critical.
00305               SetThreadPriority (hThread1, THREAD_PRIORITY_TIME_CRITICAL);
00306               return (0);
00307
00308
00309
00310
00311             case IDM_RIDLE:                   // Sets red idle.
00312               SetThreadPriority (hThread1, THREAD_PRIORITY_IDLE);
00313               return (0);
00314
00315             case IDM_RLOW:                   // Sets red to lowest possible
00316               SetThreadPriority (hThread2, THREAD_PRIORITY_LOWEST);
00317               return (0);
00318
00319             case IDM_RBNORM:                 // Sets red below normal.
00320               SetThreadPriority (hThread2, THREAD_PRIORITY_BELOW_NORMAL);
00321               return (0);
00322
00323             case IDM_RNORM:                  // Sets red to normal.
00324               SetThreadPriority (hThread2, THREAD_PRIORITY_NORMAL);
00325               return (0);
00326
00327             case IDM_RANORM:                 // Sets red above normal.
00328               SetThreadPriority (hThread2, THREAD_PRIORITY_ABOVE_NORMAL);
00329               return (0);
00330
00331             case IDM_RHIGH:                  // Sets red to highest.
00332               SetThreadPriority (hThread2, THREAD_PRIORITY_HIGHEST);
00333               return (0);
00334
00335             case IDM_RTC:                   // Sets green time critical.
00336               SetThreadPriority (hThread1, THREAD_PRIORITY_TIME_CRITICAL);
00337               return (0);
00338
00339             default:
00340               return (0);
00341
00342
00343             }
00344
00345         case WM_DESTROY :
00346             TerminateThread(hThread1, 0);
00347             TerminateThread(hThread2, 0);
00348             free (pColor1);
00349             free (pColor2);
00350             PostQuitMessage (0);
00351             return (0);
00352
00353        }
00354     return DefWindowProc (hwnd, message, wParam, lParam);
00355 }
00356
00357 /*************************************************************************\
00358 *
00359 *  FUNCTION:  ThreadProc (LPVOID)
00360 *
00361 *  PURPOSE:   A thread procedure which calculates position on the window
00362 *             and draws a colored rectangle.  The color of the rectangle
00363 *             is determined by the input parameter, it's border is
00364 *             always black (or whatever the pen color is); and since
00365 *             the window does not paint between rectangle draws, the
00366 *             rectangle leaves a black path in it's wake.
00367 *
00368 *  VARIABLES USED:
00369 *
00370 *    - horizontal, vertical:
00371 *             Local int used to indicate the next directional move the
00372 *             rectangle will make.
00373 *
00374 *    - ulx, uly:
00375 *             Local DWORD used for the Upper Left X corner and Upper
00376 *             Upper Left Y position of the rectangle.
00377 *
00378 *    - rect:  A RECT structure used to determin the current size of the
00379 *             window (in case the user resizes it).
00380 *
00381 *    - hdc:   HDC of the rectangle.
00382 *
00383 *    - Time:  A SYSTEMTIME structure.  It's milli-second field is used
00384 *             to create an apparent random starting point for the
00385 *             rectangles.
00386 *
00387 *    -hBrush: A handle to a Brush object, used to set the color of the
00388 *             rectangle.
00389 *
00390 *    -width, height:
00391 *             Local DWORDs used for the width and height of the rectangles.
00392 *
00393 *  CALLED BY:
00394 *
00395 *    MainWndProc();
00396 *
00397 \*************************************************************************/
00398
00399
00400 VOID ThreadProc ( LPVOID *Color)
00401 {
00402   int  horizontal, vertical;
00403   DWORD ulx, uly;
00404   RECT rect;
00405   HDC  hDC;
00406   SYSTEMTIME Time;
00407   HANDLE hBrush;
00408   DWORD width, height;
00409
00410   width =  10;
00411   height = 10;
00412
00413   GetSystemTime (&Time);                     // Get the time.
00414
00415   do{}while(!GetClientRect(hWnd, &rect));    // Loop, making sure window
00416                                              // exists.
00417
00418   ulx = (Time.wMilliseconds % rect.right);   // Use MOD to get a random
00419   uly = (Time.wMilliseconds % rect.bottom);  // position.
00420
00421   if(Time.wMilliseconds % 2 == 0)            // Use MOD to pick random
00422     {                                        // directions.
00423      horizontal = 1;
00424      vertical = 1;
00425     }
00426   else
00427     {
00428      horizontal = 1;
00429      vertical = -1;
00430     }
00431                                              // Set color as per input
00432                                              // parameter.
00433   hBrush = CreateSolidBrush((COLORREF)*Color);
00434
00435   do
00436     {                                        // do forever ...
00437      GetClientRect( hWnd, &rect);
00438
00439      if ( (ulx+width) > (DWORD)rect.right)   // ... check for right edge,
00440       {
00441       ulx = rect.right - width;
00442       horizontal = -1;                       //   ... if so change direction;
00443       }
00444
00445      if ((uly+height) > (DWORD)rect.bottom)  // ... check for bottom edge,
00446       {
00447       uly = rect.bottom - height;            //   ... if so change dir.
00448       vertical = -1;
00449       }
00450
00451      if (uly <= 1)                           // ... check for right edge,
00452       {
00453       uly = 1;
00454       vertical = 1;
00455       }
00456
00457      if (ulx <= 1)
00458       {                                      // ... check for top edge;
00459       ulx = 1;
00460       horizontal = 1;
00461       }
00462
00463      hDC = GetDC(hWnd);                      // ... Get DC,
00464      SelectObject( hDC, hBrush);             // ... Set brush color,
00465                                              // ... Draw rectangle,
00466      Rectangle (hDC, ulx, uly, ulx+width, uly+height);
00467      ReleaseDC(hWnd, hDC);                   // ... Release DC
00468      ulx += horizontal;                      // ... Increment/decrement
00469      uly += vertical;                        // ... position.
00470
00471     }while(1);
00472 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: STARTP/STARTP.C Source File

  • STARTP

STARTP.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /********************************************************************
00013 * This program demonstrates various CreateProcess parameters,       *
00014 * including starting processes in a given priority class. This is   *
00015 * very similar to the "start" command but with added functionality. *
00016 *                                                                   *
00017 * This program demonstrates the use of the following Win32 APIs:    *
00018 *   CreateProcess, TerminateProcess.                                *
00019 *                                                                   *
00020 * This program also uses the following Win32 APIs:                  *
00021 *   WaitForSingleObject GetLastError.                               *
00022 *                                                                   *
00023 * Execution instructions:                                           *
00024 *   see the help() function or run the program without any          *
00025 *   parameters to see detailed execution info.                      *
00026 *                                                                   *
00027 * Possible future enhancements:                                     *
00028 *   Handle cmd.exe internal commands                                *
00029 *                                                                   *
00030 * Version 1.0: NT 3.1 SDK release                                   *
00031 * Version 1.1: NT 3.5 SDK release                                   *
00032 *   Changes: added support for CREATE_SEPARATE_WOW_VDM,             *
00033 *   CREATE_UNICODE_ENVIRONMENT, and CREATE_NEW_PROCESS_GROUP        *
00034 * Version 1.2: NT & Windows 95 SDK release          *
00035 *   Changes updated documentation, added support for SW_HIDE        *
00036 ********************************************************************/
00037
00038 #include <windows.h>
00039 #include <string.h>
00040 #include <stdio.h>
00041 #include <stdlib.h>
00042
00043 /* Standard error macro for reporting API errors */
00044 #define PERR(bSuccess, api) {if (!(bSuccess)) printf("%s: Error %d from %s \
00045     on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
00046
00047 void help()
00048 {
00049   puts("Starts a specified program, batch, or command file.");
00050   puts("STARTP [options] [program] [parameters]\n");
00051   puts("  /Ttitle        Title to display in window title bar. Quote the");
00052   puts("             entire paramter to include spaces in the title");
00053   puts("  /Dpath         Starting directory");
00054   puts("  /l|/h|/r       Set priority to low/high/realtime");
00055   puts("  /min|/max|/hid Start window minimized/maximized/hidden");
00056   puts("  /w             Wait for started process to end before returning");
00057   puts("                 control to the command processor. This option starts");
00058   puts("                 the process synchronously");
00059   puts("  /c             Use current console instead of creating a new console");
00060   puts("  /b             Start detached with no console at all");
00061   puts("  /p             Create new process group for ^c, ^break events");
00062   puts("  /s             Windows NT: Run Win16 app in separate VDM ");
00063   puts("  program        A batch file or program to run as either a GUI");
00064   puts("                 application or a console application");
00065   puts("  parameters     These are the parameters passed to the program");
00066   puts("\nNote that the priority parameters may have no effect if the child");
00067   puts("process changes its own priority.");
00068   exit(1);
00069 }
00070
00071 int main(int argc, char *argv[])
00072 {
00073   char szArgs[512], *p;  /* new process arguments buffer & temp pointer */
00074   char szPgmName[MAX_PATH];  /* name of the program */
00075   BOOL fSuccess;  /* API return code */
00076   STARTUPINFO si;  /* used for CreateProcess */
00077   PROCESS_INFORMATION pi;  /* used for CreateProcess */
00078   LPSTR lpszCurDir = NULL;  /* current directory for new process */
00079   BOOL bMoreParams;  /* flag end of new process parameter processing */
00080   BOOL bWait = FALSE;  /* wait/no wait for new process to end */
00081   DWORD dwResult;  /* API return code */
00082   DWORD dwCreate = CREATE_NEW_CONSOLE;  /* new process creation flags */
00083   BOOL bExtension;  /* input filename have an explicit extension? */
00084   int i;
00085   /* the following filename extensions must all be 4 chars long */
00086   char *aExt[] = { ".exe", ".com", ".bat", ".cmd" };
00087   DWORD dwExitCode;
00088   DWORD dwVersion = GetVersion();
00089
00090   /* Check to make sure we are running on Windows NT or Windows 95 */
00091   if( !(dwVersion < 0x80000000) && (LOBYTE(LOWORD(dwVersion)) < 4) )
00092     {
00093     MessageBox( NULL,
00094        "This application cannot run on Windows 3.1.\n"
00095        "This application will now terminate.",
00096        "StartP",
00097        MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00098     return(1);
00099     }
00100   /* process all command-line parameters */
00101   if (argc < 2)
00102     help();
00103   memset(&si, 0, sizeof(STARTUPINFO));
00104   bMoreParams = TRUE;
00105   while(bMoreParams)
00106     {
00107     argv++;  /* point to the first parameter */
00108     if (!*argv) /* if *argv is NULL we're missing the program name! */
00109       {
00110       puts("Error: missing program name");
00111       exit(1);
00112       }
00113     if ((*argv)[0] == '/' || (*argv)[0] == '-')
00114       {
00115       strlwr(*argv);
00116       switch ((*argv)[1])  /* letter after the '/' or '-' */
00117         {
00118         case 't':
00119           si.lpTitle = &(*argv)[2];  /*  /Ttitle */
00120           break;
00121         case 'd':
00122           lpszCurDir = &(*argv)[2];  /*  /Dpath */
00123           break;
00124         case 'h':
00125       switch ((*argv)[2])
00126         {
00127       case '\0':
00128             dwCreate |= HIGH_PRIORITY_CLASS;
00129             break;
00130           case 'i':
00131             si.wShowWindow = SW_HIDE;
00132             si.dwFlags |= STARTF_USESHOWWINDOW;
00133       break;
00134             default:
00135               printf("Error: invalid switch - \"%s\"", *argv);
00136               help();
00137             } /* switch */
00138       break;
00139         case 'l':
00140           dwCreate |= IDLE_PRIORITY_CLASS;
00141           break;
00142         case 'r':
00143           dwCreate |= REALTIME_PRIORITY_CLASS;
00144           break;
00145         case 'm':
00146           switch ((*argv)[2])
00147             {
00148             case 'i':
00149               si.wShowWindow = SW_SHOWMINNOACTIVE;
00150               si.dwFlags |= STARTF_USESHOWWINDOW;
00151               break;
00152             case 'a':
00153               si.wShowWindow = SW_SHOWMAXIMIZED;
00154               si.dwFlags |= STARTF_USESHOWWINDOW;
00155               break;
00156             default:
00157               printf("Error: invalid switch - \"%s\"", *argv);
00158               help();
00159             } /* switch */
00160           break;
00161         case '?':
00162           help();  /* help() will terminate app */
00163         case 'w':
00164           bWait = TRUE;  /* don't end until new process ends as well */
00165           break;
00166         case 'b':
00167           dwCreate |= DETACHED_PROCESS;  /* start detached */
00168           /* detached implies no CREATE_NEW_CONSOLE so fall through */
00169         case 'c':
00170           dwCreate &= ~CREATE_NEW_CONSOLE;  /* turn off this bit */
00171           break;
00172         case 'p':
00173           dwCreate |= CREATE_NEW_PROCESS_GROUP;
00174           break;
00175         case 's':
00176           dwCreate |= CREATE_SEPARATE_WOW_VDM;
00177           break;
00178         case 'u':
00179           dwCreate |= CREATE_UNICODE_ENVIRONMENT;
00180           break;
00181         default:
00182           printf("Error: invalid switch - \"%s\"", *argv);
00183           help();
00184         } /* switch */
00185       } /* if */
00186     else  /* not a '-' or '/', must be the program name */
00187       bMoreParams = FALSE;
00188     } /* while */
00189   strcpy(szPgmName, *argv++);  /* copy program name as first param */
00190   bExtension = (BOOL) strchr(szPgmName, '.');  /* has an extension? */
00191   if (!bExtension)
00192     strcat(szPgmName, aExt[0]);  /* first extension to try */
00193   memset(szArgs, 0, sizeof(szArgs));
00194   strcpy(szArgs, szPgmName);  /* first arg: program name */
00195   p = strchr(szArgs, 0);  /* point past program name */
00196   while (*argv)  /* copy remaining arguments to szArgs separated by spaces */
00197     {
00198     strcat(p, " ");
00199     strcat(p, *argv++);
00200     }
00201   si.cb = sizeof(STARTUPINFO);
00202   i = 1;
00203   do
00204     {
00205     fSuccess = CreateProcess(NULL,  /* image file name */
00206         szArgs,  /* command line (including program name) */
00207         NULL,  /* security for process */
00208         NULL,  /* security for main thread */
00209         FALSE,  /* new process inherits handles? */
00210         dwCreate,  /* creation flags */
00211         NULL,  /* environment */
00212         lpszCurDir,  /* new current directory */
00213         &si,  /* STARTUPINFO structure */
00214         &pi);  /* PROCESS_INFORMATION structure */
00215     if (!fSuccess)
00216       switch (GetLastError())  /* process common errors */
00217         {
00218         case ERROR_FILE_NOT_FOUND:
00219           if (bExtension || i > 3)
00220             {
00221             puts("Error: program or batch file not found");
00222             exit(1);
00223             }
00224           else /* replace the filename extension with the next one */
00225             {
00226             strcpy(strchr(szPgmName, '.'), aExt[i++]);
00227             strncpy(szArgs, szPgmName, strlen(szPgmName));
00228             }
00229           break;
00230         case ERROR_DIRECTORY:
00231           puts("Error: bad starting directory");
00232           exit(1);
00233         case ERROR_PATH_NOT_FOUND:
00234           puts("Error: bad path");
00235           exit(1);
00236         default:
00237           PERR(0, "CreateProcess");
00238           exit(1);
00239         }  /* switch */
00240     } while (!fSuccess);
00241   /* pi.dwProcessId for win16 apps is actually an event handle, not */
00242   /* a process handle, so it can only be used with synchronization APIs */
00243   printf("Process %d (0x%x) created\n", pi.dwProcessId, pi.dwProcessId);
00244   /* close thread handle if not needed anymore */
00245   CloseHandle(pi.hThread);
00246   if (bWait)  /* /w flag specified? */
00247     {
00248     dwResult = WaitForSingleObject(pi.hProcess,  /* object to wait for */
00249         (DWORD) -1);  /* timeout time */
00250     PERR(dwResult != -1, "WaitForSingleObject");
00251     /* get and report the child's exit code */
00252     fSuccess = GetExitCodeProcess(pi.hProcess, &dwExitCode);
00253     PERR(fSuccess, "GetExitCodeProcess");
00254     printf("Child exit code: %d\n", dwExitCode);
00255     }
00256   CloseHandle(pi.hProcess);  /* close process handle or it won't die */
00257   return(0);
00258 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/GLTHREAD.H Source File

  • GLTHREAD

GLTHREAD.H

Go to the documentation of this file.
00001
00002 #include "glos.h"
00003 #include <gl\gl.h>
00004 #include <gl\glu.h>
00005 #include "resource.h"
00006
00007 // Function proto-types
00008 GLvoid initialize(HWND);
00009 GLvoid draw_scene(HWND);
00010 GLvoid resize(HWND);
00011 BOOL bSetupPixelFormat(HDC);
00012 GLvoid ThreadFunc1(void);
00013 GLvoid ThreadFunc2(void);
00014 GLvoid DrawWave(GLfloat fHeight, GLfloat fWidth, GLfloat fHorizon);
00015 GLfloat solve(GLfloat x, GLfloat z, GLfloat h, GLfloat w);
00016 GLvoid CalculateVectorNormal(GLfloat fVert1[], GLfloat fVert2[], GLfloat fVert3[],
00017                              GLfloat *fNormalX, GLfloat *fNormalY, GLfloat *fNormalZ);
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOCALE/LOCALE.H Source File

  • LOCALE

LOCALE.H

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /* locale.h - header file for the locale sample. */
00013
00014
00015 /* function prototypes.  Window procedures first. */
00016 LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
00017
00018
00019 #define MAXTCHAR 100
00020
00021
00022 /* the control ID's from the dialog box. */
00023 #define DID_LISTBOX     100
00024 #define DID_COMBOBOX    101
00025 #define DID_TEXT        102
00026
00027
00028 /* Define a value for the LOGFONT.lfCharSet
00029  *  This should be included in wingdi.h, but it
00030  *  was removed because the font mapper is not
00031  *  using it anyway in version 1.0.  Currently
00032  *  scheduled to be included in NT ver 1.1.
00033  */
00034 #define UNICODE_CHARSET  1
00035
00036
00037 /* structure for the lookup tables.  */
00038 typedef struct tagLookupEntry{
00039     int     Value;
00040     TCHAR    String[MAXTCHAR];
00041 } LookupEntry;
00042
00043
00044
00045 /* from WINNLS.H */
00046 #define NLANG 39
00047 LookupEntry  langstrings[NLANG] =
00048 {{ MAKELANGID (LANG_NEUTRAL       , SUBLANG_NEUTRAL)                , TEXT("NEUTRAL                ")},
00049  { MAKELANGID (LANG_CHINESE       , SUBLANG_CHINESE_SIMPLIFIED )    , TEXT("CHINESE,SIMPLIFIED     ")},
00050  { MAKELANGID (LANG_CHINESE       , SUBLANG_CHINESE_TRADITIONAL)    , TEXT("CHINESE,TRADITIONAL    ")},
00051  { MAKELANGID (LANG_CZECH         , SUBLANG_NEUTRAL)                , TEXT("CZECH                  ")},
00052  { MAKELANGID (LANG_DANISH        , SUBLANG_NEUTRAL)                , TEXT("DANISH                 ")},
00053  { MAKELANGID (LANG_DUTCH         , SUBLANG_DUTCH        )          , TEXT("DUTCH                  ")},
00054  { MAKELANGID (LANG_DUTCH         , SUBLANG_DUTCH_BELGIAN)          , TEXT("DUTCH,BELGIAN          ")},
00055  { MAKELANGID (LANG_ENGLISH       , SUBLANG_ENGLISH_US )            , TEXT("ENGLISH,US             ")},
00056  { MAKELANGID (LANG_ENGLISH       , SUBLANG_ENGLISH_UK )            , TEXT("ENGLISH,UK             ")},
00057  { MAKELANGID (LANG_ENGLISH       , SUBLANG_ENGLISH_AUS)            , TEXT("ENGLISH,AUS            ")},
00058  { MAKELANGID (LANG_ENGLISH       , SUBLANG_ENGLISH_CAN)            , TEXT("ENGLISH,CAN            ")},
00059  { MAKELANGID (LANG_ENGLISH       , SUBLANG_ENGLISH_NZ )            , TEXT("ENGLISH,NZ             ")},
00060  { MAKELANGID (LANG_FINNISH       , SUBLANG_NEUTRAL)                , TEXT("FINNISH                ")},
00061  { MAKELANGID (LANG_FRENCH        , SUBLANG_FRENCH         )        , TEXT("FRENCH                 ")},
00062  { MAKELANGID (LANG_FRENCH        , SUBLANG_FRENCH_BELGIAN )        , TEXT("FRENCH,BELGIAN         ")},
00063  { MAKELANGID (LANG_FRENCH        , SUBLANG_FRENCH_CANADIAN)        , TEXT("FRENCH,CANADIAN        ")},
00064  { MAKELANGID (LANG_FRENCH        , SUBLANG_FRENCH_SWISS   )        , TEXT("FRENCH,SWISS           ")},
00065  { MAKELANGID (LANG_GERMAN        , SUBLANG_GERMAN         )        , TEXT("GERMAN                 ")},
00066  { MAKELANGID (LANG_GERMAN        , SUBLANG_GERMAN_SWISS   )        , TEXT("GERMAN,SWISS           ")},
00067  { MAKELANGID (LANG_GERMAN        , SUBLANG_GERMAN_AUSTRIAN)        , TEXT("GERMAN,AUSTRIAN        ")},
00068  { MAKELANGID (LANG_GREEK         , SUBLANG_NEUTRAL)                , TEXT("GREEK                  ")},
00069  { MAKELANGID (LANG_HUNGARIAN     , SUBLANG_NEUTRAL)                , TEXT("HUNGARIAN              ")},
00070  { MAKELANGID (LANG_ICELANDIC     , SUBLANG_NEUTRAL)                , TEXT("ICELANDIC              ")},
00071  { MAKELANGID (LANG_ITALIAN       , SUBLANG_ITALIAN      )          , TEXT("ITALIAN                ")},
00072  { MAKELANGID (LANG_ITALIAN       , SUBLANG_ITALIAN_SWISS)          , TEXT("ITALIAN,SWISS          ")},
00073  { MAKELANGID (LANG_JAPANESE      , SUBLANG_NEUTRAL)                , TEXT("JAPANESE               ")},
00074  { MAKELANGID (LANG_KOREAN        , SUBLANG_NEUTRAL)                , TEXT("KOREAN                 ")},
00075  { MAKELANGID (LANG_NORWEGIAN     , SUBLANG_NORWEGIAN_BOKMAL )      , TEXT("NORWEGIAN,BOKMAL       ")},
00076  { MAKELANGID (LANG_NORWEGIAN     , SUBLANG_NORWEGIAN_NYNORSK)      , TEXT("NORWEGIAN,NYNORSK      ")},
00077  { MAKELANGID (LANG_POLISH        , SUBLANG_NEUTRAL)                , TEXT("POLISH                 ")},
00078  { MAKELANGID (LANG_PORTUGUESE    , SUBLANG_PORTUGUESE          )   , TEXT("PORTUGUESE             ")},
00079  { MAKELANGID (LANG_PORTUGUESE    , SUBLANG_PORTUGUESE_BRAZILIAN)   , TEXT("PORTUGUESE,BRAZILIAN   ")},
00080  { MAKELANGID (LANG_RUSSIAN       , SUBLANG_NEUTRAL)                , TEXT("RUSSIAN                ")},
00081  { MAKELANGID (LANG_SLOVAK        , SUBLANG_NEUTRAL)                , TEXT("SLOVAK                 ")},
00082  { MAKELANGID (LANG_SPANISH       , SUBLANG_SPANISH        )        , TEXT("SPANISH                ")},
00083  { MAKELANGID (LANG_SPANISH       , SUBLANG_SPANISH_MEXICAN)        , TEXT("SPANISH,MEXICAN        ")},
00084  { MAKELANGID (LANG_SPANISH       , SUBLANG_SPANISH_MODERN )        , TEXT("SPANISH,MODERN         ")},
00085  { MAKELANGID (LANG_SWEDISH       , SUBLANG_NEUTRAL)                , TEXT("SWEDISH                ")},
00086  { MAKELANGID (LANG_TURKISH    , SUBLANG_NEUTRAL)           , TEXT("TURKISH                ")}};
00087
00088
00089
00090 #define NLOCALEENTRIES 89
00091 LookupEntry  localeentry[NLOCALEENTRIES] =
00092 {{  LOCALE_ILANGUAGE         , TEXT("ILANGUAGE         ")},
00093  {  LOCALE_SLANGUAGE         , TEXT("SLANGUAGE         ")},
00094  {  LOCALE_SENGLANGUAGE      , TEXT("SENGLANGUAGE      ")},
00095  {  LOCALE_SABBREVLANGNAME   , TEXT("SABBREVLANGNAME   ")},
00096  {  LOCALE_SNATIVELANGNAME   , TEXT("SNATIVELANGNAME   ")},
00097  {  LOCALE_ICOUNTRY          , TEXT("ICOUNTRY          ")},
00098  {  LOCALE_SCOUNTRY          , TEXT("SCOUNTRY          ")},
00099  {  LOCALE_SENGCOUNTRY       , TEXT("SENGCOUNTRY       ")},
00100  {  LOCALE_SABBREVCTRYNAME   , TEXT("SABBREVCTRYNAME   ")},
00101  {  LOCALE_SNATIVECTRYNAME   , TEXT("SNATIVECTRYNAME   ")},
00102  {  LOCALE_IDEFAULTLANGUAGE  , TEXT("IDEFAULTLANGUAGE  ")},
00103  {  LOCALE_IDEFAULTCOUNTRY   , TEXT("IDEFAULTCOUNTRY   ")},
00104  {  LOCALE_IDEFAULTCODEPAGE  , TEXT("IDEFAULTCODEPAGE  ")},
00105  {  LOCALE_SLIST             , TEXT("SLIST             ")},
00106  {  LOCALE_IMEASURE          , TEXT("IMEASURE          ")},
00107  {  LOCALE_SDECIMAL          , TEXT("SDECIMAL          ")},
00108  {  LOCALE_STHOUSAND         , TEXT("STHOUSAND         ")},
00109  {  LOCALE_SGROUPING         , TEXT("SGROUPING         ")},
00110  {  LOCALE_IDIGITS           , TEXT("IDIGITS           ")},
00111  {  LOCALE_ILZERO            , TEXT("ILZERO            ")},
00112  {  LOCALE_SNATIVEDIGITS     , TEXT("SNATIVEDIGITS     ")},
00113  {  LOCALE_SCURRENCY         , TEXT("SCURRENCY         ")},
00114  {  LOCALE_SINTLSYMBOL       , TEXT("SINTLSYMBOL       ")},
00115  {  LOCALE_SMONDECIMALSEP    , TEXT("SMONDECIMALSEP    ")},
00116  {  LOCALE_SMONTHOUSANDSEP   , TEXT("SMONTHOUSANDSEP   ")},
00117  {  LOCALE_SMONGROUPING      , TEXT("SMONGROUPING      ")},
00118  {  LOCALE_ICURRDIGITS       , TEXT("ICURRDIGITS       ")},
00119  {  LOCALE_IINTLCURRDIGITS   , TEXT("IINTLCURRDIGITS   ")},
00120  {  LOCALE_ICURRENCY         , TEXT("ICURRENCY         ")},
00121  {  LOCALE_INEGCURR          , TEXT("INEGCURR          ")},
00122  {  LOCALE_SDATE             , TEXT("SDATE             ")},
00123  {  LOCALE_STIME             , TEXT("STIME             ")},
00124  {  LOCALE_SSHORTDATE        , TEXT("SSHORTDATE        ")},
00125  {  LOCALE_SLONGDATE         , TEXT("SLONGDATE         ")},
00126  {  LOCALE_IDATE             , TEXT("IDATE             ")},
00127  {  LOCALE_ILDATE            , TEXT("ILDATE            ")},
00128  {  LOCALE_ITIME             , TEXT("ITIME             ")},
00129  {  LOCALE_ICENTURY          , TEXT("ICENTURY          ")},
00130  {  LOCALE_ITLZERO           , TEXT("ITLZERO           ")},
00131  {  LOCALE_IDAYLZERO         , TEXT("IDAYLZERO         ")},
00132  {  LOCALE_IMONLZERO         , TEXT("IMONLZERO         ")},
00133  {  LOCALE_S1159             , TEXT("S1159             ")},
00134  {  LOCALE_S2359             , TEXT("S2359             ")},
00135  {  LOCALE_SDAYNAME1         , TEXT("SDAYNAME1         ")},
00136  {  LOCALE_SDAYNAME2         , TEXT("SDAYNAME2         ")},
00137  {  LOCALE_SDAYNAME3         , TEXT("SDAYNAME3         ")},
00138  {  LOCALE_SDAYNAME4         , TEXT("SDAYNAME4         ")},
00139  {  LOCALE_SDAYNAME5         , TEXT("SDAYNAME5         ")},
00140  {  LOCALE_SDAYNAME6         , TEXT("SDAYNAME6         ")},
00141  {  LOCALE_SDAYNAME7         , TEXT("SDAYNAME7         ")},
00142  {  LOCALE_SABBREVDAYNAME1   , TEXT("SABBREVDAYNAME1   ")},
00143  {  LOCALE_SABBREVDAYNAME2   , TEXT("SABBREVDAYNAME2   ")},
00144  {  LOCALE_SABBREVDAYNAME3   , TEXT("SABBREVDAYNAME3   ")},
00145  {  LOCALE_SABBREVDAYNAME4   , TEXT("SABBREVDAYNAME4   ")},
00146  {  LOCALE_SABBREVDAYNAME5   , TEXT("SABBREVDAYNAME5   ")},
00147  {  LOCALE_SABBREVDAYNAME6   , TEXT("SABBREVDAYNAME6   ")},
00148  {  LOCALE_SABBREVDAYNAME7   , TEXT("SABBREVDAYNAME7   ")},
00149  {  LOCALE_SMONTHNAME1       , TEXT("SMONTHNAME1       ")},
00150  {  LOCALE_SMONTHNAME2       , TEXT("SMONTHNAME2       ")},
00151  {  LOCALE_SMONTHNAME3       , TEXT("SMONTHNAME3       ")},
00152  {  LOCALE_SMONTHNAME4       , TEXT("SMONTHNAME4       ")},
00153  {  LOCALE_SMONTHNAME5       , TEXT("SMONTHNAME5       ")},
00154  {  LOCALE_SMONTHNAME6       , TEXT("SMONTHNAME6       ")},
00155  {  LOCALE_SMONTHNAME7       , TEXT("SMONTHNAME7       ")},
00156  {  LOCALE_SMONTHNAME8       , TEXT("SMONTHNAME8       ")},
00157  {  LOCALE_SMONTHNAME9       , TEXT("SMONTHNAME9       ")},
00158  {  LOCALE_SMONTHNAME10      , TEXT("SMONTHNAME10      ")},
00159  {  LOCALE_SMONTHNAME11      , TEXT("SMONTHNAME11      ")},
00160  {  LOCALE_SMONTHNAME12      , TEXT("SMONTHNAME12      ")},
00161  {  LOCALE_SABBREVMONTHNAME1 , TEXT("SABBREVMONTHNAME1 ")},
00162  {  LOCALE_SABBREVMONTHNAME2 , TEXT("SABBREVMONTHNAME2 ")},
00163  {  LOCALE_SABBREVMONTHNAME3 , TEXT("SABBREVMONTHNAME3 ")},
00164  {  LOCALE_SABBREVMONTHNAME4 , TEXT("SABBREVMONTHNAME4 ")},
00165  {  LOCALE_SABBREVMONTHNAME5 , TEXT("SABBREVMONTHNAME5 ")},
00166  {  LOCALE_SABBREVMONTHNAME6 , TEXT("SABBREVMONTHNAME6 ")},
00167  {  LOCALE_SABBREVMONTHNAME7 , TEXT("SABBREVMONTHNAME7 ")},
00168  {  LOCALE_SABBREVMONTHNAME8 , TEXT("SABBREVMONTHNAME8 ")},
00169  {  LOCALE_SABBREVMONTHNAME9 , TEXT("SABBREVMONTHNAME9 ")},
00170  {  LOCALE_SABBREVMONTHNAME10, TEXT("SABBREVMONTHNAME10")},
00171  {  LOCALE_SABBREVMONTHNAME11, TEXT("SABBREVMONTHNAME11")},
00172  {  LOCALE_SABBREVMONTHNAME12, TEXT("SABBREVMONTHNAME12")},
00173  {  LOCALE_SPOSITIVESIGN     , TEXT("SPOSITIVESIGN     ")},
00174  {  LOCALE_SNEGATIVESIGN     , TEXT("SNEGATIVESIGN     ")},
00175  {  LOCALE_IPOSSIGNPOSN      , TEXT("IPOSSIGNPOSN      ")},
00176  {  LOCALE_INEGSIGNPOSN      , TEXT("INEGSIGNPOSN      ")},
00177  {  LOCALE_IPOSSYMPRECEDES   , TEXT("IPOSSYMPRECEDES   ")},
00178  {  LOCALE_IPOSSEPBYSPACE    , TEXT("IPOSSEPBYSPACE    ")},
00179  {  LOCALE_INEGSYMPRECEDES   , TEXT("INEGSYMPRECEDES   ")},
00180  {  LOCALE_INEGSEPBYSPACE    , TEXT("INEGSEPBYSPACE    ")}} ;
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: LOCALE/LOCALE.C Source File

  • LOCALE

LOCALE.C

Go to the documentation of this file.
00001
00002 /******************************************************************************\
00003 *       This is a part of the Microsoft Source Code Samples.
00004 *       Copyright (C) 1992-1996 Microsoft Corporation.
00005 *       All rights reserved.
00006 *       This source code is only intended as a supplement to
00007 *       Microsoft Development Tools and/or WinHelp documentation.
00008 *       See these sources for detailed information regarding the
00009 *       Microsoft samples programs.
00010 \******************************************************************************/
00011
00012 /**************************************************************************\
00013 *  locale.c -- sample program demonstrating the locale... APIs
00014 *
00015 *  In this sample the main window is a dialog box.  There is no need to
00016 *   register a new window class or create a new window.  Instead just call
00017 *   DialogBox() and use the template defined in the .RC file.  All of the
00018 *   interesting code is thus in the window procedure for the dialog box.
00019 *   In this case, simply respond to the combobox command messsages and fill
00020 *   the list box with appropriate values.
00021 *
00022 \**************************************************************************/
00023
00024 #define UNICODE
00025
00026
00027 #include <windows.h>
00028 #include "locale.h"
00029
00030
00031 /**************************************************************************\
00032 *
00033 *  function:  WinMain()
00034 *
00035 *  input parameters:  c.f. generic sample
00036 *
00037 \**************************************************************************/
00038 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00039                      LPSTR lpCmdLine, int nCmdShow)
00040 {
00041 int ret;
00042
00043     UNREFERENCED_PARAMETER( hPrevInstance );
00044     UNREFERENCED_PARAMETER( lpCmdLine );
00045     UNREFERENCED_PARAMETER( nCmdShow);
00046
00047 // check if running on Windows NT, if not, display notice and terminate
00048     if( GetVersion() & 0x80000000 )
00049     {
00050        MessageBoxA( NULL,
00051            "This sample application can only be run on Windows NT.\n"
00052            "This application will now terminate.",
00053            "Locale",
00054            MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00055         return( 1 );
00056     }
00057
00058     ret = DialogBox (hInstance, TEXT("localeDlg"), NULL, (DLGPROC)MainDlgProc);
00059     return ret;
00060 }
00061
00062
00063
00064 /**************************************************************************\
00065 *
00066 *  function:  MainDlgProc()
00067 *
00068 *  input parameters:  standard window procedure parameters.
00069 *
00070 \**************************************************************************/
00071 LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00072 {
00073   int i;
00074   TCHAR buffer[MAXTCHAR];
00075
00076   UNREFERENCED_PARAMETER(lParam);
00077
00078
00079   switch (message) {
00080
00081     /********************************************************************\
00082     * WM_INITDIALOG
00083     *
00084     * Fill the combobox with the language, sublanguage pairs.
00085     *
00086     \********************************************************************/
00087     case WM_INITDIALOG:
00088
00089       /* fill up the combobox with the possible input values to
00090        *  GetLocaleInfoW().  The strings are in a lookup table
00091        *  in the file locale.h
00092        */
00093       for (i = 0; i < NLANG; i++) {
00094
00095         SendDlgItemMessage (hwnd, DID_COMBOBOX, CB_ADDSTRING, 0,
00096             (LPARAM)langstrings[i].String);
00097       }
00098
00099       /* Attempt to create a unicode font for the listbox with the
00100        *  same size as the default system font.  This will work well
00101        *  if the uclucida.ttf font was installed with the control panel.
00102        *  If not, then some of the characters in the strings returned
00103        *  by GetLocaleInfoW() will be displayed as the 'missing' font glyph.
00104        */
00105       { HFONT   hfont;
00106         LOGFONT  logfont;
00107
00108         GetObject (GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &logfont);
00109         logfont.lfCharSet = UNICODE_CHARSET;
00110         wsprintf (logfont.lfFaceName, TEXT("Lucida Sans Unicode"));
00111         hfont = CreateFontIndirect (&logfont);
00112         SendDlgItemMessage (hwnd, DID_LISTBOX, WM_SETFONT, (WPARAM) hfont, 0);
00113       }
00114     return 0;
00115
00116
00117     /********************************************************************\
00118     * WM_SYSCOMMAND
00119     *
00120     * ignore all syscommand messages, except for SC_CLOSE.
00121     *  on this one, call EndDialog().
00122     \********************************************************************/
00123     case WM_SYSCOMMAND:
00124       if (wParam == SC_CLOSE) {
00125         EndDialog (hwnd, TRUE);
00126         return TRUE;
00127       } else
00128         return FALSE;
00129     break;
00130
00131
00132
00133     /********************************************************************\
00134     * WM_COMMAND
00135     *
00136     * When the different languages are selected, clear the list box,
00137     *  then fill it up again with the new information.
00138     *
00139     \********************************************************************/
00140     case WM_COMMAND:
00141       if ((HIWORD(wParam) == CBN_SELCHANGE) && (LOWORD(wParam) == DID_COMBOBOX)) {
00142         int iSel;
00143         TCHAR linfo[MAXTCHAR];
00144
00145         iSel = SendMessage ((HWND) lParam, CB_GETCURSEL, 0,0);
00146         SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0, 0);
00147
00148         for (i = 0; i < NLOCALEENTRIES; i++) {
00149           linfo[0] = 0;
00150           GetLocaleInfoW (MAKELCID( langstrings[iSel].Value, 0 ),
00151                   localeentry[i].Value, linfo, MAXTCHAR);
00152
00153           wsprintf (buffer, TEXT("%s \t %s"), localeentry[i].String, linfo);
00154
00155           SendDlgItemMessage (hwnd, DID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)buffer);
00156         }
00157
00158       }
00159     break; /* end WM_COMMAND */
00160
00161
00162     default: return FALSE;
00163   } /* end switch(message) */
00164 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: GLTHREAD/THREADS.C Source File

  • GLTHREAD

THREADS.C

Go to the documentation of this file.
00001 //****************************************************************************
00002 // File: glthread.c
00003 //
00004 // Purpose: Contains code to set up the pixel format and initialize OpenGL.
00005 //          Also contains code to show how to implement two threads in an
00006 //          OpenGL application.
00007 //
00008 // Development Team:
00009 //         Greg Binkerd - Windows Developer Support
00010 //
00011 // Written by Microsoft Windows Developer Support
00012 // Copyright (c) 1995-1996 Microsoft Corporation. All rights reserved.
00013 //****************************************************************************
00014
00015 #include "glthread.h"
00016 #include <math.h>
00017
00018 // Threads that will perform the OpenGL rendering
00019 HANDLE hThreads[2];
00020 // Handle to main window
00021 extern HWND ghWnd;
00022
00023 HPALETTE ghpalOld, ghPalette = (HPALETTE) 0;
00024 GLfloat radius;
00025 RECT    oldrect;
00026
00027 unsigned char threeto8[8] = {
00028     0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
00029 };
00030
00031 unsigned char twoto8[4] = {
00032     0, 0x55, 0xaa, 0xff
00033 };
00034
00035 unsigned char oneto8[2] = {
00036     0, 255
00037 };
00038
00039 static int defaultOverride[13] = {
00040     0, 3, 24, 27, 64, 67, 88, 173, 181, 236, 247, 164, 91
00041 };
00042
00043 static PALETTEENTRY defaultPalEntry[20] = {
00044     { 0,   0,   0,    0 },
00045     { 0x80,0,   0,    0 },
00046     { 0,   0x80,0,    0 },
00047     { 0x80,0x80,0,    0 },
00048     { 0,   0,   0x80, 0 },
00049     { 0x80,0,   0x80, 0 },
00050     { 0,   0x80,0x80, 0 },
00051     { 0xC0,0xC0,0xC0, 0 },
00052
00053     { 192, 220, 192,  0 },
00054     { 166, 202, 240,  0 },
00055     { 255, 251, 240,  0 },
00056     { 160, 160, 164,  0 },
00057
00058     { 0x80,0x80,0x80, 0 },
00059     { 0xFF,0,   0,    0 },
00060     { 0,   0xFF,0,    0 },
00061     { 0xFF,0xFF,0,    0 },
00062     { 0,   0,   0xFF, 0 },
00063     { 0xFF,0,   0xFF, 0 },
00064     { 0,   0xFF,0xFF, 0 },
00065     { 0xFF,0xFF,0xFF, 0 }
00066 };
00067
00068 //****************************************************************************
00069 // Function: ComponentFromIndex
00070 //
00071 //
00072 // Comments: Taken from the "GenGL" OpenGL sample application
00073 //
00074 //****************************************************************************
00075 unsigned char ComponentFromIndex(int i, UINT nbits, UINT shift)
00076 {
00077     unsigned char val;
00078
00079     val = (unsigned char) (i >> shift);
00080     switch (nbits)
00081     {
00082         case 1:
00083             val &= 0x1;
00084             return oneto8[val];
00085
00086         case 2:
00087             val &= 0x3;
00088             return twoto8[val];
00089
00090         case 3:
00091             val &= 0x7;
00092             return threeto8[val];
00093
00094         default:
00095             return 0;
00096     }
00097 }
00098
00099 //****************************************************************************
00100 // Function: CreateRGBPalette
00101 //
00102 //
00103 // Comments: Taken from the "GenGL" OpenGL sample application
00104 //
00105 //****************************************************************************
00106 void CreateRGBPalette(HDC hDC)
00107 {
00108     PIXELFORMATDESCRIPTOR pfd;
00109     LOGPALETTE *pPal;
00110     int n, i;
00111
00112     n = GetPixelFormat(hDC);
00113     DescribePixelFormat(hDC, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
00114
00115     if (pfd.dwFlags & PFD_NEED_PALETTE) {
00116         n = 1 << pfd.cColorBits;
00117         pPal = (PLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
00118                n * sizeof(PALETTEENTRY));
00119         pPal->palVersion = 0x300;
00120         pPal->palNumEntries = n;
00121         for (i=0; i<n; i++)
00122         {
00123             pPal->palPalEntry[i].peRed =
00124                     ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift);
00125             pPal->palPalEntry[i].peGreen =
00126                     ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift);
00127             pPal->palPalEntry[i].peBlue =
00128                     ComponentFromIndex(i, pfd.cBlueBits, pfd.cBlueShift);
00129             pPal->palPalEntry[i].peFlags = 0;
00130         }
00131
00132         /* fix up the palette to include the default GDI palette */
00133         if ((pfd.cColorBits == 8)                           &&
00134             (pfd.cRedBits   == 3) && (pfd.cRedShift   == 0) &&
00135             (pfd.cGreenBits == 3) && (pfd.cGreenShift == 3) &&
00136             (pfd.cBlueBits  == 2) && (pfd.cBlueShift  == 6))
00137         {
00138             for (i = 1 ; i <= 12 ; i++)
00139                 pPal->palPalEntry[defaultOverride[i]] = defaultPalEntry[i];
00140         }
00141
00142         ghPalette = CreatePalette(pPal);
00143         LocalFree(pPal);
00144
00145         ghpalOld = SelectPalette(hDC, ghPalette, FALSE);
00146         n = RealizePalette(hDC);
00147     }
00148 }
00149
00150 //****************************************************************************
00151 // Function: bSetupPixelFormat
00152 //
00153 //
00154 // Comments: Taken from the "GenGL" OpenGL sample application
00155 //
00156 //****************************************************************************
00157 BOOL bSetupPixelFormat(HDC hDC)
00158 {
00159     static PIXELFORMATDESCRIPTOR pfd = {
00160         sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
00161         1,                              // version number
00162         PFD_DRAW_TO_WINDOW |            // support window
00163         PFD_SUPPORT_OPENGL,             // support OpenGL
00164         PFD_TYPE_RGBA,                  // RGBA type
00165         24,                             // 24-bit color depth
00166         0, 0, 0, 0, 0, 0,               // color bits ignored
00167         0,                              // no alpha buffer
00168         0,                              // shift bit ignored
00169         0,                              // no accumulation buffer
00170         0, 0, 0, 0,                     // accum bits ignored
00171         32,                             // 32-bit z-buffer
00172         0,                              // no stencil buffer
00173         0,                              // no auxiliary buffer
00174         PFD_MAIN_PLANE,                 // main layer
00175         0,                              // reserved
00176         0, 0, 0                         // layer masks ignored
00177     };
00178     int pixelformat;
00179
00180     if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
00181     {
00182         MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
00183         return FALSE;
00184     }
00185
00186     if (SetPixelFormat(hDC, pixelformat, &pfd) == FALSE)
00187     {
00188         MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
00189         return FALSE;
00190     }
00191
00192     CreateRGBPalette(hDC);
00193
00194     return TRUE;
00195 }
00196
00197
00198 //****************************************************************************
00199 // Function: initialize
00200 //
00201 // Purpose: Called by Windows on app startup.  Initializes everything,
00202 //          and enters a message loop.
00203 //
00204 // Parameters:
00205 //    hWnd     == Handle to window
00206 //
00207 // Returns: none
00208 //
00209 // Comments:
00210 //
00211 // History:  Date       Author        Reason
00212 //           3/20/95     GGB          Created
00213 //****************************************************************************
00214
00215 GLvoid initialize(HWND hWnd)
00216 {
00217     GLfloat light_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
00218     GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
00219     GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
00220     /*  light_position is NOT default value */
00221     GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
00222     GLfloat maxObjectSize, aspect;
00223     GLdouble near_plane, far_plane;
00224
00225     GetClientRect(hWnd, &oldrect);
00226     glClearColor( 0.0, 0.0, 0.0, 1.0 );
00227     glClearDepth( 70.0 );
00228
00229     glEnable(GL_DEPTH_TEST);
00230
00231     // Make it so our normal vectors are automatically changed to "unit" length
00232     glEnable(GL_NORMALIZE);
00233
00234     glMatrixMode( GL_PROJECTION );
00235     aspect = (GLfloat) oldrect.right / oldrect.bottom;;
00236     gluPerspective( 45.0, aspect, 3.0, 70.0 );
00237     glMatrixMode( GL_MODELVIEW );
00238
00239     // Set up lighting
00240     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
00241     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
00242     glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
00243     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00244
00245     glEnable(GL_LIGHTING);
00246     glEnable(GL_LIGHT0);
00247     glDepthFunc(GL_LESS);
00248     glEnable(GL_DEPTH_TEST);
00249
00250     near_plane = 3.0;
00251     far_plane = 70.0;
00252     maxObjectSize = 3.0;
00253     radius = near_plane + maxObjectSize/2.0;
00254 }
00255
00256
00257 //****************************************************************************
00258 // Function: ThreadFunc1
00259 //
00260 // Purpose:  Thread that draws the 3D wave on the left side of the screen.
00261 //           This thread calls glClear and let's thread "2" proceed after
00262 //           it has cleared the screen.  Then, they both start drawing their
00263 //           own waves at the same time.
00264 //
00265 // Parameters: none
00266 //
00267 // Returns: none
00268 //
00269 // Comments:
00270 //
00271 // History:  Date       Author        Reason
00272 //           3/21/95     GGB          Created
00273 //****************************************************************************
00274
00275 GLvoid ThreadFunc1(void)
00276 {
00277     HDC   hDC;
00278     HGLRC hRC;
00279
00280     // Get a DC for the main window
00281     hDC = GetDC(ghWnd);
00282     bSetupPixelFormat(hDC);
00283     hRC = wglCreateContext( hDC );
00284     wglMakeCurrent( hDC, hRC );
00285     initialize(ghWnd);
00286
00287     // Clear the main window.  Only _one_ thread should be doing this.
00288     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00289     // Now, it's safe for the other thread to start drawing.
00290     ResumeThread(hThreads[1]);
00291
00292     glPushMatrix();
00293     glTranslatef(0.0, 0.0, -radius);
00294
00295     // Define our point of reference
00296     gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
00297     DrawWave(0.6, 0.7, -2.5);
00298     glPopMatrix();
00299     glFinish();
00300
00301     wglMakeCurrent(NULL, NULL);
00302     if (hRC)
00303         wglDeleteContext(hRC);
00304     if (hDC)
00305         ReleaseDC(ghWnd, hDC);
00306 }
00307
00308
00309 //****************************************************************************
00310 // Function: ThreadFunc2
00311 //
00312 // Purpose:  Thread that draws the 3D wave on the right side of the screen.
00313 //           This thread waits until thread "1" has cleared the screen and has
00314 //           called ResumeThread(hThreads[1]).  Then, it draws the wave.
00315 //
00316 // Parameters: none
00317 //
00318 // Returns: none
00319 //
00320 // Comments:
00321 //
00322 // History:  Date       Author        Reason
00323 //           3/21/95     GGB          Created
00324 //****************************************************************************
00325
00326 GLvoid ThreadFunc2(void)
00327 {
00328     HDC   hDC;
00329     HGLRC hRC;
00330
00331     // Get a DC for the main window
00332     hDC = GetDC(ghWnd);
00333     bSetupPixelFormat(hDC);
00334     hRC = wglCreateContext( hDC );
00335     wglMakeCurrent( hDC, hRC );
00336     initialize(ghWnd);
00337
00338     glPushMatrix();
00339     glTranslatef(0.0, 0.0, -radius);
00340
00341     // Define our point of reference
00342     gluLookAt(0.5,1.0,2.0,0.0,0.2,0.0,0.0,1.0,0.0);
00343     DrawWave(0.2, 0.3, 2.5);
00344     glPopMatrix();
00345     glFinish();
00346
00347     wglMakeCurrent(NULL, NULL);
00348     if (hRC)
00349         wglDeleteContext(hRC);
00350     if (hDC)
00351         ReleaseDC(ghWnd, hDC);
00352 }
00353
00354
00355 //****************************************************************************
00356 // Function: draw_scene
00357 //
00358 // Purpose:  Called when a WM_PAINT message is sent to the main window.  It
00359 //           creates two threads.  One is created suspended so the other
00360 //           can call glClear to clear the rendering context.  Then, the
00361 //           thread that calls glClear will call ResumeThread to let the other
00362 //           thread start drawing.
00363 //
00364 // Parameters: hWnd == main window handle
00365 //
00366 // Returns: none
00367 //
00368 // Comments:
00369 //
00370 // History:  Date       Author        Reason
00371 //           3/22/95     GGB          Created
00372 //****************************************************************************
00373
00374 GLvoid draw_scene(HWND hWnd)
00375 {
00376     DWORD dwThread1ID;
00377     DWORD dwThread2ID;
00378
00379     hThreads[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc1,
00380                                NULL, 0, &dwThread1ID);
00381
00382     // Create this thread suspended so it will wait until the window has been
00383     // cleared before drawing.
00384     hThreads[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFunc2,
00385                                NULL, CREATE_SUSPENDED,&dwThread2ID);
00386
00387     // Wait for both threads to finish.
00388     WaitForMultipleObjects(2, hThreads, TRUE, 10000);
00389     CloseHandle(hThreads[0]);
00390     CloseHandle(hThreads[1]);
00391 }
00392
00393
00394 //****************************************************************************
00395 // Function: resize
00396 //
00397 //
00398 // Comments: Taken from the "GenGL" OpenGL sample application
00399 //
00400 //****************************************************************************
00401 GLvoid resize(HWND hWnd)
00402 {
00403     RECT    rect;
00404
00405     GetClientRect(hWnd, &rect);
00406
00407     glViewport(0, 0, rect.right, rect.bottom);
00408
00409     oldrect.right = rect.right;
00410     oldrect.bottom = rect.bottom;
00411 }
00412
00413
00414 //****************************************************************************
00415 // Function: DrawWave
00416 //
00417 // Purpose: Called by the two threads to draw a "cos" 3D wave
00418 //
00419 // Parameters:
00420 //    fHeight     == Height of wave
00421 //    fWidth      == Width of wave
00422 //    fHorizon    == Where to place the wave along the "x" axis
00423 //
00424 // Returns: none
00425 //
00426 // Comments:
00427 //
00428 // History:  Date       Author        Reason
00429 //           3/22/95     GGB           Created
00430 //****************************************************************************
00431
00432 GLvoid DrawWave(GLfloat fHeight, GLfloat fWidth, GLfloat fHorizon)
00433 {
00434     GLfloat x;
00435     GLfloat z;
00436     GLfloat step;
00437
00438     step = 0.11;
00439     for (z=3.5;z >= -12.0;z-=step)
00440     {
00441         for (x= -2.0 + fHorizon; x <= (2.0 + 0.01 + fHorizon); x += step)
00442         {
00443             GLfloat fNormalX, fNormalY, fNormalZ;
00444             GLfloat fVert1[3];
00445             GLfloat fVert2[3];
00446             GLfloat fVert3[3];
00447             GLfloat fVert4[3];
00448
00449             glBegin(GL_POLYGON);
00450             fVert1[0] = x;
00451             fVert1[1] = solve(x,z,fHeight,fWidth);
00452             fVert1[2] = z;
00453             glVertex3fv(fVert1);
00454             fVert2[0] = x;
00455             fVert2[1] = solve(x,z-step,fHeight,fWidth);
00456             fVert2[2] = z-step;
00457             glVertex3fv(fVert2);
00458             fVert3[0] = x+step;
00459             fVert3[1] = solve(x+step,z-step,fHeight,fWidth);
00460             fVert3[2] = z-step;
00461             glVertex3fv(fVert3);
00462             fVert4[0] = x+step;
00463             fVert4[1] = solve(x+step,z,fHeight,fWidth);
00464             fVert4[2] = z;
00465             glVertex3fv(fVert4);
00466
00467             // Calculate the vector normal coming out of the 3D polygon.
00468             CalculateVectorNormal(fVert1, fVert2, fVert3, &fNormalX, &fNormalY,
00469                                   &fNormalZ);
00470             // Set the normal vector for the polygon
00471             glNormal3f(fNormalX, fNormalY, fNormalZ);
00472             glEnd();
00473         }
00474     }
00475 }
00476
00477
00478 //****************************************************************************
00479 // Function: solve
00480 //
00481 // Purpose: Calculates the "y" value of a "cos" wave given an x and z.
00482 //
00483 // Parameters:
00484 //    x     == value for the "x" coordinate
00485 //    y     == value for the "y" coordinate
00486 //    h     == value for the height of the wave
00487 //    w     == value for the width of the wave
00488 //
00489 // Returns: value for "y"
00490 //
00491 // Comments:
00492 //
00493 // History:  Date       Author        Reason
00494 //           3/22/95     GGB           Created
00495 //****************************************************************************
00496
00497 GLfloat solve(GLfloat x, GLfloat z, GLfloat h, GLfloat w)
00498 {
00499     GLfloat y;
00500     y = cos(x/w)*h+cos(z/w)*h;
00501     return y;
00502 }
00503
00504
00505 //****************************************************************************
00506 // Function: CalculateVectorNormal
00507 //
00508 // Purpose: Given three points of a 3D plane, this function will calculate the
00509 //          normal vector of that plane.
00510 //
00511 // Parameters:
00512 //      fVert1[]   == array for 1st point (3 elements are x, y, and z).
00513 //      fVert2[]   == array for 2nd point (3 elements are x, y, and z).
00514 //      fVert3[]   == array for 3rd point (3 elements are x, y, and z).
00515 //
00516 // Returns:
00517 //      fNormalX   == X vector for the normal vector
00518 //      fNormalY   == Y vector for the normal vector
00519 //      fNormalZ   == Z vector for the normal vector
00520 //
00521 // Comments:
00522 //
00523 // History:  Date       Author        Reason
00524 //           3/22/95     GGB           Created
00525 //****************************************************************************
00526
00527 GLvoid CalculateVectorNormal(GLfloat fVert1[], GLfloat fVert2[],
00528                              GLfloat fVert3[], GLfloat *fNormalX,
00529                              GLfloat *fNormalY, GLfloat *fNormalZ)
00530 {
00531     GLfloat Qx, Qy, Qz, Px, Py, Pz;
00532
00533     Qx = fVert2[0]-fVert1[0];
00534     Qy = fVert2[1]-fVert1[1];
00535     Qz = fVert2[2]-fVert1[2];
00536     Px = fVert3[0]-fVert1[0];
00537     Py = fVert3[1]-fVert1[1];
00538     Pz = fVert3[2]-fVert1[2];
00539
00540     *fNormalX = Py*Qz - Pz*Qy;
00541     *fNormalY = Pz*Qx - Px*Qz;
00542     *fNormalZ = Px*Qy - Py*Qx;
00543 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: ASYN_IO/ASYN_IO.C Source File

  • ASYN_IO

ASYN_IO.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 //       This is a part of the Microsoft Source Code Samples.
00003 //       Copyright (C) 1992-1996 Microsoft Corporation.
00004 //       All rights reserved.
00005 //       This source code is only intended as a supplement to
00006 //       Microsoft Development Tools and/or WinHelp documentation.
00007 //       See these sources for detailed information regarding the
00008 //       Microsoft samples programs.
00009 /////////////////////////////////////////////////////////////////////////////
00010
00011 /////////////////////////////////////////////////////////////////////////////
00012 //   MODULE:  ASYN_IO.C
00013 //
00014 //
00015 //   PURPOSE: Demonstrates the basic concepts envolved when using
00016 //            asynchronous IO. In particular the main advantage is your
00017 //            app more correctly thread can go about doing useful work
00018 //            while waiting for IO. The main disadvantage is you must keep
00019 //            track of the file pointer.
00020 //
00021 //   INPUT: Both the File to read and File to write to must be entered
00022 //          on via the command line. Note the file to write to must be
00023 //          unique.
00024 //
00025 //   FUNCTIONS:
00026 //
00027 //       Do_BackgroundTask()
00028 //
00029 //
00030 //   COMMENTS: Reads a file asynchronously writes to another synchronously
00031 //
00032 //
00033 /////////////////////////////////////////////////////////////////////////////
00034
00035 #include <windows.h>
00036 #include <stdio.h>
00037
00038 #define SECTOR_SIZE  1024
00039
00040 VOID ErrorMsg         (LPCTSTR psz);
00041 VOID Do_BackgroundTask(VOID);
00042
00043 VOID main(int argc, char *argv[])
00044 {
00045   BOOL       bSuccess ;          // return code of last API called
00046
00047   CHAR       buf[SECTOR_SIZE] ;  // Buffer used by either
00048                                    // ReadFile() or WriteFile()
00049
00050   DWORD      cbBytesRead,        // count of bytes read by ReadFile()
00051                                    // When asynchonous I/O is performed
00052                                    // one must check how many bytes were
00053                                    // read by calling GetOverLappedResults().
00054
00055                cbBytesWritten,     // count of bytes written by WriteFile()
00056
00057                cbBytesTransfered ; // this value is returned by
00058                                    // GetOverLappedResults() represents the
00059                                    // count of bytes transfered asynchronous
00060
00061   DWORD      dwStatus,           // value returned by GetLastError()
00062                dwSuccess ;         // return code of last API called
00063
00064     HANDLE     hInfile,            // Handle to the file to read
00065                hOutfile;           // Handle to the file to write to
00066
00067     HANDLE     hEvent ;            // Handle to the synchronization Event
00068
00069     OVERLAPPED OverLapped ;        // The operating system does not automatically
00070                                    // track the current file position of a file
00071                                    // open for asynchroous I/O. Instead one must
00072                                    // manually track this by updating the OVERLAPPED
00073                                    // structure. To update this structure one uses
00074                                    // the result returned by GetOverLappedResults().
00075
00076 /////////////////////////////////////////////////////////////////////////////
00077 //
00078 //  This block of code initalizes all the necessary variables needed to do
00079 //  asynchronous IO. Specfically it opens the files and initializes the
00080 //  synchronization EVENT and OVERLAPPED structure needed to keep track
00081 //  of asynchronous file I/O
00082 //
00083 /////////////////////////////////////////////////////////////////////////////
00084
00085   // check if running on Windows NT, if not, display notice and terminate
00086   if (GetVersion() & 0x80000000)
00087       {
00088       MessageBox(NULL,
00089                    "This sample application can only be run on Windows NT.\n"
00090                    "This application will now terminate.",
00091                    "Event",
00092                    MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
00093         return;
00094       }
00095
00096     if (argc != 3)
00097       {
00098         printf ("\nUsage: ASYN_IO input_file output_file\n");
00099         ExitProcess(1L);
00100       }
00101
00102   // Open file which will be copying.  Note we are opening this
00103   // asynchronously
00104
00105     hInfile = CreateFile(argv[1],              // File to read
00106                          GENERIC_READ,         // Open file for reading only
00107                          FILE_SHARE_READ,      // Allow others to read file
00108                          NULL,                 // No security
00109                          OPEN_EXISTING,        // Fail if file doesn't exit
00110                          FILE_FLAG_OVERLAPPED, // Async I/o
00111                          NULL);
00112
00113   if (hInfile == INVALID_HANDLE_VALUE)
00114       {
00115         printf("Error opening %s.\n", argv[1]);
00116         ErrorMsg("CreateFile");
00117       }
00118
00119   // Create the file to write to; here we have opened it for synchronous IO.
00120
00121   hOutfile = CreateFile(argv[2],                 // File to write to
00122                           GENERIC_WRITE,           // Open file only to write to
00123                           0,                       // No sharing allowed
00124                           NULL,                    // No security
00125                           CREATE_NEW,              // Fail if file exists
00126                           FILE_ATTRIBUTE_NORMAL,   // No attributes
00127                           NULL);
00128
00129     if (hOutfile == INVALID_HANDLE_VALUE)
00130       {
00131       printf("Error opening %s.\n", argv[2]);
00132         ErrorMsg("CreateFile") ;
00133       }
00134
00135   // Create Synchronizing Event
00136
00137     hEvent = CreateEvent(NULL,    // No security
00138                          TRUE,    // Manual reset
00139                          FALSE,   // Initially Event set to non-signaled state
00140                          NULL);   // No name
00141     if (hEvent == NULL)
00142     ErrorMsg("CreateEvent") ;
00143
00144   //
00145     // Intialize OverLapped structure. We will be using an Event instead
00146     // of the file handle for synchronizing I/O. One reason to use a unique
00147     // event instead of the file handle would be a so multi-threaded app
00148   // would know which thread to unblock when the handle is set to the
00149   // signaled state.
00150   //
00151
00152     memset(&OverLapped, 0, sizeof(OVERLAPPED));
00153     OverLapped.hEvent = hEvent ;
00154
00155     bSuccess = TRUE ;
00156
00157   /***************************************************************************\
00158   **                                                                         **
00159   ** This is the main function of this program. Here we loop until the file  **
00160   ** has been copied. Notice that even though we are using asynchronous I/O  **
00161   ** ReadFile() may still return sychronously if it can be done fast enough  **
00162   **                                                                         **
00163   \***************************************************************************/
00164
00165     while (bSuccess)
00166       {
00167
00168     // Read file asynchronously
00169
00170         bSuccess = ReadFile(hInfile,        // Handle of file to read
00171                       buf,            // Buffer to store input
00172                       SECTOR_SIZE,    // Number of bytes to read
00173                       &cbBytesRead,   // Number of bytes read. See note]
00174                                       // above in delcaration
00175                       &OverLapped);   // Used for asynchronous I/O
00176
00177     // Check whether ReadFile() has completed yet
00178
00179         if (!bSuccess && ((dwStatus = GetLastError()) == ERROR_IO_PENDING))
00180           {
00181           printf("\nIO Pending");
00182
00183
00184       // Read not complete yet first execute the background task then check
00185       // to the if event "hEvent" set to the signaled state. If the event is
00186       // not set signaled state then loop through again - run the background
00187       // task and check the event.
00188
00189           Do_BackgroundTask();
00190
00191           dwSuccess = WaitForSingleObject(hEvent, 0);
00192
00193           if (dwSuccess == WAIT_FAILED)
00194         {
00195               ErrorMsg("WaitForSingleObject");
00196             }
00197           else if (dwSuccess == WAIT_OBJECT_0)
00198             {
00199               bSuccess = GetOverlappedResult(hInfile,
00200                                              &OverLapped,
00201                                              &cbBytesTransfered,
00202                                              FALSE);
00203               if (!bSuccess)
00204                   ErrorMsg("GetOverLappedResult");
00205               else
00206                 {
00207                   // Read has completed now find out how many bytes have been read
00208                   printf ("\nNumber of bytes transfered is %d\n", cbBytesTransfered);
00209                   OverLapped.Offset += cbBytesTransfered ;
00210                   cbBytesRead = cbBytesTransfered ;
00211                 }
00212             }
00213           else if (dwSuccess == WAIT_TIMEOUT)
00214               {
00215               Do_BackgroundTask () ;
00216             }
00217           }
00218
00219     // ReadFile() read file synchronously; update Overlapped structure
00220
00221     else if (bSuccess  && cbBytesRead != 0)
00222           {
00223           printf ( "\nNumber of bytes transfered is %d\n", cbBytesRead ) ;
00224           OverLapped.Offset += cbBytesRead ;
00225           }
00226
00227     // ReadFile() has found the end of the file; exit loop
00228
00229         else if (!bSuccess  && GetLastError() == ERROR_HANDLE_EOF)
00230           {
00231           printf("\nEnd of file read\n");
00232           break ;
00233           }
00234         else
00235       {
00236
00237       // An error occured while reading, print out status and exit loop.
00238
00239           ErrorMsg ("ReadFile");
00240       }
00241
00242   // Write to file synchronously
00243
00244   bSuccess = WriteFile(hOutfile,             // Handle of file to write to
00245                      buf,                  // Data to write to file
00246                      cbBytesRead,          // Number of bytes to write
00247                      &cbBytesWritten,      // Number of bytes written
00248                      NULL);                // Only need for asynchonous output
00249
00250   if (!bSuccess)
00251       ErrorMsg("WriteFile");
00252
00253    } // End of WHILE loop
00254
00255    CloseHandle(hInfile);        // Close handle to input file
00256    FlushFileBuffers(hOutfile);  // Make sure all data written to file first
00257    CloseHandle (hOutfile);      // Close handle to output file
00258    ExitProcess(0L);
00259
00260 }
00261
00262 /////////////////////////////////////////////////////////////////////////////
00263 //
00264 //   FUNCTION: Do_BackgroundTask ( VOID )
00265 //
00266 //   PURPOSE: Works in the background while IO sytems
00267 //
00268 //   COMMENTS:
00269 //
00270 //      Currently this does nothing if I have the time I will come up
00271 //      with some silly task to keep the user entertained.
00272 //
00273 //   INPUT: None
00274 //
00275 //   OUTPUT: None
00276 //
00277 /////////////////////////////////////////////////////////////////////////////
00278 VOID Do_BackgroundTask(VOID)
00279 {
00280   Sleep (5000L) ;
00281 }
00282
00283 /////////////////////////////////////////////////////////////////////////////
00284 //
00285 //   FUNCTION: ErrorMsg(LPTSTR)
00286 //
00287 //   PURPOSE: Prints out an error message the return code of the last API
00288 //            to fail.
00289 //
00290 //   INPUT: psz: This string is a description of where the code failed in
00291 //          the module
00292 //
00293 //   OUTPUT: None
00294 //
00295 /////////////////////////////////////////////////////////////////////////////
00296
00297 VOID ErrorMsg(LPCTSTR psz)
00298 {
00299   LPVOID lpvMessageBuffer;
00300
00301   FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00302             NULL, GetLastError(),
00303             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
00304             (LPTSTR)&lpvMessageBuffer, 0, NULL);
00305
00306   //... now display this string
00307   printf("ERROR: API        = %s.\n", psz);
00308   printf("       error code = %d.\n", GetLastError());
00309   printf("       message    = %s.\n", (LPTSTR)lpvMessageBuffer);
00310
00311   // Free the buffer allocated by the system
00312   LocalFree(lpvMessageBuffer);
00313
00314   ExitProcess(EXIT_FAILURE);
00315 }
Generated on Wed Nov 13 2024 17:29:08 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: SERVENUM/DEMO/INIT.C Source File

  • SERVENUM
  • DEMO

INIT.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   init.c
00009 //
00010 //  PURPOSE:   Performs application and instance specific initialization.
00011 //
00012 //  FUNCTIONS:
00013 //    InitApplication() - Initializes window data and registers window.
00014 //    InitInstance() - Saves instance handle and creates main window.
00015 //
00016 //  COMMENTS:
00017 //
00018
00019 #include <windows.h>            // required for all Windows applications
00020 #include "globals.h"            // prototypes specific to this application
00021
00022 HINSTANCE hInst;                // current instance
00023
00024 TCHAR szAppName[9];              // The name of this application
00025 TCHAR szTitle[40];               // The title bar text
00026
00027 //
00028 //  FUNCTION: InitApplication(HINSTANCE)
00029 //
00030 //  PURPOSE: Initializes window data and registers window class.
00031 //
00032 //  PARAMETERS:
00033 //    hInstance - The handle to the instance of this application that
00034 //          is currently being executed.
00035 //
00036 //  RETURN VALUE:
00037 //    TRUE - Success
00038 //    FALSE - Initialization failed
00039 //
00040 //  COMMENTS:
00041 //
00042 //    This function is called at initialization time only if no other
00043 //    instances of the application are running.  This function performs
00044 //    initialization tasks that can be done once for any number of running
00045 //    instances.
00046 //
00047 //    In this case, we initialize a window class by filling out a data
00048 //    structure of type WNDCLASS and calling the Windows RegisterClass()
00049 //    function.  Since all instances of this application use the same
00050 //    window class, we only need to do this when the first instance is
00051 //    initialized.
00052 //
00053
00054 BOOL InitApplication(HINSTANCE hInstance)
00055 {
00056     WNDCLASS  wc;
00057
00058     // Load the application name and description strings.
00059
00060     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
00061     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
00062
00063     // Fill in window class structure with parameters that describe the
00064     // main window.
00065
00066     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
00067     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
00068     wc.cbClsExtra    = 0;                       // No per-class extra data.
00069     wc.cbWndExtra    = 0;                       // No per-window extra data.
00070     wc.hInstance     = hInstance;               // Owner of this class
00071     wc.hIcon         = LoadIcon(hInstance, szAppName); // Icon name from .RC
00072     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
00073     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
00074     wc.lpszMenuName  = szAppName;               // Menu name from .RC
00075     wc.lpszClassName = szAppName;               // Name to register as
00076
00077     // Register the window class and return FALSE if unsuccesful.
00078
00079     if (!RegisterClass(&wc))
00080     {
00081         return FALSE;
00082     }
00083     //
00084     // **TODO** Call module specific application initialization functions here.
00085     //
00086
00087     return TRUE;
00088 }
00089
00090
00091 //
00092 //  FUNCTION:  InitInstance(HINSTANCE, int)
00093 //
00094 //  PURPOSE:  Saves instance handle and creates main window.
00095 //
00096 //  PARAMTERS:
00097 //    hInstance - The handle to the instance of this application that
00098 //          is currently being executed.
00099 //    nCmdShow - Specifies how the main window is to be diplayed.
00100 //
00101 //  RETURN VALUE:
00102 //    TRUE - Success
00103 //    FALSE - Initialization failed
00104 //
00105 //  COMMENTS:
00106 //    This function is called at initialization time for every instance of
00107 //    this application.  This function performs initialization tasks that
00108 //    cannot be shared by multiple instances.
00109 //
00110 //    In this case, we save the instance handle in a static variable and
00111 //    create and display the main program window.
00112 //
00113
00114 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
00115 {
00116     HWND    hwnd; // Main window handle.
00117
00118     // Save the instance handle in static variable, which will be used in
00119     // many subsequence calls from this application to Windows.
00120
00121     hInst = hInstance; // Store instance handle in our global variable
00122
00123     // Create a main window for this application instance.
00124     hwnd = CreateWindow(szAppName,           // See RegisterClass() call.
00125                         szTitle,             // Text for window title bar.
00126                         WS_OVERLAPPEDWINDOW, // Window style.
00127                         CW_USEDEFAULT, 0,    // Use default positioning
00128                         CW_USEDEFAULT, 0,    // Use default size
00129                         NULL,                // Overlapped has no parent.
00130                         NULL,                // Use the window class menu.
00131                         hInstance,
00132                         NULL);
00133
00134     // If window could not be created, return "failure"
00135     if (!hwnd)
00136         return FALSE;
00137
00138     //
00139     // **TODO** Call module specific instance initialization functions here.
00140     //
00141
00142     // Make the window visible; update its client area; and return "success"
00143     ShowWindow(hwnd, nCmdShow); // Show the window
00144     UpdateWindow(hwnd);         // Sends WM_PAINT message
00145
00146     return TRUE;                // We succeeded...
00147 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: MINREC/RECHOOK.C Source File

  • MINREC

RECHOOK.C

Go to the documentation of this file.
00001 // ************************************************************************
00002 //
00003 //                      Microsoft Developer Support
00004 //               Copyright (c) 1992-1996 Microsoft Corporation
00005 //
00006 // ************************************************************************
00007 // MODULE    : RecHook.C
00008 // PURPOSE   : A Small Win32 Recorder-like Sample Application Hook DLL
00009 // FUNCTIONS :
00010 //   DllMain()            - Dll entry point (via _DllMainCRTStartup)
00011 //   StartJournalRecord   - starts the journal record hook
00012 //   StopJournalRecord    - stops the journal record hook
00013 //   StartJournalPlayback - starts the journal playback hook
00014 //   StopJournalPlayback  - stops the journal playback hook
00015 //   StopAllJournalling   - stops any current journal hook
00016 // COMMENTS  : The Journal Record File contains an EVENTHEADER structure
00017 //             followed by a variable number of EVENTMSG structures.
00018 // ************************************************************************
00019 #define   STRICT               // strict type checking enabled
00020
00021 // If this program is going to be run exclusively on Windows NT enable
00022 // the UNICODE define below.  However, Windows 95 doesn't support UNICODE
00023 // so for Windows 95 leave the define commented out.
00024
00025 // #define   UNICODE              // make the application unicode compliant
00026 #include <Windows.H>           // required for all Windows applications
00027
00028 #include "RecHook.H"
00029 #include "MinRec.H"            // we need IDM_MACRO_STOP
00030
00031 // Internal Defines
00032 // -----------------------------------------------------------------------
00033 #define MINREC_FILENAME  TEXT("MinRec.Rec") // File for record/play events
00034 #define MINREC_SIGNATURE "MinRec\0"         // Journal Record File signature
00035
00036 //-- header for the MinRec record/playback file
00037 typedef struct EVENTHEADER_STRUCT {
00038   CHAR   Signature[7];
00039   UINT   RecordedMsgCount;
00040   DWORD  BaseMsgTime;
00041 } EVENTHEADER, *PEVENTHEADER;
00042
00043 //-- various "file global" data
00044 typedef struct GLOBAL_STRUCT {
00045   BOOL      fRecording;
00046   BOOL      fPlaying;
00047   BOOL      fStopRecording;
00048   BOOL      fStopPlaying;
00049   UINT      PlayedMsgCount;
00050   UINT      RecordedMsgCount;
00051   DWORD     BaseMsgTime;
00052   DWORD     LastMsgTime;
00053   HANDLE    hFile;
00054   EVENTMSG  EventMsg;
00055   HHOOK     hHookRecord;
00056   HHOOK     hHookPlayback;
00057   HHOOK     hHookGetMsg;
00058   HINSTANCE hInstance;
00059 } GLOBAL, *PGLOBAL;
00060
00061 // Global Data (file local)
00062 // -----------------------------------------------------------------------
00063 static GLOBAL  Global;                // various global data
00064
00065 // Internal Function Prototypes
00066 // -----------------------------------------------------------------------
00067 LRESULT CALLBACK JournalRecordProc  ( int, WPARAM, LPARAM );
00068 LRESULT CALLBACK JournalPlaybackProc( int, WPARAM, LPARAM );
00069 LRESULT CALLBACK GetMsgProc         ( int, WPARAM, LPARAM );
00070
00071
00072 // ************************************************************************
00073 // FUNCTION : DllMain( HINSTANCE, DWORD, LPVOID )
00074 // PURPOSE  : DllMain is called by the C Run-Time library from the
00075 //            _DllMainCRTStartup entry point.  The DLL entry point gets
00076 //            called (entered) on the following events: "Process Attach",
00077 //            "Thread Attach", "Thread Detach" or "Process Detach".
00078 // ************************************************************************
00079 BOOL WINAPI
00080 DllMain( HINSTANCE hInstanceDll, DWORD dwReason, LPVOID lpvReserved )
00081 {
00082   switch( dwReason ) {
00083
00084     case DLL_PROCESS_ATTACH:
00085       Global.fRecording    = FALSE;
00086       Global.fPlaying      = FALSE;
00087       Global.hInstance     = hInstanceDll;
00088       break;
00089
00090   }
00091
00092   return( TRUE );
00093   UNREFERENCED_PARAMETER( lpvReserved );
00094 }
00095
00096
00097 // ************************************************************************
00098 // FUNCTION : StartJournalRecord()
00099 // PURPOSE  : Creates the record file and installs the record hook.
00100 // ************************************************************************
00101 BOOL
00102 StartJournalRecord()
00103 {
00104   // Do not allow recording while playing back
00105   if( Global.fPlaying ) {
00106     MessageBox( NULL,
00107       TEXT( "Sorry, recording while\n" )
00108       TEXT( "playing is not allowed."  ),
00109       TEXT( "MinRec - Notice!"         ),
00110       MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
00111     return( FALSE );
00112   }
00113
00114   // Create and open the journal record file and set the file pointer to
00115   //  just past the journal record file header
00116   Global.hFile = CreateFile( (LPCTSTR) MINREC_FILENAME, GENERIC_WRITE,
00117                        0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
00118   SetFilePointer( Global.hFile, (LONG) sizeof(EVENTHEADER), NULL, FILE_BEGIN );
00119
00120   // Initialize the recorded message count to zero and set recording flag
00121   Global.RecordedMsgCount = 0;
00122   Global.fRecording       = TRUE;
00123
00124   // Set the GetMsg hook to trap Ctrl+Esc, Alt+Esc and Ctrl+Alt+Del.
00125   Global.hHookGetMsg = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
00126                          Global.hInstance, 0 );
00127
00128   // Set the Journal Record hook.
00129   Global.hHookRecord = SetWindowsHookEx( WH_JOURNALRECORD, JournalRecordProc,
00130                          Global.hInstance, 0 );
00131
00132   return( TRUE );
00133 }
00134
00135
00136 // ************************************************************************
00137 // FUNCTION : JournalRecordProc()
00138 // PURPOSE  : Processes the journal record events by writing them to  the
00139 //            record file one event at a time.
00140 // ************************************************************************
00141 LRESULT CALLBACK
00142 JournalRecordProc( int nCode, WPARAM wParam, LPARAM lParam )
00143 {
00144   // if nCode < 0 or is set Global.fStopRecording we must immediately return
00145   // the result of CallNextHookEx.
00146   if( nCode < 0 || Global.fStopRecording )
00147     return( CallNextHookEx( Global.hHookRecord, nCode, wParam, lParam ) );
00148
00149   switch( nCode ) {
00150
00151     // The lParam parameter points to an EVENTMSG structure
00152     // containing information about a message removed from the system
00153     // queue.  The hook procedure must record the contents of the structure
00154     // by copying them to the Recorded Journal file.
00155     case HC_ACTION: {
00156       LPEVENTMSG lpEventMsg;
00157       DWORD      dwBytesWritten;
00158
00159       lpEventMsg = (LPEVENTMSG) lParam;
00160
00161       // user pressed Ctrl+Break.  We use this as a request to cancel
00162       // journal recording.  We wont display a message to the user here
00163       // since this is an action the user choose to do.
00164       if( (lpEventMsg->message == WM_KEYDOWN)
00165            && (LOBYTE(lpEventMsg->paramL) == VK_CANCEL) ) {
00166         StopAllJournalling();
00167       }
00168       else {
00169         // write the event message to the Recorded Journal file
00170         WriteFile( Global.hFile, (LPCSTR) lParam, sizeof(EVENTMSG),
00171           &dwBytesWritten, NULL );
00172         if( ++Global.RecordedMsgCount == 1)
00173           Global.BaseMsgTime = lpEventMsg->time;
00174       }
00175       break;
00176     }
00177
00178     // A system-modal dialog box is being displayed. Until the dialog box
00179     // is destroyed, the hook procedure must stop recording.
00180     case HC_SYSMODALON:
00181       Global.fStopRecording = TRUE;
00182       break;
00183
00184     // A system-modal dialog box has been destroyed. The hook
00185     // procedure must resume recording.
00186     case HC_SYSMODALOFF:
00187       Global.fStopRecording = FALSE;
00188       break;
00189
00190   }
00191
00192   return( CallNextHookEx( Global.hHookRecord, nCode, wParam, lParam ) );
00193   UNREFERENCED_PARAMETER( wParam );
00194 }
00195
00196
00197 // ************************************************************************
00198 // FUNCTION : StopJournalRecord()
00199 // PURPOSE  : Unhooks the record hook, records the record file header and
00200 //            closes the file.
00201 // ************************************************************************
00202 BOOL
00203 StopJournalRecord()
00204 {
00205   EVENTHEADER EventHeader;
00206
00207   // Remove the Journal Record hook if recording
00208   if( Global.fRecording ) {
00209     DWORD dwBytesWritten;
00210
00211     // remove the record hook
00212     UnhookWindowsHookEx( Global.hHookRecord );
00213
00214     // remove the get message hook
00215     UnhookWindowsHookEx( Global.hHookGetMsg );
00216
00217     // Copy Recorded Journal header data to temporary buffer
00218     lstrcpyA( EventHeader.Signature, MINREC_SIGNATURE );
00219     EventHeader.RecordedMsgCount = Global.RecordedMsgCount;
00220     EventHeader.BaseMsgTime      = Global.BaseMsgTime;
00221
00222     // Open Recorded Journal file and update the file header and close
00223     //  the file
00224     SetFilePointer( Global.hFile, 0, NULL, FILE_BEGIN );
00225     WriteFile( Global.hFile, (LPCSTR) &EventHeader, sizeof(EVENTHEADER),
00226       &dwBytesWritten, NULL );
00227     CloseHandle( Global.hFile );
00228
00229     // Clear recording flag
00230     Global.fRecording = FALSE;
00231   }
00232
00233   return( TRUE );
00234 }
00235
00236
00237 // ************************************************************************
00238 // FUNCTION : StartJournalPlayback()
00239 // PURPOSE  : Opens the playback file and reads the header and installs the
00240 //            playback hook.
00241 // ************************************************************************
00242 BOOL
00243 StartJournalPlayback()
00244 {
00245   EVENTHEADER EventHeader;
00246   DWORD       dwBytesRead;
00247
00248   // Allow infinite playback loop
00249   if( Global.fRecording ) {
00250     StopJournalRecord();
00251     MessageBox( NULL,
00252       TEXT( "Infinite playback\n" )
00253       TEXT( "loop recorded!"      ),
00254       TEXT( "MinRec - Notice!"    ),
00255       MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
00256     return( FALSE );
00257   }
00258
00259   if( Global.fPlaying ) {
00260     StopJournalPlayback();
00261   }
00262
00263   // Open Recorded Journal file
00264   Global.hFile = CreateFile( (LPCTSTR) MINREC_FILENAME, GENERIC_READ,
00265                        0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
00266   if( Global.hFile == INVALID_HANDLE_VALUE ) {
00267     MessageBox( NULL,
00268       TEXT( "The default Journal Record File\n" )
00269       TEXT( "MINREC.REC could not be found.\n"  ),
00270       TEXT( "MinRec - Error!"                   ),
00271       MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
00272     return( FALSE );
00273   }
00274
00275   // Quick check, file size should be at least the length of the header
00276   if( GetFileSize( Global.hFile, NULL ) < sizeof(EVENTHEADER) ) {
00277     MessageBox( NULL,
00278       TEXT( "The file MINREC.REC is not a \n"     )
00279       TEXT( "valid MinRec Journal Record file.\n" ),
00280       TEXT( "MinRec - Error!"                     ),
00281       MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
00282     return( FALSE );
00283   }
00284
00285   // Read Recorded Journal file header
00286   SetFilePointer( Global.hFile, 0L, NULL, FILE_BEGIN );
00287   ReadFile( Global.hFile, (LPVOID) &EventHeader, sizeof(EVENTHEADER),
00288         &dwBytesRead, NULL );
00289
00290   // Quick check, the signature of the file must be "MinRec"
00291   if( lstrcmpA( EventHeader.Signature, MINREC_SIGNATURE ) != 0 ) {
00292     MessageBox( NULL,
00293       TEXT( "The file MINREC.REC does not\n"    )
00294       TEXT( "contain a valid MinRec signature." ),
00295       TEXT( "MinRec - Error!"                   ),
00296       MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND );
00297      return( FALSE );
00298   }
00299
00300   // Store the header values
00301   Global.RecordedMsgCount = EventHeader.RecordedMsgCount;
00302   Global.BaseMsgTime      = EventHeader.BaseMsgTime;
00303   Global.LastMsgTime      = EventHeader.BaseMsgTime;
00304
00305   // If no messages were recorded, none to play back.
00306   if( Global.RecordedMsgCount == 0 ) {
00307     MessageBox( NULL,
00308       TEXT( "Sorry, nothing was recorded, so\n")
00309       TEXT( "there is nothing to playback."    ),
00310       TEXT( "MinRec - Notice!"                 ),
00311       MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
00312      return( FALSE );
00313   }
00314
00315   // Initialize the played message count to zero and set the play flag
00316   Global.PlayedMsgCount = 0;
00317   Global.fPlaying       = TRUE;
00318
00319   // Get the first recorded message from the file and store it
00320   ReadFile( Global.hFile, (LPVOID) &(Global.EventMsg), sizeof(EVENTMSG),
00321         &dwBytesRead, NULL );
00322
00323   // Set the GetMsg hook to trap Ctrl+Break, Ctrl+Esc and Ctrl+Alt+Del.
00324   Global.hHookGetMsg = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc,
00325                          Global.hInstance, 0 );
00326
00327   // Set the Journal Playback hook
00328   Global.hHookPlayback = SetWindowsHookEx( WH_JOURNALPLAYBACK,
00329                            JournalPlaybackProc, Global.hInstance, 0 );
00330
00331   return( TRUE );
00332 }
00333
00334
00335 // ************************************************************************
00336 // FUNCTION : JournalPlaybackProc()
00337 // PURPOSE  : Processes the journal playback events by reading in the
00338 //            playback file one event at a time.
00339 // ************************************************************************
00340 LRESULT CALLBACK
00341 JournalPlaybackProc( int nCode, WPARAM wParam, LPARAM lParam )
00342 {
00343   // if nCode < 0 or is set Global.fStopPlaying we must immediately return
00344   // the result of CallNextHookEx.
00345   if( nCode < 0 || Global.fStopPlaying )
00346     return( CallNextHookEx( Global.hHookPlayback, nCode, wParam, lParam ) );
00347
00348   switch( nCode ) {
00349
00350     // HC_GETNEXT occurs when Windows requests the next system message
00351     // queue message.  If we return 0 it will place the message found in
00352     // lParam into the system message queue otherwise it will sleep
00353     // for the specified number of milliseconds returned and then later
00354     // call JournalPlaybackProc with nCode set, again, to HC_GETNEXT.
00355     case HC_GETNEXT: {
00356       LRESULT SleepTime;
00357
00358       // determine the amount of time Windows must sleep before
00359       // it should place this message into the system message queue.
00360       SleepTime = Global.EventMsg.time - Global.LastMsgTime;
00361
00362       // copy the current ready system message to lParam
00363       CopyMemory( (PVOID) lParam, (CONST VOID*) &(Global.EventMsg),
00364         sizeof(EVENTMSG) );
00365
00366       // store the value of the next system message post time so we can
00367       // use this value to set SleepTime to 0 on the next HC_GETNEXT
00368       Global.LastMsgTime = Global.EventMsg.time;
00369
00370       return( SleepTime );
00371     }
00372
00373     // HC_SKIP occurs only after Windows has processed a HC_GETNEXT
00374     // condition that returned 0.  We can use this to prepare the next
00375     // ready system message to be posted or deterimine of there are no
00376     // remaining system messages to post and thus stop the playback.
00377     case HC_SKIP: {
00378       if( ++Global.PlayedMsgCount > Global.RecordedMsgCount ) {
00379         StopJournalPlayback();
00380         break;
00381         // return( (LRESULT) 0L );
00382       }
00383       else {
00384         DWORD dwBytesRead;
00385
00386         // Get the next ready message from the file and store it
00387         // in the global buffer for the next HC_GETNEXT
00388         ReadFile( Global.hFile, (LPVOID) &(Global.EventMsg), sizeof(EVENTMSG),
00389           &dwBytesRead, NULL );
00390         // fall through and call CallNextHookEx
00391         // return( (LRESULT) 0L );
00392         break;
00393
00394       }
00395     }
00396
00397     // A system-modal dialog box is being displayed. Until the dialog box
00398     // is destroyed, the hook procedure must stop playing back messages.
00399     case HC_SYSMODALON:
00400       Global.fStopPlaying = TRUE;
00401       break;
00402
00403     // A system-modal dialog box has been destroyed. The hook
00404     // procedure must resume playing back the messages.
00405     case HC_SYSMODALOFF:
00406       Global.fStopPlaying = FALSE;
00407       break;
00408
00409   }
00410
00411   return( CallNextHookEx( Global.hHookPlayback, nCode, wParam, lParam ) );
00412   UNREFERENCED_PARAMETER( wParam );
00413 }
00414
00415
00416 // ************************************************************************
00417 // FUNCTION : StopJournalPlayback()
00418 // PURPOSE  : Unhooks the playback hook and closes the playback file.
00419 // ************************************************************************
00420 BOOL
00421 StopJournalPlayback()
00422 {
00423   // Remove the Playback Journal hook if playing
00424   if( Global.fPlaying ) {
00425
00426     // remove the playback hook
00427     UnhookWindowsHookEx( Global.hHookPlayback );
00428
00429     // remove the get message hook
00430     UnhookWindowsHookEx( Global.hHookGetMsg );
00431
00432     // close the journal record file
00433     CloseHandle( Global.hFile );
00434
00435     // Clear playback flag
00436     Global.fPlaying = FALSE;
00437   }
00438
00439   return( TRUE );
00440 }
00441
00442
00443 // ************************************************************************
00444 // FUNCTION : StopAllJournalling()
00445 // PURPOSE  : Stops (unhooks) any current journal hook started (hooked) by
00446 //            this application.
00447 // ************************************************************************
00448 BOOL
00449 StopAllJournalling( )
00450 {
00451   if( Global.fRecording )
00452     StopJournalRecord();
00453   if( Global.fPlaying )
00454     StopJournalPlayback();
00455
00456   return( TRUE );
00457 }
00458
00459
00460 // ************************************************************************
00461 // FUNCTION : GetMsgProc()
00462 // PURPOSE  : Installs a get message hook to monitor messages sent to the
00463 //            queue so we can trap the WM_CANCELJOURNAL message send by the
00464 //            system when the user presses Ctrl+Esc, Alt+Esc or
00465 //            Ctrl+Alt+Del which cancels the journal hook.
00466 // COMMENTS : WM_CANCELJOURNAL gets sent to the thread which installs the
00467 //            hook but the hWnd of this message is NULL and thus does not
00468 //            get dispatched.  Thus this hook is used to retrieve this
00469 //            message.
00470 // ************************************************************************
00471 LRESULT CALLBACK
00472 GetMsgProc( int nCode, WPARAM wParam, LPARAM lParam )
00473 {
00474   // if nCode < 0 we must immediately return the result of CallNextHookEx.
00475   if( nCode < 0  )
00476     return( CallNextHookEx( Global.hHookGetMsg, nCode, wParam, lParam ) );
00477
00478   switch( ((LPMSG)lParam)->message ) {
00479
00480     // user pressed Ctrl+Esc, Alt+Esc or Ctrl+Alt+Del, the system will
00481     // automatically stop all journalling.  Thus we display a message that
00482     // this has resulted in the termination of the Jorunalling since the
00483     // user may not expect this to occur with these key events.
00484     case WM_CANCELJOURNAL:
00485       StopAllJournalling();
00486       MessageBox( NULL,
00487         TEXT( "The user has pressed either\n"            )
00488         TEXT( "Ctrl+Esc, Alt+Esc or Ctrl+Alt+Del\n"      )
00489         TEXT( "and thus the system has automatically\n"  )
00490         TEXT( "canceled all journalling.\n"              ),
00491         TEXT( "MinRec - Notice!"                         ),
00492         MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND );
00493       break;
00494
00495   }
00496
00497   return( CallNextHookEx( Global.hHookGetMsg, nCode, wParam, lParam ) );
00498   UNREFERENCED_PARAMETER( wParam );
00499 }
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/MEM.H Source File

  • NETDDE

MEM.H

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 // MODULE: mem.h
00009 //
00010 // PURPOSE:
00011 //    Contains declarations memory allocation functions
00012 //
00013
00014 #ifndef _MEM_H
00015 #define _MEM_H
00016
00017 #ifndef ERROR_NOT_ENOUGH_MEMORY
00018 #define ERROR_NOT_ENOUGH_MEMORY 8
00019 #endif
00020
00021 #ifndef ERROR_SUCCESS
00022 #define ERROR_SUCCESS 0
00023 #endif
00024
00025 //-------------------------------------------------------------
00026 // mem prototypes
00027
00028 DWORD MallocMem( LPVOID *lplpv, DWORD dwSize );
00029 DWORD ReallocMem( LPVOID *lplpv, DWORD dwSize );
00030 VOID  FreeMem( LPVOID *lplpv );
00031
00032 #endif
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1


WinNT-Templates: NETDDE/NDDEUTIL.C Source File

  • NETDDE

NDDEUTIL.C

Go to the documentation of this file.
00001 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
00002 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
00003 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
00004 // PARTICULAR PURPOSE.
00005 //
00006 // Copyright (C) 1992-1996  Microsoft Corporation.  All Rights Reserved.
00007 //
00008 //  MODULE:   nddeutil.c
00009 //
00010 //  PURPOSE:  Handle NetDDE API calls
00011 //
00012 //  FUNCTIONS:
00013 //    SetupNDDEShare - established NetDDE Share
00014 //    ShowNDDEErrMsg - displayes message box of NetDDE error
00015 //
00016 //  COMMENTS:
00017 //
00018 //  AUTHOR: Craig Link - Microsoft Developer Support
00019 //
00020
00021 #include <windows.h>            // required for all Windows applications
00022 #include <windowsx.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025
00026 #ifdef WIN16
00027 #include "win16ext.h"           // required only for win16 applications
00028 #endif
00029
00030 #include "globals.h"            // prototypes specific to this application
00031 #include <nddeapi.h>
00032 #include "nddeutil.h"
00033
00034
00035 // Module specific "globals"  Used when a variable needs to be
00036 // accessed in more than on handler function.
00037
00038
00039 //
00040 //  FUNCTION: SetupNDDEShare ( HWND, LPSTR, LPSTR, LPSTR )
00041 //
00042 //  PURPOSE: Establish NetDDE Share
00043 //
00044 //  PARAMETERS:
00045 //    hwnd - handle of calling window
00046 //    lpszShareName - name of NDDE share
00047 //    lpszApp - name of app supporting DDE conversation
00048 //    lpszTopic - topic supported in DDE converstation
00049 //
00050 //  RETURN VALUE:
00051 //    TRUE if share established
00052 //
00053 //  COMMENTS:
00054 //    Clients are give READ/WRITE permissions to the share
00055 //    to allow for advises and pokes
00056 //
00057 BOOL SetupNDDEShare(
00058     HWND  hwnd,
00059     LPSTR lpszShareName,
00060     LPSTR lpszApp,
00061     LPSTR lpszTopic )
00062 {
00063
00064 #ifdef WIN16 // Win16 bimplementation
00065     UINT uRet = 0;
00066     NDDESHAREINFO ndsiInfo;
00067
00068     lstrcpy( ndsiInfo.szShareName, lpszShareName );
00069     ndsiInfo.lpszTargetApp  = lpszApp;
00070     ndsiInfo.lpszTargetTopic= lpszTopic;
00071     ndsiInfo.lpbPassword1   = "";
00072     ndsiInfo.cbPassword1    = 0;
00073     ndsiInfo.dwPermissions1 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
00074     ndsiInfo.lpbPassword2   = "";
00075     ndsiInfo.cbPassword2    = 0;
00076     ndsiInfo.dwPermissions2 = NDDEACCESS_POKE | NDDEACCESS_ADVISE | NDDEACCESS_START_APP;
00077     ndsiInfo.lpszItem       = NULL;
00078     ndsiInfo.cAddItems      = 0;
00079     ndsiInfo.lpNDdeShareItemInfo = NULL;
00080
00081     NDdeShareDel ( NULL, lpszShareName, 0 );
00082
00083     uRet = NDdeShareAdd(NULL, 2, (LPBYTE) &ndsiInfo, sizeof(NDDESHAREINFO));
00084
00085     if (uRet != NDDE_NO_ERROR )
00086     {
00087         ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
00088         return FALSE;
00089     }
00090
00091     return TRUE;
00092
00093
00094 #else  // Win32 implementation
00095     FARPROC lpfn = NULL;
00096     BOOL bRet = TRUE;
00097     UINT uRet = 0;
00098     NDDESHAREINFO ndsiInfo;
00099     PSECURITY_DESCRIPTOR pSD = NULL;
00100     long lShareType = 0;
00101     long len = 0;
00102     char szAppTopicList[3*(MAX_APPNAME+MAX_TOPICNAME+2)+1];
00103     // create app / topic list - this is 3 null terminated strings
00104     // terminated by another null
00105
00106     wsprintf(szAppTopicList,
00107             "%s|%s",
00108             lpszApp,
00109             lpszTopic );
00110
00111     len = lstrlen(szAppTopicList)+1;  // include NULL charater
00112
00113     wsprintf(szAppTopicList+len,
00114             "%s|%s",
00115             lpszApp,
00116             lpszTopic );
00117
00118     wsprintf(szAppTopicList+len*2,
00119             "%s|%s",
00120             lpszApp,
00121             lpszTopic );
00122
00123     szAppTopicList[len*3] = 0;        // terminate with double null
00124
00125
00126     lShareType = SHARE_TYPE_OLD | SHARE_TYPE_NEW | SHARE_TYPE_STATIC;
00127
00128     // Get a pointer to the NDdeIsValidAppTopicList() API
00129     lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeIsValidAppTopicListA"));
00130     if (!lpfn)
00131     {
00132         MessageBox(NULL, TEXT("Error calling NetDDE API"), TEXT("NDDECHAT"),
00133                    MB_OK);
00134         return (FALSE);
00135     }
00136
00137     if( (lpfn)(szAppTopicList)) {
00138
00139         ndsiInfo.lRevision = 1;
00140         ndsiInfo.lpszShareName = lpszShareName;
00141         ndsiInfo.lShareType = lShareType;
00142         ndsiInfo.lpszAppTopicList = szAppTopicList;
00143         ndsiInfo.fSharedFlag = TRUE;
00144         ndsiInfo.fService = FALSE;
00145         ndsiInfo.fStartAppFlag = TRUE;
00146         ndsiInfo.nCmdShow = SW_SHOWNORMAL;
00147         ndsiInfo.cNumItems = 0;
00148         ndsiInfo.lpszItemList = "";
00149
00150         // Delete possible old share
00151         lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareDelA"));
00152         (lpfn)( NULL, lpszShareName, 0 );
00153
00154
00155         // Create a Security descriptor which allows write access
00156         // This enables pokes from client ( ie writes )
00157
00158         // Allocate memory for the security descriptor.
00159         pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
00160                                         SECURITY_DESCRIPTOR_MIN_LENGTH);
00161
00162         // Initialize the new security descriptor.
00163         InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION);
00164
00165         // Add a NULL descriptor ACL to the security descriptor.
00166         SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE);
00167
00168         // create the new share
00169         lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeShareAddA"));
00170         uRet = (lpfn)( NULL, 2, pSD, (LPBYTE)&ndsiInfo, sizeof(NDDESHAREINFO) );
00171         if ( uRet == NDDE_NO_ERROR )
00172         {
00173             // trust the new share to allow remote access
00174             lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeSetTrustedShareA"));
00175             uRet = (lpfn)( NULL, lpszShareName,
00176                            NDDE_TRUST_SHARE_INIT | NDDE_TRUST_SHARE_START);
00177             if ( uRet != NDDE_NO_ERROR )
00178             {
00179                 ShowNDDEErrMsg ( hwnd, "Error Trusting Share", uRet );
00180                 bRet = FALSE;
00181             }
00182         }
00183         else
00184         {
00185             ShowNDDEErrMsg (  hwnd, "Error Adding Share", uRet );
00186             bRet = FALSE;
00187         }
00188
00189         // free security descriptor
00190         LocalFree( pSD );
00191     }
00192     else
00193     {
00194         MessageBox ( hwnd, "Invalid Topic List", szAppName, MB_ICONEXCLAMATION | MB_OK );
00195         bRet = FALSE;
00196     }
00197
00198     return bRet;
00199 #endif  // Win32
00200
00201 }
00202
00203
00204 //
00205 //  FUNCTION: ShowNDDEErrMsg ( HWND hwnd, LPSTR lpstr, UINT uCode )
00206 //
00207 //  PURPOSE: display messagebox containing NDDE error string
00208 //
00209 //  PARAMETERS:
00210 //    hwnd - handle to messgebox owner window
00211 //    lpstr - pointer to message box caption text
00212 //    uCode - NDDE error code
00213 //
00214 //  RETURN VALUE:
00215 //    none
00216 //
00217 //  COMMENTS:
00218 //
00219 VOID ShowNDDEErrMsg ( HWND hwnd, LPSTR lpstr, UINT uCode )
00220 {
00221     char szBuf[256];
00222     FARPROC lpfn;
00223
00224     if ( uCode == NDDE_NO_ERROR )
00225         return;
00226
00227     MessageBeep(MB_ICONEXCLAMATION);
00228
00229     wsprintf( (LPSTR)szBuf, "%s\n", lpstr );
00230     lpfn = GetProcAddress(g_hInstNetDde, TEXT("NDdeGetErrorStringA"));
00231     if ( (lpfn) ( uCode,
00232                   (LPSTR)szBuf+lstrlen((LPSTR)szBuf),
00233                   255-lstrlen((LPSTR)szBuf) ) == NDDE_NO_ERROR )
00234     {
00235         MessageBox (hwnd, szBuf, szAppName, MB_ICONEXCLAMATION | MB_OK );
00236     }
00237 }
00238
Generated on Wed Nov 13 2024 17:29:09 for WinNT-Templates by doxygen 1.7.1