Thread: Help me find this error and get rid of this warning message please

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Help me find this error and get rid of this warning message please

    Here's the .c file:
    Code:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    static TCHAR szAppName[] = TEXT("Aquamarine");
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
        HWND     hwnd;
        MSG         msg;
        WNDCLASS wndclass;
    
        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc = WndProc;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance = hInstance;
        wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        wndclass.lpszMenuName = szAppName;
        wndclass.lpszClassName = szAppName;
    
        if(!RegisterClass(&wndclass)){
            MessageBox(NULL, TEXT("Error registering window class."),
                       szAppName, MB_ICONERROR);
            return 0;
        }
    
        hwnd = CreateWindow(szAppName, TEXT("Aquamarine"), WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL,
                            hInstance, NULL);
        
        ShowWindow(hwnd, iCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&msg, NULL, 0, 0) > 0){
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HMENU hMenu;
    
        switch(message)
        {
        case WM_COMMAND:
            hMenu = GetMenu(hwnd);
    
            switch(LOWORD(wParam))
            {
                case ID_REGISTER:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_BUY:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_PAYMENT:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_RETURN:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_SEARCH_NAME:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_SEARCH_PHONE:
                    MessageBox(NULL, TEXT("Esta opção não funciona ainda.\r\nAguarde e confie..."),
                               szAppName, MB_ICONWARNING);
                    return 0;
    
                case ID_APP_EXIT:
                    SendMessage(hwnd, WM_CLOSE, 0, 0);
                    return 0;
            }
            break;
    
            case WM_CLOSE:
                DestroyWindow(hwnd);
                break;
    
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
        }
    
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
    Here's the .h file:
    Code:
    #define ID_REGISTER       101
    #define ID_APP_EXIT       102
    
    #define ID_BUY            103
    #define ID_PAYMENT        104
    #define ID_RETURN         105
    
    #define ID_SEARCH_NAME    106
    #define ID_SEARCH_PHONE   107
    And here's the .rc file:
    Code:
    #include "resource.h"
    
    AQUAMARINE MENU DISCARDABLE
    BEGIN
        POPUP "&Cliente novo"
        BEGIN
            MENUITEM "&Cadastrar", ID_REGISTER
            MENUITEM SEPARATOR
            MENUITEM "S&air", ID_APP_EXIT
        END
    
        POPUP "&Transações"
        BEGIN
            MENUITEM "&Compra", ID_BUY
            MENUITEM "&Pagamento", ID_PAYMENT
            MENUITEM "&Devolução", ID_RETURN
        END
        
        POPUP "&Procurar"
        BEGIN
            MENUITEM "&Por nome", ID_SEARCH_NAME
            MENUITEM "&Por telefone", ID_SEARCH_PHONE
        END
        
        POPUP "&Sobre"
        BEGIN
            MENUITEM "&Sobre o programa...", ID_ABOUT
        END
    END
    This is what happens when I try to compile this program:
    c:\Documents and Settings\kao\My Documents\Visual Studio Projects\GUI\resource.h(11): fatal error RC1004: unexpected end of file found
    c:\Documents and Settings\kao\My Documents\Visual Studio Projects\GUI\GUI.cpp(44): warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
    Any ideas? Thanks.

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    try adding an extra line to the end of your header file.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    204
    It worked. That was silly
    What about that warning. Do you know how I can fix it? Thanks.

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Well really the warning simply refers to the fact that you are returning msg.wParam from your main function which is defined as returning an int.

    This warning is occuring because WPARAM is defined as an UINT whereas main returns a INT. And since we know our basic datatypes we can now see where the 'possible loss of data' can occur. Nothing to worry about.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>What about that warning. Do you know how I can fix it? Thanks.

    try a cast to get rid of the warning


    return (int) msg.wParam;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed