13.07.2015 Views

REFERENCE GUIDE

REFERENCE GUIDE

REFERENCE GUIDE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

_window function can then process the message and carry out anyrequested changes to the window. When the window functionreturns, Windows returns control to the main function. The mainfunction can then pull the next message from the queue.Unless noted otherwise, Windows can send messages in anysequence. An application should not rely on receiving messagesin a particular order.Windows generates a virtual-key message each time the userpresses a keyboard key. The virtual-key message contains avirtual-key code that defines which key was pressed, but does notdefine the character value of that key. To retrieve the charactervalue, the main function must translate the virtual-key messageby using the TranslateMessage function. This function putsanother message with an appropriate character value in theapplication queue. The message can then be dispatched to awindow function.Translatingmessages In general, a main function should use the TranslateMessagefunction to translate every message, not just virtual-key messages.Although TranslateMessage has no effect on other types ofmessages, it guarantees that any keyboard input is translatedcorrectly.The following program fragment illustrates the typical loop that amain function uses to pull messages from the queues anddispatch them to window functions:int PASCAL WinMain(hlnstance, hPrevlnstance, lpCmdLine, nShowCmd)HANDLE hlnstance;HANDLE hPrevlnstance;LPSTR lpCmdLine;int nShowCmd;MSG msg;while (GetMessage((LPMSG)&msg, NULL, 0, 0)){TranslateMessage((LPMSG)&msg);DispatchMessage((LPMSG)&msg);exit(msg.wParam);16Software development kit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!