Wednesday 1 January 2014

Here is the code for GUI in C++,
Tested in Code::Blocks hope it will help you :)
  1. #include <windows.h>
  2. /* Declare Windows procedure */
  3. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  4. /* Make the class name into a global variable */
  5. char szClassName[ ] = "CodeBlocksWindowsApp";
  6. int WINAPI WinMain (HINSTANCE hThisInstance,
  7. HINSTANCE hPrevInstance,
  8. LPSTR lpszArgument,
  9. int nCmdShow)
  10. {
  11. HWND hwnd; /* This is the handle for our window */
  12. MSG messages; /* Here messages to the application are saved */
  13. WNDCLASSEX wincl; /* Data structure for the windowclass */
  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. /* Use default icon and mouse-pointer */
  21. wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  22. wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  23. wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  24. wincl.lpszMenuName = NULL; /* No menu */
  25. wincl.cbClsExtra = 0; /* No extra bytes after the window class */
  26. wincl.cbWndExtra = 0; /* structure or the window instance */
  27. /* Use Windows's default colour as the background of the window */
  28. wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  29. /* Register the window class, and if it fails quit the program */
  30. if (!RegisterClassEx (&wincl))
  31. return 0;
  32. /* The class is registered, let's create the program*/
  33. hwnd = CreateWindowEx (
  34. 0, /* Extended possibilites for variation */
  35. szClassName, /* Classname */
  36. "syedarslanrizvi http://facebook.com/syedarslanrizvi", /* Title Text */
  37. WS_OVERLAPPEDWINDOW, /* default window */
  38. CW_USEDEFAULT, /* Windows decides the position */
  39. CW_USEDEFAULT, /* where the window ends up on the screen */
  40. 544, /* The programs width */
  41. 375, /* and height in pixels */
  42. HWND_DESKTOP, /* The window is a child-window to desktop */
  43. NULL, /* No menu */
  44. hThisInstance, /* Program Instance handler */
  45. NULL /* No Window Creation data */
  46. );
  47. /* Make the window visible on the screen */
  48. ShowWindow (hwnd, nCmdShow);
  49. /* Run the message loop. It will run until GetMessage() returns 0 */
  50. while (GetMessage (&messages, NULL, 0, 0))
  51. {
  52. /* Translate virtual-key messages into character messages */
  53. TranslateMessage(&messages);
  54. /* Send message to WindowProcedure */
  55. DispatchMessage(&messages);
  56. }
  57. /* The program return-value is 0 - The value that PostQuitMessage() gave */
  58. return messages.wParam;
  59. }
  60. /* This function is called by the Windows function DispatchMessage() */
  61. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  62. {
  63. switch (message) /* handle the messages */
  64. {
  65. case WM_DESTROY:
  66. PostQuitMessage (0); /* send a WM_QUIT to the message queue */
  67. break;
  68. default: /* for messages that we don't deal with */
  69. return DefWindowProc (hwnd, message, wParam, lParam);
  70. }
  71. return 0;
  72. }

0 comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!