mensaje bip
Lo hice usando la API C, ¡lo cual fue un poco problemático!
#include lt;windows.hgt;
#include "resource.h"
#include "stdlib.h"
#define BUFFER(x, y)*(pBuffer y*cxBuffer x)//Predefinir para solicitar un nuevo espacio de memoria
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
char szAppName[]="first";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)//función principal de winmain
{< / p>
// static char szAppName[]="Instancia"; // Nombre de clase de ventana
HWND hwnd; // Identificador de ventana
MSG msg;
WNDCLASSEX wndclass; //Clase de ventana
wndclass.cbSize=sizeof(wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc; //Función de procesamiento de ventanas
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0; hInstance;
wndclass.hIcon=LoadIcon(hInstance, MAKEINTRESOURCE(MYICON1));
wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);
wndclass . hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wndclass.lpszClassName=szAppName;
// wndclass . hIconSm=LoadIcon(NULL, MAKEINTRESOURCE(MYICON2));
wndclass.hIconSm=LoadIcon(hInstance, MAKEINTRESOURCE(MYICON2));
if(!RegisterClassEx(amp; wndclass) ) //Emitir una advertencia si falla el registro
{
MessageBeep(0);
return FALSE;
HMENU hMenu;
hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
hwnd=CreateWin
dow(szAppName,
"La primera ventana de mi instancia 9-1",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow); //Mostrar ventana
UpdateWindow(hwnd); //Dibujar área de usuario
while (GetMessage) (amp; msg, NULL, 0, 0))//Bucle de mensajes
{
TranslateMessage(amp; msg); //Traducir mensaje
DispatchMessage (amp; msg); // Pasa el mensaje a la función de procesamiento
}
return msg.wParam
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)// Función de procesamiento de ventanas | Función de procesamiento de mensajes
{
static char *pBuffer=NULL;
p>static int cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer, xCaret, yCaret;
HDC hdc;
int x, y, i; p >
PAINTSTRUCT ps;
TEXTMETRIC tm;
static int iColorID[5]={WHITE_BRUSH, LTGRAY_BRUSH, GREY_BRUSH, DKGRAY_BRUSH, BLACK_BRUSH}; > static int iSelection=ID_MENUITEM40013;
HMENU hMenu;
switch(iMsg)
{
caso WM_COMMAND:
hMenu=GetMenu(hwnd);
switch(LOWORD(wParam))
{
caso ID_MENUITEM40001:
caso ID_MENUITEM40002 :
caso ID_MENUITEM40003:
MessageBeep(0);
devuelve 0
caso ID_MENUITEM40004:
SendMessage(hwnd, WM_CLOSE, 0, 0L);
devuelve 0;
caso ID_MENUITEM40005:
caso ID_MENUITEM40006:
caso ID_MENUITEM40007:
caso ID_MENUITEM40008:
caso ID_MENUITEM40018:
caso ID_MENUITEM40019:
caso ID_MENUITEM40020:
caso ID_MENUITEM40021:
caso ID_MENUITEM40022:
CheckMenuItem(hMenu, iSelection, MF_UNCHECKED);
iSelection=LOWORD(wParam);
CheckMenuItem(hMenu, iSelection, MF_CHECKED); /p>
SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG) GetStockObject(iColorID[LOWORD(wParam)-ID_MENUITEM40018]));
InvalidateRect(hwnd, NULL, TRUE); p> devuelve 0;
caso ID_MENUITEM40011:
MessageBox(hwnd, "¡Ayuda aún no implementada!", szAppName, MB_ICONEXCLAMATION|MB_OK
devuelve 0); ;
caso ID_MENUITEM40012:
MessageBox(hwnd, "Este bloc de notas se produce utilizando tecnología C. Los derechos de autor pertenecen al equipo Perak de nuestra empresa. ¡Los infractores serán procesados!", szAppName, MB_ICONINFORMATION | MB_OK);
devuelve 0
}
descanso
/* caso WM_TIMER:
MessageBeep (0);
return 0;
case WM_DESTROY:
PostQuitMessage(0); //Llama a la función postquitmessage para salir del programa
devolver 0;
caso WM_CREATE:
hdc=GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT)); >
GetTextMetrics(hdc, amp; tm);
cxChar=tm.tmAveCharWidth
cyChar=tm.tmHeight
ReleaseDC(hwnd, hdc);
devuelve 0;
caso WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam)
p>
cxBuffer=max(1, cxClient/cxChar);
cyBuffer=max(1, cyClient/cyChar);
p>
if(pBuffer!=NULL)
gratis(pBuffer);
if((pBuffer=(char*)malloc(cxBuffer*cyBuffer))==NULL )
MessageBox(hwnd, "La ventana es demasiado grande y no hay suficiente memoria. Redúzcala adecuadamente.", "Typer", MB_ICONEXCLAMATION|MB_OK
else<); / p>
for(y=0;ylt;cyBuffer;y)
for(x=0;xlt;cxBuffer;x)
BUFFER(x, y) = ' ';
xCaret=0;
yCaret=0;
if(hwnd==GetFocus())//Obtener enfoque
SetCaretPos(xCaret*cxChar, yCaret*cyChar); //Establece el cursor
return 0;
case WM_SETFOCUS:
CreateCaret(hwnd, NULL, cxChar, cyChar);
SetCaretPos(xCaret*cxChar, yCaret*cyChar);
ShowCaret(hwnd); >
caso WM_KILLFOCUS:
HideCaret(hwnd);
DestroyCaret();
devuelve 0
caso WM_KEYDOWN:
p>switch(wParam)// El código escaneado se traduce en código virtual y el código virtual se almacena en el parámetro wparam del teclado
{
case VK_HOME: //tecla de inicio p>
xCaret=0;
break
case VK_END: //fin de tecla
xCaret=cxBuffer-1;
descanso
caso VK_PRIOR: //página arriba
yCaret=0;
case VK_NEXT: // tecla de avance de página
yCaret=cyBuffer-1;
break;
case VK_LEFT: //Flecha izquierda clave
xCaret=max( xCaret-1, 0);
break;
case VK_RIGHT: //tecla de flecha derecha
xCaret=min(xCaret 1, 0);
p>break;
case VK_UP: //Tecla de flecha hacia arriba
yCaret=max(yCaret-1) , 0);
break;
case VK_DOWN: //Tecla de flecha hacia abajo
yCaret=min(yCaret 1, cyBuffer-1); >
descanso;
case VK_DELETE: //del key
for(x=xCaret;xlt;cxBuffer-1;x)
BUFFER(x,yCaret)=BUFFER(x 1,yCaret);
BUFFER(cxBuffer-1, yCaret)=' ';
HideCaret(hwnd);
hdc=GetDC(hwnd); p> SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
TextOut(hdc, xCaret*cxChar, yCaret*cyChar, amp; BUFFER(xCaret, yCaret), cxBuffer-xCaret
<); p> ShowCaret(hwnd);ReleaseDC(hwnd, hdc);
descanso
}
SetCaretPos(xCaret*cxChar; , yCaret*cyChar);
return 0;
case WM_CHAR: //
for(i=0; ilt; (int)LOWORD(lParam) ; i )
{
cambiar(wParam)
{
caso '\b':
if(xCaretgt; 0)
{
xCaret--;
SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1L); }
ruptura;
caso '\t':
hacer
{
EnviarMessage(hwnd, WM_CHAR, ' ', 1L);
}
while(xCaret 8!=0
break
case '); \n':
if( yCaret==cyBuffer)
yCaret=0
break
case '\r'; :
xCaret=0;
if( yCaret==cyBuffer)
yCaret=0
descanso
;caso '\x1B':
for(y=0;ylt;cyBuffer;y)
for(x=0;xlt;cxBuffer;x)
BUFFER(x, y)=' ';
xCaret=0;
yCaret=0
InvalidateRect(hwnd, NULL, FALSE; );
descanso;
predeterminado:
BUFFER(xCaret,
yCaret)=(char)wParam;
HideCaret(hwnd);
hdc=GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT)) ;
TextOut(hdc, xCaret*cxChar, yCaret*cyChar, amp; BUFFER(xCaret, yCaret), 1
ShowCaret(hwnd); > ReleaseDC(hwnd, hdc);
if( xCaret==cxBuffer)
{
xCaret=0;
if( yCaret==cyBuffer)
yCaret=0
}
descanso
}
}
SetCaretPos(xCaret*cxChar, yCaret*cyChar);
devuelve 0;
caso WM_PAINT:
hdc=BeginPaint(hwnd, amp;ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
for(y=0;ylt;cyBuffer;y)
TextOut( hdc, 0, y*cyChar, amp; BUFFER (0, y), cxBuffer
EndPaint (hwnd, amp; ps
return 0; p> p>
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);