Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [RESOLVED] Message Box will not show on top of window

[RESOLVED] Message Box will not show on top of window

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminlounge
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brandon X12000
    wrote on last edited by
    #1

    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 \*/
    
    L A 2 Replies Last reply
    0
    • B Brandon X12000

      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 \*/
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      1. You should follow the call to ShowWindow() with a call to UpdateWindow(), to get your controls drawn straight away. 2. Your WindowProcedure() has a case for handling the WM_PAINT message, so Windows thinks you are handling it even though you are not. If you remove that case* then your MessageBox 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 the Alt 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.

      B 1 Reply Last reply
      0
      • L Lost User

        1. You should follow the call to ShowWindow() with a call to UpdateWindow(), to get your controls drawn straight away. 2. Your WindowProcedure() has a case for handling the WM_PAINT message, so Windows thinks you are handling it even though you are not. If you remove that case* then your MessageBox 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 the Alt 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.

        B Offline
        B Offline
        Brandon X12000
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • B Brandon X12000

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          B 1 Reply Last reply
          0
          • L Lost User

            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.

            B Offline
            B Offline
            Brandon X12000
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • B Brandon X12000

              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 \*/
              
              A Offline
              A Offline
              Arun S J
              wrote on last edited by
              #6

              MB_APPLMODAL is used as the type flag combination

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups