Ejemplo n.º 1
1
/* Ôóíêöèÿ îáðàáîòêè ñîîáùåíèÿ îêíà.
 * ÀÐÃÓÌÅÍÒÛ:
 *   - äåñêðèïòîð îêíà:
 *       HWND hWnd;
 *   - íîìåð ñîîáùåíèÿ (ñì. WM_***):
 *       UINT Msg;
 *   - ïàðàìåòð ñîîáøåíèÿ ('word parameter'):
 *       WPARAM wParam;
 *   - ïàðàìåòð ñîîáøåíèÿ ('long parameter'):
 *       LPARAM lParam;
 * ÂÎÇÂÐÀÙÀÅÌÎÅ ÇÍÀ×ÅÍÈÅ:
 *   (LRESULT) - â çàâèñèìîñòè îò ñîîáùåíèÿ.
 */
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam )
{
  HDC hDC;   
  CREATESTRUCT *cs;    
  SYSTEMTIME st;
  CHAR Buf[100];
  HFONT hFnt, hOldFnt; 
 /* HPEN hPen; */
 /* HBRUSH hBrush, hOldBr;*/
  static INT xx[100], yy[100];
  static BITMAP bm;
  static HBITMAP hBm, hBmLogo;
  static HDC hMemDC, hMemDCLogo;
  static INT w, h;
  

  switch (Msg)
  {
  case WM_CREATE:
    cs = (CREATESTRUCT *)lParam;
    SetTimer(hWnd, 111, 50, NULL);     

    hBmLogo = LoadImage(NULL, "clock.bmp", IMAGE_BITMAP, w, h, LR_LOADFROMFILE);  
    GetObject(hBmLogo, sizeof(bm), &bm);   

    /* ñîçäàåì êîíòåêñò â ïàìÿòè */
    hDC = GetDC(hWnd);
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDCLogo, hBmLogo);     
    return 0;

  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);

    /* ñîçäàåì êàðòèíêó ðàçìåðîì ñ îêíî */
    if (hBm != NULL)
      DeleteObject(hBm);

    hDC = GetDC(hWnd);                                                                            
    hBm = CreateCompatibleBitmap(hDC, w, h); 
    
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDC, hBm);
    SendMessage(hWnd, WM_TIMER, 111, 0);
    return 0;

  case WM_TIMER:
    /* Clear Background */
    SelectObject(hMemDC, GetStockObject(NULL_PEN));
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(0, 0, 0));   
    Rectangle(hMemDC, 0, 0, w, h);

    StretchBlt(hMemDC, w / 2 - bm.bmWidth / 2, h / 2 - bm.bmHeight / 2, bm.bmWidth, bm.bmHeight,
      hMemDCLogo, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);    

    GetLocalTime(&st); 
    DrawHand(hMemDC, w / 2, h / 2, 160, 5, (st.wSecond * 6 + 180) * PI / 180);
    DrawHand(hMemDC, w / 2, h / 2, 130, 10, (st.wMinute * 6 + 180) * PI / 180);
    DrawHand(hMemDC, w / 2, h / 2, 130, 10, (st.wHour % 12 * 30 + 180) * PI / 180);
    SelectObject(hMemDC, GetStockObject(NULL_PEN));
    SelectObject(hMemDC, GetStockObject(NULL_BRUSH));

    hFnt = CreateFont(h / 8 , 0, 0, 0, FW_BOLD, FALSE, FALSE,
      FALSE, RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS,
      CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
      VARIABLE_PITCH | FF_ROMAN, "");     
   
    hOldFnt = SelectObject(hMemDC, hFnt);
    GetLocalTime(&st);
    SetTextColor(hMemDC, RGB(255, 255, 255));
    SetBkColor(hMemDC, RGB(12, 24, 200));
    SetBkMode(hMemDC, TRANSPARENT);
    TextOut(hMemDC, w / 4, h / 6, Buf,
      sprintf(Buf, "%02d:%02d:%02d (%02d.%02d.%d)",
        st.wHour, st.wMinute, st.wSecond,
        st.wDay, st.wMonth, st.wYear)); 

    DeleteObject(hFnt);  

    InvalidateRect(hWnd, NULL, TRUE);
    return 0;      

  case WM_ERASEBKGND:
    BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
    return 0;

  case WM_DESTROY:
    DeleteDC(hMemDC);
    DeleteObject(hBm);
    DeleteDC(hMemDCLogo);
    DeleteObject(hBmLogo);
    KillTimer(hWnd, 111);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
Ejemplo n.º 2
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HWND hList;
	static HFONT hFont;
	static DWORD dwSplitLine;
	switch (msg)
	{
	case WM_CREATE:
		InitCommonControls();
		hFont = CreateFont(26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS ゴシック"));
		hList = CreateWindowEx(0, TEXT("LISTBOX"), 0, WS_VISIBLE | WS_CHILD | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_EXTENDEDSEL | LBS_MULTIPLESEL, 0, 0, 0, 0, hWnd, (HMENU)IDC_LIST, ((LPCREATESTRUCT)lParam)->hInstance, 0);
		SendMessage(hList, WM_SETFONT, (WPARAM)hFont, 0);
		EditDefProc = (WNDPROC)SetWindowLong(hList, GWL_WNDPROC, (LONG)ListProc);
		{
			int n;
			LPTSTR* argv = CommandLineToArgvW(GetCommandLine(), &n);
			for (int i = 1; i<n; i++)
			{
				CalcSha1(hList, argv[i]);
				const DWORD dwTempWidth = GetStringWidth(hList, PathFindFileName(argv[i]));
				if (dwTempWidth>dwSplitLine)dwSplitLine = dwTempWidth;
			}
			if (argv) GlobalFree(argv);
			const DWORD dwLastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
			SendMessage(hList, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, dwLastItem - 1));
		}
		DragAcceptFiles(hWnd, TRUE);
		break;
	case WM_ERASEBKGND:
		return 1;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_COPYTOCLIPBOARD:
		{
			const int nSelItems = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
			if (nSelItems > 0)
			{
				int* pBuffer = (int*)GlobalAlloc(0, sizeof(int) * nSelItems);
				SendMessage(hList, LB_GETSELITEMS, nSelItems, (LPARAM)pBuffer);
				INT nLen = 0;
				for (int i = 0; i < nSelItems; i++)
				{
					DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, pBuffer[i], 0);
					nLen += lstrlen(pData->szFilePath);
					nLen += lstrlen(pData->szHashValue);
					nLen += 3;
				}
				HGLOBAL hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, sizeof(TCHAR)*(nLen + 1));
				LPTSTR lpszBuflpszBuf = (LPTSTR)GlobalLock(hMem);
				lpszBuflpszBuf[0] = 0;
				for (int i = 0; i < nSelItems; i++)
				{
					DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, pBuffer[i], 0);
					lstrcat(lpszBuflpszBuf, pData->szFilePath);
					lstrcat(lpszBuflpszBuf, TEXT("\t"));
					lstrcat(lpszBuflpszBuf, pData->szHashValue);
					lstrcat(lpszBuflpszBuf, TEXT("\r\n"));
				}
				lpszBuflpszBuf[nLen] = 0;
				GlobalFree(pBuffer);
				GlobalUnlock(hMem);
				OpenClipboard(NULL);
				EmptyClipboard();
				SetClipboardData(CF_UNICODETEXT, hMem);
				CloseClipboard();
			}
		}
		break;
		case ID_SELECTALL:
			SendMessage(hList, LB_SETSEL, 1, -1);
			break;
		case ID_DELETE:
		{
			const int nSelItems = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
			if (nSelItems > 0)
			{
				int* pBuffer = (int*)GlobalAlloc(0, sizeof(int) * nSelItems);
				SendMessage(hList, LB_GETSELITEMS, nSelItems, (LPARAM)pBuffer);
				for (int i = nSelItems - 1; i >= 0; i--)
				{
					DeleteItem(hList, pBuffer[i]);
				}
				GlobalFree(pBuffer);
				dwSplitLine = 0;
				const int nCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
				for (int i = 0; i < nCount; i++)
				{
					const DATA* pData = (const DATA*)SendMessage(hList, LB_GETITEMDATA, i, 0);
					const DWORD dwTemp = GetStringWidth(hList, PathFindFileName(pData->szFilePath));
					if (dwTemp>dwSplitLine)dwSplitLine = dwTemp;
				}
			}
		}
		break;
		}
		break;
	case WM_MEASUREITEM:
		((LPMEASUREITEMSTRUCT)lParam)->itemHeight = 32;
		return 0;
	case WM_SIZE:
		MoveWindow(hList, 0, 0, LOWORD(lParam), HIWORD(lParam), 0);
		break;
	case WM_EXITTHREAD:
	{
		DATA* pData = (DATA*)lParam;
		WaitForSingleObject(pData->hThread, INFINITE);
		CloseHandle(pData->hThread);
		pData->hThread = 0;
		InvalidateRect(hList, 0, 0);
	}
	break;
	case WM_DRAWITEM:
		if ((UINT)wParam == IDC_LIST)
		{
			LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
			if (lpdis->itemID == -1)
			{
				if (!SendMessage(hList, LB_GETCOUNT, 0, 0))
				{
					RECT rect;
					GetClientRect(hList, &rect);
					HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
					FillRect(lpdis->hDC, &rect, hBrush);
					DeleteObject(hBrush);
					SetTextColor(lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
					DrawText(lpdis->hDC, TEXT("ここにファイルをドラッグ"), -1, &rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_CENTER);
				}
				break;
			}
			DATA* pData = (DATA*)SendMessage(hList, LB_GETITEMDATA, lpdis->itemID, 0);
			if ((lpdis->itemState)&(ODS_SELECTED))
			{
				SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT));
				SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			}
			else
			{
				SetBkColor(lpdis->hDC, GetSysColor(COLOR_WINDOW));
				SetTextColor(lpdis->hDC, GetSysColor(COLOR_WINDOWTEXT));
			}
			RECT rect1 = lpdis->rcItem;
			rect1.right = dwSplitLine + 16;
			const LPCTSTR lpszFileName = PathFindFileName(pData->szFilePath);
			SetTextAlign(lpdis->hDC, TA_RIGHT);
			ExtTextOut(lpdis->hDC, rect1.right, rect1.top + 4, ETO_OPAQUE, &rect1, lpszFileName, lstrlen(lpszFileName), 0);
			RECT rect2 = lpdis->rcItem;
			rect2.left = dwSplitLine + 16;
			SetTextAlign(lpdis->hDC, TA_LEFT);
			ExtTextOut(lpdis->hDC, rect2.left + 32, rect2.top + 4, ETO_OPAQUE, &rect2, pData->szHashValue, lstrlen(pData->szHashValue), 0);
		}
		break;
	case WM_DROPFILES:
	{
		HDROP hDrop = (HDROP)wParam;
		TCHAR szFileName[MAX_PATH];
		UINT i;
		const DWORD dwFastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
		SendMessage(hList, LB_SETSEL, 0, -1);
		const UINT nFiles = DragQueryFile((HDROP)hDrop, 0xFFFFFFFF, NULL, 0);
		for (i = 0; i<nFiles; i++)
		{
			DragQueryFile(hDrop, i, szFileName, sizeof(szFileName));
			CalcSha1(hList, szFileName);
			const DWORD dwTempWidth = GetStringWidth(hList, PathFindFileName(szFileName));
			if (dwTempWidth>dwSplitLine)dwSplitLine = dwTempWidth;
		}
		DragFinish(hDrop);
		const DWORD dwLastItem = SendMessage(hList, LB_GETCOUNT, 0, 0);
		SendMessage(hList, LB_SELITEMRANGE, TRUE, MAKELPARAM(dwFastItem, dwLastItem - 1));
		SetForegroundWindow(hWnd);
	}
	break;
	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;
	case WM_DESTROY:
	{
		const int nCount = SendMessage(hList, LB_GETCOUNT, 0, 0);
		for (int i = nCount - 1; i >= 0; i--)
		{
			DeleteItem(hList, i);
		}
	}
	DeleteObject(hFont);
	PostQuitMessage(0);
	break;
	default:
		return DefDlgProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 3
