如果不用MFC,而是用API直接设计Windows程序,现在大多数书上都是简单的举了一个例子,生成的窗口都是白色的,没有任何东西的窗口。如果我想在这样的窗口上面添加一些文本框、按钮之类的东西,甚至加入一些ActiveX控件,请问如何实现?另外,以前那本很有名的《Windows程序设计》现在那里有电子版下载?谢谢!

解决方案 »

  1.   

    用CreateWindow或CreateWindowEx可以创建文本框,按钮之类东西
    具体你去找MSDN吧。要学API写windows程序还是买本《Windows程序设计》这本书吧。就算你找到了电子版,上千页的大家伙你会坚持坐电脑前看下来?
      

  2.   

    http://www.cntomorrow.com:3310/data/Programming%20Windows%20CHS.chm
      

  3.   

    转个代码给你看看。#include <windows.h>
    HWND hwndMain;
    HBRUSH hbrush;
    bool  InitMainWindow(HINSTANCE hInst);
    LRESULT CALLBACK WndMainProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    MSG msg;
    hbrush = CreateSolidBrush(RGB(255,0,0));
    InitMainWindow(hInstance);
    while(GetMessage(&msg,NULL,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    DeleteObject(hbrush);
    return msg.wParam;
    }bool  InitMainWindow(HINSTANCE hInst)
    {
    char szClassName[] = "TEMP";
    char szWindName[]  = "temp";
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = hbrush;
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hIcon = NULL;//LoadIcon(hInst,(LPCTSTR)IDI_CZICON);
    wc.hIconSm = NULL;//LoadIcon(hInst,(LPCTSTR)IDI_CZICON);
    wc.hInstance = hInst;
    wc.lpfnWndProc = WndMainProc;
    wc.lpszClassName = szClassName;
    wc.lpszMenuName = NULL;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    if(!RegisterClassEx(&wc))
    return false; hwndMain = CreateWindowEx(WS_EX_TOPMOST,szClassName,szWindName,WS_POPUP|WS_BORDER,
    20,20,5,5,
    NULL,NULL,hInst,NULL);
    if(!hwndMain)
    return false;
    ShowWindow(hwndMain,SW_SHOW);
    UpdateWindow(hwndMain); return true;
    }LRESULT CALLBACK WndMainProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    PAINTSTRUCT pt;
    RECT rect;
    switch(message)
    {
    case WM_KEYDOWN:
    {
    GetWindowRect(hwnd,&rect);
    switch(wParam)
    {
    case VK_ESCAPE:
    PostQuitMessage(0);
    case VK_DOWN:
    GetWindowRect(hwnd,&rect);
    // MoveWindow(hwnd,rect.top+1,rect.left,rect.right-rect.left,rect.bottom-rect.top,false);
    SetWindowPos(hwnd,NULL,rect.left,rect.top+1,rect.right-rect.left,rect.bottom-rect.top,SWP_NOZORDER);
    break;
    case VK_UP:
    GetWindowRect(hwnd,&rect);
    // MoveWindow(hwnd,rect.top-1,rect.left,rect.right-rect.left,rect.bottom-rect.top,false);
    SetWindowPos(hwnd,NULL,rect.left,rect.top-1,NULL,NULL,SWP_NOZORDER|SWP_NOSIZE);
    break;
    case VK_LEFT:
    GetWindowRect(hwnd,&rect);
    // MoveWindow(hwnd,rect.top,rect.left-1,rect.right-rect.left,rect.bottom-rect.top,false);
    SetWindowPos(hwnd,NULL,rect.left-1,rect.top,rect.right-rect.left,rect.bottom-rect.top,SWP_NOZORDER|SWP_NOSIZE);
    break;
    case VK_RIGHT:
    GetWindowRect(hwnd,&rect);
    // MoveWindow(hwnd,rect.top+1,rect.left+1,rect.right-rect.left,rect.bottom-rect.top,false);
    SetWindowPos(hwnd,NULL,rect.left+1,rect.top,rect.right-rect.left,rect.bottom-rect.top,SWP_NOZORDER|SWP_NOSIZE);
    GetWindowRect(hwnd,&rect);
    break;
    }
    break;
    }
    break;
    default:
    return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
    }