C++ form creation at run-time

Does anyone have any resources on creating forms in C++ without using MFC.  I know this is the hard way to do things.
LVL 1
boodabellyAsked:
Who is Participating?
 
nietodCommented:
The following is a simple sample windows program that creates a window.
******************************************
/ Basic window procedure.  This is where you will do most
// of your work to "customize" the window to do what you want.
LRESULT                                          // Result.  Interpretation depends on the        //
                                                           // message being handled.
CALLBACK WndPrc(HWND   WndHnd,                   // >> window.
                UINT   Msg,                      // Message to be handled.
                WPARAM WrdPrm,                   // Word parameter.  Interpretation depends on    
                                                 // message being handled.
                LPARAM LngPrm)                   // Long parameter.  Interpretation depends on
                                                 // message being handled.
{
   BOOL    Handled = TRUE;                       // Was message handled by this routine?
   LRESULT RetVal  = 0;                          // Value to be returned.                         //

   switch (Msg)                                  // Branch based on message.
   {
   case WM_DESTROY:                              // If this is a destroy window message, then    
   {
      // Make application quite when window is closed.
      PostQuitMessage(0);                        // Post a quite message.
      Handled = FALSE;                           // Indicate message was not handled.
      break;
   }
   default:                                      // otherwise, if any other message, then         //
      Handled = FALSE;                           // Indicate message was not handled.             //
   }

   if (!Handled)                                 // If message was not handled, then
      RetVal = DefWindowProc(WndHnd,Msg,WrdPrm,LngPrm);
   return RetVal;                                // Return the return value.  
}
//------------------------------------------------------------------------------------------------//
// Procedure to register the window class.
void
RegWndCls(void)
{
   HCURSOR    ArwCrs = LoadCursor(NULL,IDC_ARROW);  // Default cursor.
   HBRUSH     GryBrh = GetStockObject(LTGRAY_BRUSH); // Background brush.
   WNDCLASSEX WndCls = {sizeof(WNDCLASSEX),   // Create window class parameter block.
                        CS_DBLCLKS,
                        WndPrc,
                        0,
                        0,
                        GetModuleHandle(NULL),
                        NULL,
                        ArwCrs,
                        GryBrh,
                        NULL,
                        "WndClsNam",
                        NULL};
   RegisterClassEx(&WndCls);                     // Try to register the class.
}
//------------------------------------------------------------------------------------------------//
// Procedure to create a window.
HWND  // >> window created.
CrtWnd(char *Ttl) // Window title.
{
   return CreateWindow("QWnd",Ttl,
                       WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                       CW_USEDEFAULT,CW_USEDEFAULT,
                       CW_USEDEFAULT,CW_USEDEFAULT,
                       NULL,NULL,GetModuleHandle(NULL),NULL);
}
//------------------------------------------------------------------------------------------------//
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,
                   int nShowCmd)
{
   RegWndCls(); // Register the window class.

   MSG      WndMsg;
   HWND WndHnd = CrtWnd("Window Title"); // Create a window.

   // Process messages until a quit message.
   while (GetMessage(&WndMsg,NULL,0,0))
   {
      DispatchMessage(&WndMsg);
   }
   return WndMsg.wParam;
};

***********************************************
Is that what you want?
0
 
boodabellyAuthor Commented:
Edited text of question.
0
 
nietodCommented:
Forms?  You mean windows?  You can just use CreateWindow() or CreateWindowEx().  What specifically do you want to know about?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
chensuCommented:
By forms, I guess boodabelly means dialog boxes that contain various controls. What do you want to do?

0
 
boodabellyAuthor Commented:
Yeah, sorry for not being clear.  I was programming in VB for a while and that is what the referred to windows as.  I need to make something like a "form" or "windows".  I am trying to make a heads up display for a game and dont have one yet.  Ill see what I can do with the code that neitod posted.  Or I guess it would be easier to create the graphics and just put them on the screen.
0
 
nietodCommented:
If you need really fast graphics, you might want to look into direct draw.  It a lot more complex thant standard windows graphics, but much more poserful too.

If you don't go the direct draw route, you still will need the to create windows, i.e the code i posted.  Then you will probably want to output the graphics by drawing to an off-screen bitmap and then copyingthe bitmap into your window with BitBlt().

If you are starting windows program through the windows API, you need to get a a good introductory book on windows programming, like Teach Youself Windows in 21 days or the charles Petzold book, whose name has escaped me at the moment.
0
 
boodabellyAuthor Commented:
I have a book on Direct Draw & DX6 and game programming for drawing bitmaps off screen and then putting them on the screen.  I am trying to port the code for linux, so I didnt know if there was a viable ( easy ) alternative to that with out having to write a whole lot of classes to handle the graphics in linux.  It might be easier just to stick with windows programming though.  I'll give it a try, but I think for the time being DirectX is the way to go.

Off the subject, do you know if linux supports OpenGL?  I havent checked on that alternative yet.
0
 
nietodCommented:
I have no idea.
0
 
emildCommented:
AFAIK there's a library called MESA which is an implementation of OpenGL for LINUX
0
 
yowkeeCommented:
To create a window("form") under Linux is a different story with under Windows. You can't use the standard Windows API, you may choose some existing library like Gtk+, Qt, wxWindow (cross-platform) to do the GUI programming under Linux.

For OpenGL implementation, try this: http://linux.box.sk/box.php3?prj=linux&gfx=linux&srch=OpenGL
0
 
dalehendCommented:
www.wxwindows.org has example source using MDI. It is a framework built similar to MFC, though. It also has a library and example source to support OpenGL called glcanvas, allowing graphics in any kind of window,i.e., scrollable, resizeable.
wxWindows source works for Linux, Win32, MacOS, etc.
0
 
boodabellyAuthor Commented:
sorry it took so long
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.