This month's discussion will center on the Windows API.
A common operation working with computers is to return to the desktop. Your desktop often contains recent information, new icons, new programs and other features that you want to get access. Microsoft recognized this need by providing a MINIMIZE-ALL option on your taskbar. Windows 98 actually has an option on the taskbar for bring up a list of desktop utilities. Sometimes this is not enough. At work some of the programs that I use are so unfriendly that they will not allow themselves to be minimized.
The desktop is simply another folder on your hard drive. You can open it with Microsoft Explorer. Unfortunately the path is fairly long and not consistent between operating systems. I have written a desktop utility which displays a small icon on the taskbar. When you double-click on the icon the program launches Windows Explorer with the proper path to bring up the information that's normally contained on the desktop.
The program uses the standard Windows 32-bit API, application programming language interface. Although I have tried it with Microsoft Visual C++ version 5 it will probably compile using any compiler. An additional feature will resize in the window to scale it to the available video space.
The biggest challenge for this program was to create a application program window which was non-obtrusive. There is no window. The only evidence of the program is a small icon which is typically near the clock on the lower right hand corner of the screen.
// Desktop.cpp A desktop utility for the task bar. B.Arnold 8/3/99 #define STRICT #include <windows.h> #pragma hdrstop #include <windowsx.h> #include <stdio.h> #include <stdlib.h> #include <winuser.h> #include <shellapi.h> // taskbar #include <io.h> #include "resource.h" ..... int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdParam, int nCmdShow) { char ProgName[] = HEADING; MSG msg; HWND hWnd; ghInstance = hInstance; // Note: hPrevInstance always 0 WNDCLASSEX wndclass; // '..EX' needed for small icon wndclass.cbSize = sizeof(wndclass); // ex wndclass.lpszClassName = ProgName; wndclass.lpfnWndProc = (WNDPROC) MainWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON3)); wndclass.hIconSm = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON3)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wndclass.lpszMenuName = NULL; wndclass.style = CS_DBLCLKS; if (!RegisterClassEx(&wndclass)) exit(0);; ... /**********************************************************************/ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static int x, y; switch (message) { case WM_CREATE: // needed for taskbar algorithm ShowWindow(hWnd,SW_HIDE); tb.cbSize = sizeof(tb); // setup taskbar icon tb.hWnd = hWnd; tb.uID = IDI_ICON3; tb.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; tb.uCallbackMessage = WM_TASKBAR; tb.hIcon = (HICON) LoadImage(ghInstance,MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON,16,16,LR_DEFAULTCOLOR); strcpy(tb.szTip,"View Desktop Folder"); // 63 MAX Shell_NotifyIcon(NIM_ADD, &tb); return 0; .... void WinExec2(char *lpCmdLine, UINT uCmdShow) { static STARTUPINFO si; static PROCESS_INFORMATION pi; memset(&si,0,sizeof(si)); memset(&pi,0,sizeof(pi)); si.cb = sizeof(si); si.wShowWindow=uCmdShow; CreateProcess( NULL, // pointer to name of executable module lpCmdLine, // pointer to command line string NULL, // pointer to process security attributes NULL, // pointer to thread security attributes FALSE, // handle inheritance flag NULL, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &si, // pointer to STARTUPINFO &pi // pointer to PROCESS_INFORMATION ); WaitForInputIdle(pi.hProcess, 6000); // wait up to 6 secs. } int isWinNT(void) { OSVERSIONINFO osvi; memset(&osvi, 0, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); GetVersionEx (&osvi); if (osvi.dwPlatformId == VER_PLATFORM_WIN32s) return 0; else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) return 0; else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) return 1; // NT or 2000 return 0; }