EVC编的程序,在PDA上运行。API编程,没有用MFC
窗体的Timer事件不响应,可我把窗体隐藏后,却响应了。可能是什么原因呢?会不会是某些地方阻住了?
设置定时器:SetTimer(pass,1,1000 ,NULL);//pass是窗体的句柄
这个窗体句柄我检查过,没问题。断点跟踪,没进入过WM_TIMER的代码内。把窗体隐藏后,进入了。那么应该也不是Timer的ID号的问题。
没有必要再发一个贴子吧
把代码打包,传上来吧。否则没有办法分析的,可以肯定是程序的问题。
试试这个
#include
#include
#include
#include "Commdlg.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING] = {L"Nemochips"}; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING] = {L"NEMO"}; // The title bar text
static g_bImageDrawn = FALSE;
HMENU hmTrackPopup;
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPTSTR lpCmdLine,int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
INT a = 0;
Sleep(5000);
ATOM tom = MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
printf("winmain InitInstance fail !");
return FALSE;
}
CoInitialize(NULL);
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)"");
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = NULL;
wndclass.hInstance = hInstance;
wndclass.hCursor = NULL;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szWindowClass;
return RegisterClass (&wndclass);
}
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, 0,
0, 0, 320, 240, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
printf("create fail!!!");
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
SetFocus(hWnd);
SetTimer(hWnd, TIMER_ID, TIMER_RATE, NULL)
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR *pszHello = TEXT("NemoPlayer");
//LoadString(hInst, 111, szHello, MAX_LOADSTRING);
FILE *fpYUV = NULL;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, pszHello, _tcslen(pszHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TIMER:
//..............
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
我把程序截取了一下,可能有点乱,以下是出问题的窗体的代码:
#include "stdafx.h"
#include
#include "player.h"
#include "try.h"
#include "0005.h"
#define PLAYER 1
#define MAIN 0
//HINSTANCE hInstance= NULL;
unsigned short usX_Bg_BitMap2;//背景位图在clientarea的位置
unsigned short usy_Bg_BitMap2;
unsigned short usWidth_Bg_BitMap2;
unsigned short usHeight_Bg_BitMap2;
HWND g_hwndBTplayer[5];
HWND g_hwndslider[15];
TCHAR BtplayerClassName[]=TEXT("bt");
TCHAR SliderClassName[]=TEXT("slider");
//标志位:
static bool playornot=true;
static LPCTSTR lpString;
static LPCTSTR lpStringtemp;
HWND m_hWnd;
HWAVEOUT hwo;
WAVEHDR hdr;
PBYTE pBufferBits;
PWAVEFORMATEX pwfx;
char Lname[30][100];
char* Ljingdu[30];//此处不正确
char* Lweidu[30];
char* Llujing[30];
char* Lrange[30];
int hangID;
DWORD volume;
unsigned int vol;
bool autoclose;
unsigned long second;
DWORD dwDuration;
DWORD dwPlayRate;
HWND g_hwndlist;
HWND g_hwndpro;
HWND pass;
//HWND passbutton;
LVITEM lvItem;
int mark;
LPTSTR lujing;
//=_T("My Documents\\个人\\peoplepark.wav");//支持汉字路径:OK!!!
LPTSTR pszText=NULL;//Why设为此类型???
extern int formstate;
int i;
int m;
DWORD dwNumRead;
DWORD dwNum;
bool paintagain;
LRESULT CALLBACK Dlgplayer(HWND hDlgplayer, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc,hdcMem;
PAINTSTRUCT ps;
static HINSTANCE hInstance = NULL;
//存储背景位图的句柄
static HBITMAP hBitMapBk;
//background位图的宽度与高度
static int cxSource,cySource;
pass=hDlgplayer;
switch (message)
{
case WM_CREATE:
{
BITMAP bitmap;
//获取实体句柄
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
//获取背景位图句柄
unsigned int uiID = (unsigned int)MAKEINTRESOURCE(IDB_BITMAP_BACK_GROUND2);
hBitMapBk = LoadBitmap(hInstance,(LPWSTR)uiID);
//获取背景位图详细信息
GetObject(hBitMapBk,sizeof(BITMAP),&bitmap);
cxSource = bitmap.bmWidth;//位图大小最终是窗体大小
cySource = bitmap.bmHeight;
g_hwndBTplayer[0] = CreateWindow(BtplayerClassName,TEXT(""),
WS_CHILD|WS_VISIBLE,
180,45,53,54,
hDlgplayer,NULL,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
InitCommonControls();
g_hwndlist = CreateWindow(WC_LISTVIEW,TEXT(""),
WS_CHILD|WS_VISIBLE|LVS_ALIGNTOP|WS_VSCROLL|LVS_EX_FULLROWSELECT|
WS_BORDER|LVS_REPORT,
15,25,160,180,
hDlgplayer,NULL,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
ListView_SetExtendedListViewStyle(g_hwndlist, LVS_EX_FULLROWSELECT);
LV_COLUMN lvcol;
lvcol.cx = 158;
lvcol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvcol.fmt = LVCFMT_LEFT;
lvcol.pszText= _T("景点名称");
ListView_InsertColumn(g_hwndlist,0,(const LV_COLUMN FAR*)& lvcol);
g_hwndpro = CreateWindow(PROGRESS_CLASS,TEXT(""),
WS_CHILD|WS_VISIBLE|PBS_SMOOTH|WS_BORDER,
15,215,160,10,
hDlgplayer,NULL,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
PostMessage(g_hwndpro,PBM_SETSTEP,(WPARAM)1,0L);
PostMessage(g_hwndpro,PBM_SETPOS,(WPARAM)50,0L);
SetFocus(pass);
second=0;
SetTimer(hDlgplayer,1,1000 ,NULL);
}
break;
case WM_SIZE:
{
RECT rect_client ;
GetClientRect(hDlgplayer,&rect_client);
usHeight_Bg_BitMap2 = (unsigned short)rect_client.bottom;
usWidth_Bg_BitMap2 = (unsigned short)rect_client.right;
usX_Bg_BitMap2 = (unsigned short)rect_client.left;
usy_Bg_BitMap2 = (unsigned short)rect_client.top;
}
break;
case WM_TIMER:
{
switch(wParam)
{
case 1:
// MessageBox(pass,_T("ss"),_T("dd"),MB_OK);
second++;
PostMessage(g_hwndpro,PBM_SETPOS,(WPARAM)second,0L);
if(second==dwDuration)
KillTimer(hDlgplayer,1);
break;
default:
break;
}
}
break;
case WM_PAINT:
hdc = BeginPaint(hDlgplayer, &ps);
//重画机体背景位图
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem,hBitMapBk);
//SetStretchBltMode(hdc,COLORONCOLOR);
StretchBlt(hdc,usX_Bg_BitMap2,usy_Bg_BitMap2,usWidth_Bg_BitMap2,usHeight_Bg_BitMap2,
//StretchBlt(hdc,usX_Bg_BitMap,usy_Bg_BitMap,cxSource,cySource,
hdcMem,0,0,cxSource,cySource,SRCCOPY);
DeleteDC(hdcMem);
EndPaint(hDlgplayer, &ps);
break;
case WM_DESTROY:
DeleteObject(hBitMapBk);
// DeleteObject(hBitMapTB00);
// PostQuitMessage(0);
break;
}
return FALSE;
}
LRESULT CALLBACK BTPlayerWndProc(HWND hWndbtplayer,UINT message,WPARAM wParam,LPARAM lParam)
{
SetFocus(pass);
return 0;
}
LRESULT CALLBACK SliderWndProc(HWND hWndslider,UINT message,WPARAM wParam,LPARAM lParam)
{
SetFocus(pass);
return 0;
}
我试过,把g_hwndBTplayer[0] = CreateWindow(BtplayerClassName,TEXT(""),
WS_CHILD|WS_VISIBLE,
180,45,53,54,
hDlgplayer,NULL,
((LPCREATESTRUCT)lParam)->hInstance,NULL);
这一段去掉之后,timer就可以响应了。应该是这个按钮子窗体的问题。但是不知为什么。
窗体类的注册是这样的:
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MY0005));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
RegisterClass(&wc);
wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wc.lpfnWndProc = (WNDPROC)Dlgmain;
wc.lpszClassName = ClassNameMain;
RegisterClass(&wc);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpfnWndProc = (WNDPROC)Dlgplayer;
wc.lpszClassName = ClassNamePlayer;
RegisterClass(&wc);
wc.lpfnWndProc = (WNDPROC)Dlgsample;
wc.lpszClassName = ClassNameSample;
RegisterClass(&wc);
//注册按钮窗体
wc.lpfnWndProc = (WNDPROC)BTWndProc;
wc.cbWndExtra = sizeof(long);
wc.hIcon = NULL;
wc.lpszClassName = BtClassName;
RegisterClass(&wc);
//注册出问题的窗体的按钮子窗体:
wc.lpfnWndProc = (WNDPROC)BTPlayerWndProc;
wc.cbWndExtra = sizeof(long);
wc.hIcon = NULL;
wc.lpszClassName = BtplayerClassName;
RegisterClass(&wc);
//注册slider窗体
wc.lpfnWndProc = (WNDPROC)SliderWndProc;
wc.cbWndExtra = sizeof(long);
wc.hIcon = NULL;
wc.lpszClassName = SliderClassName;
return RegisterClass(&wc);
}
The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions retrieve this message only when no other higher-priority messages are in the thread's message queue.
g_hwndBTplayer[0] = CreateWindow(BtplayerClassName,TEXT( " "),
WS_CHILD ¦WS_VISIBLE,
180,45,53,54,
hDlgplayer,NULL,
((LPCREATESTRUCT)lParam)-> hInstance,NULL);
我猜可能是你的那个窗口占用太多资源吧。
这样看代码,不容易看出问题的。
楼主最好将自己整个工程打包。呵呵~,我的要求是不是有点太高!源代码可是宝贝。