Commit 183a3caf335e5b77f4137f33557b868cbc74b33d

Authored by xiemeng
1 parent 382df1f4

first_update

Too many changes to show.

To preserve performance only 11 of 28 files are displayed.

@@ -96,6 +96,9 @@ IniData_struct g_IniData[] = @@ -96,6 +96,9 @@ IniData_struct g_IniData[] =
96 {"Check Fastboot OEM Lock Enable", (bool*)&g_sMetaComm.bCheckFastbootLock, INI_BOOLEAN}, 96 {"Check Fastboot OEM Lock Enable", (bool*)&g_sMetaComm.bCheckFastbootLock, INI_BOOLEAN},
97 {"Check Calibration flag Enable", (bool*)&g_sMetaComm.bCheckCalFlag, INI_BOOLEAN}, 97 {"Check Calibration flag Enable", (bool*)&g_sMetaComm.bCheckCalFlag, INI_BOOLEAN},
98 {"Check FinalTest flag Enable", (bool*)&g_sMetaComm.bCheckFtFlag, INI_BOOLEAN}, 98 {"Check FinalTest flag Enable", (bool*)&g_sMetaComm.bCheckFtFlag, INI_BOOLEAN},
  99 + {"Check QCTest flag Enable", (bool*)&g_sMetaComm.bCheckQCFlag, INI_BOOLEAN},
  100 + {"QCTest_flag_index", (bool*)&g_sMetaComm.QCFlag_index, INI_INTEGER},
  101 + {"Check_SW_VER", (char*)&g_sMetaComm.check_sw_ver, INI_STRING},
99 // C2K Modem 102 // C2K Modem
100 {"Write Meid", (bool*)&g_sMetaComm.sWriteOption.bWriteMeid, INI_BOOLEAN}, 103 {"Write Meid", (bool*)&g_sMetaComm.sWriteOption.bWriteMeid, INI_BOOLEAN},
101 {"Write Esn", (bool*)&g_sMetaComm.sWriteOption.bWriteEsn, INI_BOOLEAN}, 104 {"Write Esn", (bool*)&g_sMetaComm.sWriteOption.bWriteEsn, INI_BOOLEAN},
@@ -275,6 +275,9 @@ typedef struct { @@ -275,6 +275,9 @@ typedef struct {
275 bool bSkipWriteProdInfo; 275 bool bSkipWriteProdInfo;
276 bool bCheckCalFlag; 276 bool bCheckCalFlag;
277 bool bCheckFtFlag; 277 bool bCheckFtFlag;
  278 + bool bCheckQCFlag;
  279 + UINT QCFlag_index;
  280 + char check_sw_ver[255];
278 bool bCheckBTWifi; 281 bool bCheckBTWifi;
279 bool bCheckBackNVtoPC; 282 bool bCheckBackNVtoPC;
280 bool bCheckFastbootLock; 283 bool bCheckFastbootLock;
@@ -932,10 +932,8 @@ void FeaturePhoneSN::ThreadMainEntryPoint() @@ -932,10 +932,8 @@ void FeaturePhoneSN::ThreadMainEntryPoint()
932 EnableStartBTN(false); 932 EnableStartBTN(false);
933 933
934 SNThread_Init(); 934 SNThread_Init();
935 - UpdateProgress(0.05);  
936 935
937 SetupMetaModeParameters(); 936 SetupMetaModeParameters();
938 - UpdateProgress(0.10);  
939 937
940 EnableStartBTN(true); 938 EnableStartBTN(true);
941 939
@@ -946,7 +944,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint() @@ -946,7 +944,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint()
946 UpdateUIMsg("EnterModemMeta() : MetaResult = %s", ResultToString(MetaResult)); 944 UpdateUIMsg("EnterModemMeta() : MetaResult = %s", ResultToString(MetaResult));
947 goto End; 945 goto End;
948 } 946 }
949 - UpdateProgress(0.15);  
950 947
951 UpdateUIMsg("Start load and init database..."); 948 UpdateUIMsg("Start load and init database...");
952 MetaResult = LoadModemDatabase(0); 949 MetaResult = LoadModemDatabase(0);
@@ -957,7 +954,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint() @@ -957,7 +954,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint()
957 PopupMsgBox("Error", MB_OK|MB_ICONERROR, "LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult)); 954 PopupMsgBox("Error", MB_OK|MB_ICONERROR, "LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult));
958 goto End; 955 goto End;
959 } 956 }
960 - UpdateProgress(0.20);  
961 957
962 /* 958 /*
963 META_MISC_GetRID_r(m_hMauiMetaHandle, 5000, (unsigned char*)strChipID,16); 959 META_MISC_GetRID_r(m_hMauiMetaHandle, 5000, (unsigned char*)strChipID,16);
@@ -969,7 +965,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint() @@ -969,7 +965,6 @@ void FeaturePhoneSN::ThreadMainEntryPoint()
969 */ 965 */
970 966
971 EnableStartBTN(false); 967 EnableStartBTN(false);
972 - UpdateProgress(0.22);  
973 UpdateUIMsg("Start loop write data to nvram..."); 968 UpdateUIMsg("Start loop write data to nvram...");
974 MetaResult = WriteNvramLoop(); 969 MetaResult = WriteNvramLoop();
975 if (MetaResult != META_SUCCESS) 970 if (MetaResult != META_SUCCESS)
@@ -981,14 +976,12 @@ void FeaturePhoneSN::ThreadMainEntryPoint() @@ -981,14 +976,12 @@ void FeaturePhoneSN::ThreadMainEntryPoint()
981 End: 976 End:
982 if (m_bStopBeforeUSBInsert == true) 977 if (m_bStopBeforeUSBInsert == true)
983 { 978 {
984 - UpdateProgress(0.0);  
985 UpdateUIMsg("..."); 979 UpdateUIMsg("...");
986 } 980 }
987 else 981 else
988 { 982 {
989 if (bAnyOperationFail) 983 if (bAnyOperationFail)
990 { 984 {
991 - m_Process->SendMessage(PBM_SETBARCOLOR, 0, RGB(255, 0, 0));  
992 UpdateUICountResult(FAIL); 985 UpdateUICountResult(FAIL);
993 } 986 }
994 else 987 else
@@ -1006,7 +999,6 @@ End: @@ -1006,7 +999,6 @@ End:
1006 999
1007 ExitModemMeta(); 1000 ExitModemMeta();
1008 1001
1009 - UpdateProgress(1.0);  
1010 } 1002 }
1011 1003
1012 EnableStartBTN(true); 1004 EnableStartBTN(true);
@@ -149,13 +149,6 @@ UINT SNBase::ThreadStaticEntryPoint(LPVOID pThis) @@ -149,13 +149,6 @@ UINT SNBase::ThreadStaticEntryPoint(LPVOID pThis)
149 return 1; 149 return 1;
150 } 150 }
151 151
152 -void SNBase::SetProgress()  
153 -{  
154 - m_iProcessRange = 1000;  
155 - m_Process->SetRange(0, m_iProcessRange);  
156 - m_Process->SendMessage(PBM_SETBARCOLOR, 0, RGB(0, 0, 255));  
157 - UpdateProgress(0.01);  
158 -}  
159 152
160 int SNBase::UpdateUIMsg(const char * strMsg, ...) 153 int SNBase::UpdateUIMsg(const char * strMsg, ...)
161 { 154 {
@@ -166,9 +159,7 @@ int SNBase::UpdateUIMsg(const char * strMsg, ...) @@ -166,9 +159,7 @@ int SNBase::UpdateUIMsg(const char * strMsg, ...)
166 va_start(varg, strMsg); 159 va_start(varg, strMsg);
167 iRet = vsprintf(szBuf, strMsg, varg); 160 iRet = vsprintf(szBuf, strMsg, varg);
168 va_end(varg); 161 va_end(varg);
169 -  
170 - g_pMainDlg->SetDlgItemText(IDC_OPERATE_INFO, szBuf);  
171 - 162 + g_pMainDlg->myloglist.SetCurSel(g_pMainDlg->myloglist.AddString(szBuf));
172 return iRet; 163 return iRet;
173 } 164 }
174 165
@@ -197,12 +188,6 @@ void SNBase::UpdateUICountResult(WriteNvram_Status_e eWriteStatus) @@ -197,12 +188,6 @@ void SNBase::UpdateUICountResult(WriteNvram_Status_e eWriteStatus)
197 { 188 {
198 failNums += 1; 189 failNums += 1;
199 } 190 }
200 - sprintf(strTotal, "%d", totalNums);  
201 - sprintf(strPass, "%d", passNums);  
202 - sprintf(strFail, "%d", failNums);  
203 - g_pMainDlg->SetDlgItemText(IDC_COUNT_TOTAL, strTotal);  
204 - g_pMainDlg->SetDlgItemText(IDC_COUNT_PASS, strPass);  
205 - g_pMainDlg->SetDlgItemText(IDC_COUNT_FAIL, strFail);  
206 191
207 UpdateMainDlgUI(true, eWriteStatus); 192 UpdateMainDlgUI(true, eWriteStatus);
208 } 193 }
@@ -226,16 +211,6 @@ void SNBase::UpdateMainDlgUI(bool bEnable, WriteNvram_Status_e eWriteStatus) @@ -226,16 +211,6 @@ void SNBase::UpdateMainDlgUI(bool bEnable, WriteNvram_Status_e eWriteStatus)
226 211
227 } 212 }
228 213
229 -void SNBase::UpdateProgress(double dPercent)  
230 -{  
231 - if (dPercent >= 1)  
232 - {  
233 - dPercent = 1;  
234 - }  
235 -  
236 - int curPos = (int)(dPercent * m_iProcessRange);  
237 - m_Process->SetPos(curPos);  
238 -}  
239 214
240 void SNBase::PopupMsgBox(const char* strTilte, UINT uType, const char* strMsg, ...) 215 void SNBase::PopupMsgBox(const char* strTilte, UINT uType, const char* strMsg, ...)
241 { 216 {
@@ -250,22 +225,7 @@ void SNBase::PopupMsgBox(const char* strTilte, UINT uType, const char* strMsg, . @@ -250,22 +225,7 @@ void SNBase::PopupMsgBox(const char* strTilte, UINT uType, const char* strMsg, .
250 225
251 bool SNBase::NeedScanData() 226 bool SNBase::NeedScanData()
252 { 227 {
253 - if (g_sMetaComm.sWriteOption.bWriteBarcode ||  
254 - g_sMetaComm.sWriteOption.bWriteIMEI ||  
255 - g_sMetaComm.sWriteOption.bWriteBT ||  
256 - g_sMetaComm.sWriteOption.bWriteWifi ||  
257 - g_sMetaComm.sWriteOption.bWriteEthernetMac ||  
258 - g_sMetaComm.sWriteOption.bWriteDrmkeyMCID ||  
259 - g_sMetaComm.sWriteOption.bWriteMeid ||  
260 - g_sMetaComm.sWriteOption.bWriteEsn ||  
261 - g_sMetaComm.sWriteOption.bWriteSerialNo)  
262 - {  
263 - return true;  
264 - }  
265 - else  
266 - {  
267 - return false;  
268 - } 228 + return true;
269 } 229 }
270 230
271 CheckCalFlag_Status_e SNBase::CheckCalibrationStatus(const char* strBarcode) 231 CheckCalFlag_Status_e SNBase::CheckCalibrationStatus(const char* strBarcode)
@@ -1209,8 +1169,6 @@ void SNBase::SNThread_Init() @@ -1209,8 +1169,6 @@ void SNBase::SNThread_Init()
1209 //Get main dialog handle 1169 //Get main dialog handle
1210 //g_pMainDlg = (CSNWriterDlg*)g_MainDlgHandle; 1170 //g_pMainDlg = (CSNWriterDlg*)g_MainDlgHandle;
1211 1171
1212 - m_Process = &(g_pMainDlg->m_ProgressSN);  
1213 - SetProgress();  
1214 1172
1215 m_bNeedBackupIMEI = false; 1173 m_bNeedBackupIMEI = false;
1216 memset(m_strBackupIMEI, 0, IMEI_ARRAY_LEN); 1174 memset(m_strBackupIMEI, 0, IMEI_ARRAY_LEN);
@@ -98,8 +98,6 @@ protected: @@ -98,8 +98,6 @@ protected:
98 virtual META_RESULT WriteNvramLoop() = 0; 98 virtual META_RESULT WriteNvramLoop() = 0;
99 99
100 virtual META_RESULT LoadModemDatabase(int MDindex) = 0; 100 virtual META_RESULT LoadModemDatabase(int MDindex) = 0;
101 - virtual void UpdateProgress(double dPercent);  
102 - virtual void SetProgress();  
103 101
104 virtual META_RESULT ConductBarcodeData(char *pOutData, unsigned short RID_para, char *pInDatabuf, int bufSize); 102 virtual META_RESULT ConductBarcodeData(char *pOutData, unsigned short RID_para, char *pInDatabuf, int bufSize);
105 virtual META_RESULT ConductIMEIData(char *pOutData, unsigned short RID_para, char *pInDatabuf, int bufSize); 103 virtual META_RESULT ConductIMEIData(char *pOutData, unsigned short RID_para, char *pInDatabuf, int bufSize);
@@ -137,7 +135,6 @@ public: @@ -137,7 +135,6 @@ public:
137 void EnableStartBTN(bool bEnable = true); 135 void EnableStartBTN(bool bEnable = true);
138 136
139 protected: 137 protected:
140 - CProgressCtrl *m_Process;  
141 UINT m_iProcessRange; 138 UINT m_iProcessRange;
142 bool m_bBackupNvramSuccess; 139 bool m_bBackupNvramSuccess;
143 }; 140 };
@@ -168,7 +168,7 @@ META_RESULT SmartPhoneSN::WriteNvramLoop() @@ -168,7 +168,7 @@ META_RESULT SmartPhoneSN::WriteNvramLoop()
168 iRet = APSwithToModemMeta_Ex(); 168 iRet = APSwithToModemMeta_Ex();
169 if (iRet == META_SUCCESS) 169 if (iRet == META_SUCCESS)
170 { 170 {
171 - spNextStage = SP_CHECK_CAL_FT_FLAG_STAGE; 171 + spNextStage = SP_BARCODE_MD_STAGE;
172 } 172 }
173 else 173 else
174 { 174 {
@@ -178,73 +178,29 @@ META_RESULT SmartPhoneSN::WriteNvramLoop() @@ -178,73 +178,29 @@ META_RESULT SmartPhoneSN::WriteNvramLoop()
178 break; 178 break;
179 179
180 case SP_CHECK_CAL_FT_FLAG_STAGE: 180 case SP_CHECK_CAL_FT_FLAG_STAGE:
181 - if (g_sMetaComm.bCheckCalFlag || g_sMetaComm.bCheckFtFlag)  
182 { 181 {
183 char tmpBuf[2048] = {0}; 182 char tmpBuf[2048] = {0};
184 - iRet = REQ_ReadModem_NVRAM_Start(WRITE_BARCODE, tmpBuf, 1); 183 + iRet = REQ_ReadModem_NVRAM_Start(WRITE_BARCODE, m_sScanData.strBarcode, 1);
185 if (iRet == META_SUCCESS) 184 if (iRet == META_SUCCESS)
186 { 185 {
187 - bool bCheckPass = true;  
188 - bCheckPass = CheckCalFinalTestStatus(tmpBuf);  
189 - if (bCheckPass == true)  
190 - {  
191 - spNextStage = SP_BARCODE_MD_STAGE;  
192 - }  
193 - else  
194 - {  
195 - iRet = META_FAILED;  
196 - spNextStage = SP_END_STAGE;  
197 - } 186 + g_pMainDlg->mybarcode = CString(m_sScanData.strBarcode);
  187 + g_pMainDlg->GetDlgItem(IDC_STATIC_BARCODE)->SetWindowText(m_sScanData.strBarcode);
  188 + spNextStage = SP_BARCODE_MD_STAGE;
198 } 189 }
199 else 190 else
200 { 191 {
201 - UpdateUIMsg("ERROR!! Read Barcode: MetaResult = %s", ResultToString(iRet));  
202 spNextStage = SP_END_STAGE; 192 spNextStage = SP_END_STAGE;
203 } 193 }
204 } 194 }
205 - else  
206 - {  
207 - spNextStage = SP_BARCODE_MD_STAGE;  
208 - }  
209 break; 195 break;
210 196
  197 +
211 case SP_BARCODE_MD_STAGE: 198 case SP_BARCODE_MD_STAGE:
212 if (g_sMetaComm.sWriteOption.bWriteIMEI) 199 if (g_sMetaComm.sWriteOption.bWriteIMEI)
213 - {  
214 - if (mdNums == 1 && g_sMetaComm.sIMEIOption.iImeiNums == 1)  
215 - {  
216 - multiIMEIOption = SINGLE_MD_SINGLE_IMEI;  
217 - }  
218 - else if (mdNums == 1 && g_sMetaComm.sIMEIOption.iImeiNums >= 2)  
219 - {  
220 - multiIMEIOption = SINGLE_MD_MULTI_IMEI;  
221 - }  
222 - else if (mdNums == 2)  
223 - {  
224 - if (m_iC2kProject != 0 && g_sMetaComm.sIMEIOption.iImeiNums == 1)  
225 - {  
226 - multiIMEIOption = SINGLE_MD_SINGLE_IMEI;  
227 - }  
228 - if (m_iC2kProject != 0 && g_sMetaComm.sIMEIOption.iImeiNums >= 2 )  
229 - {  
230 - multiIMEIOption = SINGLE_MD_MULTI_IMEI;  
231 - }  
232 - if (g_sMetaComm.eTargetType == SMART_PHONE_DUALMODEM && g_sMetaComm.sIMEIOption.iImeiNums == 2)  
233 - {  
234 - multiIMEIOption = DUAL_MD_DUAL_IMEI;  
235 - }  
236 - }  
237 - else  
238 - {  
239 - multiIMEIOption = MULTIIMEI_RESERVE;  
240 - }  
241 - } 200 + multiIMEIOption = DUAL_MD_DUAL_IMEI;
242 spNextStage = SP_IMEI_MD_STAGE; 201 spNextStage = SP_IMEI_MD_STAGE;
243 -  
244 break; 202 break;
245 -  
246 case SP_IMEI_MD_STAGE: 203 case SP_IMEI_MD_STAGE:
247 -  
248 bWriteModemFail = false; 204 bWriteModemFail = false;
249 for (MDIndex = 0; MDIndex < mdNums && bWriteModemFail == false; MDIndex++) 205 for (MDIndex = 0; MDIndex < mdNums && bWriteModemFail == false; MDIndex++)
250 { 206 {
@@ -277,7 +233,39 @@ META_RESULT SmartPhoneSN::WriteNvramLoop() @@ -277,7 +233,39 @@ META_RESULT SmartPhoneSN::WriteNvramLoop()
277 { 233 {
278 fBeginProcess += fStep; 234 fBeginProcess += fStep;
279 MTRACE(g_hEBOOT_DEBUG, "Barcode[%d] = \"%s\"", MDIndex, m_sScanData.strBarcode); 235 MTRACE(g_hEBOOT_DEBUG, "Barcode[%d] = \"%s\"", MDIndex, m_sScanData.strBarcode);
280 - iRet = REQ_WriteModem_NVRAM_Start(WRITE_BARCODE, m_sScanData.strBarcode, 1); 236 + switch (g_pMainDlg->myintcft)
  237 + {
  238 + case 0:
  239 + m_sScanData.strBarcode[60] = ' ';
  240 + m_sScanData.strBarcode[61] = ' ';
  241 + m_sScanData.strBarcode[62] = ' ';
  242 + break;
  243 + case 1:
  244 + m_sScanData.strBarcode[60] = '1';
  245 + m_sScanData.strBarcode[61] = '0';
  246 + m_sScanData.strBarcode[62] = 'P';
  247 + break;
  248 + case 2:
  249 + m_sScanData.strBarcode[60] = '0';
  250 + m_sScanData.strBarcode[61] = '1';
  251 + m_sScanData.strBarcode[62] = 'F';
  252 + break;
  253 + }
  254 +
  255 + switch (g_pMainDlg->myintsmt)
  256 + {
  257 + case 0:
  258 + m_sScanData.strBarcode[55] = ' ';
  259 + break;
  260 + case 1:
  261 + m_sScanData.strBarcode[55] = '1';
  262 + break;
  263 + case 2:
  264 + m_sScanData.strBarcode[55] = '3';
  265 + break;
  266 + }
  267 +
  268 + iRet = REQ_WriteModem_NVRAM_Start(WRITE_BARCODE, m_sScanData.strBarcode, 1);
281 if (iRet != META_SUCCESS) 269 if (iRet != META_SUCCESS)
282 { 270 {
283 UpdateUIMsg("ERROR!! Barcode[%d] : MetaResult = %s", MDIndex, ResultToString(iRet)); 271 UpdateUIMsg("ERROR!! Barcode[%d] : MetaResult = %s", MDIndex, ResultToString(iRet));
@@ -371,296 +359,10 @@ META_RESULT SmartPhoneSN::WriteNvramLoop() @@ -371,296 +359,10 @@ META_RESULT SmartPhoneSN::WriteNvramLoop()
371 } 359 }
372 } 360 }
373 361
374 - if (bWriteModemFail == true)  
375 - {  
376 spNextStage = SP_END_STAGE; 362 spNextStage = SP_END_STAGE;
377 - }  
378 - else  
379 - {  
380 - spNextStage = SP_C2K_STAGE;  
381 - }  
382 -  
383 - break;  
384 -  
385 - case SP_C2K_STAGE:  
386 - fBeginProcess += fStep;  
387 - if (g_sMetaComm.sWriteOption.bWriteMeid || g_sMetaComm.sWriteOption.bWriteEsn)  
388 - {  
389 - if (m_iC2kProject != 0)  
390 - iRet = EnterC2KGen90();  
391 - else  
392 - iRet = EnterC2KGen93();  
393 -  
394 - if (iRet != META_SUCCESS)  
395 - {  
396 - spNextStage = SP_END_STAGE;  
397 - break;  
398 - }  
399 - }  
400 - spNextStage = SP_MD2AP_STAGE;  
401 - break;  
402 -  
403 - case SP_MD2AP_STAGE:  
404 -  
405 - if (g_sMetaComm.sIMEIOption.bLockOtp)  
406 - {  
407 - iRet = LockOTP();  
408 - if (iRet != 0)  
409 - {  
410 - spNextStage = SP_END_STAGE;  
411 - break;  
412 - }  
413 - }  
414 -  
415 - fBeginProcess += fStep;  
416 - iRet = ModemSwithToAPMeta();  
417 - if (iRet == META_SUCCESS)  
418 - {  
419 - spNextStage = SP_WRITE_TEMP_STAGE;  
420 - }  
421 - else  
422 - {  
423 - spNextStage = SP_END_STAGE;  
424 - }  
425 - break;  
426 -  
427 - case SP_WRITE_TEMP_STAGE:  
428 - if (QuerySpeakerCalibrationSupport() == SPMETA_DLL::META_SUCCESS && g_sMetaComm.sIMEIOption.Temp_Option.bWriteTemperature) //Query support yes or no from target  
429 - {  
430 - fBeginProcess += fStep;  
431 - float minTemp = 20.0;  
432 - float maxTemp = 30.0;  
433 - float curTemp = 0.0;  
434 - curTemp = atof(g_sMetaComm.sIMEIOption.Temp_Option.strTemperatureData);  
435 -  
436 - MTRACE(g_hEBOOT_DEBUG, "CurTemperature = \"%s\"", g_sMetaComm.sIMEIOption.Temp_Option.strTemperatureData);  
437 - if ((minTemp <= curTemp) && (curTemp <= maxTemp))  
438 - {  
439 - iRet = REQ_WriteAP_NVRAM_Start(WRITE_TEMPERATURE, g_sMetaComm.sIMEIOption.Temp_Option.strTemperatureData, 1);  
440 - if (iRet == META_SUCCESS)  
441 - {  
442 - spNextStage = SP_BT_ADDRESS_STAGE;  
443 - }  
444 - else  
445 - {  
446 - UpdateUIMsg("ERROR!! Audio_Temperature : MetaResult = %s", ResultToString_SP(iRet));  
447 - spNextStage = SP_END_STAGE;  
448 - }  
449 - }  
450 - else  
451 - {  
452 - UpdateUIMsg("Warning: Temperature must be between 20.0~30.0, please reset current temperature!!");  
453 - MTRACE(g_hEBOOT_DEBUG, "Warning: Temperature must be between 20.0~30.0, please reset current temperature!!");  
454 - iRet = META_FAILED;  
455 - spNextStage = SP_END_STAGE;  
456 - }  
457 - }  
458 - else  
459 - {  
460 - spNextStage = SP_BT_ADDRESS_STAGE;  
461 - }  
462 - break;  
463 -  
464 - case SP_BT_ADDRESS_STAGE:  
465 - if (g_sMetaComm.sWriteOption.bWriteBT)  
466 - {  
467 - fBeginProcess += fStep;  
468 - MTRACE(g_hEBOOT_DEBUG, "BT = \"%s\"", m_sScanData.strBTAddr);  
469 - iRet = REQ_WriteAP_NVRAM_Start(WRITE_BT, m_sScanData.strBTAddr, 1);  
470 - if (iRet == META_SUCCESS)  
471 - {  
472 - spNextStage = SP_WIFI_ADDRESS_STAGE;  
473 - }  
474 - else  
475 - {  
476 - UpdateUIMsg("ERROR!! BT : MetaResult = %s", ResultToString_SP(iRet));  
477 - spNextStage = SP_END_STAGE;  
478 - }  
479 - }  
480 - else  
481 - {  
482 - spNextStage = SP_WIFI_ADDRESS_STAGE;  
483 - }  
484 - break;  
485 -  
486 - case SP_WIFI_ADDRESS_STAGE:  
487 - if (g_sMetaComm.sWriteOption.bWriteWifi)  
488 - {  
489 - fBeginProcess += fStep;  
490 - MTRACE(g_hEBOOT_DEBUG, "Wifi = \"%s\"", m_sScanData.strWifiAddr);  
491 - iRet = REQ_WriteAP_NVRAM_Start(WRITE_WIFI, m_sScanData.strWifiAddr, 1);  
492 - if (iRet == META_SUCCESS)  
493 - {  
494 - spNextStage = SP_ETHERNET_MAC_STAGE;  
495 - }  
496 - else  
497 - {  
498 - UpdateUIMsg("ERROR!! Wifi : MetaResult = %s", ResultToString_SP(iRet));  
499 - spNextStage = SP_END_STAGE;  
500 - }  
501 - }  
502 - else  
503 - {  
504 - spNextStage = SP_ETHERNET_MAC_STAGE;  
505 - }  
506 - break;  
507 -  
508 - case SP_ETHERNET_MAC_STAGE:  
509 - if (g_sMetaComm.sWriteOption.bWriteEthernetMac)  
510 - {  
511 - fBeginProcess += fStep;  
512 - MTRACE(g_hEBOOT_DEBUG, "Ethernet Mac = \"%s\"", m_sScanData.strEthernetMac);  
513 - iRet = REQ_WriteAP_NVRAM_Start(WRITE_ETHERNET_MAC, m_sScanData.strEthernetMac, 1);  
514 - if (iRet == META_SUCCESS)  
515 - {  
516 - spNextStage = SP_HDCP_STAGE;  
517 - }  
518 - else  
519 - {  
520 - UpdateUIMsg("ERROR!! Ethernet Mac : MetaResult = %s", ResultToString_SP(iRet));  
521 - spNextStage = SP_END_STAGE;  
522 - }  
523 - }  
524 - else  
525 - {  
526 - spNextStage = SP_HDCP_STAGE;  
527 - }  
528 - break;  
529 -  
530 - case SP_HDCP_STAGE:  
531 - fBeginProcess += fStep;  
532 - if (g_sMetaComm.sWriteOption.bWriteHdcp)  
533 - {  
534 - iRet = REQ_WriteHdcpBinToAPNvram_Start(g_sMetaComm.sLoadFile.strHdcpBinPath);  
535 - if (iRet == META_SUCCESS)  
536 - {  
537 - spNextStage = SP_DRMKEY_STAGE;  
538 - }  
539 - else  
540 - {  
541 - UpdateUIMsg("ERROR!! Hdcp : MetaResult = %s", ResultToString_SP(iRet));  
542 - spNextStage = SP_END_STAGE;  
543 - }  
544 - }  
545 - else  
546 - {  
547 - spNextStage = SP_DRMKEY_STAGE;  
548 - }  
549 - break;  
550 363
551 - case SP_DRMKEY_STAGE:  
552 - fBeginProcess += fStep;  
553 - if (g_sMetaComm.sWriteOption.bWriteDrm)  
554 - {  
555 - iRet = REQ_InstallDRMKey_Start();  
556 - if (iRet == META_SUCCESS)  
557 - {  
558 - spNextStage = SP_HDCPDATA_INSTALL_STAGE;  
559 - }  
560 - else  
561 - {  
562 - UpdateUIMsg("ERROR!! DRMKey : MetaResult = %s", ResultToString_SP(iRet));  
563 - spNextStage = SP_END_STAGE;  
564 - }  
565 - }  
566 - else  
567 - {  
568 - spNextStage = SP_HDCPDATA_INSTALL_STAGE;  
569 - }  
570 break; 364 break;
571 365
572 - case SP_HDCPDATA_INSTALL_STAGE:  
573 - fBeginProcess += fStep;  
574 - if (g_sMetaComm.sWriteOption.bInstallHdcpData)  
575 - {  
576 - iRet = REQ_InstallHdcpData_Start(g_sMetaComm.sLoadFile.strHdcpDataPath, g_sMetaComm.sLoadFile.strHdcpCekPath);  
577 - if (iRet == META_SUCCESS)  
578 - {  
579 - spNextStage = SP_DRMKEY_MCID_STAGE;  
580 - }  
581 - else  
582 - {  
583 - UpdateUIMsg("ERROR!! HdcpData : MetaResult = %s", ResultToString_SP(iRet));  
584 - spNextStage = SP_END_STAGE;  
585 - }  
586 - }  
587 - else  
588 - {  
589 - spNextStage = SP_DRMKEY_MCID_STAGE;  
590 - }  
591 - break;  
592 -  
593 - case SP_DRMKEY_MCID_STAGE:  
594 - fBeginProcess += fStep;  
595 - if (g_sMetaComm.sWriteOption.bWriteDrmkeyMCID)  
596 - {  
597 - iRet = REQ_WriteDRMKeyMCID_Start(m_sScanData.strDrmkeyMCID);  
598 - if (iRet == META_SUCCESS)  
599 - {  
600 - spNextStage = SP_BACKUPNV_TO_PC_STAGE;  
601 - }  
602 - else  
603 - {  
604 - UpdateUIMsg("ERROR!! DRMKeyMCID : MetaResult = %s", ResultToString_SP(iRet));  
605 - spNextStage = SP_END_STAGE;  
606 - }  
607 - }  
608 - else  
609 - {  
610 - spNextStage = SP_BACKUPNV_TO_PC_STAGE;  
611 - }  
612 - break;  
613 -  
614 - case SP_BACKUPNV_TO_PC_STAGE:  
615 - if (g_sMetaComm.bCheckBackNVtoPC)  
616 - {  
617 - fBeginProcess += fStep;  
618 - char NumFile[100] = {0};  
619 - iRet = GetNvramFileName(NumFile);  
620 -  
621 - if (iRet == META_SUCCESS)  
622 - {  
623 - iRet = REQ_BackupNvram2PC_Start(NumFile);  
624 - if (iRet != META_SUCCESS)  
625 - {  
626 - UpdateUIMsg("ERROR!! REQ_BackupNvram2PC_Start : MetaResult = %s", ResultToString_SP(iRet));  
627 - spNextStage = SP_END_STAGE;  
628 - }  
629 - else  
630 - {  
631 - spNextStage = SP_BACKUP_NVRAM_STAGE;  
632 - }  
633 - }  
634 - else  
635 - {  
636 - spNextStage = SP_END_STAGE;  
637 - }  
638 - }  
639 - else  
640 - {  
641 - spNextStage = SP_BACKUP_NVRAM_STAGE;  
642 - }  
643 - break;  
644 -  
645 - case SP_BACKUP_NVRAM_STAGE:  
646 - {  
647 - fBeginProcess += fStep;  
648 -  
649 - iRet = REQ_BackupNvram2BinRegion_Start();  
650 - if (iRet != META_SUCCESS)  
651 - {  
652 - m_bBackupNvramSuccess = false;  
653 - UpdateUIMsg("ERROR!! BackUP : MetaResult = %s", ResultToString_SP(iRet));  
654 - spNextStage = SP_END_STAGE;  
655 - }  
656 - else  
657 - {  
658 - m_bBackupNvramSuccess = true;  
659 - spNextStage = SP_PRODINFO_STAGE;  
660 - }  
661 -  
662 - break;  
663 - }  
664 366
665 case SP_PRODINFO_STAGE: 367 case SP_PRODINFO_STAGE:
666 { 368 {
@@ -680,7 +382,6 @@ META_RESULT SmartPhoneSN::WriteNvramLoop() @@ -680,7 +382,6 @@ META_RESULT SmartPhoneSN::WriteNvramLoop()
680 } 382 }
681 } 383 }
682 384
683 - UpdateProgress(fBeginProcess);  
684 spStage = spNextStage; 385 spStage = spNextStage;
685 } 386 }
686 387
@@ -1744,6 +1445,122 @@ Err: @@ -1744,6 +1445,122 @@ Err:
1744 return meta_result; 1445 return meta_result;
1745 } 1446 }
1746 1447
  1448 +
  1449 +
  1450 +SPMETA_DLL::META_RESULT SmartPhoneSN::REQ_WriteAP_PRODINFO_QC()
  1451 +{
  1452 + SPMETA_DLL::META_RESULT meta_result = SPMETA_DLL::META_SUCCESS;
  1453 + m_bWriteNvram = true;
  1454 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::REQ_WriteAP_PRODINFO_Start(): Write Barcode/Imei/Bt/Wifi/Serial.No to prod_info start...");
  1455 +
  1456 + int iIMEINums = g_sMetaComm.sIMEIOption.iImeiNums;
  1457 + int iMetaTimeout = 5000;
  1458 + int iWriteBufSize = 0;
  1459 + char *pLID = "AP_CFG_REEB_PRODUCT_INFO_LID";
  1460 + char *pFuncName = NULL;
  1461 + unsigned char *pWriteData = NULL;
  1462 +
  1463 + SPMETA_DLL::FT_NVRAM_WRITE_REQ sNVRAM_WriteReq;
  1464 + SPMETA_DLL::FT_NVRAM_READ_REQ sNVRAM_ReadReq;
  1465 + SPMETA_DLL::FT_NVRAM_READ_CNF sNVRAM_ReadCnf;
  1466 + memset(&sNVRAM_WriteReq, 0, sizeof(SPMETA_DLL::FT_NVRAM_WRITE_REQ));
  1467 + memset(&sNVRAM_ReadReq, 0, sizeof(SPMETA_DLL::FT_NVRAM_READ_REQ));
  1468 + memset(&sNVRAM_ReadCnf, 0, sizeof(SPMETA_DLL::FT_NVRAM_READ_CNF));
  1469 + meta_result = SPMETA_DLL::SP_META_NVRAM_GetRecLen(pLID, &iWriteBufSize);
  1470 + if ( SPMETA_DLL::META_SUCCESS != meta_result)
  1471 + return meta_result;
  1472 + if ( NULL != sNVRAM_ReadCnf.buf )
  1473 + {
  1474 + free(sNVRAM_ReadCnf.buf);
  1475 + sNVRAM_ReadCnf.buf = NULL;
  1476 + }
  1477 +
  1478 + if (NULL != pWriteData)
  1479 + {
  1480 + free(pWriteData);
  1481 + pWriteData = NULL;
  1482 + }
  1483 +
  1484 + sNVRAM_ReadReq.LID = pLID;
  1485 + sNVRAM_ReadReq.RID = 1;
  1486 + sNVRAM_ReadCnf.len = iWriteBufSize;
  1487 + sNVRAM_ReadCnf.buf = (unsigned char*) malloc(iWriteBufSize * sizeof(unsigned char));
  1488 + pWriteData = (unsigned char*) malloc(iWriteBufSize * sizeof(unsigned char));
  1489 + if (NULL == sNVRAM_ReadCnf.buf || NULL == pWriteData)
  1490 + return SPMETA_DLL::META_FAILED;
  1491 + meta_result = REQ_ReadFromAPNVRAM (&sNVRAM_ReadReq, &sNVRAM_ReadCnf);
  1492 + if (meta_result != SPMETA_DLL::META_SUCCESS )
  1493 + {
  1494 + pFuncName = "SmartPhoneSN::REQ_ReadFromAPNVRAM()";
  1495 + goto Err;
  1496 + }
  1497 +
  1498 +
  1499 + meta_result = ConductProdInfoData(sNVRAM_ReadCnf.buf, iWriteBufSize);
  1500 + if (meta_result != SPMETA_DLL::META_SUCCESS)
  1501 + {
  1502 + pFuncName = "SmartPhoneSN::ConductProdInfoData()";
  1503 + goto Err;
  1504 + }
  1505 + else
  1506 + {
  1507 + memcpy(pWriteData, sNVRAM_ReadCnf.buf, iWriteBufSize);
  1508 + sNVRAM_ReadCnf.buf[g_sMetaComm.QCFlag_index] = g_pMainDlg->myintqc + 0x30;
  1509 + }
  1510 +
  1511 + sNVRAM_WriteReq.LID = pLID;
  1512 + sNVRAM_WriteReq.RID = 1;
  1513 + sNVRAM_WriteReq.len = iWriteBufSize;
  1514 + sNVRAM_WriteReq.buf = pWriteData;
  1515 + m_sNVRAM_OPID = 1;
  1516 + meta_result = REQ_WriteToAPNVRAM(sNVRAM_WriteReq);
  1517 + if (meta_result != SPMETA_DLL::META_SUCCESS )
  1518 + {
  1519 + pFuncName = "SmartPhoneSN::REQ_WriteToAPNVRAM()";
  1520 + goto Err;
  1521 + }
  1522 + memset(sNVRAM_ReadCnf.buf, 0 , sNVRAM_ReadCnf.len);
  1523 + meta_result = REQ_ReadFromAPNVRAM (&sNVRAM_ReadReq, &sNVRAM_ReadCnf);
  1524 + if (meta_result != SPMETA_DLL::META_SUCCESS )
  1525 + {
  1526 + pFuncName = "SmartPhoneSN::REQ_ReadFromAPNVRAM()";
  1527 + goto Err;
  1528 + }
  1529 + else
  1530 + {
  1531 + if (memcmp(sNVRAM_ReadCnf.buf, pWriteData, sNVRAM_ReadCnf.len) != 0)
  1532 + {
  1533 + meta_result = SPMETA_DLL::META_FAILED;
  1534 + }
  1535 + }
  1536 + if (sNVRAM_ReadCnf.buf != NULL)
  1537 + {
  1538 + free (sNVRAM_ReadCnf.buf);
  1539 + sNVRAM_ReadCnf.buf = NULL;
  1540 + }
  1541 + if (pWriteData != NULL)
  1542 + {
  1543 + free (pWriteData);
  1544 + pWriteData = NULL;
  1545 + }
  1546 + return meta_result;
  1547 +
  1548 +Err:
  1549 + if (sNVRAM_ReadCnf.buf != NULL)
  1550 + {
  1551 + free (sNVRAM_ReadCnf.buf);
  1552 + sNVRAM_ReadCnf.buf = NULL;
  1553 + }
  1554 + if (pWriteData != NULL)
  1555 + {
  1556 + free (pWriteData);
  1557 + pWriteData = NULL;
  1558 + }
  1559 + return meta_result;
  1560 +}
  1561 +
  1562 +
  1563 +