0
void Picker_HandleDrawItem(HWND hWnd, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	struct PickerInfo *pPickerInfo;
	HDC         hDC = lpDrawItemStruct->hDC;
	RECT        rcItem = lpDrawItemStruct->rcItem;
	UINT        uiFlags = ILD_TRANSPARENT;
	HIMAGELIST  hImageList;
	int         nItem = lpDrawItemStruct->itemID;
	COLORREF    clrTextSave = 0;
	COLORREF    clrBkSave = 0;
	COLORREF    clrImage = GetSysColor(COLOR_WINDOW);
	static TCHAR szBuff[MAX_PATH];
	BOOL        bFocus = (GetFocus() == hWnd);
	LPCTSTR     pszText;
	UINT        nStateImageMask = 0;
	BOOL        bSelected = 0;
	LV_COLUMN   lvc;
	LV_ITEM     lvi;
	RECT        rcAllLabels;
	RECT        rcLabel;
	RECT        rcIcon;
	int         offset = 0;
	SIZE        size;
	int         i = 0, j = 0;
	int         nColumn = 0;
	int         nColumnMax = 0;
	int         *order;
	BOOL        bDrawAsChild = 0;
	int indent_space = 0;
	BOOL		bColorChild = FALSE;
	BOOL		bParentFound = FALSE;
	int		nParent = 0;
	HBITMAP		hBackground = GetBackgroundBitmap();
	MYBITMAPINFO *pbmDesc = GetBackgroundInfo();
	BOOL res = 0;

	pPickerInfo = GetPickerInfo(hWnd);

	order = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*order));
	if (!order)
		return;
	nColumnMax = Picker_GetNumColumns(hWnd);

	if (GetUseOldControl())
	{
		pPickerInfo->pCallbacks->pfnGetColumnOrder(order);
	}
	else
	{
		/* Get the Column Order and save it */
		res = ListView_GetColumnOrderArray(hWnd, nColumnMax, order);

		/* Disallow moving column 0 */
		if (order[0] != 0)
		{
			for (i = 0; i < nColumnMax; i++)
			{
				if (order[i] == 0)
				{
					order[i] = order[0];
					order[0] = 0;
				}
			}
			res = ListView_SetColumnOrderArray(hWnd, nColumnMax, order);
		}
	}

	/* Labels are offset by a certain amount */
	/* This offset is related to the width of a space character */
	GetTextExtentPoint32(hDC, TEXT(" "), 1, &size);
	offset = size.cx;

	lvi.mask	   = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM;
	lvi.iItem	   = nItem;
	lvi.iSubItem   = order[0];
	lvi.pszText	   = szBuff;
	lvi.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]);
	lvi.stateMask  = 0xFFFF;	   /* get all state flags */
	res = ListView_GetItem(hWnd, &lvi);

	bSelected = ((lvi.state & LVIS_DROPHILITED) || ( (lvi.state & LVIS_SELECTED)
		&& ((bFocus) || (GetWindowLong(hWnd, GWL_STYLE) & LVS_SHOWSELALWAYS))));

	/* figure out if we indent and draw grayed */
	if (pPickerInfo->pCallbacks->pfnFindItemParent)
		nParent = pPickerInfo->pCallbacks->pfnFindItemParent(hWnd, lvi.lParam);
	else
		nParent = -1;
	bDrawAsChild = (pPickerInfo->pCallbacks->pfnGetViewMode() == VIEW_GROUPED && (nParent >= 0));

	/* only indent if parent is also in this view */
	if ((nParent >= 0) && bDrawAsChild)
	{
		for (i = 0; i < ListView_GetItemCount(hWnd); i++)
		{
			lvi.mask = LVIF_PARAM;
			lvi.iItem = i;
			res = ListView_GetItem(hWnd, &lvi);

			if (lvi.lParam == nParent)
			{
				bParentFound = TRUE;
				break;
			}
		}
	}

	if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren())
	{
		if (!bParentFound && bDrawAsChild)
		{
			/*Reset it, as no Parent is there*/
			bDrawAsChild = FALSE;
			bColorChild = TRUE;
		}
		else
		{
			nParent = -1;
			bParentFound = FALSE;
		}
	}

	res = ListView_GetItemRect_Modified(hWnd, nItem, &rcAllLabels, LVIR_BOUNDS);
	res = ListView_GetItemRect_Modified(hWnd, nItem, &rcLabel, LVIR_LABEL);

	rcAllLabels.left = rcLabel.left;

	if (hBackground != NULL)
	{
		RECT		rcClient;
		HRGN		rgnBitmap;
		RECT		rcTmpBmp = rcItem;
		RECT		rcFirstItem;
		HPALETTE	hPAL;
		HDC 		htempDC;
		HBITMAP 	oldBitmap;

		htempDC = CreateCompatibleDC(hDC);

		oldBitmap = (HBITMAP)SelectObject(htempDC, hBackground);

		GetClientRect(hWnd, &rcClient);
		rcTmpBmp.right = rcClient.right;
		/* We also need to check whether it is the last item
           The update region has to be extended to the bottom if it is */
		if (nItem == ListView_GetItemCount(hWnd) - 1)
			rcTmpBmp.bottom = rcClient.bottom;

		rgnBitmap = CreateRectRgnIndirect(&rcTmpBmp);
		SelectClipRgn(hDC, rgnBitmap);
		DeleteBitmap(rgnBitmap);

		hPAL = GetBackgroundPalette();
		if (hPAL == NULL)
			hPAL = CreateHalftonePalette(hDC);

		if (GetDeviceCaps(htempDC, RASTERCAPS) & RC_PALETTE && hPAL != NULL)
		{
			SelectPalette(htempDC, hPAL, FALSE);
			RealizePalette(htempDC);
		}

		res = ListView_GetItemRect_Modified(hWnd, 0, &rcFirstItem, LVIR_BOUNDS);

		for (i = rcFirstItem.left; i < rcClient.right; i += pbmDesc->bmWidth)
			for (j = rcFirstItem.top; j < rcClient.bottom; j +=  pbmDesc->bmHeight)
				BitBlt(hDC, i, j, pbmDesc->bmWidth, pbmDesc->bmHeight, htempDC, 0, 0, SRCCOPY);

		SelectObject(htempDC, oldBitmap);
		DeleteDC(htempDC);

		if (GetBackgroundPalette() == NULL)
		{
			DeletePalette(hPAL);
			hPAL = NULL;
		}
	}

	indent_space = 0;

	if (bDrawAsChild)
	{
		RECT rect;

		res = ListView_GetItemRect_Modified(hWnd, nItem, &rect, LVIR_ICON);

		/* indent width of icon + the space between the icon and text
         * so left of clone icon starts at text of parent
         */
		indent_space = rect.right - rect.left + offset;
	}

	rcAllLabels.left += indent_space;

	if (bSelected)
	{
		HBRUSH hBrush;
		HBRUSH hOldBrush;

		if (bFocus)
		{
			clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
			clrBkSave	= SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
			hBrush		= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
		}
		else
		{
			clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT));
			clrBkSave	= SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
			hBrush		= CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
		}

		hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
		FillRect(hDC, &rcAllLabels, hBrush);
		SelectObject(hDC, hOldBrush);
		DeleteBrush(hBrush);
	}
	else
	{
		if (hBackground == NULL)
		{
			HBRUSH hBrush;

			hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			FillRect(hDC, &rcAllLabels, hBrush);
			DeleteBrush(hBrush);
		}

		if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren())
		{
			if (bDrawAsChild || bColorChild)
				clrTextSave = SetTextColor(hDC, GetListCloneColor());
			else
				clrTextSave = SetTextColor(hDC, GetListFontColor());
		}
		else
		{
			if (bDrawAsChild)
				clrTextSave = SetTextColor(hDC, GetListCloneColor());
			else
				clrTextSave = SetTextColor(hDC, GetListFontColor());
		}

		clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_WINDOW));
	}


	if (lvi.state & LVIS_CUT)
	{
		clrImage = GetSysColor(COLOR_WINDOW);
		uiFlags |= ILD_BLEND50;
	}
	else if (bSelected)
	{
		if (bFocus)
			clrImage = GetSysColor(COLOR_HIGHLIGHT);
		else
			clrImage = GetSysColor(COLOR_BTNFACE);

		uiFlags |= ILD_BLEND50;
	}

	nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;

	if (nStateImageMask)
	{
		int nImage = (nStateImageMask >> 12) - 1;
		hImageList = ListView_GetImageList(hWnd, LVSIL_STATE);
		if (hImageList)
			ImageList_Draw(hImageList, nImage, hDC, rcItem.left, rcItem.top, ILD_TRANSPARENT);
	}

	res = ListView_GetItemRect_Modified(hWnd, nItem, &rcIcon, LVIR_ICON);

	rcIcon.left += indent_space;

	res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL);

	hImageList = ListView_GetImageList(hWnd, LVSIL_SMALL);
	if (hImageList)
	{
		UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK;
		if (rcIcon.left + 16 + indent_space < rcItem.right)
		{
			ImageList_DrawEx(hImageList, lvi.iImage, hDC, rcIcon.left, rcIcon.top, 16, 16,
				GetSysColor(COLOR_WINDOW), clrImage, uiFlags | nOvlImageMask);
		}
	}

	res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL);

	pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2*offset + indent_space);

	rcLabel = rcItem;
	rcLabel.left  += offset + indent_space;
	rcLabel.right -= offset;

	DrawText(hDC, pszText, -1, &rcLabel, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);

	for (nColumn = 1; nColumn < nColumnMax; nColumn++)
	{
		int 	nRetLen;
		UINT	nJustify;
		LV_ITEM lvItem;

		lvc.mask = LVCF_FMT | LVCF_WIDTH;
		res = ListView_GetColumn(hWnd, order[nColumn], &lvc);

		lvItem.mask 	  = LVIF_TEXT;
		lvItem.iItem	  = nItem;
		lvItem.iSubItem   = order[nColumn];
		lvItem.pszText	  = szBuff;
		lvItem.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]);

		if (ListView_GetItem(hWnd, &lvItem) == FALSE)
			continue;

		rcItem.left   = rcItem.right;
		rcItem.right += lvc.cx;

		nRetLen = _tcslen(szBuff);
		if (nRetLen == 0)
			continue;

		pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2 * offset);

		nJustify = DT_LEFT;

		if (pszText == szBuff)
		{
			switch (lvc.fmt & LVCFMT_JUSTIFYMASK)
			{
			case LVCFMT_RIGHT:
				nJustify = DT_RIGHT;
				break;

			case LVCFMT_CENTER:
				nJustify = DT_CENTER;
				break;

			default:
				break;
			}
		}

		rcLabel = rcItem;
		rcLabel.left  += offset;
		rcLabel.right -= offset;
		DrawText(hDC, pszText, -1, &rcLabel,
				 nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
	}

	if (lvi.state & LVIS_FOCUSED && bFocus)
		DrawFocusRect(hDC, &rcAllLabels);

	SetTextColor(hDC, clrTextSave);
	SetBkColor(hDC, clrBkSave);
	free(order);
	res++;
}
LRESULT CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   static SQLHENV henv;
   static SQLHDBC hdbc;
   static SQLHSTMT hstmt;
   static int ifconnect=0;
   static SQLCHAR server[32];
   static char Content[10240] ;
   static RECT rect;
   static PAINTSTRUCT ps;
   static HBRUSH hbrush;	
   static HDC hDC ;
	static RedrawFlag = 0;
	LPDRAWITEMSTRUCT pdis;
	//~ char Content2[10240] ;
	SQLCHAR sqlstr[1024];	
	SQLRETURN retcode;
 
	//~ SQLHENV env;
	char dsn[256];
	char desc[256];
	SQLSMALLINT dsn_ret;
	SQLSMALLINT desc_ret;
	SQLUSMALLINT direction;
	SQLRETURN ret;
	HWND hEditTN = GetDlgItem(hwndDlg, IDC_EDIT1);
	HWND hEdit = GetDlgItem(hwndDlg, IDC_EDIT2);
	HWND hCBox = GetDlgItem(hwndDlg,IDC_COMBO1);
	HWND hBTN1 = GetDlgItem(hwndDlg,IDC_BUTTON1);
	int curSel;
	char szTable[256]; // receives name of item to delete. 
	LPDRAWITEMSTRUCT dItem;
	char text[20];
	int len;
	SIZE sz;

	GetWindowRect(hBTN1,&rect);
	
	switch (uMsg)
	{

	case WM_INITDIALOG:// WM_INITDIALOG message is sent before dialog is displayed
		{
		   // Allocate environment handle
		   retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
		   // Set the ODBC version environment attribute
		   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
			  retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
		   }
		   else {
					MessageBoxPrintf("Prompt","fail to SQLAllocHandle SQL_HANDLE_ENV\n");
					return FALSE;
			}
			
		  direction = SQL_FETCH_FIRST;
		  while(SQL_SUCCEEDED(ret = SQLDataSources(henv, direction,
							   dsn, sizeof(dsn), &dsn_ret,
							   desc, sizeof(desc), &desc_ret))) 
		  {
			direction = SQL_FETCH_NEXT;
			//MessageBoxPrintf("DSN","%s\n",dsn);
			ComboBox_InsertString(hCBox,0,dsn);								   
			if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
		  }
			
			return TRUE;
		}
		break;
	case WM_COMMAND://
		{
			switch (LOWORD(wParam)) 
            { 
                // Process the accelerator and menu commands. 
 
                case ID_ACCELERATOR1: 
				//~ MessageBoxPrintf("hi","hello");
				//~ GetModuleHandle()
				SendMessage(hEdit, EM_SETSEL,(WPARAM)0,(LPARAM) sizeof(Content)/sizeof(char));
			return TRUE;
			}
			
			switch(wParam)
			{
				case IDC_BUTTON1:
				{
					//disconnect
					if (ifconnect) {
						retcode = SQLDisconnect(hdbc);	
					   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
							SetWindowText(GetDlgItem(hwndDlg, IDC_BUTTON1), (LPCTSTR )"Connect");				   
							//~ MessageBoxPrintf("Prompt","Disconnected from %s!\n",server);
							ifconnect = 0;
						InvalidateRect(GetDlgItem(hwndDlg, IDC_BUTTON1),NULL, TRUE);  
						UpdateWindow(GetDlgItem(hwndDlg, IDC_BUTTON1));						   
							return 0;
					   }
					   //~ else
					   //~ {
							//~ MessageBoxPrintf("Prompt","Not Connect yet!\n");						
						//~ }
					}

					  // Allocate connection handle
						 retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
					  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
							 // Set login timeout to 5 seconds					  
							SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0);	
					  }
					  else{
							SQLFreeHandle(SQL_HANDLE_DBC, hdbc);  
							SQLFreeHandle(SQL_HANDLE_ENV, henv);								
							return FALSE;					  
					  }

					// Connect to data source
						if(!ComboBox_GetTextLength(hCBox)){
							MessageBoxPrintf("ERROR","Please Select an Item!");
							return FALSE;
						}
						curSel=ComboBox_GetCurSel(hCBox);
						ComboBox_GetLBText(hCBox,curSel,server);
						retcode = SQLConnect(
						hdbc
						, (SQLCHAR*) server
						, SQL_NTS
						, (SQLCHAR*) NULL
						, 0
						, NULL
						, 0);
					  
					if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
						ifconnect=1;
						SetWindowText(GetDlgItem(hwndDlg, IDC_BUTTON1), (LPCTSTR )"Connected");
						RedrawFlag=1;
						//~ SendMessage(hBTN1, WM_CTLCOLORBTN, (WPARAM)GetWindowDC(hBTN1), (LPARAM)hBTN1);
						//~ SendDlgItemMessage(hwndDlg,IDC_BUTTON1
						//~ ,WM_CTLCOLORBTN,(WPARAM)GetWindowDC(hBTN1), (LPARAM)hBTN1);
						InvalidateRect(GetDlgItem(hwndDlg, IDC_BUTTON1),NULL, TRUE);  
						UpdateWindow(GetDlgItem(hwndDlg, IDC_BUTTON1));
						//~ InvalidateRect(hwndDlg,NULL,TRUE);
						//~ MessageBoxPrintf("Prompt","Connected to %s!\n" ,server);							
					}
					else {
						MessageBoxPrintf("Prompt","Fail to Connect to %s!\n",server);	
						ShowDBStmtError(hwndDlg,hdbc);								
					}
				}
				break;
				
				case IDC_BUTTON3:
				{
					//~ MessageBoxPrintf("INFO","length:%d\n",Edit_GetTextLength(hEdit));
					if(!Edit_GetTextLength(hEditTN)){
						MessageBoxPrintf("Error","[SKM.]TABNAME");
						return FALSE;
					}
					
					ZeroMemory(Content,sizeof(Content)/sizeof(char));
					SetDlgItemText(hwndDlg,IDC_EDIT2,Content);										
					if (!ifconnect) {
						MessageBoxPrintf("Prompt","Not Connect yet!\n");						
						return 0;
					}
					//初始化语句句柄
					retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
					//SQL_NTS telling the function the previous parameter is Null-Terminated String, 
					//please alculate the string length for me
                    if (!GetDlgItemText(hwndDlg, IDC_EDIT1, szTable, sizeof(szTable)/sizeof(SQLCHAR))) 
					{
						*szTable=0;
						MessageBoxPrintf("","%s\n",sqlstr);
					}
					
					// 判断表是否存在
					wsprintf(sqlstr,"select count(0) from syscat.columns where tabname = upper('%s')",szTable);
					retcode = SQLPrepare(hstmt,(SQLCHAR*)sqlstr,SQL_NTS);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					retcode =SQLExecute(hstmt);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					while ( SQLFetch(hstmt) != SQL_NO_DATA_FOUND ){
						SQLINTEGER id=0;
						SQLGetData(hstmt,1,SQL_C_ULONG,&id,sizeof(SQLINTEGER),(SQLINTEGER*)NULL);
						if(0==id){
						MessageBoxPrintf("ERROR","TABLE <%s> does not exists!",szTable);
							return FALSE;
						}
					}
					SQLFreeStmt(hstmt,SQL_CLOSE);

					// do the job
					wsprintf(sqlstr,"select COLNAME from syscat.columns where tabname = upper('%s') ORDER BY COLNO ASC",szTable);
					retcode = SQLPrepare(hstmt,(SQLCHAR*)sqlstr,SQL_NTS);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					retcode =SQLExecute(hstmt);
					CHECKDBSTMTERROR(hwndDlg,retcode,hstmt);
					while ( SQLFetch(hstmt) != SQL_NO_DATA_FOUND ){
						//~ SQLINTEGER id=0;
						char name[32];
						ZeroMemory(name,sizeof(name)/sizeof(char));
						//~ SQLGetData(hstmt,1,SQL_C_ULONG,&id,sizeof(SQLINTEGER),(SQLINTEGER*)NULL);
						SQLGetData(hstmt,1,SQL_C_CHAR,name,sizeof(name)/sizeof(SQLCHAR),(SQLINTEGER*)NULL);
						//~ MessageBoxPrintf("Result","%s",name);
						strncat(Content,name,32);
						strncat(Content,"\r\n,",32);
					}
					*(Content+strlen(Content)-1)=0;
					//~ strncpy(Content2,Content,strlen(Content)-2);
					SetDlgItemText(hwndDlg,IDC_EDIT2,Content);
					//~ SendMessage(hEdit, EM_LINESCROLL, 0, 80);//WS_VSCROLL
					SQLFreeStmt(hstmt,SQL_CLOSE);
				}				
				default:
					break;
			}
			return TRUE;
		}
		break;
		
	case WM_CTLCOLORBTN:
			//~ hDC = BeginPaint((HWND)wParam, &ps);
			//~ FillRect(hDC, &rect, hbrush);
			//~ EndPaint((HWND)wParam, &ps);		
			//~ if(RedrawFlag){
				//~ hbrush = CreateSolidBrush(RGB(0,255,0));			
				//~ SetTextColor((HDC)wParam,RGB(0,0,0));						
				//~ SetBkColor((HDC)wParam,RGB(0,255,0));
			//~ return (long)hbrush ;
			//~ }
			//~ else 
			//~ {
				//~ SetTextColor((HDC)wParam,RGB(255,0,0));	
				//~ SetBkColor((HDC)wParam,RGB(0,0,0));		
				//~ SetBkMode((HDC)wParam, TRANSPARENT);
				//~ return (long)hbrush ;
			//~ }
	break;
	
	case WM_CLOSE://Massage for terminate/exit (may close button clicked on title bar)
		{
			//Close dialog
			SQLFreeStmt(hstmt,SQL_CLOSE);	
			SQLDisconnect(hdbc);	
			SQLFreeHandle(SQL_HANDLE_DBC, hdbc);  
			SQLFreeHandle(SQL_HANDLE_ENV, henv);					
			//~ EndDialog(hwndDlg,0);
			DestroyWindow(hwndDlg);			
			break;
		}
	case WM_DESTROY:
		{
			PostQuitMessage(0); 
			return TRUE;
		}
	case WM_CTLCOLORDLG: //set its text and background colors using the specified display device context handle.
		{
			break;			
		}
	case WM_PAINT:
		{
			if (RedrawFlag == 1){
				hbrush = CreateSolidBrush(RGB(0,255,0));
				hDC = BeginPaint(hBTN1, &ps);
				FillRect(hDC, &rect, hbrush);
				EndPaint(hBTN1, &ps);
				return (LONG)hbrush;
			}
			break;	
		}
	case WM_DRAWITEM:
	{
				dItem = (DRAWITEMSTRUCT*)lParam;
				if (ifconnect){
				SetBkColor(dItem->hDC, RGB(0,255,0));				
					}
					else
					{
				SetBkColor(dItem->hDC, RGB(255,0,0));						
					}
                //~ SetTextColor(dItem->hDC, RGB(0,0,0xFF));
				memset(text, '\0', 20);

				GetWindowText(dItem->hwndItem, text, 20);
				len=lstrlen(text);

				GetTextExtentPoint32(dItem->hDC, text, len, &sz);

				ExtTextOut( dItem->hDC
							, ((dItem->rcItem.right - dItem->rcItem.left) / 2) + dItem->rcItem.left - (sz.cx / 2)
							, ((dItem->rcItem.bottom - dItem->rcItem.top) / 2) + dItem->rcItem.top - (sz.cy / 2)
							, ETO_OPAQUE | ETO_CLIPPED, &dItem->rcItem, text, len, NULL);

				DrawEdge( dItem->hDC, &dItem->rcItem
						, (dItem->itemState & ODS_SELECTED ? BDR_SUNKENOUTER : BDR_RAISEDOUTER), BF_RECT);
                return DefWindowProc(hwndDlg, uMsg, wParam, lParam);
break;			
		
	}
	case WM_CTLCOLORSTATIC: //可以控制静态控件的颜色
		{
			break;			
		}
	default:
		break;			
	}
	return FALSE;
}
Ejemplo n.º 5
0
BOOL CALLBACK AutoMap_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
   switch (msg)
      {
      case WM_INITDIALOG:
         AutoMap_OnInitDialog (hDlg);
         break;

      case WM_CTLCOLORSTATIC:
         if ((HWND)lp == GetDlgItem (hDlg, IDC_CHUNK_SIZE))
            {
            if (IsWindowEnabled ((HWND)lp))
               {
               static HBRUSH hbrStatic = CreateSolidBrush (GetSysColor (COLOR_WINDOW));
               SetTextColor ((HDC)wp, GetSysColor (COLOR_WINDOWTEXT));
               SetBkColor ((HDC)wp, GetSysColor (COLOR_WINDOW));
               return (BOOL)hbrStatic;
               }
            }
         break;

      case WM_COMMAND:
         switch (LOWORD(wp))
            {
            case IDHELP:
               AutoMap_DlgProc (hDlg, WM_HELP, 0, 0);
               break;

            case IDOK:
               EndDialog(hDlg, IDOK);
               break;

            case IDCANCEL:
               EndDialog(hDlg, IDCANCEL);
               break;

				case IDC_ADD:
					AutoMap_OnAdd(hDlg);
					break;

				case IDC_CHANGE:
					AutoMap_OnEdit(hDlg);
					break;

				case IDC_REMOVE:
					AutoMap_OnRemove(hDlg);
					break;
            }
         break;

      case WM_NOTIFY:
         switch (((LPNMHDR)lp)->code)
         	{
            case FLN_ITEMSELECT:
               AutoMap_OnSelect (hDlg);
               break;

            case FLN_LDBLCLICK:
               if (IsWindowEnabled (GetDlgItem (hDlg, IDC_EDIT)))
                  AutoMap_OnEdit (hDlg);
               break;
            }
         break;

      case WM_HELP:
         WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_ADVANCED_AUTOMAP);
         break;
      }

   return FALSE;
}
Ejemplo n.º 6
0
static LRESULT CALLBACK TitleWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    TitleData* data = (TitleData*)GetWindowLong(hWnd, GWL_USERDATA);
    switch (msg)
    {

#ifdef SDK_REGISTRATION

    case WM_TIMER:
        {
            ScrollTextData* scroll = data->scrollText;
            switch (wp) 
            {
            case SCROLL_TIMER:
                data->bRepaint = TRUE;
                scroll->offset++;
                if (scroll->offset >= ((scroll->font.lfHeight * 
                    scroll->lineCount) + SCROLL_LINE_SPACE * (
                    scroll->lineCount + 1)))
                {
                    scroll->offset = 0;
                    scroll->bFirstLoop = FALSE;
                }
                if (scroll->offset == SCROLL_INIT_OFFSET && scroll->bOneTime)
                {
                    TitleStopScroller(GetParent(hWnd));
                }
                else
                {
                    InvalidateRect(hWnd, NULL, FALSE);
                }
                break;

            case SCROLL_DELAY_TIMER:
                KillTimer(hWnd, SCROLL_DELAY_TIMER);
                SetTimer(hWnd, SCROLL_TIMER, SCROLL_TIMER_PERIOD, NULL);
                ShowWindow(GetDlgItem(GetParent(hWnd),IDC_PRODUCT_KEY),SW_HIDE);
                scroll->bScrolling = TRUE;
                scroll->bFirstLoop = TRUE;
                scroll->offset = SCROLL_INIT_OFFSET;
                data->bRepaint = TRUE;
                InvalidateRect(hWnd, NULL, FALSE);
                break;

            default:
                // Forward the message to the default window proc
                return CallWindowProc(data->superProc, hWnd, msg, wp, lp);
            }
        }
        return 0;

#endif // SDK_REGISTRATION

    case WM_PAINT:
        if (data->hBitmap)
        {
            RECT rc;
            if (GetUpdateRect(hWnd, &rc, FALSE)) 
            {
                PAINTSTRUCT paint;
                HDC dc = BeginPaint(hWnd, &paint);
                if (dc) 
                {
                    int w = RECT_Width(&rc);
                    int h = RECT_Height(&rc);
                    if (!data->hOffScreen)
                    {
                        data->hOffScreen = CreateCompatibleBitmap(dc,w,h);
                    }
                    if (!data->hOffScreenBg)
                    {
                        data->hOffScreenBg = CreateCompatibleBitmap(dc,w,h);
                    }
                    if (!data->hOffScreenDC && data->hOffScreen)
                    {
                        data->hOffScreenDC = CreateCompatibleDC(dc);
                        if (data->hOffScreenDC)
                        {
                            SetTextColor(data->hOffScreenDC, RGB(0,0,0));
                            SetBkColor(data->hOffScreenDC, RGB(255,255,255));
                            SetBkMode(data->hOffScreenDC, OPAQUE);
                        }
                    }
                    if (!data->hBitmapDC)
                    {
                        data->hBitmapDC = CreateCompatibleDC(dc);
                    }

                    if (data->hBitmapDC &&
                        data->hOffScreenDC && 
                        data->hOffScreen &&
                        data->hOffScreenBg)
                    {
                        TitlePaint(data, hWnd, dc);
                    }
                    
                    EndPaint(hWnd, &paint);
                    return 1;
                }
            }
        }
        return 0;
        
    case WM_DESTROY:
        {
            // Cleanup
            LRESULT result = CallWindowProc(data->superProc, hWnd, msg, wp, lp);
            SetWindowLong(hWnd, GWL_WNDPROC, (LONG)data->superProc);
            SetWindowLong(hWnd, GWL_USERDATA, 0);

#ifdef SDK_REGISTRATION
            if (data->hGradientBitmap) DeleteBitmap(data->hGradientBitmap);
            TitleDeleteScrollData(data->scrollText);
            data->scrollText = NULL;
#endif // SDK_REGISTRATION

            if (data->hOffScreenDC) DeleteDC(data->hOffScreenDC);
            if (data->hOffScreen) DeleteBitmap(data->hOffScreen);
            if (data->hBitmapDC) DeleteDC(data->hBitmapDC);
            if (data->hBitmap) DeleteBitmap(data->hBitmap);
            if (data->hFont) DeleteFont(data->hFont);
            free(data->productName);

            free(data);
            return result;
        }
    
    default:
        // Forward the message to the default window proc
        return CallWindowProc(data->superProc, hWnd, msg, wp, lp);
    }
}
Ejemplo n.º 7
0
FIBITMAP* CreateDIBFromDC(HDC hDC, const RECT* rect, HWND hCapture/*=NULL*/)
{
	///HDC GetDC			(NULL)		entire desktp
	///HDC GetDC			(HWND hWnd)	client area of the specified window. (may include artifacts)
	///HDC GetWindowDC		(HWND hWnd)	entire window.
	FIBITMAP* dib;// return value
	HBITMAP hBitmap;					// handles to device-dependent bitmaps
	HDC hScrDC, hMemDC;					// screen DC and memory DC
	long width = rect->right - rect->left;
	long height = rect->bottom - rect->top;

	// create a DC for the screen and create
	// a memory DC compatible to screen DC
	if (!(hScrDC = hDC)) hScrDC = GetDC(hCapture);
	hMemDC = CreateCompatibleDC(hScrDC);
	// create a bitmap compatible with the screen DC
	hBitmap = CreateCompatibleBitmap(hScrDC, width, height);//width,height
	// select new bitmap into memory DC
	SelectObject(hMemDC, hBitmap);

	if (hCapture && hDC) {
		PrintWindow(hCapture, hMemDC, 0);
	}
	else {// bitblt screen DC to memory DC
		BitBlt(hMemDC, 0, 0, width, height, hScrDC, rect->left, rect->top, CAPTUREBLT | SRCCOPY);
	}
	dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap);

	//alpha channel from window is always wrong and sometimes even for desktop (Win7, no aero)
	//coz GDI do not draw all in alpha mode.
	//we have to create our own new alpha channel.
	bool bFixAlpha = true;
	bool bInvert = false;
	HBRUSH hBr = CreateSolidBrush(RGB(255, 255, 255));//Create a SolidBrush object for non transparent area
	HBITMAP hMask = CreateBitmap(width, height, 1, 1, NULL);// Create monochrome (1 bit) B+W mask bitmap.
	HDC hMaskDC = CreateCompatibleDC(0);
	SelectBitmap(hMaskDC, hMask);
	HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
	if (hCapture && GetWindowRgn(hCapture, hRgn) == ERROR) {
		if ((GetWindowLongPtr(hCapture, GWL_EXSTYLE)&WS_EX_LAYERED)) {
			BYTE bAlpha = 0;
			COLORREF crKey = 0x00000000;
			DWORD dwFlags = 0;
			if (GetLayeredWindowAttributes(hCapture, &crKey, &bAlpha, &dwFlags)) {
				/// per window transparency (like fading in a whole window)
				if ((dwFlags&LWA_COLORKEY)) {
					SetBkColor(hMemDC, crKey);
					BitBlt(hMaskDC, 0, 0, width, height, hMemDC, rect->left, rect->top, SRCCOPY);
					bInvert = true;
				}
				else if ((dwFlags&LWA_ALPHA)) {
					bFixAlpha = false;
				}
			}
			else {//per-pixel transparency (won't use the WM_PAINT)
				bFixAlpha = false;
			}
		}
		else {//not layered - fill the window region
			SetRectRgn(hRgn, 0, 0, width, height);
			FillRgn(hMaskDC, hRgn, hBr);
		}
	}
	else {
		if (!hCapture) SetRectRgn(hRgn, 0, 0, width, height);//client area only, no transparency
		FillRgn(hMaskDC, hRgn, hBr);
	}
	DeleteObject(hRgn);
	if (bFixAlpha) {
		FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask);
		if (bInvert) FIP->FI_Invert(dibMask);
		FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask);
		//copy the dib8 alpha mask to dib32 main bitmap
		FIP->FI_SetChannel(dib, dib8, FICC_ALPHA);
		FIP->FI_Unload(dibMask);
		FIP->FI_Unload(dib8);
	}
	DeleteDC(hMaskDC);
	DeleteObject(hMask);
	DeleteObject(hBr);
	//clean up
	DeleteDC(hMemDC);
	DeleteObject(hBitmap);
	if (!hDC) ReleaseDC(NULL, hScrDC);

