home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- Example.c - Source file to show how to use with AniDes32.dll
- Created by Wong Siu Wai, December 1997.
- ************************************************************/
-
- /*You must link the AniDes32.lib import library to the make file.
- For example, click <Build> in the menu and then click <Setting> for
- Visual C++, change the link property by adding AniDes32.lib
- in the edit box.*/
-
- #include <windows.h>
- #include <stdlib.h>
- #include "AniDes32.h" //Must be included for using AniDes32.dll
-
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
-
- int FAR PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR szCmdLine, int iCmdShow)
- {
- static char szAppName[] = "Example";
- WNDCLASSEX wc;
- HWND hwnd;
- MSG msg;
-
- wc.cbSize = sizeof(wc);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = szAppName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
-
- RegisterClassEx(&wc);
-
- hwnd = CreateWindow(szAppName, szAppName,
- WS_POPUP, 0, 0, //Use Popup as a full screen window
- GetSystemMetrics(SM_CXSCREEN), //Get the x-axis screen
- GetSystemMetrics(SM_CYSCREEN), //Get the y-axis screen
- NULL, NULL, hInstance, NULL);
-
- while(!SetTimer(hwnd, 1, 1000, NULL)) /*Set timer for keep on updating the window,
- set it by no more that 1 min, must be included also.*/
- {
- if(IDCANCEL == MessageBox(hwnd, "Too many clocks or timers",
- szAppName, MB_ICONEXCLAMATION | MB_RETRYCANCEL))
- return FALSE;
- }
-
- while(GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return msg.wParam;
- }
-
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- int i, xStart, yStart, xEnd, yEnd, iColor[2];
- static HRGN hRgn;
- TEXTMETRIC tm;
- RECT rect;
- HDC hdc;
-
- switch(message)
- {
- case WM_TIMER:
- for(i = 0; i <= 2; i++)
- iColor[i] = rand() % 255;
- hdc = SetDisplayDC(); //Call function SetDisplayDC() to get the dislapy DC
- GetClientRect(hwnd, &rect); //Get the client rect, now is same as the screen
- GetTextMetrics(hdc, &tm);
- xStart = (GetSystemMetrics(SM_CXSCREEN) -
- tm.tmAveCharWidth * 18) / 2; //Get the x-axis starting point
- yStart = (GetSystemMetrics(SM_CYSCREEN) -
- tm.tmHeight - tm.tmExternalLeading) / 2; //Get the y-axis starting point
- xEnd = xStart + tm.tmAveCharWidth * 18; //Get the x-axis ending point
- yEnd = yStart + tm.tmHeight + tm.tmExternalLeading; //Get the y-axis ending point
- hRgn = SetAniDesk(hdc, xStart, yStart, xEnd, yEnd); /*Call function SetAniDesk(handle of DC, x-starting point,
- y-starting point, x-ending point, y-ending) to get the clipping region,
- you are not needed to select the region to the DC and must save the handle
- for the next step*/
- SetBkMode(hdc, TRANSPARENT); //Set Background mode to transparent
- SetTextColor(hdc, RGB(iColor[0], iColor[1], iColor[2])); //Set the text color
- DrawText(hdc, "Hello, Windows95 !", -1, &rect,
- DT_SINGLELINE | DT_CENTER | DT_VCENTER);
- ResetDisplayDC(hdc); //Call function ResetDisplay(hwndle of DC) to delete the Display DC
- return 0;
-
- case WM_DESTROY:
- ResetAniDesk(hRgn); /*Call function ResetAniDesk to delete
- the clipping region, same as DeleteObject function*/
- KillTimer(hwnd, 1);
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hwnd, message, wParam, lParam);
- }