Results 1 to 8 of 8

Thread: Starting Win32

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Smile Starting Win32

    hello
    I had a question about win32 apps. How do i make one in C++. I've been working with console appications for a while, and now im hoping to move into the win32 applications. I know theres an option that you can start with, but how do I structure it. Can anyone give me a starting point. The Hello World program is a bit complicated if you don't have a clue where to start.

    Any tips or hints are greatly appriciated!
    Thanks!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, how about the thread RIGHT NEXT to this one?
    http://forums.vb-world.net/showthrea...threadid=71834

    Here's a skeleton of your basic Win32 entry point:
    Code:
    #include <windows.h>
    
    int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
        MessageBox(NULL, "Hello!", "Windows App!", MB_OK);
    
        return 0;
    }
    What those parameters mean:
    hInstance -- handle to the current instance of your program
    hPrevInstance -- unused in Win32, it's a relic from old versions
    lpCmdLine -- the whole command line supplied w/o the program filename
    nCmdShow -- you know in shortcuts where you can set it to open a window maximised/minimised/etc? this is where windows passes that to the program
    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

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Try the
    http://www.winprog.org/tutorial

    the tutorial there is very thorough and explains basic windows programming in details.
    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

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Here is the most common example:
    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

  5. #5
    ChimpFace9000
    Guest
    Yet another example of why we need an FAQ.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    while(GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    Actually, that's wrong, I'm afraid Since GetMessage can also return -1 you need to check for that as well, otherwise your program can get stuck looping around doing nothing
    Code:
    int i;
    while(i = GetMessage(&msg, NULL, 0, 0)) {
        if(i == -1) break;
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    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
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by ChimpFace9000
    Yet another example of why we need an FAQ.
    True
    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

  8. #8

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Unhappy

    Hey thanks for all the replies!
    I'm gonna go check out the links right now... I was in a rush and I din't pay attention to the other threads, next time i'll be more observant.

    I agree that we need a FAQ , so ppl. like me can directly go there.
    Anyways, thanks for links

    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

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