Thread: Open a new window and run function when button clicked

  1. #1
    Registered User
    Join Date
    May 2017

    Question Open a new window and run function when button clicked

    Hello ,

    I am really new with windows programming. I have a complete c++ coding about simple scanner. I decided to choose WinAPI to create simple application. I have created a button 'scan' and when clicked it will open new window that display 'scanning files..' and start scanning. But when I write like this, I have to close the window then the scan() function can run. How can I make the 2 function run at the same time? I have tried THREAD and FUTURE but it does not work. Can anyone suggest another idea

             case WM_CREATE:
                    CreateWindow(TEXT("button"), TEXT("Scan"),    
                        WS_VISIBLE | WS_CHILD ,
                        75, 100, 110, 25,        
                        hwnd1,(HMENU) 1, NULL, NULL);
            case WM_COMMAND:
                if (LOWORD(wParam1) == 1) 
                    int WINAPI Win2();
                    int window2 = Win2();
                    int scan();
                    int scanner = scan();

  2. #2
    Registered User
    Join Date
    Dec 2010
    Shamokin PA (middle of nowhere)
    To open a new window with the click of a button on your main or first program window, you need to execute another CreateWindow() or CreateWindowEx() function call, where the szClassName parameter is a pre-existing window class, or one you registered elsewhere in your application, such in WM_CREATE code. Having done that and having successfully created a 2nd window, you could call some function or other to perform whatever data processing you wish to perform, and that function could draw output to your new window.

    Having said that there are quite a few somewhat tricky issues involved. First, drawing of text or whatever on any window should be performed in WM_PAINT handling code. Its possible to do it other ways but results are extremely poor and unsatisfactory. I'm sure you'll try that, and you'll find to your dismay that I'm right.

    Second, if the function you call that does some kind of 'scan' (whatever that means) takes any amount of time to do it, and there are intermediate outputs you wish to draw, then some type of threading will be necessary to achieve any type of decent results.

    I could move on to third, fourth, etc, but I thing points 1 and 2 above are enough for now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My BS_OWNERDRAW button draw as white when clicked...
    By Jonathan Beaubi in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2007, 10:41 AM
  2. exit while loop when button clicked
    By shav in forum Windows Programming
    Replies: 18
    Last Post: 02-02-2005, 05:46 AM
  3. Window won't open on button command?
    By psychopath in forum Windows Programming
    Replies: 13
    Last Post: 08-16-2004, 08:39 AM
  4. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 08:53 AM
  5. Window Button
    By sean345 in forum Windows Programming
    Replies: 13
    Last Post: 07-08-2002, 03:13 PM

Tags for this Thread