473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Windows App - C++

Hi,

I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause?

Thank you in advance,
Anthony

#include <windows.h>
#include <string.h>

long WINAPI MainWndProc(HWND,UINT,WPARAM,LPARAM);

HWND hWnd;
HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton;
char szMessage[50] = "";

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);

hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);

hwndEdit = CreateWindow("EDIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hWnd,NULL,hInstance,NULL);

hwndButton = CreateWindow("BUTTON","Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,40,35,35,hWnd,NULL,hInstance,NULL);

hwndClearButton = CreateWindow("BUTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,40,35,35,hWnd,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);

MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}//end WinMain()

long WINAPI MainWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM
lParam)
{
HWND hwndCtl = (HWND)lParam;
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButton)
{
strcpy(szMessage,"This program is an overlapped style Window.");
SetWindowText(hwndEdit,szMessage);
}
else if(hwndCtl == hwndClearButton)
{
strcpy(szMessage,"");
SetWindowText(hwndEdit,szMessage);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}

return 0;
}//end MainWndProc()
Jul 22 '05 #1
32 2110
August1 wrote:
I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause? [...]


Somebody in a newsgroup dedicated to Windows programming undoubtedly
could. Here your question is off-topic. Please consider choosing
the newsgroup where to post more carefully.

V
Jul 22 '05 #2
> Somebody in a newsgroup dedicated to Windows programming undoubtedly
could. Here your question is off-topic. Please consider choosing
the newsgroup where to post more carefully.


The Windows API is mainly written in C. Windows applications can be
written in any number of source languages which then make calls to
your system's API - languages as VB, C++, J++, Foxpro, etc. Using C++
you may also use the Microsoft Foundation Classes to facilitate
communication with the API and program execution, though not
recommended for cross-platform functionality. The language I am
referencing is C++. The question is not off-topic. I have already
resolved the matter, but if you have nothing pertaining to code
assessment - I have no interest in your suggestion.

Regards
Jul 22 '05 #3

"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
Somebody in a newsgroup dedicated to Windows programming undoubtedly
could. Here your question is off-topic. Please consider choosing
the newsgroup where to post more carefully.


The Windows API is mainly written in C. Windows applications can be
written in any number of source languages which then make calls to
your system's API - languages as VB, C++, J++, Foxpro, etc. Using C++
you may also use the Microsoft Foundation Classes to facilitate
communication with the API and program execution, though not
recommended for cross-platform functionality. The language I am
referencing is C++. The question is not off-topic.


It is. If you want answers instead of abuse try

news:comp.os.ms-windows.programmer.win32

But if you just want to waste your time, post here!

john
Jul 22 '05 #4
The Windows API is mainly written in C. Windows applications can be
written in any number of source languages which then make calls to
your system's API - languages as VB, C++, J++, Foxpro, etc. Using C++
you may also use the Microsoft Foundation Classes to facilitate
communication with the API and program execution, though not
recommended for cross-platform functionality. The language I am
referencing is C++. The question is not off-topic. I have already
resolved the matter, but if you have nothing pertaining to code
assessment - I have no interest in your suggestion.

You misunderstand.

You'll hear no mention whatsoever of *any* platform here! We converse here
about what can actually be done with C++ itself and its Standard Libraries.
-JKop
Jul 22 '05 #5
an*********@hotmail.com (August1) writes:
Somebody in a newsgroup dedicated to Windows programming undoubtedly
could. Here your question is off-topic. Please consider choosing
the newsgroup where to post more carefully.
The Windows API is mainly written in C. Windows applications can be
written in any number of source languages which then make calls to
your system's API - languages as VB, C++, J++, Foxpro, etc. Using C++
you may also use the Microsoft Foundation Classes to facilitate
communication with the API and program execution, though not
recommended for cross-platform functionality.


All true. Irrelevent, but true.
The language I am referencing is C++. The question is not off-topic.


