在窗口中放置一个窗口

时间:2013-06-29 07:51:23

标签: c winapi window parent-child

我现在被分配制作一个图形/笛卡尔飞机制作程序,我被要求用C语言,或者更准确地说,在Win32中,我有一点问题,但我想在我的内部放一个弹出窗口窗口作为临时图形字段,问题是当我创建窗口时,应该是“图形字段”出现在主/父窗口之外,它似乎使用整个屏幕作为对它的位置的引用,而不是指定的父/主窗口:

HWND DrawGrap(HWND hwnd)
{
LPSTR nme = "graph";
WNDCLASSEX c;
c.style = CS_VREDRAW|CS_HREDRAW;
c.lpfnWndProc = MathProc;
c.cbClsExtra = 0;
c.cbWndExtra = 0;
c.hInstance = GetModuleHandle(NULL);
c.hIcon = LoadIcon(NULL,IDI_APPLICATION);
c.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
c.hCursor = LoadCursor(NULL,IDC_ARROW);
c.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
c.lpszMenuName = NULL;
c.lpszClassName = nme;
c.cbSize = sizeof(c);

RegisterClassEx(&c);

return CreateWindowEx(0,nme,"",WS_VISIBLE|WS_POPUP|WS_CHILD,
                      10, 10,
                      460,200,hwnd,NULL,GetModuleHandle(NULL),0);

 }
 void InitializeUI(HWND hwnd)
{       
    //Graph
    DrawGrap(hwnd);
    //GroupBoxes for coordinate inputs
    P1BOX = CreateWindowEx(0,"BUTTON","Point 1",
                        WS_VISIBLE|WS_CHILD|BS_GROUPBOX,
                        10,230,225,120,hwnd,(HMENU)111,
                        GetModuleHandle(NULL),0);                       
    P2BOX = CreateWindowEx(0,"BUTTON","Point 2",
                        WS_VISIBLE|WS_CHILD|BS_GROUPBOX,
                        250,230,225,120,hwnd,(HMENU)112,
                        GetModuleHandle(NULL),0);

    //Coordinate Labels:
    CreateLabel("X :",P1BOX,30);
    CreateLabel("Y :",P1BOX,80);
    CreateLabel("X :",P2BOX,30);
    CreateLabel("Y :",P2BOX,80);                
    //Input boxes
    hP1X = CreateBox(P1BOX,40,30,P1X);
    hP1Y = CreateBox(P1BOX,40,80,P1X);
    hP2X = CreateBox(P2BOX,40,30,P1X);
    hP2Y = CreateBox(P2BOX,40,80,P1X);

    //buttons
    CreateButton("Gen. Equation",125,360,hwnd,GENEQBTN);
    CreateButton("Point-Slope",255,360,hwnd,PSLOPEBTN);
    CreateButton("Slope-intercept",125,395,hwnd,SINTERCEPTBTN);
    CreateButton("Intercept",255,395,hwnd,INTERCEPTBTN);
    CreateButton("Slope",195,430,hwnd,SLOPEBTN);
 }

但是当我替换:

中的NULL时
return CreateWindowEx(0,nme,"",WS_VISIBLE|WS_POPUP|WS_CHILD,
                      10, 10,
                      460,200,hwnd,NULL,GetModuleHandle(NULL),0);

使用:

return CreateWindowEx(0,nme,"",WS_VISIBLE|WS_POPUP|WS_CHILD,
                      10, 10,
                      460,200,hwnd,(HMENU)443,GetModuleHandle(NULL),0);

“图形场”似乎是透明的。我该如何解决这个问题

1 个答案:

答案 0 :(得分:0)

似乎弹出窗口不尊重父母的偏移。

使用ClientToScreen函数将父窗口内的坐标转换为屏幕坐标,然后使用转换后的坐标创建弹出窗口。