SetDlgItemText() Error

X

Xzyx987X

Sorry if this is off topic for this group, but I couln't find any place
better for directing question on Windows API programming. Here's the
problem, I am calling the SetDlgItemText() function to set the text of an
edit box for an about window for my program. For some weird reason though it
won't work, and the GetLastError function gives a Control ID not found
error. I am sure that the parameters are correct so I'm at a loss as to the
cause. The only reason I can think of that this would happen is that the
about window is set as a child window of the main one, but I don't see why
that would be a problem. To be honest I would rather just send the edit box
a set text message but the object is being genorated by a recource script
and I'm not sure how to get it's hWnd. If you know how then please tell me.
Another question I wanted to ask, just in case anyone knows, when using the
CreateWindowEx() function one of the parameters is a handle to the
application instance. The way I have the application set up though, it is a
command line program that makes use of windows.h (the command line is really
handy for debbuging) so I can't get this from the winmain function. Having
this parameter NULL causes no problems in WinXP, but according to MSDN it
may break compatiblility with Win98 and below. Then again they are probobly
assuming the application has a winmain, which it doesn't. Does anyone know
if this would actually be a problem, and if so how would I get the handle to
the application instance without having a winmain?

Here's the source (stripped of any sort of practical functionallity):

#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include "resource.h"

//Function declarations

BOOL MainDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);

BOOL AboutDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);

void initialize_proc(HWND hWnd);

//Global variable declarations

HWND hWstatusbar;

//Main function. Serves as entry point for MainDialogProc

bool main(void)
{
DialogBoxParam(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_MAIN),
NULL,
(DLGPROC)MainDialogProc,
0);

return FALSE;
}

BOOL MainDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{

switch(uMsg)
{

case 48: //Didn't feel like looking up the constant for this :p
initialize_proc(hWnd);
return TRUE;
break;

case WM_CLOSE:
EndDialog(hWnd, 0);
return TRUE;
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{

case ID_HELP_ABOUT:
DialogBoxParam(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_DLG_ABOUT),
hWnd,
(DLGPROC)AboutDialogProc,
0);
break;
case ID_FILE_EXIT:
EndDialog(hWnd, 0);
return TRUE;

}

}

return FALSE;

}

BOOL AboutDialogProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{

switch (uMsg)
{
case 48:
SetDlgItemText(hWnd, IDC_DISCLAIMER, "About Box.");
printf("Last Error: %d \n", GetLastError());
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{

case IDOK:
EndDialog(hWnd, 0);
return TRUE;

}

}

return FALSE;

}

void initialize_proc(HWND hWnd)
{

//This code is a bit messy and inflexible but the GUI coding isn't really
the point here :)

//Variables for creating the status bar

INITCOMMONCONTROLSEX ControlSet;

RECT rcClient;

ControlSet.dwSize = sizeof (ControlSet);
ControlSet.dwICC = ICC_BAR_CLASSES;

InitCommonControlsEx(&ControlSet);

GetClientRect(hWnd, &rcClient);

int parts[2] = {rcClient.right / 2, rcClient.right};

//Create the status bar

hWstatusbar = CreateWindowEx(
0,
STATUSCLASSNAME,
(LPCTSTR) NULL,
WS_CHILD | WS_VISIBLE,
0,
0,
0,
0,
hWnd,
(HMENU) NULL,
(HINSTANCE) NULL, //This statement may break compatibility with Win9x (at
least according to MSDN)
NULL);

//Make sure status bar create was successful and if so, divide the status
window into 2 parts and set the message

if (!hWstatusbar){printf("Status bar create error: %d \n",
GetLastError());}

else
{

SendMessage(hWstatusbar,
SB_SETPARTS,
(WPARAM) 2,
(LPARAM) parts);
SendMessage(hWstatusbar,
WM_SETTEXT,
(WPARAM) 1,
(LPARAM) "Ready!");

}

//Set the icon for the main diolog.

SendMessage(hWnd,
WM_SETICON,
ICON_SMALL,
(LPARAM) LoadImage(NULL,
"C:\\Documents and Settings\\zyx987.ZYX987S-COMP\\My
Documents\\icon.ico",
IMAGE_ICON,
16,
16,
LR_LOADFROMFILE)
);

return;

}
 
V

Victor Bazarov

Xzyx987X said:
Sorry if this is off topic for this group, but I couln't find any place
better for directing question on Windows API programming. [...]

How about comp.os.ms-windows.programmer?
 
X

Xzyx987X

Ok thanks for your help. I'll repost this there.
Victor Bazarov said:
Xzyx987X said:
Sorry if this is off topic for this group, but I couln't find any place
better for directing question on Windows API programming. [...]

How about comp.os.ms-windows.programmer?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
topweb3twitterchannels

Latest Threads

Top