Red de conocimiento informático - Conocimiento del nombre de dominio - Cómo escribir un programa de formulario en lenguaje C

Cómo escribir un programa de formulario en lenguaje C

Pasos:

1. Registrar clase de ventana;

2. Crear formulario;

3.

4. Escriba una función de procesamiento de mensajes de ventana.

Código: #include?

#include

LRESULT?CALLBACK?WindowProc(HWND?hwnd,?UINT ?msg,?WPARAM?wParam,?LPARAM?lParam);

int?WINAPI?_tWinMain?(HINSTANCE?hInstance,?HINSTANCE?hPrevInstance,?LPWSTR?szCmdLine,?int?nCmdShow)

{

WNDCLASS?wc;

wc.style?=?CS_HREDRAW?|?CS_VREDRAW;

wc.lpfnWndProc?=?WindowProc;

wc.cbClsExtra?=?0;

wc.cbWndExtra?=?0;

wc.hInstance?=?hInstance;

wc.hIcon?=?NULL;

wc.hCursor?=?LoadCursor(NULL,IDC_ARROW);

wc.hbrBackground?=?(HBRUSH)COLOR_WINDOW;// (HBRUSH)GetStockObject();

wc.lpszMenuName?=?NULL;

wc.lpszClassName?=?_T("MyWindowClass");

if ?(!RegisterClass(&wc))

{

MessageBox?(NULL,?_T("No se puede registrar la clase de ventana"),?_T("Error"),?MB_OK ) ;

return?0?;

}

HWND?newWindow?=?CreateWindow(

_T("MyWindowClass") ,

_T("Mi primer programa winapi"),

WS_OVERLAPPEDWINDOW,

0,

0,

CW_USEDEFAULT,

CW_USEDEFAULT,

NULL,

NULL,

hInstancia,

NULL

);

if?(NULL?==?newWindow)

{

MessageBox?(NULL,?_T(" No se puede crear formulario"),?_T("Error"),?MB_OK);

return?0;

}

ShowWindow(newWindow,? nCmdShow) ;

ActualizarVentana(nuevaVentana);

MSG?msg;

mientras(GetMessage(&msg,?NULL,?0,?0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

LRESULT?CALLBACK?WindowProc(HWND?hwnd,?UINT?uMsg,?WPARAM?wParam,?LPARAM?lParam)

{

cambiar?(uMsg)

{

caso

?WM_DESTROY:

{

PostQuitMessage(0);

interrupción;

}

¿predeterminado?:

return?DefWindowProc(hwnd,?uMsg,?wParam,?lParam);

}

return?0;

}

Es un formulario con solo una barra de título, un botón de cerrar, un botón de minimizar, un botón de maximizar/restaurar y un área de visualización.