A litttle MFC push...

This is a discussion on A litttle MFC push... within the Windows Programming forums, part of the Platform Specific Boards category; main.cpp Code: #include <afxwin.h> #include "main.h" CApp app; BOOL CApp::InitInstance() { m_pMainWnd = new CMarco(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } ...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308

    Question A litttle MFC push...

    main.cpp
    Code:
    #include <afxwin.h>
    #include "main.h"
    
    CApp app;
    
    BOOL CApp::InitInstance() {
    	m_pMainWnd = new CMarco();
    	m_pMainWnd->ShowWindow(m_nCmdShow);
    	m_pMainWnd->UpdateWindow();
    	return TRUE;
    }
    
    BEGIN_MESSAGE_MAP(CMarco, CFrameWnd)
    	ON_WM_CREATE()
    	ON_WM_PAINT()
    	ON_BN_CLICKED(10000, OnBnClicked1)
    	ON_BN_CLICKED(20000, OnBnClicked2)
    END_MESSAGE_MAP()
    
    CMarco::CMarco() {
    	Create(NULL, "Hola");
    }
    
    CMarco::~CMarco() {
    	delete m_btn2;
    	delete m_btn3;
    }
    
    void CMarco::OnCreate(LPCREATESTRUCT lpCreateStruct) {
    	m_btn2 = new CButton();
    	m_btn2->Create("Hola", WS_CHILD|WS_VISIBLE, CRect(10, 10, 50, 40), this, 10000);
    
    	m_btn3 = new CButton();
    	m_btn2->Create("Boo", WS_CHILD|WS_VISIBLE, CRect(10, 60, 50, 40), this, 20000);
    }
    
    void CMarco::OnBnClicked1() {
    	MessageBox("Estás presionado", "Hola");
    }
    
    void CMarco::OnBnClicked2() {
    	m_btn2->EnableWindow(FALSE);
    }
    
    
    void CMarco::OnPaint() {
    	CPaintDC dc(this);
    
    	dc.TextOut(5, 5, "Joel");
    } // :~ Al terminar CPaintDC es eliminada, Qué bien!
    main.h
    Code:
    #if !defined(_MFC_MAIN_H_)
    #define _MFC_MAIN_H_
    
    class CApp : public CWinApp {
    public:
    	virtual BOOL InitInstance();
    };
    
    class CMarco : public CFrameWnd {
    public:
    	CMarco();
    	~CMarco();
    private:
    	CButton* m_btn2;
    	CButton* m_btn3;
    protected:
    	afx_msg void OnPaint();
    	afx_msg void OnBnClicked1();
    	afx_msg void OnBnClicked2();
    	afx_msg void OnCreate(LPCREATESTRUCT lpCreateStruct);
    	DECLARE_MESSAGE_MAP();
    };
    
    #endif
    Why the buttons are not showed?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Looks fine to me.

    Have you tried making the buttons normal members instead of allocating them on the heap? Should make no difference, but ...

    Hmm, how about button styles?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. swapping pointers
    By csvraju in forum C Programming
    Replies: 17
    Last Post: 04-01-2009, 04:18 AM
  2. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 04:48 PM
  3. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  4. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 01:15 PM
  5. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 09:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21