#ifdef _DEBUG
	switch (FIP->FI_GetImageType(dib)) {
	case FIT_UNKNOWN:
		OutputDebugStringA("FIBITMAP Type: FIT_UNKNOWN\r\n");
		break;
	case FIT_BITMAP:
		OutputDebugStringA("FIBITMAP Type: FIT_BITMAP\r\n");
		break;
	case FIT_UINT16:
		OutputDebugStringA("FIBITMAP Type: FIT_UINT16\r\n");
		break;
	case FIT_INT16:
		OutputDebugStringA("FIBITMAP Type: FIT_INT16\r\n");
		break;
	case FIT_UINT32:
		OutputDebugStringA("FIBITMAP Type: FIT_UINT32\r\n");
		break;
	case FIT_INT32:
		OutputDebugStringA("FIBITMAP Type: FIT_INT32\r\n");
		break;
	case FIT_FLOAT:
		OutputDebugStringA("FIBITMAP Type: FIT_FLOAT\r\n");
		break;
	case FIT_DOUBLE:
		OutputDebugStringA("FIBITMAP Type: FIT_DOUBLE\r\n");
		break;
	case FIT_COMPLEX:
		OutputDebugStringA("FIBITMAP Type: FIT_COMPLEX\r\n");
		break;
	case FIT_RGB16:
		OutputDebugStringA("FIBITMAP Type: FIT_RGB16\r\n");
		break;
	case FIT_RGBA16:
		OutputDebugStringA("FIBITMAP Type: FIT_RGBA16\r\n");
		break;
	case FIT_RGBF:
		OutputDebugStringA("FIBITMAP Type: FIT_RGBF\r\n");
		break;
	case FIT_RGBAF:
		OutputDebugStringA("FIBITMAP Type: FIT_RGBAF\r\n");
		break;
	default:
		OutputDebugStringA("FIBITMAP Type: non detectable image type (error)\r\n");
		break;
	}
	BOOL inf = FIP->FI_IsTransparent(dib);
	OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: false\r\n");
#endif
	return dib;
}
INT_PTR CALLBACK DlgProcColorToolWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static COLORCHOOSER* pCC = NULL;
	static int iCurrentHotTrack;
	static BOOL bChoosing;
	static int iRows;
	static int iColumns;
	static HWND hPreviousActiveWindow;

	switch (msg) {
		case WM_INITDIALOG: {
			RECT rc;
			int iSquareRoot;
			int width ;
			int height;

			TranslateDialogDefault(hwndDlg);
			pCC = (COLORCHOOSER*) lParam;

			iCurrentHotTrack = -2;
			bChoosing = FALSE;

			iSquareRoot = (int)sqrt(static_cast<float>(pCC->pModule->nColorCount));

			iColumns = iSquareRoot * iSquareRoot == pCC->pModule->nColorCount ? iSquareRoot : iSquareRoot + 1;
			iRows = iSquareRoot;

			rc.top = rc.left = 100;
			rc.right =  100 +  iColumns * 25 + 1;
			rc.bottom = iRows * 20 + 100 + 20;

			AdjustWindowRectEx(&rc, GetWindowLongPtr(hwndDlg, GWL_STYLE), FALSE, GetWindowLongPtr(hwndDlg, GWL_EXSTYLE));

			width = rc.right - rc.left;
			height = rc.bottom - rc.top;

			pCC->yPosition -= height;


			SetDlgItemText(hwndDlg, IDC_COLORTEXT, pCC->bForeground ? CTranslator::get(CTranslator::GEN_MUC_TEXTCOLOR) :
						   CTranslator::get(CTranslator::GEN_MUC_BGCOLOR));
			SetWindowPos(GetDlgItem(hwndDlg, IDC_COLORTEXT), NULL,  0, 0, width, 20, 0);
			SetWindowPos(hwndDlg, NULL, pCC->xPosition, pCC->yPosition, width, height, SWP_SHOWWINDOW);
		}
		break;

		case WM_CTLCOLOREDIT:
		case WM_CTLCOLORSTATIC:
			if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_COLORTEXT)) {
				SetTextColor((HDC)wParam, RGB(60, 60, 150));
				SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
				return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
			}
			break;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
				case IDOK:
					if (iCurrentHotTrack >= 0)
						PostMessage(hwndDlg, WM_LBUTTONUP, 0, 0);
					break;
				case IDCANCEL:
					DestroyWindow(hwndDlg);
					break;
			}
			break;

		case WM_LBUTTONUP:
			if (iCurrentHotTrack >= 0 && iCurrentHotTrack < pCC->pModule->nColorCount && pCC->hWndTarget != NULL) {
				HWND hWindow;
				CHARFORMAT2 cf;
				cf.cbSize = sizeof(CHARFORMAT2);
				cf.dwMask = 0;
				cf.dwEffects = 0;
				hWindow = GetParent(pCC->hWndTarget);

				if (pCC->bForeground) {
					pCC->si->bFGSet = TRUE;
					pCC->si->iFG = iCurrentHotTrack;
					if (IsDlgButtonChecked(hWindow, IDC_COLOR)) {
						cf.dwMask = CFM_COLOR;
						cf.crTextColor = pCC->pModule->crColors[iCurrentHotTrack];
						SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
					}
				} else {
					pCC->si->bBGSet = TRUE;
					pCC->si->iBG = iCurrentHotTrack;
					if (IsDlgButtonChecked(hWindow, IDC_BKGCOLOR)) {
						cf.dwMask = CFM_BACKCOLOR;
						cf.crBackColor = pCC->pModule->crColors[iCurrentHotTrack];
						SendMessage(pCC->hWndTarget, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
					}
				}
			}
			PostMessage(hwndDlg, WM_CLOSE, 0, 0);
			break;

		case WM_ACTIVATE:
			if (wParam == WA_INACTIVE)
				PostMessage(hwndDlg, WM_CLOSE, 0, 0);
			else if ((wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE))
				hPreviousActiveWindow = (HWND)lParam;
			break;

		case WM_MOUSEMOVE: {
			HDC hdc = GetDC(hwndDlg);
			POINT pt;
			RECT rect;
			int but;

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

			if (iCurrentHotTrack == -2)
				return 0; // prevent focussing when not drawn yet!

			but = CalculateCoordinatesToButton(pCC, pt);

			// weird stuff
			if (but != iCurrentHotTrack) {
				if (iCurrentHotTrack >= 0) {
					rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
					DrawFocusRect(hdc, &rect);
					iCurrentHotTrack = -1;
				}
				iCurrentHotTrack = but;

				if (iCurrentHotTrack >= 0) {
					rect = CalculateButtonToCoordinates(pCC, iCurrentHotTrack);
					DrawFocusRect(hdc, &rect);
				}
			}
			ReleaseDC(hwndDlg, hdc);
		}
		break;

		case WM_PAINT: {
			PAINTSTRUCT ps;
			HDC hdc;
			RECT rc;
			int i = 0;
			int iThisRow = 1;
			int iThisColumn = 0;

			GetClientRect(hwndDlg, &rc);

			rc.top += 20;

			hdc = BeginPaint(hwndDlg, &ps);

			// fill background
			FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW));

			for (i; i < pCC->pModule->nColorCount; i++) {
				HBRUSH hbr;

				// decide place to draw the color block in the window
				iThisColumn ++;
				if (iThisColumn > iColumns) {
					iThisColumn = 1;
					iThisRow++;
				}

				if (pCC->bForeground && pCC->si->bFGSet && pCC->si->iFG == i ||
						!pCC->bForeground && pCC->si->bBGSet && pCC->si->iBG == i) {
					rc.top = (iThisRow - 1) * 20 + 1 + 20 ;
					rc.left = (iThisColumn - 1) * 25 + 1 + 1 ;
					rc.bottom = iThisRow * 20 - 1 + 20 ;
					rc.right = iThisColumn * 25 - 1 ;

					DrawEdge(hdc, &rc, EDGE_RAISED, BF_TOP | BF_LEFT | BF_RIGHT | BF_BOTTOM);
				}

				rc.top = (iThisRow - 1) * 20 + 3 + 20 ;
				rc.left = (iThisColumn - 1) * 25 + 3 + 1 ;
				rc.bottom = iThisRow * 20 - 3 + 20 ;
				rc.right = iThisColumn * 25 - 3 ;

				FillRect(hdc, &rc, CSkin::m_BrushBack);

				hbr = CreateSolidBrush(pCC->pModule->crColors[i]);

				rc.top = (iThisRow - 1) * 20 + 4 + 20;
				rc.left = (iThisColumn - 1) * 25 + 4 + 1;
				rc.bottom = iThisRow * 20 - 4 + 20;
				rc.right = iThisColumn * 25 - 4;

				FillRect(hdc, &rc, hbr);
				DeleteObject(hbr);
			}

			EndPaint(hwndDlg, &ps);
			iCurrentHotTrack = -1;
		}
		break;

		case WM_CLOSE:
			SetFocus(pCC->hWndTarget);
			DestroyWindow(hwndDlg);
			break;

		case WM_DESTROY:
			mir_free(pCC);
			return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
Archivo: guiwin.c Proyecto: mbert/elvis
static void gwdraw(GUIWIN *gw, long fg, long bg, int bits, Char *text, int len)

