شما اینجا هستید
Message Loop ( حلقه رویداد ) - قسمت اول
Message Loop ( ???? ??? )
?? ???? ?????? ????? Message Loop ?? Event Loop ?? ???? ?????? ?? ?????? ?????? ????? ??? ?? ???? ?? ?????? ?? ????? Message ?? Event ( ???? ?? ??????) ?? ?????? ? ????? ???. ?? ??? ??? ??? ???? ?? ?????? ???? ?????? ?? ?? ?? ?????? ???? ?? ?????? ???? ???.
???? ???? ?? ???? ?? ?????? ?? ????? ????? ?????? ???? ??? ???? ?? ... ???? ???? ?????? ???? ?? ????? ???? ?? ?? ?????? ?? ??? ??????. ???? ???? ?????? ?? ?? ?? ?? ?? ????? ?? ?? ??? ?? ???? ???? ???? (???? Mozilla firefox ): ?? ????? ??? ??? ?????? ?? ??? ?????? ???? ???? ?? ????? ???? ????? ?? ???. ???? ???? ????? ?? ??? ??? ????? ??? ?????? ???? ?? ????? ????? ???? ?? ?? ?????? ?????? ???? ? ?? ?? ????? ???? ?? ??? ??? ??????? ??? ?????? ?? ?? ???? ???? ?? ??? ?????? ????? ?? ??? ? ?????? ???? ???? ? ??? ???? ?? ?? ?? ?????? ?? ???. ?? ???? ?? ????? ?? ????? ???? ????? ???? ?? ?????? ?????? ?? ????.
?? ????? ???? ???? ????? ?? ??? ?? ??? ???? minimize ?? ????? ???? ?? ????? ????? ???? ????? minimize ?? ?? ?????? ????? ?? ??? ? ?? ????? ????? ???? ??? ?? ????? ??? ?? minimize ?????. ????? ???? ????? ????? ?? ?????? ?? ?? ???? ?? ?????? ?? ??? ?? ????? ???? ???? ??? ?? ???? ????? ????. ???? ????? ?? ???? Close ??? ?? ? ???? close ?? ????? ????? ??? ????? ??? ?? ?????? ?? ????? ???? close ???? ??? ??? ??? ??? ???? ?????? ???? ????? ???? ?? ????? ???? ??? ????? ?? ???.
?? ???? ???? ?? ??? ???? ?? ?? ?? ??? ????? ???? ?? ???? ?? ?? ??? ?????? ????? ?????? device change ?? ???? ????? ?? ??? ????? ???. ???? ???? ????? ?? ?? flash memory ?? ???? USB ???? ?? ???? ????? ???? ?? ?? ?????? ??? ?????? ?? ????? ??? ?????? ?? ?? ?????? ?????? ????? ?????. ??? ???? ?? ?????? ??? ?????? ?? ?? ??? ?? ????? flash memory ??? ?? ?? ????? ???? ???? ???? ???? ???? ???? autorun.inf ?? ????? ???? ?? ??? ???? ??? ?? ????? ?? ?????? ?? ?????? ???? device change ?? ????? ?? usb ?? ?????? ???? ????.
?? ?? ??? ??????? ?? ???????? ???? ???? ???? ?? ???? ??? ????? ?? ????? ?? ????. ???? ????? ????? ?? ?? ??? ???? ?????? ?? ????? ???? ??? ???? ?????? ???.
??? ?? ????? ?? ?????? C ?????? ?? ???? main ???? ?? ???. ??? ?????? ???? ?? ?? ???? window application ????? ?? ????? ???? windows ?? ???? WinMain ???? ?? ????. ??? ???? ?? ???? ???? main ?? 2 ??????? ?????? ?????? ?? ???? 4 ??????? ?????? ?? ???. ??? ??? ???? ?? ??? ???? ???:
int CALLBACK WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);
?? ???? ???? hInstance ?? handle ?? ?????? ??? ??? ???.
hPrevInstance
?? ???? ?? ?????? ???? ??? ?? ?????? ????? ?? NULL ???.lpCmdLine ???????? ??? ?? ?????? ????? ??? ???.
nCmdShow ?? ????? int ???? ?????? ????? ?????? ???. ???? ??? ????? ?? ?? ?? ?????? ?? ???? ??? ??????.
???? ??????? ????? ?????? ??? ???? ?? ???? MSDN ????? ???.
???? ???? ?? ??? ??????? ?? ???? ????? ???? ?? ?????? ??? ???? ?? ????.
???? ??????? ?? ???? ?? ?????? windows ???? ?? ???? ???? ??? ??? ?? ?? ???????? ?????? ??? ? ????? ?? ?? ??? ????? ???? ?? ????? ??? ??? ?? ?? ???? ???? ?? ??? ???? ?? ???? ?? ????. ???? ???? LPSTR ???? * char ???.
?? header ???? ??? ?????? ?? ??? string ????? ?? ???? ????? ?? ???? ??? 2 ??? ????? ??? ???. ???? (string) ???? ?? ?? char ????? ?? ???? ? ?? ???? ?? ?? WCHAR ????? ?? ????. char ?? ????? ??? ? WCHAR ?? ????? ???. ?? ????? ???? ????? ???? ???? ?? ???? ???? ??? ??? ?? ??????? ???? ?? ??? ???? ??????? ?????. ???? ????? ?? ???? ?? ???? ?? ????? ?? ????. ??? ???? ??? ?????? ?? ??? ????? ?? ???? ????.
?? ?????? LPSTR ???? * char ? LPWSTR ???? * WCHAR ???.
?? ?? ????? ???? ????? ?? ?????? (user-provided entry point)? ???? ?? ????? ?? ?? ???? ???? (message loop) ????? ????. ???? ??? ?? ?? ????? ?? ?????? ????? ???? ???? ????? ?? ?? ????? ?????? ??? ?? ????? ????? ? ???? ?? ???. ??? ???? ???? ?? ????? ?? ???? close ?????? ????? ????? ???? ???? ????? ??? ? ?????? ???? ?????? ??.
???? ?????? ???? ?? windows ? ???? GetMessage ???. ?? ?? ??? ???? ?? ???? winmain ???? ?? ????:
MSG msg;
BOOL bRet;
// Start the message loop.
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
?? ?? ???? ?? ???? ???? ???? ??? ??? ?? ?? ?? ????? ?? GetMessage ????? ??? ??? ???????? ( ???? ???? quit ???? ?????? ????? ???? ????) ?? ???? ?? ????. ???? ???? ?????? ?? ???? TranslateMessage ? DispatchMessage ?? ??? ?? ????.
???? TranslateMessage ? ???? ??? ????? ?? ?? ???? ??????? ?? ?????? ?? ???? thread ??? ?? ???. ???? DispatchMessage ? ???? ?????? ??? ?? ?? ???? ????? ( ?? ?? ??? ????? ????? ???? ????? ??) ????? ?? ?????.
???? ?? ?? ?? ???? ?? ?? ????? ?? ??? ??? ?? ???? GetMessage ??? ???? ?? ?????? ?? ??? ? ???? DispatchMessage ?? ?? ?? ???? ????? (Window Procedure) ????? ?? ???. ?? ???? ?? ?????? ??? ???? ?? ???? ????? ?? ????? ?? ????. ?? ????? ??? ??? ??????? ???? ??? ????? ?? ?????? ???? ???? ???? ?? ????? ?? window ????? ??????. ????? ? ??????? ???? ???? CreateWindowEx ???? ????? ??? ?? ?? ??? ?? ?? ????? ?? ???:
HWND CreateWindowEx( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam );
???? CreateWindowEx ?? ??? ???? ???? CreateWindow ???? ?? ????? ??????? ?? ???? ? ?? ???? ?? ??? ????? ?? ?? ????? ????? ?? ?? ??????. HWND ??? ???? ?? ???? ??? ?????? ??? ?? ???? ?? ???? ???????. ??? ???? ???? ??? ???? ?? ????? ?? ???? ??????? ???? ?? ????.
??????? ??? ????? ??? ???? ???? ????? ????? ???? ??? ???. ?????? ?? ?? ?? ?????? ?? ???? ???? ??????. ?? ??? ?????:
dwExStyle :
?????? ?? ????? ?? ???? ?? ???. ?????? ???? ???????:
????? | ????? |
WS_EX_ACCEPTFILES | ????? ?????? drag & drop ?? ????. |
WS_EX_CAPTIONOKBTN | ?????? ???? OK ?? ???? ????? |
WS_EX_CLIENTEDGE | ????? ?? ??? ??? ???? |
WS_EX_CONTEXTMENU | ?????? ???? help ?? ???? ????? |
WS_EX_TOPMOST | ???? ?? ??? ?? ??? ????? ???? ????? ??? ? ????? ??? ???? ???? ?? ??. |
.... |
DWORD ?? ???
? unsigned long ??? ?? ?? ???????? ?????? ???????? (typedef) ??? ???.
lpClassName: ?? ???? ????? ?? null ??? ?? ?? ???? ??? ???? ??? ????? ?? ????. ???? ???? ?? ??? ??? ????? ???? ???? ???? ???? RegisterClass ?????? ??? ?
???.
lpWindowName
: ???? ????? ?? null ??? ?? ??? ????? ???. ??? ???? ?? ????? ????? ???? ???? ?? ???.
dwStyle: ??? ????? ?? ?????? ????? ??? ?? ???? ???? ??? ???? ????? ???. ???? ????? ????? ?? ??? ?????? ?????? ?? ???? ????? ???. ( ?? ????? ????? or )
????? | ????? |
---|---|
WS_BORDER | ????? ?? ??? ???? |
WS_CAPTION | ????? ????? ???? ????? |
WS_CHILD | ????? ?? ??? ????? |
WS_HSCROLL | ????? ?? ?????? ???? |
WS_MAXIMIZEBOX | ????? ???? maximize |
WS_MINIMIZEBOX | ????? ???? minimize |
WS_POPUP | ????? ?? ?????? pop-up |
WS_VISIBLE | ????? ????? ?? ?? ???? ??? ??? |
WS_VSCROLL | ????? ?? ?????? ????? |
..... | ..... |
x , y : ?????? ????? ????? ??? ?? ???? ?? ???? ???? ? ?? ???? ????? ???.
nWidth ? nHeight :
??? ? ?????? ????? ???? ??? ???.
hWndParent:
??? ????? ?? ?? ????? ?? ??? ??? ?????? ????? ???? ???? ???? ????? ??? ?? ??? ??? ???? ????? NULL.
hMenu: ?
??? ???? ?????? ?? NULL.lpParam : ??????? ????? ???? ????? ?? ????? ??????? ?? ????? NULL ????.
????? ???? ?? ???? ????? ????? ?? ???? ?? ????? ????? ??? ?? ??? ??? ???? ????? NULL ?? ???? ??????.
?????? ????? ?? ???? ?? ???? MSDN ?????? ????????.
?? ?? ????? ?? ????? ?? ?????? ?? ?? ???? ???? ?? ???? ????. ???? ShowWindow ?? ????? ????? ?? ???? ???.
? ????? ????? ?? ?? ??? ?? ????? ?? ???? ???? RegisterClass ???:
ATOM WINAPI RegisterClass( __in const WNDCLASS *lpWndClass );
??? ???? ?? ???? ?
lpWndClass ?? ?????? ?? ?????? WNDCLASS ???:
typedef struct tagWNDCLASS { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; } WNDCLASS, *PWNDCLASS;
3 ????? ??? ?? ???
?????? ?? ???? ???? ????? ??? ???? :hInstance : ???? ?? ????? ?? ?? ???? ??? ????? ???.
lpszClassName : ??? ???? ?????
lpfnWndProc : ?????? ?? ???? ?????. WNDPROC ?? ???? ?????? ?? ???? ??? ?? ?????? :
typedef LRESULT (CALLBACK* WNDPROC) (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
???? ?????? ??? ??? ?? ???.
??????? ??? ??? ??? ?? ??? ????:
hwnd : ???? ?? ????? ???? ???? ???
uMsg : ???? ????? ???
wParam : ??????? ??? ????
lParam : ??????? ??? ???? ( ??? ??????? ?? ???? ?? ??? ???? ?? ????? ???? ??????? ?????? ?????.)
? ?? ??? ?? ?? ?? ????? ??? ?? ????. ???????? ??????? ???? ??? ???? ?????. ?? ???? ????? ?? ???? ?????? ????? ?? ????? ?? ????? ????? ??????.
???? ?????.
افزودن نظر جدید