Oppure

Loading
26/10/07 16:49
The Lizard King
Ciao raga, ho qualche problema con un programma, ora vi mostro il sorgente:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("HelloWin") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = GetSysColorBrush(COLOR_3DFACE) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     hwnd = CreateWindow (szAppName,                  // window class name
                          "The Hello Program",        // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          CW_USEDEFAULT,              // initial x position
                          CW_USEDEFAULT,              // initial y position
                          CW_USEDEFAULT,              // initial x size
                          CW_USEDEFAULT,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters

     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;

     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     HDC         hdc ;
     PAINTSTRUCT ps ;
     RECT        rect ;

     switch (message)
     {
     case WM_CREATE:
          PlaySound ("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC) ;
          break;

     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;

          GetClientRect (hwnd, &rect) ;

          DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
          EndPaint (hwnd, &ps) ;
          break;

     case WM_DESTROY:
          PostQuitMessage (0) ;
          break;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}


E questi invece sono gli errori:
img139.imageshack.us/img139/4034/…

Come risolvo? :(
Ultima modifica effettuata da The Lizard King 26/10/07 16:49
aaa
26/10/07 20:23
Dax89
Stai facendo delle chiamate alle API di windows e il solo windows.h non è sufficiente.
Aggiungi gli headers in questo modo:

#include <windows.h>
#include <winuser.h>
#include <winbase.h>

Poi aggiungi le librerie kernel32 e user32 al linker;)
aaa
27/10/07 10:13
The Lizard King
Postato originariamente da Dax89:

Stai facendo delle chiamate alle API di windows e il solo windows.h non è sufficiente.
Aggiungi gli headers in questo modo:

#include <windows.h>
#include <winuser.h>
#include <winbase.h>

Poi aggiungi le librerie kernel32 e user32 al linker;)


Ho aggiunto gli headers mancanti, ma come faccio ad aggiungere quelle 2 librerie? Da dove le prendo?? :-?
aaa
28/10/07 9:18
Dax89
Aggiungi al codice queste 2 direttive (non sono sicuro che funzioni):
Se usi DevCpp:

#pragma comment(lib, "libkernel32.o")
#pragma comment(lib, "libuser32.o")


Se usi Visual Studio

#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
Ultima modifica effettuata da Dax89 28/10/07 9:19
aaa
28/10/07 12:53
The Lizard King
Non sai come fare per Codeblocks? :-?
aaa
28/10/07 13:53
Dax89
Se usi gcc si fa come DevCpp.;)
Ultima modifica effettuata da Dax89 28/10/07 13:54
aaa
28/10/07 19:24
The Lizard King
Grazie ma ho provato di tutto, non mi riconosce mai PlaySound() e le parti contenute in esso... forse abbiamo sbagliato librerie? :-?
aaa
29/10/07 16:32
Dax89
Perchè l' API PlaySound risiede in winmm.dll
(credo che si chiami però PlaySoundA).

Aggiungi alle direttive include questa:

#include <winmm.h>


Poi correggi le direttive del linker con queste:

#pragma comment(lib, "libkernel32.a")
#pragma comment(lib, "libuser32.a")
#pragma comment(lib, "libwinmm.a")

Ultima modifica effettuata da Dax89 29/10/07 16:33
aaa