aleksk
Гость
|
|
« Ответ #18 : 19-07-2006 20:52 » |
|
HINSTANCE hI; WNDCLASS wc; HWND htestwnd, hmainwnd;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); BOOL OnCreate (HWND, LPCREATESTRUCT); void OnPaint (HWND); void OnDestroy (HWND); void OnLButtonDown (HWND, BOOL, int, int, UINT);
LRESULT CALLBACK TestWndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ButtProc (HWND, UINT, WPARAM, LPARAM); BOOL OnButtCreate (HWND, LPCREATESTRUCT); void OnButtPaint (HWND); void OnButtDestroy (HWND); void OnButtLButtonDown (HWND, BOOL, int, int, UINT); void OnButtLButtonUp (HWND, int, int, UINT);
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE, LPSTR, int) { char szClassName[] ="MainWindow"; char szTitle[] = "MyProga"; MSG Msg; hI = hInst;
ZeroMemory (&wc, sizeof(wc)); wc.lpfnWndProc = WndProc; wc.hInstance = hInst; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_HAND); wc.hbrBackground = GetStockBrush (LTGRAY_BRUSH); wc.lpszClassName = szClassName; RegisterClass (&wc); HWND hmainwnd = CreateWindow (szClassName, NULL, WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, HWND_DESKTOP, NULL, hInst, NULL); ShowWindow (hmainwnd, SW_SHOWNORMAL);
while (GetMessage (&Msg, NULL, 0, 0)) DispatchMessage (&Msg); return 0; }
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { HANDLE_MSG (hwnd, WM_CREATE, OnCreate); HANDLE_MSG (hwnd, WM_PAINT, OnPaint); HANDLE_MSG (hwnd, WM_DESTROY, OnDestroy); HANDLE_MSG (hwnd, WM_LBUTTONDOWN, OnLButtonDown); //HANDLE_MSG (hwnd, WM_LBUTTONUP, OnLButtonUp);
default: return (DefWindowProc (hwnd, msg, wParam, lParam)); } }
BOOL OnCreate (HWND hwnd, LPCREATESTRUCT) { char szButtClassName[]="ButtWindow"; wc.lpfnWndProc = ButtProc; wc.lpszClassName = szButtClassName; wc.hbrBackground = GetStockBrush (BLACK_BRUSH); RegisterClass (&wc);
HWND hbuttwnd = CreateWindow (szButtClassName, NULL, WS_CHILDWINDOW | WS_VISIBLE , 0, 464, 344, 88, hwnd, NULL, hI, NULL); ZeroMemory (&wc, sizeof(wc));
char szTestClassName[]="TestWindow"; wc.lpfnWndProc = TestWndProc; wc.lpszClassName = szTestClassName; wc.hCursor = LoadCursor (NULL, IDC_HAND); wc.hbrBackground = GetStockBrush (BLACK_BRUSH); RegisterClass (&wc); HWND htestwnd = CreateWindow (szTestClassName, NULL, WS_OVERLAPPEDWINDOW , 0, 0, 800, 600, NULL, NULL, hI, NULL); return TRUE; }
void OnPaint (HWND hwnd) { PAINTSTRUCT ps; HDC hdc = BeginPaint (hwnd, &ps); BitBlt (hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); EndPaint (hwnd, &ps); }
void OnDestroy (HWND) { DeleteMixer (); DeleteBitmap (hBitmap); SelectBitmap (hdcMem, hOldBitmap); DeleteDC (hdcMem); PostQuitMessage (0); }
LRESULT CALLBACK TestWndProc (HWND htestwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return (DefWindowProc (htestwnd, msg, wParam, lParam)); }
LRESULT CALLBACK ButtProc (HWND hbuttwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { HANDLE_MSG (hbuttwnd, WM_CREATE, OnButtCreate); HANDLE_MSG (hbuttwnd, WM_PAINT, OnButtPaint); HANDLE_MSG (hbuttwnd, WM_DESTROY, OnButtDestroy); HANDLE_MSG (hbuttwnd, WM_LBUTTONDOWN, OnButtLButtonDown); HANDLE_MSG (hbuttwnd, WM_LBUTTONUP, OnButtLButtonUp);
default: return (DefWindowProc (hbuttwnd, msg, wParam, lParam)); } }
void OnButtLButtonDown (HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlag) { ShowWindow (htestwnd, SW_SHOWNORMAL); UpdateWindow ( htestwnd); MessageBeep (MB_OK);
ButtonPush =1; InvalidateRect (hwnd, NULL, FALSE); }
void OnButtLButtonUp (HWND hwnd, int x, int y, UINT keyFlag) { ButtonPush =0; InvalidateRect (hwnd, NULL, FALSE); }
|