{
    register int    i;
    GUI_WINDOW      *gwp = (GUI_WINDOW *)gw;
    COLORREF        fgc, bgc;
    HBRUSH	    hBrush, hPrevBrush;
    HPEN            hPen, hPrevPen;
    HDC		    hDC;
    HFONT           hFont;
    RECT            rect;
    int             ileft;
    int             xleft, xcenter, xright, ytop, ycenter, ybottom, radius;
    UINT	    options;

    /* Italics are slanted rightward from the bottom of the character cell.
     * We'd like for them to look slanted from the center of the characters,
     * and we can achieve that effect by shifting italic text slightly leftward.
     */
    ileft = 0;
    if ((bits & COLOR_GRAPHIC) != COLOR_GRAPHIC && (bits & COLOR_ITALIC))
        ileft = (gwp->ycsize - 3) / 6; /* just a guess */

    /* Convert fg and bg args into COLORREF values */
    fgc = (COLORREF)fg;
    bgc = (COLORREF)bg;

    /* compute the update RECT */
    rect.top = gwp->currow * gwp->ycsize;
    rect.left = gwp->curcol * gwp->xcsize + gwp->xcsize / 2;
    rect.bottom = rect.top + gwp->ycsize;
    rect.right = rect.left + gwp->xcsize * len;

    /* Get the window's DC */
    hDC = GetDC (gwp->clientHWnd);
    SetMapMode (hDC, MM_TEXT);

    /* hide caret */
    if (gwp->cursor_type != CURSOR_NONE && gwp->clientHWnd == GetFocus ())
    {
        HideCaret (gwp->clientHWnd);
        gwp->cursor_type = CURSOR_NONE;
    }

    /* graphic chars are a special case */
    if ((bits & COLOR_GRAPHIC) == COLOR_GRAPHIC)
    {
        /* Strip out the COLOR_GRAPHIC bits */
        bits &= ~COLOR_GRAPHIC;

        /* Erase the area */
#ifdef FEATURE_IMAGE
        if (normalimage && (long)bgc == colorinfo[COLOR_FONT_NORMAL].bg)
        {
            gw_erase_rect(hDC, &rect, normalimage, gwp->scrolled);
        }
        else if (idleimage && (long)bgc == colorinfo[COLOR_FONT_IDLE].bg)
        {
            gw_erase_rect(hDC, &rect, idleimage, gwp->scrolled);
        }
        else
#endif
        {
            hBrush = CreateSolidBrush (bgc);
            FillRect (hDC, &rect, hBrush);
            DeleteObject(hBrush);
        }

        /* Select the foreground color */
        hPen = CreatePen(PS_SOLID, 0, fgc);
        hPrevPen = SelectObject(hDC, hPen);

        /* Find special points in the first character cell */
        radius = gwp->xcsize / 3;
        xleft = rect.left;
        xright = xleft + gwp->xcsize;
        xcenter = (xleft + xright) / 2;
        ytop = rect.top;
        ybottom = rect.bottom;
        ycenter = (ytop + ybottom) / 2;

        /* For each graphic character... */
        for (i = 0; i < len; text++, i++)
        {
            /* Draw line segments, as appropriate for this character */
            if (strchr("123456|", *text))
            {
                MoveToEx(hDC, xcenter, ytop, NULL);
                LineTo(hDC, xcenter, ycenter);
            }
            if (strchr("456789|", *text))
            {
                MoveToEx(hDC, xcenter, ycenter, NULL);
                LineTo(hDC, xcenter, ybottom);
            }
            if (strchr("235689-", *text))
            {
                MoveToEx(hDC, xleft, ycenter, NULL);
                LineTo(hDC, xcenter, ycenter);
            }
            if (strchr("124578-", *text))
            {
                MoveToEx(hDC, xcenter, ycenter, NULL);
                LineTo(hDC, xright, ycenter);
            }
            if (*text == 'o')
            {
                Arc(hDC, xcenter - radius, ycenter - radius,
                    xcenter + radius, ycenter + radius,
                    xcenter - radius, ycenter,  xcenter - radius, ycenter);
            }
            if (*text == '*')
            {
                HBRUSH	oldbrush, newbrush;
                newbrush = CreateSolidBrush(fgc);
                oldbrush = SelectObject(hDC, newbrush);
                Pie(hDC, xcenter - radius, ycenter - radius,
                    xcenter + radius, ycenter + radius,
                    xcenter - radius, ycenter,  xcenter - radius, ycenter);
                SelectObject(hDC, oldbrush);
                DeleteObject(newbrush);
            }

            /* Advance the points to the next cell */
            xleft = xright;
            xcenter += gwp->xcsize;
            xright += gwp->xcsize;
        }

        /* Restore foreground color to its previous value, so we can delete
         * the local hPen object.
         */
        SelectObject(hDC, hPrevPen);
        DeleteObject(hPen);
    }
    else
    {
        /* Find a font with the right bold/italic/underlined attributes */
        i = 0;
        if (bits & COLOR_BOLD) i += 1;
        if (bits & COLOR_ITALIC) i += 2;
        if (bits & COLOR_UNDERLINED) i += 4;
        hFont = gwp->fonts[i];

        /* prepare DC & output text */
        SetTextColor(hDC, fgc);
        SetBkColor(hDC, bgc);
        SetBkMode(hDC, OPAQUE);
        SelectObject(hDC, hFont);
        options = ETO_OPAQUE | ETO_CLIPPED;
#ifdef FEATURE_IMAGE
        if (normalimage && (long)bgc == colorinfo[COLOR_FONT_NORMAL].bg)
        {
            gw_erase_rect(hDC, &rect, normalimage, gwp->scrolled);
            options = ETO_CLIPPED;
            SetBkMode(hDC, TRANSPARENT);
        }
        else if (idleimage && (long)bgc == colorinfo[COLOR_FONT_IDLE].bg)
        {
            gw_erase_rect(hDC, &rect, idleimage, gwp->scrolled);
            options = ETO_CLIPPED;
            SetBkMode(hDC, TRANSPARENT);
        }
#endif
        ExtTextOut(hDC, rect.left - ileft, rect.top, options, &rect,
                   (char *)text, len, gwp->font_size_array);
#ifdef FEATURE_IMAGE
        SetBkColor(hDC, bgc);
        SetBkMode(hDC, OPAQUE);
#endif
    }

    /* If COLOR_BOXED then draw a rectangle around the text */
    if (bits & (COLOR_BOXED | COLOR_LEFTBOX | COLOR_RIGHTBOX))
    {
        /* Select the foreground color */
        hPen = CreatePen(PS_SOLID, 0, fgc);
        hPrevPen = SelectObject(hDC, hPen);

        /* Draw the rectangle */
        if (bits & COLOR_BOXED)
        {
            MoveToEx(hDC, rect.left, rect.top, NULL);
            LineTo(hDC, rect.right, rect.top);
            MoveToEx(hDC, rect.left, rect.bottom - 1, NULL);
            LineTo(hDC, rect.right, rect.bottom - 1);
        }
        if (bits & COLOR_RIGHTBOX)
        {
            MoveToEx(hDC, rect.right - 1, rect.top, NULL);
            LineTo(hDC, rect.right - 1, rect.bottom);
        }
        if (bits & COLOR_LEFTBOX)
        {
            MoveToEx(hDC, rect.left, rect.top, NULL);
            LineTo(hDC, rect.left, rect.bottom);
        }

        /* Restore foreground color to its previous value, so we can delete
         * the local hPen object.
         */
        SelectObject(hDC, hPrevPen);
        DeleteObject(hPen);
    }

    /* release the window's device context */
    ReleaseDC(gwp->clientHWnd, hDC);

    /* update cursor position */
    gwp->curcol += len;
}
Ejemplo n.º 11
0
int Init_ConsoleWin(void)
{
    HDC conDC;
    WNDCLASS wndclass;
    TEXTMETRIC metrics;
    RECT cRect;
    int width,height;
    int scr_width,scr_height;
    HINSTANCE hInstance;
    char titlebuffer[2048];

    if (con_hWnd)
        return TRUE;
    hInstance = GetModuleHandle(NULL);
    Init_Console();
    /* Register the frame class */
    wndclass.style         = CS_OWNDC;
    wndclass.lpfnWndProc   = (WNDPROC)ConWndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon (hInstance, IDI_WINLOGO);
    wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
    wndclass.lpszMenuName  = szConName;
    wndclass.lpszClassName = szConName;

    if (!RegisterClass(&wndclass))
        return FALSE;

    width=100;
    height=100;
    strcpy(titlebuffer,PACKAGE);
    strcat(titlebuffer," ");
    strcat(titlebuffer,VERSION);
    strcat(titlebuffer," console");
    con_hWnd = CreateWindow(szConName, titlebuffer,
                            WS_CAPTION | WS_POPUP,
                            0, 0, width, height,
                            NULL, NULL, hInstance, NULL);
    conDC=GetDC(con_hWnd);
    OemFont = GetStockObject(OEM_FIXED_FONT);
    SelectObject(conDC, OemFont);
    GetTextMetrics(conDC, &metrics);
    OemWidth = metrics.tmAveCharWidth;
    OemHeight = metrics.tmHeight;
    GetClientRect(con_hWnd, &cRect);
    width += (OemWidth * 80) - cRect.right;
    height += (OemHeight * 25) - cRect.bottom;
    // proff 11/09/98: Added code for centering console
    scr_width = GetSystemMetrics(SM_CXFULLSCREEN);
    scr_height = GetSystemMetrics(SM_CYFULLSCREEN);
    MoveWindow(con_hWnd, (scr_width-width)/2, (scr_height-height)/2, width, height, TRUE);
    GetClientRect(con_hWnd, &cRect);
    ConWidth = cRect.right;
    ConHeight = cRect.bottom;
    SetTextColor(conDC, RGB(192,192,192));
    SetBkColor(conDC, RGB(0,0,0));
    SetBkMode(conDC, OPAQUE);
    ReleaseDC(con_hWnd,conDC);
    ShowWindow(con_hWnd, SW_SHOW);
    UpdateWindow(con_hWnd);
    return TRUE;
}
Ejemplo n.º 12
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static int taskID, adjusted, playedItem, range_max, range_min, needMoreUpDown;
	static HWND hAdjButton[5], /*hSlider, hSliderVal,*/ hPlay, hDone /*hMore*/;
	static char versionstr[16], buf[1024], inst1[256], inst2[256];
	static HWND hbut[MAX_INTERVALS];
	static int ready4Respond, intvl, instID;
	static HBRUSH hBackgrnd;
	static HWND hFreak, hMsg, hFeed, hBegin, hMsgOperator, hCount;	//, hCap;
	static HFONT hFont, hFont2, hFont3, hFont4;
	static HBITMAP hBitmap[14];

	static bool fCollectingSeq = false;
	static vector<int> SeqTMs;
	static DWORD Tick0;

	int i, answer, j, id, count, nAnchor, anchor[8];

	WORD command;
	DWORD hal;
	char cody[64];

	HDC hdc;
	int bltx[]={30, 30, 30, 30, 25, 25,}, 
		 blty[]={25, 50, 50, 25, 25, 25,};
	COLORREF col;
	//char AppPath[512], procname[64], verstr[16];

	static bool banchor[8];
	static int sizex, sizey, cintl, cintlna, marginx, spacing, width, height, marginy, icount;

	switch (uMsg)
	{
	case WM__INIT_DISPLAY:
		hBitmap[0] = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP_CL_UP));
		hBitmap[1] = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP_CL_UP_SM));
		hBitmap[2] = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP_CL_DOWN_SM));
		hBitmap[3] = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP_CL_DOWN));
		hBitmap[4] = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP_PLAY));
		sizex = GetSystemMetrics (SM_CXSCREEN)-10;
		sizey = GetSystemMetrics (SM_CYSCREEN)-30;
		hMsg=CreateWindow ("Static", "", WS_CHILD|WS_VISIBLE, 100, 80, 800, 100, hwnd,
									(HMENU)ID_HMSG, hInst, NULL);
		hMsgOperator=CreateWindow ("Static", "", WS_CHILD|WS_VISIBLE, 100, 540, 800, 100, hwnd,
									(HMENU)ID_HMSG2, hInst, NULL);
		hFeed=CreateWindow ("Static", "", WS_CHILD, 100, 600, 390, 45, hwnd,
									(HMENU)ID_FEEDBACK, hInst, NULL);
		hCount = CreateWindow ("Static", "", WS_CHILD, 400, 335, 150, 150, hwnd,
									(HMENU)ID_COUNTER, hInst, NULL);
		//hCap = CreateWindow ("Static", "Connection: OFF", WS_CHILD|WS_VISIBLE, 
		//	20, 8, 100, 25, hwnd, (HMENU)ID_CAP, hInst, NULL);
			// Creating the buttons
		hPlay = CreateWindow ("button", "", WS_CHILD | BS_BITMAP | BS_CENTER | BS_VCENTER, xPos[0]+(xPos[3]-xPos[0])/3, 
				yPos+160, butWidth[3]*2/3, butHeight[3]*11/15, hwnd, (HMENU)IDC_PLAY, hInst, NULL);
		SendMessage (hPlay, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap[4]);
		hDone= CreateWindow ("Button", "DONE", WS_CHILD|WS_DISABLED, xPos[2]+(xPos[3]-xPos[0])/3, yPos+160, butWidth[3]*4/9, butHeight[3]*33/60, hwnd,
									(HMENU)IDC_DONE, hInst, NULL);
		for (j=0; j<MAX_INTERVALS; j++)
			hbut[j] = CreateWindow ("Button", itoa(j+1, buf, 10), WS_CHILD|WS_DISABLED, 
				0, 0, 0, 0, hwnd, (HMENU)(BUTT1+j), hInst, NULL);
		hBegin = CreateWindow ("button", "Press to start", WS_CHILD|WS_DISABLED, sizex/3, sizey*7/10, sizex/3, sizey*20/100,
			hwnd, (HMENU)ID_HBEGIN, hInst, NULL);
		hFont = CreateFont (25, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, 
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_ROMAN,
			"Verdana");
		hFont2 = CreateFont (20, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, 
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_ROMAN,
			"Times New Roman");
		hFont3 = CreateFont (20, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, 
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_ROMAN,
			"Verdana");
		hFont4 = CreateFont (13, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, 
			OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_ROMAN,
			"Arial");

		hAdjButton[0] = CreateWindow ("button", "", WS_CHILD | BS_BITMAP | BS_CENTER | BS_VCENTER, xPos[0], yPos, butWidth[0], butHeight[0],
			hwnd, (HMENU)IDB_BITMAP_CL_UP, hInst, NULL);
		SendMessage (hAdjButton[0], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap[0]);
		hAdjButton[1] = CreateWindow ("button", "", WS_CHILD | BS_BITMAP | BS_CENTER | BS_VCENTER, xPos[1], yPos, butWidth[1], butHeight[1],
			hwnd, (HMENU)IDB_BITMAP_CL_UP_SM, hInst, NULL);
		SendMessage (hAdjButton[1], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap[1]);
		hAdjButton[2] = CreateWindow ("button", "", WS_CHILD | BS_BITMAP | BS_CENTER | BS_VCENTER, xPos[2], yPos, butWidth[2], butHeight[2],
			hwnd, (HMENU)IDB_BITMAP_CL_DOWN_SM, hInst, NULL);
		SendMessage (hAdjButton[2], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap[2]);
		hAdjButton[3] = CreateWindow ("button", "", WS_CHILD | BS_BITMAP | BS_CENTER | BS_VCENTER, xPos[3], yPos, butWidth[3], butHeight[3],
			hwnd, (HMENU)IDB_BITMAP_CL_DOWN, hInst, NULL);
		SendMessage (hAdjButton[3], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap[3]);
		hBackgrnd = CreateSolidBrush(GetSysColor (COLOR_WINDOW));
		ready4Respond = 0;
		//GetCurrentProcInfo(AppPath, procname, verstr);
		//getVersionStringAndUpdateTitle(hwnd, procname, verstr);
		break;

	case WM_SIZE:
		MoveWindow(hwnd, 0, 0, sizex, sizey, 1);
		break;

	case WM_CTLCOLORSTATIC:
		hdc = (HDC)wParam;
		col = GetSysColor (COLOR_WINDOW);
		id = (int)GetWindowLong ((HWND)lParam, GWL_ID);
		switch (id)
		{
		case ID_FEEDBACK:
			SelectObject (hdc, hFont2);
			SetTextColor (hdc, RGB(113, 30, 225));
			SetBkColor (hdc, col);
			return (LRESULT) hBackgrnd;
		case ID_HMSG:
			SelectObject (hdc, hFont);
			SetTextColor (hdc, RGB(100, 80, 64));
			SetBkColor (hdc, col);
			return (LRESULT) hBackgrnd;
		case ID_HMSG2:
			SelectObject (hdc, hFont);
			SetTextColor (hdc, RGB(190, 30, 64));
			SetBkColor (hdc, col);
			return (LRESULT) hBackgrnd;
		case ID_CAP:
			SelectObject (hdc, hFont4 );
			SetBkColor (hdc, col);
			return (LRESULT) hBackgrnd;
		}
		break;

	case WM_FL_CONNECTED:
		//SetWindowText (hCap, "Connection: On");
		break;

	case WM__MOVE_BUTTONS:
		count = (WPARAM)wParam;
		if (count == 0)
			break;
		// Calculating the width, spacing, etc... of the buttons
		{
			int each = (int)(sizex/(count+0.2));
			width = each * 8/10;
			spacing = each * 2/10;
			marginx = each * 2/10;
			height = sizey * 3/10;
			marginy = sizey * 25/100;
		}
		for (j=0; j<count; j++)
			MoveWindow(hbut[j], marginx+j*(width+spacing), marginy, width, height, 0);
		break;

	case WM_FL_ARRIVED:
		command = LOWORD(wParam);
		switch (command)
		{
		case FL_INIT:
			taskID = 0;
			// Receiving the number of interval from O-PC
			hal = *(DWORD*)lParam;
			cintl = LOWORD(hal);
			cintlna = HIWORD(hal);

//			memcpy((void*)&cintl, (void*)lParam, sizeof(int)); 
			SendMessage(hwnd, WM__MOVE_BUTTONS, cintl, 0);
			intvl = stopped = 0; 
			// Arranging the buttons
			for (j=0; j<cintl; j++)
			{
				SetWindowText (hbut[j], itoa(j+1, buf, 10));
				MoveWindow(hbut[j], marginx+j*(width+spacing), marginy, width, height, 0);
				ShowWindow(hbut[j], SW_SHOW);
			}
			if (cintl == 1) {
				SetWindowText (hbut[0], "Correct");
				SetWindowText (hbut[1], "Incorrect");
				SetWindowText (hbut[2], "Skip");
			}
			ShowWindow(hBegin, SW_SHOW);
			SetWindowText(hMsg, "Press 'begin' to start");
			ShowWindow(hMsg, SW_SHOW);
			ShowWindow(hCount, SW_HIDE);
			ShowWindow(hPlay, SW_HIDE);
			ShowWindow(hFeed, SW_HIDE);
			icount = 5;
			instID=0;
			strcpy(inst1, "");
			strcpy(inst2, "");
			memset((void*)banchor, 0, 8);
			break;
		case FL_INIT2:
			if ((count=str2array(anchor, 8, (char*)lParam, " "))<1) 
			{
				MessageBox (hwnd, (char*)lParam, "Invalid incoming string", MB_OK);
				break;
			}
			nAnchor = count; // the number of anchored intervals
			//Check what intervals are anchors
			for (j=0; j<nAnchor; j++) banchor[anchor[j]] = true;
			break;

		case FL_INIT_SLIDER:
			taskID = 2;
			ShowButtons(hAdjButton, hPlay, hDone, SW_SHOW);
			SetWindowText (hMsg, "Press ""PLAY"" button (or ""done"" when it's done)");
			break;
		case FL_ABOUT2PRESENT:
			SendMessage(hwnd, WM__MOVE_BUTTONS, cintl, 0);
			if (taskID==0)
			{
				ready4Respond = 0; // Just to re-assure
				if (!stopped)
				{
					ShowWindow (hbut[intvl], SW_SHOW);
					if (intvl>0)
						ShowWindow (hbut[intvl-1], SW_HIDE);
				}
			}
			else // slider
			{
				EnableButtons (hAdjButton, hPlay, hDone, 0);
				if (playedItem==0)
					SetWindowText (hMsg, "Listen to SOUND 1...");
				else
					SetWindowText (hMsg, "Listen to SOUND 2...");
			}
			break;
		case FL_ABOUT2STOP:
			if (taskID==0)
			{
				intvl++;
				if (intvl==cintl) 
				{	
					for (i=0; i<cintl; i++) ShowWindow (hbut[i], SW_HIDE); 
					if (cintlna>1)
					{
						for (i=0; i<cintl; i++) 
						{
							ShowWindow (hbut[i], SW_SHOW); 
							EnableWindow (hbut[i], !banchor[i]);
						}
					}
					else
					{
						SendMessage(hwnd, WM__MOVE_BUTTONS, 3, 0);
						for (i=0; i<3; i++) 
						{
							ShowWindow (hbut[i], SW_SHOW); 
							EnableWindow (hbut[i], TRUE);
						}
					}
					intvl = 0; 
					SetWindowText (hMsg, inst2);
					ready4Respond = 1;
				}
			}
			else // slider
			{
				EnableButtons (hAdjButton, NULL, NULL, 1);
				SetWindowText (hMsg, "");
				playedItem++;
			}
			break;

		case FL_END_OF_PRSENTATION:
			EnableWindow (hPlay, TRUE);
			EnableWindow (hDone, TRUE);
			SetWindowText (hMsg, inst1);
			break;

		case FL_TEXT:
			ShowWindow (hMsgOperator, SW_SHOW);
			SetWindowText (hMsgOperator, (char*)lParam);
			break;

		case FL_DONE:
			stopped=1;
			SetWindowText (hMsg, "Session done....");
			ShowWindow(hMsg, SW_SHOW);
			break;

		case FL_FEEDBACK:
			ShowWindow (hFeed, SW_SHOW);
			SetWindowText (hFeed, (char*)lParam);
			SetTimer (hwnd, FDBCKTIMER, 1500, NULL);
			break;
		case FL_STOP:
			PostMessage (hwnd, WM__STOPPED, 0, 1);
			break;
		case FL_RESUME:
			stopped=0;
			if (taskID==0 || taskID==1)
				for (j=0; j<cintl; j++)		ShowWindow (hbut[j], SW_SHOW); 
			else
				ShowButtons(hAdjButton, hPlay, hDone, SW_SHOW);
			break;

		case FL_COUNT:
			ShowWindow (hCount, SW_SHOW);
			SetWindowText (hMsg, "Wait for the next one....");
			SetWindowText (hCount, itoa(icount--, buf, 10));
			break;

		case FL_INSTRUCTION:
			if (instID==0)
			{
				strcpy(inst1, (char*)lParam);
				instID++;
				EnableWindow (hBegin, TRUE);
			} else
				strcpy(inst2, (char*)lParam);
			break;
		case FL_BUTTON_TEXT:	// Manual button control
			{
				int iBtn;
				if (sscanf((char*)lParam, "%d:", &iBtn) != 1)
					MessageBox(hwnd, "Invalid message format. (No button index)", "Error", MB_ICONQUESTION);
				int iStart = 0, iEnd = 0;
				if (iBtn == 0)
					iStart = 0, iEnd = cintl;
				else {
					if (iBtn>0 && iBtn<=cintl)
						iStart = iBtn - 1, iEnd = iBtn;
					else
						MessageBox(hwnd, "Button index is out of range.", "Error", MB_ICONQUESTION);
				}
				char *txt = strchr((char*)lParam,':') + 1;
				if (strncmp(txt, "FILE ", 5) == 0) {
					txt += 5;
				    HBITMAP hBitmap = (HBITMAP) ::LoadImage (0, txt, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
					if (hBitmap == 0)
						MessageBox(hwnd, "Cannot load bitmap from file", "Error", MB_ICONQUESTION);
					else
						for (int i=iStart; i<iEnd; ++i) {
							SetWindowLongPtr(hbut[i], GWL_STYLE, WS_CHILD|BS_BITMAP);
							SendMessage(hbut[i], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
						}
				} else
					for (int i=iStart; i<iEnd; ++i) {
						SetWindowLongPtr(hbut[i], GWL_STYLE, WS_CHILD);
						SetWindowText (hbut[i], txt);
					}
			}
			break;
		case FL_BUTTON:	// Manual button control
			{
				DWORD dw = *(DWORD*)lParam;
				int iBtn = LOBYTE(LOWORD(dw));
				int nBtn = HIBYTE(LOWORD(dw));
				int fShow   = LOBYTE(HIWORD(dw));
				int fEnable = HIBYTE(HIWORD(dw));

				if (nBtn>0 && nBtn!=cintl) {
					cintl = nBtn;
					SendMessage(hwnd, WM__MOVE_BUTTONS, cintl, 0);
				}
				int iStart = 0, iEnd = 0;
				if (iBtn == 0)
					iStart = 0, iEnd = cintl;
				else {
					if (iBtn>0 && iBtn<=cintl)
						iStart = iBtn - 1, iEnd = iBtn;
					else
						MessageBox(hwnd, "Button index is out of range.", "Error", MB_ICONQUESTION);
				}
				for (int i=iStart; i<iEnd; ++i) {
					if (fShow)		// 0:No change, 1:Hide, 2:Show
						ShowWindow(hbut[i], (fShow-1) ? SW_SHOW : SW_HIDE);
					if (fEnable)	// 0:No change, 1:Disable, 2:Enable
						EnableWindow(hbut[i], fEnable-1);
				}
			}
			break;
		case FL_INSTRUCT:		// Manual control
			SetWindowText(hMsg, (char*)lParam);
			break;
		case FL_RECEIVE_SEQ_END:
			fCollectingSeq = false;
			if (SeqTMs.size())
				FER(flySendBin(FL_RESPONSE, &SeqTMs[0], sizeof(SeqTMs[0]) * SeqTMs.size()))
			else
				FER(flySendText(FL_RESPONSE, ""))
			ShowWindow(hbut[0], SW_HIDE); 
			EnableWindow(hbut[0], false);
			break;
		case FL_RECEIVE_SEQ:	// Manual control
			SetWindowText(hbut[0], "Click when done");
			EnableWindow(hbut[0], true);
			for (int i=1; i<MAX_INTERVALS; ++i)
				ShowWindow(hbut[i], SW_HIDE); 
			SendMessage(hwnd, WM__MOVE_BUTTONS, 1, 0);
			ShowWindow(hbut[0], SW_SHOW);

			ShowWindow (hFeed, SW_SHOW);
			SetWindowText (hFeed, "Waiting for keys...");

			fCollectingSeq = true;
			SeqTMs.clear();
			Tick0 = GetTickCount();
			// go through
		case FL_RECEIVE:
			if (*(char*)lParam)
				SetWindowText(hMsg, (char*)lParam);
			ready4Respond = 1;
			break;
		}
		break;

	case WM_KEYDOWN:
		if (fCollectingSeq && wParam == VK_RETURN) {
			int tm = int(GetTickCount() - Tick0);
			SeqTMs.push_back(tm);
			char buf[120];
			sprintf(buf, "%d  at  %.2f sec", SeqTMs.size(), tm/1000.);
			SetWindowText(hFeed, buf);
		}
		break;

	case WM_FL_SENT_OK:
		command = LOWORD(wParam);
		switch (command)
		{
		case FL_BEGIN:
		case FL_RESPONSE:
			for (j=0; j<cintl; j++)
				ShowWindow (hbut[j], SW_HIDE);
			SetWindowText (hMsg, inst1);
			break;
		}
		break ;

	case WM_FL_NETWORK_ERR:
		itoa(LOWORD(wParam), cody, 10);
		MessageBox(hwnd, (char*)lParam, cody, MB_OK);
		break ;

	case WM__STOPPED:
		stopped=1;
		intvl = 0;
		if ((int)lParam==1) // "panic" pressed
			strcpy(buf,"Stop pressed.");
		else // stopped by the operator
			strcpy(buf,"Stopped by the operator");
		SetWindowText (hMsg, buf);
		ShowWindow (hBegin, SW_HIDE); 
		for (j=0; j<max(cintl,3); j++)	// max(3) is necessary for the single interval case
			ShowWindow (hbut[j], SW_HIDE); 
		ShowButtons(hAdjButton, hPlay, hDone, SW_HIDE);
		break;

	case WM_COMMAND:
 		answer = LOWORD(wParam)-BUTT1;
		switch (LOWORD(wParam))
		{
		case IDC_PLAY:
			playedItem = 0;
			FER(flySendText (FL_PLAY, ""));
			break;
		case IDB_BITMAP_CL_UP:
			FER(flySendText (FL_ADJUST, "+BIG"));
			SendMessage (hwnd, WM_COMMAND, IDC_PLAY, 0);
			break;
		case IDB_BITMAP_CL_UP_SM:
			FER(flySendText (FL_ADJUST, "+SMALL"));
			SendMessage (hwnd, WM_COMMAND, IDC_PLAY, 0);
			break;
		case IDB_BITMAP_CL_DOWN:
			FER(flySendText (FL_ADJUST, "-BIG"));
			SendMessage (hwnd, WM_COMMAND, IDC_PLAY, 0);
			break;
		case IDB_BITMAP_CL_DOWN_SM:
			FER(flySendText (FL_ADJUST, "-SMALL"));
			SendMessage (hwnd, WM_COMMAND, IDC_PLAY, 0);
			break;
		case IDC_DONE:
			ShowButtons(hAdjButton, hPlay, hDone, SW_HIDE);
			SetWindowText (hMsg, "Done. Wait for the next trial.");
			FER(sendfly(FL_DONE, "", 0))
			EnableWindow (hDone, 0);
			needMoreUpDown = 0;
			break;

		case BUTT1:
		case BUTT2:
		case BUTT3:
		case BUTT4:
		case BUTT5:
			if (fCollectingSeq) {
				SendMessage(hwnd, WM_FL_ARRIVED, FL_RECEIVE_SEQ_END, 0);
			} else if (ready4Respond) {
				for (j=0; j<max(cintl,3); j++)	// max(3) is necessary for the single interval case
				{
					ShowWindow (hbut[j], SW_HIDE); 
					EnableWindow (hbut[j], 0);
				}
				if (cintl == 1 && answer == 2)
					FER(sendfly (FL_SKIP, "", 0))
				else
					FER(sendflyn (FL_RESPONSE, &answer, sizeof(int), 0))
			}
			ready4Respond = 0;
			break;
	
		case ID_HBEGIN:
			answer=10;
			FER(sendfly (FL_BEGIN, "", 0))
			ShowWindow(hBegin, SW_HIDE);
			SetWindowText (hMsg, inst1);
			SetTimer (hwnd, BEGINDELAY, 500, NULL);
			for (j=0; j<cintl; j++)
			{
				ShowWindow (hbut[j], SW_HIDE); 
				EnableWindow (hbut[j], 0);
			}
			break;

		case ID_RESPONSE_1:
		case ID_RESPONSE_2:
		case ID_RESPONSE_3:
		case ID_RESPONSE_4:
			SendMessage (hwnd, WM_COMMAND, BUTT1 + (LOWORD(wParam)-ID_RESPONSE_1), 0);
			break;
		case ID_STOP:
			FER(sendfly(FL_STOP, "", 0))
			SendMessage(hwnd, WM__STOPPED, 0, STOPPED_BY_USER);
			break;

		default:
			MessageBox(hwnd, "UNKNOWN", "ERROR", MB_OK);
			break;
		}
		break ;

	case WM_TIMER:
		switch (wParam)
		{
		case FDBCKTIMER:
			ShowWindow (hFeed, SW_HIDE);
			break;
		}
		break;

	case WM_FL_CLOSE:
		//SetWindowText (hCap, "Connection: Off");
	case WM_CLOSE:
		for (j=0; j<MAX_INTERVALS; j++)
			DestroyWindow (hbut[j]);
		DestroyWindow(hBegin);
		DestroyWindow(hCount);
		DestroyWindow(hFeed); 
		DestroyWindow(hMsg); 
		DestroyWindow(hMsgOperator);
		DestroyWindow(hPlay);
		DestroyWindow(hDone);
		for (j=0; j<4; j++)
			DestroyWindow (hAdjButton[j]);
		for (j=0; j<5; j++) DeleteObject(hBitmap[j]);
		DeleteObject(hFont);
		DeleteObject(hFont2);
		DeleteObject(hFont3);
		DeleteObject(hFont4);
		DeleteObject(hBackgrnd);
		SetWindowLong (hwnd, GWL_WNDPROC, (LONG)hOrgProc);
		PostMessage(hwnd, uMsg, wParam, lParam);	// This will be handled by hOrgProc and current dll (this code) will be unloaded there.
		return 0;	// Must return here. Otherwise, the CallWindowProc() below will unload current dll and it causes a crash.(This code will be gone when CallWindowProc() returns.)
	}
    return CallWindowProc(hOrgProc, hwnd, uMsg, wParam, lParam);
}
Ejemplo n.º 13
0
/* Text log window callback. */
static LRESULT CALLBACK wlog_text_log_callback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   CREATESTRUCT* create_struct;

   ALLEGRO_NATIVE_DIALOG* textlog = (ALLEGRO_NATIVE_DIALOG*)GetWindowLongPtr(hWnd, GWLP_USERDATA);

   switch (uMsg) {
      case WM_CTLCOLORSTATIC:
         /* Set colors for text and background */
         SetBkColor((HDC)wParam, RGB(16, 16, 16));
         SetTextColor((HDC)wParam, RGB(128, 255, 128));
         return (LRESULT)CreateSolidBrush(RGB(16, 16, 16));

      case WM_CREATE:
         /* Set user data for window, so we will be able to retieve text log structure any time */
         create_struct = (CREATESTRUCT*)lParam;
         SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)create_struct->lpCreateParams);
         break;

      case WM_CLOSE:
         if (textlog->is_active) {
            if (!(textlog->flags & ALLEGRO_TEXTLOG_NO_CLOSE)) {
               wlog_emit_close_event(textlog, false);
            }
            return 0;
         }
         break;

      case WM_DESTROY:
         PostQuitMessage(0);
         break;

      case WM_KEYDOWN:
         if (wParam == VK_ESCAPE) {
            wlog_emit_close_event(textlog, true);
         }

         break;

      case WM_MOVE:
         InvalidateRect(hWnd, NULL, FALSE);
         break;

      case WM_SIZE:
         /* Match text log size to parent client area */
         if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) {
            RECT client_rect;
            GetClientRect(hWnd, &client_rect);
            MoveWindow(textlog->tl_textview, client_rect.left, client_rect.top,
               client_rect.right - client_rect.left, client_rect.bottom - client_rect.top, TRUE);
         }
         break;

      case WM_USER:
         al_lock_mutex(textlog->tl_text_mutex);
         wlog_do_append_native_text_log(textlog);
         al_unlock_mutex(textlog->tl_text_mutex);
         break;
   }

   return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 14
