Results 1 to 8 of 8

Thread: Beginner can't create window!?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Unhappy

    Hi,
    I am new to C++, and I would like to use CreateWindow/Ex to display a normal window. Can somebody show me how to do it, please?

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    PHP Code:
    BOOL InitInstance(HANDLE hInstanceint nCmdShow)
    {
        
    HWND hWnd;
        
    DWORD dwFlags WS_OVERLAPPED WS_CAPTION WS_MINIMIZEBOX WS_SYSMENU;

        
    hWnd CreateWindow(szClass"Tutorial"dwFlags
                            
    200300300100NULLNULL, (HINSTANCE)hInstanceNULL);

        if(!
    hWnd)
            return 
    FALSE;

        return 
    TRUE;

    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Technocrat -- it's now HINSTANCE rather than HANDLE for the instance handle

    And Jhd -- are you new to C++ or Windows programming with C++?

    http://www.parksie.net/Raw.zip (change LONG_PTR to LRESULT if you have any problems)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    You know I dont know why it is that way in that program I took that snipit from. Thats strange
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    1. open visual c++
    2. File > New
    3. Click Projects tab
    4. click Win32 Application and give it a name
    5. click finish
    6. click the File View Tab on TreeView
    7. go to File > New
    8. in the first tab Click C++ Source File and name it
    9. Copy and paste the code in the new file
    10. right click the Header folder and add Windows.h
    11. click execute
    
    #include <windows.h>
    LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
    char szWinNamw[] = "MyWin";
    int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
    				LPSTR kposzArgs, int nWinMode)
    
    
        {
        	HWND hwnd;
        	MSG msg;
        	WNDCLASSEX wcl;
        	wcl.cbSize = sizeof(WNDCLASSEX);
        	wcl.hInstance = hThisInst;
        	wcl.lpszClassName = "My Window";
        	wcl.lpfnWndProc = WindowFunc;
        	wcl.style = 0;
        	wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        	wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
        	wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
        	wcl.lpszMenuName = NULL;
        	wcl.cbClsExtra = 0;
        	wcl.cbWndExtra = 0;
        	wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        	if(!RegisterClassEx(&wcl)) return 0;
        	hwnd = CreateWindow(
        		"My Window",
        		"Skeleton Window",
        		WS_OVERLAPPEDWINDOW,
        		CW_USEDEFAULT,
        		CW_USEDEFAULT,
        		CW_USEDEFAULT,
        		CW_USEDEFAULT,
        		HWND_DESKTOP,
        		NULL,
        		hThisInst,
        		NULL
        		);
        	ShowWindow(hwnd, nWinMode);
        	UpdateWindow(hwnd);
        	while(GetMessage(&msg, NULL, 0, 0))
    
    
            	{
            		TranslateMessage(&msg);
            		DispatchMessage(&msg);
            	}
            	return msg.wParam;
        }
        LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message,
        							WPARAM wParam, LPARAM lParam)
    
    
            {
    
    
                	switch(message)	{
                	case WM_DESTROY:
                		PostQuitMessage(0);
                		break;
                	default:
                		return DefWindowProc(hwnd, message, wParam, lParam);
                	}
                	return 0;
            }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't add windows.h to your project...that'll confuse the compiler

    Technocrat -- it used to be HANDLE for everything, until they started differentiating the handle types.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I pulled it out of a Novell SDK pack I am working with. They had backwards comp on everything they could, thats prob why it was like that.

    Once again it would be nice to have a FAQ so poor Vlatko doesnt have to paste that code in every week when some on asks the same question.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah...and that list of C++ tutorial sites
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width