GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Feb-2007, 12:25
Zorachus's Avatar
Zorachus Zorachus is offline
Junior Member
 
Join Date: Jul 2005
Posts: 58
Zorachus will become famous soon enough

Traditional Win32 programming vs. wxWidgets


I need a bit of advice.

I'm looking into coding Win32 programs, after programming console applications for a couple of years now. I've found several tutorials (only a few good ones, but so it goes), and have a pretty good idea of how a basic windows application is generated. I just re-wrote this, and heavily commented it. I think that I get everything in it.

CPP / C++ / C Code:
#include <windows.h>  //necessary for all winapi programs
//search win32 API help for additional styles

char progname[] = "First program";

LRESULT CALLBACK winproc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //function to be explained later

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) //ignore hPrevInst.  hInst is handle to this prog instance
//lpszCmdLine is asciiz string of command line parameters.  intCmdShow determines how window shows up:  minimized, maximized, etc.
/*To find out where exe lays:
     
     char * buf;
     buf=malloc(512);
     GetModuleFileName(hInst,buf,512);
     
     */
     
{
     WNDCLASSEX winclass; //defines a windows class, which contains such things as buttons, scrollbars, etc.
     HWND hWnd; //defines window handle variable
     MSG msg; //defines message variable
     
     winclass.cbSize=sizeof(WNDCLASSEX);  //determines size of expanded wndclass, stores to .cbSize
     winclass.style=CS_DBLCLKS;  //style includes flags.  cs_dblclks checks for double click and sends appropriate message if so.
     //different flags are ORed together.
     winclass.lpfnWndProc=&winproc;  //points to function that will do the most work in our program
     winclass.cbClsExtra=0;  //tells windows to allocate extra zero-initialized bytes after class/window structures.  set to zero normally
     winclass.cbWndExtra=0;  //tells windows to allocate extra zero-initialized bytes after class/window structures.  set to zero normally
     winclass.hInstance=hInst;  //instance we get as a winmain parameter
     winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);  //handle to icon that we wish to use.  this loads the standard application icon
     winclass.hCursor=LoadCursor(NULL, IDC_ARROW);  //handle to cursor.  use IDI_WAIT for hourglass.
     winclass.hbrBackground=GetSysColorBrush(COLOR_APPWORKSPACE); //if you want to draw yourself, set to NULL.  this example is a default brush.
     winclass.lpszMenuName=NULL;  //points to menu, which we don't have in this program.
     winclass.lpszClassName=progname; //name of window class, which in this case is same as application name
     winclass.hIconSm=NULL; //points to 16x16 graphic in upper-left hand corner.  set here to NULL so windows will generate it.
     
     if (!RegisterClassEx(&winclass))
        return 0;  //registers the extendend class.  if registration fails, terminate program.
        
     hWnd=CreateWindow(  //finally creates the window
          progname,  //class name
          progname,  //window name, same in this case, will be shown at the title line
          WS_SYSMENU|WS_CAPTION|WS_BORDER|WS_OVERLAPPED|WS_VISIBLE|WS_MINIMIZEBOX,
          //above line:  set of flags for style.
          //WS_SYSMENU gives us the top-left menu where we can close, move, resize the window
          //WS_CAPTION gives us the title line
          //WS_BORDER gives the window a thin-line, non resizable border
          //WS_OVERLAPPED makes this an overlapped window (who knows what that means?)
          //WS_VISIBLE makes window visible
          //WS_MINIMIZEBOX puts minimize box in top right corner of window
          //next four parameters are x, y, x-size, y-size
          CW_USEDEFAULT, //lets windows figure out default location for window
          0, //this is ignored because x is USEDEFAULT
          320, //x size of window
          200,// y size of window.  these dimensions include entire window, not just client area
          NULL,//handle of parent window if we had one
          NULL,//handle of window menu or child menu if we had one
          hInst, //handle to window
          NULL);//would point to window creation data passed to our message handled function if ever needed to do so
          
     ShowWindow(hWnd,nCmdShow); //calls to set window visibility
     UpdateWindow(hWnd); //sends WM_PAINT call to window, which repaints whole window to make it nice and clean :)
     while (GetMessage(&msg,NULL,0,0))//windows has control while getmessage call is running
     {
           TranslateMessage(&msg); //translates any scancodes into legible characters
           DispatchMessage(&msg); //sends message back to message handler
     }//If getMessage "fails," we have received a WM_QUIT message
     return (msg.wParam); //error code for program termination
}

LRESULT CALLBACK winproc (//this is the windows procedure
        HWND hWnd, //handle to the window
        UINT uMsg, //message identifier, WM_TIMER for instance, which means we have received a timer message
        WPARAM wParam, //unexplained 32 bit integer
        LPARAM lParam)  //unexplained 32 bit integer
        {
               switch (uMsg) 
               {
                      case WM_DESTROY: //should always be answered with PostQuitMessage, if need to stop shutdown, stop earlier at WM_CLOSE
                           PostQuitMessage(0); //when handling WM_DESTROY, deallocate timers and open devices
                           break;
                      default:
                           return DefWindowProc (hWnd, uMsg, wParam, lParam); //has default answers for most messages (generally ignored)
                           break; //saves trouble of you having to write everything yourself to answer messages
               }
        return 0;
        }

My conundrum is this: The next tutorial, something along the lines of drawing a "simple" (heh, right) plasma, is a bit beyond me, and ill-explained. I'm sure that I could figure it out, but is there truly a reason that I shouldn't abandon traditional Windows 32 programming and just use wxWidgets? I'm on the verge, and if there are no benefits to learning it the old school way, I may just do it.

Comments and/or suggestions are appreciated. Thanks in advance for the advice.
__________________
Pursue everything!

P.S. This is what you would get at some point in the alphabet with the removal of the Q and R.
  #2  
Old 09-Feb-2007, 13:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,701
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Traditional Win32 programming vs. wxWidgets


Quote:
Originally Posted by Zorachus
I need a bit of advice.

I'm looking into coding Win32 programs
I'm on the verge, and if there are no benefits to learning it the old school way, I may just do it.

Flashback to the distant past, When the World was Young.

I worked part of the way through the Petzold Windows API book about a million years ago (Windows 3.1). This was just for amusement. I typed in each and every line of code, since that's the way I learn. (The eyeball-to-fingers path that leads, mostly, through the brain. Eyeball-to-brain is not nearly as effective.)

Subsequently I purchased Microsoft Visual C++ for use in a project that I was working on (it wasn't a Windows project, but the client required that I present the result in a Visual Studio project workspace). I went through some examples from other books using the visual setup stuff. Easier to make dialog boxes without creating resource files "by hand", but still lots of lines of code.

Now, flash forward to the 21st century.


Here's what it takes to create a 320x200 window with "First Program" as its title using Qt (Here is the Mother Ship for Qt)

CPP / C++ / C Code:
#include <QApplication>
#include <QWidget>
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QWidget *window = new QWidget;

    window->setWindowTitle("First Program");
    window->resize(320, 200);
    window->show();

    return app.exec();
}

Notes:
1. I use Qt as an example, because I have it on all of my personal platforms (Windows XP and several Linux distributions). I use it for learning and personal amusement. It very well may be that other cross-platform (or even single-platform) tools suit your purposes better. WxWidgets may be just the thing four you (or FLTK or ...). Don't choose a tool based on anybody else's opinion. Check them out. (Look for links to tutorials and examples on the suppliers' web pages. Look all over the Web.) It is not my intent to steer you away from WxWidgets, but to present a few thinking points. Many of the following Good Things hold for WxWidgets and other toolsets as well. Compare.

2. Free downloads of open-source (GPL) versions of Qt for Windows, Linux and other platforms are available. If you are going to develop closed-source applications (things that you will distribute without supplying source code), there are commercial development licenses.

3. By default, Qt uses the default "theme" of your setup. That is, on Windows, the stuff you create looks like the rest of your Windows thingies (border color, title color, etc.). On Linux it looks like the rest of your Linux stuff. Etc. This is a Big Deal for me.

4. It is a set of C++ classes (not C). There are approximately a gazillion of them.

5. Supplied with the free download version (as well as the commercial version, of course), there is a good "assistant" program with complete documentation and a lot of tutorial programs already written and compiled for you. Step-by-step descriptions help you learn how to write your own.

6. There is also a visual "designer" program that lets you add the kind of widgets that you want and arrange them visually (drag-and-drop) instead of writing the code directly. However, the <layout> classes do a pretty good job of getting things fairly presentable just from simple code. Stuff you write yourself in pure C++.

7. I have no connection with the parent company (Trolltech) and I don't develop commercial applications based on Qt (or any other GUI development system). I have no emotional attachment to Qt either.

8. There may be some benefits in learning the ins and outs of the Windows API functions in actual applications. I don't think it ever hurts to know what's going on beneath the covers when you develop a high-level application, but if you are looking for a quicker way to learn how to create visual programs, higher-level toolkits may be better for you.

9. Just because I know that some contributors to this board use Qt doesn't mean that you can get simple answers to all of your complex questions here (or, even, your simple questions either). On the other hand, there is an FLTK board on gidforums that has some experts ready to help. They will fall all over themselves to come to your assistance. Maybe you should check that one out.

10. All of these points are presented for your consideration. Make a note of which will be important to your learning process and compare the various tools that you run across before choosing one to try. (And if, after trying one of the freebies, you decide to change to another, just consider it part of the learning process. You don't have to stick with one that turns out not to be your cup of tea.)

11. The opinions expressed here are not necessarily my own. It's these dang voices in my head. Your Mileage May Vary.

Regards,

Dave
  #3  
Old 10-Feb-2007, 17:54
killzone killzone is offline
Junior Member
 
Join Date: Nov 2006
Posts: 66
killzone is an unknown quantity at this point

Re: Traditional Win32 programming vs. wxWidgets


If you do use WxWidgets Try Wx-DevC++ it's a really good WYSIWYG Editor for developing WxWidgets
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Windows examples (know any?) Robbie Dave C++ Forum 10 06-Oct-2006 19:11
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 21:02
printer / font color / windows programming nicolas_qc MS Visual C++ / MFC Forum 0 03-Jan-2006 23:13
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
GUI programming crystalattice C++ Forum 5 14-Sep-2004 12:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:26.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.