Say what is going on with this edit field?

This is a discussion on Say what is going on with this edit field? within the Windows Programming forums, part of the Platform Specific Boards category; for some reason, with this edit field, you cant type anything! for some reason, it shows, but you cant type ...

  1. #1
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343

    Say what is going on with this edit field?

    for some reason, with this edit field, you cant type anything! for some reason, it shows, but you cant type anything! i want to know wtf is going on here! ive tried everythig i can think of, i even went and retyped it all out! tell me why this wont work!
    Code:
    #include <windows.h>
    #include "menus.h"
    #define IDC_MAIN_TEXT   100001
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    HINSTANCE hInstGlobal;
    HWND hEdit;
    int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	WNDCLASS darkclass;
    	darkclass.style = 0;
    	darkclass.cbClsExtra = 0;
    	darkclass.cbWndExtra = 0;
    	darkclass.lpfnWndProc = WndProc;
    	darkclass.hInstance = hInstance;
    	darkclass.hbrBackground = (HBRUSH) (COLOR_3DSHADOW+1);
    	darkclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    	darkclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    	darkclass.lpszMenuName = "MAIN";
    	darkclass.lpszClassName = "darkcode";
    	
    	RegisterClass(&darkclass);
    	
    	HWND darkwindow;
    	
    	darkwindow = CreateWindow("darkcode", "DarkCode v1", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE, 5, 5, 800, 600, NULL, NULL, hInstance, NULL);
    	ShowWindow (darkwindow, nCmdShow);
    	UpdateWindow (darkwindow);
    	
    	MSG message;
    	while (GetMessage(&message, NULL, 0, 0))
    	{
    		DispatchMessage(&message);
    	}
    	
    	return (message.wParam);
    }
    LRESULT CALLBACK WndProc (HWND hwnd, UINT uimessage, WPARAM wParam, LPARAM lParam)
    {
    	switch(uimessage)
    	{    	
    		case WM_CREATE:
            hEdit = CreateWindow("EDIT", "",WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |
                   ES_WANTRETURN | WS_BORDER,
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                hwnd, (HMENU)IDC_MAIN_TEXT, hInstGlobal, NULL);
                
                SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,
                (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
            break;
        	
        	case WM_SIZE:
        	    /*
        		GetClientRect (hwnd, &rect);
        		MoveWindow (hEdit, 0, 0, rect.right, rect.bottom,TRUE);
        		*/
        		if(wParam != SIZE_MINIMIZED)
                MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),
                   HIWORD(lParam), TRUE);
        		return 0;
       		case WM_SETFOCUS:
             SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
             
       		case WM_COMMAND:
       			if (HIWORD(wParam) == 0)
       			{
       				switch LOWORD(wParam)
       				{
       					case DARKCODE_NEW:
       						char *EditString;
       						EditString = new char[80];
       						lstrcpy (EditString, "");
       						SetWindowText (hEdit, EditString);
       						delete [] EditString;
       						return 0;
    					case DARKCODE_EXIT:
    						PostQuitMessage(0);
    						return 0;
    					case HELP_ABOUT:
    						MessageBox(NULL, "Hi, this is DarkCode, enjoy", "DarkCode v1", MB_OK);
    						MessageBox(NULL, "Thnk you for choosing DarkCode v1", "Thanx", MB_OK);
    						return 0;
    				}
    			}
    			return 0;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    		default:
    			return DefWindowProc (hwnd, uimessage, wParam, lParam);
    	}
    }
    and thats the entire main.cpp file.

    im also having a little trouble here too:

    say my resource script for my MAIN menu is
    Code:
    MAIN MENU
    {
    POPUP "&File"
    {
    MENUITEM "New", FILE_NEW
    MENUITEM "Exit", NEW_EXIT
    }
    POPUP "&Option"
    {
    MENUITEM "Help Boxes", OPT_HELPBOXES
    }
    }
    now of course, this isn;t my real resource script, that would be silly, but say i wanted "Help Boxes" menu item to be checkmarkable, what attribute would i put in there because CHECKED doesn;t work
    MENUITEM "Help Boxes", OPT_HELPBOXES, CHECKED
    yeah, that doesn;t work, so what should i so?

    please people, please answer these two, ill be forever grateful!
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    For your first question:
    Code:
    	MSG message;
    	while (GetMessage(&message, NULL, 0, 0))
    	{
    		DispatchMessage(&message);
    	}
    Try this:
    Code:
    	MSG message;
    	while (GetMessage(&message, NULL, 0, 0))
    	{
    		TranslateMessage(&message);
    		DispatchMessage(&message);
    	}

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You also have some other errors. Your WinMain should be WINAPI not APIENTRY. You have correctly created a global for your instance variable, but you are not setting it up. Your WM_CREATE handler does not return a value. The LOWORD values in your WM_COMMAND handler do not match your resource file.

    There are probably others...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    k, ill give those suggestions a try, i hope they work -_-' im still a little new the win32 programming and something just slip me, im glad to have made it this far without referance really....no-one really has helped me on this subject before... thanks!

    ps. if it dont work, ill say what else is wrong and post the source again.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  5. #5
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    can't you just use GetModuleHandle() instead of making a global HINSTANCE?

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> can't you just use GetModuleHandle() instead of making a global HINSTANCE?

    You can get the module handle in several ways, but why bother, the system gives it to you for free - why run a stack push, a jump, the assignment, the stack unwind and another PC adjustment?

    There is an ancient reason for treating global variables as a sin. Todays environments do away with that. A global variable is often a far more efficient solution than the hoop jumping that some people get up to to avoid a global.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    >> There is an ancient reason for treating global variables as a sin. Todays environments do away with that. A global variable is often a far more efficient solution than the hoop jumping that some people get up to to avoid a global.


    I don't get it. In today's environment machines are fast enough that in all honesty, you're not going to notice the far more efficient solution of a global var over a function call such as GetModuleHandle(NULL); Even at that why not have yourself a static HINSTANCE in the window process - no repeated calling of GetModuleHandle, and no globlal

    -Futura
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  8. #8
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    bah, i used a global variable and you can actually type now! i even got all the exports and saves work, i now have 2 more questions.

    1. making a menuitem checkmarkable and unchecked when clicked. i used in my resource:
    MENUITEM "PHP", SYN_PHP, CHECKED
    and it worked, but you cant uncheck it. how do i make it so you can switch it on or off?

    2. adding text to an edit field. like say, when someone clicks on the menu item, some more text appears, but doesn't erase the original text. like say the user has typed in
    Code:
    <?
    $var = 5;
    $name = "jake";
    ?>
    and "jake" forgets how to make text appear, so he goes to
    Code Snippets>PHP>Echo
    and i then want the code: ' echo "text here"; ' to appear at the end of the document, then the user copies and pastes the thing to where he wants it and changes "text here" to whever he wants to say, like
    Code:
    <?
    $var = 5;
    $name = "jake";
    echo "hi im $name, and im 1$var years old";
    ?>
    so i guess the question is, what code do i put in my project to make the php function appear on the edit field when the user clicks the menu item?

    it looks like this right now:
    Code:
    case CODE_PHP_ECHO:
    break;

    thank you.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    1. Probably the most flexible way of manipulating your menu items is to set up a MENUITEMINFO structure and call the SetMenuItemInfo() API function.

    2. You can manipulate the contents of an edit box by calling GetWindowText() to read the contents into a buffer and SetWindowText() to write it back.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    ok, i like that second one, how would i be able to do that?

    the edit field is called hEdit, just a small example, unless its like 20 lines of code, then you dont have to. but at least tell me how to do it with an example. just a small one. it doesn;t have to be an entire windows shell, just whatever needs to be inbetween
    case CODE_PHP_SETUP:
    break;

    and ill be happy. cuz when i figure out how to do that, i have ALOT of work to do -_-', but vreating my first app is so much fun, and im learning all sorts of things! and this is one extra that is NEEDED for my program.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  11. #11
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    GetWindowText and SetWindowText are fundamental functions that you have to learn how to use if you do anything. i mean, why have an edit box if you dont know how to process whats in it?

    here's how to use them:

    1. Create a buffer to hold a string. Either create a local buffer of a set size or create a pointer and allocate memory for it. ie:
    Code:
    char *ptr; //Create pointer
    ptr=(char *)malloc(256); //Allocate 256 bytes and set the pointer to it
    
    char str[256]; //Create a local stack buffer of 256 bytes
    2. Pass a pointer to the buffer to the function.
    Code:
    GetWindowText(hwnd,ptr,255);
    GetWindowText(hwnd,(char *)&str,255);
    255 is the maximum characters to copy to the buffer, leaving space for a null-terminator

    For SetWindowText, just put your text into the buffer and pass the pointer:
    Code:
    lstrcpy(ptr,"Window Text");
    SetWindowText(hwnd,ptr);
    
    lstrcpy((char *)&str,"Window Text");
    SetWindowText(hwnd,(char *)&str);
    see, simple. i just hope you know what all the terminology means. just ask if you dont, its important to understand it all.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  12. #12
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    i can set that 256 to any number i want right? because, surly there is going to be alot of text entered when they use this menu function. know what i mean?
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> i can set that 256 to any number i want right?

    Within reason, yes. If you want to make a big buffer, allocate the memory on the heap, (i.e. use new or malloc()), rather than on the stack, (i.e. by declaring a damn great big buffer as an array).

    Remember also, if you are allocating dynamic memory with new or malloc(), to release it when you have finished with it using delete or free(). Note new/delete are the C++ way of doing this, malloc()/free() still work but there may become a time when they won't. I would advocate using new/delete for allocating heap memory.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    uhh guys, im sorry, i tried the code (everything you said) and it created erros, i fixed it, then it somehow changed the title of the program to wehatever the "Window Text" was, then i modified it so its always pointing to hEdit, the edit field, but then when you select it, it erases everything before that you typed in and replaces it with "Window Text", what am i doing wrong!
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  15. #15
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    post ALL of your code for us to look at. actually, attach your .cpp, its easier that way
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 01:03 AM
  2. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  3. Subclassed edit not doing what it's supposed to
    By tyouk in forum Windows Programming
    Replies: 8
    Last Post: 01-21-2005, 10:25 PM
  4. Used to be Say what is going on with this edit field?
    By bennyandthejets in forum Windows Programming
    Replies: 5
    Last Post: 01-11-2003, 06:38 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM

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