Il problema qui è che le applicazioni Windows in vanilla C sono un gran casino... questo il codice per far apparire la tua finestra vuota:Originariamente inviato da MonsterMash
P.S. Se "il metodo semplice per" vi pare un'espressione brutta, ditemi pure i metodi complessi...
.codice:#include <windows.h> HINSTANCE ghInstance; /* hInstance dell'applicazione */ LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM ); /********************************************************************\ * Function: int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) * * * * Purpose: Initializes Application * * * * Comments: Register window class, create and display the main * * window, and enter message loop. * * * * * \********************************************************************/ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { WNDCLASS wc; MSG msg; HWND hWnd; BOOL bRet; if( !hPrevInstance ) { wc.lpszClassName = TEXT("MonsterMash_MainWindowClass"); /* occhio che deve essere un ID unico */ wc.lpfnWndProc = MainWndProc; wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 ); wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = 0; RegisterClass( &wc ); } ghInstance = hInstance; hWnd = CreateWindow( TEXT("MonsterMash_MainWindowClass"), TEXT("Una finestra vuota"), WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow( hWnd, nCmdShow ); while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0 ) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage( &msg ); DispatchMessage( &msg ); } } return (int)msg.wParam; } /********************************************************************\ * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) * * * * Purpose: Processes Application Messages * * * * Comments: The following messages are processed * * * * WM_PAINT * * WM_DESTROY * * * * * \********************************************************************/ LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hDC; switch( msg ) { /**************************************************************\ * WM_PAINT: * \**************************************************************/ case WM_PAINT: hDC = BeginPaint( hWnd, &ps ); /* qui puoi disegnare sulla finestra tramite il device context hDC */ EndPaint( hWnd, &ps ); break; /**************************************************************\ * WM_DESTROY: PostQuitMessage() is called * \**************************************************************/ case WM_DESTROY: PostQuitMessage( 0 ); break; /**************************************************************\ * Let the default window proc handle all other messages * \**************************************************************/ default: return( DefWindowProc( hWnd, msg, wParam, lParam )); } return 0; }
Comunque se davvero hai intenzione di proseguire sulla strada di scrivere applicazioni Windows in C procurati un buon libro (ho acquistato di recente a poco prezzo su Amazon questo, prendendolo usato).

Rispondi quotando