| | |
?A Simple Win32 GUI Introduction Snippet?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
Here is the Snippet
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
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.
C++ Syntax (Toggle Plain Text)
#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
C++ Syntax (Toggle Plain Text)
#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
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!
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!
A very good tutorial about Windows GUI programming for the beginner is at:
http://www.functionx.com/win32/
http://www.functionx.com/win32/
May 'the Google' be with you!
![]() |
Similar Threads
- GUI, matrix and vector libraries (C++)
- a C++ gui (C++)
- Simple CLI/GUI application for XHTML templates. (HTML and CSS)
- perl gui (Perl)
- WIN32 GUI application - Problem popping up dialog box (C++)
Other Threads in the C++ Forum
- Previous Thread: c doubts
- Next Thread: Subclassed Editbox Control: Do I need to create 2 subclasses for two edit controls?
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






