Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Console App GetMeassage never returns.

Hello.

I am trying to add a window to my console app.
I create a thread for message loop, but it doesn't
work because GetMessage never returns.
Can you help me?

Many thanks.

[code]


#include


HANDLE handle=NULL;
HINSTANCE hInst=NULL;
HWND hwnd=NULL;
MSG msg;
DWORD thdid=NULL;


//--------------------
DWORD WINAPI pmpthd(LPVOID){ //message loop thread
int status;

while(1){
status=GetMessage(&msg,NULL,0,0);
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message==WM_QUIT || status<=0)break;
}
return 0;
}
//-------------------


LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){

switch(msg){

case WM_CREATE:
ShowWindow(hwnd,SW_RESTORE);
break;

case WM_KEYDOWN:
switch(wParam){
case VK_ESCAPE:
PostQuitMessage(0);
break;
}

MessageBox(hwnd,"OK","OK",MB_OK);

break;
}

return DefWindowProc(hwnd,msg,wParam,lParam);
}


void outwin(){

hInst=GetModuleHandle(NULL);

WNDCLASSEX wc;

wc.cbSize =sizeof(WNDCLASSEX);
wc.lpszClassName="MyClass";
wc.lpfnWndProc =WndProc;
wc.hInstance =hInst;
wc.style =0; //CS_HREDRAW | CS_VREDRAW;
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH) COLOR_BTNFACE;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hIcon =NULL;
wc.hIconSm =NULL;
wc.lpszMenuName =NULL;

if(!RegisterClassEx(&wc)){MessageBox(NULL,"Register class failed","RC FAILED",MB_OK);return;}

hwnd=CreateWindowEx(WS_EX_TOPMOST, //WS_EX_APPWINDOW,
"MyClass",
"Output Window (Enter for Fullscreen)",
WS_CAPTION|WS_VISIBLE|WS_BORDER, //WS_OVERLAPPEDWINDOW,
50,
50,
320,
200,
NULL,
NULL,
hInst,
NULL
);

if(!hwnd){MessageBox(NULL,"Create window failed","CW FAILED",MB_OK);return;}


handle=CreateThread(0,0,pmpthd,0,0,&thdid);
}


////////////////////////////


int main(int argc,char* argv[]){

outwin();

while(1);

return 0;
}


[/code]

Comments

Sign In or Register to comment.