simple question on creating a window

This is a discussion on simple question on creating a window within the Windows Programming forums, part of the Platform Specific Boards category; hi all~ i'm newbie to windows and GUI programming and just start reading "Windows Programming" but something confused me on ...

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    simple question on creating a window

    hi all~

    i'm newbie to windows and GUI programming and just start reading "Windows Programming" but something confused me on createing a window. here are my questions:

    1. all samples in the book are written in C, can C++ do windows programing instead ?
    2. there are always some attributes like "WINAPI" and "CALLBACK" in function declaration like this:
    Code:
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);
    what's the difference for functions with and without them ?
    and i'd appreciate anyone could figure out where relative documentation is in MSDN.
    3. for a simple window program, how many functions we must code with ? (i know only WinMain, ShowWindow and UpdateWindow)

    tks.
    Never end on learning~

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    1. Yes.

    2. They're #defined macros for __stdcall.

    3. For a quick, no-frills window, you'll use about a dozen.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    1. Yes. Anything (with possibly a few exceptions, I'm not sure) written in C can be compiled as C++. If you want more OO design (eg, using classes) you might look into MFC or write your own wrappers for the API.

    2. Take a look at this page. WINAPI, for example, is defined as __stdcall (at least on my compiler)

    3. Read some tutorials

    Edit: Guess I'm sloooow
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    1. As Ken already said, yes. But sometimes when porting C code to C++, you'll have to add some casts to make it compile. For example,

    C
    Code:
    hBitmap = LoadImage( ...etc...);
    C++
    Code:
    hBitmap = (HBITMAP) LoadImage( ...etc...);
    3. Here's my boilerplate windows program. I usually use it whenever I start a new windows project. I also maintain a list of tutorials/tools here.

  5. #5
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563
    tks guys i've made a cute window now, but met some problems when facing messages. here is my callback function to deal with messages:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (iMsg)
    	{
    		case WM_PAINT:
    			PAINTSTRUCT ps;
    			HDC hdc;
    			hdc = BeginPaint(hwnd, &ps);
    			TextOut(hdc, 100, 100, "Holla !", 10);
    			EndPaint(hwnd, &ps);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		default:
    			return DefWindowProc(hwnd, iMsg, wParam, lParam);
    	}
    
    	return 0;
    }
    when i compile the program it reports an error like this:
    [Linker error] undefined reference to `TextOutA@20'
    i'm with Dev-C++, anyone help me ? tks !!!
    Never end on learning~

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    you should compile in gui mode.
    niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. Newbie question about creating a window
    By gozu in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2007, 05:17 PM
  3. Errors with simple window handler
    By Chapmad in forum Windows Programming
    Replies: 11
    Last Post: 08-30-2004, 02:44 PM
  4. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 08:23 AM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21