int CUI Application
DWORD WINAPI mainGUI( LPVOID lp)
{
HMODULE hInstance= 0;
hInstance = GetModuleHandle(NULL);
HWND hWnd; MSG msg;
hWnd = CreateWindow("EDIT", "This window was created from main() and can get messages from the console below.",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
if (!hWnd) return (1);
*(HWND*)lp = hWnd;
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
int main(int argc, char* argv[])
{
DWORD ID; HWND hWindow;
char szOutput[64];
CreateThread(NULL,0,mainGUI, &hWindow, NULL,&ID);
printf("This console created the window above./nType in the message you want to send to the window./n/"quit/" to exit./n/n");
while (true) {
scanf("%s", szOutput);
if (!strcmp(szOutput, "quit")) break;
SendMessage(hWindow,WM_SETTEXT, strlen(szOutput), (LPARAM)szOutput);
}
return 0;
}
in GUI. to control the CONSOLE Window
AllocConsole();
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); // return an OS file handle
WriteFile(handle, msg1, strlen(msg1), &dwBytesWritten, NULL);
WriteFile(handle, msg2, strlen(msg2), &dwBytesWritten, NULL);
int hCrt = _open_osfhandle((long)handle,_O_TEXT); // return a runtime file handle
write(hCrt, msg3, strlen(msg3)); // for files opened by _open()
FILE * hf = _fdopen( hCrt, "w" ); // stream
char buf[2];
setvbuf( hf, buf, _IONBF, 1 );
*stdout = *hf;
fprintf(hf, msg4); // for files opened by fopen
printf(msg5);
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); // return an OS file handle
ReadFile(hIn, temp, 1, &dwBytesWritten, NULL);
FreeConsole();
return (0);
}