DestroyWindow(hCtrl);//hCtrl是一個Static的控件hWnd是一個Dialog的控件 HWND hWndTmp=CreateWindowEx(ouExStyle,(LPCSTR)"STATIC",
str,ouStyle|WS_VISIBLE,wrt.left -rt.left -3,
wrt.top -rt.top -23,
rt.right -rt.left ,
rt.bottom -rt.top ,
(HWND)hWnd,(HMENU)IDC_SAMPLE,(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),NULL);
我有如上代碼,但不知為什麼當運行兩次時就正確,但運行一次就不正確!還請各位大俠幫忙!
str,ouStyle|WS_VISIBLE,wrt.left -rt.left -3,
wrt.top -rt.top -23,
rt.right -rt.left ,
rt.bottom -rt.top ,
(HWND)hWnd,(HMENU)IDC_SAMPLE,(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),NULL);
我有如上代碼,但不知為什麼當運行兩次時就正確,但運行一次就不正確!還請各位大俠幫忙!
{
char str[127];
HWND hCtrl;//樣例控件句柄
DWORD ouStyle=WS_CHILD|WS_VISIBLE;//基本樣式
DWORD ouExStyle=0;//擴展樣式
RECT rt,wrt; //控件和對話框的坐標
int intAlign;//對齊方式
intAlign=SendDlgItemMessage(hWnd,IDC_ALIGN,CB_GETCURSEL,0,0);
switch(intAlign)
{
case 1:
ouStyle=ouStyle|SS_LEFT;
break;
case 2:
if (IsDlgButtonChecked(hWnd,IDC_CHECK3)==BST_CHECKED)
{
ouStyle=ouStyle|SS_LEFT;
}
else
{
ouStyle=ouStyle|SS_RIGHT;
}
break;
case 3:
if (IsDlgButtonChecked(hWnd,IDC_CHECK3)==BST_CHECKED)
{
ouStyle=ouStyle|SS_LEFT;
}
else
{
ouStyle=ouStyle|SS_CENTER;
}
break;
default:
break;
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK1)==BST_CHECKED)
{
ouStyle=ouStyle|SS_CENTERIMAGE;//上下左右對中
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK2)==BST_CHECKED)
{
ouStyle=ouStyle|SS_NOPREFIX;//不用&
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK3)==BST_CHECKED)
{
ouStyle=ouStyle|SS_LEFTNOWORDWRAP;//不回行
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK4)==BST_CHECKED)
{
ouStyle=ouStyle|SS_SIMPLE;//簡單
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK5)==BST_CHECKED)
{
ouStyle=ouStyle|SS_NOTIFY;//通知 }
if (IsDlgButtonChecked(hWnd,IDC_CHECK6)==BST_CHECKED)
{
ouStyle=ouStyle|SS_SUNKEN;//下沉
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK7)==BST_CHECKED)
{
ouStyle=ouStyle|SS_ETCHEDFRAME;//邊界線
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK8)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_CLIENTEDGE;//客戶區邊界
} if (IsDlgButtonChecked(hWnd,IDC_CHECK9)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_STATICEDGE;//靜態框
} if (IsDlgButtonChecked(hWnd,IDC_CHECK10)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_DLGMODALFRAME;//模型框
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK11)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_TRANSPARENT;//透明
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK12)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_ACCEPTFILES;//接受文件
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK13)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_RIGHT;//阿拉伯文用
}
if (IsDlgButtonChecked(hWnd,IDC_CHECK14)==BST_CHECKED)
{
ouExStyle=ouExStyle|WS_EX_RTLREADING;//阿拉伯文用
}
hCtrl=GetDlgItem(hWnd,IDC_SAMPLE);
GetWindowRect(hWnd,&wrt);
GetWindowRect(hCtrl,&rt);
GetDlgItemText(hWnd,IDC_SAMPLE,str,127);
DestroyWindow(hCtrl); HWND hWndTmp=CreateWindowEx(ouExStyle,(LPCSTR)"STATIC",
str,ouStyle|WS_VISIBLE,wrt.left -rt.left -3,
wrt.top -rt.top -23,
rt.right -rt.left ,
rt.bottom -rt.top ,
(HWND)hWnd,(HMENU)IDC_SAMPLE,(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),NULL);
}//這是完整代碼
你用GetWindowLong获得早先的style,然后再| 或者 &~你需要的风格,再用SetWindowLong试一下
ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW,SWP_NOZORDER);
你可以查msdn找到这个函数的说明文档