Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

NOT GIVING THE REQUIRED OUTPUT

bodhi2016bodhi2016 Member Posts: 50
Iknow c++ .Now i am trying to learn win32 api programming usiing c++ from the book programming windows by charles petzold.I have The e-book .there was a code and i copied and pasted in the complier to see the output.THE CODE IS GIVEN BELOW.THE WHOLE BOOK IS IN C BUT I AM COMPILING THE CODE AS C++.THE OUTPUT IS SUPPOSEDTO COME A WHITE WINDOW WITH "HELLOWINDOWS " WRITTEN IN THE MIDDLE WITH SOME SOUND .BUT THE OUTPUT I AM RECEIVING IS A SMALL DIALOG BOX
WITH CROSS SIGN AT THE LEFT HAND SIDE AND THEN WRITTEN "HELLO WINDOWS 98".POINT OUT THE MISTAKE
HELLOWIN.C

/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/

#include

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 = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
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
TEXT ("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 (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ;

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) ;
return 0 ;

case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
By the way i forgot to tell that i am using Dev c++.I am not getting errors but the output is not is not as told in the book.Can anybody tel me some other book in which the code are also in c++ for learning win32 api

Comments

  • LundinLundin Member Posts: 3,711
    I don't think there is an error. When you are using CW_USEDEFAULT, you tell Windows that you don't care about the size of the window. Try the following and you should get a small window (depending on screen resolution):

    hwnd = CreateWindow (szAppName, // window class name
    TEXT ("The Hello Program"), // window caption
    WS_OVERLAPPEDWINDOW, // window style
    CW_USEDEFAULT, // initial x position
    CW_USEDEFAULT, // initial y position
    300, // initial x size
    300, // initial y size
    NULL, // parent window handle
    NULL, // window menu handle
    hInstance, // program instance handle
    NULL) ; // creation parameters
  • carlycarly Member Posts: 46
    : Iknow c++ .Now i am trying to learn win32 api programming usiing
    : c++ from the book programming windows by charles petzold.I have The
    : e-book .there was a code and i copied and pasted in the complier to
    : see the output.

    ask on win32 api newsgroup for details :
    news://nntp.aioe.org/comp.os.ms-windows.programmer.win32
  • LundinLundin Member Posts: 3,711
    : ask on win32 api newsgroup for details

    ...or simply ask here at Programmer's Heaven. :-)
  • carlycarly Member Posts: 46
    : : ask on win32 api newsgroup for details
    :
    : ...or simply ask here at Programmer's Heaven. :-)
    :

    No, as Usenet exists for 29 years, 100% of win32 api questions are answered...
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [color=Blue]Try to comment out the "PlaySound ..." line and see what happens. It may be some issue with Multimedia API on your system.[/color]
  • MT2002MT2002 Member Posts: 1,444
    : Iknow c++ .

    No one can ever completely learn C++. You will see what I mean...

    : Now i am trying to learn win32 api programming usiing
    : c++ from the book programming windows by charles petzold.

    That is a great book for learning Win32 programming.

    : I have The
    : e-book .there was a code and i copied and pasted in the complier to
    : see the output.THE CODE IS GIVEN BELOW.THE WHOLE BOOK IS IN C BUT I
    : AM COMPILING THE CODE AS C++.THE OUTPUT IS SUPPOSEDTO COME A WHITE
    : WINDOW WITH "HELLOWINDOWS " WRITTEN IN THE MIDDLE WITH SOME SOUND
    : .BUT THE OUTPUT I AM RECEIVING IS A SMALL DIALOG BOX
    : WITH CROSS SIGN AT THE LEFT HAND SIDE AND THEN WRITTEN "HELLO
    : WINDOWS 98".POINT OUT THE MISTAKE

    A few things about your post:

    > Please use paragraphs. They increase readability alot.
    > Please do not forget to turn off the capslock. Typing text in all caps usually represents "yelling". And ending it with "POINT OUT THE MISTAKE" sounds like an order as if we have to do it, without any "please" or "thank you".
    > Please use code tags.

    The code you posted looks fine. Try to describe your problem more clearly and detailed. What exactally is your code doing that is different then the books?

    By your description, it sounds like your code is outputting a message box rather then a window. However, because you have no message box at all within your code, I suspect you are simply building the wrong project, as it is impossible for your code (in its current state) to do this.

    : By the way i forgot to tell that i am using Dev c++.I am not getting
    : errors but the output is not is not as told in the book.Can anybody
    : tel me some other book in which the code are also in c++ for
    : learning win32 api

    Your book is one of the most recommended for learning the Win32 API. I personally recommend sticking with it.

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.brokenthorn.com]Website :: OS Development Series[rightbr][/link][/size]
Sign In or Register to comment.