Oh but it is, just as asking an English teacher for help on your
microbiology homework probably won't be productive even though the
assignment is written in English.
--
% Randy Yates % "...the answer lies within your soul
%% Fuquay-Varina, NC % 'cause no one knows which side
%%% 919-577-9882 % the coin will fall."
%%%% <ya***@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #6
Mike Wahler posted:
"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
"> But if you just want to waste your time, post here!
>
> john


Depends on your perceptions. Next.


If you're expecting answers to Windows programming
questions here, be warned that you'll be waiting
a long time. The choice is yours.

-Mike

Not that long really. Here's an answer:
Fuck Off
-JKop
Jul 22 '05 #7
> All true. Irrelevent, but true.

Oh but it is, just as asking an English teacher for help on your
microbiology homework probably won't be productive even though the
assignment is written in English.


Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications. Many people today
prefer to use C++ for Windows apps, so they have a greater
understanding of the language and use it for more than console
applications. Therefore they wouldn't find it difficult to answer
console-related or gui-related questions should any be presented.

Regards
Jul 22 '05 #8
August1 posted:
All true. Irrelevent, but true.

Oh but it is, just as asking an English teacher for help on your
microbiology homework probably won't be productive even though the
assignment is written in English.
Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications.


Not really. I make Win32 Graphical User Interface programs, but I still find
all this irrelevant considering where we are.
Many people today
prefer to use C++ for Windows apps, so they have a greater
understanding of the language and use it for more than console
applications.
Bullshit.

If anything, coding for Windows will just mess up your C++ technique.

Case and point:

#define LRESULT long

Therefore they wouldn't find it difficult to answer
console-related or gui-related questions should any be presented.

Absolutely correct.

Where are we again?

-JKop
Jul 22 '05 #9
"August1" <an*********@hotmail.com> wrote in message
news:fc*************************@posting.google.co m...
All true. Irrelevent, but true.

Oh but it is, just as asking an English teacher for help on your
microbiology homework probably won't be productive even though the
assignment is written in English.


Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications. Many people today
prefer to use C++ for Windows apps, so they have a greater
understanding of the language and use it for more than console
applications. Therefore they wouldn't find it difficult to answer
console-related or gui-related questions should any be presented.


You're missing the point again. I'm fairly certain that
many people participating here have good or even expert
knowledge of e.g. GUI programming. They'd not find it
difficult at all to answer questions about it. But they
still don't do it here. Guess why.

John has already given you the name of the group where
your Windows questions will be welcomed with open arms.
If you go there, you'll even see his name, and articles
by him discussing Windows. But I now wonder if he'll
help you even there, given your behavior here.

Here is the "official" document defining the purpose
of comp.lang.c++:

http://www.slack.net/~shiva/welcome.txt

Please read it carefully before posting here again. Thank you.

-Mike
Jul 22 '05 #10

"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
"> But if you just want to waste your time, post here!

john


Depends on your perceptions. Next.


Next? Am I being insulted?

John
Jul 22 '05 #11
John Harrison wrote:
"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
"> But if you just want to waste your time, post here!
john


Depends on your perceptions. Next.

Next? Am I being insulted?


Do you feel insulted? Nobody can tell except you. :-)
Jul 22 '05 #12
Mike Wahler wrote:
[...]
Here is the "official" document defining the purpose
of comp.lang.c++:

http://www.slack.net/~shiva/welcome.txt

Please read it carefully before posting here again. Thank you.


Mike, I wish I had your patience. I hope you're not really
holding your breath that 'August1' will read the welcome msg.
I'd really be disappointed if you suffocate.
Jul 22 '05 #13
an*********@hotmail.com (August1) writes:
All true. Irrelevent, but true.

Oh but it is, just as asking an English teacher for help on your
microbiology homework probably won't be productive even though the
assignment is written in English.


Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications. Many people today
prefer to use C++ for Windows apps, so they have a greater
understanding of the language and use it for more than console
applications. Therefore they wouldn't find it difficult to answer
console-related or gui-related questions should any be presented.


