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
A

Alain Rist

@Alain Rist
About
Posts
183
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • trying to solve exam question and getting unreasonable length code, can it be shorter?
    A Alain Rist

    Hi Stefan, Not sure this quick answer deserved such in-depth excellent review ;) My updated post should address your pertinent issues, and handle empty input string. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC question data-structures performance

  • trying to solve exam question and getting unreasonable length code, can it be shorter?
    A Alain Rist

    Hi,

    atikot wrote:

    can anyone help me come up with more reasonable solution?

    This is shorter:

    // CharCount.c : Defines the entry point for the console application.

    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>

    void CharCount(char str[], char** result)
    {
    int i;
    unsigned int count[256];
    if (!strlen(str))
    return;
    if (*result = (char*)malloc(min(strlen(str), 256) * 8)) // Allocate a 'reasonable' output size
    {
    char* out = *result;
    memset(count, 0, sizeof(count));
    for (i = 0; str[i]; i++)
    ++count[str[i]];
    for (i = 0; i < 256; i++)
    if (count[i])
    out += sprintf(out, "%c %u;", (char)i, count[i]);
    *--out = '\0';
    }
    }

    int main()
    {
    char* out = NULL;
    CharCount("abbacdeefg", &out);
    if (out)
    printf("%s\n", out);
    free(out);
    }

    cheers, AR Code edited after Stefan_Lang[^]'s excellent review.

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    modified on Monday, July 4, 2011 10:43 AM

    C / C++ / MFC question data-structures performance

  • Migration from MFC to STL
    A Alain Rist

    Hi, If your compiler supports C++2011 (VC2010 or gcc 4.5) std::vector::shrink_to_fit() is the functional equivalent to CByteArray::FreeExtra().If you are on C++2003 use v.reserve(v.size()) to achieve the same goal. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL c++ css

  • Memory alignment changed from studio 2005 to 2010?
    A Alain Rist

    Hi William, Try linking your exe with Data Execution Prevention off: Project->Properties->Linker->Advanced->Data Execution Prevention (DEP)->No. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC csharp c++ visual-studio design debugging

  • Migration from MFC to STL
    A Alain Rist

    Hi Hrishi,

    hrishi321 wrote:

    I have many classes already in my VC++ project, which were build on MFC. Meaning the data types were MFC based. like CByteArray, CString etc etc. Now I need to avoid the uses of MFC data types , and introduce STL data types.

    As MFC internally uses its own collection and string classes, you will increase your code footprint, and keep dependancy on all MFC classes and data types. Anyhow you can use CStdString[^] as drop-in replacement for CString, and you should write your own CStdByteArray etc.. based on STL collections and exposing the same interface as the matching MFC collections. It could be an interesting CodeProject article :) Good luck! AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL c++ css

  • ToolTip text in WTL
    A Alain Rist

    Hi Selva,

    SelvaKr wrote:

    Tool tips are specified in the resource as direct strings in the prompt field of the properties.

    The VC resource editor intends to help you to create toolbar tooltips, they are actually in the resource stringtable. For instance in your .rc file you have:

    STRINGTABLE
    BEGIN
    ID_FILE_NEW "Create a new document\nNew"

    A toolbar button's tooltip is the part of the string resource with same ID following '\n'. As the part preceding '\n' is the status bar text when a menu entry with same ID is hovered you can localize the strings matching your menus and toolbars in one step. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL c++ help tutorial learning

  • The correct way to clear a embeded map variable [modified]
    A Alain Rist

    cy163@hotmail.com wrote:

    I am not very sure if I am correct when i free a map variable.

    Are you looking for this[^]? cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL

  • Does VS resource compiler support PNG file
    A Alain Rist

    A png image is not a Windows Icon resource :)

    ID_PNG PNG "res\\Test.png"

    cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC visual-studio learning

  • European Union Public Licence (EUPL) acceptance?
    A Alain Rist

    Hans Dietrich wrote:

    OK, so compatible with GPLv2, but not compatible with GPLv3.

    GPLv3 is dated 29 June 2007, the link in my previous post was published on Mar 11, 2009 :) I suppose EUPL updating is a lengthy process, which is not bad in this case ;) cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    Site Bugs / Suggestions question

  • European Union Public Licence (EUPL) acceptance?
    A Alain Rist

    The answers are here[^] :) cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    Site Bugs / Suggestions question

  • European Union Public Licence (EUPL) acceptance?
    A Alain Rist

    Hi, It would be nice to add the EUPL[^] to the accepted licenses. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    Site Bugs / Suggestions question

  • Creating a window without focus [modified]
    A Alain Rist

    Hi, Your popup should handle WM_ACTIVATE with:

    if (wParam != WA_INACTIVE)
    ::SetActiveWindow(::GetParent(GetSafeHwnd()));

    cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC question c++

  • Edit Text
    A Alain Rist

    john5632 wrote:

    How to edit text in CListCtrl?

    The answer is here[^]. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC tutorial question

  • add menu item
    A Alain Rist

    john5632 wrote:

    How to add sub item in menu?

    The answer is here[^]. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC tutorial question

  • How to get IDOK / IDCANCEL command message from an non-modal dialog set as client in CFrameWindowImpl?
    A Alain Rist

    Sorry, I don't understand the relationship with your OP :(

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL hardware tutorial question

  • How to create an flicker free owner draw listbox using CDoubleBufferWindowImpl?
    A Alain Rist

    Hi Philipp,

    Philipp Kursawe wrote:

    I guess the first step would be to move the MSG_WM_DRAWITEM message handling to my custom listbox control

    It may be your choice but it's not the first step. You need to use a double buffered CListBox, for instance:

    class CMyListBox : public CDoubleBufferWindowImpl<CMyListBox, CListBox, ATL::CControlWinTraits>
    {
    BEGIN_MSG_MAP(CMyListBox)
    CHAIN_MSG_MAP(CDoubleBufferWindowImpl)
    END_MSG_MAP()
    void DoPaint(HDC hdc)
    {
    DefWindowProc(WM_PAINT, (WPARAM)hdc, 0);
    }
    };

    If you subclass the listbox in your parent dialog OnInit(), you can check with breakpoints that the dc referenced in your DrawItem() member is the MemoryDC set in CMyListBox::DoPaint(). My test code:

    class CTest0View :
    public CDialogImpl<CTest0View>,
    public COwnerDraw<CTest0View>
    {
    public:
    enum { IDD = IDD_TEST0_FORM };
    CMyListBox m_lb;
    void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
    // must be implemented
    return;
    }
    BEGIN_MSG_MAP(CTest0View)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInit)
    CHAIN_MSG_MAP(COwnerDraw<CTest0View>)
    FORWARD_NOTIFICATIONS()
    END_MSG_MAP()

    LRESULT OnInit(UINT /\*uMsg\*/, WPARAM /\*wParam\*/, LPARAM /\*lParam\*/, BOOL& bHandled)
    {
    	m\_lb.SubclassWindow(GetDlgItem(IDC\_LIST1));
    	m\_lb.AddString(L"Titi");
    	m\_lb.AddString(L"Tata");
    	m\_lb.AddString(L"Toto");
    
    	return bHandled = FALSE;
    }
    

    };

    cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL tutorial question

  • Using CContainedWindowT in a base class causes assert in conrete class
    A Alain Rist

    Hi Philipp, You are misunderstanding ATL::CContainedWindow operation. Post on the WTL support list[^] for help. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL c++ help

  • How to get IDOK / IDCANCEL command message from an non-modal dialog set as client in CFrameWindowImpl?
    A Alain Rist

    Hi Philipp, In your dialog message map add FORWARD_NOTIFICATIONS() to forward the WM_COMMAND (and some other) messages to the dialog's parent, ie your CTabViewImpl based window. CTabViewImpl in turn will forward (if not handled) the same messages to it's parent, see CTabViewImpl message map. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    ATL / WTL / STL hardware tutorial question

  • how do i convert unicode string to ansi format?
    A Alain Rist

    Hi, I suppose you want something like this (C++):

    #include <sstream>
    #include <iterator>
    size_t OutputByteVals(const std::wstring ws, std::ostream& out)
    {
    const size_t nBytes = ws.size() * sizeof(wchar_t);
    std::copy_n(reinterpret_cast<const char *>(ws.data()), nBytes , std::ostream_iterator<int>(out, " "));
    return nBytes;
    }

    cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    modified on Wednesday, March 2, 2011 3:22 AM

    C / C++ / MFC question

  • How to get value 1.3 from a float value 1.333333
    A Alain Rist

    Hi Andrew, 1 With a modern compiler implementing move semantics it is not that slow. You can also quicken it with a template for decimal. 2 It is safe, accurate and handles negative values. 3 It is flexible. You don't have to write a new one for each rounding you may need. All in all this is an academic discussion :) Real world uses fixed point representations when needing rounded decimal values. cheers, AR

    When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

    C / C++ / MFC tutorial
  • Login

  • Don't have an account? Register

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