本文介绍了通过Win32仅在C语言中创建屏幕保护程序的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试创建一个Win32屏幕保护程序.我知道一些Windows编程.
您能帮我实际如何对Win32 xyz.c文件进行必要的修改,以便我可以将其作为成功的屏幕保护程序加载.

OP中的代码在评论中发布:

Hi,
I am trying to create a win32 screen saver. I know a bit of windows programming.
Could you please help me how do i actually make necessary modifications of my win32 xyz.c file so that I could load it as a successful screen saver.

Code from OP posted in comments:

/********************************************************************************
*                                                                               *
* Name: Code rain                                                               *
* Date: 11/08/2012                                                              *
* Author: Kiran Bhatter.                                                        *
* Version: 0.1                                                                  *
* Source: C                                                                     *
*                                                                               *
********************************************************************************/
#include <windows.h>
#include <tchar.h>
#include <scrnsave.h>

const TCHAR szSaverName[] = _T("example");
HWND hWnd = NULL;
int cxClient = 0, cyClient = 0;

LONG WINAPI ScreenSaverProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
    MSG msg;
    WNDCLASSEX wc = {0};

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_VREDRAW | CS_HREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.lpfnWndProc = ScreenSaverProc;
    wc.hInstance = hInstance;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szSaverName;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, _T("RegisterClassEx() failed!"), szSaverName, MB_ICONERROR);
        return 1;
    }

    hWnd = CreateWindowEx(0, szSaverName, szSaverName, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);

    if(!hWnd)
    {
        MessageBox(NULL, _T("CreateWindowEx() failed!"), szSaverName, MB_ICONERROR);
        return 1;
    }

    ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd);

    while(1)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if(msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    UnregisterClass(szSaverName, hInstance);

    return msg.wParam;
}

LONG WINAPI ScreenSaverProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg)
    {
        case WM_CREATE:
            return 0;

        case WM_SIZE:
            cxClient = LOWORD(lParam);
            cyClient = HIWORD(lParam);
            return 0;

        case WM_KEYDOWN:
            switch(wParam)
            {
                case VK_ESCAPE:
                    SendMessage(hWnd, WM_DESTROY, 0, 0);
                    break;
            }
            return 0;

        case WM_CLOSE:
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            return 0;
    }
    
    return DefScreenSaverProc(hWnd, iMsg, wParam, lParam);
}

推荐答案




这篇关于通过Win32仅在C语言中创建屏幕保护程序的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 10:03