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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
C

codeII

@codeII
About
Posts
19
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What is the Maximum size of WCHAR
    C codeII

    WCHAR* InputText = ( WCHAR* ) HeapAlloc( GetProcessHeap( ), HEAP_GENERATE_EXCEPTIONS, 5 * 1024 * 1024 );

    C / C++ / MFC question

  • How to write copy constructor when returning any template object.
    C codeII

    pagePathArray( pagePathArray& rhs )
    {
    m_memberOne = rhs.m_memberOne;
    ...
    }

    Or easier:

    void COpenFolderPage::GetPagesPath( CArray<type,type>& pagePathArray )
    {
    }

    C / C++ / MFC help tutorial

  • breaking up an int in c programming
    C codeII

    int nValue = 112233;
    int nDiv = 1000000;

    while ( nDiv /= 100 ) //StepSize
    {
    cout<

    C / C++ / MFC tutorial question

  • breaking up an int in c programming
    C codeII

    int nValue = 112233;
    int n1 = nValue / 10000;
    nValue -= ( n1 * 10000 );
    int n2 = nValue / 100;
    nValue -= ( n2 * 100 );
    int n3 = nValue;

    C / C++ / MFC tutorial question

  • How to modify private member variable of any class
    C codeII

    Here is a dirty trick to do so:

    class ClassProtected
    {
    private:
    int m_One;
    UINT m_Two;
    int m_Three;
    };

    class ClassPublic
    {
    public:
    int m_One;
    UINT m_Two;
    int m_Three;
    };

    ClassProtected test; ClassPublic* pTest = (ClassPublic*) &test; pTest->m_One = 1; pTest->m_Two = 2; pTest->m_Three = 3;

    C / C++ / MFC tutorial question

  • Convert to double value
    C codeII

    You cannot change these types in memory, because int and double have different sizes in memory. Else you could have changed your type in memory like this:

    int nTst = 2;
    double dTmp = (double) nTst;
    double* pTst = (double*)&nTst;
    *pTst = dTmp;

    Is this what you meant?

    C / C++ / MFC performance help question

  • Base class pointer to Derived Class object??
    C codeII

    Try using virtual functions. This gives your base class pointer a behaviour depending on the class where it is derived from.

    class CBase
    {
    public:
    virtual void OpenDoor( ) = 0;
    };

    class House: public CBase
    {
    public:
    virtual void OpenDoor( )
    {
    AfxMessageBox(_T("Open door of house") );
    }
    };

    class Car: public CBase
    {
    public:
    virtual void OpenDoor( )
    {
    AfxMessageBox(_T("Open door of Car") );
    }
    };

    CBase* pObject = new House; pObject->OpenDoor( );

    C / C++ / MFC question

  • How to convert a CString to WCHAR?
    C codeII

    Sindse ATL 7.0 and MFC 7.0 You can use CStringW (or CStringA ) This code is valid for both Unicode and Multibyte:

    CString cMyCString("Test");
    CStringW cMyCStringW( cMyCString );
    (LPCWSTR) cMyCStringW;

    C / C++ / MFC help tutorial question

  • How to Save the DC.
    C codeII

    #include "atlimage.h" bool SafeDcToBmp( const CDC& cdc, LPCTSTR cBitmapPathAndName ) { CImage image; CRect cdcRect; bool bSucc = false; if( cdc.GetWindow( ) ) { cdc.GetWindow( )->GetClientRect( cdcRect ); image.Create( cdcRect.Width( ), cdcRect.Height( ), 24 ); ::BitBlt( image.GetDC( ), 0,0, image.GetWidth( ), image.GetHeight( ), cdc.m_hDC, 0,0,SRCCOPY ); bSucc = ( S_OK == image.Save( cBitmapPathAndName ) ); } return bSucc; } //Usage CDC cdc; cdc.Attach( GetDC( )->m_hDC ); SafeDcToBmp( cdc, _T("c:\\MyFile.bmp") ); cdc.Detach( );

    C / C++ / MFC graphics tutorial question

  • static variable
    C codeII

    int& MyFunction( ) { static int localStatic = 0; int nMyArray[ 10 ]; if ( localStatic < 10 ) { //localStatic is not guaranteed < 10 nMyArray[ localStatic ] = 1; } return localStatic; } When one tread comes inside the “if statement” another tread could have set localStatic to for instance 11. If you want to use a variable outside the scope of the function why are you not using a global? When using a static in a function this “means” that the function is responsible for this variable. And it cannot, when this variable is managed outside this function. Keeping strict rules provides confusing situations, In terms of who is modifying what. Another thing you should know is that when you are using a static within a class function, different instances of this class would use the same static instance; this can cause problems like the tread example above. Using globals: In header: extern int g_MyVar; In cpp int g_MyVar = 0; or when possible using a local variable giving to the function void MyFunction( int& nValue ) { nValue++; … } int nValue = 0; MyFunction( nValue );

    C / C++ / MFC c++ question

  • draw and select object
    C codeII

    here is another approach the first thing you need to do is make a stack which supports all the graphics you are using: MyGraphicsStack; MyGraphicsStack.add( line, rect, color, ... ); <- user draws a line MyGraphicsStack.add( circle, rect, color, ..., fill ); <- user draws .. . . (or better, make objects and inherit from the same base class) Now when the user clicks, you create a white temporary bitmap with the same dimensions as the user is drawing on. the next thing is drawing your stack ( in the correct order ) on this temporary bitmap. For each item you are drawing, ignore the color in the GraphicsStack but use instead: (COLORREF)index_Of_Current_Object_In_MyStack. (index casting to a color) for filled objects: use this color for the fill/and the border color. Then transform your mouse coordinates where the user clicked, to bitmap coordinates. And for this coordination obtain the bitmap pixel color. When you cast the pixel color back it will be the index of the object kept in your stack, ( or white in case user pressed the bitmap ) UINT nInd = (COLORREF)getpixel(..) if ( nInd < MyGraphicsStack.Size( ) ) { MyGraphicsStack[ nInd ] //<-- here it is } in this way you have always the topmost object even when objects are drawn over each other. You also distinct objects which are filled or not. ( depending on the bit depth of the bitmap you are creating you are limited in the number of items you can draw, in that case you could work with more bitmaps, for a normal 24 bits bitmap you can keep 16777216 - 1 objects 1 = bitmap itself ) remark: Because Gdi+ plus can ignore drawing objects you are drawing outside the region of the dc, you can also create a small bitmap (I think 16x16 is the minimum?) and when drawing to this bitmap correct for the offset ( the bitmap coordinates the user selected ) in this way that the centre pixel of your small bitmap is the pixel you are interested in. well have fun!

    Graphics graphics winforms help question

  • VC++ compilation
    C codeII

    Internal a LPCWSTR/CStringW is in UTF-16 LE, a CString also when you compile in UNICODE. Converting UTF-16 LE to UTF-8 you should use WideCharToMultiByte( CP_UTF8, 0, stringw, BYTE* ); When you want a Unicode file, you should first write an encoding tag.

    C / C++ / MFC c++ question

  • To assign string from String table to a controll's caption at design time?
    C codeII

    I’m sorry didn’t read your question very well. As far as I know it is impossible. Here you can read the Parameters you can pass to a control http://msdn2.microsoft.com/en-us/library/aa380902.aspx created in the resource. I tried to manually insert a string table Id, after reordering the resource (putting the string table before the dialog’s definition, but it didn’t work.

    C / C++ / MFC question design

  • To assign string from String table to a controll's caption at design time?
    C codeII

    CString cDlgItemTxt; cDlgItemTxt.LoadString( IDS_STRINGTABLEID ); GetDlgItem( ID_DLGITEM )->SetWindowText( cDlgItemTxt );

    C / C++ / MFC question design

  • two dimensional array initialization
    C codeII

    Yep, It only makes sence when you dynamically want assign/reassign an array. //f.i. reassign string 2 (before deletion!): delete [] pArr[ 1 ]; pArr[ 1 ] = new TCHAR[ _tcslen( _T("Every body") ) + 1 ]; _tcscpy( pArr[ 1 ], _T("Every body") ); Regards, Koos

    C / C++ / MFC csharp visual-studio data-structures help tutorial

  • two dimensional array initialization
    C codeII

    Dynamic you can do it something like this: int nNmbOfStrings = 2; int nI; LPTSTR* pArr = new LPTSTR[ nNmbOfStrings ]; pArr[ 0 ] = new TCHAR[ _tcslen( _T("hello") ) + 1 ]; pArr[ 1 ] = new TCHAR[ _tcslen( _T("world") ) + 1 ]; _tcscpy( pArr[ 0 ], _T("hello") ); _tcscpy( pArr[ 1 ], _T("world") ); //deletion: for ( nI = 0; nI < nNmbOfStrings; nI++ ) { delete [] pArr[ nI ]; pArr[ nI ] = NULL; } delete [] pArr; pArr = NULL;

    C / C++ / MFC csharp visual-studio data-structures help tutorial

  • Help wuth click map
    C codeII

    Create a second bitmap with the same dimensions which you don't display. Give each unique area a unique color. The next step is, when the user clicks your bitmap get the mouse coordinates relative to your bitmap and use these coords on your internal map. DWORD ID = GetPixel( x, y ); switch ( ID ) { case 12: //South African; }

    Graphics graphics help question

  • Problem with fopen
    C codeII

    try _tfopen without casting a TCHAR to a char

    C / C++ / MFC help

  • Passing a reference to a pointer
    C codeII

    :doh:This technique can be used to assign/reassign a pointer within a function. Another way of doing this is a pointer to a pointer **. exampl. Void MyAllocFunction( TYPE*& pData ) { delete [] pData; pData = new TYPE[ x ]; } TYPE* pData = NULL; MyAllocFunction( pData ); delete [] pData; From these methods I prefer a reference to a pointer for readability and error safety reasons. Preferably a function which allocates a pointer has to destroy it; this keeps it clear what function is responsible for destruction. From this point of view you have to provide using both of these techniques.

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

  • Don't have an account? Register

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