Ejemplo n.º 1
0
BOOL CALLBACK NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PNHRIPWindow data;

	data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);
	switch (message)
	{
	case WM_INITDIALOG:
	    /* set text control font */
		hdc = GetDC(hWnd);
		SendMessage(hWnd, WM_SETFONT,
			(WPARAM)mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE), 0);
		ReleaseDC(hWnd, hdc);

		SetFocus(GetDlgItem(hWnd, IDOK));
	return FALSE;

	case WM_MSNH_COMMAND:
		onMSNHCommand(hWnd, wParam, lParam);
	break;

	case WM_PAINT:
	{
		int bitmap_offset;
		RECT clientrect;
		RECT textrect;
		HDC hdcBitmap;
		HANDLE OldBitmap;
		PAINTSTRUCT ps;
		HFONT OldFont;

		hdc = BeginPaint (hWnd, &ps);
		OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
		hdcBitmap = CreateCompatibleDC(hdc);
		SetBkMode (hdc, TRANSPARENT);
		GetClientRect (hWnd, &clientrect);
		textrect = clientrect;
		textrect.top += RIP_OFFSET_Y;
		textrect.left += RIP_OFFSET_X;
		textrect.right -= RIP_OFFSET_X;
		if (data->window_text)
		{
			DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
				DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
			DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
				DT_LEFT | DT_NOPREFIX);
		}
		OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpRip);
		SetBkMode (hdc, OPAQUE);
		bitmap_offset = (textrect.right - textrect.left - RIP_WIDTH) / 2;
		BitBlt (hdc, textrect.left + bitmap_offset, textrect.bottom, RIP_WIDTH,
			RIP_HEIGHT, hdcBitmap, 0, 0, SRCCOPY);
		SetBkMode (hdc, TRANSPARENT);
		if (data->rip_text)
		{
			textrect.left += RIP_GRAVE_X + bitmap_offset;
			textrect.top = textrect.bottom + RIP_GRAVE_Y;
			textrect.right = textrect.left + RIP_GRAVE_WIDTH;
			textrect.bottom = textrect.top + RIP_GRAVE_HEIGHT;
			DrawText (hdc, data->rip_text, strlen(data->rip_text), &textrect,
				DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_WORDBREAK);
		}
		SelectObject (hdcBitmap, OldBitmap);
		SelectObject (hdc, OldFont);
		DeleteDC (hdcBitmap);
		EndPaint (hWnd, &ps);
	}
	break;

	case WM_COMMAND:
		switch (LOWORD(wParam))
        {
          case IDOK:
			mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
			if( GetNHApp()->hMainWnd==hWnd )
				GetNHApp()->hMainWnd=NULL;
			DestroyWindow(hWnd);
			SetFocus(GetNHApp()->hMainWnd);
			return TRUE;
		}
	break;

	case WM_CLOSE:
	    /* if we get this here, we saved the bones so we can just force a quit */

	    mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
	    if( GetNHApp()->hMainWnd==hWnd )
		GetNHApp()->hMainWnd=NULL;
	    DestroyWindow(hWnd);
	    SetFocus(GetNHApp()->hMainWnd);
	    program_state.stopprint++;
	    return TRUE;

	case WM_DESTROY:
		if( data ) {
			if( data->window_text ) free(data->window_text);
			if( data->rip_text ) free(data->rip_text);
			if (data->rip_bmp != NULL) DeleteObject(data->rip_bmp);
			free(data);
			SetWindowLong(hWnd, GWL_USERDATA, (LONG)0);
		}
	break;

	}
	return FALSE;
}
Ejemplo n.º 2
0
INT_PTR CALLBACK
NHSplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;

    UNREFERENCED_PARAMETER(lParam);

    switch (message) {
    case WM_INITDIALOG:
        /* set text control font */
        hdc = GetDC(hWnd);
        SendMessage(hWnd, WM_SETFONT,
                    (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
                    0);
        ReleaseDC(hWnd, hdc);

        SetFocus(GetDlgItem(hWnd, IDOK));
        return FALSE;

    case WM_PAINT: {
        char VersionString[BUFSZ];
        RECT rt;
        HDC hdcBitmap;
        HANDLE OldBitmap;
        HANDLE OldFont;
        PAINTSTRUCT ps;

        hdc = BeginPaint(hWnd, &ps);
        /* Show splash graphic */

        hdcBitmap = CreateCompatibleDC(hdc);
        SetBkMode(hdc, OPAQUE);
        OldBitmap = SelectObject(hdcBitmap, GetNHApp()->bmpSplash);
        (*GetNHApp()->lpfnTransparentBlt)(hdc, SPLASH_OFFSET_X, SPLASH_OFFSET_Y,
                                  SPLASH_WIDTH, SPLASH_HEIGHT, hdcBitmap, 0,
                                  0, SPLASH_WIDTH, SPLASH_HEIGHT,
                                  TILE_BK_COLOR);

        SelectObject(hdcBitmap, OldBitmap);
        DeleteDC(hdcBitmap);

        SetBkMode(hdc, TRANSPARENT);
        /* Print version number */

        SetTextColor(hdc, RGB(0, 0, 0));
        rt.right = rt.left = SPLASH_VERSION_X;
        rt.bottom = rt.top = SPLASH_VERSION_Y;
        Sprintf(VersionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR,
                PATCHLEVEL);
        OldFont = SelectObject(hdc, version_splash_font);
        DrawText(hdc, VersionString, strlen(VersionString), &rt,
                 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
        DrawText(hdc, VersionString, strlen(VersionString), &rt,
                 DT_LEFT | DT_NOPREFIX);
        EndPaint(hWnd, &ps);
    } break;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDOK:
            mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
            if (GetNHApp()->hMainWnd == hWnd)
                GetNHApp()->hMainWnd = NULL;
            DestroyWindow(hWnd);
            SetFocus(GetNHApp()->hMainWnd);
            return TRUE;
        }
        break;
    }
    return FALSE;
}
Ejemplo n.º 3
0
INT_PTR CALLBACK
NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HWND control;
    HDC hdc;
    PNHTextWindow data;
    TCHAR title[MAX_LOADSTRING];

    data = (PNHTextWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
    switch (message) {
    case WM_INITDIALOG:
        /* set text control font */
        control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
        if (!control) {
            panic("cannot get text view window");
        }

        hdc = GetDC(control);
        SendMessage(control, WM_SETFONT,
                    (WPARAM) mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE),
                    0);
        ReleaseDC(control, hdc);

        /* subclass edit control */
        editControlWndProc =
            (WNDPROC) GetWindowLongPtr(control, GWLP_WNDPROC);
        SetWindowLongPtr(control, GWLP_WNDPROC, (LONG_PTR) NHEditHookWndProc);

        SetFocus(control);

        /* Even though the dialog has no caption, you can still set the title
           which shows on Alt-Tab */
        LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
        SetWindowText(hWnd, title);
        return FALSE;

    case WM_MSNH_COMMAND:
        onMSNHCommand(hWnd, wParam, lParam);
        break;

    case WM_SIZE: {
        RECT rt;

        GetWindowRect(hWnd, &rt);
        ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
        ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
        mswin_update_window_placement(NHW_TEXT, &rt);

        LayoutText(hWnd);
    }
    return FALSE;

    case WM_MOVE: {
        RECT rt;
        GetWindowRect(hWnd, &rt);
        ScreenToClient(GetNHApp()->hMainWnd, (LPPOINT) &rt);
        ScreenToClient(GetNHApp()->hMainWnd, ((LPPOINT) &rt) + 1);
        mswin_update_window_placement(NHW_TEXT, &rt);
    }
    return FALSE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDOK:
        case IDCANCEL:
            mswin_window_mark_dead(mswin_winid_from_handle(hWnd));
            if (GetNHApp()->hMainWnd == hWnd)
                GetNHApp()->hMainWnd = NULL;
            DestroyWindow(hWnd);
            SetFocus(GetNHApp()->hMainWnd);
            return TRUE;
        }
        break;

    case WM_CTLCOLORSTATIC: { /* sent by edit control before it is drawn */
        HDC hdcEdit = (HDC) wParam;
        HWND hwndEdit = (HWND) lParam;
        if (hwndEdit == GetDlgItem(hWnd, IDC_TEXT_CONTROL)) {
            SetBkColor(hdcEdit, text_bg_brush ? text_bg_color
                       : (COLORREF) GetSysColor(
                           DEFAULT_COLOR_BG_TEXT));
            SetTextColor(hdcEdit, text_fg_brush ? text_fg_color
                         : (COLORREF) GetSysColor(
                             DEFAULT_COLOR_FG_TEXT));
            return (INT_PTR)(text_bg_brush
                             ? text_bg_brush
                             : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT));
        }
    }
    return FALSE;

    case WM_DESTROY:
        if (data) {
            if (data->window_text)
                free(data->window_text);
            free(data);
            SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
        }
        break;
    }
    return FALSE;
}