Saturday, November 26, 2011

Creating a transparent textbox/edit control


First of all, the concept here is not originally mine but I have made a lot of changes to the original code. The original code can be seen here: http://www.codeguru.com/cpp/controls/editctrl/backgroundcolor/article.php/c6857

The code was written under MFC framework but what it does is pretty obvious. I mean, if you want to apply it in a non-MFC project, you already knew what to do.

Before I posted my modified code here, I made sure first that it works. I am using this code in a project I'm working on as of this posting.

My IDE is MS Visual Studio 2010. OS: Windows 7.

So, here we go.



// The MFC header class --> transedit.h

#pragma once

#pragma pack
(push, 1)

class TransEdit : public CEdit
{
    CBrush m_Brush;
    COLORREF m_clrText;
public:
    TransEdit();
    void SetTextColor(COLORREF clr);
    DECLARE_DYNCREATE(TransEdit)

private:
    void PrepareBackground();
    DECLARE_MESSAGE_MAP()

protected:
    //{{AFX_MSG(TransEdit)
    afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    //}}AFX_MSG
public:
    afx_msg void OnEnUpdate();
    afx_msg void OnSize(UINT nType, int cx, int cy);
};

#pragma pack(pop)



// The TransEdit implementation --> transedit.cpp

#include "stdafx.h"
#include "transedit.h"

BEGIN_MESSAGE_MAP(TransEdit, CEdit)
    ON_WM_CTLCOLOR_REFLECT()
    ON_CONTROL_REFLECT(EN_UPDATE, OnEnUpdate)
    ON_WM_SIZE()
END_MESSAGE_MAP()

IMPLEMENT_DYNCREATE(TransEdit, CEdit)


TransEdit::TransEdit()
{
    m_clrText = GetSysColor(COLOR_WINDOWTEXT);
}

void TransEdit::SetTextColor(COLORREF clr)
{
    m_clrText = clr;
}

HBRUSH TransEdit::CtlColor(CDC *pDC, UINT nCtlColor)
{
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetTextColor(m_clrText);
    return (HBRUSH)m_Brush;
}

void TransEdit::PrepareBackground()
{
    if( m_Brush.m_hObject!=0 )
        return;

    CWnd * pParent = GetParent();
    CBitmap bkgnd;
    CClientDC dc(pParent);
    CDC thisMem;
    CRect pos, rc;
    GetWindowRect(pos);
    rc = pos;
    ScreenToClient(rc);
    pParent->ScreenToClient(pos);
    pos.InflateRect(rc.left, rc.top);

    CBitmap* pOldThisBmp;
    thisMem.CreateCompatibleDC( &dc );
    CSize sz = pos.Size();

    bkgnd.DeleteObject();
    bkgnd.CreateCompatibleBitmap(&dc, sz.cx, sz.cy );
    pOldThisBmp = thisMem.SelectObject(&bkgnd);
    thisMem.BitBlt(0, 0, sz.cx, sz.cy, &dc, pos.left, pos.top, SRCCOPY);
    thisMem.SelectObject(pOldThisBmp);
    m_Brush.DeleteObject();
    m_Brush.CreatePatternBrush(&bkgnd);
}

void TransEdit::OnEnUpdate()
{
    CRect rc;
    CWnd * pParent = GetParent();
    GetWindowRect(rc);
    pParent->ScreenToClient(rc);
    pParent->InvalidateRect(rc, 1);
    PrepareBackground();
}

void TransEdit::OnSize(UINT nType, int cx, int cy)
{
    m_Brush.DeleteObject();
    BOOL b = IsWindowVisible();
    CEdit::OnSize(nType, cx, cy);
    if( b )
        ShowWindow(SW_HIDE);
    OnEnUpdate();
    if( b )
        ShowWindow(SW_SHOW);
}



That’s all it!

If you find this useful, feel free to use/modify it. You want to claim it as your own? Go on, f@ck yourself!

Wednesday, October 5, 2011

This is how I get things done--at least in my mail box.



Most of the online email servers, at least the ones I know (yahoo mail, gmail and mail.com) has this feature of getting your inbox organized into something that suits you. It is called mail filtering. Using filtering enables you to control to what folder received emails should go. It helps keep your inbox uncluttered and reading mails a hobby than a vexing task of wading through the ocean of important and unwanted mails, not just the spams.

And what the hell made me post this when I know that most web users uses online email servers and most probably had known and been using this feature before I even know it exists? Well, for those who knows and uses this already, this is not for you. For those who doesn't and want to give themselves a favor, get inspired by this, read the documentation in your email servers on how to use filtering and enjoy reading your mails.

By the way, for yahoo users, here is a starter:

  1. On your yahoo mail, click options.
  2. Once you are on the options tab, look at the left pane for the label filters and click on it.
  3. When the filters pane is visible which located on the right side, click on the add filter button.
  4. Supply a name you think appropriate and on the sender contains field, type in some words that is exists in the email address of the sender. e. g. yahoo for whoeveryouare@yahoo.com. All fields are simply self-explanatory. Whatever word you typed will then be compared to sender's email address if that word exists on it.
  5. In the move to folder, select a folder where these kind of mails will be moved to or select new folder so you can supply a new folder's name appropriate for these said emails later when you click save changes.
  6. Finally, click on save changes and that's all that, you have a new filter. You can use to a maximum of 100 filters.

If you have already those sort of emails before you created its filter, you can drag them one by one and drop to the folder you have just created for it. Or you can search your mail filtered so that only those emails of that particular sender will be included in the result, click on the topmost check box located at the left of your mails panel so that everything are selected and move them to that folder. For additional information in doing all these, yahoo has a detailed explanation on how to do it.













Good luck