Ejemplo n.º 1
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAERO_SUBCLASS_WND_DATA pWndData = (PAERO_SUBCLASS_WND_DATA)GetProp(hWnd, WINDOW_DATA_STRING);
    ASSERT(pWndData);
    ASSERT(pWndData->m_pDwmApiImpl);
    WNDPROC pOldProc = pWndData->m_oldWndProc;
    ASSERT(pOldProc);
    BOOL bCompositionEnabled = pWndData->m_pDwmApiImpl->IsDwmCompositionEnabled();

    /// 
    /// if aero glass is turned off and if we are not in destruction code, 
    /// just call the original wnd proc we had prior to subclassing:
    /// 
    if(WM_COMMAND!=uMsg && WM_DWMCOMPOSITIONCHANGED!=uMsg && WM_DESTROY!=uMsg && WM_NCDESTROY!=uMsg && !bCompositionEnabled)
        return CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam);

    if (uMsg == pWndData->m_uiRedrawMsg)
    {
        HWND hControl = (HWND)lParam;
        ASSERT(hControl);
        ASSERT(::IsWindow(hControl));

        
        PAERO_SUBCLASS_WND_DATA pCtrlData = (PAERO_SUBCLASS_WND_DATA)GetProp(hControl, WINDOW_DATA_STRING);
        if(pCtrlData && pCtrlData->m_dwFlags & WD_IN_PAINT_CONTROL)
        {
            HDC hdc = GetDC(hControl);
            if(hdc)
            {
                RECT rc;
                VERIFY(GetWindowRect(hControl, &rc));

                VERIFY(MapWindowPoints(NULL, hControl, (LPPOINT) &rc, 2));

                PaintControl(hControl, hdc, &rc, (pCtrlData->m_dwFlags & WD_DRAW_BORDER)!=0);
                VERIFY(1==ReleaseDC(hControl, hdc));
            }
            pCtrlData->m_dwFlags &= ~WD_IN_PAINT_CONTROL;
            return 0;
        }
    }



    switch(uMsg)
    {
        case WM_CTLCOLORSTATIC:
            {
                HWND hControl = (HWND)lParam;
                ASSERT(hControl);
                ASSERT(IsWindow(hControl));
                PAERO_SUBCLASS_WND_DATA pCtrlData = (PAERO_SUBCLASS_WND_DATA)GetProp(hControl, WINDOW_DATA_STRING);
                if(pCtrlData)
                {
                    if(pCtrlData->m_dwFlags&WD_RETURN_BLACK_BRUSH)
                        return (LRESULT)GetStockObject(BLACK_BRUSH);

                    else if(pCtrlData->m_dwFlags&WD_RETURN_WHITE_BRUSH)
                        return (LRESULT)GetStockObject(WHITE_BRUSH);
                    else
                    {
                        pCtrlData->m_dwFlags|=WD_IN_PAINT_CONTROL;
                        PostMessage((HWND)lParam, pWndData->m_uiRedrawMsg, 0, NULL);
                    }
                }
            }

            break;
        case WM_CTLCOLOREDIT:
            {
                PAERO_SUBCLASS_WND_DATA pCtrlData = (PAERO_SUBCLASS_WND_DATA)GetProp((HWND)lParam, WINDOW_DATA_STRING);
                if(pCtrlData)
                    pCtrlData->m_dwFlags|=WD_IN_PAINT_CONTROL;
                PostMessage((HWND)lParam, pWndData->m_uiRedrawMsg, 0, NULL);
            }
            break;

        case WM_PAINT:
            {
                if(!IsIconic(hWnd) && !(pWndData->m_dwFlags&WD_NO_FRAME_EXTEND))
                {
                    PAINTSTRUCT ps;
                    HDC hdc = BeginPaint(hWnd, &ps);

                    /// 
                    /// we have to paint the *entire* client area in black, not only the
                    /// paint area inside ps, because otherwise we get ugly areas of white
                    /// if we partially move the window out of the desktop and back in again:
                    /// 
                    /// 
                    MARGINS marGlassInset = {-1, -1, -1, -1}; // -1 means the whole window
                    if(hdc && pWndData->m_pDwmApiImpl->IsDwmCompositionEnabled() 
                        && SUCCEEDED(pWndData->m_pDwmApiImpl->DwmExtendFrameIntoClientArea(hWnd, &marGlassInset)))
                    {
                        RECT rcClient;
                        VERIFY(GetClientRect(hWnd, &rcClient));
                        VERIFY(PatBlt(hdc, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));
                    }

                    EndPaint(hWnd, &ps);
                    return 1;
                }
            }
            break;
        case WM_COMMAND:
            {
                if(bCompositionEnabled)
                {
                    if(LBN_SELCHANGE==HIWORD(wParam))
                    {
                        InvalidateRgn((HWND)lParam, NULL, TRUE);
                        VERIFY(UpdateWindow((HWND)lParam));
                    }
                }

                if(ACN_STOP==HIWORD(wParam))
                {
                    /// 
                    /// if it is an animation control that has just stopped playing,
                    /// reset the WD_PLAY flag so it repaints itself properly again if
                    /// e.g. Aero is turned off an on again:
                    /// 
                    PAERO_SUBCLASS_WND_DATA pCtrlData = (PAERO_SUBCLASS_WND_DATA)GetProp((HWND)lParam, WINDOW_DATA_STRING);                    
                    if(pCtrlData)
                    {
                        pCtrlData->m_dwFlags&=~WD_PLAY;
                    }
                }
                if(ACN_START==HIWORD(wParam))
                {
                    PAERO_SUBCLASS_WND_DATA pCtrlData = (PAERO_SUBCLASS_WND_DATA)GetProp((HWND)lParam, WINDOW_DATA_STRING);                    
                    if(pCtrlData)
                    {
                        pCtrlData->m_dwFlags|=WD_PLAY;
                    }
                }

            }

            break;
        case WM_NOTIFY:
            {
                
                LPNMHDR lpnmh = (LPNMHDR)lParam;

                if(lpnmh)
                {
                    ASSERT(lpnmh->hwndFrom);
                    ASSERT(IsWindow(lpnmh->hwndFrom));

                    switch(lpnmh->code)
                    {
                        case LVN_ITEMCHANGED:
                        {
                            /// 
                            /// if we select and deselect list view items,
                            /// its header control sometimes vanishes so
                            /// we have to force a redraw:
                            /// 
                            HWND hHeader = ListView_GetHeader(lpnmh->hwndFrom);
                            if(hHeader)
                            {
                                InvalidateRgn(hHeader, NULL, TRUE);
                                VERIFY(UpdateWindow(hHeader));
                            }
                         }
                            break;
                         default:
                            break;
                    }
                }
            }

            break;
        case WM_DESTROY:
            ASSERT(pWndData->m_pUxTheme);
            ASSERT(pWndData->m_pDwmApiImpl);
            VERIFY(SUCCEEDED(pWndData->m_pUxTheme->BufferedPaintUnInit()));
            delete pWndData->m_pUxTheme;
            delete pWndData->m_pDwmApiImpl;
            if(WndProc==(WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC))
            {
                VERIFY(WndProc==(WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR) pWndData->m_oldWndProc));
                VERIFY(pWndData==RemoveProp(hWnd, WINDOW_DATA_STRING)); 
                VERIFY(!LocalFree(pWndData));
            }
            break;
        case WM_NCDESTROY:
            if(WndProc==(WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC))
            {
                VERIFY(WndProc==(WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR) pWndData->m_oldWndProc));
                VERIFY(pWndData==RemoveProp(hWnd, WINDOW_DATA_STRING)); 
                VERIFY(!LocalFree(pWndData));
            }
            break;
                
    }
    
    return CallWindowProc(pOldProc, hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 2
0
INT_PTR CALLBACK EspServiceTriggersDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
)
{
    PSERVICE_TRIGGERS_CONTEXT context;

    if (uMsg == WM_INITDIALOG)
    {
        context = PhAllocate(sizeof(SERVICE_TRIGGERS_CONTEXT));
        memset(context, 0, sizeof(SERVICE_TRIGGERS_CONTEXT));

        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PSERVICE_TRIGGERS_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_DESTROY)
            RemoveProp(hwndDlg, L"Context");
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
    {
        NTSTATUS status;
        LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
        PPH_SERVICE_ITEM serviceItem = (PPH_SERVICE_ITEM)propSheetPage->lParam;
        HWND triggersLv;

        context->ServiceItem = serviceItem;
        context->TriggersLv = triggersLv = GetDlgItem(hwndDlg, IDC_TRIGGERS);
        context->TriggerContext = EsCreateServiceTriggerContext(
                                      context->ServiceItem,
                                      hwndDlg,
                                      triggersLv
                                  );

        status = EspLoadTriggerInfo(hwndDlg, context);

        if (!NT_SUCCESS(status))
        {
            PhShowWarning(hwndDlg, L"Unable to query service trigger information: %s",
                          ((PPH_STRING)PH_AUTO(PhGetNtMessage(status)))->Buffer);
        }
    }
    break;
    case WM_DESTROY:
    {
        EsDestroyServiceTriggerContext(context->TriggerContext);
        PhFree(context);
    }
    break;
    case WM_COMMAND:
    {
        switch (LOWORD(wParam))
        {
        case IDC_NEW:
            if (context->TriggerContext)
                EsHandleEventServiceTrigger(context->TriggerContext, ES_TRIGGER_EVENT_NEW);
            break;
        case IDC_EDIT:
            if (context->TriggerContext)
                EsHandleEventServiceTrigger(context->TriggerContext, ES_TRIGGER_EVENT_EDIT);
            break;
        case IDC_DELETE:
            if (context->TriggerContext)
                EsHandleEventServiceTrigger(context->TriggerContext, ES_TRIGGER_EVENT_DELETE);
            break;
        }
    }
    break;
    case WM_NOTIFY:
    {
        LPNMHDR header = (LPNMHDR)lParam;

        switch (header->code)
        {
        case PSN_KILLACTIVE:
        {
            SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
        }
        return TRUE;
        case PSN_APPLY:
        {
            ULONG win32Result = 0;

            SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);

            if (!EsSaveServiceTriggerInfo(context->TriggerContext, &win32Result))
            {
                if (win32Result == ERROR_CANCELLED || (PhShowMessage(
                        hwndDlg,
                        MB_ICONERROR | MB_RETRYCANCEL,
                        L"Unable to change service trigger information: %s",
                        ((PPH_STRING)PH_AUTO(PhGetWin32Message(win32Result)))->Buffer
                                                       ) == IDRETRY))
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                }
            }

            return TRUE;
        }
        break;
        case LVN_ITEMCHANGED:
        {
            if (header->hwndFrom == context->TriggersLv && context->TriggerContext)
            {
                EsHandleEventServiceTrigger(context->TriggerContext, ES_TRIGGER_EVENT_SELECTIONCHANGED);
            }
        }
        break;
        case NM_DBLCLK:
        {
            if (header->hwndFrom == context->TriggersLv && context->TriggerContext)
            {
                EsHandleEventServiceTrigger(context->TriggerContext, ES_TRIGGER_EVENT_EDIT);
            }
        }
        break;
        }
    }
    break;
    }

    return FALSE;
}
Ejemplo n.º 3
0
LRESULT CALLBACK NcAreaWndSubclassProc(
    _In_ HWND hWnd,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam,
    _In_ UINT_PTR uIdSubclass,
    _In_ ULONG_PTR dwRefData
    )
{
    PEDIT_CONTEXT context;

    context = (PEDIT_CONTEXT)GetProp(hWnd, L"EditSubclassContext");

    switch (uMsg)
    {
    case WM_NCDESTROY:
        {
            NcAreaFreeTheme(context);

            if (context->ImageList)
                ImageList_Destroy(context->ImageList);

            if (context->WindowFont)
                DeleteObject(context->WindowFont);

            RemoveWindowSubclass(hWnd, NcAreaWndSubclassProc, uIdSubclass);
            RemoveProp(hWnd, L"EditSubclassContext");
            PhFree(context);
        }
        break;
    case WM_ERASEBKGND:
        return 1;
    case WM_NCCALCSIZE:
        {
            LPNCCALCSIZE_PARAMS ncCalcSize = (NCCALCSIZE_PARAMS*)lParam;

            // Let Windows handle the non-client defaults.
            DefSubclassProc(hWnd, uMsg, wParam, lParam);

            // Deflate the client area to accommodate the custom button.
            ncCalcSize->rgrc[0].right -= context->CXWidth;
        }
        return 0;
    case WM_NCPAINT:
        {
            RECT windowRect;

            // Let Windows handle the non-client defaults.
            DefSubclassProc(hWnd, uMsg, wParam, lParam);

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Adjust the coordinates (start from 0,0).
            OffsetRect(&windowRect, -windowRect.left, -windowRect.top);

            // Get the position of the inserted button.
            NcAreaGetButtonRect(context, &windowRect);

            // Draw the button.
            NcAreaDrawButton(context, windowRect);
        }
        return 0;
    case WM_NCHITTEST:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            windowPoint.x = GET_X_LPARAM(lParam);
            windowPoint.y = GET_Y_LPARAM(lParam);

            // Get the position of the inserted button.
            GetWindowRect(hWnd, &windowRect);
            NcAreaGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                return HTBORDER;
            }
        }
        break;
    case WM_NCLBUTTONDOWN:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            windowPoint.x = GET_X_LPARAM(lParam);
            windowPoint.y = GET_Y_LPARAM(lParam);

            // Get the position of the inserted button.
            GetWindowRect(hWnd, &windowRect);
            NcAreaGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                context->Pushed = TRUE;

                SetCapture(hWnd);

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    case WM_LBUTTONUP:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            windowPoint.x = GET_X_LPARAM(lParam);
            windowPoint.y = GET_Y_LPARAM(lParam);

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Adjust the coordinates (start from 0,0).
            OffsetRect(&windowRect, -windowRect.left, -windowRect.top);

            // Get the position of the inserted button.
            NcAreaGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                // Forward click notification.
                SendMessage(PhMainWndHandle, WM_COMMAND, MAKEWPARAM(context->CommandID, BN_CLICKED), 0);
            }

            if (GetCapture() == hWnd)
            {
                context->Pushed = FALSE;
                ReleaseCapture();
            }

            RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
        }
        break;
    case WM_KEYDOWN:
        {
            if (wParam == '\t' || wParam == '\r')
            {
                HWND tnHandle;

                tnHandle = GetCurrentTreeNewHandle();

                if (tnHandle)
                {
                    SetFocus(tnHandle);

                    if (wParam == '\r')
                    {
                        if (TreeNew_GetFlatNodeCount(tnHandle) > 0)
                        {
                            TreeNew_DeselectRange(tnHandle, 0, -1);
                            TreeNew_SelectRange(tnHandle, 0, 0);
                            TreeNew_SetFocusNode(tnHandle, TreeNew_GetFlatNode(tnHandle, 0));
                            TreeNew_SetMarkNode(tnHandle, TreeNew_GetFlatNode(tnHandle, 0));
                        }
                    }
                }
                else
                {
                    PTOOLSTATUS_TAB_INFO tabInfo;

                    if ((tabInfo = FindTabInfo(SelectedTabIndex)) && tabInfo->ActivateContent)
                        tabInfo->ActivateContent(wParam == '\r');
                }

                return FALSE;
            }

            // Handle CTRL+A below Vista.
            if (WindowsVersion < WINDOWS_VISTA && (GetKeyState(VK_CONTROL) & VK_LCONTROL) && wParam == 'A')
            {
                Edit_SetSel(hWnd, 0, -1);
                return FALSE;
            }
        }
        break;
    case WM_CHAR:
        if (wParam == '\t' || wParam == '\r')
            return FALSE;
        break;
    case WM_CUT:
    case WM_CLEAR:
    case WM_PASTE:
    case WM_UNDO:
    case WM_KEYUP:
    case WM_SETTEXT:
    case WM_KILLFOCUS:
        RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
        break;
    case WM_SETTINGCHANGE:
    case WM_SYSCOLORCHANGE:
    case WM_THEMECHANGED:
        {
            NcAreaFreeTheme(context);
            NcAreaInitializeTheme(context);
            NcAreaInitializeFont(context);

            // Reset the client area margins.
            SendMessage(hWnd, EM_SETMARGINS, EC_LEFTMARGIN, MAKELPARAM(0, 0));

            // Force the edit control to update its non-client area.
            RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            //SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
        }
        break;
    case WM_SETFOCUS:
        {
            if (SearchBoxDisplayMode != SEARCHBOX_DISPLAY_MODE_HIDEINACTIVE)
                break;

            if (!RebarBandExists(REBAR_BAND_ID_SEARCHBOX))
            {
                UINT height = (UINT)SendMessage(RebarHandle, RB_GETROWHEIGHT, 0, 0);
                RebarBandInsert(REBAR_BAND_ID_SEARCHBOX, SearchboxHandle, PhMultiplyDivide(180, PhGlobalDpi, 96), height - 2);
            }
        }
        break;
    case WM_NCMOUSEMOVE:
        {
            POINT windowPoint;
            RECT windowRect;

            // Get the screen coordinates of the mouse.
            windowPoint.x = GET_X_LPARAM(lParam);
            windowPoint.y = GET_Y_LPARAM(lParam);

            // Get the screen coordinates of the window.
            GetWindowRect(hWnd, &windowRect);

            // Get the position of the inserted button.
            NcAreaGetButtonRect(context, &windowRect);

            // Check that the mouse is within the inserted button.
            if (PtInRect(&windowRect, windowPoint))
            {
                if (!context->Hot)
                {
                    TRACKMOUSEEVENT trackMouseEvent = { sizeof(TRACKMOUSEEVENT) };
                    trackMouseEvent.dwFlags = TME_LEAVE | TME_NONCLIENT;
                    trackMouseEvent.hwndTrack = hWnd;

                    context->Hot = TRUE;
                    RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);

                    TrackMouseEvent(&trackMouseEvent);
                }
            }
        }
        break;
    case WM_NCMOUSELEAVE:
        {
            if (context->Hot)
            {
                context->Hot = FALSE;

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    case WM_MOUSEMOVE:
        {
            if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
            {
                POINT windowPoint;
                RECT windowRect;

                // Get the screen coordinates of the mouse.
                windowPoint.x = GET_X_LPARAM(lParam);
                windowPoint.y = GET_Y_LPARAM(lParam);

                // Get the screen coordinates of the window.
                GetWindowRect(hWnd, &windowRect);

                // Adjust the coordinates (start from 0,0).
                OffsetRect(&windowRect, -windowRect.left, -windowRect.top);

                // Get the position of the inserted button.
                NcAreaGetButtonRect(context, &windowRect);

                // Check that the mouse is within the inserted button.
                context->Pushed = PtInRect(&windowRect, windowPoint);

                RedrawWindow(hWnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
            }
        }
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 4
0
INT_PTR CALLBACK RestartComputerDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PSERVICE_RECOVERY_CONTEXT context;

    if (uMsg == WM_INITDIALOG)
    {
        context = (PSERVICE_RECOVERY_CONTEXT)lParam;
        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PSERVICE_RECOVERY_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_DESTROY)
            RemoveProp(hwndDlg, L"Context");
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            SetDlgItemInt(hwndDlg, IDC_RESTARTCOMPAFTER, context->RebootAfter / (1000 * 60), FALSE); // ms to min
            Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE), context->RebootMessage ? BST_CHECKED : BST_UNCHECKED);
            SetDlgItemText(hwndDlg, IDC_RESTARTMESSAGE, PhGetString(context->RebootMessage));

            SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_RESTARTCOMPAFTER), TRUE);
            Edit_SetSel(GetDlgItem(hwndDlg, IDC_RESTARTCOMPAFTER), 0, -1);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDOK:
                {
                    context->RebootAfter = GetDlgItemInt(hwndDlg, IDC_RESTARTCOMPAFTER, NULL, FALSE) * 1000 * 60;

                    if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE)) == BST_CHECKED)
                        PhMoveReference(&context->RebootMessage, PhGetWindowText(GetDlgItem(hwndDlg, IDC_RESTARTMESSAGE)));
                    else
                        PhClearReference(&context->RebootMessage);

                    context->Dirty = TRUE;

                    EndDialog(hwndDlg, IDOK);
                }
                break;
            case IDC_USEDEFAULTMESSAGE:
                {
                    PPH_STRING message;
                    PWSTR computerName;
                    ULONG bufferSize;
                    BOOLEAN allocated = TRUE;

                    // Get the computer name.

                    bufferSize = 64;
                    computerName = PhAllocate((bufferSize + 1) * sizeof(WCHAR));

                    if (!GetComputerName(computerName, &bufferSize))
                    {
                        PhFree(computerName);
                        computerName = PhAllocate((bufferSize + 1) * sizeof(WCHAR));

                        if (!GetComputerName(computerName, &bufferSize))
                        {
                            PhFree(computerName);
                            computerName = L"(unknown)";
                            allocated = FALSE;
                        }
                    }

                    // This message is exactly the same as the one in the Services console,
                    // except the double spaces are replaced by single spaces.
                    message = PhFormatString(
                        L"Your computer is connected to the computer named %s. "
                        L"The %s service on %s has ended unexpectedly. "
                        L"%s will restart automatically, and then you can reestablish the connection.",
                        computerName,
                        context->ServiceItem->Name->Buffer,
                        computerName,
                        computerName
                        );
                    SetDlgItemText(hwndDlg, IDC_RESTARTMESSAGE, message->Buffer);
                    PhDereferenceObject(message);

                    if (allocated)
                        PhFree(computerName);

                    Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE), BST_CHECKED);
                }
                break;
            case IDC_RESTARTMESSAGE:
                {
                    if (HIWORD(wParam) == EN_CHANGE)
                    {
                        // A zero length restart message disables it, so we might as well uncheck the box.
                        Button_SetCheck(GetDlgItem(hwndDlg, IDC_ENABLERESTARTMESSAGE),
                            GetWindowTextLength(GetDlgItem(hwndDlg, IDC_RESTARTMESSAGE)) != 0 ? BST_CHECKED : BST_UNCHECKED);
                    }
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 5
0
LRESULT FrameWindow::FrameWndProc(HWND hWndFrame, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    FrameWindow* frame = (FrameWindow*)GetProp(hWndFrame, L"FrameWindowPointer");

    switch(uMsg)
    {
    case WM_NCCREATE:
        if(NULL == frame)
        {
            frame = new FrameWindow(hWndFrame);
            SetProp(hWndFrame, L"FrameWindowPointer", frame);
        }
        return TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDM_ABOUT:
            DialogBox((HINSTANCE)GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUTBOX), hWndFrame, AboutDialog::About);
            break;

		case IDM_NEW:
			frame->NewDocument(wParam, lParam);
			break;

        case IDM_EXIT:
            DestroyWindow(hWndFrame);
            break;

        default:
            if(frame)
                return DefFrameProc(hWndFrame, frame->hClientWnd, uMsg, wParam, lParam);
	        else
		        return DefFrameProc(hWndFrame, NULL, uMsg, wParam, lParam);
        }
        break;
        
    case WM_CREATE:
        return frame->Create(wParam, lParam);

    case WM_NCDESTROY:
        RemoveProp(hWndFrame,  L"FrameWindowPointer");  // remove the C++ object pointer from the property list
        if(frame)
            delete frame;
        PostQuitMessage(0);
        return 0;

	case WM_SIZE:
		return frame->Size(wParam, lParam);

    default:
       if(frame)
           return DefFrameProc(hWndFrame, frame->hClientWnd, uMsg, wParam, lParam);
	   else
		   return DefFrameProc(hWndFrame, NULL, uMsg, wParam, lParam);
    }

       if(frame)
           return DefFrameProc(hWndFrame, frame->hClientWnd, uMsg, wParam, lParam);
	   else
		   return DefFrameProc(hWndFrame, NULL, uMsg, wParam, lParam);
}
Ejemplo n.º 6
0
CWindowBase::~CWindowBase()
{
	RemoveProp(m_hWnd, _T("CWindowBase"));
}
Ejemplo n.º 7
0
BOOL FAR PASCAL CfgEdtBox (HWND hWnd, unsigned uMsg, WPARAM wParam,
                LPARAM lParam)
{
    #define PRPLOW  "PrpLow"
    #define PRPHGH  "PrpHgh"
    DIGCFG  FAR *   lpDigCfg;           /* Inst local data block ptr    */
    BOOL            bfXlt_OK;

    switch (uMsg) {
    case WM_INITDIALOG:
        /****************************************************************/
        /* Store instance specific data pointer                         */
        /****************************************************************/
        if (!SetProp (hWnd, PRPLOW, (HANDLE) LOWORD (lParam)) ||
            !SetProp (hWnd, PRPHGH, (HANDLE) HIWORD (lParam))) {
            EndDialog (hWnd, -1);
            break;
        }
        lpDigCfg = (DIGCFG FAR *) lParam;

        /****************************************************************/
        /****************************************************************/
        CtrDlgBox (NULL, hWnd, NULL, CTR_CTR);

        /****************************************************************/
        SetDlgItemInt (hWnd, DI_LVLINP, lpDigCfg->usLvlInp, FALSE);
        SetDlgItemInt (hWnd, DI_LVLOUT, lpDigCfg->usLvlOut, FALSE);

        /************************************************************/
        /* Set focus on 1st edit cntrl, ask Windows not to override */
        /************************************************************/
        SetFocus (GetDlgItem (hWnd, IDOK));
        return (FALSE);
  
    case WM_CTLCOLOR:
      if ((CTLCOLOR_DLG == HIWORD (lParam)) 
        || (CTLCOLOR_STATIC == HIWORD (lParam)) 
        || (CTLCOLOR_BTN == HIWORD (lParam))) { 
          SetBkColor ((HDC) wParam, MCIGlo.ulDBxClr);
          return ((BOOL) MCIGlo.hDBxBsh);
      }
      return (FALSE);

    case WM_COMMAND:
      if (NULL == (lpDigCfg = (DIGCFG FAR *) 
        MAKELONG (GetProp (hWnd, PRPLOW), GetProp (hWnd, PRPHGH)))) {
          EndDialog (hWnd, -1);
          break;
      }
      switch(wParam) {
        /****************************************************************/
        /****************************************************************/
        case IDOK:
            lpDigCfg->usLvlInp = GetDlgItemInt (hWnd, DI_LVLINP, &bfXlt_OK, FALSE);
            lpDigCfg->usLvlOut = GetDlgItemInt (hWnd, DI_LVLOUT, &bfXlt_OK, FALSE);
            EndDialog(hWnd, 0);
            return(TRUE);

        case IDCANCEL:
            EndDialog(hWnd, -1);
            return(TRUE);

        default:
            return(FALSE);
      }
      break;

    case WM_DESTROY:
      RemoveProp (hWnd, PRPLOW);
      RemoveProp (hWnd, PRPHGH);
      break;

    default:
        return(FALSE);
    }

    return(FALSE);
}
Ejemplo n.º 8
0
static INT_PTR CALLBACK PhpProcessTerminatorDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            PPH_PROCESS_ITEM processItem = (PPH_PROCESS_ITEM)lParam;
            PPH_STRING title;
            HWND lvHandle;
            HIMAGELIST imageList;
            ULONG i;

            PhCenterWindow(hwndDlg, GetParent(hwndDlg));

            title = PhFormatString(
                L"Terminator - %s (%u)",
                processItem->ProcessName->Buffer,
                (ULONG)processItem->ProcessId
                );
            SetWindowText(hwndDlg, title->Buffer);
            PhDereferenceObject(title);

            SetProp(hwndDlg, L"ProcessItem", (HANDLE)processItem);

            lvHandle = GetDlgItem(hwndDlg, IDC_TERMINATOR_LIST);
            PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 70, L"ID");
            PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 280, L"Description");
            ListView_SetExtendedListViewStyleEx(lvHandle, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES, -1);
            PhSetControlTheme(lvHandle, L"explorer");

            imageList = ImageList_Create(16, 16, ILC_COLOR32, 0, 0);
            ImageList_SetImageCount(imageList, 2);
            PhSetImageListBitmap(imageList, CROSS_INDEX, PhInstanceHandle, MAKEINTRESOURCE(IDB_CROSS));
            PhSetImageListBitmap(imageList, TICK_INDEX, PhInstanceHandle, MAKEINTRESOURCE(IDB_TICK));

            for (i = 0; i < sizeof(PhTerminatorTests) / sizeof(TEST_ITEM); i++)
            {
                INT itemIndex;
                BOOLEAN check;

                itemIndex = PhAddListViewItem(
                    lvHandle,
                    MAXINT,
                    PhTerminatorTests[i].Id,
                    &PhTerminatorTests[i]
                    );
                PhSetListViewSubItem(lvHandle, itemIndex, 1, PhTerminatorTests[i].Description);
                PhSetListViewItemImageIndex(lvHandle, itemIndex, -1);

                check = TRUE;

                if (WSTR_EQUAL(PhTerminatorTests[i].Id, L"TT4") || WSTR_EQUAL(PhTerminatorTests[i].Id, L"M1"))
                    check = FALSE;

                ListView_SetCheckState(lvHandle, itemIndex, check);
            }

            ListView_SetImageList(lvHandle, imageList, LVSIL_SMALL);

            SetDlgItemText(
                hwndDlg,
                IDC_TERMINATOR_TEXT,
                L"Double-click a termination method or click Run Selected."
                );
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, L"ProcessItem");
        }
        break;
    case WM_COMMAND:
        {
            INT id = LOWORD(wParam);

            switch (id)
            {
            case IDCANCEL: // Esc and X button to close
            case IDOK:
                EndDialog(hwndDlg, IDOK);
                break;
            case IDC_RUNSELECTED:
                {
                    if (PhShowConfirmMessage(hwndDlg, L"run", L"the selected terminator tests", NULL, FALSE))
                    {
                        HWND lvHandle;
                        ULONG i;

                        lvHandle = GetDlgItem(hwndDlg, IDC_TERMINATOR_LIST);

                        for (i = 0; i < sizeof(PhTerminatorTests) / sizeof(TEST_ITEM); i++)
                        {
                            if (ListView_GetCheckState(lvHandle, i))
                            {
                                if (PhpRunTerminatorTest(
                                    hwndDlg,
                                    i
                                    ))
                                    break;
                            }
                        }
                    }
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            if (header->hwndFrom == GetDlgItem(hwndDlg, IDC_TERMINATOR_LIST))
            {
                if (header->code == NM_DBLCLK)
                {
                    LPNMITEMACTIVATE itemActivate = (LPNMITEMACTIVATE)header;

                    if (itemActivate->iItem != -1)
                    {
                        if (PhShowConfirmMessage(hwndDlg, L"run", L"the selected test", NULL, FALSE))
                        {
                            PhpRunTerminatorTest(
                                hwndDlg,
                                itemActivate->iItem
                                );
                        }
                    }
                }
                else if (header->code == LVN_ITEMCHANGED)
                {
                    ULONG i;
                    BOOLEAN oneSelected;

                    oneSelected = FALSE;

                    for (i = 0; i < sizeof(PhTerminatorTests) / sizeof(TEST_ITEM); i++)
                    {
                        if (ListView_GetCheckState(header->hwndFrom, i))
                        {
                            oneSelected = TRUE;
                            break;
                        }
                    }

                    EnableWindow(GetDlgItem(hwndDlg, IDC_RUNSELECTED), oneSelected);
                }
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 9
0
inline BOOL HookHandle(UINT MessageId, HWND hWnd, WPARAM wParam, LPARAM lParam)
{
	////////////////////////////////////////////////////////////////
	// HANDLE DEFERRED UPDATES

	// Is this a deferred-update message?
	if (MessageId == VNC_DEFERRED_UPDATE)
	{

		// NOTE : NEVER use the SendDeferred- routines to send updates
		//		from here, or you'll get an infinite loop....!

		// NB : The format of DEFERRED_UPDATE matches that of UpdateRectMessage,
		//		so just send the exact same message data to WinVNC
		PostThreadMessage(
			vnc_thread_id,
			UpdateRectMessage,
			wParam,
			lParam
			);

		return FALSE;
	}

	// *** Could use WM_COPYDATA to send data to WinVNC

/*
	if (GetClassLong(hWnd, GCW_ATOM) == 32768)
	{
		_RPT4(_CRT_WARN, "DBG : popup menu message (hwnd=%d, msg=%d, l=%d, w=%d)\n",
		hWnd, MessageId, lParam, wParam);
	}
*/

	////////////////////////////////////////////////////////////////
	// UPDATE-TRIGGERING MESSAGES

	// Do something dependent upon message type
	switch (MessageId)
	{
		
		////////////////////////////////////////////////////////////////
		// Messages indicating only a border repaint.
	case WM_NCPAINT:
	case WM_NCACTIVATE:
		SendDeferredBorderRect(hWnd);
		old_cursor = NULL;
		break;

		////////////////////////////////////////////////////////////////
		// Messages indicating a client area repaint
	case WM_CHAR:
	case WM_KEYUP:							// Handle key-presses
	case WM_KEYDOWN:
		if (prf_use_KeyPress)
			SendDeferredWindowRect(hWnd);
		break;

	case WM_LBUTTONUP:						// Handle LMB clicks
		if (prf_use_LButtonUp)
			SendDeferredWindowRect(hWnd);
		break;

	case WM_MBUTTONUP:						// Handle MMB clicks
		if (prf_use_MButtonUp)
			SendDeferredWindowRect(hWnd);
		break;

	case WM_RBUTTONUP:						// Handle RMB clicks
		if (prf_use_RButtonUp)
			SendDeferredWindowRect(hWnd);
		break;

	case WM_TIMER:
		if (prf_use_Timer)
			SendDeferredWindowRect(hWnd);
		break;

	case WM_HSCROLL:
	case WM_VSCROLL:
		if (((int) LOWORD(wParam) == SB_THUMBTRACK) || ((int) LOWORD(wParam) == SB_ENDSCROLL))
			SendDeferredWindowRect(hWnd);
		break;

	case 485:  // HACK to handle popup menus
		{
			// Get the old popup menu selection value
			HANDLE prop = GetProp(hWnd, (LPCTSTR) MAKELONG(VNC_POPUPSELN_ATOM, 0));
			if (prop != (HANDLE) wParam)
			{
				// It did, so update the menu & the selection value
				SendDeferredWindowRect(hWnd);
				SetProp(hWnd,
					(LPCTSTR) MAKELONG(VNC_POPUPSELN_ATOM, 0),
					(HANDLE) wParam);
			}
		}
		break;

		////////////////////////////////////////////////////////////////
		// Messages indicating a full window update
	case WM_SYSCOLORCHANGE:
	case WM_PALETTECHANGED:
	case WM_SETTEXT:
	case WM_ENABLE:
	case BM_SETCHECK:
	case BM_SETSTATE:
	case EM_SETSEL:
	//case WM_MENUSELECT:
		SendDeferredWindowRect(hWnd);
		break;

		////////////////////////////////////////////////////////////////
		// Messages indicating that an area of the window needs updating
		// Uses GetUpdateRect to find out which
	case WM_PAINT:
		if (prf_use_GetUpdateRect)
		{
			HRGN region;
			region = CreateRectRgn(0, 0, 0, 0);

			// Get the affected region
			if (GetUpdateRgn(hWnd, region, FALSE) != ERROR)
			{
				int buffsize;
				UINT x;
				RGNDATA *buff;
				POINT TopLeft;

				// Get the top-left point of the client area
				TopLeft.x = 0;
				TopLeft.y = 0;
				if (!ClientToScreen(hWnd, &TopLeft))
					break;

				// Get the size of buffer required
				buffsize = GetRegionData(region, 0, 0);
				if (buffsize != 0)
				{
					buff = (RGNDATA *) new BYTE [buffsize];
					if (buff == NULL)
						break;

					// Now get the region data
					if(GetRegionData(region, buffsize, buff))
					{
						for (x=0; x<(buff->rdh.nCount); x++)
						{
							// Obtain the rectangles from the list
							RECT *urect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + (x * sizeof(RECT)));
							SendDeferredUpdateRect(
								hWnd,
								(SHORT) (TopLeft.x + urect->left),
								(SHORT) (TopLeft.y + urect->top),
								(SHORT) (TopLeft.x + urect->right),
								(SHORT) (TopLeft.y + urect->bottom)
								);

							// Modified by mws for VNC ver. 3.3.6
							// We yield this thread so our PostMessages and socket commands
							// can complete, otherwise this hook can suck up too many
							// timeslices before it returns
							Sleep (0);
						}
					}

					delete [] buff;
				}
			}

			// Now free the region
			if (region != NULL)
				DeleteObject(region);
		}
		else
			SendDeferredWindowRect(hWnd);
		break;

		////////////////////////////////////////////////////////////////
		// Messages indicating full repaint of this and a different window
		// Send the new position of the window
	case WM_WINDOWPOSCHANGING:
		if (IsWindowVisible(hWnd))
			SendWindowRect(hWnd);
		break;

	case WM_WINDOWPOSCHANGED:
		if (IsWindowVisible(hWnd))
			SendDeferredWindowRect(hWnd);
		break;

	////////////////////////////////////////////////////////////////
	// WinVNC also wants to know about mouse movement
	case WM_NCMOUSEMOVE:
	case WM_MOUSEMOVE:
		// Inform WinVNC that the mouse has moved and pass it the current cursor handle
		{
			ULONG new_cursor = (ULONG)GetCursor();
			if (new_cursor != old_cursor) {
					PostThreadMessage(
										vnc_thread_id,
										MouseMoveMessage,
										(ULONG) new_cursor, 0);
				old_cursor=new_cursor;
			}
		}
		break;

    // RealVNC 335
    case WM_MOUSEWHEEL:           // Handle mousewheel events
       SendDeferredWindowRect(hWnd);
       break;
		////////////////////////////////////////////////////////////////
		// VNCHOOKS PROPERTIES HANDLING WINDOWS
	case WM_DESTROY:
		RemoveProp(hWnd, (LPCTSTR) MAKELONG(VNC_POPUPSELN_ATOM, 0));
		break;

	}

	return TRUE;
}
Ejemplo n.º 10
0
Archivo: winpfbdd.c Proyecto: aosm/X11
Bool
winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  Bool			fReturn;
  
  ErrorF ("winCloseScreenPrimaryDD - Freeing screen resources\n");

  /* Flag that the screen is closed */
  pScreenPriv->fClosed = TRUE;
  pScreenPriv->fActive = FALSE;

  /* Call the wrapped CloseScreen procedure */
  pScreen->CloseScreen = pScreenPriv->CloseScreen;
  fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);

  /* Delete the window property */
  RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);

  /* Free the offscreen surface, if there is one */
  if (pScreenPriv->pddsOffscreen)
    {
      IDirectDrawSurface2_Unlock (pScreenPriv->pddsOffscreen, NULL);
      IDirectDrawSurface2_Release (pScreenPriv->pddsOffscreen);
      pScreenPriv->pddsOffscreen = NULL;
    }

  /* Release the primary surface, if there is one */
  if (pScreenPriv->pddsPrimary)
    {
      IDirectDrawSurface2_Unlock (pScreenPriv->pddsPrimary, NULL);
      IDirectDrawSurface2_Release (pScreenPriv->pddsPrimary);
      pScreenPriv->pddsPrimary = NULL;
    }

  /* Free the DirectDraw object, if there is one */
  if (pScreenPriv->pdd)
    {
      IDirectDraw2_RestoreDisplayMode (pScreenPriv->pdd);
      IDirectDraw2_Release (pScreenPriv->pdd);
      pScreenPriv->pdd = NULL;
    }

  /* Delete tray icon, if we have one */
  if (!pScreenInfo->fNoTrayIcon)
    winDeleteNotifyIcon (pScreenPriv);

  /* Free the exit confirmation dialog box, if it exists */
  if (g_hDlgExit != NULL)
    {
      DestroyWindow (g_hDlgExit);
      g_hDlgExit = NULL;
    }

  /* Kill our window */
  if (pScreenPriv->hwndScreen)
    {
      DestroyWindow (pScreenPriv->hwndScreen);
      pScreenPriv->hwndScreen = NULL;
    }

  /* Kill our screeninfo's pointer to the screen */
  pScreenInfo->pScreen = NULL;

  /* Invalidate the ScreenInfo's fb pointer */
  pScreenInfo->pfb = NULL;

  /* Free the screen privates for this screen */
  free ((pointer) pScreenPriv);

  return fReturn;
}
Ejemplo n.º 11
0
INT_PTR CALLBACK PhpChooseProcessDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PCHOOSE_PROCESS_DIALOG_CONTEXT context = NULL;

    if (uMsg == WM_INITDIALOG)
    {
        context = (PCHOOSE_PROCESS_DIALOG_CONTEXT)lParam;
        SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)context);
    }
    else
    {
        context = (PCHOOSE_PROCESS_DIALOG_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom());

        if (uMsg == WM_DESTROY)
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            HWND lvHandle;

            PhCenterWindow(hwndDlg, GetParent(hwndDlg));

            SetDlgItemText(hwndDlg, IDC_MESSAGE, context->Message);

            PhInitializeLayoutManager(&context->LayoutManager, hwndDlg);
            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_MESSAGE), NULL,
                PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE);
            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_LIST), NULL,
                PH_ANCHOR_ALL);
            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDOK), NULL,
                PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDCANCEL), NULL,
                PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_REFRESH), NULL,
                PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT);
            PhLayoutManagerLayout(&context->LayoutManager);

            context->MinimumSize.left = 0;
            context->MinimumSize.top = 0;
            context->MinimumSize.right = 280;
            context->MinimumSize.bottom = 170;
            MapDialogRect(hwndDlg, &context->MinimumSize);

            context->ListViewHandle = lvHandle = GetDlgItem(hwndDlg, IDC_LIST);
            context->ImageList = ImageList_Create(PhSmallIconSize.X, PhSmallIconSize.Y, ILC_COLOR32 | ILC_MASK, 0, 40);

            PhSetListViewStyle(lvHandle, FALSE, TRUE);
            PhSetControlTheme(lvHandle, L"explorer");
            PhAddListViewColumn(lvHandle, 0, 0, 0, LVCFMT_LEFT, 180, L"Name");
            PhAddListViewColumn(lvHandle, 1, 1, 1, LVCFMT_LEFT, 60, L"PID");
            PhAddListViewColumn(lvHandle, 2, 2, 2, LVCFMT_LEFT, 160, L"User name");
            PhSetExtendedListView(lvHandle);

            ListView_SetImageList(lvHandle, context->ImageList, LVSIL_SMALL);

            PhpRefreshProcessList(hwndDlg, context);

            EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
        }
        break;
    case WM_DESTROY:
        {
            ImageList_Destroy(context->ImageList);
            PhDeleteLayoutManager(&context->LayoutManager);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                {
                    EndDialog(hwndDlg, IDCANCEL);
                }
                break;
            case IDOK:
                {
                    if (ListView_GetSelectedCount(context->ListViewHandle) == 1)
                    {
                        context->ProcessId = (HANDLE)PhGetSelectedListViewItemParam(context->ListViewHandle);
                        EndDialog(hwndDlg, IDOK);
                    }
                }
                break;
            case IDC_REFRESH:
                {
                    PhpRefreshProcessList(hwndDlg, context);
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case LVN_ITEMCHANGED:
                {
                    EnableWindow(GetDlgItem(hwndDlg, IDOK), ListView_GetSelectedCount(context->ListViewHandle) == 1);
                }
                break;
            case NM_DBLCLK:
                {
                    SendMessage(hwndDlg, WM_COMMAND, IDOK, 0);
                }
                break;
            }
        }
        break;
    case WM_SIZE:
        {
            PhLayoutManagerLayout(&context->LayoutManager);
        }
        break;
    case WM_SIZING:
        {
            PhResizingMinimumSize((PRECT)lParam, wParam, context->MinimumSize.right, context->MinimumSize.bottom);
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 12
0
static LRESULT WINAPI lv_newProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  WNDPROC oldproc = (WNDPROC)GetProp(hwnd,WDL_UTF8_OLDPROCPROP);
  if (!oldproc) return 0;

  if (msg==WM_NCDESTROY)
  {
    SetWindowLongPtr(hwnd, GWLP_WNDPROC,(INT_PTR)oldproc);
    RemoveProp(hwnd,WDL_UTF8_OLDPROCPROP);
  }
  else if (msg == LVM_INSERTCOLUMNA || msg==LVM_SETCOLUMNA)
  {
    LPLVCOLUMNA pCol = (LPLVCOLUMNA) lParam;
    char *str;
    if (pCol && (str=pCol->pszText) && (pCol->mask & LVCF_TEXT) && WDL_HasUTF8(str))
    {
      MBTOWIDE(wbuf,str);
      if (wbuf_ok)
      {
        LRESULT rv;
        pCol->pszText=(char*)wbuf; // set new buffer
        rv=CallWindowProc(oldproc,hwnd,msg==LVM_INSERTCOLUMNA?LVM_INSERTCOLUMNW:LVM_SETCOLUMNW,wParam,lParam);
        pCol->pszText = str; // restore old pointer
        MBTOWIDE_FREE(wbuf);
        return rv;
      }

    }
  }
  else if (msg == LVM_INSERTITEMA || msg == LVM_SETITEMA || msg == LVM_SETITEMTEXTA) 
  {
    LPLVITEMA pItem = (LPLVITEMA) lParam;
    char *str;
    if (pItem && (str=pItem->pszText) && (msg==LVM_SETITEMTEXTA || (pItem->mask&LVIF_TEXT)) && WDL_HasUTF8(str))
    {
      MBTOWIDE(wbuf,str);
      if (wbuf_ok)
      {
        LRESULT rv;
        pItem->pszText=(char*)wbuf; // set new buffer
        rv=CallWindowProc(oldproc,hwnd,msg == LVM_INSERTITEMA ? LVM_INSERTITEMW : msg == LVM_SETITEMA ? LVM_SETITEMW : LVM_SETITEMTEXTW,wParam,lParam);
        pItem->pszText = str; // restore old pointer
        MBTOWIDE_FREE(wbuf);
        return rv;
      }

      MBTOWIDE_FREE(wbuf);
    }
  }
  else if (msg==LVM_GETITEMA||msg==LVM_GETITEMTEXTA)
  {
    LPLVITEMA pItem = (LPLVITEMA) lParam;
    char *obuf;
    if (pItem && (msg == LVM_GETITEMTEXTA || (pItem->mask & LVIF_TEXT)) && (obuf=pItem->pszText) && pItem->cchTextMax > 3)
    {
      WIDETOMB_ALLOC(wbuf,pItem->cchTextMax);
      if (wbuf)
      {
        LRESULT rv;
        int oldsz=pItem->cchTextMax;
        *wbuf=0;
        *obuf=0;
        pItem->cchTextMax=wbuf_size/sizeof(WCHAR);
        pItem->pszText = (char *)wbuf;
        rv=CallWindowProc(oldproc,hwnd,msg==LVM_GETITEMTEXTA ? LVM_GETITEMTEXTW : LVM_GETITEMW,wParam,lParam);

        if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,obuf,oldsz,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER)
          obuf[oldsz-1]=0;

        pItem->cchTextMax=oldsz;
        pItem->pszText=obuf;
        WIDETOMB_FREE(wbuf);

        if (obuf[0]) return rv;
      }
    }
  }

  return CallWindowProc(oldproc,hwnd,msg,wParam,lParam);
}
Ejemplo n.º 13
0
static INT_PTR CALLBACK PhpMemoryProtectDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)lParam);

            SetDlgItemText(hwndDlg, IDC_INTRO,
                L"Possible values:\r\n"
                L"\r\n"
                L"0x01 - PAGE_NOACCESS\r\n"
                L"0x02 - PAGE_READONLY\r\n"
                L"0x04 - PAGE_READWRITE\r\n"
                L"0x08 - PAGE_WRITECOPY\r\n"
                L"0x10 - PAGE_EXECUTE\r\n"
                L"0x20 - PAGE_EXECUTE_READ\r\n"
                L"0x40 - PAGE_EXECUTE_READWRITE\r\n"
                L"0x80 - PAGE_EXECUTE_WRITECOPY\r\n"
                L"Modifiers:\r\n"
                L"0x100 - PAGE_GUARD\r\n"
                L"0x200 - PAGE_NOCACHE\r\n"
                L"0x400 - PAGE_WRITECOMBINE\r\n"
                );

            SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_VALUE), TRUE);
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
                EndDialog(hwndDlg, IDCANCEL);
                break;
            case IDOK:
                {
                    NTSTATUS status;
                    PMEMORY_PROTECT_CONTEXT context = (PMEMORY_PROTECT_CONTEXT)GetProp(hwndDlg, PhMakeContextAtom());
                    HANDLE processHandle;
                    ULONG64 protect;

                    PhStringToInteger64(&PhaGetDlgItemText(hwndDlg, IDC_VALUE)->sr, 0, &protect);

                    if (NT_SUCCESS(status = PhOpenProcess(
                        &processHandle,
                        PROCESS_VM_OPERATION,
                        context->ProcessItem->ProcessId
                        )))
                    {
                        PVOID baseAddress;
                        SIZE_T regionSize;
                        ULONG oldProtect;

                        baseAddress = context->MemoryItem->BaseAddress;
                        regionSize = context->MemoryItem->RegionSize;

                        status = NtProtectVirtualMemory(
                            processHandle,
                            &baseAddress,
                            &regionSize,
                            (ULONG)protect,
                            &oldProtect
                            );

                        if (NT_SUCCESS(status))
                            context->MemoryItem->Protect = (ULONG)protect;
                    }

                    if (NT_SUCCESS(status))
                    {
                        EndDialog(hwndDlg, IDOK);
                    }
                    else
                    {
                        PhShowStatus(hwndDlg, L"Unable to change memory protection", status, 0);
                        SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_VALUE), TRUE);
                        Edit_SetSel(GetDlgItem(hwndDlg, IDC_VALUE), 0, -1);
                    }
                }
                break;
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 14
0
BOOL AeroAutoSubclass(HWND hWnd, DWORD dwFlags, DWORD dwReserved)
{
    if(!hWnd || !IsWindow(hWnd) || 0L!=dwReserved)  
    {
        SetLastError(ERROR_INVALID_PARAMETER);        
        return FALSE;
    }

    UINT uiRedrawMsg = RegisterWindowMessage(REDRAWSTRING);
    if(!uiRedrawMsg)
        return FALSE; // use the RegisterWindowMessage last error

    CDwmApiImpl *pDwm = NULL;
    CUxThemeAeroImpl *pUxTheme = NULL;
    PAERO_SUBCLASS_WND_DATA pWndData = NULL;
    DWORD dwLastError = ERROR_SUCCESS;
    MARGINS marGlassInset = {-1,-1,-1,-1};
    HRESULT hRes = S_OK;
    bool bBufferedPaintInitialized = false;
    ERROR_PARENT_AERO_SUBCLASS_WND_DATA errParentAeroData;
    ZeroMemory(&errParentAeroData, sizeof(errParentAeroData));
    errParentAeroData.m_dwFlags = dwFlags;
    errParentAeroData.m_hWndParent = hWnd;

    try
    {
        pDwm = new CDwmApiImpl;
    }
    catch (...)
    {
        dwLastError = ERROR_NOT_ENOUGH_MEMORY;
    }

    if(ERROR_SUCCESS!=dwLastError)
        goto CLEANUP;

    try
    {
        pUxTheme = new CUxThemeAeroImpl;
    }
    catch (...)
    {
        dwLastError = ERROR_NOT_ENOUGH_MEMORY;
    }

    if(ERROR_SUCCESS!=dwLastError)
        goto CLEANUP;

    pWndData = (PAERO_SUBCLASS_WND_DATA)LocalAlloc(LPTR, sizeof(AERO_SUBCLASS_WND_DATA));
    if(!pWndData)
    {
        dwLastError = GetLastError();
        goto CLEANUP;
    }

    if(!pDwm->Initialize())
    {
        dwLastError = GetLastError();
        goto CLEANUP;
    }

    if(!pUxTheme->Initialize())
    {
        dwLastError = GetLastError();
        goto CLEANUP;
    }

    if(pDwm->IsDwmCompositionEnabled() && !(dwFlags&ASC_NO_FRAME_EXTENSION))
    {
        /// 
        /// we do not evaluate the return value of pDwm->DwmExtendFrameIntoClientArea, because
        /// if composition is turned off in the tiny little race condition after the previous call
        /// to IsDwmCompositionEnabled and before the following call to DwmExtendFrameIntoClientArea,
        /// we would see DwmExtendFrameIntoClientArea fail. However, if composition is turned on again 
        /// aterwards, the UI can display composition again without problems:
        /// 
        pDwm->DwmExtendFrameIntoClientArea(hWnd, &marGlassInset);
    }

    hRes = pUxTheme->BufferedPaintInit();
    if(FAILED(hRes))
    {
        dwLastError = hRes;
        goto CLEANUP;
    }
    bBufferedPaintInitialized = true;

    if(!SetProp(hWnd, WINDOW_DATA_STRING, pWndData))
    {
        dwLastError = hRes;
        goto CLEANUP;
    }

    errParentAeroData.m_pdwError = &dwLastError;
    errParentAeroData.m_pWndParentAeroData = pWndData;
    pWndData->m_pDwmApiImpl = pDwm;
    pWndData->m_pUxTheme = pUxTheme;
    pWndData->m_uiRedrawMsg = uiRedrawMsg;

    if(dwFlags&ASC_NO_FRAME_EXTENSION)
        pWndData->m_dwFlags |= WD_NO_FRAME_EXTEND;

    if(!EnumChildWindows(hWnd, SubclassChildWindows, (LPARAM)&errParentAeroData))
    {
        if(ERROR_SUCCESS==dwLastError)
            dwLastError = GetLastError();
        goto CLEANUP;
    }
    
    
    if(ERROR_SUCCESS!=dwLastError)
        goto CLEANUP;


    pWndData->m_oldWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR) WndProc);
    if(!pWndData->m_oldWndProc)
    {
        dwLastError = GetLastError();
        goto CLEANUP;
    }




CLEANUP:

    if(ERROR_SUCCESS!=dwLastError)
    {
        RemoveProp(hWnd, WINDOW_DATA_STRING); // don't care if this fails


        if(pDwm)
            delete pDwm;
        if(pUxTheme)
        {
            if(bBufferedPaintInitialized)
                pUxTheme->BufferedPaintUnInit();
                
            delete pUxTheme;
        }
        if(pWndData)
            VERIFY(!LocalFree(pWndData));

        SetLastError(dwLastError);
        return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 15
0
//BRACKETS: added so our popup windows can have a menu bar too
//
//  FUNCTION: PopupWndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Handle commands from the menus.
LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  //For now, we are only interest in WM_COMMAND's that we know are in our menus
  //and WM_CLOSE so we can delegate that back to the browser
  CefRefPtr<CefBrowser> browser = ClientHandler::GetBrowserForNativeWindow(hWnd);
  switch (message)
  {
      
    case WM_COMMAND:
      {
        int wmId    = LOWORD(wParam);
        int wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
          case IDM_CLOSE:
            if (g_handler.get() && browser.get()) {
              HWND browserHwnd = browser->GetHost()->GetWindowHandle();
              HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
              if (closing) {
                RemoveProp(browserHwnd, CLOSING_PROP);
                break;
              }

 		      CefRefPtr<CommandCallback> callback = new CloseWindowCommandCallback(browser);
 		      g_handler->SendJSCommand(browser, FILE_CLOSE_WINDOW, callback);
			}
			return 0;
          default:
            ExtensionString commandId = NativeMenuModel::getInstance(getMenuParent(browser)).getCommandId(wmId);
            if (commandId.size() > 0) {
              CefRefPtr<CommandCallback> callback = new EditCommandCallback(browser, commandId);
              g_handler->SendJSCommand(browser, commandId, callback);
            }
        }
	  }
      break;

    case WM_CLOSE:
      if (g_handler.get() && browser.get()) {
        HWND browserHwnd = browser->GetHost()->GetWindowHandle();
        HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
        if (closing) {
            RemoveProp(browserHwnd, CLOSING_PROP);
            break;
        }

        CefRefPtr<CommandCallback> callback = new CloseWindowCommandCallback(browser);
        g_handler->SendJSCommand(browser, FILE_CLOSE_WINDOW, callback);
 		return 0;
      }
      break;

    case WM_INITMENUPOPUP:
        HMENU menu = (HMENU)wParam;
        int count = GetMenuItemCount(menu);
        void* menuParent = getMenuParent(browser);
        for (int i = 0; i < count; i++) {
            UINT id = GetMenuItemID(menu, i);

            bool enabled = NativeMenuModel::getInstance(menuParent).isMenuItemEnabled(id);
            UINT flagEnabled = enabled ? MF_ENABLED | MF_BYCOMMAND : MF_DISABLED | MF_BYCOMMAND;
            EnableMenuItem(menu, id,  flagEnabled);

            bool checked = NativeMenuModel::getInstance(menuParent).isMenuItemChecked(id);
            UINT flagChecked = checked ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
            CheckMenuItem(menu, id, flagChecked);
        }
        break;
  }

  if (g_popupWndOldProc) 
    return (LRESULT)::CallWindowProc(g_popupWndOldProc, hWnd, message, wParam, lParam);
  return ::DefWindowProc(hWnd, message, wParam, lParam);
}
Ejemplo n.º 16
0
LRESULT WINAPI 
SendMailToolbarWndProc(	HWND hwnd, 
						UINT msg, 
						WPARAM wParam, 
						LPARAM lParam)
{
	WNDPROC lpOldProc;

	lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" );
   
	switch(msg)
	{
		case WM_DESTROY:   
		{
			//  Put back old window proc and
			SetWindowLong( hwnd, GWL_WNDPROC, (DWORD)lpOldProc );

			// remove window property
			RemoveProp( hwnd, "oldproc" ); 
			break;
		}

		case WM_NOTIFY:
		{
			static char szTooltip[256] = {0x00};
			LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) lParam;;

			switch (((LPNMHDR)lParam)->code)
			{
				case TTN_NEEDTEXTA:
				{
					if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_MIME )
					{
						int StringId =	lpToolTipText->hdr.idFrom -  
										WM_USER - 1000;

						LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						lpToolTipText->lpszText = szTooltip;

						if(g_hwndEudoraStatusbar)
						{
							SendMessage(g_hwndEudoraStatusbar,
										SB_SETTEXT,
										(WPARAM)0,
										(LPARAM)szTooltip);
						}
					
						return 0;
					}
				}

				case TTN_NEEDTEXTW:
				{
					static wchar_t wideBuf[256];

					if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_MIME )
					{
						int StringId = lpToolTipText->hdr.idFrom -  
										WM_USER - 1000;
					
    					LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						MultiByteToWideChar(CP_ACP, 
											MB_PRECOMPOSED, 
											szTooltip, 
											-1, 
											wideBuf, 
											256);

						lpToolTipText->lpszText = (char*)wideBuf;

						if(g_hwndEudoraStatusbar)
						{
							SendMessage(g_hwndEudoraStatusbar,
										SB_SETTEXT,
										(WPARAM)0,
										(LPARAM)szTooltip);
						}

						return 0;
					}
				}
			}
			break;
		}
	
		case WM_COMMAND:
		{
			switch(wParam)
			{
				case IDC_SENDMAIL:
				{
					HWND hwndSendToolbar = NULL;
					BOOL bEncrypt = FALSE;
					BOOL bSign = FALSE;
					BOOL bPGPMIME = FALSE;
					BYTE KeyboardStatus[256];
					//char temp[100];

					// Did the user have the shift key pressed 
					// when they sent mail?
					GetKeyboardState( KeyboardStatus );

					// Get our Toolbar
					hwndSendToolbar =  FindWindowEx(hwnd, 
													NULL, 
													"ToolbarWindow32", 
													NULL);

					if(hwndSendToolbar)
					{	
						g_bSendingMail = TRUE;
						g_hwndSendToolbar = hwndSendToolbar;

						// set up the Eudora Plugin Menu correctly
						SendMessage(hwnd, 
									WM_COMMAND, 
									(WPARAM)IDC_PLUGINMENU, 
									0);
						
						// See if the user wants us to use PGPMIME
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_MIME,
										0))
						{
							bPGPMIME = TRUE;
						}

						// See if the user wants us encrypt the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_ENCRYPT,
										0))
						{
							bEncrypt = TRUE;
						}

						// See if the user wants us sign the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_SIGN,
										0))
						{
							bSign = TRUE;
						}
					}
					else
					{
						int err;
						char szMessage[256];
						char szTitle[256];

						LoadString(g_hinst, IDS_E_SENDMAIL, szMessage, 
							sizeof(szMessage));
						LoadString(g_hinst, IDS_E_SENDMAILTITLE, szTitle, 
							sizeof(szTitle));

						err = MessageBox(NULL, 
								szMessage, 
								szTitle,	
								MB_YESNO|MB_ICONSTOP);

						if(err == IDNO)
						{
							return 0;
						}
					}	

					if(!bPGPMIME)
					{
						if(!SendMessage(hwnd, WM_COMMAND, IDC_JUSTDOIT, 0))
						{
							return 0;
						}
						else
						{
							LRESULT lresult;
							BYTE oldKeyboardStatus[256];
							
							GetKeyboardState( oldKeyboardStatus );
							SetKeyboardState( KeyboardStatus );

							lresult =  CallWindowProc(	lpOldProc, 
														hwnd, 
														msg, 
														wParam, 
														lParam );
							
							// reset these keys so they don't "stick"
							oldKeyboardStatus[VK_SHIFT]		= 0;
							oldKeyboardStatus[VK_CONTROL]	= 0;
							oldKeyboardStatus[VK_MENU]		= 0;

							SetKeyboardState( oldKeyboardStatus );

							return lresult;
						}
					}
					
					break;
				}

				case IDC_JUSTDOIT:
				{
					HWND hwndSendToolbar = NULL;
					BOOL bEncrypt = FALSE;
					BOOL bSign = FALSE;
					BOOL bEncryptSuccessful = FALSE;
					HCURSOR hCursor, hOldCursor;
					//char temp[100];

					// Get our Toolbar
					hwndSendToolbar =  FindWindowEx(hwnd, 
													NULL, 
													"ToolbarWindow32", 
													NULL);

					if(hwndSendToolbar)
					{		
						// See if the user wants us encrypt the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_ENCRYPT,
										0))
						{
							bEncrypt = TRUE;
						}

						// See if the user wants us sign the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_SIGN,
										0))
						{
							bSign = TRUE;
						}
					}

					// does the user want us to do anything to the message
					if(bEncrypt || bSign )
					{
						BOOL bSelectedText = FALSE;
						CHARRANGE chRange = {0,0};
						HWND hwndParent = NULL;
						HWND hwndRichEdit = NULL;
						HWND hwndAfxWnd = NULL;
						HWND hwndHeaders = NULL;
						char* pRichEditText = NULL;
						char** pPGPRecipients = NULL;
						long NumAddresses = 0;
						long nChar = 0;
						HEADERDATA hd;

						// zero out HEADERDATA struct
						memset(&hd, 0x00, sizeof(hd));

						// Find the windows we are interested in...
						hwndParent		= GetParent(hwnd);
						hwndAfxWnd		= FindWindowEx(	hwndParent, 
														NULL, 
														"AfxMDIFrame40", 
														NULL);

						if(!hwndAfxWnd) // 3.04 and 3.05 use new mfc versions
						{
							hwndAfxWnd	= FindWindowEx(	hwndParent, 
														NULL, 
														"AfxMDIFrame42", 
									 					NULL);
							if(!hwndAfxWnd) 
							{
								char szMessage[256];

								LoadString(g_hinst, IDS_E_OLDVERSION, 
									szMessage, sizeof(szMessage));

								MessageBox(NULL,
									szMessage,
									0, 
									MB_OK);

								return 0;
							}

						}						

						hwndRichEdit	= FindWindowEx(	hwndAfxWnd, 
														NULL, 
														"RICHEDIT", 
														NULL);

						hwndHeaders		= FindWindowEx(	hwndAfxWnd, 
														NULL, 
														"#32770", //Dialog 
														NULL);

						// See if the user has selected text in the window
						SendMessage(hwndRichEdit,  
									EM_EXGETSEL, 
									(WPARAM)0,
									(LPARAM) 
									&chRange);

						bSelectedText = chRange.cpMax - chRange.cpMin;

						// if not context menu invoked then we don't 
						// want to do selected text. 
						// this will protect users 
						if(lParam != SENT_FROM_CONTEXT_MENU)
						{
							bSelectedText = FALSE;
						}

						if(!bSelectedText)
						{
							RECT rect;

							// there is a bug in the richedit control... 
							// so if there is no selected text click in 
							// the lower right corner real quick to 
							// clear up the bug...

							GetClientRect(hwndRichEdit, &rect);
							SendMessage(hwndRichEdit, 
										WM_LBUTTONDOWN, 
										MK_LBUTTON, 
										MAKELPARAM(rect.right - 5, 
										rect.bottom -5 )); 

							SendMessage(hwndRichEdit, 
										WM_LBUTTONUP, 
										MK_LBUTTON,  
										MAKELPARAM(rect.right - 5 , 
										rect.bottom -5 )); 
						}

						// This could take awhile... give some feedback.
						hCursor = LoadCursor(NULL, IDC_WAIT);
						hOldCursor = SetCursor(hCursor);

						// get text of message
						pRichEditText = GetRichEditContents (	hwndRichEdit, 
																&nChar, 
																FALSE, 
																bSelectedText);

						// get the email headers
						GetEudoraHeaders( hwndHeaders, &hd);

						// now create an appropriate list for pgplib
						NumAddresses = CreateRecipientListFromEudoraHeaders(
														&hd, 
														&pPGPRecipients);

						if( pRichEditText )
						{				
							char* pInAttachments = "";
							char* pOutAttachments = NULL;

							// if context menu invoked then we don't 
							// want to do attachments. 
							if(lParam != SENT_FROM_CONTEXT_MENU)
							{
								pInAttachments = hd.pAttachments;
							}

							// length might have changed
							nChar = strlen(pRichEditText);

							// Encrypt Text
							bEncryptSuccessful = EncryptSignRichEditText(	
															&pRichEditText, 
															&nChar, 
															bEncrypt, 
															bSign, 
															pPGPRecipients, 
															NumAddresses,
															pInAttachments,
															&pOutAttachments);

							if( bEncryptSuccessful )
							{
								SetRichEditContents (	hwndRichEdit, 
														pRichEditText,
														FALSE, 
														bSelectedText);

								if(pOutAttachments)
								{
									// set the attachments
									SetEudoraAttachments(	hwndHeaders, 
															pOutAttachments);

									free(pOutAttachments);
								}
								else
								{
									// Wait for about .5 seconds 
									// so user can see encrypted text...
									Sleep(500);
								}
							}
						}
						
						// want to reset buttons for context menu
						// regardless of success or failure
						if(	bEncryptSuccessful || 
							lParam == SENT_FROM_CONTEXT_MENU)
						{
							// Reset the buttons
							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_ENCRYPT, 
										MAKELPARAM(FALSE,0));
							
							HeapFree(GetProcessHeap(), 0, pRichEditText);
						} 

						// want to reset buttons for context menu
						// regardless of success or failure
						if(	bEncryptSuccessful || 
							lParam == SENT_FROM_CONTEXT_MENU)
						{
							// Reset the buttons
							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_ENCRYPT, 
										MAKELPARAM(FALSE,0));

							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_SIGN,
										MAKELPARAM(FALSE, 0));

							SendMessage(hwndSendToolbar,
										TB_ENABLEBUTTON,
										(WPARAM)IDC_JUSTDOIT,
										MAKELPARAM(FALSE, 0));
						}

						// clean up after ourselves
						FreeRecipientList(pPGPRecipients, NumAddresses);

						FreeHeaderData(&hd);

						SetCursor(hOldCursor);
					}
					else
					{
						// we 'successfully' did nothing to the message
						bEncryptSuccessful = TRUE;
					}

					return bEncryptSuccessful;
					break;
				}

				case IDC_KEYMGR:
				{
					char szPath[MAX_PATH];
					char szPGPkeys[256];
					PGPError error = kPGPError_NoErr;

					LoadString(g_hinst, IDS_PGPKEYSEXE, szPGPkeys,
						sizeof(szPGPkeys));

					error = PGPclGetPath (kPGPclPGPkeysExeFile,
						szPath, sizeof(szPath));

					if( IsntPGPError(error) )
					{
						PGPclExecute (szPath, SW_SHOW);
					}
					else
					{
						char szError[256];

						LoadString(g_hinst, IDS_E_LAUNCHPGPKEYS, szError,
							sizeof(szError));

						MessageBox(NULL, 
							szError, 
							0, 
							MB_OK);
					}
					
					break;
				}
			}
		}
		
		case WM_ENTERIDLE:
		{
			if( g_bSendingMail && g_hwndSendToolbar && wParam == MSGF_MENU )
			{
				g_bInitializeButtons = FALSE;
				g_bSendingMail = FALSE;
				g_hwndSendToolbar = NULL;
				PostMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_ESCAPE, 0x001c0001); 
				PostMessage(hwnd, WM_KEYUP, (WPARAM)VK_ESCAPE, 0x001c0001); 
			}

			break;
		}
	
		case WM_DRAWITEM:
		{
			// control identifier 
			UINT idCtl = (UINT) wParam;	
			// item-drawing information
			LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;  
			//char szString[256] = {0x00};

			if( g_bSendingMail )
			{
				if(lpdis && lpdis->CtlType == ODT_MENU)
				{
					if(*((void**)(lpdis->itemData + 4)))
					{
						WPARAM wCommand = 0;
						BOOL bItemChecked = FALSE;

						// see if it is already checked
						if((lpdis->itemState & ODS_CHECKED)) 
						{
							bItemChecked = TRUE;
						}

						// see which plugin this menuitem represents
						if( !strcmp(*((char**)(lpdis->itemData + 4)), 
										"PGP plugin 1 (use toolbar)") )
						{
							wCommand = IDC_ENCRYPT;

							// we might be getting a window from a cancel...
							if( g_bInitializeButtons && bItemChecked) 
							{
								g_bEncrypt = TRUE;
							}
						}
						else if( !strcmp(*((char**)(lpdis->itemData + 4)), 
											"PGP plugin 2 (use toolbar)") )
						{
							wCommand = IDC_SIGN;

							// we might be getting a window from a cancel...
							if( g_bInitializeButtons && bItemChecked) 
							{
								g_bSign	= TRUE;
							}
						}

						if( !g_bInitializeButtons )
						{
							// make sure the window handle is valid
							if( g_hwndSendToolbar) 
							{
								if( wCommand ) // is this one of our menus
								{
									BOOL bCommandPressed = FALSE;
									BOOL bPGPMIMEPressed = FALSE;

									bCommandPressed = SendMessage(	
														g_hwndSendToolbar, 
														TB_ISBUTTONCHECKED, 
														wCommand, 
														0);

									bPGPMIMEPressed = SendMessage(	
														g_hwndSendToolbar, 
														TB_ISBUTTONCHECKED, 
														IDC_MIME, 
														0);

									if( (bCommandPressed && 
										!bItemChecked && bPGPMIMEPressed) || 
										(bCommandPressed && bItemChecked && 
										!bPGPMIMEPressed) ||
										(!bCommandPressed && bItemChecked))
									{
										SendMessage(hwnd, 
													WM_COMMAND, 
													(WPARAM)lpdis->itemID, 
													0);
									}
								}
							}
						}
					}
				}
			}
			break;
		}
	} 
	
	//  Pass all non-custom messages to old window proc
	return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam ) ;
}
Ejemplo n.º 17
0
INT_PTR CALLBACK PhpHandleGeneralDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
            PHANDLE_PROPERTIES_CONTEXT context = (PHANDLE_PROPERTIES_CONTEXT)propSheetPage->lParam;
            PPH_ACCESS_ENTRY accessEntries;
            ULONG numberOfAccessEntries;
            HANDLE processHandle;
            OBJECT_BASIC_INFORMATION basicInfo;
            BOOLEAN haveBasicInfo = FALSE;

            SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)context);

            SetDlgItemText(hwndDlg, IDC_NAME, PhGetString(context->HandleItem->BestObjectName));
            SetDlgItemText(hwndDlg, IDC_TYPE, context->HandleItem->TypeName->Buffer);
            SetDlgItemText(hwndDlg, IDC_ADDRESS, context->HandleItem->ObjectString);

            if (PhGetAccessEntries(
                context->HandleItem->TypeName->Buffer,
                &accessEntries,
                &numberOfAccessEntries
                ))
            {
                PPH_STRING accessString;
                PPH_STRING grantedAccessString;

                accessString = PhGetAccessString(
                    context->HandleItem->GrantedAccess,
                    accessEntries,
                    numberOfAccessEntries
                    );

                if (accessString->Length != 0)
                {
                    grantedAccessString = PhFormatString(
                        L"%s (%s)",
                        context->HandleItem->GrantedAccessString,
                        accessString->Buffer
                        );
                    SetDlgItemText(hwndDlg, IDC_GRANTED_ACCESS, grantedAccessString->Buffer);
                    PhDereferenceObject(grantedAccessString);
                }
                else
                {
                    SetDlgItemText(hwndDlg, IDC_GRANTED_ACCESS, context->HandleItem->GrantedAccessString);
                }

                PhDereferenceObject(accessString);

                PhFree(accessEntries);
            }
            else
            {
                SetDlgItemText(hwndDlg, IDC_GRANTED_ACCESS, context->HandleItem->GrantedAccessString);
            }

            if (NT_SUCCESS(PhOpenProcess(
                &processHandle,
                PROCESS_DUP_HANDLE,
                context->ProcessId
                )))
            {
                if (NT_SUCCESS(PhGetHandleInformation(
                    processHandle,
                    context->HandleItem->Handle,
                    -1,
                    &basicInfo,
                    NULL,
                    NULL,
                    NULL
                    )))
                {
                    SetDlgItemInt(hwndDlg, IDC_REFERENCES, basicInfo.PointerCount, FALSE);
                    SetDlgItemInt(hwndDlg, IDC_HANDLES, basicInfo.HandleCount, FALSE);
                    SetDlgItemInt(hwndDlg, IDC_PAGED, basicInfo.PagedPoolCharge, FALSE);
                    SetDlgItemInt(hwndDlg, IDC_NONPAGED, basicInfo.NonPagedPoolCharge, FALSE);

                    haveBasicInfo = TRUE;
                }

                NtClose(processHandle);
            }

            if (!haveBasicInfo)
            {
                SetDlgItemText(hwndDlg, IDC_REFERENCES, L"Unknown");
                SetDlgItemText(hwndDlg, IDC_HANDLES, L"Unknown");
                SetDlgItemText(hwndDlg, IDC_PAGED, L"Unknown");
                SetDlgItemText(hwndDlg, IDC_NONPAGED, L"Unknown");
            }
        }
        break;
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case PSN_QUERYINITIALFOCUS:
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LONG_PTR)GetDlgItem(hwndDlg, IDC_BASICINFORMATION));
                }
                return TRUE;
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 18
0
static BOOL CALLBACK PropEnumProc(HWND hwnd, LPCSTR lpszString, HANDLE hData){
	if((DWORD)(VOID *)hData != 0xffffffff){
		RemoveProp(hwnd, lpszString);
	}
	return TRUE;
}
Ejemplo n.º 19
0
static INT_PTR CALLBACK PhpInformationDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            PINFORMATION_CONTEXT context = (PINFORMATION_CONTEXT)lParam;
            PPH_LAYOUT_MANAGER layoutManager;

            PhCenterWindow(hwndDlg, GetParent(hwndDlg));

            SetDlgItemText(hwndDlg, IDC_TEXT, context->String);

            layoutManager = PhAllocate(sizeof(PH_LAYOUT_MANAGER));
            PhInitializeLayoutManager(layoutManager, hwndDlg);
            PhAddLayoutItem(layoutManager, GetDlgItem(hwndDlg, IDC_TEXT), NULL,
                PH_ANCHOR_ALL);
            PhAddLayoutItem(layoutManager, GetDlgItem(hwndDlg, IDOK), NULL,
                PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
            PhAddLayoutItem(layoutManager, GetDlgItem(hwndDlg, IDC_COPY), NULL,
                PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
            PhAddLayoutItem(layoutManager, GetDlgItem(hwndDlg, IDC_SAVE), NULL,
                PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);

            if (MinimumSize.left == -1)
            {
                RECT rect;

                rect.left = 0;
                rect.top = 0;
                rect.right = 200;
                rect.bottom = 140;
                MapDialogRect(hwndDlg, &rect);
                MinimumSize = rect;
                MinimumSize.left = 0;
            }

            SetProp(hwndDlg, L"LayoutManager", (HANDLE)layoutManager);
            SetProp(hwndDlg, L"String", (HANDLE)context->String);

            SendMessage(hwndDlg, WM_NEXTDLGCTL, (LPARAM)GetDlgItem(hwndDlg, IDOK), TRUE);
        }
        break;
    case WM_DESTROY:
        {
            PPH_LAYOUT_MANAGER layoutManager;

            layoutManager = (PPH_LAYOUT_MANAGER)GetProp(hwndDlg, L"LayoutManager");
            PhDeleteLayoutManager(layoutManager);
            PhFree(layoutManager);
            RemoveProp(hwndDlg, L"String");
            RemoveProp(hwndDlg, L"LayoutManager");
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDCANCEL:
            case IDOK:
                EndDialog(hwndDlg, IDOK);
                break;
            case IDC_COPY:
                {
                    HWND editControl;
                    LONG selStart;
                    LONG selEnd;
                    PWSTR buffer;
                    PH_STRINGREF string;

                    editControl = GetDlgItem(hwndDlg, IDC_TEXT);
                    SendMessage(editControl, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);
                    buffer = (PWSTR)GetProp(hwndDlg, L"String");

                    if (selStart == selEnd)
                    {
                        // Select and copy the entire string.
                        PhInitializeStringRefLongHint(&string, buffer);
                        Edit_SetSel(editControl, 0, -1);
                    }
                    else
                    {
                        string.Buffer = buffer + selStart;
                        string.Length = (selEnd - selStart) * 2;
                    }

                    PhSetClipboardString(hwndDlg, &string);
                    SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)editControl, TRUE);
                }
                break;
            case IDC_SAVE:
                {
                    static PH_FILETYPE_FILTER filters[] =
                    {
                        { L"Text files (*.txt)", L"*.txt" },
                        { L"All files (*.*)", L"*.*" }
                    };
                    PVOID fileDialog;

                    fileDialog = PhCreateSaveFileDialog();

                    PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
                    PhSetFileDialogFileName(fileDialog, L"Information.txt");

                    if (PhShowFileDialog(hwndDlg, fileDialog))
                    {
                        NTSTATUS status;
                        PPH_STRING fileName;
                        PPH_FILE_STREAM fileStream;

                        fileName = PH_AUTO(PhGetFileDialogFileName(fileDialog));

                        if (NT_SUCCESS(status = PhCreateFileStream(
                            &fileStream,
                            fileName->Buffer,
                            FILE_GENERIC_WRITE,
                            FILE_SHARE_READ,
                            FILE_OVERWRITE_IF,
                            0
                            )))
                        {
                            PH_STRINGREF string;

                            PhWriteStringAsUtf8FileStream(fileStream, &PhUnicodeByteOrderMark);
                            PhInitializeStringRef(&string, (PWSTR)GetProp(hwndDlg, L"String"));
                            PhWriteStringAsUtf8FileStream(fileStream, &string);
                            PhDereferenceObject(fileStream);
                        }

                        if (!NT_SUCCESS(status))
                            PhShowStatus(hwndDlg, L"Unable to create the file", status, 0);
                    }

                    PhFreeFileDialog(fileDialog);
                }
                break;
            }
        }
        break;
    case WM_SIZE:
        {
            PPH_LAYOUT_MANAGER layoutManager;

            layoutManager = (PPH_LAYOUT_MANAGER)GetProp(hwndDlg, L"LayoutManager");
            PhLayoutManagerLayout(layoutManager);
        }
        break;
    case WM_SIZING:
        {
            PhResizingMinimumSize((PRECT)lParam, wParam, MinimumSize.right, MinimumSize.bottom);
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 20
0
static INT_PTR CALLBACK NetAdapterDialogProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PPH_NETADAPTER_SYSINFO_CONTEXT context = NULL;

    if (uMsg == WM_INITDIALOG)
    {
        context = (PPH_NETADAPTER_SYSINFO_CONTEXT)lParam;

        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PPH_NETADAPTER_SYSINFO_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_NCDESTROY)
        {
            PhDeleteLayoutManager(&context->LayoutManager);

            PhDeleteGraphState(&context->GraphState);

            if (context->GraphHandle)
                DestroyWindow(context->GraphHandle);

            if (context->PanelWindowHandle)
                DestroyWindow(context->PanelWindowHandle);

            PhUnregisterCallback(&PhProcessesUpdatedEvent, &context->ProcessesUpdatedRegistration);

            RemoveProp(hwndDlg, L"Context");
        }
    }

    if (context == NULL)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            PPH_LAYOUT_ITEM graphItem;
            PPH_LAYOUT_ITEM panelItem;

            context->WindowHandle = hwndDlg;

            PhInitializeGraphState(&context->GraphState);
            PhInitializeLayoutManager(&context->LayoutManager, hwndDlg);

            PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_ADAPTERNAME), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT | PH_LAYOUT_FORCE_INVALIDATE);
            graphItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_GRAPH_LAYOUT), NULL, PH_ANCHOR_ALL);
            panelItem = PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_LAYOUT), NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);

            SendMessage(GetDlgItem(hwndDlg, IDC_ADAPTERNAME), WM_SETFONT, (WPARAM)context->SysinfoSection->Parameters->LargeFont, FALSE);
            SetDlgItemText(hwndDlg, IDC_ADAPTERNAME, context->SysinfoSection->Name.Buffer);

            context->PanelWindowHandle = CreateDialogParam(PluginInstance->DllBase, MAKEINTRESOURCE(IDD_NETADAPTER_PANEL), hwndDlg, NetAdapterPanelDialogProc, (LPARAM)context);
            ShowWindow(context->PanelWindowHandle, SW_SHOW);
            PhAddLayoutItemEx(&context->LayoutManager, context->PanelWindowHandle, NULL, PH_ANCHOR_LEFT | PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM, panelItem->Margin);

            // Create the graph control.
            context->GraphHandle = CreateWindow(
                PH_GRAPH_CLASSNAME,
                NULL,
                WS_VISIBLE | WS_CHILD | WS_BORDER,
                0,
                0,
                3,
                3,
                hwndDlg,
                NULL,
                NULL,
                NULL
                );
            Graph_SetTooltip(context->GraphHandle, TRUE);

            PhAddLayoutItemEx(&context->LayoutManager, context->GraphHandle, NULL, PH_ANCHOR_ALL, graphItem->Margin);

            PhRegisterCallback(
                &PhProcessesUpdatedEvent,
                ProcessesUpdatedHandler,
                context,
                &context->ProcessesUpdatedRegistration
                );

            NetAdapterUpdateGraphs(context);
            NetAdapterUpdatePanel(context);
        }
        break;
    case WM_SIZE:
        PhLayoutManagerLayout(&context->LayoutManager);
        break;
    case WM_NOTIFY:
        {
            NMHDR* header = (NMHDR*)lParam;

            if (header->hwndFrom == context->GraphHandle)
            {
                switch (header->code)
                {
                case GCN_GETDRAWINFO:
                    {
                        PPH_GRAPH_GETDRAWINFO getDrawInfo = (PPH_GRAPH_GETDRAWINFO)header;
                        PPH_GRAPH_DRAW_INFO drawInfo = getDrawInfo->DrawInfo;

                        drawInfo->Flags = PH_GRAPH_USE_GRID | PH_GRAPH_USE_LINE_2;
                        context->SysinfoSection->Parameters->ColorSetupFunction(drawInfo, PhGetIntegerSetting(L"ColorIoReadOther"), PhGetIntegerSetting(L"ColorIoWrite"));

                        PhGraphStateGetDrawInfo(
                            &context->GraphState,
                            getDrawInfo,
                            context->InboundBuffer.Count
                            );

                        if (!context->GraphState.Valid)
                        {
                            ULONG i;
                            FLOAT max = 0;

                            for (i = 0; i < drawInfo->LineDataCount; i++)
                            {
                                FLOAT data1;
                                FLOAT data2;

                                context->GraphState.Data1[i] = data1 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->InboundBuffer, i);
                                context->GraphState.Data2[i] = data2 = (FLOAT)PhGetItemCircularBuffer_ULONG64(&context->OutboundBuffer, i);

                                if (max < data1 + data2)
                                    max = data1 + data2;
                            }

                            // Minimum scaling of 1 MB.
                            //if (max < 1024 * 1024)
                            //    max = 1024 * 1024;

                            // Scale the data.
                            PhDivideSinglesBySingle(
                                context->GraphState.Data1,
                                max,
                                drawInfo->LineDataCount
                                );

                            // Scale the data.
                            PhDivideSinglesBySingle(
                                context->GraphState.Data2,
                                max,
                                drawInfo->LineDataCount
                                );

                            context->GraphState.Valid = TRUE;
                        }
                    }
                    break;
                case GCN_GETTOOLTIPTEXT:
                    {
                        PPH_GRAPH_GETTOOLTIPTEXT getTooltipText = (PPH_GRAPH_GETTOOLTIPTEXT)header;

                        if (getTooltipText->Index < getTooltipText->TotalCount)
                        {
                            if (context->GraphState.TooltipIndex != getTooltipText->Index)
                            {
                                ULONG64 adapterInboundValue = PhGetItemCircularBuffer_ULONG64(
                                    &context->InboundBuffer,
                                    getTooltipText->Index
                                    );

                                ULONG64 adapterOutboundValue = PhGetItemCircularBuffer_ULONG64(
                                    &context->OutboundBuffer,
                                    getTooltipText->Index
                                    );

                                PhMoveReference(&context->GraphState.TooltipText, PhFormatString(
                                    L"R: %s\nS: %s\n%s",
                                    PhaFormatSize(adapterInboundValue, -1)->Buffer,
                                    PhaFormatSize(adapterOutboundValue, -1)->Buffer,
                                    ((PPH_STRING)PhAutoDereferenceObject(PhGetStatisticsTimeString(NULL, getTooltipText->Index)))->Buffer
                                    ));
                            }

                            getTooltipText->Text = context->GraphState.TooltipText->sr;
                        }
                    }
                    break;
                }
            }
        }
        break;
    case MSG_UPDATE:
        {
            NetAdapterUpdateGraphs(context);
            NetAdapterUpdatePanel(context);
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 21
0
INT_PTR CALLBACK EspServiceRecoveryDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PSERVICE_RECOVERY_CONTEXT context;

    if (uMsg == WM_INITDIALOG)
    {
        context = PhAllocate(sizeof(SERVICE_RECOVERY_CONTEXT));
        memset(context, 0, sizeof(SERVICE_RECOVERY_CONTEXT));

        SetProp(hwndDlg, L"Context", (HANDLE)context);
    }
    else
    {
        context = (PSERVICE_RECOVERY_CONTEXT)GetProp(hwndDlg, L"Context");

        if (uMsg == WM_DESTROY)
            RemoveProp(hwndDlg, L"Context");
    }

    if (!context)
        return FALSE;

    switch (uMsg)
    {
    case WM_INITDIALOG:
        {
            NTSTATUS status;
            LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
            PPH_SERVICE_ITEM serviceItem = (PPH_SERVICE_ITEM)propSheetPage->lParam;

            context->ServiceItem = serviceItem;

            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_FIRSTFAILURE));
            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_SECONDFAILURE));
            EspAddServiceActionStrings(GetDlgItem(hwndDlg, IDC_SUBSEQUENTFAILURES));

            status = EspLoadRecoveryInfo(hwndDlg, context);

            if (status == STATUS_SOME_NOT_MAPPED)
            {
                if (context->NumberOfActions > 3)
                {
                    PhShowWarning(
                        hwndDlg,
                        L"The service has %lu failure actions configured, but this program only supports editing 3. "
                        L"If you save the recovery information using this program, the additional failure actions will be lost.",
                        context->NumberOfActions
                        );
                }
            }
            else if (!NT_SUCCESS(status))
            {
                SetDlgItemText(hwndDlg, IDC_RESETFAILCOUNT, L"0");

                if (WindowsVersion >= WINDOWS_VISTA)
                {
                    context->EnableFlagCheckBox = TRUE;
                    EnableWindow(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS), TRUE);
                }

                PhShowWarning(hwndDlg, L"Unable to query service recovery information: %s",
                    ((PPH_STRING)PhAutoDereferenceObject(PhGetNtMessage(status)))->Buffer);
            }

            EspFixControls(hwndDlg, context);

            context->Ready = TRUE;
        }
        break;
    case WM_DESTROY:
        {
            PhClearReference(&context->RebootMessage);
            PhFree(context);
        }
        break;
    case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
            case IDC_FIRSTFAILURE:
            case IDC_SECONDFAILURE:
            case IDC_SUBSEQUENTFAILURES:
                {
                    if (HIWORD(wParam) == CBN_SELCHANGE)
                    {
                        EspFixControls(hwndDlg, context);
                    }
                }
                break;
            case IDC_RESTARTCOMPUTEROPTIONS:
                {
                    DialogBoxParam(
                        PluginInstance->DllBase,
                        MAKEINTRESOURCE(IDD_RESTARTCOMP),
                        hwndDlg,
                        RestartComputerDlgProc,
                        (LPARAM)context
                        );
                }
                break;
            case IDC_BROWSE:
                {
                    static PH_FILETYPE_FILTER filters[] =
                    {
                        { L"Executable files (*.exe;*.cmd;*.bat)", L"*.exe;*.cmd;*.bat" },
                        { L"All files (*.*)", L"*.*" }
                    };
                    PVOID fileDialog;
                    PPH_STRING fileName;

                    fileDialog = PhCreateOpenFileDialog();
                    PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));

                    fileName = PhaGetDlgItemText(hwndDlg, IDC_RUNPROGRAM);
                    PhSetFileDialogFileName(fileDialog, fileName->Buffer);

                    if (PhShowFileDialog(hwndDlg, fileDialog))
                    {
                        fileName = PhGetFileDialogFileName(fileDialog);
                        SetDlgItemText(hwndDlg, IDC_RUNPROGRAM, fileName->Buffer);
                        PhDereferenceObject(fileName);
                    }

                    PhFreeFileDialog(fileDialog);
                }
                break;
            case IDC_ENABLEFORERRORSTOPS:
                {
                    context->Dirty = TRUE;
                }
                break;
            }

            switch (HIWORD(wParam))
            {
            case EN_CHANGE:
            case CBN_SELCHANGE:
                {
                    if (context->Ready)
                        context->Dirty = TRUE;
                }
                break;
            }
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case PSN_KILLACTIVE:
                {
                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
                }
                return TRUE;
            case PSN_APPLY:
                {
                    NTSTATUS status;
                    PPH_SERVICE_ITEM serviceItem = context->ServiceItem;
                    SC_HANDLE serviceHandle;
                    ULONG restartServiceAfter;
                    SERVICE_FAILURE_ACTIONS failureActions;
                    SC_ACTION actions[3];
                    ULONG i;
                    BOOLEAN enableRestart = FALSE;

                    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);

                    if (!context->Dirty)
                    {
                        return TRUE;
                    }

                    // Build the failure actions structure.

                    failureActions.dwResetPeriod = GetDlgItemInt(hwndDlg, IDC_RESETFAILCOUNT, NULL, FALSE) * 60 * 60 * 24;
                    failureActions.lpRebootMsg = PhGetStringOrEmpty(context->RebootMessage);
                    failureActions.lpCommand = PhaGetDlgItemText(hwndDlg, IDC_RUNPROGRAM)->Buffer;
                    failureActions.cActions = 3;
                    failureActions.lpsaActions = actions;

                    actions[0].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_FIRSTFAILURE));
                    actions[1].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_SECONDFAILURE));
                    actions[2].Type = ComboBoxToServiceAction(GetDlgItem(hwndDlg, IDC_SUBSEQUENTFAILURES));

                    restartServiceAfter = GetDlgItemInt(hwndDlg, IDC_RESTARTSERVICEAFTER, NULL, FALSE) * 1000 * 60;

                    for (i = 0; i < 3; i++)
                    {
                        switch (actions[i].Type)
                        {
                        case SC_ACTION_RESTART:
                            actions[i].Delay = restartServiceAfter;
                            enableRestart = TRUE;
                            break;
                        case SC_ACTION_REBOOT:
                            actions[i].Delay = context->RebootAfter;
                            break;
                        case SC_ACTION_RUN_COMMAND:
                            actions[i].Delay = 0;
                            break;
                        }
                    }

                    // Try to save the changes.

                    serviceHandle = PhOpenService(
                        serviceItem->Name->Buffer,
                        SERVICE_CHANGE_CONFIG | (enableRestart ? SERVICE_START : 0) // SC_ACTION_RESTART requires SERVICE_START
                        );

                    if (serviceHandle)
                    {
                        if (ChangeServiceConfig2(
                            serviceHandle,
                            SERVICE_CONFIG_FAILURE_ACTIONS,
                            &failureActions
                            ))
                        {
                            if (context->EnableFlagCheckBox)
                            {
                                SERVICE_FAILURE_ACTIONS_FLAG failureActionsFlag;

                                failureActionsFlag.fFailureActionsOnNonCrashFailures =
                                    Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS)) == BST_CHECKED;

                                ChangeServiceConfig2(
                                    serviceHandle,
                                    SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
                                    &failureActionsFlag
                                    );
                            }

                            CloseServiceHandle(serviceHandle);
                        }
                        else
                        {
                            CloseServiceHandle(serviceHandle);
                            goto ErrorCase;
                        }
                    }
                    else
                    {
                        if (GetLastError() == ERROR_ACCESS_DENIED && !PhElevated)
                        {
                            // Elevate using phsvc.
                            if (PhUiConnectToPhSvc(hwndDlg, FALSE))
                            {
                                if (NT_SUCCESS(status = PhSvcCallChangeServiceConfig2(
                                    serviceItem->Name->Buffer,
                                    SERVICE_CONFIG_FAILURE_ACTIONS,
                                    &failureActions
                                    )))
                                {
                                    if (context->EnableFlagCheckBox)
                                    {
                                        SERVICE_FAILURE_ACTIONS_FLAG failureActionsFlag;

                                        failureActionsFlag.fFailureActionsOnNonCrashFailures =
                                            Button_GetCheck(GetDlgItem(hwndDlg, IDC_ENABLEFORERRORSTOPS)) == BST_CHECKED;

                                        PhSvcCallChangeServiceConfig2(
                                            serviceItem->Name->Buffer,
                                            SERVICE_CONFIG_FAILURE_ACTIONS_FLAG,
                                            &failureActionsFlag
                                            );
                                    }
                                }

                                PhUiDisconnectFromPhSvc();

                                if (!NT_SUCCESS(status))
                                {
                                    SetLastError(PhNtStatusToDosError(status));
                                    goto ErrorCase;
                                }
                            }
                            else
                            {
                                // User cancelled elevation.
                                SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                            }
                        }
                        else
                        {
                            goto ErrorCase;
                        }
                    }

                    return TRUE;
