Tabbed Windows with MDI?

This is a discussion on Tabbed Windows with MDI? within the Windows Programming forums, part of the Platform Specific Boards category; Your code is off. First of all, there is no need to call GlobalAlloc(). Regular malloc() works just fine. Also ...

  1. #16
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Your code is off. First of all, there is no need to call GlobalAlloc(). Regular malloc() works just fine. Also you need to call GetWindowText() to get the text.

  2. #17
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    hM..whoops. a good point with the whole GetWindowText()..i had that originally in my code, but it was commented out so when i posted, i deleted it. lol but what do i store the window text in? like, what kind of variable? or how does that work? lol
    also, my child windows have a title. doesn't GetWindowText() retrieve the title of a window?
    Last edited by willc0de4food; 05-18-2005 at 09:26 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Yeah, GetWindowText() would just get the title text of a Child window. You need to pass the HWND of the window you want to get the text of (Like an EditBox) to GetWindowText().

    The proper use of the function would look something like:
    Code:
    TCHAR szText[1024];
    HWND hwndEdit = GetDlgItem(hwnd,IDC_MYEDIT);
    if(hwndEdit)
    {
       GetWindowText(hwndEdit,szText,sizeof(szText)/sizeof(TCHAR));
    }

  4. #19
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    ok, and then to modify the text entered i would modify szText? and then send that text back to the window?


    // edit
    yay ^_^ i got it to work. here's my code:
    Code:
    case ID_SHIBBY_ENCRYPT:
                        {
                             char algorithm[25] = "Az!By@Cx#Dw$Ev%Fu^Gt&Hs*";
                             int i;
                             DWORD dwTextLength;
                             dwTextLength = GetWindowTextLength(hwnd);
                             if (dwTextLength <= 0) MessageBox(hwnd, "There is no text to encrypt.", "Error.", MB_OK | MB_ICONERROR);
                             else if(dwTextLength > 0)// No need to bother if there's no text.
                             {
                                    LPSTR pszText;
                                    pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
                                    if (pszText == NULL) MessageBox(hwnd, "An error occured.\n\nWhoops!", "OOPs!", MB_OK | MB_ICONERROR);
                                    else if(pszText != NULL)
                                    {
                                      TCHAR szText[1024];
                                      HWND hwndEdit = GetDlgItem(hwnd,IDC_CHILD_EDIT);
                                      DWORD txtLength;
                                      txtLength = GetWindowTextLength(hwndEdit);
                                      if(hwndEdit)
                                      {
                                         GetWindowText(hwndEdit,szText,sizeof(szText)/sizeof(TCHAR));
                                      }     
                                      MessageBox(hwnd, szText, "szText variable", MB_OK);
                                      if(szText != NULL)
                                      {
                                             for (i = 0; i <= txtLength; i++)
                                             {
                                                 szText[i] = szText[i] ^ algorithm[i % 24];
                                             }
                                             SetWindowText(hwndEdit, szText);
                                      }
                                    }
                             }                                    
                        }
                        break;
    now if i wanted to add a required password to decrypt.. how would i incorporate this? i was thinking either having a master password and then storing it in the same directory as the program or a folder inside that which contains the program, OR having a password to be entered for each save. however, this could be bad b/c if i put more then 1 password, i may not remember what pw i did for which file. but i think i want to first prompt the user to set a password if the password doesn't exist (the password existing in the file would be encrypted also). so any suggestions? lol
    Last edited by willc0de4food; 05-18-2005 at 05:45 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #20
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Yep. Using the Message WM_SETTEXT, or by using an API. I forget which one; I don't like to use them unless necessary. It's probably SetWindowText() or similar. Of course, I would hope that you know this already.

  6. #21
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    would this code be better for my purposes:
    Code:
    case ID_SHIBBY_ENCRYPT:
    {
    char algorithm[31] = "Az!By@Cx#Dw$Ev%Fu^Gt&Hs*Ir(Js)";
    char* buf;
    int i, len;
    HWND hwndEdit = GetDlgItem(hwnd,IDC_CHILD_EDIT);
                             
    len = GetWindowTextLength(hwndEdit);
    buf = (char*)GlobalAlloc(GPTR, len + 1);
    GetDlgItemText(hwnd, IDC_CHILD_EDIT, buf, len + 1);
    
    for (i = 0; i &lt;= len; i++)
    {
        buf[i] = buf[i] ^ algorithm[i % 30];
    }
    SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM)buf);
    }
    break;
    ?
    i would assume so, because its shorter and i believe its more efficient but i'm just talking out of that which i am sitting on


    also, i'm having a little trouble with decrypting the text after i encrypt. here's an example:
    original text: This is some text. This is text tabbed.
    This is text on a new line.

    Encrypted text: H1Y)0XP+Ae@>pN N!

    Decrypted text: This is some text. This
    the tabbed text was actually tabbed, but the post untabbed it.? lol
    Also, this text encrypts / decrypts perfectly:
    This is some text. This is text spaced over 6 spaces.
    This is text on a new line.

    other times, the decrypted text will have some junk characters that are not readable. how do i fix this? :-[ please and thank you!
    Last edited by willc0de4food; 05-18-2005 at 11:19 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #22
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Don't forget to check any memory allocs for fails and to free them when finished.

    Use the text length in GetWindowtext() not the length +1
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #23
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    thanks one last thing.. how would i close all open child edit windows?
    Registered Linux User #380033. Be counted: http://counter.li.org

  9. #24
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Are these MDI child windows?

    If so, do something like the following:
    Code:
    BOOL CALLBACK CloseEnumProc(HWND hwnd, LPARAM lParam)
    {
    	if(GetWindow(hwnd,GW_OWNER))
    	{
    		/* Window is an icon title */
    		return TRUE;
    	}
    
    	/* Close the window */
    	SendMessage(hwnd,WM_CLOSE,0,0);
    	return TRUE;
    }
    // ....
    EnumChildWindows(hwndClient, CloseEnumProc,0);

  10. #25
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    sweet thanks..i'll try that when i get home. i knew i shouldn't have checked at work now i'm anxious and i have to wait til after 9. but yea, here's a compiled version that i've been working on so far..
    here (hosted on my pc)
    here (hosted by angelfire)
    here (hosted by freewebs)
    Registered Linux User #380033. Be counted: http://counter.li.org

  11. #26
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    :-D sweet.. i got it to work ^_^ i used your function but before the call to it, i had to declare hwndClient and i tried using the hwnd var i declared at the beginning of the function so i tried HWND hwndClient = GetDlgItem(hwnd, IDC_CHILD_EDIT); but obviously that didn't work.. but what DID work was:
    Code:
    HWND hwndClient = GetWindow(g_hMainWindow, GW_CHILD);
     EnumChildWindows(hwndClient, CloseEnumProc,0);
    however, i have yet to resolve the whole "setting a password for decryption" problem.. i want to create a dialogbox that prompts the user to enter the password they would like to set. then i would like to take the password they create, encrypt it, maybe add some text to the beginning and end of it just to make it more secure, and then save it in the same folder as that which the program is being run in. I can do the whole file save / manipulation thing as I know C, but how would i create the dialog prompt and then get the text entered in the prompt?


    // edit
    ok, i created the dialog and can get / manipulate the text. but i also need to store the length of the original string as i believe thats the reason i have having problems with decrypting the string in the beginning. so i want to take the length of the string and append it to the beginning of the encrypted string, but i've been running in to problems here (i think, i was pretty tired last night). but i'm at work so i have to go, just figured i'd update...
    Last edited by willc0de4food; 05-20-2005 at 02:00 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  2. Editor design: Traditional MDI versus Tabbed MDI
    By psychopath in forum Game Programming
    Replies: 7
    Last Post: 01-22-2007, 07:48 AM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 01:19 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 10:37 AM

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