Thread: Say what is going on with this edit field?

  1. #16
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    the code is up there, is hasn;t changed much. what i added only was:

    Code:
    case CODE_HTML_QUICK_LINK:
    						char *ptr; 
    						char str[256]; 
    						GetWindowText(hEdit,(char *)&str,255);
    						lstrcpy((char *)&str,"<a href=\"mylink.html\"></a>");
    						SetWindowText(hEdit,(char *)&str);
    						break;
    im sorry, but like i said, i have a REAL problem giving out my source code. as in i REALLY dont like doing so. its probably just me. but lets see if we cant put all to gether

    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 CODE_HTML_QUICK_LINK:
    						char *ptr; 
    						char str[256]; 
    						GetWindowText(hEdit,(char *)&str,255);
    						lstrcpy((char *)&str,"<a href=\"mylink.html\"></a>");
    						SetWindowText(hEdit,(char *)&str);
    						break;
    					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);
    	}
    }
    hows that? i just went and posted the code.
    ~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. #17
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You have not included your header and resource script, so I can't compile it. Also, the program does not include the snippet you have included above.

    I am not really clear about this, but should you be using strcat() rather than strcpy()?

    >>> i have a REAL problem giving out my source code.

    Why? You'll find that people do simply not have the time to study code, even really short programs like this, to try to debug it in their head. They will want to compile it, see what it does, understand the actual problem, (people are notoriously bad at describing their expectation and the actrual behaviour), then go to the debugger.

    In an ideal world, I would be able to spend all day everyday helping people, but my wife won't let me!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #18
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    darkviper, surely that program does not compile, and if it does, it would never function properly. there are many issues to clear up.

    1. you dont translate your message
    2. your WM_CREATE capture doesn't return a value. it should return DefWindowProc(...)
    3. In WM_SIZE, you resize the edit control twice. why?
    4. WM_SIZE should return DefWindowProc, not 0.
    5. WM_SETFOCUS continues straight on to WM_COMMAND. very bad.
    6. what is the point of the DARKCODE_NEW code? you wrote so many lines where only 1 is necessary.
    Code:
    SetWindowText(hEdit,"");
    Why is the buffer 80 characters long when your string is only 1 char long?
    7. CODE_HTML_QUICK_LINK capture breaks instead of return 0.
    8. CODE_HTML_QUICK_LINK capture wastes time by declaring a pointer AND a local array. only use pointers for that kind of thing.

    and thats about it. please, just post your entire program. we promise we wont plagarise it, or steal even a snippet of code from it.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #19
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    fine, you got me. thats not my most updated source. in fact, it does compile. there are 4 files
    main.cpp
    menus.h
    resource.h
    resource.rc

    heres a couple problems now. when i try to compile, it gives me this error:
    ../DarkCode/rm | Permission Denied
    ../DarkCode/Makefile.win | [Build Error] [clean] Error 1

    heres the thing, i dont have ANY files accoiated or even related to a filename named rm. but if you spot it in any source files, PLEASE tell me!

    i would also like to know how to make a bitmap named dc.bmp show up on my main program background.

    i have a couple more questions. but ill stick to one right now.


    this is a bit of a long read, but try to compile, as many have been fixed, contrary to what the previous post said. it does translate messages, i just didn;t want to post my newest script.

    main.cpp
    Code:
    *source code taken down, sorry :(

    it may compile differently on MSVC++, because this was compiled with Bloodshed. but give it a try.

    one more thing, how can i set the text length for hEdit to be unlimited?

    again, thank you for your help.


    the cool thing is to me, is i typed this all up by hand. nothing produced code for me!
    Last edited by DarkViper; 01-14-2003 at 09:52 PM.
    ~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. #20
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    A great way of getting an hInstance is:

    // ...

    static HINSTANCE hInstance;

    // ...

    case WM_CREATE:
    hInstance = *((LPCREATESTRUCT) lParam)->hInstance;

    // ...

  6. #21
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    wow. i mean, wow. thats a hell of a lot a code there darkviper. usually, people only post the code that produces the error, but i guess you want us to do all the work ey? find out where the actual error is. i dont know about other people, but i dont have the time to check through pages and pages of code looking for the error.

    you'd make things go a lot quicker if you debugged it by yourself. then, once the problem code is isolated, you can post it up and others can help you to solve it. in the meantime, i guess i'll be nice and attempt to compile it.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #22
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i cant believe, theres so much code i cant even copy it into my compiler. you couldn't attach the files could you?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #23
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    ok, third post in a row, ill stop soon. the code compiled relatively fine on MSVC++, just a few simple errors that any programmer could fix. now that i see the program in action im beginning to change my mind about it. perhaps it is worth all the trouble and effort you must have put into it. one thing is, the scroll bar goes into the status bar, but that shouldn't be too hard to fix.

    i guess you'll have to get someone else to compile it, someone who has bloodshed, because it works fine for me.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #24
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Next time, zip the files together and post the .zip, when you post a message, there is an "Attach file" box, hit the browse button and navigate to the zip.

    Now, what I did was started with the .cpp. Visual Studio would not let me load it because your HELP_QHELP was too big for VC to handle, (actually I didn't know that!), so I just edited a load of it out.

    The .h's loaded okay.

    The resource script includes an icon and a cursor which I didn't have so I just commented that out in the resource script.

    Then I built it, and I'm afraid to say, yes, it compiles fine, and runs. As Ben pointed out, your editbox needs to be sized a little differently because it is overwriting the status bar when there is more than a page of editing.

    So, what could be wrong?

    Does your help/documentation tell you anything useful about "Error 1"?

    Maybe you should try trimming your HELP_QHELP the way I had to and see if that helps. Could be you are blowing up the compiler and that is it's way of telling you so.

    IDE's have a habit of creating a whole bunch of intermediate files when compiling a project. Have you an option to delete and re-create these? With VC there is a "Clean" option on the build menu which does just that. Sometime the intermediate files can get out of step and screw things up, that is why the IDE's don't like you editing these files.

    If you can't do that, can you open a completely new project and add the four files and try again?

    Is "rm" a .exe on your system? With VC, when you "rebuild all", the environment runs the resource compiler the code compiler the linker etc., these all have relatively cryptic names. It could be you don't have access too, or your IDE cannot find one of it's own components, possibly, if it is easy, reinstall the package.

    Ask Bloodshed, there is a forum here...

    http://sourceforge.net/forum/forum.php?forum_id=48211

    Can you get Visual Studio?

    I'm really sorry that I couldn't help more, but unless I can see the error, I can't fix it! That really is a lot of work you've done there - stick with it. Once you got it to compile, then we will certainly try to help you with your other questions, (although you should open a new thread for them).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #25
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    damn... sorry, i forgot about the zipping part i thought "damn, im only goiing to be able to post one source at a time!"

    anyways, just after i pressed "submit" a kid IM'ed me on AIM (my cantact name is darkviperVV) (a kid that i knew, klinerr ) and he saud "it maybe just your compiler being electronically lazy to compile your program, try rebooting and recompiling"

    well, maybe so, the comp had been running ALL day. and my project was open about 90% of the time it was on. so maybe a reboot was needed. if it compiled on yours, then it should work.


    btw, the QHELP function, it has compiled with that since like, last month! so that couln't be the problem.


    maybe itll compile now.


    as for the edit box overlapping the tool bar, ive been trying to fix it, sizes are different on each operating system, and im ALWAYS working in 1024x756 screen res. if your running in 800x600 or any others, i dont know.ill have to test that.

    ill try recompiling it when i get home. if it doesn;t work, ill see what i can do abut reverting it.

    ill try to include the icons and cursors next time

    the help file, i grayed that out until i figure out ho to make a .hlp file.

    as for rm. i have NEVER heard of it in my life! this is the first time its done this, then again, this is my first windows program (ive done a good job eh? ) and ive only been doing consol stuff before.

    rm...rm...rm....i dont know, maybe itll be good now.


    btw, i cant get Visual Studio, due to, here are my system stats here:

    only 400 MB left on my system (out of 2 GB)
    200MGz
    Pentium MMX
    32MB RAM

    those are THE main resons i cant have visual studio, or hats what i would have started with! i cant wait for my new computer.


    ill post a zip next time.
    ~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. #26
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>>
    "it maybe just your compiler being electronically lazy to compile your program, try rebooting and recompiling"
    <<<

    Of course, it is always worth a reboot!

    >>> QHELP function

    Fair enough - it broke VC though. You might want to remember that if you ever get enough space for VC! I have VC++ 6 Pro on a 233 Mhz PII system, it used to work with 32 MB but crawled, that machine has 160MB now. Works just fine with projects up to 200,000 lines of code. It is slower than this machine of course, (2.53 GHz P-IV 512MB PC2700 DDR RAM and 80 GB disk), but what could you expect!

    >>> edit box overlapping the tool bar,

    I didn't see it overlapping the tool bar, it was the status bar at the bottom that was being corrupted.

    >>> if your running in 800x600

    I'm 1280x1024.

    >>> as for rm. i have NEVER heard of it in my life

    Use your search option, I'd bee interested to know if there is a component called that.

    >>> this is my first windows program

    I would say there is hope for you. Most people moving from a console to Windows are starting to get lost with the WM_PAINT handler! Keep it up - as I said - there is hope there, if you have that kind of patience and dedication in the face of the adveristy you have, you could end up a pro.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #27
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    YAY! it works!

    i just compiled it where i am. in MSVC++, MSVC++ rules, i cant wait to be able to get it,.
    ~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. #28
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    congratulations. i cant wait for the next version to come out.

    about getting a decent computer, its not really that expensive, at least, if you just want a programming comp. you wont have to get a good video card or monitor, or a large hard drive. m'boards aren't that expensive, and processors and ram cost nearly nothing. i just got my new computer a couple months ago, before that i had the cheapest hunk a junk ever. but i saved up the money for a bit, and now i have a top of the line system. There is still hope.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  14. #29
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    now, knowing me, id be gaming too. so a graphics card comes to mind. a cheap 3d card is needed. as well as a burner..as for a scanner, ive lived without one. but also dont forget, everything is cheaper in the US and autralia. here in canadam its 1.5 exchange rate between canada and the US, so, just a stripped tower, with a mother board, a graphics card, 1.7GHz, (unknown ram, i forgot), and 40GB of space, comes close to $700 canadian.

    it aint pennies here

    i gots a couple more question, about the code
    please tell me:

    how i could make a bitmap appear (the way i was shown didn;t work)

    Set the text limit to a different amound (more or less, NO limit, but anything is better than 21.9k or less), i think the function is SetLimitText or something, but i dnt know how to use this, or where to put it.

    adding text to what the user has already typed in, at the very end fo the document, to what i want it to say. like i was describing WAY above. remember? well, it still didn;t work. it replaces everything that was originally typed in with the code that was placed in when they clicked the menu item.

    optional: Syntax Hiliting, how do i do this???????? there has got to be a WS_UPDATE or something similar, so for a stored array data, if a word typed in looks exactly like it, itll change color. but i need this to also export as normal text, and not with the coloring, or will it matter?

    any or all questions answered would be hot, thank you.

    i cant wait till the next version comes out either windows programming is so much fun when it works
    ~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. #30
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Bitmaps:
    Code:
    HDC hdc,hdc2;
    HBITMAP hBit;
    BITMAP bm;
    
    hBit=(HBITMAP)LoadImage(NULL,"pic.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    			
    hdc=GetDC(hwnd);
    hdc2=CreateCompatibleDC(hdc);
    
    SelectObject(hdc2,hBit);
    GetObject(hBit,sizeof(BITMAP),&bm);
    BitBlt(hdc,300,0,bm.bmWidth,bm.bmHeight,hdc2,0,0,SRCCOPY);
    
    ReleaseDC(hwnd,hdc);
    DeleteDC(hdc2);
    What happens here is:
    1. A standard loadimage
    2. Get the device context for the window
    3. Create a compatible memory device context (bitmaps can only be put onto memory DCs.
    4. Select the bitmap into the memory DC
    5. Get bitmap data for dimensions
    6. BitBlt from one to the other. this means just transferring the pixel data.

    Any decent reference will have info on all the functions used there. if you dont have a reference, i recommend the Win32 Programmer's Reference by Microsoft. i dont remember where i got it but someone else will.

    Set text limit:
    EM_SETLIMITTEXT
    SendMessage(hEdit,EM_SETLIMITTEXT,0,0);
    Sets it to the maximum possible. (65k for multilines)
    If you want to change the limit:
    SendMessage(hEdit,EM_SETLIMITTEXT,(WPARAM)nLimit,0 );
    You can also allocate your own buffer, but i doubt you'll need that.

    Syntax Highlighting:
    Cant be done with an edit. You'll need to use a rich edit control. Dont worry, rich edits aren't that much harder than edit controls. But id save it till the next version.

    Adding text at end of document/at cursor:
    I can remember the proper way to do this, but a dodgy way is to GetWindowText into a buffer, lstrcat the addition onto the end of it, and SetWindowText it back.
    Another dodgy way:
    Create a function called SendKeys
    Pass the string you want to it
    In the function, loop through every character in the string and manually send a WM_KEYDOWN message. That way, the string will be inserted at the cursor. Then you could hook up a timer and have it type itself in kind of slow, to look real cool, like the computers alive or something.

    Any probs, just post it.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

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, 12: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