BOOL CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg){ case WM_INITDIALOG:{ DWORD style; g_opHdlg=hdlg; bOptionsInit=TRUE; TranslateDialogDefault(hdlg); if(g_iButtonsCount!=DBGetContactSettingByte(NULL, PLGNAME,"ButtonsCount", 0)) { LOGFONT logFont; HFONT hFont; bNeedRestart=TRUE; EnableWindow(GetDlgItem(hdlg,IDC_BUTTONSLIST),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_BLISTADD),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_BLISTREMOVE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_MENUTREE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_MTREEADD),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_MTREEREMOVE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_BUTTONNAME),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_MENUNAME),FALSE); ShowWindow(GetDlgItem(hdlg,IDC_WARNING),SW_SHOW); hFont = (HFONT)SendMessage(GetDlgItem(hdlg, IDC_WARNING), WM_GETFONT, 0, 0); GetObject(hFont, sizeof logFont, &logFont); logFont.lfWeight = FW_BOLD; hFont = CreateFontIndirect(&logFont); SendMessage(GetDlgItem(hdlg, IDC_WARNING), WM_SETFONT, (WPARAM)hFont, 0); break; } g_iOPButtonsCount=g_iButtonsCount; hButtonsList=GetDlgItem(hdlg,IDC_BUTTONSLIST); hMenuTree=GetDlgItem(hdlg,IDC_MENUTREE); style = GetWindowLong(hButtonsList,GWL_STYLE); style |=TVS_NOHSCROLL; SetWindowLong(hButtonsList,GWL_STYLE, style); style = GetWindowLong(hMenuTree,GWL_STYLE); style |=TVS_NOHSCROLL; SetWindowLong(hMenuTree,GWL_STYLE, style); BuildButtonsList(hButtonsList); if(!TreeView_GetCount(hButtonsList)) EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE); oldBNameProc = (WNDPROC) SetWindowLong(GetDlgItem(hdlg,IDC_BUTTONNAME), GWL_WNDPROC, (LONG) EditSubclassProc); oldMNameProc = (WNDPROC) SetWindowLong(GetDlgItem(hdlg,IDC_MENUNAME) , GWL_WNDPROC, (LONG) EditSubclassProc); EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); CheckDlgButton(hdlg,IDC_RAUTOSEND,(g_bRClickAuto=DBGetContactSettingByte(NULL,PLGNAME,"RClickAuto",0))); CheckDlgButton(hdlg,IDC_LAUTOSEND,(g_bLClickAuto=DBGetContactSettingByte(NULL,PLGNAME,"LClickAuto",0))); CheckDlgButton(hdlg,IDC_ENABLEQUICKMENU,(g_bQuickMenu=DBGetContactSettingByte(NULL, PLGNAME,"QuickMenu", 1))); bOptionsInit=FALSE; }break; case WM_LBUTTONUP: if(drag) { TVHITTESTINFO hti; HTREEITEM htiAfter=NULL; ButtonData* bd=NULL; TVITEM tvi; RECT rc; BYTE height; BOOLEAN bAsChild = FALSE; TreeView_SetInsertMark(hMenuTree, NULL, 0 ); ReleaseCapture(); SetCursor( LoadCursor( NULL, IDC_ARROW ) ); hti.pt.x = ( SHORT )LOWORD( lparam ); hti.pt.y = ( SHORT )HIWORD( lparam ); ClientToScreen(hdlg,&hti.pt); ScreenToClient(hMenuTree,&hti.pt); TreeView_HitTest( hMenuTree, &hti ); if(TreeView_GetParent(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem)) break; if(TreeView_GetChild(hMenuTree,hti.hItem)&&TreeView_GetChild(hMenuTree,hDragItem)) break; if( hti.flags & TVHT_ABOVE ) { htiAfter = TVI_FIRST; } else if( hti.flags & ( TVHT_NOWHERE|TVHT_BELOW ) ) { htiAfter = TVI_LAST; } else if( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT ) ) { // check where over the item, the pointer is if( !TreeView_GetItemRect( hMenuTree, hti.hItem, &rc, FALSE ) ) { drag=0; break; } height = ( BYTE )( rc.bottom - rc.top ); if( hti.pt.y - ( height / 3 ) < rc.top ) { HTREEITEM hItem = hti.hItem; if( !( hti.hItem = TreeView_GetPrevSibling( hMenuTree, hItem ) ) ) { if( !( hti.hItem = TreeView_GetParent(hMenuTree, hItem ) )) htiAfter = TVI_FIRST; else bAsChild = TRUE; } } else if( hti.pt.y + ( height / 3 ) <= rc.bottom ) { bAsChild = TRUE; } } if(TreeView_GetChild(hMenuTree,hDragItem)&&bAsChild) break; if(hti.hItem){ tvi.hItem=hti.hItem; tvi.mask=TVIF_PARAM |TVIF_HANDLE; TreeView_GetItem(hMenuTree,&tvi); if((bd=(ButtonData*)tvi.lParam)&&(bd->fEntryOpType&QMF_EX_SEPARATOR)) bAsChild = FALSE; } if(TreeView_GetParent(hMenuTree,hti.hItem)) bAsChild = FALSE; MoveItem( hDragItem, htiAfter?htiAfter:hti.hItem, bAsChild ); SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); drag=0; } break; /////////////////////////////////// //From UserInfoEx by DeathAxe // case WM_MOUSEMOVE: { if (!drag) break; { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(lparam); hti.pt.y=(short)HIWORD(lparam); ClientToScreen(hdlg,&hti.pt); ScreenToClient(hMenuTree,&hti.pt); TreeView_HitTest(hMenuTree,&hti); if( hti.flags & ( TVHT_ONITEM|TVHT_ONITEMRIGHT ) ) { RECT rc; BYTE height; if( TreeView_GetItemRect(hMenuTree, hti.hItem, &rc, FALSE ) ) { height = ( BYTE )( rc.bottom - rc.top ); if( hti.pt.y - ( height / 3 ) < rc.top ) { SetCursor( LoadCursor( NULL, IDC_ARROW ) ); TreeView_SetInsertMark( hMenuTree, hti.hItem, 0 ); } else if( hti.pt.y + ( height / 3 ) > rc.bottom ) { SetCursor( LoadCursor( NULL, IDC_ARROW ) ); TreeView_SetInsertMark( hMenuTree, hti.hItem, 1 ); } else { TreeView_SetInsertMark( hMenuTree, NULL, 0 ); SetCursor( LoadCursor( GetModuleHandle(NULL), MAKEINTRESOURCE( 183 ) ) ); } } } else { if( hti.flags & TVHT_ABOVE ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEUP, 0 ), 0 ); if( hti.flags & TVHT_BELOW ) SendMessage( hMenuTree, WM_VSCROLL, MAKEWPARAM( SB_LINEDOWN, 0 ), 0 ); TreeView_SetInsertMark( hMenuTree, NULL, 0 ); } } }break; ///////////// case WM_DESTROY: if (g_varhelpDlg) DestroyWindow(g_varhelpDlg); g_varhelpDlg=NULL; break; case WM_NOTIFY:{ switch(((LPNMHDR)lparam)->idFrom) { case 0:{ if (((LPNMHDR)lparam)->code == PSN_APPLY ) { if(!bNeedRestart){ SetMenuEntryProperties(hdlg); SaveMenuTree(hdlg); } DBWriteContactSettingByte(NULL,PLGNAME,"RClickAuto",(BYTE)(g_bRClickAuto=IsDlgButtonChecked(hdlg,IDC_RAUTOSEND))); DBWriteContactSettingByte(NULL,PLGNAME,"LClickAuto",(BYTE)(g_bLClickAuto=IsDlgButtonChecked(hdlg,IDC_LAUTOSEND))); DBWriteContactSettingByte(NULL,PLGNAME,"QuickMenu",(BYTE)(g_bQuickMenu=IsDlgButtonChecked(hdlg,IDC_ENABLEQUICKMENU))); return 1; } else if (((LPNMHDR)lparam)->code == PSN_RESET ) { if(!bNeedRestart) RestoreModuleData(hdlg); return 1; } } break; case IDC_MENUTREE: switch (((LPNMHDR)lparam)->code){ case TVN_KEYDOWN:{ TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam); if ( pTVKeyDown->wVKey == VK_F2 ) TreeView_EditLabel(hMenuTree,TreeView_GetSelection(hMenuTree)); else if ( pTVKeyDown->wVKey == VK_DELETE ) SendMessage(hdlg,WM_COMMAND,IDC_MTREEREMOVE,0); }break; case TVN_BEGINLABELEDITA: case TVN_BEGINLABELEDITW: hwndEdit=TreeView_GetEditControl(hMenuTree); oldEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) LabelEditSubclassProc); break; case TVN_ENDLABELEDITA: case TVN_ENDLABELEDITW: { TVITEM tvi; ButtonData* bd=NULL; TCHAR strbuf[256]; TCHAR szLabel[256]; SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) oldEditProc); tvi.pszText = strbuf; tvi.cchTextMax = sizeof(strbuf); tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM; tvi.hItem=TreeView_GetSelection(hMenuTree); TreeView_GetItem(hMenuTree,&tvi); GetWindowText(hwndEdit, szLabel, sizeof(szLabel)); hwndEdit=NULL; if(!_tcslen(szLabel)) break; if (bd = (ButtonData*)tvi.lParam){ if(!_tcscmp(szLabel,_T("---"))){ if(TreeView_GetChild(hMenuTree,tvi.hItem)) break; else{ bd->fEntryOpType=QMF_EX_SEPARATOR; EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); } } else { bd->fEntryOpType&=~QMF_EX_SEPARATOR; EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/); } bd->pszOpName=mir_tstrdup(szLabel); tvi.pszText=szLabel; TreeView_SetItem(hMenuTree, &tvi); SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); } }break; case NM_KILLFOCUS: TreeView_EndEditLabelNow(hButtonsList, 1); break; case TVN_BEGINDRAGA: case TVN_BEGINDRAGW: SetCapture(hdlg); drag=1; hDragItem=((LPNMTREEVIEW)lparam)->itemNew.hItem; TreeView_SelectItem(hMenuTree,hDragItem); break; case TVN_SELCHANGINGA: case TVN_SELCHANGINGW: { TVITEM tvi; HTREEITEM hti; ButtonData* bd; hti=TreeView_GetSelection(hMenuTree); if (hti==NULL) break; tvi.hItem=hti; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(hMenuTree,&tvi); if (tvi.lParam == 0) break; bd = ( ButtonData* )tvi.lParam; if (bd) { TCHAR szValue[256]; GetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE), szValue, sizeof(szValue)); if(_tcslen(szValue)) { if(bd->pszOpValue&&(bd->pszOpValue!=bd->pszValue)) mir_free(bd->pszOpValue); bd->pszOpValue=mir_tstrdup(szValue); } bd->bOpInQMenu=IsDlgButtonChecked(hdlg,IDC_INQMENU); bd->bIsOpServName=IsDlgButtonChecked(hdlg,IDC_ISSERVNAME); } }break; case TVN_SELCHANGEDA: case TVN_SELCHANGEDW: { TVITEM tvi; HTREEITEM hti; ButtonData* bd=NULL; hti=TreeView_GetSelection(hMenuTree); if (hti==NULL) break; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(hMenuTree,&tvi); bd = ( ButtonData* )tvi.lParam; if (bd) { if(!TreeView_GetChild(hMenuTree, tvi.hItem)&&!(bd->fEntryOpType&QMF_EX_SEPARATOR)) { EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),TRUE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),TRUE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),TRUE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),bd->pszOpValue/*?bd->pszOpValue:bd->pszValue*/); } else { EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); if(!(bd->fEntryOpType&QMF_EX_SEPARATOR)) EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); } CheckDlgButton(hdlg,IDC_INQMENU,bd->bOpInQMenu); CheckDlgButton(hdlg,IDC_ISSERVNAME,bd->bIsOpServName); } } }break; case IDC_BUTTONSLIST: switch (((LPNMHDR)lparam)->code) { case TVN_KEYDOWN:{ TV_KEYDOWN* pTVKeyDown = (TV_KEYDOWN*) ((LPNMHDR)lparam); if ( pTVKeyDown->wVKey == VK_F2 ) TreeView_EditLabel(hButtonsList,TreeView_GetSelection(hButtonsList)); else if ( pTVKeyDown->wVKey == VK_DELETE ) SendMessage(hdlg,WM_COMMAND,IDC_BLISTREMOVE,0); }break; case TVN_BEGINLABELEDITA: case TVN_BEGINLABELEDITW: hwndEdit=TreeView_GetEditControl(hButtonsList); oldEditProc = (WNDPROC) SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) LabelEditSubclassProc); break; case TVN_ENDLABELEDITA: case TVN_ENDLABELEDITW:{ TVITEM tvi; TCHAR strbuf[128]; TCHAR szLabel[128]; SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG) oldEditProc); tvi.pszText = strbuf; tvi.cchTextMax = sizeof(strbuf); tvi.mask=TVIF_TEXT |TVIF_HANDLE|TVIF_PARAM; tvi.hItem=TreeView_GetSelection(hButtonsList); TreeView_GetItem(hButtonsList,&tvi); GetWindowText(hwndEdit, szLabel, sizeof(szLabel)); hwndEdit=NULL; if(!_tcslen(szLabel)) break; tvi.pszText=szLabel; ((ListData*)tvi.lParam)->dwOPFlags|=QMF_RENAMED; TreeView_SetItem(hButtonsList, &tvi); SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); }break; case TVN_SELCHANGINGA: case TVN_SELCHANGINGW: SetMenuEntryProperties(hdlg); break; case TVN_SELCHANGEDA: case TVN_SELCHANGEDW:{ TVITEM tvi; HTREEITEM hti; hti=TreeView_GetSelection(hButtonsList); if(hti==NULL||!TreeView_GetCount(hButtonsList)){ EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); break; } tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(hButtonsList,&tvi); if(tvi.lParam==0) break; BuildMenuTree(hMenuTree,(SortedList *)((ListData*)tvi.lParam)->sl); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),TRUE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),TRUE); CheckDlgButton(hdlg,IDC_ISSERVNAME2,((ListData*)tvi.lParam)->bIsOpServName); if(((ListData*)tvi.lParam)->ptszOPQValue) SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),((ListData*)tvi.lParam)->ptszOPQValue); else SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),_T("")); }break; }break; } }break; case WM_COMMAND:{ switch(LOWORD(wparam)){ case IDC_VARHELP:{ if(!g_varhelpDlg) g_varhelpDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_HELPDIALOG), 0, HelpDlgProc); else //ShowWindow(g_varhelpDlg,SW_SHOWDEFAULT); SetWindowPos(g_varhelpDlg,0,0,0,0,0,SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE); }break; case IDC_BLISTADD:{ TVINSERTSTRUCT tvis; ListData* ld=NULL; TCHAR namebuff[MAX_PATH]={'\0'}; int count=TreeView_GetCount(hButtonsList); if (count>10) break; if(g_iOPButtonsCount==99){ MessageBox(NULL,_T("Congratulation!\n\ You have clicked this button 100 times!\n\ There was access violation at this point...\n\ And now function for freeing resources must be called...\n\ But no! there's only break :D"),_T("You win!"),MB_OK); break; } ld=mir_alloc(sizeof(ListData)); ButtonsList[g_iOPButtonsCount++]=ld; ld->sl=li.List_Create(0,1); ld->dwOPFlags=QMF_NEW; ld->bIsOpServName=0; ld->ptszButtonName=NULL; ld->ptszOPQValue=NULL; ld->ptszQValue=NULL; tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; GetWindowText(GetDlgItem(hdlg,IDC_BUTTONNAME),namebuff,MAX_PATH); tvis.item.mask=TVIF_PARAM|TVIF_TEXT; tvis.item.pszText=(_tcslen(namebuff))?namebuff:TranslateT("New Button"); tvis.item.lParam=(LPARAM)ld; TreeView_SelectItem(hButtonsList,TreeView_InsertItem(hButtonsList,&tvis)); }break; case IDC_BLISTREMOVE:{ TVITEM tvi; ListData* ld; if(!(tvi.hItem=TreeView_GetSelection(hButtonsList))) break; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(hButtonsList,&tvi); ld= (ListData*)tvi.lParam; ld->dwOPFlags|=QMF_DELETNEEDED; TreeView_DeleteItem(hButtonsList,tvi.hItem); if(!TreeView_GetCount(hButtonsList)) { TreeView_DeleteAllItems(hMenuTree); EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_RCLICKVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME2),FALSE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); SetWindowText(GetDlgItem(hdlg,IDC_RCLICKVALUE),_T("")); } }break; case IDC_MTREEADD:{ TVINSERTSTRUCT tvis; TVITEM tvi; ButtonData *bd=NULL; SortedList *sl=NULL; TCHAR namebuff[MAX_PATH]={'\0'}; if(!TreeView_GetCount(hButtonsList)) break; if(!(tvi.hItem=TreeView_GetSelection(hButtonsList))) break; bd=mir_alloc(sizeof(ButtonData)); memset(bd,0,sizeof(ButtonData)); GetWindowText(GetDlgItem(hdlg,IDC_MENUNAME),namebuff,MAX_PATH); bd->dwOPPos=TreeView_GetCount(hMenuTree)-1; bd->pszOpName=_tcslen(namebuff)?mir_tstrdup(namebuff):mir_tstrdup(TranslateT("New Menu Entry")); bd->pszOpValue=mir_tstrdup(bd->pszOpName); bd->fEntryOpType=!_tcscmp(namebuff,_T("---"))?QMF_EX_SEPARATOR:0; bd->dwOPFlags=QMF_NEW; bd->pszName=NULL; bd->pszValue=NULL; tvi.mask=TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem(hButtonsList,&tvi); sl=((ListData*)tvi.lParam)->sl; li.List_InsertPtr(sl,bd); tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask=TVIF_PARAM|TVIF_TEXT; tvis.item.pszText=bd->pszOpName; tvis.item.lParam=(LPARAM)bd; TreeView_SelectItem(hMenuTree,TreeView_InsertItem(hMenuTree,&tvis)); }break; case IDC_MTREEREMOVE:{ TVITEM tvi; TVINSERTSTRUCT tvis; HTREEITEM hti=NULL; ButtonData *bd=NULL; tvi.mask=TVIF_HANDLE|TVIF_PARAM; if(!(tvi.hItem=TreeView_GetSelection(hMenuTree))) break; TreeView_GetItem(hMenuTree,&tvi); hti=tvi.hItem; bd= (ButtonData*)tvi.lParam; bd->dwOPFlags|=QMF_DELETNEEDED; if(tvi.hItem=TreeView_GetChild(hMenuTree,tvi.hItem)){ TCHAR strbuf[128]; while(tvi.hItem){ tvis.hInsertAfter=hti; tvi.pszText = strbuf; tvi.cchTextMax = sizeof(strbuf); tvi.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT; TreeView_GetItem(hMenuTree,&tvi); tvis.hParent=NULL; tvis.item=tvi; TreeView_InsertItem(hMenuTree,&tvis); tvi.hItem=TreeView_GetNextSibling(hMenuTree,tvi.hItem); } } TreeView_DeleteItem(hMenuTree,hti); if(!TreeView_GetCount(hMenuTree)){ EnableWindow(GetDlgItem(hdlg,IDC_MENUVALUE),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_ISSERVNAME),FALSE); EnableWindow(GetDlgItem(hdlg,IDC_INQMENU),FALSE); SetWindowText(GetDlgItem(hdlg,IDC_MENUVALUE),_T("")); } }break; } }break; case WM_NCDESTROY: if(oldBNameProc) SetWindowLong(GetDlgItem(hdlg,IDC_BUTTONNAME), GWL_WNDPROC, (LONG) oldBNameProc); if(oldMNameProc) SetWindowLong(GetDlgItem(hdlg,IDC_MENUNAME) , GWL_WNDPROC, (LONG) oldMNameProc); break; case WM_CLOSE: EndDialog(hdlg,0); return 0; }
INT_PTR TffdshowPageDec::msgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CBX_PRESETS: if (HIWORD(wParam) == CBN_SELCHANGE) { char_t presetName[256], actPresetName[256]; GetDlgItemText(m_hwnd, IDC_CBX_PRESETS, presetName, 255); deciD->getActivePresetName(actPresetName, 255); if (stricmp(presetName, actPresetName) != 0) { selectPreset(presetName); } return TRUE; } break; } break; case WM_FFONNEWFILTERS: { for (ThtiPages::const_iterator hp = filterPages.begin(); hp != filterPages.end(); hp++) for (TconfPages::const_iterator i = (*hp)->begin(); i != (*hp)->end(); i++) { ((TconfPageDec*)(*i))->onNewFilter(); } return TRUE; } case WM_NOTIFY: { NMHDR *nmhdr = LPNMHDR(lParam); if (nmhdr->hwndFrom == htv && nmhdr->idFrom == IDC_TV_TREE) switch (nmhdr->code) { case TVN_GETINFOTIP: { if (!cfgGet(IDFF_showHints)) { return FALSE; } NMTVGETINFOTIP *nmtvit = LPNMTVGETINFOTIP(lParam); TconfPageBase *page = hti2page(nmtvit->hItem); char_t tipS[1024] = _l(""); if (deciD->getFilterTipEx(page->filterID, page->filterPageID, tipS, 1023) != S_OK) { page->getTip(tipS, 1023); } if (tipS[0] == '\0') { return FALSE; } memset(nmtvit->pszText, 0, nmtvit->cchTextMax); ff_strncpy(nmtvit->pszText, tipS, nmtvit->cchTextMax - 1); return TRUE; } case NM_CUSTOMDRAW: { NMTVCUSTOMDRAW *tvcd = LPNMTVCUSTOMDRAW(lParam); int rcDy = tvcd->nmcd.rc.bottom - tvcd->nmcd.rc.top; if (tvcd->nmcd.dwDrawStage == CDDS_PREPAINT) { setDlgResult(CDRF_NOTIFYITEMDRAW); return TRUE; } else if (tvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT) { TconfPageBase *page = ((ThtiPage*)tvcd->nmcd.lItemlParam)->getPage(); if (page->getInter() == -1 && page->getOrder() == -1) { return FALSE; } setDlgResult(CDRF_NOTIFYPOSTPAINT); return TRUE; } else if (tvcd->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT) { RECT &tr = tvcd->nmcd.rc; if (tr.right > tr.left && tr.bottom > tr.top) { RECT rr; TreeView_GetItemRect(htv, HTREEITEM(tvcd->nmcd.dwItemSpec), &rr, true); rr.left -= 24; TconfPageBase *page = ((ThtiPage*)tvcd->nmcd.lItemlParam)->getPage(); if (page->getInter() != -1) { ImageList_Draw(hil, page->getInter() ? ilChecked : ilClear, tvcd->nmcd.hdc, tr.left + 8 + rr.left, tr.top + (rcDy - 16) / 2, ILD_TRANSPARENT); } if (isIn(page->getOrder(), deciD->getMinOrder2(), deciD->getMaxOrder2()) && (tvcd->nmcd.uItemState & CDIS_SELECTED)) { int img; HTREEITEM hti = page->hti; HTREEITEM htiPrev = TreeView_GetPrevVisible(htv, hti), htiNext = TreeView_GetNextVisible(htv, hti); int order = page->getOrder(), orderPrev = hti2page(htiPrev)->getOrder(), orderNext = hti2page(htiNext)->getOrder(); if (order == deciD->getMinOrder2()) { img = ilArrowD; } else if (order == deciD->getMaxOrder2()) { img = ilArrowU; } else { img = ilArrowUD; } ImageList_DrawEx(hil, img, tvcd->nmcd.hdc, tr.left + 2 + rr.left, tr.top + (rcDy - 16) / 2, 5, 16, CLR_DEFAULT, CLR_DEFAULT, ILD_TRANSPARENT); } } return TRUE; } return FALSE; } case NM_CLICK: { POINT ps; GetCursorPos(&ps); ScreenToClient(htv, &ps); TVHITTESTINFO tvhti; tvhti.pt = ps; HTREEITEM hti = TreeView_HitTest(htv, &tvhti); if (!hti) { return FALSE; } RECT rr; TreeView_GetItemRect(htv, hti, &rr, TRUE); RECT r; TreeView_GetItemRect(htv, hti, &r, FALSE); ps.x -= rr.left - 24; int iconTop = ((r.bottom - r.top) - 16) / 2; ps.y -= r.top; if (ps.x >= 8 && ps.x <= 16 + 8 && ps.y >= iconTop + 2 && ps.y <= iconTop + 13) { if (invInter(hti2page(hti), &r)) { return TRUE; } } else if (ps.x >= 2 && ps.x <= 7 && TreeView_GetSelection(htv) == tvhti.hItem) { int center = (r.bottom - r.top) / 2; if (ps.y > center - 6 && ps.y < center - 1 && page->getOrder() > deciD->getMinOrder2()) { swap(-1); return TRUE; } else if (ps.y > center + 1 && ps.y < center + 6 && page->getOrder() < deciD->getMaxOrder2()) { swap(1); return TRUE; } } return FALSE; } case TVN_BEGINDRAG: { NMTREEVIEW *nmtv = LPNMTREEVIEW(lParam); dragpage = hti2page(nmtv->itemNew.hItem); int order = dragpage->getOrder(); TreeView_SelectItem(htv, nmtv->itemNew.hItem); if (isIn(order, deciD->getMinOrder2(), deciD->getMaxOrder2())) { SetCapture(m_hwnd); } else { dragpage = NULL; } break; } } break; } case WM_MOUSEMOVE: if (dragpage) { TVHITTESTINFO tvhti; tvhti.pt.x = LOWORD(lParam) - tvx; tvhti.pt.y = HIWORD(lParam) - tvy; if (HTREEITEM htiTarget = TreeView_HitTest(htv, &tvhti)) { //TreeView_SelectDropTarget(htv,htiTarget); TconfPageBase *targetpage = hti2page(htiTarget); if (isIn(targetpage->getOrder(), deciD->getMinOrder2(), deciD->getMaxOrder2())) { swap(dragpage, targetpage); } } return TRUE; } break; case WM_LBUTTONUP: if (dragpage) { dragpage = NULL; ReleaseCapture(); return TRUE; } break; } return TffdshowPageBase::msgProc(uMsg, wParam, lParam); }
/* * This function is the configuration box. * (Being a dialog procedure, in general it returns 0 if the default * dialog processing should be performed, and 1 if it should not.) */ static INT_PTR CALLBACK config_dialog_proc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { when WM_INITDIALOG: { ctrlbox = ctrl_new_box(); setup_config_box(ctrlbox); windlg_init(); winctrl_init(&ctrls_base); winctrl_init(&ctrls_panel); windlg_add_tree(&ctrls_base); windlg_add_tree(&ctrls_panel); copy_config("dialog", &new_cfg, &file_cfg); RECT r; GetWindowRect(GetParent(wnd), &r); dlg.wnd = wnd; /* * Create the actual GUI widgets. */ // here we need the correct DIALOG_HEIGHT already create_controls(wnd, ""); /* Open and Cancel buttons etc */ SendMessage(wnd, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadIcon(inst, MAKEINTRESOURCE(IDI_MAINICON))); /* * Create the tree view. */ r.left = 3; r.right = r.left + 64; r.top = 3; r.bottom = r.top + DIALOG_HEIGHT - 26; MapDialogRect(wnd, &r); HWND treeview = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | TVS_HASLINES | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS, r.left, r.top, r.right - r.left, r.bottom - r.top, wnd, (HMENU) IDCX_TREEVIEW, inst, null); WPARAM font = SendMessage(wnd, WM_GETFONT, 0, 0); SendMessage(treeview, WM_SETFONT, font, MAKELPARAM(true, 0)); treeview_faff tvfaff; tvfaff.treeview = treeview; memset(tvfaff.lastat, 0, sizeof (tvfaff.lastat)); /* * Set up the tree view contents. */ HTREEITEM hfirst = null; char *path = null; for (int i = 0; i < ctrlbox->nctrlsets; i++) { controlset *s = ctrlbox->ctrlsets[i]; HTREEITEM item; int j; char *c; if (!s->pathname[0]) continue; j = path ? ctrl_path_compare(s->pathname, path) : 0; if (j == INT_MAX) continue; /* same path, nothing to add to tree */ /* * We expect never to find an implicit path * component. For example, we expect never to see * A/B/C followed by A/D/E, because that would * _implicitly_ create A/D. All our path prefixes * are expected to contain actual controls and be * selectable in the treeview; so we would expect * to see A/D _explicitly_ before encountering * A/D/E. */ c = strrchr(s->pathname, '/'); if (!c) c = s->pathname; else c++; item = treeview_insert(&tvfaff, j, c, s->pathname); if (!hfirst) hfirst = item; path = s->pathname; /* * Put the treeview selection on to the Session panel. * This should also cause creation of the relevant * controls. */ TreeView_SelectItem(treeview, hfirst); } /* * Set focus into the first available control. */ for (winctrl *c = ctrls_panel.first; c; c = c->next) { if (c->ctrl) { dlg_set_focus(c->ctrl); break; } } } when WM_DESTROY: winctrl_cleanup(&ctrls_base); winctrl_cleanup(&ctrls_panel); ctrl_free_box(ctrlbox); config_wnd = 0; when WM_NOTIFY: { if (LOWORD(wParam) == IDCX_TREEVIEW && ((LPNMHDR) lParam)->code == TVN_SELCHANGED) { HTREEITEM i = TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom); TVITEM item; char buffer[64]; item.hItem = i; item.pszText = buffer; item.cchTextMax = sizeof (buffer); item.mask = TVIF_TEXT | TVIF_PARAM; TreeView_GetItem(((LPNMHDR) lParam)->hwndFrom, &item); /* Destroy all controls in the currently visible panel. */ for (winctrl *c = ctrls_panel.first; c; c = c->next) { for (int k = 0; k < c->num_ids; k++) { HWND item = GetDlgItem(wnd, c->base_id + k); if (item) DestroyWindow(item); } } winctrl_cleanup(&ctrls_panel); // here we need the correct DIALOG_HEIGHT already create_controls(wnd, (char *) item.lParam); dlg_refresh(null); /* set up control values */ } } when WM_CLOSE: DestroyWindow(wnd); when WM_COMMAND or WM_DRAWITEM: { int ret = winctrl_handle_command(msg, wParam, lParam); if (dlg.ended) DestroyWindow(wnd); return ret; } when WM_USER: { HWND target = (HWND)wParam; // could delegate this to winctrls.c, like winctrl_handle_command; // but then we'd have to fiddle with the location of dragndrop /* * Look up the window handle in our data; find the control. (Hmm, apparently it works without looking for the widget entry that was particularly introduced for this purpose...) */ control * ctrl = null; for (winctrl *c = ctrls_panel.first; c && !ctrl; c = c->next) { if (c->ctrl) for (int k = 0; k < c->num_ids; k++) { #ifdef debug_dragndrop printf(" [->%8p] %8p\n", target, GetDlgItem(wnd, c->base_id + k)); #endif if (target == GetDlgItem(wnd, c->base_id + k)) { ctrl = c->ctrl; break; } } } if (ctrl) { //dlg_editbox_set_w(ctrl, L"Test"); // may hit unrelated items... // drop the drag-and-drop contents here dragndrop = (wstring)lParam; ctrl->handler(ctrl, EVENT_DROP); } } } return 0; }
//------------------------------------------------------------------------------ BOOL CALLBACK DialogProc_reg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: switch(LOWORD(wParam)) { //------------------------------------------ case BT_SEARCH: { char tmp[MAX_PATH]; //select lstv SetFocus(GetDlgItem(hwnd,LV_VIEW)); SendDlgItemMessage(hwnd,ED_SEARCH,WM_GETTEXT ,(WPARAM)MAX_PATH, (LPARAM)tmp); if (!SendDlgItemMessage(hwnd,BT_SEARCH_MATCH_CASE, BM_GETCHECK,(WPARAM) 0, (LPARAM)0)) pos_search_reg = LVSearchNoCass(GetDlgItem(hwnd,LV_VIEW), DLG_REG_LV_NB_COLUMN, tmp, pos_search_reg); else pos_search_reg = LVSearch(GetDlgItem(hwnd,LV_VIEW), DLG_REG_LV_NB_COLUMN, tmp, pos_search_reg); } break; //------------------------------------------ case BT_TREE_VIEW: if (IsWindowVisible(GetDlgItem(hwnd,LV_VIEW))) { ShowWindow(GetDlgItem(hwnd,ED_SEARCH), SW_HIDE); ShowWindow(GetDlgItem(hwnd,BT_SEARCH), SW_HIDE); ShowWindow(GetDlgItem(hwnd,LV_VIEW), SW_HIDE); ShowWindow(GetDlgItem(hwnd,TV_VIEW), SW_SHOW); }else { ShowWindow(GetDlgItem(hwnd,TV_VIEW), SW_HIDE); ShowWindow(GetDlgItem(hwnd,ED_SEARCH), SW_SHOW); ShowWindow(GetDlgItem(hwnd,BT_SEARCH), SW_SHOW); ShowWindow(GetDlgItem(hwnd,LV_VIEW), SW_SHOW); } break; //------------------------------------------ case POPUP_TV_CP_COMPLET_PATH:CopyTVData(hwnd,TV_VIEW, (HTREEITEM)SendDlgItemMessage(hwnd, TV_VIEW, TVM_GETNEXTITEM, TVGN_CARET, 0), FALSE);break; case POPUP_TV_CP_VALUE_AND_DATA:CopyTVData(hwnd,TV_VIEW, (HTREEITEM)SendDlgItemMessage(hwnd, TV_VIEW, TVM_GETNEXTITEM, TVGN_CARET, 0), TRUE);break; //------------------------------------------ case POPUP_S_VIEW: { char file[MAX_PATH]="raw_registry_export"; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFile = file; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter ="*.csv \0*.csv\0*.xml \0*.xml\0*.html \0*.html\0*.reg \0*.reg\0"; ofn.nFilterIndex = 1; ofn.Flags =OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.lpstrDefExt ="csv\0"; if (GetSaveFileName(&ofn)==TRUE) { if (ofn.nFilterIndex == SAVE_TYPE_REG5)SaveLSTVItemstoREG(GetDlgItem(hwnd,LV_VIEW), file, FALSE); else SaveLSTV(GetDlgItem(hwnd,LV_VIEW), file, ofn.nFilterIndex, DLG_REG_LV_NB_COLUMN); SendMessage(hstatus_bar,SB_SETTEXT,0, (LPARAM)"Export done !!!"); } } break; //----------------------------------------------------- case POPUP_S_SELECTION: { char file[MAX_PATH]="raw_registry_selected_keys_export"; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFile = file; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter ="*.csv \0*.csv\0*.xml \0*.xml\0*.html \0*.html\0*.reg \0*.reg\0"; ofn.nFilterIndex = 1; ofn.Flags =OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.lpstrDefExt ="csv\0"; if (GetSaveFileName(&ofn)==TRUE) { if (ofn.nFilterIndex == SAVE_TYPE_REG5)SaveLSTVItemstoREG(GetDlgItem(hwnd,LV_VIEW), file, TRUE); else SaveLSTVSelectedItems(GetDlgItem(hwnd,LV_VIEW), file, ofn.nFilterIndex, DLG_REG_LV_NB_COLUMN); SendMessage(hstatus_bar,SB_SETTEXT,0, (LPARAM)"Export done !!!"); } } break; //----------------------------------------------------- case POPUP_A_SEARCH: { char tmp[MAX_PATH]; SendDlgItemMessage(hwnd,ED_SEARCH,WM_GETTEXT ,(WPARAM)MAX_PATH, (LPARAM)tmp); LVAllSearch(GetDlgItem(hwnd,LV_VIEW), DLG_REG_LV_NB_COLUMN, tmp); } break; //----------------------------------------------------- case POPUP_I_00:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 0);break; case POPUP_I_01:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 1);break; case POPUP_I_02:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 2);break; case POPUP_I_03:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 3);break; case POPUP_I_04:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 4);break; case POPUP_I_05:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 5);break; case POPUP_I_06:CopyDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), 6);break; //----------------------------------------------------- case POPUP_CP_LINE:CopyAllDataToClipboard(GetDlgItem(hwnd,LV_VIEW), SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED), DLG_REG_LV_NB_COLUMN);break; //----------------------------------------------------- case POPUP_O_PATH: { char path[MAX_PATH]=""; ListView_GetItemText(GetDlgItem(hwnd,LV_VIEW),SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED),0,path,MAX_PATH); if (path[0]!=0) { char *c = path; while (*c++); while (*c != '\\' && *c != '/')c--; c++; *c=0; ShellExecute(h_main, "explore", path, NULL,NULL,SW_SHOW); } } break; } break; } break; case WM_CLOSE : ShowWindow(hwnd, SW_HIDE);break; case WM_CONTEXTMENU: if ((HWND)wParam == GetDlgItem(hwnd,TV_VIEW)) { //select trv item TV_HITTESTINFO tvh_info; tvh_info.pt.x = LOWORD(lParam); tvh_info.pt.y = HIWORD(lParam); ScreenToClient(GetDlgItem(hwnd,TV_VIEW), &(tvh_info.pt)); HTREEITEM hItemSelect = TreeView_HitTest(GetDlgItem(hwnd,TV_VIEW), &tvh_info); if (hItemSelect != 0)TreeView_SelectItem(GetDlgItem(hwnd,TV_VIEW),hItemSelect); HMENU hmenu; if ((hmenu = LoadMenu(hinst, MAKEINTRESOURCE(POPUP_TV_REGISTRY)))!= NULL) { POINT pos; if (GetCursorPos(&pos)!=0) { TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, pos.x, pos.y,hwnd, NULL); }else TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),hwnd, NULL); DestroyMenu(hmenu); } }else if ((HWND)wParam == GetDlgItem(hwnd,LV_VIEW)) { HMENU hmenu; if ((hmenu = LoadMenu(hinst, MAKEINTRESOURCE(POPUP_LSTV_REGISTRY)))!= NULL) { POINT pos; if (GetCursorPos(&pos)!=0) { TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, pos.x, pos.y,hwnd, NULL); }else TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),hwnd, NULL); DestroyMenu(hmenu); } } break; case WM_SIZE: { unsigned int mWidth = LOWORD(lParam); unsigned int mHeight = HIWORD(lParam); //controle de la taille minimum if (mWidth<800 ||mHeight<600) { RECT Rect; GetWindowRect(hwnd, &Rect); MoveWindow(hwnd,Rect.left,Rect.top,800+20,600+64,TRUE); }else { MoveWindow(GetDlgItem(hwnd,ED_SEARCH),5,0,mWidth-122,22,TRUE); MoveWindow(GetDlgItem(hwnd,BT_SEARCH),mWidth-113,0,55,22,TRUE); MoveWindow(GetDlgItem(hwnd,BT_TREE_VIEW),mWidth-57,0,55,22,TRUE); MoveWindow(GetDlgItem(hwnd,BT_SEARCH_MATCH_CASE),mWidth-113,24,120,18,TRUE); MoveWindow(GetDlgItem(hwnd,LV_VIEW),5,47,mWidth-10,mHeight-73,TRUE); MoveWindow(GetDlgItem(hwnd,TV_VIEW),5,47,mWidth-10,mHeight-73,TRUE); MoveWindow(GetDlgItem(hwnd,STB),0,mHeight-22,mWidth,22,TRUE); //column resise unsigned int i; DWORD column_sz = (mWidth-30)/DLG_REG_LV_NB_COLUMN; for (i=0;i<DLG_REG_LV_NB_COLUMN;i++) { redimColumnH(GetDlgItem(hwnd,LV_VIEW),i,column_sz); } } InvalidateRect(hwnd, NULL, TRUE); } break; case WM_NOTIFY: switch(((LPNMHDR)lParam)->code) { case LVN_COLUMNCLICK: TRI_REG_VIEW = !TRI_REG_VIEW; c_Tri(GetDlgItem(h_reg,LV_VIEW),((LPNMLISTVIEW)lParam)->iSubItem,TRI_REG_VIEW); break; case NM_DBLCLK: if (LOWORD(wParam) == LV_VIEW) { long i, index = SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETNEXTITEM,-1,LVNI_FOCUSED); if (index > -1) { char tmp[MAX_LINE_SIZE+1], tmp2[MAX_LINE_SIZE+1]; RichEditInit(GetDlgItem(h_info,DLG_INFO_TXT)); //for each column LVCOLUMN lvc; lvc.mask = LVCF_TEXT; lvc.cchTextMax = MAX_LINE_SIZE; lvc.pszText = tmp; for (i=0;i<DLG_REG_LV_NB_COLUMN;i++) { tmp[0] = 0; tmp2[0] = 0; if (SendDlgItemMessage(hwnd,LV_VIEW,LVM_GETCOLUMN,(WPARAM)i,(LPARAM)&lvc) != 0) { if (strlen(tmp)>0) { ListView_GetItemText(GetDlgItem(h_reg,LV_VIEW),index,i,tmp2,MAX_LINE_SIZE); if (strlen(tmp2)>0) { RichEditCouleur(GetDlgItem(h_info,DLG_INFO_TXT),NOIR,"\r\n["); RichEditCouleurGras(GetDlgItem(h_info,DLG_INFO_TXT),NOIR,tmp); RichEditCouleur(GetDlgItem(h_info,DLG_INFO_TXT),NOIR,"]\r\n"); RichEditCouleur(GetDlgItem(h_info,DLG_INFO_TXT),NOIR,tmp2); RichEditCouleur(GetDlgItem(h_info,DLG_INFO_TXT),NOIR,"\r\n"); } } } } RichSetTopPos(GetDlgItem(h_info,DLG_INFO_TXT)); if(RichEditTextSize(GetDlgItem(h_info,DLG_INFO_TXT))) { ShowWindow (h_info, SW_SHOW); UpdateWindow(h_info); } } RichSetTopPos(GetDlgItem(h_info,DLG_INFO_TXT)); } break; } break; } return FALSE; }
/** * name: MoveItem() * class: CPsTree * desc: moves a treeitem and its children to a new position * param: pPs - datastructure of the propertysheetpage * hItem - the HTREEITEM to move * hInsertAfter - the HTREEITEM to insert hItem after * bAsChild - tells, whether to try to add hItem as child of hInsertAfter or not * return: handle to new (moved) treeitem if successful or NULL otherwise **/ HTREEITEM CPsTree::MoveItem(HTREEITEM hItem, HTREEITEM hInsertAfter, BYTE bAsChild) { TVINSERTSTRUCT tvis; HTREEITEM hParent, hChild, hNewItem; int iItemIndex; if (!hItem || !hInsertAfter) return NULL; if (hItem == hInsertAfter) return hItem; switch ((ULONG_PTR)hInsertAfter) { case TVI_ROOT: case TVI_FIRST: case TVI_LAST: hParent = NULL; bAsChild = FALSE; break; default: hParent = TreeView_GetParent(_hWndTree, hInsertAfter); break; } // do not move a parent next to its own children! if (hItem == hParent) return hItem; // get detailed information about the item to move if (FAILED(iItemIndex = FindItemIndexByHandle(hItem))) return hItem; // item should be inserted as the first child of an existing root item if (bAsChild) { tvis.hParent = hInsertAfter; tvis.hInsertAfter = (_dwFlags & PSTVF_SORTTREE) ? TVI_SORT : ((bAsChild == 2) ? TVI_LAST : TVI_FIRST); } // item should be inserted after an existing item else { tvis.hParent = hParent; tvis.hInsertAfter = hInsertAfter; } // don't move subitems of a protocol to root as this would mean them not to be unique anymore if (!_pPs->hContact && (_pItems[iItemIndex]->Flags() & PSPF_PROTOPREPENDED) && !tvis.hParent) return hItem; // prepare the insert structure tvis.itemex.mask = TVIF_PARAM|TVIF_TEXT; tvis.itemex.state = TVIS_EXPANDED; tvis.itemex.stateMask = TVIS_EXPANDED; tvis.itemex.pszText = _pItems[iItemIndex]->Label(); tvis.itemex.lParam = (LPARAM)iItemIndex; if ((tvis.itemex.iImage = tvis.itemex.iSelectedImage = _pItems[iItemIndex]->Image()) >= 0) tvis.itemex.mask |= TVIF_IMAGE|TVIF_SELECTEDIMAGE; // insert the item if (!(hNewItem = TreeView_InsertItem(_hWndTree, &tvis))) return hItem; // update handle pointer in the page structure _pItems[iItemIndex]->Hti(hNewItem); // get the index of the parent _pItems[iItemIndex]->Parent(FindItemIndexByHandle(tvis.hParent)); // move children hInsertAfter = hNewItem; while (hChild = TreeView_GetChild(_hWndTree, hItem)) { MoveItem(hChild, hInsertAfter, 2); } // delete old tree TreeView_DeleteItem(_hWndTree, hItem); _dwFlags |= PSTVF_POS_CHANGED; TreeView_SelectItem(_hWndTree, hNewItem); TreeView_Expand(_hWndTree, hNewItem, TVE_EXPAND); return hNewItem; }
static LRESULT CALLBACK ParentSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { CMsgTree *dat = CWndUserData(hWnd).GetMsgTree(); switch (Msg) { case WM_NOTIFY: { if (((LPNMHDR)lParam)->hwndFrom == dat->hTreeView) { switch (((LPNMHDR)lParam)->code) { case TVN_BEGINDRAGA: case TVN_BEGINDRAGW: { LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam; NMMSGTREE nm = {0}; COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); int Order = TreeCtrl->hItemToOrder(pnmtv->itemNew.hItem); _ASSERT(Order != -1); if (Order != -1) { nm.ItemOld = (Order <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(Order)] : (CBaseTreeItem*)&TreeCtrl->Value[Order]; nm.hdr.code = MTN_BEGINDRAG; nm.hdr.hwndFrom = dat->hTreeView; nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView); if (!SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nm)) { SetCapture(hWnd); dat->hPrevDropTarget = dat->hDragItem = pnmtv->itemNew.hItem; SetFocus(dat->hTreeView); TreeView_SelectItem(dat->hTreeView, dat->hDragItem); } } } break; case TVN_SELCHANGEDA: case TVN_SELCHANGEDW: { if (dat->UpdateLock) { return 0; } LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam; NMMSGTREE nm = {0}; COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); if (pnmtv->itemOld.hItem) { int Order = TreeCtrl->IDToOrder(pnmtv->itemOld.lParam); if (Order != -1) { nm.ItemOld = (Order <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(Order)] : (CBaseTreeItem*)&TreeCtrl->Value[Order]; } } if (pnmtv->itemNew.hItem) { int Order = TreeCtrl->IDToOrder(pnmtv->itemNew.lParam); if (Order != -1) { nm.ItemNew = (Order <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(Order)] : (CBaseTreeItem*)&TreeCtrl->Value[Order]; } } nm.hdr.code = MTN_SELCHANGED; nm.hdr.hwndFrom = dat->hTreeView; nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView); SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nm); } break; case TVN_BEGINLABELEDITA: case TVN_BEGINLABELEDITW: { if (dat->GetTreeCtrl()->IDToOrder(((LPNMTVDISPINFO)lParam)->item.lParam) < 0) { return true; // cancel editing } g_OrigEditProc = (WNDPROC)SetWindowLongPtr(TreeView_GetEditControl(dat->hTreeView), GWLP_WNDPROC, (LONG_PTR)EditSubclassProc); } break; // case TVN_ENDLABELEDITA: // stupid miranda options.. how am I supposed to get ptvdi->item.pszText if it's in ANSI?? case TVN_ENDLABELEDIT: { LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam; if (ptvdi->item.pszText) { COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); int Order = TreeCtrl->IDToOrder(ptvdi->item.lParam); if (Order >= 0) { TreeCtrl->Value[Order].Title = ptvdi->item.pszText; TreeCtrl->SetModified(true); NMMSGTREE nm = {0}; nm.ItemNew = &TreeCtrl->Value[Order]; nm.hdr.code = MTN_ITEMRENAMED; nm.hdr.hwndFrom = dat->hTreeView; nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView); SendMessage(GetParent(dat->hTreeView), WM_NOTIFY, 0, (LPARAM)&nm); return true; // commit new text } } } break; case NM_CLICK: case NM_RCLICK: { TVHITTESTINFO hitTest; hitTest.pt.x = (short)LOWORD(GetMessagePos()); hitTest.pt.y = (short)HIWORD(GetMessagePos()); ScreenToClient(dat->hTreeView, &hitTest.pt); TreeView_HitTest(dat->hTreeView, &hitTest); if (hitTest.hItem) { if (TreeView_GetSelection(dat->hTreeView) == hitTest.hItem) { // make sure TVN_SELCHANGED notification is sent always, even if previous selected item was the same as new TreeView_SelectItem(dat->hTreeView, NULL); } TreeView_SelectItem(dat->hTreeView, hitTest.hItem); } } break; case NM_CUSTOMDRAW: { NMTVCUSTOMDRAW *lpNMCD = (NMTVCUSTOMDRAW*)lParam; switch (lpNMCD->nmcd.dwDrawStage) { case CDDS_PREPAINT: // the control is about to start painting { return CDRF_NOTIFYITEMDRAW; // instruct the control to return information when it draws items } break; case CDDS_ITEMPREPAINT: { return CDRF_NOTIFYPOSTPAINT; } break; case CDDS_ITEMPOSTPAINT: { RECT rc; TreeView_GetItemRect(lpNMCD->nmcd.hdr.hwndFrom, (HTREEITEM)lpNMCD->nmcd.dwItemSpec, &rc, true); int iSize = GetSystemMetrics(SM_CXSMICON); int I; int x = rc.left - iSize - 5; for (I = 0; I < lengthof(StatusModeList); I++) { if (lpNMCD->nmcd.lItemlParam == dat->MsgTreePage.GetValue(StatusModeList[I].DBSetting)) { DrawIconEx(lpNMCD->nmcd.hdc, x, rc.top, LoadSkinnedProtoIcon(NULL, StatusModeList[I].Status), iSize, iSize, 0, GetSysColorBrush(COLOR_WINDOW), DI_NORMAL); x -= iSize + 1; } /* if (lpNMCD->nmcd.lItemlParam == GetRecentGroupID(StatusModeList[I].Status)) { DrawIconEx(lpNMCD->nmcd.hdc, 3, rc.top, LoadSkinnedProtoIcon(NULL, StatusModeList[I].Status), iSize, iSize, 0, GetSysColorBrush(COLOR_WINDOW), DI_NORMAL); }*/ } } break; } } break; } } } break; case WM_MOUSEMOVE: { if (dat->hDragItem) { TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hWnd, &hti.pt); ScreenToClient(dat->hTreeView, &hti.pt); TreeView_HitTest(dat->hTreeView, &hti); if (hti.hItem) { TreeView_SelectDropTarget(dat->hTreeView, hti.hItem); SetTimer(hWnd, MSGTREE_TIMER_ID, MSGTREE_DRAGANDDROP_GROUPEXPANDTIME, NULL); } else { if (hti.flags & TVHT_ABOVE) { SendMessage(dat->hTreeView, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0); } if (hti.flags & TVHT_BELOW) { SendMessage(dat->hTreeView, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0); } TreeView_SelectDropTarget(dat->hTreeView, NULL); KillTimer(hWnd, MSGTREE_TIMER_ID); } } } break; case WM_LBUTTONUP: { if (dat->hDragItem) { TreeView_SelectDropTarget(dat->hTreeView, NULL); KillTimer(hWnd, MSGTREE_TIMER_ID); ReleaseCapture(); TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hWnd, &hti.pt); ScreenToClient(dat->hTreeView, &hti.pt); TreeView_HitTest(dat->hTreeView, &hti); if (hti.hItem && dat->hDragItem != hti.hItem) { NMMSGTREE nm = {0}; COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); int OrderOld = TreeCtrl->hItemToOrder(dat->hDragItem); int OrderNew = TreeCtrl->hItemToOrder(hti.hItem); _ASSERT(OrderOld != -1 && OrderNew != -1); nm.ItemOld = (OrderOld <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(OrderOld)] : (CBaseTreeItem*)&TreeCtrl->Value[OrderOld]; nm.ItemNew = (OrderNew <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(OrderNew)] : (CBaseTreeItem*)&TreeCtrl->Value[OrderNew]; nm.hdr.code = MTN_ENDDRAG; nm.hdr.hwndFrom = dat->hTreeView; nm.hdr.idFrom = GetDlgCtrlID(dat->hTreeView); if (!SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nm)) { dat->UpdateLock++; dat->GetTreeCtrl()->MoveItem(hWnd, dat->hDragItem, hti.hItem); dat->UpdateLock--; } } dat->hDragItem = NULL; } } break; case WM_TIMER: { if (wParam == MSGTREE_TIMER_ID) { KillTimer(hWnd, MSGTREE_TIMER_ID); TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(GetMessagePos()); hti.pt.y = (short)HIWORD(GetMessagePos()); ScreenToClient(dat->hTreeView, &hti.pt); TreeView_HitTest(dat->hTreeView, &hti); if (hti.hItem && dat->hDragItem != hti.hItem && TreeView_GetChild(dat->hTreeView, hti.hItem)) // target is a group and is not the same item that we're dragging { TreeView_Expand(dat->hTreeView, hti.hItem, TVE_EXPAND); } } } break; } return CallWindowProc(dat->OrigParentProc, hWnd, Msg, wParam, lParam); }
INT_PTR CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch ( msg ) { case WM_DESTROY: { if ( hPreviewBitmap ) ske_UnloadGlyphImage( hPreviewBitmap ); break; } case WM_INITDIALOG: { HTREEITEM it; TranslateDialogDefault( hwndDlg ); it = FillAvailableSkinList( hwndDlg ); HWND wnd = GetDlgItem( hwndDlg, IDC_TREE1 ); TreeView_SelectItem( wnd, it ); } return 0; case WM_COMMAND: { int isLoad = 0; switch ( LOWORD( wParam ) ) { case IDC_COLOUR_MENUNORMAL: case IDC_COLOUR_MENUSELECTED: case IDC_COLOUR_FRAMES: case IDC_COLOUR_STATUSBAR: SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_BUTTON_INFO: { TCHAR Author[255]; TCHAR URL[MAX_PATH]; TCHAR Contact[255]; TCHAR Description[400]; TCHAR text[2000]; SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 ) ); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam ); } if ( !sd ) return 0; if ( sd->File && !_tcschr( sd->File, _T('%') ) ) { GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Author" ), TranslateT( "( unknown )" ), Author, SIZEOF( Author ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "URL" ), _T( "" ), URL, SIZEOF( URL ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Contact" ), _T( "" ), Contact, SIZEOF( Contact ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Description" ), _T( "" ), Description, SIZEOF( Description ), sd->File ); _sntprintf( text, SIZEOF( text ), TranslateT( "%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s" ), sd->Name, Description, Author, Contact, URL, sd->File ); } else { _sntprintf( text, SIZEOF( text ), TranslateT( "%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s" ), TranslateT( "reVista for Modern v0.5" ), TranslateT( "This is second default Modern Contact list skin in Vista Aero style" ), TranslateT( "Angeli-Ka (graphics), FYR (template)" ), _T( "JID: [email protected]" ), _T("fyr.mirandaim.ru"), TranslateT( "Inside library" ) ); } MessageBox( hwndDlg, text, TranslateT( "Skin Information" ), MB_OK|MB_ICONINFORMATION ); } break; case IDC_BUTTON_APPLY_SKIN: if ( HIWORD( wParam ) == BN_CLICKED ) { SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 ) ); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam ); } if ( !sd ) return 0; if ( glSkinWasModified>0 ) { int res = 0; if ( glSkinWasModified == 1 ) res = MessageBox( hwndDlg, TranslateT( "Skin editor contains not stored changes.\n\nAll changes will be lost.\n\n Continue to load new skin?" ), TranslateT( "Warning!" ), MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST ); else res = MessageBox( hwndDlg, TranslateT( "Current skin was not saved to file.\n\nAll changes will be lost.\n\n Continue to load new skin?" ), TranslateT( "Warning!" ), MB_OKCANCEL|MB_ICONWARNING|MB_DEFBUTTON2|MB_TOPMOST ); if ( res!= IDOK ) return 0; } ske_LoadSkinFromIniFile( sd->File, FALSE ); ske_LoadSkinFromDB( ); glOtherSkinWasLoaded = TRUE; pcli->pfnClcBroadcast( INTM_RELOADOPTIONS, 0, 0 ); Sync( CLUIFrames_OnClistResize_mod, 0, 0 ); ske_RedrawCompleteWindow( ); Sync( CLUIFrames_OnClistResize_mod, 0, 0 ); { HWND hwnd = pcli->hwndContactList; RECT rc = {0}; GetWindowRect( hwnd, &rc ); Sync( CLUIFrames_OnMoving, hwnd, &rc ); } if ( g_hCLUIOptionsWnd ) { SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_LEFTMARGINSPIN, UDM_SETPOS, 0, ModernGetSettingByte( NULL, "CLUI", "LeftClientMargin", SETTING_LEFTCLIENTMARIGN_DEFAULT ) ); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_RIGHTMARGINSPIN, UDM_SETPOS, 0, ModernGetSettingByte( NULL, "CLUI", "RightClientMargin", SETTING_RIGHTCLIENTMARIGN_DEFAULT ) ); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_TOPMARGINSPIN, UDM_SETPOS, 0, ModernGetSettingByte( NULL, "CLUI", "TopClientMargin", SETTING_TOPCLIENTMARIGN_DEFAULT ) ); SendDlgItemMessage( g_hCLUIOptionsWnd, IDC_BOTTOMMARGINSPIN, UDM_SETPOS, 0, ModernGetSettingByte( NULL, "CLUI", "BottomClientMargin", SETTING_BOTTOMCLIENTMARIGN_DEFAULT ) ); } } break; case IDC_BUTTON_LOAD: isLoad = 1; if ( HIWORD( wParam ) == BN_CLICKED ) { { TCHAR str[MAX_PATH] = {0}; OPENFILENAME ofn = {0}; TCHAR filter[512] = {0}; int res = 0; ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.hwndOwner = hwndDlg; ofn.hInstance = NULL; mir_sntprintf(filter, SIZEOF(filter), _T("%s (*.msf)%c*.MSF%c%c"), TranslateT("Miranda skin file"), 0, 0, 0); ofn.lpstrFilter = filter; ofn.lpstrFile = str; ofn.Flags = isLoad?( OFN_FILEMUSTEXIST | OFN_HIDEREADONLY ) : ( OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY ) | OFN_DONTADDTORECENT; ofn.nMaxFile = sizeof( str ); ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrDefExt = _T( "msf" ); { DWORD tick = GetTickCount( ); res = GetOpenFileName( &ofn ); if( !res ) if ( GetTickCount( )-tick<100 ) { res = GetOpenFileName( &ofn ); if( !res ) break; } else break; } if ( res ) { HTREEITEM it = AddSkinToListFullName( hwndDlg, ofn.lpstrFile ); TreeView_SelectItem( GetDlgItem( hwndDlg, IDC_TREE1 ), it ); //SendDlgItemMessage( hwndDlg, IDC_SKINS_LIST, LB_SETCURSEL, it, 0 ); //SendMessage( hwndDlg, WM_COMMAND, MAKEWPARAM( IDC_SKINS_LIST, LBN_SELCHANGE ), 0 ); } } } } break; } case WM_DRAWITEM: if ( wParam == IDC_PREVIEW ) { //TODO:Draw hPreviewBitmap here HDC memDC, imgDC; HBITMAP hbmp, holdbmp, imgOldbmp; int mWidth, mHeight; RECT workRect = {0}; HBRUSH hbr = CreateSolidBrush( GetSysColor( COLOR_3DFACE ) ); DRAWITEMSTRUCT *dis = ( DRAWITEMSTRUCT * )lParam; mWidth = dis->rcItem.right-dis->rcItem.left; mHeight = dis->rcItem.bottom-dis->rcItem.top; memDC = CreateCompatibleDC( dis->hDC ); hbmp = ske_CreateDIB32( mWidth, mHeight ); holdbmp = ( HBITMAP )SelectObject( memDC, hbmp ); workRect = dis->rcItem; OffsetRect( &workRect, -workRect.left, -workRect.top ); FillRect( memDC, &workRect, hbr ); DeleteObject( hbr ); if ( hPreviewBitmap ) { //variables BITMAP bmp = {0}; POINT imgPos = {0}; int wWidth, wHeight; int dWidth, dHeight; float xScale = 1, yScale = 1; //GetSize GetObject( hPreviewBitmap, sizeof( BITMAP ), &bmp ); wWidth = workRect.right-workRect.left; wHeight = workRect.bottom-workRect.top; if ( wWidth<bmp.bmWidth ) xScale = ( float )wWidth/bmp.bmWidth; if ( wHeight<bmp.bmHeight ) yScale = ( float )wHeight/bmp.bmHeight; xScale = min( xScale, yScale ); yScale = xScale; dWidth = ( int )( xScale*bmp.bmWidth ); dHeight = ( int )( yScale*bmp.bmHeight ); //CalcPosition imgPos.x = workRect.left+( ( wWidth-dWidth )>>1 ); imgPos.y = workRect.top+( ( wHeight-dHeight )>>1 ); //DrawImage if ( !g_CluiData.fGDIPlusFail ) //Use gdi+ engine { DrawAvatarImageWithGDIp( memDC, imgPos.x, imgPos.y, dWidth, dHeight, hPreviewBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, 8, 255 ); } else { BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; imgDC = CreateCompatibleDC( dis->hDC ); imgOldbmp = ( HBITMAP )SelectObject( imgDC, hPreviewBitmap ); ske_AlphaBlend( memDC, imgPos.x, imgPos.y, dWidth, dHeight, imgDC, 0, 0, bmp.bmWidth, bmp.bmHeight, bf ); SelectObject( imgDC, imgOldbmp ); mod_DeleteDC( imgDC ); } } BitBlt( dis->hDC, dis->rcItem.left, dis->rcItem.top, mWidth, mHeight, memDC, 0, 0, SRCCOPY ); SelectObject( memDC, holdbmp ); DeleteObject( hbmp ); mod_DeleteDC( memDC ); } break; case WM_NOTIFY: switch ( ( ( LPNMHDR )lParam )->idFrom ) { case IDC_TREE1: { NMTREEVIEW * nmtv = ( NMTREEVIEW * ) lParam; if ( !nmtv ) return 0; if ( nmtv->hdr.code == TVN_SELCHANGEDA || nmtv->hdr.code == TVN_SELCHANGEDW ) { SkinListData * sd = NULL; if ( hPreviewBitmap ) { ske_UnloadGlyphImage( hPreviewBitmap ); hPreviewBitmap = NULL; } if ( nmtv->itemNew.lParam ) { sd = ( SkinListData* )nmtv->itemNew.lParam; { TCHAR buf[MAX_PATH]; CallService( MS_UTILS_PATHTORELATIVET, ( WPARAM )sd->File, ( LPARAM )buf ); SendDlgItemMessage( hwndDlg, IDC_EDIT_SKIN_FILENAME, WM_SETTEXT, 0, ( LPARAM )buf ); } { TCHAR prfn[MAX_PATH] = {0}; TCHAR imfn[MAX_PATH] = {0}; TCHAR skinfolder[MAX_PATH] = {0}; GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Preview" ), _T( "" ), imfn, SIZEOF( imfn ), sd->File ); IniParser::GetSkinFolder( sd->File, skinfolder ); _sntprintf( prfn, SIZEOF( prfn ), _T("%s\\%s"), skinfolder, imfn ); CallService( MS_UTILS_PATHTOABSOLUTET, ( WPARAM )prfn, ( LPARAM ) imfn ); char * imfn_ch = mir_t2a( imfn ); hPreviewBitmap = ske_LoadGlyphImage( imfn_ch ); mir_free( imfn_ch ); } EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_APPLY_SKIN ), TRUE ); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_INFO ), TRUE ); if ( hPreviewBitmap ) InvalidateRect( GetDlgItem( hwndDlg, IDC_PREVIEW ), NULL, TRUE ); else //prepare text { TCHAR Author[255]; TCHAR URL[MAX_PATH]; TCHAR Contact[255]; TCHAR Description[400]; TCHAR text[2000]; SkinListData* sd = NULL; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg, IDC_TREE1 ) ); if ( hti == 0 ) return 0; { TVITEM tvi = {0}; tvi.hItem = hti; tvi.mask = TVIF_HANDLE|TVIF_PARAM; TreeView_GetItem( GetDlgItem( hwndDlg, IDC_TREE1 ), &tvi ); sd = ( SkinListData* )( tvi.lParam ); } if ( !sd ) return 0; if( sd->File && !_tcschr( sd->File, _T('%') ) ) { GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Author" ), TranslateT( "( unknown )" ), Author, SIZEOF( Author ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "URL" ), _T( "" ), URL, SIZEOF( URL ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Contact" ), _T( "" ), Contact, SIZEOF( Contact ), sd->File ); GetPrivateProfileString( _T( "Skin_Description_Section" ), _T( "Description" ), _T( "" ), Description, SIZEOF( Description ), sd->File ); _sntprintf( text, SIZEOF( text ), TranslateT( "Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s" ), sd->Name, Description, Author, Contact, URL ); } else { _sntprintf( text, SIZEOF( text ), TranslateT( "%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n" ), TranslateT( "reVista for Modern v0.5" ), TranslateT( "This is second default Modern Contact list skin in Vista Aero style" ), TranslateT( "graphics by Angeli-Ka\ntemplate by FYR" ), _T("JID: [email protected]"), _T("fyr.mirandaim.ru") ); } ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), SW_HIDE ); ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_INFO ), SW_SHOW ); SendDlgItemMessage( hwndDlg, IDC_STATIC_INFO, WM_SETTEXT, 0, ( LPARAM )text ); } } else { //no selected SendDlgItemMessage( hwndDlg, IDC_EDIT_SKIN_FILENAME, WM_SETTEXT, 0, ( LPARAM )TranslateT( "Select skin from list" ) ); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_APPLY_SKIN ), FALSE ); EnableWindow( GetDlgItem( hwndDlg, IDC_BUTTON_INFO ), FALSE ); SendDlgItemMessage( hwndDlg, IDC_STATIC_INFO, WM_SETTEXT, 0, ( LPARAM )TranslateT( "Please select skin to apply" ) ); ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), SW_HIDE ); } ShowWindow( GetDlgItem( hwndDlg, IDC_PREVIEW ), hPreviewBitmap?SW_SHOW:SW_HIDE ); return 0; } else if ( nmtv->hdr.code == TVN_DELETEITEMA || nmtv->hdr.code == TVN_DELETEITEMW ) { if ( nmtv->itemOld.lParam ) mir_free_and_nill( nmtv->itemOld.lParam ); return 0; } break; } case 0: switch ( ( ( LPNMHDR )lParam )->code ) { case PSN_APPLY: { { DWORD tick = GetTickCount( ); pcli->pfnClcBroadcast( INTM_RELOADOPTIONS, 0, 0 ); NotifyEventHooks( g_CluiData.hEventBkgrChanged, 0, 0 ); pcli->pfnClcBroadcast( INTM_INVALIDATE, 0, 0 ); RedrawWindow( GetParent( pcli->hwndContactTree ), NULL, NULL, RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN ); } return 0; } break; } break; } }
//------------------------------------------------------------------------------ BOOL CALLBACK DialogProc_conf(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { switch(LOWORD(wParam)) { case BT_START: if (start_scan) CreateThread(NULL,0,StopGUIScan,0,0,0); else { //init start_scan = TRUE; //local or not ? if(TreeView_GetCount(htrv_files) > NB_MX_TYPE_FILES_TITLE)LOCAL_SCAN = FALSE; else LOCAL_SCAN = TRUE; //read state ! if (IsDlgButtonChecked(h_conf,BT_ACL_FILE_CHK)==BST_CHECKED)FILE_ACL=TRUE; else FILE_ACL=FALSE; if (IsDlgButtonChecked(h_conf,BT_ADS_FILE_CHK)==BST_CHECKED)FILE_ADS=TRUE; else FILE_ADS=FALSE; if (IsDlgButtonChecked(h_conf,BT_SHA_FILE_CHK)==BST_CHECKED)FILE_SHA=TRUE; else FILE_SHA=FALSE; if (IsDlgButtonChecked(h_conf,BT_UTC_CHK)==BST_CHECKED)UTC_TIME=TRUE; else UTC_TIME=FALSE; if (IsDlgButtonChecked(h_conf,BT_MAGIC_CHK)==BST_CHECKED)enable_magic=TRUE; else enable_magic=FALSE; if (IsDlgButtonChecked(h_conf,BT_RA_CHK)==BST_CHECKED)enable_remote=TRUE; else enable_remote=FALSE; if (Ischeck_treeview(htrv_test, H_tests[INDEX_FILE_NK]))enable_LNK= TRUE; else enable_LNK= FALSE; EnableWindow(htrv_files,FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_ACL_FILE_CHK),FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_ADS_FILE_CHK),FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_SHA_FILE_CHK),FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_UTC_CHK),FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_MAGIC_CHK),FALSE); EnableWindow(GetDlgItem((HWND)h_conf,BT_RA_CHK),FALSE); if(TreeView_GetCount(htrv_files) > NB_MX_TYPE_FILES_TITLE)LOCAL_SCAN = FALSE; else LOCAL_SCAN = TRUE; //create new session and select it ! SendMessage(hCombo_session, CB_RESETCONTENT,0,0); FORMAT_CALBAK_READ_INFO fcri; fcri.type = TYPE_SQL_ADD_SESSION; SQLITE_WriteData(&fcri, SQLITE_LOCAL_BDD); //start h_thread_scan = CreateThread(NULL,0,GUIScan,0,0,0); SetWindowText(GetDlgItem((HWND)h_conf,BT_START),cps[TXT_BT_STOP].c); } break; //---------------------------------------- case POPUP_TRV_FILES_ADD_FILE: { char files[MAX_LINE_DBSIZE]=""; memset(files,0,MAX_LINE_DBSIZE); OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = h_conf; ofn.lpstrFile = files; ofn.nMaxFile = MAX_LINE_DBSIZE; ofn.lpstrFilter = "*.* \0*.*\0" "*.log\0*.log\0" "*.evt\0*.evt\0" "*.evtx\0*.evtx\0" "*.db\0*.db\0" "*.sqlite\0*.sqlite\0" "*.dat\0*.dat\0" "*.pf\0*.pf\0" "*.job\0*.job\0" "ntds.dit\0ntds.dit\0" "sam\0sam\0" "system\0system\0" "software\0software\0" "security\0security\0" "default\0default\0" "hardware\0hardware\0"; ofn.nFilterIndex = 1; ofn.Flags =/*OFN_FILEMUSTEXIST |*/ OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_SHOWHELP; ofn.lpstrDefExt ="*.*"; if (GetOpenFileName(&ofn)==TRUE) { //firt is path char path[MAX_PATH],totalpath[MAX_PATH]; strncpy(path,files,MAX_PATH); //after file name char *p = files+strlen(files)+1; if (*p == 0)FileToTreeView(path); while (*p) { snprintf(totalpath,MAX_PATH,"%s\\%s",path,p); FileToTreeView(totalpath); p = p+strlen(p)+1; } //tri and clean CleanTreeViewFiles(htrv_files); //expend des branches SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); } } break; case POPUP_TRV_FILES_ADD_PATH: { BROWSEINFO browser; LPITEMIDLIST lip; char path[MAX_PATH] = ""; browser.hwndOwner = h_conf; browser.pidlRoot = 0; browser.lpfn = 0; browser.iImage = 0; browser.lParam = 0; browser.ulFlags = BIF_NEWDIALOGSTYLE; browser.pszDisplayName = path; browser.lpszTitle = ""; lip = SHBrowseForFolder(&browser); if (lip != NULL) { if (SHGetPathFromIDList(lip,path)) { FileToTreeView(path); //tri and clean CleanTreeViewFiles(htrv_files); //expend all SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); } } } break; case POPUP_TRV_FILES_UP: { //get selection + parent HTREEITEM hitem = (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0); HTREEITEM hparent = (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_PARENT, (LPARAM)hitem); //get txt char tmp[MAX_PATH]; GetItemTreeView(hitem,htrv_files,tmp, MAX_PATH); //add item if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_LOGS])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_FILES])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_APPLI])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); //remove item SendMessage(htrv_files,TVM_DELETEITEM,(WPARAM)0, (LPARAM)hitem); //expend all SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); } break; case POPUP_TRV_FILES_DOWN: { //get selection + parent HTREEITEM hitem = (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0); HTREEITEM hparent = (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_PARENT, (LPARAM)hitem); //get txt char tmp[MAX_PATH]; GetItemTreeView(hitem,htrv_files,tmp, MAX_PATH); //add item if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_LOGS])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_FILES])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); else if (hparent == TRV_HTREEITEM_CONF[FILES_TITLE_APPLI])AddItemTreeView(htrv_files,tmp, TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); //remove item SendMessage(htrv_files,TVM_DELETEITEM,(WPARAM)0, (LPARAM)hitem); //expend all SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); } break; case POPUP_TRV_FILES_REMOVE_ITEMS:TreeView_DeleteItem(htrv_files, (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0));break; case POPUP_TRV_FILES_CLEAN_ALL: SendMessage(htrv_files,TVM_DELETEITEM,(WPARAM)0, (LPARAM)TVI_ROOT); check_childs_treeview(htrv_test, FALSE); TRV_HTREEITEM_CONF[FILES_TITLE_LOGS] = AddItemTreeView(htrv_files,cps[TXT_FILE_AUDIT].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_FILES] = AddItemTreeView(htrv_files,cps[TXT_FILE_REP].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY] = AddItemTreeView(htrv_files,cps[TXT_FILE_REGISTRY].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_APPLI] = AddItemTreeView(htrv_files,cps[TXT_FILE_APPLI].c, TVI_ROOT); break; case POPUP_TRV_FILES_OPEN_PATH: { //get item txt char path[MAX_PATH]; TVITEM tvitem; tvitem.mask = TVIF_HANDLE|TVIF_TEXT; tvitem.hItem = (HTREEITEM)SendMessage(htrv_files,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0); tvitem.cchTextMax = MAX_PATH; tvitem.pszText = path; if (SendMessage(htrv_files,TVM_GETITEM,(WPARAM)0, (LPARAM)&tvitem)) { //directory or file if(isDirectory(path))ShellExecute(h_main, "explore", path, NULL,NULL,SW_SHOW); else { //extract char *c = path; while (*c++); while (*c != '\\')c--; c++; *c=0; ShellExecute(h_main, "explore", path, NULL,NULL,SW_SHOW); } } } break; case POPUP_TRV_FILES_AUTO_SEARCH: if (B_AUTOSEARCH) { B_AUTOSEARCH = FALSE; DWORD IDThread; GetExitCodeThread(h_AUTOSEARCH,&IDThread); TerminateThread(h_AUTOSEARCH,IDThread); //clean results unsigned int i; for (i=0;i<NB_MX_TYPE_FILES_TITLE;i++) { //tri SendMessage(htrv_files,TVM_SORTCHILDREN, TRUE,(LPARAM)TRV_HTREEITEM_CONF[i]); SupDoublon(htrv_files,TRV_HTREEITEM_CONF[i]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[i]); } }else { B_AUTOSEARCH = TRUE; h_AUTOSEARCH = CreateThread(NULL,0,AutoSearchFiles,0,0,0); } break; case POPUP_TRV_FILES_AUTO_SEARCH_PATH: if (B_AUTOSEARCH) { B_AUTOSEARCH = FALSE; DWORD IDThread; GetExitCodeThread(h_AUTOSEARCH,&IDThread); TerminateThread(h_AUTOSEARCH,IDThread); //clean results unsigned int i; for (i=0;i<NB_MX_TYPE_FILES_TITLE;i++) { //tri SendMessage(htrv_files,TVM_SORTCHILDREN, TRUE,(LPARAM)TRV_HTREEITEM_CONF[i]); SupDoublon(htrv_files,TRV_HTREEITEM_CONF[i]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[i]); } }else { BROWSEINFO browser; LPITEMIDLIST lip; char path[MAX_PATH] = ""; browser.hwndOwner = h_conf; browser.pidlRoot = 0; browser.lpfn = 0; browser.iImage = 0; browser.lParam = 0; browser.ulFlags = BIF_NEWDIALOGSTYLE; browser.pszDisplayName = path; browser.lpszTitle = ""; lip = SHBrowseForFolder(&browser); if (lip != NULL) { if (SHGetPathFromIDList(lip,path)) { strncat(path,"\\\0",MAX_PATH); B_AUTOSEARCH = TRUE; h_AUTOSEARCH = CreateThread(NULL,0,AutoSearchFiles,path,0,0); } } } break; case POPUP_TRV_FILES_SAVE_LIST: { char file[MAX_PATH]=""; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = h_conf; ofn.lpstrFile = file; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter ="*.txt \0*.txt\0*.csv\0*.csv\0"; ofn.nFilterIndex = 1; ofn.Flags =OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.lpstrDefExt =".txt\0"; if (GetSaveFileName(&ofn)==TRUE) { if (ofn.nFilterIndex == 2) SaveTRV(htrv_files, file, SAVE_TYPE_CSV); else SaveTRV(htrv_files, file, SAVE_TYPE_TXT); } } break; case POPUP_TRV_FILES_LOAD_LIST: { char file[MAX_LINE_SIZE]=""; memset(file,0,MAX_LINE_SIZE); OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = h_conf; ofn.lpstrFile = file; ofn.nMaxFile = MAX_LINE_SIZE; ofn.lpstrFilter = "*.* \0*.*\0" "*.txt\0*.txt\0" "*.csv\0*.csv\0"; ofn.nFilterIndex = 1; ofn.Flags =/*OFN_FILEMUSTEXIST |*/ OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_SHOWHELP; ofn.lpstrDefExt ="*.*"; if (GetOpenFileName(&ofn)==TRUE) { loadFile_test(file, ofn.nFilterIndex); } } break; case POPUP_TRV_CHECK_ALL:check_childs_treeview(htrv_test, TRUE);break; case POPUP_TRV_UNCHECK_ALL:check_childs_treeview(htrv_test, FALSE);break; case POPUP_TRV_STOP_TEST: { //get item index int index = GetTrvItemIndex((HTREEITEM)SendMessage(htrv_test,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0), htrv_test); if (index < NB_TESTS) { //kill the thread DWORD IDThread; GetExitCodeThread(h_thread_test[index],&IDThread); TerminateThread(h_thread_test[index],IDThread); h_thread_test[index] = 0; check_treeview(htrv_test, H_tests[index], TRV_STATE_UNCHECK); } } break; } } break; case WM_NOTIFY: /*if (((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) { TRI_PROCESS_VIEW = !TRI_PROCESS_VIEW; c_Tri(((LPNMHDR)lParam)->hwndFrom,((LPNMLISTVIEW)lParam)->iSubItem,TRI_PROCESS_VIEW); }else */if (((LPNMHDR)lParam)->code == NM_CLICK && ((LPNMHDR)lParam)->hwndFrom == htrv_test) { //selected item and state TV_HITTESTINFO Struct; POINT pt; GetCursorPos(&pt); ScreenToClient(htrv_test, &pt); Struct.pt = pt; HTREEITEM hItemSelect = TreeView_HitTest(htrv_test, &Struct); if (hItemSelect != NULL) { if (Struct.flags == TVHT_ONITEMSTATEICON)TreeView_SelectItem(htrv_test,hItemSelect); else//check case { if (Ischeck_treeview(htrv_test, hItemSelect))check_treeview(htrv_test, hItemSelect, TRV_STATE_CHECK); else check_treeview(htrv_test, hItemSelect, TRV_STATE_UNCHECK); } } } break; case WM_CONTEXTMENU://popup menu if ((HWND)wParam == htrv_test) { //select trv item TV_HITTESTINFO tvh_info; tvh_info.pt.x = LOWORD(lParam); tvh_info.pt.y = HIWORD(lParam); ScreenToClient(htrv_test, &(tvh_info.pt)); HTREEITEM hItemSelect = TreeView_HitTest(htrv_test, &tvh_info); if (hItemSelect != 0)TreeView_SelectItem(htrv_test,hItemSelect); //popup HMENU hmenu; if ((hmenu = LoadMenu(hinst, MAKEINTRESOURCE(POPUP_TRV_TEST)))!= NULL) { //set text !!! ModifyMenu(hmenu,POPUP_TRV_CHECK_ALL ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_CHECK_ALL ,cps[TXT_POPUP_CHECK_ALL].c); ModifyMenu(hmenu,POPUP_TRV_UNCHECK_ALL ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_UNCHECK_ALL ,cps[TXT_POPUP_UNCHECK_ALL].c); HTREEITEM item = (HTREEITEM)SendMessage(htrv_test,TVM_GETNEXTITEM,(WPARAM)TVGN_CARET, (LPARAM)0); BOOL check = Ischeck_treeview(htrv_test, item); if (start_scan && (item!=NULL) && check && (h_thread_test[GetTrvItemIndex(item, htrv_test)]!=NULL)) { ModifyMenu(hmenu,POPUP_TRV_STOP_TEST ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_STOP_TEST ,cps[TXT_POPUP_STOP_TEST].c); }else { RemoveMenu(hmenu,POPUP_TRV_STOP_TEST,MF_BYCOMMAND); RemoveMenu(GetSubMenu(hmenu, 0),2,MF_BYPOSITION); } //affichage du popup menu POINT pos; if (GetCursorPos(&pos)!=0) { TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, pos.x, pos.y,hwnd, NULL); }else TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),hwnd, NULL); DestroyMenu(hmenu); } }else if ((HWND)wParam == htrv_files) { //select trv item TV_HITTESTINFO tvh_info; tvh_info.pt.x = LOWORD(lParam); tvh_info.pt.y = HIWORD(lParam); ScreenToClient(htrv_files, &(tvh_info.pt)); HTREEITEM hItemSelect = TreeView_HitTest(htrv_files, &tvh_info); if (hItemSelect != NULL)TreeView_SelectItem(htrv_files,hItemSelect); //popup HMENU hmenu; if ((hmenu = LoadMenu(hinst, MAKEINTRESOURCE(POPUP_TRV_FILES)))!= NULL) { //set text !!! ModifyMenu(hmenu,POPUP_TRV_FILES_ADD_FILE ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_ADD_FILE ,cps[TXT_POPUP_ADD_FILE].c); ModifyMenu(hmenu,POPUP_TRV_FILES_ADD_PATH ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_ADD_PATH ,cps[TXT_POPUP_ADD_PATH].c); if (B_AUTOSEARCH) { RemoveMenu(hmenu,POPUP_TRV_FILES_AUTO_SEARCH_PATH ,MF_BYCOMMAND); ModifyMenu(hmenu,POPUP_TRV_FILES_AUTO_SEARCH ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_AUTO_SEARCH ,cps[TXT_POPUP_AUTO_SEARCH_STOP].c); }else { ModifyMenu(hmenu,POPUP_TRV_FILES_AUTO_SEARCH ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_AUTO_SEARCH ,cps[TXT_POPUP_AUTO_SEARCH].c); ModifyMenu(hmenu,POPUP_TRV_FILES_AUTO_SEARCH_PATH ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_AUTO_SEARCH_PATH ,cps[TXT_POPUP_AUTO_SEARCH_PATH].c); } if (SendMessage(htrv_files,TVM_GETCOUNT,(WPARAM)0,(LPARAM)0) > 4) { ModifyMenu(hmenu,POPUP_TRV_FILES_UP ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_UP ,cps[TXT_POPUP_UP].c); ModifyMenu(hmenu,POPUP_TRV_FILES_DOWN ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_DOWN ,cps[TXT_POPUP_DOWN].c); ModifyMenu(hmenu,POPUP_TRV_FILES_REMOVE_ITEMS ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_REMOVE_ITEMS ,cps[TXT_POPUP_REMOVE_ITEMS].c); ModifyMenu(hmenu,POPUP_TRV_FILES_CLEAN_ALL ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_CLEAN_ALL ,cps[TXT_POPUP_CLEAN_ALL].c); ModifyMenu(hmenu,POPUP_TRV_FILES_OPEN_PATH ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_OPEN_PATH ,cps[TXT_POPUP_OPEN_PATH].c); ModifyMenu(hmenu,POPUP_TRV_FILES_SAVE_LIST ,MF_BYCOMMAND|MF_STRING ,POPUP_TRV_FILES_SAVE_LIST ,cps[TXT_POPUP_SAVE_LIST].c); }else { RemoveMenu(GetSubMenu(hmenu,0),2 ,MF_BYPOSITION); RemoveMenu(hmenu,POPUP_TRV_FILES_UP ,MF_BYCOMMAND); RemoveMenu(hmenu,POPUP_TRV_FILES_DOWN ,MF_BYCOMMAND); RemoveMenu(hmenu,POPUP_TRV_FILES_REMOVE_ITEMS ,MF_BYCOMMAND); RemoveMenu(hmenu,POPUP_TRV_FILES_CLEAN_ALL ,MF_BYCOMMAND); RemoveMenu(hmenu,POPUP_TRV_FILES_OPEN_PATH ,MF_BYCOMMAND); RemoveMenu(hmenu,POPUP_TRV_FILES_SAVE_LIST ,MF_BYCOMMAND); } //affichage du popup menu POINT pos; if (GetCursorPos(&pos)!=0) { TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, pos.x, pos.y,hwnd, NULL); }else TrackPopupMenuEx(GetSubMenu(hmenu, 0), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),hwnd, NULL); DestroyMenu(hmenu); } } break; case WM_DROPFILES://gestion du drag and drop de fichier ^^ { if (B_AUTOSEARCH)break; HDROP H_DropInfo=(HDROP)wParam; char tmp[MAX_PATH]; DWORD i,nb_path = DragQueryFile(H_DropInfo, 0xFFFFFFFF, tmp, MAX_PATH); for (i=0;i<nb_path;i++) { //get data DragQueryFile(H_DropInfo, i, tmp, MAX_PATH); //add FileToTreeView(tmp); } DragFinish(H_DropInfo); //tri and clean CleanTreeViewFiles(htrv_files); //expend des branches SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_FILES]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_LOGS]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY]); SendMessage(htrv_files,TVM_EXPAND, TVE_EXPAND,(LPARAM)TRV_HTREEITEM_CONF[FILES_TITLE_APPLI]); } break; case WM_INITDIALOG: //add language correction SetWindowText(GetDlgItem(hwnd,BT_ACL_FILE_CHK),cps[TXT_CHECK_ACL].c); SetWindowText(GetDlgItem(hwnd,BT_SHA_FILE_CHK),cps[TXT_CHECK_SHA].c); SetWindowText(GetDlgItem(hwnd,BT_ADS_FILE_CHK),cps[TXT_CHECK_ADS].c); SetWindowText(GetDlgItem(hwnd,BT_START),cps[TXT_BT_START].c); SetWindowText(GetDlgItem(hwnd,GRP_CONF),cps[TXT_GRP_CONF].c); //check all tests CheckDlgButton(hwnd,BT_ACL_FILE_CHK,BST_CHECKED); CheckDlgButton(hwnd,BT_ADS_FILE_CHK,BST_CHECKED); CheckDlgButton(hwnd,BT_UTC_CHK,BST_CHECKED); //add icon SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(ICON_APP))); //add files owners htrv_files = GetDlgItem(hwnd,TRV_FILES); SendMessage(htrv_files,CBEM_SETIMAGELIST,0,(LPARAM)H_ImagList_icon); TRV_HTREEITEM_CONF[FILES_TITLE_LOGS] = AddItemTreeView(htrv_files,cps[TXT_FILE_AUDIT].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_FILES] = AddItemTreeView(htrv_files,cps[TXT_FILE_REP].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_REGISTRY] = AddItemTreeView(htrv_files,cps[TXT_FILE_REGISTRY].c, TVI_ROOT); TRV_HTREEITEM_CONF[FILES_TITLE_APPLI] = AddItemTreeView(htrv_files,cps[TXT_FILE_APPLI].c, TVI_ROOT); //add list of test //get all tests in list of rubriques htrv_test = GetDlgItem(hwnd,TRV_TEST); unsigned int i; NB_TESTS = SendMessage(hlstbox, LB_GETCOUNT,0,0); char tmp[DEFAULT_TMP_SIZE]; for (i=0;i<NB_TESTS;i++) { if (SendMessage(hlstbox, LB_GETTEXTLEN,i,0) < DEFAULT_TMP_SIZE) { tmp[0] = 0; if(SendMessage(hlstbox, LB_GETTEXT,i,(LPARAM)tmp) > 0) { //add item H_tests[i] = AddItemTreeView(htrv_test,tmp, TVI_ROOT); } } } break; case WM_SIZE: { unsigned int mWidth = LOWORD(lParam); unsigned int mHeight = HIWORD(lParam); //controle de la taille minimum if ((mWidth<800) || (mHeight<600)) { RECT Rect; GetWindowRect(hwnd, &Rect); MoveWindow(hwnd,Rect.left,Rect.top,800+20,600+64,TRUE); }else { MoveWindow(GetDlgItem(hwnd,TRV_FILES),0,0,mWidth/2,mHeight-27,TRUE); MoveWindow(GetDlgItem(hwnd,TRV_TEST),mWidth/2+2,0,(mWidth/2)-2,mHeight-167,TRUE); MoveWindow(GetDlgItem(hwnd,GRP_CONF),mWidth/2+2,mHeight-165,(mWidth/2)-2,98,TRUE); MoveWindow(GetDlgItem(hwnd,BT_ACL_FILE_CHK),mWidth/2+20,mHeight-148,(mWidth/2)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_ADS_FILE_CHK),mWidth/2+20,mHeight-128,(mWidth/2)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_SHA_FILE_CHK),mWidth/2+20,mHeight-108,(mWidth/2)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_UTC_CHK),mWidth/2+20,mHeight-88,(mWidth/4)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_RA_CHK),mWidth*3/4+20,mHeight-108,(mWidth*1/4)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_MAGIC_CHK),mWidth*3/4+20,mHeight-88,(mWidth*1/4)-40,17,TRUE); MoveWindow(GetDlgItem(hwnd,BT_START),mWidth/2+2,mHeight-64,(mWidth/2)-2,38,TRUE); MoveWindow(GetDlgItem(hwnd,DLG_CONF_SB),0,mHeight-25,mWidth,25,TRUE); } InvalidateRect(hwnd, NULL, TRUE); } break; case WM_CLOSE: { //if in stop case if ((start_scan == FALSE) && (stop_scan == TRUE)) { sqlite3_close(db_scan); CloseWindow(hwnd); PostQuitMessage(0); } //kill all threads unsigned int i; DWORD IDThread; for (i=0;i<NB_TESTS;i++) { GetExitCodeThread(h_thread_test[i],&IDThread); TerminateThread(h_thread_test[i],IDThread); } GetExitCodeThread(h_thread_scan,&IDThread); TerminateThread(h_thread_scan,IDThread); ShowWindow (h_main, SW_SHOW); UpdateWindow(h_main); EndDialog(hwnd, 0); } break; } return 0; }
//---------------------------------------------------// // TreeView_mHpProcess //---------------------------------------------------// void TreeView_mHpProcess(HWND hWndActive,BOOL &bChangeWnd,int iCurrentWnd,int iCountWnd) { switch(GetmHpVarStruct()->CourantTask->GetmHpStep()) { case 2: // 1° CLICK { EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,7); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 3: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,50,(TIMERPROC)mHpTimerProc); break; } case 4: // UNCLICK + Selection { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); if(GetFocus()!=GetmHpVarStruct()->hWndCurCtrl) SetFocus(GetmHpVarStruct()->hWndCurCtrl); TreeView_SelectItem(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 5: // DELAY { SetTimer(hWndActive,ID_TIMER_DELAI,1,(TIMERPROC)mHpTimerProc); break; } case 6: // 2° CLICK { EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,8); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 7: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,50,(TIMERPROC)mHpTimerProc); break; } case 8: // UNCLICK + Expand { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); TreeView_Expand(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,TVE_EXPAND); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 9: // DELAY { SetTimer(hWndActive,ID_TIMER_DELAI,400,(TIMERPROC)mHpTimerProc); break; } case 10: // NEXT SELECTION { GetmHpVarStruct()->SelItemListe->ItemIndexSuivant(); hCurSelItm=GetNexthTreeItemToSel(GetmHpVarStruct()->hWndCurCtrl,TreeView_GetChild(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm)); if(hCurSelItm!=NULL) { RECT CtlRct; GetWindowRect(GetmHpVarStruct()->hWndCurCtrl,&CtlRct); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; RECT ItmRct; TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&ItmRct,TRUE); ListTreeStatusPos(hWndActive,ItmRct); if(!GetmHpVarStruct()->AscensSens) { // When the last visible item is selected, that launch an auto-scroll TreeView_EnsureVisible(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&ItmRct,TRUE); // GetmHpVarStruct()->YnextPos=(int)(CtlRct.top+((ItmRct.bottom-ItmRct.top)/2)+ItmRct.top); GetmHpVarStruct()->XnextPos=(int)(CtlRct.left+((ItmRct.right-ItmRct.left)/2)+ItmRct.left); // DoubleClick | Click if(GetmHpVarStruct()->SelItemListe->IsNextIndexExist()) GetmHpVarStruct()->CourantTask->SetmHpStep(1); } else MoveOnScrollBar(GetmHpVarStruct()->hWndCurCtrl,CtlRct); // Not visible SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else // END { GetmHpVarStruct()->CourantTask->SetmHpStep(14); SetTimer(hWndActive,ID_TIMER_DELAI,1,(TIMERPROC)mHpTimerProc); } break; } case 11: // CLICK { GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CursorType=1; SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); break; } case 12: // DELAY { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_PRESS)); SetTimer(hWndActive,ID_TIMER_DELAI,150,(TIMERPROC)mHpTimerProc); break; } case 13: // LAST SELECTION { RECT ctlRct; RECT itmRct; int iLastAscens; if(!GetmHpVarStruct()->AscensSens) { PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); if(GetFocus()!=GetmHpVarStruct()->hWndCurCtrl) SetFocus(GetmHpVarStruct()->hWndCurCtrl); TreeView_SelectItem(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); GetmHpVarStruct()->bRefreshDDraw=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CourantTask->SetmHpStep(14); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else { switch(GetmHpVarStruct()->AscensSens) { case 1: // UP { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_VERT)-1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 2: // DOWN { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_VERT)+1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 3: // RIGHT { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_HORZ)+1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } case 4: // LEFT { if(!RestoreBackBuffer(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else { UpdateBackBuffer(TRUE); SendMessage(GetmHpVarStruct()->hWndCurCtrl,WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION,(GetScrollPos(GetmHpVarStruct()->hWndCurCtrl,SB_HORZ)-1)),NULL); if(!UpdateFrame(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); } break; } } iLastAscens=GetmHpVarStruct()->AscensSens; GetWindowRect(GetmHpVarStruct()->hWndCurCtrl,&ctlRct); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&itmRct,TRUE); ListTreeStatusPos(hWndActive,itmRct); if(!GetmHpVarStruct()->AscensSens) { // When the last visible item is selected, that launch an auto-scroll TreeView_EnsureVisible(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm); TreeView_GetItemRect(GetmHpVarStruct()->hWndCurCtrl,hCurSelItm,&itmRct,TRUE); // GetmHpVarStruct()->YnextPos=(int)(ctlRct.top+((itmRct.bottom-itmRct.top)/2)+itmRct.top); GetmHpVarStruct()->XnextPos=(int)(ctlRct.left+((itmRct.right-itmRct.left)/2)+itmRct.left); // DoubleClick | Click if(GetmHpVarStruct()->SelItemListe->IsNextIndexExist()) GetmHpVarStruct()->CourantTask->SetmHpStep(1); else GetmHpVarStruct()->CourantTask->SetmHpStep(10); PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else // Not visible { if(iLastAscens!=GetmHpVarStruct()->AscensSens) { MoveOnScrollBar(GetmHpVarStruct()->hWndCurCtrl,ctlRct); GetmHpVarStruct()->CourantTask->SetmHpStep(10); PlayResourceWAV(MAKEINTRESOURCE(IDR_WAVE_UNPRESS)); EndObjects(hWndActive); GetmHpVarStruct()->bRefreshDDraw=TRUE; GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); if(!DoInit(hWndActive)) StopmHelp(hWndActive,TRUE,TRUE); else SetTimer(hWndActive,ID_TIMER_DDRAW,1,(TIMERPROC)mHpTimerProc); } else { GetmHpVarStruct()->CourantTask->SetmHpStep(12); SetTimer(hWndActive,ID_TIMER_DELAI,200,(TIMERPROC)mHpTimerProc); } } } break; } case 14: { if((!bFindItm)&&(GetmHpVarStruct()->CourantTask->GetmHpOption()>=10)) ViewCtrlNotReadyMsg(hWndActive,4); else SetTimer(hWndActive,ID_TIMER_DELAI,300,(TIMERPROC)mHpTimerProc); break; } case 15: { if(GetmHpVarStruct()->TaskList->NextCellule()) { GetmHpVarStruct()->bNewDepl=TRUE; SetDDrawObj(hWndActive,0); GetmHpVarStruct()->CourantTask=GetmHpVarStruct()->TaskList->GetCurrentTask(); GetNextPos(hWndActive); } else NextRepeatAssistProc(hWndActive); break; } default: NULL; } }
static INT_PTR CALLBACK GenMenuOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct OrderData *dat = (struct OrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_USERDATA); LPNMHDR hdr; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat=(struct OrderData*)mir_alloc(sizeof(struct OrderData)); SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_USERDATA,(LONG_PTR)dat); dat->dragging = 0; dat->iInitMenuValue = DBGetContactSettingByte( NULL, "CList", "MoveProtoMenus", FALSE ); MyOldWindowProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_WNDPROC); SetWindowLongPtr(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWLP_WNDPROC,(LONG_PTR)&LBTNDOWNProc); { HIMAGELIST himlCheckBoxes; himlCheckBoxes=ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 2, 2); ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK); ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK); TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUOBJECTS),himlCheckBoxes,TVSIL_NORMAL); TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUITEMS),himlCheckBoxes,TVSIL_NORMAL); } CheckDlgButton(hwndDlg, dat->iInitMenuValue ? IDC_RADIO2 : IDC_RADIO1, TRUE ); CheckDlgButton(hwndDlg, IDC_DISABLEMENUICONS, bIconsDisabled ); BuildMenuObjectsTree(hwndDlg); return TRUE; case WM_COMMAND: if ( HIWORD(wParam) == BN_CLICKED || HIWORD( wParam ) == BN_DBLCLK ) { switch ( LOWORD( wParam )) { case IDC_INSERTSEPARATOR: InsertSeparator(hwndDlg); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RESETMENU: ResetMenuItems( hwndDlg ); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_DISABLEMENUICONS: case IDC_RADIO1: case IDC_RADIO2: SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); break; case IDC_GENMENU_DEFAULT: { TVITEM tvi; HTREEITEM hti; MenuItemOptData *iod; hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_MENUITEMS)); if (hti==NULL) break; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),&tvi); iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr( iod->name, STR_SEPARATOR )) break; if (iod->name) mir_free(iod->name); iod->name = mir_tstrdup( iod->defname ); SaveTree(hwndDlg); RebuildCurrent(hwndDlg); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); } break; case IDC_GENMENU_SET: { TVITEM tvi; TCHAR buf[256]; MenuItemOptData *iod; HTREEITEM hti = TreeView_GetSelection( GetDlgItem( hwndDlg,IDC_MENUITEMS )); if ( hti == NULL ) break; tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem = hti; SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_GETITEM, 0, (LPARAM)&tvi); iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr(iod->name, STR_SEPARATOR )) break; ZeroMemory(buf,sizeof( buf )); GetDlgItemText( hwndDlg, IDC_GENMENU_CUSTOMNAME, buf, SIZEOF( buf )); if (iod->name) mir_free(iod->name); iod->name = mir_tstrdup(buf); SaveTree(hwndDlg); RebuildCurrent(hwndDlg); SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); } break; } } break; case WM_NOTIFY: hdr = (LPNMHDR)lParam; switch( hdr->idFrom ) { case 0: if (hdr->code == PSN_APPLY ) { bIconsDisabled = IsDlgButtonChecked(hwndDlg, IDC_DISABLEMENUICONS) != 0; DBWriteContactSettingByte(NULL, "CList", "DisableMenuIcons", bIconsDisabled); SaveTree(hwndDlg); int iNewMenuValue = IsDlgButtonChecked(hwndDlg, IDC_RADIO1) ? 0 : 1; if ( iNewMenuValue != dat->iInitMenuValue ) { RebuildProtoMenus( iNewMenuValue ); dat->iInitMenuValue = iNewMenuValue; } RebuildCurrent(hwndDlg); } break; case IDC_MENUOBJECTS: if (hdr->code == TVN_SELCHANGEDA ) RebuildCurrent( hwndDlg ); break; case IDC_MENUITEMS: switch (hdr->code) { case NM_CUSTOMDRAW: { int i= handleCustomDraw(GetDlgItem(hwndDlg,IDC_MENUITEMS),(LPNMTVCUSTOMDRAW) lParam); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, i); return TRUE; } case TVN_BEGINDRAGA: SetCapture(hwndDlg); dat->dragging=1; dat->hDragItem=((LPNMTREEVIEW)lParam)->itemNew.hItem; TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),dat->hDragItem); break; case NM_CLICK: { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(GetMessagePos()); hti.pt.y=(short)HIWORD(GetMessagePos()); ScreenToClient(hdr->hwndFrom,&hti.pt); if (TreeView_HitTest(hdr->hwndFrom,&hti)) { if (hti.flags&TVHT_ONITEMICON) { TVITEM tvi; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti.hItem; TreeView_GetItem(hdr->hwndFrom,&tvi); tvi.iImage=tvi.iSelectedImage=!tvi.iImage; ((MenuItemOptData *)tvi.lParam)->show=tvi.iImage; TreeView_SetItem(hdr->hwndFrom,&tvi); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); //all changes take effect in runtime //ShowWindow(GetDlgItem(hwndDlg,IDC_BUTTONORDERTREEWARNING),SW_SHOW); } /*--------MultiSelection----------*/ if (hti.flags&TVHT_ONITEMLABEL) { /// LabelClicked Set/unset selection TVITEM tvi; HWND tvw=hdr->hwndFrom; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hti.hItem; TreeView_GetItem(tvw,&tvi); if (GetKeyState(VK_CONTROL)&0x8000) { if (((MenuItemOptData *)tvi.lParam)->isSelected) ((MenuItemOptData *)tvi.lParam)->isSelected=0; else ((MenuItemOptData *)tvi.lParam)->isSelected=1; //current selection order++. TreeView_SetItem(tvw,&tvi); } else if (GetKeyState(VK_SHIFT)&0x8000) { ; // shifted click } else { // reset all selection except current HTREEITEM hit; hit=TreeView_GetRoot(tvw); if (hit) do { TVITEM tvi={0}; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hit; TreeView_GetItem(tvw,&tvi); if (hti.hItem!=hit) ((MenuItemOptData *)tvi.lParam)->isSelected=0; else ((MenuItemOptData *)tvi.lParam)->isSelected=1; TreeView_SetItem(tvw,&tvi); } while (hit=TreeView_GetNextSibling(tvw,hit)); } } } break; } case TVN_SELCHANGING: { LPNMTREEVIEW pn; pn = (LPNMTREEVIEW) lParam; //((MenuItemOptData *)(pn->itemNew.lParam))->isSelected=1; /*if (pn->action==NotKeyPressed) { remove all selection } */ } case TVN_SELCHANGEDA: { TVITEM tvi; HTREEITEM hti; MenuItemOptData *iod; SetDlgItemTextA(hwndDlg,IDC_GENMENU_CUSTOMNAME,""); SetDlgItemTextA(hwndDlg,IDC_GENMENU_SERVICE,""); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_CUSTOMNAME),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_DEFAULT),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_SET),FALSE); hti=TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_MENUITEMS)); if (hti==NULL) break; tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM; tvi.hItem=hti; TreeView_GetItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),&tvi); if ( tvi.lParam == 0 ) break; iod = ( MenuItemOptData * )tvi.lParam; if ( iod->name && _tcsstr(iod->name, STR_SEPARATOR)) break; SetDlgItemText(hwndDlg,IDC_GENMENU_CUSTOMNAME,iod->name); if (iod->pimi->submenu.first == NULL && iod->uniqname) SetDlgItemTextA(hwndDlg, IDC_GENMENU_SERVICE, iod->uniqname); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_DEFAULT), lstrcmp(iod->name, iod->defname) != 0); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_SET),TRUE); EnableWindow(GetDlgItem(hwndDlg,IDC_GENMENU_CUSTOMNAME),TRUE); break; } break; } } break; case WM_MOUSEMOVE: if (!dat||!dat->dragging) break; { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(lParam); hti.pt.y=(short)HIWORD(lParam); ClientToScreen(hwndDlg,&hti.pt); ScreenToClient(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti.pt); TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)) { HTREEITEM it = hti.hItem; hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_MENUITEMS))/2; TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (!(hti.flags&TVHT_ABOVE)) TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti.hItem,1); else TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),it,0); } else { if (hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg,IDC_MENUITEMS,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),0); if (hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg,IDC_MENUITEMS,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),0); TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),NULL,0); } } break; case WM_LBUTTONUP: if (!dat->dragging) break; TreeView_SetInsertMark(GetDlgItem(hwndDlg,IDC_MENUITEMS),NULL,0); dat->dragging=0; ReleaseCapture(); { TVHITTESTINFO hti; hti.pt.x=(short)LOWORD(lParam); hti.pt.y=(short)HIWORD(lParam); ClientToScreen(hwndDlg,&hti.pt); ScreenToClient(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti.pt); hti.pt.y-=TreeView_GetItemHeight(GetDlgItem(hwndDlg,IDC_MENUITEMS))/2; TreeView_HitTest(GetDlgItem(hwndDlg,IDC_MENUITEMS),&hti); if (hti.flags&TVHT_ABOVE) hti.hItem=TVI_FIRST; if (dat->hDragItem==hti.hItem) break; dat->hDragItem=NULL; if (hti.flags&(TVHT_ONITEM|TVHT_ONITEMRIGHT)||(hti.hItem==TVI_FIRST)) { HWND tvw; HTREEITEM * pSIT; HTREEITEM FirstItem=NULL; UINT uITCnt,uSic ; tvw=GetDlgItem(hwndDlg,IDC_MENUITEMS); uITCnt=TreeView_GetCount(tvw); uSic=0; if (uITCnt) { pSIT=(HTREEITEM *)mir_alloc(sizeof(HTREEITEM)*uITCnt); if (pSIT) { HTREEITEM hit; hit=TreeView_GetRoot(tvw); if (hit) do { TVITEM tvi={0}; tvi.mask=TVIF_HANDLE|TVIF_PARAM; tvi.hItem=hit; TreeView_GetItem(tvw,&tvi); if (((MenuItemOptData *)tvi.lParam)->isSelected) { pSIT[uSic]=tvi.hItem; uSic++; } }while (hit=TreeView_GetNextSibling(tvw,hit)); // Proceed moving { UINT i; HTREEITEM insertAfter; insertAfter=hti.hItem; for (i=0; i<uSic; i++) { if (insertAfter) insertAfter=MoveItemAbove(tvw,pSIT[i],insertAfter); else break; if (!i) FirstItem=insertAfter; } } // free pointers... mir_free(pSIT); } } if (FirstItem) TreeView_SelectItem(tvw,FirstItem); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); SaveTree(hwndDlg); } } break; case WM_DESTROY: if ( dat ) mir_free( dat ); ImageList_Destroy(TreeView_SetImageList(GetDlgItem(hwndDlg,IDC_MENUOBJECTS),NULL,TVSIL_NORMAL)); FreeTreeData( hwndDlg ); break; } return FALSE; }
static INT_PTR CALLBACK IPSDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_INITDIALOG: { hIpsDlg = hDlg; hIpsList = GetDlgItem(hIpsDlg, IDC_IPSTREE1); hWhiteBGBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF)); hDefPreview = LoadBitmap(hAppInst, MAKEINTRESOURCE(BMP_PREVIEW)); DWORD dwStyle = (DWORD) GetWindowLongPtr(hIpsList, GWL_STYLE); dwStyle |= TVS_CHECKBOXES; SetWindowLongPtr(hIpsList, GWL_STYLE, (LONG_PTR) dwStyle); patchSettingInit(); initPatchPreviewPos(); wndInMid(hDlg, hScrnWnd); SetFocus(hDlg); // Enable Esc=close break; } case WM_COMMAND: { int wID = LOWORD(wParam); int Notify = HIWORD(wParam); if (Notify == BN_CLICKED) { switch (wID) { case IDOK: { ipsOkay(); break; } case IDCANCEL: { SendMessage(hDlg, WM_CLOSE, 0, 0); return 0; } case IDC_IPSCLEAR: { clearPatches(); break; } case IDC_IPS_ENFORCE: { bEnforceDep = !bEnforceDep; break; } } } if (wID == IDC_IPS_LANG && Notify == CBN_SELCHANGE) { nPatchLang = SendDlgItemMessage(hIpsDlg, IDC_IPS_LANG, CB_GETCURSEL, 0, 0); TreeView_DeleteAllItems(hIpsList); // rebuild ips list rebuildIpsList(); return 0; } break; } case WM_NOTIFY: { NMHDR* pNmHdr = (NMHDR*)lParam; if (LOWORD(wParam) == IDC_IPSTREE1 && pNmHdr->code == TVN_SELCHANGED) { refreshPatch(); return 1; } if (LOWORD(wParam) == IDC_IPSTREE1 && pNmHdr->code == NM_DBLCLK) { // disable double-click node-expand SetWindowLongPtr(hIpsDlg, DWLP_MSGRESULT, 1); return 1; } if (LOWORD(wParam) == IDC_IPSTREE1 && pNmHdr->code == NM_CLICK) { POINT cursorPos; GetCursorPos(&cursorPos); ScreenToClient(hIpsList, &cursorPos); TVHITTESTINFO thi; thi.pt = cursorPos; TreeView_HitTest(hIpsList, &thi); if (thi.flags == TVHT_ONITEMSTATEICON) { TreeView_SelectItem(hIpsList, thi.hItem); // check state and get patch index int id = checkPatchState(thi.hItem); // apply patch relations applyRelations(id); } return 1; } SetWindowLongPtr(hIpsDlg, DWLP_MSGRESULT, CDRF_DODEFAULT); return 1; } case WM_CTLCOLORSTATIC: if ((HWND)lParam == GetDlgItem(hIpsDlg, IDC_TEXTCOMMENT)) { return (BOOL)hWhiteBGBrush; } break; case WM_CLOSE: patchSettingExit(); break; } return 0; }
static int BuildTree(HWND hwndDlg,int MenuObjectId, BOOL bReread) { char menuItemName[256],MenuNameItems[256]; char buf[256]; FreeTreeData( hwndDlg ); TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_MENUITEMS)); int menupos = GetMenuObjbyId( MenuObjectId ); if ( menupos == -1 ) return FALSE; TIntMenuObject* pimo = g_menus[menupos]; if ( pimo->m_items.first == NULL ) return FALSE; mir_snprintf( MenuNameItems, sizeof(MenuNameItems), "%s_Items", pimo->Name ); int count = 0; { for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) if ( p->mi.root == ( HGENMENU )-1 || p->mi.root == NULL ) count++; } lpMenuItemOptData *PDar = ( lpMenuItemOptData* )mir_alloc( sizeof( lpMenuItemOptData )*count ); count = 0; { for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) { if ( p->mi.root != ( HGENMENU )-1 && p->mi.root != NULL ) continue; MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData )); GetMenuItemName( p, menuItemName, sizeof( menuItemName )); { DBVARIANT dbv; mir_snprintf(buf, SIZEOF(buf), "%s_name", menuItemName); if ( !DBGetContactSettingTString( NULL, MenuNameItems, buf, &dbv )) { PD->name = mir_tstrdup( dbv.ptszVal ); DBFreeVariant( &dbv ); } else PD->name = mir_tstrdup( p->mi.ptszName ); } PD->pimi = p; PD->defname = mir_tstrdup( p->mi.ptszName ); mir_snprintf( buf, SIZEOF(buf), "%s_visible", menuItemName ); PD->show = DBGetContactSettingByte( NULL, MenuNameItems, buf, 1 ); if ( bReread ) { mir_snprintf( buf, SIZEOF(buf), "%s_pos", menuItemName ); PD->pos = DBGetContactSettingDword( NULL, MenuNameItems, buf, 1 ); } else PD->pos = ( PD->pimi ) ? PD->pimi->originalPosition : 0; PD->id = p->iCommand; if ( p->UniqName ) PD->uniqname = mir_strdup( p->UniqName ); PDar[ count ] = PD; count++; } } qsort( PDar, count, sizeof( lpMenuItemOptData ), sortfunc ); SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0); int lastpos = 0; bool first = TRUE; TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; for ( int i=0; i < count; i++ ) { if ( PDar[i]->pos - lastpos >= SEPARATORPOSITIONINTERVAL ) { MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData )); PD->id = -1; PD->name = mir_tstrdup( STR_SEPARATOR ); PD->pos = PDar[i]->pos - 1; PD->show = TRUE; tvis.item.lParam = ( LPARAM )PD; tvis.item.pszText = PD->name; tvis.item.iImage = tvis.item.iSelectedImage = PD->show; SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); } tvis.item.lParam = ( LPARAM )PDar[i]; tvis.item.pszText = PDar[i]->name; tvis.item.iImage = tvis.item.iSelectedImage = PDar[i]->show; HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); if ( first ) { TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti); first=FALSE; } lastpos = PDar[i]->pos; } SendDlgItemMessage( hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0 ); mir_free( PDar ); ShowWindow( GetDlgItem( hwndDlg, IDC_NOTSUPPORTWARNING ),( pimo->m_bUseUserDefinedItems ) ? SW_HIDE : SW_SHOW ); EnableWindow( GetDlgItem( hwndDlg, IDC_MENUITEMS ), pimo->m_bUseUserDefinedItems ); EnableWindow( GetDlgItem( hwndDlg, IDC_INSERTSEPARATOR ), pimo->m_bUseUserDefinedItems ); return 1; }
//this function is called whenever the table link is clicked from the DB level void HandleClickTableURL(const wchar_t *url) { MDIWindow *wnd = NULL; HTREEITEM hitem = NULL; wyWChar buff[MAX_PATH] = {0}; TVITEM tvitem; wnd = GetActiveWin(); if(!wnd || !wnd->m_pcqueryobject) { return; } //switch the current selection image switch(wnd->m_pcqueryobject->GetSelectionImage()) { case NDATABASE: //get the selection hitem = TreeView_GetSelection(wnd->m_pcqueryobject->m_hwnd); if(hitem) { //expand and get the first child TreeView_Expand(wnd->m_pcqueryobject->m_hwnd, hitem, TVE_EXPAND); hitem = TreeView_GetChild(wnd->m_pcqueryobject->m_hwnd, hitem); } break; case NTABLES: //get the selection hitem = TreeView_GetSelection(wnd->m_pcqueryobject->m_hwnd); } if(!hitem) { return; } //expand the Tables folder TreeView_Expand(wnd->m_pcqueryobject->m_hwnd, hitem, TVE_EXPAND); //traverse through the tables for(hitem = TreeView_GetChild(wnd->m_pcqueryobject->m_hwnd, hitem); hitem; hitem = TreeView_GetNextSibling(wnd->m_pcqueryobject->m_hwnd, hitem)) { //get the item tvitem.hItem = hitem; tvitem.mask = TVIF_TEXT; buff[0] = 0; tvitem.pszText = buff; tvitem.cchTextMax = MAX_PATH - 1; TreeView_GetItem(wnd->m_pcqueryobject->m_hwnd, &tvitem); //compare the item with the url if(!wcscmp(url, tvitem.pszText)) { //set the selection; this will generate TVN_SELCHANGING and TVN_SELCHANGED messages TreeView_SelectItem(wnd->m_pcqueryobject->m_hwnd, hitem); break; } } if(!hitem) { MDIWindow *wnd = GetActiveWin(); yog_message(wnd->m_hwnd, PROMPT_MESSAGE, pGlobals->m_appname.GetAsWideChar(), MB_OK | MB_ICONINFORMATION); } return; }
BOOL CALLBACK PropDlg::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG: { /* set discription */ TCHAR szBuffer[256]; /* change language previously to avoid change of dynamic text*/ NLChangeDialog(_hInst, _hParent, _hSelf, _T("FavProp")); _stprintf(szBuffer, _T("%s:"), _pDesc); ::SetWindowText(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), szBuffer); /* if name is not defined extract from link */ _tcscpy(szBuffer, _pLink); if ((_pName[0] == '\0') && (szBuffer[0] != '\0')) { if (szBuffer[_tcslen(szBuffer)-1] == '\\') { szBuffer[_tcslen(szBuffer)-1] = '\0'; } if (szBuffer[_tcslen(szBuffer)-1] == ':') { _tcscpy(_pName, szBuffer); } else { _tcscpy(_pName, (_tcsrchr(szBuffer, '\\')+1)); } } /* set name and link */ ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_NAME), _pName); ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); SetFocus(::GetDlgItem(_hSelf, IDC_EDIT_NAME)); _hTreeCtrl = ::GetDlgItem(_hSelf, IDC_TREE_SELECT); goToCenter(); if (_linkDlg == LINK_DLG_NONE) { RECT rcName, rcLink; ::ShowWindow(::GetDlgItem(_hSelf, IDC_BTN_OPENDLG), SW_HIDE); ::GetWindowRect(::GetDlgItem(_hSelf, IDC_EDIT_NAME), &rcName); ::GetWindowRect(::GetDlgItem(_hSelf, IDC_EDIT_LINK), &rcLink); rcLink.right = rcName.right; ScreenToClient(_hSelf, &rcLink); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_EDIT_LINK), NULL, rcLink.left, rcLink.top, rcLink.right-rcLink.left, rcLink.bottom-rcLink.top, SWP_NOZORDER); } if (_seeDetails == FALSE) { RECT rc = {0}; ::DestroyWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT)); ::DestroyWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT)); ::DestroyWindow(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS)); /* resize window */ ::GetWindowRect(_hSelf, &rc); rc.top += 74; rc.bottom -= 74; /* resize window and keep sure to resize correct */ ::SetWindowPos(_hSelf, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); } else { /* get current icon offset */ UINT iIconPos = _pElem->uParam & FAVES_PARAM; /* set image list */ ::SendMessage(_hTreeCtrl, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)GetSmallImageList(FALSE)); HTREEITEM hItem = InsertItem(_pElem->pszName, iIconPos, _iUImgPos, 0, 0, TVI_ROOT, TVI_LAST, TRUE, (LPARAM)_pElem); TreeView_SelectItem(_hTreeCtrl, hItem); if (!NLGetText(_hInst, _hParent, _T("Details"), _szDetails, 20)) { _tcscpy(_szDetails, _T("Details %s")); } _stprintf(szBuffer, _szDetails, _T("<<")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); } break; } case WM_COMMAND : { switch (LOWORD(wParam)) { case IDC_BUTTON_DETAILS: { RECT rc = {0}; TCHAR szBuffer[20]; /* toggle visibility state */ _seeDetails ^= TRUE; /* resize window */ ::GetWindowRect(_hSelf, &rc); if (_seeDetails == FALSE) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT), SW_HIDE); ::ShowWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT), SW_HIDE); _stprintf(szBuffer, _szDetails, _T(">>")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); rc.bottom -= 148; } else { ::ShowWindow(::GetDlgItem(_hSelf, IDC_TREE_SELECT), SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDC_STATIC_SELECT), SW_SHOW); _stprintf(szBuffer, _szDetails, _T("<<")); ::SetWindowText(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), szBuffer); rc.bottom += 148; } ::SetWindowPos(_hSelf, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); break; } case IDC_BTN_OPENDLG: { if (_linkDlg == LINK_DLG_FOLDER) { // This code was copied and slightly modifed from: // http://www.bcbdev.com/faqs/faq62.htm // SHBrowseForFolder returns a PIDL. The memory for the PIDL is // allocated by the shell. Eventually, we will need to free this // memory, so we need to get a pointer to the shell malloc COM // object that will free the PIDL later on. LPMALLOC pShellMalloc = 0; if (::SHGetMalloc(&pShellMalloc) == NO_ERROR) { // If we were able to get the shell malloc object, // then proceed by initializing the BROWSEINFO stuct BROWSEINFO info; ZeroMemory(&info, sizeof(info)); info.hwndOwner = _hParent; info.pidlRoot = NULL; info.pszDisplayName = (LPTSTR)new TCHAR[MAX_PATH]; info.lpszTitle = _T("Select a folder:"); info.ulFlags = BIF_RETURNONLYFSDIRS; info.lpfn = BrowseCallbackProc; info.lParam = (LPARAM)_pLink; // Execute the browsing dialog. LPITEMIDLIST pidl = ::SHBrowseForFolder(&info); // pidl will be null if they cancel the browse dialog. // pidl will be not null when they select a folder. if (pidl) { // Try to convert the pidl to a display string. // Return is true if success. if (::SHGetPathFromIDList(pidl, _pLink)) { // Set edit control to the directory path. ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); } pShellMalloc->Free(pidl); } pShellMalloc->Release(); delete [] info.pszDisplayName; } } else { LPTSTR pszLink = NULL; FileDlg dlg(_hInst, _hParent); dlg.setDefFileName(_pLink); if (_tcsstr(_pDesc, _T("Session")) != NULL) dlg.setExtFilter(_T("Session file"), _T(".session"), NULL); dlg.setExtFilter(_T("All types"), _T(".*"), NULL); if (_fileMustExist == TRUE) { pszLink = dlg.doSaveDlg(); } else { pszLink = dlg.doOpenSingleFileDlg(); } if (pszLink != NULL) { // Set edit control to the directory path. _tcscpy(_pLink, pszLink); ::SetWindowText(::GetDlgItem(_hSelf, IDC_EDIT_LINK), _pLink); } } break; } case IDCANCEL: { ::EndDialog(_hSelf, FALSE); return TRUE; } case IDOK: { UINT lengthName = ::SendDlgItemMessage(_hSelf, IDC_EDIT_NAME, WM_GETTEXTLENGTH, 0, 0) + 1; UINT lengthLink = ::SendDlgItemMessage(_hSelf, IDC_EDIT_LINK, WM_GETTEXTLENGTH, 0, 0) + 1; SendDlgItemMessage(_hSelf, IDC_EDIT_NAME, WM_GETTEXT, lengthName, (LPARAM)_pName); SendDlgItemMessage(_hSelf, IDC_EDIT_LINK, WM_GETTEXT, lengthLink, (LPARAM)_pLink); if ((_tcslen(_pName) != 0) && (_tcslen(_pLink) != 0)) { TCHAR pszGroupName[MAX_PATH]; GetFolderPathName(TreeView_GetSelection(_hTreeCtrl), pszGroupName); _strGroupName = pszGroupName; ::EndDialog(_hSelf, TRUE); return TRUE; } else { if (NLMessageBox(_hInst, _hParent, _T("MsgBox AllFields"), MB_OK) == FALSE) ::MessageBox(_hParent, _T("Fill out all fields!"), _T("Error"), MB_OK); } break; } default: break; } break; } case WM_SIZE: { RECT rc = {0}; RECT rcMain = {0}; /* get main window size */ ::GetWindowRect(_hSelf, &rcMain); /* resize static box */ ::GetWindowRect(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), &rc); rc.bottom = rcMain.bottom - 46; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_STATIC_FAVES_DESC), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of OK button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDOK), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDOK), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of CANCEL button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDCANCEL), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDCANCEL), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); /* set position of DETAILS button */ ::GetWindowRect(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), &rc); rc.top = rcMain.bottom - 36; rc.bottom = rcMain.bottom - 12; ScreenToClient(_hSelf, &rc); ::SetWindowPos(::GetDlgItem(_hSelf, IDC_BUTTON_DETAILS), NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); break; } case WM_NOTIFY: { LPNMHDR nmhdr = (LPNMHDR)lParam; if (nmhdr->hwndFrom == _hTreeCtrl) { switch (nmhdr->code) { case TVN_ITEMEXPANDING: { DWORD dwpos = ::GetMessagePos(); TVHITTESTINFO ht; HTREEITEM hItem; ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos); ::ScreenToClient(_hTreeCtrl, &ht.pt); hItem = TreeView_HitTest(_hTreeCtrl, &ht); if (hItem != NULL) { if (!TreeView_GetChild(_hTreeCtrl, hItem)) { DrawChildrenOfItem(hItem); } } break; } case TVN_SELCHANGED: { /* only when link params are also viewed */ if (_bWithLink == TRUE) { HTREEITEM hItem = TreeView_GetSelection(_hTreeCtrl); if (hItem != NULL) { PELEM pElem = (PELEM)GetParam(hItem); if (pElem != NULL) { if (pElem->uParam & FAVES_PARAM_LINK) { ::SetDlgItemText(_hSelf, IDC_EDIT_NAME, pElem->pszName); ::SetDlgItemText(_hSelf, IDC_EDIT_LINK, pElem->pszLink); } else { ::SetDlgItemText(_hSelf, IDC_EDIT_NAME, _T("")); ::SetDlgItemText(_hSelf, IDC_EDIT_LINK, _T("")); } } } } break; } default: break; } } break; } case WM_DESTROY : { /* deregister this dialog */ ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (LPARAM)_hSelf); break; } default: break; } return FALSE; }
LRESULT CALLBACK TreeListWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { HWND TreeControl, HeaderControl, ToolTip; PTL_SUBITEMS newsubitems, subitems, *ppsubitems; TVHITTESTINFO lhti; LONG cx, headerheight; HANDLE hheap; ULONG i; RECT hr; LPTSTR s; NONCLIENTMETRICS ncm; HFONT font; LPNMHEADER hdr; SCROLLINFO scroll; TV_INSERTSTRUCT ins; size_t size; TVITEMEX item; LRESULT result; switch (uMsg) { case TVM_GETITEM: if (wParam == 0) return 0; item = *((LPTVITEMEX)wParam); ppsubitems = (PTL_SUBITEMS *)lParam; if (ppsubitems) item.mask |= TVIF_PARAM; result = SendMessage((HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT), TVM_GETITEM, 0, (LPARAM)&item); if (ppsubitems) { *ppsubitems = (PTL_SUBITEMS)item.lParam; item.lParam = 0; item.mask &= ~TVIF_PARAM; } *((LPTVITEMEX)wParam) = item; return result; case TVM_INSERTITEM: if (wParam == 0) return 0; hheap = (HANDLE)GetWindowLongPtr(hwnd, TL_HEAP_SLOT); if (!hheap) return 0; ins = *((LPTV_INSERTSTRUCT)wParam); if (lParam) { size = 0; subitems = (PTL_SUBITEMS)lParam; ins.item.mask |= TVIF_PARAM; for (i = 0; i < subitems->Count; i++) size += (_strlen(subitems->Text[i]) + 1) * sizeof(TCHAR); size += sizeof(TL_SUBITEMS) + (subitems->Count * sizeof(LPTSTR)); newsubitems = HeapAlloc(hheap, 0, size); if (!newsubitems) return 0; RtlSecureZeroMemory(newsubitems, size); newsubitems->ColorFlags = subitems->ColorFlags; newsubitems->BgColor = subitems->BgColor; newsubitems->FontColor = subitems->FontColor; newsubitems->Count = subitems->Count; s = (LPTSTR)((PBYTE)newsubitems + sizeof(TL_SUBITEMS) + (subitems->Count * sizeof(LPTSTR))); for (i = 0; i < subitems->Count; i++) { newsubitems->Text[i] = s; _strcpy(newsubitems->Text[i], subitems->Text[i]); s += _strlen(subitems->Text[i]) + 1; } ins.item.lParam = (LPARAM)newsubitems; } else ins.item.lParam = 0; result = SendMessage((HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT), TVM_INSERTITEM, 0, (LPARAM)&ins); TreeListUpdateTooltips(hwnd); return result; case HDM_INSERTITEM: return SendMessage((HWND)GetWindowLongPtr(hwnd, TL_HEADERCONTROL_SLOT), HDM_INSERTITEM, wParam, lParam); case TVM_GETNEXTITEM: return SendMessage((HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT), TVM_GETNEXTITEM, wParam, lParam); case TVM_DELETEITEM: if (lParam == (LPARAM)TVI_ROOT) { SendMessage((HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT), TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT); hheap = (HANDLE)GetWindowLongPtr(hwnd, TL_HEAP_SLOT); SetWindowLongPtr(hwnd, TL_HEAP_SLOT, 0); HeapDestroy(hheap); hheap = HeapCreate(0, 0, 0); if (hheap == NULL) return FALSE; SetWindowLongPtr(hwnd, TL_HEAP_SLOT, (LONG_PTR)hheap); SetWindowLongPtr(hwnd, TL_TOOLTIPSBUFFER_SLOT, (LONG_PTR)HeapAlloc(hheap, 0, TL_SIZEOF_PRIVATEBUFFER)); return TRUE; } break; case WM_CONTEXTMENU: TreeControl = (HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT); lhti.flags = 0; lhti.hItem = NULL; lhti.pt.x = GET_X_LPARAM(lParam); lhti.pt.y = GET_Y_LPARAM(lParam); ScreenToClient(TreeControl, &lhti.pt); TreeView_HitTest(TreeControl, &lhti); if (lhti.hItem) TreeView_SelectItem(TreeControl, lhti.hItem); return SendMessage(GetParent(hwnd), WM_CONTEXTMENU, wParam, lParam); case WM_NOTIFY: hdr = (LPNMHEADER)lParam; HeaderControl = (HWND)GetWindowLongPtr(hwnd, TL_HEADERCONTROL_SLOT); TreeControl = (HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT); if (hdr->hdr.hwndFrom == TreeControl) { switch (hdr->hdr.code) { case NM_CUSTOMDRAW: return TreeListCustomDraw(HeaderControl, (LPNMTVCUSTOMDRAW)lParam); case TVN_ITEMEXPANDED: if ((((LPNMTREEVIEW)lParam)->action == TVE_EXPAND) && (GetWindowLongPtr(hwnd, GWL_STYLE) & TLSTYLE_COLAUTOEXPAND)) TreeListAutoExpand(HeaderControl, (LPNMTREEVIEW)lParam); TreeListUpdateTooltips(hwnd); break; } /* break to DefWindowProc */ break; } if (hdr->hdr.hwndFrom == HeaderControl) { switch (hdr->hdr.code) { case HDN_ITEMCHANGED: TreeListHandleHeaderNotify(hwnd, TreeControl, HeaderControl); break; case HDN_ITEMCHANGING: if (((hdr->pitem->mask & HDI_WIDTH) != 0) && (hdr->iItem == 0) && (hdr->pitem->cxy < 120)) return TRUE; break; } } break; case WM_HSCROLL: TreeControl = (HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT); HeaderControl = (HWND)GetWindowLongPtr(hwnd, TL_HEADERCONTROL_SLOT); RtlSecureZeroMemory(&hr, sizeof(hr)); GetWindowRect(HeaderControl, &hr); headerheight = hr.bottom - hr.top; RtlSecureZeroMemory(&scroll, sizeof(scroll)); scroll.cbSize = sizeof(scroll); scroll.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_HORZ, &scroll); scroll.fMask = SIF_ALL; cx = scroll.nMax - scroll.nPage; switch (LOWORD(wParam)) { case SB_LINELEFT: scroll.nPos -= 16; break; case SB_LINERIGHT: scroll.nPos += 16; break; case SB_THUMBTRACK: scroll.nPos = scroll.nTrackPos; break; case SB_PAGELEFT: scroll.nPos -= cx; break; case SB_PAGERIGHT: scroll.nPos += cx; break; } if (scroll.nPos < 0) scroll.nPos = 0; if (scroll.nPos > cx) scroll.nPos = cx; SetScrollInfo(hwnd, SB_HORZ, &scroll, TRUE); SetWindowPos(HeaderControl, 0, -scroll.nPos, 0, 0, headerheight, SWP_NOSIZE | SWP_NOZORDER); GetClientRect(hwnd, &hr); MoveWindow(TreeControl, -scroll.nPos, headerheight, hr.right + scroll.nPos, hr.bottom - headerheight, TRUE); break; case WM_SETFOCUS: SetFocus((HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT)); break; case WM_SIZE: result = DefWindowProc(hwnd, uMsg, wParam, lParam); RtlSecureZeroMemory(&hr, sizeof(hr)); GetClientRect(hwnd, &hr); RtlSecureZeroMemory(&ncm, sizeof(ncm)); ncm.cbSize = sizeof(ncm) - sizeof(int); if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm) - sizeof(int), &ncm, 0)) { cx = ncm.iCaptionHeight; } else { cx = 20; } HeaderControl = (HWND)GetWindowLongPtr(hwnd, TL_HEADERCONTROL_SLOT); TreeControl = (HWND)GetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT); SetWindowPos(HeaderControl, NULL, 0, 0, hr.right, cx, SWP_NOMOVE); SetWindowPos(TreeControl, NULL, 0, 0, hr.right, hr.bottom - cx, SWP_NOMOVE); UpdateWindow(HeaderControl); UpdateWindow(TreeControl); return result; case WM_CREATE: hheap = HeapCreate(0, 0, 0); if (hheap == NULL) return -1; RtlSecureZeroMemory(&hr, sizeof(hr)); GetClientRect(hwnd, &hr); RtlSecureZeroMemory(&ncm, sizeof(ncm)); ncm.cbSize = sizeof(ncm) - sizeof(int); if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm) - sizeof(int), &ncm, 0)) { font = CreateFontIndirect(&ncm.lfMenuFont); cx = ncm.iCaptionHeight; } else { font = GetStockObject(DEFAULT_GUI_FONT); cx = 20; } HeaderControl = CreateWindowEx(0, WC_HEADER, NULL, WS_VISIBLE | WS_CHILD | HDS_FULLDRAG, 0, 0, hr.right, cx, hwnd, NULL, NULL, NULL); TreeControl = CreateWindowEx(0, WC_TREEVIEW, NULL, WS_VISIBLE | WS_CHILD | TVS_NOHSCROLL | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_FULLROWSELECT | TVS_NOTOOLTIPS | TVS_SHOWSELALWAYS, 0, cx, hr.right, hr.bottom - cx, hwnd, NULL, NULL, NULL); ToolTip = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, hwnd, NULL, NULL, NULL); SendMessage(ToolTip, TTM_SETDELAYTIME, TTDT_INITIAL, 0); SendMessage(ToolTip, TTM_SETDELAYTIME, TTDT_RESHOW, 0); /*hook*/ SetWindowLongPtr(hwnd, TL_TREEWNDPROC_SLOT, /*old wndproc here*/SetWindowLongPtr(TreeControl, GWLP_WNDPROC, (LONG_PTR)&TreeListHookProc)); SendMessage(TreeControl, TVM_SETEXTENDEDSTYLE, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER); SendMessage(HeaderControl, WM_SETFONT, (WPARAM)font, TRUE); SetWindowLongPtr(hwnd, TL_TREECONTROL_SLOT, (LONG_PTR)TreeControl); SetWindowLongPtr(hwnd, TL_HEADERCONTROL_SLOT, (LONG_PTR)HeaderControl); SetWindowLongPtr(hwnd, TL_HEAP_SLOT, (LONG_PTR)hheap); SetWindowLongPtr(hwnd, TL_TOOLTIPS_SLOT, (LONG_PTR)ToolTip); SetWindowLongPtr(hwnd, TL_TOOLTIPSBUFFER_SLOT, (LONG_PTR)HeapAlloc(hheap, 0, TL_SIZEOF_PRIVATEBUFFER)); if (tl_theme == NULL) tl_theme = OpenThemeData(TreeControl, VSCLASS_TREEVIEW); break; case WM_DESTROY: DestroyWindow((HWND)GetWindowLongPtr(hwnd, TL_TOOLTIPS_SLOT)); HeapDestroy((HANDLE)GetWindowLongPtr(hwnd, TL_HEAP_SLOT)); } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
static INT_PTR CALLBACK ButOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hTree = GetDlgItem(hwndDlg, IDC_BUTTONORDERTREE); OrderData *dat = (OrderData*)GetWindowLongPtr(hTree, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat = (OrderData*)malloc( sizeof(OrderData)); SetWindowLongPtr(hTree, GWLP_USERDATA, (LONG_PTR)dat); dat->dragging = 0; SetWindowLongPtr(hTree, GWL_STYLE, GetWindowLongPtr(hTree, GWL_STYLE)|TVS_NOHSCROLL); SetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, g_ctrl->nButtonHeight, FALSE); SendDlgItemMessage(hwndDlg, IDC_SPIN_HEIGHT, UDM_SETRANGE, 0, MAKELONG(50,10)); SendDlgItemMessage(hwndDlg, IDC_SPIN_HEIGHT, UDM_SETPOS, 0, MAKELONG(g_ctrl->nButtonHeight,0)); SetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, g_ctrl->nButtonWidth, FALSE); SendDlgItemMessage(hwndDlg, IDC_SPIN_WIDTH, UDM_SETRANGE, 0, MAKELONG(50,10)); SendDlgItemMessage(hwndDlg, IDC_SPIN_WIDTH, UDM_SETPOS, 0, MAKELONG(g_ctrl->nButtonWidth,0)); SetDlgItemInt(hwndDlg, IDC_BUTTGAP, g_ctrl->nButtonSpace, FALSE); SendDlgItemMessage(hwndDlg, IDC_SPIN_GAP, UDM_SETRANGE, 0, MAKELONG(20,0)); SendDlgItemMessage(hwndDlg, IDC_SPIN_GAP, UDM_SETPOS, 0, MAKELONG(g_ctrl->nButtonSpace,0)); CheckDlgButton(hwndDlg, IDC_USEFLAT, g_ctrl->bFlatButtons); CheckDlgButton(hwndDlg, IDC_AUTORESIZE, g_ctrl->bAutoSize); CheckDlgButton(hwndDlg, IDC_SINGLELINE, g_ctrl->bSingleLine); BuildTree(hwndDlg); EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_DELLBUTTON), FALSE); OptionshWnd = hwndDlg; return TRUE; case WM_COMMAND: if (HIWORD(wParam) == EN_CHANGE && OptionshWnd) { switch(LOWORD(wParam)) { case IDC_ENAME: case IDC_EPATH: break; default: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; } if ((HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DBLCLK)) { int ctrlid = LOWORD(wParam); //----- Launch buttons ----- if (ctrlid == IDC_BROWSE) { TCHAR str[MAX_PATH]; OPENFILENAME ofn = {0}; GetDlgItemText(hwndDlg, IDC_EPATH, str, sizeof(str)); ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.hwndOwner = hwndDlg; ofn.hInstance = NULL; ofn.lpstrFilter = NULL; ofn.lpstrFile = str; ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; ofn.nMaxFile = sizeof(str); ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrDefExt = _T("exe"); if (!GetOpenFileName(&ofn)) break; SetDlgItemText(hwndDlg, IDC_EPATH, str); break; } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); if (ctrlid == IDC_LBUTTONSET) { TVITEM tvi ={0}; tvi.hItem = TreeView_GetSelection(hTree); if (tvi.hItem == NULL) break; tvi.mask = TVIF_PARAM; TreeView_GetItem(hTree, &tvi); TopButtonInt* btn = (TopButtonInt*)tvi.lParam; TCHAR buf [256]; // probably, condition not needs if (btn->dwFlags & TTBBF_ISLBUTTON) { if (!(btn->dwFlags & TTBBF_OPTIONAL)) { // create button TTBButton ttb = { 0 }; ttb.cbSize = sizeof(ttb); ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_RUN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISLBUTTON | TTBBF_INTERNAL | TTBBF_OPTIONAL; ttb.name = NULL; ttb.program = NULL; int id = btn->id; btn = CreateButton(&ttb); btn->id = id; tvi.lParam = (LPARAM)btn; TreeView_SetItem(hTree, &tvi); } GetDlgItemText(hwndDlg, IDC_ENAME, buf, 255); replaceStr(btn->pszName, _T2A(buf)); tvi.mask = TVIF_TEXT; tvi.pszText = buf; TreeView_SetItem(hTree, &tvi); GetDlgItemText(hwndDlg, IDC_EPATH, buf, 255); replaceStrT(btn->ptszProgram, buf); } break; } if (ctrlid == IDC_ADDLBUTTON) { // create button TTBButton ttb = { 0 }; ttb.cbSize = sizeof(ttb); ttb.hIconDn = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_RUN), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISLBUTTON | TTBBF_INTERNAL | TTBBF_OPTIONAL; ttb.name = LPGEN("Default"); ttb.program = _T("Execute Path"); TopButtonInt* b = CreateButton(&ttb); // get selection for insert TVITEM tvi = {0}; tvi.hItem = TreeView_GetSelection(hTree); // insert item AddLine(hTree, b, tvi.hItem, dat->himlButtonIcons); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } //----- Separators ----- if (ctrlid == IDC_ADDSEP) { // create button TTBButton ttb = { 0 }; ttb.cbSize = sizeof(ttb); ttb.dwFlags = TTBBF_VISIBLE | TTBBF_ISSEPARATOR | TTBBF_INTERNAL | TTBBF_OPTIONAL; TopButtonInt* b = CreateButton(&ttb); // get selection for insert TVITEM tvi = {0}; tvi.hItem = TreeView_GetSelection(hTree); // insert item AddLine(hTree, b, tvi.hItem, dat->himlButtonIcons); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } if (ctrlid == IDC_REMOVEBUTTON) { TVITEM tvi = {0}; tvi.hItem = TreeView_GetSelection(hTree); if (tvi.hItem == NULL) break; tvi.mask = TVIF_PARAM; TreeView_GetItem(hTree, &tvi); TopButtonInt* btn = (TopButtonInt*)tvi.lParam; // if button enabled for separator and launch only, no need condition // except possible service button introducing if (btn->dwFlags & (TTBBF_ISSEPARATOR | TTBBF_ISLBUTTON)) { // delete if was added in options if (btn->dwFlags & TTBBF_OPTIONAL) delete btn; TreeView_DeleteItem(hTree,tvi.hItem); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; } } break; case WM_NOTIFY: switch(((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: g_ctrl->nButtonHeight = GetDlgItemInt(hwndDlg, IDC_BUTTHEIGHT, NULL, FALSE); g_ctrl->nButtonWidth = GetDlgItemInt(hwndDlg, IDC_BUTTWIDTH, NULL, FALSE); g_ctrl->nButtonSpace = GetDlgItemInt(hwndDlg, IDC_BUTTGAP, NULL, FALSE); g_ctrl->bFlatButtons = (BYTE)IsDlgButtonChecked(hwndDlg, IDC_USEFLAT); g_ctrl->bAutoSize = (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTORESIZE); g_ctrl->bSingleLine = (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SINGLELINE); db_set_dw(0, TTB_OPTDIR, "BUTTHEIGHT", g_ctrl->nButtonHeight); db_set_dw(0, TTB_OPTDIR, "BUTTWIDTH", g_ctrl->nButtonWidth); db_set_dw(0, TTB_OPTDIR, "BUTTGAP", g_ctrl->nButtonSpace); db_set_b(0, TTB_OPTDIR, "UseFlatButton", g_ctrl->bFlatButtons); db_set_b(0, TTB_OPTDIR, "SingleLine", g_ctrl->bSingleLine); db_set_b(0, TTB_OPTDIR, "AutoSize", g_ctrl->bAutoSize); SaveTree(hwndDlg); RecreateWindows(); ArrangeButtons(); } break; case IDC_BUTTONORDERTREE: switch (((LPNMHDR)lParam)->code) { case TVN_BEGINDRAGA: case TVN_BEGINDRAGW: SetCapture(hwndDlg); dat->dragging = 1; dat->hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem; TreeView_SelectItem(hTree, dat->hDragItem); break; case NM_CLICK: { TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(GetMessagePos()); hti.pt.y = (short)HIWORD(GetMessagePos()); ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) if (hti.flags & TVHT_ONITEMSTATEICON) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); TreeView_SelectItem(hTree, hti.hItem); } } break; case TVN_SELCHANGEDA: case TVN_SELCHANGEDW: { HTREEITEM hti = TreeView_GetSelection(hTree); if (hti == NULL) break; TopButtonInt *btn = (TopButtonInt*)((LPNMTREEVIEW)lParam)->itemNew.lParam; mir_cslock lck(csButtonsHook); if (btn->dwFlags & TTBBF_ISLBUTTON) { bool enable = (btn->dwFlags & TTBBF_INTERNAL) !=0; EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), enable); EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), enable); EnableWindow(GetDlgItem(hwndDlg, IDC_REMOVEBUTTON), enable); EnableWindow(GetDlgItem(hwndDlg, IDC_LBUTTONSET), enable); if (btn->pszName != NULL) SetDlgItemTextA(hwndDlg, IDC_ENAME, btn->pszName); else SetDlgItemTextA(hwndDlg, IDC_ENAME, ""); if (btn->ptszProgram != NULL) SetDlgItemText(hwndDlg, IDC_EPATH, btn->ptszProgram); else SetDlgItemTextA(hwndDlg, IDC_EPATH, ""); } else { EnableWindow(GetDlgItem(hwndDlg,IDC_REMOVEBUTTON), (btn->dwFlags & TTBBF_ISSEPARATOR)?TRUE:FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_ENAME), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_EPATH), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_LBUTTONSET), FALSE); SetDlgItemTextA(hwndDlg, IDC_ENAME, ""); SetDlgItemTextA(hwndDlg, IDC_EPATH, ""); } } } break; } break; case WM_MOUSEMOVE: if (dat->dragging) { TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hwndDlg, &hti.pt); ScreenToClient(hTree, &hti.pt); TreeView_HitTest(hTree, &hti); if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) { HTREEITEM it=hti.hItem; hti.pt.y -= TreeView_GetItemHeight(hTree)/2; TreeView_HitTest(hTree, &hti); if (!(hti.flags&TVHT_ABOVE)) TreeView_SetInsertMark(hTree,hti.hItem,1); else TreeView_SetInsertMark(hTree,it,0); } else { if (hti.flags & TVHT_ABOVE) SendMessage(hTree, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0); if (hti.flags & TVHT_BELOW) SendMessage(hTree, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0); TreeView_SetInsertMark(hTree, NULL, 0); } } break; case WM_LBUTTONUP: if (dat->dragging) { TreeView_SetInsertMark(hTree, NULL, 0); dat->dragging = 0; ReleaseCapture(); TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hwndDlg, &hti.pt); ScreenToClient(hTree, &hti.pt); hti.pt.y -= TreeView_GetItemHeight(hTree)/2; TreeView_HitTest(hTree, &hti); if (dat->hDragItem == hti.hItem) break; if (hti.flags&TVHT_ABOVE) hti.hItem=TVI_FIRST; TVITEM tvi; tvi.mask = TVIF_HANDLE|TVIF_PARAM; tvi.hItem = (HTREEITEM) dat->hDragItem; TreeView_GetItem(hTree, &tvi); if ( (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) || (hti.hItem==TVI_FIRST)) { TVINSERTSTRUCT tvis; TCHAR name[128]; tvis.item.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE; tvis.item.stateMask = 0xFFFFFFFF; tvis.item.pszText = name; tvis.item.cchTextMax = SIZEOF(name); tvis.item.hItem = dat->hDragItem; TreeView_GetItem(hTree, &tvis.item); TreeView_DeleteItem(hTree, dat->hDragItem); tvis.hParent = NULL; tvis.hInsertAfter = hti.hItem; TreeView_SelectItem(hTree, TreeView_InsertItem(hTree, &tvis)); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } break; case WM_DESTROY: if (dat) { ImageList_Destroy(dat->himlButtonIcons); free(dat); } OptionshWnd = NULL; break; } return FALSE; }
static LRESULT CALLBACK MsgTreeSubclassProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { CMsgTree *dat = CWndUserData(GetParent(hWnd)).GetMsgTree(); switch (Msg) { case UM_MSGTREE_UPDATE: // returns TRUE if updated { bool Modified = dat->MsgTreePage.GetModified(); TCString WndTitle; if (Modified) { WndTitle.GetBuffer(256); HWND hCurWnd = hWnd; do { hCurWnd = GetParent(hCurWnd); } while (hCurWnd && !GetWindowText(hCurWnd, WndTitle, 256)); WndTitle.ReleaseBuffer(); } if (!Modified || MessageBox(GetParent(hWnd), TCString(TranslateT("You've made changes to multiple Message trees at a time.\r\nDo you want to leave changes in \"")) + WndTitle + TranslateT("\" dialog?\r\nPress Yes to leave changes in this dialog, or No to discard its changes and save changes of the other Message tree instead."), WndTitle + _T(" - ") + TranslateT("New Away System"), MB_ICONQUESTION | MB_YESNO) == IDNO) { COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); TCString OldTitle, OldMsg, NewTitle, NewMsg; int OldOrder = TreeCtrl->IDToOrder(TreeCtrl->GetSelectedItemID(GetParent(hWnd))); if (OldOrder != -1) { CBaseTreeItem* ItemOld = (OldOrder <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(OldOrder)] : (CBaseTreeItem*)&TreeCtrl->Value[OldOrder]; OldTitle = ItemOld->Title; if (!(ItemOld->Flags & TIF_ROOTITEM)) { OldMsg = ((CTreeItem*)ItemOld)->User_Str1; } } dat->UpdateLock++; dat->MsgTreePage.DBToMemToPage(); dat->UpdateLock--; NMMSGTREE nm = {0}; int Order = TreeCtrl->IDToOrder(TreeCtrl->GetSelectedItemID(GetParent(hWnd))); if (Order != -1) { nm.ItemNew = (Order <= TREECTRL_ROOTORDEROFFS) ? (CBaseTreeItem*)&TreeCtrl->RootItems[ROOT_ORDER_TO_INDEX(Order)] : (CBaseTreeItem*)&TreeCtrl->Value[Order]; NewTitle = nm.ItemNew->Title; if (!(nm.ItemNew->Flags & TIF_ROOTITEM)) { NewMsg = ((CTreeItem*)nm.ItemNew)->User_Str1; } } if (OldTitle.IsEmpty()) { OldTitle = _T(""); // to be sure that NULL will be equal to "" in the latter comparisons } if (OldMsg.IsEmpty()) { OldMsg = _T(""); } if (NewTitle.IsEmpty()) { NewTitle = _T(""); } if (NewMsg.IsEmpty()) { NewMsg = _T(""); } if (OldTitle != (const TCHAR*)NewTitle || OldMsg != (const TCHAR*)NewMsg) { // probably it's better to leave nm.ItemOld = NULL, to prevent accidental rewriting of it with old data from an edit control etc. nm.hdr.code = MTN_SELCHANGED; nm.hdr.hwndFrom = hWnd; nm.hdr.idFrom = GetDlgCtrlID(hWnd); SendMessage(GetParent(hWnd), WM_NOTIFY, 0, (LPARAM)&nm); } return true; } return false; } break; case WM_KEYDOWN: { switch (wParam) { case VK_DELETE: { dat->DeleteSelectedItem(); } break; case VK_INSERT: { dat->AddMessage(); } break; } } break; case WM_RBUTTONDOWN: { SetFocus(hWnd); TVHITTESTINFO hitTest; hitTest.pt.x = (short)LOWORD(lParam); hitTest.pt.y = (short)HIWORD(lParam); TreeView_HitTest(hWnd, &hitTest); if (hitTest.hItem && hitTest.flags & TVHT_ONITEM) { TreeView_SelectItem(hWnd, hitTest.hItem); } return DefWindowProc(hWnd, Msg, wParam, lParam); } break; case WM_CONTEXTMENU: { TVHITTESTINFO ht; ht.pt.x = (short)LOWORD(lParam); ht.pt.y = (short)HIWORD(lParam); TVITEM tvi = {0}; if (ht.pt.x == -1 && ht.pt.y == -1) // use selected item { if (tvi.hItem = TreeView_GetSelection(hWnd)) { TreeView_EnsureVisible(hWnd, tvi.hItem); RECT rc; TreeView_GetItemRect(hWnd, tvi.hItem, &rc, true); ht.pt.x = rc.left; ht.pt.y = rc.bottom; } } else { ScreenToClient(hWnd, &ht.pt); TreeView_HitTest(hWnd, &ht); if (ht.hItem && ht.flags & TVHT_ONITEM) { tvi.hItem = ht.hItem; } } if (tvi.hItem) { COptItem_TreeCtrl *TreeCtrl = dat->GetTreeCtrl(); tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(hWnd, &tvi); int Order = TreeCtrl->IDToOrder(tvi.lParam); if (Order >= 0) { HMENU hMenu; if (TreeCtrl->Value[Order].Flags & TIF_GROUP) { hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_CATEGORYMENU)); } else { hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MSGTREE_MESSAGEMENU)); } _ASSERT(hMenu); HMENU hPopupMenu = GetSubMenu(hMenu, 0); TranslateMenu(hPopupMenu); ClientToScreen(hWnd, &ht.pt); struct { int ItemID, IconID; } MenuItems[] = { IDM_MSGTREEMENU_NEWMESSAGE, IMGLIST_NEWMESSAGE, IDM_MSGTREEMENU_NEWCATEGORY, IMGLIST_NEWCATEGORY, IDM_MSGTREEMENU_DELETE, IMGLIST_DELETE }; MENUITEMINFO mii = {0}; mii.cbSize = sizeof(mii); mii.fMask = MIIM_BITMAP | MIIM_DATA | MIIM_STATE | MIIM_CHECKMARKS; mii.hbmpItem = HBMMENU_CALLBACK; int I; for (I = 0; I < lengthof(MenuItems); I++) // set icons { mii.dwItemData = MenuItems[I].IconID; SetMenuItemInfo(hPopupMenu, MenuItems[I].ItemID, false, &mii); } mii.fMask = MIIM_STATE; mii.fState = MFS_CHECKED; for (I = 0; I < lengthof(StatusModeList); I++) // set checkmarks { if (TreeCtrl->Value[Order].ID == dat->MsgTreePage.GetValue(StatusModeList[I].DBSetting)) { SetMenuItemInfo(hPopupMenu, StatusModeList[I].MenuItemID, false, &mii); } } int MenuResult = TrackPopupMenu(hPopupMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, ht.pt.x, ht.pt.y, 0, hWnd, NULL); switch (MenuResult) { case IDM_MSGTREEMENU_NEWMESSAGE: { dat->AddMessage(); } break; case IDM_MSGTREEMENU_NEWCATEGORY: { dat->AddCategory(); } break; case IDM_MSGTREEMENU_RENAME: { TreeView_EditLabel(hWnd, tvi.hItem); } break; case IDM_MSGTREEMENU_DELETE: { dat->DeleteSelectedItem(); } break; case IDR_MSGTREEMENU_DEF_ONL: case IDR_MSGTREEMENU_DEF_AWAY: case IDR_MSGTREEMENU_DEF_NA: case IDR_MSGTREEMENU_DEF_OCC: case IDR_MSGTREEMENU_DEF_DND: case IDR_MSGTREEMENU_DEF_FFC: case IDR_MSGTREEMENU_DEF_INV: case IDR_MSGTREEMENU_DEF_OTP: case IDR_MSGTREEMENU_DEF_OTL: { int I; for (I = 0; I < lengthof(StatusModeList); I++) { if (StatusModeList[I].MenuItemID == MenuResult) { dat->SetDefMsg(StatusModeList[I].Status, tvi.lParam); break; } } } break; } DestroyMenu(hMenu); return 0; } } } break; case WM_MEASUREITEM: { LPMEASUREITEMSTRUCT lpmi = (LPMEASUREITEMSTRUCT)lParam; if (lpmi->CtlType == ODT_MENU) { lpmi->itemWidth = max(0, GetSystemMetrics(SM_CXSMICON) - GetSystemMetrics(SM_CXMENUCHECK) + 4); lpmi->itemHeight = GetSystemMetrics(SM_CYSMICON) + 2; return true; } } break; case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->CtlType == ODT_MENU) { ImageList_DrawEx(dat->hImageList, dis->itemData, dis->hDC, 2, (dis->rcItem.bottom + dis->rcItem.top - GetSystemMetrics(SM_CYSMICON)) / 2 + 1, 0, 0, GetSysColor(COLOR_WINDOW), CLR_NONE, ILD_NORMAL); return true; } } break; } return CallWindowProc(dat->OrigTreeViewProc, hWnd, Msg, wParam, lParam); }
BOOL CDeviceView::ListDevicesByType() { HTREEITEM hDevItem = NULL; GUID ClassGuid; WCHAR ClassName[CLASS_NAME_LEN]; WCHAR ClassDescription[CLASS_DESC_LEN]; INT ClassIndex; INT ClassImage; LPTSTR DeviceId = NULL; BOOL bSuccess; /* Get the details of the root of the device tree */ bSuccess = m_Devices->GetDeviceTreeRoot(ClassName, CLASS_NAME_LEN, &ClassImage); if (bSuccess) { /* Add the root of the device tree to the treeview */ m_hTreeRoot = InsertIntoTreeView(NULL, ClassName, NULL, ClassImage, 0); } /* If something went wrong, bail */ if (m_hTreeRoot == NULL) return FALSE; ClassIndex = 0; do { /* Get the next device class */ bSuccess = m_Devices->EnumClasses(ClassIndex, &ClassGuid, ClassName, CLASS_NAME_LEN, ClassDescription, CLASS_DESC_LEN, &ClassImage); if (bSuccess) { BOOL bDevSuccess, AddedParent; HANDLE Handle = NULL; WCHAR DeviceName[DEVICE_NAME_LEN]; INT DeviceIndex = 0; BOOL MoreItems = FALSE; BOOL DeviceHasProblem = FALSE; ULONG DeviceStatus = 0; ULONG ProblemNumber = 0; ULONG OverlayImage = 0; AddedParent = FALSE; do { /* Enum all the devices that belong to this class */ bDevSuccess = m_Devices->EnumDevicesForClass(&Handle, &ClassGuid, DeviceIndex, &MoreItems, DeviceName, DEVICE_NAME_LEN, &DeviceId, &DeviceStatus, &ProblemNumber); if (bDevSuccess) { /* Check if this is a hidden device */ if (DeviceStatus & DN_NO_SHOW_IN_DM) { if (m_ShowHidden == FALSE) { DeviceIndex++; continue; } } /* Check if the device has a problem */ if (DeviceStatus & DN_HAS_PROBLEM) { DeviceHasProblem = TRUE; OverlayImage = 1; } /* The disabled overlay takes precidence over the problem overlay */ if (ProblemNumber == CM_PROB_HARDWARE_DISABLED) { OverlayImage = 2; } /* We have a device, we're gonna need to add the parent first */ if (AddedParent == FALSE) { /* Insert the new class under the root item */ hDevItem = InsertIntoTreeView(m_hTreeRoot, ClassDescription, NULL, ClassImage, 0); /* Don't add it again */ AddedParent = TRUE; } /* Add the device under the class item */ (VOID)InsertIntoTreeView(hDevItem, DeviceName, (LPARAM)DeviceId, ClassImage, OverlayImage); /* Check if there's a problem with the device */ if (DeviceHasProblem) { /* Expand the class */ (VOID)TreeView_Expand(m_hTreeView, hDevItem, TVE_EXPAND); } } DeviceIndex++; } while (MoreItems); /* Check if this class has any devices */ if (AddedParent == TRUE) { /* Sort the devices alphabetically */ (VOID)TreeView_SortChildren(m_hTreeView, hDevItem, 0); } } ClassIndex++; } while (bSuccess); /* Sort the classes alphabetically */ (VOID)TreeView_SortChildren(m_hTreeView, m_hTreeRoot, 0); /* Expand the root item */ (VOID)TreeView_Expand(m_hTreeView, m_hTreeRoot, TVE_EXPAND); /* Pre-select the root item */ (VOID)TreeView_SelectItem(m_hTreeView, m_hTreeRoot); return 0; }
static LRESULT OnNotify(PMAIN_WND_INFO Info, LPARAM lParam) { LPNMHDR pnmhdr = (LPNMHDR)lParam; LRESULT ret = 0; switch (pnmhdr->code) { case TVN_SELCHANGED: { LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW)lParam; if (Info->Display == DevicesByType) { if (!TreeView_GetChild(Info->hTreeView, pnmtv->itemNew.hItem)) { SendMessage(Info->hTool, TB_SETSTATE, IDC_PROP, (LPARAM)MAKELONG(TBSTATE_ENABLED, 0)); EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED); EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED); } else { SendMessage(Info->hTool, TB_SETSTATE, IDC_PROP, (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0)); EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED); EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED); } } else if (Info->Display == DevicesByConnection) { if (pnmtv->itemNew.hItem == TreeView_GetRoot(Info->hTreeView)) { SendMessage(Info->hTool, TB_SETSTATE, IDC_PROP, (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0)); EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED); EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED); } else { SendMessage(Info->hTool, TB_SETSTATE, IDC_PROP, (LPARAM)MAKELONG(TBSTATE_ENABLED, 0)); EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_ENABLED); EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_ENABLED); } } } break; case NM_DBLCLK: { HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView); TV_HITTESTINFO HitTest; if (Info->Display == DevicesByType) { if (!TreeView_GetChild(Info->hTreeView, hSelected)) { if (GetCursorPos(&HitTest.pt) && ScreenToClient(Info->hTreeView, &HitTest.pt)) { if (TreeView_HitTest(Info->hTreeView, &HitTest)) { if (HitTest.hItem == hSelected) { OpenPropSheet(Info->hTreeView, hSelected); ret = TRUE; } } } } } else if (Info->Display == DevicesByConnection) { if (hSelected != TreeView_GetRoot(Info->hTreeView)) { if (GetCursorPos(&HitTest.pt) && ScreenToClient(Info->hTreeView, &HitTest.pt)) { if (TreeView_HitTest(Info->hTreeView, &HitTest)) { if (HitTest.hItem == hSelected) { OpenPropSheet(Info->hTreeView, hSelected); ret = TRUE; } } } } } } break; case NM_RCLICK: { TV_HITTESTINFO HitTest; if (GetCursorPos(&HitTest.pt) && ScreenToClient(Info->hTreeView, &HitTest.pt)) { if (TreeView_HitTest(Info->hTreeView, &HitTest)) (void)TreeView_SelectItem(Info->hTreeView, HitTest.hItem); } } break; case TTN_GETDISPINFO: { LPTOOLTIPTEXT lpttt; UINT idButton; lpttt = (LPTOOLTIPTEXT)lParam; idButton = (UINT)lpttt->hdr.idFrom; switch (idButton) { case IDC_PROP: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP); break; case IDC_REFRESH: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH); break; case IDC_PROGHELP: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP); break; case IDC_EXIT: lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT); break; } } break; } return ret; }
INT_PTR CALLBACK AddCustomFileDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_INITDIALOG: { CenterWindow(hDlg); hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MAMEUI_ICON)); SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); hBrush = CreateSolidBrush(RGB(240, 240, 240)); if (IsWindowsSevenOrHigher()) SendMessage(GetDlgItem(hDlg, IDC_CUSTOM_TREE), TVM_SETEXTENDEDSTYLE, TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER); SetWindowTheme(GetDlgItem(hDlg, IDC_CUSTOM_TREE), L"Explorer", NULL); TREEFOLDER **folders; int num_folders = 0; TVINSERTSTRUCT tvis; TVITEM tvi; bool first_entry = true; HIMAGELIST treeview_icons = GetTreeViewIconList(); // current game passed in using DialogBoxParam() driver_index = lParam; (void)TreeView_SetImageList(GetDlgItem(hDlg, IDC_CUSTOM_TREE), treeview_icons, LVSIL_NORMAL); GetFolders(&folders, &num_folders); // insert custom folders into our tree view for (int i = 0; i < num_folders; i++) { if (folders[i]->m_dwFlags & F_CUSTOM) { HTREEITEM hti; if (folders[i]->m_nParent == -1) { memset(&tvi, 0, sizeof(TVITEM)); tvis.hParent = TVI_ROOT; tvis.hInsertAfter = TVI_SORT; tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.pszText = folders[i]->m_lptTitle; tvi.lParam = (LPARAM)folders[i]; tvi.iImage = GetTreeViewIconIndex(folders[i]->m_nIconId); tvi.iSelectedImage = 0; tvis.item = tvi; hti = TreeView_InsertItem(GetDlgItem(hDlg, IDC_CUSTOM_TREE), &tvis); /* look for children of this custom folder */ for (int jj = 0; jj < num_folders; jj++) { if (folders[jj]->m_nParent == i) { HTREEITEM hti_child; tvis.hParent = hti; tvis.hInsertAfter = TVI_SORT; tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.pszText = folders[jj]->m_lptTitle; tvi.lParam = (LPARAM)folders[jj]; tvi.iImage = GetTreeViewIconIndex(folders[jj]->m_nIconId); tvi.iSelectedImage = 0; tvis.item = tvi; hti_child = TreeView_InsertItem(GetDlgItem(hDlg, IDC_CUSTOM_TREE), &tvis); if (folders[jj] == default_selection) (void)TreeView_SelectItem(GetDlgItem(hDlg, IDC_CUSTOM_TREE), hti_child); } } /*TreeView_Expand(GetDlgItem(hDlg,IDC_CUSTOM_TREE),hti,TVE_EXPAND);*/ if (first_entry || folders[i] == default_selection) { (void)TreeView_SelectItem(GetDlgItem(hDlg, IDC_CUSTOM_TREE),hti); first_entry = false; } } } } win_set_window_text_utf8(GetDlgItem(hDlg, IDC_CUSTOMFILE_GAME), GetDriverGameTitle(driver_index)); return true; } case WM_CTLCOLORDLG: return (LRESULT) hBrush; case WM_CTLCOLORSTATIC: case WM_CTLCOLORBTN: hDC = (HDC)wParam; SetBkMode(hDC, TRANSPARENT); SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); return (LRESULT) hBrush; case WM_COMMAND: switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: { TVITEM tvi; tvi.hItem = TreeView_GetSelection(GetDlgItem(hDlg, IDC_CUSTOM_TREE)); tvi.mask = TVIF_PARAM; if (TreeView_GetItem(GetDlgItem(hDlg, IDC_CUSTOM_TREE),&tvi) == true) { /* should look for New... */ default_selection = (LPTREEFOLDER)tvi.lParam; /* start here next time */ AddToCustomFolder((LPTREEFOLDER)tvi.lParam, driver_index); } DestroyIcon(hIcon); DeleteObject(hBrush); EndDialog(hDlg, 0); return true; } case IDCANCEL: DestroyIcon(hIcon); DeleteObject(hBrush); EndDialog(hDlg, 0); return true; } break; } return false; }
INT_PTR CALLBACK DlgProcToolBar(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HTREEITEM hti; switch (uMsg) { case WM_INITDIALOG: hToolBarTree = GetDlgItem(hwndDlg, IDC_TOOLBARTREE); { LONG_PTR style = GetWindowLongPtr(hToolBarTree, GWL_STYLE); style ^= TVS_CHECKBOXES; SetWindowLongPtr(hToolBarTree, GWL_STYLE, style); style |= TVS_CHECKBOXES; style |= TVS_NOHSCROLL; SetWindowLongPtr(hToolBarTree, GWL_STYLE, style); } { mir_cslock lck(ToolBarCS); BuildMenuObjectsTree(hToolBarTree); } Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE); SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 0)); SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_SETPOS, 0, MAKELONG(PluginConfig.g_iButtonsBarGap, 0)); TranslateDialogDefault(hwndDlg); bOptionsInit = FALSE; break; case WM_LBUTTONUP: if (drag) { TreeView_SetInsertMark(hToolBarTree, NULL, 0); drag = 0; ReleaseCapture(); TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hwndDlg, &hti.pt); ScreenToClient(hToolBarTree, &hti.pt); hti.pt.y -= TreeView_GetItemHeight(hToolBarTree) / 2; TreeView_HitTest(hToolBarTree, &hti); if (hDragItem == hti.hItem) break; if (hti.flags & TVHT_ABOVE) hti.hItem = TVI_FIRST; TVITEM tvi; tvi.mask = TVIF_HANDLE | TVIF_PARAM; tvi.hItem = (HTREEITEM)hDragItem; TreeView_GetItem(hToolBarTree, &tvi); if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT) || (hti.hItem == TVI_FIRST)) { TVINSERTSTRUCT tvis; TCHAR strbuf[128]; tvis.item.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE; tvis.item.stateMask = 0xFFFFFFFF; tvis.item.pszText = strbuf; tvis.item.cchTextMax = sizeof(strbuf); tvis.item.hItem = (HTREEITEM)hDragItem; TreeView_GetItem(hToolBarTree, &tvis.item); TreeView_DeleteItem(hToolBarTree, hDragItem); tvis.hParent = NULL; tvis.hInsertAfter = hti.hItem; TreeView_SelectItem(hToolBarTree, TreeView_InsertItem(hToolBarTree, &tvis)); SendMessage((GetParent(hwndDlg)), PSM_CHANGED, 0, 0); } } break; case WM_MOUSEMOVE: if (drag) { TVHITTESTINFO hti; hti.pt.x = (short)LOWORD(lParam); hti.pt.y = (short)HIWORD(lParam); ClientToScreen(hwndDlg, &hti.pt); ScreenToClient(hToolBarTree, &hti.pt); TreeView_HitTest(hToolBarTree, &hti); if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) { HTREEITEM it = hti.hItem; hti.pt.y -= TreeView_GetItemHeight(hToolBarTree) / 2; TreeView_HitTest(hToolBarTree, &hti); if (!(hti.flags & TVHT_ABOVE)) TreeView_SetInsertMark(hToolBarTree, hti.hItem, 1); else TreeView_SetInsertMark(hToolBarTree, it, 0); } else { if (hti.flags & TVHT_ABOVE) SendMessage(hToolBarTree, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0); if (hti.flags & TVHT_BELOW) SendMessage(hToolBarTree, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0); TreeView_SetInsertMark(hToolBarTree, NULL, 0); } } break; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam && (HWND)lParam != hToolBarTree) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); if ((HIWORD(wParam) == EN_CHANGE) && ((HWND)lParam == GetFocus())) if (!bOptionsInit) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); switch (LOWORD(wParam)) { case IDC_BBRESET: CallService(MS_DB_MODULE_DELETE, NULL, LPARAM("TabSRMM_Toolbar")); CB_HardReInit(); BuildMenuObjectsTree(hToolBarTree); break; case IDC_SEPARATOR: hti = TreeView_GetSelection(hToolBarTree); if (!hti) hti = TVI_FIRST; CustomButtonData *cbd = new CustomButtonData(); cbd->bSeparator = cbd->bHidden = cbd->bIMButton = cbd->bLSided = true; cbd->dwButtonOrigID = ++dwSepCount; cbd->pszModuleName = "Tabsrmm_sep"; cbd->iButtonWidth = 22; cbd->opFlags = BBSF_NTBDESTRUCT; LButtonsList.insert(cbd); TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = hti; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvis.item.pszText = TranslateT("<Separator>"); tvis.item.iImage = tvis.item.iSelectedImage = -1; tvis.item.lParam = (LPARAM)cbd; hti = TreeView_InsertItem(hToolBarTree, &tvis); TreeView_SetCheckState(hToolBarTree, hti, (cbd->bIMButton || cbd->bChatButton)); } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_RESET: CB_ReInitCustomButtons(); dwSepCount = M.GetDword("TabSRMM_Toolbar", "SeparatorsCount", 0); return 1; case PSN_APPLY: hti = TreeView_GetSelection(hToolBarTree); if (hti) { TVITEM tvi; tvi.mask = TVIF_HANDLE | TVIF_PARAM; tvi.hItem = hti; TreeView_GetItem(hToolBarTree, &tvi); if (tvi.lParam) { CustomButtonData *cbd = (CustomButtonData*)tvi.lParam; if (cbd) { cbd->bIMButton = IsDlgButtonChecked(hwndDlg, IDC_IMCHECK) != 0; cbd->bChatButton = IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK) != 0; cbd->bCanBeHidden = IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN) != 0; } } } SaveTree(hToolBarTree); CB_ReInitCustomButtons(); PluginConfig.g_iButtonsBarGap = (BYTE)SendDlgItemMessage(hwndDlg, IDC_SPIN1, UDM_GETPOS, 0, 0); if (PluginConfig.g_iButtonsBarGap != M.GetByte("ButtonsBarGap", 1)) M.BroadcastMessageAsync(WM_SIZE, 0, 0); db_set_b(0, SRMSGMOD_T, "ButtonsBarGap", PluginConfig.g_iButtonsBarGap); BuildMenuObjectsTree((HWND)hToolBarTree); Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE); return 1; } break; case IDC_TOOLBARTREE: switch (((LPNMHDR)lParam)->code) { case TVN_BEGINDRAGA: case TVN_BEGINDRAGW: SetCapture(hwndDlg); drag = 1; hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem; TreeView_SelectItem(hToolBarTree, hDragItem); break; case TVN_SELCHANGINGA: case TVN_SELCHANGINGW: hti = TreeView_GetSelection(hToolBarTree); if (hti != NULL) { TCHAR strbuf[128]; TVITEM tvi; tvi.hItem = hti; tvi.pszText = strbuf; tvi.cchTextMax = sizeof(strbuf); tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(hToolBarTree, &tvi); if (tvi.lParam == 0 || !TreeView_GetCheckState(hToolBarTree, tvi.hItem) || !_tcscmp(tvi.pszText, MIDDLE_SEPARATOR)) break; CustomButtonData *cbd = (CustomButtonData*)tvi.lParam; if (cbd) { cbd->opFlags = (IsDlgButtonChecked(hwndDlg, IDC_IMCHECK)) ? BBSF_IMBUTTON : 0; cbd->opFlags |= (IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK)) ? BBSF_CHATBUTTON : 0; cbd->opFlags |= (IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN)) ? BBSF_CANBEHIDDEN : 0; cbd->bIMButton = (IsDlgButtonChecked(hwndDlg, IDC_IMCHECK) ? TRUE : FALSE); cbd->bChatButton = (IsDlgButtonChecked(hwndDlg, IDC_CHATCHECK) ? TRUE : FALSE); cbd->bCanBeHidden = (IsDlgButtonChecked(hwndDlg, IDC_CANBEHIDDEN) ? TRUE : FALSE); } } break; case TVN_SELCHANGEDW: case TVN_SELCHANGEDA: hti = TreeView_GetSelection(hToolBarTree); if (hti != NULL) { TCHAR strbuf[128]; TVITEM tvi; tvi.pszText = strbuf; tvi.cchTextMax = sizeof(strbuf); tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM; tvi.hItem = hti; TreeView_GetItem(hToolBarTree, &tvi); if (!TreeView_GetCheckState(hToolBarTree, tvi.hItem) || !_tcscmp(tvi.pszText, MIDDLE_SEPARATOR)) { Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE); break; } if (tvi.lParam == 0) break; CustomButtonData *cbd = (CustomButtonData*)tvi.lParam; if (cbd) { Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, TRUE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, TRUE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, TRUE); CheckDlgButton(hwndDlg, IDC_IMCHECK, (cbd->bIMButton) ? 1 : 0); CheckDlgButton(hwndDlg, IDC_CHATCHECK, (cbd->bChatButton) ? 1 : 0); CheckDlgButton(hwndDlg, IDC_CANBEHIDDEN, (cbd->bCanBeHidden) ? 1 : 0); } } break; case NM_CLICK: TVHITTESTINFO hti = { 0 }; GetCursorPos(&hti.pt); ScreenToClient(hToolBarTree, &hti.pt); if (TreeView_HitTest(hToolBarTree, &hti)) { if (hti.flags&TVHT_ONITEMSTATEICON) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0); if (TreeView_GetCheckState(hToolBarTree, hti.hItem)) { Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, FALSE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, FALSE); CheckDlgButton(hwndDlg, IDC_IMCHECK, 1); } else { Utils::enableDlgControl(hwndDlg, IDC_IMCHECK, TRUE); Utils::enableDlgControl(hwndDlg, IDC_CHATCHECK, TRUE); Utils::enableDlgControl(hwndDlg, IDC_CANBEHIDDEN, TRUE); } TreeView_SelectItem(hToolBarTree, hti.hItem); } } } } break; case WM_DESTROY: HIMAGELIST hIml = TreeView_GetImageList(GetDlgItem(hwndDlg, IDC_TOOLBARTREE), TVSIL_NORMAL); ImageList_Destroy(hIml); hIml = TreeView_GetImageList(GetDlgItem(hwndDlg, IDC_TOOLBARTREE), TVSIL_STATE); ImageList_Destroy(hIml); break; } return FALSE; }
INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct IcoLibOptsData *dat; static HTREEITEM prevItem = 0; static HWND hPreview = NULL; dat = (struct IcoLibOptsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); hPreview = GetDlgItem(hwndDlg, IDC_PREVIEW); dat = (struct IcoLibOptsData*)mir_alloc(sizeof(struct IcoLibOptsData)); dat->hwndIndex = NULL; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); // // Reset temporary data & upload sections list // { mir_cslock lck(csIconList); for (int indx = 0; indx < iconList.getCount(); indx++) { iconList[indx]->temp_file = NULL; iconList[indx]->temp_icon = NULL; iconList[indx]->temp_reset = FALSE; } bNeedRebuild = FALSE; } // // Setup preview listview // ListView_SetUnicodeFormat(hPreview, TRUE); ListView_SetExtendedListViewStyleEx(hPreview, LVS_EX_INFOTIP, LVS_EX_INFOTIP); ListView_SetImageList(hPreview, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 0, 30), LVSIL_NORMAL); ListView_SetIconSpacing(hPreview, 56, 67); SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0); return TRUE; case DM_REBUILD_CTREE: { HWND hwndTree = GetDlgItem(hwndDlg, IDC_CATEGORYLIST); int indx; TCHAR itemName[1024]; HTREEITEM hSection; if (!hwndTree) break; TreeView_SelectItem(hwndTree, NULL); TreeView_DeleteAllItems(hwndTree); for (indx = 0; indx < sectionList.getCount(); indx++) { TCHAR* sectionName; int sectionLevel = 0; hSection = NULL; mir_tstrcpy(itemName, sectionList[indx]->name); sectionName = itemName; while (sectionName) { // allow multi-level tree TCHAR* pItemName = sectionName; HTREEITEM hItem; if (sectionName = _tcschr(sectionName, '/')) { // one level deeper *sectionName = 0; } pItemName = TranslateTS(pItemName); hItem = FindNamedTreeItemAt(hwndTree, hSection, pItemName); if (!sectionName || !hItem) { if (!hItem) { TVINSERTSTRUCT tvis = {0}; TreeItem *treeItem = (TreeItem *)mir_alloc(sizeof(TreeItem)); treeItem->value = SECTIONPARAM_MAKE(indx, sectionLevel, sectionName ? 0 : SECTIONPARAM_HAVEPAGE); treeItem->paramName = mir_t2a(itemName); tvis.hParent = hSection; tvis.hInsertAfter = TVI_SORT; tvis.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_STATE; tvis.item.pszText = pItemName; tvis.item.lParam = (LPARAM) treeItem; tvis.item.state = tvis.item.stateMask = db_get_b(NULL, "SkinIconsUI", treeItem->paramName, TVIS_EXPANDED); hItem = TreeView_InsertItem(hwndTree, &tvis); } else { TVITEM tvi = {0}; tvi.hItem = hItem; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(hwndTree, &tvi); TreeItem *treeItem = (TreeItem *)tvi.lParam; treeItem->value = SECTIONPARAM_MAKE(indx, sectionLevel, SECTIONPARAM_HAVEPAGE); } } if (sectionName) { *sectionName = '/'; sectionName++; } sectionLevel++; hSection = hItem; } } ShowWindow(hwndTree, SW_SHOW); TreeView_SelectItem(hwndTree, FindNamedTreeItemAt(hwndTree, 0, NULL)); } break; // Rebuild preview to new section case DM_REBUILDICONSPREVIEW: { SectionItem* sectionActive = (SectionItem*)lParam; EnableWindow(hPreview, sectionActive != NULL); ListView_DeleteAllItems(hPreview); HIMAGELIST hIml = ListView_GetImageList(hPreview, LVSIL_NORMAL); ImageList_RemoveAll(hIml); if (sectionActive == NULL) break; LVITEM lvi = {0}; lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; { mir_cslock lck(csIconList); for (int indx = 0; indx < iconList.getCount(); indx++) { IcolibItem *item = iconList[indx]; if (item->section == sectionActive) { lvi.pszText = item->getDescr(); HICON hIcon = item->temp_icon; if (!hIcon) hIcon = IconItem_GetIcon_Preview(item); lvi.iImage = ImageList_AddIcon(hIml, hIcon); lvi.lParam = indx; ListView_InsertItem(hPreview, &lvi); if (hIcon != item->temp_icon) SafeDestroyIcon(&hIcon); } } } if (sectionActive->flags & SIDF_SORTED) ListView_SortItems(hPreview, DoSortIconsFunc, 0); else ListView_SortItems(hPreview, DoSortIconsFuncByOrder, 0); } break; // Refresh preview to new section case DM_UPDATEICONSPREVIEW: { LVITEM lvi = {0}; HICON hIcon; int indx, count; HIMAGELIST hIml = ListView_GetImageList(hPreview, LVSIL_NORMAL); lvi.mask = LVIF_IMAGE|LVIF_PARAM; count = ListView_GetItemCount(hPreview); for (indx = 0; indx < count; indx++) { lvi.iItem = indx; ListView_GetItem(hPreview, &lvi); { mir_cslock lck(csIconList); hIcon = iconList[lvi.lParam]->temp_icon; if (!hIcon) hIcon = IconItem_GetIcon_Preview(iconList[lvi.lParam]); } if (hIcon) ImageList_ReplaceIcon(hIml, lvi.iImage, hIcon); if (hIcon != iconList[lvi.lParam]->temp_icon) SafeDestroyIcon(&hIcon); } ListView_RedrawItems(hPreview, 0, count); } break; // Temporary change icon - only inside options dialog case DM_CHANGEICON: { LVITEM lvi = {0}; lvi.mask = LVIF_PARAM; lvi.iItem = wParam; ListView_GetItem(hPreview, &lvi); { mir_cslock lck(csIconList); IcolibItem *item = iconList[ lvi.lParam ]; SAFE_FREE((void**)&item->temp_file); SafeDestroyIcon(&item->temp_icon); TCHAR *path = (TCHAR*)lParam; item->temp_file = mir_tstrdup(path); item->temp_icon = (HICON)ExtractIconFromPath(path, item->cx, item->cy); item->temp_reset = FALSE; } DoOptionsChanged(hwndDlg); } break; case WM_COMMAND: if (LOWORD(wParam) == IDC_IMPORT) { dat->hwndIndex = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ICOLIB_IMPORT), GetParent(hwndDlg), DlgProcIconImport, (LPARAM)hwndDlg); EnableWindow((HWND)lParam, FALSE); } else if (LOWORD(wParam) == IDC_GETMORE) { OpenIconsPage(); break; } else if (LOWORD(wParam) == IDC_LOADICONS) { TCHAR filetmp[1] = {0}; TCHAR *file; if (file = OpenFileDlg(hwndDlg, filetmp, FALSE)) { HWND htv = GetDlgItem(hwndDlg, IDC_CATEGORYLIST); TCHAR filename[ MAX_PATH ]; PathToRelativeT(file, filename); SAFE_FREE((void**)&file); MySetCursor(IDC_WAIT); LoadSubIcons(htv, filename, TreeView_GetSelection(htv)); MySetCursor(IDC_ARROW); DoOptionsChanged(hwndDlg); } } break; case WM_CONTEXTMENU: if ((HWND)wParam == hPreview) { UINT count = ListView_GetSelectedCount(hPreview); if (count > 0) { int cmd = OpenPopupMenu(hwndDlg); switch(cmd) { case ID_CANCELCHANGE: case ID_RESET: { LVITEM lvi = {0}; int itemIndx = -1; while ((itemIndx = ListView_GetNextItem(hPreview, itemIndx, LVNI_SELECTED)) != -1) { lvi.mask = LVIF_PARAM; lvi.iItem = itemIndx; //lvhti.iItem; ListView_GetItem(hPreview, &lvi); UndoChanges(lvi.lParam, cmd); } DoOptionsChanged(hwndDlg); break; } } } } else { HWND htv = GetDlgItem(hwndDlg, IDC_CATEGORYLIST); if ((HWND)wParam == htv) { int cmd = OpenPopupMenu(hwndDlg); switch(cmd) { case ID_CANCELCHANGE: case ID_RESET: UndoSubItemChanges(htv, TreeView_GetSelection(htv), cmd); DoOptionsChanged(hwndDlg); break; } } } break; case WM_NOTIFY: switch(((LPNMHDR)lParam)->idFrom) { case 0: switch(((LPNMHDR)lParam)->code) { case PSN_APPLY: { mir_cslock lck(csIconList); for (int indx = 0; indx < iconList.getCount(); indx++) { IcolibItem *item = iconList[indx]; if (item->temp_reset) { db_unset(NULL, "SkinIcons", item->name); if (item->source_small != item->default_icon) { IconSourceItem_Release(&item->source_small); } } else if (item->temp_file) { db_set_ts(NULL, "SkinIcons", item->name, item->temp_file); IconSourceItem_Release(&item->source_small); SafeDestroyIcon(&item->temp_icon); } } } DoIconsChanged(hwndDlg); return TRUE; } break; case IDC_PREVIEW: if (((LPNMHDR)lParam)->code == LVN_GETINFOTIP) { IcolibItem *item; NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam; LVITEM lvi; lvi.mask = LVIF_PARAM; lvi.iItem = pInfoTip->iItem; ListView_GetItem(pInfoTip->hdr.hwndFrom, &lvi); if (lvi.lParam < iconList.getCount()) { item = iconList[lvi.lParam]; if (item->temp_file) _tcsncpy(pInfoTip->pszText, item->temp_file, pInfoTip->cchTextMax); else if (item->default_file) mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s, %d"), item->default_file, item->default_indx); } } if (bNeedRebuild) { bNeedRebuild = FALSE; SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0); } break; case IDC_CATEGORYLIST: switch(((NMHDR*)lParam)->code) { case TVN_SELCHANGEDA: // !!!! This needs to be here - both !! case TVN_SELCHANGEDW: { NMTREEVIEW *pnmtv = (NMTREEVIEW*)lParam; TVITEM tvi = pnmtv->itemNew; TreeItem *treeItem = (TreeItem *)tvi.lParam; if (treeItem) SendMessage(hwndDlg, DM_REBUILDICONSPREVIEW, 0, (LPARAM)( (SECTIONPARAM_FLAGS(treeItem->value)&SECTIONPARAM_HAVEPAGE)? sectionList[ SECTIONPARAM_INDEX(treeItem->value) ] : NULL)); break; } case TVN_DELETEITEMA: // no idea why both TVN_SELCHANGEDA/W should be there but let's keep this both too... case TVN_DELETEITEMW: { TreeItem *treeItem = (TreeItem *)(((LPNMTREEVIEW)lParam)->itemOld.lParam); if (treeItem) { mir_free(treeItem->paramName); mir_free(treeItem); } break; } } if (bNeedRebuild) { { mir_cslock lck(csIconList); bNeedRebuild = FALSE; } SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0); } } break; case WM_DESTROY: SaveCollapseState( GetDlgItem(hwndDlg, IDC_CATEGORYLIST)); DestroyWindow(dat->hwndIndex); { mir_cslock lck(csIconList); for (int indx = 0; indx < iconList.getCount(); indx++) { IcolibItem *item = iconList[indx]; SAFE_FREE((void**)&item->temp_file); SafeDestroyIcon(&item->temp_icon); } } SAFE_FREE((void**)&dat); break; } return FALSE; }
static void RebuildPageTree(HWND hdlg, OptionsDlgData *dat) { LPARAM oldSel = SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_GETEDITSEL, 0, 0); GetDlgItemText(hdlg, IDC_KEYWORD_FILTER, dat->szFilterString, _countof(dat->szFilterString)); // if filter string is set to all modules then make the filter string empty (this will return all modules) BOOL bRemoveFocusFromFilter = FALSE; if (mir_tstrcmp(dat->szFilterString, TranslateT(ALL_MODULES_FILTER)) == 0) { dat->szFilterString[0] = 0; bRemoveFocusFromFilter = TRUE; } // if filter string is set to core modules replace it with the name of the executable (this will return all core modules) else if (mir_tstrcmp(dat->szFilterString, TranslateT(CORE_MODULES_FILTER)) == 0) { // replace string with process name - that will show core settings TCHAR szFileName[300]; GetModuleFileName(g_hInst, szFileName, _countof(szFileName)); TCHAR *pos = _tcsrchr(szFileName, _T('\\')); if (pos) pos++; else pos = szFileName; _tcsncpy_s(dat->szFilterString, pos, _TRUNCATE); } else { int sel = SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, (UINT)CB_GETCURSEL, 0, 0); if (sel != -1) { HINSTANCE hinst = (HINSTANCE)SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, (UINT)CB_GETITEMDATA, sel, 0); TCHAR szFileName[300]; GetModuleFileName(hinst, szFileName, _countof(szFileName)); TCHAR *pos = _tcsrchr(szFileName, _T('\\')); if (pos) pos++; else pos = szFileName; _tcsncpy_s(dat->szFilterString, pos, _TRUNCATE); } } _tcslwr_locale(dat->szFilterString); //all strings are stored as lowercase ... make sure filter string is lowercase too HWND hwndTree = GetDlgItem(hdlg, IDC_PAGETREE); SendMessage(hwndTree, WM_SETREDRAW, FALSE, 0); HWND oldWnd = NULL; HWND oldTab = NULL; CMString fullTitle; OptionsPageData *opd = dat->getCurrent(); if (opd != NULL) { oldWnd = opd->getHwnd(); if (opd->insideTab) oldTab = GetDlgItem(hdlg, IDC_TAB); } dat->hCurrentPage = NULL; TreeView_SelectItem(hwndTree, NULL); TreeView_DeleteAllItems(hwndTree); TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = TVI_SORT; tvis.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM; tvis.item.state = tvis.item.stateMask = TVIS_EXPANDED; for (int i = 0; i < dat->arOpd.getCount(); i++) { if (!CheckPageShow(hdlg, dat, i)) continue; opd = dat->arOpd[i]; TCHAR *ptszGroup = TranslateTH(opd->hLangpack, opd->ptszGroup); TCHAR *ptszTitle = opd->getString(opd->ptszTitle), *useTitle; TCHAR *ptszTab = TranslateTH(opd->hLangpack, opd->ptszTab); tvis.hParent = NULL; useTitle = ptszTitle; if (ptszGroup != NULL) { tvis.hParent = FindNamedTreeItemAtRoot(hwndTree, ptszGroup); if (tvis.hParent == NULL) { tvis.item.lParam = -1; tvis.item.pszText = ptszGroup; tvis.hParent = TreeView_InsertItem(hwndTree, &tvis); } } else { TVITEM tvi; tvi.hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle); if (tvi.hItem != NULL) { if (i == dat->currentPage) dat->hCurrentPage = tvi.hItem; tvi.mask = TVIF_PARAM; TreeView_GetItem(hwndTree, &tvi); if (tvi.lParam == -1) { tvi.lParam = i; TreeView_SetItem(hwndTree, &tvi); continue; } } } if (ptszTab != NULL) { HTREEITEM hItem; if (tvis.hParent == NULL) hItem = FindNamedTreeItemAtRoot(hwndTree, useTitle); else hItem = FindNamedTreeItemAtChildren(hwndTree, tvis.hParent, useTitle); if (hItem != NULL) { if (i == dat->currentPage) { TVITEM tvi; tvi.hItem = hItem; tvi.mask = TVIF_PARAM; tvi.lParam = dat->currentPage; TreeView_SetItem(hwndTree, &tvi); dat->hCurrentPage = hItem; } continue; } } tvis.item.pszText = useTitle; tvis.item.lParam = i; opd->hTreeItem = TreeView_InsertItem(hwndTree, &tvis); if (i == dat->currentPage) dat->hCurrentPage = opd->hTreeItem; } char str[128]; TVITEMA tvi; tvi.mask = TVIF_TEXT | TVIF_STATE; tvi.pszText = str; tvi.cchTextMax = _countof(str); tvi.hItem = TreeView_GetRoot(hwndTree); while (tvi.hItem != NULL) { if (SendMessageA(hwndTree, TVM_GETITEMA, 0, (LPARAM)&tvi)) { char buf[130]; mir_snprintf(buf, "%s%s", OPTSTATE_PREFIX, str); if (!db_get_b(NULL, "Options", buf, 1)) TreeView_Expand(hwndTree, tvi.hItem, TVE_COLLAPSE); } tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); } if (dat->hCurrentPage == NULL) { dat->hCurrentPage = TreeView_GetRoot(hwndTree); dat->currentPage = -1; } TreeView_SelectItem(hwndTree, dat->hCurrentPage); if (oldWnd) { opd = dat->getCurrent(); if (opd && oldWnd != opd->getHwnd()) { ShowWindow(oldWnd, SW_HIDE); if (oldTab && (opd == NULL || !opd->insideTab)) ShowWindow(oldTab, SW_HIDE); } } if (dat->szFilterString[0] == 0) // Clear the keyword combo box SetDlgItemText(hdlg, IDC_KEYWORD_FILTER, _T("")); if (!bRemoveFocusFromFilter) SetFocus(GetDlgItem(hdlg, IDC_KEYWORD_FILTER)); //set the focus back to the combo box SendDlgItemMessage(hdlg, IDC_KEYWORD_FILTER, CB_SETEDITSEL, 0, oldSel); //but don't select any of the text SendMessage(hwndTree, WM_SETREDRAW, TRUE, 0); TreeView_EnsureVisible(hwndTree, dat->hCurrentPage); }
void Explorerplusplus::OnTreeViewRightClick(WPARAM wParam,LPARAM lParam) { LPITEMIDLIST pidl = NULL; POINT *ppt = NULL; HTREEITEM hItem; HTREEITEM hPrevItem; IShellFolder *pShellParentFolder = NULL; LPITEMIDLIST pidlRelative = NULL; HRESULT hr; hItem = (HTREEITEM)wParam; ppt = (POINT *)lParam; m_bTreeViewRightClick = TRUE; hPrevItem = TreeView_GetSelection(m_hTreeView); TreeView_SelectItem(m_hTreeView,hItem); pidl = m_pMyTreeView->BuildPath(hItem); hr = SHBindToParent(pidl,IID_IShellFolder,(void **)&pShellParentFolder, (LPCITEMIDLIST *)&pidlRelative); if(SUCCEEDED(hr)) { HTREEITEM hParent; LPITEMIDLIST pidlParent = NULL; hParent = TreeView_GetParent(m_hTreeView,hItem); /* If we right-click on the "Desktop" item in the treeview, there is no parent. In such case, use "Desktop" as parent item as well, to allow the context menu to be shown. */ if(hParent == NULL) { hParent = hItem; } if(hParent != NULL) { pidlParent = m_pMyTreeView->BuildPath(hParent); if(pidlParent != NULL) { m_bTreeViewOpenInNewTab = FALSE; std::list<LPITEMIDLIST> pidlList; pidlList.push_back(pidlRelative); CFileContextMenuManager fcmm(m_hContainer,pidlParent, pidlList); FileContextMenuInfo_t fcmi; fcmi.uFrom = FROM_TREEVIEW; CStatusBar StatusBar(m_hStatusBar); fcmm.ShowMenu(this,MIN_SHELL_MENU_ID,MAX_SHELL_MENU_ID,ppt,&StatusBar, reinterpret_cast<DWORD_PTR>(&fcmi),TRUE,GetKeyState(VK_SHIFT) & 0x80); CoTaskMemFree(pidlParent); } } pShellParentFolder->Release(); } /* Don't switch back to the previous folder if the folder that was right-clicked was opened in a new tab (i.e. can just keep the selection the same). */ if(!m_bTreeViewOpenInNewTab) TreeView_SelectItem(m_hTreeView,hPrevItem); m_bTreeViewRightClick = FALSE; CoTaskMemFree(pidl); }
INT_PTR CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { if (hPreviewBitmap) ske_UnloadGlyphImage(hPreviewBitmap); break; } case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); SetDlgItemText(hwndDlg, IDC_SKINFOLDERLABEL, SkinsFolder); HTREEITEM it = FillAvailableSkinList(hwndDlg); HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1); TreeView_SelectItem(wnd, it); } return 0; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_COLOUR_MENUNORMAL: case IDC_COLOUR_MENUSELECTED: case IDC_COLOUR_FRAMES: case IDC_COLOUR_STATUSBAR: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_BUTTON_INFO: { TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; if (sd->File && !_tcschr(sd->File, _T('%'))) { GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File); mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), sd->Name, Description, Author, Contact, URL, sd->File); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("Angeli-Ka (graphics), FYR (template)"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru"), TranslateT("Inside library")); } MessageBox(hwndDlg, text, TranslateT("Skin information"), MB_OK | MB_ICONINFORMATION); } break; case IDC_BUTTON_APPLY_SKIN: if (HIWORD(wParam) == BN_CLICKED) { SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; ske_LoadSkinFromIniFile(sd->File, FALSE); ske_LoadSkinFromDB(); pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0); Sync(CLUIFrames_OnClistResize_mod, 0, 0); ske_RedrawCompleteWindow(); Sync(CLUIFrames_OnClistResize_mod, 0, 0); { HWND hwnd = pcli->hwndContactList; RECT rc = { 0 }; GetWindowRect(hwnd, &rc); Sync(CLUIFrames_OnMoving, hwnd, &rc); } if (g_hCLUIOptionsWnd) { SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_LEFTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "LeftClientMargin", SETTING_LEFTCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_RIGHTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "RightClientMargin", SETTING_RIGHTCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_TOPMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "TopClientMargin", SETTING_TOPCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_BOTTOMMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "BottomClientMargin", SETTING_BOTTOMCLIENTMARIGN_DEFAULT)); } } break; case IDC_BUTTON_RESCAN: if (HIWORD(wParam) == BN_CLICKED) { HTREEITEM it = FillAvailableSkinList(hwndDlg); HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1); TreeView_SelectItem(wnd, it); } } break; } case WM_DRAWITEM: if (wParam == IDC_PREVIEW) { //TODO:Draw hPreviewBitmap here int mWidth, mHeight; HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; mWidth = dis->rcItem.right - dis->rcItem.left; mHeight = dis->rcItem.bottom - dis->rcItem.top; HDC memDC = CreateCompatibleDC(dis->hDC); HBITMAP hbmp = ske_CreateDIB32(mWidth, mHeight); HBITMAP holdbmp = (HBITMAP)SelectObject(memDC, hbmp); RECT workRect = dis->rcItem; OffsetRect(&workRect, -workRect.left, -workRect.top); FillRect(memDC, &workRect, hbr); DeleteObject(hbr); if (hPreviewBitmap) { //variables BITMAP bmp = { 0 }; POINT imgPos = { 0 }; float xScale = 1, yScale = 1; //GetSize GetObject(hPreviewBitmap, sizeof(BITMAP), &bmp); int wWidth = workRect.right - workRect.left; int wHeight = workRect.bottom - workRect.top; if (wWidth < bmp.bmWidth) xScale = (float)wWidth / bmp.bmWidth; if (wHeight < bmp.bmHeight) yScale = (float)wHeight / bmp.bmHeight; xScale = min(xScale, yScale); yScale = xScale; int dWidth = (int)(xScale*bmp.bmWidth); int dHeight = (int)(yScale*bmp.bmHeight); //CalcPosition imgPos.x = workRect.left + ((wWidth - dWidth) >> 1); imgPos.y = workRect.top + ((wHeight - dHeight) >> 1); //DrawImage DrawAvatarImageWithGDIp(memDC, imgPos.x, imgPos.y, dWidth, dHeight, hPreviewBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, 8, 255); } BitBlt(dis->hDC, dis->rcItem.left, dis->rcItem.top, mWidth, mHeight, memDC, 0, 0, SRCCOPY); SelectObject(memDC, holdbmp); DeleteObject(hbmp); DeleteDC(memDC); } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case IDC_TREE1: { NMTREEVIEW * nmtv = (NMTREEVIEW *)lParam; if (nmtv == NULL) return 0; if (nmtv->hdr.code == TVN_SELCHANGEDA || nmtv->hdr.code == TVN_SELCHANGEDW) { SkinListData * sd = NULL; if (hPreviewBitmap) { ske_UnloadGlyphImage(hPreviewBitmap); hPreviewBitmap = NULL; } if (nmtv->itemNew.lParam) { sd = (SkinListData*)nmtv->itemNew.lParam; TCHAR buf[MAX_PATH]; PathToRelativeT(sd->File, buf); SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, buf); TCHAR prfn[MAX_PATH] = { 0 }, imfn[MAX_PATH] = { 0 }, skinfolder[MAX_PATH] = { 0 }; GetPrivateProfileString(_T("Skin_Description_Section"), _T("Preview"), _T(""), imfn, SIZEOF(imfn), sd->File); IniParser::GetSkinFolder(sd->File, skinfolder); mir_sntprintf(prfn, SIZEOF(prfn), _T("%s\\%s"), skinfolder, imfn); PathToAbsoluteT(prfn, imfn); hPreviewBitmap = ske_LoadGlyphImage(imfn); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), TRUE); if (hPreviewBitmap) InvalidateRect(GetDlgItem(hwndDlg, IDC_PREVIEW), NULL, TRUE); else { //prepare text TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData* sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; if (sd->File && !_tcschr(sd->File, _T('%'))) { GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File); mir_sntprintf(text, SIZEOF(text), TranslateT("Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s"), sd->Name, Description, Author, Contact, URL); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("graphics by Angeli-Ka\ntemplate by FYR"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru")); } ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_INFO), SW_SHOW); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, text); } } else { //no selected SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, TranslateT("Select skin from list")); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), FALSE); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, TranslateT("Please select skin to apply")); ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE); } ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), hPreviewBitmap ? SW_SHOW : SW_HIDE); return 0; } else if (nmtv->hdr.code == TVN_DELETEITEMA || nmtv->hdr.code == TVN_DELETEITEMW) { mir_free_and_nil(nmtv->itemOld.lParam); return 0; } } break; case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0); NotifyEventHooks(g_CluiData.hEventBkgrChanged, 0, 0); pcli->pfnClcBroadcast(INTM_INVALIDATE, 0, 0); RedrawWindow(GetParent(pcli->hwndContactTree), NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } break; } }
/////////////////////////////////// //From UserInfoEx by DeathAxe // void MoveItem( HTREEITEM hItem, HTREEITEM hInsertAfter, BOOLEAN bAsChild ) { TVINSERTSTRUCT tvis; //TCHAR strbuf[128]; HTREEITEM hParent, hChild, hNewItem; if( !hItem || !hInsertAfter ) return; if( hItem == hInsertAfter ) return; switch( ( ULONG_PTR )hInsertAfter ) { case TVI_ROOT: case TVI_FIRST: case TVI_LAST: hParent = NULL; bAsChild = FALSE; break; default: hParent = TreeView_GetParent( hMenuTree, hInsertAfter ); break; } // do not move a parent next to its own children! if( hItem == hParent ) return; // prepare the insert structure { TCHAR strbuf[128]; tvis.item.mask=TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT; tvis.item.pszText=strbuf; tvis.item.cchTextMax=sizeof(strbuf); tvis.item.hItem=hItem; TreeView_GetItem(hMenuTree,&tvis.item); } // item should be inserted as the first child of an existing root item if( bAsChild ) { tvis.hParent = hInsertAfter; tvis.hInsertAfter = ( bAsChild == 2 ) ? TVI_LAST : TVI_FIRST ; } // item should be inserted after an existing item else { tvis.hParent = hParent; tvis.hInsertAfter = hInsertAfter; } // insert the item if( !( hNewItem = TreeView_InsertItem( hMenuTree, &tvis ) ) ) return; // move children hInsertAfter = hNewItem; while( hChild = TreeView_GetChild( hMenuTree, hItem ) ) { MoveItem( hChild, hInsertAfter, 2 ); } // delete old tree TreeView_DeleteItem( hMenuTree, hItem ); TreeView_SelectItem( hMenuTree, hNewItem ); //TreeView_Expand( hMenuTree, hNewItem, TVE_EXPAND ); }
static INT_PTR CALLBACK DefInpProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_INITDIALOG: { hIpsDlg = hDlg; hWhiteBGBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF)); hPreview = PNGLoadBitmap(hIpsDlg, NULL, 304, 228, 2); SendDlgItemMessage(hIpsDlg, IDC_SCREENSHOT_H, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hPreview); LONG_PTR Style; Style = GetWindowLongPtr (GetDlgItem(hIpsDlg, IDC_TREE1), GWL_STYLE); Style |= TVS_CHECKBOXES; SetWindowLongPtr (GetDlgItem(hIpsDlg, IDC_TREE1), GWL_STYLE, Style); IpsManagerInit(); WndInMid(hDlg, hScrnWnd); SetFocus(hDlg); // Enable Esc=close break; } case WM_COMMAND: { int wID = LOWORD(wParam); int Notify = HIWORD(wParam); if (Notify == BN_CLICKED) { switch (wID) { case IDOK: { IpsOkay(); break; } case IDCANCEL: { SendMessage(hDlg, WM_CLOSE, 0, 0); return 0; } case IDC_IPSMAN_DESELECTALL: { for (int i = 0; i < nNumPatches; i++) { for (int j = 0; j < nNumPatches; j++) { _TreeView_SetCheckState(hIpsList, hPatchHandlesIndex[j], FALSE); } } break; } } } if (wID == IDC_CHOOSE_LIST && Notify == CBN_SELCHANGE) { nIpsSelectedLanguage = SendMessage(GetDlgItem(hIpsDlg, IDC_CHOOSE_LIST), CB_GETCURSEL, 0, 0); TreeView_DeleteAllItems(hIpsList); FillListBox(); RefreshPatch(); return 0; } break; } case WM_NOTIFY: { NMHDR* pNmHdr = (NMHDR*)lParam; if (LOWORD(wParam) == IDC_TREE1 && pNmHdr->code == TVN_SELCHANGED) { RefreshPatch(); return 1; } if (LOWORD(wParam) == IDC_TREE1 && pNmHdr->code == NM_DBLCLK) { // disable double-click node-expand SetWindowLongPtr(hIpsDlg, DWLP_MSGRESULT, 1); return 1; } if (LOWORD(wParam) == IDC_TREE1 && pNmHdr->code == NM_CLICK) { POINT cursorPos; GetCursorPos(&cursorPos); ScreenToClient(hIpsList, &cursorPos); TVHITTESTINFO thi; thi.pt = cursorPos; TreeView_HitTest(hIpsList, &thi); if (thi.flags == TVHT_ONITEMSTATEICON) { TreeView_SelectItem(hIpsList, thi.hItem); } return 1; } SetWindowLongPtr(hIpsDlg, DWLP_MSGRESULT, CDRF_DODEFAULT); return 1; } case WM_CTLCOLORSTATIC: { if ((HWND)lParam == GetDlgItem(hIpsDlg, IDC_TEXTCOMMENT)) { return (INT_PTR)hWhiteBGBrush; } break; } case WM_CLOSE: { IpsManagerExit(); break; } } return 0; }
void TreeNode::Select() { TreeView_SelectItem(mTreeView->GetHandle(), mHandle); }