![]() |
WGX library Architecture - Reference Manual - Guides |
|
00001 /* 00002 * WGX - Windows GUI Extended Library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #define WIN32_NO_STATUS 00028 #include <windows.h> 00029 #include <stdio.h> 00030 #include <stdlib.h> 00031 #include <shellapi.h> 00032 00033 #include "wgx.h" 00034 00042 void __cdecl WgxEnableWindows(HANDLE hMainWindow, ...) 00043 { 00044 va_list marker; 00045 int id; 00046 00047 va_start(marker,hMainWindow); 00048 do { 00049 id = va_arg(marker,int); 00050 if(id) (void)EnableWindow(GetDlgItem(hMainWindow,id),TRUE); 00051 } while(id); 00052 va_end(marker); 00053 } 00054 00062 void __cdecl WgxDisableWindows(HANDLE hMainWindow, ...) 00063 { 00064 va_list marker; 00065 int id; 00066 00067 va_start(marker,hMainWindow); 00068 do { 00069 id = va_arg(marker,int); 00070 if(id) (void)EnableWindow(GetDlgItem(hMainWindow,id),FALSE); 00071 } while(id); 00072 va_end(marker); 00073 } 00074 00083 void __stdcall WgxSetIcon(HINSTANCE hInstance,HWND hWindow,UINT IconID) 00084 { 00085 HICON hIcon; 00086 00087 hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IconID)); 00088 (void)SendMessage(hWindow,WM_SETICON,1,(LRESULT)hIcon); 00089 if(hIcon) (void)DeleteObject(hIcon); 00090 } 00091 00099 HFONT __stdcall WgxSetFont(HWND hWindow,LPLOGFONT lplf) 00100 { 00101 HFONT hFont; 00102 HWND hChild; 00103 00104 hFont = CreateFontIndirect(lplf); 00105 if(!hFont) return NULL; 00106 00107 (void)SendMessage(hWindow,WM_SETFONT,(WPARAM)hFont,MAKELPARAM(TRUE,0)); 00108 hChild = GetWindow(hWindow,GW_CHILD); 00109 while(hChild){ 00110 (void)SendMessage(hChild,WM_SETFONT,(WPARAM)hFont,MAKELPARAM(TRUE,0)); 00111 hChild = GetWindow(hChild,GW_HWNDNEXT); 00112 } 00113 00114 /* redraw the main window */ 00115 (void)InvalidateRect(hWindow,NULL,TRUE); 00116 (void)UpdateWindow(hWindow); 00117 00118 return hFont; 00119 } 00120 00130 void __stdcall WgxCheckWindowCoordinates(LPRECT lprc,int min_width,int min_height) 00131 { 00132 int cx,cy; 00133 00134 cx = GetSystemMetrics(SM_CXSCREEN); 00135 cy = GetSystemMetrics(SM_CYSCREEN); 00136 if(lprc->left < 0) lprc->left = 0; if(lprc->top < 0) lprc->top = 0; 00137 if(lprc->left >= (cx - min_width)) lprc->left = cx - min_width; 00138 if(lprc->top >= (cy - min_height)) lprc->top = cy - min_height; 00139 } 00140 00145 BOOL __stdcall WgxShellExecuteW(HWND hwnd,LPCWSTR lpOperation,LPCWSTR lpFile, 00146 LPCWSTR lpParameters,LPCWSTR lpDirectory,INT nShowCmd) 00147 { 00148 HINSTANCE hApp; 00149 int error_code; 00150 char *error_description = ""; 00151 short *error_msg; 00152 int buffer_length; 00153 00154 hApp = ShellExecuteW(hwnd,lpOperation,lpFile,lpParameters,lpDirectory,nShowCmd); 00155 error_code = (int)(LONG_PTR)hApp; 00156 if(error_code > 32) return TRUE; 00157 00158 /* handle errors */ 00159 switch(error_code){ 00160 case 0: 00161 error_description = "The operating system is out of memory or resources."; 00162 break; 00163 case ERROR_FILE_NOT_FOUND: 00164 /*case SE_ERR_FNF:*/ 00165 error_description = "The specified file was not found."; 00166 break; 00167 case ERROR_PATH_NOT_FOUND: 00168 /*case SE_ERR_PNF:*/ 00169 error_description = "The specified path was not found."; 00170 break; 00171 case ERROR_BAD_FORMAT: 00172 error_description = "The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image)."; 00173 break; 00174 case SE_ERR_ACCESSDENIED: 00175 error_description = "The operating system denied access to the specified file."; 00176 break; 00177 case SE_ERR_ASSOCINCOMPLETE: 00178 error_description = "The file name association is incomplete or invalid."; 00179 break; 00180 case SE_ERR_DDEBUSY: 00181 error_description = "The Dynamic Data Exchange (DDE) transaction could not be completed\n" 00182 " because other DDE transactions were being processed."; 00183 break; 00184 case SE_ERR_DDEFAIL: 00185 error_description = "The DDE transaction failed."; 00186 break; 00187 case SE_ERR_DDETIMEOUT: 00188 error_description = "The DDE transaction could not be completed because the request timed out."; 00189 break; 00190 case SE_ERR_DLLNOTFOUND: 00191 error_description = "The specified dynamic-link library (DLL) was not found."; 00192 break; 00193 case SE_ERR_NOASSOC: 00194 error_description = "There is no application associated with the given file name extension.\n" 00195 "Or you attempt to print a file that is not printable."; 00196 break; 00197 case SE_ERR_OOM: 00198 error_description = "There was not enough memory to complete the operation."; 00199 break; 00200 case SE_ERR_SHARE: 00201 error_description = "A sharing violation occurred."; 00202 break; 00203 } 00204 00205 if(!lpOperation) lpOperation = L"open"; 00206 if(!lpFile) lpFile = L""; 00207 if(!lpParameters) lpParameters = L""; 00208 00209 buffer_length = wcslen(lpOperation) + wcslen(lpFile) + wcslen(lpParameters); 00210 buffer_length += strlen(error_description); 00211 buffer_length += 64; 00212 00213 error_msg = malloc(buffer_length * sizeof(short)); 00214 if(error_msg == NULL){ 00215 MessageBoxW(hwnd,L"Not enough memory!",L"Error!",MB_OK | MB_ICONHAND); 00216 return FALSE; 00217 } 00218 00219 (void)_snwprintf(error_msg,buffer_length,L"Cannot %ls %ls %ls\n%hs", 00220 lpOperation,lpFile,lpParameters,error_description); 00221 error_msg[buffer_length-1] = 0; 00222 00223 MessageBoxW(hwnd,error_msg,L"Error!",MB_OK | MB_ICONHAND); 00224 free(error_msg); 00225 return FALSE; 00226 } 00227