Advertisement

Questions about MFC and general Windows stuff...

Started by August 17, 2000 09:16 PM
3 comments, last by _Seifer_ 24 years, 4 months ago
What I''m currently working on is a Windows version of the mini-game Triple Triad from FF8 (just to give clarity on what I''m asking), for those who don''t know, it''s essentially a card game. I''m making it with MFC (don''t hurt me) and graphics are just GDI (no! stop laughing) so no DX or the like. OK, there are two questions I want to ask here: One, is it actually possible to load a bitmap from a file into a CBitmap object? I know it can be done from a resource but the graphics chosen are essentially dynamic (randomly/user chosen) and I need to splice together the filenames. The LoadBitmap member function doesn''t let me do that, it only lets me specify the resource ID which isn''t easily splicable. That''s not very convenient as there are 211 different images that could be loaded (and I hate huge switch statements, hence MFC). I don''t care how it''s done, as long as I can dynamically choose the images. Second, how do I get control over bitmaps like there is in the standard Windows game Solitaire. By that I mean, how do I make it so I can drag the cards around? Do I have to set up handlers for the WM_LMOUSEBUTTON (not sure if that''s actually it) and WM_MOUSEMOVE messages and just keep track of where things are going? Or is there actually a drag and drop message that can be issued? Or would it just be easier if I made it a two click process (once on card, then on board)? On that note, is there an easy way to check if the card has been clicked (other than simply checking coordinates) much in the same manner a button is checked. It''s an SDI app so AFAIK I can''t just put in a button for each card. Oh yeah, finally, if anyone wants to help me with making this game, I''d like to know. It may eventually be multiplayer and stuff, so it should be pretty cool. Thanks in advance for any help. -Seifer
I can''t help you out for the first question, but maybe on the second question....


There is a WM_MBUTTONDOWN and corresponding WM_MBUTTONUP message that you could add handlers for.

As to the checking coordinates, I believe you would have to do that, to see which bitmap would be needed. If you detect a WM_MBUTTONDOWN, set a flag (bool variable, whatever), then if you want to draw the card in motion, you could use the MOUSEMOVE (if the flag is set, then you draw the card in motion or something), then, on your BUTTONUP message, (again assuming the flag is set), you can set the card down, and call whatever else you need to.

I don''t know if this helps you out or not. If you need further explanation, let me know.

Good luck.

Mihkael

Advertisement
Well, your idea is fairly close to what I was hoping I wouldn''t have to do but, I hadn''t thought of those flags (man, that would make it difficult ^_^). Come to think of it, that won''t be too bad. I could just put a CRect in the card object to allow for easier bounds checking. I''ll have to see if it has a default bounds checking function. If not, I''ll just have to inherit it and make my own. Then again, this is Windows programming, there are never any easy ways out.

Anyway, I had an idea for my first problem: if I import the graphics as resources all in the right order, the resource IDs SHOULD be consecutive, so it''ll just take a little addition (which seems so much easier than splicing together filenames, not to mention it hides the graphics files from users on the most part, which tidies up the folder.

Of course, if there is a more reliable solution to either problem (the cards'' resource IDs may change without me knowing it; silly MSVC++), I''d love to hear it.

Thanks Mihkael.

-Seifer
I avoid MFC as much as possible but in straight Win32 programming the standard way to load a bitmap from a file is to use LoadImage.

Making assumptions about how id''s are allocated will probably break you some day. If you want to keep the folder tidier than put the bitmaps in a "Graphics" subfolder.

-Mike
You can use LoadImage() to load an image from a file into an HBITMAP handle and then use CBitmap::FromHandle() to attach the handle to a CBitmap. Hope this helps!

[Edit: Spelling error in the function name]

-------------------------------
That's just my 200 bucks' worth!

..-=gLaDiAtOr=-..

Edited by - Gladiator on August 18, 2000 3:36:37 PM

This topic is closed to new replies.

Advertisement