Thread: Project - Help Plz

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    7

    Project - Help Plz

    Ok. Well. I have a prog. Here is code.

    Code:
    #include <windows.h> 
    #include <fstream> 
    
    #define IDR_MYMENU 101 
    #define IDI_MYICON 201 
    #define ID_FILE_EXIT 9001 
    #define ID_STUFF_GO 9002 
    #define ID_OPEN 9003 
    #define ID_SAVE 9004 
    #define ID_SELECT 9005 
    #define ID_MOVE 9006 
    #define ID_ROTATE 9007 
    #define ID_SCALE 9008 
    #define ID_DELETE 9009 
    #define ID_HELPTOPICS 9010 
    #define ID_ABOUT 9011 
    #define IDC_MAIN_EDIT 
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); 
    
    char szClassName[ ] = "WindowsApp"; 
    
    int WINAPI WinMain (HINSTANCE hThisInstance, 
                        HINSTANCE hPrevInstance, 
                        LPSTR lpszArgument, 
                        int nFunsterStil) 
    
    { 
        HWND hwnd;               /* This is the handle for our window */ 
        MSG messages;            /* Here messages to the application are saved */ 
        WNDCLASSEX wincl;        /* Data structure for the windowclass */ 
    
        wincl.hInstance = hThisInstance; 
        wincl.lpszClassName = szClassName; 
        wincl.lpfnWndProc = WindowProcedure;      
        wincl.style = CS_DBLCLKS;                  
        wincl.cbSize = sizeof (WNDCLASSEX); 
    
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); 
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 
        wincl.hCursor = LoadCursor (NULL, IDC_CROSS); 
        wincl.lpszMenuName = NULL;                  
        wincl.cbClsExtra = 0;                      
        wincl.cbWndExtra = 0;                      
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; 
    
        if (!RegisterClassEx (&wincl)) 
            return 0; 
    
        hwnd = CreateWindowEx ( 
               0,                   /* Extended possibilites for variation */ 
               szClassName,         /* Classname */ 
               "Halo Map Modelin Kit 1.0",       /* Title Text */ 
               WS_OVERLAPPEDWINDOW, /* default window */ 
               CW_USEDEFAULT,       /* Windows decides the position */ 
               CW_USEDEFAULT,       /* where the window ends up on the screen */ 
               600,                 /* The programs width */ 
               400,                 /* and height in pixels */ 
               HWND_DESKTOP,        /* The window is a child-window to desktop */ 
               NULL,                /* No menu */ 
               hThisInstance,       /* Program Instance handler */ 
               NULL                 /* No Window Creation data */ 
               ); 
    
    
        ShowWindow (hwnd, nFunsterStil); 
    
        while (GetMessage (&messages, NULL, 0, 0)) 
        { 
            TranslateMessage(&messages); 
            DispatchMessage(&messages); 
        } 
    
        return messages.wParam; 
    } 
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 
    { 
        switch (message)                  
        { 
            PAINTSTRUCT ps; 
            HDC hdc; 
            case WM_CREATE: 
                      HMENU m_MENU, m_SUBMENU; 
                      m_MENU = CreateMenu(); 
                      m_SUBMENU = CreatePopupMenu(); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_OPEN, "&Open"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SAVE, "&Save"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_FILE_EXIT, "&Exit"); 
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&File"); 
                      SetMenu(hwnd, m_MENU); 
                      m_SUBMENU = CreatePopupMenu(); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SELECT, "&Select"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_MOVE, "&Move"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_ROTATE, "&Rotate"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SCALE, "&Scale"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_DELETE, "&Delete"); 
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&Tools"); 
                      SetMenu(hwnd, m_MENU); 
                      m_SUBMENU = CreatePopupMenu(); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_HELPTOPICS, "&Help Topics"); 
                      AppendMenu(m_SUBMENU, MF_STRING, ID_ABOUT, "&About");      
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&Help"); 
                      SetMenu(hwnd, m_MENU); 
                                        
                 break; 
            case WM_DESTROY: 
                     PostQuitMessage (0);      
                break; 
            case WM_LBUTTONDOWN: 
                      
                 break; 
            case WM_RBUTTONDOWN:  
                                    
                 break; 
            case WM_COMMAND: 
                    switch(LOWORD(wParam)) 
                    { 
                         case ID_FILE_EXIT: 
                              if(MessageBox(hwnd, "Are you sure?", "Leave HaloMapModelinKit", MB_YESNO)== IDYES) 
                              { 
                                   PostMessage(hwnd, WM_CLOSE, 0, 0); 
                              } 
                         break; 
                         case ID_STUFF_GO: 
                         break; 
                          
                         case ID_OPEN: 
                         { 
        OPENFILENAME ofn; 
        char szFileName[MAX_PATH] = ""; 
    
        ZeroMemory(&ofn, sizeof(ofn)); 
    
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW 
        ofn.hwndOwner = hwnd; 
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; 
        ofn.lpstrFile = szFileName; 
        ofn.nMaxFile = MAX_PATH; 
        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; 
        ofn.lpstrDefExt = "txt"; 
    
        if(GetOpenFileName(&ofn)) 
        { 
            // Do something usefull with the filename stored in szFileName 
        } 
    
                          
    
                         } 
                         case ID_SAVE: 
                         { 
        OPENFILENAME ofn; 
        char szFileName[MAX_PATH] = ""; 
    
        ZeroMemory(&ofn, sizeof(ofn)); 
    
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW 
        ofn.hwndOwner = hwnd; 
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; 
        ofn.lpstrFile = szFileName; 
        ofn.nMaxFile = MAX_PATH; 
        ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; 
        ofn.lpstrDefExt = "txt"; 
    
        if(GetSaveFileName(&ofn)) 
        { 
            // Do something usefull with the filename stored in szFileName 
        } 
    
    
                         } 
                          
                         case ID_ABOUT: 
                         { 
                         // Code here 
                         } 
                                  
                         case ID_HELPTOPICS: 
                         { 
                         // Code here 
                         } 
                          
                         case ID_SELECT: 
                         { 
                         // Code here 
                         } 
                          
                         case ID_MOVE: 
                         { 
                         // Code here 
                         } 
                          
                         case ID_ROTATE: 
                         { 
                         // Code here 
                         } 
                          
                         case ID_SCALE: 
                         { 
                         // Code here 
                         } 
                          
                         case ID_DELETE: 
                         { 
                         // Code here 
                         } 
                          
                         break; 
                    } 
            break; 
    
    
            default:                      
                return DefWindowProc (hwnd, message, wParam, lParam); 
        } 
    
        return 0; 
    }
    I want it so when u click About on the Help Toolbar it shows sumtin like this:

    http://winprog.org/tutorial/images/dlg_one.gif

    I looked at code here. http://winprog.org/tutorial/dialogs.html

    But no luck. PLEASE PLEASE PLEASE help me. Make it so it does sumtin like that when you click About. Give me cpp or source code then. Thanks guys. Btw I'm usin BloodShed Dev C++ 4.9.80

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Change
    Code:
                   case ID_about : 
                         { 
                         // Code here 
                         }
    To
    Code:
                   case ID_about : 
                         { 
                         // Code here 
                         MessageBox(hwnd, "About", "My About Box", MB_OK);
                         }
    If your serious about this stuff, buy Programming Windows by Charles Petzold (SP?). Its a good book (may be able to find a chm avaliable on the net somewhere too).

    Edit: BTW, the type of dialog you want to make is whats usually made by whats called a Resource Editor. VC++ 6.0 has one, but I'm not sure if devC++ does (never used it).
    Last edited by nickname_changed; 02-20-2004 at 08:48 PM.

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    Wow. Thanks. Is there any way I can link that to a rc or have in the same file to change font and stuff? Like this.

    Code:
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END
    I'd like to be able to change font in main but a rc is good. Thanks so far

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    Anyone?

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    Bump

  6. #6
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Bumping threads will get them closed, so don't do it. Read the forum guidelines.

    Also, this thread is more to do with Windows programming than C++, so it's moving to the Windows forum...
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Regarding resource files, they're pretty easy to add. I assume you are using Dev-C++, your code looks very much like the windows app template code.

    So, create your .rc file. Press Alt+P to open project options. Go to the files tab, select your rc file in the list to the left and make sure that 'include in compilation' is checked (on the right)... Click 'Ok'..

    Now if your resource file is correct you can now use dialog templates (use the winprog tut, it explains it well IMO.).

    Also, if you want to change the font on a dialog or a non-dialog window you can send the WM_SETFONT message to it. You'll have to create a font unless you use the default stock font(s).

  9. #9
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    Thanks for all your help guys and sorry about bumping. I will remember that. Most forums for C++ programmin u can.

  10. #10
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    Gah. None of those worked. Step by step plz on how to change font. Here is example of what I want. I have this code.

    Code:
    #include <windows.h>
    #include <fstream>
    
    #define IDR_MYMENU 101
    #define IDI_MYICON 201
    #define ID_FILE_EXIT 9001
    #define ID_STUFF_GO 9002
    #define ID_OPEN 9003
    #define ID_SAVE 9004
    #define ID_SELECT 9005
    #define ID_MOVE 9006
    #define ID_ROTATE 9007
    #define ID_SCALE 9008
    #define ID_DELETE 9009
    #define ID_HELPTOPICS 9010
    #define ID_ABOUT 9011
    #define IDC_MAIN_EDIT
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      
        wincl.style = CS_DBLCLKS;                 
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_CROSS);
        wincl.lpszMenuName = NULL;                 
        wincl.cbClsExtra = 0;                      
        wincl.cbWndExtra = 0;                      
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        if (!RegisterClassEx (&wincl))
            return 0;
    
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Halo Map Modelin Kit 1.0",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               600,                 /* The programs width */
               400,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
    
        ShowWindow (hwnd, nFunsterStil);
    
        while (GetMessage (&messages, NULL, 0, 0))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
    
        return messages.wParam;
    }
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  
        {
            PAINTSTRUCT ps;
            HDC hdc;
            case WM_CREATE:
                      HMENU m_MENU, m_SUBMENU;
                      m_MENU = CreateMenu();
                      m_SUBMENU = CreatePopupMenu();
                      AppendMenu(m_SUBMENU, MF_STRING, ID_OPEN, "&Open");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SAVE, "&Save");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_FILE_EXIT, "&Exit");
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&File");
                      SetMenu(hwnd, m_MENU);
                      m_SUBMENU = CreatePopupMenu();
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SELECT, "&Select");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_MOVE, "&Move");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_ROTATE, "&Rotate");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_SCALE, "&Scale");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_DELETE, "&Delete");
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&Tools");
                      SetMenu(hwnd, m_MENU);
                      m_SUBMENU = CreatePopupMenu();
                      AppendMenu(m_SUBMENU, MF_STRING, ID_HELPTOPICS, "&Help Topics");
                      AppendMenu(m_SUBMENU, MF_STRING, ID_ABOUT, "&About");      
                      AppendMenu(m_MENU, MF_STRING | MF_POPUP, (UINT)m_SUBMENU, "&Help");
                      SetMenu(hwnd, m_MENU);
                                       
                 break;
            case WM_DESTROY:
                     PostQuitMessage (0);     
                break;
            case WM_LBUTTONDOWN:
                      
                 break;
            case WM_RBUTTONDOWN:  
                                   
                 break;
            case WM_COMMAND:
                    switch(LOWORD(wParam))
                    {
                         case ID_FILE_EXIT:
                              if(MessageBox(hwnd, "Are you sure?", "Leave HaloMapModelinKit", MB_YESNO)== IDYES)
                              {
                                   PostMessage(hwnd, WM_CLOSE, 0, 0);
                              }
                         break;
                         case ID_STUFF_GO:
                         break;
                         
                         case ID_OPEN:
                         {
        OPENFILENAME ofn;
        char szFileName[MAX_PATH] = "";
    
        ZeroMemory(&ofn, sizeof(ofn));
    
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
        ofn.hwndOwner = hwnd;
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
        ofn.lpstrFile = szFileName;
        ofn.nMaxFile = MAX_PATH;
        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
        ofn.lpstrDefExt = "txt";
    
        if(GetOpenFileName(&ofn))
        {
            // Do something usefull with the filename stored in szFileName 
        }
                         break;
    
                          
    
                         }
                         case ID_SAVE:
                         {
        OPENFILENAME ofn;
        char szFileName[MAX_PATH] = "";
    
        ZeroMemory(&ofn, sizeof(ofn));
    
        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
        ofn.hwndOwner = hwnd;
        ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
        ofn.lpstrFile = szFileName;
        ofn.nMaxFile = MAX_PATH;
        ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
        ofn.lpstrDefExt = "txt";
    
        if(GetSaveFileName(&ofn))
        {
            // Do something usefull with the filename stored in szFileName 
        }
                         break;
    
    
                         }
                         
                         case ID_ABOUT:
                         {
                         // Code here
                         MessageBox(hwnd, "Halo Map Modelin Kit 1.0 Beta 1\n\nMade By Deadly Shadow\n\nSpecial Thanks to Kaptain Kommie", "About Halo Map Modelin Kit", MB_OK);
                         }
                         break;
                                  
                         case ID_HELPTOPICS:
                         {
                         // Code here
                         }
                         break;
                         
                         case ID_SELECT:
                         {
                         // Code here
                         }
                         break;
                         
                         case ID_MOVE:
                         {
                         // Code here
                         }
                         break;
                         
                         case ID_ROTATE:
                         {
                         // Code here
                         }
                         break;
                         
                         case ID_SCALE:
                         {
                         // Code here
                         }
                         break;
                         
                         case ID_DELETE:
                         {
                         // Code here
                         }
                         
                         break;
                    }
            break;
    
    
            default:                     
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }

    Now. You see case ID_ABOUT: right?

    Well... Suppose I wanted to change stuff in there. Like. Verdana Font. Size 8. Blue bg. Etc. PLEASE step by step. I'm a noob to win32 but not uch to C++. Thanks yall

  11. #11
    Well, first use CreateFont() to make your font... Then send the WM_SETFONT message using the created font.

    I don't think you can change the text or the colors on a popup message though. I think it's best to use a dialog for that.

  12. #12
    Registered User
    Join Date
    Feb 2004
    Posts
    7
    What??? I don't know what ur talkin about sorry. Can u plz explain better on how to do that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Project for University plz help
    By kopros in forum C Programming
    Replies: 8
    Last Post: 12-15-2006, 12:48 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM