Jump to content
  • Advertisement
Sign in to follow this  
Dakar

Textbox Woes

This topic is 4708 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on a textbox program, and now I'm pretty much stuck. This is what I have so far: (note there's some code debris from earlier tests) WinToolBarTest.cpp:
#include "classheader.h"
//#include "Resources.h"
#include "menu.h"

/*  Declare Windows procedure  */


/*  Make the class name into a global variable  */
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 */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* 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 */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    UpdateWindow (hwnd);
    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */
 
Menu.h:
#ifndef MENU_H
#define MENU_H

#include "resources.h"


109 MENU
 BEGIN
   POPUP "&File"
     BEGIN
       MENUITEM "&Save", ID_SAVE
       MENUITEM "&Open", ID_OPEN
       MENUITEM "E&xit", ID_EXIT
     END
 END

#endif

Resources.h:
#ifndef RESOURCES_H
#define RESOURCES_H

#define IDR_MENU 103

#define ID_OPEN 1000
#define ID_SAVE 1001
#define ID_EXIT 1002

#endif

ClassHeader.h:
#ifndef CLASS_HEADER_H
#define CLASS_HEADER_H

#include <windows.h>
#include <commctrl.h>
#define IDC_MAIN_EDIT 100

class OpenClose //Handles toolbar and open/close functions.
{
  public:
         
         friend LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, //continuation
         WPARAM wParam, LPARAM lParam);
         
         OpenClose();
         //OpenClose(OpenClose &copy);
         ~OpenClose();
         
         void Button_Set();
         
  private:       
         //struct MiscItems
         //{
                HWND hTool;
                TBBUTTON tbb[3];
                TBADDBITMAP tbab;
         //}; 
         HWND TxtBox;
         HFONT DefTxt;      
};

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

    
#endif

ClassFiles.cpp:
#include "classheader.h"

OpenClose::OpenClose()
{
                      //MiscItems Button;
                      TxtBox = NULL;
                      DefTxt = NULL;                      
}

OpenClose::~OpenClose() {} //Nothing to see here, move along...

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_CREATE: //Generate a Textbox.
          {
             OpenClose set;
             
            set.TxtBox = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
            WS_CHILD | WS_VISIBLE | WS_VSCROLL | 
            WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 
            0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
            
            if(set.TxtBox == NULL)
            MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);

            set.DefTxt = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
            SendMessage(set.TxtBox, WM_SETFONT, (WPARAM)set.DefTxt, MAKELPARAM(FALSE, 0));
            
            set.Button_Set();
        
            break;
          }
        
        case WM_SIZE: //We don't the textbox to fill up only PART of the screen, right?
          {
             HWND TxtBox;
             RECT Update;
             
             GetClientRect(hwnd, &Update);
             TxtBox = GetDlgItem(hwnd, IDC_MAIN_EDIT);
             SetWindowPos(TxtBox, NULL, 0, 0, Update.right, Update.bottom, SWP_NOZORDER); 
             
             break;
          }
                   
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

void OpenClose::Button_Set() //Attach the buttons to our TextBox.
{
    tbab.hInst = HINST_COMMCTRL; //Where we find it.
    tbab.nID = IDB_STD_SMALL_COLOR; //The Bitmap?
    SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
    
    //This serves no function in the code yet, and should be cancelled out.
    
    /*ZeroMemory(tbb, sizeof(tbb));
    tbb[0].iBitmap = STD_FILENEW;
    tbb[0].fsState = TBSTATE_ENABLED;
    tbb[0].fsStyle = TBSTYLE_BUTTON;
    tbb[0].idCommand = ID_FILE_NEW;

    tbb[1].iBitmap = STD_FILEOPEN;
    tbb[1].fsState = TBSTATE_ENABLED;
    tbb[1].fsStyle = TBSTYLE_BUTTON;
    tbb[1].idCommand = ID_FILE_OPEN;

    tbb[2].iBitmap = STD_FILESAVE;
    tbb[2].fsState = TBSTATE_ENABLED;
    tbb[2].fsStyle = TBSTYLE_BUTTON;
    tbb[2].idCommand = ID_FILE_SAVEAS;

    SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);*/
}

Whenever I try to compile it, I get the following error:
7 C:\Dev-Cpp\menu.h syntax error before numeric constant 
It also can't find szClassName, although that is probably tied to the main error. I've been tearing my hair out trying to figure out what is wrong, so I hope somebody will be able to help. Thanks! ~Dakar

Share this post


Link to post
Share on other sites
Advertisement
menu.h does not contain valid C++ code, it contains statements for the resource compiler. Probably you should have called it menu.rc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
menu.h does not contain valid C++ code, it contains statements for the resource compiler. Probably you should have called it menu.rc.


Changing it solved the problem. Thanks!

~Dakar

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!