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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Buggy window behavior?

Buggy window behavior?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 5 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.
  • J Offline
    J Offline
    Jerry Hammond
    wrote on last edited by
    #1

    Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

    A C M J N 5 Replies Last reply
    0
    • J Jerry Hammond

      Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

      A Offline
      A Offline
      alex barylski
      wrote on last edited by
      #2

      Everything looks prety good to me :) Maybe try commenting out DefWindowProc() and compiling...see what happens The word of the day is legs, let's go back to my house and spread the word ;P

      1 Reply Last reply
      0
      • J Jerry Hammond

        Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

        C Offline
        C Offline
        Chris Richardson
        wrote on last edited by
        #3

        I'm pretty sure you need to add the following code to your WM_PAINT case:

             PAINTSTRUCT a\_stPaint;
             BeginPaint( hWnd, &a\_stPaint );
             
             // Do your painting here.
             
             EndPaint( hWnd, &a\_stPaint );
        

        It's been a while since I did raw Win32, so I'm not certain. Chris Richardson

        1 Reply Last reply
        0
        • J Jerry Hammond

          Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

          M Offline
          M Offline
          Monty2
          wrote on last edited by
          #4

          in WM_CREATE and WM_PAINT ... don't return 0 do a break; and call DefwindowProc might help Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

          1 Reply Last reply
          0
          • J Jerry Hammond

            Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

            J Offline
            J Offline
            Jerry Hammond
            wrote on last edited by
            #5

            This gets weirder and weirder. I created a new solution (workspace). Copy&pasted the code into a new .cpp file, compile and executed and all worked just fine. Can we say, "things that make you go hmmm?" Thanks for all the suggestions and help. Best, Jerry

            The only way of discovering the limits of the possible is to venture a little past them into the impossible.--Arthur C. Clark

            Toasty0.com

            1 Reply Last reply
            0
            • J Jerry Hammond

              Using one of the teach-yourself-you-dummie books I entered the following code to creat a window. It compiles just fine, without error or warning. But once I execute it my CPU usage pegs at 100%, the small Icon does not render, and clicking the close button fails to close the window. //Standard wondows include #include //Message Loop CallBack Function Prototype LRESULT CALLBACK fnMessageProcessor (HWND, UINT, WPARAM, LPARAM); //Function called automatically when the program starts int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; //Set up window class wndclass.cbSize =sizeof(WNDCLASSEX); wndclass.style =CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc =fnMessageProcessor; 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 (GRAY_BRUSH); wndclass.lpszMenuName=NULL; wndclass.lpszClassName="Window Class"; //Class Name wndclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION); //Register the window class if(RegisterClassEx(&wndclass)==0) { //the program failed, exit exit(1); } //Create the window hWnd=CreateWindowEx( WS_EX_OVERLAPPEDWINDOW, "Window Class", //Class Name "Create Window Example", //Title bar text WS_OVERLAPPEDWINDOW, 0, 0, 400, 600, NULL, NULL, hInstance, NULL); //Display Window ShowWindow(hWnd, iCmdShow); //Process Messages until program is terminated while(GetMessage (&msg,NULL,0,0)); { TranslateMessage(&msg); DispatchMessage(&msg); } return (msg.wParam); } //Message loop callBack function (Required for all windows programs) LRESULT CALLBACK fnMessageProcessor(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch(iMsg) { //Called when window is first created case WM_CREATE: return(0); //Called when window is refreshed case WM_PAINT: return(0); //Called when the user closes the window case WM_DESTROY: PostQuitMessage(0); return(0); default: return DefWindowProc(hWnd, iMsg, wParam, lParam); } } Do any of you have any observations about the code and or any suggestion to overcome this buggy behavior? Thanks all. Best, Jerry

              N Offline
              N Offline
              nema32
              wrote on last edited by
              #6

              TranslateMessage() and DispatchMessage() are never getting called. Why? Because your while loop does nothing thanks to the common error of an extra semicolon. Your message pump is effectively: while (GetMessage(&msg, NULL, 0, 0)) ;

              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