Frage zu ShowWindow(hwnd, SW_HIDE);



  • Ich hätte da eine kleine frage und zwar wie kann ich ein konsolenprogramm im hintergrund laufen lassen. (Das dos fenster soll nicht aufblinken). Ist das mit ShowWindow(hwnd, SW_HIDE); realisierbar ??? Ich wäre für ein kleines lauffähiges "Hello World" Programm (das man natürlich nicht sieht) als beispiel sehr erfreut.

    Sorry, falls sich die frage etwas blöd anhört, aber für nen linuxer is das win/dos zeugs ned immer so einfach ^^.

    Danke schon mal.



  • Wenn ein Programm im Hintergrund laufen soll, wäre es viel viel geschickter erst gar kein *Konsolen*programm zu schreiben 😉

    Also brauchst du die Konsole irgendwann? Wenn ja, schreib gleich zu Beginn ShowWindow(GetConsoleWindow(), SW_HIDE) hin. Wenn du es nicht brauchst wäre es besser statt eine Konsolenanwendung eine Windowsanwendung ohne Fenster zu schreiben.

    MfG SideWinder



  • ich bekommen folgende fehlermeldung:

    Linking: Dateipfad 
     -Error: Unresloved External '_main' referenced from modul c0nt.ASM
    

    benutze diesen code hier:

    #include <stdio.h> 
    #include <conio.h> 
    #include <stdlib.h> 
    #include <windows.h> 
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
        { 
          struct test 
           { 
          int a; 
          int b; 
          int c; 
          }; 
    
      HWND hwnd = FindWindow("ConsoleWindowClass",NULL); 
    ShowWindow(hwnd,SW_HIDE); 
    
     struct test fu; 
       printf("Struct fu:\n"); 
       fu.a=101; 
        fu.b=102; 
       printf("%d\n%d\n",fu.a,fu.b); 
       struct test rudi; 
       printf("\nStruct rudi:\n"); 
       rudi.a=201; 
       rudi.b=202; 
       printf("%d\n%d",rudi.a,rudi.b); 
       getch(); 
       }
    

    bitte um rat

    C/C++ Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    struct test
    {
    int a;
    int b;
    int c;
    };

    HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
    ShowWindow(hwnd,SW_HIDE);

    struct test fu;
    printf("Struct fu:\n");
    fu.a=101;
    fu.b=102;
    printf("%d\n%d\n",fu.a,fu.b);
    struct test rudi;
    printf("\nStruct rudi:\n");
    rudi.a=201;
    rudi.b=202;
    printf("%d\n%d",rudi.a,rudi.b);
    getch();
    }
    C/C++ Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    struct test
    {
    int a;
    int b;
    int c;
    };

    HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
    ShowWindow(hwnd,SW_HIDE);

    struct test fu;
    printf("Struct fu:\n");
    fu.a=101;
    fu.b=102;
    printf("%d\n%d\n",fu.a,fu.b);
    struct test rudi;
    printf("\nStruct rudi:\n");
    rudi.a=201;
    rudi.b=202;
    printf("%d\n%d",rudi.a,rudi.b);
    getch();
    }

    es soll ein konsolenprogramm sein, das praktisch "unsichtbar" ist also im hintergrund läuft. es wäre sehr nett von euch wenn mir wer den lauffähigen code posten könnte. ich benutze einen borland compiler.

    Danke im v******Code:
    Linking: Dateipfad
    -Error: Unresloved External '_main' referenced from modul c0nt.ASM

    C/C++ Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    struct test
    {
    int a;
    int b;
    int c;
    };

    HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
    ShowWindow(hwnd,SW_HIDE);

    struct test fu;
    printf("Struct fu:\n");
    fu.a=101;
    fu.b=102;
    printf("%d\n%d\n",fu.a,fu.b);
    struct test rudi;
    printf("\nStruct rudi:\n");
    rudi.a=201;
    rudi.b=202;
    printf("%d\n%d",rudi.a,rudi.b);
    getch();
    }
    C/C++ Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>

    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    struct test
    {
    int a;
    int b;
    int c;
    };

    HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
    ShowWindow(hwnd,SW_HIDE);

    struct test fu;
    printf("Struct fu:\n");
    fu.a=101;
    fu.b=102;
    printf("%d\n%d\n",fu.a,fu.b);
    struct test rudi;
    printf("\nStruct rudi:\n");
    rudi.a=201;
    rudi.b=202;
    printf("%d\n%d",rudi.a,rudi.b);
    getch();
    }

    es soll ein konsolenprogramm sein, das praktisch "unsichtbar" ist also im hintergrund läuft. es wäre sehr nett von euch wenn mir wer den lauffähigen code posten könnte. ich benutze einen borland compiler.

    Danke im v******



  • ohh gott da hab ich wohl nen kleinen copy/paste fehler gemacht.

    ps: das prog das als code ausgegeben werden soll ist es.

    benutzte borland c++ 5.0.1 habe vorhin versucht mir bei borland den 5.5 zu saugen, der link scheint aber irgendwie "tot" zu sein



  • Das ist Code, der nicht für eine Konsolenanwendung geeignet ist. Deswegen hast du das Problem, dass er den Einstiegspunkt main() nicht findet.

    Lass einfach das ShowWindow(), etc. weg, passt doch. Erstell keine Konsolenanwendung sondern eine normale Windowsanwendung und benütz den selben Code.

    MfG SideWinder



  • ich wäre dir sehr verbunden wenn du mir einfach mal den code posten könntest, irgendwie bekomm ichs ned hin.



  • Das hat nichts mit dem Code zu tun, sondern mit dem Projekttyp 😉 Wenn du ein neues Projekt anlegst, wirst du irgendwo gefragt, ob du eine Konsolen-Anwendung, Windows-Anwendung, DLL ... anlegen willst. Dort wählst du einfach aus, daß du eine Windows-Anwendung haben willst.

    (der Typ bestimmt auch den Einstiegspunkt für das Programm: Konsolenprogramme beginnen mit "int main()", Windows-Programme mit der WinMain())

    PS: Was macht dein Programm eigentlich für einen Sinn, wenn du kein Konsolenfenster hast, in dem die Ausgaben zu sehen sind?


Anmelden zum Antworten