Oh dear. I'm afraid I've thrown pearls before swine. I'm not sure
what number would be less, your IQ or number of years in school.
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
ra*********@sonyericsson.com, 919-472-1124
Jul 22 '05 #14
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:GD****************@newsread1.dllstx09.us.to.v erio.net...
Mike Wahler wrote:
[...]
Here is the "official" document defining the purpose
of comp.lang.c++:

http://www.slack.net/~shiva/welcome.txt

Please read it carefully before posting here again. Thank you.
Mike, I wish I had your patience.


It comes and goes. :-)
I hope you're not really
holding your breath that 'August1' will read the welcome msg.
Not really, but I decided I'd give him one last chance.
Nobody had posted that link in this thread yet. We'll see.
But I have indeed been glancing at my plonk button.
I'd really be disappointed if you suffocate.


Thanks for caring about me. :-)

-Mike
Jul 22 '05 #15
August1 wrote:
Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications. Many people today
prefer to use C++ for Windows apps, so they have a greater
understanding of the language and use it for more than console
applications. Therefore they wouldn't find it difficult to answer
console-related or gui-related questions should any be presented.


Oh, dear. Yet another newbie challenging the topicality protocols.

Why don't we all just discuss keyboard layouts while we're at it?

August1, only an elite minority are capable of answering technical
questions, on fora of _their_ choice, and you are danged lucky to have such
a wide selection of them. However, posting to the narrowest technical
newsgroup possible is

==> in your best interest. <==

If, for example, you post a Linux question to a Microsoft newsgroup, you
very well might get a good answer, and a hearty discussion. If you instead
post to a Linux newsgroup, the regulars there will _compete_ with each other
to provide the best answer. They will review each others' answers, provide
emmendments and additions, and generally aid the Linux cause.

Apologies on behalf of my e-siblings who can only phrase this in terms of
territory - "you are off-topic, so get lost". That's stimulating to write,
but hardly enfranchising to read. You yourself can also try to do better.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #16
"Phlip" <ph*******@yahoo.com> wrote in message
news:GZ*****************@newssvr17.news.prodigy.co m...

[excellent presentation of advantages of topicality]

Very well put. Kudos.

-Mike
Jul 22 '05 #17
August1 wrote:

Irrelevent only to those who find it irrelevent, or dedicate much of
their time in C/C++ with console applications.


You've been told that this is off-topic. Instead of acknowledging that
and apologizing, you argue. To what end? Do you think you'll
everybody's mind. Instead, what happens is this:
*plonk*


Brian
Jul 22 '05 #18
No point has been missed, no insults have been offered to anyone, no
exclamations have been added for emphasis to convey a conviction, no
profanity has been offered, no "misconduct" has been presented. i do
however find some of the responses interesting.

regards
Jul 22 '05 #19
August1 wrote:
No point has been missed, no insults have been offered to anyone, no
exclamations have been added for emphasis to convey a conviction, no
profanity has been offered, no "misconduct" has been presented. i do
however find some of the responses interesting.


Attempt to be gracious noted! Now answer questions about C++ here.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #20
* August1:

I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause?
Because you forgot to compile and run the program?

If you have any problems with compiling, ask in a compiler-specific
newsgroup.

If you have any problems getting the program to run, ask in a Windows-specific
newsgroup.
#include <windows.h>
For C++ always #define STRICT and NOMINMAX before this #include.

#include <string.h>
Preferentially use
#include <cstring>
long WINAPI MainWndProc(HWND,UINT,WPARAM,LPARAM);

HWND hWnd;
Don't use global variables.

HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton;
char szMessage[50] = "";
Here you're into buffer overflow territory; instead consider
std::string.
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
Check out your compiler's support for standard 'main'. g++ supports
that directly for Windows GUI application. Use standard 'main'.

WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);
A simpler way might be to use an initializer, "WNDCLASS wc = { ... };".

Anyway, to ensure all non-assigned fields are zero, declare it like
WNDCLASS wc = {0};

hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);

hwndEdit = CreateWindow("EDIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hWnd,NULL,hInstance,NULL);

hwndButton = CreateWindow("BUTTON","Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,40,35,35,hWnd,NULL,hInstance,NULL);

hwndClearButton = CreateWindow("BUTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,40,35,35,hWnd,NULL,hInstance,NULL);
Error checking might be a good idea... For example using a function

template< typename T >
inline void throwIf0( T const& x )
{
if( !x ) { throw std::runtime_error( "Ooops." ); }
}

Then

hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);
throwIf0( hWnd );

of course with a 'catch' somewhere.

ShowWindow(hWnd,nCmdShow);

MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
Here should be cast to the return type, i.e.
return static_cast<int>( msg.wParam );

}//end WinMain()
long WINAPI MainWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM
lParam)
{
HWND hwndCtl = (HWND)lParam;
Don't use C style casts.

In this case, use a reinterpret_cast or the appropriate system-specific
macro/function (off-topic hint: <windowsx.h>).

Anyway the logic is flawed: you don't yet have enough information to
say that this argument represents what you think it does. But it works.
With a bit of maintainance it will cease to work.

switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButton)
{
strcpy(szMessage,"This program is an overlapped style Window.");
Buffer overflow?

Indentation!

SetWindowText(hwndEdit,szMessage);
}
else if(hwndCtl == hwndClearButton)
{
strcpy(szMessage,"");
SetWindowText(hwndEdit,szMessage);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}

return 0;
Unreachable.
}//end MainWndProc()


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 22 '05 #21
Alf P. Steinbach wrote:
#include <windows.h>


For C++ always #define STRICT and NOMINMAX before this #include.


And WIN32_LEAN_AND_MEAN!
#include <string.h>


Preferentially use

#include <cstring>


James Kanze points out don't use the C++-style C Library Headers unless you
really really mean it. Right now, in our legacy-code besotted world,
<cstring> is a portability dead spot, and <string.h> is everywhere you need
to be.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #22
> You've been told that this is off-topic. Instead of acknowledging that
and apologizing, you argue. To what end? Do you think you'll
everybody's mind. Instead, what happens is this:
*plonk*


I've not laughed so heartily in about 1 month. Thanks to all.
regards
Jul 22 '05 #23
August1 wrote:
Hi,

I'm beginning to approach Windows programming in C++. I've written
a short
application which is to do nothing more than demonstrate the Window
style being used. The child windows are not appearing within the
parent window. Could someone point out the cause?

I am using .NET so I do not know these Win32 stuff. In any case,
comp.lang.c++ is about talking ISO C++, that is the pure C++ language as
defined by the ISO C++ standard.

For questions about the trillions of system specific applications of
C++, one should post the relevant newsgroups.

For example there are MS newsgroups for MS platform programming and in
particular MS provides a free newsgroup server
msnews.microsoft.com
with all the newsgroups regarding their platforms.
Just configure your newsgroup reader to access that server and find the
relevant newsgroups.
Also there are some of those MS newsgroups, and other non-MS newsgroups
about Win32 available in Usenet (Usenet is where you found this
newsgroup), just search for newsgroups with the word Win32 in your
newsgroup client.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #24
August1 wrote:

[Something that calls itself Default User wrote:]
You've been told that this is off-topic.
Instead of acknowledging that and apologizing, you argue. To what end?
Do you think you'll [change] everybody's mind.
Instead, what happens is this:

*plonk*


I've not laughed so heartily in about 1 month. Thanks to all.
regards


Please ignore our trolls.
They seem to think that it's fun to ambush new subscribers.

The comp.lang.c++ newsgroup is a good place to get bad advice
about Windows specific programming.
I hope the you found the redirection to more appropriate forums helpful.

Please come back to us
when you have specific questions about standard C++.
Jul 22 '05 #25
> Because you forgot to compile and run the program?

If you have any problems with compiling, ask in a compiler-specific
newsgroup.

