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. CreateWindow

CreateWindow

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 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.
  • C Offline
    C Offline
    confalonieri
    wrote on last edited by
    #1

    Hi, In my application I need to create an empty window just to receive messages and treat them. I wrote the following code: HINSTANCE hApi = (HINSTANCE) GetModuleHandle(NULL); if (! hApi) ...// manage error CHAR * WindowClassName = "MyWindowClass"; WNDCLASS WindowClassInfo; if (! GetClassInfo(hApi, WindowClassName, &WindowClassInfo)) { WindowClassInfo.hCursor = NULL; WindowClassInfo.hIcon = NULL; WindowClassInfo.lpszMenuName = NULL; WindowClassInfo.lpszClassName = WindowClassName; WindowClassInfo.hbrBackground = NULL; WindowClassInfo.hInstance = hApi; WindowClassInfo.style = CS_OWNDC | CS_VREDRAW | S_HREDRAW; WindowClassInfo.lpfnWndProc = (WNDPROC) MyProc; WindowClassInfo.cbClsExtra = 0; WindowClassInfo.cbWndExtra = 0; if (! RegisterClass(&WindowClassInfo)) ...//manage error } HWND hWnd = CreateWindow(WindowClassName, "MyWindow", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hApi, NULL); if (! hWnd) ...//manage error But, unfortunately, CreateWindow return NULL and GetLastError return 0 !!! Did anybody could help me ? Thanks in advance. Robin.

    J E 2 Replies Last reply
    0
    • C confalonieri

      Hi, In my application I need to create an empty window just to receive messages and treat them. I wrote the following code: HINSTANCE hApi = (HINSTANCE) GetModuleHandle(NULL); if (! hApi) ...// manage error CHAR * WindowClassName = "MyWindowClass"; WNDCLASS WindowClassInfo; if (! GetClassInfo(hApi, WindowClassName, &WindowClassInfo)) { WindowClassInfo.hCursor = NULL; WindowClassInfo.hIcon = NULL; WindowClassInfo.lpszMenuName = NULL; WindowClassInfo.lpszClassName = WindowClassName; WindowClassInfo.hbrBackground = NULL; WindowClassInfo.hInstance = hApi; WindowClassInfo.style = CS_OWNDC | CS_VREDRAW | S_HREDRAW; WindowClassInfo.lpfnWndProc = (WNDPROC) MyProc; WindowClassInfo.cbClsExtra = 0; WindowClassInfo.cbWndExtra = 0; if (! RegisterClass(&WindowClassInfo)) ...//manage error } HWND hWnd = CreateWindow(WindowClassName, "MyWindow", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hApi, NULL); if (! hWnd) ...//manage error But, unfortunately, CreateWindow return NULL and GetLastError return 0 !!! Did anybody could help me ? Thanks in advance. Robin.

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Everything seems OK. The only possible problem I can think of is that MyProc is not properly declared as a WINDPROC should. Could you show us this function? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      C 1 Reply Last reply
      0
      • C confalonieri

        Hi, In my application I need to create an empty window just to receive messages and treat them. I wrote the following code: HINSTANCE hApi = (HINSTANCE) GetModuleHandle(NULL); if (! hApi) ...// manage error CHAR * WindowClassName = "MyWindowClass"; WNDCLASS WindowClassInfo; if (! GetClassInfo(hApi, WindowClassName, &WindowClassInfo)) { WindowClassInfo.hCursor = NULL; WindowClassInfo.hIcon = NULL; WindowClassInfo.lpszMenuName = NULL; WindowClassInfo.lpszClassName = WindowClassName; WindowClassInfo.hbrBackground = NULL; WindowClassInfo.hInstance = hApi; WindowClassInfo.style = CS_OWNDC | CS_VREDRAW | S_HREDRAW; WindowClassInfo.lpfnWndProc = (WNDPROC) MyProc; WindowClassInfo.cbClsExtra = 0; WindowClassInfo.cbWndExtra = 0; if (! RegisterClass(&WindowClassInfo)) ...//manage error } HWND hWnd = CreateWindow(WindowClassName, "MyWindow", WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hApi, NULL); if (! hWnd) ...//manage error But, unfortunately, CreateWindow return NULL and GetLastError return 0 !!! Did anybody could help me ? Thanks in advance. Robin.

        E Offline
        E Offline
        Ernest Laurentin
        wrote on last edited by
        #3

        Try this, if it work, check your WindowProc function like Joaquim suggested:

        LPCTSTR szWindowClassName = \_T("MyWindowClass");
        
        WNDCLASS WindowClassInfo;
        
        if (!GetClassInfo(hApi,szWindowClassName, &WindowClassInfo))
        {
        	WindowClassInfo.hCursor = NULL;
        	WindowClassInfo.hIcon = NULL;
        	WindowClassInfo.lpszMenuName = NULL;
        	WindowClassInfo.lpszClassName = szWindowClassName;
        	WindowClassInfo.hbrBackground = NULL;
        	WindowClassInfo.hInstance = hApi;
        	WindowClassInfo.style = CS\_OWNDC | CS\_VREDRAW | CS\_HREDRAW;
        	WindowClassInfo.lpfnWndProc = (WNDPROC) ::DefWindowProc;
        	WindowClassInfo.cbClsExtra = 0;
        	WindowClassInfo.cbWndExtra = 0;
        
        	if (!RegisterClass(&WindowClassInfo))
        	{
        		TRACE( " ERROR \\n");
        	}
        }
        
        HWND hWnd = CreateWindow(szWindowClassName,
        			"MyWindow",
        			WS\_OVERLAPPEDWINDOW,
        			0,
        			0,
        			CW\_USEDEFAULT,
        			CW\_USEDEFAULT,
        			NULL,
        			NULL,
        			hApi,
        			NULL);
        ASSERT( hWnd != NULL );
        
        C 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          Everything seems OK. The only possible problem I can think of is that MyProc is not properly declared as a WINDPROC should. Could you show us this function? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

          C Offline
          C Offline
          confalonieri
          wrote on last edited by
          #4

          MyProc is declared in a header as following: LRESULT CALLBACK fidLinkEventProc(HWND _hWnd, UINT _iMsg, WPARAM _wParam, LPARAM _lParam); and MyProc is defined in a .c file: LRESULT CALLBACK MyProc(HWND _hWnd, UINT _iMsg, WPARAM _wParam, LPARAM _lParam) { switch (_iMsg) { ... } return 0; }

          1 Reply Last reply
          0
          • E Ernest Laurentin

            Try this, if it work, check your WindowProc function like Joaquim suggested:

            LPCTSTR szWindowClassName = \_T("MyWindowClass");
            
            WNDCLASS WindowClassInfo;
            
            if (!GetClassInfo(hApi,szWindowClassName, &WindowClassInfo))
            {
            	WindowClassInfo.hCursor = NULL;
            	WindowClassInfo.hIcon = NULL;
            	WindowClassInfo.lpszMenuName = NULL;
            	WindowClassInfo.lpszClassName = szWindowClassName;
            	WindowClassInfo.hbrBackground = NULL;
            	WindowClassInfo.hInstance = hApi;
            	WindowClassInfo.style = CS\_OWNDC | CS\_VREDRAW | CS\_HREDRAW;
            	WindowClassInfo.lpfnWndProc = (WNDPROC) ::DefWindowProc;
            	WindowClassInfo.cbClsExtra = 0;
            	WindowClassInfo.cbWndExtra = 0;
            
            	if (!RegisterClass(&WindowClassInfo))
            	{
            		TRACE( " ERROR \\n");
            	}
            }
            
            HWND hWnd = CreateWindow(szWindowClassName,
            			"MyWindow",
            			WS\_OVERLAPPEDWINDOW,
            			0,
            			0,
            			CW\_USEDEFAULT,
            			CW\_USEDEFAULT,
            			NULL,
            			NULL,
            			hApi,
            			NULL);
            ASSERT( hWnd != NULL );
            
            C Offline
            C Offline
            confalonieri
            wrote on last edited by
            #5

            Thank for your help. I solved my problem: MyProc was always returning 0 whatever the message was, whereas it has to treat Windows messages such as "WM_CREATE", ... (traditional messages to create a window). Now, I use "return DefWindowProc(_hWnd,_iMsg,_wParam,_lParam)" when I receive a Windows message different from my messages.

            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