Stupid C++ Question

How can forms and command buttons etc. be created with C++(Not Visual). I have seen books on coding C++ but none ever mentioned actually creating forms and objects on the forms....

StephenB
LVL 1
stephenbladeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
viktornetConnect With a Mentor Commented:
you use CreateWindow() to create windows/buttons/edit boxes/listboxes and so on... if you need a full example (with source code) on how to accomplish this task, let me know and I will supply some code. What you're trying to do is write a Win32 Application and not using VC++'s Visual IDE. You only use it to type your code in there (or you might type it some place else)

..-=ViKtOr=-..
0
 
chensuCommented:
Standard C++ does not provide any support to create forms and buttons. You've got tell us the platform and C++ compiler you are using.
0
 
stephenbladeAuthor Commented:
Which C++ Compiler would be easiest to accomplish this with and still have small program size for distribution?



StephenB
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
AlexVirochovskyCommented:
>>easiest to accomplish
>>still have small program size for distribution
 Or this  or this:
easiest to accomplish : i think,
it is BC++ Builder (some hours) ,
but NOT little apps
small program size for distribution:
VC , of course, but NOT easy
write for   newbe.
0
 
abusimbelCommented:
C++ in itsself doestn't contain any methods to do that. You must refer the platform documentation.
Windows Programming, Motif Programming, or something so...

0
 
basantCommented:
Since THere is not Windows/GUI standard which is applicable for all/most platforms so There is no specific C/C++ library available for GUI.

e.g
Unix supports : X/Motif
WinNT /95/.. : Win32
0
 
TallBoyCommented:
Rubbish.  C++ can do everything that Visual can do, and more.

Before I post the answer to your question, one thing is not clear:

When you say that you want to create forms and buttons, are you talking about ordinary dialog boxes with edit controls in them, or something more akin to Microsoft Excel?
0
 
chensuCommented:
>C++ can do everything that Visual can do, and more.

C++ is a programming language, which is platform independent.
0
 
stephenbladeAuthor Commented:
Yes, Tallboy I mean regular forms such as the types one might create normally using VB.

  StephenBlade
0
 
stephenbladeAuthor Commented:
Yes please email me the code at stephenblade@jlyne.com and I will gladly accept your answer! Thanks so much!!

0
 
viktornetCommented:
Here is some code that I wrote for you. You could use it as a template for almost all of your Win32 Applications...

============
#define WIN32_MEAN_LEAN

////////////////////////
////// INCLUDES ////////
////////////////////////

#include <windows.h>
#include <windowsx.h>

///////////////////////
////// DEFINES ////////
///////////////////////

#define TITLE "Template"
#define WIDTH 320
#define HEIGHT 200

///////////////////////
////// GLOBALS ////////
///////////////////////

MSG msg;
HWND hMainWnd;
WNDCLASS wc;

//////////////////////////
////// PROTOTYPES ////////
//////////////////////////

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

//////////////////////////////
////// IMPLEMENTATION ////////
//////////////////////////////

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
{
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.lpfnWndProc = WndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInst;
      wc.hIcon = LoadIcon(0, IDI_APPLICATION);
      wc.hCursor = LoadCursor(0, IDC_ARROW);
      wc.hbrBackground = GetStockObject(WHITE_BRUSH+1);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = "WC1";

      if (!RegisterClass(&wc)) return 0;

      if (!(hMainWnd = CreateWindow("WC1", TITLE, WS_OVERLAPPEDWINDOW, 0, 0, WIDTH, HEIGHT, 0, 0, hInst, NULL))) return 0;

      ShowWindow(hMainWnd, SW_SHOW);
      UpdateWindow(hMainWnd);

      while(GetMessage(&msg, 0, 0, 0)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }

      return (msg.lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
      HDC hDC;
      PAINTSTRUCT ps;

      switch (uMsg) {
            case WM_DESTROY:
                  PostQuitMessage(0);
                  break;

            case WM_PAINT:
                  hDC = BeginPaint(hMainWnd, &ps);
                  EndPaint(hMainWnd, &ps);
                  break;
      }
      return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
==========

Do you see how I used CreateWindow()?? You use it the same way for creating other controls such as edit boxes, BUT!! instead of passing "WC1" (or whatever happen to be your window class' name) as the first parameter of the CreateWindow() function, you pass "EDIT" for an edit box, "BUTTON" for a button, and so on... there are like 8 or so controls that windows uses all the time that have been registered while windows was loading... Also, you pass the handle to the window where you want to place your button or whatever as the Parent parameter of the CreateWindow() functions...

Let me know if you don't understand something!

..-=ViKtOr=-..
0
 
stephenbladeAuthor Commented:
Thanks so much please recomend a beginers book that i could learn this stuff from.

0
 
stephenbladeAuthor Commented:
I tried to compile your code but get Compiling NONAME00.CPP:
Error NONAME00.CPP 37: Type mismatch in redeclaration of 'pascal WinMain(unsigned int,unsigned int,char far*,int)'
Warning NONAME00.CPP 62: Parameter 'hPrevInst' is never used
Warning NONAME00.CPP 62: Parameter 'lpCmdLine' is never used
Warning NONAME00.CPP 62: Parameter 'nCmdShow' is never used
Warning NONAME00.CPP 80: 'hDC' is assigned a value that is never used

Using Borland C++
0
 
viktornetCommented:
What version of Borland C++ are you using? You MUST create a Win32 Application and not a DOS application... Then you try to compile the code...

..-=ViKtOr=-..
0
 
stephenbladeAuthor Commented:
borland C++ for windows version 3.1
And I tried creating a win32 app.

0
 
viktornetCommented:
You can not create a Win32 app under a 16-bit OS system... I think you should use Borland C++ 5.x in order to be able to create that kind of programs and you should run it under Win9.x (and now Win2000)..

I tested the code using VC++ 5 and it works just fine... The code is correct, you just need to find the tools (compilers) in order to be able to get a final application out of the code.

..-=ViKtOr=-..
0
 
kevinfCommented:
Stephen,

A [rather old] book that covers what you are trying to achieve is called "Programming Windows" by Charles Petzold. There has been several editions and it may even be out of print. One particular concept you will need to grasp when you investigate this is called event-driven programming because virtually the whole Windows GUI programming interface uses "events" to notify your program when something has happened to your window, a control on your window etc.

Essentially you are using C++ to call the standard Windows Application programming interfaces (like CreateWindow () etc) and you therefore take it upon yourself to handle the many problems etc associated with this level of development.

Wrapper environments like MFC, OWL, VCL (from Delphi or C++Builder) try and hide some of the above complexity from you, as well as providing you a more visually interactive development environment.

Learning raw Windows API will give you an extremely good grounding for moving to the above wrapper environments so it is always useful. However, if you are newbie and want to start making things "happen" sooner rather than later I recommend perhaps gaining an understanding of Windows Programming at the API but using one of the above wrapper classes to accomplish what you need to.

C++Builder would be my recommendation.

Kevin Frey
0
All Courses

From novice to tech pro — start learning today.