MessageBox, changing text.

This is a discussion on MessageBox, changing text. within the Windows Programming forums, part of the Platform Specific Boards category; How would I make the text change in my MessageBox? Lets say I want a count to 10. So how ...

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    MessageBox, changing text.

    How would I make the text change in my MessageBox?
    Lets say I want a count to 10.
    So how would I make it type count without making 10 diffrent MessageBox'es?

    And how do I make the MessageBox show in front?
    I got a full screen program, but you need to go out of it to see the MessageBox.
    I want to be able to see it in the fullscreen.

    Thanks
    Last edited by XunTric; 01-14-2006 at 02:12 PM.

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Washington D.C.
    Posts
    25
    I cannot help you with the latter, but as for counting to ten

    Code:
    char *buffer = (char *)malloc(64);
    
    for(int i = 1; i <= 10; i++)
    {
        sprintf(buffer, "%u", i);
        MessageBox(0, buffer, 0, 0);
    }

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    That makes 10 MessageBox'es which prints one number each.
    I want 1 MessageBox which counts to 10 without making new boxes.

    Still thanks for helping!

  4. #4
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    MessageBoxes really arnt designed for doing what your asking, your best option would be to create your own dialog for displaying the messages and updating them.

    If you really want to use a message box, then you could get a handle to the messagebox widnow, then a handle to the static text (child window) inside the parent message box and update it from your main program. You might have to use a seperate thread to do this, and you do it i think with the FindWindow() function. Once you have a correct handle you could use SetWindowText() to update the messagebox. Alot of work though, you would be better off making your own custom message box dialog.

    I just had a quick look using Spy++ and a messagebox dialog window has a class name of #32770 (Dialog) and the window name is what you set it as in the MessageBox() function.

    Hope thats some help.
    TNT
    You Can Stop Me, But You Cant Stop Us All

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    XMsgBox does exactly this. You can download it here (near the bottom).

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    One more, still ten messageboxes but automated:
    Code:
    #include <windows.h>
    
    typedef int (WINAPI *MyProcA)(HWND, LPCTSTR, LPCTSTR, UINT, WORD, DWORD);
    
    int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
    	HMODULE hUser32 = LoadLibrary("user32.dll");
    	MyProcA MessageBoxTimeoutA = NULL;
    	char szInt[32] = {'\0'};
    	int i;
    
    	if(hUser32)
    	{
    		MessageBoxTimeoutA = (MyProcA)GetProcAddress(hUser32, "MessageBoxTimeoutA");
    
    		if(MessageBoxTimeoutA)
    			for(i = 1; i < 11; i++)
    			{
    				wsprintf(szInt, "%i", i);
    				/* int MessageBoxTimeoutA(HWND hWnd, LPCTSTR lpText,
    				 * LPCTSTR lpCaption, UINT uType, WORD wLanguageId,
    				 * DWORD dwMilliseconds)
    				 */
    				MessageBoxTimeoutA( NULL, szInt, "Information:", MB_OK, 0, i * 150);
    			}
    
    		FreeLibrary(hUser32);
    	}
    	
        return(0);
    }

  7. #7
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    //anonytmouse

    Thats C, forgot to say im coding C++.

    //TNT

    Im not really sure how to do this.
    This was my best try. :P

    Code:
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    
    HWND hwnd;
    
    int main()
    {
        MessageBox(NULL, "Test Text", "Test Title", MB_OK);
        
        hwnd = FindWindow(0, "Test Title");
        SetWindowText(hwnd, "New Text");    
    }

  8. #8
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    What you have done there is correct so far, but it will only change the title of the message box , and the problem is that your program state is paused until the ok button is pressed on the created message box. This is why all of your findwindow() e.t.c code will have to go in a seperate thread i think, i would give you some code for the thread but i cant rembmer how to do them properly. But heres some code for how you would change the main meassage rather than the title.

    Code:
    HWND h_msgbox;
    HWND h_msgbox_text;
    
    h_msgbox = FindWindow(0, "Test Title");
    
    if(h_msgbox != NULL)
    {
    // window found now get the static text handle to change.
    
    // Im not sure as i dont have a compiler but you probably have to use the SetParent() function here, so it searchs the parent HWND for the child HWND.
    
    h_msgbox_text = FindWindow(0, "Message Box Text");
    
    if(h_msgbox_text != NULL)
    {
    SetWindowText(h_msgbox_text, "New Text");    
    }
    
    else
    {
    // child error
    }
    
    
    }
    
    else
    {
    // error
    }
    I think thats correct, but you will need to put the code after the message box creation in a seperate thread. Hope thats some help.
    Last edited by (TNT); 01-16-2006 at 07:58 AM.
    TNT
    You Can Stop Me, But You Cant Stop Us All

  9. #9
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    Im kinda new so I dont really know what a thread is.
    Like a other function?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  2. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  3. Read word from text file (It is an essay)
    By forfor in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 11:45 AM
  4. Changing the Console text back to black
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 07-12-2002, 08:11 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM

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