請問大神
這兩段代碼 一個在 creat之后就move有效 但是在WM_SIZE中move卻無效
case WM_CREATE:
for(i=0;i<NUM;i++)
{
hwndscroll[i] = CreateWindow(TEXT("scrollbar"),NULL,
WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,
0,0,0,0,hwnd,(HMENU)i,hinstance,NULL);
SetScrollRange(hwndscroll[i],SB_CTL,0,255,false);
SetScrollPos(hwndscroll[i],SB_CTL,0,false);
MoveWindow(hwndscroll[i],0,0,
10,100 ,true);
}
return 0;
/*case WM_SIZE:
MoveWindow(hwndscroll[i],0,0,
10,100 ,true);
return 0;*/
這個有效
case WM_CREATE:
for(i=0;i<NUM;i++)
{
hwndscroll[i] = CreateWindow(TEXT("scrollbar"),NULL,
WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,
0,0,0,0,hwnd,(HMENU)i,hinstance,NULL);
SetScrollRange(hwndscroll[i],SB_CTL,0,255,false);
SetScrollPos(hwndscroll[i],SB_CTL,0,false);
/*MoveWindow(hwndscroll[i],0,0,
10,100 ,true);*/
}
return 0;
case WM_SIZE:
MoveWindow(hwndscroll[i],0,0,
10,100 ,true);
return 0;
這個無效
求解決辦法
全部代碼如下
// win32-0.cpp : 定義應用程式的入口點。
//
#include "stdafx.h"
#include <windows.h>
#define NUM 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int idfocus ;
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ; //視窗句柄
MSG msg ; //訊息結構
WNDCLASS wndclass ; //視窗類結構
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;//加載圖示供程式使用
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; //加載滑鼠指標供程式使用
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;//獲取一個圖形物件,在這個例子中,是獲取繪制視窗背景的刷子
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))//為程式視窗注冊視窗類
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
//根據視窗類創建一個視窗
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ; //在螢屏上顯示視窗
UpdateWindow (hwnd) ; //指示視窗重繪自身
while (GetMessage (&msg, NULL, 0, 0)) //從訊息佇列中獲取訊息
{
TranslateMessage (&msg) ; //轉換某些鍵盤訊息
DispatchMessage (&msg) ; //將訊息發送給視窗程序
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static HWND hwndscroll[NUM];
static int i;
static int cxclient,cyclient;
static int cychar;
HINSTANCE hinstance;
hinstance = (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);
switch (message)
{
case WM_CREATE:
for(i=0;i<NUM;i++)
{
hwndscroll[i] = CreateWindow(TEXT("scrollbar"),NULL,
WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,
0,0,0,0,hwnd,(HMENU)i,hinstance,NULL);
SetScrollRange(hwndscroll[i],SB_CTL,0,255,false);
SetScrollPos(hwndscroll[i],SB_CTL,0,false);
/*MoveWindow(hwndscroll[i],0,0,
10,100 ,true);*/
}
return 0;
case WM_SIZE:
MoveWindow(hwndscroll[i],0,0,
10,100 ,true);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ; //在訊息佇列中插入一條“退出”訊息
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam);//執行默認的訊息處理
}
/*LRESULT CALLBACK scrollproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);//執行默認的訊息處理
}*/
uj5u.com熱心網友回復:
不對不對 上面的代碼是錯的這個才是
// win32-0.cpp : 定義應用程式的入口點。
//
#include "stdafx.h"
#include <windows.h>
#define NUM 1
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int idfocus ;
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ; //視窗句柄
MSG msg ; //訊息結構
WNDCLASS wndclass ; //視窗類結構
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;//加載圖示供程式使用
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; //加載滑鼠指標供程式使用
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;//獲取一個圖形物件,在這個例子中,是獲取繪制視窗背景的刷子
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))//為程式視窗注冊視窗類
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
//根據視窗類創建一個視窗
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ; //在螢屏上顯示視窗
UpdateWindow (hwnd) ; //指示視窗重繪自身
while (GetMessage (&msg, NULL, 0, 0)) //從訊息佇列中獲取訊息
{
TranslateMessage (&msg) ; //轉換某些鍵盤訊息
DispatchMessage (&msg) ; //將訊息發送給視窗程序
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static HWND hwndscroll[NUM];
static int i;
static int cxclient,cyclient;
static int cychar;
HINSTANCE hinstance;
hinstance = (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);
switch (message)
{
case WM_CREATE:
for(i=0;i<NUM;i++)
{
hwndscroll[i] = CreateWindow(TEXT("scrollbar"),NULL,
WS_CHILD|WS_VISIBLE|WS_TABSTOP|SBS_VERT,
0,0,0,0,hwnd,(HMENU)i,hinstance,NULL);
//SetScrollRange(hwndscroll[i],SB_CTL,0,255,false);
//SetScrollPos(hwndscroll[i],SB_CTL,0,false);
}
cychar = HIWORD(GetDialogBaseUnits);
return 0;
case WM_SIZE:
cxclient = LOWORD(lParam);
cyclient = HIWORD(lParam);
for(i=0;i<NUM;i++)
{
MoveWindow(hwndscroll[i],(i * 2 + 1) * cxclient / 14,2 * cychar,
cxclient/14,cyclient - 4 * cychar,true);
}
return 0;
case WM_DESTROY:
PostQuitMessage (0) ; //在訊息佇列中插入一條“退出”訊息
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam);//執行默認的訊息處理
}
/*LRESULT CALLBACK scrollproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);//執行默認的訊息處理
}*/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/78711.html
