Reputation: 7850
I have console application in c. I want to convert into window application, kindly guide me so that I can make it possible.
Upvotes: 1
Views: 354
Reputation: 4245
That is a huge topic that requires a separate discussion. You may want to learn some GUI toolkit. Qt or wxWidgets will do (though they are written in C++, not C). If you're into C crossplatform development, you may take a look at GTK+. If you are planning only to write programs for Windows, you may learn Windows API. Whichever way you choose, there's a lot of docs available, but each and every way requires a lot of study and cannot be explained here.
Upvotes: 3
Reputation: 34463
Outline of steps you need to take:
First two are quite easy, the most work lies in the next steps. if you want the window be just your own replication of a console, you can design a dialogue containing one text or edit control, and implement a simple dialog procedure and a message loop. Some code snippets follow, but giving a complete and working sample would go beyond the reasonable space. If you understand the code below, I guess it should get you started. If not, I am afraid you will have to learn Windows progamming basics first.
HWND consoleEditHWnd; static int CALLBACK ConsoleDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { InitWindow((HINSTANCE)hInstApp,hDlg); consoleEditHWnd = GetDlgItem(hDlg,IDC_CONSOLE_EDIT); return TRUE; } case WM_SIZE: if (consoleEditHWnd) { RECT rect; GetClientRect(hDlg, &rect); MoveWindow( consoleEditHWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, TRUE ); } break; } return FALSE; }
hwndApp = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CONSOLE), NULL, ConsoleDlgProc); ShowWindow((HWND)hwndApp,SW_SHOW); UpdateWindow((HWND)hwndApp); MSG msg; while( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); }
When you want to add some text into the "console", you can do it using
int count = GetWindowTextLengthW(consoleEditHWnd); ... allocate a buffer GetWindowTextW(consoleEditHWnd,buffer,count+newTextSize); ... append SetWindowTextW(consoleEditHWnd,buffer);
Upvotes: 2