0
// FUNCTIONS //////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd, 
						    UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT		ps;		// used in WM_PAINT
HDC				hdc;	// handle to a device context
char buffer[80];        // used to print strings

// what is the message 
switch(msg)
	{	
	case WM_CREATE: 
        {
		// do initialization stuff here
        // return success
		return(0);
		} break;

    case WM_COMMAND: // all buttons come thru here
         {
         // get the dc
         hdc = GetDC(hwnd);

         // set background mode
         SetBkMode(hdc,OPAQUE);

         // select a random text and background color
         SetTextColor(hdc,RGB(0,255,0));
         SetBkColor(hdc,RGB(128,128,128));

         // print out the wparam an lparam
         sprintf(buffer, "LOWORD(wparam) = %d, HIWORD(wparam) = %d                    ", 
                 LOWORD(wparam), HIWORD(wparam));

         // print text at a random location
         TextOut(hdc,220,100,buffer,strlen(buffer));           

         sprintf(buffer, "LOWORD(lparam) = 0X%X, HIWORD(lparam) = 0X%X                     ", 
                 LOWORD(lparam), HIWORD(lparam));

         // print text at a random location
         TextOut(hdc,220,140,buffer,strlen(buffer));      

         // release the dc
         ReleaseDC(hwnd, hdc);

         } break;
   
	case WM_PAINT: 
		{
		// simply validate the window 
   	    hdc = BeginPaint(hwnd,&ps);	 
        
        // end painting
        EndPaint(hwnd,&ps);

        // return success
		return(0);
   		} break;

	case WM_DESTROY: 
		{

		// kill the application, this sends a WM_QUIT message 
		PostQuitMessage(0);

        // return success
		return(0);
		} break;

	default:break;

    } // end switch

