00001 #include <windows.h>
00002 #include "CommunTools.h"
00003 #include "MyString.h"
00004 #include <stdio.h>
00005
00006
00007
00008 void DrawTextOnFirstPlan(char *text,BOOL shadowMode)
00009 {
00010 int len = (int)strlen(text);
00011 HWND hWnd = GetDesktopWindow();
00012 HDC hDC = GetDC(NULL);
00013
00014 HFONT hFont = CreateFont(100,45,0,0,0,0,0,0,0,0,0,0,0,"Arial");
00015 HFONT hFontOld = (HFONT) SelectObject(hDC,hFont);
00016 RECT rect;
00017 GetWindowRect(hWnd,&rect);
00018
00019 SetBkMode(hDC,TRANSPARENT);
00020
00021 if (shadowMode)
00022 {
00023 SetTextColor(hDC, RGB(64,64,64));
00024 for (int i=0;i<3;i++)
00025 {
00026 for (int j=0;j<3;j++)
00027 {
00028 DrawText(hDC,text,len,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
00029 rect.right+=1;
00030 rect.left+=1;
00031 }
00032 rect.right-=3;
00033 rect.left-=3;
00034 rect.bottom+=1;
00035 rect.top+=1;
00036 }
00037
00038
00039 rect.right+=1;
00040 rect.left+=1;
00041 rect.bottom-=2;
00042 rect.top-=2;
00043 }
00044 SetTextColor(hDC, RGB(0,255,0));
00045 DrawText(hDC,text,len,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
00046 SelectObject(hDC,hFontOld);
00047 }
00048
00053 void MyOpenBrowser(char *url)
00054 {
00055 char Browser[MAX_PATH];
00056 char RegPath[MAX_PATH + MAX_PATH];
00057 char RegValue [MAX_PATH + MAX_PATH] ;
00058 DWORD DataSize = MAX_PATH;
00059 static HINSTANCE hShell=NULL;
00060 DWORD type = REG_SZ ;
00061 HKEY hKey;
00062
00063 RegOpenKeyEx(HKEY_CLASSES_ROOT, ".htm", 0, KEY_QUERY_VALUE, &hKey);
00064 RegQueryValueEx(hKey,NULL,NULL,&type,(unsigned char *)RegPath,&DataSize);
00065 RegCloseKey(hKey);
00066
00067 strcat(RegPath,"\\shell\\open\\command");
00068 DataSize = MAX_PATH*2; type = REG_SZ ;
00069 RegOpenKeyEx(HKEY_CLASSES_ROOT, RegPath,0, KEY_QUERY_VALUE ,&hKey) ;
00070 RegQueryValueEx(hKey,NULL,NULL,&type,(unsigned char *)RegValue,&DataSize) ;
00071
00072 RegCloseKey(hKey);
00073
00074 char *pos = strstr(RegValue,"\"%1\"");
00075 if(!pos )
00076 {
00077 pos = strstr(RegValue,"%1");
00078 if(pos == NULL) pos = RegValue+strlen(RegValue)-1;
00079 else *pos = '\0';
00080 } else *pos = '\0';
00081 pos = strstr(RegValue, " -") ;
00082 if (pos != NULL) *pos = '\0' ;
00083 char *q = Browser ;
00084 for (size_t i = 0; i < strlen (RegValue) ; i++)
00085 {
00086 if (RegValue[i] != '\"')
00087 {
00088 *q = RegValue[i];
00089 q++ ;
00090 }
00091 }
00092 *q = '\0' ;
00093
00094 ShellExecute(NULL,"open",Browser,url,NULL,SW_SHOW);
00095 }
00096
00097
00098
00099 void ErrorMessage(BOOL useLastError, UINT type, const TCHAR* message, ...)
00100 {
00101 const INT bufferSize = 4096;
00102 static TCHAR buffer[bufferSize];
00103
00104 if(message != NULL)
00105 {
00106 va_list ap;
00107 va_start(ap, message);
00108 vsprintf(buffer, message, ap);
00109 va_end(ap);
00110 }
00111 else
00112 lstrcpy(buffer, TEXT(""));
00113
00114 if(useLastError)
00115 {
00116 DWORD lastError = GetLastError();
00117
00118 TCHAR* lastErrorMsg = NULL;
00119 DWORD size = FormatMessage(
00120 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00121 NULL,
00122 lastError,
00123 0,
00124 (TCHAR*)&lastErrorMsg,
00125 bufferSize / 2,
00126 NULL);
00127 if(size == 0)
00128 SetLastError(lastError);
00129
00130 const TCHAR unknownError[] = TEXT("Unknown error.");
00131
00132 if(lstrlen(buffer) > 0)
00133 {
00134 static TCHAR temp[bufferSize];
00135 wsprintf(
00136 temp,
00137 TEXT("%s\n\n%s"),
00138 buffer,
00139 (lastErrorMsg != NULL) ?
00140 lastErrorMsg : unknownError);
00141 lstrcpy(buffer, temp);
00142 }
00143 else
00144 lstrcpy(
00145 buffer,
00146 (lastErrorMsg != NULL) ?
00147 lastErrorMsg : unknownError);
00148
00149 if(lastErrorMsg != NULL)
00150 LocalFree(lastErrorMsg);
00151 }
00152
00153 HWND hWndFocus = GetFocus();
00154 MessageBox(NULL, buffer, "Error on 3D Controls", type);
00155 if(hWndFocus != NULL && IsWindow(hWndFocus)) SetFocus(hWndFocus);
00156 }
00157
00158
00159
00160 BOOL Run(char *exe,char *message)
00161 {
00162 char *prog = exe;
00163 char *parameter = NULL;
00164
00165 char sep=' ';
00166 if (exe[0]=='\"')
00167 {
00168 sep='\"';
00169 prog++;
00170 }
00171
00172 for (unsigned int i=0;i<strlen(prog);i++)
00173 if (prog[i]==sep)
00174 {
00175 if (i<(strlen(prog)-1)) parameter = prog+i+1+(sep=='\"');
00176 prog[i]='\0';
00177 break;
00178 }
00179
00180 HINSTANCE hInstExe = ShellExecute(NULL,"open",prog,parameter,NULL,SW_SHOW);
00181 BOOL state =FALSE;
00182 MyString textErr;
00183 switch ((long)hInstExe)
00184 {
00185 case 0: textErr="The operating system is out of memory or resources."; break;
00186 case ERROR_FILE_NOT_FOUND: textErr="The specified file was not found."; break;
00187 case ERROR_PATH_NOT_FOUND: textErr="The specified path was not found."; break;
00188 case ERROR_BAD_FORMAT: textErr="The .exe file is invalid (non-Win32® .exe or error in .exe image)."; break;
00189 case SE_ERR_ACCESSDENIED: textErr="The operating system denied access to the specified file. ";break;
00190 case SE_ERR_ASSOCINCOMPLETE: textErr="The file name association is incomplete or invalid."; break;
00191 case SE_ERR_DDEBUSY: textErr="The DDE transaction could not be completed because other DDE transactions were being processed."; break;
00192 case SE_ERR_DDEFAIL: textErr="The DDE transaction failed."; break;
00193 case SE_ERR_DDETIMEOUT: textErr="The DDE transaction could not be completed because the request timed out."; break;
00194 case SE_ERR_DLLNOTFOUND: textErr="The specified dynamic-link library was not found."; break;
00195 case SE_ERR_NOASSOC: textErr="There is no application associated with the given file name extension."; break;
00196 case SE_ERR_OOM: textErr="There was not enough memory to complete the operation."; break;
00197 case SE_ERR_SHARE: textErr="A sharing violation occurred."; break;
00198 default:
00199 state = TRUE;
00200 textErr = "Lancemennt correct !";
00201 }
00202
00203 if (message) strcpy (message,textErr);
00204
00205 if (parameter) prog[i]=sep;
00206 return state;
00207 }
00208
00209 void MailTo (char *eMail)
00210 {
00211 MyString temp;
00212 temp<<"mailto:"<<eMail;
00213 ShellExecute(NULL,"open",temp,NULL,NULL,0);
00214 }