ErrorCase:
                    if (PhShowMessage(
                        hwndDlg,
                        MB_ICONERROR | MB_RETRYCANCEL,
                        L"Unable to change service recovery information: %s",
                        ((PPH_STRING)PhAutoDereferenceObject(PhGetWin32Message(GetLastError())))->Buffer
                        ) == IDRETRY)
                    {
                        SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                    }
                }
                return TRUE;
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 22
0
LRESULT PASCAL HotKeyWndProc(HWND hWnd, register UINT uMsg, register WPARAM wParam, register LPARAM lParam)
{
	CM_HOTKEY *pHotKey = ( CM_HOTKEY * ) GetProp( hWnd, _T("HOTKEY") ); 

	switch ( uMsg )
	{
		case WM_CREATE:
			{
				CM_HOTKEY *pHotKey = new CM_HOTKEY;
				ZeroMemory( pHotKey, sizeof( CM_HOTKEY ) );
				SetProp( hWnd, _T("HOTKEY"), pHotKey ); 
				SetWindowLong( hWnd, GWL_EXSTYLE, GetWindowLong( hWnd, GWL_EXSTYLE ) | WS_EX_CLIENTEDGE );
				SetWindowPos( hWnd, NULL, -1, -1, -1, -1, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_DRAWFRAME );
				SendMessage( hWnd, UM_UPDATEHOTKEYTEXT, 0, 0 );
				g_bEatCommand = FALSE;
				break;
			}

		case WM_DESTROY:
			{
				RemoveProp( hWnd, _T("HOTKEY") );
				delete pHotKey;
				break;
			}

		case UM_TAKEBACKFOCUS:
		{
			if ( GetFocus() != hWnd )
			{
				SetFocus( hWnd );
			}
			g_bEatCommand = FALSE;
			return 0;
		}

		case HOTM_QUERYEATCOMMAND:
		{
			return g_bEatCommand;
		}

		case UM_UPDATEHOTKEYTEXT:
		{
			TCHAR szHotKey[ 100 ];
			*szHotKey = '\0';
			GetHotKeyString( *pHotKey, szHotKey );
			g_bCanUpdateText = TRUE;
			SetWindowText( hWnd, szHotKey );
			g_bCanUpdateText = FALSE;
			SendMessage( hWnd, EM_SETSEL, 1000, 1000 );

			return 0;
		}

		case UM_INTERNALSETHOTKEY:
		{
			UINT nVirtKey = wParam;
			switch ( nVirtKey )
			{
				case VK_CONTROL:
				case VK_SHIFT:
				case VK_MENU:
				{
					nVirtKey = 0;
				}
			}

			if ( nVirtKey )
			{
				CM_HOTKEY cmHotKey = *pHotKey;
				BYTE byModifiers = 0;
				byModifiers |= ( ( GetKeyState( VK_CONTROL ) < 0 ) ? HOTKEYF_CONTROL : 0 );
				byModifiers |= ( ( GetKeyState( VK_SHIFT ) < 0 ) ? HOTKEYF_SHIFT : 0 );
				byModifiers |= ( ( GetKeyState( VK_MENU ) < 0 ) ? HOTKEYF_ALT : 0 );

				if ( cmHotKey.byModifiers1 || cmHotKey.nVirtKey1 )
				{
					if ( !cmHotKey.byModifiers2 && !cmHotKey.nVirtKey2 )
					{
						cmHotKey.byModifiers2 = byModifiers;
						cmHotKey.nVirtKey2 = nVirtKey;
					}
					else
					{
						cmHotKey.byModifiers2 = 0;
						cmHotKey.nVirtKey2 = 0;
						goto set_loword;
					}
				}
				else
				{
					set_loword:
					ASSERT( !cmHotKey.byModifiers2 && !cmHotKey.nVirtKey2 );
					cmHotKey.byModifiers1 = byModifiers;
					cmHotKey.nVirtKey1 = nVirtKey;
				}

				SendMessage( hWnd, HOTM_SETHOTKEY, 0, ( LPARAM ) &cmHotKey );
			}
			return 0;
		}

		case HOTM_SETHOTKEY:
		{
			if ( lParam )
			{
				*pHotKey = *( CM_HOTKEY * ) lParam;
			}
			else
			{
				CM_HOTKEY cmHotKey = { 0, 0, 0, 0 };
				*pHotKey = cmHotKey;
			}
			SendMessage( hWnd, UM_UPDATEHOTKEYTEXT, 0, 0 );
			return 0;
		}

		case HOTM_GETHOTKEY:
		{
			*( ( CM_HOTKEY * ) lParam ) = *pHotKey;
			break;
		}

		case WM_KEYDOWN:
		case WM_SYSKEYDOWN:
		{
			g_bEatCommand = TRUE;
			SendMessage( hWnd, UM_INTERNALSETHOTKEY, wParam, lParam );
			PostMessage( hWnd, UM_TAKEBACKFOCUS, 0, 0 );
			return DefWindowProc( hWnd, uMsg, wParam, lParam );
		}
		case WM_KEYUP:
		case WM_SYSKEYUP:
		{
			return DefWindowProc( hWnd, uMsg, wParam, lParam );
		}
		case WM_CHAR:
		case WM_SYSCHAR:
		{
			return DefWindowProc( hWnd, uMsg, wParam, lParam );
		}

	case WM_LBUTTONDOWN:
		case WM_LBUTTONUP:
		case WM_LBUTTONDBLCLK:
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_RBUTTONDBLCLK:
		case WM_MBUTTONDOWN:
		case WM_MBUTTONUP:
		case WM_MBUTTONDBLCLK:
		case WM_CONTEXTMENU:
		{
			SetFocus( hWnd );
			return 0;
		}

		case WM_SYSCOMMAND:
		{
			return 0;
		}
		case WM_SETTEXT:
		{
			if ( g_bCanUpdateText )
		{
				break;
			}
			else
			{
				return 0;
			}
		}
		case WM_GETDLGCODE:
		{
			DWORD dwDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS | DLGC_WANTTAB;
			if ( HAS_FLAG( GetWindowLong( hWnd, GWL_STYLE ), ES_WANTRETURN ) )
			{
				dwDlgCode |= DLGC_WANTALLKEYS;
			}
			return dwDlgCode;
		}
	}

	// Other than the above messages, the hotkey control behaves identical to an edit control
	WNDCLASS wcEdit;
	VERIFY( GetClassInfo( ( HINSTANCE ) GetWindowLong( hWnd, GWL_HINSTANCE ), _T("EDIT"), &wcEdit ) );
#ifdef _ACTIVEX
	return CallWindowProc( wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam );
#else
	#if _MSC_VER  > 1100 
		return CallWindowProc( ( WNDPROC ) wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam );
	#else
		return CallWindowProc( ( FARPROC ) wcEdit.lpfnWndProc, hWnd, uMsg, wParam, lParam );
	#endif

#endif
}
Ejemplo n.º 23
0
LRESULT CALLBACK PhpExtendedListViewWndProc(
    _In_ HWND hwnd,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    PPH_EXTLV_CONTEXT context;
    WNDPROC oldWndProc;

    context = (PPH_EXTLV_CONTEXT)GetProp(hwnd, PhpMakeExtLvContextAtom());
    oldWndProc = context->OldWndProc;

    switch (uMsg)
    {
    case WM_DESTROY:
        {
            SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc);
            PhFree(context);
            RemoveProp(hwnd, PhpMakeExtLvContextAtom());
        }
        break;
    case WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case HDN_ITEMCLICK:
                {
                    HWND headerHandle;

                    headerHandle = (HWND)CallWindowProc(context->OldWndProc, hwnd, LVM_GETHEADER, 0, 0);

                    if (header->hwndFrom == headerHandle)
                    {
                        LPNMHEADER header2 = (LPNMHEADER)header;

                        if (header2->iItem == context->SortColumn)
                        {
                            if (context->TriState)
                            {
                                if (context->SortOrder == AscendingSortOrder)
                                    context->SortOrder = DescendingSortOrder;
                                else if (context->SortOrder == DescendingSortOrder)
                                    context->SortOrder = NoSortOrder;
                                else
                                    context->SortOrder = AscendingSortOrder;
                            }
                            else
                            {
                                if (context->SortOrder == AscendingSortOrder)
                                    context->SortOrder = DescendingSortOrder;
                                else
                                    context->SortOrder = AscendingSortOrder;
                            }
                        }
                        else
                        {
                            context->SortColumn = header2->iItem;
                            context->SortOrder = AscendingSortOrder;
                        }

                        PhSetHeaderSortIcon(headerHandle, context->SortColumn, context->SortOrder);
                        ExtendedListView_SortItems(hwnd);
                    }
                }
                break;
            }
        }
        break;
    case WM_REFLECT + WM_NOTIFY:
        {
            LPNMHDR header = (LPNMHDR)lParam;

            switch (header->code)
            {
            case NM_CUSTOMDRAW:
                {
                    if (header->hwndFrom == hwnd)
                    {
                        LPNMLVCUSTOMDRAW customDraw = (LPNMLVCUSTOMDRAW)header;

                        switch (customDraw->nmcd.dwDrawStage)
                        {
                        case CDDS_PREPAINT:
                            return CDRF_NOTIFYITEMDRAW;
                        case CDDS_ITEMPREPAINT:
                            {
                                BOOLEAN colorChanged = FALSE;
                                HFONT newFont = NULL;

                                if (context->ItemColorFunction)
                                {
                                    customDraw->clrTextBk = context->ItemColorFunction(
                                        (INT)customDraw->nmcd.dwItemSpec,
                                        (PVOID)customDraw->nmcd.lItemlParam,
                                        context->Context
                                        );
                                    colorChanged = TRUE;
                                }

                                if (context->ItemFontFunction)
                                {
                                    newFont = context->ItemFontFunction(
                                        (INT)customDraw->nmcd.dwItemSpec,
                                        (PVOID)customDraw->nmcd.lItemlParam,
                                        context->Context
                                        );
                                }

                                if (newFont)
                                    SelectObject(customDraw->nmcd.hdc, newFont);

                                if (colorChanged)
                                {
                                    if (PhGetColorBrightness(customDraw->clrTextBk) > 100) // slightly less than half
                                        customDraw->clrText = RGB(0x00, 0x00, 0x00);
                                    else
                                        customDraw->clrText = RGB(0xff, 0xff, 0xff);
                                }

                                if (!newFont)
                                    return CDRF_DODEFAULT;
                                else
                                    return CDRF_NEWFONT;
                            }
                            break;
                        }
                    }
                }
                break;
            }
        }
        break;
    case WM_SETCURSOR:
        {
            if (context->Cursor)
            {
                SetCursor(context->Cursor);
                return TRUE;
            }
        }
        break;
    case WM_UPDATEUISTATE:
        {
            // Disable focus rectangles by setting or masking out the flag where appropriate.
            switch (LOWORD(wParam))
            {
            case UIS_SET:
                wParam |= UISF_HIDEFOCUS << 16;
                break;
            case UIS_CLEAR:
            case UIS_INITIALIZE:
                wParam &= ~(UISF_HIDEFOCUS << 16);
                break;
            }
        }
        break;
    case ELVM_ADDFALLBACKCOLUMN:
        {
            if (context->NumberOfFallbackColumns < PH_MAX_COMPARE_FUNCTIONS)
                context->FallbackColumns[context->NumberOfFallbackColumns++] = (ULONG)wParam;
            else
                return FALSE;
        }
        return TRUE;
    case ELVM_ADDFALLBACKCOLUMNS:
        {
            ULONG numberOfColumns = (ULONG)wParam;
            PULONG columns = (PULONG)lParam;

            if (context->NumberOfFallbackColumns + numberOfColumns <= PH_MAX_COMPARE_FUNCTIONS)
            {
                memcpy(
                    &context->FallbackColumns[context->NumberOfFallbackColumns],
                    columns,
                    numberOfColumns * sizeof(ULONG)
                    );
                context->NumberOfFallbackColumns += numberOfColumns;
            }
            else
            {
                return FALSE;
            }
        }
        return TRUE;
    case ELVM_INIT:
        {
            PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder);

            // HACK to fix tooltips showing behind Always On Top windows.
            SetWindowPos(ListView_GetToolTips(hwnd), HWND_TOPMOST, 0, 0, 0, 0,
                SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

            // Make sure focus rectangles are disabled.
            SendMessage(hwnd, WM_CHANGEUISTATE, MAKELONG(UIS_SET, UISF_HIDEFOCUS), 0);
        }
        return TRUE;
    case ELVM_SETCOLUMNWIDTH:
        {
            ULONG column = (ULONG)wParam;
            LONG width = (LONG)lParam;

            if (width == ELVSCW_AUTOSIZE_REMAININGSPACE)
            {
                RECT clientRect;
                LONG availableWidth;
                ULONG i;
                LVCOLUMN lvColumn;

                GetClientRect(hwnd, &clientRect);
                availableWidth = clientRect.right;
                i = 0;
                lvColumn.mask = LVCF_WIDTH;

                while (TRUE)
                {
                    if (i != column)
                    {
                        if (CallWindowProc(oldWndProc, hwnd, LVM_GETCOLUMN, i, (LPARAM)&lvColumn))
                        {
                            availableWidth -= lvColumn.cx;
                        }
                        else
                        {
                            break;
                        }
                    }

                    i++;
                }

                if (availableWidth >= 40)
                    return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, availableWidth);
            }

            return CallWindowProc(oldWndProc, hwnd, LVM_SETCOLUMNWIDTH, column, width);
        }
        break;
    case ELVM_SETCOMPAREFUNCTION:
        {
            ULONG column = (ULONG)wParam;
            PPH_COMPARE_FUNCTION compareFunction = (PPH_COMPARE_FUNCTION)lParam;

            if (column >= PH_MAX_COMPARE_FUNCTIONS)
                return FALSE;

            context->CompareFunctions[column] = compareFunction;
        }
        return TRUE;
    case ELVM_SETCONTEXT:
        {
            context->Context = (PVOID)lParam;
        }
        return TRUE;
    case ELVM_SETCURSOR:
        {
            context->Cursor = (HCURSOR)lParam;
        }
        return TRUE;
    case ELVM_SETITEMCOLORFUNCTION:
        {
            context->ItemColorFunction = (PPH_EXTLV_GET_ITEM_COLOR)lParam;
        }
        return TRUE;
    case ELVM_SETITEMFONTFUNCTION:
        {
            context->ItemFontFunction = (PPH_EXTLV_GET_ITEM_FONT)lParam;
        }
        return TRUE;
    case ELVM_SETREDRAW:
        {
            if (wParam)
                context->EnableRedraw++;
            else
                context->EnableRedraw--;

            if (context->EnableRedraw == 1)
            {
                SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
                InvalidateRect(hwnd, NULL, FALSE);
            }
            else if (context->EnableRedraw == 0)
            {
                SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
            }
        }
        return TRUE;
    case ELVM_SETSORT:
        {
            context->SortColumn = (ULONG)wParam;
            context->SortOrder = (PH_SORT_ORDER)lParam;

            PhSetHeaderSortIcon(ListView_GetHeader(hwnd), context->SortColumn, context->SortOrder);
        }
        return TRUE;
    case ELVM_SETSORTFAST:
        {
            context->SortFast = !!wParam;
        }
        return TRUE;
    case ELVM_SETTRISTATE:
        {
            context->TriState = !!wParam;
        }
        return TRUE;
    case ELVM_SETTRISTATECOMPAREFUNCTION:
        {
            context->TriStateCompareFunction = (PPH_COMPARE_FUNCTION)lParam;
        }
        return TRUE;
    case ELVM_SORTITEMS:
        {
            if (context->SortFast)
            {
                // This sort method is faster than the normal sort because our comparison function
                // doesn't have to call the list view window procedure to get the item lParam values.
                // The disadvantage of this method is that default sorting is not available - if a
                // column doesn't have a comparison function, it doesn't get sorted at all.

                ListView_SortItems(
                    hwnd,
                    PhpExtendedListViewCompareFastFunc,
                    (LPARAM)context
                    );
            }
            else
            {
                ListView_SortItemsEx(
                    hwnd,
                    PhpExtendedListViewCompareFunc,
                    (LPARAM)context
                    );
            }
        }
        return TRUE;
    }

    return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
}
Ejemplo n.º 24
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

