Windows gui

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2006
Posts: 2
Reputation: hak is an unknown quantity at this point 
Solved Threads: 0
hak hak is offline Offline
Newbie Poster

Windows gui

 
0
  #1
Mar 1st, 2006
I know this is a noob question but where do i put my own code in this menu code for windows.

  1. #include <windows.h>
  2.  
  3. /* Declare Windows procedure */
  4. LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
  5. /* Make the class name into a global variable */
  6. char szClassName[ ] = "WindowsApp";
  7. int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
  8.  
  9. {
  10. HWND hwnd; /* This is the handle for our window */
  11. MSG messages; /* Here messages to the application are saved */
  12. WNDCLASSEX wincl; /* Data structure for the windowclass */
  13.  
  14. /* The Window structure */
  15. wincl.hInstance = hThisInstance;
  16. wincl.lpszClassName = szClassName;
  17. wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
  18. wincl.style = CS_DBLCLKS; /* Catch double-clicks */
  19. wincl.cbSize = sizeof(WNDCLASSEX);
  20.  
  21. /* Use default icon and mouse-pointer */
  22. wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  23. wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  24. wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
  25. wincl.lpszMenuName = NULL; /* No menu */
  26. wincl.cbClsExtra = 0; /* No extra bytes after the window class */
  27. wincl.cbWndExtra = 0; /* structure or the window instance */
  28. /* Use light-gray as the background of the window */
  29. wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
  30.  
  31. /* Register the window class, if fail quit the program */
  32. if(!RegisterClassEx(&wincl)) return 0;
  33.  
  34. /* The class is registered, let's create the program*/
  35. hwnd = CreateWindowEx(
  36. 0, /* Extended possibilites for variation */
  37. szClassName, /* Classname */
  38. "Windows App", /* Title Text */
  39. WS_OVERLAPPEDWINDOW, /* default window */
  40. CW_USEDEFAULT, /* Windows decides the position */
  41. CW_USEDEFAULT, /* where the window ends up on the screen */
  42. 544, /* The programs width */
  43. 375, /* and height in pixels */
  44. HWND_DESKTOP, /* The window is a child-window to desktop */
  45. NULL, /* No menu */
  46. hThisInstance, /* Program Instance handler */
  47. NULL /* No Window Creation data */
  48. );
  49.  
  50. /* Make the window visible on the screen */
  51. ShowWindow(hwnd, nFunsterStil);
  52. /* Run the message loop. It will run until GetMessage( ) returns 0 */
  53. while(GetMessage(&messages, NULL, 0, 0))
  54. {
  55. /* Translate virtual-key messages into character messages */
  56. TranslateMessage(&messages);
  57. /* Send message to WindowProcedure */
  58. DispatchMessage(&messages);
  59. }
  60.  
  61. /* The program return-value is 0 - The value that PostQuitMessage( ) gave */
  62. return messages.wParam;
  63. }
  64.  
  65. /* This function is called by the Windows function DispatchMessage( ) */
  66. LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  67. {
  68. switch (message) /* handle the messages */
  69. {
  70. case WM_DESTROY:
  71. PostQuitMessage(0); /* send a WM_QUIT to the message queue */
  72. break;
  73. default: /* for messages that we don't deal with */
  74. return DefWindowProc(hwnd, message, wParam, lParam);
  75. }
  76. return 0;
  77. }
Edit: Added code tags!
Last edited by vegaseat; Mar 2nd, 2006 at 12:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,616
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Windows gui

 
0
  #2
Mar 1st, 2006
start at the beginning, not somewhere in the middle of things.Here is a good tutorial to get you started.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Windows gui

 
0
  #3
Mar 2nd, 2006
Generally, you create your window and other controls in WinMain() after the call to RegisterClass() and before the start of the event loop. I prefer to put these things into their own functions to make things more readable. Anything related to an actual response to an event goes into CALLBACK WndProc(). Again, once you have indicated the event, you can call your own response functions.

Read the tutorial (somewhat ancient) recommended by AncientDragon. Also look at some of the simple GUI code snippets here on DaniWeb. For instance:
http://www.daniweb.com/code/snippet96.html
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Windows gui

 
0
  #4
Mar 3rd, 2006
nothing wrong with old tutorials, they teach the core instead of getting sidetracked into fancy new additions...

Why include XP skinning into a tutorial teaching introductory Win32 programming for example...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Windows gui

 
0
  #5
Mar 3rd, 2006
Why do folks assume that old is bad?
The win GUI tutorial at http://www.winprog.org/tutorial/ is great! There is a heck of a learning curve, mostly because the underlying API was written by MS and includes the kitchen sink. Not a fault of the tutorial.

Once you can make yourself a mental picture of the parts and figure out how they are connected you are 10% there!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,616
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Windows gui

 
0
  #6
Mar 3rd, 2006
>>Why do folks assume that old is bad?

My wife is getting old too, but she's still in good working order and I intend to keep her around for awhile. Already have her broke in, getting a new wife means I have to start all over again.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 480
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 57
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training

Re: Windows gui

 
0
  #7
Mar 3rd, 2006
does she like younger men
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Windows gui

 
0
  #8
Mar 4th, 2006
Sounds more like Ancient's wife has him broke in!

Happy coding!
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



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC