RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 3714 | Replies: 2
Reply
Join Date: Jun 2005
Location: cincinnati, Ohio
Posts: 19
Reputation: bandm is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
bandm's Avatar
bandm bandm is offline Offline
Newbie Poster

?A Simple Win32 GUI Introduction Snippet?

  #1  
Jul 22nd, 2005
Hello,

I am just messin around with this "A Simple Win32 GUI Introduction" snippet I found on this site. I am able to paste it in to a simple project in my Visual C++ application and run it. Basically it is just a blank window. It says you can play around with it, and I did figure out how to change the Title. But what else can we do with this? I have a simple console application that I wrote that calculates two resistors in parallel.

#include <iostream>
using namespace std;

int main()
{
    int R1, R2;
    float Rpar;
    cout << "Enter the value for R1: " ;
    cin >> R1;
    cout << "Enter the value for R2: ";
    cin >> R2;
    Rpar = (R1 * R2) / (R1 + R2);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
    system ("pause");
    return 0;
    
   }

Here is the Snippet

#include <windows.h> /* Windows header */

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "WindowsApp";   /* Class ID */

int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
        HWND hwnd;
        MSG messages;
        WNDCLASSEX wincl;

        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure; /* See end of code */
        wincl.style = CS_DBLCLKS;
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;
        wincl.cbClsExtra = 0;
        wincl.cbWndExtra = 0;
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Default windows background colour */

        if (!RegisterClassEx (&wincl))
        return 0;

        hwnd = CreateWindowEx (
        0,
        szClassName,         /* Classname */
        "Windows App",       /* Title Text */
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,       /* Default x... */
        CW_USEDEFAULT,       /* ...and default y position of window */
        640,                 /* The programs width... */
        480,                 /* ...and height in pixels */
        HWND_DESKTOP,
        NULL,
        hThisInstance,
        NULL
        );

        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
        while (GetMessage (&messages, NULL, 0, 0))
        {
                TranslateMessage(&messages);
                DispatchMessage(&messages);
        }

        /* Return: wParam from a quit message usually = 0 */
        return messages.wParam;
}

LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ /* Called when window processes a message */
        switch (message)
        {
                case WM_DESTROY: /* Destoy message: called if you press the "x" in the top right corner */
                PostQuitMessage (0); /* Send a message to quit */
                break;
                default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
}


Can this be incorporated into this window, and not disappear after hitting any key?

Just playin around. Oh Yes! How do you change the background color?

any help would be appreciated

ThanX BandM
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Posts: 2,548
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Solution Re: ?A Simple Win32 GUI Introduction Snippet?

  #2  
Jul 22nd, 2005
Just a hint, on your parallel resistor calculator declare both R1 and R2 as a float or something like:

R1 = 1
R2 = 2

will give you a parallel resistance of 0

BTW, the Windows snippet you have is the one that comes up with DevCpp when you create a Windows Application. You need to add EditBoxes for data entry and output, also a button to click to do your calculations. The easiest way to do all of this is with a form builder in visual studio. The problem there is, that your total code is now scattered across several goofy sounding files.

Plotzki schmotzki!
May 'the Google' be with you!
Reply With Quote  
Join Date: Oct 2004
Posts: 2,548
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 11
Solved Threads: 178
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Solution Re: ?A Simple Win32 GUI Introduction Snippet?

  #3  
Jul 23rd, 2005
A very good tutorial about Windows GUI programming for the beginner is at:
http://www.functionx.com/win32/
May 'the Google' be with you!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC