|
100鱼币
- #include <Windows.h>
- HINSTANCE g_hInstance;
- LRESULT CALLBACK WndProc(HWND hWnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch(uMsg)
- {
- case WM_MOUSEWHEEL:
- {
- int n = HIWORD(wParam); //向前滚正值 向后滚负值
- static int i = n; //i保存上一次n的值
- RECT rc;
- GetClientRect(hWnd,&rc);
- if(n > i) //如果n大于上一次n的值,则说明鼠标滚轮向前滚
- {
-
- MoveWindow(hWnd,rc.left--,rc.top--,rc.right++,rc.bottom++,TRUE);
- }
- else
- {
- MoveWindow(hWnd,rc.left++,rc.top++,rc.right--,rc.bottom--,TRUE);
- }
-
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd,uMsg,wParam,lParam);
- }
- void RegisterWnd(LPCTSTR lpClassName)
- {
- WNDCLASSEX wce;
- wce.style = CS_HREDRAW|CS_VREDRAW;
- wce.lpfnWndProc = WndProc;
- wce.cbSize = sizeof(WNDCLASSEX);
- wce.cbClsExtra = 0;
- wce.cbWndExtra = 0;
- wce.hInstance = g_hInstance;
- wce.hIcon = 0;
- wce.hCursor = 0;
- wce.hIconSm = 0;
- wce.hbrBackground = HBRUSH(COLOR_BTNFACE);
- wce.lpszClassName = lpClassName;
- wce.lpszMenuName = 0;
- if(!RegisterClassEx(&wce))
- {
- MessageBox(NULL,TEXT("注册失败"),TEXT("提示"),MB_OK);
- }
- }
- HWND CreateWnd(LPCTSTR lpClassName)
- {
- HWND hWnd = CreateWindowEx(0,lpClassName,L"HELLO",
- WS_OVERLAPPEDWINDOW,500,200,
- 500,500,NULL,NULL,g_hInstance,NULL);
- return hWnd;
- }
- void DisplayWnd(HWND hWnd)
- {
- ShowWindow(hWnd,SW_SHOW);
- UpdateWindow(hWnd);
- }
- void Message()
- {
- MSG msg;
- while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- g_hInstance = hInstance;
- RegisterWnd(L"hello");
- HWND hWnd = CreateWnd(L"hello");
- DisplayWnd(hWnd);
- Message();
- return 0;
- }
复制代码
|
最佳答案
查看完整内容
问题看错了,再看了下标题,这是我改的
case WM_MOUSEWHEEL:
{
RECT rc;
GetWindowRect(hWnd,&rc);
if((short)HIWORD(wParam) > 0)
{
MoveWindow(hWnd,rc.left--,rc.top--,rc.right-rc.left+1,rc.bottom-rc.top+1,TRUE);
}
else
{
MoveWindow(hWnd,rc.left++,rc.top++,rc.right-rc.le ...
|