/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2002 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #include "ImgPF.h" #define ISGRAY16(pBitmap) (((pBitmap)->Order == ORDER_GRAY) && ((pBitmap)->BitsPerPixel == 16)) #define TYPE8 0x1 #define TYPE16 0x2 static L_BOOL AddMesgDialog_OnCommand (HWND hWnd, L_INT id, HWND hWndCtl, L_UINT codeNotify); static L_BOOL AddMesgDialog_OnClose (HWND hWnd); static L_BOOL AddMesgDialog_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam); #ifdef UNICODE extern HFONT ghDlgFont; #endif// UNICODE L_BOOL CALLBACK AddMesgDlgProc(HWND hWnd, L_UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { HANDLE_MSG (hWnd, WM_COMMAND, AddMesgDialog_OnCommand); HANDLE_MSG (hWnd, WM_INITDIALOG, AddMesgDialog_OnInitDialog); HANDLE_MSG (hWnd, WM_CLOSE, AddMesgDialog_OnClose); } return FALSE; } static L_BOOL AddMesgDialog_OnInitDialog (HWND hWnd, HWND hWndFocus, LPARAM lParam) { LPADDMESGDLGDATA pAddMesgData; pCHILDDATA pData; L_INT nByteLeft; L_INT nByteAdd; L_INT nRet; HWND hWndParent; HWND hWndCtrl; L_TCHAR szBuffer[20]; pAddMesgData = (LPADDMESGDLGDATA)lParam; hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); if (!pData) { MessageBox(hWnd, TEXT("Error"), NULL, MB_OK); return TRUE; } MoveDialogToMiddle(hWnd); nRet = L_IsGrayScaleBitmap(&pData->LeadBitmap); pAddMesgData->nType = (ISGRAY16(&pData->LeadBitmap) || pData->LeadBitmap.BitsPerPixel == 48) ? TYPE16: ( (pData->LeadBitmap.BitsPerPixel == 24) || (pData->LeadBitmap.BitsPerPixel == 8 && nRet != GRAY_NO && nRet != GRAY_NOTORDERED)) ? TYPE8 : 0; if(pAddMesgData->nType == 0) { MessageBox(hWnd, TEXT("Image format recognized, but this type not supported by this function"), TEXT("Error"), MB_OK | MB_ICONINFORMATION); EndDialog(hWnd, 0); return TRUE; } SetWindowLong(hWnd,GWL_USERDATA,(LONG)pAddMesgData); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_POS_CHK); Button_SetCheck(hWndCtrl, BST_CHECKED); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_CHK); Button_SetCheck(hWndCtrl, BST_CHECKED); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_TXT_RAD); Button_SetCheck(hWndCtrl, BST_CHECKED); SetDlgItemInt(hWnd, IDC_ADMSG_XPOS_EDT, 0, FALSE); SetDlgItemInt(hWnd, IDC_ADMSG_YPOS_EDT, 0, FALSE); ShowWindow(GetDlgItem(hWnd, IDC_ADMSG_BTFRM_TXT), SW_SHOW); ShowWindow(GetDlgItem(hWnd, IDC_ADMSG_BYTE_EDT ), SW_SHOW); ShowWindow(GetDlgItem(hWnd, IDC_ADMSG_BYTE_TXT) , SW_SHOW); wsprintf(szBuffer, TEXT("%d X %d"), BITMAPWIDTH(&pData->LeadBitmap), BITMAPHEIGHT(&pData->LeadBitmap)); SetWindowText(GetDlgItem(hWnd, IDC_ADMSG_IMGSZ_TXT), szBuffer); nByteLeft = (pData->LeadBitmap.BytesPerLine * BITMAPHEIGHT(&pData->LeadBitmap)); nByteAdd = (nByteLeft * pAddMesgData->nType * 9 / 8 / 16) - 9; SetDlgItemInt(hWnd, IDC_ADMSG_BYTE_EDT, nByteAdd, TRUE); pData->uTimerID = SetTimer(hWnd, 1, 100, NULL); UNLOCKCHILDDATA(hWndParent); Edit_SetText(GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT), TEXT("LEAD Technologies, Inc.")); Edit_SetSel(GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT), 0, Edit_GetTextLength(GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT))); #ifdef UNICODE SetControlFont ( hWnd, ghDlgFont) ; #endif// UNICODE return TRUE; } static L_BOOL AddMesgDialog_OnClose (HWND hWnd) { EndDialog(hWnd, 0); return TRUE; } static L_BOOL AddMesgDialog_OnCommand (HWND hWnd, L_INT id, HWND hWndCtl, L_UINT codeNotify) { LPADDMESGDLGDATA pAddMesgData; pCHILDDATA pData; L_UCHAR uConfirmPass[50]; static TCHAR pstrFileName[MAX_PATH]; static TCHAR pstrTitleName[MAX_PATH]; POINT ptStart; L_INT nByteLeft; L_INT nByteAdd; L_INT nByte; L_INT nFlag1; L_INT nFlag2; HWND hWndCtrl; HWND hWndParent; L_BOOL bEnable; pAddMesgData = (LPADDMESGDLGDATA) GetWindowLong(hWnd,GWL_USERDATA); hWndParent = FORWARD_WM_MDIGETACTIVE(hWndClient, SendMessage); pData = LOCKCHILDDATA (hWndParent); if (!pData) { MessageBox(hWnd, TEXT("Error"), NULL, MB_OK); return TRUE; } switch(id) { case IDCANCEL: EndDialog(hWnd, 0); return FALSE; case IDC_ADMSG_TXT_RAD: case IDC_ADMSG_FILE_RAD: hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FILE_RAD); bEnable = Button_GetCheck(hWndCtrl); nFlag1 = (bEnable) ? SW_HIDE : SW_SHOW; nFlag2 = (bEnable) ? SW_SHOW : SW_HIDE; hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_BROWS_BTN); ShowWindow(hWndCtrl, nFlag2); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FNAME_EDT); ShowWindow(hWndCtrl, nFlag2); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT); ShowWindow(hWndCtrl, nFlag1); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_POS_CHK); break; case IDC_ADMSG_BROWS_BTN: { L_TCHAR pstrFileName[L_MAXPATH]; memset(pstrFileName, 0, sizeof(pstrFileName)); if(FileOpenDlg(hWnd, pstrFileName) == SUCCESS) { hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FNAME_EDT); Edit_SetText(hWndCtrl, pstrFileName); } } break; case IDC_ADMSG_XPOS_EDT: case IDC_ADMSG_YPOS_EDT: case IDC_ADMSG_MSG_EDT: case IDC_ADMSG_PSW_EDT: switch(codeNotify) { case EN_CHANGE: hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FILE_RAD); if(Button_GetCheck(hWndCtrl)) break; hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_POS_CHK); { ptStart.x = GetDlgItemInt(hWnd, IDC_ADMSG_XPOS_EDT,NULL, TRUE); ptStart.y = GetDlgItemInt(hWnd, IDC_ADMSG_YPOS_EDT,NULL, TRUE); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT); nByte = Edit_GetTextLength(hWndCtrl) + 8; hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_CHK); if(!Button_GetCheck(hWndCtrl)) { hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_EDT); nByte += Edit_GetTextLength(hWndCtrl); } nByteLeft = (pData->LeadBitmap.Width * (BITMAPHEIGHT(&pData->LeadBitmap) - ptStart.y - 1) + pData->LeadBitmap.Width - ptStart.x) * pData->LeadBitmap.BitsPerPixel / 8; nByteAdd = (nByte * 8 + (9 - (nByte * 8) % 9)) * 16 / pAddMesgData->nType / 9; nByteAdd = (nByteLeft - nByteAdd) * pAddMesgData->nType * 9 / 8 / 16; SetDlgItemInt(hWnd, IDC_ADMSG_BYTE_EDT, nByteAdd, TRUE); if(nByteAdd < 0) MessageBox(hWnd, TEXT("You can't add more character to image!"), TEXT("STOP"), MB_OK); } break; } UNLOCKCHILDDATA(hWndParent); return FALSE; case IDOK: hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_CHK); if(!Button_GetCheck(hWndCtrl)) { hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_EDT); nByte = Edit_GetTextLength(hWndCtrl); if(nByte == 0) { MessageBox(hWnd, TEXT("Enter your password!"),TEXT("Password"),MB_OK); return FALSE; } nByte++; pAddMesgData->pAddMesgInfo->pPassword = (L_UCHAR L_FAR *) GlobalAllocPtr(GHND, sizeof(L_UCHAR) * nByte); if(!pAddMesgData->pAddMesgInfo->pPassword) return FALSE; GetWindowTextA(hWndCtrl, pAddMesgData->pAddMesgInfo->pPassword, nByte); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_CONF_EDT); nByte = Edit_GetTextLength(hWndCtrl); if(nByte == 0) { MessageBox(hWnd, TEXT("Confirm your password!"),TEXT("Password Confirm"),MB_OK); return FALSE; } GetWindowTextA(hWndCtrl, uConfirmPass, ++nByte); if(strcmp(pAddMesgData->pAddMesgInfo->pPassword, uConfirmPass) != 0) { MessageBox(hWnd, TEXT("Renter your password!"),TEXT("Password Error"),MB_OK); return FALSE; } } else pAddMesgData->pAddMesgInfo->pPassword = NULL; hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_POS_CHK); if(!Button_GetCheck(hWndCtrl)) { pAddMesgData->pAddMesgInfo->pStart = (LPPOINT) GlobalAllocPtr(GHND, sizeof(POINT)); if(!pAddMesgData->pAddMesgInfo->pStart) return FALSE; pAddMesgData->pAddMesgInfo->pStart->x = GetDlgItemInt(hWnd, IDC_ADMSG_XPOS_EDT,NULL, TRUE); pAddMesgData->pAddMesgInfo->pStart->y = GetDlgItemInt(hWnd, IDC_ADMSG_YPOS_EDT,NULL, TRUE); } hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_TXT_RAD); if(Button_GetCheck(hWndCtrl)) { hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_MSG_EDT); nByte = Edit_GetTextLength(hWndCtrl) + 1; pAddMesgData->pAddMesgInfo->pStrMsg = (L_TCHAR L_FAR *) GlobalAllocPtr(GHND, sizeof(L_TCHAR) * nByte); if(!pAddMesgData->pAddMesgInfo->pStrMsg) return FALSE; GetWindowText(hWndCtrl, pAddMesgData->pAddMesgInfo->pStrMsg, nByte); } hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FILE_RAD); if(Button_GetCheck(hWndCtrl)) { hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FNAME_EDT); nByte = Edit_GetTextLength(hWndCtrl) + 1; pAddMesgData->pAddMesgInfo->pFileName = (L_TCHAR L_FAR *) GlobalAllocPtr(GHND, sizeof(L_TCHAR) * nByte); if(!pAddMesgData->pAddMesgInfo->pFileName) return FALSE; GetWindowText(hWndCtrl, pAddMesgData->pAddMesgInfo->pFileName, nByte); } UNLOCKCHILDDATA(hWndParent); EndDialog(hWnd, TRUE); return TRUE; case IDC_ADMSG_POS_CHK: bEnable = Button_GetCheck(hWndCtl); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_XPOS_EDT); SetDlgItemInt(hWnd, IDC_ADMSG_XPOS_EDT, 0, FALSE); EnableWindow(hWndCtrl, !bEnable); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_YPOS_EDT); SetDlgItemInt(hWnd, IDC_ADMSG_YPOS_EDT, 0, FALSE); EnableWindow(hWndCtrl, !bEnable); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_FILE_RAD); break; case IDC_ADMSG_PSW_CHK: bEnable = Button_GetCheck(hWndCtl); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_PSW_EDT); EnableWindow(hWndCtrl, !bEnable); Edit_SetText(hWndCtrl, TEXT("")); hWndCtrl = GetDlgItem(hWnd, IDC_ADMSG_CONF_EDT); EnableWindow(hWndCtrl, !bEnable); Edit_SetText(hWndCtrl, TEXT("")); break; } UNLOCKCHILDDATA(hWndParent); return FALSE; }