Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Adding UI to an existing console project using windows form

Adding UI to an existing console project using windows form

Scheduled Pinned Locked Moved C / C++ / MFC
design
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 9350237
    wrote on last edited by
    #1

    Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:

    printf ("\n");
    printf ("-----------------------------------\n");
    printf ("\n\n");

    printf ("Dyad name:");
    scanf("%s",fname);
    printf ("\\n\\n");
    
        printf ("Epoch number \[1-%d\]:",NEPOCHS);
    scanf("%d",&epoch);
    printf ("\\n\\n");
    
    printf("Group: Haptic (0) or Visuo-haptic (1):");
    scanf("%d",&lineEnable);
    printf ("\\n\\n");
    
    switch(lineEnable){
    case 0: // Haptic
    	strcpy(prefix,"haptic");
    	break;
    case 1: // Visuo-Haptic
    	strcpy(prefix,"visuohaptic");
    }
    
    printf ("\\n\\n");	
    printf ("\[x\] - Exit application\\n");
    printf ("\\n\\n");
    

    Thank you!

    L L 2 Replies Last reply
    0
    • M Member 9350237

      Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:

      printf ("\n");
      printf ("-----------------------------------\n");
      printf ("\n\n");

      printf ("Dyad name:");
      scanf("%s",fname);
      printf ("\\n\\n");
      
          printf ("Epoch number \[1-%d\]:",NEPOCHS);
      scanf("%d",&epoch);
      printf ("\\n\\n");
      
      printf("Group: Haptic (0) or Visuo-haptic (1):");
      scanf("%d",&lineEnable);
      printf ("\\n\\n");
      
      switch(lineEnable){
      case 0: // Haptic
      	strcpy(prefix,"haptic");
      	break;
      case 1: // Visuo-Haptic
      	strcpy(prefix,"visuohaptic");
      }
      
      printf ("\\n\\n");	
      printf ("\[x\] - Exit application\\n");
      printf ("\\n\\n");
      

      Thank you!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Windows forms applications and console applications are quite different. If you want a full GUI then create a Forms application from scratch. However, since this is C++ you may like to investigate the Windows API or MFC. [edit] This looks much the same as your question of last June[^]. [/edit]

      M 1 Reply Last reply
      0
      • M Member 9350237

        Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:

        printf ("\n");
        printf ("-----------------------------------\n");
        printf ("\n\n");

        printf ("Dyad name:");
        scanf("%s",fname);
        printf ("\\n\\n");
        
            printf ("Epoch number \[1-%d\]:",NEPOCHS);
        scanf("%d",&epoch);
        printf ("\\n\\n");
        
        printf("Group: Haptic (0) or Visuo-haptic (1):");
        scanf("%d",&lineEnable);
        printf ("\\n\\n");
        
        switch(lineEnable){
        case 0: // Haptic
        	strcpy(prefix,"haptic");
        	break;
        case 1: // Visuo-Haptic
        	strcpy(prefix,"visuohaptic");
        }
        
        printf ("\\n\\n");	
        printf ("\[x\] - Exit application\\n");
        printf ("\\n\\n");
        

        Thank you!

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        There is nothing very difficult you just need to deal with the console input/outpur code and put it into a window or dialog. The "Main" function becomes "WinMain" and you change the compilation from console to Win GUI. Normally its fairly trivial as everything but the user input/output elements will compile as is. Generally you just look at your console input/output and sketch out a couple of screens on paper then build that and start replacing the console calls into those screens. In that example above it would just be a dialog or window with the entry boxes. When the user has entered them you would press a button .. Ok/Continue etc ... check the entries are valid .. do what you want with them and continue on. It isn't really that hard. The start point is as always build the GUI screen skeleton to move you program into it. Here is a 5min mock up of your code you posted. I would probably use more advanced entry for epoch but I limited myself to 5min

        #define _WIN32_WINNT 0x0500
        #include
        #include

        #define ID_DYANNAME 100
        #define ID_EPOCHNUMBER 101
        #define ID_GROUPBUTTONS 102
        #define ID_HAPTIC 103
        #define ID_VISUOHAPTIC 104
        #define ID_PROCESS 200

        // This is your Data you want
        char FName[256] = { 0 };
        int epoch = 0;
        char prefix[256] = { 0 };

        LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

        switch (msg) {
        case WM\_CREATE: {
        			CreateWindowEx(0, "STATIC", "Dyad name:",
        				WS\_VISIBLE | WS\_CHILD | SS\_RIGHT,
        				20, 20, 300, 20,
        				hwnd, 0, 0, 0);
        			CreateWindowEx(0, "EDIT", "",
        				WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT,
        				330, 20, 100, 20,
        				hwnd, (HMENU) ID\_DYANNAME, 0, 0);
        			CreateWindowEx(0, "STATIC", "Epoch number \[1-%d\]:",
        				WS\_VISIBLE | WS\_CHILD | SS\_RIGHT,
        				20, 50, 300, 20,
        				hwnd, 0, 0, 0);
        			CreateWindowEx(0, "EDIT", "",
        				WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT,
        				330, 50, 100, 20,
        				hwnd, (HMENU) ID\_EPOCHNUMBER, 0, 0);
        
        			/\*Group for Radio button for haptic or visuo-haptic \*/
        			CreateWindowEx(WS\_EX\_WINDOWEDGE,
        				"BUTTON",
        				"Select Mode:",
        				WS\_VISIBLE | WS\_CHILD | BS\_GROUPBOX,
        				120, 80,
        				320, 70,
        				hwnd,
        				(HMENU) ID\_GROUPBUTTONS,
        				0, NULL);
        			HWND Button = CreateWindowEx(WS\_EX\_WINDOWEDGE,
        				"BUTTON",
        				"Haptic",
        				WS\_VISIBLE | WS\_CHILD | BS\_AUTORADIOBUTTON | WS\_GROUP,
        				130, 100,
        				200, 20,
        				hwnd,
        				(HMENU) ID\_HAPTIC,
        				0, NULL);
        			CreateWindowEx(WS\_EX\_WINDOWEDG
        
        M 1 Reply Last reply
        0
        • L Lost User

          Windows forms applications and console applications are quite different. If you want a full GUI then create a Forms application from scratch. However, since this is C++ you may like to investigate the Windows API or MFC. [edit] This looks much the same as your question of last June[^]. [/edit]

          M Offline
          M Offline
          Member 9350237
          wrote on last edited by
          #4

          Thank you very much for the information

          1 Reply Last reply
          0
          • L leon de boer

            There is nothing very difficult you just need to deal with the console input/outpur code and put it into a window or dialog. The "Main" function becomes "WinMain" and you change the compilation from console to Win GUI. Normally its fairly trivial as everything but the user input/output elements will compile as is. Generally you just look at your console input/output and sketch out a couple of screens on paper then build that and start replacing the console calls into those screens. In that example above it would just be a dialog or window with the entry boxes. When the user has entered them you would press a button .. Ok/Continue etc ... check the entries are valid .. do what you want with them and continue on. It isn't really that hard. The start point is as always build the GUI screen skeleton to move you program into it. Here is a 5min mock up of your code you posted. I would probably use more advanced entry for epoch but I limited myself to 5min

            #define _WIN32_WINNT 0x0500
            #include
            #include

            #define ID_DYANNAME 100
            #define ID_EPOCHNUMBER 101
            #define ID_GROUPBUTTONS 102
            #define ID_HAPTIC 103
            #define ID_VISUOHAPTIC 104
            #define ID_PROCESS 200

            // This is your Data you want
            char FName[256] = { 0 };
            int epoch = 0;
            char prefix[256] = { 0 };

            LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

            switch (msg) {
            case WM\_CREATE: {
            			CreateWindowEx(0, "STATIC", "Dyad name:",
            				WS\_VISIBLE | WS\_CHILD | SS\_RIGHT,
            				20, 20, 300, 20,
            				hwnd, 0, 0, 0);
            			CreateWindowEx(0, "EDIT", "",
            				WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT,
            				330, 20, 100, 20,
            				hwnd, (HMENU) ID\_DYANNAME, 0, 0);
            			CreateWindowEx(0, "STATIC", "Epoch number \[1-%d\]:",
            				WS\_VISIBLE | WS\_CHILD | SS\_RIGHT,
            				20, 50, 300, 20,
            				hwnd, 0, 0, 0);
            			CreateWindowEx(0, "EDIT", "",
            				WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT,
            				330, 50, 100, 20,
            				hwnd, (HMENU) ID\_EPOCHNUMBER, 0, 0);
            
            			/\*Group for Radio button for haptic or visuo-haptic \*/
            			CreateWindowEx(WS\_EX\_WINDOWEDGE,
            				"BUTTON",
            				"Select Mode:",
            				WS\_VISIBLE | WS\_CHILD | BS\_GROUPBOX,
            				120, 80,
            				320, 70,
            				hwnd,
            				(HMENU) ID\_GROUPBUTTONS,
            				0, NULL);
            			HWND Button = CreateWindowEx(WS\_EX\_WINDOWEDGE,
            				"BUTTON",
            				"Haptic",
            				WS\_VISIBLE | WS\_CHILD | BS\_AUTORADIOBUTTON | WS\_GROUP,
            				130, 100,
            				200, 20,
            				hwnd,
            				(HMENU) ID\_HAPTIC,
            				0, NULL);
            			CreateWindowEx(WS\_EX\_WINDOWEDG
            
            M Offline
            M Offline
            Member 9350237
            wrote on last edited by
            #5

            Thank you so much for the information

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups