Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2003, 07:52 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default making windows

Please explain why in the world these won't work:

window header file

//Diablo Trainer
//Window
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
class Diablo //This declares the class for the window
{
private: //These are the variables/functions that only this class can use!
HINSTANCE hInst;
WNDCLASSEX DiableWndCls;
HWND hWnd;
public: //These are the variables/functions that all classes can use!
Diablo (HINSTANCE hIns); /* a constructer */
void show(void); /* shows the window */
}

window .cpp file

#include <windows.h>
#include "diablo(window).h" //always include the header(.h) file made for the window
Diablo::Diablo(INSTANCE hIns)
{
hIns=hIns;

DiabloWndCls.cbSize=sizeof (WNDCLASSEX);
DiabloWndCls..style=NULL;
DiabloWndCls.lpfnWndProc=WndProc;
DiabloWndCls.cbClsExtra=0;
DiabloWndCls.cbWndExtra=0;
DiabloWndCls.hInstance=hInst;
DiabloWndCls.hIcon=LoadIcon(NULL,IDA_APPLICATION);
DiabloWndCls.hCursor=LoadCursor(NULL, IDC_ARROW);
DiabloWndCls.hbrBackground=(HBRUSH)(COLOR_WINDOW);
DiabloWndCls.lpszMenuName=NULL;
DiabloWndCls.lpszClassName="DiabloClass";
DiabloWndCls.hIconSm=LadIcon(NULL, IDA_APPLICATION);

if(!RegisterClassEx(&DiabloWndCls))
{
MessageBox(NULL, "Grrrr!\nStupid Computer Couldn't Register Window Class!", "ERROR",MB_OK|MB_ICONERROR);
}
hWnd=CreateWindowEx(WS_EX_APPWINDOW, "DiabloClass", "Diablo 1.09 Trianer", WS_OVERLAPPEDWINDOW, 0, 0, 300, 400, NULL, NULL, hInst, NULL);
if(hWnd==NULL)
{
MessageBox(NULL, "Couldn't Create Window! :(", "ERROR", MB_OK|MB_ICONERROR);
}
}
void Diablo::Show(void)
{
ShowWindow(hWnd, SH_SHOW);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
MSG Msg:
Diablo mainWindow(hInst);
mainWindow.show(0;
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
DestoryWindow(hWnd);
break;
case WM_DESTORY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

 
Old August 31st, 2003, 12:14 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It won't work because you have too many typos in the source, to begin with!

>> #include "diablo(window).h"
#include "diablo.h"

>> Diablo::Diablo(INSTANCE hIns)
>> {
>> hIns=hIns;


Diablo::Diablo(HINSTANCE hIns)
{
 hIns=hInst;

>> DiabloWndCls..style=NULL;

DiabloWndCls.style=NULL;

But then again, you declared it as:

WNDCLASSEX DiableWndCls;

>> mainWindow.show(0;

mainWindow.show(0);

>> void show(void); // take no parameter here!


I'm going to stop there.

>> "Grrrr!\nStupid Computer Couldn't Register Window Class!"

change to:

"Grrrr!\nI'm too impatient to program - what's the point?"

Perhaps you should slow down a bit and do things one step at a time. I know that programming can be frustrating, but remember that impatience will only make things more difficult. So grab a *big* cup of coffee, roll up your sleeves, and get to work!





"The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." - Donald Knuth
 
Old September 1st, 2003, 02:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Hi Stuby085,

What you are doing here is just not acceptable in
programming. You simply can’t afford to be this
careless while writing the code and these are
simple syntactical mistakes in your elementary level
program we are talking about as Sebastiani
pointed out.

Also the amount of uncertainty about the
problem that reflects in your query indicates
that you have a long way to go before you would
comfortably be able to write such programs.
If you are declaring a function with the name
Show and later you are calling show than you are
simply not calling the function you declared.
This is too simple a thing to be explained at
this level. If you knew what MSG, HINSTANCE etc.
are you couldnt have made such mistakes.

Having said that, one of the programmers
here was kind enough to correct your code.

Here it is..

//window header file

//Diablo Trainer
//Window
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

class Diablo //This declares the class for the window
{
private: //These are the variables/functions that only this class can use!
    HINSTANCE hInst;
    WNDCLASSEX DiabloWndCls;
    HWND hWnd;

public: //These are the variables/functions that all classes can use!
    Diablo (HINSTANCE hIns); /* a constructer */
    void Show(void); /* shows the window */
};













//window .cpp file

#include <windows.h>
#include "Diablo.h" //always include the header(.h) file made for the window
#include "resource.h"

Diablo::Diablo(HINSTANCE hIns)
{
    hIns=hIns;

    DiabloWndCls.cbSize=sizeof (WNDCLASSEX);
    DiabloWndCls.style=NULL;
    DiabloWndCls.lpfnWndProc=WndProc;
    DiabloWndCls.cbClsExtra=0;
    DiabloWndCls.cbWndExtra=0;
    DiabloWndCls.hInstance=hInst;
    DiabloWndCls.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(I DA_APPLICATION));
    DiabloWndCls.hCursor=LoadCursor(NULL, IDC_ARROW);
    DiabloWndCls.hbrBackground=(HBRUSH)(COLOR_WINDOW);
    DiabloWndCls.lpszMenuName=NULL;
    DiabloWndCls.lpszClassName="DiabloClass";
    DiabloWndCls.hIconSm=LoadIcon(NULL, MAKEINTRESOURCE(IDA_APPLICATION));

    if(!RegisterClassEx(&DiabloWndCls))
    {
        MessageBox(NULL, "Grrrr!\nStupid Computer Couldn't Register Window Class!", "ERROR",MB_OK|MB_ICONERROR);
    }

    hWnd=CreateWindowEx(WS_EX_APPWINDOW, "DiabloClass", "Diablo 1.09 Trianer", WS_OVERLAPPEDWINDOW, 0, 0, 300, 400, NULL, NULL, hInst, NULL);
    if(hWnd==NULL)
    {
        MessageBox(NULL, "Couldn't Create Window! :(", "ERROR", MB_OK| MB_ICONERROR);
    }
}

void Diablo::Show(void)
{
    ShowWindow(hWnd, SW_SHOW);
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
    MSG Msg;
    Diablo mainWindow(hInst);
    mainWindow.Show();
    while(GetMessage(&Msg, NULL, 0, 0))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_CLOSE:
            ::DestroyWindow(hWnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

The code requires you to create an ICON with name
IDA_APPLICATION in you project.



Regards

Ankur Verma
.Net and C++ Specialist
Wiley Tech Support





Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a webjukebox jerryjet Flash (all versions) 1 February 17th, 2008 01:20 AM
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
making the right choices? spacky001 C# 5 November 29th, 2005 05:53 AM
Windows 98 OCX control issues vs Windows XP benoyraj VB How-To 0 May 5th, 2004 08:10 AM
making calculator help bcmaverik VB.NET 2002/2003 Basics 7 January 6th, 2004 11:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.