Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
K

kylur

@kylur
About
Posts
21
Topics
8
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • C++ class hierarchy design problem
    K kylur

    Thank you for the reply, Berndus. This answer really caught my eye as it 1) took advantage on templates and specialization, 2) the helper functions can all be moved into the IPipe class as private members, 3) is understandable and 4) is short. Looking closer at the get_the_value functions and they start to look very similar to the reinterpret_cast as suggested in another reply - the only difference being explicitly returning the union member. Good job! I think this is the solution I'll use. Regards, Kylur. :)

    C / C++ / MFC help question c++ design hardware

  • C++ class hierarchy design problem
    K kylur

    Huh?

    C / C++ / MFC help question c++ design hardware

  • C++ class hierarchy design problem
    K kylur

    Thanks for the reply, "cmk". And no I had not tried your suggestion. But now I (almost) have (I used return reinterpret_cast(v);) and yes it does work! And I'm not sure if you're a friggin' genius or if I'm just an idiot for not seeing this solution. For some unknown reason however, I'm a little reluctant to use this - "gurus" tend to frown on casts and in this case I'm not really sure what a reinterpret_cast of a union is really doing (although I have to say it does seem to work). I'll really have to think about this some more! Regards, Kylur.

    C / C++ / MFC help question c++ design hardware

  • C++ class hierarchy design problem
    K kylur

    Thanks for the reply, Jonathan. Yes, this works - if fact it was my original attempt! I rejected it only because it just looked too wordy - I know, bad reason but I've got a little extra time to do investigations on this project so I thought I'd try a few other ideas. Regards, Kylur.

    C / C++ / MFC help question c++ design hardware

  • Scrolling size on zooming
    K kylur

    Anu, Try this: // header file: "MyScrollView.h"

    #pragma once

    class CDoc;
    class CMyScrollView : public CScrollView
    {
    DECLARE_DYNCREATE(CMyScrollView)
    DECLARE_MESSAGE_MAP()

    public:
    CMyScrollView();
    virtual ~CMyScrollView();

    CDoc\* GetDocument();
    

    protected:
    virtual void OnDraw(CDC* pDC);
    virtual void OnInitialUpdate();

    private:
    int Height;
    int Width;
    CBitmap* Bitmap;
    CDC* MemDC;
    };

    // implementation file: "MyScrollView.cpp"

    #include "stdafx.h"
    #include "MyScrollView.h"

    IMPLEMENT_DYNCREATE(CMyScrollView, CScrollView)
    BEGIN_MESSAGE_MAP(CMyScrollView, CScrollView)
    END_MESSAGE_MAP()

    CMyScrollView::CMyScrollView() :
    Bitmap(new CBitmap), Width(1000), Height(200), MemDC(new CDC)
    {
    MemDC->CreateCompatibleDC(NULL);
    }

    CMyScrollView::~CMyScrollView()
    {
    delete Bitmap;
    delete MemDC;
    }

    CDoc* CMyScrollView::GetDocument()
    { return (CDoc*)m_pDocument; }

    void CMyScrollView::OnInitialUpdate()
    {
    CScrollView::OnInitialUpdate();

    GetParentFrame()->SetWindowText("CMyScrollView");
    
    CClientDC dc(this);
    Bitmap->CreateCompatibleBitmap(&dc, Width, Height);
    Bitmap->SetBitmapDimension(Width, Height);
    
    CBitmap\* OldBitmap = MemDC->SelectObject(Bitmap);
    
    MemDC->PatBlt(0, 0, Width, Height, BLACKNESS);
    CPen WhitePen(PS\_SOLID, 1, RGB(255,255,255));
    CPen\* 	OldPen = MemDC->SelectObject(&WhitePen);
    MemDC->MoveTo(0, 0);				// ie top left
    MemDC->LineTo(Width, Height);		// ie bottom right
    MemDC->MoveTo(Width, 0);			// ie top right
    MemDC->LineTo(0, Height);			// ie bottom left
    MemDC->SelectObject(OldPen);
    
    CPen RedPen(PS\_SOLID, 1, RGB(255,0,0));
    OldPen = MemDC->SelectObject(&RedPen);
    MemDC->Rectangle(0,0,10,10);		// red rect in top left
    MemDC->SelectObject(OldPen);
    
    CPen GreenPen(PS\_SOLID, 1, RGB(0,255,0));
    OldPen = MemDC->SelectObject(&GreenPen);
    MemDC->Ellipse(Width-20, Height-20, Width, Height);	// green circle bottom right
    MemDC->SelectObject(OldPen);
    
    CRect Rect(0,Height-20,20,Height);
    CBrush Brush(RGB(0,0,255));
    MemDC->FillRect(Rect, &Brush);		// blue rect in bottom left
    
    MemDC->SelectObject(OldBitmap);
    
    SetScrollSizes(MM\_TEXT, CSize(Width, Height));
    ResizeParentToFit(TRUE);
    

    }

    void CMyScrollView::OnDraw(CDC* pDC) // works!
    {
    if (Bitmap)
    {
    pDC->SetStretchBltMode( COLORONCOLOR );

    	CBitmap\* OldBitmap = MemDC->SelectObject(Bitmap);
    
    	pDC->BitBlt( // l, t, w, h
    		0, 0, Width, Height,
    
    C / C++ / MFC question tutorial

  • C++ class hierarchy design problem
    K kylur

    Fellow coders, RE: a C++ design problem. I am attempting to construct a C++ class hierarchy on top of a C legacy system. The result will be then placed into an embedded controller. The controller communicates with a Windows program via a series of 'software pipes' to a supplied DLL and then calls in the Windows program to fetch information from the DLL. The data in a given pipe will be of a specific type. In order to generalize this process the third party library uses the following header:

    typedef unsigned char BYTE;
    typedef unsigned short WORD;
    typedef unsigned long DWORD;
    
    typedef union gen\_scalar {
    	double	\_double;
    	\_\_int64	\_i64;
    	float	\_float;
    	long	\_i32;
    	short	\_i16;
    	DWORD	\_long;
    	WORD	\_word;
    	BYTE	\_byte;
    } GENERIC\_SCALAR;
    

    And then, for example, reading a long from a pipe would be:

    long Get(PIPE\* pipe)
    {
    	GENERIC\_SCALAR v;
    	pipe\_value\_get(pipe, &v);
    	Return v.\_i32;
    };
    

    So, the hierarchy starts with a base class:

    class Pipe
    {
    public:
    	Pipe(PIPE\* pipe)
    		: pipe\_(pipe)
    	{};
    	virtual ~Pipe()
    	{};
    	
    protected:
    	PIPE\*	pipe\_;
    };
    

    where a PIPE* is just a handle to the communication pipe. Then an input class is needed:

    class IPipe : public Pipe
    {
    public:
    	IPipe(PIPE\* pipe)
    		: Pipe(pipe)
    	{
    		pipe\_open(pipe\_, P\_READ);
    	};
    };
    

    There would also be a corresponding output class OPipe. And now the part I need help with! Suppose I know a pipe will contain a series of 'shorts'. Then I could create:

    class ShortIPipe : public IPipe
    {
    public:
    	ShortIPipe(IPIPE\* pipe)
    		: IPipe(pipe)
    	{};
    	
    	short Get() const
    	{
    		GENERIC\_SCALAR v;
    		pipe\_value\_get(pipe\_, &v);
    		return v.\_i16;
    	};
    };
    

    And so on for a long, double, float, etc, pipe(s). However, the only difference between all these classes is the return value, that is, v._i16 or v._i32, etc. I'd prefer to create a single class which can handle them all. Maybe a template class? For example:

    template <typename T>
    class IPipe : public Pipe
    {
    public:
    	IPipe(PIPE\* pipe)
    		: Pipe(pipe)
    	{
    		pipe\_open(pipe\_, P\_READ);
    	};
    	
    
    	T Get() const
    	{
    		GENERIC\_SCALAR v;
    		pipe\_value\_get(pipe\_, &v);
    		return v.\_???;// depends on T
    	};		
    };
    

    Used like:

    IPipe<short> spipe(...);
    short s = spipe.Get();
    

    And so, (finally) the question is how, within the Get() member, do I define the return value? No

    C / C++ / MFC help question c++ design hardware

  • Change print header to show timestamp
    K kylur

    Using File | Print, enabling "Print Header" adds the filename and page # to printouts. How do I add a timestamp to each page also? Regards, Kylur.

    Visual Studio question

  • Transparent Bitmaps
    K kylur

    And the four line would be?..... (Or at least where should I look to find them myself?)

    C / C++ / MFC question graphics help tutorial workspace

  • Transparent Bitmaps
    K kylur

    I'm developing an application that allows the user to create a bitmap from portions of "n" other source bitmaps. For example, starting with three bitmaps (A, B, and C), the user could select the top third of A, the middle third of B and the bottom third of C and create destination bitmap D. What I'd like to do is create a window that shows one of bitmap A, B, C.... (and has a dialog bar allowing selection of which one). A, B, and C are fully formed, that is, all pixels are defined. Bitmap D is undefined, that is, all pixels are (by default) white. I'd like to display D as a translucent bitmap on top of the selected source bitmap. It the user left-click+moves the mouse over the pair of bitmaps the pixels on A are copied up into D. Once all desired pixels of A are copied upto D, the user would change A to B, D would now be displayed on top of B and the user could copied pixels from B upto D. And so on for all source bitmaps. The undefined parts of D (ie the white pixels) I'd like to show as a "gray film", and the cursor would then be an "eraser" ie remove the "film" and allows the underlying bitmap to shine through. In theory this is all fairly easy. BUT, I'm stymied on the simple part of how do I create and display the translucent bitmap D? Attempts so far are: 1. create aDC_ with aBitmap_ 2. create dDC_ with dBitmap_ 3. create memDC_ with memBitmap_ 4. memDC_->BitBlt(..., aDC_..., SRCCOPY) 5. memDC_->BitBlt(..., dDC_, ..., ?) <=== this is the translucent bitmap 6. pDC->BitBlt(..., memDC_..., SRCCOPY); The question is how do a setup the DC_'s to get the translucency to work? Any help is much appreciated! Regards, Kylur.

    C / C++ / MFC question graphics help tutorial workspace

  • Keystrokes for custom control in dialog
    K kylur

    Thanks! Exactly what I needed.

    C / C++ / MFC question graphics

  • Keystrokes for custom control in dialog
    K kylur

    I've created a custom control (a la article by Chris) to display a region of a bitmap. The control has vertical and a horizontal markers manipulated with the OnLButtonDown/OnLButtonUp/OnMouseMove handlers. The control is placed in a dialog. Now I'd like to add OnKeyDown support. Unfortunately, the dialog traps the WM_KEYDOWN message and just advances to the next control!:mad: How do I get the WM_KEYDOWN message to the custom control? Regards, Kylur

    C / C++ / MFC question graphics

  • Algorithm Request
    K kylur

    double x(123.3) ceil(log10(x)) => 3 ie the # digits left of decimal. I'm still working of # digits right of decimal... Regards, Kylur

    C / C++ / MFC algorithms workspace

  • CToolBar and/or CDialogBar
    K kylur

    Thanks! I appreciate the advise. Regards, Kylur

    C / C++ / MFC question career

  • CToolBar and/or CDialogBar
    K kylur

    Greetings all! I'd like to create a bar which will have a mixture of the tool buttons and controls (combo, pushbutton, edit, etc). The CToolBar class will work for the tool buttons but the job of implementing the controls is too involved. The CDialogBar class will work for the controls but how do I get the tool buttons to work? I've tried a standard button with the BS_ICON style; two problems: 1) button is 16x16, icon is 16x16 but the display lops off part of the icon and 2) how do I get the button to stay "depressed"? I've tried a standard button with the BS_BITMAP style but it: 1) loses the 'transparency' feature of icons, and 2) I still cannot get the button to stay "depressed". The BS_PUSHLIKE style does cause the button to appear to be pushed in on mouse click but does not remain pushed in. The CReBar class will allow for the wrapping of a CToolBar in one band and the CDialogBar in another band but I'd really like to mix the tool buttons and controls in a more logical order. So, the upshot is, I'd like to use the CDialogBar with BS_ICON style if the following problems can be fixed: 1) how do I display the full (standard sized) icon? 2) how do I simulate the icon being "depressed"? Regards, Kylur.

    C / C++ / MFC question career

  • Templates &amp; error C2440
    K kylur

    try: int (*ONEPARAMFUNCITON)(int*) = IndirectFunction<int>; then: int x(666); cout << ONEPARAMFUNCITON(&x) << endl; should work! -- modified at 15:11 Friday 21st October, 2005

    C / C++ / MFC help question html wpf com

  • embedded propertysheet in a dialogbar: how to make ON_UPDATE_COMMAND_UI work
    K kylur

    I've constructed a propertysheet with a working ON_UPDATE_COMMAND_UI system. I've constructed a dialogbar with a working ON_UPDATE_COMMAND_UI system. I've constructed a dialogbar with an embedded propertysheet. Now how do I construct a dialogbar with an embedded propertysheet _AND_ still have ON_UPDATE_COMMAND_UI working in the propertysheet? CMyDialogbar has a CMyPropertySheet member which assume the position of a placeholder control in the dialogbar. The problem seems to be that the idle message does not cascade on from CMyDialogbar into the CMyPropertySheet. Any ideas? Regards, David.

    C / C++ / MFC hardware help tutorial question

  • Singleton with polymorphic classes
    K kylur

    Much appreciated... exactly what I needed. Thank you, Kylur.

    C / C++ / MFC c++ tutorial question

  • Singleton with polymorphic classes
    K kylur

    I appreciate your taking the time to look at this question but your "answer" is less than helpful. The singleton pattern is implemented correctly; I've even implemented the auto_ptr to destroy on exit and noted the need for thread-safety (not required in this simple testbed). I've reread the GoF section on singletons and search >100 sites, lots of info on regular classes but nothing on polymorphic classes. The GoF site shows a polymorphic use but the ctor is public in all the dervied classes, so, they could be directly instantiated. So, again, how to ensure derived classes are not implemented directly.

    C / C++ / MFC c++ tutorial question

  • Singleton with polymorphic classes
    K kylur

    // D.cpp: Singleton returning pointer to polymorphic class // // [Q] How to change definitions of derived classes to disallow // direct construction of derived objects? // ie CDerived1 D1 or CDerived2* D2 = new CDerived2 should not // possible! // #include "stdafx.h" #include #include #include using namespace std; /////////////////////////////////////////////////////////////////////////////// static int Type(0); /////////////////////////////////////////////////////////////////// forwards // class CBase; class CDerived1; class CDerived2; /////////////////////////////////////////////////////////////////////////////// class CBase { public: static CBase* GetInstance(); virtual ~CBase(); virtual ostream& Print(ostream& os) const; protected: CBase(); CBase(const CBase&); // not implemented CBase& operator=(const CBase&); // not implemented private: static auto_ptr Instance_; // will auto destroy }; /////////////////////////////////////////////////////////////////////////////// class CDerived1 : public CBase { public: virtual ~CDerived1(); ostream& Print(ostream& os) const; public: // but should be protected to disallow direct creation CDerived1(); CDerived1(const CDerived1&); // not implemented CDerived1& operator=(const CDerived1&); // not implemented }; /////////////////////////////////////////////////////////////////////////////// class CDerived2 : public CBase { public: virtual ~CDerived2(); ostream& Print(ostream& os) const; public: // but should be protected to disallow direct creation CDerived2(); CDerived2(const CDerived2&); // not implemented CDerived2& operator=(const CDerived2&); // not implemented }; /////////////////////////////////////////////////////////////////////////////// ostream& operator<<(ostream& os, const CBase& rhs) { return rhs.Print(os); }; ostream& operator<<(ostream& os, const CDerived1& rhs) { return rhs.Print(os); }; ostream& operator<<(ostream& os, const CDerived2& rhs) { return rhs.Print(os); }; /////////////////////////////////////////////////////////////////////////////// auto_ptr CBase::Instance_; CBase::CBase() { cout << "Base: ctor\n"; } CBase::~CBase() { cout << "Base: dtor\n"; } CBase* CBase::GetInstance() { // as coded is not thread-safe! required double-check/lock // if (Instance_.get() == NULL) { switch (Type) { case 1: Instance_.reset(new CDerived1); break; case 2

    C / C++ / MFC c++ tutorial question

  • setting the size of a CFrameWnd
    K kylur

    see "The MFC Answer Book", E. Kain, FAQ 3.9. Basically put a MoveWindow(...) in the OnCreate method. Regards, Kylur

    C / C++ / MFC question c++
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups