Пример #1
0
BOOL
InitControls(HWND hwnd)
{
    if (SettingsInfo.bSaveWndPos)
    {
        MoveWindow(hwnd, SettingsInfo.Left, SettingsInfo.Top,
                   SettingsInfo.Right - SettingsInfo.Left,
                   SettingsInfo.Bottom - SettingsInfo.Top, TRUE);

        if (SettingsInfo.Maximized) ShowWindow(hwnd, SW_MAXIMIZE);
    }

    if (CreateStatusBar(hwnd) &&
        CreateToolBar(hwnd) &&
        CreateListView(hwnd) &&
        CreateTreeView(hwnd) &&
        CreateRichEdit(hwnd) &&
        CreateVSplitBar(hwnd) &&
        CreateHSplitBar(hwnd))
    {
        WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN];

        InitApplicationsList();

        InitCategoriesList();

        LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, sizeof(szBuffer2) / sizeof(WCHAR));
        swprintf(szBuffer1, szBuffer2, ListView_GetItemCount(hListView));
        SetStatusBarText(szBuffer1);
        return TRUE;
    }

    return FALSE;
}
Пример #2
0
BOOL
InitControls(HWND hwnd)
{

    if (CreateStatusBar(hwnd) &&
        CreateToolBar(hwnd)   &&
        CreateListView(hwnd)  &&
        CreateTreeView(hwnd)  &&
        CreateRichEdit(hwnd)  &&
        CreateVSplitBar(hwnd) &&
        CreateHSplitBar(hwnd))
    {
        WCHAR szBuffer1[MAX_STR_LEN], szBuffer2[MAX_STR_LEN];

        InitApplicationsList();

        InitCategoriesList();

        LoadStringW(hInst, IDS_APPS_COUNT, szBuffer2, _countof(szBuffer2));
        StringCbPrintfW(szBuffer1, sizeof(szBuffer1),
                        szBuffer2,
                        ListView_GetItemCount(hListView));
        SetStatusBarText(szBuffer1);
        return TRUE;
    }

    return FALSE;
}
Пример #3
0
void CPpcMainWnd::OnCreate(HWND hwnd)
{
	m_hWnd = hwnd;
	CreateMenuBar();
	CreateListView();

	CMainWnd::OnCreate(hwnd);

	RegisterHotKeys();
	SetTimer(m_hWnd, ID_TIMER_DISPCHECK, TIMER_DISPCHECK_INTERVAL, NULL);
	SetTimer(m_hWnd, ID_TIMER_DISPSTATE, TIMER_DISPSTATE_INTERVAL, NULL);

	memset(&m_sai, 0, sizeof(m_sai));
	m_sai.cbSize = sizeof(m_sai);

	SetFocus(m_hwndLV);
	ShowWindow(m_hwndLV, SW_HIDE);
}
Пример #4
0
static BOOL
InitMainWnd(PMAIN_WND_INFO Info)
{
    if (!pCreateToolbar(Info))
    {
        DisplayString(_T("error creating toolbar"));
        return FALSE;
    }

    if (!CreateListView(Info))
    {
        DisplayString(_T("error creating list view"));
        return FALSE;
    }

    if (!CreateStatusBar(Info))
        DisplayString(_T("error creating status bar"));

    /* Create Popup Menu */
    Info->hShortcutMenu = LoadMenu(hInstance,
                                   MAKEINTRESOURCE(IDR_POPUP));

    Info->bIsUserAnAdmin = IsUserAnAdmin();
    if (Info->bIsUserAnAdmin)
    {
        HMENU hMainMenu = GetMenu(Info->hMainWnd);

        SendMessage(Info->hTool,
                    TB_SETSTATE,
                    ID_CREATE,
                    (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
        if (hMainMenu)
        {
            EnableMenuItem(hMainMenu,
                           ID_CREATE,
                           MF_ENABLED);
        }
        EnableMenuItem(GetSubMenu(Info->hShortcutMenu, 0),
                       ID_CREATE,
                       MF_ENABLED);
    }

    return TRUE;
}
Пример #5
0
int WINAPI WinMain(HINSTANCE hInstance,
		   HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASS wc;
	HWND hWnd, hWndListView;
	MSG msg;
	BOOL ret;

	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
	UNREFERENCED_PARAMETER(nCmdShow);

	ZeroMemory(&wc, sizeof(wc));
	wc.lpfnWndProc = WndProc;
	wc.hInstance = hInstance;
	wc.lpszClassName = CLASS_NAME;
	wc.hbrBackground = GetStockObject(WHITE_BRUSH);
	RegisterClass(&wc);

	hWnd = CreateWindow(CLASS_NAME, WND_NAME, WS_OVERLAPPEDWINDOW,
			    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
			    CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
	if (hWnd == NULL)
		return GetLastError();

	hWndListView = CreateListView(hInstance, hWnd);
	if (hWndListView == NULL)
		return GetLastError();

	UpdateListView(hWndListView);
	SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) hWndListView);
	SetTimer(hWnd, TIMER_ID, TIMER_INTERVAL_MS, NULL);

	ShowWindow(hWnd, SW_SHOW);
	ShowWindow(hWndListView, SW_SHOW);

	while ((ret = GetMessage(&msg, hWnd, 0, 0)) != 0 && ret != -1) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}
Пример #6
0
    BOOL CreateLayout()
    {
        bool b = TRUE;

        m_ClientPanel = new CUiPanel();
        m_ClientPanel->m_VerticalAlignment = UiAlign_Stretch;
        m_ClientPanel->m_HorizontalAlignment = UiAlign_Stretch;

        // Top level
        b = b && CreateStatusBar();
        b = b && CreateToolbar();
        b = b && CreateSearchBar();
        b = b && CreateVSplitter();

        // Inside V Splitter
        b = b && CreateHSplitter();
        b = b && CreateTreeView();

        // Inside H Splitter
        b = b && CreateListView();
        b = b && CreateRichEdit();

        if (b)
        {
            RECT rTop;
            RECT rBottom;

            /* Size status bar */
            m_StatusBar->SendMessage(WM_SIZE, 0, 0);

            /* Size tool bar */
            m_Toolbar->AutoSize();

            ::GetWindowRect(m_Toolbar->m_hWnd, &rTop);
            ::GetWindowRect(m_StatusBar->m_hWnd, &rBottom);

            m_VSplitter->m_Margin.top = rTop.bottom - rTop.top;
            m_VSplitter->m_Margin.bottom = rBottom.bottom-rBottom.top;
        }

        return b;
    }
Пример #7
0
INT_PTR CALLBACK ListDlgPRoc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HWND hList = NULL;
	static LVCOLUMN lvCol{ 0 };
	static LVITEM lvItem{ 0 };
	static CSettings* settings{ 0 };
	switch (message)
	{
	case WM_INITDIALOG:
		InitCommonControls();
		settings = reinterpret_cast<CSettings*>(lParam);
		EnumWindows(EnumWindowsProc, NULL);
		hList = CreateListView(hWnd);
		InitListView(hList);
		break;
	case WM_NOTIFY:
		return ListViewNotify(settings->spotify, hWnd, lParam, settings->program);
	case WM_SIZE:
		ResizeListView(hList, hWnd);
		break;
	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK)
		{
			saveSelection(settings->spotify, hList, settings->program);
			EndDialog(hWnd, 0);
		}
		break;
	case WM_CLOSE:
	case WM_DESTROY:
		EndDialog(hWnd, 0);
		break;
	default:
		break;
	}
	return 0;
}
Пример #8
0
LONG APIENTRY MainWndProc(
	HWND hWnd,                /* window handle                   */
	UINT message,             /* type of message                 */
	UINT wParam,              /* additional information          */
	LONG lParam)              /* additional information          */
{
	static HWND hWndListView;
	DWORD dwStyle;

	switch (message) 
	{

		case WM_CREATE:

			hWndListView = CreateListView( hWnd );
			if (hWndListView == NULL)
				MessageBox (NULL, "Listview not created!", NULL, MB_OK );
		 
			break;

		case WM_NOTIFY:
			return( NotifyHandler(hWnd, message, wParam, lParam));
			break;

		case WM_COMMAND:

			switch( LOWORD( wParam ))
			{

				case IDM_LARGEICON:
					dwStyle = GetWindowLong(hWndListView, GWL_STYLE);
					
					if ((dwStyle & LVS_TYPEMASK) != LVS_ICON)
						SetWindowLong(hWndListView, GWL_STYLE,
							(dwStyle & ~LVS_TYPEMASK) | LVS_ICON);
					break;

				case IDM_SMALLICON:
					dwStyle = GetWindowLong(hWndListView, GWL_STYLE);
					
					if ((dwStyle & LVS_TYPEMASK) != LVS_SMALLICON)
						SetWindowLong(hWndListView, GWL_STYLE,
							(dwStyle & ~LVS_TYPEMASK) | LVS_SMALLICON);
					break;

				case IDM_LISTVIEW:
					dwStyle = GetWindowLong(hWndListView, GWL_STYLE);

					if ((dwStyle & LVS_TYPEMASK) != LVS_LIST)
						SetWindowLong(hWndListView, GWL_STYLE,
							(dwStyle & ~LVS_TYPEMASK) | LVS_LIST);
					break;

				case IDM_REPORTVIEW:
					dwStyle = GetWindowLong(hWndListView, GWL_STYLE);

					if ((dwStyle & LVS_TYPEMASK) != LVS_REPORT)
						SetWindowLong(hWndListView, GWL_STYLE,
							(dwStyle & ~LVS_TYPEMASK) | LVS_REPORT);
					break;

				case IDM_EXIT:
					PostQuitMessage(0);
					break;

				case IDM_ABOUT:
					DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)About);
					break;

				default:
					return (DefWindowProc(hWnd, message, wParam, lParam));

		}
		break;

		case WM_SIZE:
            MoveWindow(hWndListView, 0, 0, LOWORD(lParam),HIWORD(lParam),TRUE);
            break;

		case WM_DESTROY:                  /* message: window being destroyed */
			PostQuitMessage(0);
			break;

		default:
			return (DefWindowProc(hWnd, message, wParam, lParam));
	}
	return (0);
}
Пример #9
0
// -----------------------------------------------------------------------
// Initialize Form
int CALLBACK FRMDllDef(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    int i = 0;

    switch(uMsg)
    {
        case WM_SYSCOLORCHANGE:
            ListViewSetBackColor(FRMDllDefListview, GetSysColor(COLOR_WINDOW));
            break;
        case WM_INITDIALOG:
            ControlSetText(hwndDlg, "Select procedures to export");
            FRMDllDefCmdOk = CreateButton(263, 1 + 16, 77, 23, hwndDlg, "Ok", 1, 0, 0, 0, BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, Buttons_StaticEdge);
            FRMDllDefCmdCancel = CreateButton(263, 25 + 16, 77, 23, hwndDlg, "Cancel", 2, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMDllDefCmdSelAll = CreateButton(263, 51 + 16, 77, 23, hwndDlg, "Select all", 3, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMDllDefCmdUnSelAll = CreateButton(263, 75 + 16, 77, 23, hwndDlg, "Unselect all", 4, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            CreateLabel(1, 2, 250, 15, hwndDlg, "Entry point :", 0, 0, 0, 0);
            FRMDllDefComboBox = CreateComboBox(2, 17, 258, 150, hwndDlg, "", 5, 0, CBS_DROPDOWNLIST | WS_TABSTOP);
            CreateLabel(1, 40, 250, 15, hwndDlg, "Exports :", 0, 0, 0, 0);
            FRMDllDefListview = CreateListView(2, 55, 258, 238, hwndDlg, 6, 0, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP, LVS_REPORT | LVS_SINGLESEL | LVS_NOCOLUMNHEADER | WS_TABSTOP, WS_EX_STATICEDGE);
            ListViewAddCol(FRMDllDefListview, "", 300, 0);
            ComboBoxAddItem(FRMDllDefComboBox, "[None]", -1);
            FreezeTimer = 1;
            ComboBoxSetIndex(FRMDllDefComboBox, DllDefFillFilesList());
            ListViewSetItemSel(FRMDllDefListview, 0);
            SetFocus(FRMDllDefComboBox);
            return(0);
        case WM_NOTIFY:
            if(ControlGetNotifiedhWnd(lParam) == FRMDllDefListview)
            {
                switch(ControlGetNotifiedMsg(lParam))
                {
                    case NM_DBLCLK:
                        ListViewCheckBoxItemDoubleClick(FRMDllDefListview);
                        return(0);
                }
            }
            break;
        case WM_COMMAND:
            if((HWND) lParam == FRMDllDefCmdOk)
            {
                SaveDllDef();
                ControlClose(hwndDlg);
                return(0);
            }
            else if((HWND) lParam == FRMDllDefCmdCancel)
            {
                ControlClose(hwndDlg);
                return(0);
            }
            else if((HWND) lParam == FRMDllDefCmdSelAll)
            {
                for(i = 0; i <= ListViewItemCount(FRMDllDefListview) - 1; i++)
                {
                    ListViewSetItemCheckbox(FRMDllDefListview, i, 1);
                }
                return(0);
            }
            else if((HWND) lParam == FRMDllDefCmdUnSelAll)
            {
                for(i = 0; i <= ListViewItemCount(FRMDllDefListview) - 1; i++)
                {
                    ListViewSetItemCheckbox(FRMDllDefListview, i, 0);
                }
                return(0);
            }
            break;
        case WM_CLOSE:
            StringReleaseSplit(DllDefArray);
            FreezeTimer = 0;
            EndDialog(hwndDlg, 0);
    }
    return(0);
}
Пример #10
0
/*******************************************************************************
 *
 *  FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
 *
 *  PURPOSE:  Processes messages for the child windows.
 *
 *  WM_COMMAND  - process the application menu
 *  WM_PAINT    - Paint the main window
 *  WM_DESTROY  - post a quit message and return
 *
 */
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    BOOL Result;

    switch (message)
    {
    case WM_CREATE:
    {
        WNDPROC oldproc;
        HFONT hFont;
        WCHAR buffer[MAX_PATH];

        /* Load "My Computer" string */
        LoadStringW(hInst, IDS_MY_COMPUTER, buffer, COUNT_OF(buffer));

        g_pChildWnd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ChildWnd));
        if (!g_pChildWnd) return 0;

        wcsncpy(g_pChildWnd->szPath, buffer, MAX_PATH);
        g_pChildWnd->nSplitPos = 250;
        g_pChildWnd->hWnd = hWnd;
        g_pChildWnd->hAddressBarWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP,
                                                      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                                      hWnd, (HMENU)0, hInst, 0);
        g_pChildWnd->hAddressBtnWnd = CreateWindowExW(0, L"Button", L"»", WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP | BS_TEXT | BS_CENTER | BS_VCENTER | BS_FLAT | BS_DEFPUSHBUTTON,
                                                      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                                                      hWnd, (HMENU)0, hInst, 0);
        g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, (HMENU) TREE_WINDOW);
        g_pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW/*, g_pChildWnd->szPath*/);
        SetFocus(g_pChildWnd->hTreeWnd);

        /* set the address bar and button font */
        if ((g_pChildWnd->hAddressBarWnd) && (g_pChildWnd->hAddressBtnWnd))
        {
            hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            SendMessageW(g_pChildWnd->hAddressBarWnd,
                         WM_SETFONT,
                         (WPARAM)hFont,
                         0);
            SendMessageW(g_pChildWnd->hAddressBtnWnd,
                         WM_SETFONT,
                         (WPARAM)hFont,
                         0);
        }
        /* Subclass the AddressBar */
        oldproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_WNDPROC);
        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_USERDATA, (DWORD_PTR)oldproc);
        SetWindowLongPtr(g_pChildWnd->hAddressBarWnd, GWLP_WNDPROC, (DWORD_PTR)AddressBarProc);
        break;
    }
    case WM_COMMAND:
        if(HIWORD(wParam) == BN_CLICKED)
        {
            PostMessageW(g_pChildWnd->hAddressBarWnd, WM_KEYUP, VK_RETURN, 0);
        }

        if (!_CmdWndProc(hWnd, message, wParam, lParam))
        {
            goto def;
        }
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        return 0;
    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT)
        {
            POINT pt;
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if (pt.x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1)
            {
                SetCursor(LoadCursorW(0, IDC_SIZEWE));
                return TRUE;
            }
        }
        goto def;
    case WM_DESTROY:
        DestroyTreeView();
        DestroyListView(g_pChildWnd->hListWnd);
        DestroyMainMenu();
        HeapFree(GetProcessHeap(), 0, g_pChildWnd);
        g_pChildWnd = NULL;
        PostQuitMessage(0);
        break;
    case WM_LBUTTONDOWN:
    {
        RECT rt;
        int x = (short)LOWORD(lParam);
        GetClientRect(hWnd, &rt);
        if (x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1)
        {
            last_split = g_pChildWnd->nSplitPos;
            draw_splitbar(hWnd, last_split);
            SetCapture(hWnd);
        }
        break;
    }

    case WM_LBUTTONUP:
    case WM_RBUTTONDOWN:
        if (GetCapture() == hWnd)
        {
            finish_splitbar(hWnd, LOWORD(lParam));
        }
        break;

    case WM_CAPTURECHANGED:
        if (GetCapture()==hWnd && last_split>=0)
            draw_splitbar(hWnd, last_split);
        break;

    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            if (GetCapture() == hWnd)
            {
                RECT rt;
                draw_splitbar(hWnd, last_split);
                GetClientRect(hWnd, &rt);
                ResizeWnd(rt.right, rt.bottom);
                last_split = -1;
                ReleaseCapture();
                SetCursor(LoadCursorW(0, IDC_ARROW));
            }
        break;

    case WM_MOUSEMOVE:
        if (GetCapture() == hWnd)
        {
            HDC hdc;
            RECT rt;
            HGDIOBJ OldObj;
            int x = LOWORD(lParam);
            if(!SizingPattern)
            {
                const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
                SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern);
            }
            if(!SizingBrush)
            {
                SizingBrush = CreatePatternBrush(SizingPattern);
            }

            GetClientRect(hWnd, &rt);
            x = (SHORT) min(max(x, SPLIT_MIN), rt.right - SPLIT_MIN);
            if(last_split != x)
            {
                rt.left = last_split-SPLIT_WIDTH/2;
                rt.right = last_split+SPLIT_WIDTH/2+1;
                hdc = GetDC(hWnd);
                OldObj = SelectObject(hdc, SizingBrush);
                PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT);
                last_split = x;
                rt.left = x-SPLIT_WIDTH/2;
                rt.right = x+SPLIT_WIDTH/2+1;
                PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT);
                SelectObject(hdc, OldObj);
                ReleaseDC(hWnd, hdc);
            }
        }
        break;

    case WM_SETFOCUS:
        if (g_pChildWnd != NULL)
        {
            SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd);
        }
        break;

    case WM_TIMER:
        break;

    case WM_NOTIFY:
        if ((int)wParam == TREE_WINDOW && g_pChildWnd != NULL)
        {
            switch (((LPNMHDR)lParam)->code)
            {
            case TVN_ITEMEXPANDING:
                return !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam);
            case TVN_SELCHANGED:
                UpdateAddress(((NMTREEVIEW*)lParam)->itemNew.hItem, NULL, NULL);
                break;
            case NM_SETFOCUS:
                g_pChildWnd->nFocusPanel = 0;
                break;
            case TVN_BEGINLABELEDIT:
            {
                LPNMTVDISPINFO ptvdi;
                /* cancel label edit for rootkeys  */
                ptvdi = (LPNMTVDISPINFO) lParam;
                if (!TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem) ||
                    !TreeView_GetParent(g_pChildWnd->hTreeWnd, TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem)))
                    return TRUE;
                break;
            }
            case TVN_ENDLABELEDIT:
            {
                LPCWSTR keyPath;
                HKEY hRootKey;
                HKEY hKey = NULL;
                LPNMTVDISPINFO ptvdi;
                LONG lResult = TRUE;
                WCHAR szBuffer[MAX_PATH];

                ptvdi = (LPNMTVDISPINFO) lParam;
                if (ptvdi->item.pszText)
                {
                    keyPath = GetItemPath(g_pChildWnd->hTreeWnd, TreeView_GetParent(g_pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey);
                    _snwprintf(szBuffer, COUNT_OF(szBuffer), L"%s\\%s", keyPath, ptvdi->item.pszText);
                    keyPath = GetItemPath(g_pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey);
                    if (RegOpenKeyExW(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
                    {
                        lResult = FALSE;
                        RegCloseKey(hKey);
                        (void)TreeView_EditLabel(g_pChildWnd->hTreeWnd, ptvdi->item.hItem);
                    }
                    else
                    {
                        if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
                            lResult = FALSE;
                        else
                            UpdateAddress(ptvdi->item.hItem, hRootKey, szBuffer);
                    }
                    return lResult;
                }
            }
            default:
                return 0;
            }
        }
        else
        {
            if ((int)wParam == LIST_WINDOW && g_pChildWnd != NULL)
            {
                switch (((LPNMHDR)lParam)->code)
                {
                case NM_SETFOCUS:
                    g_pChildWnd->nFocusPanel = 1;
                    break;
                default:
                    if(!ListWndNotifyProc(g_pChildWnd->hListWnd, wParam, lParam, &Result))
                    {
                        goto def;
                    }
                    return Result;
                    break;
                }
            }
        }
        break;

    case WM_CONTEXTMENU:
    {
        POINT pt;
        if((HWND)wParam == g_pChildWnd->hListWnd)
        {
            int i, cnt;
            BOOL IsDefault;
            pt.x = (short) LOWORD(lParam);
            pt.y = (short) HIWORD(lParam);
            cnt = ListView_GetSelectedCount(g_pChildWnd->hListWnd);
            i = ListView_GetNextItem(g_pChildWnd->hListWnd, -1, LVNI_FOCUSED | LVNI_SELECTED);
            if (pt.x == -1 && pt.y == -1)
            {
                RECT rc;
                if (i != -1)
                {
                    rc.left = LVIR_BOUNDS;
                    SendMessageW(g_pChildWnd->hListWnd, LVM_GETITEMRECT, i, (LPARAM) &rc);
                    pt.x = rc.left + 8;
                    pt.y = rc.top + 8;
                }
                else
                    pt.x = pt.y = 0;
                ClientToScreen(g_pChildWnd->hListWnd, &pt);
            }
            if(i == -1)
            {
                TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW), TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
            }
            else
            {
                HMENU mnu = GetSubMenu(hPopupMenus, PM_MODIFYVALUE);
                SetMenuDefaultItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND);
                IsDefault = IsDefaultValue(g_pChildWnd->hListWnd, i);
                if(cnt == 1)
                    EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | (IsDefault ? MF_DISABLED | MF_GRAYED : MF_ENABLED));
                else
                    EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
                EnableMenuItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED));
                EnableMenuItem(mnu, ID_EDIT_MODIFY_BIN, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED));

                TrackPopupMenu(mnu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
            }
        }
        else if ((HWND)wParam == g_pChildWnd->hTreeWnd)
        {
            TVHITTESTINFO hti;
            HMENU hContextMenu;
            TVITEMW item;
            MENUITEMINFOW mii;
            WCHAR resource[256];
            WCHAR buffer[256];
            LPWSTR s;
            LPCWSTR keyPath;
            HKEY hRootKey;
            int iLastPos;
            WORD wID;

            pt.x = (short) LOWORD(lParam);
            pt.y = (short) HIWORD(lParam);

            if (pt.x == -1 && pt.y == -1)
            {
                RECT rc;
                hti.hItem = TreeView_GetSelection(g_pChildWnd->hTreeWnd);
                if (hti.hItem != NULL)
                {
                    TreeView_GetItemRect(g_pChildWnd->hTreeWnd, hti.hItem, &rc, TRUE);
                    pt.x = rc.left + 8;
                    pt.y = rc.top + 8;
                    ClientToScreen(g_pChildWnd->hTreeWnd, &pt);
                    hti.flags = TVHT_ONITEM;
                }
                else
                    hti.flags = 0;
            }
            else
            {
                hti.pt.x = pt.x;
                hti.pt.y = pt.y;
                ScreenToClient(g_pChildWnd->hTreeWnd, &hti.pt);
                (void)TreeView_HitTest(g_pChildWnd->hTreeWnd, &hti);
            }

            if (hti.flags & TVHT_ONITEM)
            {
                hContextMenu = GetSubMenu(hPopupMenus, PM_TREECONTEXT);
                (void)TreeView_SelectItem(g_pChildWnd->hTreeWnd, hti.hItem);

                memset(&item, 0, sizeof(item));
                item.mask = TVIF_STATE | TVIF_CHILDREN;
                item.hItem = hti.hItem;
                (void)TreeView_GetItem(g_pChildWnd->hTreeWnd, &item);

                /* Set the Expand/Collapse menu item appropriately */
                LoadStringW(hInst, (item.state & TVIS_EXPANDED) ? IDS_COLLAPSE : IDS_EXPAND, buffer, COUNT_OF(buffer));
                memset(&mii, 0, sizeof(mii));
                mii.cbSize = sizeof(mii);
                mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_ID;
                mii.fState = (item.cChildren > 0) ? MFS_DEFAULT : MFS_GRAYED;
                mii.wID = (item.state & TVIS_EXPANDED) ? ID_TREE_COLLAPSEBRANCH : ID_TREE_EXPANDBRANCH;
                mii.dwTypeData = (LPWSTR) buffer;
                SetMenuItemInfo(hContextMenu, 0, TRUE, &mii);

                /* Remove any existing suggestions */
                memset(&mii, 0, sizeof(mii));
                mii.cbSize = sizeof(mii);
                mii.fMask = MIIM_ID;
                GetMenuItemInfo(hContextMenu, GetMenuItemCount(hContextMenu) - 1, TRUE, &mii);
                if ((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX))
                {
                    do
                    {
                        iLastPos = GetMenuItemCount(hContextMenu) - 1;
                        GetMenuItemInfo(hContextMenu, iLastPos, TRUE, &mii);
                        RemoveMenu(hContextMenu, iLastPos, MF_BYPOSITION);
                    }
                    while((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX));
                }

                /* Come up with suggestions */
                keyPath = GetItemPath(g_pChildWnd->hTreeWnd, NULL, &hRootKey);
                SuggestKeys(hRootKey, keyPath, Suggestions, COUNT_OF(Suggestions));
                if (Suggestions[0])
                {
                    AppendMenu(hContextMenu, MF_SEPARATOR, 0, NULL);

                    LoadStringW(hInst, IDS_GOTO_SUGGESTED_KEY, resource, COUNT_OF(resource));

                    s = Suggestions;
                    wID = ID_TREE_SUGGESTION_MIN;
                    while(*s && (wID <= ID_TREE_SUGGESTION_MAX))
                    {
                        _snwprintf(buffer, COUNT_OF(buffer), resource, s);

                        memset(&mii, 0, sizeof(mii));
                        mii.cbSize = sizeof(mii);
                        mii.fMask = MIIM_STRING | MIIM_ID;
                        mii.wID = wID++;
                        mii.dwTypeData = buffer;
                        InsertMenuItem(hContextMenu, GetMenuItemCount(hContextMenu), TRUE, &mii);

                        s += wcslen(s) + 1;
                    }
                }
                TrackPopupMenu(hContextMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, g_pChildWnd->hWnd, NULL);
            }
        }
        break;
    }

    case WM_SIZE:
        if (wParam != SIZE_MINIMIZED && g_pChildWnd != NULL)
        {
            ResizeWnd(LOWORD(lParam), HIWORD(lParam));
        }
        /* fall through */
    default:
