kake_fisk Skrevet 31. mars 2008 Del Skrevet 31. mars 2008 Jeg prøver å lære winapi, og har begynnt å forstå litt... Jeg bruker denne koden: #include <windows.h> /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0; /* The class is registered, let's create the program*/ [color="#FF0000"]void CreateToolTipForRect(HWND hwndParent) { // Create a ToolTip. HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndParent, NULL, g_hInst,NULL); SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // Set up "tool" information. // In this case, the "tool" is the entire parent window. TOOLINFO ti = { 0 }; ti.cbSize = sizeof(TOOLINFO); ti.uFlags = TTF_SUBCLASS; ti.hwnd = hwndParent; ti.hinst = g_hInst; ti.lpszText = TEXT("This is your ToolTip string.");; GetClientRect (hwndParent, &ti.rect); // Associate the ToolTip with the "tool" window. SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } // Associate the ToolTip with the tool. TOOLINFO toolInfo = { 0 }; toolInfo.cbSize = sizeof(toolInfo); toolInfo.hwnd = hDlg; toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; toolInfo.uId = (UINT_PTR)hwndTool; toolInfo.lpszText = pText; SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); return TRUE; }[/color] /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) /* handle the messages */ { case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } HWND hwndMain; HWND hwndEdit; char achTemp[256]; // temporary buffer LPSTR lpstrDict; // buffer for dictionary file LPSTR *paLpDict; // array of pointers to words UINT cWords; // number of words Error: Kompilator: Default compiler Kjører g++.exe... g++.exe "C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp" -o "C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)': C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:42: error: a function-definition is not allowed here before '{' token C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:42: error: expected `,' or `;' before '{' token C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:70: error: `TOOLINFO' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:70: error: (Each undeclared identifier is reported only once for each function it appears in.) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:70: error: expected `;' before "toolInfo" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:71: error: `toolInfo' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:72: error: `hDlg' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:73: error: `TTF_IDISHWND' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:73: error: `TTF_SUBCLASS' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:74: error: `hwndTool' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:75: error: `pText' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:76: error: `hwndTip' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:76: error: `TTM_ADDTOOL' undeclared (first use this function) C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp: At global scope: C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:83: error: expected constructor, destructor, or type conversion before '(' token C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:83: error: expected `,' or `;' before '(' token C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:86: error: expected unqualified-id before "while" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:86: error: expected `,' or `;' before "while" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:95: error: expected unqualified-id before "return" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:95: error: expected `,' or `;' before "return" C:\Documents and Settings\Ørjan\Mine dokumenter\c++\win\main.cpp:96: error: expected declaration before '}' token Kjøring avbrutt Noen som vet hva som er galt? Lenke til kommentar
Giddion Skrevet 1. april 2008 Del Skrevet 1. april 2008 Et tips er at når det dundrer inn med mange feil så prøv å fjern de du helt klart ser. Ofter får du flere syntax feil som henger sammen med andre feil. f. eks variablene under er ikke erklært, dvs. at kompilatoren ikke har snøring på hva de er. toolInfo hDlg pText hwndTip TTF_IDISHWND TTF_SUBCLASS TTM_ADDTOOL Variabler som bare er store bokstaver er ofte constanter så de pleier å dukke opp hvis du googler de. De andre har jeg ingen ide om hvor du har fra, men noen ser ut til å være handler til windows ting. Du får tenke på det selv, men for meg kan det virke som om du går litt for fort fram med kodingen din. Lenke til kommentar
Arne Skrevet 2. april 2008 Del Skrevet 2. april 2008 Er dette berre noko du har copy/pasta? Du sleit jo med å definere variablar/funksjonar for to dagar sidan... Ikkje det at eg har noko eg skulle sagt når det gjeld det (hehe..), men kanskje du skal lære deg meir standard-ting som OOP, funksjoner, pointers, og arrays før du går på dette? Og loops? Lenke til kommentar
kake_fisk Skrevet 2. april 2008 Forfatter Del Skrevet 2. april 2008 Hmm, jeg copya egentlig ja Men trodde ikke jeg skulle få så mange erros fra msdn... Er det noen som har noen forslag til hva jeg kan begynne å lære når jeg har lært det med arrays og mattematikk og sånt? Lenke til kommentar
NevroMance Skrevet 2. april 2008 Del Skrevet 2. april 2008 Object Oriented Programing (OOP) er jo noe som er veldig nyttig å kunne. Anbefaller at du lærer deg det hvis du ikke kan det. Er ikke C++ spesifikt, men fortsatt nyttig å kunne. Lenke til kommentar
kake_fisk Skrevet 2. april 2008 Forfatter Del Skrevet 2. april 2008 hmm, object oriented programming? hva er det? Lenke til kommentar
Giddion Skrevet 2. april 2008 Del Skrevet 2. april 2008 programmering ved hjelp av klasser (eller lignende i andre språk) Lenke til kommentar
kake_fisk Skrevet 2. april 2008 Forfatter Del Skrevet 2. april 2008 okay, kan prøve å finne noe på google... Lenke til kommentar
GeirGrusom Skrevet 2. april 2008 Del Skrevet 2. april 2008 http://en.wikipedia.org/wiki/Object-oriented_programming Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå