win32 API问题
下面这段代码,怎么没画出直线(好像是startorgx,startorgy无效)startorgx等是long类型,纯win32API函数写的,写在窗口过程函数里的cas...
下面这段代码,怎么没画出直线(好像是startorgx,startorgy无效)startorgx等是long类型,纯win32 API函数写的,写在窗口过程函数里的
case WM_LBUTTONDOWN:
hdc=GetDC(hWnd);
Startorgx=LOWORD(lParam);
Startorgy=HIWORD(lParam);
TextOut(hdc,LOWORD(lParam), HIWORD(lParam),"hxw",3);
//MoveToEx(hdc,Startorgx,Startorgy,(LPPOINT) NULL);
//LineTo(hdc,Startorgx+100,Startorgy+100);
ReleaseDC(hWnd,hdc);
break;
case WM_LBUTTONUP:
Endorgx=LOWORD(lParam);
Endorgy=HIWORD(lParam);
hdc=GetDC(hWnd);
MoveToEx(hdc,Startorgx,Startorgy,(LPPOINT)NULL);
LineTo(hdc,Endorgx,Endorgy);
char a[1];
sprintf(a,"%d",Startorgx);
TextOut(hdc,0,0,a,1);
//MoveToEx(hdc,0,0,(LPPOINT) NULL);
//LineTo(hdc,100,100);
TextOut(hdc,LOWORD(lParam), HIWORD(lParam),"wel",3);
ReleaseDC(hWnd,hdc);
break;
二楼的,你写的这些我知道,我想用鼠标的起始坐标来画直线,而不是随便画,我想知道我那样写为什么Startorgx,Startorgy到WM_LBUTTONUP这个里会是无效(没初始化)的呢? 展开
case WM_LBUTTONDOWN:
hdc=GetDC(hWnd);
Startorgx=LOWORD(lParam);
Startorgy=HIWORD(lParam);
TextOut(hdc,LOWORD(lParam), HIWORD(lParam),"hxw",3);
//MoveToEx(hdc,Startorgx,Startorgy,(LPPOINT) NULL);
//LineTo(hdc,Startorgx+100,Startorgy+100);
ReleaseDC(hWnd,hdc);
break;
case WM_LBUTTONUP:
Endorgx=LOWORD(lParam);
Endorgy=HIWORD(lParam);
hdc=GetDC(hWnd);
MoveToEx(hdc,Startorgx,Startorgy,(LPPOINT)NULL);
LineTo(hdc,Endorgx,Endorgy);
char a[1];
sprintf(a,"%d",Startorgx);
TextOut(hdc,0,0,a,1);
//MoveToEx(hdc,0,0,(LPPOINT) NULL);
//LineTo(hdc,100,100);
TextOut(hdc,LOWORD(lParam), HIWORD(lParam),"wel",3);
ReleaseDC(hWnd,hdc);
break;
二楼的,你写的这些我知道,我想用鼠标的起始坐标来画直线,而不是随便画,我想知道我那样写为什么Startorgx,Startorgy到WM_LBUTTONUP这个里会是无效(没初始化)的呢? 展开
展开全部
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char szText[] = "最简单的窗口程序!";
switch (message)
{
case WM_CREATE:
{
//::SetDlgItemText(hwnd, "123");
return 0 ;
}
case WM_PAINT: // 窗口客户区需要重画
{/**/
HDC hdc;
PAINTSTRUCT ps;
RECT rt;//用于定义左上角,右下角坐标
int x, y;
// 使无效的客户区变的有效,并取得设备环境句柄
hdc = ::BeginPaint (hwnd, &ps) ;
// 显示文字
::MoveToEx(hdc, 0, 200, NULL);
::LineTo(hdc, 500, 200);
::LineTo(hdc, 500, 0);
::TextOut(hdc, 10, 10, szText, strlen(szText));
::EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY: // 正在销毁窗口
// 向消息队列投递一个WM_QUIT消息,促使GetMessage函数返回0结束消息循环
::PostQuitMessage(0) ;
return 0 ;
}
// 将我们不处理的消息交给系统做默认处理
return ::DefWindowProc(hwnd, message, wParam, lParam);
}
{
char szText[] = "最简单的窗口程序!";
switch (message)
{
case WM_CREATE:
{
//::SetDlgItemText(hwnd, "123");
return 0 ;
}
case WM_PAINT: // 窗口客户区需要重画
{/**/
HDC hdc;
PAINTSTRUCT ps;
RECT rt;//用于定义左上角,右下角坐标
int x, y;
// 使无效的客户区变的有效,并取得设备环境句柄
hdc = ::BeginPaint (hwnd, &ps) ;
// 显示文字
::MoveToEx(hdc, 0, 200, NULL);
::LineTo(hdc, 500, 200);
::LineTo(hdc, 500, 0);
::TextOut(hdc, 10, 10, szText, strlen(szText));
::EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY: // 正在销毁窗口
// 向消息队列投递一个WM_QUIT消息,促使GetMessage函数返回0结束消息循环
::PostQuitMessage(0) ;
return 0 ;
}
// 将我们不处理的消息交给系统做默认处理
return ::DefWindowProc(hwnd, message, wParam, lParam);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询