?A Simple Win32 GUI Introduction Snippet?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 19
Reputation: bandm is an unknown quantity at this point 
Solved Threads: 0
bandm's Avatar
bandm bandm is offline Offline
Newbie Poster

?A Simple Win32 GUI Introduction Snippet?

 
0
  #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.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int R1, R2;
  7. float Rpar;
  8. cout << "Enter the value for R1: " ;
  9. cin >> R1;
  10. cout << "Enter the value for R2: ";
  11. cin >> R2;
  12. Rpar = (R1 * R2) / (R1 + R2);
  13. cout <<"The value of parallel resistance is: " << Rpar << "\n";
  14. system ("pause");
  15. return 0;
  16.  
  17. }

Here is the Snippet

  1.  
  2. #include <windows.h> /* Windows header */
  3.  
  4. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  5. char szClassName[ ] = "WindowsApp"; /* Class ID */
  6.  
  7. int WINAPI
  8. WinMain (HINSTANCE hThisInstance,
  9. HINSTANCE hPrevInstance,
  10. LPSTR lpszArgument,
  11. int nFunsterStil)
  12.  
  13. {
  14. HWND hwnd;
  15. MSG messages;
  16. WNDCLASSEX wincl;
  17.  
  18. wincl.hInstance = hThisInstance;
  19. wincl.lpszClassName = szClassName;
  20. wincl.lpfnWndProc = WindowProcedure; /* See end of code */
  21. wincl.style = CS_DBLCLKS;
  22. wincl.cbSize = sizeof (WNDCLASSEX);
  23. wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  24. wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  25. wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  26. wincl.lpszMenuName = NULL;
  27. wincl.cbClsExtra = 0;
  28. wincl.cbWndExtra = 0;
  29. wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Default windows background colour */
  30.  
  31. if (!RegisterClassEx (&wincl))
  32. return 0;
  33.  
  34. hwnd = CreateWindowEx (
  35. 0,
  36. szClassName, /* Classname */
  37. "Windows App", /* Title Text */
  38. WS_OVERLAPPEDWINDOW,
  39. CW_USEDEFAULT, /* Default x... */
  40. CW_USEDEFAULT, /* ...and default y position of window */
  41. 640, /* The programs width... */
  42. 480, /* ...and height in pixels */
  43. HWND_DESKTOP,
  44. NULL,
  45. hThisInstance,
  46. NULL
  47. );
  48.  
  49. /* Make the window visible on the screen */
  50. ShowWindow (hwnd, nFunsterStil);
  51. while (GetMessage (&messages, NULL, 0, 0))
  52. {
  53. TranslateMessage(&messages);
  54. DispatchMessage(&messages);
  55. }
  56.  
  57. /* Return: wParam from a quit message usually = 0 */
  58. return messages.wParam;
  59. }
  60.  
  61. LRESULT CALLBACK
  62. WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  63. { /* Called when window processes a message */
  64. switch (message)
  65. {
  66. case WM_DESTROY: /* Destoy message: called if you press the "x" in the top right corner */
  67. PostQuitMessage (0); /* Send a message to quit */
  68. break;
  69. default:
  70. return DefWindowProc (hwnd, message, wParam, lParam);
  71. }
  72. return 0;
  73. }


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
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: ?A Simple Win32 GUI Introduction Snippet?

 
0
  #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 Quick reply to this message  
Join Date: Oct 2004
Posts: 3,959
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 918
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: ?A Simple Win32 GUI Introduction Snippet?

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC