- Jan 22 Wed 2014 10:41
-
【C++ 隨手小記】MFC 視窗背景色
- Jan 15 Wed 2014 16:41
-
【C++ 隨手小記】MFC 重構元件
1. 在Create() 時的Style要加上 BS_OWNERDRAW
2. 在Class中加上 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
3. 在cpp 檔中繪製元件 <--- 從網路上找的
void CTvButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC); //Get device context object
CRect rt;
rt = lpDrawItemStruct->rcItem; //Get button rect
2. 在Class中加上 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
3. 在cpp 檔中繪製元件 <--- 從網路上找的
void CTvButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC); //Get device context object
CRect rt;
rt = lpDrawItemStruct->rcItem; //Get button rect
- Jan 02 Thu 2014 14:59
-
【C++ 隨手小記】raw socket in win7
- Sep 13 Fri 2013 16:16
-
【C++ 懶人用法】取得JPEG的RGB
#include <windows.h>
#pragma comment( lib, "gdiplus.lib" )
#include <gdiplus.h>
using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
void Filter( Bitmap* src, Bitmap* dst )
{
int w, h;
w = src->GetWidth();
h = src->GetHeight();
for( int y=0; y<h; y++ ) {
for( int x=0; x<w; x++ ) {
Color c;
c = src->GetPixel( x, y );
// do something interesting here!
dst->SetPixel( x, y, c );
}
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR sCmdLine, int nCmdShow )
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Bitmap* pBitmapIn = new Bitmap( L"input.jpg" );
Bitmap* pBitmapOut = new Bitmap( pBitmapIn->GetWidth(), pBitmapIn->GetHeight(), PixelFormat32bppRGB );
Filter( pBitmapIn, pBitmapOut );
CLSID encoderClsid;
GetEncoderClsid(L"image/jpg", &encoderClsid);
pBitmapOut->Save( L"output.jpg", &encoderClsid, 0 );
GdiplusShutdown(gdiplusToken);
return 0;
}
#pragma comment( lib, "gdiplus.lib" )
#include <gdiplus.h>
using namespace Gdiplus;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1; // Failure
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1; // Failure
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
free(pImageCodecInfo);
return -1; // Failure
}
void Filter( Bitmap* src, Bitmap* dst )
{
int w, h;
w = src->GetWidth();
h = src->GetHeight();
for( int y=0; y<h; y++ ) {
for( int x=0; x<w; x++ ) {
Color c;
c = src->GetPixel( x, y );
// do something interesting here!
dst->SetPixel( x, y, c );
}
}
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR sCmdLine, int nCmdShow )
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Bitmap* pBitmapIn = new Bitmap( L"input.jpg" );
Bitmap* pBitmapOut = new Bitmap( pBitmapIn->GetWidth(), pBitmapIn->GetHeight(), PixelFormat32bppRGB );
Filter( pBitmapIn, pBitmapOut );
CLSID encoderClsid;
GetEncoderClsid(L"image/jpg", &encoderClsid);
pBitmapOut->Save( L"output.jpg", &encoderClsid, 0 );
GdiplusShutdown(gdiplusToken);
return 0;
}
- Sep 13 Fri 2013 09:27
-
【C++ 懶人用法】MFC 貼 JPEG 方法 (網路上找到的)
LPPICTURE gpPicture;
void C169Dlg::ShowPicture(CDC *pDC, CString m_strBRoute, int x, int y, int width, int height)
{
HANDLE hFile =CreateFile(m_strBRoute, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
//Get File Size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
- Sep 19 Wed 2012 16:39
-
c++ socket - Broadcast sendto + recvfrom
- May 15 Tue 2012 08:27
-
MFC Webbrowser on dialog
1. 先要有 webbrowser2.cpp/.h 檔
2. 在Webbrowser的Dialog加上下列code
BEGIN_MESSAGE_MAP(CWebDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_COMMAND(ID_DEMO_PRINTPREVIEW, OnPrintpreview)
ON_COMMAND(ID_DEMO_PAGESETUP, OnPagesetup)
END_MESSAGE_MAP()
// CWebDlg 訊息處理常式
BOOL CWebDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CString csAddress("192.168.81.229");
COleVariant vtEmpty;
Web.Navigate(csAddress, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty);
ReSize();
return TRUE;
}
void CWebDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if (!((nID & 0xFFF0) == IDM_ABOUTBOX))
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWebDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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();
}
}
2. 在Webbrowser的Dialog加上下列code
BEGIN_MESSAGE_MAP(CWebDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_COMMAND(ID_DEMO_PRINTPREVIEW, OnPrintpreview)
ON_COMMAND(ID_DEMO_PAGESETUP, OnPagesetup)
END_MESSAGE_MAP()
// CWebDlg 訊息處理常式
BOOL CWebDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CString csAddress("192.168.81.229");
COleVariant vtEmpty;
Web.Navigate(csAddress, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty);
ReSize();
return TRUE;
}
void CWebDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if (!((nID & 0xFFF0) == IDM_ABOUTBOX))
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWebDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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();
}
}
- Apr 11 Wed 2012 00:56
-
【C++ 懶人用法】製作及使用 Dll
- Feb 29 Wed 2012 17:05
-
【Android 懶人用法】Sleep 用法
- Feb 27 Mon 2012 15:19
-
【Android 懶人用法】將Integer值放上EditText
- Feb 26 Sun 2012 12:07
-
【C++ 懶人用法】MFC Picture Control 顯示bmp圖片
Picture control 中顯示 bitmap 的用法 (寫給我自已看的...)
1. 拉Picture 元件 並且更改 ID (因預設是用 CStatic,所以要改為別的名字)
1. 拉Picture 元件 並且更改 ID (因預設是用 CStatic,所以要改為別的名字)
- Feb 19 Sun 2012 14:37
-
【C++ 懶人用法】MFC 中建立一個日曆
