/<span style="font-family: Arial, Helvetica, sans-serif;">3DCutWnd.cpp</span>
#include "stdafx.h"
#include "3DCutWnd.h"
#include "GdiPlus\Includes\gdiplus.h"
using namespace Gdiplus;
#pragma comment(lib, "GdiPlus\\Lib\\gdiplus.lib")
C3DCutWnd::C3DCutWnd()
{
}
C3DCutWnd::~C3DCutWnd()
{
}
BEGIN_MESSAGE_MAP(C3DCutWnd, CWnd)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_PAINT()
//ON_BN_CLICKED(WM_CLICK_3DPARALLELRANGES_WND_CLOSE,C3DCutWnd::OnClickOk)
ON_WM_MOVE()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
int C3DCutWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码
CRect rtWnd;
GetClientRect(&rtWnd);
CRect rt;
rt.left = rtWnd.right/2;
rt.right = rt.left+70;
rt.top = 10;
m_editCutSize.Create(WS_CHILD|WS_VISIBLE,rt,this,0);
m_editCutSize.ShowWindow(SW_SHOW);
return 0;
}
void C3DCutWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
CRect rtWnd;
GetClientRect(&rtWnd);
CRect rt;
rt.left = rtWnd.right/2;
rt.right = rt.left+70;
rt.top = 10;
rt.bottom = rt.top + 20;
m_editCutSize.MoveWindow(&rt);
m_editCutSize.Invalidate();
//Invalidate();
// TODO: 在此处添加消息处理程序代码
}
void C3DCutWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CWnd::OnPaint()
//::SetBkColor(::GetDC(this->m_hWnd),RGB(255,255,255));
Graphics graphics(this->m_hWnd);
CRect rtWnd;
GetClientRect(&rtWnd);
CRect rt;
rt.top = 10;
rt.left = 10;
rt.right = 50;
rt.bottom = 260;
REAL nH = REAL(rtWnd.bottom);
REAL nX = 0;
REAL nY = REAL(rtWnd.bottom/2);//
REAL nX2 = REAL(rtWnd.right);
REAL nY2 = nY;
Pen pen(Color(0,0,0),nH);
graphics.DrawLine(&pen,nX,nY,nX2,nY2);
FontFamily fontFamily(L"幼圆");
Gdiplus::Font font(&fontFamily, 12, FontStyleRegular, UnitPoint);
PointF ptF;
ptF.X = 0;
ptF.Y = 10;
SolidBrush solidBrush(Color(255, 255, 255));
graphics.DrawString(L"裁剪大小:",6,&font,ptF,&solidBrush);
}
void C3DCutWnd::OnClickOk()
{
this->ShowWindow(SW_HIDE);
}
void C3DCutWnd::OnMove(int x, int y)
{
CWnd::OnMove(x, y);
// TODO: 在此处添加消息处理程序代码
//Invalidate();
}
HBRUSH C3DCutWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
/<span style="font-family: Arial, Helvetica, sans-serif;">3DCutWnd.h</span>
#pragma once
//#include <iostream>
//using namespace std;
class C3DCutWnd : public CWnd
{
public:
C3DCutWnd();
~C3DCutWnd();
private:
CEdit m_editCutSize;
//CEdit m_editDistance;
/*CMyButton m_Ok;
CMyButton m_btDefault;
CMyButton m_btClose;*/
CButton m_Start;
CButton m_btClose;
CButton m_btHelp;
/*CMyButton m_btTransverse;
CMyButton m_btEndlong;*/
/*CComboBox m_ComboBox;
CListBox m_listBox;*/
public:
void SetParent(CWnd *pParentWnd);
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPaint();
afx_msg void OnClickOk();
afx_msg void OnMove(int x, int y);
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
};
调用
void CToolBoxTestDlg::OnBnClickedButton1()
{
CRect rtClientWnd;
GetClientRect(rtClientWnd);
C3DCutWnd m_3DCutWnd;
CRect rt;
rt.left = 100;
rt.right = rt.left + 210;
rt.top = rtClientWnd.bottom/2-100;
rt.bottom = rt.top + 150;
//if(m_3DCutWnd.m_hWnd == NULL && m_pParentWnd != NULL)
{
//WNDCLASS wndc;
//HINSTANCE hinstance = AfxGetInstanceHandle();
//if(!(::GetClassInfo(hinstance, tipclass, &wndc)))
//{
// wndc.style = CS_SAVEBITS;
// wndc.lpfnWndProc = ::DefWindowProc;
// wndc.cbClsExtra = wndc.cbWndExtra=0;
// wndc.hInstance = hinstance;
// wndc.hIcon = NULL;
// wndc.hCursor = LoadCursor(hinstance,IDC_ARROW);
// wndc.hbrBackground = (HBRUSH)(COLOR_INFOBK+1);
// wndc.lpszMenuName = NULL;
// wndc.lpszClassName = tipclass;//类名
// if (!AfxRegisterClass(&wndc))
// AfxThrowResourceException();
//}
HBRUSH hBrush = CreateSolidBrush(RGB(222,0,255));
//CString strClass=AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS,::LoadCursor(NULL, IDC_ARROW), (HBRUSH) ::GetStockObject(BLACK_BRUSH),::LoadIcon(NULL, IDI_APPLICATION));
CString strClass=AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS,::LoadCursor(NULL, IDC_ARROW), (HBRUSH)CreateSolidBrush(RGB(255,0,0)),::LoadIcon(NULL, IDI_APPLICATION));
m_3DCutWnd.CreateEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST,strClass,L"testWnd",WS_BORDER|WS_POPUP|WS_CAPTION,rt,m_pParentWnd,0);
m_3DCutWnd.ShowWindow(SW_SHOW);
m_3DCutWnd.Invalidate();
}
//else
}