Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - Controllare stato Radiobutton (C++)
Forum - C/C++ - Controllare stato Radiobutton (C++)

Avatar
Stromberg (Normal User)
Newbie


Messaggi: 4
Iscritto: 26/12/2011

Segnala al moderatore
Postato alle 15:06
Lunedì, 26/12/2011
Salve, volevo chiedervi come verificare lo stato di un radiobutton o checkbox in c++.
Ho letto che bisogna usare SendMessage con BM_GETCHECK ma non so come! o meglio non so come fargli capire di quale Radiobutton ne voglio controllare lo stato. Potreste spiegarmi cosa mettere al posto del commento in questo programma in modo che mi verifichi lo stato del Radiobutton?
Codice sorgente - presumibilmente C#

  1. #include <windows.h>
  2.  
  3. /*  Declare Windows procedure  */
  4. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  5.  
  6. /*  Make the class name into a global variable  */
  7. char szClassName[ ] = "WindowsApp";
  8.  
  9. int WINAPI WinMain (HINSTANCE hThisInstance,
  10.                     HINSTANCE hPrevInstance,
  11.                     LPSTR lpszArgument,
  12.                     int nFunsterStil)
  13.  
  14. {
  15.     HWND hwnd;               /* This is the handle for our window */
  16.     MSG messages;            /* Here messages to the application are saved */
  17.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  18.  
  19.     /* The Window structure */
  20.     wincl.hInstance = hThisInstance;
  21.     wincl.lpszClassName = szClassName;
  22.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  23.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  24.     wincl.cbSize = sizeof (WNDCLASSEX);
  25.  
  26.     /* Use default icon and mouse-pointer */
  27.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  28.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  29.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  30.     wincl.lpszMenuName = NULL;                 /* No menu */
  31.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  32.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  33.     /* Use Windows's default color as the background of the window */
  34.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  35.  
  36.     /* Register the window class, and if it fails quit the program */
  37.     if (!RegisterClassEx (&wincl))
  38.         return 0;
  39.  
  40.     /* The class is registered, let's create the program*/
  41.     hwnd = CreateWindowEx (
  42.            0,                   /* Extended possibilites for variation */
  43.            szClassName,         /* Classname */
  44.            "Windows App",       /* Title Text */
  45.            WS_OVERLAPPEDWINDOW, /* default window */
  46.            CW_USEDEFAULT,       /* Windows decides the position */
  47.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  48.            300,                 /* The programs width */
  49.            300,                 /* and height in pixels */
  50.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  51.            NULL,                /* No menu */
  52.            hThisInstance,       /* Program Instance handler */
  53.            NULL                 /* No Window Creation data */
  54.            );
  55.  
  56.     /* Make the window visible on the screen */
  57.     ShowWindow (hwnd, nFunsterStil);
  58.  
  59.     /* Run the message loop. It will run until GetMessage() returns 0 */
  60.     while (GetMessage (&messages, NULL, 0, 0))
  61.     {
  62.         /* Translate virtual-key messages into character messages */
  63.         TranslateMessage(&messages);
  64.         /* Send message to WindowProcedure */
  65.         DispatchMessage(&messages);
  66.     }
  67.  
  68.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  69.     return messages.wParam;
  70. }
  71.  
  72. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  73. {
  74.     switch (message)                  /* handle the messages */
  75.     {
  76.                 case WM_CREATE:
  77.                         /*Radio-1*/CreateWindow("Button", "Radio-1", WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON, 1,1,100,50,hwnd,(HMENU) 0, NULL, NULL);
  78.                         /*Radio-2*/CreateWindow("Button", "Radio-2", WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON, 1,50,100,50,hwnd,(HMENU) 1, NULL, NULL);
  79.                         /*Push*/   CreateWindow("Button", "Test", WS_VISIBLE|WS_CHILD,1,100,100,50,hwnd,(HMENU) 2, NULL, NULL);
  80.                         break;
  81.                 case WM_COMMAND:
  82.                         if (LOWORD(wParam)==2)
  83.                         {
  84.                                 if (/*COSA DEVO METTERE QUì???????????????????????*/)
  85.                                 {
  86.                                         MessageBox(hwnd, "Selezionato Radio-1", "", MB_OK);
  87.                                 }
  88.                         }
  89.                         break;
  90.         case WM_DESTROY:
  91.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  92.             break;
  93.         default:                      /* for messages that we don't deal with */
  94.             return DefWindowProc (hwnd, message, wParam, lParam);
  95.     }
  96.  
  97.     return 0;
  98. }


GRAZIE IN ANTICIPO :k:

PM