944,047 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 8807
  • C RSS
Mar 1st, 2006
0

Windows gui

Expand Post »
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.
Similar Threads
hak
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hak is offline Offline
2 posts
since Mar 2006
Mar 1st, 2006
0

Re: Windows gui

start at the beginning, not somewhere in the middle of things.Here is a good tutorial to get you started.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Mar 2nd, 2006
0

Re: Windows gui

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
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Mar 3rd, 2006
0

Re: Windows gui

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...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 3rd, 2006
0

Re: Windows gui

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!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Mar 3rd, 2006
0

Re: Windows gui

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Mar 3rd, 2006
0

Re: Windows gui

does she like younger men
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Clinton Portis is offline Offline
822 posts
since Oct 2005
Mar 4th, 2006
0

Re: Windows gui

Sounds more like Ancient's wife has him broke in!

Happy coding!
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Need immediate help ( Challenging software )
Next Thread in C Forum Timeline: accessing bmps in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC