void ListBoxSetActive(HWND hwnd, int index,BOOL fRedraw) { LISTBOX *lb=(LISTBOX *) GetListBox(hwnd); if(lb) lb->active=index; if(fRedraw) InvalidateRect(hwnd,NULL,FALSE); }
/** * "파일 풀기"를 눌렀을때 파일을 하나 푸는 함수 */ void CFV_Select::OnMenu_Extract () { int * pIndecies = NULL; /// 선택된 인덱스를 저장 CListBox * plistSel = NULL; /// 리스트 박스용 int nSelCnt = 0; /// 선택된 갯수 BYTE * btBuff = NULL; /// 임시버퍼 CVFS_Manager * pVFS = NULL; /// vfs파일 핸들 FILE * fp = NULL; /// 임시 파일포인터 VFileHandle *pVFH = NULL; /// vfs 파일핸들 CString strText = "", strFileName = "", strDir = ""; /// 스트링, 파일이름, 폴더 if(m_list.GetSelCount () > 0 && (plistSel = GetListBox ()) && (pVFS = ::g_pDlg_Main->GetVFS()) &&::g_pDlg_Main->GetSelectedVfsName ().GetLength () > 0) { /// 파일을 풀 디렉토리를 묻는다 if(GetFolder (&strDir, "파일을 풀 폴더를 선택하세요", GetSafeHwnd (), NULL, NULL)) { /// 인덱스를 저장하기 위해서 메모리를 할당 if((pIndecies = new int[m_list.GetSelCount ()])) { /// 선택된 인덱스들을 가져옴 m_list.GetSelItems (m_list.GetSelCount (), pIndecies); nSelCnt = m_list.GetSelCount (); for(short i = 0; i < nSelCnt; i++) { strText = ""; /// 리스트박스에서 문자열을 가져옴 plistSel->GetText (pIndecies[ nSelCnt - 1 - i ], strText); /// base file명만 불리해서 여기에 다시 저장하고 그리고 파일 생성할 때 사용한다 strFileName = strText; if(strFileName.ReverseFind ('\\') >= 0) { strFileName = strFileName.Right (strFileName.GetLength () - strFileName.ReverseFind ('\\') - 1); } long lFileLength = pVFS->GetFileLength (strText.GetString ()); if(lFileLength >= 0 && (btBuff = new BYTE[ lFileLength ])) { if((pVFH = pVFS->OpenFile (strText.GetString ()))) { vfread (btBuff, sizeof (BYTE), (size_t)lFileLength, pVFH); _fmode = _O_BINARY; if((fp = fopen (strDir + "\\" + strFileName, "w"))) { fwrite (btBuff, sizeof(BYTE), (size_t)lFileLength, fp); fclose (fp); } delete btBuff; pVFS->CloseFile (pVFH); } } } delete pIndecies; } } } }
void ListBoxAddString(HWND hwnd, char * text,WORD data,BOOL fRedraw) { LISTBOX *lb=(LISTBOX *) GetListBox(hwnd); if(lb) SendMessage(hwnd,LB_SETITEMHEIGHT,0,MAKELPARAM(lb->cdt->lbdt.ItemHeight,0)); int nItem = SendMessage(hwnd, LB_ADDSTRING, 0,(LPARAM) text); SendMessage(hwnd, LB_SETITEMDATA, nItem,MAKELPARAM(data,0)); if(fRedraw) InvalidateRect(hwnd,NULL,FALSE); }
BOOL WINAPI UninitializeLB(HWND hwnd) { LISTBOX *lb = GetListBox(hwnd); if(!lb) return 0; ListBoxDeleteAll(hwnd,FALSE); //restore the window procedure with the original one SetWindowLong(hwnd, GWL_WNDPROC, (LONG)lb->oldproc); RemoveProp(hwnd, PropListBoxStr); //finally, release the memory needed for the cool scrollbars HeapFree(GetProcessHeap(), 0, lb); return TRUE; }
LRESULT CALLBACK ListBoxSubclassProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { LISTBOX *lb=(LISTBOX *)GetListBox(hwnd); switch(uMsg) { case WM_PAINT: { PAINTSTRUCT ps; HDC hdc=BeginPaint(hwnd,&ps); DrawListBox(hwnd,lb,hdc); EndPaint(hwnd,&ps); } return 0; // redraw listbox case WM_LBUTTONDOWN: ListBoxNotifySelChange(hwnd); break; case LB_ADDSTRING: ListBoxContentsChangeNotify(hwnd); break; //******** // notify parent on contents change case LB_DELETESTRING: ListBoxContentsChangeNotify(hwnd); break; case LB_INSERTSTRING: ListBoxContentsChangeNotify(hwnd); break; case LB_RESETCONTENT : ListBoxContentsChangeNotify(hwnd); break; //************************************* case WM_KEYDOWN: switch (wParam) { case VK_DELETE: { HWND parent=GetParent(hwnd); SendMessage(parent,WM_KEYDOWN,VK_DELETE, 0); } break; // redraw listbox case VK_PRIOR: ListBoxNotifySelChange(hwnd); break; case VK_NEXT: ListBoxNotifySelChange(hwnd); break; case VK_UP: ListBoxNotifySelChange(hwnd); break; case VK_DOWN: ListBoxNotifySelChange(hwnd); break; case VK_HOME: ListBoxNotifySelChange(hwnd); break; case VK_END: ListBoxNotifySelChange(hwnd); break; //******************************* case VK_RETURN: { HWND parent=GetParent(hwnd); SendMessage(parent,WM_COMMAND, MAKEWPARAM(GetWindowLong(parent,GWL_ID),LBN_DBLCLK), (LPARAM)hwnd); } break; //default: // send all WM_KEYDOWN messages to parent // HWND parent=GetParent(hwnd); //SendMessage(parent,uMsg,wParam,lParam); } break; case WM_DESTROY: { LISTBOX *lb=GetListBox(hwnd); WNDPROC oldproc = lb->oldproc; UninitializeLB(hwnd); //we must call the original window procedure return CallWindowProc(oldproc, hwnd, uMsg, wParam, lParam); } } return CallWindowProc(lb->oldproc, hwnd, uMsg, wParam, lParam); }
/** * 파일을 지우는데, 지웠다는 마킹만 해 놓는 경우 */ void CFV_Select::OnMenu_RemoveFilesB () { int * pIndecies = NULL; /// 선택된 파일인덱스를 여기에 저장 CListBox * plistSel = NULL; /// 리스트박스에 대한 인스턴스 int nSelCnt = 0; /// 선택된 갯수 CString strText; /// 선택된 텍스트 CVFS_Manager * pVFS = ::g_pDlg_Main->GetVFS (); /// VFile Instance /// 선택된 갯수가 0보다 크고, 리스트박스 인스턴스가 유효하면 if(m_list.GetSelCount () > 0 && (plistSel = GetListBox ())) { /// 선택된 갯수 nSelCnt = m_list.GetSelCount (); /// 인덱스를 저장하기 위해서 메모리를 할당 if((pIndecies = new int[ nSelCnt ])) { /// 선택된 인덱스를 가져온다 m_list.GetSelItems (m_list.GetSelCount (), pIndecies); if(nSelCnt > 1 && pVFS) { /// 넘겨 주기 위해서 char ** pFiles = new char *[ nSelCnt ]; if(pFiles) { for(int i = 0; i < nSelCnt; i++) { /// 텍스트를 가져온다 plistSel->GetText (pIndecies[ i ], strText); /// std::string에 저장한다. new로 메모리 할당하는 대신에 이 방법 pFiles[ i ] = new char[ strText.GetLength () + 1]; strcpy (pFiles[ i ], strText.GetString ()); } if(pVFS && ::g_pDlg_Main->GetSelectedVfsName ().GetLength () > 0) { char buff [ 255 ]; /// 삭제하기 DWORD dwOldTime = timeGetTime (); bool bRemove= pVFS->RemoveFiles (::g_pDlg_Main->GetSelectedVfsName ().GetString (), (const char **)pFiles, nSelCnt); DWORD dwNewTime = timeGetTime (); DWORD dwSec = (dwNewTime - dwOldTime) / 1000; if(bRemove) { /// 성공 메시지 sprintf (buff, "%d초동안 %d개가 삭제되었습니다", dwSec, nSelCnt); MessageBox (buff, "파일 삭제", MB_OK | MB_ICONINFORMATION); } else { /// 실패 메시지 sprintf (buff, "%d초동안 %d개가 삭제하는데 실패했습니다.", dwSec, nSelCnt); MessageBox (buff, "파일 삭제", MB_OK | MB_ICONINFORMATION); } } /// 메모리 해제 delete pFiles; } else { /// 메모리 할당 실패했을때 에러 메시지 출력 MessageBox ("메모리를 할당하는데 실패했습니다", "에러", MB_OK | MB_ICONWARNING); } } /// 텍스트를 지운다. 꼭 역순으로 지워야 한다 for(int i = nSelCnt - 1; i >= 0 ; i--) { plistSel->DeleteString (pIndecies[ i ]); } delete pIndecies; } } }