[RESOLVED] Message Box will not show on top of window
-
Hello people this is me again, I'm making a chat application program, that people can communicate over a computer network or V.P.N. (virtual private network) and when a user clicks the red close button a message box is suppose to show, but does not, here's the code:
#include #include "stdafx.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);/* Make the class name into a global variable */
= "netchat_ad";int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_MAINFRAME)); wincl.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_NETTYPE), IMAGE\_ICON, 16, 16, 0); 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 Windows's default colour as the background of the window \*/ wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND; /\* Register the window class, and if it fails 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 \*/ "netCommunication - \[NET: \]", /\* Title Text \*/ WS\_OVERLAPPED | WS\_CAPTION | WS\_SYSMENU | WS\_MINIMIZEBOX, /\* default window \*/ CW\_USEDEFAULT, /\* Windows decides the position \*/ CW\_USEDEFAULT, /\* where the window ends up on the screen \*/
-
Hello people this is me again, I'm making a chat application program, that people can communicate over a computer network or V.P.N. (virtual private network) and when a user clicks the red close button a message box is suppose to show, but does not, here's the code:
#include #include "stdafx.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);/* Make the class name into a global variable */
= "netchat_ad";int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_MAINFRAME)); wincl.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_NETTYPE), IMAGE\_ICON, 16, 16, 0); 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 Windows's default colour as the background of the window \*/ wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND; /\* Register the window class, and if it fails 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 \*/ "netCommunication - \[NET: \]", /\* Title Text \*/ WS\_OVERLAPPED | WS\_CAPTION | WS\_SYSMENU | WS\_MINIMIZEBOX, /\* default window \*/ CW\_USEDEFAULT, /\* Windows decides the position \*/ CW\_USEDEFAULT, /\* where the window ends up on the screen \*/
1. You should follow the call to
ShowWindow()
with a call toUpdateWindow()
, to get your controls drawn straight away. 2. YourWindowProcedure()
has a case for handling theWM_PAINT
message, so Windows thinks you are handling it even though you are not. If you remove that case* then yourMessageBox
will show up on its own. As a general rule you should not add case statements for messages that you ignore. As a simple test before changing your code, press the close button on your window and then press theAlt
key on your keyboard. *I have come across this before but have not tried to figure out exactly why it happens. There is probably someone who works or worked for Microsoft who knows the answer.One of these days I'm going to think of a really clever signature.
-
1. You should follow the call to
ShowWindow()
with a call toUpdateWindow()
, to get your controls drawn straight away. 2. YourWindowProcedure()
has a case for handling theWM_PAINT
message, so Windows thinks you are handling it even though you are not. If you remove that case* then yourMessageBox
will show up on its own. As a general rule you should not add case statements for messages that you ignore. As a simple test before changing your code, press the close button on your window and then press theAlt
key on your keyboard. *I have come across this before but have not tried to figure out exactly why it happens. There is probably someone who works or worked for Microsoft who knows the answer.One of these days I'm going to think of a really clever signature.
It works now, thank you (I removed the
WM_PAINT
system call code).Richard MacCutchan wrote:
As a simple test before changing your code, press the close button on your window and then press the
Alt
key on your keyboard.The message box appears (with the
WM_PAINT
).Richard MacCutchan wrote:
*I have come across this before but have not tried to figure out exactly why it happens. There is probably someone who works or worked for Microsoft who knows the answer.
That is weird, I should ask one, one of these days or maybe e-mail one.
Richard MacCutchan wrote:
There is probably someone who works or worked for Microsoft who knows the answer.
That could be anyone, you mean computer programmer or software developer.
Simple Thanks and Regards, Brandon T. H. Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst). Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
-
It works now, thank you (I removed the
WM_PAINT
system call code).Richard MacCutchan wrote:
As a simple test before changing your code, press the close button on your window and then press the
Alt
key on your keyboard.The message box appears (with the
WM_PAINT
).Richard MacCutchan wrote:
*I have come across this before but have not tried to figure out exactly why it happens. There is probably someone who works or worked for Microsoft who knows the answer.
That is weird, I should ask one, one of these days or maybe e-mail one.
Richard MacCutchan wrote:
There is probably someone who works or worked for Microsoft who knows the answer.
That could be anyone, you mean computer programmer or software developer.
Simple Thanks and Regards, Brandon T. H. Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst). Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
Brandon T. H. wrote:
The message box appears (with the
WM_PAINT
).I suspect that the issue is connected to the fact that your code was consuming the
WM_PAINT
message, so the system did not try to do anything connected with displaying your windows (including the message box).Brandon T. H. wrote:
you mean computer programmer or software developer.
Same thing.
One of these days I'm going to think of a really clever signature.
-
Brandon T. H. wrote:
The message box appears (with the
WM_PAINT
).I suspect that the issue is connected to the fact that your code was consuming the
WM_PAINT
message, so the system did not try to do anything connected with displaying your windows (including the message box).Brandon T. H. wrote:
you mean computer programmer or software developer.
Same thing.
One of these days I'm going to think of a really clever signature.
Richard MacCutchan wrote:
I suspect that the issue is connected to the fact that your code was consuming the
WM_PAINT
message, so the system did not try to do anything connected with displaying your windows (including the message box).I did, strangely, as soon as the main window popped up for my project, the window was blank (no controls, nothing on it), but when I go to re-size it and/or move it around, the controls appeared. But the message box did not, until you told me to press the
ALT
key.Simple Thanks and Regards, Brandon T. H. Programming in C and C++ now, now developing applications, services and drivers (and maybe some kernel modules...psst kernel-mode drivers...psst). Many of life's failures are people who did not realize how close they were to success when they gave up. - Thomas Edison
-
Hello people this is me again, I'm making a chat application program, that people can communicate over a computer network or V.P.N. (virtual private network) and when a user clicks the red close button a message box is suppose to show, but does not, here's the code:
#include #include "stdafx.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);/* Make the class name into a global variable */
= "netchat_ad";int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
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(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_MAINFRAME)); wincl.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR\_NETTYPE), IMAGE\_ICON, 16, 16, 0); 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 Windows's default colour as the background of the window \*/ wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND; /\* Register the window class, and if it fails 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 \*/ "netCommunication - \[NET: \]", /\* Title Text \*/ WS\_OVERLAPPED | WS\_CAPTION | WS\_SYSMENU | WS\_MINIMIZEBOX, /\* default window \*/ CW\_USEDEFAULT, /\* Windows decides the position \*/ CW\_USEDEFAULT, /\* where the window ends up on the screen \*/