home *** CD-ROM | disk | FTP | other *** search
- /*** Windows Application --- STRING example ***/
- /*** ***/
- /*** WSTRIN-1 includes ***/
- /*** (1) WSTRIN-1.C ***/
- /*** (2) WSTRIN-1.DEF ***/
- /*** (3) WSTRING.RES ***/
-
- #pragma hdrfile "windows.sym"
- #include <windows.h>
- #pragma hdrstop
-
- #include "wmenu.h"
- #include "string.h"
-
- // Declaration
-
- void InitString(HANDLE) ;
- void InitFirstInstance(HANDLE) ;
- void InitEachInstance(HANDLE, int) ;
- long FAR PASCAL AppWndProc (HWND, WORD, WORD, LONG) ;
-
- static char szAppName[12] ;
- static char szMenuName[12] ;
- static char szAccelName[12] ;
-
- HWND hwnd ;
-
- // Definition
-
- int PASCAL WinMain(HANDLE hInstance,
- HANDLE hPrevInstance,
- LPSTR lpszCmdLine,
- int nCmdShow)
- { HANDLE hAccel ;
- MSG msg ;
-
- InitString(hInstance) ;
-
- if ( !hPrevInstance ) InitFirstInstance(hInstance) ;
-
- InitEachInstance(hInstance,nCmdShow) ;
-
- hAccel = LoadAccelerators(hInstance, szAccelName) ;
-
- while ( GetMessage(&msg, NULL, 0, 0) )
- { if ( !TranslateAccelerator(hwnd, hAccel, &msg) )
- { TranslateMessage(&msg) ;
- DispatchMessage(&msg) ;
- }
- }
- return msg.wParam ;
- }
-
-
- void InitString(HANDLE hInstance)
- {
- LoadString(hInstance, IDS_APP, szAppName,11) ;
- LoadString(hInstance, IDS_MENU, szMenuName,11) ;
- LoadString(hInstance, IDS_ACCEL, szAccelName,11) ;
- }
-
-
- void InitFirstInstance(HANDLE hInstance)
- { WNDCLASS wndclass ;
-
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = AppWndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor(NULL,IDC_ARROW) ;
- wndclass.hbrBackground = GetStockObject(WHITE_BRUSH) ;
- wndclass.lpszMenuName = szMenuName ;
- wndclass.lpszClassName = szAppName ;
-
- RegisterClass(&wndclass) ;
- }
-
-
- void InitEachInstance(HANDLE hInstance, int nCmdShow)
- {
- hwnd = CreateWindow(szAppName, // window class name
- "Windows Application", // window caption
- WS_OVERLAPPEDWINDOW ,
- CW_USEDEFAULT, // initial x position
- 0, // initial y position
- CW_USEDEFAULT, // initial x length
- 0, // initial y length
- NULL, // parent window handle
- NULL, // window menu handle
- hInstance, // program instance handle
- NULL) ; // parameters
-
- ShowWindow(hwnd,nCmdShow) ;
- UpdateWindow(hwnd) ;
- }
-
-
- long FAR PASCAL AppWndProc (HWND hwnd,
- WORD message,
- WORD wParam,
- LONG lParam)
- { static WORD Cursor_Check = IDM_CURSOR1,
- Icon_Check = IDM_ICON1,
- Bitmap_Check = IDM_BITMAP1 ;
- HMENU hMenu ;
-
- switch (message)
- { case WM_COMMAND :
- hMenu = GetMenu(hwnd) ;
- switch(wParam)
- { case IDM_CURSOR1 :
- case IDM_CURSOR2 :
- case IDM_CURSOR3 :
- CheckMenuItem(hMenu, Cursor_Check, MF_UNCHECKED) ;
- Cursor_Check = wParam ;
- CheckMenuItem(hMenu, Cursor_Check, MF_CHECKED) ;
- break ;
-
- case IDM_ICON1 :
- case IDM_ICON2 :
- CheckMenuItem(hMenu, Icon_Check, MF_UNCHECKED) ;
- Icon_Check = wParam ;
- CheckMenuItem(hMenu, Icon_Check, MF_CHECKED) ;
- break ;
-
- case IDM_BITMAP1 :
- case IDM_BITMAP2 :
- case IDM_BITMAP3 :
- CheckMenuItem(hMenu, Bitmap_Check, MF_UNCHECKED) ;
- Bitmap_Check = wParam ;
- CheckMenuItem(hMenu, Bitmap_Check, MF_CHECKED) ;
- break ;
- }
- break ;
-
- case WM_DESTROY :
- PostQuitMessage(0) ;
- break ;
-
- default :
- return DefWindowProc(hwnd, message, wParam, lParam) ;
- }
-
- return 0 ;
- }
-
-