// process any messages that we didn't take care of 
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc
CommonPhraseMsgProc (
		HWND	hwnd, 
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{
    switch (uMsg) 
	{
		case WM_CONTEXTMENU:
		{
			char szHelpFile[MAX_PATH+1];

			GetHelpDir(szHelpFile);

			WinHelp ((HWND) wParam, szHelpFile, HELP_CONTEXTMENU, 
				(DWORD) (LPVOID) aIds); 
			return TRUE;
		}

		case WM_KEYUP:
		{
			SetCapsLockMessageState(GetParent(hwnd));
			break;
		}

//		case WM_RBUTTONDOWN :
//		case WM_CONTEXTMENU :
		case WM_LBUTTONDBLCLK :
		case WM_MOUSEMOVE :
		case WM_COPY :
		case WM_CUT :
		case WM_PASTE :
		case WM_CLEAR :
			return TRUE;

		case WM_LBUTTONDOWN :
			if (GetKeyState (VK_SHIFT) & 0x8000) return TRUE;
			break;

		case WM_PAINT :
		{
			GPP *gpp;

			gpp=(GPP *)GetWindowLong (GetParent(hwnd), GWL_USERDATA);

			if (wParam) 
			{
				SetBkColor ((HDC)wParam, GetSysColor (COLOR_WINDOW));
				if (gpp->bHideText) 
					SetTextColor ((HDC)wParam, GetSysColor (COLOR_WINDOW));
				else 
					SetTextColor ((HDC)wParam, GetSysColor (COLOR_WINDOWTEXT));
			}
			break; 
		}

		case WM_KEYDOWN :
			if (GetKeyState (VK_SHIFT) & 0x8000) 
			{
				switch (wParam) 
				{
					case VK_HOME :
					case VK_END :
					case VK_UP :
					case VK_DOWN :
					case VK_LEFT :
					case VK_RIGHT :
					case VK_NEXT :
					case VK_PRIOR :
						return TRUE;
				}
			}
			break;

		case WM_SETFOCUS :
			SendMessage (hwnd, EM_SETSEL, 0xFFFF, 0xFFFF);
			break;
	}
    return FALSE; 
} 
Ejemplo n.º 16
0
INT_PTR CALLBACK DlgProcAbout(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static int iState = 0;
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{	TCHAR filename[MAX_PATH], *productCopyright;
			DWORD unused;
			DWORD verInfoSize;
			UINT blockSize;
			PVOID pVerInfo;

			GetModuleFileName(NULL,filename,SIZEOF(filename));
			verInfoSize=GetFileVersionInfoSize(filename,&unused);
			pVerInfo=mir_alloc(verInfoSize);
			GetFileVersionInfo(filename,0,verInfoSize,pVerInfo);
			VerQueryValue(pVerInfo,_T("\\StringFileInfo\\000004b0\\LegalCopyright"),(LPVOID*)&productCopyright,&blockSize);
			SetDlgItemText(hwndDlg,IDC_DEVS,productCopyright);
			mir_free(pVerInfo);
		}
		{	char productVersion[56], *p;
            int isAnsi = 0;
			TCHAR str[64];
			CallService(MS_SYSTEM_GETVERSIONTEXT,SIZEOF(productVersion),(LPARAM)productVersion);
            // Hide Unicode from version text as it is assumed at this point
            p = strstr(productVersion, " Unicode"); 
			if (p)
				*p = '\0';
            else
                isAnsi = 1;
			mir_sntprintf(str,SIZEOF(str),_T(STR_VERSION_FORMAT), TranslateT("v"), productVersion, isAnsi?" ANSI":"");
            {
                TCHAR oldTitle[256], newTitle[256];
				GetDlgItemText( hwndDlg, IDC_HEADERBAR, oldTitle, SIZEOF( oldTitle ));
				mir_sntprintf( newTitle, SIZEOF(newTitle), oldTitle, str );
				SetDlgItemText( hwndDlg, IDC_HEADERBAR, newTitle );
			}
            
			mir_sntprintf(str,SIZEOF(str),TranslateT("Built %s %s"),_T(__DATE__),_T(__TIME__));
			SetDlgItemText(hwndDlg,IDC_BUILDTIME,str);
		}
		ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_HIDE);
		{	
			HRSRC   hResInfo  = FindResource(hMirandaInst,MAKEINTRESOURCE(IDR_CREDITS),_T("TEXT"));
			DWORD   ResSize   = SizeofResource(hMirandaInst,hResInfo);
			HGLOBAL hRes      = LoadResource(hMirandaInst,hResInfo);
			char*   pszMsg    = (char*)LockResource(hRes);
			if (pszMsg)
			{
				char* pszMsgt = (char*)alloca(ResSize + 1);
				memcpy(pszMsgt, pszMsg, ResSize); pszMsgt[ResSize] = 0;

				TCHAR *ptszMsg;
				if (ResSize >=3 && pszMsgt[0] == '\xef' && pszMsgt[1] == '\xbb' && pszMsgt[2] == '\xbf')
					ptszMsg = Utf8DecodeT(pszMsgt + 3);
				else
					ptszMsg = mir_a2t_cp(pszMsgt, 1252);

				SetDlgItemText(hwndDlg, IDC_CREDITSFILE, ptszMsg);
				UnlockResource(pszMsg);
				mir_free(ptszMsg);
			}
			FreeResource(hRes);
		}
		Window_SetIcon_IcoLib(hwndDlg, SKINICON_OTHER_MIRANDA);
		return TRUE;

	case WM_COMMAND:
		switch( LOWORD( wParam )) {
		case IDOK:
		case IDCANCEL:
			DestroyWindow(hwndDlg);
			return TRUE;
		case IDC_CONTRIBLINK:
			if (iState) {
				iState = 0;
				SetDlgItemText(hwndDlg, IDC_CONTRIBLINK, TranslateT("Credits >"));
				ShowWindow(GetDlgItem(hwndDlg, IDC_DEVS), SW_SHOW);
				ShowWindow(GetDlgItem(hwndDlg, IDC_BUILDTIME), SW_SHOW);
				ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_HIDE);
			}
			else {
				iState = 1;
				SetDlgItemText(hwndDlg, IDC_CONTRIBLINK, TranslateT("< Copyright"));
				ShowWindow(GetDlgItem(hwndDlg, IDC_DEVS), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_BUILDTIME), SW_HIDE);
				ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_SHOW);
			}
			break;
		}
		break;

	case WM_CTLCOLOREDIT:
	case WM_CTLCOLORSTATIC:
		switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) {
		case IDC_WHITERECT:
		case IDC_BUILDTIME:
		case IDC_CREDITSFILE:
		case IDC_DEVS:
			SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT));
			break;
		default:
			return FALSE;
      }
		SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
		return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);

	case WM_DESTROY:
		Window_FreeIcon_IcoLib( hwndDlg );
		{	
			HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_VERSION,WM_GETFONT,0,0);
			SendDlgItemMessage(hwndDlg,IDC_VERSION,WM_SETFONT,SendDlgItemMessage(hwndDlg,IDOK,WM_GETFONT,0,0),0);
			DeleteObject(hFont);				
		}
		break;
	}
	return FALSE;
}
Ejemplo n.º 17
0
STDMETHODIMP CShellExt::Extract(LPCTSTR /*pszFile*/, UINT /*nIconIndex*/, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize) {
	WORD sizeSmall = HIWORD(nIconSize);
	WORD sizeLarge = LOWORD(nIconSize);
	ICONINFO iconinfo;
	BOOL res;
	HRESULT hrSmall = S_OK, hrLarge = S_OK;

	if (phiconSmall)
		hrSmall = LoadShellIcon(sizeSmall, sizeSmall, phiconSmall);
	if (phiconLarge)
		hrLarge = LoadShellIcon(sizeLarge, sizeLarge, phiconLarge);

	if (FAILED(hrSmall) || FAILED(hrLarge)) {
		InvalidateIcon(phiconSmall, phiconLarge);
		return S_FALSE;
	}

	if (!m_isDynamic || !phiconLarge || sizeLarge < 32)	//No modifications required
		return S_OK;

	HDC dcEditColor, dcEditMask, dcEditTemp;
	HFONT font;
	HBRUSH brush;
	HPEN pen;
	BITMAPINFO bmi;
    HBITMAP hbm;
    LPDWORD pPix;

	res = GetIconInfo(*phiconLarge, &iconinfo);
	if (!res)
		return S_OK;	//abort, the icon is still valid

	res = DestroyIcon(*phiconLarge);
	if (!res)
		return S_OK;
	else
		*phiconLarge = NULL;

	dcEditColor = CreateCompatibleDC(GetDC(0));
	dcEditMask = CreateCompatibleDC(GetDC(0));
	dcEditTemp = CreateCompatibleDC(GetDC(0));

    // Create temp bitmap to render rectangle to
    ZeroMemory(&bmi, sizeof(bmi));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = sizeLarge;
    bmi.bmiHeader.biHeight = sizeLarge;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;
    hbm = CreateDIBSection(dcEditTemp, &bmi, DIB_RGB_COLORS, (VOID**)&pPix, NULL, 0);
    memset(pPix, 0x00FFFFFF, sizeof(DWORD)*sizeLarge*sizeLarge);	//initialize to white pixels, no alpha

	SelectObject(dcEditColor, iconinfo.hbmColor);
	SelectObject(dcEditMask, iconinfo.hbmMask);
	SelectObject(dcEditTemp, hbm);

	LONG calSize = (LONG)(sizeLarge*2/5);

	LOGFONT lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0}};
	lf.lfHeight = calSize;
	lf.lfWeight = FW_NORMAL;
	lf.lfCharSet = DEFAULT_CHARSET;
	lstrcpyn(lf.lfFaceName, TEXT("Courier New"), LF_FACESIZE);
	RECT rectText = {0, 0, 0, 0};
	RECT rectBox = {0, 0, 0, 0};
	COLORREF backGround = RGB(1, 1, 60);
	COLORREF textColor = RGB(250,250,250);

	font = CreateFontIndirect(&lf);
	brush = CreateSolidBrush(backGround);
	pen = CreatePen(PS_NULL, 0, backGround);
	SelectObject(dcEditTemp, font);
	SelectObject(dcEditTemp, brush);
	SelectObject(dcEditTemp, pen);
	SetBkMode(dcEditTemp, TRANSPARENT);	//dont clear background when drawing text
	SetBkColor(dcEditTemp,  backGround);
	SetTextColor(dcEditTemp, textColor);

	//Calculate size of the displayed string
	SIZE stringSize;
	GetTextExtentPoint32(dcEditTemp, m_szFilePath, m_nameLength, &stringSize);
	stringSize.cx = std::min(stringSize.cx, (LONG)sizeLarge-2);
	stringSize.cy = std::min(stringSize.cy, (LONG)sizeLarge-2);

	rectText.top = sizeLarge - stringSize.cy - 1;
	rectText.left = sizeLarge - stringSize.cx - 1;
	rectText.bottom = sizeLarge - 1;
	rectText.right = sizeLarge - 1;

	rectBox.top = sizeLarge - stringSize.cy - 2;
	rectBox.left = sizeLarge - stringSize.cx - 2;
	rectBox.bottom = sizeLarge;
	rectBox.right = sizeLarge;

	//Draw the background (rounded) rectangle
	int elipsSize = calSize/3;
	RoundRect(dcEditTemp, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize);
	//Draw text in the rectangle
	DrawText(dcEditTemp, m_szFilePath, m_nameLength, &rectText, DT_BOTTOM|DT_SINGLELINE|DT_LEFT);

	//set alpha of non white pixels back to 255
	//premultiply alpha
	//Fill in the mask bitmap (anything not 100% alpha is transparent)
	int red, green, blue, alpha;
	for(int y = 0; y < sizeLarge; y++) {
		for(int x = 0; x < sizeLarge; x++) {
			DWORD * pix = pPix+(y*sizeLarge+x);
			red = *pix & 0xFF;
			green = *pix >> 8 & 0xFF;
			blue = *pix >> 16 & 0xFF;
			alpha = *pix >> 24 & 0xFF;
			if ((*pix << 8) == 0xFFFFFF00)
				alpha = 0x00;
			else
				alpha = 0xFF;
			red = (red*alpha)/0xFF;
			green = (green*alpha)/0xFF;
			blue = (blue*alpha)/0xFF;
			*pix = RGBA(red, green, blue, alpha);
		}
	}

	BLENDFUNCTION ftn = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
	int width = rectBox.right - rectBox.left;
	int height = rectBox.bottom - rectBox.top;
	AlphaBlend(dcEditColor, rectBox.left, rectBox.top, stringSize.cx, stringSize.cy, dcEditTemp, rectBox.left, rectBox.top, width, height, ftn);

	//Adjust the mask image: simply draw the rectangle to it
	backGround = RGB(0, 0, 0);
	DeleteBrush(brush);
	DeletePen(pen);
	brush = CreateSolidBrush(backGround);
	pen = CreatePen(PS_NULL, 0, backGround);
	SelectObject(dcEditMask, brush);
	SelectObject(dcEditMask, pen);
	RoundRect(dcEditMask, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize);


	DeleteDC(dcEditColor);
	DeleteDC(dcEditMask);
	DeleteDC(dcEditTemp);
	DeleteBrush(brush);
	DeletePen(pen);
	DeleteFont(font);
	DeleteBitmap(hbm);

	*phiconLarge = CreateIconIndirect(&iconinfo);
	DeleteBitmap(iconinfo.hbmColor);
	DeleteBitmap(iconinfo.hbmMask);

	if (*phiconLarge == NULL) {
		InvalidateIcon(phiconSmall, phiconLarge);
		return S_FALSE;
	}

	return S_OK;
}
Ejemplo n.º 18
0
static void pbarOnDraw (HWND hwnd, HDC hdc, PROGRESSDATA* pData, BOOL fVertical)
{
    RECT    rcClient;
    int     x, y, w, h;
    ldiv_t   ndiv_progress;
    unsigned int     nAllPart;
    unsigned int     nNowPart;
    int     whOne, nRem;
    int     ix, iy;
    int     i;
    int     step;
    
    if (pData->nMax == pData->nMin)
        return;
    
    if ((pData->nMax - pData->nMin) > 5)
        step = 5;
    else
        step = 1;

    GetClientRect (hwnd, &rcClient);

    x = rcClient.left + WIDTH_PBAR_BORDER;
    y = rcClient.top + WIDTH_PBAR_BORDER;
    w = RECTW (rcClient) - (WIDTH_PBAR_BORDER << 1);
    h = RECTH (rcClient) - (WIDTH_PBAR_BORDER << 1);

    ndiv_progress = ldiv (pData->nMax - pData->nMin, step);
    nAllPart = ndiv_progress.quot;
    
    ndiv_progress = ldiv (pData->nPos - pData->nMin, step);
    nNowPart = ndiv_progress.quot;
    if (fVertical)
        ndiv_progress = ldiv (h, nAllPart);
    else
        ndiv_progress = ldiv (w, nAllPart);
        
    whOne = ndiv_progress.quot;
    nRem = ndiv_progress.rem;

    SetBrushColor (hdc, GetWindowElementColorEx (hwnd, BKC_HILIGHT_NORMAL));
 
    if (whOne >= 4) {
        if (fVertical) {
            for (i = 0, iy = y + h - 1; i < nNowPart; ++i) {
                if ((iy - whOne) < y) 
                    whOne = iy - y;

                FillBox (hdc, x + 1, iy - whOne, w - 2, whOne - 1);
                iy -= whOne;
                if(nRem > 0) {
                    iy --;
                    nRem --;
                }
            }
        }
        else {
            for (i = 0, ix = x + 1; i < nNowPart; ++i) {
                if ((ix + whOne) > (x + w)) 
                    whOne = x + w - ix;

                FillBox (hdc, ix, y + 1, whOne - 1, h - 2);
                ix += whOne;
                if(nRem > 0) {
                    ix ++;
                    nRem --;
                }
            }
        }
    }
    else {
        // no vertical support
        double d = (nNowPart*1.0)/nAllPart;

        if (fVertical) {
            int prog = (int)(h*d);

            FillBox (hdc, x + 1, rcClient.bottom - WIDTH_PBAR_BORDER - prog, 
                    w - 2, prog);
        }
        else {
            char szText[8];
            SIZE text_ext;
            RECT rc_clip = rcClient;
            int prog = (int)(w*d);

            FillBox (hdc, x, y + 1, (int)(w*d), h - 2);

            SetBkMode (hdc, BM_TRANSPARENT);
            sprintf (szText, "%.0f%%", (d*100));
            GetTextExtent (hdc, szText, -1, &text_ext);
            x += ((w - text_ext.cx) >> 1);
            y += ((h - text_ext.cy) >> 1);

            rc_clip.right = prog;
            SelectClipRect (hdc, &rc_clip);
            SetTextColor (hdc, GetWindowElementColorEx (hwnd, FGC_HILIGHT_NORMAL));
            SetBkColor (hdc, GetWindowElementColorEx (hwnd, BKC_HILIGHT_NORMAL));
            TextOut (hdc, x, y, szText);

            rc_clip.right = rcClient.right;
            rc_clip.left = prog;
            SelectClipRect (hdc, &rc_clip);
            SetTextColor (hdc, GetWindowElementColorEx (hwnd, FGC_CONTROL_NORMAL));
            SetBkColor (hdc, GetWindowBkColor (hwnd));
            TextOut (hdc, x, y, szText);
        }
    }
}
Ejemplo n.º 19
0
void draw_speller(SPELLEROBJ * st)
{
	PAINTSTRUCT ps;
	HDC hdc;
	char szdata[400];
	RECT rect;
	HBRUSH actbrush;
	int ballx,bally,i;

	
	GetClientRect(st->displayWnd, &rect);
	hdc = BeginPaint (st->displayWnd, &ps);


	//ballx=(int) ((rect.right/100.0f)*st->xpos);
	//bally=(int) ((rect.bottom/100.0f)*st->ypos);

	ballx=(int)st->xpos;
	bally=(int)st->ypos;
	
	actbrush=CreateSolidBrush(RGB(180,0,0));
    
   	SelectObject (hdc, DRAW.pen_white);		
   	SelectObject (hdc, DRAW.brush_ltgreen);
	Rectangle(hdc,0,0,rect.right,rect.bottom);

    SelectObject(hdc, DRAW.mediumFont);
	SetTextColor(hdc,RGB(255,0,0));

	SelectObject (hdc, DRAW.pen_red);	
	
    sprintf(szdata, "->  %s",st->word);  // st->selstart,st->selend,st->suggestions,
	DrawText(hdc, szdata, -1, &rect, DT_CENTER | DT_WORDBREAK );

	// sprintf(szdata, "PAD: %d SEL: %d",st->paddle,st->select); 
    // ExtTextOut( hdc, 10,10, 0, &rect,szdata, strlen(szdata), NULL ) ;

	for (i=0;i<st->selections;i++)
	{
		if ((st->dict[st->selstart+i].type==EXTEND_CHARACTERS) 
			||(st->dict[st->selstart+i].type==FINAL_CHARACTERS)
			||(st->dict[st->selstart+i].type==DICTIONARY))
			strcpy(szdata, st->dict[st->selstart+i].tag);
		else strcpy(szdata,"inv");
		
		if (i==st->select) { SetTextColor(hdc,RGB(255,0,0)); SetBkColor(hdc,RGB(255,255,0)); }
		else { SetTextColor(hdc,RGB(255,0,0)); SetBkColor(hdc,RGB(30,30,30)); }

		ExtTextOut( hdc, 100,80+i*30, 0, &rect,szdata, strlen(szdata), NULL ) ; 

		/*
		switch (i)
		{
			case 0:	ExtTextOut( hdc, 150,50, 0, &rect,szdata, strlen(szdata), NULL ) ; break;
			case 1:	ExtTextOut( hdc, 250,100, 0, &rect,szdata, strlen(szdata), NULL ) ; break;
			case 2:	ExtTextOut( hdc, 50,100, 0, &rect,szdata, strlen(szdata), NULL ) ; break;
			case 3:	ExtTextOut( hdc, 150,150, 0, &rect,szdata, strlen(szdata), NULL ) ; break;
		}
		*/
	}

	if (st->dictfile[0])
	{
		char fn[256];

		SelectObject(hdc, DRAW.scaleFont);
		SetTextColor(hdc,RGB(255,255,255));
		SetBkColor(hdc,RGB(0,0,50));
		reduce_filepath(fn,st->dictfile);
		sprintf(szdata,"Wörterbuch: %s, %d words.",fn, st->wordcount);
		ExtTextOut( hdc, 360, 70, 0, &rect,szdata, strlen(szdata), NULL );

		//ExtTextOut( hdc, 360, 80, 0, &rect,st->fn, strlen(st->fn), NULL );

	}
	if (st->suggestions)
	{
		SelectObject(hdc, st->sugfont);
		SetTextColor(hdc,RGB(255,255,0));
		SetBkColor(hdc,RGB(40,40,0));

		for (i=0;(i<st->suggestions);i++)
		{
			strcpy(szdata, st->dict[st->suggest[i]].tag);
			ExtTextOut( hdc, 360,100+i*20, 0, &rect,szdata, strlen(szdata), NULL );
		}
		if (i==MAX_SUGGEST)
		{
			strcpy(szdata, "(...)");
			ExtTextOut( hdc, 360,100+i*20, 0, &rect,szdata, strlen(szdata), NULL );
		}

	}
   	SelectObject (hdc, DRAW.brush_orange);
//	Rectangle(hdc,ballx,bally,ballx+20,bally+20);

   
	DeleteObject(actbrush);
	EndPaint( st->displayWnd, &ps );
}
Ejemplo n.º 20
0
long FAR PASCAL _export WndProc (HWND hwnd,
                                 UINT message,
                                 UINT wParam,
                                 LONG lParam)
   {
   static char    szTop[]     = "message            wParam    lParam",
                  szUnd[]     = "_______            ______    ______",
                  szFormat[]  = "%-16s%6X%8X-%04X",
                  szBuffer[50];
   static HWND    hwndButton[BUTTON_CNT];
   static RECT    rect;
   static int     cxChar, 
                  cyChar;
   HDC            hdc;
   PAINTSTRUCT    ps;
   int            i;
   static int     checkbox_state=0;                
   static int     three_state_state = 0;
   TEXTMETRIC     tm;

                  
//   TRACE_STR("ENTER WndProc");
   switch(message)
      {
//      case WM_CTLCOLOR :
//         {
//
//
//         
//         return 0;
//         }
      case WM_CREATE:
         {
         hdc = GetDC(hwnd);
         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
         GetTextMetrics(hdc,&tm);
         cxChar = tm.tmAveCharWidth;
         cyChar = tm.tmHeight + tm.tmExternalLeading;
         ReleaseDC(hwnd,hdc);

         for(i = PUSHBUTTON_ID ; i <= OWNERDRAW_ID; i++)
            {
            hwndButton [i] = 
               // create some buttons...
               CreateWindow("button",
                            button[i].text,
                            WS_CHILD | WS_VISIBLE | button[i].style,
                            cxChar,
                            cyChar * (1 + (2 * i)),
                            20 * cxChar, 
                            7 * cyChar / 4,
                            hwnd,
                            i,
                            // since lParam is a Long pointer to the creation 
                            // structure, get the hInstance out so that this
                            // window properly points to its Parent...
                            ((LPCREATESTRUCT) lParam) -> hInstance,
                            NULL);
            }
         return 0;   
         }
      case WM_SIZE :
         {
         rect.left = 24 * cxChar;
         rect.top = 2 * cyChar;
         rect.right = LOWORD(lParam);
         rect.bottom = HIWORD(lParam);
         return 0;
         }
      case WM_PAINT :
         {
         InvalidateRect(hwnd, &rect, TRUE);
         
         hdc = BeginPaint(hwnd,&ps);
         
         // Default to windows stuff.
         SetBkColor(hdc,GetSysColor(COLOR_WINDOW));
         SetTextColor(hdc,GetSysColor(COLOR_WINDOWTEXT));
         
         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
         SetBkMode(hdc,TRANSPARENT);

         TextOut( hdc, 
                  24*cxChar,
                  cyChar,
                  szTop,
                  sizeof szTop - 1);
         TextOut( hdc,
                  24*cxChar,
                  cyChar,
                  szUnd,
                  sizeof szUnd - 1);
                           
         EndPaint(hwnd,&ps);
         return 0;
         }
      case WM_COMMAND :
      case WM_DRAWITEM :
         {
         ScrollWindow(hwnd,
                      0,
                      -cyChar,
                      &rect,
                      &rect);
         hdc = GetDC(hwnd);
         
         SetBkColor(hdc,GetSysColor(COLOR_WINDOW));
         SetTextColor(hdc,GetSysColor(COLOR_WINDOWTEXT));
         
         SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));
         TextOut(hdc, 
                 24*cxChar,
                 cyChar * (rect.bottom/cyChar-1),
                 szBuffer,
                 wsprintf(szBuffer,
                          szFormat,
                          (LPSTR) (message==WM_COMMAND ? "WM_COMMAND" : "WM_DRAWITEM"),
                          wParam,            //Child Window ID
                          HIWORD(lParam),    // Child Window Handle
                          LOWORD(lParam)));  // Notification Code
         // Extreee stuff to do...                 
         if (wParam == PUSHBUTTON_ID)
            {
            // Show DEFPUSHBUTTON as pressed
            SendMessage(hwndButton[DEFPUSHBUTTON_ID],BM_SETSTATE,1,0L);
            // Change text of button
            SetWindowText(hwndButton[DEFPUSHBUTTON_ID],"F**K YOU");
            // Show it as disabled
            EnableWindow(hwndButton[DEFPUSHBUTTON_ID],FALSE);
            }
         if (wParam == CHECKBOX_ID)
            {
            // change checkbox state...
            checkbox_state ^= 1;
            SendMessage(hwndButton[CHECKBOX_ID],BM_SETCHECK,checkbox_state,0L);
            
            // do our goofy fun-ness..
            // re-enable button
            EnableWindow(hwndButton[DEFPUSHBUTTON_ID],TRUE);
            // Show DEFPUSHBUTTON as not pressed
            SendMessage(hwndButton[DEFPUSHBUTTON_ID],BM_SETSTATE,0,0L);
            // set text to default text...
            SetWindowText(hwndButton[DEFPUSHBUTTON_ID],button[DEFPUSHBUTTON_ID].text);

            }                                                      
         if (wParam == RADIOBUTTON_ID)
            {
            // change checkbox state...
            
            SendMessage(hwndButton[RADIOBUTTON_ID],BM_SETCHECK,1,0L);
            
            }
         if (wParam == BUTTON_3STATE_ID)
            {
            // change checkbox state...
            three_state_state = (++three_state_state) % 3;
            
            SendMessage(hwndButton[BUTTON_3STATE_ID],BM_SETCHECK,three_state_state,0L);
            
            }
         ReleaseDC(hwnd,hdc);
         ValidateRect(hwnd,NULL);                

         return 0;
         }
         
      case WM_DESTROY :
         {
         // insert a WM_QUIT in the queue...
         TRACE_STR("WM_DESTROY..");
         PostQuitMessage (0);
         TRACE_STR("EXIT WndProc");
         return 0;            
         }
      }//switch
//   TRACE_STR("EXIT WndProc");
   // *********************extremely important!!! ******************      
   // **                   extremely important!!!                 **
   // **                   extremely important!!!                 **
   return DefWindowProc (hwnd, message, wParam, lParam);            
   // **                   extremely important!!!                 **
   // **                   extremely important!!!                 **
   // *********************extremely important!!! ******************      
   } //WndProc