If you have any problems getting the program to run, ask in a Windows-specific
newsgroup.
#include <windows.h>


For C++ always #define STRICT and NOMINMAX before this #include.

#include <string.h>


Preferentially use
#include <cstring>
long WINAPI MainWndProc(HWND,UINT,WPARAM,LPARAM);

HWND hWnd;


Don't use global variables.

HWND hwndEdit;
HWND hwndButton;
HWND hwndClearButton;
char szMessage[50] = "";


Here you're into buffer overflow territory; instead consider
std::string.
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{


Check out your compiler's support for standard 'main'. g++ supports
that directly for Windows GUI application. Use standard 'main'.

WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);


A simpler way might be to use an initializer, "WNDCLASS wc = { ... };".

Anyway, to ensure all non-assigned fields are zero, declare it like
WNDCLASS wc = {0};

hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);

hwndEdit = CreateWindow("EDIT",NULL,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
10,10,155,20,hWnd,NULL,hInstance,NULL);

hwndButton = CreateWindow("BUTTON","Message",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,40,35,35,hWnd,NULL,hInstance,NULL);

hwndClearButton = CreateWindow("BUTTON","Clear",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
50,40,35,35,hWnd,NULL,hInstance,NULL);


Error checking might be a good idea... For example using a function

template< typename T >
inline void throwIf0( T const& x )
{
if( !x ) { throw std::runtime_error( "Ooops." ); }
}

Then

hWnd = CreateWindow("Style1","Border Demonstration",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
185,265,NULL,NULL,hInstance,NULL);
throwIf0( hWnd );

of course with a 'catch' somewhere.

ShowWindow(hWnd,nCmdShow);

MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;


Here should be cast to the return type, i.e.
return static_cast<int>( msg.wParam );

}//end WinMain()


long WINAPI MainWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM
lParam)
{
HWND hwndCtl = (HWND)lParam;


Don't use C style casts.

In this case, use a reinterpret_cast or the appropriate system-specific
macro/function (off-topic hint: <windowsx.h>).

Anyway the logic is flawed: you don't yet have enough information to
say that this argument represents what you think it does. But it works.
With a bit of maintainance it will cease to work.

switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BN_CLICKED:
if(hwndCtl == hwndButton)
{
strcpy(szMessage,"This program is an overlapped style Window.");


Buffer overflow?

Indentation!

SetWindowText(hwndEdit,szMessage);
}
else if(hwndCtl == hwndClearButton)
{
strcpy(szMessage,"");
SetWindowText(hwndEdit,szMessage);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}

return 0;


Unreachable.
}//end MainWndProc()


hello alf,

thank you for your substantive and even-tempered contribution. the
problem appears to have been resolved prior to any replies. i am also
reviewing the specific suggestions you've presented (code-related) for
subsequent use. very relevant.

regards
Jul 22 '05 #26
> Attempt to be gracious noted!
you have certainly misunderstood and presumed many things if you think
that i'm attempting to be gracious.
Jul 22 '05 #27

"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
Attempt to be gracious noted!

you have certainly misunderstood and presumed many things if you think
that i'm attempting to be gracious.


I'm curious what will you do the next time you get a Windows programming
problem? Will you post it here or will you try the other newsgroup I
suggested? Or will you take it somewhere completely different?

I must agree, I didn't think your last post demonstrated any graciousness
either. Phlip was being most presumptuous. My presumption is that you are
one of those people whose vanity or arrogance prevents you from ever
admitting that you've made a mistake.

john
Jul 22 '05 #28
"John Harrison" <jo*************@hotmail.com> writes:
"August1" <an*********@hotmail.com> wrote in message
news:fc**************************@posting.google.c om...
> Attempt to be gracious noted!

you have certainly misunderstood and presumed many things if you think
that i'm attempting to be gracious.


I'm curious what will you do the next time you get a Windows programming
problem? Will you post it here or will you try the other newsgroup I
suggested? Or will you take it somewhere completely different?

