Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • Hooking file move with shell extension?

    html linux help question discussion
    3
    0 Votes
    3 Posts
    0 Views
    L
    The HTML filename is used to create the associated directory, so they are connected by name.
  • Disable a textbox based on combo box choice

    6
    0 Votes
    6 Posts
    0 Views
    J
    In your view you create an instance of the dialog, set the members for the control as already done and finally call DoModal() to show the dialog (I will not handle modeless dialogs here). When having a modal dialog the default implementation of OnInitDialog() will call CWnd::UpdateData[^] to set the controls from the corresponding member variables. Override OnInitDialog() to do additional initialisation: BOOL CFeaturesDialog::OnInitDialog() { // Call default implementation BOOL bRet = CDialog::OnInitDialog(); // Add specific initialisation here if (m_DialogLayers == 2) GetDlgItem(IDC_Permeability)->EnableWindow(FALSE); return bRet; } If you want to enable/disable the control when the user changes the combo box selection, you have to add a corresponding handler. Open the dialog resource in the resource editor, right click on the combo box to open the context menu and select the option to add a handler. That will open a dialog that allows you to choose the notification. Select CBN_SELCHANGE and apply the settings. That will create a function declaration in the header file, a function body in the source file, and open the source file at the created function. See also Adding an MFC Message Handler[^]. You should become familiar with that because you have to use it frequently with MFC applications. In your case get the pointer to the control and use that to get the index (untested): CFeaturesDialog::OnCbnSelchange() { CComboBox *pCombo = (CComboBox*)GetDlgItem(IDC_LAYERS); GetDlgItem(IDC_Permeability)->EnableWindow(pCombo->GetCurSel() != 2); }
  • 0 Votes
    2 Posts
    1 Views
    L
    Close but not quite the actual rule goes An auto_ptr owns the thing/object that it holds a pointer to, and only one auto_ptr may own an object at a time. When you copy an auto_ptr, you automatically transfer ownership from the source auto_ptr to the target auto_ptr. After the copy, only the target auto_ptr owns the pointer and will delete it in due time, while the source is set back to a null state and can no longer be used to refer to the owned object. The line doSomething(myTest); has an implicit copy because you passed in myTest so the ownership goes into doSomething (passing like that is called an auto_ptr sink operation) and myTest gets the null state as per the description. You can't use it afterwards because it got nulled so it's a guaranteed crash if you try to use the pointer. If you want the auto-pointer back again you should have made doSomething a function returning an auto_ptr and passed it back out, try something like TestAutoPtr doSomethig(TestAutoPtr myPtr) { myPtr->m_value = 11; return myPtr; } The higher level code becomes void AutoPtrTest() { TestAutoPtr myTest(new Test()); myTest = doSomethig(myTest); /* We recopy the auto_ptr ownership back */ myTest->m_value = 10; } It's just an ownership thing .. only one scope of code can own an autoptr. If you want it back again you need to pass it back otherwise it is assumed it is no longer in use and cleaned up. The actual crash has nothing to do with the cleanup the null of the auto_ptr is automatic when it copied and it's that which causes the crash. You are attributing the crash to the cleanup which isn't the case. If you could somehow keep the autoptr inside doSomething alive say with multitask code you still couldn't use the original pointer because it's value will be null. Just use the debugger put a breakpoint on doSomething and single step into it and look at what happens to the original pointer .. your toast from that point on with the original code because it will go to null :-) In vino veritas
  • a

    2
    0 Votes
    2 Posts
    0 Views
    V
    b
  • 0 Votes
    21 Posts
    0 Views
    B
    Hi, Just a Comment. I assume that you understand that each 'C' or 'CPP' File, gets compiled into One and only One '.obj' module. The Linker stitches all those 'Obj' modules together, to create an Exe or DLL, your Target. In doing so, your program needs to link with other libraries and DLL's already on the system. For Instance, your program uses the keyboard, and uses the mouse. You did not have to write the code inside your program to track the mouse movements, register the clicks, etc. That was already done by Microsoft, and comes as part of the Windows Package. Now, Microsoft wrote all that stuff, but, the compiler needs to know what is available from Microsoft, I.e.: the function and other specifications that the Windows API provides. These specifications are included in the System Headers. If you change these specifications to suit your own purpose, well, it Might work if you also 'Re Compiled Windows' If you mess with your system header files, you are actually telling your compiler that Windows works different than that it actually does. Your Compiler caught you out, and stopped you writing a disaster. #include files do not make your program larger, at most it slows down your compiler and linker All Software Engineers should Learn and Train Machine and Assembly Language, so as to really Understand how a computer Works Bram van Kampen
  • BMP Reader C Code

    c++ data-structures help
    14
    0 Votes
    14 Posts
    1 Views
    X
    I'm actually building a BMP Reader in C And I came accross your code. I'm only in the beginning and already changed some stuff. First when you put if(headfirst.type!=19778) I see that you're not taking ENDIAN in account. I made some functions to reorder the bytes.
  • building the assimp library

    c++ csharp visual-studio help tutorial
    3
    0 Votes
    3 Posts
    0 Views
    R
    This'll probably do it: https://github.com/assimp/assimp-net Go there and download the AssimpNet.sln container called "assimp-net-master.zip". I looked at the assimp GITHUB project just now and noted a whole cockpit full of nonsensical info about CMAKE .. and roughly recall confusing CMAKE with some MS utility of a by-gone era using the suffix "MAKE" but I don't think this is a star in anybody's forest so don't bother reading further there. Hope this helps.
  • fytjfc

    4
    0 Votes
    4 Posts
    0 Views
    L
    Wasn't a question the first time this was asked, and still not a question now. If you do not understand your homework assignment. ask your teacher. It's their job to teach you, not ours. Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.
  • OpenMP parallel file writing

    c++ help question
    5
    0 Votes
    5 Posts
    0 Views
    L
    Hi, Ashish Ranjan Mishra wrote: But it is not working and crashing particularly inside recursive function. Can anyone help me out? Unfortunately you did not give any error message or debug information. Also wanted to point out that you will need to avoid the C runtime if you plan on opening more than 512/2048 files at a time. If you use the C wrappers you will be limited to 512 file handles which can be extended to 2048 via the _setmaxstdio function[^]. Best Wishes, -David Delaune
  • Array of char*

    question data-structures help tutorial
    7
    0 Votes
    7 Posts
    0 Views
    M
    Think of an array of chars as a 2d map. So along the bottom the x axis can be considdered as an array of char pointers, each one pointing to a vertical array of chars going up in the y direction. So point 0,0 is a char** You can of course extend this to a 3 d map, with char*** Any point on the 2d map can be referenced by data[x][y] SO first you alloc how many you need in the x direction: char** data = alloc(xMax) Now each vertical collum can be alloced as data[0] = alloc(y1Max) data[1] = alloc(y2Max) And so on.
  • How To Add New Code - NetBeans

    tutorial help question
    3
    0 Votes
    3 Posts
    0 Views
    L
    Get yourself a copy of Visual Studio, it is much better for building C/C++/C# projects.
  • CTreeCtrl with CustomDraw Flickering

    c++ css graphics data-structures help
    10
    0 Votes
    10 Posts
    0 Views
    L
    You should return true (being a non zero value) otherwise window will remain marked for erasing which somewhere down the track may come back to bite you. Remember the API underworkings aren't fixed you may find an old version of Windows or a new update which decides to use the flag. In vino veritas
  • COleVariant to COLORREF

    question help
    4
    0 Votes
    4 Posts
    0 Views
    _
    Working late in night, tired, I didn't notice that CMFCPropertyGridColorProperty has proper methods for set/get colors: CMFCPropertyGridColorProperty Class[^]
  • 0 Votes
    6 Posts
    0 Views
    R
    Here's how I deal with global variables. I have one header file, I call Globals.h, with these definitions : #ifdef DEFINE_GLOBALS #define Global #define GlobalVar(Type,Variable,Value) Type Variable=Value #else #define Global extern #define GlobalVar(Type,Variable,Value) extern Type Variable #endif Then, in one and ONLY one file do this : #define DEFINE_GLOBALS #include "include "Globals.h" #endif before I include headers that define variables. Here are some sample definitions : typedef FILE * PFILE; GlobalVar( PFILE, PtrLogFile, NULL ); GlobalVar( size_t, LineCount, 0 );
  • Help

    help
    3
    0 Votes
    3 Posts
    0 Views
    T
    Member 13023118 wrote: Can any one helps me to understand linear and differential cryptanalysis of PRESENT and XTEA by giving me code c or links of each type. What is your initial analysis? where you faced the problem? do you have trouble understanding some part or thing as a whole. The problem is, even if you give you whole code, you will not able to get benefit out it, as you need to understand the concept. Please rephrase the question and ask where you facing problem. Hopes that's help you!
  • 0 Votes
    2 Posts
    0 Views
    J
    That is because SS_OWNERDRAW is not a bit value that can be O-red to the style but a masked value. Use SetWindowLong(GetSafeHwnd(),GWL_STYLE,( dwStyle & ~SS_TYPEMASK) | SS_OWNERDRAW); instead. Or better: ModifyStyle(SS_TYPEMASK, SS_OWNERDRAW));
  • draw pie chart in vc++

    c++ html help
    2
    0 Votes
    2 Posts
    0 Views
    U
    Hi Please check : CDC Class[^]
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    3 Posts
    1 Views
    F
    putting _NO_CRT_STDIO_INLINE in the preprocessor definitions did the trick thanks
  • ambiguity in multiple inheritance

    help oop question
    3
    0 Votes
    3 Posts
    0 Views
    J
    You have to specify which show() function has to be called: /* derived is an instance of your class */ derived.ParentClass1::show(); derived.ParentClass2::show(); You may also put this code into a new member function using a different name like showBoth() or add functions for each: class derived : public ParentClass1, ParentClass2 { // ... void show1() { ParentClass1::show(); } void show2() { ParentClass2::show(); } void showBoth() { ParentClass1::show(); ParentClass2::show(); } };