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
  • Find maximun range of an array

    help graphics algorithms data-structures tutorial
    4
    0 Votes
    4 Posts
    0 Views
    S
    This surely is your homework, so I won't rob you of the opportunity to find the solution yourself. But I'll try to nudge you onto the right track: - Take a pen and paper, write down some random value sequences as input arrays and solve them manually. Try to do this in an algorithmic way. Use some longer sequences than you showed here. - You can't have nested loops over n for O(n), obviously. So you will have to make do with one pass over the array. But you're free to use more or other variables. - The solution is surprisingly easy and succinct - don't think too complicated. If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
  • [win32] VR double buffering ?

    help question
    7
    0 Votes
    7 Posts
    0 Views
    B
    i use the mdsn site + goolge for info yes its a lot of code i wrote it myself and i don't expect the error's to be fount fast the problem whit my code is that you see the drawing of the triangles over eatch other i think i have to change somthing in WM_PAINT but i m not sure
  • Calculate sum of M natural numbers starting from N.

    help tutorial question
    5
    0 Votes
    5 Posts
    0 Views
    U
    yeah I mean it's just an arithmetic sequence so the easiest way would be to just use the formula. the thing is the task requires using the "for" loop so I had to.
  • pascals triangle using user-define function use. Not working !

    6
    0 Votes
    6 Posts
    0 Views
    CPalliniC
    You are welcome.
  • passing parameters to Cdialog

    11
    0 Votes
    11 Posts
    0 Views
    F
    I had typo with the parameters thanks
  • [ win32 ][ code::block's ] game 1 error ?

    help game-dev question
    5
    0 Votes
    5 Posts
    0 Views
    L
    You are calling BeginPaint for every message (not just WM_PAINT), but you only call EndPaint after processing a WM_PAINT message. You need to move all code related the the painting into the block that handles the WM_PAINT message. You also need to select your brushes and pens into the device context before you draw anything. And lastly you need to delete any DC objects that you use in painting. I would suggest studying the GDI documentation on MSDN for sample code. But be aware that GDI and GDI+ are being deprecated by Microsoft in favour of Direct2D API Reference (Windows)[^]
  • Data Structure issue

    help
    13
    0 Votes
    13 Posts
    0 Views
    L
    Interesting I need to give that some more thought to see if it works for me. Most of us mathematicians and programmers are obviously just lazy and call it the Mersenne Primes algorithm, we know there are a couple of small sub section algorithms running under it. I can honestly say I have never thought much about it until this question. The problem I have is if I take it out to computability like you have (and your link), Mersenne Primes is not an Algorithm, it's not an Effective method (it doesn't terminate) .. it's not anything and you ended up calling it a project .. which I now understand. A project to me is meaningless and while to you it's just a formal definition, I lose working meaning and I am not sure I want to go that far just to get a definition :-) What is common to all the group of things that are causing problems is they all expel intermediate results and it is the intermediate results that are more important than the "project" terminating (using your terms). I see where you are going but I need time to think about it because this is tricky with this class of problems, I am even needing to look carefully at the definition of computability. A couple of the fractal situations are probably classed as not computabile. In vino veritas
  • alogaritm for mini calender project

    2
    0 Votes
    2 Posts
    0 Views
    CPalliniC
    I strongly doubt you could find an example on the web, just Googling[^].
  • CDBVariant type problem

    database help sql-server sysadmin debugging
    10
    0 Votes
    10 Posts
    2 Views
    _
    Yes, you are right ... I must change the data type in SQL in order to get right values in CDBVariant ... but I should ask this to my SQL colleagues ... :) Kindly thank you for your answer !!
  • MFC Activex Control

    c++ com algorithms tutorial
    7
    0 Votes
    7 Posts
    0 Views
    L
    You don't have to add the resource you make a memory template, its the exact opposite of a resource ... I am not sure you are really getting it In code you do this creating a memory block which you make the template in bool CreateRotation (HWND parent){ int nchar, ret; HGLOBAL hgbl; LPDLGTEMPLATE lpdt; LPWORD lpw; LPWSTR lpwsz; hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); // Allocate memory if (!hgbl) return false; // If allocate fail exit lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); // Lock the allocated memory lpdt->style = WS_POPUP | WS_CAPTION | WS_SYSMENU; // Window style lpdt->cdit = 0; // Number of controls lpdt->x = 80; // X position lpdt->y = 80; // Y position lpdt->cx = 300; // Window width lpdt->cy = 100; // Window height lpw = (LPWORD)(lpdt + 1); // Set pointer address *lpw++ = 0; // No menu *lpw++ = 0; // Predefined dialog box class (by default) lpwsz = (LPWSTR)lpw; // Typecast pointer nchar = 1 + MultiByteToWideChar(CP_ACP, 0, LanguageString[652], -1, lpwsz, 50); // Create name of window lpw += nchar; // Increment by size of name *lpw++ = 0; // No creation data GlobalUnlock(hgbl); // Release lock on the memory block ret = (int)DialogBoxIndirectParam(GetModuleHandle(0), (LPDLGTEMPLATE)hgbl, parent, (DLGPROC)RotationHandler, 0); // Create the dialog from template GlobalFree(hgbl); // Free the allocated memory if (ret == ID_Ok) { PostMessage(parent, WM_COMMAND, WSC_UPDATEEVERYTHING, 0); return true; } else return false; // Return result }; They are called runtime dialogs or dynamic dialogs but you can always know you are on the right track when you see the use of GlobalAlloc because you have to lock a block of memory to create the dialog in, which is why you don't need resource files etc. Dynamic Dialog Boxes and C++ | Dr Dobb's[^] In vino veritas
  • Program to convert decimal to binary

    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • c

    question
    3
    0 Votes
    3 Posts
    0 Views
    Richard DeemingR
    You have already posted this in QA: #include <stdio.h> int main() { int a=(1, 2, 3); int b=(3, 2, 1); for(; a>0; a--) for(; b<3; b++); printf("%d ", a*b); return 0; }[^] "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • C++ Queue and Stacks

    data-structures c++
    5
    0 Votes
    5 Posts
    0 Views
    J
    Member 13478479 wrote: I would love to post my number I would suggest removing your number. You can edit your post to do that.
  • algorithm for an optimization problem

    algorithms help question design performance
    8
    0 Votes
    8 Posts
    0 Views
    J
    Member 13478986 wrote: Can anyone please help? Start with the chair only. So A, B and H. (Ignore S) Figure that out. Then add S. After that add C and D. It might help to only do C, D, H and S first. However after you did it for A and B this should be trivial.
  • CMonthCalCtrlDlg and the 2038 problem

    c++ help com hardware question
    4
    0 Votes
    4 Posts
    0 Views
    M
    Quote: If you still want to use software from the last millenium to handle dates beyond 2038 you can use the CMonthCalCtrl when using only functions that accept SYSTEMTIME and COleDateTime parameters. I had thought that that MIGHT be the case and seems like a good solution for me ! Thank you !
  • raytracer

    announcement
    19
    0 Votes
    19 Posts
    0 Views
    B
    update : i got most of the error's removed 2 error remains : i got a back picture on screen i can't find 'black.bmp' on my pc // bluatigro 23 okt 2017 // windows raytracer 0.4 #include #include #include #include const int winx = 800 ; const int winy = 600 ; #define SMALL 1e-300 #define PI 3.14159265358979323846 // double3d class d3d { public : double x , y , z ; d3d() { x = 0.0 ; y = 0.0 ; z = 0.0 ; } d3d( double X , double Y , double Z ) { x = X ; y = Y ; z = Z ; } void fill( double X , double Y , double Z ) { x = X ; y = Y ; z = Z ; } unsigned long toColor() { return (unsigned long) ( floor( x * 255 ) + floor( y * 255 ) * 256 + floor( z * 255 ) * 256 * 256 ) ; } } ; d3d operator + ( d3d a , d3d b ) { return d3d( a.x + b.x , a.y + b.y , a.z + b.z ) ; } d3d operator - ( d3d a , d3d b ) { return d3d( a.x - b.x , a.y - b.y , a.z - b.z ) ; } d3d operator / ( d3d a , double b ) { return d3d( a.x / b , a.y / b , a.z / b ) ; } d3d operator * ( d3d a , double b ) { return d3d( a.x * b , a.y * b , a.z * b ) ; } double dot( d3d a , d3d b ) { return a.x * b.x + a.y * b.y + a.z * b.z ; } double length( d3d a ) { return sqrt( dot( a , a ) ) ; } d3d normalize( d3d a ) { return a / length( a ) ; } double getAngle( d3d a , d3d b ) { double d , la , lb ; d = dot( a , b ) ; la = length( a ) ; lb = length( b ) ; return acos( d / ( la * lb ) ) ; } d3d cross( d3d a , d3d b ) { return d3d( a.y * b.z - a.z * b.y , a.z * b.x - a.x * b.z , a.x * b.y - a.y * b.x ) ; } // primary colors const d3d BLACK = d3d( 0.0 , 0.0 , 0.0 ) ; const d3d RED = d3d( 1.0 , 0.0 , 0.0 ) ; const d3d GREEN = d3d( 0.0 , 1.0 , 0.0 ) ; const d3d YELLOW = d3d( 1.0 , 1.0 , 0.0 ) ; const d3d BLUE = d3d( 0.0 , 0.0 , 1.0 ) ; const d3d MAGENTA = d3d( 1.0 , 0.0 , 1.0 ) ; const d3d CYAN = d3d( 0.0 , 1.0 , 1.0 ) ; const d3d WHITE = d3d( 1.0 , 1.0 , 1.0 ) ; // mix colors const d3d GRAY = WHITE / 2.0 ; const d3d ORANGE = ( YELLOW + RED ) / 2.0 ; const d3d PINK = ( WHITE + RED ) / 2.0 ; // matrix class m44 { public : double m[ 4 ][ 4 ] ; m44() { int i , j ; for ( i = 0 ; i < 4 ; i++ ) { fo
  • Find out optimum volume for packing different boxes

    5
    0 Votes
    5 Posts
    0 Views
    D
    This sounds like the "bin packing problem." "One man's wage rise is another man's price increase." - Harold Wilson "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
  • Where is GetTickCount64()?

    c++ algorithms help question
    14
    0 Votes
    14 Posts
    1 Views
    L
    Download and try it, costs nothing for a single developer except download time. It is similar to VS2015 but a pile of new features. Few annoyances you have to select to install C++ it doesn't default to installing it. In vino veritas
  • 0 Votes
    15 Posts
    0 Views
    L
    For the record on GCC you can control the C standard it uses via the flag -std=C99 or C++ standard -std=C++98 (yes C99 equivalent in C++ is 98) Your GCC compiler should be defaulted to at least C11 or C14, in C or C++ unless it's really old like GCC version 4.7. In vino veritas
  • inet error

    help
    2
    0 Votes
    2 Posts
    0 Views
    L
    And what does that have to do with C/C++/MFC?