|
|
1.1 ! root 1: /********************************************************************\ ! 2: * UTSamp.c -- Sample program demonstrating Universal Thunks under * ! 3: * Win32s, including calling APIs unsupported by * ! 4: * Win32s. * ! 5: * * ! 6: * Lee Hart * ! 7: * Microsoft Developer Support * ! 8: * Copyright (c) 1993 Microsoft Corporation * ! 9: * * ! 10: * Comments: * ! 11: * Shows how to use Universal Thunks to call APIs that are not * ! 12: * available normally in Win32s. * ! 13: * * ! 14: * Functions: * ! 15: * * ! 16: * WinMain() - Initializes Application * ! 17: * MainWndProc() - Processes Application Messages * ! 18: * AboutDlgProc() - Processes "About" Dialog Box Messages * ! 19: * * ! 20: * * ! 21: \********************************************************************/ ! 22: ! 23: ! 24: /********************* Header Files *********************/ ! 25: ! 26: #include <windows.h> ! 27: #include "utsamp.h" ! 28: ! 29: /********************** Prototypes **********************/ ! 30: ! 31: LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); ! 32: LRESULT CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ); ! 33: ! 34: /******************* Global Variables *******************/ ! 35: ! 36: HANDLE ghInstance; ! 37: ! 38: /********************************************************************\ ! 39: * Function: int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) * ! 40: * * ! 41: * Purpose: Initializes Application, sets up Universal Thunk if * ! 42: * running under Win32s (as determined by the high but of * ! 43: * GetVersion(). * ! 44: * * ! 45: \********************************************************************/ ! 46: ! 47: ! 48: int WINAPI WinMain( HINSTANCE hInstance, ! 49: HINSTANCE hPrevInstance, ! 50: LPSTR lpszCmdLine, ! 51: int nCmdShow ) ! 52: { ! 53: WNDCLASS wc; ! 54: MSG msg; ! 55: HWND hWnd; ! 56: ! 57: if( !hPrevInstance ) ! 58: { ! 59: wc.lpszClassName = "UTSampClass"; ! 60: wc.lpfnWndProc = MainWndProc; ! 61: wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; ! 62: wc.hInstance = hInstance; ! 63: wc.hIcon = LoadIcon( hInstance, "UTSampIcon" ); ! 64: wc.hCursor = LoadCursor( NULL, IDC_ARROW ); ! 65: wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 ); ! 66: wc.lpszMenuName = "UTSampMenu"; ! 67: wc.cbClsExtra = 0; ! 68: wc.cbWndExtra = 0; ! 69: ! 70: RegisterClass( &wc ); ! 71: } ! 72: ! 73: ghInstance = hInstance; ! 74: ! 75: hWnd = CreateWindow( "UTSampClass", ! 76: "Universal Thunks Sample", ! 77: WS_OVERLAPPEDWINDOW, ! 78: 0, ! 79: 0, ! 80: CW_USEDEFAULT, ! 81: CW_USEDEFAULT, ! 82: NULL, ! 83: NULL, ! 84: hInstance, ! 85: NULL); ! 86: ! 87: ShowWindow( hWnd, nCmdShow ); ! 88: ! 89: while( GetMessage( &msg, NULL, 0, 0 ) ) ! 90: { ! 91: TranslateMessage( &msg ); ! 92: DispatchMessage( &msg ); ! 93: } ! 94: ! 95: return msg.wParam; ! 96: } ! 97: ! 98: ! 99: /********************************************************************\ ! 100: * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) * ! 101: * * ! 102: * Purpose: Processes Application Messages * ! 103: * * ! 104: * Comments: The following messages are processed * ! 105: * * ! 106: * WM_COMMAND * ! 107: * WM_DESTROY * ! 108: * * ! 109: * * ! 110: \********************************************************************/ ! 111: ! 112: ! 113: LRESULT CALLBACK MainWndProc( HWND hWnd, ! 114: UINT msg, ! 115: WPARAM wParam, ! 116: LPARAM lParam ) ! 117: { ! 118: switch( msg ) ! 119: { ! 120: ! 121: /********************************************************************\ ! 122: * WM_COMMAND: Handle menu selections for Exit, GetFreeSpace, * ! 123: * WNetGetUser, and Help About * ! 124: \********************************************************************/ ! 125: ! 126: case WM_COMMAND: ! 127: switch( wParam ) ! 128: { ! 129: case IDM_EXIT: ! 130: SendMessage( hWnd, WM_CLOSE, 0, 0 ); ! 131: break; ! 132: ! 133: case IDM_GETUSER: ! 134: { ! 135: CHAR buf1[255], buf2[255]; ! 136: UINT bufsize = 255; ! 137: ! 138: MyWNetGetUser( NULL, buf1, &bufsize ); ! 139: wsprintf( buf2, "WNetGetUser(...) = %s", buf1 ); ! 140: MessageBox( hWnd, buf2, "Win32s UT Sample - WNetGetUser", MB_OK ); ! 141: } ! 142: break; ! 143: ! 144: case IDM_GETMEM: ! 145: { ! 146: CHAR buf[255]; ! 147: ! 148: wsprintf(buf,"GetFreeSpace(0) = %d",MyGetFreeSpace()); ! 149: ! 150: MessageBox(hWnd, buf,"Win32s UT Sample - GetFreeSpace",MB_OK); ! 151: } ! 152: break; ! 153: ! 154: case IDM_ABOUT: ! 155: DialogBox( ghInstance, ! 156: "AboutDlg", ! 157: hWnd, ! 158: (DLGPROC) AboutDlgProc ); ! 159: break; ! 160: } ! 161: break; ! 162: ! 163: /**************************************************************\ ! 164: * WM_DESTROY: PostQuitMessage() is called * ! 165: \**************************************************************/ ! 166: ! 167: case WM_DESTROY: ! 168: PostQuitMessage( 0 ); ! 169: break; ! 170: ! 171: /**************************************************************\ ! 172: * Let the default window proc handle all other messages * ! 173: \**************************************************************/ ! 174: ! 175: default: ! 176: return( DefWindowProc( hWnd, msg, wParam, lParam ) ); ! 177: } ! 178: ! 179: return 0; ! 180: } ! 181: ! 182: /********************************************************************\ ! 183: * Function: LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)* ! 184: * * ! 185: * Purpose: Processes "About" Dialog Box Messages * ! 186: * * ! 187: * Comments: The Dialog Box is displayed when the user selects * ! 188: * Help.About. The following messages are processed: * ! 189: * * ! 190: * WM_INITDIALOG * ! 191: * WM_COMMAND * ! 192: * * ! 193: \********************************************************************/ ! 194: ! 195: ! 196: LRESULT CALLBACK AboutDlgProc( HWND hDlg, ! 197: UINT uMsg, ! 198: WPARAM wParam, ! 199: LPARAM lParam ) ! 200: { ! 201: switch( uMsg ) ! 202: { ! 203: case WM_INITDIALOG: ! 204: return TRUE; ! 205: ! 206: case WM_COMMAND: ! 207: switch( wParam ) ! 208: { ! 209: case IDOK: ! 210: EndDialog( hDlg, TRUE ); ! 211: return TRUE; ! 212: } ! 213: break; ! 214: } ! 215: ! 216: return FALSE; ! 217: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.