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++ - Programmare con GUI in c++ con windows.h
Forum - C/C++ - Programmare con GUI in c++ con windows.h

Avatar
frank92 (Normal User)
Newbie


Messaggi: 3
Iscritto: 30/03/2009

Segnala al moderatore
Postato alle 14:00
Lunedė, 30/03/2009
ciao,
come posso programmare in c++ con la libreria windows.h,
tipo creare finestre inserire testi, campi di testo, bottoni, ecc...
senza usare Visual C++, ma usando Dev C++?

Ecco l'esempio che fornisce Dev C++,ma come si aggiunge testo??
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.            544,                 /* The programs width */
  49.            375,                 /* 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.  
  73. /*  This function is called by the Windows function DispatchMessage()  */
  74.  
  75. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  76. {
  77.     switch (message)                  /* handle the messages */
  78.     {
  79.         case WM_DESTROY:
  80.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  81.             break;
  82.         default:                      /* for messages that we don't deal with */
  83.             return DefWindowProc (hwnd, message, wParam, lParam);
  84.     }
  85.  
  86.     return 0;
  87. }


PM Quote
Avatar
lorenzo (Normal User)
Guru


Messaggi: 1178
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 9:19
Martedė, 31/03/2009
eh, č una cosa abbastanza complicata....devi imparare ad usare molto bene le api che ti fornisce windows.
Quello che ti mostra dev c++ č corretto: un winmain(che spiegato banalmente equivale al main dei programmi console) e una funzione proc che gestisce i messaggi che arrivano alla tua finestra(conosci come lavorano le finestre in windows vero?)

io mi sono studiato queste cose da solo su "programming windows" di charles petzold e devo dire che mi sono trovato molto bene.

Comunque non č una cosa molto facile anche se ti aiuta a capire molto bene come funzionano le finestre windows....se vuoi qualcosa di pių intuitivo passa a .NET con i form.

per l'aggiunta di testo potresti usare la funzione TextOut(guardati l'help per ii parametri) ma ricorda che scrivere su una finestra non č cosė facile come scrivere sulla console....

Ultima modifica effettuata da lorenzo il 31/03/2009 alle 9:20
PM Quote
Avatar
frank92 (Normal User)
Newbie


Messaggi: 3
Iscritto: 30/03/2009

Segnala al moderatore
Postato alle 13:21
Giovedė, 09/04/2009
Alcuni usano Visual C++ che versione mi consigli per disegnare le finestre come in VisualBasic senza mettere quasi mai mano a i codici C++??

P.S. Esiste un listato in C++ dove viene fatto un frameset a una pagina html in una finestra di Windows??

Ultima modifica effettuata da frank92 il 09/04/2009 alle 13:26
PM Quote
Avatar
ruggy94 (Member)
Guru


Messaggi: 890
Iscritto: 21/04/2008

Segnala al moderatore
Postato alle 17:54
Giovedė, 09/04/2009
Testo quotato

Postato originariamente da frank92:
Alcuni usano Visual C++ che versione mi consigli per disegnare le finestre come in VisualBasic senza mettere quasi mai mano a i codici C++??


Se intendi "quale versione di visual c++" ci sono la Express 2005 e 2008.

http://www.microsoft.com/express/vc/ -> 2008

http://www.brothersoft.com/d.php?soft_id=65282&url=http%3A ... -> 2005

PM Quote
Avatar
lorenzo (Normal User)
Guru


Messaggi: 1178
Iscritto: 15/04/2008

Segnala al moderatore
Postato alle 9:36
Venerdė, 10/04/2009
Testo quotato

Postato originariamente da frank92:
senza mettere quasi mai mano a i codici C++??



per questo avevo chiesto anche ios e esisteva un ide simile al basic ma di quel tipo io ho trovato solo c++ builder, che usa un wrapper delle api di windows

Per visual c++ 2005/08 come ti ha detto ruggy94 non credo che sia quello che vuoi tu dato che per disegnare le form come vb con quell'ide devi usare anche il framework .NET e quindi dovresti usare il Managed c++.

Se vuoi rimanere sulle classiche api o usi le mfc, o ti scrivi il codice a mano, o provi c++ builder

Ultima modifica effettuata da lorenzo il 10/04/2009 alle 9:36
PM Quote