I know how to make the window, i just have some questions

This is a discussion on I know how to make the window, i just have some questions within the Windows Programming forums, part of the Platform Specific Boards category; question 1; How the hell, or heck, do you use resources? I tried a tutorial but it didn't work ;_; ...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    I know how to make the window, i just have some questions

    question 1;
    How the hell, or heck, do you use resources? I tried a tutorial but it didn't work ;_;

    question 2;
    What is the message loop for?

    question 3;
    How do you display text into the window?


    P.S. In the resources, i just want to make a simple menu that has File>Exit. The File>Exit doesn't have to work, i just want to be able to see it in my window
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    50
    H'lo Bluehead:

    The answers to your questions are available in the tutorials.

    Or go to www.winprog.org/tutorial

    Very good site, and the tutorial explicitly answers all of your questions.

    However, to summarize:

    1. I don't bother to paint the resources... I learned to do it by code and so I still do it by code. You make a new resource file, and you type something like:

    Code:
    IDR_MAINMENU MENU DISCARDABLE 
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "&New",                        ID_FILE_NEW
            MENUITEM "&Open...",                    ID_FILE_OPEN
            MENUITEM "Save &As...",                 ID_FILE_SAVEAS
            MENUITEM SEPARATOR
            MENUITEM "E&xit",                       ID_FILE_EXIT
        END
    END
    That will create the pretty neat little "File" tab under the main window header, the "File" button that is on EVERY SINGLE WINDOWS APP EVER CREATED. I was so happy when I learned that.. I was like.. "WHOA! SO THAT'S WHERE IT COMES FROM!"

    Sorry.. I thought it was cool

    Now, your popup doesn't have to be called "&File". It could be called "&Edit" or "&Help". Sound familiar? And they're all made exactly the same way. Side note, the & preceeds the hotkey letter, so when you hit Alt+F you get "File". If the resource instead called it "F&ile" you would have to hit Alt+I. Got it?

    Now, in order to use those, when you register your windows class, you have to make sure you fill in the wc.lpszMenuName property (in WinMain):

    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);

    Note that the stuff inside parenthesis there is the same stuff at the very beginning of what I typed for the resource.

    You also have to make sure you declare every single resource symbol used in the resource file, either in your header or at the top of your C/C++ code, with a unique identifier, i.e.

    #define IDC_MAINMENU 40001

    So much for the summary, but that isn't the whole story and I'll leave it up to you to learn the rest...


    2. Why the message loop -

    Oh boy. Boy oh boy. If it weren't for the message loop, nothing would work. You wouldn't be able to tell when your program was the one being clicked, when one of your dialog controls was selected, in other words, your WinProc would have absolutely nothing to do. What Windows does is that all the messages in Windows (ALL of them... some 40,000 messages all at the same time) are put on what's called the message queue. Every single process in windows handles every single message. If the message doesn't apply to your program, your program puts it back on the queue and checks the next one. It does this until it finds the message that the system meant for your program, and passes it onto WinProc.

    Now, there are exceptions to this "Every single message" rule, but in general (and for someone starting out) this knowledge will do the job of explaining the message loop.

    3. What do you mean "how do you display text in the window"? Depends on what you want to do with it. If it's supposed to be part of a button, you display it with the button. If you want it in a dialog, that has it's own way; if you want it in an edit box, you do that another way.... you have to be more specific.

  3. #3
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    1.) i do use winprog.com tutorials, they just confuzin

    2.) i dunno an edit box, yah
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    TextOut outputs text to the screen (Look up the parameters cause I am lazy). If you want to make an edit box, you have to make a whole separate window called a child window.

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    50
    Man, I'm not going to do all your work for you - you have to sit there and work out how to use these things.

    We all go through it - every one of us here.

    I just made a new window, using exactly what I'm about to type below, in the appropriate files I mention:

    in resource.h:

    #define IDR_MAINMENU 101
    #define ID_FILE_EXIT 40001

    in simple_window.rc:
    IDR_MAINMENU MENU DISCARDABLE
    BEGIN
    POPUP "&File"
    BEGIN
    MENUITEM "E&xit", ID_FILE_EXIT
    END
    END

    in simple_window.c:
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);

    Find a program that does NOTHING but create a simple window, i.e. a box with a title and an X box, and that's it, and add what I just gave you, and you will get what you're asking for. If you can't figure that out, you're not trying hard enough, so TRY HARDER.

    2. For edit boxes, look on the tutorial. There is an entire section devoted to adding text to an edit box. In fact, the whole section does nothing but create an edit box and add text to it. If you do nothing but copy and paste that code into your editor/compiler, you'll get what you want. Again, if you can't figure that out, TRY HARDER.

    Don't limit yourself only to that tutorial. There are tons of them out there, and dollars to dimes you'll find ONE of them that you'll think you can understand.

    www.google.com and type in "Windows programming tutorial".

  6. #6
    SytnaxBubble
    Guest

    Post For Text...

    case WM_PAINT:

    HDC hDC=GetDC(hwnd);

    TextOut(hDC, 10, 10, "Text", 5);

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    6
    I red this post and I have a problem. I have made menu but it doesnt seem to work. In menu there is comand Exit whose ID is
    ID_FILE_EXIT. Now I have situation like that I have window, menu in it, in menu there is exit with its ID. But how can I make it send message to message loop that I have pressed Exit. Ok this is so... Can somebody see my code and look is it right?
    Code:
    switch(msg)    // This is my message loop
        {
    	case ID_FILE_EXIT:           // And this is when should work exit from file menue
    		DestroyWindow(hwnd);
    		break;
            case WM_CLOSE:
                DestroyWindow(hwnd);
    		    break;
            case WM_DESTROY:
                PostQuitMessage(0);
    		    break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    50

    Ahh here's your problem...

    Control messages are routed through a message called WM_COMMAND

    You need a switch case to handle the WM_COMMAND message, which will carry the ID_FILE_EXIT message. So inside your first switch, have a case WM_COMMAND. Inside the WM_COMMAND case, have a switch that handles your different controls, such as ID_FILE_EXIT and ID_FILE_NEW, etc. i.e.:

    Code:
    case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_FILE_EXIT:
                    // Do stuff
                break;
                // ... other controls
            }
        break;
    case WM_DESTROY:
            ......
    Got it?

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    case WM_PAINT:

    HDC hDC=GetDC(hwnd);

    TextOut(hDC, 10, 10, "Text", 5);
    If you use GetDC() you should also use ReleaseDC()
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  10. #10
    Registered User
    Join Date
    May 2002
    Posts
    6
    Thenks for help bluecoder but I have another problem. Menu I've created has some weerd space between window. Here it is take a look...
    Attached Images Attached Images  

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    50
    Hmmmm.... I'm not sure. I've never seen that before... post (or send me) your code and I'll take a look. Preferrably zip it up and I'll download it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. how i create a window whith all it's elements
    By rasheed in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2006, 07:53 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 05:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21