def:
        return DefWindowProcW(hWnd, message, wParam, lParam);
    }
    return 0;
}
Пример #11
0
// -----------------------------------------------------------------------
// Initialize Form
int CALLBACK FRMRegsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    int i = 0;

    switch(uMsg)
    {
        case WM_SYSCOLORCHANGE:
            ListViewSetBackColor(FRMRegsListview, GetSysColor(COLOR_WINDOW));
            break;
        case WM_INITDIALOG:
            ControlSetText(hwndDlg, "Register files extensions");
            FRMRegsCmdRegister = CreateButton(256, 1, 77, 23, hwndDlg, "Register", 1, 0, 0, 0, BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP, Buttons_StaticEdge);
            FRMRegsCmdUnRegister = CreateButton(256, 25, 77, 23, hwndDlg, "Unregister", 3, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMRegsCmdCancel = CreateButton(256, 49, 77, 23, hwndDlg, "Cancel", 2, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMRegsCmdSelAll = CreateButton(256, 75, 77, 23, hwndDlg, "Select all", 4, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMRegsCmdUnSelAll = CreateButton(256, 99, 77, 23, hwndDlg, "Unselect all", 5, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMRegsListview = CreateListView(2, 1, 251, 211, hwndDlg, 6, 0, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP, LVS_REPORT | LVS_SINGLESEL | WS_TABSTOP | LVS_NOSORTHEADER, WS_EX_STATICEDGE);
            ListViewAddCol(FRMRegsListview, "Language", 145, 1);
            ListViewAddCol(FRMRegsListview, "Extension", 83, 0);
            FillExtLanguage();
            SetFocus(FRMRegsListview);
            return(0);
        case WM_NOTIFY:
            if(ControlGetNotifiedhWnd(lParam) == FRMRegsListview)
            {
                switch(ControlGetNotifiedMsg(lParam))
                {
                    case NM_DBLCLK:
                        ListViewCheckBoxItemDoubleClick(FRMRegsListview);
                        return(0);
                }
            }
            break;
        case WM_COMMAND:
            if((HWND) lParam == FRMRegsCmdSelAll)
            {
                for(i = 0; i <= (long) ListViewItemCount(FRMRegsListview) - 1; i++)
                {
                    ListViewSetItemCheckbox(FRMRegsListview, i, 1);
                }
                return(0);
            }
            else if((HWND) lParam == FRMRegsCmdUnSelAll)
            {
                for(i = 0; i <= (long) ListViewItemCount(FRMRegsListview) - 1; i++)
                {
                    ListViewSetItemCheckbox(FRMRegsListview, i, 0);
                }
                return(0);
            }
            else if((HWND) lParam == FRMRegsCmdRegister)
            {
                RegisterExtensions();
                SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, NULL, NULL);
                ControlClose(hwndDlg);
                return(0);
            }
            else if((HWND) lParam == FRMRegsCmdUnRegister)
            {
                UnRegisterExtensions();
                SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, NULL, NULL);
                ControlClose(hwndDlg);
                return(0);
            }
            else if((HWND) lParam == FRMRegsCmdCancel)
            {
                ControlClose(hwndDlg);
                return(0);
            }
            break;
        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            break;
    }
    return(0);
}
Пример #12
0
LRESULT CALLBACK stream_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    RECT		rect ;
    int cxClient, cyClient;
    static HMENU	hMenu ;
    POINT point ;
    int ret, idx;
    TCHAR  buf[64];
    char file_name[MAX_FILE_PATH_LEN];

    static int edit_iItem=-1 ;
    static int edit_iSubItem;

     LVITEM lv_item;
    switch (message)
    {
        case WM_CREATE:
            hwnd_stream= hwnd;
            hMenu = LoadMenu (g_hInstance, TEXT("my_popup_menu")) ;
            hMenu = GetSubMenu (hMenu, 0) ;

            hwnd_dynamic_edit=CreateWindow (TEXT("edit"), TEXT(""),
                WS_CHILD|ES_AUTOHSCROLL,
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                hwnd, (HMENU)ID_DYNAMIC_EDIT, g_hInstance, NULL) ;

            SendMessage(hwnd_dynamic_edit, WM_SETFONT, (WPARAM)char_font_2, 0); 

            hwnd_lv = CreateListView(hwnd);
            //InitListViewImageLists(hwnd_lv);
            InitListViewColumns(hwnd_lv);
            lv_row_color_init();
            old_lv_proc = (WNDPROC) SetWindowLong (hwnd_lv, 
                                 	GWL_WNDPROC, (LONG)my_lv_proc) ;

            ShowWindow(hwnd_lv, 1) ;
            refresh_window(hwnd_lv) ;

           add_tip(hwndTip, hwnd_lv, TEXT("点击鼠标右键进行操作"));

            return 0 ;

        case WM_SIZE:
      		cxClient = LOWORD (lParam) ;
      		cyClient = HIWORD (lParam) ;

            MoveWindow(hwnd_lv, 	0, 0,
                cxClient, cyClient, TRUE) ;

            return 0 ;

case WM_NOTIFY:
{

   NMHDR *pt_nmhdr=(void *)lParam;
   switch(LOWORD(wParam))
   { 
     case ID_LV:

     // if code == NM_CLICK - Single click on an item
     if(pt_nmhdr->code == NM_CLICK || pt_nmhdr->code == NM_DBLCLK) 
     {
        int iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
        int iSubItem=((LPNMITEMACTIVATE)lParam)->iSubItem;

        if (iItem>=0 && ((iSubItem>=3 && iSubItem<=5) || iSubItem==7)) 
        {

            ListView_GetSubItemRect(hwnd_lv,iItem,iSubItem,LVIR_LABEL,&rect);
            ListView_GetItemText(hwnd_lv, iItem, iSubItem, buf, sizeof(buf));
            MoveWindow	(hwnd_dynamic_edit
                ,rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE);
            SetWindowText(hwnd_dynamic_edit, buf);
            ShowWindow (hwnd_dynamic_edit, 1) ;
            SetFocus(hwnd_dynamic_edit);
            SendMessage(hwnd_dynamic_edit, EM_SETSEL, (WPARAM)0, (LPARAM)-1);

            edit_iItem = iItem;
            edit_iSubItem = iSubItem;

        }

            return 0;
     }
    else if (pt_nmhdr->code == NM_RCLICK)
    {
        point = ((LPNMITEMACTIVATE)lParam)->ptAction;
        ListView_GetItem(hwnd_lv, &lv_item);

        ClientToScreen (hwnd_lv, &point) ;
  		TrackPopupMenu (hMenu, TPM_LEFTBUTTON, point.x, point.y, 0, hwnd_stream, NULL) ;
        return 0;

    }
    else if (pt_nmhdr->code == LVN_ITEMCHANGED)
    {
        if (!init_over) break;
        if (lv_in_op)   break;
        //if((((LPNMLISTVIEW)lParam)->uOldState&LVIS_STATEIMAGEMASK) != 
        //    (((LPNMLISTVIEW)lParam)->uNewState&LVIS_STATEIMAGEMASK)) 
        {
            int iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
            int selected = ListView_GetCheckState(hwnd_lv, iItem);

            if (g_apt_streams[iItem]->selected!=selected)
            {
                doc_modified=1;
                g_apt_streams[iItem]->selected=selected;
                update_statusbar();
            }
        }
        return 0;

    }
    
    break;

   }

   break;
}

        case 	WM_COMMAND:
            switch (LOWORD(wParam))
            {
                  
                case    IDM_STREAM_NEW:
                    init_stream(&gt_edit_stream);
                    gt_edit_stream.len=gat_sample_pkts[0].len;
                    memcpy(gt_edit_stream.data, gat_sample_pkts[0].pkt_data, gt_edit_stream.len);

                    ret=DialogBox(g_hInstance, TEXT("STREAM_EDIT_DLG"), hwnd, StreamEditDlgProc);
                    if (IDOK==ret)
                    {
                        add_stream(&gt_edit_stream);
                        re_populate_items();
                    }
               	return 0 ;

                case    IDM_STREAM_NEW_HEX:
                {
                    int len;
                    char buf[MAX_PACKET_LEN];
                    if (get_open_file_name(file_name, hwnd, ALL_FILE_FILTER))
                        return 0;

                    len = read_file_to_buf(buf, sizeof(buf)-1, file_name);
                    if (len>0)
                        add_stream_from_hex_text(buf, len);
                    else
                        err_msg_box("读取文件内容失败");
                   	return 0 ;
                }

                case    IDM_STREAM_NEW_BIN:
                {
                    int len;
                    char buf[MAX_PACKET_LEN];
                    if (get_open_file_name(file_name, hwnd, ALL_FILE_FILTER))
                        return 0;

                    len = read_file_to_buf(buf, sizeof(buf)-1, file_name);
                    if (len>0)
                        add_stream_from_raw_data(buf, len);
                    else
                        err_msg_box("读取文件内容失败");
                   	return 0 ;
                }

                case    IDM_STREAM_NEW_PCAP:
                {
                    if (get_open_file_name(file_name, hwnd, PCAP_FILE_FILTER))
                        return 0;
                    add_stream_from_pcap(file_name);
                   	return 0 ;
                }
                                
                case    IDM_STREAM_DEL:
                    idx=GetIndex(hwnd_lv);
       				//ListView_DeleteItem(hwnd_lv, idx);
                    delete_stream(idx);
                    re_populate_items();
                    update_statusbar();
       				return 0 ;
                case    IDM_STREAM_EDIT:
                    cur_strm_idx=GetIndex(hwnd_lv);
                    if (cur_strm_idx<0) return 0;
                    cpy_stream(&gt_edit_stream, g_apt_streams[cur_strm_idx]);
                    ret=DialogBox(g_hInstance, TEXT("STREAM_EDIT_DLG"), hwnd, StreamEditDlgProc);
                    if (IDOK==ret)
                    {
                        doc_modified=1;
                        cpy_stream(g_apt_streams[cur_strm_idx], &gt_edit_stream);
                        re_populate_items();
                    }
       				//ListView_DeleteAllItems(hwnd_lv);
       				return 0 ;
                case    IDM_STREAM_DEL_SEL:
       				//DelSel(hwnd_lv);
                    delete_sel_stream();
                    re_populate_items();
                    update_statusbar();
       				return 0 ;

                case    IDM_STREAM_SEL_ALL:
       				SelAll(hwnd_lv);
       				return 0 ;

                case    IDM_STREAM_SEL_RVS:
       				SelRvs(hwnd_lv);
       				return 0 ;
                    
                case    IDM_STREAM_COPY:
       				copy_idx = GetIndex(hwnd_lv);
       				return 0 ;

                case    IDM_STREAM_PASTE:
       				cpy_stream(&gt_edit_stream, g_apt_streams[copy_idx]);
                    add_stream(&gt_edit_stream);
                    re_populate_items();
       				return 0 ;

                case    IDM_STREAM_MAKE_FRAGS:
                {
       				ret=DialogBox(g_hInstance, TEXT("FRAG_DLG"), hwnd, FragDlgProc);
       				return 0 ;
                }

                case    IDM_STREAM_SEL2PCAP:
                {
                    ret=get_save_file_name(file_name, hwnd, PCAP_FILE_FILTER, PCAP_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream2dump(file_name);
                    update_pcap_file_history(file_name);
       				return 0 ;
                }

                case    IDM_STREAM_2_BIN:
                {
                    ret=get_save_file_name(file_name, hwnd, BIN_FILE_FILTER, BIN_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream_2_bin(file_name);
       				return 0 ;
                }

                case    IDM_STREAM_2_TEXT:
                {
                    ret=get_save_file_name(file_name, hwnd, TEXT_FILE_FILTER, TEXT_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream_2_text(file_name);
       				return 0 ;
                }
                
                case    ID_DYNAMIC_EDIT:
       				if (HIWORD(wParam)==EN_KILLFOCUS)
                    {

            update_grid_from_edit(edit_iItem, edit_iSubItem);
            edit_iItem=-1;

           				return 0 ;
                    }

            }
            break;

case   WM_KEYDOWN:
    if (VK_RETURN==wParam)
    {

        SetFocus(hwnd);

         return 0;

    }
    break;

        case 	WM_INITMENUPOPUP:
        {
            int idx=GetIndex(hwnd_lv);
            t_stream *pt_stream = g_apt_streams[idx];
            int sel_cnt=GetSelCnt(hwnd_lv);
            int item_cnt=ListView_GetItemCount(hwnd_lv);
            if (lParam == 0)
            {
                UINT add_stream_menu_state = nr_cur_stream<MAX_STREAM_NUM ? MF_ENABLED : MF_GRAYED;
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_HEX, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_BIN, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_PCAP, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_EDIT, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_DEL, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_COPY, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_PASTE, copy_idx>=0 && item_cnt>copy_idx ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_DEL_SEL, sel_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL_ALL, item_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL_RVS, item_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_MAKE_FRAGS, idx>=0&&stream_fragable(pt_stream) ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL2PCAP, sel_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_2_BIN, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_2_TEXT, idx>=0 ? MF_ENABLED : MF_GRAYED);

                return 0;

            }

            break;
        }

    }
    
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Пример #13
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

        switch (message)
           {
           case WM_COMMAND:
              {
              switch (LOWORD(wParam))
                 {
                 case IDM_NEW:
                    if (hLV) {
                        DestroyWindow (hLV);
                    }
                    CreateListView(hWnd);
                    break;

                 case IDM_ABOUT:
                    DialogBox (hInst, TEXT("AboutBox"), hWnd, About);
                    break;

                 case IDM_EXIT:
                    PostMessage (hWnd, WM_CLOSE, 0, 0);
                    break;


                 default:
                    return (DefWindowProc(hWnd, message, wParam, lParam));
                 }
              }
              break;

           case WM_NOTIFY:
             {
             LPNMHDR lpnmhdr = (LPNMHDR) lParam;

             switch (lpnmhdr->code) {
                  case LVN_BEGINLABELEDIT:
                       return FALSE;

                  case LVN_ENDLABELEDIT:
                       return TRUE;

                  default:
                       break;
             }
             }
             break;

           case WM_SIZE:
             if (hLV) {
                 MoveWindow(hLV, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
             }
             break;

           case WM_CLOSE:
              if (hLV) {
                DestroyWindow (hLV);
              }
              DestroyWindow (hWnd);
              break;

           case WM_DESTROY:
              PostQuitMessage(0);
              break;

           default:
              return (DefWindowProc(hWnd, message, wParam, lParam));
           }

        return FALSE;
}
Пример #14
0
// -----------------------------------------------------------------------
// Initialize Form
int CALLBACK FRMAddInsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT CreatePs;
    long CurrentLvItem = 0;
    long AddInIcon = 0;
    CStr RunningInIniFile;
    POINT PopMenuCoords;
    CStr OpFilters;
    CStr LdFile;
    FARPROC AddInAuthUpDate = 0;
    FARPROC AddInDescUpDate = 0;
    long OldRunningState = 0;
    CStr BufString;

    switch(uMsg)
    {
        case WM_SYSCOLORCHANGE:
            ListViewSetBackColor(FRMAddInsListView, GetSysColor(COLOR_WINDOW));
            break;
        case WM_INITDIALOG:
            FRMAddInshWnd = hwndDlg;
            ControlSetText(hwndDlg, "AddIns manager");
            FRMAddInsCmdOk = CreateButton(327, 292, 77, 23, hwndDlg, "Ok", 1, 0, 0, 0, BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP, Buttons_StaticEdge);
            FRMAddInsCmdCancel = CreateButton(406, 292, 77, 23, hwndDlg, "Cancel", 2, 0, 0, 0, WS_TABSTOP, Buttons_StaticEdge);
            FRMAddInsListView = CreateListView(2, 1, 482, 278, hwndDlg, 0, GlobalImageList1, 0, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES, LVS_REPORT | LVS_SINGLESEL | WS_TABSTOP | LVS_NOSORTHEADER, WS_EX_STATICEDGE);
            ListViewAddCol(FRMAddInsListView, "Author", 198, 0);
            ListViewAddCol(FRMAddInsListView, "Description", 265, 1);
            ListViewSetItemSel(FRMAddInsListView, 0);
            FillAddinsList();
            hAddInsMenu = CreatePopupMenu();
            MenuAddString(hAddInsMenu, "Load/Unload AddIn", ADDIN_IDBASE + ADDIN_ENABLE, TRUE);
            MenuSetDefaultItem(hAddInsMenu, 0);
            MenuAddSeparator(hAddInsMenu);
            MenuAddString(hAddInsMenu, "Display in AddIns menu", ADDIN_IDBASE + ADDIN_MENU, TRUE);
            MenuAddString(hAddInsMenu, "Remove from AddIns menu", ADDIN_IDBASE + ADDIN_REMMENU, TRUE);
            MenuAddSeparator(hAddInsMenu);
            MenuAddString(hAddInsMenu, "Update AddIn", ADDIN_IDBASE + ADDIN_UPDATE, TRUE);
            FreezeTimer = 1;
            return(0);
        case WM_PAINT:
            BeginPaint(hwndDlg, &CreatePs);
            GDIDrawHorzSep(hwndDlg, 0, 285, 486);
            EndPaint(hwndDlg, &CreatePs);
            break;
        case WM_COMMAND:
            if((HWND) lParam == FRMAddInsCmdOk)
            {
                SaveAddInList();
                ReFillAddInsArrays();
                FillAddInsMenu();
                RefreshRunningStates();
                ControlClose(hwndDlg);
                return(0);
            }
            else if((HWND) lParam == FRMAddInsCmdCancel)
            {
                ControlClose(hwndDlg);
                return(0);
            }
            switch(wParam)
            {
                case (ADDIN_ENABLE + ADDIN_IDBASE):
                    AddInIcon = ListViewGetSubItemImage(FRMAddInsListView, CurrentPopupItem, 0);
                    if(AddInIcon == ICON_ADDINR) AddInIcon = ICON_ADDINS;
                    else AddInIcon = ICON_ADDINR;
                    ListViewSetSubItemImage(FRMAddInsListView, AddInIcon, CurrentPopupItem, 0);
                    return(0);
                case (ADDIN_MENU + ADDIN_IDBASE):
                    ListViewSetItemCheckbox(FRMAddInsListView, CurrentPopupItem, 1);
                    return(0);
                case (ADDIN_REMMENU + ADDIN_IDBASE):
                    ListViewSetItemCheckbox(FRMAddInsListView, CurrentPopupItem, 0);
                    return(0);
                case (ADDIN_UPDATE + ADDIN_IDBASE):
                    OpFilters = AppTitle + (CStr) " AddIn (*.dll)|*.dll";
                    LdFile = ComDlgGetOpenFileName(hwndDlg, OpFilters, LastAddInDir, 0, CurrentDir);
                    if(LdFile.Len() != 0)
                    {
                        // Check if the AddIn is located in AddIns directory
                        if(_strcmpi(FileGetDirectory(LdFile).Get_String(), Dirs[DIR_ADDINS]) == 0)
                        {
                            MiscMsgBox(hwndDlg, "New AddIn can't be located in AddIns directory.", MB_ERROR, Requesters);
                            return(0);
                        }
                        // Check if file exist
                        if(FileExist(Dirs[DIR_ADDINS] + (CStr) "\\" + (CStr) FileGetFileName(LdFile)) == 0)
                        {
                            MiscMsgBox(hwndDlg, "No corresponding AddIn found.", MB_ERROR, Requesters);
                            return(0);
                        }
                        // Check if names are identicals
                        if(_strcmpi(LocalAddInsFiles.Get(CurrentPopupItem)->Content,
                                   FileGetFileName(LdFile).Get_String()) != 0)
                        {
                            MiscMsgBox(hwndDlg, "AddIn name doesn't match.", MB_ERROR, Requesters);
                            return(0);
                        }
                        if(IsAddIn(LdFile) == 0)
                        {
                            MiscMsgBox(hwndDlg, "Not a Chromatic AddIn.", MB_ERROR, Requesters);
                            return(0);
                        }
                        // Step 1: Shutdown it
                        OldRunningState = ShutDownAddIn(CurrentPopupItem);
                        // Step 2: Delete it
                        BufString = Dirs[DIR_ADDINS] + (CStr) "\\" + (CStr) LocalAddInsFiles.Get(CurrentPopupItem)->Content;
                        DeleteFile(BufString.Get_String());
                        // Step 3: Copy it
                        CopyFile(LdFile.Get_String(), BufString.Get_String(), 0);
                        // Step 4: Restart it
                        RunningAddIns.Set(CurrentPopupItem, OldRunningState);
                        if(RestartAddIn(CurrentPopupItem) == 0)
                        {
                            MiscMsgBox(hwndDlg, "Can't update this AddIn.", MB_ERROR, Requesters);
                            return(0);
                        }
                        SetForegroundWindow(FRMAddInshWnd);
                        SetActiveWindow(FRMAddInshWnd);
                        // Step 5: Update listview with possible new infos
                        AddInDescUpDate = GetProcAddress(AddInsDLL.Get(CurrentPopupItem)->Content, "AddInDescription");
                        AddInAuthUpDate = GetProcAddress(AddInsDLL.Get(CurrentPopupItem)->Content, "AddInAuthor");
                        ListViewSetSelItemText(FRMAddInsListView, GetDLLDescription(LocalAddInsFiles.Get(CurrentPopupItem)->Content, AddInDescUpDate), 0);
                        ListViewSetSelItemText(FRMAddInsListView, GetDLLAuthor(AddInAuthUpDate), 1);
                        LastAddInDir = FileGetDirectory(LdFile);
                        MiscMsgBox(hwndDlg, "AddIn '" + GetDLLDescription(LocalAddInsFiles.Get(CurrentPopupItem)->Content, AddInDescUpDate) + (CStr) "' updated.", MB_INFORMATION, Requesters);
                    }
                    return(0);
            }
            break;
        case WM_NOTIFY:
            if(ControlGetNotifiedhWnd(lParam) == FRMAddInsListView)
            {
                switch(ControlGetNotifiedMsg(lParam))
                {
                    case NM_DBLCLK:
                        CurrentLvItem = ListViewGetItemUnderCursor(FRMAddInsListView);
                        if(CurrentLvItem != -1)
                        {
                            AddInIcon = ListViewGetSubItemImage(FRMAddInsListView, CurrentLvItem, 0);
                            if(AddInIcon == ICON_ADDINR) AddInIcon = ICON_ADDINS;
                            else AddInIcon = ICON_ADDINR;
                            ListViewSetItemSel(FRMAddInsListView, CurrentLvItem);
                            ListViewSetSubItemImage(FRMAddInsListView, AddInIcon, CurrentLvItem, 0);
                        }
                        return(0);
                }
            }
            break;
        case WM_CONTEXTMENU:
            CurrentLvItem = ListViewGetItemUnderCursor(FRMAddInsListView);
            if(CurrentLvItem != -1)
            {
                ListViewSetItemSel(FRMAddInsListView, CurrentLvItem);
                CurrentPopupItem = ListViewGetItemUnderCursor(FRMAddInsListView);
                SetFocus(FRMAddInsListView);
                GetCursorPos(&PopMenuCoords);
                TrackPopupMenu(hAddInsMenu, TPM_LEFTALIGN + TPM_LEFTBUTTON, PopMenuCoords.x, PopMenuCoords.y, 0, hwndDlg, NULL);
            }
            return(0);
        case WM_CLOSE:
            if(hAddInsMenu != 0) DestroyMenu(hAddInsMenu);
            FreezeTimer = 0;
            FRMAddInsListView = 0;
            EndDialog(hwndDlg, 0);
    }
    return(0);
}
Пример #15
0
// -----------------------------------------------
// List view di lettura (senza sort header)
// -----------------------------------------------
void * ehzListView(struct OBJ *objCalled,EN_MESSAGE cmd,LONG info,void *ptr)
{
	EH_DISPEXT *psExt=ptr;
	static SINT HdbMovi=-1;
	static INT16 iSend;
	DWORD dwExStyle;
	SINT iLVIndex;

	if (fReset)
	{
		if (cmd!=WS_START) win_infoarg("Inizializzare ehzListView()");
		memset(&_arsLv,0,sizeof(EH_LVLIST)*LVMAX);
		EhListInizialize();
		fReset=FALSE;
		return 0;
	}

	iLVIndex=LVFind(LV_FINDOBJ,objCalled);
	if (iLVIndex<0) iLVIndex=LVAlloc(objCalled);

 switch(cmd)
	{
		case WS_INF:
			return &_arsLv[iLVIndex];
 
		case WS_OPEN: // Creazione
			
			objCalled->hWnd=CreateListView(objCalled->nome,sys.EhWinInstance,WindowNow());
			_arsLv[iLVIndex].hWndList=objCalled->hWnd;
			_arsLv[iLVIndex].hWndHeader=ListView_GetHeader(objCalled->hWnd);//GetWindow(objCalled->hWnd, GW_CHILD);
			_arsLv[iLVIndex].idHeader=GetDlgCtrlID(_arsLv[iLVIndex].hWndHeader);
			_arsLv[iLVIndex].fLeftClick=TRUE;
			_arsLv[iLVIndex].fRightClick=TRUE;
			_arsLv[iLVIndex].fDoubleClick=FALSE;
			break;

		case WS_EXTNOTIFY:
			switch (info)
			{
				case 0: _arsLv[iLVIndex].subListNotify=ptr; break;
				case 1: _arsLv[iLVIndex].subMessage=ptr; break;
				case 2: _arsLv[iLVIndex].subHeaderNotify=ptr; break;
			}				
			break;

		case WS_SETFLAG:

			if (!strcmp(ptr,"STYLE")) // Setta lo stile della finestra
			{
				DWORD dwStyle;
				dwStyle=GetWindowLong(objCalled->hWnd, GWL_STYLE);
				dwStyle|=info;
				SetWindowLong(objCalled->hWnd, GWL_STYLE, (DWORD) dwStyle);
			}

			if (!strcmp(ptr,"!STYLE")) // Setta lo stile della finestra
			{
				LONG lStyle;
				lStyle=GetWindowLong(objCalled->hWnd, GWL_STYLE);
				lStyle&=~info;
				SetWindowLong(objCalled->hWnd, GWL_STYLE, lStyle);
			}

			if (!strcmp(ptr,"STYLEMASK")) // Setta lo stile della finestra
			{
				DWORD dwStyle;
				dwStyle=GetWindowLong(objCalled->hWnd, GWL_STYLE);
				//win_infoarg("%08x",~LVS_TYPESTYLEMASK);
				dwStyle=dwStyle&~LVS_TYPESTYLEMASK|info;
				SetWindowLong(objCalled->hWnd, GWL_STYLE, (DWORD) dwStyle);
			}

			if (!strcmp(ptr,"EXSTYLE")) // Setta lo stile della finestra
			{
				dwExStyle=ListView_GetExtendedListViewStyle(objCalled->hWnd);
				dwExStyle|=info;
				ListView_SetExtendedListViewStyle(objCalled->hWnd,dwExStyle);
			}

			if (!strcmp(ptr,"!EXSTYLE")) // Setta lo stile della finestra
			{
				dwExStyle=ListView_GetExtendedListViewStyle(objCalled->hWnd);
				dwExStyle&=~info;
				ListView_SetExtendedListViewStyle(objCalled->hWnd,dwExStyle);
			}

			if (!strcmp(ptr,"DCLK")) // Setta il Double Click
			{
				_arsLv[iLVIndex].fDoubleClick=info;
			}
			break;

		case WS_CLOSE: // Distruzione
			DestroyWindow(objCalled->hWnd);
			break;

		case WS_DEL: // Cancella le colonne
			while (TRUE)
			{
				if (!ListView_DeleteColumn(objCalled->hWnd,0)) break;
			}
    		break;

		case WS_ADD: // Aggiungi una colonna
			ListView_InsertColumn(objCalled->hWnd, info, (LV_COLUMN *) ptr);
			break;

		case WS_LINK: // Aggiunge un Item
			//
			if (ListView_SetItem(objCalled->hWnd,(LPLVITEM) ptr)==FALSE) 
				{ListView_InsertItem(objCalled->hWnd,(LPLVITEM) ptr);}
			break;

		case WS_DO: // Spostamento / Ridimensionamento
			MoveWindow(objCalled->hWnd,psExt->px,psExt->py,psExt->lx,psExt->ly,TRUE);
			break;

		case WS_DISPLAY: 
			InvalidateRect(objCalled->hWnd,NULL,TRUE);
			break;
	}
	return NULL;
}
Пример #16
0
/*******************************************************************************
 *
 *  FUNCTION: ChildWndProc(HWND, unsigned, WORD, LONG)
 *
 *  PURPOSE:  Processes messages for the child windows.
 *
 *  WM_COMMAND  - process the application menu
 *  WM_PAINT    - Paint the main window
 *  WM_DESTROY  - post a quit message and return
 *
 */
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
    case WM_CREATE:
        g_pChildWnd = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
        if (!g_pChildWnd) return 0;
        LoadStringW(hInst, IDS_REGISTRY_ROOT_NAME, g_pChildWnd->szPath, MAX_PATH);
        g_pChildWnd->nSplitPos = 250;
        g_pChildWnd->hWnd = hWnd;
        g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, TREE_WINDOW);
        g_pChildWnd->hListWnd = CreateListView(hWnd, LIST_WINDOW/*, g_pChildWnd->szPath*/);
        g_pChildWnd->nFocusPanel = 1;
        SetFocus(g_pChildWnd->hTreeWnd);
        get_last_key(g_pChildWnd->hTreeWnd);
        break;
    case WM_COMMAND:
        if (!_CmdWndProc(hWnd, message, wParam, lParam)) {
            goto def;
        }
        break;
    case WM_PAINT:
        OnPaint(hWnd);
        return 0;
    case WM_SETCURSOR:
        if (LOWORD(lParam) == HTCLIENT) {
            POINT pt;
            GetCursorPos(&pt);
            ScreenToClient(hWnd, &pt);
            if (pt.x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
                return TRUE;
            }
        }
        goto def;
    case WM_DESTROY:
        set_last_key(g_pChildWnd->hTreeWnd);
        HeapFree(GetProcessHeap(), 0, g_pChildWnd);
        g_pChildWnd = NULL;
        PostQuitMessage(0);
        break;
    case WM_LBUTTONDOWN: {
            RECT rt;
            int x = (short)LOWORD(lParam);
            GetClientRect(hWnd, &rt);
            if (x>=g_pChildWnd->nSplitPos-SPLIT_WIDTH/2 && x<g_pChildWnd->nSplitPos+SPLIT_WIDTH/2+1) {
                last_split = g_pChildWnd->nSplitPos;
                draw_splitbar(hWnd, last_split);
                SetCapture(hWnd);
            }
            break;
        }

    /* WM_RBUTTONDOWN sets the splitbar the same way as WM_LBUTTONUP */
    case WM_LBUTTONUP:
    case WM_RBUTTONDOWN:
        if (GetCapture() == hWnd) {
            finish_splitbar(hWnd, LOWORD(lParam));
        }
        break;

    case WM_CAPTURECHANGED:
        if (GetCapture()==hWnd && last_split>=0)
            draw_splitbar(hWnd, last_split);
        break;

    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            if (GetCapture() == hWnd) {
                RECT rt;
                draw_splitbar(hWnd, last_split);
                GetClientRect(hWnd, &rt);
                ResizeWnd(rt.right, rt.bottom);
                last_split = -1;
                ReleaseCapture();
                SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
            }
        break;

    case WM_MOUSEMOVE:
        if (GetCapture() == hWnd) {
            RECT rt;
            int x = LOWORD(lParam);
            HDC hdc = GetDC(hWnd);
            GetClientRect(hWnd, &rt);
            rt.left = last_split-SPLIT_WIDTH/2;
            rt.right = last_split+SPLIT_WIDTH/2+1;
            InvertRect(hdc, &rt);
            last_split = x;
            rt.left = x-SPLIT_WIDTH/2;
            rt.right = x+SPLIT_WIDTH/2+1;
            InvertRect(hdc, &rt);
            ReleaseDC(hWnd, hdc);
        }
        break;

    case WM_SETFOCUS:
        if (g_pChildWnd != NULL) {
            SetFocus(g_pChildWnd->nFocusPanel? g_pChildWnd->hListWnd: g_pChildWnd->hTreeWnd);
        }
        break;

    case WM_TIMER:
        break;

    case WM_NOTIFY:
        if (((int)wParam == TREE_WINDOW) && (g_pChildWnd != NULL)) {
            switch (((LPNMHDR)lParam)->code) {
            case TVN_ITEMEXPANDINGW:
                return !OnTreeExpanding(g_pChildWnd->hTreeWnd, (NMTREEVIEWW*)lParam);
            case TVN_SELCHANGEDW:
                OnTreeSelectionChanged(g_pChildWnd->hTreeWnd, g_pChildWnd->hListWnd,
                    ((NMTREEVIEWW *)lParam)->itemNew.hItem, TRUE);
                break;
	    case NM_SETFOCUS:
		g_pChildWnd->nFocusPanel = 0;
		break;
            case NM_RCLICK: {
		POINT pt;
                GetCursorPos(&pt);
		TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW),
			       TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL);
		break;
            }
            case TVN_BEGINLABELEDITW: {
                HKEY hRootKey;
                LPWSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
                if (!path || !*path) return 1;
                return 0;
            }
	    case TVN_ENDLABELEDITW: {
		HKEY hRootKey;
	        LPNMTVDISPINFOW dispInfo = (LPNMTVDISPINFOW)lParam;
		LPWSTR path = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey);
	        BOOL res = RenameKey(hWnd, hRootKey, path, dispInfo->item.pszText);
		if (res) {
		    TVITEMEXW item;
                    LPWSTR fullPath = GetPathFullPath(g_pChildWnd->hTreeWnd,
                     dispInfo->item.pszText);
		    item.mask = TVIF_HANDLE | TVIF_TEXT;
		    item.hItem = (HTREEITEM)SendMessageW(g_pChildWnd->hTreeWnd, TVM_GETNEXTITEM, TVGN_CARET, 0);
		    item.pszText = dispInfo->item.pszText;
                    SendMessageW( g_pChildWnd->hTreeWnd, TVM_SETITEMW, 0, (LPARAM)&item );
                    SendMessageW(hStatusBar, SB_SETTEXTW, 0, (LPARAM)fullPath);
                    HeapFree(GetProcessHeap(), 0, fullPath);
		}
                HeapFree(GetProcessHeap(), 0, path);
		return res;
	    }
            default:
                return 0; /* goto def; */
            }
        } else
            if (((int)wParam == LIST_WINDOW) && (g_pChildWnd != NULL)) {
		if (((LPNMHDR)lParam)->code == NM_SETFOCUS) {
		    g_pChildWnd->nFocusPanel = 1;
		} else if (!SendMessageW(g_pChildWnd->hListWnd, WM_NOTIFY_REFLECT, wParam, lParam)) {
                    goto def;
                }
            }
        break;

    case WM_SIZE:
        if (wParam != SIZE_MINIMIZED && g_pChildWnd != NULL) {
            ResizeWnd(LOWORD(lParam), HIWORD(lParam));
        }
        /* fall through */
default: def:
        return DefWindowProcW(hWnd, message, wParam, lParam);
    }
    return 0;
}