Thread: I need help on these few errors!!

  1. #1
    BubbleMan
    Guest

    Post I need help on these few errors!!

    CODE IS:

    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case CM_FILE_ENTRY:
    HDC hDC = GetDC(hwnd);

    char f_name[] = "Matt";
    TextOut(hDC, 10, 10, f_name, strlen(f_name));
    break;
    case CM_ABOUT_ABOUT:
    MessageBox(hwnd, "About:\n Program: StarBook(Windows)\n Company: Starfield\n Authors: David & Matt\n E-mail: [email protected]\n Web site: none yet", "About", MB_OK + MB_ICONINFORMATION);
    break;
    case CM_FILE_EXIT:
    PostQuitMessage(0);
    break;
    }
    break;

    ERRORS ARE:

    86 book_windows.cpp
    jump to case label

    83 book_windows.cpp
    crosses initialization of `char f_name[5]'

    81 book_windows.cpp
    crosses initialization of `struct HDC__ * hDC'

    89 book_windows.cpp
    jump to case label

    83 book_windows.cpp
    crosses initialization of `char f_name[5]'

    81 book_windows.cpp
    crosses initialization of `struct HDC__ * hDC'

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You'll have to take your declarations out of your case labels -

    case WM_COMMAND:
    switch(LOWORD(wParam))
    { HDC hDC;
    char f_name[80];
    case CM_FILE_ENTRY:
    hDC= GetDC(hwnd);
    f_name[] = "Matt";
    TextOut(hDC, 10, 10, f_name, strlen(f_name));
    break;
    case CM_ABOUT_about :

    //etc

  3. #3
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    actually you can use brackets

    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case CM_FILE_ENTRY:
    {
    HDC hDC = GetDC(hwnd);

    char f_name[] = "Matt";
    TextOut(hDC, 10, 10, f_name, strlen(f_name));
    }
    break;
    case CM_ABOUT_about :
    MessageBox(hwnd, "about :\n Program: StarBook(Windows)\n Company: Starfield\n Authors: David & Matt\n E-mail: [email protected]\n Web site: none yet", "About", MB_OK + MB_ICONINFORMATION);
    break;
    case CM_FILE_EXIT:
    PostQuitMessage(0);
    break;
    }
    break;

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Also you are not releasing the DC you go with GetDC before the break.

    I use a | not a + for the messagebox flags. You don't need the MB_OK as this is the default.

    To format the text as centred try

    GetTextExtentPoint32(hdc, Title1, lstrlen(sTitle1), &Size);
    XStart=(int)(((DisplayRect.right)-Size.cx)/2);//center
    TextOut(hdc, XStart,YStart,sTitle1,lstrlen(sTitle1));
    YStart+=(int)(Size.cy);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM