BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #14638同步于 2008/10/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

请高人帮我看下这个程序为啥不出结果??多谢.

aimei
2008/10/25镜像同步3 回复
// pngtuDlg.cpp : implementation file // #include "stdafx.h" #include "pngtu.h" #include "pngtuDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG 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() ///////////////////////////////////////////////////////////////////////////// // CPngtuDlg dialog CPngtuDlg::CPngtuDlg(CWnd* pParent /*=NULL*/) : CDialog(CPngtuDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPngtuDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPngtuDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPngtuDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPngtuDlg, CDialog) //{{AFX_MSG_MAP(CPngtuDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_COMMAND(ID_EXIT, OnExit) ON_WM_RBUTTONDOWN() ON_WM_CREATE() ON_WM_CONTEXTMENU() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPngtuDlg message handlers BOOL CPngtuDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // 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 strAboutMenu; 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 CPngtuDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { 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 CPngtuDlg::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(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CPngtuDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CPngtuDlg::OnExit() { // TODO: Add your command handler code here SendMessage(WM_CLOSE,1,0); } void CPngtuDlg::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CDialog::OnRButtonDown(nFlags, point); } int CPngtuDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specializedcreation code here HDC hdcTemp=GetDC()->m_hDC; m_hdcMemory=CreateCompatibleDC(hdcTemp); HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,600 ,600 ); SelectObject(m_hdcMemory,hBitMap); //if(Transparent<0||Transparent>100) Transparent=100; //m_blend.SourceConstantAlpha=int(Transparent*2.55);//1~255 HDC hdcScreen=::GetDC (m_hWnd); hFuncinst=LoadLibrary("User32.DLL"); if(hFuncinst) UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncinst,"UpdateLayerWindow"); else { AfxMessageBox("user32.dll can not open"); exit(0); } m_blend.BlendOp=0; m_blend.BlendFlags=0; m_blend.SourceConstantAlpha=255; m_blend.AlphaFormat=1 ; ImageFromSource(IDR_PNG1,"png",m_image1); ImageFromSource(IDR_PNG2,"png",m_image2); ImageFromSource(IDR_PNG3,"png",m_image3); ImageFromSource(IDR_PNG4,"png",m_image4); m_i1Width=m_image1->GetWidth(); m_i1Height=m_image1->GetHeight(); m_i2Width=m_image2->GetWidth(); m_i2Height=m_image2->GetHeight(); m_i3Width=m_image3->GetWidth(); m_i3Height=m_image3->GetHeight(); m_i4Width=m_image4->GetWidth(); m_i4Height=m_image4->GetHeight(); ::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,600,600,SWP_NOSIZE|SWP_NOMOVE); Graphics graph(m_hdcMemory); Point point1[]={Point(0,0),Point(0,m_i1Width),Point(m_i1Height,0)}; Point point2[]={Point(m_i1Width,0),Point(m_i1Width+m_i2Width,0),Point(m_i1Width,m_i1Height)}; Point point3[]={Point(m_i1Height,0),Point(m_i1Width,m_i1Height),Point(m_i1Height+m_i3Height,0)}; Point point4[]={Point(m_i1Width,m_i1Height),Point(m_i3Width,m_i4Width+m_i3Width),Point(m_i3Width,m_i1Height+m_i3Height)}; graph.DrawImage(m_image1,point1,3); //graph.DrawImage(m_image2,point2,3); //graph.DrawImage(m_image3,point3,3); //graph.DrawImage(m_image4,point4,3); CRect rct; GetWindowRect(&rct); POINT ptWinPos={rct.left,rct.top}; SIZE sizeWindow={600,600}; POINT ptSrc={0,0}; DWORD dwExStyle=GetWindowLong(m_hWnd,GWL_EXSTYLE); if((dwExStyle&0x80000)!=0x80000) SetWindowLong(m_hWnd,GWL_EXSTYLE,dwExStyle^0x80000); bool bRet=false; bRet= UpdateLayeredWindow( m_hWnd,hdcScreen,&ptWinPos, &sizeWindow,m_hdcMemory,&ptSrc,0,&m_blend,2); graph.ReleaseHDC(m_hdcMemory); ::ReleaseDC(m_hWnd,hdcScreen); hdcScreen=NULL; ::ReleaseDC(m_hWnd,hdcTemp); hdcTemp=NULL; DeleteObject(hBitMap); DeleteDC(m_hdcMemory); m_hdcMemory=NULL; //return bRet; return 0; } bool CPngtuDlg::ImageFromSource(UINT nID, LPCTSTR sTR, Image *&pImg) { HINSTANCE hInst = AfxGetResourceHandle(); HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type if (!hRsrc) return FALSE; // load resource into memory DWORD len = SizeofResource(hInst, hRsrc); BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc); if (!lpRsrc) return FALSE; // Allocate global memory on which to create stream HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len); BYTE* pmem = (BYTE*)GlobalLock(m_hMem); memcpy(pmem,lpRsrc,len); IStream* pstm; CreateStreamOnHGlobal(m_hMem,FALSE,&pstm); // load from stream pImg=Gdiplus::Image::FromStream(pstm); // free/release stuff GlobalUnlock(m_hMem); pstm->Release(); FreeResource(lpRsrc); } void CPngtuDlg::OnContextMenu(CWnd* pWnd, CPoint point) { // TODO: Add your message handler code here if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(IDR_MENU1)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); } void CPngtuDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here } 这是其中的主要程序段.不知道为什么运行没有结果 ,请指点一下吧~~谢谢了.心里有点急.呵呵[em9]
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
ayu机器人#1 · 2008/10/25
Whereis the App
aimei机器人#2 · 2008/10/25
这只是主要的实现代码,the app我没有粘上来.可是运行结果 并不显示图片,是不是我的思路错了,郁闷中^^^^
ayu机器人#3 · 2008/10/26
【 在 aimei 的大作中提到: 】 : 这只是主要的实现代码,the app我没有粘上来.可是运行结果 并不显示图片,是不是我的思路错了,郁闷中^^^^ 显示不应该在OnCreate函数中吧, OnPaint?