How to put C++ application into my Window?


I can write simple C++ applications and now with Win32 I can create a Window with a menu bar, scroll bars and such. What I don't know how to do is put my application program in my window. I have been looking for tutorials with no luck so far, but looking. I use the Dev C++ IDE. Any help will be greatly appreciated.

Thanks

Hotepmichael
Last edited on
What exactly do you mean by Window? 'Cause to draw scrollbars and buttons you already use a Window, although I'd rather recommend to use a multiplatform, "generic" and higher level library such as QT or WxWidgets.
A window and an application program are not the same thing. Win32 programming is what you do to generate the window itself. A c++ application program does what you programmed it to do. I suppose I should have said how do you create a windows application program.

Compile this code and you get a simple window, however it is not a windows application program. I want to know how to put my application program in the window.
Thanks

#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
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)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Last edited on
closed account (E0p9LyTq)
Win32 API Tutorials:
http://www.winprog.org/tutorial/
http://www.infernodevelopment.com/c-win32-api-tutorial
http://www.relisoft.com/Win32/
http://win32-framework.sourceforge.net/tutorial.htm
Thanks FurryGuy.
Topic archived. No new replies allowed.