[C/C++] programmaatje voor windows

Pagina: 1
Acties:

  • Zynth
  • Registratie: September 2001
  • Laatst online: 29-07 15:30
Ik wil voor het eerst een programmaatje schrijven voor windows.
Dit proggie hoeft alleen maar een messagebox te geven.
Deze code had ik eerst:
---------
#include <stdio.h>
#include <windows.h>

int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
MessageBox (NULL, "You've got mail !" , "Fetchit Message", 0 + MB_ICONASTERISK);
}

-----------

Ik krijg wél netjes de messagebox op mijn scherm,
maar het probleem is, dat windows daarachter een command-prompt venster opent!
En dat is niet de bedoeling!
Hoe kan ik ervoor zorgen dat windows geen command-prompt geeft als ik dit programma wil uitvoeren?
(oftewel, wat zit er fout in mijn code)

thnx!

(btw, het meeste v/d code was gegenereerd door Dev-C++)

Verwijderd

Je maakt een "console" applicatie, daar komt dat venster vandaar, je moet dus geen console applicatie maken.

  • Zynth
  • Registratie: September 2001
  • Laatst online: 29-07 15:30
hmz...
als ik een windows-applicatie aanmaak,
dan krijg ik een scherm vol met wazige code ;-)
als ik die compile, dan krijg ik een leeg windows-venstertje.
Maar ik wil alléén maar een windows-diaglo-boxje!

Als ik de functie-aanroep eruitsloop, die dat windows-venster aanroept, en die messagebox toevoeg,
dan doettie helemaal nix.

Heeft iemand misschien een voorbeeld van een standaard main-functie, waarmee ik voor windows kan programmeren, zonder allemaal onzin die ik toch niet nodig heb?

thnx!

Verwijderd

Dat het voor jou "wazig" is hoeft niet in te houden dat je het niet nodig hebt hoor :) wat voor code spuugt ie standaard uit?

  • Zynth
  • Registratie: September 2001
  • Laatst online: 29-07 15:30
Dit spuugt'ie standaard uit :-)

--------------------------------
#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 light-gray as the background of the window */
wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);

/* Register the window class, if fail quit the program */
if(!RegisterClassEx(&wincl)) return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx(
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* 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;
}

--------------------

duzzz ;-)

Verwijderd

Tamelijk standaard win32 proggie wat ie uitkakt eigenlijk,kijk ff rond wat het allemaal doet en wen er aan want je gaat dit nog vaaaaaaak zien als je win32 blijft coden ;)

ps. volgende keer even [ code] en [ /code] om je source heen zetten (zonder die spatie natuurlijk)

  • Zynth
  • Registratie: September 2001
  • Laatst online: 29-07 15:30
thnx! :-)

hmz... tja, het enige wat ik eigenlijk wil is dat hij gewoon zijn bibliotheken openstelt voor mij; zonder dattie zelf een venster bouwt enzow ;-)

  • drZymo
  • Registratie: Augustus 2000
  • Laatst online: 09-08 22:22
Op zondag 18 november 2001 00:14 schreef Zynth het volgende:
thnx! :-)

hmz... tja, het enige wat ik eigenlijk wil is dat hij gewoon zijn bibliotheken openstelt voor mij; zonder dattie zelf een venster bouwt enzow ;-)
edit:
Oops beter lezen :O


Uhm ik raad je aan de compiler eens goed door te nemen. Waarschijnlijk is er een flag (iets van /tWin32 ofzo) om zo je proggel te compilen naar windows programma ipv een console programma. Dan zou het wel moeten werken.

Anders raad ik je Visual C++ aan >:)

"There are three stages in scientific discovery: first, people deny that it is true; then they deny that it is important; finally they credit the wrong person."


Verwijderd

Je probeert nu een programma te maken dat ALLEEN een dialog-box op het scherm geeft. Dacht dat dat niet kon.
Wel kun je je alleen een form laten zien (die je er dan uit laat zien als een dialog..)

Hebben dialog-boxen ook ouders nodig?

  • drZymo
  • Registratie: Augustus 2000
  • Laatst online: 09-08 22:22
Op zondag 18 november 2001 13:25 schreef robh het volgende:
Je probeert nu een programma te maken dat ALLEEN een dialog-box op het scherm geeft. Dacht dat dat niet kon.
Wel kun je je alleen een form laten zien (die je er dan uit laat zien als een dialog..)

Hebben dialog-boxen ook ouders nodig?
nee dat werkt wel hoor. Der zijn zat voorbeeldjes van programma's die een dialog box gebruikten ipv een form.

"There are three stages in scientific discovery: first, people deny that it is true; then they deny that it is important; finally they credit the wrong person."

Pagina: 1