#ifdef SHOW_TOOLBAR_UI
  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }
    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else
#endif // SHOW_TOOLBAR_UI
  {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

#ifdef SHOW_TOOLBAR_UI
      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;
#endif // SHOW_TOOLBAR_UI

      CefWindowInfo info;
      CefBrowserSettings settings;

      // Populate the settings based on command line arguments.
      AppGetBrowserSettings(settings);

      settings.file_access_from_file_urls_allowed = true;
      settings.universal_access_from_file_urls_allowed = true;

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          szInitialUrl, settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_EXIT:
        if (g_handler.get()) {
          g_handler->QuittingApp(true);
    	  g_handler->DispatchCloseToNextBrowser();
    	} else {
          DestroyWindow(hWnd);
		}
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
/*
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
*/
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
#ifdef SHOW_TOOLBAR_UI
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
#endif // SHOW_TOOLBAR_UI
      default:
          ExtensionString commandId = NativeMenuModel::getInstance(getMenuParent(g_handler->GetBrowser())).getCommandId(wmId);
          if (commandId.size() > 0) {
              CefRefPtr<CommandCallback> callback = new EditCommandCallback(g_handler->GetBrowser(), commandId);
              g_handler->SendJSCommand(g_handler->GetBrowser(), commandId, callback);
          }
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
#ifdef SHOW_TOOLBAR_UI
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;
#endif // SHOW_TOOLBAR_UI

          HDWP hdwp = BeginDeferWindowPos(1);
#ifdef SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
#endif // SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {

        HWND hWnd = GetActiveWindow();
        SaveWindowRect(hWnd);

        // If we already initiated the browser closing, then let default window proc handle it.
        HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
        if (closing) {
		    RemoveProp(browserHwnd, CLOSING_PROP);
			break;
		}

        g_handler->QuittingApp(true);
        g_handler->DispatchCloseToNextBrowser();
        return 0;
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;

    case WM_DROPFILES:
        if (g_handler.get()) {
            return HandleDropFiles((HDROP)wParam, g_handler, g_handler->GetBrowser());
        }
        return 0;

    case WM_INITMENUPOPUP:
        HMENU menu = (HMENU)wParam;
        int count = GetMenuItemCount(menu);
        void* menuParent = getMenuParent(g_handler->GetBrowser());
        for (int i = 0; i < count; i++) {
            UINT id = GetMenuItemID(menu, i);

            bool enabled = NativeMenuModel::getInstance(menuParent).isMenuItemEnabled(id);
            UINT flagEnabled = enabled ? MF_ENABLED | MF_BYCOMMAND : MF_DISABLED | MF_BYCOMMAND;
            EnableMenuItem(menu, id,  flagEnabled);

            bool checked = NativeMenuModel::getInstance(menuParent).isMenuItemChecked(id);
            UINT flagChecked = checked ? MF_CHECKED | MF_BYCOMMAND : MF_UNCHECKED | MF_BYCOMMAND;
            CheckMenuItem(menu, id, flagChecked);
        }
        break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
/*
 * Function CHyperLink::_HyperlinkProc
 *
 * Note: Processed messages are not passed back to the static control
 *       procedure. It does work fine but be aware that it could cause
 *       some problems if the static control is already subclassed.
 *       Consider the example where the static control would be already
 *       subclassed with the ToolTip control that needs to process mouse
 *       messages. In that situation, the ToolTip control would not work
 *       as expected.
 */
LRESULT CALLBACK CHyperLink::_HyperlinkProc(HWND hwnd, UINT message,
                                           WPARAM wParam, LPARAM lParam)
{
    CHyperLink *pHyperLink = (CHyperLink *)GetProp(hwnd, PROP_OBJECT_PTR);

    switch (message)
    {
    case WM_MOUSEMOVE:
        {
            if ( pHyperLink->m_bOverControl )
            {
                // This is the most common case for static branch prediction
                // optimization
                RECT rect;
                GetClientRect(hwnd,&rect);

                POINT pt = { LOWORD(lParam), HIWORD(lParam) };

                if (!PTINRECT(&rect,pt))
                {
                    ReleaseCapture();
                }
            }
            else
            {
                pHyperLink->m_bOverControl = TRUE;
                SendMessage(hwnd, WM_SETFONT,
                            (WPARAM)CHyperLink::g_UnderlineFont, FALSE);
                InvalidateRect(hwnd, NULL, FALSE);
                pHyperLink->OnSelect();
                SetCapture(hwnd);
            }
            return 0;
        }
    case WM_SETCURSOR:
        {
            SetCursor(CHyperLink::g_hLinkCursor);
            return TRUE;
        }
    case WM_CAPTURECHANGED:
        {
            pHyperLink->m_bOverControl = FALSE;
            pHyperLink->OnDeselect();
            SendMessage(hwnd, WM_SETFONT,
                        (WPARAM)pHyperLink->m_StdFont, FALSE);
            InvalidateRect(hwnd, NULL, FALSE);
            return 0;
        }
    case WM_KEYUP:
        {
            if( wParam != VK_SPACE )
            {
                break;
            }
        }
                        // Fall through
    case WM_LBUTTONUP:
        {
            pHyperLink->Navigate();
            return 0;
        }
    case WM_SETFOCUS:   // Fall through
    case WM_KILLFOCUS:
        {
            if( message == WM_SETFOCUS )
            {
                pHyperLink->OnSelect();
            }
            else        // WM_KILLFOCUS
            {
                pHyperLink->OnDeselect();
            }
            CHyperLink::DrawFocusRect(hwnd);
            return 0;
        }
    case WM_DESTROY:
        {
            SetWindowLongPtr(hwnd, GWLP_WNDPROC,
                          (LONG_PTR) pHyperLink->m_pfnOrigCtlProc);

            SendMessage(hwnd, WM_SETFONT, (WPARAM) pHyperLink->m_StdFont, 0);

            if( --CHyperLink::g_counter <= 0 )
            {
                destroyGlobalResources();
            }

            RemoveProp(hwnd, PROP_OBJECT_PTR);
            break;
        }
    }

    return CallWindowProc(pHyperLink->m_pfnOrigCtlProc, hwnd, message,
                          wParam, lParam);
}
Ejemplo n.º 26
0
INT_PTR CALLBACK PhpProcessTokenHookProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )
{
    switch (uMsg)
    {
    case WM_DESTROY:
        {
            RemoveProp(hwndDlg, PhMakeContextAtom());
        }
        break;
    case WM_SHOWWINDOW:
        {
            if (!GetProp(hwndDlg, PhMakeContextAtom())) // LayoutInitialized
            {
                PPH_LAYOUT_ITEM dialogItem;
                HWND groupsLv;
                HWND privilegesLv;

                // This is a big violation of abstraction...

                dialogItem = PhAddPropPageLayoutItem(hwndDlg, hwndDlg,
                    PH_PROP_PAGE_TAB_CONTROL_PARENT, PH_ANCHOR_ALL);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_USER),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_USERSID),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_VIRTUALIZED),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_APPCONTAINERSID),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_GROUPS),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_TOP | PH_ANCHOR_RIGHT);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_PRIVILEGES),
                    dialogItem, PH_ANCHOR_ALL);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_INSTRUCTION),
                    dialogItem, PH_ANCHOR_LEFT | PH_ANCHOR_BOTTOM);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_INTEGRITY),
                    dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
                PhAddPropPageLayoutItem(hwndDlg, GetDlgItem(hwndDlg, IDC_ADVANCED),
                    dialogItem, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);

                PhDoPropPageLayout(hwndDlg);

                groupsLv = GetDlgItem(hwndDlg, IDC_GROUPS);
                privilegesLv = GetDlgItem(hwndDlg, IDC_PRIVILEGES);

                if (ListView_GetItemCount(groupsLv) != 0)
                {
                    ListView_SetColumnWidth(groupsLv, 0, LVSCW_AUTOSIZE);
                    ExtendedListView_SetColumnWidth(groupsLv, 1, ELVSCW_AUTOSIZE_REMAININGSPACE);
                }

                if (ListView_GetItemCount(privilegesLv) != 0)
                {
                    ListView_SetColumnWidth(privilegesLv, 0, LVSCW_AUTOSIZE);
                    ListView_SetColumnWidth(privilegesLv, 1, LVSCW_AUTOSIZE);
                    ExtendedListView_SetColumnWidth(privilegesLv, 2, ELVSCW_AUTOSIZE_REMAININGSPACE);
                }

                SetProp(hwndDlg, PhMakeContextAtom(), (HANDLE)TRUE);
            }
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 27
0
Bool
winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  Bool			fReturn;

#if CYGDEBUG
  ErrorF ("winCloseScreenShadowDDNL - Freeing screen resources\n");
#endif

  /* Flag that the screen is closed */
  pScreenPriv->fClosed = TRUE;
  pScreenPriv->fActive = FALSE;

  /* Call the wrapped CloseScreen procedure */
  pScreen->CloseScreen = pScreenPriv->CloseScreen;
  fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);

  /* Free the screen DC */
  ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);

  /* Delete the window property */
  RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);

  /* Free the shadow surface, if there is one */
  if (pScreenPriv->pddsShadow4)
    {
      IDirectDrawSurface4_Release (pScreenPriv->pddsShadow4);
      free (pScreenInfo->pfb);
      pScreenInfo->pfb = NULL;
      pScreenPriv->pddsShadow4 = NULL;
    }

  /* Detach the clipper from the primary surface and release the clipper. */
  if (pScreenPriv->pddcPrimary)
    {
      /* Detach the clipper */
      IDirectDrawSurface4_SetClipper (pScreenPriv->pddsPrimary4,
				      NULL);

      /* Release the clipper object */
      IDirectDrawClipper_Release (pScreenPriv->pddcPrimary);
      pScreenPriv->pddcPrimary = NULL;
    }

  /* Release the primary surface, if there is one */
  if (pScreenPriv->pddsPrimary4)
    {
      IDirectDrawSurface4_Release (pScreenPriv->pddsPrimary4);
      pScreenPriv->pddsPrimary4 = NULL;
    }

  /* Free the DirectDraw4 object, if there is one */
  if (pScreenPriv->pdd4)
    {
      IDirectDraw4_RestoreDisplayMode (pScreenPriv->pdd4);
      IDirectDraw4_Release (pScreenPriv->pdd4);
      pScreenPriv->pdd4 = NULL;
    }

  /* Free the DirectDraw object, if there is one */
  if (pScreenPriv->pdd)
    {
      IDirectDraw_Release (pScreenPriv->pdd);
      pScreenPriv->pdd = NULL;
    }

  /* Kill our window */
  if (pScreenPriv->hwndScreen)
    {
      DestroyWindow (pScreenPriv->hwndScreen);
      pScreenPriv->hwndScreen = NULL;
    }

  /* Destroy the thread startup mutex */
  pthread_mutex_destroy (&pScreenPriv->pmServerStarted);

  /* Kill our screeninfo's pointer to the screen */
  pScreenInfo->pScreen = NULL;

  /* Invalidate the ScreenInfo's fb pointer */
  pScreenInfo->pfb = NULL;

  /* Free the screen privates for this screen */
  free ((pointer) pScreenPriv);

  return fReturn;
}
Ejemplo n.º 28
0
LRESULT CALLBACK CLinkControl::_HyperlinkProc(HWND hwnd, UINT message,
										   WPARAM wParam, LPARAM lParam)
{
	CLinkControl *pHyperLink = (CLinkControl *)GetProp(hwnd, PROP_OBJECT_PTR);

	switch (message)
	{
	case WM_MOUSEMOVE:
		{
			if (pHyperLink->m_bOverControl)
			{
				RECT rect;
				GetClientRect(hwnd, &rect);

				POINT pt = { LOWORD(lParam), HIWORD(lParam) };

				if (!PtInRect(&rect, pt))
					ReleaseCapture();
			}
			else
			{
				pHyperLink->m_bOverControl = TRUE;
				SendMessage(hwnd, WM_SETFONT, (WPARAM)CLinkControl::g_UnderlineFont, FALSE);
				InvalidateRect(hwnd, NULL, FALSE);
				SetCapture(hwnd);
			}
		}
		break;
	case WM_SETCURSOR:
		{
			SetCursor(CLinkControl::g_hLinkCursor);
			return TRUE;
		}
		break;
	case WM_CAPTURECHANGED:
		{
			pHyperLink->m_bOverControl = FALSE;
			SendMessage(hwnd, WM_SETFONT, (WPARAM)CLinkControl::g_NormalFont, FALSE);
			InvalidateRect(hwnd, NULL, FALSE);
		}
		break;
	case WM_KEYDOWN:
		{
			if ((wParam != VK_SPACE)&&(wParam != VK_RETURN))
				break;
			PostMessage(::GetParent(hwnd), LK_LINKITEMCLICKED, (WPARAM)hwnd, (LPARAM)0);
			return 0;
		}
		break;
	case WM_LBUTTONUP:
		{
			PostMessage(::GetParent(hwnd), LK_LINKITEMCLICKED, (WPARAM)hwnd, (LPARAM)0);
		}
		break;
	case WM_GETDLGCODE:
		{
			LRESULT lres = CallWindowProc(pHyperLink->m_pfnOrigCtlProc, hwnd, message, wParam, lParam);
			// we want all keys to get the return key
			lres |= DLGC_WANTALLKEYS;
			// but we don't want the tab key since that should be used in dialogs
			// to switch the focus
			lres &= ~DLGC_WANTTAB;
			if (lParam &&
				((MSG *)lParam)->message == WM_KEYDOWN &&
				((MSG *)lParam)->wParam == VK_TAB) 
			{
				lres &= ~DLGC_WANTMESSAGE;
			}
			return lres;
		}
		break;
	case WM_SETFOCUS:	
		// Fall through
	case WM_KILLFOCUS:
		{
			CLinkControl::DrawFocusRect(hwnd);
		}
		break;
	case WM_DESTROY:
		{
			SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pHyperLink->m_pfnOrigCtlProc);

			SendMessage(hwnd, WM_SETFONT, (WPARAM)pHyperLink->m_StdFont, 0);

			if (--CLinkControl::g_counter <= 0)
				destroyGlobalResources();

			RemoveProp(hwnd, PROP_OBJECT_PTR);
		}
		break;
	}

	return CallWindowProc(pHyperLink->m_pfnOrigCtlProc, hwnd, message,
						  wParam, lParam);
}
Ejemplo n.º 29
0
/*
 * DialogProc for OpenVPN status dialog windows
 */
