Windows Applikation

  • Windows Applikation

    Ich frage mich was man machen muss, wenn man eine WindowsApp erstellen will, ohne das hinterher die Konsole geöffnet wir...


    Muss man das auch mich cout und so machen?

    Danke schonmal im Vorraus...


    Könnt ihr mir dann mal auch bitte sagen was an diesem Code Falsch ist???


    Quellcode

    1. #include <windows.h>
    2. /* Declare Windows procedure */
    3. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    4. /* Make the class name into a global variable */
    5. char szClassName[ ] = "WindowsApp";
    6. int WINAPI WinMain (HINSTANCE hThisInstance,
    7. HINSTANCE hPrevInstance,
    8. LPSTR lpszArgument,
    9. int nFunsterStil)
    10. {
    11. HWND hwnd; /* This is the handle for our window */
    12. MSG messages; /* Here messages to the application are saved */
    13. WNDCLASSEX wincl; /* Data structure for the windowclass */
    14. /* The Window structure */
    15. wincl.hInstance = hThisInstance;
    16. wincl.lpszClassName = szClassName;
    17. wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
    18. wincl.style = CS_DBLCLKS; /* Catch double-clicks */
    19. wincl.cbSize = sizeof (WNDCLASSEX);
    20. /* Use default icon and mouse-pointer */
    21. wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    22. wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    23. wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    24. wincl.lpszMenuName = NULL; /* No menu */
    25. wincl.cbClsExtra = 0; /* No extra bytes after the window class */
    26. wincl.cbWndExtra = 0; /* structure or the window instance */
    27. /* Use Windows's default color as the background of the window */
    28. wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    29. /* Register the window class, and if it fails quit the program */
    30. if (!RegisterClassEx (&wincl))
    31. return 0;
    32. /* The class is registered, let's create the program*/
    33. hwnd = CreateWindowEx (
    34. 0, /* Extended possibilites for variation */
    35. szClassName, /* Classname */
    36. "Windows App", /* Title Text */
    37. WS_OVERLAPPEDWINDOW, /* default window */
    38. CW_USEDEFAULT, /* Windows decides the position */
    39. CW_USEDEFAULT, /* where the window ends up on the screen */
    40. 544, /* The programs width */
    41. 375, /* and height in pixels */
    42. HWND_DESKTOP, /* The window is a child-window to desktop */
    43. NULL, /* No menu */
    44. hThisInstance, /* Program Instance handler */
    45. NULL /* No Window Creation data */
    46. );
    47. /* Make the window visible on the screen */
    48. ShowWindow (hwnd, nFunsterStil);
    49. /* Run the message loop. It will run until GetMessage() returns 0 */
    50. while (GetMessage (&messages, NULL, 0, 0))
    51. {
    52. /* Translate virtual-key messages into character messages */
    53. TranslateMessage(&messages);
    54. /* Send message to WindowProcedure */
    55. DispatchMessage(&messages);
    56. }
    57. /* The program return-value is 0 - The value that PostQuitMessage() gave */
    58. return messages.wParam;
    59. }
    60. /* This function is called by the Windows function DispatchMessage() */
    61. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    62. {
    63. switch (message) /* handle the messages */
    64. {
    65. case WM_DESTROY:
    66. PostQuitMessage (0); /* send a WM_QUIT to the message queue */
    67. break;
    68. default: /* for messages that we don't deal with */
    69. return DefWindowProc (hwnd, message, wParam, lParam);
    70. }
    71. return 0;
    72. }
    73. #define STRICT
    74. #include <windows.h>
    75. const char szWitz[] = "\"Ich steh' schwer auf Umweltschutz\", sagt Peter.\n"
    76. "\"Ich werfe zum Beispiel alte U-Bahn-Fahrscheine nie weg,\n"
    77. "sondern benutze sie mehrmals.\"";
    78. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    79. PSTR szCmdLine, int iCmdShow)
    80. {
    81. int iAntwort = MessageBox(NULL, szWitz, "Ha, ha, ha, ha...",
    82. MB_ICONINFORMATION | MB_OKCANCEL | MB_DEFBUTTON1);
    83. if (IDOK == iAntwort)
    84. {
    85. MessageBox(NULL, "Ja, ich finde den Witz auch Ok...",
    86. "Sie haben auf Ok gedrückt",
    87. MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1);
    88. } else if (IDCANCEL == iAntwort)
    89. {
    90. MessageBox(NULL, "Ja, warum haben sie denn auf Abbrechen gedrückt?\n"
    91. "Hat ihnen der Witz etwa nicht gefallen?",
    92. "Sie haben auf Abbrechen gedrückt",
    93. MB_ICONINFORMATION | MB_OK | MB_DEFBUTTON1);
    94. } return 0;
    95. }
    Alles anzeigen

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von ehliboy ()

  • Das ganze ist nicht wirklich falsch naja eig. schon :O

    du hast da ein tutorial verwendet welches ich auch benutzt habe 8| CONSOLE in NA WIN-API ist sinnlos...

    @d0nout ist doch nicht MFC ist sturre WIN-API...

    was mich stutzig macht ist der doppel inklude von <windows.h>...

    ich glaub du hast da zwei Codes (aus dem TuT) untereinander gehängt,

    ps.: du musst bei dem TuT noch die Kompilereinstellung geringfügig ändern :O , g00gle einfach mal nach den Fehler (Linker - Fehler)

    Lg, Gregor

    PS.: mehr kann ich auch nicht ohne den Error-Meldungen sagen....
    Meine Sprachen: C, C++,C# PHP
    E-Mail | MSN: gre.burgstaller@aon.at
  • Hab den Quelltext hier nicht gelesen.

    Es gibt einen aktuellen Compiler der an Win-Programm irgendwie noch eine Konsole einblendet,
    was sonst alle anderen Compiler bei den gleichen Quelltexten nicht machen. Aber vielleicht
    hab ich damals auch nur einen Compiler-Schalter vergessen.

    Nein, die freie Version des Compilers ist meist ohne IDE und Projektverwaltung und heisst
    auch nicht BCC.

    MfG Hainbuche