如何用C语言编写程序实现QQ窗口的震动效果?
- 内容介绍
- 文章标签
- 相关推荐
本文共计566个文字,预计阅读时间需要3分钟。
本例分享了一个C语言实现的QQ窗口拖动功能的代码示例,供大家参考。具体内容如下:
c#include
// 定义全局变量HINSTANCE hInst;LPCSTR szWindowClass=MyApp;
// 消息处理函数声明LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) { hInst=hThisInst; // 存储实例句柄
WNDCLASSEX wcex;
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.style=CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc=WndProc;
wcex.cbClsExtra=0;
wcex.cbWndExtra=0;
wcex.hInstance=hInst;
wcex.hIcon=LoadIcon(hInst, IDI_APPLICATION);
wcex.hCursor=LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName=NULL;
wcex.lpszClassName=szWindowClass;
wcex.hIconSm=LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex)) { MessageBox(NULL, Window Registration Failed!, Error!, MB_ICONEXCLAMATION | MB_OK); return 0; }
HWND hwnd=CreateWindow(szWindowClass, QQ Window Drag, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInst, NULL);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
return (int)msg.wParam;}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_NCLBUTTONDOWN: // 当用户按下窗口的栏时 ReleaseCapture(); // 释放捕获 SendMessage(hwnd, WM_NCLBUTTONUP, wParam, lParam); // 发送模拟的鼠标释放消息 break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0;}
以上代码是一个简单的QQ窗口拖动功能的实现。
本文实例为大家分享了C语言实现QQ窗口抖动的具体代码,供大家参考,具体内容如下
#include <stdio.h> #include <windows.h> int main(int argc, char *argv[]) { RECT rect; //RECT是一个矩形结构体,相当于保存了一个矩形的四条边的坐标 HWND hwnd = NULL,oldhwnd = NULL; //两个窗口句柄 int x,y,width,height; //用来保存窗口横纵坐标和宽度、高度的变量 int i; system("title C语言窗口抖动"); for(i=0;i<50;i++) { hwnd = GetForegroundWindow(); //一个API函数,获取活动窗口的句柄 if(hwnd!=oldhwnd) { GetWindowRect(hwnd,&rect); //获取指定窗口的位置 x = rect.left; y = rect.top; width = rect.right - x; height = rect.bottom - y; oldhwnd = hwnd; //把刚刚获取的窗口句柄保存起来。 } MoveWindow(hwnd,x-10,y,width,height,TRUE); //向左移动了10像素,下同 Sleep(5); //暂停5毫秒 MoveWindow(hwnd,x-10,y-10,width,height,TRUE); Sleep(5); MoveWindow(hwnd,x,y-10,width,height,TRUE); Sleep(5); MoveWindow(hwnd,x,y,width,height,TRUE); Sleep(5); } return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。
本文共计566个文字,预计阅读时间需要3分钟。
本例分享了一个C语言实现的QQ窗口拖动功能的代码示例,供大家参考。具体内容如下:
c#include
// 定义全局变量HINSTANCE hInst;LPCSTR szWindowClass=MyApp;
// 消息处理函数声明LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) { hInst=hThisInst; // 存储实例句柄
WNDCLASSEX wcex;
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.style=CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc=WndProc;
wcex.cbClsExtra=0;
wcex.cbWndExtra=0;
wcex.hInstance=hInst;
wcex.hIcon=LoadIcon(hInst, IDI_APPLICATION);
wcex.hCursor=LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName=NULL;
wcex.lpszClassName=szWindowClass;
wcex.hIconSm=LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex)) { MessageBox(NULL, Window Registration Failed!, Error!, MB_ICONEXCLAMATION | MB_OK); return 0; }
HWND hwnd=CreateWindow(szWindowClass, QQ Window Drag, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInst, NULL);
ShowWindow(hwnd, ncmdshow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
return (int)msg.wParam;}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage(0); break; case WM_NCLBUTTONDOWN: // 当用户按下窗口的栏时 ReleaseCapture(); // 释放捕获 SendMessage(hwnd, WM_NCLBUTTONUP, wParam, lParam); // 发送模拟的鼠标释放消息 break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0;}
以上代码是一个简单的QQ窗口拖动功能的实现。
本文实例为大家分享了C语言实现QQ窗口抖动的具体代码,供大家参考,具体内容如下
#include <stdio.h> #include <windows.h> int main(int argc, char *argv[]) { RECT rect; //RECT是一个矩形结构体,相当于保存了一个矩形的四条边的坐标 HWND hwnd = NULL,oldhwnd = NULL; //两个窗口句柄 int x,y,width,height; //用来保存窗口横纵坐标和宽度、高度的变量 int i; system("title C语言窗口抖动"); for(i=0;i<50;i++) { hwnd = GetForegroundWindow(); //一个API函数,获取活动窗口的句柄 if(hwnd!=oldhwnd) { GetWindowRect(hwnd,&rect); //获取指定窗口的位置 x = rect.left; y = rect.top; width = rect.right - x; height = rect.bottom - y; oldhwnd = hwnd; //把刚刚获取的窗口句柄保存起来。 } MoveWindow(hwnd,x-10,y,width,height,TRUE); //向左移动了10像素,下同 Sleep(5); //暂停5毫秒 MoveWindow(hwnd,x-10,y-10,width,height,TRUE); Sleep(5); MoveWindow(hwnd,x,y-10,width,height,TRUE); Sleep(5); MoveWindow(hwnd,x,y,width,height,TRUE); Sleep(5); } return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自由互联。