INT_PTR CALLBACK
StatusDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    connection_t *c;

    switch (msg)
    {
    case WM_MANAGEMENT:
        /* Management interface related event */
        OnManagement(wParam, lParam);
        return TRUE;

    case WM_INITDIALOG:
        c = (connection_t *) lParam;

        /* Set window icon "disconnected" */
        SetStatusWinIcon(hwndDlg, ID_ICO_CONNECTING);

        /* Set connection for this dialog */
        SetProp(hwndDlg, cfgProp, (HANDLE) c);

        /* Create log window */
        HWND hLogWnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
            WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_SUNKEN|ES_LEFT|
            ES_MULTILINE|ES_READONLY|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
            20, 25, 350, 160, hwndDlg, (HMENU) ID_EDT_LOG, o.hInstance, NULL);
        if (!hLogWnd)
        {
            ShowLocalizedMsg(IDS_ERR_CREATE_EDIT_LOGWINDOW);
            return FALSE;
        }

        /* Set font and fontsize of the log window */
        CHARFORMAT cfm = {
            .cbSize = sizeof(CHARFORMAT),
            .dwMask = CFM_SIZE|CFM_FACE|CFM_BOLD,
            .szFaceName = _T("Microsoft Sans Serif"),
            .dwEffects = 0,
            .yHeight = 160
        };
        if (SendMessage(hLogWnd, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM) &cfm) == 0)
            ShowLocalizedMsg(IDS_ERR_SET_SIZE);

        /* Set size and position of controls */
        RECT rect;
        GetClientRect(hwndDlg, &rect);
        MoveWindow(hLogWnd, 20, 25, rect.right - 40, rect.bottom - 70, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_TXT_STATUS), 20, 5, rect.right - 25, 15, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_DISCONNECT), 20, rect.bottom - 30, 110, 23, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_RESTART), 145, rect.bottom - 30, 110, 23, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_HIDE), rect.right - 130, rect.bottom - 30, 110, 23, TRUE);

        /* Set focus on the LogWindow so it scrolls automatically */
        SetFocus(hLogWnd);
        return FALSE;

    case WM_SIZE:
        MoveWindow(GetDlgItem(hwndDlg, ID_EDT_LOG), 20, 25, LOWORD(lParam) - 40, HIWORD(lParam) - 70, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_DISCONNECT), 20, HIWORD(lParam) - 30, 110, 23, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_RESTART), 145, HIWORD(lParam) - 30, 110, 23, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_HIDE), LOWORD(lParam) - 130, HIWORD(lParam) - 30, 110, 23, TRUE);
        MoveWindow(GetDlgItem(hwndDlg, ID_TXT_STATUS), 20, 5, LOWORD(lParam) - 25, 15, TRUE);
        InvalidateRect(hwndDlg, NULL, TRUE);
        return TRUE;

    case WM_COMMAND:
        c = (connection_t *) GetProp(hwndDlg, cfgProp);
        switch (LOWORD(wParam))
        {
        case ID_DISCONNECT:
            SetFocus(GetDlgItem(c->hwndStatus, ID_EDT_LOG));
            StopOpenVPN(c);
            return TRUE;

        case ID_HIDE:
            if (c->state != disconnected)
                ShowWindow(hwndDlg, SW_HIDE);
            else
                DestroyWindow(hwndDlg);
            return TRUE;

        case ID_RESTART:
            c->state = reconnecting;
            SetFocus(GetDlgItem(c->hwndStatus, ID_EDT_LOG));
            ManagementCommand(c, "signal SIGHUP", NULL, regular);
            return TRUE;
        }
        break;

    case WM_SHOWWINDOW:
        if (wParam == TRUE)
        {
            c = (connection_t *) GetProp(hwndDlg, cfgProp);
            if (c->hwndStatus)
                SetFocus(GetDlgItem(c->hwndStatus, ID_EDT_LOG));
        }
        return FALSE;

    case WM_CLOSE:
        c = (connection_t *) GetProp(hwndDlg, cfgProp);
        if (c->state != disconnected)
            ShowWindow(hwndDlg, SW_HIDE);
        else
            DestroyWindow(hwndDlg);
        return TRUE;

    case WM_NCDESTROY:
        RemoveProp(hwndDlg, cfgProp);
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return FALSE;
}