1747 int SmartPhoneSN::LoadHDCPBinFile(const char *strHdcpBinPath) 1564 int SmartPhoneSN::LoadHDCPBinFile(const char *strHdcpBinPath)
1748 { 1565 {
1749 int iRet = 0; 1566 int iRet = 0;
@@ -2468,6 +2285,101 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::REQ_ReadAP_NVRAM_Start(WriteData_Type_e da @@ -2468,6 +2285,101 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::REQ_ReadAP_NVRAM_Start(WriteData_Type_e da
2468 return MetaResult; 2285 return MetaResult;
2469 } 2286 }
2470 2287
  2288 +
  2289 +
  2290 +#if 1//def __TOPWELL_QCTEST__
  2291 +byte SmartPhoneSN::REQ_ReadAP_NVRAM_QC(void)
  2292 +{
  2293 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::REQ_ReadAP_NVRAM_QC()...");
  2294 +
  2295 + SPMETA_DLL::META_RESULT MetaResult = SPMETA_DLL::META_SUCCESS;
  2296 + int iBufLen = 0;
  2297 + char *pLID = NULL;
  2298 + CString mytest,mytesttemp;
  2299 + pLID = "AP_CFG_REEB_PRODUCT_INFO_LID";
  2300 +
  2301 + // pLID = "AP_CFG_REEB_PRODUCT_INFO_LID";
  2302 + SPMETA_DLL::FT_NVRAM_READ_REQ sNVRAM_ReadReq;
  2303 + SPMETA_DLL::FT_NVRAM_READ_CNF sNVRAM_ReadCnf;
  2304 + SPMETA_DLL::META_RESULT meta_result;
  2305 + int iWriteBufSize = 0;
  2306 + memset(&sNVRAM_ReadReq, 0, sizeof(SPMETA_DLL::FT_NVRAM_READ_REQ));
  2307 + memset(&sNVRAM_ReadCnf, 0, sizeof(SPMETA_DLL::FT_NVRAM_READ_CNF));
  2308 +
  2309 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::SP_META_NVRAM_GetRecLen(): Start to get nvram struct size via LID = \"%s\"...", pLID);
  2310 + meta_result = SPMETA_DLL::SP_META_NVRAM_GetRecLen(pLID, &iWriteBufSize);
  2311 + if ( SPMETA_DLL::META_SUCCESS != meta_result)
  2312 + {
  2313 + MTRACE_ERR (g_hEBOOT_DEBUG, "SmartPhoneSN::SP_META_NVRAM_GetRecLen(): Get nvram struct size fail, MetaResult = %s", ResultToString_SP(meta_result));
  2314 + return 0;
  2315 + }
  2316 + else
  2317 + {
  2318 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::SP_META_NVRAM_GetRecLen(): Get nvram struct size = %d successfully!", iWriteBufSize);
  2319 + if ( NULL != sNVRAM_ReadCnf.buf )
  2320 + {
  2321 + free ( sNVRAM_ReadCnf.buf );
  2322 + sNVRAM_ReadCnf.buf = NULL;
  2323 + }
  2324 +
  2325 + sNVRAM_ReadReq.LID = pLID;
  2326 + sNVRAM_ReadReq.RID = 1;
  2327 + sNVRAM_ReadCnf.len = iWriteBufSize;
  2328 + sNVRAM_ReadCnf.buf = (unsigned char*) malloc (iWriteBufSize*sizeof(unsigned char));
  2329 + if (NULL == sNVRAM_ReadCnf.buf)
  2330 + {
  2331 + MTRACE_ERR (g_hEBOOT_DEBUG, "Malloc heap memory cause fail!");
  2332 + return 0;
  2333 + }
  2334 + }
  2335 +
  2336 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::REQ_ReadFromAPNVRAM(): Start to read nvram data...");
  2337 + meta_result = REQ_ReadFromAPNVRAM (&sNVRAM_ReadReq, &sNVRAM_ReadCnf);
  2338 +
  2339 +
  2340 + if (meta_result != SPMETA_DLL::META_SUCCESS )
  2341 + {
  2342 +
  2343 +
  2344 +
  2345 + MTRACE_ERR (g_hEBOOT_DEBUG, "REQ_ReadFromAPNVRAM: fail! MetaResult = %s", ResultToString_SP(meta_result));
  2346 + return 0;
  2347 + }
  2348 +
  2349 + {
  2350 + int loop = 0;
  2351 + for (;loop<iWriteBufSize;loop++)
  2352 + {
  2353 + if(loop%50 == 0)
  2354 + mytesttemp.Format(" %d_%x\n",loop,sNVRAM_ReadCnf.buf[loop]);
  2355 + else
  2356 + mytesttemp.Format(" %d_%x",loop,sNVRAM_ReadCnf.buf[loop]);
  2357 + mytest += mytesttemp;
  2358 + }
  2359 + }
  2360 +
  2361 + if(sNVRAM_ReadCnf.buf[1006] == 0)
  2362 + {
  2363 + // ::AfxMessageBox("QC test fail");
  2364 + return 0;
  2365 + }
  2366 + else if(sNVRAM_ReadCnf.buf[1006] == 1)
  2367 + {
  2368 + // ::AfxMessageBox("QC test pass");
  2369 + return 1;
  2370 + }
  2371 + else
  2372 + {
  2373 + return 3;
  2374 + }
  2375 +
  2376 +
  2377 +}
  2378 +
  2379 +
  2380 +
  2381 +#endif
  2382 +
2471 SPMETA_DLL::META_RESULT SmartPhoneSN::REQ_WriteAP_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID) 2383 SPMETA_DLL::META_RESULT SmartPhoneSN::REQ_WriteAP_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID)
2472 { 2384 {
2473 if (!pInData) 2385 if (!pInData)
@@ -3906,7 +3818,6 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::EnterAPMetaMode() @@ -3906,7 +3818,6 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::EnterAPMetaMode()
3906 if (!g_sMetaComm.bAlreadyInMeata) 3818 if (!g_sMetaComm.bAlreadyInMeata)
3907 { 3819 {
3908 UpdateUIMsg("Start searching preloader com port and handshake..."); 3820 UpdateUIMsg("Start searching preloader com port and handshake...");
3909 - UpdateProgress(0.08);  
3910 3821
3911 bootResult = ConnectWithPreloader(); 3822 bootResult = ConnectWithPreloader();
3912 if (bootResult != 0) 3823 if (bootResult != 0)
@@ -3924,14 +3835,11 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::EnterAPMetaMode() @@ -3924,14 +3835,11 @@ SPMETA_DLL::META_RESULT SmartPhoneSN::EnterAPMetaMode()
3924 else 3835 else
3925 { 3836 {
3926 UpdateUIMsg("Already in Meta Mode, bypass preloader com port handshake."); 3837 UpdateUIMsg("Already in Meta Mode, bypass preloader com port handshake.");
3927 - UpdateProgress(0.08);  
3928 } 3838 }
3929 3839
3930 UpdateUIMsg("Start searching kernel com port and handshake..."); 3840 UpdateUIMsg("Start searching kernel com port and handshake...");
3931 - UpdateProgress(0.10);  
3932 3841
3933 bootResult = ConnectWithKernelPort_Ex(); 3842 bootResult = ConnectWithKernelPort_Ex();
3934 - UpdateProgress(0.12);  
3935 if (bootResult == 0) 3843 if (bootResult == 0)
3936 { 3844 {
3937 UpdateUIMsg("Searching kernel com port and handshake OK."); 3845 UpdateUIMsg("Searching kernel com port and handshake OK.");
@@ -4063,7 +3971,7 @@ void SmartPhoneSN::ThreadMainEntryPoint() @@ -4063,7 +3971,7 @@ void SmartPhoneSN::ThreadMainEntryPoint()
4063 bool bNeedLoadAPDB = false; 3971 bool bNeedLoadAPDB = false;
4064 int times = 0; 3972 int times = 0;
4065 int Ret = 0; 3973 int Ret = 0;
4066 - 3974 +
4067 /*For dual talk(external modem) project 3975 /*For dual talk(external modem) project
4068 * Due to dual talk project can`t switch back and forth between ap and external modem 3976 * Due to dual talk project can`t switch back and forth between ap and external modem
4069 * When target type select tablet and enable external modem option, mean that will write ap nvram, so need disable write external modem nvram 3977 * When target type select tablet and enable external modem option, mean that will write ap nvram, so need disable write external modem nvram
@@ -4071,19 +3979,19 @@ void SmartPhoneSN::ThreadMainEntryPoint() @@ -4071,19 +3979,19 @@ void SmartPhoneSN::ThreadMainEntryPoint()
4071 */ 3979 */
4072 bool bWriteBarcode = g_sMetaComm.sWriteOption.bWriteBarcode; 3980 bool bWriteBarcode = g_sMetaComm.sWriteOption.bWriteBarcode;
4073 bool bWriteIMEI = g_sMetaComm.sWriteOption.bWriteIMEI; 3981 bool bWriteIMEI = g_sMetaComm.sWriteOption.bWriteIMEI;
4074 - 3982 +
4075 if (g_sMetaComm.bDualTalk) 3983 if (g_sMetaComm.bDualTalk)
4076 { 3984 {
4077 g_sMetaComm.sWriteOption.bWriteBarcode = false; 3985 g_sMetaComm.sWriteOption.bWriteBarcode = false;
4078 g_sMetaComm.sWriteOption.bWriteIMEI = false; 3986 g_sMetaComm.sWriteOption.bWriteIMEI = false;
4079 } 3987 }
4080 - 3988 +
4081 bNeedScanData = NeedScanData(); 3989 bNeedScanData = NeedScanData();
4082 if (bNeedScanData == false) 3990 if (bNeedScanData == false)
4083 { 3991 {
4084 if (g_sMetaComm.sWriteOption.bWriteDrm == false 3992 if (g_sMetaComm.sWriteOption.bWriteDrm == false
4085 - && g_sMetaComm.sWriteOption.bWriteHdcp == false  
4086 - && g_sMetaComm.sWriteOption.bInstallHdcpData == false) 3993 + && g_sMetaComm.sWriteOption.bWriteHdcp == false
  3994 + && g_sMetaComm.sWriteOption.bInstallHdcpData == false)
4087 { 3995 {
4088 PopupMsgBox("Warning", MB_OK | MB_ICONWARNING, "At least select one write option!!"); 3996 PopupMsgBox("Warning", MB_OK | MB_ICONWARNING, "At least select one write option!!");
4089 return; 3997 return;
@@ -4101,27 +4009,17 @@ void SmartPhoneSN::ThreadMainEntryPoint() @@ -4101,27 +4009,17 @@ void SmartPhoneSN::ThreadMainEntryPoint()
4101 } 4009 }
4102 else 4010 else
4103 { 4011 {
4104 - if (g_sMetaComm.sWriteOption.bWriteBarcode ||  
4105 - g_sMetaComm.sWriteOption.bWriteIMEI ||  
4106 - g_sMetaComm.sWriteOption.bWriteBT ||  
4107 - g_sMetaComm.sWriteOption.bWriteWifi ||  
4108 - g_sMetaComm.sWriteOption.bWriteEthernetMac ||  
4109 - g_sMetaComm.sWriteOption.bWriteDrmkeyMCID ||  
4110 - g_sMetaComm.sWriteOption.bWriteSerialNo ||  
4111 - g_sMetaComm.sWriteOption.bWriteMeid ||  
4112 - g_sMetaComm.bClearMetaBootFlag)  
4113 - { 4012 + if (g_sMetaComm.sWriteOption.bWriteBarcode || g_sMetaComm.sWriteOption.bWriteIMEI)
4114 bNeedLoadAPDB = true; 4013 bNeedLoadAPDB = true;
4115 - }  
4116 } 4014 }
4117 - 4015 +
4118 bool bAnyOperationFail = false; 4016 bool bAnyOperationFail = false;
4119 META_RESULT MetaResult = META_SUCCESS; 4017 META_RESULT MetaResult = META_SUCCESS;
4120 SPMETA_DLL::META_RESULT SPMetaResult = SPMETA_DLL::META_SUCCESS; 4018 SPMETA_DLL::META_RESULT SPMetaResult = SPMETA_DLL::META_SUCCESS;
4121 - 4019 +
4122 if (g_sMetaComm.bSwithTool) 4020 if (g_sMetaComm.bSwithTool)
4123 EnableUSBSwitch(); 4021 EnableUSBSwitch();
4124 - 4022 +
4125 if (g_sMetaComm.bCheckFastbootLock) 4023 if (g_sMetaComm.bCheckFastbootLock)
4126 { 4024 {
4127 UpdateUIMsg("Start Adb_Manager_Init() and Set_Fastboot_EnvironmentVariable()..."); 4025 UpdateUIMsg("Start Adb_Manager_Init() and Set_Fastboot_EnvironmentVariable()...");
@@ -4135,7 +4033,7 @@ void SmartPhoneSN::ThreadMainEntryPoint() @@ -4135,7 +4033,7 @@ void SmartPhoneSN::ThreadMainEntryPoint()
4135 if (!Adb_Manager_Init()) 4033 if (!Adb_Manager_Init())
4136 { 4034 {
4137 MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::Adb_Manager_Init() FAIL..."); 4035 MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::Adb_Manager_Init() FAIL...");
4138 - 4036 +
4139 Adb_Manager_Deinit(); 4037 Adb_Manager_Deinit();
4140 UpdateUIMsg("SmartPhoneSN::Adb_Manager_Init() FAIL..."); 4038 UpdateUIMsg("SmartPhoneSN::Adb_Manager_Init() FAIL...");
4141 return; 4039 return;
@@ -4154,256 +4052,270 @@ void SmartPhoneSN::ThreadMainEntryPoint() @@ -4154,256 +4052,270 @@ void SmartPhoneSN::ThreadMainEntryPoint()
4154 *m_pMetaStopFlag = BOOT_STOP; 4052 *m_pMetaStopFlag = BOOT_STOP;
4155 } 4053 }
4156 MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::MetaHandle_Init() end..."); 4054 MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::MetaHandle_Init() end...");
4157 - 4055 +
4158 CScanData scanDlg; 4056 CScanData scanDlg;
4159 -  
4160 -  
4161 - while(true)  
4162 - {  
4163 - if (*m_pMetaStopFlag == BOOT_STOP)  
4164 - break;  
4165 - if (g_sMetaComm.iStressTest > 1 && iTestCount > 0)  
4166 - {  
4167 - if (iTestCount >= g_sMetaComm.iStressTest)  
4168 - break;  
4169 - }  
4170 - else if (!bSkipScanData && scanDlg.DoModal() != IDOK)  
4171 - break;  
4172 - iTestCount++;  
4173 -  
4174 - DebugOnOff(true);  
4175 - MTRACE(g_hEBOOT_DEBUG, "------------------------------------ START -------------------------------------");  
4176 - LogConfig();  
4177 - bAnyOperationFail = false;  
4178 - UpdateMainDlgUI(false, NORMAL);  
4179 - // if(g_sMetaComm.sIMEIOption.Temp_Option.bWriteTemperature)  
4180 - g_pMainDlg->ShowTemperatureOnUI();  
4181 -  
4182 - EnableStartBTN(false);  
4183 -  
4184 - //SPInit() can`t call before SNThread_Init() function  
4185 - SNThread_Init();  
4186 - //MTRACE (g_hEBOOT_DEBUG, "m_bWriteModemNvram = %d,m_sMdInfo.number_of_md = %d", m_bWriteModemNvram, m_sMdInfo.number_of_md);  
4187 - SPInit();  
4188 -  
4189 - SetupMetaModeParameters();  
4190 -  
4191 - UpdateUIMsg("Start load and init AP database...");  
4192 -  
4193 - UpdateProgress(0.06);  
4194 -  
4195 - if (g_sMetaComm.bUsbEnable)  
4196 - {  
4197 - UpdateUIMsg("Wait for usb insert...");  
4198 - }  
4199 -  
4200 - EnableStartBTN(true);  
4201 -  
4202 - MetaResult = (META_RESULT)EnterAPMetaMode();  
4203 - if (MetaResult != META_SUCCESS)  
4204 - {  
4205 - bAnyOperationFail = true;  
4206 - goto End;  
4207 - }  
4208 -  
4209 - if (g_sMetaComm.sDBFileOption.bAPDBFromDUT || g_sMetaComm.sDBFileOption.bMDDBFromDUT)  
4210 - {  
4211 - SPMetaResult = QueryDBFromDUT();  
4212 - if (SPMetaResult != 0)  
4213 - {  
4214 - UpdateUIMsg("Don't support load db from device.");  
4215 - bAnyOperationFail = true;  
4216 - goto End;  
4217 - }  
4218 - }  
4219 -  
4220 - if (bNeedLoadAPDB == true)  
4221 - {  
4222 - // load ap db from dut  
4223 - if (g_sMetaComm.sDBFileOption.bAPDBFromDUT)  
4224 - {  
4225 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetAPDBFromDUT() : Get AP DB from DUT start...");  
4226 - SPMetaResult = GetAPDBFromDUT();  
4227 - if (SPMetaResult != SPMETA_DLL::META_SUCCESS)  
4228 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : fail, will try load config DB.");  
4229 - else  
4230 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetAPDBFromDUT() : end.");  
4231 - }  
4232 -  
4233 - MetaResult = (META_RESULT)LoadAPDatabase();  
4234 - if (MetaResult != META_SUCCESS)  
4235 - {  
4236 - bAnyOperationFail = true;  
4237 - UpdateUIMsg("Load AP Database fail, %s", ResultToString_SP(MetaResult));  
4238 - goto End;  
4239 - }  
4240 - }  
4241 -  
4242 - SPMetaResult = SPMETA_DLL::SP_META_QueryIfFunctionSupportedByTarget_r(m_hSPMetaHandle, 500, "SP_META_ENCRYPTED_Support_r");  
4243 - if (SPMetaResult == SPMETA_DLL::META_SUCCESS)  
4244 - {  
4245 - if (QueryEncryptionSupport(&m_hSPMetaHandle))  
4246 - {  
4247 - Encryption Edlg;  
4248 - //Edlg.DoModal();  
4249 - while ((IDOK == Edlg.DoModal() ) && times < 3)  
4250 - {  
4251 - if (!VeritifiEncryption(&m_hSPMetaHandle))  
4252 - {  
4253 - MTRACE(g_hEBOOT_DEBUG, "VeritifiEncryption() retry : %d", times + 1);  
4254 - times = times + 1;  
4255 - }  
4256 - else  
4257 - break;  
4258 - }  
4259 - if (3 == times)  
4260 - {  
4261 - bAnyOperationFail = true;  
4262 - MTRACE(g_hEBOOT_DEBUG, "VeritifiEncryption() retry times more than 3 times!");  
4263 - goto End;  
4264 - }  
4265 - }  
4266 - }  
4267 -  
4268 - if (g_sMetaComm.eTargetType != TABLET_WIFI_ONLY)  
4269 - {  
4270 - // query modem info must after queryEncryption.  
4271 - MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information start...");  
4272 - Ret = GetSPModemInfo_Ex();  
4273 - if (Ret != 0)  
4274 - {  
4275 - bAnyOperationFail = true;  
4276 - MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information fail, MetaResult = %s", ResultToString_SP(Ret));  
4277 - UpdateUIMsg("Query modem information fail, %s", ResultToString_SP(Ret));  
4278 - goto End;  
4279 - }  
4280 - MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information end.");  
4281 - }  
4282 -  
4283 - //Special case: m_bWriteModemNvram = true && m_sMdInfo.number_of_md = 0  
4284 - //So skip to load modem database  
4285 - MTRACE (g_hEBOOT_DEBUG, "m_bWriteModemNvram = %d,m_sMdInfo.number_of_md = %d", m_bWriteModemNvram, m_sMdInfo.number_of_md);  
4286 - if ((m_bWriteModemNvram == true || g_sMetaComm.bCheckCalFlag || g_sMetaComm.bCheckFtFlag) && m_sMdInfo.number_of_md >= 1)  
4287 - {  
4288 - UpdateUIMsg("Start switch to MD meta and init Modem database...");  
4289 -  
4290 - UpdateProgress(0.14);  
4291 -  
4292 - if (!g_sMetaComm.sDBFileOption.bDBInitModem_1 && g_sMetaComm.sDBFileOption.bMDDBFromDUT)  
4293 - {  
4294 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : Get Modem DB from DUT start...");  
4295 - SPMetaResult = GetMDDBFromDUT();  
4296 - if (SPMetaResult != SPMETA_DLL::META_SUCCESS)  
4297 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : fail, will try load config DB.");  
4298 - else  
4299 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : end.");  
4300 - }  
4301 -  
4302 - UpdateProgress(0.18);  
4303 -  
4304 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex(): Switch to MODEM meta from AP meta start...");  
4305 - MetaResult = APSwithToModemMeta_Ex();  
4306 - if (MetaResult != META_SUCCESS)  
4307 - {  
4308 - bAnyOperationFail = true;  
4309 - MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex() : Switch to MODEM meta from AP meta fail.");  
4310 - UpdateUIMsg("SmartPhoneSN::ApSwithToModemMeta_Ex() : Switch to MODEM meta from AP meta fail.");  
4311 - goto End;  
4312 - }  
4313 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex(): end.");  
4314 -  
4315 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase(): start...");  
4316 - MetaResult = LoadModemDatabase(0);  
4317 - if (MetaResult != META_SUCCESS)  
4318 - {  
4319 - bAnyOperationFail = true;  
4320 - MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult));  
4321 - UpdateUIMsg("SmartPhoneSN::LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult));  
4322 - goto End;  
4323 - }  
4324 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase(): end.");  
4325 - }  
4326 - UpdateProgress(0.22);  
4327 -  
4328 - EnableStartBTN(false);  
4329 - UpdateUIMsg("Start loop write data to nvram...");  
4330 - MetaResult = WriteNvramLoop();  
4331 - if (MetaResult != META_SUCCESS)  
4332 - {  
4333 - bAnyOperationFail = true;  
4334 - goto End;  
4335 - }  
4336 - 4057 + g_sMetaComm.sWriteOption.bWriteBarcode = true;
  4058 +
  4059 + if(g_pMainDlg->mystrimei1 == "" ||g_pMainDlg->mystrimei2 == "")
  4060 + g_sMetaComm.sWriteOption.bWriteIMEI = false;
  4061 + else
  4062 + {
  4063 + strncpy(g_sMetaComm.sScanData.strIMEI[0], (LPCTSTR)g_pMainDlg->mystrimei1, strlen(g_pMainDlg->mystrimei1) + 1);
  4064 + strncpy(g_sMetaComm.sScanData.strIMEI[1], (LPCTSTR)g_pMainDlg->mystrimei2, strlen(g_pMainDlg->mystrimei2) + 1);
  4065 + g_sMetaComm.sWriteOption.bWriteIMEI = true;
  4066 + }
  4067 +
  4068 + g_sMetaComm.sWriteOption.bWriteWifi = false;
  4069 + g_sMetaComm.sWriteOption.bWriteHdcp = false;
  4070 + g_sMetaComm.sWriteOption.bWriteDrm = false;
  4071 + g_sMetaComm.sWriteOption.bInstallHdcpData = false;
  4072 + g_sMetaComm.sWriteOption.bWriteEthernetMac = false;
  4073 + g_sMetaComm.sWriteOption.bWriteDrmkeyMCID = false;
  4074 + g_sMetaComm.sWriteOption.bWriteMeid = false;
  4075 + g_sMetaComm.sWriteOption.bWriteEsn = false;
  4076 +
  4077 +
  4078 + if (*m_pMetaStopFlag == BOOT_STOP)
  4079 + return;
  4080 + if (g_sMetaComm.iStressTest > 1 && iTestCount > 0)
  4081 + {
  4082 + if (iTestCount >= g_sMetaComm.iStressTest)
  4083 + return;
  4084 + }
  4085 + else if (!bSkipScanData)
  4086 + return;
  4087 + iTestCount++;
  4088 +
  4089 + DebugOnOff(true);
  4090 + MTRACE(g_hEBOOT_DEBUG, "------------------------------------ START -------------------------------------");
  4091 + LogConfig();
  4092 + bAnyOperationFail = false;
  4093 + UpdateMainDlgUI(false, NORMAL);
  4094 + // if(g_sMetaComm.sIMEIOption.Temp_Option.bWriteTemperature)
  4095 + g_pMainDlg->ShowTemperatureOnUI();
  4096 +
  4097 + EnableStartBTN(false);
  4098 +
  4099 + //SPInit() can`t call before SNThread_Init() function
  4100 + SNThread_Init();
  4101 + //MTRACE (g_hEBOOT_DEBUG, "m_bWriteModemNvram = %d,m_sMdInfo.number_of_md = %d", m_bWriteModemNvram, m_sMdInfo.number_of_md);
  4102 + SPInit();
  4103 +
  4104 + SetupMetaModeParameters();
  4105 +
  4106 + UpdateUIMsg("Start load and init AP database...");
  4107 +
  4108 +
  4109 + if (g_sMetaComm.bUsbEnable)
  4110 + {
  4111 + UpdateUIMsg("Wait for usb insert...");
  4112 + }
  4113 +
  4114 + EnableStartBTN(true);
  4115 +
  4116 + MetaResult = (META_RESULT)EnterAPMetaMode();
  4117 + if (MetaResult != META_SUCCESS)
  4118 + {
  4119 + bAnyOperationFail = true;
  4120 + goto End;
  4121 + }
  4122 +
  4123 + if (g_sMetaComm.sDBFileOption.bAPDBFromDUT || g_sMetaComm.sDBFileOption.bMDDBFromDUT)
  4124 + {
  4125 + SPMetaResult = QueryDBFromDUT();
  4126 + if (SPMetaResult != 0)
  4127 + {
  4128 + UpdateUIMsg("Don't support load db from device.");
  4129 + bAnyOperationFail = true;
  4130 + goto End;
  4131 + }
  4132 + }
  4133 +
  4134 + if (bNeedLoadAPDB == true)
  4135 + {
  4136 + // load ap db from dut
  4137 + if (g_sMetaComm.sDBFileOption.bAPDBFromDUT)
  4138 + {
  4139 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetAPDBFromDUT() : Get AP DB from DUT start...");
  4140 + SPMetaResult = GetAPDBFromDUT();
  4141 + if (SPMetaResult != SPMETA_DLL::META_SUCCESS)
  4142 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : fail, will try load config DB.");
  4143 + else
  4144 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetAPDBFromDUT() : end.");
  4145 + }
  4146 +
  4147 + MetaResult = (META_RESULT)LoadAPDatabase();
  4148 + if (MetaResult != META_SUCCESS)
  4149 + {
  4150 + bAnyOperationFail = true;
  4151 + UpdateUIMsg("Load AP Database fail, %s", ResultToString_SP(MetaResult));
  4152 + goto End;
  4153 + }
  4154 + }
  4155 +
  4156 + SPMetaResult = SPMETA_DLL::SP_META_QueryIfFunctionSupportedByTarget_r(m_hSPMetaHandle, 500, "SP_META_ENCRYPTED_Support_r");
  4157 + if (SPMetaResult == SPMETA_DLL::META_SUCCESS)
  4158 + {
  4159 + if (QueryEncryptionSupport(&m_hSPMetaHandle))
  4160 + {
  4161 + Encryption Edlg;
  4162 + //Edlg.DoModal();
  4163 + while ((IDOK == Edlg.DoModal() ) && times < 3)
  4164 + {
  4165 + if (!VeritifiEncryption(&m_hSPMetaHandle))
  4166 + {
  4167 + MTRACE(g_hEBOOT_DEBUG, "VeritifiEncryption() retry : %d", times + 1);
  4168 + times = times + 1;
  4169 + }
  4170 + else
  4171 + break;
  4172 + }
  4173 + if (3 == times)
  4174 + {
  4175 + bAnyOperationFail = true;
  4176 + MTRACE(g_hEBOOT_DEBUG, "VeritifiEncryption() retry times more than 3 times!");
  4177 + goto End;
  4178 + }
  4179 + }
  4180 + }
  4181 +
  4182 + if (g_sMetaComm.eTargetType != TABLET_WIFI_ONLY)
  4183 + {
  4184 + // query modem info must after queryEncryption.
  4185 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information start...");
  4186 + Ret = GetSPModemInfo_Ex();
  4187 + if (Ret != 0)
  4188 + {
  4189 + bAnyOperationFail = true;
  4190 + MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information fail, MetaResult = %s", ResultToString_SP(Ret));
  4191 + UpdateUIMsg("Query modem information fail, %s", ResultToString_SP(Ret));
  4192 + goto End;
  4193 + }
  4194 + MTRACE (g_hEBOOT_DEBUG, "SmartPhoneSN::GetSPModemInfo_Ex(): Query modem information end.");
  4195 +
  4196 + REQ_WriteAP_PRODINFO_QC();
  4197 +
  4198 + }
  4199 +
  4200 + //Special case: m_bWriteModemNvram = true && m_sMdInfo.number_of_md = 0
  4201 + //So skip to load modem database
  4202 + MTRACE (g_hEBOOT_DEBUG, "m_bWriteModemNvram = %d,m_sMdInfo.number_of_md = %d", m_bWriteModemNvram, m_sMdInfo.number_of_md);
  4203 + if ((m_bWriteModemNvram == true || g_sMetaComm.bCheckCalFlag || g_sMetaComm.bCheckFtFlag) && m_sMdInfo.number_of_md >= 1)
  4204 + {
  4205 + UpdateUIMsg("Start switch to MD meta and init Modem database...");
  4206 +
  4207 +
  4208 + if (!g_sMetaComm.sDBFileOption.bDBInitModem_1 && g_sMetaComm.sDBFileOption.bMDDBFromDUT)
  4209 + {
  4210 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : Get Modem DB from DUT start...");
  4211 + SPMetaResult = GetMDDBFromDUT();
  4212 + if (SPMetaResult != SPMETA_DLL::META_SUCCESS)
  4213 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : fail, will try load config DB.");
  4214 + else
  4215 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::GetMDDBFromDUT() : end.");
  4216 + }
  4217 +
  4218 +
  4219 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex(): Switch to MODEM meta from AP meta start...");
  4220 + MetaResult = APSwithToModemMeta_Ex();
  4221 + if (MetaResult != META_SUCCESS)
  4222 + {
  4223 + bAnyOperationFail = true;
  4224 + MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex() : Switch to MODEM meta from AP meta fail.");
  4225 + UpdateUIMsg("SmartPhoneSN::ApSwithToModemMeta_Ex() : Switch to MODEM meta from AP meta fail.");
  4226 + goto End;
  4227 + }
  4228 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::ApSwithToModemMeta_Ex(): end.");
  4229 +
  4230 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase(): start...");
  4231 + MetaResult = LoadModemDatabase(0);
  4232 + if (MetaResult != META_SUCCESS)
  4233 + {
  4234 + bAnyOperationFail = true;
  4235 + MTRACE_ERR(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult));
  4236 + UpdateUIMsg("SmartPhoneSN::LoadModemDatabase() : MetaResult = %s", ResultToString(MetaResult));
  4237 + goto End;
  4238 + }
  4239 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::LoadModemDatabase(): end.");
  4240 + }
  4241 +
  4242 + EnableStartBTN(false);
  4243 + UpdateUIMsg("Start loop write data to nvram...");
  4244 + MetaResult = WriteNvramLoop();
  4245 + if (MetaResult != META_SUCCESS)
  4246 + {
  4247 + bAnyOperationFail = true;
  4248 + goto End;
  4249 + }
  4250 +
4337 End: 4251 End:
4338 - if (m_bStopBeforeUSBInsert == true)  
4339 - {  
4340 - UpdateProgress(0.0);  
4341 - UpdateUIMsg("...");  
4342 - }  
4343 - else  
4344 - {  
4345 - if (m_eMetaMode == SP_AP_META || m_eMetaMode == SP_AP2MD_FAIL)  
4346 - {  
4347 - ExitAPMetaMode();  
4348 - }  
4349 - else if (m_eMetaMode == SP_MODEM_META || m_eMetaMode == SP_MD2AP_FAIL)  
4350 - {  
4351 - ExitSPModemMeta();  
4352 - }  
4353 -  
4354 - //The backup nvram api return success, but the operator pull up usb cable immediately before all operation successfully.  
4355 - //This case will cause nvram data lose when firmware upgrate, so that put indicator turn green after exit meta.  
4356 - if (g_sMetaComm.bCheckFastbootLock && m_bBackupNvramSuccess && !bAnyOperationFail)  
4357 - {  
4358 - if (REQ_FastbootLockOem() == -1)  
4359 - {  
4360 - bAnyOperationFail = true;  
4361 - UpdateUIMsg("ERROR!! REQ_FastbootLockOem()");  
4362 - }  
4363 - }  
4364 -  
4365 - if (bAnyOperationFail)  
4366 - {  
4367 - m_Process->SendMessage(PBM_SETBARCOLOR, 0, RGB(255, 0, 0));  
4368 - UpdateUICountResult(FAIL);  
4369 - }  
4370 - else  
4371 - {  
4372 - UpdateUIMsg("All Operate successfully!!");  
4373 - MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::All Operate successfully!!");  
4374 -  
4375 -#ifdef _AUTO_GEN_FEATURE_  
4376 - if (g_AutoGenData.bEnableAutoGen)  
4377 - {  
4378 - UpdateAutoGenParaToSetupFile();  
4379 - }  
4380 -#endif  
4381 - UpdateUICountResult(PASS);  
4382 - }  
4383 -  
4384 - UpdateProgress(1.0);  
4385 - }  
4386 -  
4387 - EnableStartBTN(true);  
4388 - if (g_sMetaComm.sWriteOption.bWriteDrm)  
4389 - {  
4390 - *m_pMetaStopFlag = BOOT_STOP;  
4391 - }  
4392 - MTRACE(g_hEBOOT_DEBUG, "------------------------------------ END --------------------------------------");  
4393 - DebugOnOff(false);  
4394 - Sleep(bSkipScanData ? 3000 : 1000);  
4395 - }  
4396 - 4252 + if (m_bStopBeforeUSBInsert == true)
  4253 + {
  4254 + UpdateUIMsg("...");
  4255 + }
  4256 + else
  4257 + {
  4258 + if (m_eMetaMode == SP_AP_META || m_eMetaMode == SP_AP2MD_FAIL)
  4259 + {
  4260 + ExitAPMetaMode();
  4261 + }
  4262 + else if (m_eMetaMode == SP_MODEM_META || m_eMetaMode == SP_MD2AP_FAIL)
  4263 + {
  4264 + ExitSPModemMeta();
  4265 + }
  4266 +
  4267 + //The backup nvram api return success, but the operator pull up usb cable immediately before all operation successfully.
  4268 + //This case will cause nvram data lose when firmware upgrate, so that put indicator turn green after exit meta.
  4269 + if (g_sMetaComm.bCheckFastbootLock && m_bBackupNvramSuccess && !bAnyOperationFail)
  4270 + {
  4271 + if (REQ_FastbootLockOem() == -1)
  4272 + {
  4273 + bAnyOperationFail = true;
  4274 + UpdateUIMsg("ERROR!! REQ_FastbootLockOem()");
  4275 + }
  4276 + }
  4277 +
  4278 + if (bAnyOperationFail)
  4279 + {
  4280 + UpdateUICountResult(FAIL);
  4281 + }
  4282 + else
  4283 + {
  4284 + UpdateUIMsg("All Operate successfully!!");
  4285 + MTRACE(g_hEBOOT_DEBUG, "SmartPhoneSN::All Operate successfully!!");
  4286 +
  4287 + #ifdef _AUTO_GEN_FEATURE_
  4288 + if (g_AutoGenData.bEnableAutoGen)
  4289 + {
  4290 + UpdateAutoGenParaToSetupFile();
  4291 + }
  4292 + #endif
  4293 + UpdateUICountResult(PASS);
  4294 + }
  4295 +
  4296 + }
  4297 +
  4298 + EnableStartBTN(true);
  4299 + if (g_sMetaComm.sWriteOption.bWriteDrm)
  4300 + {
  4301 + *m_pMetaStopFlag = BOOT_STOP;
  4302 + }
  4303 + MTRACE(g_hEBOOT_DEBUG, "------------------------------------ END --------------------------------------");
  4304 + DebugOnOff(false);
  4305 + Sleep(bSkipScanData ? 3000 : 1000);
  4306 +
  4307 +
  4308 +
4397 if (g_sMetaComm.bCheckFastbootLock) 4309 if (g_sMetaComm.bCheckFastbootLock)
4398 { 4310 {
4399 Adb_Manager_Deinit(); 4311 Adb_Manager_Deinit();
4400 } 4312 }
4401 g_sMetaComm.sWriteOption.bWriteBarcode = bWriteBarcode; 4313 g_sMetaComm.sWriteOption.bWriteBarcode = bWriteBarcode;
4402 g_sMetaComm.sWriteOption.bWriteIMEI = bWriteIMEI; 4314 g_sMetaComm.sWriteOption.bWriteIMEI = bWriteIMEI;
4403 - 4315 +
4404 if (g_sMetaComm.bSwithTool) 4316 if (g_sMetaComm.bSwithTool)
4405 DisableUSBSwitch(); 4317 DisableUSBSwitch();
4406 - 4318 +
4407 MetaHandle_DeInit(); 4319 MetaHandle_DeInit();
4408 UpdateMainDlgUI(true, CANCEL); 4320 UpdateMainDlgUI(true, CANCEL);
4409 } 4321 }
@@ -4828,7 +4740,6 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4828,7 +4740,6 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4828 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] can not find C2K modem."); 4740 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] can not find C2K modem.");
4829 return META_FAILED; 4741 return META_FAILED;
4830 } 4742 }
4831 - UpdateProgress(0.14);  
4832 4743
4833 4744
4834 // init c2k 4745 // init c2k
@@ -4863,7 +4774,6 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4863,7 +4774,6 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4863 } 4774 }
4864 bInited = true; // inited 4775 bInited = true; // inited
4865 MTRACE (g_hEBOOT_DEBUG, "[C2K] META_C2K_Init() end..."); 4776 MTRACE (g_hEBOOT_DEBUG, "[C2K] META_C2K_Init() end...");
4866 - UpdateProgress(0.18);  
4867 4777
4868 4778
4869 // connect to c2k 4779 // connect to c2k
@@ -4904,16 +4814,13 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4904,16 +4814,13 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4904 { 4814 {
4905 UpdateUIMsg("META_C2K_LoadMessage_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4815 UpdateUIMsg("META_C2K_LoadMessage_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4906 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_LoadMessage_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4816 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_LoadMessage_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4907 - UpdateProgress(1.00);  
4908 goto end; 4817 goto end;
4909 } 4818 }
4910 UpdateUIMsg("META_C2K_LoadMessage_r() : successful!"); 4819 UpdateUIMsg("META_C2K_LoadMessage_r() : successful!");
4911 MTRACE (g_hEBOOT_DEBUG, "[C2K] META_C2K_LoadMessage_r() : successful!"); 4820 MTRACE (g_hEBOOT_DEBUG, "[C2K] META_C2K_LoadMessage_r() : successful!");
4912 - UpdateProgress(0.28);  
4913 } 4821 }
4914 4822
4915 UpdateUIMsg("Start connect with C2K Meta..."); 4823 UpdateUIMsg("Start connect with C2K Meta...");
4916 - UpdateProgress(0.34);  
4917 4824
4918 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() start..."); 4825 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() start...");
4919 for (i = 0; i < 20; i++) 4826 for (i = 0; i < 20; i++)
@@ -4926,13 +4833,11 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4926,13 +4833,11 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4926 { 4833 {
4927 UpdateUIMsg("META_C2K_ConnectWithTarget_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4834 UpdateUIMsg("META_C2K_ConnectWithTarget_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4928 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4835 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4929 - UpdateProgress(1.00);  
4930 goto end; 4836 goto end;
4931 } 4837 }
4932 bConnected = true; // connected 4838 bConnected = true; // connected
4933 UpdateUIMsg("META_C2K_ConnectWithTarget_r() : successful!"); 4839 UpdateUIMsg("META_C2K_ConnectWithTarget_r() : successful!");
4934 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() : successful!"); 4840 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_ConnectWithTarget_r() : successful!");
4935 - UpdateProgress(0.48);  
4936 4841
4937 4842
4938 // handshake with c2k 4843 // handshake with c2k
@@ -4946,10 +4851,8 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4946,10 +4851,8 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4946 { 4851 {
4947 UpdateUIMsg("META_C2K_LoopbackTest_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4852 UpdateUIMsg("META_C2K_LoopbackTest_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4948 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_LoopbackTest_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 4853 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_LoopbackTest_r() : fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
4949 - UpdateProgress(1.00);  
4950 goto end; 4854 goto end;
4951 } 4855 }
4952 - UpdateProgress(0.60);  
4953 4856
4954 4857
4955 // task 4858 // task
@@ -4970,13 +4873,11 @@ META_RESULT SmartPhoneSN::EnterC2KGen90() @@ -4970,13 +4873,11 @@ META_RESULT SmartPhoneSN::EnterC2KGen90()
4970 DisconnectC2KMeta(); 4873 DisconnectC2KMeta();
4971 DeinitC2KMeta(); 4874 DeinitC2KMeta();
4972 4875
4973 - UpdateProgress(1.00);  
4974 4876
4975 goto end; 4877 goto end;
4976 } 4878 }
4977 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_FlushNvram_r() : Flaush NVRAM to Flash FFS successful!"); 4879 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_FlushNvram_r() : Flaush NVRAM to Flash FFS successful!");
4978 #endif 4880 #endif
4979 - UpdateProgress(0.85);  
4980 4881
4981 end: 4882 end:
4982 // disconnect 4883 // disconnect
@@ -5049,7 +4950,6 @@ end: @@ -5049,7 +4950,6 @@ end:
5049 UpdateUIMsg("[C2K] Write MEID fail."); 4950 UpdateUIMsg("[C2K] Write MEID fail.");
5050 else if (g_sMetaComm.sWriteOption.bWriteEsn) 4951 else if (g_sMetaComm.sWriteOption.bWriteEsn)
5051 UpdateUIMsg("[C2K] Write ESN fail."); 4952 UpdateUIMsg("[C2K] Write ESN fail.");
5052 - UpdateProgress(1.00);  
5053 } 4953 }
5054 4954
5055 return ret_last; 4955 return ret_last;
@@ -5155,7 +5055,6 @@ int SmartPhoneSN::WriteMEID() @@ -5155,7 +5055,6 @@ int SmartPhoneSN::WriteMEID()
5155 return ret_meta; 5055 return ret_meta;
5156 } 5056 }
5157 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_WriteNvram_r() : Write MEID end."); 5057 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_WriteNvram_r() : Write MEID end.");
5158 - UpdateProgress(0.70);  
5159 5058
5160 5059
5161 UpdateUIMsg("Read MEID for check start..."); 5060 UpdateUIMsg("Read MEID for check start...");
@@ -5169,7 +5068,6 @@ int SmartPhoneSN::WriteMEID() @@ -5169,7 +5068,6 @@ int SmartPhoneSN::WriteMEID()
5169 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_ReadNvram_r(): Read MEID fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle)); 5068 MTRACE_ERR(g_hEBOOT_DEBUG, "[C2K] META_C2K_ReadNvram_r(): Read MEID fail, %s", META_C2K_GetErrorString(m_hMauiMetaHandle));
5170 return ret_meta; 5069 return ret_meta;
5171 } 5070 }
5172 - UpdateProgress(0.75);  
5173 5071
5174 MTRACE(g_hEBOOT_DEBUG, "[C2K] Write MEID :%s", g_sMetaComm.sScanData.strMeid); 5072 MTRACE(g_hEBOOT_DEBUG, "[C2K] Write MEID :%s", g_sMetaComm.sScanData.strMeid);
5175 MTRACE(g_hEBOOT_DEBUG, "[C2K] Read MEID :%s", data_meid.meid); 5073 MTRACE(g_hEBOOT_DEBUG, "[C2K] Read MEID :%s", data_meid.meid);
@@ -5181,7 +5079,6 @@ int SmartPhoneSN::WriteMEID() @@ -5181,7 +5079,6 @@ int SmartPhoneSN::WriteMEID()
5181 } 5079 }
5182 UpdateUIMsg("Checking MEID succesfully!"); 5080 UpdateUIMsg("Checking MEID succesfully!");
5183 MTRACE(g_hEBOOT_DEBUG, "[C2K] Checking MEID succesfully!"); 5081 MTRACE(g_hEBOOT_DEBUG, "[C2K] Checking MEID succesfully!");
5184 - UpdateProgress(0.80);  
5185 5082
5186 return META_SUCCESS; 5083 return META_SUCCESS;
5187 } 5084 }
@@ -5211,7 +5108,6 @@ int SmartPhoneSN::WriteESN() @@ -5211,7 +5108,6 @@ int SmartPhoneSN::WriteESN()
5211 } 5108 }
5212 UpdateUIMsg("META_C2K_WriteNvram_r() : Write ESN succesful!"); 5109 UpdateUIMsg("META_C2K_WriteNvram_r() : Write ESN succesful!");
5213 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_WriteNvram_r() : Write ESN succesful!"); 5110 MTRACE(g_hEBOOT_DEBUG, "[C2K] META_C2K_WriteNvram_r() : Write ESN succesful!");
5214 - UpdateProgress(0.70);  
5215 5111
5216 UpdateUIMsg("Read ESN for check start..."); 5112 UpdateUIMsg("Read ESN for check start...");
5217 MTRACE(g_hEBOOT_DEBUG, "[C2K] Read ESN for check start..."); 5113 MTRACE(g_hEBOOT_DEBUG, "[C2K] Read ESN for check start...");
@@ -5235,7 +5131,6 @@ int SmartPhoneSN::WriteESN() @@ -5235,7 +5131,6 @@ int SmartPhoneSN::WriteESN()
5235 } 5131 }
5236 UpdateUIMsg("Checking Esn Successfully!"); 5132 UpdateUIMsg("Checking Esn Successfully!");
5237 MTRACE(g_hEBOOT_DEBUG, "[C2K] Checking ESN successfully!"); 5133 MTRACE(g_hEBOOT_DEBUG, "[C2K] Checking ESN successfully!");
5238 - UpdateProgress(0.80);  
5239 5134
5240 return META_SUCCESS; 5135 return META_SUCCESS;
5241 } 5136 }
@@ -73,6 +73,10 @@ protected: @@ -73,6 +73,10 @@ protected:
73 virtual SPMETA_DLL::META_RESULT LoadAPDatabase(); 73 virtual SPMETA_DLL::META_RESULT LoadAPDatabase();
74 74
75 virtual SPMETA_DLL::META_RESULT REQ_ReadAP_NVRAM_Start(WriteData_Type_e dataType, char *pOutData, unsigned short iRID); 75 virtual SPMETA_DLL::META_RESULT REQ_ReadAP_NVRAM_Start(WriteData_Type_e dataType, char *pOutData, unsigned short iRID);
  76 + #if 1//def __TOPWELL_QCTEST__
  77 + virtual byte REQ_ReadAP_NVRAM_QC();
  78 + virtual SPMETA_DLL::META_RESULT REQ_WriteAP_PRODINFO_QC();
  79 + #endif
