#include<windows.h>
int i=0,j=0,k=0;
HWND hwnd=GetDesktopWindow();
HDC hdc=GetWindowDC(hwnd);
LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
for(i=0;i<1024;i++)
{
for(j=0;j<768;j++)
{
SetPixelV(hdc,i,j,0xffffff);
}
}
return 0;
}
}鼠标左键按下后桌面并没有变白,为什么会这样呢?
LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);这个方法没有用起来.
int i=0,j=0,k=0;
HWND hwnd=GetDesktopWindow();
HDC hdc=GetWindowDC(hwnd);
MSG msg;
WNDCLASS wndclass;
LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
RegisterClass(&wndclass);//注册窗口类
while(GetMessage(&msg,NULL,0,0))
{
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
for(i=0;i<1024;i++)
{
for(j=0;j<768;j++)
{
SetPixelV(hdc,i,j,0xffffff);
}
}
return 0;
}
}鼠标左键按下后桌面还是没有变白,为什么会这样呢?
int i=0,j=0,k=0;
HWND hwnd=GetDesktopWindow();
HDC hdc=GetWindowDC(hwnd);
MSG msg;
WNDCLASS wndclass;
LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
RegisterClass(&wndclass);//注册窗口类
wndclass.lpfnWndProc=WndProc;//窗口消息处理
while(GetMessage(&msg,NULL,0,0))
{
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONDOWN:
for(i=0;i<1024;i++)
{
for(j=0;j<768;j++)
{
SetPixelV(hdc,i,j,0xffffff);
}
}
return 0;
}
}鼠标左键按下后还是没反应
#include "stdafx.h"
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ;
MSG msg ;WNDCLASS wc ;
wc.style = CS_HREDRAW | CS_VREDRAW ;
wc.lpfnWndProc = WndProc ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
wc.hInstance = hInstance ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wc.lpszMenuName = NULL ;
wc.lpszClassName = szAppName ;
if (!RegisterClass (&wc))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;
return 0 ; }
hwnd = CreateWindow (szAppName, // window class name
TEXT ("欢迎你的到来!"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("你好,欢迎你来到VC之路!"), -1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
给你找了个例子,比较简单,对比一下吧。http://zifeiyu520yang.blog.sohu.com/115402088.html
int i=0,j=0;
HDC hdc=GetWindowDC(GetDesktopWindow());
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
for(i=0;i<1024;i++)
{
for(j=0;j<768;j++)
{
SetPixelV(hdc,i,j,0xffffff);
}
}
}桌面确实全白了
可是你上面给出的代码是在回调函数里处理的绘制啊
你要调用回调函数就得有个窗口类来调用啊
1. 创建一个窗口,在窗口中处理鼠标消息。这个就不多说了。2. 用Hook截获其他窗口的鼠标事件,这个需要写个DLL把hook的代码写在dll中。楼主可以搜索SetWindowsHookEx3. 子类化Desktop Windows,让这个窗口自己处理鼠标消息。这个也需要写个DLL,在DLL中用SetWindowLongPtr。楼主可以搜索"DLL注入"
不是注册窗口类的问题,而是要有个实际的窗口来处理鼠标消息。楼主找本书去看看windows的消息机制吧。
你用spy++看看
桌面窗口名是ProgrammeManager
实体桌面其实是个ListCtrl
2. 你应该setwindowlong,hook 窗口的winproc为你自己的winproc
3. 在你的winproc里处理 鼠标消息和paint消息ls几位给的是创建窗口,处理winproc,和lz说的在桌面上画不是一个事