Dal canale youtube: appuntisistemi
Titolo video: windows eventi
Descrizione:
Questo video mostra un sorgente C di un programma che gira sotto Windows. IL programma genera 2 finestre, che rispondono a diversi eventi: WM_DESTROY, WM_KEYUP, WM_KEYDOWN, WM_MOUSEMOVE. Agli eventi WM_DESTROY e WM_KEYDOWN rispondono entrambe le finestre; invece agli eventi WM_KEYUP (tasto rilasciato) e WM_MOUSEMOVE (movimento del mouse) risponde soltanto una delle 2 finestre e l’altra no.
In particolare WM_KEYUP (tasto rilasciato), viene sentito da finestra. Se il tasto rilasciato è ‘H’ allora la finestra2 viene nascosta. Se il tasto rilasciato è ‘V’, la finestra2 viene mostrata. Riporto il sorgente C del programma…
Codice sorgente C
#include <windows.h>
#include <stdio.h>
char nomeclasse[ ] = "WindowsApp";
char captionfinestra[ ] = "La mia finestra (H per nascondere finestra2, V per mostrare finestra2)\0";
char captionfinestra2[ ] = "La mia finestra2\0";
int larghezza = 600;
int altezza = 200;
int x,x2;
int y,y2;
HWND finestra,finestra2; /* This are the handles for our windows */
MSG messaggi,messaggi2;
WNDCLASSEX strutturafinestra; /* Data structure for the windowclass */
/* Declare Windows procedure */
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK ProceduraWindows(HWND oggettofinestra, UINT messaggiowindows, WPARAM wParam, LPARAM lParam)
{
if (messaggiowindows == WM_DESTROY) {PostQuitMessage (0);};
if (oggettofinestra == finestra) {if (messaggiowindows == WM_KEYUP) {printf("Tasto rilasciato... %c \n",wParam); if (wParam == 'H') {ShowWindow (finestra2, SW_HIDE);};if (wParam == 'V') {ShowWindow (finestra2, SW_SHOW);};};};
if (messaggiowindows == WM_KEYDOWN) {printf("Tasto premuto... %c \n",wParam);};
if (oggettofinestra == finestra2) {if (messaggiowindows == WM_MOUSEMOVE) {printf("IL mouse si muove...\n");};};
if (messaggiowindows != WM_MOUSEMOVE && messaggiowindows != WM_KEYDOWN && messaggiowindows != WM_KEYUP && messaggiowindows != WM_DESTROY) {return DefWindowProc (oggettofinestra, messaggiowindows, wParam, lParam);};
// return 0;
}
int WINAPI
WinMain (HINSTANCE istanzaquestoprogramma,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
/* The Window structure */
strutturafinestra.hInstance = istanzaquestoprogramma;
strutturafinestra.lpszClassName = nomeclasse;
strutturafinestra.lpfnWndProc = ProceduraWindows; /* This function is called by windows */
strutturafinestra.style = CS_DBLCLKS; /* Catch double-clicks */
strutturafinestra.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
strutturafinestra.hIcon = LoadIcon (NULL, IDI_APPLICATION);
strutturafinestra.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
strutturafinestra.hCursor = LoadCursor (NULL, IDC_ARROW);
strutturafinestra.lpszMenuName = NULL; /* No menu */
strutturafinestra.cbClsExtra = 0; /* No extra bytes after the window class */
strutturafinestra.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
strutturafinestra.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&strutturafinestra))
return 0;
/* The class is registered, let's create the program*/
finestra = CreateWindowEx (
0, /* Extended possibilites for variation */
nomeclasse, /* Classname */
captionfinestra, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
x, /* Windows decides the position */
y, /* where the window ends up on the screen */
larghezza, /* The programs width */
altezza, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
istanzaquestoprogramma, /* Program Instance handler */
NULL /* No Window Creation data */
);
finestra2 = CreateWindowEx (
0, /* Extended possibilites for variation */
nomeclasse, /* Classname */
captionfinestra2, /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
x2, /* Windows decides the position */
y2, /* where the window ends up on the screen */
larghezza, /* The programs width */
altezza, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
istanzaquestoprogramma, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (finestra, SW_SHOW); // SW_SHOW oppure SW_HIDE
ShowWindow (finestra2, SW_SHOW); // SW_SHOW oppure SW_HIDE
/* Run the messaggio loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messaggi, NULL, 0, 0))
{
/* Translate virtual-key messaggi into character messaggi */
TranslateMessage(&messaggi);
/* Send messaggio to ProceduraWindows */
DispatchMessage(&messaggi);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messaggi.wParam;
while (GetMessage (&messaggi2, NULL, 0, 0))
{
/* Translate virtual-key messaggi into character messaggi */
TranslateMessage(&messaggi2);
/* Send messaggio to ProceduraWindows */
DispatchMessage(&messaggi2);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messaggi2.wParam;
}
Registratore vocale con Arduino
Descrizione:
Progetto di registratore vocale digitale con ARDUINO. Un microfono é collegato all’ingresso analogico A0 di ARDUINO. ARDUINO campiona la voce e invia i campioni alla porta USB “COM3”. Un programma, scritto in C, preleva i campioni e li converte in “audio grezzo”, creando un file con estensione .raw
In seguito, con il programma ffmpeg.exe, scaricabile da ffmpeg.org, l’audio grezzo viene convertito in formato wave (estensione .wav)
come_tracciare_diagrammi_bode.wmv
Descrizione:
Come tracciare i diagrammi di Bode del modulo di una f.d.t. G(jw).
1) Calcolo del guadagno statico G(0)
2) convertire in decibel il guadagno statico con la formula dB = 20 log G(0)
3) calcolo degli zeri (annullano il numeratore)
4) calcolo dei poli (annullano il denominatore)
5) tracciamento sapendo che…
6) quando incontro uno zero la pendenza aumenta di +20dB/decade
7) quando incontro un polo la pendenza diminuisce – 20dB/decade
Animazione Lissajous javascript ffmpeg
Descrizione:
Esempio di figura di Lissajous. In questo esempio ho le seguenti funzioni:
x(t) = 200sin(2PI7freqbaset+PI/2) sul canale CH1 y(t) = 200sin(2PI5freqbaset+0) sul canale CH2
L’animazione è stata ottenuta con JAVASCRIPT e il programma ffmpeg.exe
Buona visione!
Andrea Paolini (Amministratore del Blog)