Ejemplo n.º 21
0
LRESULT CALLBACK mypluginwindow1proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	RECT rect;
	MEASUREITEMSTRUCT *mis;
	LPDRAWITEMSTRUCT dis;
	LISTITEM *pItemData;
	SIZE textSize;
	RECT r;
	LPARAM lp;
	int sel;
	HFONT oldFont;
	//PAINTSTRUCT ps;

	switch(msg)
	{
		
	case WM_MEASUREITEM:
		{
			mis = (MEASUREITEMSTRUCT *)lParam;
			mis->itemWidth = 100;
			mis->itemHeight = DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON));
			return TRUE;
		}
		
	case WM_DRAWITEM:
		dis = (LPDRAWITEMSTRUCT)lParam;
		//pItemData = (LISTITEM *)dis->itemData;
		if(dis->hwndItem == label) {
			HBRUSH ttbrush = 0;
			RECT r;
			COLORREF tcol;
			//GetClientRect(dis->hwndItem, &r);
			GetClientRect(hwnd, &r);
			if(dis->itemID != -1) {

				oldFont = (HFONT)SelectObject(dis->hDC, ContactFont);
				GetTextExtentPoint32(dis->hDC,_T("X"),1,&textSize);
				SendMessage(label, LB_SETITEMHEIGHT, 0, (LPARAM)DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON)));
				// stop full list erase
				//dis->rcItem.bottom = dis->rcItem.top + DBGetContactSettingWord(NULL, "WorldTime", "RowHeight",GetSystemMetrics(SM_CYSMICON));

				if(dis->itemState & ODS_SELECTED && dis->itemState & ODS_FOCUS) {

					if(ServiceExists(MS_SKIN_DRAWGLYPH)) {
						if(FrameIsFloating()) {
							//SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "Main Window/Backgrnd");
							SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Selection Background");
						} else {
							//SkinDrawWindowBack(label, dis->hDC, &dis->rcItem, "Main Window/Backgrnd");
							SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Selection Background");
						}
					} else {
						tcol = DBGetContactSettingDword(NULL,"CLC","SelBkColour", CLCDEFAULT_SELBKCOLOUR);
						SetBkColor(dis->hDC, tcol);
						FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol)));
					}
					
					tcol = DBGetContactSettingDword(NULL,"CLC","SelTextColour", CLCDEFAULT_SELTEXTCOLOUR);
					SetTextColor(dis->hDC, tcol);
				} else {
					
					if(ServiceExists(MS_SKIN_DRAWGLYPH)) {
						
						if(FrameIsFloating()) {
							//SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "Main Window/Backgrnd");
							SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background");
						} else {
							//SkinDrawWindowBack(label, dis->hDC, &dis->rcItem, "Main Window/Backgrnd");
							SkinDrawGlyph(dis->hDC, &r, &dis->rcItem, "World Time/Background");
						}
						
					} else {
						//tcol = DBGetContactSettingDword(NULL,"CLC","BkColour", CLCDEFAULT_BKCOLOUR);
						tcol = DBGetContactSettingDword(NULL, "WorldTime", "BgColour", GetSysColor(COLOR_3DFACE));
						SetBkColor(dis->hDC, tcol);
						FillRect(dis->hDC, &dis->rcItem, (ttbrush = CreateSolidBrush(tcol)));
					}
					
					//SendMessage(label, LB_GETITEMRECT, (WPARAM)dis->itemID, (LPARAM)&r);
					//FillRect(dis->hDC, &r, (ttbrush = CreateSolidBrush(tcol)));

					tcol = ContactFontColour;					
					SetTextColor(dis->hDC, tcol);
				}				
				
				SetBkMode(dis->hDC, TRANSPARENT);
				pItemData = &listbox_items[dis->itemID];
				{

					dis->rcItem.left += DBGetContactSettingWord(NULL, "WorldTime", "Indent", 0);
					if(show_icons) {
						//DrawIconEx(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-GetSystemMetrics(SM_CYSMICON))>>1, pItemData->icon, GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
						DrawIconEx(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-16)>>1, pItemData->icon, 0, 0, 0, NULL, DI_NORMAL);
			
						GetTextExtentPoint32(dis->hDC,pItemData->pszText,lstrlen(pItemData->pszText),&textSize);
						TextOut(dis->hDC,dis->rcItem.left + 16 + 4,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszText,lstrlen(pItemData->pszText));
					} else {
						GetTextExtentPoint32(dis->hDC,pItemData->pszText,lstrlen(pItemData->pszText),&textSize);
						TextOut(dis->hDC,dis->rcItem.left,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszText,lstrlen(pItemData->pszText));
					}

					GetTextExtentPoint32(dis->hDC,pItemData->pszTimeText,lstrlen(pItemData->pszTimeText),&textSize);
					TextOut(dis->hDC,dis->rcItem.right - textSize.cx - 2,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszTimeText,lstrlen(pItemData->pszTimeText));

					if(set_format) {
						int xSave = textSize.cx;

						GetTextExtentPoint32(dis->hDC,pItemData->pszDateText,lstrlen(pItemData->pszDateText),&textSize);
						TextOut(dis->hDC,dis->rcItem.right - textSize.cx - xSave - 4,(dis->rcItem.top+dis->rcItem.bottom-textSize.cy)>>1,pItemData->pszDateText,lstrlen(pItemData->pszDateText));
					}
				}

				SetBkMode(dis->hDC, OPAQUE);
				SelectObject(dis->hDC, oldFont);
			} else {
Ejemplo n.º 22
0
void FillSolidRect(HDC hDC, LPCRECT lpRect, COLORREF clr)
{
    SetBkColor(hDC, clr);
    ExtTextOutW(hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
}
Ejemplo n.º 23
0
INT_PTR CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
	switch (message){
    case WM_INITDIALOG: {
        CenterDialog(hDlg);
        
        //Fill the drop-down boxes
        HWND hBox = GetDlgItem(hDlg, IDC_NA_TYPE);
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"FAR");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"DBPF");
        SendMessage(hBox, CB_SETCURSEL, 0, 0);
        hBox = GetDlgItem(hDlg, IDC_NA_FARVERSION);
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"1a");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"1b");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"3");
        SendMessage(hBox, CB_SETCURSEL, 0, 0);
        hBox = GetDlgItem(hDlg, IDC_NA_DBPFVERSION);
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"1.0");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"1.1");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"2.0");
        SendMessage(hBox, CB_SETCURSEL, 0, 0);
        hBox = GetDlgItem(hDlg, IDC_NA_INDEXVERSION);
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"7.0");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"7.1");
        SendMessage(hBox, CB_INSERTSTRING, -1, (LPARAM) L"3.0");
        SendMessage(hBox, CB_SETCURSEL, 0, 0);
        
        //Create the tooltips
        HWND FARInfo = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
			WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP,
			CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, CW_USEDEFAULT,
			hDlg, NULL, hInst, NULL),
		DBPFInfo = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
			WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP,
			CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, CW_USEDEFAULT,
			hDlg, NULL, hInst, NULL);
        
        TOOLINFO tinfo = {
            sizeof(TOOLINFO),            //cbSize
            TTF_IDISHWND | TTF_SUBCLASS, //uFlags
            hDlg,                        //hwnd
            0,                           //uId
            NULL,                        //rect
            0                            //hinst
        };
        
        tinfo.uId = (UINT_PTR) GetDlgItem(hDlg, IDC_NA_FARINFO);
        tinfo.lpszText = (wchar_t*)
            L"FAR version 1a is found in The Sims 1.\r\n\r\n"
            L"Version 1b appears to be a mistake, in which it was intended to take on the version number 2.\r\n\r\n"
            L"1b and 3 are both found exclusively in The Sims Online.";
        SendMessage(FARInfo, TTM_SETMAXTIPWIDTH, 2000, 200);
		SendMessage(FARInfo, TTM_SETTITLE, TTI_INFO_LARGE, (LPARAM) L"FAR version");
		SendMessage(FARInfo, TTM_ADDTOOL, 0, (LPARAM) &tinfo);
        SendMessage(FARInfo, TTM_SETDELAYTIME, TTDT_AUTOPOP, 12000);
        tinfo.uId = (UINT_PTR) GetDlgItem(hDlg, IDC_NA_DBPFINFO);
        tinfo.lpszText = (wchar_t*)
            L"DBPF version numbers can be shortened to the form a.b;ix,y, where "
            L"a.b is the Archive version and x.y is the Index version.\r\n\r\n"
            L"DBPF 1.0;i7.0 is found in The Sims Online and SimCity 4.\r\n\r\n"
            L"1.0;i7.0 and 1.1;i7.1 are found in The Sims 2.\r\n\r\n"
            L"2.0;i3.0 is found in Spore.";
        SendMessage(DBPFInfo, TTM_SETMAXTIPWIDTH, 2000, 200);
		SendMessage(DBPFInfo, TTM_SETTITLE, TTI_INFO_LARGE, (LPARAM) L"DBPF version");
		SendMessage(DBPFInfo, TTM_ADDTOOL, 0, (LPARAM) &tinfo);
        SendMessage(DBPFInfo, TTM_SETDELAYTIME, TTDT_AUTOPOP, 20000);
        
        SetType(hDlg, TYPE_FAR);
        } return TRUE;
    case WM_CTLCOLORSTATIC:
		if((HWND) lParam == GetDlgItem(hDlg, IDC_NA_TYPETEXT)){
			SetBkColor((HDC) wParam, GetSysColor(COLOR_WINDOW));
			return (INT_PTR) GetSysColorBrush(COLOR_WINDOW);
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam)){
        case IDC_NA_TYPE:
            if(HIWORD(wParam) == CBN_SELCHANGE)
                SetType(hDlg, SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0));
            break;
        case IDOK:
            Archive::IsOpen = true;
            Archive::IsModified = true;
            
            Archive::Path[0] = '\0'; //No actual path
            wcscpy(Archive::Filename, L"Untitled");
            Archive::SetWorkspace();
            
            EndDialog(hDlg, 0);
        case IDCANCEL:
            EndDialog(hDlg, 0);
        } break;
    case WM_CLOSE:
		EndDialog(hDlg, 0);
    }
    return 0;
}
Ejemplo n.º 24
0
void rect_draw_some_item(HBITMAP src,RECT src_rect,HBITMAP dest,RECT dest_rect,
	short trans, short main_win) {
	HDC hdcMem,hdcMem2,hdcMem3,destDC;
	HBITMAP transbmp;
	COLORREF white = RGB(255,255,255),oldcolor;

	HBRUSH hbrush,old_brush;
	UINT c;
	HBITMAP store,store2;
	Boolean dlog_draw = FALSE;

	if (main_win == 2) {
		destDC = (HDC) dest;
		main_win = 1;
		dlog_draw = TRUE;
		hdcMem = CreateCompatibleDC(destDC);
		SelectObject(hdcMem, src);
		SetMapMode(hdcMem,GetMapMode((HDC) mainPtr));
		//SelectPalette(hdcMem,hpal,0);
		}
		else {
			destDC = main_dc;
			hdcMem = main_dc2;
			store = (HBITMAP) SelectObject(hdcMem,src);
			}

	if (trans != 1) {
		if (main_win == 0) { // Not transparent, into bitmap
			hdcMem2 = main_dc3;
			store2 = (HBITMAP) SelectObject(hdcMem2, dest);
			StretchBlt(hdcMem2,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,(trans >= 0) ? SRCCOPY : SRCAND);
			SelectObject(hdcMem2,store2);
			}

		else { // Not transparent, onto screen
		if (trans == 2) {
			//c = GetNearestPaletteIndex(hpal,x);
			hbrush = CreateSolidBrush(PALETTEINDEX(c));
			old_brush = (HBRUSH) SelectObject(destDC,hbrush);

			}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,ulx,uly, NULL);

		StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,(trans == 0) ? SRCCOPY : PATCOPY);
			if (trans == 2) {
				SelectObject(destDC,old_brush);
				if (DeleteObject(hbrush) == 0)
					play_sound(1);
				}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,0,0,NULL);


		}
		} // end of non-transparent draws
		else {
		if (main_win == 0) {
			hdcMem3 = CreateCompatibleDC(hdcMem);
			SelectObject(hdcMem3, dest);
			SetMapMode(hdcMem3,GetMapMode((HDC) mainPtr));
			//SelectPalette(hdcMem3,hpal,0);
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
		hdcMem2 = CreateCompatibleDC(destDC);
		SelectObject(hdcMem2, transbmp);
		oldcolor = SetBkColor(hdcMem, white);
		StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCCOPY);
		SetBkColor(hdcMem, oldcolor);

		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem2,0,0,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCAND);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		DeleteDC(hdcMem3);
		DeleteDC(hdcMem2);

			DeleteObject(transbmp);
		}
		else {
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,ulx,uly,NULL);
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
			hdcMem2 = CreateCompatibleDC(destDC);
			SelectObject(hdcMem2, transbmp);
			oldcolor = SetBkColor(hdcMem, white);
			StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCCOPY);

			SetBkColor(hdcMem, oldcolor);

			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem2,0,0,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCAND);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,0,0,NULL);
			DeleteDC(hdcMem2);

				DeleteObject(transbmp);


			}
			}
	if (dlog_draw == TRUE)
		DeleteDC(hdcMem);
		else SelectObject(hdcMem,store);
}
Ejemplo n.º 25
0
void DisplayCandStrings( 
    HWND hwnd, 
    LPCANDIDATELIST lpCandList )
{

    HDC         hdc;            // Storage for device context handle.
    LPSTR       lpStr;          // Storage for LP to a string.
    DWORD       dwNumPerPage;   // Storage for num per page
    DWORD       dwStartIndex;   // Storage for candidate index
    DWORD       dwEndIndex;     // Storage for candidate index
    RECT        rect;           // Storage for client rect.
    int         y = 0;          // 
    DWORD       dwBackColor;    // Storage for background color value
    DWORD       dwTextColor;

    //
    // Determine how many candidate strings per page.
    //

    dwNumPerPage = ( !lpCandList->dwPageSize ) ?
                     DEFAULT_CAND_NUM_PER_PAGE :
                     lpCandList->dwPageSize;

    //
    // Determine the dwStartIndex from which the candidate string will
    // start displaying.
    //

    dwStartIndex = lpCandList->dwPageStart;

    //
    // Determine the dwEndIndex which indicate the last candidate string
    // will be displayed.
    //

    dwEndIndex = dwStartIndex + dwNumPerPage;

    dwEndIndex = ( dwEndIndex >= lpCandList->dwCount ) ?
                 lpCandList->dwCount : dwEndIndex;
                 
    
    //
    // Dissplay candidate strings.
    // First paint background color.
    //

    hdc = GetDC( hwnd );

    dwBackColor = SetBkColor( hdc, RGB( 0xbf, 0xbf, 0xbf ) );

    GetClientRect( hwnd, &rect );

    ExtTextOut( hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, 0 );


    //
    // Set background color of selected candidate string to be blue.
    //

    rect.top = rect.top + 
               ( lpCandList->dwSelection - dwStartIndex ) * cyMetrics;

    rect.bottom = rect.top + cyMetrics;

    SetBkColor( hdc,RGB( 0x00, 0x00, 0xff ) );

    ExtTextOut( hdc, 0, rect.top, ETO_OPAQUE, &rect, NULL, 0, 0 );

    //
    // Display candidate strings. 
    //

    SetBkMode( hdc, TRANSPARENT );

    dwTextColor = GetTextColor( hdc );

    for ( ; dwStartIndex < dwEndIndex; dwStartIndex++, y++ )
    {

        lpStr = (LPSTR) lpCandList +
                lpCandList->dwOffset[ dwStartIndex ];

        if ( dwStartIndex == lpCandList->dwSelection )
            SetTextColor( hdc, RGB( 255, 255, 255 ) );
        else
            SetTextColor( hdc, dwTextColor );

        TextOut( hdc, 3, y * cyMetrics, lpStr, lstrlen( lpStr ) );
    }


    SetTextColor( hdc, dwTextColor );
    
    SetBkColor( hdc, dwBackColor );

    ReleaseDC( hwnd, hdc );

}
Ejemplo n.º 26
0
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initializes device-dependent objects, including the vertex buffer used
//       for rendering text and the texture map which stores the font image.
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE8 pd3dDevice )
{
    HRESULT hr;

    // Keep a local copy of the device
    m_pd3dDevice = pd3dDevice;

    // Establish the font and texture size
    m_fTextScale  = 1.0f; // Draw fonts into texture without scaling

    // Large fonts need larger textures
    if( m_dwFontHeight > 40 )
        m_dwTexWidth = m_dwTexHeight = 1024;
    else if( m_dwFontHeight > 20 )
        m_dwTexWidth = m_dwTexHeight = 512;
    else
        m_dwTexWidth  = m_dwTexHeight = 256;

    // If requested texture is too big, use a smaller texture and smaller font,
    // and scale up when rendering.
    D3DCAPS8 d3dCaps;
    m_pd3dDevice->GetDeviceCaps( &d3dCaps );

    if( m_dwTexWidth > d3dCaps.MaxTextureWidth )
    {
        m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
        m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
    }

    // Create a new texture for the font
    hr = m_pd3dDevice->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1,
                                      0, D3DFMT_A4R4G4B4,
                                      D3DPOOL_MANAGED, &m_pTexture );
    if( FAILED(hr) )
        return hr;

    // Prepare to create a bitmap
    DWORD*      pBitmapBits;
    BITMAPINFO bmi;
    ZeroMemory( &bmi.bmiHeader,  sizeof(BITMAPINFOHEADER) );
    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth       =  (int)m_dwTexWidth;
    bmi.bmiHeader.biHeight      = -(int)m_dwTexHeight;
    bmi.bmiHeader.biPlanes      = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biBitCount    = 32;

    // Create a DC and a bitmap for the font
    HDC     hDC       = CreateCompatibleDC( NULL );
    HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
                                          (VOID**)&pBitmapBits, NULL, 0 );
    SetMapMode( hDC, MM_TEXT );

    // Create a font.  By specifying ANTIALIASED_QUALITY, we might get an
    // antialiased font, but this is not guaranteed.
    INT nHeight    = -MulDiv( m_dwFontHeight, 
        (INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
    DWORD dwBold   = (m_dwFontFlags&D3DFONT_BOLD)   ? FW_BOLD : FW_NORMAL;
    DWORD dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE    : FALSE;
    HFONT hFont    = CreateFont( nHeight, 0, 0, 0, dwBold, dwItalic,
                          FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
                          CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
                          VARIABLE_PITCH, m_strFontName );
    if( NULL==hFont )
        return E_FAIL;

    SelectObject( hDC, hbmBitmap );
    SelectObject( hDC, hFont );

    // Set text properties
    SetTextColor( hDC, RGB(255,255,255) );
    SetBkColor(   hDC, 0x00000000 );
    SetTextAlign( hDC, TA_TOP );

    // Loop through all printable character and output them to the bitmap..
    // Meanwhile, keep track of the corresponding tex coords for each character.
    DWORD x = 0;
    DWORD y = 0;
    TCHAR str[2] = _T("x");
    SIZE size;

    for( TCHAR c=32; c<127; c++ )
    {
        str[0] = c;
        GetTextExtentPoint32( hDC, str, 1, &size );

        if( (DWORD)(x+size.cx+1) > m_dwTexWidth )
        {
            x  = 0;
            y += size.cy+1;
        }

        ExtTextOut( hDC, x+0, y+0, ETO_OPAQUE, NULL, str, 1, NULL );

        m_fTexCoords[c-32][0] = ((FLOAT)(x+0))/m_dwTexWidth;
        m_fTexCoords[c-32][1] = ((FLOAT)(y+0))/m_dwTexHeight;
        m_fTexCoords[c-32][2] = ((FLOAT)(x+0+size.cx))/m_dwTexWidth;
        m_fTexCoords[c-32][3] = ((FLOAT)(y+0+size.cy))/m_dwTexHeight;

        x += size.cx+1;
    }

    // Lock the surface and write the alpha values for the set pixels
    D3DLOCKED_RECT d3dlr;
    m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
    BYTE* pDstRow = (BYTE*)d3dlr.pBits;
    WORD* pDst16;
    BYTE bAlpha; // 4-bit measure of pixel intensity

    for( y=0; y < m_dwTexHeight; y++ )
    {
        pDst16 = (WORD*)pDstRow;
        for( x=0; x < m_dwTexWidth; x++ )
        {
            bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
            if (bAlpha > 0)
            {
                *pDst16++ = (bAlpha << 12) | 0x0fff;
            }
            else
            {
                *pDst16++ = 0x0000;
            }
        }
        pDstRow += d3dlr.Pitch;
    }

    // Done updating texture, so clean up used objects
    m_pTexture->UnlockRect(0);
    DeleteObject( hbmBitmap );
    DeleteDC( hDC );
    DeleteObject( hFont );

    return S_OK;
}
Ejemplo n.º 27
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  long wdata;

  switch (message)
    {

    case WM_ERASEBKGND:
      return TRUE; // JMW trying to reduce screen flicker
      break;
    case WM_COMMAND:
      return MainMenu(hWnd, message, wParam, lParam);
      break;
    case WM_CTLCOLORSTATIC:
      wdata = GetWindowLong((HWND)lParam, GWL_USERDATA);
      switch(wdata) {
      case 0:
        SetBkColor((HDC)wParam, ColorUnselected);
        SetTextColor((HDC)wParam, RGB(0x00,0x00,0x00));
        return (LRESULT)hBrushUnselected;
      case 1:
        SetBkColor((HDC)wParam, ColorSelected);
        SetTextColor((HDC)wParam, RGB(0x00,0x00,0x00));
        return (LRESULT)hBrushSelected;
      case 2:
	SetBkColor((HDC)wParam, ColorUnselected);
        SetTextColor((HDC)wParam, ColorWarning);
	return (LRESULT)hBrushUnselected;
      case 3:
	SetBkColor((HDC)wParam, ColorUnselected);
        SetTextColor((HDC)wParam, ColorOK);
	return (LRESULT)hBrushUnselected;
      case 4:
	// black on light green
        SetTextColor((HDC)wParam, RGB_BLACK); 
	SetBkColor((HDC)wParam, ColorButton);
	return (LRESULT)hBrushButton;
      case 5:
	// grey on light green
	SetBkColor((HDC)wParam, ColorButton);
        SetTextColor((HDC)wParam, RGB(0x80,0x80,0x80));
	return (LRESULT)hBrushButton;
#ifdef LXMINIMAP
      case 6:
        // black on dark yellow
        SetTextColor((HDC)wParam, RGB_BLACK);
        SetBkColor((HDC)wParam, ColorButtonHasFocus);
        return (LRESULT)hBrushButtonHasFocus;
      case 7:
        // grey on dark yellow
        SetTextColor((HDC)wParam, RGB(0x80,0x80,0x80));
        SetBkColor((HDC)wParam, ColorButtonHasFocus);
        return (LRESULT)hBrushButtonHasFocus;
#endif

      }
      break;
    case WM_CREATE:
#ifdef HAVE_ACTIVATE_INFO
      memset (&s_sai, 0, sizeof (s_sai));
      s_sai.cbSize = sizeof (s_sai);
#endif
      if (iTimerID == 0) {
        iTimerID = SetTimer(hWnd,1000,500,NULL); // 500ms  2 times per second
      }

      break;

    case WM_ACTIVATE:

      if(LOWORD(wParam) != WA_INACTIVE)
        {
          SetWindowPos(hWndMainWindow,HWND_TOP,
                 0, 0, 0, 0,
                 SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE);

#ifdef HAVE_ACTIVATE_INFO
         SHFullScreen(hWndMainWindow,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON|SHFS_HIDESTARTICON);
#endif

        }
#ifdef HAVE_ACTIVATE_INFO
      if (api_has_SHHandleWMActivate) {
        SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
      } else {
        #ifdef TESTBENCH
        StartupStore(TEXT("... SHHandleWMActivate not available%s"),NEWLINE);
        #endif
        return DefWindowProc(hWnd, message, wParam, lParam);
      }
#endif
      break;

    case WM_SETTINGCHANGE:
#ifdef HAVE_ACTIVATE_INFO
      if (api_has_SHHandleWMSettingChange) {
        SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
      } else {
        #ifdef TESTBENCH
        StartupStore(TEXT("... SHHandleWMSettingChange not available%s"),NEWLINE);
        #endif
        return DefWindowProc(hWnd, message, wParam, lParam);
      }
#endif
      break;

	#if DEBUG_FOCUS
    case WM_KILLFOCUS:
	// This is happening when focus is given to another window, either internally inside LK
	// or externally, for example to explorer..
	// SO: if we select MapWindow, we get here a KILLFOCUS from it.
	// When we select another process/program, or click on the desktop, the old window having focus is
	// receiving KILLFOCUS. So in case MapWindow was working, the signal will be sent over there, not here.
	// 
	StartupStore(_T("............ WNDPROC LOST FOCUS (KILLFOCUS)\n"));
	break;
	#endif

    case WM_SETFOCUS:
	// When explorer/desktop is giving focus to LK, this is where we get the signal.
	// But we must return focus to previous windows otherwise keys will not be working.
	// Mouse is another story, because mouse click is pertinent to a screen area which is mapped.
	// A mouse click will be sent to the window in the background, whose handler will receive the event.
	//
	// Each event handler receiving focus has to save it in hWndWithFocus, in LK.
	// Each event handler must thus handle SETFOCUS!
	//
	#if DEBUG_FOCUS
	StartupStore(_T("............ WNDPROC HAS FOCUS  (SETFOCUS)\n"));
	if (hWndWithFocus==NULL)
		StartupStore(_T(".....(no Wnd to give focus to)\n"));
	else
		StartupStore(_T(".....(passing focus to other window)\n"));
	#endif
	if (hWndWithFocus!=NULL) SetFocus(hWndWithFocus);
      break;

    case WM_KEYUP:
      break;

    case WM_TIMER:
	// WM_TIMER is run at about 2hz.
	LKHearthBeats++; // 100213
      //      ASSERT(hWnd==hWndMainWindow);
      if (ProgramStarted > psInitInProgress) {
	if (SIMMODE)
		SIMProcessTimer();
	else
		ProcessTimer();
	if (ProgramStarted==psFirstDrawDone) {
	  AfterStartup();
	  ProgramStarted = psNormalOp;
          StartupStore(_T(". ProgramStarted=NormalOp %s%s"), WhatTimeIsIt(),NEWLINE);
          StartupLogFreeRamAndStorage();

	}
      }
      break;

    case WM_INITMENUPOPUP:
      if (ProgramStarted > psInitInProgress) {
	  CheckMenuItem((HMENU) wParam,IDM_FILE_LOCK,MF_CHECKED|MF_BYCOMMAND);
	
	if(LoggerActive)
	  CheckMenuItem((HMENU) wParam,IDM_FILE_LOGGER,MF_CHECKED|MF_BYCOMMAND);
	else
	  CheckMenuItem((HMENU) wParam,IDM_FILE_LOGGER,MF_UNCHECKED|MF_BYCOMMAND);
      }
      break;

    case WM_CLOSE:

      LKASSERT(hWnd==hWndMainWindow);
      if((hWnd==hWndMainWindow) && 
         (MessageBoxX(hWndMainWindow,
		// LKTOKEN  _@M198_ = "Confirm Exit?"
               	gettext(TEXT("_@M198_")),
                      TEXT("LK8000"),
                      MB_YESNO|MB_ICONQUESTION) == IDYES)) 
        {
          if(iTimerID) {
            KillTimer(hWnd,iTimerID);
            iTimerID = 0;
          }

          Shutdown();
        }
      break;

    case WM_DESTROY:
      if (hWnd==hWndMainWindow) {
        PostQuitMessage(0);
      }
      break;

#if TESTBENCH
    case WM_DEVICECHANGE:
	 TCHAR serr[50];
	 static WPARAM oldwparam=0;
	 StartupStore(_T("DEVICE CHANGE DETECTED, CODE=0x%x%s"),wParam,NEWLINE);

	 if (wParam!=oldwparam) {
		 oldwparam=wParam;
	 	wsprintf(serr,_T("DEVICE CHANGE DETECTED\nCODE=0x%x"),wParam);
        	 MessageBoxX(hWndMainWindow, serr, TEXT("LK8000"), MB_OK|MB_ICONQUESTION, true);
		 oldwparam=0;
	 }
	 return TRUE; // acknowledge
	 break;
#endif

    default:
      return DefWindowProc(hWnd, message, wParam, lParam);
    }
  return 0;
}
BOOL CALLBACK 
DoCommonCalls (
		HWND	hDlg, 
		UINT	uMsg, 
		WPARAM	wParam,
		LPARAM	lParam) 
{
	GPP *gpp;

	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			CPGPPassphraseDialogOptions *options;

			SetWindowLong (hDlg, GWL_USERDATA, lParam);
			gpp=(GPP *)lParam;

			options = (CPGPPassphraseDialogOptions *)gpp->options;

			if(options->mWindowTitle)
				SetWindowText(hDlg,options->mWindowTitle);

			if(options->mPrompt)
				SetDlgItemText (hDlg, IDC_PROMPTSTRING, options->mPrompt);

			gpp->bHideText = TRUE;
			CheckDlgButton (hDlg, IDC_HIDETYPING, BST_CHECKED);

			SetCapsLockMessageState(hDlg);

			SetForegroundWindow (hDlg);

			// Force focus to passphrase box
			SetFocus(GetDlgItem(hDlg, IDC_PHRASE1));
			break;
		}

		case WM_KEYUP:
		{
			SetCapsLockMessageState(hDlg);
			break;
		}

		case WM_HELP:
		{
			char szHelpFile[MAX_PATH+1];

			GetHelpDir(szHelpFile);

			WinHelp ((HWND)(((LPHELPINFO) lParam)->hItemHandle), szHelpFile, 
			 HELP_WM_HELP, (DWORD) (LPSTR) aIds); 
			break; 
		}

		case WM_CONTEXTMENU:
		{
			char szHelpFile[MAX_PATH+1];

			GetHelpDir(szHelpFile);

			WinHelp ((HWND) wParam, szHelpFile, HELP_CONTEXTMENU, 
				(DWORD) (LPVOID) aIds); 
			break; 
		}

		case WM_QUIT:
		case WM_CLOSE:
		case WM_DESTROY: 
		{
			HWND hwndPhrase1,hwndPhrase2;

			gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);

			ClearPassphrases(hDlg,gpp);

			hwndPhrase1=GetDlgItem(hDlg, IDC_PHRASE1);
			hwndPhrase2=GetDlgItem(hDlg, IDC_PHRASE2);

			if(hwndPhrase1)
			{
				SetWindowLong (hwndPhrase1,
					   GWL_WNDPROC, 
					   (LONG)gpp->wpOrigPhrase1Proc);
			}

			if(hwndPhrase2)
			{
				SetWindowLong (hwndPhrase2, 
					   GWL_WNDPROC, 
					   (LONG)gpp->wpOrigPhrase2Proc);
			}

			EndDialog(hDlg,kPGPError_UserAbort);
			break;
		}

		case WM_CTLCOLOREDIT:
		{
			HWND hwndPhrase1,hwndPhrase2;

			gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);

			hwndPhrase1=GetDlgItem(hDlg, IDC_PHRASE1);
			hwndPhrase2=GetDlgItem(hDlg, IDC_PHRASE2);

			if(lParam==0)
				break;

			if (((HWND)lParam == hwndPhrase1) ||
				((HWND)lParam == hwndPhrase2)) 
			{
				SetBkColor ((HDC)wParam, GetSysColor (COLOR_WINDOW));
				if (gpp->bHideText) 
					SetTextColor ((HDC)wParam, GetSysColor (COLOR_WINDOW));
				else 
					SetTextColor ((HDC)wParam, 
							  GetSysColor (COLOR_WINDOWTEXT));
				return (BOOL)CreateSolidBrush (GetSysColor (COLOR_WINDOW));
			}
			break;
		}

		case WM_COMMAND:
		{
			gpp=(GPP *)GetWindowLong (hDlg, GWL_USERDATA);

			switch(LOWORD (wParam)) 
			{
				case IDCANCEL:
					EndDialog (hDlg, kPGPError_UserAbort);
					break;

				case IDC_HIDETYPING :
				{
					HWND hwndPhrase1,hwndPhrase2;
	
					hwndPhrase1=GetDlgItem(hDlg, IDC_PHRASE1);
					hwndPhrase2=GetDlgItem(hDlg, IDC_PHRASE2);

					if (IsDlgButtonChecked (hDlg, IDC_HIDETYPING)
							== BST_CHECKED) 
						gpp->bHideText = TRUE;
					else 
						gpp->bHideText = FALSE;

					if(hwndPhrase1!=NULL)
						InvalidateRect (hwndPhrase1, NULL, TRUE);

					if(hwndPhrase2!=NULL)
						InvalidateRect (hwndPhrase2, NULL, TRUE);
					break;
				}
			}
			break;	
		}
	}

	return FALSE;
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
// Name: create
// Desc: Initializes the font
//-----------------------------------------------------------------------------
bool GUIFont::create(LPDIRECT3DDEVICE9 d3dDevice, const char* fontName, DWORD height, bool bold, bool italic)
{
  // Validate parameters
  if (!d3dDevice || !fontName || !height) return false;

  // Make sure the font is clear
  destroy();

  // These variables are used within this method
  HFONT hFont = NULL;
  HFONT hFontOld = NULL;
  HDC hDC = NULL;
  HBITMAP hbmBitmap = NULL;
  HGDIOBJ hbmOld = NULL;

  // Assume that fonts drawn onto the texture do not need scaling unless the texture size
  // required is larger than the device's maximum
  myTextScale = 1.0f;

  // Create a device context for text to draw into
  hDC = CreateCompatibleDC(NULL);
  SetMapMode(hDC, MM_TEXT);

  // Generate the font
  if (!createGDIFont(hDC, &hFont, fontName, height, bold, italic ))
  {
    // Free our context
    DeleteDC(hDC);

    // Return failure
    return false;
  }

  // Set this new font up for use (but store the old one so we can restore it later
  hFontOld = (HFONT)SelectObject(hDC, hFont);

  // Get this device's ability information
  D3DCAPS9 d3dCaps;
  d3dDevice->GetDeviceCaps(&d3dCaps);

  // Usually the required texture is at least 128x128 pixels.
  myTexWidth = myTexHeight = 128;

  // Holds the result of painting the font
  PaintAlphabetResult par;

  // Calculate the size of the smallest power-of-two texture which will hold all the
  // printable characters we need.  First, we try making the texture larger until it gets
  // bigger than the device can support.  Then, we scale down the text to fit the largest
  // texture.
  do
  {
    // If the texture size matches the device's maximum and we've started another
    // iteration, that means the text is too big.  Scale it down.
    if (myTexWidth == d3dCaps.MaxTextureWidth)
      myTextScale *= 0.9f;

    // If this texture is smaller than the device's maximum size, scale it up
    if (myTexWidth < d3dCaps.MaxTextureWidth)
    {
      myTexWidth *= 2;
      myTexHeight *= 2;
    }

    // If the texture is larger than the device can support, scale the text a bit and
    // make the texture the maximum size.
    if (myTexWidth > d3dCaps.MaxTextureWidth)
    {
      // Calculate the text scaling amount
      myTextScale = (float)d3dCaps.MaxTextureWidth / (float)myTexWidth;
      myTexWidth = myTexHeight = d3dCaps.MaxTextureWidth;
    }

    // If we are at the maximum sized texture, the text has been scaled so it needs to
    // be recreated.
    if (myTexWidth == d3dCaps.MaxTextureWidth)
    {
      // Get rid of the new font and put the old font back in
      DeleteObject(SelectObject(hDC, hFontOld));

      // Create the new font
      if (!createGDIFont(hDC, &hFont, fontName, height, bold, italic))
      {
        // Free information
        DeleteDC(hDC);

        // Return failure
        return false;
      }

      // Select the new font
      hFontOld = (HFONT)SelectObject(hDC, hFont);
    }

  } while(PAR_FAILED_NOTENOUGHSPACE == (par = paintAlphabet(hDC, true)));

  // Check to make sure the function didn't fail
  if (par != PAR_SUCCEEDED)
  {
    // Put the old font back into the device context
    SelectObject(hDC, hFontOld);

    // Delete used information
    DeleteObject(hFont);
    DeleteDC(hDC);

    // Erase internal info
    zero();

    // This method failed
    return false;
  }

  // Create the font's texture
  if (FAILED(d3dDevice->CreateTexture(myTexWidth, myTexHeight, 1, 0, D3DFMT_A4R4G4B4,
                      D3DPOOL_MANAGED, &myTexture, NULL)))
  {
    // Put the old font back into the device context
    SelectObject(hDC, hFontOld);

    // Delete used information
    DeleteObject(hFont);
    DeleteDC(hDC);

    // Erase internal info
    zero();

    // Return failure
    return false;
  }

  // Prepare to create the bitmap
  DWORD* bitmapBits;
  BITMAPINFO bmi;
  ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
  bmi.bmiHeader.biSize    = sizeof(BITMAPINFOHEADER);
  bmi.bmiHeader.biWidth     =  (int)myTexWidth;
  bmi.bmiHeader.biHeight    = -(int)myTexHeight;
  bmi.bmiHeader.biPlanes    = 1;
  bmi.bmiHeader.biCompression = BI_RGB;
  bmi.bmiHeader.biBitCount  = 32;

  // Create a bitmap for the font
  hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&bitmapBits, NULL, 0);
  hbmOld = SelectObject(hDC, hbmBitmap);

  // Set up the text properties
  SetTextColor(hDC, RGB(255,255,255));
  SetBkColor(  hDC, 0x00000000);
  SetTextAlign(hDC, TA_TOP);

  // Actually draw the alphabet
  if (PAR_SUCCEEDED != paintAlphabet(hDC, false))
  {
    // Get rid of created Windows information
    SelectObject(hDC, hbmOld);
    SelectObject(hDC, hFontOld);
    DeleteObject(hbmBitmap);
    DeleteObject(hFont);
    DeleteDC(hDC);

    // Free internal data
    destroy();

    // Return error
    return false;
  }

  // Lock the surface and manually write the alpha values for the pixels
  D3DLOCKED_RECT d3dlr;
  if (FAILED(myTexture->LockRect(0, &d3dlr, 0, 0)))
  {
    // Get rid of created Windows information
    SelectObject(hDC, hbmOld);
    SelectObject(hDC, hFontOld);
    DeleteObject(hbmBitmap);
    DeleteObject(hFont);
    DeleteDC(hDC);

    // Free internal data
    destroy();

    // Return error
    return false;
  }

  // This data is used to fill in the texture
  BYTE* destRow;
  destRow = (BYTE*)d3dlr.pBits;
  WORD* dest16;
  BYTE alpha;
  DWORD x, y;

  // Write the alpha values
  for (y = 0; y < myTexHeight; ++y)
  {
    dest16 = (WORD*)destRow;
    for (x = 0; x < myTexWidth; ++x)
    {
      // Determine whether or not a pixel was written here
      alpha = (BYTE)((bitmapBits[myTexWidth * y + x] & 0xFF) >> 4);

      // Write the alpha value
      if (alpha > 0)
        *dest16++ = ((WORD)(alpha << 12) | 0x0FFF); // updated to remove alpha b/c it causes rendering artifacts
      else
        *dest16++ = 0x0000;
    }

    // Move to the next row
    destRow += d3dlr.Pitch;
  }

  // Unlock the texture
  myTexture->UnlockRect(0);

  // Restore states and delete temporary information
  SelectObject(hDC, hbmOld);
  SelectObject(hDC, hFontOld);
  DeleteObject(hbmBitmap);
  DeleteObject(hFont);
  DeleteDC(hDC);

  // Success
  return true;
}
Ejemplo n.º 30
0
void
Test_SrcMono1(ULONG iBmpFormat, HBITMAP hbmpDst, PVOID pvBits)
{
    COLORREF c, expected;
    HBRUSH hbr;
    RECT rect;
    struct
    {
        BITMAPINFOHEADER bmiHeader;
        ULONG bmiColors[2];
        BYTE aj[32];
    } bmi;

    SelectObject(hdcSrc, hbmp1bpp_a);
    SelectObject(hdcDst, hbmpDst);

    /* Set default dc fore and back colors */
    SetTextColor(hdcSrc, 0x000000);
    SetBkColor(hdcSrc, 0xffffff);
    SetTextColor(hdcDst, 0x000000);
    SetBkColor(hdcDst, 0xffffff);

    /* Do a bitblt operation */
    ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);

    /* Test background color */
    c = GetPixel(hdcDst, 0, 0);
    expected = 0xffffff;
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Test foreground color */
    c = GetPixel(hdcDst, 1, 0);
    expected = 0x000000;
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    if (pvBits)
    {
        c = GetDIBPixel(iBmpFormat, pvBits, 0);
        expected = iXlateFromRGB(iBmpFormat,  GetBkColor(hdcSrc));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

        c = GetDIBPixel(iBmpFormat, pvBits, 1);
        expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcSrc));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    }

    /* Set different dc fore and back colors */
    SetTextColor(hdcSrc, 0xf00f0f);
    SetBkColor(hdcSrc, 0xf0ff0f);
    SetTextColor(hdcDst, 0xefFee5);
    SetBkColor(hdcDst, 0x100121);

    /* Make sure this alone didn't affect the resulting colors */
    c = GetPixel(hdcDst, 0, 0);
    expected = 0xffffff;
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    c = GetPixel(hdcDst, 1, 0);
    expected = 0x000000;
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Repeat the bitblt operation */
    ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);

    /* Test background color */
    c = GetPixel(hdcDst, 0, 0);
    expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Test foreground color */
    c = GetPixel(hdcDst, 1, 0);
    expected = GetClosestColor(iBmpFormat, GetTextColor(hdcDst), 0);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    if (pvBits)
    {
        c = GetDIBPixel(iBmpFormat, pvBits, 0);
        expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

        c = GetDIBPixel(iBmpFormat, pvBits, 1);
        expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcDst));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    }

    /* Set inverted fore and back colors */
    SetTextColor(hdcSrc, 0);
    SetBkColor(hdcSrc, 0xffffff);
    SetTextColor(hdcDst, 0xffffff);
    SetBkColor(hdcDst, 0x000000);

    /* Repeat the bitblt operation */
    ok(BitBlt(hdcDst, 0, 0, 2, 2, hdcSrc, 0, 0, SRCCOPY), "(%ld): BitBlt failed", iBmpFormat);

    /* Test background color */
    c = GetPixel(hdcDst, 0, 0);
    expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Test foreground color */
    c = GetPixel(hdcDst, 1, 0);
    expected = GetClosestColor(iBmpFormat, GetTextColor(hdcDst), 0);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    if (pvBits)
    {
        c = GetDIBPixel(iBmpFormat, pvBits, 0);
        expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

        c = GetDIBPixel(iBmpFormat, pvBits, 1);
        expected = iXlateFromRGB(iBmpFormat, GetTextColor(hdcDst));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    }


