C UI

This is a discussion on C UI within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I've been wondering... I'm more of a VB programmer than I am a C programmer, which is why you don't ...

  1. #1
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429

    C UI

    I've been wondering... I'm more of a VB programmer than I am a C programmer, which is why you don't see me floating around in those forums very often...

    but the thought occured to me the other day, that VB is a completely interface, event driven programming language, while C... is more of a prompt type interface, from my experience with it.

    So the question is, since I've never seen/designed one, what kind of UI do you build with C/C++... or is it more programming that is built around one function, that you run, and that's it, like it doesn't need further interaction from the user?

    And if you do make a visual interface, how do you do it?

  2. #2
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Well it's completely different in Linux and Windows. In Windows you use the WinAPI or MFC, and in linux you use...well, I have no clue.

    Yes, C is a procedural language, but you can still make Event-Driven UI's in it because (at least in WinAPI) the OS sends messages to the application, and when you intercept those messages, you take whatever action is neccessary...ex:

    Every time you get a WM_SIZE message you will most likely want to resize all of the controls on your window, so you catch that message and resize all of the controls during it.

    The simplest working Windows UI app I can think of would be:

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, 
    	LPARAM lParam);
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    	PSTR pszCmdLine, int nCmdShow)
    {
    
    	WNDCLASSEX wc;
    	HWND hwnd;
    	MSG msg;
    
    	wc.cbSize=sizeof(WNDCLASSEX);
    	wc.style=CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc=WndProc;
    	wc.cbClsExtra=0;
    	wc.cbWndExtra=0;
    	wc.hInstance=hInstance;
    	wc.hIcon=LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor=LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.lpszMenuName=NULL;
    	wc.lpszClassName="TutClass";
    	wc.hIconSm=NULL;
    
    	RegisterClassEx(&wc);
    
    	hwnd=CreateWindowEx(0, "TutClass", "Hi!",
    		WS_OVERLAPPEDWINDOW,
            	CW_USEDEFAULT, CW_USEDEFAULT,
            	CW_USEDEFAULT, CW_USEDEFAULT,
    		NULL, NULL, hInstance, NULL); 
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, 0, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    
    
    LRESULT WINAPI WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, 
    	LPARAM lParam)
    {
        HDC hdc;
        PAINTSTRUCT ps;
    
        switch(uMsg)
        {
        case WM_PAINT:
    	hdc = BeginPaint(hwnd, &ps);
    	TextOut(hdc, 0, 0, "Hello, World!", 13);
    	EndPaint(hwnd, &ps);
    	return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        }
        return DefWindowProc(hwnd, uMsg, wParam,lParam);
    }
    I wrote a tutorial on it a while ago if you'd like the link...

  3. #3
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    sure... hook me up, i'd be interested in reading about it... not that I'm probably going to go anywhere with it, but I'm interested.

    Can't hurt to learn something new!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-01-2007, 07:11 AM
  2. Editor UI: Inserting entities
    By psychopath in forum Game Programming
    Replies: 2
    Last Post: 12-29-2006, 05:23 PM
  3. drawing my ui (openGL)
    By hannibar in forum Game Programming
    Replies: 1
    Last Post: 04-12-2006, 07:24 AM
  4. DirectX UI
    By gamingdl'er in forum Game Programming
    Replies: 5
    Last Post: 12-08-2005, 07:06 AM
  5. UI dies during data processing
    By fatinez in forum Windows Programming
    Replies: 5
    Last Post: 05-04-2005, 03:42 AM

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