76 virtual SPMETA_DLL::META_RESULT REQ_WriteAP_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID); 80 virtual SPMETA_DLL::META_RESULT REQ_WriteAP_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID);
77 virtual META_RESULT REQ_ReadModem_NVRAM_Start(WriteData_Type_e dataType, char *pOutData, unsigned short iRID); 81 virtual META_RESULT REQ_ReadModem_NVRAM_Start(WriteData_Type_e dataType, char *pOutData, unsigned short iRID);
78 virtual META_RESULT REQ_WriteModem_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID); 82 virtual META_RESULT REQ_WriteModem_NVRAM_Start(WriteData_Type_e dataType, char *pInData, unsigned short iRID);
1 -#include "stdafx.h"  
2 -#include "BtnST.h"  
3 -  
4 -#ifdef BTNST_USE_SOUND  
5 -#pragma comment(lib, "winmm.lib")  
6 -#include <Mmsystem.h>  
7 -#endif  
8 -  
9 -#ifdef _DEBUG  
10 -#define new DEBUG_NEW  
11 -#undef THIS_FILE  
12 -static char THIS_FILE[] = __FILE__;  
13 -#endif  
14 -  
15 -/////////////////////////////////////////////////////////////////////////////  
16 -// CButtonST  
17 -  
18 -// Mask for control's type  
19 -#define BS_TYPEMASK SS_TYPEMASK  
20 -  
21 -#ifndef TTM_SETTITLE  
22 -#define TTM_SETTITLEA (WM_USER + 32) // wParam = TTI_*, lParam = char* szTitle  
23 -#define TTM_SETTITLEW (WM_USER + 33) // wParam = TTI_*, lParam = wchar* szTitle  
24 -#ifdef UNICODE  
25 -#define TTM_SETTITLE TTM_SETTITLEW  
26 -#else  
27 -#define TTM_SETTITLE TTM_SETTITLEA  
28 -#endif  
29 -#endif  
30 -  
31 -#ifndef TTS_BALLOON  
32 -#define TTS_BALLOON 0x40  
33 -#endif  
34 -  
35 -CButtonST::CButtonST()  
36 -{  
37 - m_bIsPressed = FALSE;  
38 - m_bIsFocused = FALSE;  
39 - m_bIsDisabled = FALSE;  
40 - m_bMouseOnButton = FALSE;  
41 -  
42 - FreeResources(FALSE);  
43 -  
44 - // Default type is "flat" button  
45 - m_bIsFlat = TRUE;  
46 - // Button will be tracked also if when the window is inactive (like Internet Explorer)  
47 - m_bAlwaysTrack = TRUE;  
48 -  
49 - // By default draw border in "flat" button  
50 - m_bDrawBorder = TRUE;  
51 -  
52 - // By default icon is aligned horizontally  
53 - m_byAlign = ST_ALIGN_HORIZ;  
54 -  
55 - // By default use usual pressed style  
56 - SetPressedStyle(BTNST_PRESSED_LEFTRIGHT, FALSE);  
57 -  
58 - // By default, for "flat" button, don't draw the focus rect  
59 - m_bDrawFlatFocus = FALSE;  
60 -  
61 - // By default the button is not the default button  
62 - m_bIsDefault = FALSE;  
63 - // Invalid value, since type still unknown  
64 - m_nTypeStyle = BS_TYPEMASK;  
65 -  
66 - // By default the button is not a checkbox  
67 - m_bIsCheckBox = FALSE;  
68 - m_nCheck = 0;  
69 -  
70 - // Set default colors  
71 - SetDefaultColors(FALSE);  
72 -  
73 - // No tooltip created  
74 - m_ToolTip.m_hWnd = NULL;  
75 - m_dwToolTipStyle = 0;  
76 -  
77 - // Do not draw as a transparent button  
78 - m_bDrawTransparent = FALSE;  
79 - m_pbmpOldBk = NULL;  
80 -  
81 - // No URL defined  
82 - SetURL(NULL);  
83 -  
84 - // No cursor defined  
85 - m_hCursor = NULL;  
86 -  
87 - // No associated menu  
88 -#ifndef BTNST_USE_BCMENU  
89 - m_hMenu = NULL;  
90 -#endif  
91 - m_hParentWndMenu = NULL;  
92 - m_bMenuDisplayed = FALSE;  
93 -  
94 - m_bShowDisabledBitmap = TRUE;  
95 -  
96 - m_ptImageOrg.x = 3;  
97 - m_ptImageOrg.y = 3;  
98 -  
99 - // No defined callbacks  
100 - ::ZeroMemory(&m_csCallbacks, sizeof(m_csCallbacks));  
101 -  
102 -#ifdef BTNST_USE_SOUND  
103 - // No defined sounds  
104 - ::ZeroMemory(&m_csSounds, sizeof(m_csSounds));  
105 -#endif  
106 -} // End of CButtonST  
107 -  
108 -CButtonST::~CButtonST()  
109 -{  
110 - // Restore old bitmap (if any)  
111 - if (m_dcBk.m_hDC && m_pbmpOldBk)  
112 - {  
113 - m_dcBk.SelectObject(m_pbmpOldBk);  
114 - } // if  
115 -  
116 - FreeResources();  
117 -  
118 - // Destroy the cursor (if any)  
119 - if (m_hCursor) ::DestroyCursor(m_hCursor);  
120 -  
121 - // Destroy the menu (if any)  
122 -#ifdef BTNST_USE_BCMENU  
123 - if (m_menuPopup.m_hMenu) m_menuPopup.DestroyMenu();  
124 -#else  
125 - if (m_hMenu) ::DestroyMenu(m_hMenu);  
126 -#endif  
127 -} // End of ~CButtonST  
128 -  
129 -BEGIN_MESSAGE_MAP(CButtonST, CButton)  
130 - //{{AFX_MSG_MAP(CButtonST)  
131 - ON_WM_SETCURSOR()  
132 - ON_WM_KILLFOCUS()  
133 - ON_WM_MOUSEMOVE()  
134 - ON_WM_SYSCOLORCHANGE()  
135 - ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)  
136 - ON_WM_ACTIVATE()  
137 - ON_WM_ENABLE()  
138 - ON_WM_CANCELMODE()  
139 - ON_WM_GETDLGCODE()  
140 - ON_WM_CTLCOLOR_REFLECT()  
141 - //}}AFX_MSG_MAP  
142 -#ifdef BTNST_USE_BCMENU  
143 - ON_WM_MENUCHAR()  
144 - ON_WM_MEASUREITEM()  
145 -#endif  
146 -  
147 - ON_MESSAGE(BM_SETSTYLE, OnSetStyle)  
148 - ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)  
149 - ON_MESSAGE(BM_SETCHECK, OnSetCheck)  
150 - ON_MESSAGE(BM_GETCHECK, OnGetCheck)  
151 -END_MESSAGE_MAP()  
152 -  
153 -void CButtonST::FreeResources(BOOL bCheckForNULL)  
154 -{  
155 - if (bCheckForNULL)  
156 - {  
157 - // Destroy icons  
158 - // Note: the following two lines MUST be here! even if  
159 - // BoundChecker says they are unnecessary!  
160 - if (m_csIcons[0].hIcon) ::DestroyIcon(m_csIcons[0].hIcon);  
161 - if (m_csIcons[1].hIcon) ::DestroyIcon(m_csIcons[1].hIcon);  
162 -  
163 - // Destroy bitmaps  
164 - if (m_csBitmaps[0].hBitmap) ::DeleteObject(m_csBitmaps[0].hBitmap);  
165 - if (m_csBitmaps[1].hBitmap) ::DeleteObject(m_csBitmaps[1].hBitmap);  
166 -  
167 - // Destroy mask bitmaps  
168 - if (m_csBitmaps[0].hMask) ::DeleteObject(m_csBitmaps[0].hMask);  
169 - if (m_csBitmaps[1].hMask) ::DeleteObject(m_csBitmaps[1].hMask);  
170 - } // if  
171 -  
172 - ::ZeroMemory(&m_csIcons, sizeof(m_csIcons));  
173 - ::ZeroMemory(&m_csBitmaps, sizeof(m_csBitmaps));  
174 -} // End of FreeResources  
175 -  
176 -void CButtonST::PreSubclassWindow()  
177 -{  
178 - UINT nBS;  
179 -  
180 - nBS = GetButtonStyle();  
181 -  
182 - // Set initial control type  
183 - m_nTypeStyle = nBS & BS_TYPEMASK;  
184 -  
185 - // Check if this is a checkbox  
186 - if (nBS & BS_CHECKBOX) m_bIsCheckBox = TRUE;  
187 -  
188 - // Set initial default state flag  
189 - if (m_nTypeStyle == BS_DEFPUSHBUTTON)  
190 - {  
191 - // Set default state for a default button  
192 - m_bIsDefault = TRUE;  
193 -  
194 - // Adjust style for default button  
195 - m_nTypeStyle = BS_PUSHBUTTON;  
196 - } // If  
197 -  
198 - // You should not set the Owner Draw before this call  
199 - // (don't use the resource editor "Owner Draw" or  
200 - // ModifyStyle(0, BS_OWNERDRAW) before calling PreSubclassWindow() )  
201 - ASSERT(m_nTypeStyle != BS_OWNERDRAW);  
202 -  
203 - // Switch to owner-draw  
204 - ModifyStyle(BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED);  
205 -  
206 - CButton::PreSubclassWindow();  
207 -} // End of PreSubclassWindow  
208 -  
209 -UINT CButtonST::OnGetDlgCode()  
210 -{  
211 - UINT nCode = CButton::OnGetDlgCode();  
212 -  
213 - // Tell the system if we want default state handling  
214 - // (losing default state always allowed)  
215 - nCode |= (m_bIsDefault ? DLGC_DEFPUSHBUTTON : DLGC_UNDEFPUSHBUTTON);  
216 -  
217 - return nCode;  
218 -} // End of OnGetDlgCode  
219 -  
220 -BOOL CButtonST::PreTranslateMessage(MSG* pMsg)  
221 -{  
222 - InitToolTip();  
223 - m_ToolTip.RelayEvent(pMsg);  
224 -  
225 - if (pMsg->message == WM_LBUTTONDBLCLK)  
226 - pMsg->message = WM_LBUTTONDOWN;  
227 -  
228 - return CButton::PreTranslateMessage(pMsg);  
229 -} // End of PreTranslateMessage  
230 -  
231 -HBRUSH CButtonST::CtlColor(CDC* pDC, UINT nCtlColor)  
232 -{  
233 - return (HBRUSH)::GetStockObject(NULL_BRUSH);  
234 -} // End of CtlColor  
235 -  
236 -void CButtonST::OnSysColorChange()  
237 -{  
238 - CButton::OnSysColorChange();  
239 -  
240 - m_dcBk.DeleteDC();  
241 - m_bmpBk.DeleteObject();  
242 - SetDefaultColors();  
243 -} // End of OnSysColorChange  
244 -  
245 -LRESULT CButtonST::OnSetStyle(WPARAM wParam, LPARAM lParam)  
246 -{  
247 - UINT nNewType = (wParam & BS_TYPEMASK);  
248 -  
249 - // Update default state flag  
250 - if (nNewType == BS_DEFPUSHBUTTON)  
251 - {  
252 - m_bIsDefault = TRUE;  
253 - } // if  
254 - else if (nNewType == BS_PUSHBUTTON)  
255 - {  
256 - // Losing default state always allowed  
257 - m_bIsDefault = FALSE;  
258 - } // if  
259 -  
260 - // Can't change control type after owner-draw is set.  
261 - // Let the system process changes to other style bits  
262 - // and redrawing, while keeping owner-draw style  
263 - return DefWindowProc(BM_SETSTYLE,  
264 - (wParam & ~BS_TYPEMASK) | BS_OWNERDRAW, lParam);  
265 -} // End of OnSetStyle  
266 -  
267 -LRESULT CButtonST::OnSetCheck(WPARAM wParam, LPARAM lParam)  
268 -{  
269 - ASSERT(m_bIsCheckBox);  
270 -  
271 - switch (wParam)  
272 - {  
273 - case BST_CHECKED:  
274 - case BST_INDETERMINATE: // Indeterminate state is handled like checked state  
275 - SetCheck(1);  
276 - break;  
277 - default:  
278 - SetCheck(0);  
279 - break;  
280 - } // switch  
281 -  
282 - return 0;  
283 -} // End of OnSetCheck  
284 -  
285 -LRESULT CButtonST::OnGetCheck(WPARAM wParam, LPARAM lParam)  
286 -{  
287 - ASSERT(m_bIsCheckBox);  
288 - return GetCheck();  
289 -} // End of OnGetCheck  
290 -  
291 -#ifdef BTNST_USE_BCMENU  
292 -LRESULT CButtonST::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)  
293 -{  
294 - LRESULT lResult;  
295 - if (BCMenu::IsMenu(pMenu))  
296 - lResult = BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);  
297 - else  
298 - lResult = CButton::OnMenuChar(nChar, nFlags, pMenu);  
299 - return lResult;  
300 -} // End of OnMenuChar  
301 -#endif  
302 -  
303 -#ifdef BTNST_USE_BCMENU  
304 -void CButtonST::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)  
305 -{  
306 - BOOL bSetFlag = FALSE;  
307 - if (lpMeasureItemStruct->CtlType == ODT_MENU)  
308 - {  
309 - if (IsMenu((HMENU)lpMeasureItemStruct->itemID) && BCMenu::IsMenu((HMENU)lpMeasureItemStruct->itemID))  
310 - {  
311 - m_menuPopup.MeasureItem(lpMeasureItemStruct);  
312 - bSetFlag = TRUE;  
313 - } // if  
314 - } // if  
315 - if (!bSetFlag) CButton::OnMeasureItem(nIDCtl, lpMeasureItemStruct);  
316 -} // End of OnMeasureItem  
317 -#endif  
318 -  
319 -void CButtonST::OnEnable(BOOL bEnable)  
320 -{  
321 - CButton::OnEnable(bEnable);  
322 -  
323 - if (bEnable == FALSE)  
324 - {  
325 - CWnd* pWnd = GetParent()->GetNextDlgTabItem(this);  
326 - if (pWnd)  
327 - pWnd->SetFocus();  
328 - else  
329 - GetParent()->SetFocus();  
330 -  
331 - CancelHover();  
332 - } // if  
333 -} // End of OnEnable  
334 -  
335 -void CButtonST::OnKillFocus(CWnd * pNewWnd)  
336 -{  
337 - CButton::OnKillFocus(pNewWnd);  
338 - CancelHover();  
339 -} // End of OnKillFocus  
340 -  
341 -void CButtonST::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)  
342 -{  
343 - CButton::OnActivate(nState, pWndOther, bMinimized);  
344 - if (nState == WA_INACTIVE) CancelHover();  
345 -} // End of OnActivate  
346 -  
347 -void CButtonST::OnCancelMode()  
348 -{  
349 - CButton::OnCancelMode();  
350 - CancelHover();  
351 -} // End of OnCancelMode  
352 -  
353 -BOOL CButtonST::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)  
354 -{  
355 - // If a cursor was specified then use it!  
356 - if (m_hCursor != NULL)  
357 - {  
358 - ::SetCursor(m_hCursor);  
359 - return TRUE;  
360 - } // if  
361 -  
362 - return CButton::OnSetCursor(pWnd, nHitTest, message);  
363 -} // End of OnSetCursor  
364 -  
365 -void CButtonST::CancelHover()  
366 -{  
367 - // Only for flat buttons  
368 - if (m_bIsFlat)  
369 - {  
370 - if (m_bMouseOnButton)  
371 - {  
372 - m_bMouseOnButton = FALSE;  
373 - Invalidate();  
374 - } // if  
375 - } // if  
376 -} // End of CancelHover  
377 -  
378 -void CButtonST::OnMouseMove(UINT nFlags, CPoint point)  
379 -{  
380 - CWnd* wndUnderMouse = NULL;  
381 - CWnd* wndActive = this;  
382 - TRACKMOUSEEVENT csTME;  
383 -  
384 - CButton::OnMouseMove(nFlags, point);  
385 -  
386 - ClientToScreen(&point);  
387 - wndUnderMouse = WindowFromPoint(point);  
388 -  
389 - // If the mouse enter the button with the left button pressed then do nothing  
390 - if (nFlags & MK_LBUTTON && m_bMouseOnButton == FALSE) return;  
391 -  
392 - // If our button is not flat then do nothing  
393 - if (m_bIsFlat == FALSE) return;  
394 -  
395 - if (m_bAlwaysTrack == FALSE) wndActive = GetActiveWindow();  
396 -  
397 - if (wndUnderMouse && wndUnderMouse->m_hWnd == m_hWnd && wndActive)  
398 - {  
399 - if (!m_bMouseOnButton)  
400 - {  
401 - m_bMouseOnButton = TRUE;  
402 -  
403 - Invalidate();  
404 -  
405 -#ifdef BTNST_USE_SOUND  
406 - // Play sound ?  
407 - if (m_csSounds[0].lpszSound)  
408 - ::PlaySound(m_csSounds[0].lpszSound, m_csSounds[0].hMod, m_csSounds[0].dwFlags);  
409 -#endif  
410 -  
411 - csTME.cbSize = sizeof(csTME);  
412 - csTME.dwFlags = TME_LEAVE;  
413 - csTME.hwndTrack = m_hWnd;  
414 - ::_TrackMouseEvent(&csTME);  
415 - } // if  
416 - } else CancelHover();  
417 -} // End of OnMouseMove  
418 -  
419 -// Handler for WM_MOUSELEAVE  
420 -LRESULT CButtonST::OnMouseLeave(WPARAM wParam, LPARAM lParam)  
421 -{  
422 - CancelHover();  
423 - return 0;  
424 -} // End of OnMouseLeave  
425 -  
426 -BOOL CButtonST::OnClicked()  
427 -{  
428 - SetFocus();  
429 -  
430 -#ifdef BTNST_USE_SOUND  
431 - // Play sound ?  
432 - if (m_csSounds[1].lpszSound)  
433 - ::PlaySound(m_csSounds[1].lpszSound, m_csSounds[1].hMod, m_csSounds[1].dwFlags);  
434 -#endif  
435 -  
436 - if (m_bIsCheckBox)  
437 - {  
438 - m_nCheck = !m_nCheck;  
439 - Invalidate();  
440 - } // if  
441 - else  
442 - {  
443 - // Handle the menu (if any)  
444 -#ifdef BTNST_USE_BCMENU  
445 - if (m_menuPopup.m_hMenu)  
446 -#else  
447 - if (m_hMenu)  
448 -#endif  
449 - {  
450 - CRect rWnd;  
451 - GetWindowRect(rWnd);  
452 -  
453 - m_bMenuDisplayed = TRUE;  
454 - Invalidate();  
455 -  
456 -#ifdef BTNST_USE_BCMENU  
457 - BCMenu* psub = (BCMenu*)m_menuPopup.GetSubMenu(0);  
458 - if (m_csCallbacks.hWnd) ::SendMessage(m_csCallbacks.hWnd, m_csCallbacks.nMessage, (WPARAM)psub, m_csCallbacks.lParam);  
459 - DWORD dwRetValue = psub->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, rWnd.left, rWnd.bottom, this, NULL);  
460 -#else  
461 - HMENU hSubMenu = ::GetSubMenu(m_hMenu, 0);  
462 - if (m_csCallbacks.hWnd) ::SendMessage(m_csCallbacks.hWnd, m_csCallbacks.nMessage, (WPARAM)hSubMenu, m_csCallbacks.lParam);  
463 - DWORD dwRetValue = ::TrackPopupMenuEx(hSubMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, rWnd.left, rWnd.bottom, m_hParentWndMenu, NULL);  
464 -#endif  
465 -  
466 - m_bMenuDisplayed = FALSE;  
467 - Invalidate();  
468 -  
469 - if (dwRetValue)  
470 - ::PostMessage(m_hParentWndMenu, WM_COMMAND, MAKEWPARAM(dwRetValue, 0), (LPARAM)NULL);  
471 - } // if  
472 - else  
473 - {  
474 - // Handle the URL (if any)  
475 - if (_tcslen(m_szURL) > 0)  
476 - {  
477 - SHELLEXECUTEINFO csSEI;  
478 -  
479 - memset(&csSEI, 0, sizeof(csSEI));  
480 - csSEI.cbSize = sizeof(SHELLEXECUTEINFO);  
481 - csSEI.fMask = SEE_MASK_FLAG_NO_UI;  
482 - csSEI.lpVerb = _T("open");  
483 - csSEI.lpFile = m_szURL;  
484 - csSEI.nShow = SW_SHOWMAXIMIZED;  
485 - ::ShellExecuteEx(&csSEI);  
486 - } // if  
487 - } // else  
488 - } // else  
489 -  
490 - return FALSE;  
491 -} // End of OnClicked  
492 -  
493 -void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)  
494 -{  
495 - CDC* pDC = CDC::FromHandle(lpDIS->hDC);  
496 -  
497 - // Checkbox?  
498 - if (m_bIsCheckBox)  
499 - {  
500 - m_bIsPressed = (lpDIS->itemState & ODS_SELECTED) || (m_nCheck != 0);  
501 - } // if  
502 - else // Normal button OR other button style ...  
503 - {  
504 - m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);  
505 -  
506 - // If there is a menu and it's displayed, draw the button as pressed  
507 - if (  
508 -#ifdef BTNST_USE_BCMENU  
509 - m_menuPopup.m_hMenu  
510 -#else  
511 - m_hMenu  
512 -#endif  
513 - && m_bMenuDisplayed) m_bIsPressed = TRUE;  
514 - } // else  
515 -  
516 - m_bIsFocused = (lpDIS->itemState & ODS_FOCUS);  
517 - m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);  
518 -  
519 - CRect itemRect = lpDIS->rcItem;  
520 -  
521 - pDC->SetBkMode(TRANSPARENT);  
522 -  
523 - // Prepare draw... paint button background  
524 -  
525 - // Draw transparent?  
526 - if (m_bDrawTransparent)  
527 - PaintBk(pDC);  
528 - else  
529 - OnDrawBackground(pDC, &itemRect);  
530 -  
531 - // Draw button border  
532 - OnDrawBorder(pDC, &itemRect);  
533 -  
534 - // Read the button's title  
535 - CString sTitle;  
536 - GetWindowText(sTitle);  
537 -  
538 - CRect captionRect = lpDIS->rcItem;  
539 -  
540 - // Draw the icon  
541 - if (m_csIcons[0].hIcon)  
542 - {  
543 - DrawTheIcon(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);  
544 - } // if  
545 -  
546 - if (m_csBitmaps[0].hBitmap)  
547 - {  
548 - pDC->SetBkColor(RGB(255,255,255));  
549 - DrawTheBitmap(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);  
550 - } // if  
551 -  
552 - // Write the button title (if any)  
553 - if (sTitle.IsEmpty() == FALSE)  
554 - {  
555 - DrawTheText(pDC, (LPCTSTR)sTitle, &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);  
556 - } // if  
557 -  
558 - if (m_bIsFlat == FALSE || (m_bIsFlat && m_bDrawFlatFocus))  
559 - {  
560 - // Draw the focus rect  
561 - if (m_bIsFocused)  
562 - {  
563 - CRect focusRect = itemRect;  
564 - focusRect.DeflateRect(3, 3);  
565 - pDC->DrawFocusRect(&focusRect);  
566 - } // if  
567 - } // if  
568 -} // End of DrawItem  
569 -  
570 -void CButtonST::PaintBk(CDC* pDC)  
571 -{  
572 - CClientDC clDC(GetParent());  
573 - CRect rect;  
574 - CRect rect1;  
575 -  
576 - GetClientRect(rect);  
577 -  
578 - GetWindowRect(rect1);  
579 - GetParent()->ScreenToClient(rect1);  
580 -  
581 - if (m_dcBk.m_hDC == NULL)  
582 - {  
583 - m_dcBk.CreateCompatibleDC(&clDC);  
584 - m_bmpBk.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());  
585 - m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);  
586 - m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);  
587 - } // if  
588 -  
589 - pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);  
590 -} // End of PaintBk  
591 -  
592 -HBITMAP CButtonST::CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor)  
593 -{  
594 - HBITMAP hMask = NULL;  
595 - HDC hdcSrc = NULL;  
596 - HDC hdcDest = NULL;  
597 - HBITMAP hbmSrcT = NULL;  
598 - HBITMAP hbmDestT = NULL;  
599 - COLORREF crSaveBk;  
600 - COLORREF crSaveDestText;  
601 -  
602 - hMask = ::CreateBitmap(dwWidth, dwHeight, 1, 1, NULL);  
603 - if (hMask == NULL) return NULL;  
604 -  
605 - hdcSrc = ::CreateCompatibleDC(NULL);  
606 - hdcDest = ::CreateCompatibleDC(NULL);  
607 -  
608 - hbmSrcT = (HBITMAP)::SelectObject(hdcSrc, hSourceBitmap);  
609 - hbmDestT = (HBITMAP)::SelectObject(hdcDest, hMask);  
610 -  
611 - crSaveBk = ::SetBkColor(hdcSrc, crTransColor);  
612 -  
613 - ::BitBlt(hdcDest, 0, 0, dwWidth, dwHeight, hdcSrc, 0, 0, SRCCOPY);  
614 -  
615 - crSaveDestText = ::SetTextColor(hdcSrc, RGB(255, 255, 255));  
616 - ::SetBkColor(hdcSrc,RGB(0, 0, 0));  
617 -  
618 - ::BitBlt(hdcSrc, 0, 0, dwWidth, dwHeight, hdcDest, 0, 0, SRCAND);  
619 -  
620 - SetTextColor(hdcDest, crSaveDestText);  
621 -  
622 - ::SetBkColor(hdcSrc, crSaveBk);  
623 - ::SelectObject(hdcSrc, hbmSrcT);  
624 - ::SelectObject(hdcDest, hbmDestT);  
625 -  
626 - ::DeleteDC(hdcSrc);  
627 - ::DeleteDC(hdcDest);  
628 -  
629 - return hMask;  
630 -} // End of CreateBitmapMask  
631 -  
632 -//  
633 -// Parameters:  
634 -// [IN] bHasTitle  
635 -// TRUE if the button has a text  
636 -// [IN] rpItem  
637 -// A pointer to a RECT structure indicating the allowed paint area  
638 -// [IN/OUT]rpTitle  
639 -// A pointer to a CRect object indicating the paint area reserved for the  
640 -// text. This structure will be modified if necessary.  
641 -// [IN] bIsPressed  
642 -// TRUE if the button is currently pressed  
643 -// [IN] dwWidth  
644 -// Width of the image (icon or bitmap)  
645 -// [IN] dwHeight  
646 -// Height of the image (icon or bitmap)  
647 -// [OUT] rpImage  
648 -// A pointer to a CRect object that will receive the area available to the image  
649 -//  
650 -void CButtonST::PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage)  
651 -{  
652 - CRect rBtn;  
653 -  
654 - rpImage->CopyRect(rpItem);  
655 -  
656 - switch (m_byAlign)  
657 - {  
658 - case ST_ALIGN_HORIZ:  
659 - if (bHasTitle == FALSE)  
660 - {  
661 - // Center image horizontally  
662 - rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);  
663 - }  
664 - else  
665 - {  
666 - // Image must be placed just inside the focus rect  
667 - rpImage->left += m_ptImageOrg.x;  
668 - rpTitle->left += dwWidth + m_ptImageOrg.x;  
669 - }  
670 - // Center image vertically  
671 - rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);  
672 - break;  
673 -  
674 - case ST_ALIGN_HORIZ_RIGHT:  
675 - GetClientRect(&rBtn);  
676 - if (bHasTitle == FALSE)  
677 - {  
678 - // Center image horizontally  
679 - rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);  
680 - }  
681 - else  
682 - {  
683 - // Image must be placed just inside the focus rect  
684 - rpTitle->right = rpTitle->Width() - dwWidth - m_ptImageOrg.x;  
685 - rpTitle->left = m_ptImageOrg.x;  
686 - rpImage->left = rBtn.right - dwWidth - m_ptImageOrg.x;  
687 - // Center image vertically  
688 - rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);  
689 - }  
690 - break;  
691 -  
692 - case ST_ALIGN_VERT:  
693 - // Center image horizontally  
694 - rpImage->left += ((rpImage->Width() - (long)dwWidth)/2);  
695 - if (bHasTitle == FALSE)  
696 - {  
697 - // Center image vertically  
698 - rpImage->top += ((rpImage->Height() - (long)dwHeight)/2);  
699 - }  
700 - else  
701 - {  
702 - rpImage->top = m_ptImageOrg.y;  
703 - rpTitle->top += dwHeight;  
704 - }  
705 - break;  
706 -  
707 - case ST_ALIGN_OVERLAP:  
708 - break;  
709 - } // switch  
710 -  
711 - // If button is pressed then press image also  
712 - if (bIsPressed && m_bIsCheckBox == FALSE)  
713 - rpImage->OffsetRect(m_ptPressedOffset.x, m_ptPressedOffset.y);  
714 -} // End of PrepareImageRect  
715 -  
716 -void CButtonST::DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)  
717 -{  
718 - BYTE byIndex = 0;  
719 -  
720 - // Select the icon to use  
721 - if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))  
722 - byIndex = 0;  
723 - else  
724 - byIndex = (m_csIcons[1].hIcon == NULL ? 0 : 1);  
725 -  
726 - CRect rImage;  
727 - PrepareImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, m_csIcons[byIndex].dwWidth, m_csIcons[byIndex].dwHeight, &rImage);  
728 -  
729 - // Ole'!  
730 - pDC->DrawState( rImage.TopLeft(),  
731 - rImage.Size(),  
732 - m_csIcons[byIndex].hIcon,  
733 - (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),  
734 - (CBrush*)NULL);  
735 -} // End of DrawTheIcon  
736 -  
737 -void CButtonST::DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)  
738 -{  
739 - HDC hdcBmpMem = NULL;  
740 - HBITMAP hbmOldBmp = NULL;  
741 - HDC hdcMem = NULL;  
742 - HBITMAP hbmT = NULL;  
743 -  
744 - BYTE byIndex = 0;  
745 -  
746 - // Select the bitmap to use  
747 - if ((m_bIsCheckBox && bIsPressed) || (!m_bIsCheckBox && (bIsPressed || m_bMouseOnButton)))  
748 - byIndex = 0;  
749 - else  
750 - byIndex = (m_csBitmaps[1].hBitmap == NULL ? 0 : 1);  
751 -  
752 - CRect rImage;  
753 - PrepareImageRect(bHasTitle, rpItem, rpCaption, bIsPressed, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, &rImage);  
754 -  
755 - hdcBmpMem = ::CreateCompatibleDC(pDC->m_hDC);  
756 -  
757 - hbmOldBmp = (HBITMAP)::SelectObject(hdcBmpMem, m_csBitmaps[byIndex].hBitmap);  
758 -  
759 - hdcMem = ::CreateCompatibleDC(NULL);  
760 -  
761 - hbmT = (HBITMAP)::SelectObject(hdcMem, m_csBitmaps[byIndex].hMask);  
762 -  
763 - if (bIsDisabled && m_bShowDisabledBitmap)  
764 - {  
765 - HDC hDC = NULL;  
766 - HBITMAP hBitmap = NULL;  
767 -  
768 - hDC = ::CreateCompatibleDC(pDC->m_hDC);  
769 - hBitmap = ::CreateCompatibleBitmap(pDC->m_hDC, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight);  
770 - HBITMAP hOldBmp2 = (HBITMAP)::SelectObject(hDC, hBitmap);  
771 -  
772 - RECT rRect;  
773 - rRect.left = 0;  
774 - rRect.top = 0;  
775 - rRect.right = rImage.right + 1;  
776 - rRect.bottom = rImage.bottom + 1;  
777 - ::FillRect(hDC, &rRect, (HBRUSH)RGB(255, 255, 255));  
778 -  
779 - COLORREF crOldColor = ::SetBkColor(hDC, RGB(255,255,255));  
780 -  
781 - ::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);  
782 - ::BitBlt(hDC, 0, 0, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);  
783 -  
784 - ::SetBkColor(hDC, crOldColor);  
785 - ::SelectObject(hDC, hOldBmp2);  
786 - ::DeleteDC(hDC);  
787 -  
788 - pDC->DrawState( CPoint(rImage.left/*+1*/, rImage.top),  
789 - CSize(m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight),  
790 - hBitmap, DST_BITMAP | DSS_DISABLED);  
791 -  
792 - ::DeleteObject(hBitmap);  
793 - } // if  
794 - else  
795 - {  
796 - ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcMem, 0, 0, SRCAND);  
797 -  
798 - ::BitBlt(pDC->m_hDC, rImage.left, rImage.top, m_csBitmaps[byIndex].dwWidth, m_csBitmaps[byIndex].dwHeight, hdcBmpMem, 0, 0, SRCPAINT);  
799 - } // else  
800 -  
801 - ::SelectObject(hdcMem, hbmT);  
802 - ::DeleteDC(hdcMem);  
803 -  
804 - ::SelectObject(hdcBmpMem, hbmOldBmp);  
805 - ::DeleteDC(hdcBmpMem);  
806 -} // End of DrawTheBitmap  
807 -  
808 -void CButtonST::DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)  
809 -{  
810 - // Draw the button's title  
811 - // If button is pressed then "press" title also  
812 - if (m_bIsPressed && m_bIsCheckBox == FALSE)  
813 - rpCaption->OffsetRect(m_ptPressedOffset.x, m_ptPressedOffset.y);  
814 -  
815 - // ONLY FOR DEBUG  
816 - //CBrush brBtnShadow(RGB(255, 0, 0));  
817 - //pDC->FrameRect(rCaption, &brBtnShadow);  
818 -  
819 - // Center text  
820 - CRect centerRect = rpCaption;  
821 - pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);  
822 - rpCaption->OffsetRect((centerRect.Width() - rpCaption->Width())/2, (centerRect.Height() - rpCaption->Height())/2);  
823 - /* RFU  
824 - rpCaption->OffsetRect(0, (centerRect.Height() - rpCaption->Height())/2);  
825 - rpCaption->OffsetRect((centerRect.Width() - rpCaption->Width())-4, (centerRect.Height() - rpCaption->Height())/2);  
826 - */  
827 -  
828 - pDC->SetBkMode(TRANSPARENT);  
829 - /*  
830 - pDC->DrawState(rCaption->TopLeft(), rCaption->Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL),  
831 - TRUE, 0, (CBrush*)NULL);  
832 - */  
833 - if (m_bIsDisabled)  
834 - {  
835 - rpCaption->OffsetRect(1, 1);  
836 - pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));  
837 - pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);  
838 - rpCaption->OffsetRect(-1, -1);  
839 - pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));  
840 - pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);  
841 - } // if  
842 - else  
843 - {  
844 - if (m_bMouseOnButton || m_bIsPressed)  
845 - {  
846 - pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);  
847 - pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);  
848 - } // if  
849 - else  
850 - {  
851 - if (m_bIsFocused)  
852 - {  
853 - pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_FOCUS]);  
854 - pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_FOCUS]);  
855 - } // if  
856 - else  
857 - {  
858 - pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);  
859 - pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);  
860 - } // else  
861 - } // else  
862 - pDC->DrawText(lpszText, -1, rpCaption, DT_WORDBREAK | DT_CENTER);  
863 - } // if  
864 -} // End of DrawTheText  
865 -  
866 -// This function creates a grayscale bitmap starting from a given bitmap.  
867 -// The resulting bitmap will have the same size of the original one.  
868 -//  
869 -// Parameters:  
870 -// [IN] hBitmap  
871 -// Handle to the original bitmap.  
872 -// [IN] dwWidth  
873 -// Specifies the bitmap width, in pixels.  
874 -// [IN] dwHeight  
875 -// Specifies the bitmap height, in pixels.  
876 -// [IN] crTrans  
877 -// Color to be used as transparent color. This color will be left unchanged.  
878 -//  
879 -// Return value:  
880 -// If the function succeeds, the return value is the handle to the newly created  
881 -// grayscale bitmap.  
882 -// If the function fails, the return value is NULL.  
883 -//  
884 -HBITMAP CButtonST::CreateGrayscaleBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans)  
885 -{  
886 - HBITMAP hGrayBitmap = NULL;  
887 - HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;  
888 - HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;  
889 -  
890 - hMainDC = ::GetDC(NULL);  
891 - if (hMainDC == NULL) return NULL;  
892 - hMemDC1 = ::CreateCompatibleDC(hMainDC);  
893 - if (hMemDC1 == NULL)  
894 - {  
895 - ::ReleaseDC(NULL, hMainDC);  
896 - return NULL;  
897 - } // if  
898 - hMemDC2 = ::CreateCompatibleDC(hMainDC);  
899 - if (hMemDC2 == NULL)  
900 - {  
901 - ::DeleteDC(hMemDC1);  
902 - ::ReleaseDC(NULL, hMainDC);  
903 - return NULL;  
904 - } // if  
905 -  
906 - hGrayBitmap = ::CreateCompatibleBitmap(hMainDC, dwWidth, dwHeight);  
907 - if (hGrayBitmap)  
908 - {  
909 - hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, hGrayBitmap);  
910 - hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, hBitmap);  
911 -  
912 - //::BitBlt(hMemDC1, 0, 0, dwWidth, dwHeight, hMemDC2, 0, 0, SRCCOPY);  
913 -  
914 - DWORD dwLoopY = 0, dwLoopX = 0;  
915 - COLORREF crPixel = 0;  
916 - BYTE byNewPixel = 0;  
917 -  
918 - for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)  
919 - {  
920 - for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)  
921 - {  
922 - crPixel = ::GetPixel(hMemDC2, dwLoopX, dwLoopY);  
923 - byNewPixel = (BYTE)((GetRValue(crPixel) * 0.299) + (GetGValue(crPixel) * 0.587) + (GetBValue(crPixel) * 0.114));  
924 -  
925 - if (crPixel != crTrans)  
926 - ::SetPixel(hMemDC1, dwLoopX, dwLoopY, RGB(byNewPixel, byNewPixel, byNewPixel));  
927 - else  
928 - ::SetPixel(hMemDC1, dwLoopX, dwLoopY, crPixel);  
929 - } // for  
930 - } // for  
931 -  
932 - ::SelectObject(hMemDC1, hOldBmp1);  
933 - ::SelectObject(hMemDC2, hOldBmp2);  
934 - } // if  
935 -  
936 - ::DeleteDC(hMemDC1);  
937 - ::DeleteDC(hMemDC2);  
938 - ::ReleaseDC(NULL, hMainDC);  
939 -  
940 - return hGrayBitmap;  
941 -} // End of CreateGrayscaleBitmap  
942 -  
943 -// This function creates a bitmap that is 25% darker than the original.  
944 -// The resulting bitmap will have the same size of the original one.  
945 -//  
946 -// Parameters:  
947 -// [IN] hBitmap  
948 -// Handle to the original bitmap.  
949 -// [IN] dwWidth  
950 -// Specifies the bitmap width, in pixels.  
951 -// [IN] dwHeight  
952 -// Specifies the bitmap height, in pixels.  
953 -// [IN] crTrans  
954 -// Color to be used as transparent color. This color will be left unchanged.  
955 -//  
956 -// Return value:  
957 -// If the function succeeds, the return value is the handle to the newly created  
958 -// darker bitmap.  
959 -// If the function fails, the return value is NULL.  
960 -//  
961 -HBITMAP CButtonST::CreateDarkerBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans)  
962 -{  
963 - HBITMAP hGrayBitmap = NULL;  
964 - HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;  
965 - HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;  
966 -  
967 - hMainDC = ::GetDC(NULL);  
968 - if (hMainDC == NULL) return NULL;  
969 - hMemDC1 = ::CreateCompatibleDC(hMainDC);  
970 - if (hMemDC1 == NULL)  
971 - {  
972 - ::ReleaseDC(NULL, hMainDC);  
973 - return NULL;  
974 - } // if  
975 - hMemDC2 = ::CreateCompatibleDC(hMainDC);  
976 - if (hMemDC2 == NULL)  
977 - {  
978 - ::DeleteDC(hMemDC1);  
979 - ::ReleaseDC(NULL, hMainDC);  
980 - return NULL;  
981 - } // if  
982 -  
983 - hGrayBitmap = ::CreateCompatibleBitmap(hMainDC, dwWidth, dwHeight);  
984 - if (hGrayBitmap)  
985 - {  
986 - hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, hGrayBitmap);  
987 - hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, hBitmap);  
988 -  
989 - //::BitBlt(hMemDC1, 0, 0, dwWidth, dwHeight, hMemDC2, 0, 0, SRCCOPY);  
990 -  
991 - DWORD dwLoopY = 0, dwLoopX = 0;  
992 - COLORREF crPixel = 0;  
993 -  
994 - for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)  
995 - {  
996 - for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)  
997 - {  
998 - crPixel = ::GetPixel(hMemDC2, dwLoopX, dwLoopY);  
999 -  
1000 - if (crPixel != crTrans)  
1001 - ::SetPixel(hMemDC1, dwLoopX, dwLoopY, DarkenColor(crPixel, 0.25));  
1002 - else  
1003 - ::SetPixel(hMemDC1, dwLoopX, dwLoopY, crPixel);  
1004 - } // for  
1005 - } // for  
1006 -  
1007 - ::SelectObject(hMemDC1, hOldBmp1);  
1008 - ::SelectObject(hMemDC2, hOldBmp2);  
1009 - } // if  
1010 -  
1011 - ::DeleteDC(hMemDC1);  
1012 - ::DeleteDC(hMemDC2);  
1013 - ::ReleaseDC(NULL, hMainDC);  
1014 -  
1015 - return hGrayBitmap;  
1016 -} // End of CreateDarkerBitmap  
1017 -  
1018 -// This function creates a grayscale icon starting from a given icon.  
1019 -// The resulting icon will have the same size of the original one.  
1020 -//  
1021 -// Parameters:  
1022 -// [IN] hIcon  
1023 -// Handle to the original icon.  
1024 -//  
1025 -// Return value:  
1026 -// If the function succeeds, the return value is the handle to the newly created  
1027 -// grayscale icon.  
1028 -// If the function fails, the return value is NULL.  
1029 -//  
1030 -// Updates:  
1031 -// 26/Nov/2002 Restored 1 BitBlt operation  
1032 -// 03/May/2002 Removed dependancy from m_hWnd  
1033 -// Removed 1 BitBlt operation  
1034 -//  
1035 -HICON CButtonST::CreateGrayscaleIcon(HICON hIcon)  
1036 -{  
1037 - HICON hGrayIcon = NULL;  
1038 - HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;  
1039 - BITMAP bmp;  
1040 - HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;  
1041 - ICONINFO csII, csGrayII;  
1042 - BOOL bRetValue = FALSE;  
1043 -  
1044 - bRetValue = ::GetIconInfo(hIcon, &csII);  
1045 - if (bRetValue == FALSE) return NULL;  
1046 -  
1047 - hMainDC = ::GetDC(NULL);  
1048 - hMemDC1 = ::CreateCompatibleDC(hMainDC);  
1049 - hMemDC2 = ::CreateCompatibleDC(hMainDC);  
1050 - if (hMainDC == NULL || hMemDC1 == NULL || hMemDC2 == NULL) return NULL;  
1051 -  
1052 - if (::GetObject(csII.hbmColor, sizeof(BITMAP), &bmp))  
1053 - {  
1054 - DWORD dwWidth = csII.xHotspot*2;  
1055 - DWORD dwHeight = csII.yHotspot*2;  
1056 -  
1057 - csGrayII.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);  
1058 - if (csGrayII.hbmColor)  
1059 - {  
1060 - hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, csII.hbmColor);  
1061 - hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, csGrayII.hbmColor);  
1062 -  
1063 - //::BitBlt(hMemDC2, 0, 0, dwWidth, dwHeight, hMemDC1, 0, 0, SRCCOPY);  
1064 -  
1065 - DWORD dwLoopY = 0, dwLoopX = 0;  
1066 - COLORREF crPixel = 0;  
1067 - BYTE byNewPixel = 0;  
1068 -  
1069 - for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)  
1070 - {  
1071 - for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)  
1072 - {  
1073 - crPixel = ::GetPixel(hMemDC1, dwLoopX, dwLoopY);  
1074 - byNewPixel = (BYTE)((GetRValue(crPixel) * 0.299) + (GetGValue(crPixel) * 0.587) + (GetBValue(crPixel) * 0.114));  
1075 -  
1076 - if (crPixel)  
1077 - ::SetPixel(hMemDC2, dwLoopX, dwLoopY, RGB(byNewPixel, byNewPixel, byNewPixel));  
1078 - else  
1079 - ::SetPixel(hMemDC2, dwLoopX, dwLoopY, crPixel);  
1080 - } // for  
1081 - } // for  
1082 -  
1083 - ::SelectObject(hMemDC1, hOldBmp1);  
1084 - ::SelectObject(hMemDC2, hOldBmp2);  
1085 -  
1086 - csGrayII.hbmMask = csII.hbmMask;  
1087 -  
1088 - csGrayII.fIcon = TRUE;  
1089 - hGrayIcon = ::CreateIconIndirect(&csGrayII);  
1090 - } // if  
1091 -  
1092 - ::DeleteObject(csGrayII.hbmColor);  
1093 - //::DeleteObject(csGrayII.hbmMask);  
1094 - } // if  
1095 -  
1096 - ::DeleteObject(csII.hbmColor);  
1097 - ::DeleteObject(csII.hbmMask);  
1098 - ::DeleteDC(hMemDC1);  
1099 - ::DeleteDC(hMemDC2);  
1100 - ::ReleaseDC(NULL, hMainDC);  
1101 -  
1102 - return hGrayIcon;  
1103 -} // End of CreateGrayscaleIcon  
1104 -  
1105 -// This function creates a icon that is 25% darker than the original.  
1106 -// The resulting icon will have the same size of the original one.  
1107 -//  
1108 -// Parameters:  
1109 -// [IN] hIcon  
1110 -// Handle to the original icon.  
1111 -//  
1112 -// Return value:  
1113 -// If the function succeeds, the return value is the handle to the newly created  
1114 -// darker icon.  
1115 -// If the function fails, the return value is NULL.  
1116 -//  
1117 -HICON CButtonST::CreateDarkerIcon(HICON hIcon)  
1118 -{  
1119 - HICON hGrayIcon = NULL;  
1120 - HDC hMainDC = NULL, hMemDC1 = NULL, hMemDC2 = NULL;  
1121 - BITMAP bmp;  
1122 - HBITMAP hOldBmp1 = NULL, hOldBmp2 = NULL;  
1123 - ICONINFO csII, csGrayII;  
1124 - BOOL bRetValue = FALSE;  
1125 -  
1126 - bRetValue = ::GetIconInfo(hIcon, &csII);  
1127 - if (bRetValue == FALSE) return NULL;  
1128 -  
1129 - hMainDC = ::GetDC(NULL);  
1130 - hMemDC1 = ::CreateCompatibleDC(hMainDC);  
1131 - hMemDC2 = ::CreateCompatibleDC(hMainDC);  
1132 - if (hMainDC == NULL || hMemDC1 == NULL || hMemDC2 == NULL) return NULL;  
1133 -  
1134 - if (::GetObject(csII.hbmColor, sizeof(BITMAP), &bmp))  
1135 - {  
1136 - DWORD dwWidth = csII.xHotspot*2;  
1137 - DWORD dwHeight = csII.yHotspot*2;  
1138 -  
1139 - csGrayII.hbmColor = ::CreateBitmap(dwWidth, dwHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL);  
1140 - if (csGrayII.hbmColor)  
1141 - {  
1142 - hOldBmp1 = (HBITMAP)::SelectObject(hMemDC1, csII.hbmColor);  
1143 - hOldBmp2 = (HBITMAP)::SelectObject(hMemDC2, csGrayII.hbmColor);  
1144 -  
1145 - //::BitBlt(hMemDC2, 0, 0, dwWidth, dwHeight, hMemDC1, 0, 0, SRCCOPY);  
1146 -  
1147 - DWORD dwLoopY = 0, dwLoopX = 0;  
1148 - COLORREF crPixel = 0;  
1149 -  
1150 - for (dwLoopY = 0; dwLoopY < dwHeight; dwLoopY++)  
1151 - {  
1152 - for (dwLoopX = 0; dwLoopX < dwWidth; dwLoopX++)  
1153 - {  
1154 - crPixel = ::GetPixel(hMemDC1, dwLoopX, dwLoopY);  
1155 -  
1156 - if (crPixel)  
1157 - ::SetPixel(hMemDC2, dwLoopX, dwLoopY, DarkenColor(crPixel, 0.25));  
1158 - else  
1159 - ::SetPixel(hMemDC2, dwLoopX, dwLoopY, crPixel);  
1160 - } // for  
1161 - } // for  
1162 -  
1163 - ::SelectObject(hMemDC1, hOldBmp1);  
1164 - ::SelectObject(hMemDC2, hOldBmp2);  
1165 -  
1166 - csGrayII.hbmMask = csII.hbmMask;  
1167 -  
1168 - csGrayII.fIcon = TRUE;  
1169 - hGrayIcon = ::CreateIconIndirect(&csGrayII);  
1170 - } // if  
1171 -  
1172 - ::DeleteObject(csGrayII.hbmColor);  
1173 - //::DeleteObject(csGrayII.hbmMask);  
1174 - } // if  
1175 -  
1176 - ::DeleteObject(csII.hbmColor);  
1177 - ::DeleteObject(csII.hbmMask);  
1178 - ::DeleteDC(hMemDC1);  
1179 - ::DeleteDC(hMemDC2);  
1180 - ::ReleaseDC(NULL, hMainDC);  
1181 -  
1182 - return hGrayIcon;  
1183 -} // End of CreateDarkerIcon  
1184 -  
1185 -COLORREF CButtonST::DarkenColor(COLORREF crColor, double dFactor)  
1186 -{  
1187 - if (dFactor > 0.0 && dFactor <= 1.0)  
1188 - {  
1189 - BYTE red,green,blue,lightred,lightgreen,lightblue;  
1190 - red = GetRValue(crColor);  
1191 - green = GetGValue(crColor);  
1192 - blue = GetBValue(crColor);  
1193 - lightred = (BYTE)(red-(dFactor * red));  
1194 - lightgreen = (BYTE)(green-(dFactor * green));  
1195 - lightblue = (BYTE)(blue-(dFactor * blue));  
1196 - crColor = RGB(lightred,lightgreen,lightblue);  
1197 - } // if  
1198 -  
1199 - return crColor;  
1200 -} // End of DarkenColor  
1201 -  
1202 -// This function assigns icons to the button.  
1203 -// Any previous icon or bitmap will be removed.  
1204 -//  
1205 -// Parameters:  
1206 -// [IN] nIconIn  
1207 -// ID number of the icon resource to show when the mouse is over the button.  
1208 -// Pass NULL to remove any icon from the button.  
1209 -// [IN] nCxDesiredIn  
1210 -// Specifies the width, in pixels, of the icon to load.  
1211 -// [IN] nCyDesiredIn  
1212 -// Specifies the height, in pixels, of the icon to load.  
1213 -// [IN] nIconOut  
1214 -// ID number of the icon resource to show when the mouse is outside the button.  
1215 -// Can be NULL.  
1216 -// If this parameter is the special value BTNST_AUTO_GRAY (cast to int) the second  
1217 -// icon will be automatically created starting from nIconIn and converted to grayscale.  
1218 -// If this parameter is the special value BTNST_AUTO_DARKER (cast to int) the second  
1219 -// icon will be automatically created 25% darker starting from nIconIn.  
1220 -// [IN] nCxDesiredOut  
1221 -// Specifies the width, in pixels, of the icon to load.  
1222 -// [IN] nCyDesiredOut  
1223 -// Specifies the height, in pixels, of the icon to load.  
1224 -//  
1225 -// Return value:  
1226 -// BTNST_OK  
1227 -// Function executed successfully.  
1228 -// BTNST_INVALIDRESOURCE  
1229 -// Failed loading the specified resource.  
1230 -//  
1231 -DWORD CButtonST::SetIcon(int nIconIn, int nCxDesiredIn, int nCyDesiredIn, int nIconOut, int nCxDesiredOut, int nCyDesiredOut)  
1232 -{  
1233 - HICON hIconIn = NULL;  
1234 - HICON hIconOut = NULL;  
1235 - HINSTANCE hInstResource = NULL;  
1236 -  
1237 - // Find correct resource handle  
1238 - hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconIn), RT_GROUP_ICON);  
1239 -  
1240 - // Set icon when the mouse is IN the button  
1241 - hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconIn), IMAGE_ICON, nCxDesiredIn, nCyDesiredIn, 0);  
1242 -  
1243 - // Set icon when the mouse is OUT the button  
1244 - switch (nIconOut)  
1245 - {  
1246 - case NULL:  
1247 - break;  
1248 - case (int)BTNST_AUTO_GRAY:  
1249 - hIconOut = BTNST_AUTO_GRAY;  
1250 - break;  
1251 - case (int)BTNST_AUTO_DARKER:  
1252 - hIconOut = BTNST_AUTO_DARKER;  
1253 - break;  
1254 - default:  
1255 - hIconOut = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOut), IMAGE_ICON, nCxDesiredOut, nCyDesiredOut, 0);  
1256 - break;  
1257 - } // switch  
1258 -  
1259 - return SetIcon(hIconIn, hIconOut);  
1260 -} // End of SetIcon  
1261 -  
1262 -// This function assigns icons to the button.  
1263 -// Any previous icon or bitmap will be removed.  
1264 -//  
1265 -// Parameters:  
1266 -// [IN] nIconIn  
1267 -// ID number of the icon resource to show when the mouse is over the button.  
1268 -// Pass NULL to remove any icon from the button.  
1269 -// [IN] nIconOut  
1270 -// ID number of the icon resource to show when the mouse is outside the button.  
1271 -// Can be NULL.  
1272 -// If this parameter is the special value BTNST_AUTO_GRAY (cast to int) the second  
1273 -// icon will be automatically created starting from nIconIn and converted to grayscale.  
1274 -// If this parameter is the special value BTNST_AUTO_DARKER (cast to int) the second  
1275 -// icon will be automatically created 25% darker starting from nIconIn.  
1276 -//  
1277 -// Return value:  
1278 -// BTNST_OK  
1279 -// Function executed successfully.  
1280 -// BTNST_INVALIDRESOURCE  
1281 -// Failed loading the specified resource.  
1282 -//  
1283 -DWORD CButtonST::SetIcon(int nIconIn, int nIconOut)  
1284 -{  
1285 - return SetIcon(nIconIn, 0, 0, nIconOut, 0, 0);  
1286 -} // End of SetIcon  
1287 -  
1288 -// This function assigns icons to the button.  
1289 -// Any previous icon or bitmap will be removed.  
1290 -//  
1291 -// Parameters:  
1292 -// [IN] hIconIn  
1293 -// Handle fo the icon to show when the mouse is over the button.  
1294 -// Pass NULL to remove any icon from the button.  
1295 -// [IN] hIconOut  
1296 -// Handle to the icon to show when the mouse is outside the button.  
1297 -// Can be NULL.  
1298 -// If this parameter is the special value BTNST_AUTO_GRAY the second  
1299 -// icon will be automatically created starting from hIconIn and converted to grayscale.  
1300 -// If this parameter is the special value BTNST_AUTO_DARKER the second  
1301 -// icon will be automatically created 25% darker starting from hIconIn.  
1302 -//  
1303 -// Return value:  
1304 -// BTNST_OK  
1305 -// Function executed successfully.  
1306 -// BTNST_INVALIDRESOURCE  
1307 -// Failed loading the specified resource.  
1308 -//  
1309 -DWORD CButtonST::SetIcon(HICON hIconIn, HICON hIconOut)  
1310 -{  
1311 - BOOL bRetValue;  
1312 - ICONINFO ii;  
1313 -  
1314 - // Free any loaded resource  
1315 - FreeResources();  
1316 -  
1317 - if (hIconIn)  
1318 - {  
1319 - // Icon when mouse over button?  
1320 - m_csIcons[0].hIcon = hIconIn;  
1321 - // Get icon dimension  
1322 - ::ZeroMemory(&ii, sizeof(ICONINFO));  
1323 - bRetValue = ::GetIconInfo(hIconIn, &ii);  
1324 - if (bRetValue == FALSE)  
1325 - {  
1326 - FreeResources();  
1327 - return BTNST_INVALIDRESOURCE;  
1328 - } // if  
1329 -  
1330 - m_csIcons[0].dwWidth = (DWORD)(ii.xHotspot * 2);  
1331 - m_csIcons[0].dwHeight = (DWORD)(ii.yHotspot * 2);  
1332 - ::DeleteObject(ii.hbmMask);  
1333 - ::DeleteObject(ii.hbmColor);  
1334 -  
1335 - // Icon when mouse outside button?  
1336 - if (hIconOut)  
1337 - {  
1338 - switch ((int)hIconOut)  
1339 - {  
1340 - case (int)BTNST_AUTO_GRAY:  
1341 - hIconOut = CreateGrayscaleIcon(hIconIn);  
1342 - break;  
1343 - case (int)BTNST_AUTO_DARKER:  
1344 - hIconOut = CreateDarkerIcon(hIconIn);  
1345 - break;  
1346 - } // switch  
1347 -  
1348 - m_csIcons[1].hIcon = hIconOut;  
1349 - // Get icon dimension  
1350 - ::ZeroMemory(&ii, sizeof(ICONINFO));  
1351 - bRetValue = ::GetIconInfo(hIconOut, &ii);  
1352 - if (bRetValue == FALSE)  
1353 - {  
1354 - FreeResources();  
1355 - return BTNST_INVALIDRESOURCE;  
1356 - } // if  
1357 -  
1358 - m_csIcons[1].dwWidth = (DWORD)(ii.xHotspot * 2);  
1359 - m_csIcons[1].dwHeight = (DWORD)(ii.yHotspot * 2);  
1360 - ::DeleteObject(ii.hbmMask);  
1361 - ::DeleteObject(ii.hbmColor);  
1362 - } // if  
1363 - } // if  
1364 -  
1365 - Invalidate();  
1366 -  
1367 - return BTNST_OK;  
1368 -} // End of SetIcon  
1369 -  
1370 -// This function assigns bitmaps to the button.  
1371 -// Any previous icon or bitmap will be removed.  
1372 -//  
1373 -// Parameters:  
1374 -// [IN] nBitmapIn  
1375 -// ID number of the bitmap resource to show when the mouse is over the button.  
1376 -// Pass NULL to remove any bitmap from the button.  
1377 -// [IN] crTransColorIn  
1378 -// Color (inside nBitmapIn) to be used as transparent color.  
1379 -// [IN] nBitmapOut  
1380 -// ID number of the bitmap resource to show when the mouse is outside the button.  
1381 -// Can be NULL.  
1382 -// [IN] crTransColorOut  
1383 -// Color (inside nBitmapOut) to be used as transparent color.  
1384 -//  
1385 -// Return value:  
1386 -// BTNST_OK  
1387 -// Function executed successfully.  
1388 -// BTNST_INVALIDRESOURCE  
1389 -// Failed loading the specified resource.  
1390 -// BTNST_FAILEDMASK  
1391 -// Failed creating mask bitmap.  
1392 -//  
1393 -DWORD CButtonST::SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut, COLORREF crTransColorOut)  
1394 -{  
1395 - HBITMAP hBitmapIn = NULL;  
1396 - HBITMAP hBitmapOut = NULL;  
1397 - HINSTANCE hInstResource = NULL;  
1398 -  
1399 - // Find correct resource handle  
1400 - hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nBitmapIn), RT_BITMAP);  
1401 -  
1402 - // Load bitmap In  
1403 - hBitmapIn = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapIn), IMAGE_BITMAP, 0, 0, 0);  
1404 -  
1405 - // Load bitmap Out  
1406 - switch (nBitmapOut)  
1407 - {  
1408 - case NULL:  
1409 - break;  
1410 - case (int)BTNST_AUTO_GRAY:  
1411 - hBitmapOut = (HBITMAP)BTNST_AUTO_GRAY;  
1412 - break;  
1413 - case (int)BTNST_AUTO_DARKER:  
1414 - hBitmapOut = (HBITMAP)BTNST_AUTO_DARKER;  
1415 - break;  
1416 - default:  
1417 - hBitmapOut = (HBITMAP)::LoadImage(hInstResource, MAKEINTRESOURCE(nBitmapOut), IMAGE_BITMAP, 0, 0, 0);  
1418 - break;  
1419 - } // if  
1420 -  
1421 - return SetBitmaps(hBitmapIn, crTransColorIn, hBitmapOut, crTransColorOut);  
1422 -} // End of SetBitmaps  
1423 -  
1424 -// This function assigns bitmaps to the button.  
1425 -// Any previous icon or bitmap will be removed.  
1426 -//  
1427 -// Parameters:  
1428 -// [IN] hBitmapIn  
1429 -// Handle fo the bitmap to show when the mouse is over the button.  
1430 -// Pass NULL to remove any bitmap from the button.  
1431 -// [IN] crTransColorIn  
1432 -// Color (inside hBitmapIn) to be used as transparent color.  
1433 -// [IN] hBitmapOut  
1434 -// Handle to the bitmap to show when the mouse is outside the button.  
1435 -// Can be NULL.  
1436 -// [IN] crTransColorOut  
1437 -// Color (inside hBitmapOut) to be used as transparent color.  
1438 -//  
1439 -// Return value:  
1440 -// BTNST_OK  
1441 -// Function executed successfully.  
1442 -// BTNST_INVALIDRESOURCE  
1443 -// Failed loading the specified resource.  
1444 -// BTNST_FAILEDMASK  
1445 -// Failed creating mask bitmap.  
1446 -//  
1447 -DWORD CButtonST::SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut, COLORREF crTransColorOut)  
1448 -{  
1449 - int nRetValue = 0;  
1450 - BITMAP csBitmapSize;  
1451 -  
1452 - // Free any loaded resource  
1453 - FreeResources();  
1454 -  
1455 - if (hBitmapIn)  
1456 - {  
1457 - m_csBitmaps[0].hBitmap = hBitmapIn;  
1458 - m_csBitmaps[0].crTransparent = crTransColorIn;  
1459 - // Get bitmap size  
1460 - nRetValue = ::GetObject(hBitmapIn, sizeof(csBitmapSize), &csBitmapSize);  
1461 - if (nRetValue == 0)  
1462 - {  
1463 - FreeResources();  
1464 - return BTNST_INVALIDRESOURCE;  
1465 - } // if  
1466 - m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth;  
1467 - m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight;  
1468 -  
1469 - // Create grayscale/darker bitmap BEFORE mask (of hBitmapIn)  
1470 - switch ((int)hBitmapOut)  
1471 - {  
1472 - case (int)BTNST_AUTO_GRAY:  
1473 - hBitmapOut = CreateGrayscaleBitmap(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);  
1474 - m_csBitmaps[1].hBitmap = hBitmapOut;  
1475 - crTransColorOut = crTransColorIn;  
1476 - break;  
1477 - case (int)BTNST_AUTO_DARKER:  
1478 - hBitmapOut = CreateDarkerBitmap(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);  
1479 - m_csBitmaps[1].hBitmap = hBitmapOut;  
1480 - crTransColorOut = crTransColorIn;  
1481 - break;  
1482 - } // switch  
1483 -  
1484 - // Create mask for bitmap In  
1485 - m_csBitmaps[0].hMask = CreateBitmapMask(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn);  
1486 - if (m_csBitmaps[0].hMask == NULL)  
1487 - {  
1488 - FreeResources();  
1489 - return BTNST_FAILEDMASK;  
1490 - } // if  
1491 -  
1492 - if (hBitmapOut)  
1493 - {  
1494 - m_csBitmaps[1].hBitmap = hBitmapOut;  
1495 - m_csBitmaps[1].crTransparent = crTransColorOut;  
1496 - // Get bitmap size  
1497 - nRetValue = ::GetObject(hBitmapOut, sizeof(csBitmapSize), &csBitmapSize);  
1498 - if (nRetValue == 0)  
1499 - {  
1500 - FreeResources();  
1501 - return BTNST_INVALIDRESOURCE;  
1502 - } // if  
1503 - m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth;  
1504 - m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight;  
1505 -  
1506 - // Create mask for bitmap Out  
1507 - m_csBitmaps[1].hMask = CreateBitmapMask(hBitmapOut, m_csBitmaps[1].dwWidth, m_csBitmaps[1].dwHeight, crTransColorOut);  
1508 - if (m_csBitmaps[1].hMask == NULL)  
1509 - {  
1510 - FreeResources();  
1511 - return BTNST_FAILEDMASK;  
1512 - } // if  
1513 - } // if  
1514 - } // if  
1515 -  
1516 - Invalidate();  
1517 -  
1518 - return BTNST_OK;  
1519 -} // End of SetBitmaps  
1520 -  
1521 -// This functions sets the button to have a standard or flat style.  
1522 -//  
1523 -// Parameters:  
1524 -// [IN] bFlat  
1525 -// If TRUE the button will have a flat style, else  
1526 -// will have a standard style.  
1527 -// By default, CButtonST buttons are flat.  
1528 -// [IN] bRepaint  
1529 -// If TRUE the control will be repainted.  
1530 -//  
1531 -// Return value:  
1532 -// BTNST_OK  
1533 -// Function executed successfully.  
1534 -//  
1535 -DWORD CButtonST::SetFlat(BOOL bFlat, BOOL bRepaint)  
1536 -{  
1537 - m_bIsFlat = bFlat;  
1538 - if (bRepaint) Invalidate();  
1539 -  
1540 - return BTNST_OK;  
1541 -} // End of SetFlat  
1542 -  
1543 -// This function sets the alignment type between icon/bitmap and text.  
1544 -//  
1545 -// Parameters:  
1546 -// [IN] byAlign  
1547 -// Alignment type. Can be one of the following values:  
1548 -// ST_ALIGN_HORIZ Icon/bitmap on the left, text on the right  
1549 -// ST_ALIGN_VERT Icon/bitmap on the top, text on the bottom  
1550 -// ST_ALIGN_HORIZ_RIGHT Icon/bitmap on the right, text on the left  
1551 -// ST_ALIGN_OVERLAP Icon/bitmap on the same space as text  
1552 -// By default, CButtonST buttons have ST_ALIGN_HORIZ alignment.  
1553 -// [IN] bRepaint  
1554 -// If TRUE the control will be repainted.  
1555 -//  
1556 -// Return value:  
1557 -// BTNST_OK  
1558 -// Function executed successfully.  
1559 -// BTNST_INVALIDALIGN  
1560 -// Alignment type not supported.  
1561 -//  
1562 -DWORD CButtonST::SetAlign(BYTE byAlign, BOOL bRepaint)  
1563 -{  
1564 - switch (byAlign)  
1565 - {  
1566 - case ST_ALIGN_HORIZ:  
1567 - case ST_ALIGN_HORIZ_RIGHT:  
1568 - case ST_ALIGN_VERT:  
1569 - case ST_ALIGN_OVERLAP:  
1570 - m_byAlign = byAlign;  
1571 - if (bRepaint) Invalidate();  
1572 - return BTNST_OK;  
1573 - break;  
1574 - } // switch  
1575 -  
1576 - return BTNST_INVALIDALIGN;  
1577 -} // End of SetAlign  
1578 -  
1579 -// This function sets the pressed style.  
1580 -//  
1581 -// Parameters:  
1582 -// [IN] byStyle  
1583 -// Pressed style. Can be one of the following values:  
1584 -// BTNST_PRESSED_LEFTRIGHT Pressed style from left to right (as usual)  
1585 -// BTNST_PRESSED_TOPBOTTOM Pressed style from top to bottom  
1586 -// By default, CButtonST buttons have BTNST_PRESSED_LEFTRIGHT style.  
1587 -// [IN] bRepaint  
1588 -// If TRUE the control will be repainted.  
1589 -//  
1590 -// Return value:  
1591 -// BTNST_OK  
1592 -// Function executed successfully.  
1593 -// BTNST_INVALIDPRESSEDSTYLE  
1594 -// Pressed style not supported.  
1595 -//  
1596 -DWORD CButtonST::SetPressedStyle(BYTE byStyle, BOOL bRepaint)  
1597 -{  
1598 - switch (byStyle)  
1599 - {  
1600 - case BTNST_PRESSED_LEFTRIGHT:  
1601 - m_ptPressedOffset.x = 1;  
1602 - m_ptPressedOffset.y = 1;  
1603 - break;  
1604 - case BTNST_PRESSED_TOPBOTTOM:  
1605 - m_ptPressedOffset.x = 0;  
1606 - m_ptPressedOffset.y = 2;  
1607 - break;  
1608 - default:  
1609 - return BTNST_INVALIDPRESSEDSTYLE;  
1610 - } // switch  
1611 -  
1612 - if (bRepaint) Invalidate();  
1613 -  
1614 - return BTNST_OK;  
1615 -} // End of SetPressedStyle  
1616 -  
1617 -// This function sets the state of the checkbox.  
1618 -// If the button is not a checkbox, this function has no meaning.  
1619 -//  
1620 -// Parameters:  
1621 -// [IN] nCheck  
1622 -// 1 to check the checkbox.  
1623 -// 0 to un-check the checkbox.  
1624 -// [IN] bRepaint  
1625 -// If TRUE the control will be repainted.  
1626 -//  
1627 -// Return value:  
1628 -// BTNST_OK  
1629 -// Function executed successfully.  
1630 -//  
1631 -DWORD CButtonST::SetCheck(int nCheck, BOOL bRepaint)  
1632 -{  
1633 - if (m_bIsCheckBox)  
1634 - {  
1635 - if (nCheck == 0) m_nCheck = 0;  
1636 - else m_nCheck = 1;  
1637 -  
1638 - if (bRepaint) Invalidate();  
1639 - } // if  
1640 -  
1641 - return BTNST_OK;  
1642 -} // End of SetCheck  
1643 -  
1644 -// This function returns the current state of the checkbox.  
1645 -// If the button is not a checkbox, this function has no meaning.  
1646 -//  
1647 -// Return value:  
1648 -// The current state of the checkbox.  
1649 -// 1 if checked.  
1650 -// 0 if not checked or the button is not a checkbox.  
1651 -//  
1652 -int CButtonST::GetCheck()  
1653 -{  
1654 - return m_nCheck;  
1655 -} // End of GetCheck  
1656 -  
1657 -// This function sets all colors to a default value.  
1658 -//  
1659 -// Parameters:  
1660 -// [IN] bRepaint  
1661 -// If TRUE the control will be repainted.  
1662 -//  
1663 -// Return value:  
1664 -// BTNST_OK  
1665 -// Function executed successfully.  
1666 -//  
1667 -DWORD CButtonST::SetDefaultColors(BOOL bRepaint)  
1668 -{  
1669 - m_crColors[BTNST_COLOR_BK_IN] = ::GetSysColor(COLOR_BTNFACE);  
1670 - m_crColors[BTNST_COLOR_FG_IN] = ::GetSysColor(COLOR_BTNTEXT);  
1671 - m_crColors[BTNST_COLOR_BK_OUT] = ::GetSysColor(COLOR_BTNFACE);  
1672 - m_crColors[BTNST_COLOR_FG_OUT] = ::GetSysColor(COLOR_BTNTEXT);  
1673 - m_crColors[BTNST_COLOR_BK_FOCUS] = ::GetSysColor(COLOR_BTNFACE);  
1674 - m_crColors[BTNST_COLOR_FG_FOCUS] = ::GetSysColor(COLOR_BTNTEXT);  
1675 -  
1676 - if (bRepaint) Invalidate();  
1677 -  
1678 - return BTNST_OK;  
1679 -} // End of SetDefaultColors  
1680 -  
1681 -// This function sets the color to use for a particular state.  
1682 -//  
1683 -// Parameters:  
1684 -// [IN] byColorIndex  
1685 -// Index of the color to set. Can be one of the following values:  
1686 -// BTNST_COLOR_BK_IN Background color when mouse is over the button  
1687 -// BTNST_COLOR_FG_IN Text color when mouse is over the button  
1688 -// BTNST_COLOR_BK_OUT Background color when mouse is outside the button  
1689 -// BTNST_COLOR_FG_OUT Text color when mouse is outside the button  
1690 -// BTNST_COLOR_BK_FOCUS Background color when the button is focused  
1691 -// BTNST_COLOR_FG_FOCUS Text color when the button is focused  
1692 -// [IN] crColor  
1693 -// New color.  
1694 -// [IN] bRepaint  
1695 -// If TRUE the control will be repainted.  
1696 -//  
1697 -// Return value:  
1698 -// BTNST_OK  
1699 -// Function executed successfully.  
1700 -// BTNST_INVALIDINDEX  
1701 -// Invalid color index.  
1702 -//  
1703 -DWORD CButtonST::SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint)  
1704 -{  
1705 - if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;  
1706 -  
1707 - // Set new color  
1708 - m_crColors[byColorIndex] = crColor;  
1709 -  
1710 - if (bRepaint) Invalidate();  
1711 -  
1712 - return BTNST_OK;  
1713 -} // End of SetColor  
1714 -  
1715 -// This functions returns the color used for a particular state.  
1716 -//  
1717 -// Parameters:  
1718 -// [IN] byColorIndex  
1719 -// Index of the color to get.  
1720 -// See SetColor for the list of available colors.  
1721 -// [OUT] crpColor  
1722 -// A pointer to a COLORREF that will receive the color.  
1723 -//  
1724 -// Return value:  
1725 -// BTNST_OK  
1726 -// Function executed successfully.  
1727 -// BTNST_INVALIDINDEX  
1728 -// Invalid color index.  
1729 -//  
1730 -DWORD CButtonST::GetColor(BYTE byColorIndex, COLORREF* crpColor)  
1731 -{  
1732 - if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;  
1733 -  
1734 - // Get color  
1735 - *crpColor = m_crColors[byColorIndex];  
1736 -  
1737 - return BTNST_OK;  
1738 -} // End of GetColor  
1739 -  
1740 -// This function applies an offset to the RGB components of the specified color.  
1741 -// This function can be seen as an easy way to make a color darker or lighter than  
1742 -// its default value.  
1743 -//  
1744 -// Parameters:  
1745 -// [IN] byColorIndex  
1746 -// Index of the color to set.  
1747 -// See SetColor for the list of available colors.  
1748 -// [IN] shOffsetColor  
1749 -// A short value indicating the offset to apply to the color.  
1750 -// This value must be between -255 and 255.  
1751 -// [IN] bRepaint  
1752 -// If TRUE the control will be repainted.  
1753 -//  
1754 -// Return value:  
1755 -// BTNST_OK  
1756 -// Function executed successfully.  
1757 -// BTNST_INVALIDINDEX  
1758 -// Invalid color index.  
1759 -// BTNST_BADPARAM  
1760 -// The specified offset is out of range.  
1761 -//  
1762 -DWORD CButtonST::OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint)  
1763 -{  
1764 - BYTE byRed = 0;  
1765 - BYTE byGreen = 0;  
1766 - BYTE byBlue = 0;  
1767 - short shOffsetR = shOffset;  
1768 - short shOffsetG = shOffset;  
1769 - short shOffsetB = shOffset;  
1770 -  
1771 - if (byColorIndex >= BTNST_MAX_COLORS) return BTNST_INVALIDINDEX;  
1772 - if (shOffset < -255 || shOffset > 255) return BTNST_BADPARAM;  
1773 -  
1774 - // Get RGB components of specified color  
1775 - byRed = GetRValue(m_crColors[byColorIndex]);  
1776 - byGreen = GetGValue(m_crColors[byColorIndex]);  
1777 - byBlue = GetBValue(m_crColors[byColorIndex]);  
1778 -  
1779 - // Calculate max. allowed real offset  
1780 - if (shOffset > 0)  
1781 - {  
1782 - if (byRed + shOffset > 255) shOffsetR = 255 - byRed;  
1783 - if (byGreen + shOffset > 255) shOffsetG = 255 - byGreen;  
1784 - if (byBlue + shOffset > 255) shOffsetB = 255 - byBlue;  
1785 -  
1786 - shOffset = min(min(shOffsetR, shOffsetG), shOffsetB);  
1787 - } // if  
1788 - else  
1789 - {  
1790 - if (byRed + shOffset < 0) shOffsetR = -byRed;  
1791 - if (byGreen + shOffset < 0) shOffsetG = -byGreen;  
1792 - if (byBlue + shOffset < 0) shOffsetB = -byBlue;  
1793 -  
1794 - shOffset = max(max(shOffsetR, shOffsetG), shOffsetB);  
1795 - } // else  
1796 -  
1797 - // Set new color  
1798 - m_crColors[byColorIndex] = RGB(byRed + shOffset, byGreen + shOffset, byBlue + shOffset);  
1799 -  
1800 - if (bRepaint) Invalidate();  
1801 -  
1802 - return BTNST_OK;  
1803 -} // End of OffsetColor  
1804 -  
1805 -// This function sets the hilight logic for the button.  
1806 -// Applies only to flat buttons.  
1807 -//  
1808 -// Parameters:  
1809 -// [IN] bAlwaysTrack  
1810 -// If TRUE the button will be hilighted even if the window that owns it, is  
1811 -// not the active window.  
1812 -// If FALSE the button will be hilighted only if the window that owns it,  
1813 -// is the active window.  
1814 -//  
1815 -// Return value:  
1816 -// BTNST_OK  
1817 -// Function executed successfully.  
1818 -//  
1819 -DWORD CButtonST::SetAlwaysTrack(BOOL bAlwaysTrack)  
1820 -{  
1821 - m_bAlwaysTrack = bAlwaysTrack;  
1822 - return BTNST_OK;  
1823 -} // End of SetAlwaysTrack  
1824 -  
1825 -// This function sets the cursor to be used when the mouse is over the button.  
1826 -//  
1827 -// Parameters:  
1828 -// [IN] nCursorId  
1829 -// ID number of the cursor resource.  
1830 -// Pass NULL to remove a previously loaded cursor.  
1831 -// [IN] bRepaint  
1832 -// If TRUE the control will be repainted.  
1833 -//  
1834 -// Return value:  
1835 -// BTNST_OK  
1836 -// Function executed successfully.  
1837 -// BTNST_INVALIDRESOURCE  
1838 -// Failed loading the specified resource.  
1839 -//  
1840 -DWORD CButtonST::SetBtnCursor(int nCursorId, BOOL bRepaint)  
1841 -{  
1842 - HINSTANCE hInstResource = NULL;  
1843 - // Destroy any previous cursor  
1844 - if (m_hCursor)  
1845 - {  
1846 - ::DestroyCursor(m_hCursor);  
1847 - m_hCursor = NULL;  
1848 - } // if  
1849 -  
1850 - // Load cursor  
1851 - if (nCursorId)  
1852 - {  
1853 - hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR);  
1854 - // Load cursor resource  
1855 - m_hCursor = (HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);  
1856 - // Repaint the button  
1857 - if (bRepaint) Invalidate();  
1858 - // If something wrong  
1859 - if (m_hCursor == NULL) return BTNST_INVALIDRESOURCE;  
1860 - } // if  
1861 -  
1862 - return BTNST_OK;  
1863 -} // End of SetBtnCursor  
1864 -  
1865 -// This function sets if the button border must be drawn.  
1866 -// Applies only to flat buttons.  
1867 -//  
1868 -// Parameters:  
1869 -// [IN] bDrawBorder  
1870 -// If TRUE the border will be drawn.  
1871 -// [IN] bRepaint  
1872 -// If TRUE the control will be repainted.  
1873 -//  
1874 -// Return value:  
1875 -// BTNST_OK  
1876 -// Function executed successfully.  
1877 -//  
1878 -DWORD CButtonST::DrawBorder(BOOL bDrawBorder, BOOL bRepaint)  
1879 -{  
1880 - m_bDrawBorder = bDrawBorder;  
1881 - // Repaint the button  
1882 - if (bRepaint) Invalidate();  
1883 -  
1884 - return BTNST_OK;  
1885 -} // End of DrawBorder  
1886 -  
1887 -// This function sets if the focus rectangle must be drawn for flat buttons.  
1888 -//  
1889 -// Parameters:  
1890 -// [IN] bDrawFlatFocus  
1891 -// If TRUE the focus rectangle will be drawn also for flat buttons.  
1892 -// [IN] bRepaint  
1893 -// If TRUE the control will be repainted.  
1894 -//  
1895 -// Return value:  
1896 -// BTNST_OK  
1897 -// Function executed successfully.  
1898 -//  
1899 -DWORD CButtonST::DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint)  
1900 -{  
1901 - m_bDrawFlatFocus = bDrawFlatFocus;  
1902 - // Repaint the button  
1903 - if (bRepaint) Invalidate();  
1904 -  
1905 - return BTNST_OK;  
1906 -} // End of DrawFlatFocus  
1907 -  
1908 -void CButtonST::InitToolTip()  
1909 -{  
1910 - if (m_ToolTip.m_hWnd == NULL)  
1911 - {  
1912 - // Create ToolTip control  
1913 - m_ToolTip.Create(this, m_dwToolTipStyle);  
1914 - // Create inactive  
1915 - m_ToolTip.Activate(FALSE);  
1916 - // Enable multiline  
1917 - m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400);  
1918 - //m_ToolTip.SendMessage(TTM_SETTITLE, TTI_INFO, (LPARAM)_T("Title"));  
1919 - } // if  
1920 -} // End of InitToolTip  
1921 -  
1922 -// This function sets the text to show in the button tooltip.  
1923 -//  
1924 -// Parameters:  
1925 -// [IN] nText  
1926 -// ID number of the string resource containing the text to show.  
1927 -// [IN] bActivate  
1928 -// If TRUE the tooltip will be created active.  
1929 -//  
1930 -void CButtonST::SetTooltipText(int nText, BOOL bActivate)  
1931 -{  
1932 - CString sText;  
1933 -  
1934 - // Load string resource  
1935 - sText.LoadString(nText);  
1936 - // If string resource is not empty  
1937 - if (sText.IsEmpty() == FALSE) SetTooltipText((LPCTSTR)sText, bActivate);  
1938 -} // End of SetTooltipText  
1939 -  
1940 -// This function sets the text to show in the button tooltip.  
1941 -//  
1942 -// Parameters:  
1943 -// [IN] lpszText  
1944 -// Pointer to a null-terminated string containing the text to show.  
1945 -// [IN] bActivate  
1946 -// If TRUE the tooltip will be created active.  
1947 -//  
1948 -void CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)  
1949 -{  
1950 - // We cannot accept NULL pointer  
1951 - if (lpszText == NULL) return;  
1952 -  
1953 - // Initialize ToolTip  
1954 - InitToolTip();  
1955 -  
1956 - // If there is no tooltip defined then add it  
1957 - if (m_ToolTip.GetToolCount() == 0)  
1958 - {  
1959 - CRect rectBtn;  
1960 - GetClientRect(rectBtn);  
1961 - m_ToolTip.AddTool(this, lpszText, rectBtn, 1);  
1962 - } // if  
1963 -  
1964 - // Set text for tooltip  
1965 - m_ToolTip.UpdateTipText(lpszText, this, 1);  
1966 - m_ToolTip.Activate(bActivate);  
1967 -} // End of SetTooltipText  
1968 -  
1969 -// This function enables or disables the button tooltip.  
1970 -//  
1971 -// Parameters:  
1972 -// [IN] bActivate  
1973 -// If TRUE the tooltip will be activated.  
1974 -//  
1975 -void CButtonST::ActivateTooltip(BOOL bActivate)  
1976 -{  
1977 - // If there is no tooltip then do nothing  
1978 - if (m_ToolTip.GetToolCount() == 0) return;  
1979 -  
1980 - // Activate tooltip  
1981 - m_ToolTip.Activate(bActivate);  
1982 -} // End of EnableTooltip  
1983 -  
1984 -// This function enables the tooltip to be displayed using the balloon style.  
1985 -// This function must be called before any call to SetTooltipText is made.  
1986 -//  
1987 -// Return value:  
1988 -// BTNST_OK  
1989 -// Function executed successfully.  
1990 -//  
1991 -DWORD CButtonST::EnableBalloonTooltip()  
1992 -{  
1993 - m_dwToolTipStyle |= TTS_BALLOON;  
1994 - return BTNST_OK;  
1995 -} // End of EnableBalloonTooltip  
1996 -  
1997 -// This function returns if the button is the default button.  
1998 -//  
1999 -// Return value:  
2000 -// TRUE  
2001 -// The button is the default button.  
2002 -// FALSE  
2003 -// The button is not the default button.  
2004 -//  
2005 -BOOL CButtonST::GetDefault()  
2006 -{  
2007 - return m_bIsDefault;  
2008 -} // End of GetDefault  
2009 -  
2010 -// This function enables the transparent mode.  
2011 -// Note: this operation is not reversible.  
2012 -// DrawTransparent should be called just after the button is created.  
2013 -// Do not use trasparent buttons until you really need it (you have a bitmapped  
2014 -// background) since each transparent button makes a copy in memory of its background.  
2015 -// This may bring unnecessary memory use and execution overload.  
2016 -//  
2017 -// Parameters:  
2018 -// [IN] bRepaint  
2019 -// If TRUE the control will be repainted.  
2020 -//  
2021 -void CButtonST::DrawTransparent(BOOL bRepaint)  
2022 -{  
2023 - m_bDrawTransparent = TRUE;  
2024 -  
2025 - // Restore old bitmap (if any)  
2026 - if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)  
2027 - {  
2028 - m_dcBk.SelectObject(m_pbmpOldBk);  
2029 - } // if  
2030 -  
2031 - m_bmpBk.DeleteObject();  
2032 - m_dcBk.DeleteDC();  
2033 -  
2034 - // Repaint the button  
2035 - if (bRepaint) Invalidate();  
2036 -} // End of DrawTransparent  
2037 -  
2038 -DWORD CButtonST::SetBk(CDC* pDC)  
2039 -{  
2040 - if (m_bDrawTransparent && pDC)  
2041 - {  
2042 - // Restore old bitmap (if any)  
2043 - if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)  
2044 - {  
2045 - m_dcBk.SelectObject(m_pbmpOldBk);  
2046 - } // if  
2047 -  
2048 - m_bmpBk.DeleteObject();  
2049 - m_dcBk.DeleteDC();  
2050 -  
2051 - CRect rect;  
2052 - CRect rect1;  
2053 -  
2054 - GetClientRect(rect);  
2055 -  
2056 - GetWindowRect(rect1);  
2057 - GetParent()->ScreenToClient(rect1);  
2058 -  
2059 - m_dcBk.CreateCompatibleDC(pDC);  
2060 - m_bmpBk.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());  
2061 - m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk);  
2062 - m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, rect1.left, rect1.top, SRCCOPY);  
2063 -  
2064 - return BTNST_OK;  
2065 - } // if  
2066 -  
2067 - return BTNST_BADPARAM;  
2068 -} // End of SetBk  
2069 -  
2070 -// This function sets the URL that will be opened when the button is clicked.  
2071 -//  
2072 -// Parameters:  
2073 -// [IN] lpszURL  
2074 -// Pointer to a null-terminated string that contains the URL.  
2075 -// Pass NULL to removed any previously specified URL.  
2076 -//  
2077 -// Return value:  
2078 -// BTNST_OK  
2079 -// Function executed successfully.  
2080 -//  
2081 -DWORD CButtonST::SetURL(LPCTSTR lpszURL)  
2082 -{  
2083 - // Remove any existing URL  
2084 - memset(m_szURL, 0, sizeof(m_szURL));  
2085 -  
2086 - if (lpszURL)  
2087 - {  
2088 - // Store the URL  
2089 - _tcsncpy(m_szURL, lpszURL, _MAX_PATH);  
2090 - } // if  
2091 -  
2092 - return BTNST_OK;  
2093 -} // End of SetURL  
2094 -  
2095 -// This function associates a menu to the button.  
2096 -// The menu will be displayed clicking the button.  
2097 -//  
2098 -// Parameters:  
2099 -// [IN] nMenu  
2100 -// ID number of the menu resource.  
2101 -// Pass NULL to remove any menu from the button.  
2102 -// [IN] hParentWnd  
2103 -// Handle to the window that owns the menu.  
2104 -// This window receives all messages from the menu.  
2105 -// [IN] bRepaint  
2106 -// If TRUE the control will be repainted.  
2107 -//  
2108 -// Return value:  
2109 -// BTNST_OK  
2110 -// Function executed successfully.  
2111 -// BTNST_INVALIDRESOURCE  
2112 -// Failed loading the specified resource.  
2113 -//  
2114 -#ifndef BTNST_USE_BCMENU  
2115 -DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint)  
2116 -{  
2117 - HINSTANCE hInstResource = NULL;  
2118 -  
2119 - // Destroy any previous menu  
2120 - if (m_hMenu)  
2121 - {  
2122 - ::DestroyMenu(m_hMenu);  
2123 - m_hMenu = NULL;  
2124 - m_hParentWndMenu = NULL;  
2125 - m_bMenuDisplayed = FALSE;  
2126 - } // if  
2127 -  
2128 - // Load menu  
2129 - if (nMenu)  
2130 - {  
2131 - // Find correct resource handle  
2132 - hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nMenu), RT_MENU);  
2133 - // Load menu resource  
2134 - m_hMenu = ::LoadMenu(hInstResource, MAKEINTRESOURCE(nMenu));  
2135 - m_hParentWndMenu = hParentWnd;  
2136 - // If something wrong  
2137 - if (m_hMenu == NULL) return BTNST_INVALIDRESOURCE;  
2138 - } // if  
2139 -  
2140 - // Repaint the button  
2141 - if (bRepaint) Invalidate();  
2142 -  
2143 - return BTNST_OK;  
2144 -} // End of SetMenu  
2145 -#endif  
2146 -  
2147 -// This function associates a menu to the button.  
2148 -// The menu will be displayed clicking the button.  
2149 -// The menu will be handled by the BCMenu class.  
2150 -//  
2151 -// Parameters:  
2152 -// [IN] nMenu  
2153 -// ID number of the menu resource.  
2154 -// Pass NULL to remove any menu from the button.  
2155 -// [IN] hParentWnd  
2156 -// Handle to the window that owns the menu.  
2157 -// This window receives all messages from the menu.  
2158 -// [IN] bWinXPStyle  
2159 -// If TRUE the menu will be displayed using the new Windows XP style.  
2160 -// If FALSE the menu will be displayed using the standard style.  
2161 -// [IN] nToolbarID  
2162 -// Resource ID of the toolbar to be associated to the menu.  
2163 -// [IN] sizeToolbarIcon  
2164 -// A CSize object indicating the size (in pixels) of each icon into the toolbar.  
2165 -// All icons into the toolbar must have the same size.  
2166 -// [IN] crToolbarBk  
2167 -// A COLORREF value indicating the color to use as background for the icons into the toolbar.  
2168 -// This color will be used as the "transparent" color.  
2169 -// [IN] bRepaint  
2170 -// If TRUE the control will be repainted.  
2171 -//  
2172 -// Return value:  
2173 -// BTNST_OK  
2174 -// Function executed successfully.  
2175 -// BTNST_INVALIDRESOURCE  
2176 -// Failed loading the specified resource.  
2177 -//  
2178 -#ifdef BTNST_USE_BCMENU  
2179 -DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle, UINT nToolbarID, CSize sizeToolbarIcon, COLORREF crToolbarBk, BOOL bRepaint)  
2180 -{  
2181 - BOOL bRetValue = FALSE;  
2182 -  
2183 - // Destroy any previous menu  
2184 - if (m_menuPopup.m_hMenu)  
2185 - {  
2186 - m_menuPopup.DestroyMenu();  
2187 - m_hParentWndMenu = NULL;  
2188 - m_bMenuDisplayed = FALSE;  
2189 - } // if  
2190 -  
2191 - // Load menu  
2192 - if (nMenu)  
2193 - {  
2194 - m_menuPopup.SetMenuDrawMode(bWinXPStyle);  
2195 - // Load menu  
2196 - bRetValue = m_menuPopup.LoadMenu(nMenu);  
2197 - // If something wrong  
2198 - if (bRetValue == FALSE) return BTNST_INVALIDRESOURCE;  
2199 -  
2200 - // Load toolbar  
2201 - if (nToolbarID)  
2202 - {  
2203 - m_menuPopup.SetBitmapBackground(crToolbarBk);  
2204 - m_menuPopup.SetIconSize(sizeToolbarIcon.cx, sizeToolbarIcon.cy);  
2205 -  
2206 - bRetValue = m_menuPopup.LoadToolbar(nToolbarID);  
2207 - // If something wrong  
2208 - if (bRetValue == FALSE)  
2209 - {  
2210 - m_menuPopup.DestroyMenu();  
2211 - return BTNST_INVALIDRESOURCE;  
2212 - } // if  
2213 - } // if  
2214 -  
2215 - m_hParentWndMenu = hParentWnd;  
2216 - } // if  
2217 -  
2218 - // Repaint the button  
2219 - if (bRepaint) Invalidate();  
2220 -  
2221 - return BTNST_OK;  
2222 -} // End of SetMenu  
2223 -#endif  
2224 -  
2225 -// This function sets the callback message that will be sent to the  
2226 -// specified window just before the menu associated to the button is displayed.  
2227 -//  
2228 -// Parameters:  
2229 -// [IN] hWnd  
2230 -// Handle of the window that will receive the callback message.  
2231 -// Pass NULL to remove any previously specified callback message.  
2232 -// [IN] nMessage  
2233 -// Callback message to send to window.  
2234 -// [IN] lParam  
2235 -// A 32 bits user specified value that will be passed to the callback function.  
2236 -//  
2237 -// Remarks:  
2238 -// the callback function must be in the form:  
2239 -// LRESULT On_MenuCallback(WPARAM wParam, LPARAM lParam)  
2240 -// Where:  
2241 -// [IN] wParam  
2242 -// If support for BCMenu is enabled: a pointer to BCMenu  
2243 -// else a HMENU handle to the menu that is being to be displayed.  
2244 -// [IN] lParam  
2245 -// The 32 bits user specified value.  
2246 -//  
2247 -// Return value:  
2248 -// BTNST_OK  
2249 -// Function executed successfully.  
2250 -//  
2251 -DWORD CButtonST::SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam)  
2252 -{  
2253 - m_csCallbacks.hWnd = hWnd;  
2254 - m_csCallbacks.nMessage = nMessage;  
2255 - m_csCallbacks.lParam = lParam;  
2256 -  
2257 - return BTNST_OK;  
2258 -} // End of SetMenuCallback  
2259 -  
2260 -// This function resizes the button to the same size of the image.  
2261 -// To get good results both the IN and OUT images should have the same size.  
2262 -//  
2263 -void CButtonST::SizeToContent()  
2264 -{  
2265 - if (m_csIcons[0].hIcon)  
2266 - {  
2267 - m_ptImageOrg.x = 0;  
2268 - m_ptImageOrg.y = 0;  
2269 - SetWindowPos( NULL, -1, -1, m_csIcons[0].dwWidth, m_csIcons[0].dwHeight,  
2270 - SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);  
2271 - } // if  
2272 - else  
2273 - if (m_csBitmaps[0].hBitmap)  
2274 - {  
2275 - m_ptImageOrg.x = 0;  
2276 - m_ptImageOrg.y = 0;  
2277 - SetWindowPos( NULL, -1, -1, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight,  
2278 - SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);  
2279 - } // if  
2280 -} // End of SizeToContent  
2281 -  
2282 -// This function sets the sound that must be played on particular button states.  
2283 -//  
2284 -// Parameters:  
2285 -// [IN] lpszSound  
2286 -// A string that specifies the sound to play.  
2287 -// If hMod is NULL this string is interpreted as a filename, else it  
2288 -// is interpreted as a resource identifier.  
2289 -// Pass NULL to remove any previously specified sound.  
2290 -// [IN] hMod  
2291 -// Handle to the executable file that contains the resource to be loaded.  
2292 -// This parameter must be NULL unless lpszSound specifies a resource identifier.  
2293 -// [IN] bPlayOnClick  
2294 -// TRUE if the sound must be played when the button is clicked.  
2295 -// FALSE if the sound must be played when the mouse is moved over the button.  
2296 -// [IN] bPlayAsync  
2297 -// TRUE if the sound must be played asynchronously.  
2298 -// FALSE if the sound must be played synchronously. The application takes control  
2299 -// when the sound is completely played.  
2300 -//  
2301 -// Return value:  
2302 -// BTNST_OK  
2303 -// Function executed successfully.  
2304 -//  
2305 -#ifdef BTNST_USE_SOUND  
2306 -DWORD CButtonST::SetSound(LPCTSTR lpszSound, HMODULE hMod, BOOL bPlayOnClick, BOOL bPlayAsync)  
2307 -{  
2308 - BYTE byIndex = bPlayOnClick ? 1 : 0;  
2309 -  
2310 - // Store new sound  
2311 - if (lpszSound)  
2312 - {  
2313 - if (hMod) // From resource identifier ?  
2314 - {  
2315 - m_csSounds[byIndex].lpszSound = lpszSound;  
2316 - } // if  
2317 - else  
2318 - {  
2319 - _tcscpy(m_csSounds[byIndex].szSound, lpszSound);  
2320 - m_csSounds[byIndex].lpszSound = m_csSounds[byIndex].szSound;  
2321 - } // else  
2322 -  
2323 - m_csSounds[byIndex].hMod = hMod;  
2324 - m_csSounds[byIndex].dwFlags = SND_NODEFAULT | SND_NOWAIT;  
2325 - m_csSounds[byIndex].dwFlags |= hMod ? SND_RESOURCE : SND_FILENAME;  
2326 - m_csSounds[byIndex].dwFlags |= bPlayAsync ? SND_ASYNC : SND_SYNC;  
2327 - } // if  
2328 - else  
2329 - {  
2330 - // Or remove any existing  
2331 - ::ZeroMemory(&m_csSounds[byIndex], sizeof(STRUCT_SOUND));  
2332 - } // else  
2333 -  
2334 - return BTNST_OK;  
2335 -} // End of SetSound  
2336 -#endif  
2337 -  
2338 -// This function is called every time the button background needs to be painted.  
2339 -// If the button is in transparent mode this function will NOT be called.  
2340 -// This is a virtual function that can be rewritten in CButtonST-derived classes  
2341 -// to produce a whole range of buttons not available by default.  
2342 -//  
2343 -// Parameters:  
2344 -// [IN] pDC  
2345 -// Pointer to a CDC object that indicates the device context.  
2346 -// [IN] pRect  
2347 -// Pointer to a CRect object that indicates the bounds of the  
2348 -// area to be painted.  
2349 -//  
2350 -// Return value:  
2351 -// BTNST_OK  
2352 -// Function executed successfully.  
2353 -//  
2354 -DWORD CButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)  
2355 -{  
2356 - COLORREF crColor;  
2357 -  
2358 - if (m_bIsFlat == FALSE)  
2359 - {  
2360 - if (m_bIsFocused || m_bIsDefault)  
2361 - {  
2362 - CBrush br(RGB(0,0,0));  
2363 - pDC->FrameRect(pRect, &br);  
2364 - pRect->DeflateRect(1, 1);  
2365 - } // if  
2366 - } // if  
2367 -  
2368 - if (m_bMouseOnButton || m_bIsPressed)  
2369 - crColor = m_crColors[BTNST_COLOR_BK_IN];  
2370 - else  
2371 - {  
2372 - if (m_bIsFocused)  
2373 - crColor = m_crColors[BTNST_COLOR_BK_FOCUS];  
2374 - else  
2375 - crColor = m_crColors[BTNST_COLOR_BK_OUT];  
2376 - } // else  
2377 -  
2378 - CBrush brBackground(crColor);  
2379 -  
2380 - pDC->FillRect(pRect, &brBackground);  
2381 -  
2382 - return BTNST_OK;  
2383 -} // End of OnDrawBackground  
2384 -  
2385 -// This function is called every time the button border needs to be painted.  
2386 -// This is a virtual function that can be rewritten in CButtonST-derived classes  
2387 -// to produce a whole range of buttons not available by default.  
2388 -//  
2389 -// Parameters:  
2390 -// [IN] pDC  
2391 -// Pointer to a CDC object that indicates the device context.  
2392 -// [IN] pRect  
2393 -// Pointer to a CRect object that indicates the bounds of the  
2394 -// area to be painted.  
2395 -//  
2396 -// Return value:  
2397 -// BTNST_OK  
2398 -// Function executed successfully.  
2399 -//  
2400 -DWORD CButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)  
2401 -{  
2402 - // Draw pressed button  
2403 - if (m_bIsPressed)  
2404 - {  
2405 - if (m_bIsFlat)  
2406 - {  
2407 - if (m_bDrawBorder)  
2408 - pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));  
2409 - }  
2410 - else  
2411 - {  
2412 - CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));  
2413 - pDC->FrameRect(pRect, &brBtnShadow);  
2414 - }  
2415 - }  
2416 - else // ...else draw non pressed button  
2417 - {  
2418 - CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White  
2419 - CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT)); // Light gray  
2420 - CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); // Dark gray  
2421 - CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black  
2422 -  
2423 - if (m_bIsFlat)  
2424 - {  
2425 - if (m_bMouseOnButton && m_bDrawBorder)  
2426 - pDC->Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));  
2427 - }  
2428 - else  
2429 - {  
2430 - // Draw top-left borders  
2431 - // White line  
2432 - CPen* pOldPen = pDC->SelectObject(&penBtnHiLight);  
2433 - pDC->MoveTo(pRect->left, pRect->bottom-1);  
2434 - pDC->LineTo(pRect->left, pRect->top);  
2435 - pDC->LineTo(pRect->right, pRect->top);  
2436 - // Light gray line  
2437 - pDC->SelectObject(pen3DLight);  
2438 - pDC->MoveTo(pRect->left+1, pRect->bottom-1);  
2439 - pDC->LineTo(pRect->left+1, pRect->top+1);  
2440 - pDC->LineTo(pRect->right, pRect->top+1);  
2441 - // Draw bottom-right borders  
2442 - // Black line  
2443 - pDC->SelectObject(pen3DDKShadow);  
2444 - pDC->MoveTo(pRect->left, pRect->bottom-1);  
2445 - pDC->LineTo(pRect->right-1, pRect->bottom-1);  
2446 - pDC->LineTo(pRect->right-1, pRect->top-1);  
2447 - // Dark gray line  
2448 - pDC->SelectObject(penBtnShadow);  
2449 - pDC->MoveTo(pRect->left+1, pRect->bottom-2);  
2450 - pDC->LineTo(pRect->right-2, pRect->bottom-2);  
2451 - pDC->LineTo(pRect->right-2, pRect->top);  
2452 - //  
2453 - pDC->SelectObject(pOldPen);  
2454 - } // else  
2455 - } // else  
2456 -  
2457 - return BTNST_OK;  
2458 -} // End of OnDrawBorder  
2459 -  
2460 -#undef BS_TYPEMASK  
1 -//  
2 -// Class: CButtonST  
3 -//  
4 -// Compiler: Visual C++  
5 -// Tested on: Visual C++ 5.0  
6 -// Visual C++ 6.0  
7 -//  
8 -// Version: See GetVersionC() or GetVersionI()  
9 -//  
10 -// Created: xx/xxxx/1998  
11 -// Updated: 03/March/2003  
12 -//  
13 -// Author: Davide Calabro' davide_calabro@yahoo.com  
14 -// http://www.softechsoftware.it  
15 -//  
16 -// Note: Code for the PreSubclassWindow and OnSetStyle functions  
17 -// has been taken from the COddButton class  
18 -// published by Paolo Messina and Jerzy Kaczorowski  
19 -//  
20 -// Disclaimer  
21 -// ----------  
22 -// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT  
23 -// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE  
24 -// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE  
25 -// RISK OF USING THIS SOFTWARE.  
26 -//  
27 -// Terms of use  
28 -// ------------  
29 -// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.  
30 -// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU  
31 -// ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:  
32 -//  
33 -// Davide Calabro'  
34 -// P.O. Box 65  
35 -// 21019 Somma Lombardo (VA)  
36 -// Italy  
37 -//  
38 -#ifndef _BTNST_H  
39 -#define _BTNST_H  
40 -  
41 -// Uncomment the following 2 lines to enable support for BCMenu class  
42 -#undef BTNST_USE_BCMENU  
43 -#ifdef BTNST_USE_BCMENU  
44 -#include "BCMenu.h"  
45 -#endif  
46 -  
47 -  
48 -  
49 -// Uncomment the following line to enable support for sound effects  
50 -#define BTNST_USE_SOUND  
51 -  
52 -#if _MSC_VER >= 1000  
53 -#pragma once  
54 -#endif // _MSC_VER >= 1000  
55 -  
56 -// Return values  
57 -#ifndef BTNST_OK  
58 -#define BTNST_OK 0  
59 -#endif  
60 -#ifndef BTNST_INVALIDRESOURCE  
61 -#define BTNST_INVALIDRESOURCE 1  
62 -#endif  
63 -#ifndef BTNST_FAILEDMASK  
64 -#define BTNST_FAILEDMASK 2  
65 -#endif  
66 -#ifndef BTNST_INVALIDINDEX  
67 -#define BTNST_INVALIDINDEX 3  
68 -#endif  
69 -#ifndef BTNST_INVALIDALIGN  
70 -#define BTNST_INVALIDALIGN 4  
71 -#endif  
72 -#ifndef BTNST_BADPARAM  
73 -#define BTNST_BADPARAM 5  
74 -#endif  
75 -#ifndef BTNST_INVALIDPRESSEDSTYLE  
76 -#define BTNST_INVALIDPRESSEDSTYLE 6  
77 -#endif  
78 -  
79 -// Dummy identifier for grayscale icon  
80 -#ifndef BTNST_AUTO_GRAY  
81 -#define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L)  
82 -#endif  
83 -// Dummy identifier for 15% darker icon  
84 -#ifndef BTNST_AUTO_DARKER  
85 -#define BTNST_AUTO_DARKER (HICON)(0xffffffff - 2L)  
86 -#endif  
87 -  
88 -class CButtonST : public CButton  
89 -{  
90 -public:  
91 - CButtonST();  
92 - ~CButtonST();  
93 -  
94 - enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right  
95 - ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom  
96 - ST_ALIGN_HORIZ_RIGHT, // Icon/bitmap on the right, text on the left  
97 - ST_ALIGN_OVERLAP // Icon/bitmap on the same space as text  
98 - };  
99 -  
100 - enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside  
101 - BTNST_COLOR_FG_IN, // Text color when mouse is INside  
102 - BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside  
103 - BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside  
104 - BTNST_COLOR_BK_FOCUS, // Background color when the button is focused  
105 - BTNST_COLOR_FG_FOCUS, // Text color when the button is focused  
106 -  
107 - BTNST_MAX_COLORS  
108 - };  
109 -  
110 - enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual)  
111 - BTNST_PRESSED_TOPBOTTOM // Pressed style from top to bottom  
112 - };  
113 -  
114 - // ClassWizard generated virtual function overrides  
115 - //{{AFX_VIRTUAL(CButtonST)  
116 - public:  
117 - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);  
118 - virtual BOOL PreTranslateMessage(MSG* pMsg);  
119 - protected:  
120 - virtual void PreSubclassWindow();  
121 - //}}AFX_VIRTUAL  
122 -  
123 -public:  
124 - DWORD SetDefaultColors(BOOL bRepaint = TRUE);  
125 - DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE);  
126 - DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor);  
127 - DWORD OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint = TRUE);  
128 -  
129 - DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE);  
130 - int GetCheck();  
131 -  
132 - DWORD SetURL(LPCTSTR lpszURL = NULL);  
133 - void DrawTransparent(BOOL bRepaint = FALSE);  
134 - DWORD SetBk(CDC* pDC);  
135 -  
136 - BOOL GetDefault();  
137 - DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE);  
138 -  
139 - void SetTooltipText(int nText, BOOL bActivate = TRUE);  
140 - void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);  
141 - void ActivateTooltip(BOOL bEnable = TRUE);  
142 - DWORD EnableBalloonTooltip();  
143 -  
144 - DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE);  
145 -  
146 - DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE);  
147 - DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE);  
148 - DWORD SetPressedStyle(BYTE byStyle, BOOL bRepaint = TRUE);  
149 -  
150 - DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE);  
151 - DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE);  
152 -  
153 - DWORD SetIcon(int nIconIn, int nCxDesiredIn, int nCyDesiredIn, int nIconOut = NULL, int nCxDesiredOut = 0, int nCyDesiredOut = 0);  
154 - DWORD SetIcon(int nIconIn, int nIconOut = NULL);  
155 - DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL);  
156 -  
157 - DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut = NULL, COLORREF crTransColorOut = 0);  
158 - DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0);  
159 -  
160 - void SizeToContent();  
161 -  
162 -#ifdef BTNST_USE_BCMENU  
163 - DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle = TRUE, UINT nToolbarID = NULL, CSize sizeToolbarIcon = CSize(16, 16), COLORREF crToolbarBk = RGB(255, 0, 255), BOOL bRepaint = TRUE);  
164 -#else  
165 - DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE);  
166 -#endif  
167 - DWORD SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam = 0);  
168 -  
169 -#ifdef BTNST_USE_SOUND  
170 - DWORD SetSound(LPCTSTR lpszSound, HMODULE hMod = NULL, BOOL bPlayOnClick = FALSE, BOOL bPlayAsync = TRUE);  
171 -#endif  
172 -  
173 - static short GetVersionI() {return 39;}  
174 - static LPCTSTR GetVersionC() {return (LPCTSTR)_T("3.9");}  
175 -  
176 - BOOL m_bShowDisabledBitmap;  
177 - POINT m_ptImageOrg;  
178 - POINT m_ptPressedOffset;  
179 -  
180 -protected:  
181 - //{{AFX_MSG(CButtonST)  
182 - afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);  
183 - afx_msg void OnKillFocus(CWnd* pNewWnd);  
184 - afx_msg void OnMouseMove(UINT nFlags, CPoint point);  
185 - afx_msg void OnSysColorChange();  
186 - afx_msg BOOL OnClicked();  
187 - afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);  
188 - afx_msg void OnEnable(BOOL bEnable);  
189 - afx_msg void OnCancelMode();  
190 - afx_msg UINT OnGetDlgCode();  
191 - //}}AFX_MSG  
192 -  
193 -#ifdef BTNST_USE_BCMENU  
194 - afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);  
195 - afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);  
196 -#endif  
197 -  
198 - afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);  
199 - HICON CreateGrayscaleIcon(HICON hIcon);  
200 - HICON CreateDarkerIcon(HICON hIcon);  
201 - HBITMAP CreateGrayscaleBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans);  
202 - HBITMAP CreateDarkerBitmap(HBITMAP hBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTrans);  
203 - COLORREF DarkenColor(COLORREF crColor, double dFactor);  
204 - virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect);  
205 - virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect);  
206 -  
207 - BOOL m_bIsFlat; // Is a flat button?  
208 - BOOL m_bMouseOnButton; // Is mouse over the button?  
209 - BOOL m_bDrawTransparent; // Draw transparent?  
210 - BOOL m_bIsPressed; // Is button pressed?  
211 - BOOL m_bIsFocused; // Is button focused?  
212 - BOOL m_bIsDisabled; // Is button disabled?  
213 - BOOL m_bIsDefault; // Is default button?  
214 - BOOL m_bIsCheckBox; // Is the button a checkbox?  
215 - BYTE m_byAlign; // Align mode  
216 - BOOL m_bDrawBorder; // Draw border?  
217 - BOOL m_bDrawFlatFocus; // Draw focus rectangle for flat button?  
218 - COLORREF m_crColors[BTNST_MAX_COLORS]; // Colors to be used  
219 - HWND m_hParentWndMenu; // Handle to window for menu selection  
220 - BOOL m_bMenuDisplayed; // Is menu displayed ?  
221 -  
222 -#ifdef BTNST_USE_BCMENU  
223 - BCMenu m_menuPopup; // BCMenu class instance  
224 -#else  
225 - HMENU m_hMenu; // Handle to associated menu  
226 -#endif  
227 -  
228 -private:  
229 - LRESULT OnSetCheck(WPARAM wParam, LPARAM lParam);  
230 - LRESULT OnGetCheck(WPARAM wParam, LPARAM lParam);  
231 - LRESULT OnSetStyle(WPARAM wParam, LPARAM lParam);  
232 - LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);  
233 -  
234 - void CancelHover();  
235 - void FreeResources(BOOL bCheckForNULL = TRUE);  
236 - void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);  
237 - HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);  
238 - virtual void DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);  
239 - virtual void DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);  
240 - virtual void DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);  
241 - void PaintBk(CDC* pDC);  
242 -  
243 - void InitToolTip();  
244 -  
245 - HCURSOR m_hCursor; // Handle to cursor  
246 - CToolTipCtrl m_ToolTip; // Tooltip  
247 -  
248 - CDC m_dcBk;  
249 - CBitmap m_bmpBk;  
250 - CBitmap* m_pbmpOldBk;  
251 -  
252 - BOOL m_bAlwaysTrack; // Always hilight button?  
253 - int m_nCheck; // Current value for checkbox  
254 - UINT m_nTypeStyle; // Button style  
255 - DWORD m_dwToolTipStyle; // Style of tooltip control  
256 -  
257 - TCHAR m_szURL[_MAX_PATH]; // URL to open when clicked  
258 -  
259 -#pragma pack(1)  
260 - typedef struct _STRUCT_ICONS  
261 - {  
262 - HICON hIcon; // Handle to icon  
263 - DWORD dwWidth; // Width of icon  
264 - DWORD dwHeight; // Height of icon  
265 - } STRUCT_ICONS;  
266 -#pragma pack()  
267 -  
268 -#pragma pack(1)  
269 - typedef struct _STRUCT_BITMAPS  
270 - {  
271 - HBITMAP hBitmap; // Handle to bitmap  
272 - DWORD dwWidth; // Width of bitmap  
273 - DWORD dwHeight; // Height of bitmap  
274 - HBITMAP hMask; // Handle to mask bitmap  
275 - COLORREF crTransparent; // Transparent color  
276 - } STRUCT_BITMAPS;  
277 -#pragma pack()  
278 -  
279 -#pragma pack(1)  
280 - typedef struct _STRUCT_CALLBACK  
281 - {  
282 - HWND hWnd; // Handle to window  
283 - UINT nMessage; // Message identifier  
284 - WPARAM wParam;  
285 - LPARAM lParam;  
286 - } STRUCT_CALLBACK;  
287 -#pragma pack()  
288 -  
289 - STRUCT_ICONS m_csIcons[2];  
290 - STRUCT_BITMAPS m_csBitmaps[2];  
291 -  
292 - STRUCT_CALLBACK m_csCallbacks;  
293 -  
294 -#ifdef BTNST_USE_SOUND  
295 -#pragma pack(1)  
296 - typedef struct _STRUCT_SOUND  
297 - {  
298 - TCHAR szSound[_MAX_PATH];  
299 - LPCTSTR lpszSound;  
300 - HMODULE hMod;  
301 - DWORD dwFlags;  
302 - } STRUCT_SOUND;  
303 -#pragma pack()  
304 -  
305 - STRUCT_SOUND m_csSounds[2]; // Index 0 = Over 1 = Clicked  
306 -#endif  
307 -  
308 - DECLARE_MESSAGE_MAP()  
309 -};  
310 -  
311 -//{{AFX_INSERT_LOCATION}}  
312 -// Microsoft Developer Studio will insert additional declarations immediately before the previous line.  
313 -  
314 -#endif  
1 -#include "stdafx.h"  
2 -#include "CeXDib.h"  
3 -  
4 -#ifdef _DEBUG  
5 -#undef THIS_FILE  
6 -static char THIS_FILE[]=__FILE__;  
7 -#define new DEBUG_NEW  
8 -#endif  
9 -  
10 -CCeXDib::CCeXDib()  
11 -{  
12 - m_hDib = NULL;  
13 - m_dwLineWidth = 0;  
14 - m_wColors = 0;  
15 -  
16 - m_hMemDC = NULL;  
17 - m_hBitmap = NULL;  
18 - m_lpBits = NULL;  
19 -  
20 - FreeResources();  
21 -}  
22 -  
23 -CCeXDib::~CCeXDib()  
24 -{  
25 -  
26 - FreeResources();  
27 -}  
28 -  
29 -void CCeXDib::FreeResources()  
30 -{  
31 - if (m_hMemDC) ::DeleteDC(m_hMemDC);  
32 - if (m_hBitmap) ::DeleteObject(m_hBitmap);  
33 - if (m_hDib) delete m_hDib;  
34 -  
35 - m_hDib = NULL;  
36 - m_hMemDC = NULL;  
37 - m_hBitmap = NULL;  
38 - m_lpBits = NULL;  
39 - memset(&m_bi, 0, sizeof(m_bi));  
40 -} // End of FreeResources  
41 -  
42 -HDIB CCeXDib::Create(DWORD dwWidth, DWORD dwHeight, WORD wBitCount)  
43 -{  
44 - LPBITMAPINFOHEADER lpbi = NULL; // Pointer to BITMAPINFOHEADER  
45 - DWORD dwLen = 0; // Size of memory block  
46 -  
47 - FreeResources();  
48 -  
49 - // Following <switch> is taken from  
50 - // CDIBSectionLite class by Chris Maunder  
51 - switch (wBitCount)  
52 - {  
53 - case 1: m_wColors = 2; break;  
54 -#ifdef _WIN32_WCE  
55 - case 2: m_wColors = 4; break; // winCE only  
56 -#endif  
57 - case 4: m_wColors = 16; break;  
58 - case 8: m_wColors = 256; break;  
59 - case 16:  
60 - case 24:  
61 - case 32: m_wColors = 0; break; // 16,24 or 32 bpp have no color table  
62 -  
63 - default:  
64 - m_wColors = 0;  
65 - } // switch  
66 -/*  
67 - // Make sure bits per pixel is valid  
68 - if (wBitCount <= 1) wBitCount = 1;  
69 - else if (wBitCount <= 4) wBitCount = 4;  
70 - else if (wBitCount <= 8) wBitCount = 8;  
71 - else wBitCount = 24;  
72 -  
73 - switch (wBitCount)  
74 - {  
75 - case 1:  
76 - m_wColors = 2;  
77 - break;  
78 - case 4:  
79 - m_wColors = 16;  
80 - break;  
81 - case 8:  
82 - m_wColors = 256;  
83 - break;  
84 - default:  
85 - m_wColors = 0;  
86 - break;  
87 - } // switch  
88 -*/  
89 - m_dwLineWidth = WIDTHBYTES(wBitCount * dwWidth);  
90 -  
91 - // Initialize BITMAPINFOHEADER  
92 - m_bi.biSize = sizeof(BITMAPINFOHEADER);  
93 - m_bi.biWidth = dwWidth; // fill in width from parameter  
94 - m_bi.biHeight = dwHeight; // fill in height from parameter  
95 - m_bi.biPlanes = 1; // must be 1  
96 - m_bi.biBitCount = wBitCount; // from parameter  
97 - m_bi.biCompression = BI_RGB;  
98 - m_bi.biSizeImage = m_dwLineWidth * dwHeight;  
99 - m_bi.biXPelsPerMeter = 0;  
100 - m_bi.biYPelsPerMeter = 0;  
101 - m_bi.biClrUsed = 0;  
102 - m_bi.biClrImportant = 0;  
103 -  
104 - // Calculate size of memory block required to store the DIB. This  
105 - // block should be big enough to hold the BITMAPINFOHEADER, the color  
106 - // table, and the bits.  
107 - dwLen = GetSize();  
108 -  
109 - m_hDib = new HDIB[dwLen]; // Allocate memory block to store our bitmap  
110 - if (m_hDib == NULL) return NULL;  
111 -  
112 - // Use our bitmap info structure to fill in first part of  
113 - // our DIB with the BITMAPINFOHEADER  
114 - lpbi = (LPBITMAPINFOHEADER)(m_hDib);  
115 - *lpbi = m_bi;  
116 -  
117 - return m_hDib; // Return handle to the DIB  
118 -} // End of Create  
119 -  
120 -DWORD CCeXDib::GetSize()  
121 -{  
122 - return m_bi.biSize + m_bi.biSizeImage + GetPaletteSize();  
123 -} // End of GetSize  
124 -  
125 -DWORD CCeXDib::GetPaletteSize()  
126 -{  
127 - return (m_wColors * sizeof(RGBQUAD));  
128 -} // End of GetPaletteSize  
129 -  
130 -LPBYTE CCeXDib::GetBits()  
131 -{  
132 - if (m_hDib) return ((LPBYTE)m_hDib + *(LPDWORD)m_hDib + GetPaletteSize());  
133 -  
134 - return NULL;  
135 -} // End of GetBits  
136 -  
137 -DWORD CCeXDib::GetWidth()  
138 -{  
139 - return m_bi.biWidth;  
140 -} // End of GetWidth  
141 -  
142 -DWORD CCeXDib::GetHeight()  
143 -{  
144 - return m_bi.biHeight;  
145 -} // End of GetHeight  
146 -  
147 -DWORD CCeXDib::GetLineWidth()  
148 -{  
149 - return m_dwLineWidth;  
150 -} // End of GetLineWidth  
151 -  
152 -void CCeXDib::BlendPalette(COLORREF crColor, DWORD dwPerc)  
153 -{  
154 - if (m_hDib == NULL || m_wColors == 0) return;  
155 -  
156 - LPBYTE iDst = (LPBYTE)(m_hDib) + sizeof(BITMAPINFOHEADER);  
157 -  
158 - long i,r,g,b;  
159 -  
160 - RGBQUAD* pPal = (RGBQUAD*)iDst;  
161 -  
162 - r = GetRValue(crColor);  
163 - g = GetGValue(crColor);  
164 - b = GetBValue(crColor);  
165 -  
166 - if (dwPerc > 100) dwPerc = 100;  
167 -  
168 - for (i = 0; i < m_wColors; i++)  
169 - {  
170 - pPal[i].rgbBlue = (BYTE)((pPal[i].rgbBlue * (100 - dwPerc) + b * dwPerc) / 100);  
171 - pPal[i].rgbGreen = (BYTE)((pPal[i].rgbGreen * (100 - dwPerc) + g * dwPerc) / 100);  
172 - pPal[i].rgbRed = (BYTE)((pPal[i].rgbRed * (100 - dwPerc) + r * dwPerc) / 100);  
173 - } // for  
174 -} // End of BlendPalette  
175 -  
176 -void CCeXDib::Clear(BYTE byVal)  
177 -{  
178 - if (m_hDib) memset(GetBits(), byVal, m_bi.biSizeImage);  
179 -} // End of Clear  
180 -  
181 -void CCeXDib::SetPixelIndex(DWORD dwX, DWORD dwY, BYTE byI)  
182 -{  
183 - if ((m_hDib == NULL) || (m_wColors == 0) ||  
184 - ((long)dwX < 0) || ((long)dwY < 0) || (dwX >= (DWORD)m_bi.biWidth) || (dwY >= (DWORD)m_bi.biHeight)) return;  
185 -  
186 - LPBYTE iDst = GetBits();  
187 - iDst[(m_bi.biHeight - dwY - 1) * m_dwLineWidth + dwX] = byI;  
188 -} // End of SetPixelIndex  
189 -  
190 -void CCeXDib::Clone(CCeXDib* src)  
191 -{  
192 - Create(src->GetWidth(), src->GetHeight(), src->GetBitCount());  
193 - if (m_hDib) memcpy(m_hDib, src->m_hDib, GetSize());  
194 -} // End of Clone  
195 -  
196 -WORD CCeXDib::GetBitCount()  
197 -{  
198 - return m_bi.biBitCount;  
199 -} // End of GetBitCount  
200 -  
201 -void CCeXDib::SetPaletteIndex(BYTE byIdx, BYTE byR, BYTE byG, BYTE byB)  
202 -{  
203 - if (m_hDib && m_wColors)  
204 - {  
205 - LPBYTE iDst = (LPBYTE)(m_hDib) + sizeof(BITMAPINFOHEADER);  
206 - if ((byIdx >= 0) && (byIdx < m_wColors))  
207 - {  
208 - long ldx = byIdx * sizeof(RGBQUAD);  
209 - iDst[ldx++] = (BYTE)byB;  
210 - iDst[ldx++] = (BYTE)byG;  
211 - iDst[ldx++] = (BYTE)byR;  
212 - iDst[ldx] = (BYTE)0;  
213 - } // if  
214 - } // if  
215 -} // End of SetPaletteIndex  
216 -  
217 -void CCeXDib::Draw(HDC hDC, DWORD dwX, DWORD dwY)  
218 -{  
219 - HBITMAP hBitmap = NULL;  
220 - HBITMAP hOldBitmap = NULL;  
221 - HDC hMemDC = NULL;  
222 -  
223 - if (m_hBitmap == NULL)  
224 - {  
225 - m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)m_hDib, DIB_RGB_COLORS, &m_lpBits, NULL, 0);  
226 - if (m_hBitmap == NULL) return;  
227 - if (m_lpBits == NULL)  
228 - {  
229 - ::DeleteObject(m_hBitmap);  
230 - m_hBitmap = NULL;  
231 - return;  
232 - } // if  
233 - } // if  
234 -  
235 - memcpy(m_lpBits, GetBits(), m_bi.biSizeImage);  
236 -  
237 - if (m_hMemDC == NULL)  
238 - {  
239 - m_hMemDC = CreateCompatibleDC(hDC);  
240 - if (m_hMemDC == NULL) return;  
241 - } // if  
242 -  
243 - hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap);  
244 -  
245 - BitBlt(hDC, dwX, dwY, m_bi.biWidth, m_bi.biHeight, m_hMemDC, 0, 0, SRCCOPY);  
246 -  
247 - SelectObject(m_hMemDC, hOldBitmap);  
248 -} // End of Draw  
249 -  
250 -void CCeXDib::SetGrayPalette()  
251 -{  
252 - RGBQUAD pal[256];  
253 - RGBQUAD* ppal;  
254 - LPBYTE iDst;  
255 - int ni;  
256 -  
257 - if (m_hDib == NULL || m_wColors == 0) return;  
258 -  
259 - ppal = (RGBQUAD*)&pal[0];  
260 - iDst = (LPBYTE)(m_hDib) + sizeof(BITMAPINFOHEADER);  
261 - for (ni = 0; ni < m_wColors; ni++)  
262 - {  
263 - pal[ni] = RGB2RGBQUAD(RGB(ni,ni,ni));  
264 - } // for  
265 -  
266 - pal[0] = RGB2RGBQUAD(RGB(0,0,0));  
267 - pal[m_wColors-1] = RGB2RGBQUAD(RGB(255,255,255));  
268 -  
269 - memcpy(iDst, ppal, GetPaletteSize());  
270 -} // End of SetGrayPalette  
271 -  
272 -RGBQUAD CCeXDib::RGB2RGBQUAD(COLORREF cr)  
273 -{  
274 - RGBQUAD c;  
275 - c.rgbRed = GetRValue(cr); /* get R, G, and B out of DWORD */  
276 - c.rgbGreen = GetGValue(cr);  
277 - c.rgbBlue = GetBValue(cr);  
278 - c.rgbReserved=0;  
279 - return c;  
280 -} // End of RGB2RGBQUAD  
281 -  
282 -WORD CCeXDib::GetNumColors()  
283 -{  
284 - return m_wColors;  
285 -} // End of GetNumColors  
286 -  
287 -BOOL CCeXDib::WriteBMP(LPCTSTR bmpFileName)  
288 -{  
289 - BITMAPFILEHEADER hdr;  
290 - HANDLE hFile;  
291 - DWORD nByteWrite;  
292 -  
293 - if (*bmpFileName == _T('\0') || m_hDib == 0) return 0;  
294 -  
295 - hFile=CreateFile( // open if exist ini file  
296 - bmpFileName, // pointer to name of the file  
297 - GENERIC_WRITE, // access mode  
298 - 0, // share mode  
299 - NULL, // pointer to security descriptor  
300 - CREATE_ALWAYS, // how to create  
301 - FILE_ATTRIBUTE_NORMAL, // file attributes  
302 - NULL // handle to file with attributes to copy  
303 - );  
304 - if (hFile == INVALID_HANDLE_VALUE) return FALSE;  
305 -  
306 - // Fill in the fields of the file header  
307 - hdr.bfType = BFT_BITMAP;  
308 - hdr.bfSize = GetSize() + sizeof(BITMAPFILEHEADER);  
309 - hdr.bfReserved1 = hdr.bfReserved2 = 0;  
310 - hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER)+  
311 - m_bi.biSize + GetPaletteSize();  
312 -  
313 - // Write the file header  
314 - WriteFile( // write ini (sync mode <-> no overlapped)  
315 - hFile, // handle of file to write  
316 - (LPSTR) &hdr, // address of buffer that contains data  
317 - sizeof(BITMAPFILEHEADER), // number of bytes to write  
318 - &nByteWrite, // address of number of bytes written  
319 - NULL // address of structure for data  
320 - );  
321 -  
322 - // Write the DIB header and the bits  
323 - WriteFile( // write ini (sync mode <-> no overlapped)  
324 - hFile, // handle of file to write  
325 - (LPSTR) m_hDib, // address of buffer that contains data  
326 - GetSize(), // number of bytes to write  
327 - &nByteWrite, // address of number of bytes written  
328 - NULL // address of structure for data  
329 - );  
330 -  
331 - CloseHandle(hFile); // free file handle  
332 -  
333 - return TRUE;  
334 -} // End of WriteBMP  
1 -//  
2 -// Class: CCeXDib  
3 -//  
4 -// Compiler: Visual C++  
5 -// eMbedded Visual C++  
6 -// Tested on: Visual C++ 6.0  
7 -// Windows CE 3.0  
8 -//  
9 -// Author: Davide Calabro' davide_calabro@yahoo.com  
10 -// http://www.softechsoftware.it  
11 -//  
12 -// Note: This class uses code snippets taken from a similar class written  
13 -// for the Win32 enviroment by Davide Pizzolato (ing.davide.pizzolato@libero.it)  
14 -//  
15 -// Disclaimer  
16 -// ----------  
17 -// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT  
18 -// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE  
19 -// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE  
20 -// RISK OF USING THIS SOFTWARE.  
21 -//  
22 -// Terms of use  
23 -// ------------  
24 -// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.  
25 -// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU  
26 -// ARE GENTLY ASKED TO DONATE 1$ (ONE U.S. DOLLAR) TO THE AUTHOR:  
27 -//  
28 -// Davide Calabro'  
29 -// P.O. Box 65  
30 -// 21019 Somma Lombardo (VA)  
31 -// Italy  
32 -//  
33 -//  
34 -#ifndef _CEXDIB_H_  
35 -#define _CEXDIB_H_  
36 -  
37 -#if _MSC_VER > 1000  
38 -#pragma once  
39 -#endif // _MSC_VER > 1000  
40 -  
41 -#ifndef HDIB  
42 -#define HDIB HANDLE  
43 -#endif  
44 -  
45 -#ifndef WIDTHBYTES  
46 -#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)  
47 -#endif  
48 -  
49 -#ifndef BFT_BITMAP  
50 -#define BFT_BITMAP 0x4d42 // 'BM'  
51 -#endif  
52 -  
53 -class CCeXDib  
54 -{  
55 -public:  
56 - CCeXDib();  
57 - virtual ~CCeXDib();  
58 -  
59 - HDIB Create(DWORD dwWidth, DWORD dwHeight, WORD wBitCount);  
60 - void Clone(CCeXDib* src);  
61 - void Draw(HDC hDC, DWORD dwX, DWORD dwY);  
62 - LPBYTE GetBits();  
63 - void Clear(BYTE byVal = 0);  
64 -  
65 - void SetGrayPalette();  
66 - void SetPaletteIndex(BYTE byIdx, BYTE byR, BYTE byG, BYTE byB);  
67 - void SetPixelIndex(DWORD dwX, DWORD dwY, BYTE byI);  
68 - void BlendPalette(COLORREF crColor, DWORD dwPerc);  
69 -  
70 - WORD GetBitCount();  
71 - DWORD GetLineWidth();  
72 - DWORD GetWidth();  
73 - DWORD GetHeight();  
74 - WORD GetNumColors();  
75 -  
76 - BOOL WriteBMP(LPCTSTR bmpFileName);  
77 -  
78 -private:  
79 - void FreeResources();  
80 -  
81 - DWORD GetPaletteSize();  
82 - DWORD GetSize();  
83 -  
84 - RGBQUAD RGB2RGBQUAD(COLORREF cr);  
85 -  
86 - HDIB m_hDib;  
87 - BITMAPINFOHEADER m_bi;  
88 - DWORD m_dwLineWidth;  
89 - WORD m_wColors;  
90 -  
91 - HBITMAP m_hBitmap; // Handle to bitmap  
92 - HDC m_hMemDC; // Handle to memory DC  
93 - LPVOID m_lpBits; // Pointer to actual bitmap bits  
94 -};  
95 -  
96 -#endif  
Please register or login to post a comment