/* Hatch brush ****************************************************************/

    /* Set dc fore and back colors */
    SetTextColor(hdcDst, 0x102030);
    SetBkColor(hdcDst, 0xeeccdd);
    SetBkMode(hdcDst, OPAQUE);

    /* Create a hatch brush */
    hbr = CreateHatchBrush(HS_DIAGCROSS, 0x123456);

    /* Fill the destination bitmap */
    rect.left = rect.top = 0;
    rect.bottom = rect.right = 4;
    ok(FillRect(hdcDst, &rect, hbr), "FillRect failed\n");

    /* Test the fore color of the hatch brush */
    c = GetPixel(hdcDst, 0, 0);
    expected = GetClosestColor(iBmpFormat, 0x123456, 0);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Test the back color of the hatch brush */
    c = GetPixel(hdcDst, 1, 0);
    expected = GetClosestColor(iBmpFormat, GetBkColor(hdcDst), 0xffffff);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    if (pvBits)
    {
        c = GetDIBPixel(iBmpFormat, pvBits, 0);
        expected = iXlateFromRGB(iBmpFormat, 0x123456);
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

        c = GetDIBPixel(iBmpFormat, pvBits, 1);
        expected = iXlateFromRGB(iBmpFormat, GetBkColor(hdcDst));
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    }

    DeleteObject(hbr);

/* DIB brush ******************************************************************/

    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = 8;
    bmi.bmiHeader.biHeight = 8;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biSizeImage = 0;
    bmi.bmiHeader.biXPelsPerMeter = 1;
    bmi.bmiHeader.biYPelsPerMeter = 1;
    bmi.bmiHeader.biClrUsed = 2;
    bmi.bmiHeader.biClrImportant = 2;
    bmi.bmiColors[0] = 0xeeeeee;
    bmi.bmiColors[1] = 0x111111;
    memset(bmi.aj, 0xaaaa, sizeof(bmi.aj));
    hbr = CreateDIBPatternBrushPt(&bmi, DIB_RGB_COLORS);
    ok(hbr != 0, "CreateDIBPatternBrushPt failed\n");

    rect.left = rect.top = 0;
    rect.bottom = rect.right = 4;
    ok(FillRect(hdcDst, &rect, hbr),"FillRect failed\n");

    /* Test color 1 of the dib brush */
    c = GetPixel(hdcDst, 0, 0);
    expected = GetClosestColor(iBmpFormat, bmi.bmiColors[1], 0);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    /* Test color 0 of the dib brush */
    c = GetPixel(hdcDst, 1, 0);
    expected = GetClosestColor(iBmpFormat, bmi.bmiColors[0], 0xffffff);
    ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

    if (pvBits)
    {
        c = GetDIBPixel(iBmpFormat, pvBits, 0);
        expected = iXlateFromRGB(iBmpFormat, bmi.bmiColors[1]);
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);

        c = GetDIBPixel(iBmpFormat, pvBits, 1);
        expected = iXlateFromRGB(iBmpFormat, bmi.bmiColors[0]);
        ok(c == expected, "(%ld): wrong color, expected %lx, got %lx\n", iBmpFormat, expected, c);
    }

    DeleteObject(hbr);


}