/*
 * ThreadProc for OpenVPN status dialog windows
 */
static DWORD WINAPI
ThreadOpenVPNStatus(void *p)
{
    connection_t *c = p;
    TCHAR conn_name[200];
    MSG msg;

    /* Cut of extention from config filename. */
    _tcsncpy(conn_name, c->config_file, _countof(conn_name));
    conn_name[_tcslen(conn_name) - _tcslen(o.ext_string) - 1] = _T('\0');

    c->state = (c->state == suspended ? resuming : connecting);

    /* Create and Show Status Dialog */
    c->hwndStatus = CreateLocalizedDialogParam(ID_DLG_STATUS, StatusDialogFunc, (LPARAM) c);
    if (!c->hwndStatus)
        return 1;

    CheckAndSetTrayIcon();
    SetMenuStatus(c, connecting);
    SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTING));
    SetWindowText(c->hwndStatus, LoadLocalizedString(IDS_NFO_CONNECTION_XXX, conn_name));

    if (!OpenManagement(c))
        PostMessage(c->hwndStatus, WM_CLOSE, 0, 0);

    if (o.silent_connection[0] == '0')
        ShowWindow(c->hwndStatus, SW_SHOW);

    /* Run the message loop for the status window */
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.hwnd == NULL)
        {
            switch (msg.message)
            {
            case WM_OVPN_STOP:
                c->state = disconnecting;
                RunDisconnectScript(c, false);
                EnableWindow(GetDlgItem(c->hwndStatus, ID_DISCONNECT), FALSE);
                EnableWindow(GetDlgItem(c->hwndStatus, ID_RESTART), FALSE);
                SetMenuStatus(c, disconnecting);
                SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM));
                SetEvent(c->exit_event);
                break;

            case WM_OVPN_SUSPEND:
                c->state = suspending;
                EnableWindow(GetDlgItem(c->hwndStatus, ID_DISCONNECT), FALSE);
                EnableWindow(GetDlgItem(c->hwndStatus, ID_RESTART), FALSE);
                SetMenuStatus(&o.conn[config], disconnecting);
                SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_WAIT_TERM));
                SetEvent(c->exit_event);
                break;
            }
        }
        else if (IsDialogMessage(c->hwndStatus, &msg) == 0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return 0;
}
Ejemplo n.º 30
0
static LRESULT CALLBACK BaseBar_WindowProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
    LPBASEBARINFO lpbi = (LPBASEBARINFO)GetProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0));//GetWindowLong(hwnd, GWL_USERDATA);

    switch (uMessage)
    {
    case WM_CREATE:
    {
        LPCREATESTRUCT lpcs    = (LPCREATESTRUCT)lParam;
        DWORD          dwStyle = RBS_VERTICALGRIPPER | RBS_REGISTERDROP | RBS_AUTOSIZE | RBS_VARHEIGHT | RBS_DBLCLKTOGGLE | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE;
        REBARBANDINFO  rbBand;
        TBBUTTON tbb;

        if (lpcs->lpszName)
            lpbi->pszTitle = String_Duplicate(lpcs->lpszName);

        lpbi->dwAlign = BaseBar_GetAlign(hwnd);
        lpbi->dwAllowableAligns = CCS_LEFT | CCS_RIGHT | CCS_TOP | CCS_BOTTOM;

        if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
            dwStyle |= CCS_VERT;

        if (!(lpbi->hwndRebar = CreateWindowEx(0, REBARCLASSNAME, NULL, WS_VISIBLE | WS_BORDER | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | dwStyle,
            0, 0, 0, 0, hwnd, (HMENU) REBARID, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL)))
            return (0);

        SendMessage(lpbi->hwndRebar, RB_SETBKCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNFACE));

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_HEADERSIZE | RBBIM_ID | RBBIM_STYLE | RBBIM_COLORS;
        rbBand.fStyle     = RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT | RBBS_NOGRIPPER;
        rbBand.clrFore    = GetSysColor(COLOR_BTNTEXT);
        rbBand.clrBack    = GetSysColor(COLOR_BTNFACE);
        rbBand.cxHeader   = ((lpcs->style & CCS_VERT) ? 21 : 24);
        rbBand.wID        = (UINT)lpcs->hMenu;

        if (lpcs->style & CCS_VERT)
        {
            rbBand.fMask |= RBBIM_TEXT;
            rbBand.lpText = (char*)lpcs->lpszName;
        }

        SendMessage(lpbi->hwndRebar, RB_INSERTBAND, (int) -1, (LPARAM) &rbBand);

        ZeroMemory(&tbb, sizeof(TBBUTTON));

        tbb.iBitmap   = 0; 
        tbb.idCommand = IDM_BAND_CLOSE;
        tbb.fsState   = TBSTATE_ENABLED; 
        tbb.fsStyle   = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE;

        lpbi->hwndToolbar = CreateToolbarEx(lpbi->hwndRebar, WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER  | CCS_NOPARENTALIGN | CCS_NOMOVEY | CCS_NORESIZE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT,
            IDC_TOOLBAR, 1, PCPControls_GetHandle(), IDB_CHECKBOX, &tbb, 1, 13, 12, 11, 10, sizeof (TBBUTTON));

        SendMessage(lpbi->hwndToolbar, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG(20, 18));
        SendMessage(lpbi->hwndToolbar, TB_SETBITMAPSIZE, 0, (LPARAM) MAKELONG(10, 9));
    }
    return (TRUE);
    case WM_SIZE:
    {
        RECT rcNew;

        GetClientRect(hwnd, &rcNew);

        if (wParam == SIZE_RESTORED && !EqualRect(&rcNew, &lpbi->rcSize))
        {
            NMHDR nmhdr;

            MoveWindow(lpbi->hwndRebar, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);

            nmhdr.code     = RBN_HEIGHTCHANGE;
            nmhdr.hwndFrom = hwnd;
            nmhdr.idFrom   = GetDlgCtrlID(hwnd);
            SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);

            if (lpbi->hwndToolbar)
            {
                RECT  rcBand;
                DWORD dwSize = (DWORD)SendMessage(lpbi->hwndToolbar, TB_GETBUTTONSIZE, 0, 0);

                SendMessage(lpbi->hwndRebar, RB_GETBANDBORDERS, 0, (LPARAM)&rcBand);

                if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
                {
                    int x = (LOWORD(lParam) - 24);
                    int y = ((rcBand.top - HIWORD(dwSize)) / 2);
                    MoveWindow(lpbi->hwndToolbar, x, y, 20, 18, TRUE);
                }
                else
                {
                    MoveWindow(lpbi->hwndToolbar, 2, 2, 20, 18, TRUE);
                }
            }
        }

        GetClientRect(hwnd, &lpbi->rcSize);
    }
    break;
    case WM_NOTIFY:
    {
        LPNMHDR lphdr = (LPNMHDR)lParam;

        if (lphdr->code == NM_NCHITTEST && lphdr->idFrom == REBARID)
        {
            if (HIBYTE(GetAsyncKeyState(VK_RBUTTON)))
            {
                HMENU hMenu = LoadMenu(PCPControls_GetHandle(), MAKEINTRESOURCE(IDR_BANDMENU));
                HMENU hPopupMenu = GetSubMenu(hMenu, 0);
                POINT pt;

                if (lpbi->dwAllowableAligns & CCS_VERT)
                {
                    if (!(lpbi->dwAllowableAligns & CCS_LEFT))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_LEFT, FALSE);
                    if (!(lpbi->dwAllowableAligns & CCS_RIGHT))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_RIGHT, FALSE);

                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_TOP, FALSE);
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_BOTTOM, FALSE);
                }
                else
                {
                    if (!(lpbi->dwAllowableAligns & CCS_TOP))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_TOP, FALSE);
                    if (!(lpbi->dwAllowableAligns & CCS_BOTTOM))
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_BOTTOM, FALSE);

                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_LEFT, FALSE);
                        Menu_EnableMenuItem(hPopupMenu, IDM_BAND_RIGHT, FALSE);
                }

                GetCursorPos(&pt);

                Menu_TrackPopupMenu(hPopupMenu, pt.x, pt.y, hwnd);
            }
            return (HTCLIENT);
        }
        else if (lphdr->code == NM_CUSTOMDRAW && lphdr->idFrom == REBARID)
        {
            LPNMCUSTOMDRAW lpnmcd = (LPNMCUSTOMDRAW) lParam;

            if (lpnmcd->dwDrawStage == CDDS_PREPAINT)
                return (CDRF_NOTIFYPOSTPAINT);
            else if (lpnmcd->dwDrawStage == CDDS_POSTPAINT && (lpbi->dwAlign == CCS_TOP || lpbi->dwAlign == CCS_BOTTOM))
            {
                DrawEdge(lpnmcd->hdc, &lpnmcd->rc, EDGE_ETCHED, BF_RIGHT);
            }
        }
        else if (lphdr->idFrom == IDC_TOOLBAR)
        {
        }
    }
    return (SendMessage(GetParent(hwnd), uMessage, wParam, lParam));
    case WM_COMMAND:
    {
        DWORD dwAlign;

        switch (LOWORD(wParam))
        {
        case IDM_BAND_LEFT:
            dwAlign = CCS_LEFT;
        break;
        case IDM_BAND_RIGHT:
            dwAlign = CCS_RIGHT;
        break;
        case IDM_BAND_TOP:
            dwAlign = CCS_TOP;
        break;
        case IDM_BAND_BOTTOM:
            dwAlign = CCS_BOTTOM;
        break;
        case IDM_BAND_CLOSE:
        {
            NMHDR nmhdr;

            nmhdr.code     = BBN_CLOSE;
            nmhdr.hwndFrom = hwnd;
            nmhdr.idFrom   = GetDlgCtrlID(hwnd);

            SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
        }
        return (0);
        default:
        return (0);
        }

        SendMessage(hwnd, BCM_SETALIGNMENT, (WPARAM)dwAlign, 0L);
    }
    case WM_GETMINMAXINFO:
    {
        MINMAXINFO *lpmmi = (MINMAXINFO *)lParam;
        
        if (lpmmi != NULL)
        {
            int cx = GetSystemMetrics(SM_CXSCREEN);
            int cy = GetSystemMetrics(SM_CYSCREEN);
            
            if (lpbi->dwAlign == CCS_LEFT || lpbi->dwAlign == CCS_RIGHT)
                lpmmi->ptMaxTrackSize.x = cx / 2;
            else
                lpmmi->ptMaxTrackSize.y = cy / 2;
            
            if (lpbi->dwAlign == CCS_LEFT)
            {
                lpmmi->ptMinTrackSize.x = 50;
            }
            else if (lpbi->dwAlign == CCS_RIGHT)
            {
                lpmmi->ptMinTrackSize.x = 50;
            }
            else if (lpbi->dwAlign == CCS_TOP)
            {
                lpmmi->ptMinTrackSize.y = 50;
            }
            else if (lpbi->dwAlign == CCS_BOTTOM)
            {
                lpmmi->ptMinTrackSize.y = 50;
            }
            else
            {
                lpmmi->ptMinTrackSize.x = 56;
                lpmmi->ptMinTrackSize.y = 24;
            }
        }
    }
    return (FALSE);
    case WM_NCCREATE:
    {
        lpbi = Mem_Alloc(sizeof(BASEBARINFO));

        if (lpbi == NULL)
            return (FALSE);

        SetProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0), lpbi);
    }
    return (TRUE);
    case WM_NCDESTROY:
    {
        RemoveProp(hwnd, (LPCTSTR)MAKEWORD(s_hBaseBarAtom, 0));

        if (lpbi != NULL)
        {
            if (lpbi->pszTitle != NULL)
                Mem_Free(lpbi->pszTitle);

            Mem_Free(lpbi);
        }
    }
    return (TRUE);
    case WM_NCHITTEST:
    {
        POINT pt = {LOWORD(lParam), HIWORD(lParam)};
        RECT  re;

        GetWindowRect(hwnd, &re);

        if (!PtInRect(&re, pt))
            return (HTNOWHERE);

        if (lpbi->dwAlign == CCS_LEFT)
        {
            re.left = re.right - 4;

            if (PtInRect(&re, pt))
                return (HTRIGHT);
        }
        else if (lpbi->dwAlign == CCS_RIGHT)
        {
            re.right = re.left + 4;

            if (PtInRect(&re, pt))
                return (HTLEFT);
        }
        else if (lpbi->dwAlign == CCS_BOTTOM)
        {
            re.bottom = re.top + 4;

            if (PtInRect(&re, pt))
                return (HTTOP);
        }
        else if (lpbi->dwAlign == CCS_TOP)
        {
            re.top = re.bottom - 4;

            if (PtInRect(&re, pt))
                return (HTBOTTOM);
        }
    }
    return (HTCLIENT);
    case WM_NCCALCSIZE:
    {
        if (wParam == TRUE)
        {
            NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *) lParam;

            if (lpbi->dwAlign == CCS_LEFT)
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].right  -= 4;
            }
            else if (lpbi->dwAlign == CCS_RIGHT)
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].left   += 4;
            }
            else if (lpbi->dwAlign == CCS_BOTTOM)
            {
                ncp->rgrc[0].top    += 4;
            }
            else if (lpbi->dwAlign == CCS_TOP)
            {
                ncp->rgrc[0].bottom -= 4;
            }
            else
            {
                ncp->rgrc[0].top    += 4;
                ncp->rgrc[0].right  -= 4;
                ncp->rgrc[0].left   += 4;
                ncp->rgrc[0].bottom -= 4;
            }
        }
    }
    break;
    case WM_ERASEBKGND:
    return (TRUE);
    case WM_NCPAINT:
    {
        HDC  hdc = GetWindowDC(hwnd);
        RECT rcWindow, rcClient;

        if (hdc == NULL)
            break;

        GetClientRect(hwnd, &rcClient);
        GetWindowRect(hwnd, &rcWindow);

        MapWindowPoints(NULL, hwnd, (LPPOINT)&rcWindow, 2);
        OffsetRect(&rcClient, -rcWindow.left, -rcWindow.top);
        OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
        ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

        FillRect(hdc, &rcWindow, (HBRUSH)GetSysColorBrush(COLOR_BTNFACE));
        ReleaseDC(hwnd, hdc);
    }
    return (TRUE);
    case BCM_SETCLIENTWND:
    {
        REBARBANDINFO rbBand;
        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_CHILDSIZE | RBBIM_CHILD;
        rbBand.cyIntegral = 1;
        rbBand.cyMaxChild = -1;
        rbBand.hwndChild  = (HWND)lParam;

        return (SendMessage(lpbi->hwndRebar, RB_SETBANDINFO, 0, (LPARAM)&rbBand));
    }
    case BCM_GETCLIENTWND:
    {
        REBARBANDINFO rbBand;
        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize     = sizeof(REBARBANDINFO);
        rbBand.fMask      = RBBIM_CHILD;
        SendMessage(lpbi->hwndRebar, RB_GETBANDINFO, 0, (LPARAM)&rbBand);

        return (LRESULT)((IsWindow(rbBand.hwndChild) ? rbBand.hwndChild : NULL));
    }
    case BCM_SETIMAGELIST:
    {
        REBARINFO  rbi;
        HIMAGELIST hilOld = BandCtrl_GetImageList(hwnd);

        rbi.cbSize = sizeof(REBARINFO);
        rbi.fMask  = RBIM_IMAGELIST;
        rbi.himl   = (HIMAGELIST)lParam;

        if (!SendMessage(lpbi->hwndRebar, RB_SETBARINFO, 0, (LPARAM) &rbi))
            return ((LRESULT)NULL);

        return ((LRESULT)hilOld);
    }
    case BCM_GETIMAGELIST:
    {
        REBARINFO rbi;

        rbi.cbSize = sizeof(REBARINFO);
        rbi.fMask  = RBIM_IMAGELIST;
        rbi.himl   = 0;

        if (!SendMessage(lpbi->hwndRebar, RB_GETBARINFO, 0, (LPARAM) &rbi))
            return ((LRESULT)NULL);

        return ((LRESULT)rbi.himl);
    }
    case BCM_SETTITLEIMAGE:
    {
        REBARBANDINFO rbBand;

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize = sizeof(REBARBANDINFO);
        rbBand.fMask  = RBBIM_IMAGE;
        rbBand.iImage = wParam;

        return (SendMessage(lpbi->hwndRebar, RB_SETBANDINFO, 0, (LPARAM)&rbBand));
    }
    case BCM_GETTITLEIMAGE:
    {
        REBARBANDINFO rbBand;

        ZeroMemory(&rbBand, sizeof(REBARBANDINFO));

        rbBand.cbSize = sizeof(REBARBANDINFO);
        rbBand.fMask  = RBBIM_IMAGE;
        rbBand.iImage = -1;
        SendMessage(lpbi->hwndRebar, RB_GETBANDINFO, 0, (LPARAM)&rbBand);

        return (rbBand.iImage);
    }
    case BCM_GETALIGNMENT:
    return ((LRESULT)lpbi->dwAlign);
    case BCM_SETALIGNMENT:
    {
        NMHDR nmhdr;
        DWORD dwStyle;

        if (lpbi->dwAlign == wParam)
            return (wParam);

        lpbi->dwAlign = wParam;

        dwStyle = GetWindowLong(lpbi->hwndRebar, GWL_STYLE);
        dwStyle &= ~(CCS_BOTTOM | CCS_TOP | CCS_LEFT | CCS_RIGHT);
        dwStyle |= lpbi->dwAlign;

        SetWindowLong(lpbi->hwndRebar, GWL_STYLE, dwStyle);

        SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

        nmhdr.code     = RBN_HEIGHTCHANGE;
        nmhdr.hwndFrom = hwnd;
        nmhdr.idFrom   = GetDlgCtrlID(hwnd);
        SendMessage(GetParent(hwnd), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);

        return (lpbi->dwAlign);
    }
    case BCM_SETDATA:
    {
        LPARAM lParamOld = lpbi->lParam;
        lpbi->lParam = lParam;
        return (lParamOld);
    }
    case BCM_GETDATA:
    return (lpbi->lParam);
    case BCM_SETALLOWABLEALIGNS:
    {
        DWORD dwOldAllowableAligns = lpbi->dwAllowableAligns;

        lpbi->dwAllowableAligns = lParam;

        return (dwOldAllowableAligns);
    }
    case BCM_GETALLOWABLEALIGNS:
    return (lpbi->dwAllowableAligns);
    }

    return (DefWindowProc(hwnd, uMessage, wParam, lParam));
}