I must agree, I didn't think your last post demonstrated any graciousness
either. Phlip was being most presumptuous. My presumption is that you are
one of those people whose vanity or arrogance prevents you from ever
admitting that you've made a mistake.

john


To be brutally honest, John, I think he (or she) is just stupid. No use
reasoning with a moron.
--
% Randy Yates % "My Shangri-la has gone away, fading like
%% Fuquay-Varina, NC % the Beatles on 'Hey Jude'"
%%% 919-577-9882 %
%%%% <ya***@ieee.org> % 'Shangri-La', *A New World Record*, ELO
http://home.earthlink.net/~yatescr
Jul 22 '05 #29
On Wed, 20 Oct 2004 00:13:59 GMT, al***@start.no (Alf P. Steinbach) wrote:
long WINAPI MainWndProc(HWND,UINT,WPARAM,LPARAM);

HWND hWnd;
Don't use global variables.


You might want to suggest an alternative, such as recommending either a
vector for storing HWNDs, a singleton class, or a function that returns a
constant reference to the variable. Alternativly, you could recommend that
the variable be renamed (as it conflicts or is confused with standard
naming conventions with these callback functions) and placed within it's
minimal scope.

There might be cases where variables actually need to be global. For
example, copy protection module might want to give direct global read
access to a set of variables containing a registration key to make it
slightly harder for crackers to disable a centralized copy protection
function. However, this does have a disadvantage of both redundant code and
bugs that appear in the remote functions, but the decision is up to the
designer.
WNDCLASS wc;
wc.lpszClassName = "Style1";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
wc.lpszMenuName = "";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass(&wc);


A simpler way might be to use an initializer, "WNDCLASS wc = { ... };".


This requires actually looking at the header file to see which order the
values are assigned. I've seen structures like this before - it's
generally more readable when assigning each member by name, and less prone
to transposition errors. (e.g. switching around fields lpszMenuName and
lpszClassName).

Anyway, to ensure all non-assigned fields are zero, declare it like
WNDCLASS wc = {0};


While you could use that method of using a "clean" structure, it's better
to assign the fields individually to see if "you missed something". While
this not normally be critical, a bug involving core windows messages or
window classes can potentially mess up the system.

It may be a bit better to instead call a function that fills in suitable
default values for the Window Class (with parameters to address the most
common changes), and to make changes as necessairy.
Jul 22 '05 #30
E. Robert Tisdale wrote:
Please ignore our trolls.
They seem to think that it's fun to ambush new subscribers.

I see you still haven't figured out how to use your own killfile there
Trollsdale.


Brian
Jul 22 '05 #31
Phlip <ph*******@yahoo.com> spoke thus:
August1, only an elite minority are capable of answering technical
questions, on fora of _their_ choice, and you are danged lucky to have such
a wide selection of them. However, posting to the narrowest technical
newsgroup possible is ==> in your best interest. <== If, for example, you post a Linux question to a Microsoft newsgroup, you
very well might get a good answer, and a hearty discussion. If you instead
post to a Linux newsgroup, the regulars there will _compete_ with each other
to provide the best answer. They will review each others' answers, provide
emmendments and additions, and generally aid the Linux cause.


This text would be an excellent addition to the welcome messages I and
others link to from time to time (if the maintainers of those
messages are listening to my humble opinion, of course).

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #32
> I'm curious what will you do the next time you get a Windows programming
problem? Will you post it here or will you try the other newsgroup I
suggested? Or will you take it somewhere completely different?

I must agree, I didn't think your last post demonstrated any graciousness
either. Phlip was being most presumptuous. My presumption is that you are
one of those people whose vanity or arrogance prevents you from ever
admitting that you've made a mistake.

john


I don't give it much consideration because there are simply too many
resources to derive from, a newsgroup is an infrequent selection, and
your presumption is misguided however well-intended. If the posts are
reviewed, it could be suggested that the latter characterizations
you've offered pertain to others.

regards
Jul 22 '05 #33

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.