Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2.  
  3. #define ID_BUTTON 1
  4.  
  5. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  6. CHAR szClassName[ ] = "CodeBlocksWindowsApp";
  7. HWND hButton, hEdit, hList;
  8.  
  9. int WINAPI WinMain (HINSTANCE hThisInstance,
  10.                      HINSTANCE hPrevInstance,
  11.                      LPSTR lpszArgument,
  12.                      int nCmdShow)
  13. {
  14.     HWND hwnd;               /* This is the handle for our window */
  15.     MSG messages;            /* Here messages to the application are saved */
  16.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  17.  
  18.     /* The Window structure */
  19.     wincl.hInstance = hThisInstance;
  20.     wincl.lpszClassName = szClassName;
  21.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  22.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  23.     wincl.cbSize = sizeof (WNDCLASSEX);
  24.  
  25.     /* Use default icon and mouse-pointer */
  26.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  27.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  28.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  29.     wincl.lpszMenuName = NULL;                 /* No menu */
  30.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  31.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  32.     /* Use Windows's default colour as the background of the window */
  33.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  34.  
  35.     /* Register the window class, and if it fails quit the program */
  36.     if (!RegisterClassEx (&wincl))
  37.         return 0;
  38.  
  39.     /* The class is registered, let's create the program*/
  40.     hwnd = CreateWindowEx (
  41.            0,                   /* Extended possibilites for variation */
  42.            szClassName,         /* Classname */
  43.            "Code::Blocks Template Windows App",       /* Title Text */
  44.            WS_OVERLAPPEDWINDOW, /* default window */
  45.            CW_USEDEFAULT,       /* Windows decides the position */
  46.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  47.            544,                 /* The programs width */
  48.            375,                 /* and height in pixels */
  49.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  50.            NULL,                /* No menu */
  51.            hThisInstance,       /* Program Instance handler */
  52.            NULL                 /* No Window Creation data */
  53.            );
  54.     { /// hwnd
  55.         hButton = CreateWindowEx(0, "BUTTON", "Zapisz", WS_CHILD | WS_VISIBLE, 0, 315, 200, 21, hwnd, (HMENU)ID_BUTTON, hThisInstance, NULL);
  56.         hList = CreateWindowEx(0, "LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 0, 200, 300, hwnd, NULL, hThisInstance, NULL);
  57.         hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE, 0, 291, 200, 20, hwnd, NULL, hThisInstance, NULL);
  58.  
  59.     }
  60.  
  61.     /* Make the window visible on the screen */
  62.     ShowWindow (hwnd, nCmdShow);
  63.  
  64.     /* Run the message loop. It will run until GetMessage() returns 0 */
  65.     while (GetMessage (&messages, NULL, 0, 0))
  66.     {
  67.         /* Translate virtual-key messages into character messages */
  68.         TranslateMessage(&messages);
  69.         /* Send message to WindowProcedure */
  70.         DispatchMessage(&messages);
  71.     }
  72.  
  73.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  74.     return messages.wParam;
  75. }
  76.  
  77.  
  78. /*  This function is called by the Windows function DispatchMessage()  */
  79.  
  80. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  81. {
  82.     switch (message)                  /* handle the messages */
  83.     {
  84.         case WM_COMMAND:{
  85.             switch(wParam)
  86.             {
  87.                 case ID_BUTTON:{
  88.                     ///tutaj ta Twoja instrukcja
  89.                     break;
  90.                 }
  91.                 case 123:{
  92.                     ///tuaj obsluga innego przycisku
  93.                     break;
  94.                 }
  95.             }
  96.             break;
  97.         }
  98.         case WM_DESTROY:
  99.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  100.             break;
  101.         default:                      /* for messages that we don't deal with */
  102.             return DefWindowProc (hwnd, message, wParam, lParam);
  103.     }
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement