I have a program in MFC (dialog based) that creates a random number. I have imported 3 pictures (a.bmp, b.bmp, c.bmp). The random number is between 1 and 10. I want to make it so if the random number is 123 or 4 display a, 567 display b, and 8910 display c.
How can i do this?
how about a dialog box that can be used as a login that will talk with a mysql server?
I don't know how you have the pictures stored, but if you follow this general idea and have a pointer to the data type that represents the picture, and then points to the right picture based upon the random number, you're set. Alternatively, if you have all of the pictures in an array, instead of dealing with a pointer, set an index value, and then access that element of the array, provided you got a valid index.
int x = (rand() % 10) + 1;
Somepicture *pic = NULL;
pic = a;
pic = b;
pic = c;
/* Do something with pic if it's not NULL. */
As far as talking to a mysql server, what about it? Check the documentation for the mysql SDK.
When I do stuff like this I tend to use an If statement instead of a switch. It saves time typing, especially if you have a large list. (might not be as readable tho)
else if(x<8) pic=b;
wasn't really what i was looking for. I made a dialog app in mfc and i want it to display a picture like in the if statement and the switch. I already had that, but how do i make it so that IDC_BITMAP1 is displayed if a=1234 and IDC_BITMAP2 is displayed if b=567 etc.
Erm. I'm not sure if I get exactly what you are on about. Are you asking how to actually draw the picture by any chance?
nope. I imported 3 pictures, with resources named IDB_BITMAP1, 2 and 3 respectively. I created a bitmap display section in the dialog box. I want to make an if/switch statement that will let me display IDB_BITMAP1 in the bitmap section if a==123 or 4, IDB_BITMAP2 is a >4.
Apparently you know how to load and draw an image. You also know how to generate a random number, and select an image based on the result.
What else is there you need to know?
I don't do MFC, so I can't help ya with specifics if you're asking an MFC-specific question. I agree with Mike. If you know how to display an image and already have code like what I posted for a random number, then you should be set.
Create a static and give it the SS_BITMAP style (at least).
Use the class wiz to link a variable to a static control.
[Picture controls are a sub-class of static controls see CStatic as the base class]
Call the SetBitmap() method to change the image displayed.
May require a paint msg (to the statics parent) before the changes are visible
[ InvalidateRect() then UpdateWindow() ]
Try this: Bitmap[rand()%3].Draw().
The MFC class CBitmap does not have a 'Draw()' method.
Nor does that link the Bitmap to the Picture control.
I think you are thinking of managed C++ [.NET] not MFC [non .NET].