jackba / wy-internal-system

Automatically exported from code.google.com/p/wy-internal-system
0 stars 0 forks source link

MFC CDialog #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
//Paint the bg
void CPicturedButtonDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
//      CDialog::OnPaint();
        CPaintDC dc(this);
        CRect rect;
        ::GetClientRect(this->GetSafeHwnd(), &rect);

        CDC dcMem;
        dcMem.CreateCompatibleDC(&dc);
        CBitmap bmpBG;
        bmpBG.LoadBitmapW(IDB_MUFC2);
        BITMAP bitmap;
        bmpBG.GetBitmap(&bitmap);
        CBitmap *pBmpOld = (CBitmap *)dcMem.SelectObject(bmpBG);
        dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &dcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
    }
}

Original issue reported on code.google.com by Giggs...@gmail.com on 17 Feb 2012 at 7:42

GoogleCodeExporter commented 9 years ago
处理WM_NCPAINT时排除客户区 CWindowDC dc(this); 

 CRgn rgn; 
 CRect rcWindow, rcClient; 
 GetWindowRect(rcWindow); 
 GetClientRect(rcClient); 
 ClientToScreen(rcClient); 
 rcClient.OffsetRect(-rcWindow.TopLeft()); 

 rgn.CreateRectRgn(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); 
 dc.SelectClipRgn(&rgn, RGN_DIFF); 

Original comment by Giggs...@gmail.com on 17 Feb 2012 at 9:48

GoogleCodeExporter commented 9 years ago
a server/client sample to research

Original comment by Giggs...@gmail.com on 14 Jun 2013 at 10:57

Attachments:

GoogleCodeExporter commented 9 years ago
memory leakage:
#include "stdafx.h"
#include "Leak.h"
#include <shlwapi.h>
#include "../util/String.h"

#include <map>
#include <string>
using std::map;
using std::string;
#pragma  comment(lib, "Shlwapi.lib")

static std::map<int, string> m_mapMem;
static CRITICAL_SECTION m_cs;
static const char *FISH_BONE = ">+++++++:>\r\n";
static char* m_dir = NULL;

bool Leak_Init(char *dir)
{
    if (!PathFileExistsA(dir))
    {
        printf("Dir not exist.\n");
        return false;
    }
    m_dir = dir;
    ::InitializeCriticalSection(&m_cs);

    return true;
}
void Leak_New(int address, int size, char *module, char *function, char 
*type_name)
{
    char num[10];
    memset(num, 0, 10);
    itoa(size, num, 10);

    string info;
    info.append(num);
    info.append(" ");
    info.append(module);
    info.append(" ");
    info.append(function);
    info.append(" ");
    info.append(type_name);

    if (m_mapMem.find(address) != m_mapMem.end())
    {
        printf("Leak Error:Duplicated Key Found!\n");
        return;
    }
    ::EnterCriticalSection(&m_cs);

    m_mapMem.insert(std::pair<int, string>(address, info));
    printf("Memory new-ed:@%d %s \n", address, m_mapMem[address].c_str());

    ::LeaveCriticalSection(&m_cs);
}
void Leak_Delete(int address)
{   
    ::EnterCriticalSection(&m_cs);

    map<int, string>::const_iterator ptr = m_mapMem.find(address);
    if (ptr != m_mapMem.end())
    {
        printf("Memory deleted:@%d %s \n", address, m_mapMem[address].c_str());
        m_mapMem.erase(ptr);

        ::LeaveCriticalSection(&m_cs);

        return;
    }
    else
    {
        printf("Leak:no such memory:%d\n", address);
    }

    ::LeaveCriticalSection(&m_cs);
}
void Leak_Show()
{
    map<int,string>::iterator ptr;
    for (ptr = m_mapMem.begin(); ptr != m_mapMem.end(); ptr++)
    {
        printf("[%d]%s\n", (*ptr).first, (*ptr).second.c_str());
    }
}
void Leak_Fini()
{
    Leak_Show();

    m_mapMem.clear();
    ::DeleteCriticalSection(&m_cs);
}
bool Leak_ToFile()
{
    if (!m_mapMem.empty())
    {
        string filename;
        filename.clear();
        //
        filename.append(m_dir);
        filename.append("\\mem_");
        char *tmp = util_TimeNowToFileName();
        filename.append(tmp);
        delete tmp;
        filename.append(".log");
        //
        FILE *fp = NULL;
        if (NULL == (fp = fopen(filename.c_str(), "a+")))
        {
            return false;
        }
        map<int, string>::const_iterator ptr;
        ptr = m_mapMem.begin(); 
        fwrite(FISH_BONE, 1, strlen(FISH_BONE), fp);
        for (ptr = m_mapMem.begin(); ptr != m_mapMem.end(); ptr++)
        {
            fwrite((*ptr).second.c_str(), 1, strlen((*ptr).second.c_str()), fp);
            fwrite("\r\n", 1, 2, fp);
        }
        //
        fclose(fp);
        printf("Log file path:%s\n\n", filename.c_str());
    }
    printf("File(s) written.\n");

    return true;    
}

Original comment by Giggs...@gmail.com on 14 Jun 2013 at 11:00